The library now has an initialized bool. Also the world editor will refresh rects in the library if needed.

This commit is contained in:
Relintai 2020-04-17 19:21:46 +02:00
parent c382dac3ff
commit bee499d951
5 changed files with 24 additions and 0 deletions

View File

@ -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<Material> VoxelmanLibrary::get_material(const int index) {
ERR_FAIL_INDEX_V(index, _materials.size(), Ref<VoxelSurface>(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> texture) {
@ -189,6 +197,7 @@ void VoxelmanLibrary::setup_material_albedo(int material_index, Ref<Texture> 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);

View File

@ -43,6 +43,9 @@ public:
};
public:
bool get_initialized() const;
void set_initialized(const bool value);
Ref<Material> get_material(const int index);
void add_material(const Ref<Material> &value);
void set_material(const int index, const Ref<Material> &value);
@ -95,6 +98,7 @@ protected:
static void _bind_methods();
private:
bool _initialized;
Vector<Ref<Material> > _materials;
Vector<Ref<Material> > _liquid_materials;
Vector<Ref<Material> > _clutter_materials;

View File

@ -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> &texture) {

View File

@ -113,6 +113,8 @@ void VoxelmanLibrarySimple::set_voxel_surfaces(const Vector<Variant> &surfaces)
_voxel_surfaces.push_back(surface);
}
set_initialized(true);
}
//Liquids

View File

@ -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<VoxelSurface> surface = library->get_voxel_surface(i);