Added getters

This commit is contained in:
Marc Gilleron 2017-01-01 05:23:22 +01:00
parent 8d1c8cc339
commit 670f46b470
4 changed files with 52 additions and 27 deletions

View File

@ -27,9 +27,16 @@ Ref<Voxel> VoxelLibrary::create_voxel(int id, String name) {
return voxel;
}
Ref<Voxel> VoxelLibrary::_get_voxel_bind(int id) {
ERR_FAIL_COND_V(id < 0 || id >= MAX_VOXEL_TYPES, Ref<Voxel>());
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);
}

View File

@ -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<Voxel> _get_voxel_bind(int id);
private:
Ref<Voxel> _voxel_types[MAX_VOXEL_TYPES];
int _atlas_size;
protected:
static void _bind_methods();
};
#endif // VOXEL_LIBRARY_H

View File

@ -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<VoxelLibrary> library) {
ERR_FAIL_COND(library.is_null());
@ -135,6 +136,11 @@ void VoxelMesher::set_material(Ref<Material> material, unsigned int id) {
_surface_tool[id].set_material(material);
}
Ref<Material> VoxelMesher::get_material(unsigned int id) const {
ERR_FAIL_COND_V(id >= MAX_MATERIALS, Ref<Material>());
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<Mesh> 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);
}

View File

@ -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> material, unsigned int id);
Ref<Material> get_material(unsigned int id) const;
void set_library(Ref<VoxelLibrary> library);
Ref<VoxelLibrary> 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<Mesh> build(const VoxelBuffer & buffer_ref);
Ref<Mesh> build_ref(Ref<VoxelBuffer> buffer_ref);
protected:
static void _bind_methods();
private:
Ref<VoxelLibrary> _library;
Ref<Material> _materials[MAX_MATERIALS];
@ -21,24 +41,6 @@ private:
float _baked_occlusion_darkness;
bool _bake_occlusion;
public:
VoxelMesher();
void set_material(Ref<Material> material, unsigned int id);
void set_library(Ref<VoxelLibrary> library);
void set_occlusion_darkness(float darkness);
void set_occlusion_enabled(bool enable);
Ref<Mesh> build(const VoxelBuffer & buffer_ref);
Ref<Mesh> build_ref(Ref<VoxelBuffer> buffer_ref);
protected:
static void _bind_methods();
};