diff --git a/meshers/blocky/voxel_blocky_library_base.cpp b/meshers/blocky/voxel_blocky_library_base.cpp index 31f513409..36283ef1c 100644 --- a/meshers/blocky/voxel_blocky_library_base.cpp +++ b/meshers/blocky/voxel_blocky_library_base.cpp @@ -45,6 +45,10 @@ Ref VoxelBlockyLibraryBase::get_material_by_index(unsigned int index) return _indexed_materials[index]; } +unsigned int VoxelBlockyLibraryBase::get_material_index_count() const { + return _indexed_materials.size(); +} + #ifdef TOOLS_ENABLED void VoxelBlockyLibraryBase::get_configuration_warnings(PackedStringArray &out_warnings) const { diff --git a/meshers/blocky/voxel_blocky_library_base.h b/meshers/blocky/voxel_blocky_library_base.h index 078717a89..ccdb3357d 100644 --- a/meshers/blocky/voxel_blocky_library_base.h +++ b/meshers/blocky/voxel_blocky_library_base.h @@ -82,6 +82,7 @@ class VoxelBlockyLibraryBase : public Resource { } Ref get_material_by_index(unsigned int index) const; + unsigned int get_material_index_count() const; #ifdef TOOLS_ENABLED virtual void get_configuration_warnings(PackedStringArray &out_warnings) const; diff --git a/meshers/blocky/voxel_mesher_blocky.cpp b/meshers/blocky/voxel_mesher_blocky.cpp index 3d2053fb0..7a7100e9d 100644 --- a/meshers/blocky/voxel_mesher_blocky.cpp +++ b/meshers/blocky/voxel_mesher_blocky.cpp @@ -881,6 +881,14 @@ Ref VoxelMesherBlocky::get_material_by_index(unsigned int index) const return lib->get_material_by_index(index); } +unsigned int VoxelMesherBlocky::get_material_index_count() const { + Ref lib = get_library(); + if (lib.is_null()) { + return 0; + } + return lib->get_material_index_count(); +} + #ifdef TOOLS_ENABLED void VoxelMesherBlocky::get_configuration_warnings(PackedStringArray &out_warnings) const { diff --git a/meshers/blocky/voxel_mesher_blocky.h b/meshers/blocky/voxel_mesher_blocky.h index acfdc58ef..ae6f06d08 100644 --- a/meshers/blocky/voxel_mesher_blocky.h +++ b/meshers/blocky/voxel_mesher_blocky.h @@ -47,6 +47,7 @@ class VoxelMesherBlocky : public VoxelMesher { } Ref get_material_by_index(unsigned int index) const override; + unsigned int get_material_index_count() const override; // Using std::vector because they make this mesher twice as fast than Godot Vectors. // See why: https://github.com/godotengine/godot/issues/24731 diff --git a/meshers/cubes/voxel_mesher_cubes.cpp b/meshers/cubes/voxel_mesher_cubes.cpp index 5911e9ea1..3fbe62096 100644 --- a/meshers/cubes/voxel_mesher_cubes.cpp +++ b/meshers/cubes/voxel_mesher_cubes.cpp @@ -1126,6 +1126,10 @@ Ref VoxelMesherCubes::get_material_by_index(unsigned int i) const { return _materials[i]; } +unsigned int VoxelMesherCubes::get_material_index_count() const { + return _materials.size(); +} + void VoxelMesherCubes::_b_set_opaque_material(Ref material) { set_material_by_index(MATERIAL_OPAQUE, material); } diff --git a/meshers/cubes/voxel_mesher_cubes.h b/meshers/cubes/voxel_mesher_cubes.h index bcf9a4d70..e7705f03b 100644 --- a/meshers/cubes/voxel_mesher_cubes.h +++ b/meshers/cubes/voxel_mesher_cubes.h @@ -70,6 +70,7 @@ class VoxelMesherCubes : public VoxelMesher { void set_material_by_index(Materials id, Ref material); Ref get_material_by_index(unsigned int i) const override; + unsigned int get_material_index_count() const override; static Ref generate_mesh_from_image(Ref image, float voxel_size); diff --git a/meshers/voxel_mesher.cpp b/meshers/voxel_mesher.cpp index 3d8d154f0..61ed4616b 100644 --- a/meshers/voxel_mesher.cpp +++ b/meshers/voxel_mesher.cpp @@ -152,6 +152,11 @@ Ref VoxelMesher::get_material_by_index(unsigned int i) const { return Ref(); } +unsigned int VoxelMesher::get_material_index_count() const { + // May be implemented in some meshers + return 0; +} + bool VoxelMesher::is_mesh_empty(const StdVector &surfaces) { if (surfaces.size() == 0) { return true; diff --git a/meshers/voxel_mesher.h b/meshers/voxel_mesher.h index 2d516713f..c87e8356c 100644 --- a/meshers/voxel_mesher.h +++ b/meshers/voxel_mesher.h @@ -106,6 +106,8 @@ class VoxelMesher : public Resource { // index does not have a material assigned. If not provided here, a default material may be used. // An error can be produced if the index is out of bounds. virtual Ref get_material_by_index(unsigned int i) const; + // Get the highest+1 material index + virtual unsigned int get_material_index_count() const; #ifdef TOOLS_ENABLED // If the mesher has problems, messages may be returned by this method so they can be shown to the user.