Remove create_mesher and _create_mesher from chunks. Mesher creating now should be handled by the world itself in _create_chunk. This makes worlds able to use different chunk mesher setups for different parts of a world. Also this cust down the amount of classes that you need to create if you are implementing a new mesher.

This commit is contained in:
Relintai 2020-10-06 19:43:49 +02:00
parent 3add3daef4
commit 0e4e59e970
15 changed files with 96 additions and 118 deletions

View File

@ -22,15 +22,8 @@ SOFTWARE.
#include "voxel_chunk_blocky.h"
#include "../../meshers/blocky/voxel_mesher_blocky.h"
#include "../../meshers/blocky/voxel_mesher_liquid_blocky.h"
#include "../../defines.h"
#include "../jobs/voxel_light_job.h"
#include "../jobs/voxel_prop_job.h"
#include "../jobs/voxel_terrarin_job.h"
VoxelChunkBlocky::VoxelChunkBlocky() {
}
@ -41,25 +34,6 @@ void VoxelChunkBlocky::_setup_channels() {
set_channel_count(MAX_DEFAULT_CHANNELS);
}
void VoxelChunkBlocky::_create_meshers() {
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherBlocky)));
tj->add_mesher(Ref<VoxelMesher>(memnew(VoxelMesherBlocky())));
tj->add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquidBlocky())));
add_job(lj);
add_job(tj);
add_job(pj);
}
void VoxelChunkBlocky::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_channel"), "set_channel_compressed", "get_channel_compressed", 0);

View File

@ -34,7 +34,6 @@ public:
protected:
virtual void _setup_channels();
virtual void _create_meshers();
static void _bind_methods();
};

View File

@ -24,10 +24,33 @@ SOFTWARE.
#include "voxel_chunk_blocky.h"
#include "../../meshers/blocky/voxel_mesher_blocky.h"
#include "../../meshers/blocky/voxel_mesher_liquid_blocky.h"
#include "../jobs/voxel_light_job.h"
#include "../jobs/voxel_prop_job.h"
#include "../jobs/voxel_terrarin_job.h"
Ref<VoxelChunk> VoxelWorldBlocky::_create_chunk(int x, int y, int z, Ref<VoxelChunk> chunk) {
if (!chunk.is_valid()) {
chunk = Ref<VoxelChunk>(memnew(VoxelChunkBlocky));
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherBlocky)));
tj->add_mesher(Ref<VoxelMesher>(memnew(VoxelMesherBlocky())));
tj->add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquidBlocky())));
chunk->add_job(lj);
chunk->add_job(tj);
chunk->add_job(pj);
}
return VoxelWorld::_create_chunk(x, y, z, chunk);

View File

@ -22,14 +22,8 @@ SOFTWARE.
#include "voxel_chunk_cubic.h"
#include "../../meshers/cubic/voxel_mesher_cubic.h"
#include "../../defines.h"
#include "../jobs/voxel_light_job.h"
#include "../jobs/voxel_prop_job.h"
#include "../jobs/voxel_terrarin_job.h"
VoxelChunkCubic::VoxelChunkCubic() {
}
@ -40,29 +34,6 @@ void VoxelChunkCubic::_setup_channels() {
set_channel_count(MAX_DEFAULT_CHANNELS);
}
void VoxelChunkCubic::_create_meshers() {
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherCubic)));
Ref<VoxelMesher> m = Ref<VoxelMesher>(memnew(VoxelMesherCubic()));
m->set_channel_index_type(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
m->set_channel_index_isolevel(VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
tj->add_mesher(m);
//add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquidMarchingCubes())));
add_job(lj);
add_job(tj);
add_job(pj);
}
void VoxelChunkCubic::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_channel"), "set_channel_compressed", "get_channel_compressed", 0);
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "isolevel_channel"), "set_channel_compressed", "get_channel_compressed", 1);

View File

@ -34,7 +34,6 @@ public:
protected:
virtual void _setup_channels();
virtual void _create_meshers();
static void _bind_methods();
};

View File

