From 601a61619b37364dc7e37737e930c73fdc40df52 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 13 Feb 2020 14:16:57 +0100 Subject: [PATCH] Added mesher index property to both VoxelMesher, and VoxelSurface. --- library/voxel_surface.cpp | 12 ++++++++++++ library/voxel_surface.h | 4 ++++ meshers/voxel_mesher.cpp | 23 +++++++++++++++++++---- meshers/voxel_mesher.h | 15 ++++++++++----- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/library/voxel_surface.cpp b/library/voxel_surface.cpp index 8de03c1..26d5c15 100644 --- a/library/voxel_surface.cpp +++ b/library/voxel_surface.cpp @@ -29,6 +29,13 @@ void VoxelSurface::set_id(const int value) { _id = value; } +int VoxelSurface::get_mesher_index() const { + return _mesher_index; +} +void VoxelSurface::set_mesher_index(const int value) { + _mesher_index = value; +} + bool VoxelSurface::is_transparent() const { return _is_transparent; } @@ -93,6 +100,7 @@ void VoxelSurface::refresh_rects() { VoxelSurface::VoxelSurface() { _id = 0; + _mesher_index = 0; _is_transparent = false; _library = NULL; } @@ -106,6 +114,10 @@ void VoxelSurface::_bind_methods() { ClassDB::bind_method(D_METHOD("set_id", "value"), &VoxelSurface::set_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id"); + ClassDB::bind_method(D_METHOD("get_mesher_index"), &VoxelSurface::get_mesher_index); + ClassDB::bind_method(D_METHOD("set_mesher_index", "value"), &VoxelSurface::set_mesher_index); + ADD_PROPERTY(PropertyInfo(Variant::INT, "mesher_index"), "set_mesher_index", "get_mesher_index"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "voxel_name"), "set_name", "get_name"); ClassDB::bind_method(D_METHOD("set_transparent", "transparent"), &VoxelSurface::set_transparent); diff --git a/library/voxel_surface.h b/library/voxel_surface.h index 0ea8f37..3ab6b22 100644 --- a/library/voxel_surface.h +++ b/library/voxel_surface.h @@ -69,6 +69,9 @@ public: int get_id() const; void set_id(const int value); + int get_mesher_index() const; + void set_mesher_index(const int value); + bool is_transparent() const; void set_transparent(const bool transparent); @@ -95,6 +98,7 @@ protected: VoxelmanLibrary *_library; int _id; + int _mesher_index; bool _is_transparent; Rect2 _rects[VOXEL_SIDES_COUNT]; Ref _clutter; diff --git a/meshers/voxel_mesher.cpp b/meshers/voxel_mesher.cpp index c09e04a..29b1da0 100644 --- a/meshers/voxel_mesher.cpp +++ b/meshers/voxel_mesher.cpp @@ -24,10 +24,17 @@ SOFTWARE. #include "../world/voxel_chunk.h" +int VoxelMesher::get_mesher_index() const { + return _mesher_index; +} +void VoxelMesher::set_mesher_index(const int value) { + _mesher_index = value; +} + Ref VoxelMesher::get_library() { return _library; } -void VoxelMesher::set_library(Ref library) { +void VoxelMesher::set_library(const Ref &library) { _library = library; } @@ -687,7 +694,7 @@ PoolVector VoxelMesher::get_indices() { return _indices; } -void VoxelMesher::set_indices(const PoolVector values) { +void VoxelMesher::set_indices(const PoolVector &values) { _indices = values; } @@ -707,17 +714,21 @@ void VoxelMesher::remove_indices(int idx) { _indices.remove(idx); } -VoxelMesher::VoxelMesher(Ref library) { +VoxelMesher::VoxelMesher(const Ref &library) { _library = library; + _mesher_index = 0; _voxel_scale = 1; _lod_size = 1; + _ao_strength = 0.25; + _base_light_value = 0.5; + _uv_margin = Rect2(0, 0, 1, 1); _surface_tool.instance(); } VoxelMesher::VoxelMesher() { - + _mesher_index = 0; _voxel_scale = 1; _lod_size = 1; _ao_strength = 0.25; @@ -741,6 +752,10 @@ void VoxelMesher::_bind_methods() { 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_mesher_index"), &VoxelMesher::get_mesher_index); + ClassDB::bind_method(D_METHOD("set_mesher_index", "value"), &VoxelMesher::set_mesher_index); + ADD_PROPERTY(PropertyInfo(Variant::INT, "mesher_index"), "set_mesher_index", "get_mesher_index"); + ClassDB::bind_method(D_METHOD("get_library"), &VoxelMesher::get_library); ClassDB::bind_method(D_METHOD("set_library", "value"), &VoxelMesher::set_library); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary"), "set_library", "get_library"); diff --git a/meshers/voxel_mesher.h b/meshers/voxel_mesher.h index b6ed937..0c25661 100644 --- a/meshers/voxel_mesher.h +++ b/meshers/voxel_mesher.h @@ -52,17 +52,20 @@ class VoxelMesher : public Reference { GDCLASS(VoxelMesher, Reference); public: + int get_mesher_index() const; + void set_mesher_index(const int value); + Ref get_library(); - void set_library(Ref library); + void set_library(const Ref &library); Ref get_material(); void set_material(const Ref &material); float get_ao_strength() const; - void set_ao_strength(float value); + void set_ao_strength(const float value); float get_base_light_value() const; - void set_base_light_value(float value); + void set_base_light_value(const float value); float get_voxel_scale() const; void set_voxel_scale(const float voxel_scale); @@ -134,19 +137,21 @@ public: void add_uv2(Vector2 vector); PoolVector get_indices(); - void set_indices(const PoolVector values); + void set_indices(const PoolVector &values); int get_indices_count(); int get_indice(int idx); void remove_indices(int idx); void add_indices(int index); - VoxelMesher(Ref library); + VoxelMesher(const Ref &library); VoxelMesher(); ~VoxelMesher(); protected: static void _bind_methods(); + int _mesher_index; + PoolVector _vertices; PoolVector _normals; PoolVector _colors;