From 8805d63f4a29adaf8ebe806ca11b3b9cc627652d Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 10 Aug 2021 09:28:06 +0200 Subject: [PATCH] Added a material_cache property to PropInstancePropJob. --- prop_instance_prop_job.cpp | 31 ++++++++++++++++++++----------- prop_instance_prop_job.h | 6 ++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/prop_instance_prop_job.cpp b/prop_instance_prop_job.cpp index 9382ca1..b3d9067 100644 --- a/prop_instance_prop_job.cpp +++ b/prop_instance_prop_job.cpp @@ -30,10 +30,11 @@ SOFTWARE. #define GET_WORLD get_world #endif +#include "jobs/prop_mesher_job_step.h" #include "prop_instance.h" #include "prop_instance_merger.h" #include "prop_mesher.h" -#include "jobs/prop_mesher_job_step.h" +#include "material_cache/prop_material_cache.h" #ifdef MESH_DATA_RESOURCE_PRESENT #include "../mesh_data_resource/mesh_data_resource.h" @@ -63,6 +64,13 @@ void PropInstancePropJob::set_texture_packer(const Ref &packer) { } #endif +Ref PropInstancePropJob::get_material_cache() { + return _material_cache; +} +void PropInstancePropJob::set_material_cache(const Ref &cache) { + _material_cache = cache; +} + Ref PropInstancePropJob::get_jobs_step(int index) const { ERR_FAIL_INDEX_V(index, _job_steps.size(), Ref()); @@ -85,7 +93,6 @@ int PropInstancePropJob::get_jobs_step_count() const { return _job_steps.size(); } - PropInstanceMerger *PropInstancePropJob::get_prop_instace() { return _prop_instace; } @@ -118,7 +125,6 @@ void PropInstancePropJob::clear_meshes() { #endif void PropInstancePropJob::phase_physics_process() { - //TODO this should only update the differences for (int i = 0; i < _prop_instace->collider_get_num(); ++i) { PhysicsServer::get_singleton()->free(_prop_instace->collider_body_get(i)); @@ -326,7 +332,6 @@ void PropInstancePropJob::phase_prop() { } if (should_do()) { - RID mesh_rid = _prop_instace->mesh_get(0); VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); @@ -614,7 +619,7 @@ void PropInstancePropJob::step_type_normal() { Ref lmat; -/* + /* if (chunk->prop_material_cache_key_has()) { lmat = chunk->get_library()->prop_material_cache_get(_chunk->prop_material_cache_key_get())->material_lod_get(_current_mesh); } else { @@ -644,7 +649,7 @@ void PropInstancePropJob::step_type_drop_uv2() { Ref lmat; -/* + /* if (chunk->prop_material_cache_key_has()) { lmat = chunk->get_library()->prop_material_cache_get(_chunk->prop_material_cache_key_get())->material_lod_get(_current_mesh); } else { @@ -669,7 +674,7 @@ void PropInstancePropJob::step_type_merge_verts() { Ref lmat; -/* + /* if (chunk->prop_material_cache_key_has()) { lmat = chunk->get_library()->prop_material_cache_get(_chunk->prop_material_cache_key_get())->material_lod_get(_current_mesh); } else { @@ -685,8 +690,8 @@ void PropInstancePropJob::step_type_merge_verts() { } void PropInstancePropJob::step_type_bake_texture() { - Ref mat;// = chunk->get_library()->material_lod_get(0); - Ref spmat;// = chunk->get_library()->material_lod_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()) { @@ -705,7 +710,7 @@ void PropInstancePropJob::step_type_bake_texture() { Ref lmat; -/* + /* if (chunk->prop_material_cache_key_has()) { lmat = chunk->get_library()->prop_material_cache_get(_chunk->prop_material_cache_key_get())->material_lod_get(_current_mesh); } else { @@ -741,7 +746,7 @@ void PropInstancePropJob::step_type_simplify_mesh() { Ref lmat; -/* + /* if (chunk->prop_material_cache_key_has()) { lmat = chunk->get_library()->prop_material_cache_get(_chunk->prop_material_cache_key_get())->material_lod_get(_current_mesh); } else { @@ -880,6 +885,10 @@ void PropInstancePropJob::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_packer", PROPERTY_HINT_RESOURCE_TYPE, "TexturePacker", 0), "set_texture_packer", "get_texture_packer"); #endif + ClassDB::bind_method(D_METHOD("get_material_cache"), &PropInstancePropJob::get_material_cache); + ClassDB::bind_method(D_METHOD("set_material_cache", "packer"), &PropInstancePropJob::set_material_cache); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_cache", PROPERTY_HINT_RESOURCE_TYPE, "PropMaterialCache", 0), "set_material_cache", "get_material_cache"); + ClassDB::bind_method(D_METHOD("get_jobs_step", "index"), &PropInstancePropJob::get_jobs_step); ClassDB::bind_method(D_METHOD("set_jobs_step", "index", "mesher"), &PropInstancePropJob::set_jobs_step); ClassDB::bind_method(D_METHOD("remove_jobs_step", "index"), &PropInstancePropJob::remove_jobs_step); diff --git a/prop_instance_prop_job.h b/prop_instance_prop_job.h index a25217c..768c971 100644 --- a/prop_instance_prop_job.h +++ b/prop_instance_prop_job.h @@ -33,6 +33,7 @@ class PropMesher; class PropInstance; class PropInstanceMerger; class PropMesherJobStep; +class PropMaterialCache; #if MESH_DATA_RESOURCE_PRESENT class PropDataMeshData; @@ -47,6 +48,9 @@ public: void set_texture_packer(const Ref &packer); #endif + Ref get_material_cache(); + void set_material_cache(const Ref &cache); + Ref get_jobs_step(const int index) const; void set_jobs_step(const int index, const Ref &step); void remove_jobs_step(const int index); @@ -102,6 +106,8 @@ protected: Ref _texture_packer; #endif + Ref _material_cache; + Vector> _job_steps; int _current_job_step; int _current_mesh;