mirror of
https://github.com/Relintai/voxelman.git
synced 2025-04-13 21:00:47 +02:00
Remove the old terrain meshing method.
This commit is contained in:
parent
ad311181c8
commit
18dc41c8e4
@ -316,332 +316,9 @@ void VoxelTerrainJob::phase_physics_process() {
|
|||||||
next_phase();
|
next_phase();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Remove chunk get_lod_num!
|
|
||||||
// Or make it automatic
|
|
||||||
//Also remove VoxelChunkDefault::BUILD_FLAG_CREATE_LODS
|
|
||||||
|
|
||||||
void VoxelTerrainJob::phase_terrain_mesh() {
|
void VoxelTerrainJob::phase_terrain_mesh() {
|
||||||
Ref<VoxelChunkDefault> chunk = _chunk;
|
Ref<VoxelChunkDefault> chunk = _chunk;
|
||||||
|
|
||||||
if ((chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) {
|
|
||||||
int starti = 0;
|
|
||||||
|
|
||||||
if (has_meta("bptm_ulm")) {
|
|
||||||
starti = get_meta("bptm_ulm");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = starti; i < _meshers.size(); ++i) {
|
|
||||||
if (should_return()) {
|
|
||||||
set_meta("bptm_ulm", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<VoxelMesher> mesher = _meshers.get(i);
|
|
||||||
|
|
||||||
ERR_CONTINUE(!mesher.is_valid());
|
|
||||||
|
|
||||||
mesher->bake_colors(_chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
starti = 0;
|
|
||||||
|
|
||||||
if (has_meta("bptm_ullm")) {
|
|
||||||
starti = get_meta("bptm_ullm");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = starti; i < _liquid_meshers.size(); ++i) {
|
|
||||||
if (should_return()) {
|
|
||||||
set_meta("bptm_ullm", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<VoxelMesher> mesher = _liquid_meshers.get(i);
|
|
||||||
|
|
||||||
ERR_CONTINUE(!mesher.is_valid());
|
|
||||||
|
|
||||||
mesher->bake_colors(_chunk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int starti = 0;
|
|
||||||
|
|
||||||
if (has_meta("bptm_mm")) {
|
|
||||||
starti = get_meta("bptm_mm");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<VoxelMesher> mesher;
|
|
||||||
for (int i = starti; i < _meshers.size(); ++i) {
|
|
||||||
if (should_return()) {
|
|
||||||
set_meta("bptm_mm", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<VoxelMesher> m = _meshers.get(i);
|
|
||||||
|
|
||||||
ERR_CONTINUE(!m.is_valid());
|
|
||||||
|
|
||||||
if (!mesher.is_valid()) {
|
|
||||||
mesher = m;
|
|
||||||
mesher->set_material(_chunk->get_library()->material_get(0));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mesher->set_material(_chunk->get_library()->material_get(0));
|
|
||||||
mesher->add_mesher(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
ERR_FAIL_COND(!mesher.is_valid());
|
|
||||||
|
|
||||||
starti = 0;
|
|
||||||
|
|
||||||
if (has_meta("bptm_lmm")) {
|
|
||||||
starti = get_meta("bptm_lmm");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<VoxelMesher> liquid_mesher;
|
|
||||||
for (int i = starti; i < _liquid_meshers.size(); ++i) {
|
|
||||||
if (should_return()) {
|
|
||||||
set_meta("bptm_lmm", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<VoxelMesher> m = _liquid_meshers.get(i);
|
|
||||||
|
|
||||||
ERR_CONTINUE(!m.is_valid());
|
|
||||||
|
|
||||||
if (!liquid_mesher.is_valid()) {
|
|
||||||
liquid_mesher = m;
|
|
||||||
liquid_mesher->set_material(_chunk->get_library()->material_get(0));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
liquid_mesher->set_material(_chunk->get_library()->material_get(0));
|
|
||||||
liquid_mesher->add_mesher(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesher->get_vertex_count() == 0 && liquid_mesher.is_valid() && liquid_mesher->get_vertex_count() == 0) {
|
|
||||||
if (has_meta("bptm_ulm")) {
|
|
||||||
remove_meta("bptm_ulm");
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
next_phase();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesher->get_vertex_count() != 0) {
|
|
||||||
if (should_do()) {
|
|
||||||
temp_mesh_arr = mesher->build_mesh();
|
|
||||||
|
|
||||||
if (should_return()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RID mesh_rid = chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
|
||||||
|
|
||||||
if (should_do()) {
|
|
||||||
if (mesh_rid == RID()) {
|
|
||||||
if ((chunk->get_build_flags() & VoxelChunkDefault::BUILD_FLAG_CREATE_LODS) != 0)
|
|
||||||
chunk->meshes_create(VoxelChunkDefault::MESH_INDEX_TERRAIN, chunk->get_lod_num() + 1);
|
|
||||||
else
|
|
||||||
chunk->meshes_create(VoxelChunkDefault::MESH_INDEX_TERRAIN, 1);
|
|
||||||
|
|
||||||
mesh_rid = chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0)
|
|
||||||
#if !GODOT4
|
|
||||||
VS::get_singleton()->mesh_remove_surface(mesh_rid, 0);
|
|
||||||
#else
|
|
||||||
VS::get_singleton()->mesh_clear(mesh_rid);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (should_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()->material_get(0).is_valid())
|
|
||||||
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_get(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->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 1), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
|
|
||||||
|
|
||||||
if (chunk->get_library()->material_get(1).is_valid())
|
|
||||||
VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 1), 0, chunk->get_library()->material_get(1)->get_rid());
|
|
||||||
}
|
|
||||||
if (should_return()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (should_do()) {
|
|
||||||
if (chunk->get_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(chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 2), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr2);
|
|
||||||
|
|
||||||
if (chunk->get_library()->material_get(2).is_valid())
|
|
||||||
VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 2), 0, chunk->get_library()->material_get(2)->get_rid());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (should_return()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (should_do()) {
|
|
||||||
if (chunk->get_lod_num() >= 3) {
|
|
||||||
Ref<ShaderMaterial> mat = chunk->get_library()->material_get(0);
|
|
||||||
Ref<SpatialMaterial> spmat = chunk->get_library()->material_get(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(
|
|
||||||
chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 3),
|
|
||||||
VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
|
|
||||||
|
|
||||||
if (chunk->get_library()->material_get(3).is_valid())
|
|
||||||
VisualServer::get_singleton()->mesh_surface_set_material(
|
|
||||||
chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 3), 0,
|
|
||||||
chunk->get_library()->material_get(3)->get_rid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (should_return()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef MESH_UTILS_PRESENT
|
|
||||||
if (should_do()) {
|
|
||||||
if (chunk->get_lod_num() > 4) {
|
|
||||||
Ref<FastQuadraticMeshSimplifier> fqms;
|
|
||||||
fqms.INSTANCE();
|
|
||||||
fqms->set_preserve_border_edges(true);
|
|
||||||
fqms->initialize(temp_mesh_arr);
|
|
||||||
|
|
||||||
for (int i = 4; i < chunk->get_lod_num(); ++i) {
|
|
||||||
fqms->simplify_mesh(temp_mesh_arr.size() * 0.8, 7);
|
|
||||||
temp_mesh_arr = fqms->get_arrays();
|
|
||||||
|
|
||||||
VisualServer::get_singleton()->mesh_add_surface_from_arrays(
|
|
||||||
chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, i),
|
|
||||||
VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
|
|
||||||
|
|
||||||
if (chunk->get_library()->material_get(i).is_valid())
|
|
||||||
VisualServer::get_singleton()->mesh_surface_set_material(
|
|
||||||
chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_TERRAIN, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, i), 0,
|
|
||||||
chunk->get_library()->material_get(i)->get_rid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (should_return()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (liquid_mesher.is_valid() && liquid_mesher->get_vertex_count() != 0) {
|
|
||||||
if (should_do()) {
|
|
||||||
temp_mesh_arr = liquid_mesher->build_mesh();
|
|
||||||
|
|
||||||
if (should_return()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RID mesh_rid = chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_LIQUID, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
|
||||||
|
|
||||||
if (should_do()) {
|
|
||||||
if (mesh_rid == RID()) {
|
|
||||||
chunk->meshes_create(VoxelChunkDefault::MESH_INDEX_LIQUID, 1);
|
|
||||||
|
|
||||||
mesh_rid = chunk->mesh_rid_get_index(VoxelChunkDefault::MESH_INDEX_LIQUID, VoxelChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0)
|
|
||||||
#if !GODOT4
|
|
||||||
VS::get_singleton()->mesh_remove_surface(mesh_rid, 0);
|
|
||||||
#else
|
|
||||||
VS::get_singleton()->mesh_clear(mesh_rid);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (should_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()->liquid_material_get(0).is_valid())
|
|
||||||
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->liquid_material_get(0)->get_rid());
|
|
||||||
|
|
||||||
// if (should_return()) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_meta("bptm_ulm")) {
|
|
||||||
remove_meta("bptm_ulm");
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
next_phase();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelTerrainJob::new_phase_terrain_mesh() {
|
|
||||||
Ref<VoxelChunkDefault> chunk = _chunk;
|
|
||||||
|
|
||||||
ERR_FAIL_COND(_meshers.size() == 0);
|
ERR_FAIL_COND(_meshers.size() == 0);
|
||||||
|
|
||||||
if (should_return()) {
|
if (should_return()) {
|
||||||
|
@ -35,6 +35,10 @@ include_pool_vector
|
|||||||
|
|
||||||
class VoxelMesher;
|
class VoxelMesher;
|
||||||
|
|
||||||
|
//TODO Remove chunk get_lod_num!
|
||||||
|
// Or make it automatic
|
||||||
|
//Also remove VoxelChunkDefault::BUILD_FLAG_CREATE_LODS
|
||||||
|
|
||||||
class VoxelTerrainJob : public VoxelJob {
|
class VoxelTerrainJob : public VoxelJob {
|
||||||
GDCLASS(VoxelTerrainJob, VoxelJob);
|
GDCLASS(VoxelTerrainJob, VoxelJob);
|
||||||
|
|
||||||
@ -65,7 +69,6 @@ public:
|
|||||||
void phase_collider();
|
void phase_collider();
|
||||||
void phase_physics_proces();
|
void phase_physics_proces();
|
||||||
void phase_terrain_mesh();
|
void phase_terrain_mesh();
|
||||||
void new_phase_terrain_mesh();
|
|
||||||
void phase_finalize();
|
void phase_finalize();
|
||||||
void phase_physics_process();
|
void phase_physics_process();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user