diff --git a/library/voxelman_library.cpp b/library/voxelman_library.cpp index 2dda85c..e292a48 100644 --- a/library/voxelman_library.cpp +++ b/library/voxelman_library.cpp @@ -26,6 +26,13 @@ SOFTWARE. #include "core/version.h" +bool VoxelmanLibrary::get_initialized() const { + return _initialized; +} +void VoxelmanLibrary::set_initialized(const bool value) { + _initialized = value; +} + //Materials Ref VoxelmanLibrary::get_material(const int index) { ERR_FAIL_INDEX_V(index, _materials.size(), Ref(NULL)); @@ -181,6 +188,7 @@ void VoxelmanLibrary::clear_props() { //Rects void VoxelmanLibrary::refresh_rects() { + _initialized = true; } void VoxelmanLibrary::setup_material_albedo(int material_index, Ref texture) { @@ -189,6 +197,7 @@ void VoxelmanLibrary::setup_material_albedo(int material_index, Ref tex } VoxelmanLibrary::VoxelmanLibrary() { + _initialized = false; } VoxelmanLibrary::~VoxelmanLibrary() { @@ -198,6 +207,10 @@ VoxelmanLibrary::~VoxelmanLibrary() { } void VoxelmanLibrary::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_initialized"), &VoxelmanLibrary::get_initialized); + ClassDB::bind_method(D_METHOD("set_initialized", "value"), &VoxelmanLibrary::set_initialized); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "initialized"), "set_initialized", "get_initialized"); + BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::INT, "material_index"), PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"))); ClassDB::bind_method(D_METHOD("get_material", "index"), &VoxelmanLibrary::get_material); diff --git a/library/voxelman_library.h b/library/voxelman_library.h index d9d3dbd..e63e4e1 100644 --- a/library/voxelman_library.h +++ b/library/voxelman_library.h @@ -43,6 +43,9 @@ public: }; public: + bool get_initialized() const; + void set_initialized(const bool value); + Ref get_material(const int index); void add_material(const Ref &value); void set_material(const int index, const Ref &value); @@ -95,6 +98,7 @@ protected: static void _bind_methods(); private: + bool _initialized; Vector > _materials; Vector > _liquid_materials; Vector > _clutter_materials; diff --git a/library/voxelman_library_merger.cpp b/library/voxelman_library_merger.cpp index 3f2be4d..b7fb2c1 100644 --- a/library/voxelman_library_merger.cpp +++ b/library/voxelman_library_merger.cpp @@ -333,6 +333,8 @@ void VoxelmanLibraryMerger::refresh_rects() { surface->refresh_rects(); } } + + set_initialized(true); } void VoxelmanLibraryMerger::_setup_material_albedo(const int material_index, const Ref &texture) { diff --git a/library/voxelman_library_simple.cpp b/library/voxelman_library_simple.cpp index 2c9d2c4..d307f54 100644 --- a/library/voxelman_library_simple.cpp +++ b/library/voxelman_library_simple.cpp @@ -113,6 +113,8 @@ void VoxelmanLibrarySimple::set_voxel_surfaces(const Vector &surfaces) _voxel_surfaces.push_back(surface); } + + set_initialized(true); } //Liquids diff --git a/world/voxel_world_editor.cpp b/world/voxel_world_editor.cpp index e4b17dd..a0a02ef 100644 --- a/world/voxel_world_editor.cpp +++ b/world/voxel_world_editor.cpp @@ -163,6 +163,9 @@ void VoxelWorldEditor::edit(VoxelWorld *p_world) { if (!library.is_valid()) return; + if (!library->get_initialized()) + library->refresh_rects(); + bool f = false; for (int i = 0; i < library->get_num_surfaces(); ++i) { Ref surface = library->get_voxel_surface(i);