diff --git a/voxel_library.cpp b/voxel_library.cpp index 170f407..15710a6 100644 --- a/voxel_library.cpp +++ b/voxel_library.cpp @@ -27,9 +27,16 @@ Ref VoxelLibrary::create_voxel(int id, String name) { return voxel; } +Ref VoxelLibrary::_get_voxel_bind(int id) { + ERR_FAIL_COND_V(id < 0 || id >= MAX_VOXEL_TYPES, Ref()); + return _voxel_types[id]; +} + void VoxelLibrary::_bind_methods() { ObjectTypeDB::bind_method(_MD("create_voxel:Voxel", "id", "name"), &VoxelLibrary::create_voxel); + ObjectTypeDB::bind_method(_MD("get_voxel", "id"), &VoxelLibrary::_get_voxel_bind); + ObjectTypeDB::bind_method(_MD("set_atlas_size", "square_size"), &VoxelLibrary::set_atlas_size); } diff --git a/voxel_library.h b/voxel_library.h index 97831cc..8d4b04a 100644 --- a/voxel_library.h +++ b/voxel_library.h @@ -24,13 +24,15 @@ public: _FORCE_INLINE_ bool has_voxel(int id) const { return _voxel_types[id].is_valid(); } _FORCE_INLINE_ const Voxel & get_voxel_const(int id) const { return **_voxel_types[id]; } +protected: + static void _bind_methods(); + + Ref _get_voxel_bind(int id); + private: Ref _voxel_types[MAX_VOXEL_TYPES]; int _atlas_size; -protected: - static void _bind_methods(); - }; #endif // VOXEL_LIBRARY_H diff --git a/voxel_mesher.cpp b/voxel_mesher.cpp index 9309941..8d5c1f6 100644 --- a/voxel_mesher.cpp +++ b/voxel_mesher.cpp @@ -120,9 +120,10 @@ static const unsigned int g_edge_corners[EDGE_COUNT][2] = { }; -VoxelMesher::VoxelMesher(): _baked_occlusion_darkness(0.75), _bake_occlusion(true) { - -} +VoxelMesher::VoxelMesher(): + _baked_occlusion_darkness(0.75), + _bake_occlusion(true) +{} void VoxelMesher::set_library(Ref library) { ERR_FAIL_COND(library.is_null()); @@ -135,6 +136,11 @@ void VoxelMesher::set_material(Ref material, unsigned int id) { _surface_tool[id].set_material(material); } +Ref VoxelMesher::get_material(unsigned int id) const { + ERR_FAIL_COND_V(id >= MAX_MATERIALS, Ref()); + return _materials[id]; +} + void VoxelMesher::set_occlusion_darkness(float darkness) { _baked_occlusion_darkness = darkness; if (_baked_occlusion_darkness < 0.0) @@ -338,10 +344,18 @@ Ref VoxelMesher::build(const VoxelBuffer & buffer) { void VoxelMesher::_bind_methods() { - ObjectTypeDB::bind_method(_MD("set_material", "material", "id"), &VoxelMesher::set_material); + ObjectTypeDB::bind_method(_MD("set_material", "material", "id"), &VoxelMesher::set_material); + ObjectTypeDB::bind_method(_MD("get_material:Material", "id"), &VoxelMesher::get_material); + ObjectTypeDB::bind_method(_MD("set_library", "voxel_library"), &VoxelMesher::set_library); + ObjectTypeDB::bind_method(_MD("get_library:VoxelLibrary"), &VoxelMesher::get_library); + ObjectTypeDB::bind_method(_MD("set_occlusion_enabled", "enable"), &VoxelMesher::set_occlusion_enabled); + ObjectTypeDB::bind_method(_MD("get_occlusion_enabled"), &VoxelMesher::get_occlusion_enabled); + ObjectTypeDB::bind_method(_MD("set_occlusion_darkness", "value"), &VoxelMesher::set_occlusion_darkness); - ObjectTypeDB::bind_method(_MD("build", "voxel_buffer"), &VoxelMesher::build_ref); + ObjectTypeDB::bind_method(_MD("get_occlusion_darkness"), &VoxelMesher::get_occlusion_darkness); + + ObjectTypeDB::bind_method(_MD("build", "voxel_buffer"), &VoxelMesher::build_ref); } diff --git a/voxel_mesher.h b/voxel_mesher.h index 020456d..78f832c 100644 --- a/voxel_mesher.h +++ b/voxel_mesher.h @@ -9,11 +9,31 @@ #include "voxel_library.h" class VoxelMesher : public Reference { - OBJ_TYPE(VoxelMesher, Reference); + OBJ_TYPE(VoxelMesher, Reference) public: static const unsigned int MAX_MATERIALS = 8; // Arbitrary. Tweak if needed. + VoxelMesher(); + + void set_material(Ref material, unsigned int id); + Ref get_material(unsigned int id) const; + + void set_library(Ref library); + Ref get_library() const { return _library; } + + void set_occlusion_darkness(float darkness); + float get_occlusion_darkness() const { return _baked_occlusion_darkness; } + + void set_occlusion_enabled(bool enable); + bool get_occlusion_enabled() const { return _bake_occlusion; } + + Ref build(const VoxelBuffer & buffer_ref); + Ref build_ref(Ref buffer_ref); + +protected: + static void _bind_methods(); + private: Ref _library; Ref _materials[MAX_MATERIALS]; @@ -21,24 +41,6 @@ private: float _baked_occlusion_darkness; bool _bake_occlusion; -public: - VoxelMesher(); - - void set_material(Ref material, unsigned int id); - - void set_library(Ref library); - - void set_occlusion_darkness(float darkness); - - void set_occlusion_enabled(bool enable); - - Ref build(const VoxelBuffer & buffer_ref); - Ref build_ref(Ref buffer_ref); - -protected: - - static void _bind_methods(); - };