Added a material_cache property to PropInstancePropJob.

This commit is contained in:
Relintai 2021-08-10 09:28:06 +02:00
parent f526e99239
commit 8805d63f4a
2 changed files with 26 additions and 11 deletions

View File

@ -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<TexturePacker> &packer) {
}
#endif
Ref<PropMaterialCache> PropInstancePropJob::get_material_cache() {
return _material_cache;
}
void PropInstancePropJob::set_material_cache(const Ref<PropMaterialCache> &cache) {
_material_cache = cache;
}
Ref<PropMesherJobStep> PropInstancePropJob::get_jobs_step(int index) const {
ERR_FAIL_INDEX_V(index, _job_steps.size(), Ref<PropMesherJobStep>());
@ -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<Material> 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<Material> 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<Material> 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<ShaderMaterial> mat;// = chunk->get_library()->material_lod_get(0);
Ref<SpatialMaterial> spmat;// = chunk->get_library()->material_lod_get(0);
Ref<ShaderMaterial> mat; // = chunk->get_library()->material_lod_get(0);
Ref<SpatialMaterial> spmat; // = chunk->get_library()->material_lod_get(0);
Ref<Texture> tex;
if (mat.is_valid()) {
@ -705,7 +710,7 @@ void PropInstancePropJob::step_type_bake_texture() {
Ref<Material> 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<Material> 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);

View File

@ -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<TexturePacker> &packer);
#endif
Ref<PropMaterialCache> get_material_cache();
void set_material_cache(const Ref<PropMaterialCache> &cache);
Ref<PropMesherJobStep> get_jobs_step(const int index) const;
void set_jobs_step(const int index, const Ref<PropMesherJobStep> &step);
void remove_jobs_step(const int index);
@ -102,6 +106,8 @@ protected:
Ref<TexturePacker> _texture_packer;
#endif
Ref<PropMaterialCache> _material_cache;
Vector<Ref<PropMesherJobStep>> _job_steps;
int _current_job_step;
int _current_mesh;