From adf42dc30d5d5885c212cb438509a62d36349894 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 1 Aug 2021 22:21:20 +0200 Subject: [PATCH] Per chunk material support for the Terrain job. --- world/jobs/terra_terrarin_job.cpp | 78 ++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/world/jobs/terra_terrarin_job.cpp b/world/jobs/terra_terrarin_job.cpp index 302d646..06a2e28 100644 --- a/world/jobs/terra_terrarin_job.cpp +++ b/world/jobs/terra_terrarin_job.cpp @@ -480,8 +480,17 @@ void TerraTerrarinJob::step_type_normal() { VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->material_lod_get(_current_mesh).is_valid()) - VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_lod_get(_current_mesh)->get_rid()); + Ref lmat; + + if (chunk->get_library()->supports_caching()) { + lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + } else { + lmat = chunk->get_library()->material_lod_get(_current_mesh); + } + + if (lmat.is_valid()) { + VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid()); + } ++_current_mesh; } @@ -512,8 +521,17 @@ void TerraTerrarinJob::step_type_normal_lod() { VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->material_lod_get(_current_mesh).is_valid()) - VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_lod_get(_current_mesh)->get_rid()); + Ref lmat; + + if (chunk->get_library()->supports_caching()) { + lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + } else { + lmat = chunk->get_library()->material_lod_get(_current_mesh); + } + + if (lmat.is_valid()) { + VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid()); + } ++_current_mesh; } @@ -527,8 +545,17 @@ void TerraTerrarinJob::step_type_drop_uv2() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->material_lod_get(_current_mesh).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_lod_get(_current_mesh)->get_rid()); + Ref lmat; + + if (chunk->get_library()->supports_caching()) { + lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + } else { + lmat = chunk->get_library()->material_lod_get(_current_mesh); + } + + if (lmat.is_valid()) { + VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid()); + } ++_current_mesh; } @@ -542,8 +569,17 @@ void TerraTerrarinJob::step_type_merge_verts() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->material_lod_get(_current_mesh).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_lod_get(_current_mesh)->get_rid()); + Ref lmat; + + if (chunk->get_library()->supports_caching()) { + lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + } else { + lmat = chunk->get_library()->material_lod_get(_current_mesh); + } + + if (lmat.is_valid()) { + VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid()); + } ++_current_mesh; } @@ -569,8 +605,17 @@ void TerraTerrarinJob::step_type_bake_texture() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->material_lod_get(_current_mesh).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_lod_get(_current_mesh)->get_rid()); + Ref lmat; + + if (chunk->get_library()->supports_caching()) { + lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + } else { + lmat = chunk->get_library()->material_lod_get(_current_mesh); + } + + if (lmat.is_valid()) { + VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid()); + } } ++_current_mesh; @@ -595,8 +640,17 @@ void TerraTerrarinJob::step_type_simplify_mesh() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->material_lod_get(_current_mesh).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_lod_get(_current_mesh)->get_rid()); + Ref lmat; + + if (chunk->get_library()->supports_caching()) { + lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + } else { + lmat = chunk->get_library()->material_lod_get(_current_mesh); + } + + if (lmat.is_valid()) { + VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid()); + } ++_current_mesh; }