VoxelTerrarinJob now has the necessary code in it as methods.

This commit is contained in:
Relintai 2020-10-01 21:31:39 +02:00
parent bf17467879
commit 3f23be12bc
2 changed files with 366 additions and 428 deletions

View File

@ -74,444 +74,385 @@ int VoxelTerrarinJob::get_liquid_mesher_count() const {
return _liquid_meshers.size(); return _liquid_meshers.size();
} }
void VoxelTerrarinJob::_execute() { void VoxelTerrarinJob::phase_setup() {
ERR_FAIL_COND(!_chunk.is_valid()); for (int i = 0; i < _meshers.size(); ++i) {
Ref<VoxelMesher> mesher = _meshers.get(i);
Ref<VoxelmanLibrary> library = _chunk->get_library(); ERR_CONTINUE(!mesher.is_valid());
ERR_FAIL_COND(!library.is_valid()); mesher->set_library(_chunk->get_library());
/* mesher->reset();
int phase = 0; }
switch (phase) { for (int i = 0; i < _liquid_meshers.size(); ++i) {
case BUILD_PHASE_SETUP: { Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
for (int i = 0; i < _meshers.size(); ++i) {
Ref<VoxelMesher> mesher = _meshers.get(i);
ERR_CONTINUE(!mesher.is_valid()); ERR_CONTINUE(!mesher.is_valid());
mesher->set_library(_library); mesher->set_library(_chunk->get_library());
mesher->reset(); mesher->reset();
} }
}
for (int i = 0; i < _liquid_meshers.size(); ++i) { void VoxelTerrarinJob::phase_terrarin_mesh_setup() {
Ref<VoxelMesher> mesher = _liquid_meshers.get(i); int starti = 0;
ERR_CONTINUE(!mesher.is_valid()); if (has_meta("tms_m")) {
starti = get_meta("tms_m");
}
mesher->set_library(_library); for (int i = starti; i < _meshers.size(); ++i) {
mesher->reset(); if (should_return()) {
} set_meta("tms_m", i);
if (get_prop_mesher().is_valid()) {
get_prop_mesher()->reset();
get_prop_mesher()->set_library(_library);
}
next_phase();
return; return;
} }
case BUILD_PHASE_TERRARIN_MESH_SETUP: {
int starti = 0;
if (_job->has_meta("tms_m")) { Ref<VoxelMesher> mesher = _meshers.get(i);
starti = _job->get_meta("tms_m");
}
for (int i = starti; i < _meshers.size(); ++i) { ERR_CONTINUE(!mesher.is_valid());
if (_job->should_return()) {
_job->set_meta("tms_m", i);
return;
}
Ref<VoxelMesher> mesher = _meshers.get(i); mesher->add_chunk(_chunk);
}
ERR_CONTINUE(!mesher.is_valid()); starti = 0;
mesher->add_chunk(this); if (has_meta("tms_lm")) {
} starti = get_meta("tms_lm");
}
starti = 0;
if (_job->has_meta("tms_lm")) {
starti = _job->get_meta("tms_lm");
}
for (int i = starti; i < _liquid_meshers.size(); ++i) {
if (_job->should_return()) {
_job->set_meta("tms_lm", i);
return;
}
Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
ERR_CONTINUE(!mesher.is_valid());
mesher->add_chunk(this);
}
next_phase();
if (_job->has_meta("tms_m")) {
_job->remove_meta("tms_m");
}
if (_job->has_meta("tms_lm")) {
_job->remove_meta("tms_lm");
}
for (int i = starti; i < _liquid_meshers.size(); ++i) {
if (should_return()) {
set_meta("tms_lm", i);
return; return;
} }
case BUILD_PHASE_COLLIDER: {
if ((_build_flags & BUILD_FLAG_CREATE_COLLIDER) == 0) { Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
next_phase();
ERR_CONTINUE(!mesher.is_valid());
mesher->add_chunk(_chunk);
}
if (has_meta("tms_m")) {
remove_meta("tms_m");
}
if (has_meta("tms_lm")) {
remove_meta("tms_lm");
}
}
void VoxelTerrarinJob::phase_collider() {
Ref<VoxelChunkDefault> chunk = _chunk;
if ((chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_CREATE_COLLIDER) == 0) {
return;
}
int starti = 0;
if (has_meta("bpc_aa")) {
starti = get_meta("bpc_aa");
}
for (int i = starti; i < _meshers.size(); ++i) {
if (should_return()) {
set_meta("bpc_aa", i);
return;
}
Ref<VoxelMesher> mesher = _meshers.get(i);
ERR_CONTINUE(!mesher.is_valid());
temp_arr_collider.append_array(mesher->build_collider());
}
if (Engine::get_singleton()->is_editor_hint()) {
starti = 0;
if (has_meta("bpc_laa")) {
starti = get_meta("bpc_laa");
}
for (int i = 0; i < _liquid_meshers.size(); ++i) {
if (should_return()) {
set_meta("bpc_laa", i);
return; return;
} }
int starti = 0; Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
if (_job->has_meta("bpc_aa")) { ERR_CONTINUE(!mesher.is_valid());
starti = _job->get_meta("bpc_aa");
}
for (int i = starti; i < _meshers.size(); ++i) { temp_arr_collider_liquid.append_array(mesher->build_collider());
if (_job->should_return()) {
_job->set_meta("bpc_aa", i);
return;
}
Ref<VoxelMesher> mesher = _meshers.get(i);
ERR_CONTINUE(!mesher.is_valid());
temp_arr_collider.append_array(mesher->build_collider());
}
if (Engine::get_singleton()->is_editor_hint()) {
starti = 0;
if (_job->has_meta("bpc_laa")) {
starti = _job->get_meta("bpc_laa");
}
for (int i = 0; i < _liquid_meshers.size(); ++i) {
if (_job->should_return()) {
_job->set_meta("bpc_laa", i);
return;
}
Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
ERR_CONTINUE(!mesher.is_valid());
temp_arr_collider_liquid.append_array(mesher->build_collider());
}
}
if (_job->has_meta("bpc_aa")) {
_job->remove_meta("bpc_aa");
}
if (_job->has_meta("bpc_laa")) {
_job->remove_meta("bpc_laa");
}
if (temp_arr_collider.size() == 0 && temp_arr_collider_liquid.size() == 0
#ifdef MESH_DATA_RESOURCE_PRESENT
&& get_mesh_data_resource_count() == 0
#endif
) {
next_phase();
return;
}
set_active_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS);
return;
} }
case BUILD_PHASE_LIGHTS: { }
bool gr = (_build_flags & BUILD_FLAG_AUTO_GENERATE_RAO) != 0;
if (!gr && (_build_flags & BUILD_FLAG_USE_LIGHTING) == 0) { if (has_meta("bpc_aa")) {
next_phase(); remove_meta("bpc_aa");
return; }
}
bool bl = (_build_flags & BUILD_FLAG_BAKE_LIGHTS) != 0; if (has_meta("bpc_laa")) {
remove_meta("bpc_laa");
}
if (bl && _job->should_do()) { if (temp_arr_collider.size() == 0 && temp_arr_collider_liquid.size() == 0) {
clear_baked_lights(); return;
}
if (_job->should_return()) //set_active_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS);
return; //return;
} }
if (gr && _job->should_do()) { void VoxelTerrarinJob::phase_terrarin_mesh() {
generate_random_ao(_voxel_world->get_current_seed()); Ref<VoxelChunkDefault> chunk = _chunk;
if (_job->should_return()) if (should_do()) {
return; for (int i = 0; i < _meshers.size(); ++i) {
} Ref<VoxelMesher> mesher = _meshers.get(i);
if (bl && _job->should_do()) { ERR_CONTINUE(!mesher.is_valid());
bake_lights();
if (_job->should_return()) mesher->set_library(_chunk->get_library());
return;
}
_job->reset_stages();
next_phase();
return;
} }
case BUILD_PHASE_TERRARIN_MESH: {
if (_job->should_do()) {
for (int i = 0; i < _meshers.size(); ++i) {
Ref<VoxelMesher> mesher = _meshers.get(i);
ERR_CONTINUE(!mesher.is_valid()); for (int i = 0; i < _liquid_meshers.size(); ++i) {
Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
mesher->set_library(_library); ERR_CONTINUE(!mesher.is_valid());
}
for (int i = 0; i < _liquid_meshers.size(); ++i) { mesher->set_library(_chunk->get_library());
Ref<VoxelMesher> mesher = _liquid_meshers.get(i); }
ERR_CONTINUE(!mesher.is_valid()); if (should_return())
return;
}
mesher->set_library(_library); if ((chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) {
} int starti = 0;
if (_job->should_return()) if (has_meta("bptm_ulm")) {
return; starti = get_meta("bptm_ulm");
}
for (int i = starti; i < _meshers.size(); ++i) {
if (should_return()) {
set_meta("bptm_ulm", i);
} }
if ((_build_flags & VoxelTerrarinJob::BUILD_FLAG_USE_LIGHTING) != 0) { Ref<VoxelMesher> mesher = _meshers.get(i);
int starti = 0;
if (_job->has_meta("bptm_ulm")) { ERR_CONTINUE(!mesher.is_valid());
starti = _job->get_meta("bptm_ulm");
}
for (int i = starti; i < _meshers.size(); ++i) { mesher->bake_colors(_chunk);
if (_job->should_return()) { }
_job->set_meta("bptm_ulm", i);
}
Ref<VoxelMesher> mesher = _meshers.get(i); starti = 0;
ERR_CONTINUE(!mesher.is_valid()); if (has_meta("bptm_ullm")) {
starti = get_meta("bptm_ullm");
}
mesher->bake_colors(this); for (int i = starti; i < _liquid_meshers.size(); ++i) {
} if (should_return()) {
set_meta("bptm_ullm", i);
starti = 0;
if (_job->has_meta("bptm_ullm")) {
starti = _job->get_meta("bptm_ullm");
}
for (int i = starti; i < _liquid_meshers.size(); ++i) {
if (_job->should_return()) {
_job->set_meta("bptm_ullm", i);
}
Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
ERR_CONTINUE(!mesher.is_valid());
mesher->bake_colors(this);
}
} }
int starti = 0; Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
if (_job->has_meta("bptm_mm")) { ERR_CONTINUE(!mesher.is_valid());
starti = _job->get_meta("bptm_mm");
}
Ref<VoxelMesher> mesher; mesher->bake_colors(_chunk);
for (int i = starti; i < _meshers.size(); ++i) { }
if (_job->should_return()) { }
_job->set_meta("bptm_mm", i);
}
Ref<VoxelMesher> m = _meshers.get(i); int starti = 0;
ERR_CONTINUE(!m.is_valid()); if (has_meta("bptm_mm")) {
starti = get_meta("bptm_mm");
}
if (!mesher.is_valid()) { Ref<VoxelMesher> mesher;
mesher = m; for (int i = starti; i < _meshers.size(); ++i) {
mesher->set_material(get_library()->get_material(0)); if (should_return()) {
continue; set_meta("bptm_mm", i);
} }
mesher->set_material(get_library()->get_material(0)); Ref<VoxelMesher> m = _meshers.get(i);
mesher->add_mesher(m);
}
ERR_FAIL_COND(!mesher.is_valid()); ERR_CONTINUE(!m.is_valid());
starti = 0; if (!mesher.is_valid()) {
mesher = m;
mesher->set_material(_chunk->get_library()->get_material(0));
continue;
}
if (_job->has_meta("bptm_lmm")) { mesher->set_material(_chunk->get_library()->get_material(0));
starti = _job->get_meta("bptm_lmm"); mesher->add_mesher(m);
} }
Ref<VoxelMesher> liquid_mesher; ERR_FAIL_COND(!mesher.is_valid());
for (int i = starti; i < _liquid_meshers.size(); ++i) {
if (_job->should_return()) {
_job->set_meta("bptm_lmm", i);
}
Ref<VoxelMesher> m = _liquid_meshers.get(i); starti = 0;
ERR_CONTINUE(!m.is_valid()); if (has_meta("bptm_lmm")) {
starti = get_meta("bptm_lmm");
}
if (!liquid_mesher.is_valid()) { Ref<VoxelMesher> liquid_mesher;
liquid_mesher = m; for (int i = starti; i < _liquid_meshers.size(); ++i) {
liquid_mesher->set_material(get_library()->get_material(0)); if (should_return()) {
continue; set_meta("bptm_lmm", i);
} }
liquid_mesher->set_material(get_library()->get_material(0)); Ref<VoxelMesher> m = _liquid_meshers.get(i);
liquid_mesher->add_mesher(m);
}
if (mesher->get_vertex_count() == 0 && liquid_mesher.is_valid() && liquid_mesher->get_vertex_count() == 0) { ERR_CONTINUE(!m.is_valid());
if (_job->has_meta("bptm_ulm")) { if (!liquid_mesher.is_valid()) {
_job->remove_meta("bptm_ulm"); liquid_mesher = m;
} liquid_mesher->set_material(_chunk->get_library()->get_material(0));
continue;
}
if (_job->has_meta("bptm_ullm")) { liquid_mesher->set_material(_chunk->get_library()->get_material(0));
_job->remove_meta("bptm_ullm"); liquid_mesher->add_mesher(m);
} }
if (_job->has_meta("bptm_mm")) { if (mesher->get_vertex_count() == 0 && liquid_mesher.is_valid() && liquid_mesher->get_vertex_count() == 0) {
_job->remove_meta("bptm_mm");
}
if (_job->has_meta("bptm_lmm")) { if (has_meta("bptm_ulm")) {
_job->remove_meta("bptm_lmm"); remove_meta("bptm_ulm");
} }
_job->reset_stages(); if (has_meta("bptm_ullm")) {
remove_meta("bptm_ullm");
}
next_phase(); if (has_meta("bptm_mm")) {
remove_meta("bptm_mm");
}
if (has_meta("bptm_lmm")) {
remove_meta("bptm_lmm");
}
reset_stages();
return;
}
if (mesher->get_vertex_count() != 0) {
if (should_do()) {
temp_mesh_arr = mesher->build_mesh();
if (should_return()) {
return; return;
} }
}
if (mesher->get_vertex_count() != 0) { RID mesh_rid = chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
if (_job->should_do()) { if (should_do()) {
temp_mesh_arr = mesher->build_mesh(); if (mesh_rid == RID()) {
if ((chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_CREATE_LODS) != 0)
chunk->create_meshes(VoxelChunkDefault::MESH_INDEX_TERRARIN, chunk->get_lod_num() + 1);
else
chunk->create_meshes(VoxelChunkDefault::MESH_INDEX_TERRARIN, 1);
if (_job->should_return()) { mesh_rid = chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
return; }
}
}
RID mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0); if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0)
if (_job->should_do()) {
if (mesh_rid == RID()) {
if ((_build_flags & BUILD_FLAG_CREATE_LODS) != 0)
create_meshes(MESH_INDEX_TERRARIN, _lod_num + 1);
else
create_meshes(MESH_INDEX_TERRARIN, 1);
mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0);
}
if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0)
#if !GODOT4 #if !GODOT4
VS::get_singleton()->mesh_remove_surface(mesh_rid, 0); VS::get_singleton()->mesh_remove_surface(mesh_rid, 0);
#else #else
VS::get_singleton()->mesh_clear(mesh_rid); VS::get_singleton()->mesh_clear(mesh_rid);
#endif #endif
if (_job->should_return()) { if (should_return()) {
return; return;
}
}
if (should_do()) {
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
if (chunk->get_library()->get_material(0).is_valid())
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->get_material(0)->get_rid());
if (should_return()) {
return;
}
}
if ((chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_CREATE_LODS) != 0) {
if (should_do()) {
if (chunk->get_lod_num() >= 1) {
//for lod 1 just remove uv2
temp_mesh_arr[VisualServer::ARRAY_TEX_UV2] = Variant();
VisualServer::get_singleton()->mesh_add_surface_from_arrays(chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 1), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
if (chunk->get_library()->get_material(1).is_valid())
VisualServer::get_singleton()->mesh_surface_set_material(chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 1), 0, chunk->get_library()->get_material(1)->get_rid());
}
if (should_return()) {
return;
}
}
if (should_do()) {
if (chunk->get_lod_num() >= 2) {
Array temp_mesh_arr2 = chunk->merge_mesh_array(temp_mesh_arr);
temp_mesh_arr = temp_mesh_arr2;
VisualServer::get_singleton()->mesh_add_surface_from_arrays(chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 2), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr2);
if (chunk->get_library()->get_material(2).is_valid())
VisualServer::get_singleton()->mesh_surface_set_material(chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 2), 0, chunk->get_library()->get_material(2)->get_rid());
}
if (should_return()) {
return;
}
}
if (should_do()) {
if (chunk->get_lod_num() >= 3) {
Ref<ShaderMaterial> mat = chunk->get_library()->get_material(0);
Ref<SpatialMaterial> spmat = chunk->get_library()->get_material(0);
Ref<Texture> tex;
if (mat.is_valid()) {
tex = mat->get_shader_param("texture_albedo");
} else if (spmat.is_valid()) {
tex = spmat->get_texture(SpatialMaterial::TEXTURE_ALBEDO);
}
if (tex.is_valid()) {
temp_mesh_arr = chunk->bake_mesh_array_uv(temp_mesh_arr, tex);
temp_mesh_arr[VisualServer::ARRAY_TEX_UV] = Variant();
VisualServer::get_singleton()->mesh_add_surface_from_arrays(chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 3), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
if (chunk->get_library()->get_material(3).is_valid())
VisualServer::get_singleton()->mesh_surface_set_material(chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_TERRARIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 3), 0, chunk->get_library()->get_material(3)->get_rid());
} }
} }
if (_job->should_do()) { if (should_return()) {
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); return;
if (_library->get_material(0).is_valid())
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, _library->get_material(0)->get_rid());
if (_job->should_return()) {
return;
}
} }
}
if ((_build_flags & BUILD_FLAG_CREATE_LODS) != 0) { /*
if (_job->should_do()) { if (should_do()) {
if (_lod_num >= 1) { if (chunk->get_lod_num() > 4) {
//for lod 1 just remove uv2
temp_mesh_arr[VisualServer::ARRAY_TEX_UV2] = Variant();
VisualServer::get_singleton()->mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
if (get_library()->get_material(1).is_valid())
VisualServer::get_singleton()->mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), 0, get_library()->get_material(1)->get_rid());
}
if (_job->should_return()) {
return;
}
}
if (_job->should_do()) {
if (_lod_num >= 2) {
Array temp_mesh_arr2 = merge_mesh_array(temp_mesh_arr);
temp_mesh_arr = temp_mesh_arr2;
VisualServer::get_singleton()->mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr2);
if (get_library()->get_material(2).is_valid())
VisualServer::get_singleton()->mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), 0, get_library()->get_material(2)->get_rid());
}
if (_job->should_return()) {
return;
}
}
if (_job->should_do()) {
if (_lod_num >= 3) {
Ref<ShaderMaterial> mat = get_library()->get_material(0);
Ref<SpatialMaterial> spmat = get_library()->get_material(0);
Ref<Texture> tex;
if (mat.is_valid()) {
tex = mat->get_shader_param("texture_albedo");
} else if (spmat.is_valid()) {
tex = spmat->get_texture(SpatialMaterial::TEXTURE_ALBEDO);
}
if (tex.is_valid()) {
temp_mesh_arr = bake_mesh_array_uv(temp_mesh_arr, tex);
temp_mesh_arr[VisualServer::ARRAY_TEX_UV] = Variant();
VisualServer::get_singleton()->mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
if (get_library()->get_material(3).is_valid())
VisualServer::get_singleton()->mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), 0, get_library()->get_material(3)->get_rid());
}
}
if (_job->should_return()) {
return;
}
}
//----
if (_job->should_do()) {
if (_lod_num > 4) {
Ref<FastQuadraticMeshSimplifier> fqms; Ref<FastQuadraticMeshSimplifier> fqms;
fqms.instance(); fqms.instance();
fqms->initialize(temp_mesh_arr); fqms->initialize(temp_mesh_arr);
@ -532,98 +473,89 @@ void VoxelTerrarinJob::_execute() {
} }
} }
if (_job->should_return()) { if (should_return()) {
return; return;
} }
} }
//---- */
}
}
if (liquid_mesher.is_valid() && liquid_mesher->get_vertex_count() != 0) {
if (_job->should_do()) {
temp_mesh_arr = liquid_mesher->build_mesh();
if (_job->should_return()) {
return;
} }
} }
RID mesh_rid = get_mesh_rid_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH, 0); if (liquid_mesher.is_valid() && liquid_mesher->get_vertex_count() != 0) {
if (should_do()) {
temp_mesh_arr = liquid_mesher->build_mesh();
if (_job->should_do()) { if (should_return()) {
if (mesh_rid == RID()) { return;
create_meshes(MESH_INDEX_LIQUID, 1); }
mesh_rid = get_mesh_rid_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH, 0);
} }
if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0) RID mesh_rid = chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_LIQUID, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
if (should_do()) {
if (mesh_rid == RID()) {
chunk->create_meshes(VoxelChunkDefault::MESH_INDEX_LIQUID, 1);
mesh_rid = chunk->get_mesh_rid_index(VoxelChunkDefault::MESH_INDEX_LIQUID, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
}
if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0)
#if !GODOT4 #if !GODOT4
VS::get_singleton()->mesh_remove_surface(mesh_rid, 0); VS::get_singleton()->mesh_remove_surface(mesh_rid, 0);
#else #else
VS::get_singleton()->mesh_clear(mesh_rid); VS::get_singleton()->mesh_clear(mesh_rid);
#endif #endif
if (_job->should_return()) { if (should_return()) {
return; return;
}
} }
// if (should_do()) {
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
if (chunk->get_library()->get_liquid_material(0).is_valid())
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->get_liquid_material(0)->get_rid());
// if (should_return()) {
// return;
// }
//}
} }
// if (_job->should_do()) { if (has_meta("bptm_ulm")) {
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); remove_meta("bptm_ulm");
if (_library->get_liquid_material(0).is_valid())
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, _library->get_liquid_material(0)->get_rid());
// if (_job->should_return()) {
// return;
// }
//}
}
if (_job->has_meta("bptm_ulm")) {
_job->remove_meta("bptm_ulm");
}
if (_job->has_meta("bptm_ullm")) {
_job->remove_meta("bptm_ullm");
}
if (_job->has_meta("bptm_mm")) {
_job->remove_meta("bptm_mm");
}
if (_job->has_meta("bptm_lmm")) {
_job->remove_meta("bptm_lmm");
}
_job->reset_stages();
next_phase();
return;
}
case BUILD_PHASE_FINALIZE: {
#if TOOLS_ENABLED
if (_debug_mesh_array.size() > 0) {
debug_mesh_send();
}
#endif
set_current_lod_level(get_current_lod_level());
call_deferred("update_transforms");
next_phase();
return;
}
} }
next_phase(); if (has_meta("bptm_ullm")) {
*/ remove_meta("bptm_ullm");
}
if (has_meta("bptm_mm")) {
remove_meta("bptm_mm");
}
if (has_meta("bptm_lmm")) {
remove_meta("bptm_lmm");
}
reset_stages();
}
void VoxelTerrarinJob::_execute() {
ERR_FAIL_COND(!_chunk.is_valid());
Ref<VoxelmanLibrary> library = _chunk->get_library();
ERR_FAIL_COND(!library.is_valid());
//Todo add checks for these whether the phases are done or not
phase_setup();
phase_terrarin_mesh_setup();
phase_collider();
phase_terrarin_mesh();
//finish
} }
VoxelTerrarinJob::VoxelTerrarinJob() { VoxelTerrarinJob::VoxelTerrarinJob() {

View File

@ -45,6 +45,11 @@ public:
void add_liquid_mesher(const Ref<VoxelMesher> &mesher); void add_liquid_mesher(const Ref<VoxelMesher> &mesher);
int get_liquid_mesher_count() const; int get_liquid_mesher_count() const;
void phase_setup();
void phase_terrarin_mesh_setup();
void phase_collider();
void phase_terrarin_mesh();
void _execute(); void _execute();
VoxelTerrarinJob(); VoxelTerrarinJob();
@ -58,6 +63,7 @@ protected:
PoolVector<Vector3> temp_arr_collider; PoolVector<Vector3> temp_arr_collider;
PoolVector<Vector3> temp_arr_collider_liquid; PoolVector<Vector3> temp_arr_collider_liquid;
Array temp_mesh_arr;
}; };
#endif #endif