@ -24,10 +24,36 @@ SOFTWARE.
#include "voxel_chunk_cubic.h"
#include "../../meshers/cubic/voxel_mesher_cubic.h"
#include "../jobs/voxel_light_job.h"
#include "../jobs/voxel_prop_job.h"
#include "../jobs/voxel_terrarin_job.h"
Ref<VoxelChunk> VoxelWorldCubic::_create_chunk(int x, int y, int z, Ref<VoxelChunk> chunk) {
if (!chunk.is_valid()) {
chunk = Ref<VoxelChunk>(memnew(VoxelChunkCubic));
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherCubic)));
Ref<VoxelMesher> m = Ref<VoxelMesher>(memnew(VoxelMesherCubic()));
m->set_channel_index_type(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
m->set_channel_index_isolevel(VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
tj->add_mesher(m);
//add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquidMarchingCubes())));
chunk->add_job(lj);
chunk->add_job(tj);
chunk->add_job(pj);
}
return VoxelWorld::_create_chunk(x, y, z, chunk);

View File

@ -870,22 +870,6 @@ void VoxelChunkDefault::_setup_channels() {
set_channel_count(MAX_DEFAULT_CHANNELS);
}
void VoxelChunkDefault::_create_meshers() {
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherDefault)));
add_job(lj);
add_job(tj);
add_job(pj);
}
void VoxelChunkDefault::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_build_flags"), &VoxelChunkDefault::get_build_flags);
ClassDB::bind_method(D_METHOD("set_build_flags", "value"), &VoxelChunkDefault::set_build_flags);
@ -957,7 +941,6 @@ void VoxelChunkDefault::_bind_methods() {
//virtuals
ClassDB::bind_method(D_METHOD("_setup_channels"), &VoxelChunkDefault::_setup_channels);
ClassDB::bind_method(D_METHOD("_create_meshers"), &VoxelChunkDefault::_create_meshers);
ClassDB::bind_method(D_METHOD("_visibility_changed", "visible"), &VoxelChunkDefault::_visibility_changed);
//lights

View File

@ -182,7 +182,6 @@ public:
protected:
virtual void _setup_channels();
virtual void _create_meshers();
virtual void _visibility_changed(bool visible);
virtual void _exit_tree();

View File

@ -26,6 +26,11 @@ SOFTWARE.
#include "../../defines.h"
#include "../../meshers/default/voxel_mesher_default.h"
#include "../jobs/voxel_light_job.h"
#include "../jobs/voxel_prop_job.h"
#include "../jobs/voxel_terrarin_job.h"
_FORCE_INLINE_ int VoxelWorldDefault::get_build_flags() const {
return _build_flags;
}
@ -160,6 +165,20 @@ void VoxelWorldDefault::_update_lods() {
Ref<VoxelChunk> VoxelWorldDefault::_create_chunk(int x, int y, int z, Ref<VoxelChunk> chunk) {
if (!chunk.is_valid()) {
chunk = Ref<VoxelChunk>(memnew(VoxelChunkDefault));
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherDefault)));
chunk->add_job(lj);
chunk->add_job(tj);
chunk->add_job(pj);
}
Ref<VoxelChunkDefault> vcd = chunk;

View File

@ -22,14 +22,8 @@ SOFTWARE.
#include "voxel_chunk_marching_cubes.h"
#include "../../meshers/marching_cubes/voxel_mesher_marching_cubes.h"
#include "../../defines.h"
#include "../jobs/voxel_light_job.h"
#include "../jobs/voxel_prop_job.h"
#include "../jobs/voxel_terrarin_job.h"
VoxelChunkMarchingCubes::VoxelChunkMarchingCubes() {
}
@ -40,29 +34,6 @@ void VoxelChunkMarchingCubes::_setup_channels() {
set_channel_count(MAX_DEFAULT_CHANNELS);
}
void VoxelChunkMarchingCubes::_create_meshers() {
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherMarchingCubes)));
Ref<VoxelMesher> m = Ref<VoxelMesher>(memnew(VoxelMesherMarchingCubes()));
m->set_channel_index_type(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
m->set_channel_index_isolevel(VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
tj->add_mesher(m);
//add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquidMarchingCubes())));
add_job(lj);
add_job(tj);
add_job(pj);
}
void VoxelChunkMarchingCubes::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_channel"), "set_channel_compressed", "get_channel_compressed", 0);
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "isolevel_channel"), "set_channel_compressed", "get_channel_compressed", 1);

