From f00933bb7135aff41dc6d6b6d6eb398a08538084 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 18 Nov 2019 20:03:40 +0100 Subject: [PATCH] More work on fixing the build. --- data/voxel_light.cpp | 16 +-- data/voxel_light.h | 14 ++- meshers/cubic_mesher/voxel_cube_points.cpp | 10 +- meshers/cubic_mesher/voxel_cube_points.h | 8 +- meshers/cubic_mesher/voxel_mesher_cubic.cpp | 2 +- meshers/cubic_mesher/voxel_mesher_cubic.h | 2 +- meshers/voxel_mesher.cpp | 104 +++++++++++++------- meshers/voxel_mesher.h | 22 +++-- world/voxel_world.h | 2 - 9 files changed, 107 insertions(+), 73 deletions(-) diff --git a/data/voxel_light.cpp b/data/voxel_light.cpp index 5cfe4e2..836f770 100644 --- a/data/voxel_light.cpp +++ b/data/voxel_light.cpp @@ -1,22 +1,22 @@ #include "voxel_light.h" int VoxelLight::get_world_position_x() const { - return _world_position.x; + return _world_position_x; } int VoxelLight::get_world_position_y() const { - return _world_position.y; + return _world_position_y; } int VoxelLight::get_world_position_z() const { - return _world_position.z; + return _world_position_z; } -Vector3i VoxelLight::get_world_position() { - return _world_position; +Vector3 VoxelLight::get_world_position() { + return Vector3(_world_position_x, _world_position_y, _world_position_z); } void VoxelLight::set_world_position(const int x, const int y, const int z) { - _world_position.x = x; - _world_position.y = y; - _world_position.z = z; + _world_position_x = x; + _world_position_y = y; + _world_position_z = z; } Color VoxelLight::get_color() const { diff --git a/data/voxel_light.h b/data/voxel_light.h index c4670d1..97599f7 100644 --- a/data/voxel_light.h +++ b/data/voxel_light.h @@ -5,8 +5,6 @@ #include "core/reference.h" #include "core/vector.h" -#include "../math/vector3i.h" - class VoxelLight : public Reference { GDCLASS(VoxelLight, Reference); @@ -14,7 +12,7 @@ public: int get_world_position_x() const; int get_world_position_y() const; int get_world_position_z() const; - Vector3i get_world_position(); + Vector3 get_world_position(); void set_world_position(const int x, const int y, const int z); Color get_color() const; @@ -30,8 +28,14 @@ private: static void _bind_methods(); private: - Vector3i _chunk_position; - Vector3i _world_position; + int _chunk_position_x; + int _chunk_position_y; + int _chunk_position_z; + + int _world_position_x; + int _world_position_y; + int _world_position_z; + Color _color; int _size; }; diff --git a/meshers/cubic_mesher/voxel_cube_points.cpp b/meshers/cubic_mesher/voxel_cube_points.cpp index b167551..9b6025e 100644 --- a/meshers/cubic_mesher/voxel_cube_points.cpp +++ b/meshers/cubic_mesher/voxel_cube_points.cpp @@ -168,7 +168,7 @@ void VoxelCubePoints::recalculate_point(int point) { _points[point] = dynamic_offset; } -void VoxelCubePoints::refresh_neighbours(const Ref buffer) { +void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) { int neighbours = 0; int x = _x; @@ -405,7 +405,7 @@ void VoxelCubePoints::refresh_neighbours(const Ref buffer) { _point_neighbours[P111] = neighbours; } -void VoxelCubePoints::setup(const Ref buffer, int x, int y, int z, int size) { +void VoxelCubePoints::setup(const VoxelChunk *buffer, int x, int y, int z, int size) { ERR_FAIL_COND(size <= 0); ERR_FAIL_COND(!buffer->validate_pos(x + size, y + size, z + size) || !buffer->validate_pos(x, y, z)); @@ -509,7 +509,7 @@ bool VoxelCubePoints::is_face_visible(int face) { } -bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3i point) { +bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3 point) { for (int i = 0; i < POINT_COUNT; i += 1) { if (get_point(i) == (point)) { return true; @@ -520,7 +520,7 @@ bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3i point) { bool VoxelCubePoints::is_sub_voxel_point(int x, int y, int z) { for (int i = 0; i < POINT_COUNT; i += 1) { - if (get_point(i) == Vector3i(x, y, z)) { + if (get_point(i) == Vector3(x, y, z)) { return true; } } @@ -531,7 +531,7 @@ void VoxelCubePoints::set_point(int point, int x, int y, int z) { _points[point] = Vector3(x, y, z); } -int VoxelCubePoints::get_point_id_vec(Vector3i point) { +int VoxelCubePoints::get_point_id_vec(Vector3 point) { for (int i = 0; i < POINT_COUNT; ++i) { if (get_point(i) == point) { return i; diff --git a/meshers/cubic_mesher/voxel_cube_points.h b/meshers/cubic_mesher/voxel_cube_points.h index b276ff5..71c7303 100644 --- a/meshers/cubic_mesher/voxel_cube_points.h +++ b/meshers/cubic_mesher/voxel_cube_points.h @@ -1,8 +1,6 @@ #ifndef SUB_VOXEL_POINTS_H #define SUB_VOXEL_POINTS_H -#include "../../math/vector3i.h" -#include "../../world/voxel_buffer.h" #include "core/reference.h" #include "core/vector.h" @@ -91,8 +89,8 @@ public: void refresh_points(); void recalculate_point(int point); - void refresh_neighbours(const Ref buffer); - void setup(const Ref buffer, int x, int y, int z, int size = 1); + void refresh_neighbours(const VoxelChunk *buffer); + void setup(const VoxelChunk *buffer, int x, int y, int z, int size = 1); void reset(); @@ -101,10 +99,8 @@ public: Vector3 get_points_for_face(int face, int index); bool is_face_visible(int face); - bool is_sub_voxel_point_vec(Vector3i point); bool is_sub_voxel_point(int x, int y, int z); void set_point(int point, int x, int y, int z); - int get_point_id_vec(Vector3i point); int get_point_id(int x, int y, int z); Vector3 get_point_for_face(int face, int pointIndex); diff --git a/meshers/cubic_mesher/voxel_mesher_cubic.cpp b/meshers/cubic_mesher/voxel_mesher_cubic.cpp index e6bb1bd..80e9162 100644 --- a/meshers/cubic_mesher/voxel_mesher_cubic.cpp +++ b/meshers/cubic_mesher/voxel_mesher_cubic.cpp @@ -1,7 +1,7 @@ #include "voxel_mesher_cubic.h" -void VoxelMesherCubic::_add_buffer(Ref buffer) { +void VoxelMesherCubic::_add_buffer(VoxelChunk *buffer) { buffer->generate_ao(); Vector3i bfs = buffer->get_size(); diff --git a/meshers/cubic_mesher/voxel_mesher_cubic.h b/meshers/cubic_mesher/voxel_mesher_cubic.h index b14afd4..f8a2543 100644 --- a/meshers/cubic_mesher/voxel_mesher_cubic.h +++ b/meshers/cubic_mesher/voxel_mesher_cubic.h @@ -13,7 +13,7 @@ class VoxelMesherCubic : public VoxelMesher { GDCLASS(VoxelMesherCubic, VoxelMesher); public: - void _add_buffer(Ref buffer); + void _add_buffer(VoxelChunk *buffer); VoxelMesherCubic(); ~VoxelMesherCubic(); diff --git a/meshers/voxel_mesher.cpp b/meshers/voxel_mesher.cpp index 38eb37e..696e827 100644 --- a/meshers/voxel_mesher.cpp +++ b/meshers/voxel_mesher.cpp @@ -1,5 +1,7 @@ #include "voxel_mesher.h" +#include "../world/voxel_chunk.h" + Ref VoxelMesher::get_library() { return _library; } @@ -113,16 +115,30 @@ void VoxelMesher::reset() { _surface_tool->clear(); } -void VoxelMesher::add_buffer(Ref voxels) { - ERR_FAIL_COND(!has_method("_add_buffer")); +void VoxelMesher::add_chunk_bind(Node *chunk) { + VoxelChunk *vchunk = Object::cast_to(chunk); - call("_add_buffer", voxels); + ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk)); + + add_chunk(vchunk); +} +void VoxelMesher::add_chunk(VoxelChunk *chunk) { + ERR_FAIL_COND(!has_method("_add_chunk")); + + call("_add_chunk", chunk); } -void VoxelMesher::add_buffer_liquid(Ref voxels) { - ERR_FAIL_COND(!has_method("_add_buffer_liquid")); +void VoxelMesher::add_chunk_liquid_bind(Node *chunk) { + VoxelChunk *vchunk = Object::cast_to(chunk); - call("_add_buffer_liquid", voxels); + ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk)); + + add_chunk_liquid(vchunk); +} +void VoxelMesher::add_chunk_liquid(VoxelChunk *chunk) { + ERR_FAIL_COND(!has_method("_add_chunk_liquid")); + + call("_add_chunk_liquid", chunk); } void VoxelMesher::add_mesh_data_resource(Ref mesh, const Vector3 position, const Vector3 rotation, const Vector3 scale, const Rect2 uv_rect) { @@ -254,11 +270,18 @@ void VoxelMesher::add_mesh_data_resource_transform(Ref mesh, c } } -void VoxelMesher::bake_colors(Ref voxels) { - if (has_method("_bake_colors")) - call("_bake_colors", voxels); +void VoxelMesher::bake_colors_bind(Node *chunk) { + VoxelChunk *vchunk = Object::cast_to(chunk); + + ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk)); + + bake_colors(vchunk); } -void VoxelMesher::_bake_colors(Ref buffer) { +void VoxelMesher::bake_colors(VoxelChunk *chunk) { + if (has_method("_bake_colors")) + call("_bake_colors", chunk); +} +void VoxelMesher::_bake_colors(VoxelChunk *chunk) { Color base_light(_base_light_value, _base_light_value, _base_light_value); ERR_FAIL_COND(_vertices.size() != _normals.size()); @@ -278,14 +301,14 @@ void VoxelMesher::_bake_colors(Ref buffer) { unsigned int y = (unsigned int)(vert.y / _voxel_scale); unsigned int z = (unsigned int)(vert.z / _voxel_scale); - if (buffer->validate_pos(x, y, z)) { + if (chunk->validate_pos(x, y, z)) { Color light = Color( - buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_R) / 255.0, - buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_G) / 255.0, - buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_B) / 255.0); + chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_G) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0); - float ao = (buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_AO) / 255.0) * _ao_strength; - float rao = buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_RANDOM_AO) / 255.0; + float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength; + float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0; ao += rao; light.r += _base_light_value; @@ -313,11 +336,18 @@ void VoxelMesher::_bake_colors(Ref buffer) { } } -void VoxelMesher::bake_liquid_colors(Ref voxels) { - if (has_method("_bake_liquid_colors")) - call("_bake_liquid_colors", voxels); +void VoxelMesher::bake_liquid_colors_bind(Node *chunk) { + VoxelChunk *vchunk = Object::cast_to(chunk); + + ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk)); + + bake_liquid_colors(vchunk); } -void VoxelMesher::_bake_liquid_colors(Ref buffer) { +void VoxelMesher::bake_liquid_colors(VoxelChunk *chunk) { + if (has_method("_bake_liquid_colors")) + call("_bake_liquid_colors", chunk); +} +void VoxelMesher::_bake_liquid_colors(VoxelChunk *chunk) { Color base_light(_base_light_value, _base_light_value, _base_light_value); ERR_FAIL_COND(_vertices.size() != _normals.size()); @@ -337,14 +367,14 @@ void VoxelMesher::_bake_liquid_colors(Ref buffer) { unsigned int y = (unsigned int)(vert.y / _voxel_scale); unsigned int z = (unsigned int)(vert.z / _voxel_scale); - if (buffer->validate_pos(x, y, z)) { + if (chunk->validate_pos(x, y, z)) { Color light = Color( - buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_R) / 255.0, - buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_G) / 255.0, - buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_B) / 255.0); + chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_G) / 255.0, + chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0); - float ao = (buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_AO) / 255.0) * _ao_strength; - float rao = buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_RANDOM_AO) / 255.0; + float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength; + float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0; ao += rao; light.r += _base_light_value; @@ -427,7 +457,7 @@ void VoxelMesher::bake_lights(MeshInstance *node, Vector > &ligh for (int i = 0; i < lights.size(); ++i) { Ref light = lights.get(i); - Vector3 lightDir = light->get_world_position().to_vec3() - vertex; + Vector3 lightDir = light->get_world_position() - vertex; float dist2 = lightDir.dot(lightDir); //inverse sqrt @@ -630,10 +660,10 @@ VoxelMesher::~VoxelMesher() { } void VoxelMesher::_bind_methods() { - BIND_VMETHOD(MethodInfo("_add_buffer", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer"))); - BIND_VMETHOD(MethodInfo("_add_buffer_liquid", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer"))); - BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer"))); - BIND_VMETHOD(MethodInfo("_bake_liquid_colors", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer"))); + BIND_VMETHOD(MethodInfo("_add_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"))); + BIND_VMETHOD(MethodInfo("_add_chunk_liquid", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"))); + BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"))); + BIND_VMETHOD(MethodInfo("_bake_liquid_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"))); ClassDB::bind_method(D_METHOD("get_library"), &VoxelMesher::get_library); ClassDB::bind_method(D_METHOD("set_library", "value"), &VoxelMesher::set_library); @@ -663,15 +693,17 @@ void VoxelMesher::_bind_methods() { ClassDB::bind_method(D_METHOD("set_uv_margin", "value"), &VoxelMesher::set_uv_margin); ADD_PROPERTY(PropertyInfo(Variant::RECT2, "uv_margin"), "set_uv_margin", "get_uv_margin"); - ClassDB::bind_method(D_METHOD("add_buffer", "buffer"), &VoxelMesher::add_buffer); + ClassDB::bind_method(D_METHOD("add_chunk", "chunk"), &VoxelMesher::add_chunk_bind); + ClassDB::bind_method(D_METHOD("add_chunk_liquid", "chunk"), &VoxelMesher::add_chunk_liquid_bind); + ClassDB::bind_method(D_METHOD("add_mesh_data_resource", "mesh", "position", "rotation", "scale", "uv_rect"), &VoxelMesher::add_mesh_data_resource, DEFVAL(Rect2(0, 0, 1, 1)), DEFVAL(Vector3(1.0, 1.0, 1.0)), DEFVAL(Vector3()), DEFVAL(Vector3())); ClassDB::bind_method(D_METHOD("add_mesh_data_resource_transform", "mesh", "transform", "uv_rect"), &VoxelMesher::add_mesh_data_resource_transform, DEFVAL(Rect2(0, 0, 1, 1))); - ClassDB::bind_method(D_METHOD("bake_colors", "buffer"), &VoxelMesher::bake_colors); - ClassDB::bind_method(D_METHOD("_bake_colors", "buffer"), &VoxelMesher::_bake_colors); + ClassDB::bind_method(D_METHOD("bake_colors", "chunk"), &VoxelMesher::bake_colors_bind); + ClassDB::bind_method(D_METHOD("_bake_colors", "chunk"), &VoxelMesher::_bake_colors); - ClassDB::bind_method(D_METHOD("bake_liquid_colors", "buffer"), &VoxelMesher::bake_liquid_colors); - ClassDB::bind_method(D_METHOD("_bake_liquid_colors", "buffer"), &VoxelMesher::_bake_liquid_colors); + ClassDB::bind_method(D_METHOD("bake_liquid_colors", "chunk"), &VoxelMesher::bake_liquid_colors_bind); + ClassDB::bind_method(D_METHOD("_bake_liquid_colors", "chunk"), &VoxelMesher::_bake_liquid_colors); ClassDB::bind_method(D_METHOD("get_vertex_count"), &VoxelMesher::get_vertex_count); ClassDB::bind_method(D_METHOD("get_vertex", "idx"), &VoxelMesher::get_vertex); diff --git a/meshers/voxel_mesher.h b/meshers/voxel_mesher.h index 3b747f3..c3dbd90 100644 --- a/meshers/voxel_mesher.h +++ b/meshers/voxel_mesher.h @@ -17,15 +17,13 @@ #include "scene/resources/concave_polygon_shape.h" #include "../library/voxelman_library.h" -#include "../math/vector3i.h" -#include "../world/voxel_buffer.h" #include "../../entity_spell_system/meshes/mesh_data_resource.h" const double PI_2 = 3.141592653589793238463 / 2; const double PI = 3.141592653589793238463; class VoxelmanLibrary; -class Voxel; +class VoxelChunk; class VoxelMesher : public Reference { GDCLASS(VoxelMesher, Reference); @@ -54,16 +52,22 @@ public: void reset(); - void add_buffer(Ref voxels); - void add_buffer_liquid(Ref voxels); + void add_chunk_bind(Node *chunk); + void add_chunk(VoxelChunk *chunk); + + void add_chunk_liquid_bind(Node *chunk); + void add_chunk_liquid(VoxelChunk *chunk); + void add_mesh_data_resource(Ref mesh, const Vector3 position = Vector3(0, 0, 0), const Vector3 rotation = Vector3(0, 0, 0), const Vector3 scale = Vector3(1.0, 1.0, 1.0), const Rect2 uv_rect = Rect2(0, 0, 1, 1)); void add_mesh_data_resource_transform(Ref mesh, const Transform transform, const Rect2 uv_rect = Rect2(0, 0, 1, 1)); - void bake_colors(Ref voxels); - void _bake_colors(Ref buffer); + void bake_colors_bind(Node *chunk); + void bake_colors(VoxelChunk *chunk); + void _bake_colors(VoxelChunk *chunk); - void bake_liquid_colors(Ref voxels); - void _bake_liquid_colors(Ref buffer); + void bake_liquid_colors_bind(Node *chunk); + void bake_liquid_colors(VoxelChunk *chunk); + void _bake_liquid_colors(VoxelChunk *chunk); void build_collider(RID shape) const; diff --git a/world/voxel_world.h b/world/voxel_world.h index 3ba5325..d607187 100644 --- a/world/voxel_world.h +++ b/world/voxel_world.h @@ -4,10 +4,8 @@ #include "scene/3d/navigation.h" #include "core/hash_map.h" -#include "../math/vector3i.h" #include "../library/voxelman_library.h" #include "../level_generator/voxelman_level_generator.h" -#include "voxel_buffer.h" #include "../areas/world_area.h" class VoxelChunk;