From 660ea8bf74c98fccfad1dc4e1be208e1261e3e93 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 1 Aug 2021 16:33:17 +0200 Subject: [PATCH] Use the new lod variant of the library's material getters wherever possible. --- meshers/terra_mesher.cpp | 2 +- world/jobs/terra_prop_job.cpp | 24 +++++++-------- world/jobs/terra_terrarin_job.cpp | 50 ++++++++++--------------------- 3 files changed, 29 insertions(+), 47 deletions(-) diff --git a/meshers/terra_mesher.cpp b/meshers/terra_mesher.cpp index 48c22d1..d9b8101 100644 --- a/meshers/terra_mesher.cpp +++ b/meshers/terra_mesher.cpp @@ -291,7 +291,7 @@ void TerraMesher::build_mesh_into(RID mesh) { VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VisualServer::PRIMITIVE_TRIANGLES, arr); if (_material.is_valid()) - VS::get_singleton()->mesh_surface_set_material(mesh, 0, _library->material_get(0)->get_rid()); + VS::get_singleton()->mesh_surface_set_material(mesh, 0, _library->material_lod_get(0)->get_rid()); } void TerraMesher::generate_normals(bool p_flip) { diff --git a/world/jobs/terra_prop_job.cpp b/world/jobs/terra_prop_job.cpp index 6007d6f..f740473 100644 --- a/world/jobs/terra_prop_job.cpp +++ b/world/jobs/terra_prop_job.cpp @@ -226,8 +226,8 @@ void TerraPropJob::phase_prop() { VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->prop_material_get(0).is_valid()) - VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->prop_material_get(0)->get_rid()); + if (chunk->get_library()->prop_material_lod_get(0).is_valid()) + VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->prop_material_lod_get(0)->get_rid()); if (should_return()) { return; @@ -243,8 +243,8 @@ void TerraPropJob::phase_prop() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 1), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->prop_material_get(1).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 1), 0, chunk->get_library()->prop_material_get(1)->get_rid()); + if (chunk->get_library()->prop_material_lod_get(1).is_valid()) + VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 1), 0, chunk->get_library()->prop_material_lod_get(1)->get_rid()); } if (should_return()) { @@ -259,8 +259,8 @@ void TerraPropJob::phase_prop() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 2), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr2); - if (chunk->get_library()->prop_material_get(2).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 2), 0, chunk->get_library()->prop_material_get(2)->get_rid()); + if (chunk->get_library()->prop_material_lod_get(2).is_valid()) + VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 2), 0, chunk->get_library()->prop_material_lod_get(2)->get_rid()); } if (should_return()) { return; @@ -269,8 +269,8 @@ void TerraPropJob::phase_prop() { // if (should_do()) { if (chunk->get_lod_num() >= 3) { - Ref mat = chunk->get_library()->prop_material_get(0); - Ref spmat = chunk->get_library()->prop_material_get(0); + Ref mat = chunk->get_library()->prop_material_lod_get(0); + Ref spmat = chunk->get_library()->prop_material_lod_get(0); Ref tex; if (mat.is_valid()) { @@ -285,8 +285,8 @@ void TerraPropJob::phase_prop() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 3), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->prop_material_get(3).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 3), 0, chunk->get_library()->prop_material_get(3)->get_rid()); + if (chunk->get_library()->prop_material_lod_get(3).is_valid()) + VisualServer::get_singleton()->mesh_surface_set_material(chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 3), 0, chunk->get_library()->prop_material_lod_get(3)->get_rid()); } } @@ -306,10 +306,10 @@ void TerraPropJob::phase_prop() { chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_TERRARIN, TerraChunkDefault::MESH_TYPE_INDEX_MESH, i), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - if (chunk->get_library()->prop_material_get(i).is_valid()) + if (chunk->get_library()->prop_material_lod_get(i).is_valid()) VisualServer::get_singleton()->mesh_surface_set_material( chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_TERRARIN, TerraChunkDefault::MESH_TYPE_INDEX_MESH, i), 0, - chunk->get_library()->prop_material_get(i)->get_rid()); + chunk->get_library()->prop_material_lod_get(i)->get_rid()); } } diff --git a/world/jobs/terra_terrarin_job.cpp b/world/jobs/terra_terrarin_job.cpp index eb6fba2..2f0350e 100644 --- a/world/jobs/terra_terrarin_job.cpp +++ b/world/jobs/terra_terrarin_job.cpp @@ -351,8 +351,8 @@ void TerraTerrarinJob::phase_terrarin_mesh() { // 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 (chunk->get_library()->liquid_material_lod_get(0).is_valid()) + VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->liquid_material_lod_get(0)->get_rid()); // if (should_return()) { // return; @@ -444,11 +444,8 @@ void TerraTerrarinJob::step_type_normal() { VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - int matnum = chunk->get_library()->material_get_num(); - int mindex = matnum <= _current_mesh ? matnum - 1 : _current_mesh; - - if (chunk->get_library()->material_get(mindex).is_valid()) - VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_get(mindex)->get_rid()); + 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()); ++_current_mesh; } @@ -479,11 +476,8 @@ void TerraTerrarinJob::step_type_normal_lod() { VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - int matnum = chunk->get_library()->material_get_num(); - int mindex = matnum <= _current_mesh ? matnum - 1 : _current_mesh; - - if (chunk->get_library()->material_get(mindex).is_valid()) - VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_get(mindex)->get_rid()); + 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()); ++_current_mesh; } @@ -498,11 +492,8 @@ void TerraTerrarinJob::step_type_drop_uv2() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - int matnum = chunk->get_library()->material_get_num(); - int mindex = matnum <= _current_mesh ? matnum - 1 : _current_mesh; - - if (chunk->get_library()->material_get(mindex).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_get(mindex)->get_rid()); + 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()); ++_current_mesh; } @@ -517,11 +508,8 @@ void TerraTerrarinJob::step_type_merge_verts() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - int matnum = chunk->get_library()->material_get_num(); - int mindex = matnum <= _current_mesh ? matnum - 1 : _current_mesh; - - if (chunk->get_library()->material_get(mindex).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_get(mindex)->get_rid()); + 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()); ++_current_mesh; } @@ -529,8 +517,8 @@ void TerraTerrarinJob::step_type_merge_verts() { void TerraTerrarinJob::step_type_bake_texture() { Ref chunk = _chunk; - Ref mat = chunk->get_library()->material_get(0); - Ref spmat = chunk->get_library()->material_get(0); + Ref mat = chunk->get_library()->material_lod_get(0); + Ref spmat = chunk->get_library()->material_lod_get(0); Ref tex; if (mat.is_valid()) { @@ -547,11 +535,8 @@ void TerraTerrarinJob::step_type_bake_texture() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - int matnum = chunk->get_library()->material_get_num(); - int mindex = matnum <= _current_mesh ? matnum - 1 : _current_mesh; - - if (chunk->get_library()->material_get(mindex).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_get(mindex)->get_rid()); + 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()); } ++_current_mesh; @@ -577,11 +562,8 @@ void TerraTerrarinJob::step_type_simplify_mesh() { VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); - int matnum = chunk->get_library()->material_get_num(); - int mindex = matnum <= _current_mesh ? matnum - 1 : _current_mesh; - - if (chunk->get_library()->material_get(mindex).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->material_get(mindex)->get_rid()); + 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()); ++_current_mesh; }