Started terrain editor

This commit is contained in:
2025-01-02 04:16:30 +03:00
parent c3720f69c8
commit 6622e1a6ac
13 changed files with 765 additions and 160 deletions

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=16 format=2]
[ext_resource path="res://terrain/terrain_draw.png" type="Image" id=2]
[ext_resource path="res://terrain/terrain.png" type="Image" id=3]
@@ -44,7 +44,11 @@ extents = Vector3( 50, 1, 50 )
size = Vector3( 4, 4, 120 )
[sub_resource type="CubeMesh" id=14]
size = Vector3( 3, 60, 3 )
size = Vector3( 1.5, 60, 1.5 )
[sub_resource type="TorusMesh" id=15]
inner_radius = 5.5
outer_radius = 7.0
[node name="editor" type="Spatial"]
@@ -67,10 +71,17 @@ focus_mode = 2
unique_name_in_owner = true
margin_top = 52.0
margin_right = 248.0
margin_bottom = 524.0
margin_bottom = 128.0
[node name="v_terrain" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 132.0
margin_right = 248.0
margin_bottom = 132.0
[node name="v_buildings" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
visible = false
margin_top = 528.0
margin_right = 248.0
margin_bottom = 528.0
@@ -520,3 +531,25 @@ shape = SubResource( 12 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 30, 0 )
mesh = SubResource( 14 )
material/0 = SubResource( 11 )
[node name="terrain_cursor" type="Spatial" parent="."]
unique_name_in_owner = true
[node name="Area" type="Area" parent="terrain_cursor"]
collision_layer = 32768
collision_mask = 32768
monitoring = false
[node name="CollisionShape" type="CollisionShape" parent="terrain_cursor/Area"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
shape = SubResource( 12 )
[node name="mi" type="MeshInstance" parent="terrain_cursor"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 30, 0 )
mesh = SubResource( 14 )
material/0 = SubResource( 11 )
[node name="mi2" type="MeshInstance" parent="terrain_cursor"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 30, 0 )
mesh = SubResource( 15 )
material/0 = SubResource( 11 )

View File

@@ -2,44 +2,68 @@
#include <modules/voxel/util/fixed_array.h>
#include "modules/voxel/util/span.h"
namespace {
namespace
{
inline float get_height_repeat(const Image &im, int x, int y) {
int xx = (float)x * 0.1f + im.get_width() / 2;
int yy = (float)y * 0.1f + im.get_height() / 2;
float r = im.get_pixel(wrap(xx, im.get_width()), wrap(yy, im.get_height())).r;
float px = (r - 0.5) * 2.0f;
float s = (px >= 0.0f) ? 1.0f : -1.0f;
float m = px * px * s * 0.5f;
return m + 0.5f;
}
#if 0
inline float get_height_repeat(const Image &im, int x, int y)
{
int xx = (float)x * 0.1f + im.get_width() / 2;
int yy = (float)y * 0.1f + im.get_height() / 2;
float r = im.get_pixel(wrap(xx, im.get_width()), wrap(yy, im.get_height())).r;
float px = (r - 0.5) * 2.0f;
float s = (px >= 0.0f) ? 1.0f : -1.0f;
float m = px * px * s * 0.5f;
return m + 0.5f;
}
inline float get_height_blurred(const Image &im, int x, int y) {
int xx = x;
int yy = y;
float h = 0.0f;
int i, j, count = 0;
for (i = -24; i < 25; i += 2)
for (j = -24; j < 25; j += 2) {
h += get_height_repeat(im, xx + j, yy + i);
count += 1;
}
return h / (float)count;
}
inline float get_height_blurred(const Image &im, int x, int y)
{
int xx = x;
int yy = y;
float h = 0.0f;
int i, j, count = 0;
for (i = -24; i < 25; i += 2)
for (j = -24; j < 25; j += 2)
{
h += get_height_repeat(im, xx + j, yy + i);
count += 1;
}
return h / (float)count;
}
#endif
inline float get_height_linear_img(const Image &im, int x, int y)
{
int xx = x + im.get_width() / 2;
int yy = y + im.get_height() / 2;
float r = im.get_pixel(wrap(xx, im.get_width()), wrap(yy, im.get_height())).r;
float px = (r - 0.5) * 2.0f;
float s = (px >= 0.0f) ? 1.0f : -1.0f;
float m = px * px * s * 0.5f;
return m + 0.5f;
}
} // namespace
VoxelGeneratorImgMapper::VoxelGeneratorImgMapper() {
VoxelGeneratorImgMapper::VoxelGeneratorImgMapper()
: VoxelGeneratorHeightmap(),
world_size(10240),
grid_size(0)
{
}
VoxelGeneratorImgMapper::~VoxelGeneratorImgMapper() {
if (_parameters.image.is_valid()) {
VoxelGeneratorImgMapper::~VoxelGeneratorImgMapper()
{
if (_parameters.image.is_valid())
{
_parameters.image->unlock();
}
}
void VoxelGeneratorImgMapper::set_image_bg(Ref<Image> im) {
if (im == _image_bg) {
void VoxelGeneratorImgMapper::set_image_bg(Ref<Image> im)
{
if (im == _image_bg)
{
return;
}
if (!im.is_valid())
@@ -48,60 +72,70 @@ void VoxelGeneratorImgMapper::set_image_bg(Ref<Image> im) {
compose();
}
Ref<Image> VoxelGeneratorImgMapper::get_image_bg() const {
Ref<Image> VoxelGeneratorImgMapper::get_image_bg() const
{
return _image_bg;
}
void VoxelGeneratorImgMapper::set_image_overlay(Ref<Image> im)
{
if (im == _image_overlay || !im.is_valid()) {
if (im == _image_overlay || !im.is_valid())
{
return;
}
_image_overlay = im;
compose();
}
Ref<Image> VoxelGeneratorImgMapper::get_image_overlay() const {
Ref<Image> VoxelGeneratorImgMapper::get_image_overlay() const
{
return _image_overlay;
}
void VoxelGeneratorImgMapper::set_image_buildings(Ref<Image> im)
{
if (im == _image_buildings || !im.is_valid()) {
if (im == _image_buildings || !im.is_valid())
{
return;
}
_image_buildings = im;
compose();
}
Ref<Image> VoxelGeneratorImgMapper::get_image_buildings() const {
Ref<Image> VoxelGeneratorImgMapper::get_image_buildings() const
{
return _image_buildings;
}
void VoxelGeneratorImgMapper::set_image_draw(Ref<Image> im)
{
if (im == _image_draw || !im.is_valid()) {
if (im == _image_draw || !im.is_valid())
{
return;
}
_image_draw = im;
compose();
}
Ref<Image> VoxelGeneratorImgMapper::get_image_draw() const {
Ref<Image> VoxelGeneratorImgMapper::get_image_draw() const
{
return _image_draw;
}
void VoxelGeneratorImgMapper::set_blur_enabled(bool enable) {
void VoxelGeneratorImgMapper::set_blur_enabled(bool enable)
{
RWLockWrite wlock(_parameters_lock);
_parameters.blur_enabled = enable;
}
bool VoxelGeneratorImgMapper::is_blur_enabled() const {
bool VoxelGeneratorImgMapper::is_blur_enabled() const
{
RWLockRead rlock(_parameters_lock);
return _parameters.blur_enabled;
}
VoxelGenerator::Result VoxelGeneratorImgMapper::generate_block(VoxelBlockRequest &input) {
VoxelGenerator::Result VoxelGeneratorImgMapper::generate_block(VoxelBlockRequest &input)
{
VoxelBufferInternal &out_buffer = input.voxel_buffer;
Parameters params;
@@ -117,16 +151,12 @@ VoxelGenerator::Result VoxelGeneratorImgMapper::generate_block(VoxelBlockRequest
ERR_FAIL_COND_V(params.image->get_height() == 0, result);
const Image &image = **params.image;
if (params.blur_enabled) {
{
result = VoxelGeneratorHeightmap::generate(
out_buffer,
[&image](int x, int z) { return get_height_blurred(image, x, z); },
input.origin_in_voxels, input.lod);
} else {
result = VoxelGeneratorHeightmap::generate(
out_buffer,
[&image](int x, int z) { return get_height_repeat(image, x, z); },
input.origin_in_voxels, input.lod);
out_buffer,
[this](int x, int z)
{ return get_height_linear(Vector3(x, 0, z)); },
input.origin_in_voxels, input.lod);
}
out_buffer.compress_uniform_channels();
@@ -139,7 +169,7 @@ void VoxelGeneratorImgMapper::set_height(const Vector3 &v, float height)
float h = CLAMP(height, -100.0f, 100.0f);
float c = (h + 100.0f) / 200.0;
Vector2 pt = Vector2(v.x * 0.1f + _image_overlay->get_width() / 2,
v.z * 0.1f + _image_overlay->get_height() / 2);
v.z * 0.1f + _image_overlay->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_overlay->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_overlay->get_height() - 1);
_image_overlay->fill_rect(Rect2(pt - Vector2(3, 3), Vector2(6, 6)), Color(c, 0, 0, 1));
@@ -147,10 +177,37 @@ void VoxelGeneratorImgMapper::set_height(const Vector3 &v, float height)
float VoxelGeneratorImgMapper::get_height(const Vector3 &v)
{
#if 0
if (_parameters.blur_enabled)
return get_height_blurred(**_parameters.image, v.x, v.z);
else
return get_height_repeat(**_parameters.image, v.x, v.z);
#endif
return get_height_linear(v);
}
float VoxelGeneratorImgMapper::get_height_linear(const Vector3 &v)
{
int px = (int)(v.x / grid_size);
int pz = (int)(v.z / grid_size);
float mx = (float)px * grid_size;
float mz = (float)pz * grid_size;
// float Mx = mx + (float)grid_size;
// float Mz = mz + (float)grid_size;
float x_weight = (v.x - mx) / (float)grid_size;
float z_weight = (v.z - mz) / (float)grid_size;
// float d0x = (v.x - mx) / (float)grid_size;
// float d0z = (v.z - mz) / (float)grid_size;
// float d1x = (mx + (float)grid_size - v.x) / (float)grid_size;
// float d1z = (mz + (float)grid_size - v.z) / (float)grid_size;
float p0 = get_height_linear_img(**_parameters.image, px, pz);
float p1 = get_height_linear_img(**_parameters.image, px + 1, pz);
float p2 = get_height_linear_img(**_parameters.image, px, pz + 1);
float p3 = get_height_linear_img(**_parameters.image, px + 1, pz + 1);
float a = (1.0f - x_weight);
float b = (1.0f - z_weight);
float result = p0 * a * b + p1 * x_weight * b + p2 * z_weight * a + p3 * x_weight * z_weight;
return result;
}
float VoxelGeneratorImgMapper::get_height_full(const Vector3 &v)
@@ -158,26 +215,254 @@ float VoxelGeneratorImgMapper::get_height_full(const Vector3 &v)
return get_height(v) * 200.0f - 100.0f;
}
std::map<int, struct EditBrush *> EditBrush::brushes;
struct Brush0 : EditBrush
{
Brush0(Ref<Image> &image) : EditBrush(0, image)
{
}
void draw(const Vector3 &v, float r, float s)
{
int i, j;
int xs = 3 * r;
float c = 0.5f;
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r)
{
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + draw_image->get_width() / 2,
pos.z * 0.1f + draw_image->get_height() / 2);
pt.x = CLAMP(pt.x, 1, draw_image->get_width() - 1);
pt.y = CLAMP(pt.y, 1, draw_image->get_height() - 1);
draw_image->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
}
}
}
};
struct Brush1 : EditBrush
{
Brush1(Ref<Image> &image) : EditBrush(1, image)
{
}
void draw(const Vector3 &v, float r, float s)
{
int i, j;
int xs = 3 * r;
float c = 0.5f;
/* erase stuff */
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r)
{
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + draw_image->get_width() / 2,
pos.z * 0.1f + draw_image->get_height() / 2);
pt.x = CLAMP(pt.x, 1, draw_image->get_width() - 1);
pt.y = CLAMP(pt.y, 1, draw_image->get_height() - 1);
draw_image->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 0));
}
}
}
};
struct Brush2 : EditBrush
{
Ref<Curve> curve;
Brush2(Ref<Image> &image, Ref<Curve> &curve)
: EditBrush(2, image), curve(curve)
{
}
void draw(const Vector3 &v, float r, float s)
{
int i, j;
int xs = 3 * r;
float c = 0.5f;
float scale = s / 100.0f;
ERR_FAIL_COND(!curve.is_valid());
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r)
{
float h = curve->interpolate_baked(xr / r) * scale;
h = CLAMP(h, -100.0, 100.0f);
c = (h + 100.0f) / 200.0;
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + draw_image->get_width() / 2,
pos.z * 0.1f + draw_image->get_height() / 2);
pt.x = CLAMP(pt.x, 1, draw_image->get_width() - 1);
pt.y = CLAMP(pt.y, 1, draw_image->get_height() - 1);
draw_image->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
}
}
}
};
struct Brush3 : EditBrush
{
Ref<Curve> curve;
VoxelGeneratorImgMapper *imgmap;
Brush3(Ref<Image> &image, Ref<Curve> &curve,
VoxelGeneratorImgMapper *imgmap)
: EditBrush(3, image), curve(curve), imgmap(imgmap)
{
}
void draw(const Vector3 &v, float r, float s)
{
int i, j;
int xs = 3 * r;
float c = 0.5f;
float scale = s / 100.0f;
/* rel draw curve1 */
ERR_FAIL_COND(!curve.is_valid());
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r)
{
float h = curve->interpolate_baked(xr / r) * scale;
if (h < -2.0f || h > 2.0f)
{
h += imgmap->get_height_full(v + Vector3(i, 0.0f, j));
h = CLAMP(h, -100.0, 100.0f);
c = (h + 100.0f) / 200.0;
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + draw_image->get_width() / 2,
pos.z * 0.1f + draw_image->get_height() / 2);
pt.x = CLAMP(pt.x, 1, draw_image->get_width() - 1);
pt.y = CLAMP(pt.y, 1, draw_image->get_height() - 1);
draw_image->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
}
}
}
}
};
struct Brush4 : EditBrush
{
Ref<Curve> curve;
VoxelGeneratorImgMapper *imgmap;
Brush4(Ref<Image> &image, Ref<Curve> &curve,
VoxelGeneratorImgMapper *imgmap)
: EditBrush(4, image), curve(curve), imgmap(imgmap)
{
}
void draw(const Vector3 &v, float r, float s)
{
int i, j;
int xs = 3 * r;
float c = 0.5f;
float scale = s / 100.0f;
/* rel draw curve2 */
ERR_FAIL_COND(!curve.is_valid());
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r)
{
float h = curve->interpolate_baked(xr / r) * scale;
if (h < -2.0f || h > 2.0f)
{
h += imgmap->get_height_full(v + Vector3(i, 0.0f, j));
h = CLAMP(h, -100.0, 100.0f);
c = (h + 100.0f) / 200.0;
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + draw_image->get_width() / 2,
pos.z * 0.1f + draw_image->get_height() / 2);
pt.x = CLAMP(pt.x, 1, draw_image->get_width() - 1);
pt.y = CLAMP(pt.y, 1, draw_image->get_height() - 1);
draw_image->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
}
}
}
}
};
struct Brush5 : EditBrush
{
VoxelGeneratorImgMapper *imgmap;
Brush5(Ref<Image> &image,
VoxelGeneratorImgMapper *imgmap)
: EditBrush(5, image), imgmap(imgmap)
{
}
void draw(const Vector3 &v, float r, float s)
{
int i, j;
int xs = 3 * r;
float c = 0.5f;
float scale = s / 100.0f;
float h = imgmap->get_height_full(v) + 2.0f;
h = CLAMP(h, -100.0, 100.0f);
for (i = -8; i < 8 + 1; i++)
for (j = -8; j < 8 + 1; j++)
{
Vector3 pos(v.x + i, v.y, v.z + j);
h = MAX(h, imgmap->get_height_full(pos) + 2.0f);
}
c = (h + 100.0f) / 200.0;
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r)
{
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + draw_image->get_width() / 2,
pos.z * 0.1f + draw_image->get_height() / 2);
pt.x = CLAMP(pt.x, 1, draw_image->get_width() - 1);
pt.y = CLAMP(pt.y, 1, draw_image->get_height() - 1);
draw_image->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
}
}
}
};
void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int id)
{
ERR_FAIL_COND(!_image_draw.is_valid());
ERR_FAIL_COND(!curve1.is_valid());
ERR_FAIL_COND(!curve2.is_valid());
static struct Brush0 b0(_image_draw);
static struct Brush1 b1(_image_draw);
static struct Brush2 b2(_image_draw, curve1);
static struct Brush3 b3(_image_draw, curve1, this);
static struct Brush4 b4(_image_draw, curve2, this);
static struct Brush5 b5(_image_draw, this);
int i, j;
if (r < 1.0f)
r = 1.0f;
ERR_FAIL_COND(!_image_draw.is_valid());
float c = 0.5f;
int xs = 3 * r;
float base_h = get_height_full(v);
float scale = s / 100.0f;
switch (id) {
EditBrush::draw_brush(v, r, s, id);
#if 0
switch (id)
{
case 0:
/* flat stuff */
for (i = -xs ; i < xs + 1; i++)
for (j = -xs ; j < xs + 1; j++) {
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r) {
if (xr < r)
{
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + _image_draw->get_width() / 2,
pos.z * 0.1f + _image_draw->get_height() / 2);
pos.z * 0.1f + _image_draw->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_draw->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_draw->get_height() - 1);
_image_draw->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
@@ -186,13 +471,15 @@ void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int
break;
case 1:
/* erase stuff */
for (i = -xs ; i < xs + 1; i++)
for (j = -xs ; j < xs + 1; j++) {
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r) {
if (xr < r)
{
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + _image_draw->get_width() / 2,
pos.z * 0.1f + _image_draw->get_height() / 2);
pos.z * 0.1f + _image_draw->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_draw->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_draw->get_height() - 1);
_image_draw->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 0));
@@ -202,17 +489,19 @@ void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int
case 2:
/* abs draw curve */
ERR_FAIL_COND(!curve1.is_valid());
for (i = -xs ; i < xs + 1; i++)
for (j = -xs ; j < xs + 1; j++) {
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r) {
if (xr < r)
{
float h = curve1->interpolate_baked(xr / r) * scale;
h = CLAMP(h, -100.0, 100.0f);
c = (h + 100.0f) / 200.0;
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + _image_draw->get_width() / 2,
pos.z * 0.1f + _image_draw->get_height() / 2);
pos.z * 0.1f + _image_draw->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_draw->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_draw->get_height() - 1);
_image_draw->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
@@ -222,19 +511,22 @@ void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int
case 3:
/* rel draw curve1 */
ERR_FAIL_COND(!curve1.is_valid());
for (i = -xs ; i < xs + 1; i++)
for (j = -xs ; j < xs + 1; j++) {
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r) {
if (xr < r)
{
float h = curve1->interpolate_baked(xr / r) * scale;
if (h < -2.0f || h > 2.0f) {
if (h < -2.0f || h > 2.0f)
{
h += get_height_full(v + Vector3(i, 0.0f, j));
h = CLAMP(h, -100.0, 100.0f);
c = (h + 100.0f) / 200.0;
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + _image_draw->get_width() / 2,
pos.z * 0.1f + _image_draw->get_height() / 2);
pos.z * 0.1f + _image_draw->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_draw->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_draw->get_height() - 1);
_image_draw->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
@@ -245,19 +537,22 @@ void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int
case 4:
/* rel draw curve2 */
ERR_FAIL_COND(!curve2.is_valid());
for (i = -xs ; i < xs + 1; i++)
for (j = -xs ; j < xs + 1; j++) {
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r) {
if (xr < r)
{
float h = curve2->interpolate_baked(xr / r) * scale;
if (h < -2.0f || h > 2.0f) {
if (h < -2.0f || h > 2.0f)
{
h += get_height_full(v + Vector3(i, 0.0f, j));
h = CLAMP(h, -100.0, 100.0f);
c = (h + 100.0f) / 200.0;
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + _image_draw->get_width() / 2,
pos.z * 0.1f + _image_draw->get_height() / 2);
pos.z * 0.1f + _image_draw->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_draw->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_draw->get_height() - 1);
_image_draw->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
@@ -303,31 +598,36 @@ void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int
} break;
#endif
case 5:
{
float h = get_height_full(v) + 2.0f;
h = CLAMP(h, -100.0, 100.0f);
for (i = -8 ; i < 8 + 1; i++)
for (j = -8 ; j < 8 + 1; j++) {
{
float h = get_height_full(v) + 2.0f;
h = CLAMP(h, -100.0, 100.0f);
for (i = -8; i < 8 + 1; i++)
for (j = -8; j < 8 + 1; j++)
{
Vector3 pos(v.x + i, v.y, v.z + j);
h = MAX(h, get_height_full(pos) + 2.0f);
}
c = (h + 100.0f) / 200.0;
for (i = -xs; i < xs + 1; i++)
for (j = -xs; j < xs + 1; j++)
{
float xr = Vector2(i, j).length();
if (xr < r)
{
Vector3 pos(v.x + i, v.y, v.z + j);
h = MAX(h, get_height_full(pos) + 2.0f);
Vector2 pt = Vector2(pos.x * 0.1f + _image_draw->get_width() / 2,
pos.z * 0.1f + _image_draw->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_draw->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_draw->get_height() - 1);
_image_draw->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
}
c = (h + 100.0f) / 200.0;
for (i = -xs ; i < xs + 1; i++)
for (j = -xs ; j < xs + 1; j++) {
float xr = Vector2(i, j).length();
if (xr < r) {
Vector3 pos(v.x + i, v.y, v.z + j);
Vector2 pt = Vector2(pos.x * 0.1f + _image_draw->get_width() / 2,
pos.z * 0.1f + _image_draw->get_height() / 2);
pt.x = CLAMP(pt.x, 1, _image_draw->get_width() - 1);
pt.y = CLAMP(pt.y, 1, _image_draw->get_height() - 1);
_image_draw->fill_rect(Rect2(pt - Vector2(1, 1), Vector2(2, 2)), Color(c, 0, 0, 1));
}
}
} break;
}
}
break;
default:
break;
}
#endif
}
void VoxelGeneratorImgMapper::compose()
@@ -338,27 +638,33 @@ void VoxelGeneratorImgMapper::compose()
ERR_FAIL_COND(!_image_draw.is_valid());
copy = _image_bg->duplicate();
if (copy->get_width() == _image_draw->get_width() &&
copy->get_height() == _image_draw->get_height()) {
copy->blend_rect(_image_draw,
Rect2(0, 0, _image_draw->get_width(),
_image_draw->get_height()),
Vector2());
copy->get_height() == _image_draw->get_height())
{
copy->blend_rect(_image_draw,
Rect2(0, 0, _image_draw->get_width(),
_image_draw->get_height()),
Vector2());
}
if (copy->get_width() == _image_overlay->get_width() &&
copy->get_height() == _image_overlay->get_height()) {
copy->blend_rect(_image_overlay,
Rect2(0, 0, _image_overlay->get_width(),
_image_overlay->get_height()),
Vector2());
copy->get_height() == _image_overlay->get_height())
{
copy->blend_rect(_image_overlay,
Rect2(0, 0, _image_overlay->get_width(),
_image_overlay->get_height()),
Vector2());
}
RWLockWrite wlock(_parameters_lock);
// lock() prevents us from reading the same image from multiple threads, so we lock it up-front.
// This might no longer be needed in Godot 4.
if (_parameters.image.is_valid()) {
if (_parameters.image.is_valid())
{
_parameters.image->unlock();
}
_parameters.image = copy;
if (_parameters.image.is_valid()) {
if (copy->get_width() > 0)
grid_size = world_size / copy->get_width();
if (_parameters.image.is_valid())
{
_parameters.image->lock();
}
}
@@ -421,7 +727,28 @@ Ref<Curve> VoxelGeneratorImgMapper::get_curve4() const
return curve4;
}
void VoxelGeneratorImgMapper::_bind_methods() {
void VoxelGeneratorImgMapper::set_grid_size(int value)
{
grid_size = value;
}
int VoxelGeneratorImgMapper::get_grid_size() const
{
return grid_size;
}
void VoxelGeneratorImgMapper::set_world_size(int value)
{
world_size = value;
}
int VoxelGeneratorImgMapper::get_world_size() const
{
return world_size;
}
void VoxelGeneratorImgMapper::_bind_methods()
{
ClassDB::bind_method(D_METHOD("set_image_bg", "image"), &VoxelGeneratorImgMapper::set_image_bg);
ClassDB::bind_method(D_METHOD("get_image_bg"), &VoxelGeneratorImgMapper::get_image_bg);
@@ -450,6 +777,9 @@ void VoxelGeneratorImgMapper::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_blur_enabled", "enable"), &VoxelGeneratorImgMapper::set_blur_enabled);
ClassDB::bind_method(D_METHOD("is_blur_enabled"), &VoxelGeneratorImgMapper::is_blur_enabled);
ClassDB::bind_method(D_METHOD("set_world_size", "value"), &VoxelGeneratorImgMapper::set_world_size);
ClassDB::bind_method(D_METHOD("get_world_size"), &VoxelGeneratorImgMapper::get_world_size);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image_bg", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "set_image_bg", "get_image_bg");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image_overlay", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "set_image_overlay", "get_image_overlay");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image_draw", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "set_image_draw", "get_image_draw");

View File

@@ -1,12 +1,34 @@
#ifndef HEADER_VOXEL_GENERATOR_IMGMAPPER
#define HEADER_VOXEL_GENERATOR_IMGMAPPER
#include <map>
#include <modules/voxel/generators/simple/voxel_generator_heightmap.h>
#include <core/image.h>
#include <scene/resources/curve.h>
struct EditBrush
{
static std::map<int, struct EditBrush *> brushes;
int id;
Ref<Image> &draw_image;
virtual void draw(const Vector3 &v, float r, float s) = 0;
EditBrush(int id, Ref<Image> &im) : id(id), draw_image(im)
{
brushes[id] = this;
}
virtual ~EditBrush()
{
brushes.erase(id);
}
static void draw_brush(const Vector3 &v, float r, float s, int id)
{
if (brushes.find(id) != brushes.end())
brushes.at(id)->draw(v, r, s);
}
};
// Provides infinite tiling heightmap based on an image
class VoxelGeneratorImgMapper : public VoxelGeneratorHeightmap {
class VoxelGeneratorImgMapper : public VoxelGeneratorHeightmap
{
GDCLASS(VoxelGeneratorImgMapper, VoxelGeneratorHeightmap)
public:
@@ -33,7 +55,9 @@ public:
void set_height(const Vector3 &v, float height);
void draw_brush(const Vector3 &v, float r, float s, int id);
float get_height(const Vector3 &v);
float get_height_linear(const Vector3 &v);
float get_height_full(const Vector3 &v);
float get_height_full_linear(const Vector3 &v);
void compose();
void save_png();
@@ -49,6 +73,9 @@ public:
void set_curve4(const Ref<Curve> &curve);
Ref<Curve> get_curve4() const;
void set_world_size(int value);
int get_world_size() const;
private:
static void _bind_methods();
@@ -61,7 +88,8 @@ private:
Ref<Curve> curve1, curve2, curve3, curve4;
struct Parameters {
struct Parameters
{
int width, height;
// This is a read-only copy of the image.
// It wastes memory for sure, but Godot does not offer any way to secure this better.
@@ -73,6 +101,10 @@ private:
Parameters _parameters;
RWLock _parameters_lock;
int grid_size;
int world_size;
void set_grid_size(int value);
int get_grid_size() const;
};
#endif // HEADER_VOXEL_GENERATOR_IMGMAPPER

View File

@@ -6,6 +6,12 @@
#include <core/hash_map.h>
#include "building_layout_graph.h"
#include "region_tree.h"
#define SHRINK_RIGHT (1 << 0)
#define SHRINK_LEFT (1 << 1)
#define SHRINK_BACKWARD (1 << 2)
#define SHRINK_FORWARD (1 << 3)
static inline bool check_rtree_split(const struct region_tree *rt,
flecs::entity grid_floor_e,
const List<struct region> &regions)
@@ -572,11 +578,6 @@ void region_tree::shrink_rooms(flecs::entity grid_floor_e)
struct region backup = item->region;
List<struct region_tree *> neighbors;
#define SHRINK_RIGHT (1 << 0)
#define SHRINK_LEFT (1 << 1)
#define SHRINK_BACKWARD (1 << 2)
#define SHRINK_FORWARD (1 << 3)
int shrink_flags = 0;
if (item->neighbors_left.size() > 0)
shrink_flags |= SHRINK_LEFT;
@@ -627,12 +628,6 @@ void region_tree::shrink_rooms(flecs::entity grid_floor_e)
}
if (shrink_flags)
base_rtree->find_neighbors(grid_floor_e);
#if 0
if (shrink_flags == 0xf)
item->region.rect = item->region.rect.grow(-1);
if (!base_rtree->check(grid_floor_e))
item->region = backup;
#endif
}
assert(base_rtree->check(grid_floor_e));
// assert(accepted == 0 || shrunk > 0);
@@ -738,19 +733,6 @@ void region_tree::place(flecs::entity grid_floor_e) const
for (i = 0; i < (int)delete_cells.size(); i++)
delete_cells[i].destruct();
delete_cells.clear();
#if 0
for (i = region.rect.position.x;
i < region.rect.position.x + region.rect.size.x; i++)
for (j = region.rect.position.y;
j < region.rect.position.y + region.rect.size.y; j++) {
int cell_id = i + grid_size * j;
String cname = "cell_" + itos(cell_id);
flecs::entity cell_e =
grid_floor_e.lookup(cname.ascii().ptr());
if (cell_e.is_valid())
cell_e.destruct();
}
#endif
queue.push_back(this);
bool result = true;
while (!queue.empty()) {
@@ -819,11 +801,6 @@ void region_tree::place(flecs::entity grid_floor_e) const
cname.ascii().ptr());
if (cell_e.is_valid())
continue;
#if 0
update_cell(grid_floor_e,
grid_floor_e.parent().id(),
grid_floor_e.id(), id);
#endif
create_corridoor_cell(
grid_floor_e,
grid_floor_e.parent().id(), id);

View File

@@ -234,6 +234,11 @@ void StreamWorld::remove_building(const String &key)
update_items();
}
VoxelLodTerrain *StreamWorld::get_terrain()
{
return terrain;
}
void StreamWorld::run_command(const String &command,
const Vector<Variant> &args)
{

View File

@@ -53,6 +53,7 @@ private:
static void _bind_methods();
public:
VoxelLodTerrain *get_terrain();
void run_command(const String &command, const Vector<Variant> &args);
StreamWorld();
~StreamWorld();

View File

@@ -0,0 +1,152 @@
#include <core/ustring.h>
#include <core/math/vector2.h>
#include <core/math/vector3.h>
#include <scene/3d/camera.h>
#include "editor_event.h"
#include "world_editor.h"
#include "terrain_editor.h"
void TerrainEditor::exit()
{
if (active)
deactivate();
}
void TerrainEditor::update(float delta)
{
if (!active)
activate();
if (!cursor_enabled && get_camera_mode() == 3) {
cursor_enabled = true;
get_as_node<Spatial>(cursor_name)->show();
} else if (cursor_enabled && get_camera_mode() != 3) {
cursor_enabled = false;
get_as_node<Spatial>(cursor_name)->hide();
}
if (camera_moved) {
Camera *cam = editor->get_viewport()->get_camera();
assert(cam);
camera_moved = false;
Transform cam_xform = cam->get_global_transform();
float h = cam_xform.origin.y;
cam_xform.origin.z += Math::abs(h) * camera_motion.z * delta;
cam_xform.origin.x += Math::abs(h) * camera_motion.x * delta;
cam_xform.origin.y += camera_motion.y * delta;
camera_motion = Vector3();
cam->set_global_transform(cam_xform);
Array move_args;
move_args.push_back(cam_xform);
editor->emit_signal("editor_event", "editor_camera_moved",
move_args);
}
}
TerrainEditor::TerrainEditor(WorldEditor *editor)
: editor(editor)
, active(false)
, cursor_enabled(false)
, cursor_name("%terrain_cursor")
, camera_moved(false)
{
}
TerrainEditor::~TerrainEditor()
{
}
void TerrainEditor::activate()
{
EditorEvent::get_singleton()->event.add_listener(
this, &TerrainEditor::event_handler);
active = true;
}
void TerrainEditor::deactivate()
{
EditorEvent::get_singleton()->event.remove_listener(
this, &TerrainEditor::event_handler);
active = false;
}
void TerrainEditor::event_handler(const String &event,
const Vector<Variant> &args)
{
print_line("TerrainEditor::event: " + event);
if (event == "mouse_press" || event == "mouse_drag") {
if (cursor_enabled) {
/* Raycasting outside physics process */
Vector2 position = args[0];
Camera *cam = editor->get_viewport()->get_camera();
Vector3 start = cam->project_ray_origin(position);
Vector3 normal = cam->project_ray_normal(position);
Vector3 end = start + normal * cam->get_zfar();
PhysicsDirectSpaceState *space_state =
editor->get_world()->get_direct_space_state();
PhysicsDirectSpaceState::RayResult result;
Set<RID> exclude;
space_state->intersect_ray(start, end, result, exclude,
(1 << 15) | (1 << 0), true,
true);
Vector3 result_pre;
if (result.rid == RID())
goto end;
result_pre = result.position;
result_pre.x = Math::stepify(result_pre.x, 2.0f);
result_pre.z = Math::stepify(result_pre.z, 2.0f);
start = result_pre + Vector3(0.0f, 200.0f, 0.0f);
end = result_pre - Vector3(0.0f, 200.0f, 0.0f);
space_state->intersect_ray(start, end, result, exclude,
(1 << 15) | (1 << 0), true,
true);
if (result.rid != RID()) {
set_cursor_position(result.position);
set_ui_cursor_position(result.position);
}
end:;
}
}
}
Vector3 TerrainEditor::get_cursor_position()
{
Spatial *cursor = get_as_node<Spatial>(cursor_name);
return cursor->get_global_transform().origin;
}
void TerrainEditor::set_cursor_position(const Vector3 &cursor_position)
{
Spatial *cursor = get_as_node<Spatial>(cursor_name);
cursor->set_global_transform(Transform(Basis(), cursor_position));
Array pargs;
pargs.push_back(cursor_position);
editor->emit_signal("editor_event", "line_cursor_motion", pargs);
}
void TerrainEditor::set_ui_cursor_position(const Vector3 &cursor_position)
{
#if 0
LineEdit *cursor_x = get_as_node<LineEdit>("%cursor_x");
LineEdit *cursor_y = get_as_node<LineEdit>("%cursor_y");
LineEdit *cursor_z = get_as_node<LineEdit>("%cursor_z");
cursor_x->set_text(String::num(cursor_position.x));
cursor_y->set_text(String::num(cursor_position.y));
cursor_z->set_text(String::num(cursor_position.z));
#endif
}
int TerrainEditor::get_camera_mode() const
{
return editor->get_camera_mode();
}
Node *TerrainEditor::scene()
{
return editor->get_tree()->get_current_scene();
}
template <class T> T *TerrainEditor::get_as_node(const String &path)
{
Node *node = scene()->get_node(NodePath(path));
assert(node);
T *ret = Object::cast_to<T>(node);
assert(ret);
return ret;
}

View File

@@ -0,0 +1,30 @@
/* ~/godot-projects/streaming_world/src/modules/stream/ui/terrain_editor.h */
#ifndef TERRAIN_EDITOR_H_
#define TERRAIN_EDITOR_H_
class WorldEditor;
class TerrainEditor {
WorldEditor *editor;
bool active;
bool cursor_enabled;
String cursor_name;
bool camera_moved;
Vector3 camera_motion;
public:
void exit();
void update(float delta);
TerrainEditor(WorldEditor *editor);
virtual ~TerrainEditor();
protected:
void activate();
void deactivate();
void event_handler(const String &event, const Vector<Variant> &args);
Vector3 get_cursor_position();
void set_cursor_position(const Vector3 &cursor_position);
void set_ui_cursor_position(const Vector3 &cursor_position);
template <class T> T *get_as_node(const String &path);
int get_camera_mode() const;
Node *scene();
};
#endif // TERRAIN_EDITOR_H_

View File

@@ -93,6 +93,7 @@ void MainTabs::_notification(int which)
String title, command, header;
};
struct menu_data items[] = {
{ "Terrain", "select_terrain", "Terrain mode" },
{ "Buildings", "select_buildings", "Buildings mode" },
{ "Navigation", "select_navigation",
"Navigation mode" },
@@ -176,6 +177,15 @@ void MainTabs::_notification(int which)
add_child(tab);
switch (i) {
case 0: {
std::vector<Variant> args_data = {
items[i].header
};
ui_field::ui_field_builder(this, tab,
"l_p{v{}}",
args_data.data(),
args_data.size());
} break;
case 1: {
// VBoxContainer *v = memnew(VBoxContainer);
//panel->add_child(v);
//v->set_owner(this);
@@ -239,15 +249,6 @@ void MainTabs::_notification(int which)
args_data.size());
}
} break;
case 1: {
std::vector<Variant> args_data = {
items[i].header
};
ui_field::ui_field_builder(this, tab,
"l_p{v{}}",
args_data.data(),
args_data.size());
} break;
case 2: {
std::vector<Variant> args_data = {
items[i].header
@@ -258,6 +259,15 @@ void MainTabs::_notification(int which)
args_data.size());
} break;
case 3: {
std::vector<Variant> args_data = {
items[i].header
};
ui_field::ui_field_builder(this, tab,
"l_p{v{}}",
args_data.data(),
args_data.size());
} break;
case 4: {
std::vector<Variant> args_data = {
/* clang-format off */
"road_lines_base",
@@ -321,7 +331,7 @@ void MainTabs::_notification(int which)
// "p{v{lh#!{m#!m#!m#!m#!m#!}_lh{le#!}i.#!x#!_lv#!{h{e#!e#!e#!b#!}}_lv#!{h{e#!e#!e#!b#!}}}}",
args_data.data(), args_data.size());
} break;
case 4: {
case 5: {
std::vector<Variant> args_data = {
items[i].header
};
@@ -330,7 +340,7 @@ void MainTabs::_notification(int which)
args_data.data(),
args_data.size());
} break;
case 5: {
case 6: {
if (!Engine::get_singleton()->is_editor_hint()) {
assert(pv);
pv->setup_layout_tab(tab,

View File

@@ -11,11 +11,13 @@
#include <scene/main/viewport.h>
#include <scene/3d/camera.h>
#include <scene/scene_string_names.h>
#include <modules/voxel/terrain/voxel_lod_terrain.h>
#include "road_lines_editor.h"
#include "world_editor.h"
#include "editor_event.h"
#include "base_data.h"
#include "buildings_editor.h"
#include "terrain_editor.h"
#include "world_editor.h"
class HandleCommandButton : public Object {
GDCLASS(HandleCommandButton, Object)
@@ -76,6 +78,7 @@ WorldEditor::WorldEditor()
, drag_delay(0.2f)
, road_lines_editor(memnew(RoadLinesEditor(this)))
, buildings_editor(memnew(BuildingsEditor(this)))
, terrain_editor(memnew(TerrainEditor(this)))
{
flecs::entity e;
flecs::world ecs = BaseData::get_singleton()->get();
@@ -216,6 +219,11 @@ void WorldEditor::mode_npc()
disable_all();
print_line("NPC");
}
void WorldEditor::mode_terrain()
{
disable_all();
print_line("TERRAIN");
}
struct StringHasher {
std::size_t operator()(const String &s) const
{
@@ -227,14 +235,14 @@ static std::unordered_map<String, int, StringHasher> modes = {
{ "select_navigation", WorldEditor::MODE_NAVIGATION },
{ "select_poi", WorldEditor::MODE_POI },
{ "select_road_lines", WorldEditor::MODE_ROAD_LINES },
{ "select_npc", WorldEditor::MODE_NPC }
{ "select_npc", WorldEditor::MODE_NPC },
{ "select_terrain", WorldEditor::MODE_TERRAIN },
};
static std::unordered_map<int, String> vmode = { { 2, "%v_buildings" },
{ 3, "%v_navigation" },
{ 5, "%v_poi" },
{ 6, "%v_road_lines" },
{ 7, "%v_npc" } };
static std::unordered_map<int, String> vmode = {
{ 2, "%v_buildings" }, { 3, "%v_navigation" }, { 5, "%v_poi" },
{ 6, "%v_road_lines" }, { 7, "%v_npc" }, { 8, "%v_terrain" },
};
void WorldEditor::tools_button(const String &button)
{
@@ -257,6 +265,8 @@ void WorldEditor::tools_button(const String &button)
case MODE_BUILDINGS:
buildings_editor->exit();
break;
case MODE_TERRAIN:
terrain_editor->exit();
}
switch (modes[button]) {
case MODE_BUILDINGS:
@@ -274,6 +284,9 @@ void WorldEditor::tools_button(const String &button)
case MODE_NPC:
mode_npc();
break;
case MODE_TERRAIN:
mode_terrain();
break;
}
EditorEvent::get_singleton()->event.emit(
"mode_change_post", varray(current_mode, modes[button]));
@@ -404,6 +417,14 @@ void WorldEditor::event_signal_handler(const String &event,
emit_signal("editor_event", event, args);
}
Ref<VoxelGeneratorImgMapper> WorldEditor::get_heightmap()
{
StreamWorld *world = get_stream_world();
VoxelLodTerrain *terrain = world->get_terrain();
assert(terrain);
return terrain->get_generator();
}
StreamWorld *WorldEditor::get_stream_world()
{
return stream_world;
@@ -417,8 +438,9 @@ void WorldEditor::world_command_result(const String &what,
}
static std::vector<String> tool_buttons = {
"%select_buildings", "%select_navigation", "%select_poi",
"%select_road_lines", "%select_npc", "%buildings_save",
"%select_terrain", "%select_buildings", "%select_navigation",
"%select_poi", "%select_road_lines", "%select_npc",
"%buildings_save",
};
std::vector<HandleCommandButton *> tool_handlers;
void WorldEditor::_notification(int which)
@@ -469,6 +491,10 @@ void WorldEditor::_notification(int which)
get_node(NodePath("%line_cursor")));
assert(line_cursor);
line_cursor->hide();
Spatial *terrain_cursor = Object::cast_to<Spatial>(
get_node(NodePath("%terrain_cursor")));
assert(terrain_cursor);
terrain_cursor->hide();
set_process_unhandled_input(true);
set_physics_process(true);
@@ -529,6 +555,9 @@ void WorldEditor::_notification(int which)
case MODE_ROAD_LINES:
road_lines_editor->update(delta);
break;
case MODE_TERRAIN:
terrain_editor->update(delta);
break;
}
} break;
}

View File

@@ -4,10 +4,12 @@
#include <cassert>
#include <list>
#include <scene/3d/spatial.h>
#include <modules/imgmapper/voxel_generator_imgmapper.h>
#include "stream.h"
#include "base_data.h"
class RoadLinesEditor;
class BuildingsEditor;
class TerrainEditor;
class WorldEditor : public Spatial {
GDCLASS(WorldEditor, Spatial)
protected:
@@ -20,6 +22,7 @@ protected:
void mode_poi();
void mode_road_lines();
void mode_npc();
void mode_terrain();
void tools_button(const String &button);
StreamWorld *get_stream_world();
void world_command_result(const String &what,
@@ -38,6 +41,7 @@ private:
float drag_delay;
RoadLinesEditor *road_lines_editor;
BuildingsEditor *buildings_editor;
TerrainEditor *terrain_editor;
public:
enum {
@@ -46,6 +50,7 @@ public:
MODE_POI = 5,
MODE_ROAD_LINES = 6,
MODE_NPC = 7,
MODE_TERRAIN = 8,
};
WorldEditor();
virtual ~WorldEditor();
@@ -54,6 +59,7 @@ public:
int get_current_mode() const;
void event_signal_handler(const String &event,
const Vector<Variant> &args);
Ref<VoxelGeneratorImgMapper> get_heightmap();
struct components {
struct world_editor_node {
WorldEditor *node;