View File

@ -34,7 +34,6 @@ public:
protected:
virtual void _setup_channels();
virtual void _create_meshers();
static void _bind_methods();
};

View File

@ -24,10 +24,35 @@ SOFTWARE.
#include "voxel_chunk_marching_cubes.h"
Ref<VoxelChunk> VoxelWorldMarchingCubes::_create_chunk(int x, int y, int z, Ref<VoxelChunk> chunk) {
#include "../../meshers/marching_cubes/voxel_mesher_marching_cubes.h"
#include "../jobs/voxel_light_job.h"
#include "../jobs/voxel_prop_job.h"
#include "../jobs/voxel_terrarin_job.h"
Ref<VoxelChunk> VoxelWorldMarchingCubes::_create_chunk(int x, int y, int z, Ref<VoxelChunk> chunk) {
if (!chunk.is_valid()) {
chunk = Ref<VoxelChunk>(memnew(VoxelChunkMarchingCubes));
Ref<VoxelTerrarinJob> tj;
tj.instance();
Ref<VoxelLightJob> lj;
lj.instance();
Ref<VoxelPropJob> pj;
pj.instance();
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherMarchingCubes)));
Ref<VoxelMesher> m = Ref<VoxelMesher>(memnew(VoxelMesherMarchingCubes()));
m->set_channel_index_type(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
m->set_channel_index_isolevel(VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
tj->add_mesher(m);
//add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquidMarchingCubes())));
chunk->add_job(lj);
chunk->add_job(tj);
chunk->add_job(pj);
}
return VoxelWorld::_create_chunk(x, y, z, chunk);

View File

@ -562,12 +562,6 @@ _FORCE_INLINE_ int VoxelChunk::get_data_size() const {
return _data_size_x * _data_size_y * _data_size_z;
}
void VoxelChunk::create_meshers() {
ERR_FAIL_COND_MSG(!has_method("_create_meshers"), "VoxelChunk: _create_meshers() is missing! Please implement it!");
call("_create_meshers");
}
void VoxelChunk::build() {
ERR_FAIL_COND(!INSTANCE_VALIDATE(get_voxel_world()));
ERR_FAIL_COND(!get_voxel_world()->is_inside_tree());
@ -1128,7 +1122,6 @@ void VoxelChunk::_bind_methods() {
BIND_VMETHOD(MethodInfo("_mesh_data_resource_added", PropertyInfo(Variant::INT, "index")));
BIND_VMETHOD(MethodInfo("_create_meshers"));
BIND_VMETHOD(MethodInfo("_setup_channels"));
BIND_VMETHOD(MethodInfo("_bake_lights"));
@ -1355,8 +1348,6 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_collider", "index"), &VoxelChunk::remove_collider);
ClassDB::bind_method(D_METHOD("clear_colliders"), &VoxelChunk::clear_colliders);
ClassDB::bind_method(D_METHOD("create_meshers"), &VoxelChunk::create_meshers);
BIND_VMETHOD(MethodInfo("_build"));
ClassDB::bind_method(D_METHOD("build"), &VoxelChunk::build);
ClassDB::bind_method(D_METHOD("_build"), &VoxelChunk::_build);

View File

@ -184,7 +184,6 @@ public:
int get_data_size() const;
//Meshing
void create_meshers();
void build();
void clear();
void finalize_build();

View File

@ -402,6 +402,8 @@ Ref<VoxelChunk> VoxelWorld::create_chunk(const int x, const int y, const int z)
Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z, Ref<VoxelChunk> chunk) {
if (!chunk.is_valid()) {
chunk.instance();
//no meshers here
}
ERR_FAIL_COND_V(!chunk.is_valid(), NULL);
@ -420,8 +422,6 @@ Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z,
chunk->set_size(_chunk_size_x, _chunk_size_y, _chunk_size_z, _data_margin_start, _data_margin_end);
//chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale));
chunk->create_meshers();
add_chunk(chunk, x, y, z);
add_to_generation_queue(chunk);