From e3e8db3ace08ba14c2e44837c877a480e7d380b2 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 02:02:13 +0300 Subject: [PATCH 1/8] Refactoring: improved working with prim_id inside IdData --- .../scene_delegate/blender_scene_delegate.cc | 64 +++++++++++----- .../scene_delegate/blender_scene_delegate.h | 25 ++++--- .../blender/render/hydra/scene_delegate/id.cc | 6 +- .../blender/render/hydra/scene_delegate/id.h | 7 +- .../render/hydra/scene_delegate/instancer.cc | 57 +++++++-------- .../render/hydra/scene_delegate/instancer.h | 11 +-- .../render/hydra/scene_delegate/light.cc | 11 +-- .../render/hydra/scene_delegate/light.h | 2 +- .../render/hydra/scene_delegate/material.cc | 22 ++---- .../render/hydra/scene_delegate/material.h | 8 +- .../render/hydra/scene_delegate/mesh.cc | 13 ++-- .../render/hydra/scene_delegate/mesh.h | 4 +- .../render/hydra/scene_delegate/object.cc | 73 +++++++++---------- .../render/hydra/scene_delegate/object.h | 7 +- .../render/hydra/scene_delegate/world.cc | 21 ++---- .../render/hydra/scene_delegate/world.h | 6 +- 16 files changed, 176 insertions(+), 161 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index d9c9cb912448..22e4b832971e 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -35,7 +35,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) return obj_data->transform(); } - if (id == WorldData::prim_id(this)) { + if (id == world_prim_id()) { return world_data_->transform(); } @@ -71,7 +71,7 @@ pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, if (l_data) { return l_data->get_data(key); } - if (id == WorldData::prim_id(this)) { + if (id == world_prim_id()) { return world_data_->get_data(key); } return pxr::VtValue(); @@ -111,7 +111,7 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { - if (id == WorldData::prim_id(this)) { + if (id == world_prim_id()) { return true; } @@ -187,7 +187,35 @@ void BlenderSceneDelegate::clear() materials_.clear(); } -ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) +pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const +{ + /* Making id of object in form like _ */ + char str[32]; + snprintf(str, 32, "%s_%016llx", prefix, (uint64_t)id); + return GetDelegateID().AppendElementString(str); +} + +pxr::SdfPath BlenderSceneDelegate::object_prim_id(Object *object) const +{ + return prim_id((ID *)object, "O"); +} + +pxr::SdfPath BlenderSceneDelegate::material_prim_id(Material *mat) const +{ + return prim_id((ID *)mat, "M"); +} + +pxr::SdfPath BlenderSceneDelegate::instancer_prim_id(Object *object) const +{ + return prim_id((ID *)object, "I"); +} + +pxr::SdfPath BlenderSceneDelegate::world_prim_id() const +{ + return GetDelegateID().AppendElementString("World"); +} + +ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const { auto it = objects_.find(id); if (it != objects_.end()) { @@ -200,17 +228,17 @@ ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) return nullptr; } -MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) +MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) const { return dynamic_cast(object_data(id)); } -LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) +LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) const { return dynamic_cast(object_data(id)); } -MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) +MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const { auto it = materials_.find(id); if (it == materials_.end()) { @@ -219,7 +247,7 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) return it->second.get(); } -InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id) +InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id) const { auto it = instancers_.find(id); if (it != instancers_.end()) { @@ -233,7 +261,7 @@ void BlenderSceneDelegate::update_objects(Object *object) if (!ObjectData::is_supported(object)) { return; } - pxr::SdfPath id = ObjectData::prim_id(this, object); + pxr::SdfPath id = object_prim_id(object); ObjectData *obj_data = object_data(id); if (obj_data) { obj_data->update(); @@ -242,7 +270,7 @@ void BlenderSceneDelegate::update_objects(Object *object) if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) { return; } - objects_[id] = ObjectData::create(this, object); + objects_[id] = ObjectData::create(this, object, id); obj_data = object_data(id); obj_data->update_visibility(view3d_); } @@ -254,7 +282,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) it.second->check_update(object); } - pxr::SdfPath id = InstancerData::prim_id(this, object); + pxr::SdfPath id = instancer_prim_id(object); InstancerData *i_data = instancer_data(id); if (i_data) { if (object->transflag & OB_DUPLI) { @@ -272,7 +300,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) { return; } - instancers_[id] = InstancerData::create(this, object); + instancers_[id] = InstancerData::create(this, object, id); i_data = instancer_data(id); i_data->update_visibility(view3d_); } @@ -282,7 +310,7 @@ void BlenderSceneDelegate::update_world() World *world = scene_->world; if (!world_data_) { if (world) { - world_data_ = WorldData::create(this, world, context_); + world_data_ = WorldData::create(this, world, world_prim_id()); } } else { @@ -343,7 +371,7 @@ void BlenderSceneDelegate::check_updates() } break; case ID_MA: { - MaterialData *mat_data = material_data(MaterialData::prim_id(this, (Material *)id)); + MaterialData *mat_data = material_data(material_prim_id((Material *)id)); if (mat_data) { mat_data->update(); } @@ -420,8 +448,8 @@ void BlenderSceneDelegate::remove_unused_objects() if (!ObjectData::is_supported(object)) { continue; } - available_objects.insert(ObjectData::prim_id(this, object).GetName()); - available_objects.insert(InstancerData::prim_id(this, object).GetName()); + available_objects.insert(object_prim_id(object).GetName()); + available_objects.insert(instancer_prim_id(object).GetName()); } ITER_END; @@ -501,10 +529,10 @@ void BlenderSceneDelegate::update_visibility() continue; } - if (!object_data(ObjectData::prim_id(this, object))) { + if (!object_data(object_prim_id(object))) { update_objects(object); } - if (!instancer_data(InstancerData::prim_id(this, object))) { + if (!instancer_data(instancer_prim_id(object))) { update_instancers(object); } } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 61eb66265657..d8c5d88d4ca4 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -52,13 +52,23 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void clear(); EngineType engine_type; + Depsgraph *depsgraph_ = nullptr; + bContext *context_ = nullptr; + View3D *view3d_ = nullptr; + Scene *scene_ = nullptr; private: - ObjectData *object_data(pxr::SdfPath const &id); - MeshData *mesh_data(pxr::SdfPath const &id); - LightData *light_data(pxr::SdfPath const &id); - MaterialData *material_data(pxr::SdfPath const &id); - InstancerData *instancer_data(pxr::SdfPath const &id); + pxr::SdfPath prim_id(ID *id, const char *prefix) const; + pxr::SdfPath object_prim_id(Object *object) const; + pxr::SdfPath material_prim_id(Material *mat) const; + pxr::SdfPath instancer_prim_id(Object *object) const; + pxr::SdfPath world_prim_id() const; + + ObjectData *object_data(pxr::SdfPath const &id) const; + MeshData *mesh_data(pxr::SdfPath const &id) const; + LightData *light_data(pxr::SdfPath const &id) const; + MaterialData *material_data(pxr::SdfPath const &id) const; + InstancerData *instancer_data(pxr::SdfPath const &id) const; void update_objects(Object *object); void update_instancers(Object *object); @@ -68,11 +78,6 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void remove_unused_objects(); void update_visibility(); - Depsgraph *depsgraph_ = nullptr; - bContext *context_ = nullptr; - View3D *view3d_ = nullptr; - Scene *scene_ = nullptr; - ObjectDataMap objects_; MaterialDataMap materials_; InstancerDataMap instancers_; diff --git a/source/blender/render/hydra/scene_delegate/id.cc b/source/blender/render/hydra/scene_delegate/id.cc index c2f048d796e0..e4032049d3fb 100644 --- a/source/blender/render/hydra/scene_delegate/id.cc +++ b/source/blender/render/hydra/scene_delegate/id.cc @@ -3,13 +3,13 @@ #include "BKE_lib_id.h" -#include "blender_scene_delegate.h" +//#include "blender_scene_delegate.h" #include "id.h" namespace blender::render::hydra { -IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) - : scene_delegate_(scene_delegate), id_(id) +IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id) + : id_(id), p_id_(prim_id), scene_delegate_(scene_delegate) { } diff --git a/source/blender/render/hydra/scene_delegate/id.h b/source/blender/render/hydra/scene_delegate/id.h index 15411cbb046f..d31272d1a5e8 100644 --- a/source/blender/render/hydra/scene_delegate/id.h +++ b/source/blender/render/hydra/scene_delegate/id.h @@ -18,7 +18,7 @@ class IdData { friend InstancerData; public: - IdData(BlenderSceneDelegate *scene_delegate, ID *id); + IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id); virtual ~IdData() = default; virtual void init() = 0; @@ -29,10 +29,11 @@ class IdData { virtual pxr::VtValue get_data(pxr::TfToken const &key) const; template const T get_data(pxr::TfToken const &key) const; - protected: - BlenderSceneDelegate *scene_delegate_; ID *id_; pxr::SdfPath p_id_; + + protected: + BlenderSceneDelegate *scene_delegate_; }; template const T IdData::get_data(pxr::TfToken const &key) const diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 87dadf4bd70f..c6e87ccc12b6 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -9,11 +9,21 @@ namespace blender::render::hydra { -InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object) - : ObjectData(scene_delegate, object) +InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id) + : ObjectData(scene_delegate, object, prim_id) { - p_id_ = prim_id(scene_delegate, object); - ID_LOG(2, ""); +} + +std::unique_ptr InstancerData::create(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id) +{ + auto data = std::make_unique(scene_delegate, object, prim_id); + data->init(); + data->insert(); + return data; } bool InstancerData::is_supported(Object *object) @@ -32,24 +42,6 @@ bool InstancerData::is_supported(Object *object) return false; } -std::unique_ptr InstancerData::create(BlenderSceneDelegate *scene_delegate, - Object *object) -{ - auto data = std::make_unique(scene_delegate, object); - data->init(); - data->insert(); - return data; -} - -pxr::SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object) -{ - /* Making id of instancer in form like I_. Example: - * I_000002073e369608 */ - char str[32]; - snprintf(str, 32, "I_%016llx", (uint64_t)object); - return scene_delegate->GetDelegateID().AppendElementString(str); -} - void InstancerData::init() { ID_LOG(2, ""); @@ -159,8 +151,7 @@ pxr::SdfPathVector InstancerData::prototypes() void InstancerData::check_update(Object *object) { - pxr::SdfPath path = ObjectData::prim_id(scene_delegate_, object); - path = p_id_.AppendElementString(path.GetName()); + pxr::SdfPath path = object_prim_id(object); auto it = instances_.find(path); if (it == instances_.end()) { return; @@ -207,6 +198,14 @@ void InstancerData::available_materials(std::set &paths) } } +pxr::SdfPath InstancerData::object_prim_id(Object *object) const +{ + /* Making id of object in form like _ */ + char str[32]; + snprintf(str, 32, "O_%016llx", (uint64_t)object); + return p_id_.AppendElementString(str); +} + void InstancerData::set_instances() { transforms_.clear(); @@ -219,8 +218,7 @@ void InstancerData::set_instances() ListBase *lb = object_duplilist(scene_delegate_->depsgraph_, scene_delegate_->scene_, (Object *)id_); LISTBASE_FOREACH (DupliObject *, dupli, lb) { - path = ObjectData::prim_id(scene_delegate_, dupli->ob); - path = p_id_.AppendElementString(path.GetName()); + path = object_prim_id(dupli->ob); auto it = instances_.find(path); if (it == instances_.end()) { inst = &instances_[path]; @@ -236,7 +234,7 @@ void InstancerData::set_instances() } transforms_.push_back(gf_matrix_from_transform(dupli->mat)); inst->indices.push_back(index); - ID_LOG(2, "Instance %s %d", inst->obj_data->id_->name, index); + ID_LOG(2, "%s %d", inst->obj_data->id_->name, index); ++index; } free_object_duplilist(lb); @@ -254,10 +252,9 @@ void InstancerData::set_instances() InstanceMeshData::InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, - pxr::SdfPath const &p_id) - : MeshData(scene_delegate, object) + pxr::SdfPath const &prim_id) + : MeshData(scene_delegate, object, prim_id) { - this->p_id_ = p_id; } pxr::GfMatrix4d InstanceMeshData::transform() diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index ddd23e6cc468..2b3d5f947717 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -18,12 +18,12 @@ class InstancerData : public ObjectData { }; public: - InstancerData(BlenderSceneDelegate *scene_delegate, Object *object); + InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); - static bool is_supported(Object *object); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, - Object *object); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); + Object *object, + pxr::SdfPath const &prim_id); + static bool is_supported(Object *object); void init() override; void insert() override; @@ -43,6 +43,7 @@ class InstancerData : public ObjectData { void available_materials(std::set &paths); private: + pxr::SdfPath object_prim_id(Object *object) const; void set_instances(); pxr::TfHashMap instances_; @@ -54,7 +55,7 @@ using InstancerDataMap = class InstanceMeshData : public MeshData { public: - InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &p_id); + InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); pxr::GfMatrix4d transform() override; }; diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index e54fd6f3e80d..5c468cfc90f4 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -14,10 +14,11 @@ namespace blender::render::hydra { -LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) - : ObjectData(scene_delegate, object) +LightData::LightData(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id) + : ObjectData(scene_delegate, object, prim_id) { - ID_LOG(2, ""); } void LightData::init() @@ -87,7 +88,7 @@ void LightData::init() void LightData::insert() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + ID_LOG(2, ""); scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_); } @@ -99,7 +100,7 @@ void LightData::remove() void LightData::update() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + ID_LOG(2, ""); Light *light = (Light *)((Object *)id_)->data; if (prim_type(light) != p_type_) { diff --git a/source/blender/render/hydra/scene_delegate/light.h b/source/blender/render/hydra/scene_delegate/light.h index 4aa91040e761..cce0a2bf7edf 100644 --- a/source/blender/render/hydra/scene_delegate/light.h +++ b/source/blender/render/hydra/scene_delegate/light.h @@ -15,7 +15,7 @@ namespace blender::render::hydra { class LightData : public ObjectData { public: - LightData(BlenderSceneDelegate *scene_delegate, Object *object); + LightData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); void init() override; void insert() override; diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index b385800f9b31..30c6ac064567 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -20,31 +20,23 @@ namespace blender::render::hydra { -MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) - : IdData(scene_delegate, (ID *)material) +MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, + Material *material, + pxr::SdfPath const &prim_id) + : IdData(scene_delegate, (ID *)material, prim_id) { - p_id_ = prim_id(scene_delegate, material); - ID_LOG(2, ""); } std::unique_ptr MaterialData::create(BlenderSceneDelegate *scene_delegate, - Material *material) + Material *material, + pxr::SdfPath const &prim_id) { - auto data = std::make_unique(scene_delegate, material); + auto data = std::make_unique(scene_delegate, material, prim_id); data->init(); data->insert(); return data; } -pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material) -{ - /* Making id of material in form like M_. - * Example: M_000002074e812088 */ - char str[32]; - snprintf(str, 32, "M_%016llx", (uint64_t)material); - return scene_delegate->GetDelegateID().AppendElementString(str); -} - void MaterialData::init() { ID_LOG(2, ""); diff --git a/source/blender/render/hydra/scene_delegate/material.h b/source/blender/render/hydra/scene_delegate/material.h index 1389fec8ade1..cf25151ae8f9 100644 --- a/source/blender/render/hydra/scene_delegate/material.h +++ b/source/blender/render/hydra/scene_delegate/material.h @@ -19,11 +19,13 @@ class MaterialData : IdData { friend MeshData; public: - MaterialData(BlenderSceneDelegate *scene_delegate, Material *material); + MaterialData(BlenderSceneDelegate *scene_delegate, + Material *material, + pxr::SdfPath const &prim_id); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, - Material *material); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material); + Material *material, + pxr::SdfPath const &prim_id); void init() override; void insert() override; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 5ad051e3895f..7dd11d4ef893 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -15,15 +15,16 @@ namespace blender::render::hydra { -MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) - : ObjectData(scene_delegate, object), mat_data_(nullptr) +MeshData::MeshData(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id) + : ObjectData(scene_delegate, object, prim_id) { - ID_LOG(2, ""); } void MeshData::init() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + ID_LOG(2, ""); Object *object = (Object *)id_; if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && @@ -215,10 +216,10 @@ void MeshData::write_material() mat_data_ = nullptr; return; } - pxr::SdfPath id = MaterialData::prim_id(scene_delegate_, mat); + pxr::SdfPath id = scene_delegate_->material_prim_id(mat); mat_data_ = scene_delegate_->material_data(id); if (!mat_data_) { - scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat); + scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat, id); mat_data_ = scene_delegate_->material_data(id); } } diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index c710c7317e8d..c5ad74f0210d 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -15,7 +15,7 @@ namespace blender::render::hydra { class MeshData : public ObjectData { public: - MeshData(BlenderSceneDelegate *scene_delegate, Object *object); + MeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); void init() override; void insert() override; @@ -42,7 +42,7 @@ class MeshData : public ObjectData { pxr::VtVec3fArray normals_; pxr::VtMatrix4dArray instances_; - MaterialData *mat_data_; + MaterialData *mat_data_ = nullptr; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 63f4f43177a7..3edb714eb07f 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -11,10 +11,40 @@ namespace blender::render::hydra { -ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) - : IdData(scene_delegate, (ID *)object), visible(true) +ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id) + : IdData(scene_delegate, (ID *)object, prim_id), visible(true) { - p_id_ = prim_id(scene_delegate, object); +} + +std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id) +{ + std::unique_ptr data; + + switch (object->type) { + case OB_MESH: + case OB_SURF: + case OB_FONT: + case OB_CURVES_LEGACY: + case OB_MBALL: + data = std::make_unique(scene_delegate, object, prim_id); + break; + + case OB_LAMP: + data = std::make_unique(scene_delegate, object, prim_id); + break; + + default: + break; + } + if (data) { + data->init(); + data->insert(); + } + return data; } bool ObjectData::is_supported(Object *object) @@ -34,43 +64,6 @@ bool ObjectData::is_supported(Object *object) return false; } -std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_delegate, - Object *object) -{ - std::unique_ptr data; - - switch (object->type) { - case OB_MESH: - case OB_SURF: - case OB_FONT: - case OB_CURVES_LEGACY: - case OB_MBALL: - data = std::make_unique(scene_delegate, object); - break; - - case OB_LAMP: - data = std::make_unique(scene_delegate, object); - break; - - default: - break; - } - if (data) { - data->init(); - data->insert(); - } - return data; -} - -pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object) -{ - /* Making id of object in form like O_. Example: - * O_000002073e369608 */ - char str[32]; - snprintf(str, 32, "O_%016llx", (uint64_t)object); - return scene_delegate->GetDelegateID().AppendElementString(str); -} - pxr::GfMatrix4d ObjectData::transform() { return gf_matrix_from_transform(((Object *)id_)->object_to_world); diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 4a60b5d64c59..78f850c425d1 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -16,11 +16,12 @@ namespace blender::render::hydra { class ObjectData : public IdData { public: - ObjectData(BlenderSceneDelegate *scene_delegate, Object *object); + ObjectData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); + static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id); static bool is_supported(Object *object); - static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Object *object); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); virtual pxr::GfMatrix4d transform(); virtual bool update_visibility(View3D *view3d); diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 33fc0a08612d..f15d4dd0fbc5 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -28,28 +28,23 @@ namespace blender::render::hydra { -WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) - : IdData(scene_delegate, (ID *)world), context_(context) +WorldData::WorldData(BlenderSceneDelegate *scene_delegate, + World *world, + pxr::SdfPath const &prim_id) + : IdData(scene_delegate, (ID *)world, prim_id) { - p_id_ = prim_id(scene_delegate); - ID_LOG(2, ""); } std::unique_ptr WorldData::create(BlenderSceneDelegate *scene_delegate, World *world, - bContext *context) + pxr::SdfPath const &prim_id) { - auto data = std::make_unique(scene_delegate, world, context); + auto data = std::make_unique(scene_delegate, world, prim_id); data->init(); data->insert(); return data; } -pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) -{ - return scene_delegate->GetDelegateID().AppendElementString("World"); -} - void WorldData::init() { ID_LOG(2, ""); @@ -101,8 +96,8 @@ void WorldData::init() Image *image = (Image *)color_input_node->id; if (image) { - Main *bmain = CTX_data_main(context_); - Scene *scene = CTX_data_scene(context_); + Main *bmain = CTX_data_main(scene_delegate_->context_); + Scene *scene = scene_delegate_->scene_; ReportList reports; ImageSaveOptions opts; diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 71924a7862bc..564842b7c850 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -20,12 +20,11 @@ namespace blender::render::hydra { class WorldData : public IdData { public: - WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); + WorldData(BlenderSceneDelegate *scene_delegate, World *world, pxr::SdfPath const &prim_id); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, World *world, - bContext *context); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate); + pxr::SdfPath const &prim_id); void init() override; void insert() override; @@ -38,7 +37,6 @@ class WorldData : public IdData { private: std::map data_; - bContext *context_; }; } // namespace blender::render::hydra -- 2.30.2 From 83bc3c1d673aa4c29fd0c2ee3de442cdc30a0882 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 02:13:23 +0300 Subject: [PATCH 2/8] Improved working with update_visibility(). Fixed crash with Storm delegate after closing viewport. --- source/blender/render/hydra/engine.h | 4 ++-- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 8 ++++---- .../render/hydra/scene_delegate/blender_scene_delegate.h | 1 - source/blender/render/hydra/scene_delegate/instancer.cc | 8 ++------ source/blender/render/hydra/scene_delegate/instancer.h | 2 +- source/blender/render/hydra/scene_delegate/light.cc | 4 ++-- source/blender/render/hydra/scene_delegate/light.h | 2 +- source/blender/render/hydra/scene_delegate/mesh.cc | 4 ++-- source/blender/render/hydra/scene_delegate/mesh.h | 2 +- source/blender/render/hydra/scene_delegate/object.cc | 6 +++--- source/blender/render/hydra/scene_delegate/object.h | 2 +- 11 files changed, 19 insertions(+), 24 deletions(-) diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 4de015e51ee1..07b65c8d5320 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -39,6 +39,8 @@ class Engine { RenderEngine *bl_engine_; /* The order is important due to deletion order */ + pxr::HgiUniquePtr hgi_; + pxr::HdDriver hgi_driver_; pxr::HdPluginRenderDelegateUniqueHandle render_delegate_; std::unique_ptr render_index_; std::unique_ptr scene_delegate_; @@ -47,8 +49,6 @@ class Engine { std::unique_ptr simple_light_task_delegate_; std::unique_ptr engine_; - pxr::HgiUniquePtr hgi_; - pxr::HdDriver hgi_driver_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 22e4b832971e..7e9819a4bc24 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -272,7 +272,7 @@ void BlenderSceneDelegate::update_objects(Object *object) } objects_[id] = ObjectData::create(this, object, id); obj_data = object_data(id); - obj_data->update_visibility(view3d_); + obj_data->update_visibility(); } void BlenderSceneDelegate::update_instancers(Object *object) @@ -302,7 +302,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) } instancers_[id] = InstancerData::create(this, object, id); i_data = instancer_data(id); - i_data->update_visibility(view3d_); + i_data->update_visibility(); } void BlenderSceneDelegate::update_world() @@ -503,10 +503,10 @@ void BlenderSceneDelegate::remove_unused_objects() void BlenderSceneDelegate::update_visibility() { for (auto &it : objects_) { - it.second->update_visibility(view3d_); + it.second->update_visibility(); } for (auto &it : instancers_) { - it.second->update_visibility(view3d_); + it.second->update_visibility(); } /* Add objects which were invisible before and not added yet */ diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index d8c5d88d4ca4..b543c6062084 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -22,7 +22,6 @@ extern struct CLG_LogRef *LOG_BSD; /* BSD - Blender Scene Delegate */ class BlenderSceneDelegate : public pxr::HdSceneDelegate { friend MeshData; - friend InstancerData; public: enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW }; diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index c6e87ccc12b6..dbb9e043287a 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -101,13 +101,9 @@ pxr::GfMatrix4d InstancerData::transform() return pxr::GfMatrix4d(1.0); } -bool InstancerData::update_visibility(View3D *view3d) +bool InstancerData::update_visibility() { - if (!view3d) { - return false; - } - - bool ret = ObjectData::update_visibility(view3d); + bool ret = ObjectData::update_visibility(); if (ret) { scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( p_id_, pxr::HdChangeTracker::DirtyVisibility); diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 2b3d5f947717..a9ab34f27194 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -32,7 +32,7 @@ class InstancerData : public ObjectData { pxr::VtValue get_data(pxr::TfToken const &key) const override; pxr::GfMatrix4d transform() override; - bool update_visibility(View3D *view3d) override; + bool update_visibility() override; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); pxr::VtIntArray indices(pxr::SdfPath const &id); diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 5c468cfc90f4..97a73d040d34 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -142,9 +142,9 @@ pxr::VtValue LightData::get_data(pxr::TfToken const &key) const return ret; } -bool LightData::update_visibility(View3D *view3d) +bool LightData::update_visibility() { - bool ret = ObjectData::update_visibility(view3d); + bool ret = ObjectData::update_visibility(); if (ret) { scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, pxr::HdLight::DirtyParams); diff --git a/source/blender/render/hydra/scene_delegate/light.h b/source/blender/render/hydra/scene_delegate/light.h index cce0a2bf7edf..2d9a04ad6636 100644 --- a/source/blender/render/hydra/scene_delegate/light.h +++ b/source/blender/render/hydra/scene_delegate/light.h @@ -23,7 +23,7 @@ class LightData : public ObjectData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - bool update_visibility(View3D *view3d) override; + bool update_visibility() override; private: pxr::TfToken prim_type(Light *light); diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 7dd11d4ef893..999d9abfea3e 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -117,9 +117,9 @@ pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const return ret; } -bool MeshData::update_visibility(View3D *view3d) +bool MeshData::update_visibility() { - bool ret = ObjectData::update_visibility(view3d); + bool ret = ObjectData::update_visibility(); if (ret) { scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( p_id_, pxr::HdChangeTracker::DirtyVisibility); diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index c5ad74f0210d..6a4051ab0232 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -23,7 +23,7 @@ class MeshData : public ObjectData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - bool update_visibility(View3D *view3d) override; + bool update_visibility() override; pxr::HdMeshTopology mesh_topology(); pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 3edb714eb07f..a29648263b10 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -69,14 +69,14 @@ pxr::GfMatrix4d ObjectData::transform() return gf_matrix_from_transform(((Object *)id_)->object_to_world); } -bool ObjectData::update_visibility(View3D *view3d) +bool ObjectData::update_visibility() { - if (!view3d) { + if (!scene_delegate_->view3d_) { return false; } bool prev_visible = visible; - visible = BKE_object_is_visible_in_viewport(view3d, (Object *)id_); + visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d_, (Object *)id_); bool ret = visible != prev_visible; if (ret) { ID_LOG(2, ""); diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 78f850c425d1..513843286d27 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -24,7 +24,7 @@ class ObjectData : public IdData { static bool is_supported(Object *object); virtual pxr::GfMatrix4d transform(); - virtual bool update_visibility(View3D *view3d); + virtual bool update_visibility(); bool visible; }; -- 2.30.2 From d70e059988848987e340b53fd0505710355bec75 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 02:20:30 +0300 Subject: [PATCH 3/8] Removed some friends --- .../render/hydra/scene_delegate/blender_scene_delegate.h | 2 +- source/blender/render/hydra/scene_delegate/id.h | 3 --- source/blender/render/hydra/scene_delegate/instancer.h | 2 -- source/blender/render/hydra/scene_delegate/material.h | 6 +----- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index b543c6062084..1ad875e236ac 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -21,7 +21,7 @@ namespace blender::render::hydra { extern struct CLG_LogRef *LOG_BSD; /* BSD - Blender Scene Delegate */ class BlenderSceneDelegate : public pxr::HdSceneDelegate { - friend MeshData; + friend MeshData; /* has access to materials_*/ public: enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW }; diff --git a/source/blender/render/hydra/scene_delegate/id.h b/source/blender/render/hydra/scene_delegate/id.h index d31272d1a5e8..93336f9b8314 100644 --- a/source/blender/render/hydra/scene_delegate/id.h +++ b/source/blender/render/hydra/scene_delegate/id.h @@ -12,11 +12,8 @@ namespace blender::render::hydra { class BlenderSceneDelegate; -class InstancerData; class IdData { - friend InstancerData; - public: IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id); virtual ~IdData() = default; diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index a9ab34f27194..b8222214a08f 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -10,8 +10,6 @@ namespace blender::render::hydra { class InstancerData : public ObjectData { - friend BlenderSceneDelegate; - struct Instance { std::unique_ptr obj_data; pxr::VtIntArray indices; diff --git a/source/blender/render/hydra/scene_delegate/material.h b/source/blender/render/hydra/scene_delegate/material.h index cf25151ae8f9..df97af4f614f 100644 --- a/source/blender/render/hydra/scene_delegate/material.h +++ b/source/blender/render/hydra/scene_delegate/material.h @@ -13,11 +13,7 @@ namespace blender::render::hydra { -class MeshData; - -class MaterialData : IdData { - friend MeshData; - +class MaterialData : public IdData { public: MaterialData(BlenderSceneDelegate *scene_delegate, Material *material, -- 2.30.2 From 724409e318ddd7a58df28bd166c9729223436094 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 02:31:15 +0300 Subject: [PATCH 4/8] Renaming --- .../scene_delegate/blender_scene_delegate.cc | 32 +++++++++---------- .../scene_delegate/blender_scene_delegate.h | 8 ++--- .../blender/render/hydra/scene_delegate/id.cc | 2 +- .../blender/render/hydra/scene_delegate/id.h | 6 ++-- .../render/hydra/scene_delegate/instancer.cc | 28 ++++++++-------- .../render/hydra/scene_delegate/light.cc | 18 +++++------ .../render/hydra/scene_delegate/material.cc | 16 +++++----- .../render/hydra/scene_delegate/mesh.cc | 32 +++++++++---------- .../render/hydra/scene_delegate/object.cc | 6 ++-- .../render/hydra/scene_delegate/world.cc | 16 +++++----- 10 files changed, 82 insertions(+), 82 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 7e9819a4bc24..8d774120daac 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -123,7 +123,7 @@ pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id) CLOG_INFO(LOG_BSD, 3, "%s", prim_id.GetText()); InstancerData *i_data = instancer_data(prim_id.GetParentPath()); if (i_data) { - return i_data->p_id_; + return i_data->prim_id; } return pxr::SdfPath(); } @@ -152,12 +152,12 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const & void BlenderSceneDelegate::populate(Depsgraph * deps, bContext * cont) { - bool is_populated = depsgraph_ != nullptr; + bool is_populated = depsgraph != nullptr; - depsgraph_ = deps; - context_ = cont; - scene_ = DEG_get_input_scene(depsgraph_); - view3d_ = CTX_wm_view3d(context_); + depsgraph = deps; + context = cont; + scene = DEG_get_input_scene(depsgraph); + view3d = CTX_wm_view3d(context); if (is_populated) { check_updates(); @@ -267,7 +267,7 @@ void BlenderSceneDelegate::update_objects(Object *object) obj_data->update(); return; } - if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) { + if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { return; } objects_[id] = ObjectData::create(this, object, id); @@ -297,7 +297,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) if ((object->transflag & OB_DUPLI) == 0) { return; } - if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) { + if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { return; } instancers_[id] = InstancerData::create(this, object, id); @@ -307,7 +307,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) void BlenderSceneDelegate::update_world() { - World *world = scene_->world; + World *world = scene->world; if (!world_data_) { if (world) { world_data_ = WorldData::create(this, world, world_prim_id()); @@ -331,13 +331,13 @@ void BlenderSceneDelegate::check_updates() bool do_update_visibility = false; bool do_update_world = false; - unsigned int scene_recalc = scene_->id.recalc; + unsigned int scene_recalc = scene->id.recalc; if (scene_recalc) { /* Checking scene updates */ CLOG_INFO(LOG_BSD, 2, "Update: %s [%s]", - ((ID *)scene_)->name, + ((ID *)scene)->name, std::bitset<32>(scene_recalc).to_string().c_str()); if (scene_recalc & ID_RECALC_BASE_FLAGS) { @@ -347,7 +347,7 @@ void BlenderSceneDelegate::check_updates() do_update_collection = true; } if (scene_recalc & ID_RECALC_AUDIO_VOLUME) { - if ((scene_->world && !world_data_) || (!scene_->world && world_data_)) { + if ((scene->world && !world_data_) || (!scene->world && world_data_)) { do_update_world = true; } } @@ -355,7 +355,7 @@ void BlenderSceneDelegate::check_updates() /* Checking other objects updates */ DEGIDIterData data = {0}; - data.graph = depsgraph_; + data.graph = depsgraph; data.only_updated = true; ITER_BEGIN ( DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { @@ -403,7 +403,7 @@ void BlenderSceneDelegate::check_updates() void BlenderSceneDelegate::add_new_objects() { DEGObjectIterSettings settings = {0}; - settings.depsgraph = depsgraph_; + settings.depsgraph = depsgraph; settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; DEGObjectIterData data = {0}; @@ -433,7 +433,7 @@ void BlenderSceneDelegate::remove_unused_objects() std::set available_objects; DEGObjectIterSettings settings = {0}; - settings.depsgraph = depsgraph_; + settings.depsgraph = depsgraph; settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; DEGObjectIterData data = {0}; data.settings = &settings; @@ -511,7 +511,7 @@ void BlenderSceneDelegate::update_visibility() /* Add objects which were invisible before and not added yet */ DEGObjectIterSettings settings = {0}; - settings.depsgraph = depsgraph_; + settings.depsgraph = depsgraph; settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; DEGObjectIterData data = {0}; diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 1ad875e236ac..7db71c2de335 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -51,10 +51,10 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void clear(); EngineType engine_type; - Depsgraph *depsgraph_ = nullptr; - bContext *context_ = nullptr; - View3D *view3d_ = nullptr; - Scene *scene_ = nullptr; + Depsgraph *depsgraph = nullptr; + bContext *context = nullptr; + View3D *view3d = nullptr; + Scene *scene = nullptr; private: pxr::SdfPath prim_id(ID *id, const char *prefix) const; diff --git a/source/blender/render/hydra/scene_delegate/id.cc b/source/blender/render/hydra/scene_delegate/id.cc index e4032049d3fb..7a84eaee8eb1 100644 --- a/source/blender/render/hydra/scene_delegate/id.cc +++ b/source/blender/render/hydra/scene_delegate/id.cc @@ -9,7 +9,7 @@ namespace blender::render::hydra { IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id) - : id_(id), p_id_(prim_id), scene_delegate_(scene_delegate) + : id(id), prim_id(prim_id), scene_delegate_(scene_delegate) { } diff --git a/source/blender/render/hydra/scene_delegate/id.h b/source/blender/render/hydra/scene_delegate/id.h index 93336f9b8314..8fbd202e947e 100644 --- a/source/blender/render/hydra/scene_delegate/id.h +++ b/source/blender/render/hydra/scene_delegate/id.h @@ -26,8 +26,8 @@ class IdData { virtual pxr::VtValue get_data(pxr::TfToken const &key) const; template const T get_data(pxr::TfToken const &key) const; - ID *id_; - pxr::SdfPath p_id_; + ID *id; + pxr::SdfPath prim_id; protected: BlenderSceneDelegate *scene_delegate_; @@ -39,6 +39,6 @@ template const T IdData::get_data(pxr::TfToken const &key) const } #define ID_LOG(level, msg, ...) \ - CLOG_INFO(LOG_BSD, level, "%s (%s): " msg, p_id_.GetText(), id_->name, __VA_ARGS__); + CLOG_INFO(LOG_BSD, level, "%s (%s): " msg, prim_id.GetText(), id->name, __VA_ARGS__); } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index dbb9e043287a..8a6d60d0b3dc 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -51,7 +51,7 @@ void InstancerData::init() void InstancerData::insert() { ID_LOG(2, ""); - scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, p_id_); + scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, prim_id); for (auto &it : instances_) { it.second.obj_data->insert(); } @@ -59,11 +59,11 @@ void InstancerData::insert() void InstancerData::remove() { - CLOG_INFO(LOG_BSD, 2, "%s", p_id_.GetText()); + CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); for (auto &it : instances_) { it.second.obj_data->remove(); } - scene_delegate_->GetRenderIndex().RemoveInstancer(p_id_); + scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id); } void InstancerData::update() @@ -72,17 +72,17 @@ void InstancerData::update() pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; - Object *object = (Object *)id_; - if ((id_->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { + Object *object = (Object *)id; + if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { set_instances(); bits |= pxr::HdChangeTracker::AllDirty; } - else if (id_->recalc & ID_RECALC_TRANSFORM) { + else if (id->recalc & ID_RECALC_TRANSFORM) { set_instances(); bits |= pxr::HdChangeTracker::DirtyTransform; } if (bits != pxr::HdChangeTracker::Clean) { - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id_, bits); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(prim_id, bits); } } @@ -106,11 +106,11 @@ bool InstancerData::update_visibility() bool ret = ObjectData::update_visibility(); if (ret) { scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( - p_id_, pxr::HdChangeTracker::DirtyVisibility); + prim_id, pxr::HdChangeTracker::DirtyVisibility); for (auto &it : instances_) { it.second.obj_data->visible = visible; scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( - it.second.obj_data->p_id_, pxr::HdChangeTracker::DirtyVisibility); + it.second.obj_data->prim_id, pxr::HdChangeTracker::DirtyVisibility); } } return ret; @@ -161,7 +161,7 @@ void InstancerData::check_update(Object *object) bits |= pxr::HdChangeTracker::DirtyTransform; } if (bits != pxr::HdChangeTracker::Clean) { - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id_, bits); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(prim_id, bits); } } @@ -179,7 +179,7 @@ void InstancerData::check_remove(std::set &available_objects) } if (ret) { set_instances(); - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id_, + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(prim_id, pxr::HdChangeTracker::AllDirty); } } @@ -199,7 +199,7 @@ pxr::SdfPath InstancerData::object_prim_id(Object *object) const /* Making id of object in form like _ */ char str[32]; snprintf(str, 32, "O_%016llx", (uint64_t)object); - return p_id_.AppendElementString(str); + return prim_id.AppendElementString(str); } void InstancerData::set_instances() @@ -212,7 +212,7 @@ void InstancerData::set_instances() Instance *inst; pxr::SdfPath path; - ListBase *lb = object_duplilist(scene_delegate_->depsgraph_, scene_delegate_->scene_, (Object *)id_); + ListBase *lb = object_duplilist(scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { path = object_prim_id(dupli->ob); auto it = instances_.find(path); @@ -230,7 +230,7 @@ void InstancerData::set_instances() } transforms_.push_back(gf_matrix_from_transform(dupli->mat)); inst->indices.push_back(index); - ID_LOG(2, "%s %d", inst->obj_data->id_->name, index); + ID_LOG(2, "%s %d", inst->obj_data->id->name, index); ++index; } free_object_duplilist(lb); diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 97a73d040d34..c29a52bb4454 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -25,7 +25,7 @@ void LightData::init() { ID_LOG(2, ""); - Light *light = (Light *)((Object *)id_)->data; + Light *light = (Light *)((Object *)id)->data; data_.clear(); float intensity = light->energy; @@ -89,20 +89,20 @@ void LightData::init() void LightData::insert() { ID_LOG(2, ""); - scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_); + scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, prim_id); } void LightData::remove() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, p_id_); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); + scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, prim_id); } void LightData::update() { ID_LOG(2, ""); - Light *light = (Light *)((Object *)id_)->data; + Light *light = (Light *)((Object *)id)->data; if (prim_type(light) != p_type_) { remove(); init(); @@ -111,14 +111,14 @@ void LightData::update() } pxr::HdDirtyBits bits = pxr::HdLight::Clean; - if (id_->recalc & ID_RECALC_GEOMETRY) { + if (id->recalc & ID_RECALC_GEOMETRY) { init(); bits = pxr::HdLight::AllDirty; } - else if (id_->recalc & ID_RECALC_TRANSFORM) { + else if (id->recalc & ID_RECALC_TRANSFORM) { bits = pxr::HdLight::DirtyTransform; } - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, bits); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits); } pxr::VtValue LightData::get_data(pxr::TfToken const &key) const @@ -146,7 +146,7 @@ bool LightData::update_visibility() { bool ret = ObjectData::update_visibility(); if (ret) { - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, pxr::HdLight::DirtyParams); } return ret; diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 30c6ac064567..66d3dea23124 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -54,7 +54,7 @@ void MaterialData::init() func = PyDict_GetItemString(dict, "export_mtlx"); PointerRNA materialptr; - RNA_pointer_create(NULL, &RNA_Material, id_, &materialptr); + RNA_pointer_create(NULL, &RNA_Material, id, &materialptr); PyObject *material = pyrna_struct_CreatePyObject(&materialptr); result = PyObject_CallFunction(func, "O", material); @@ -68,7 +68,7 @@ void MaterialData::init() Py_DECREF(result); } else { - CLOG_ERROR(LOG_BSD, "Export error for %s", id_->name); + CLOG_ERROR(LOG_BSD, "Export error for %s", id->name); PyErr_Print(); } Py_DECREF(module); @@ -81,22 +81,22 @@ void MaterialData::init() void MaterialData::insert() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); scene_delegate_->GetRenderIndex().InsertSprim( - pxr::HdPrimTypeTokens->material, scene_delegate_, p_id_); + pxr::HdPrimTypeTokens->material, scene_delegate_, prim_id); } void MaterialData::remove() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id_); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); + scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id); } void MaterialData::update() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); init(); - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, pxr::HdMaterial::AllDirty); } diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 999d9abfea3e..730c5f15f470 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -26,7 +26,7 @@ void MeshData::init() { ID_LOG(2, ""); - Object *object = (Object *)id_; + Object *object = (Object *)id; if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && BLI_listbase_is_empty(&object->modifiers)) { write_mesh((Mesh *)object->data); @@ -48,35 +48,35 @@ void MeshData::insert() return; } - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); scene_delegate_->GetRenderIndex().InsertRprim( - pxr::HdPrimTypeTokens->mesh, scene_delegate_, p_id_); + pxr::HdPrimTypeTokens->mesh, scene_delegate_, prim_id); } void MeshData::remove() { - if (!scene_delegate_->GetRenderIndex().HasRprim(p_id_)) { + if (!scene_delegate_->GetRenderIndex().HasRprim(prim_id)) { return; } - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - scene_delegate_->GetRenderIndex().RemoveRprim(p_id_); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); + scene_delegate_->GetRenderIndex().RemoveRprim(prim_id); } void MeshData::update() { pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; - Object *object = (Object *)id_; - if ((id_->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { + Object *object = (Object *)id; + if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { init(); bits = pxr::HdChangeTracker::AllDirty; } else { - if (id_->recalc & ID_RECALC_SHADING) { + if (id->recalc & ID_RECALC_SHADING) { write_material(); bits |= pxr::HdChangeTracker::DirtyMaterialId; } - if (id_->recalc & ID_RECALC_TRANSFORM) { + if (id->recalc & ID_RECALC_TRANSFORM) { bits |= pxr::HdChangeTracker::DirtyTransform; } } @@ -85,7 +85,7 @@ void MeshData::update() return; } - if (!scene_delegate_->GetRenderIndex().HasRprim(p_id_)) { + if (!scene_delegate_->GetRenderIndex().HasRprim(prim_id)) { insert(); return; } @@ -95,8 +95,8 @@ void MeshData::update() remove(); return; } - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(p_id_, bits); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(prim_id, bits); } pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const @@ -122,7 +122,7 @@ bool MeshData::update_visibility() bool ret = ObjectData::update_visibility(); if (ret) { scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( - p_id_, pxr::HdChangeTracker::DirtyVisibility); + prim_id, pxr::HdChangeTracker::DirtyVisibility); } return ret; } @@ -162,7 +162,7 @@ pxr::SdfPath MeshData::material_id() if (!mat_data_) { return pxr::SdfPath(); } - return mat_data_->p_id_; + return mat_data_->prim_id; } void MeshData::write_mesh(Mesh *mesh) @@ -206,7 +206,7 @@ void MeshData::write_mesh(Mesh *mesh) void MeshData::write_material() { - Object *object = (Object *)id_; + Object *object = (Object *)id; Material *mat = nullptr; if (BKE_object_material_count_eval(object) > 0) { mat = BKE_object_material_get_eval(object, object->actcol); diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index a29648263b10..7af6a78257f3 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -66,17 +66,17 @@ bool ObjectData::is_supported(Object *object) pxr::GfMatrix4d ObjectData::transform() { - return gf_matrix_from_transform(((Object *)id_)->object_to_world); + return gf_matrix_from_transform(((Object *)id)->object_to_world); } bool ObjectData::update_visibility() { - if (!scene_delegate_->view3d_) { + if (!scene_delegate_->view3d) { return false; } bool prev_visible = visible; - visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d_, (Object *)id_); + visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, (Object *)id); bool ret = visible != prev_visible; if (ret) { ID_LOG(2, ""); diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index f15d4dd0fbc5..12685d7ab38a 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -49,7 +49,7 @@ void WorldData::init() { ID_LOG(2, ""); - World *world = (World *)id_; + World *world = (World *)id; data_.clear(); data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; @@ -96,8 +96,8 @@ void WorldData::init() Image *image = (Image *)color_input_node->id; if (image) { - Main *bmain = CTX_data_main(scene_delegate_->context_); - Scene *scene = scene_delegate_->scene_; + Main *bmain = CTX_data_main(scene_delegate_->context); + Scene *scene = scene_delegate_->scene; ReportList reports; ImageSaveOptions opts; @@ -122,26 +122,26 @@ void WorldData::insert() { ID_LOG(2, ""); scene_delegate_->GetRenderIndex().InsertSprim( - pxr::HdPrimTypeTokens->domeLight, scene_delegate_, p_id_); + pxr::HdPrimTypeTokens->domeLight, scene_delegate_, prim_id); } void WorldData::remove() { - CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id_); + CLOG_INFO(LOG_BSD, 2, "%s", id->name); + scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id); } void WorldData::update() { ID_LOG(2, ""); init(); - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, pxr::HdLight::AllDirty); } void WorldData::update(World *world) { - id_ = (ID *)world; + id = (ID *)world; update(); } -- 2.30.2 From b9f0befc8aec7e9a4a01fcc7bbf245ed8c830103 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 03:01:11 +0300 Subject: [PATCH 5/8] Added const to some methods. Moved calculation of material_resource to MaterialData::init(). --- .../render/hydra/scene_delegate/instancer.cc | 14 +++---- .../render/hydra/scene_delegate/instancer.h | 10 ++--- .../render/hydra/scene_delegate/light.cc | 2 +- .../render/hydra/scene_delegate/material.cc | 38 +++++++++---------- .../render/hydra/scene_delegate/material.h | 2 +- .../render/hydra/scene_delegate/mesh.cc | 20 +++++----- .../render/hydra/scene_delegate/mesh.h | 6 +-- .../render/hydra/scene_delegate/world.cc | 2 +- 8 files changed, 47 insertions(+), 47 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 8a6d60d0b3dc..af954ead0031 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -116,7 +116,7 @@ bool InstancerData::update_visibility() return ret; } -pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpolation interpolation) const { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationInstance) { @@ -126,17 +126,17 @@ pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpo return primvars; } -pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id) +pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id) const { - return instances_[id].indices; + return instances_.find(id)->second.indices; } -ObjectData *InstancerData::object_data(pxr::SdfPath const &id) +ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const { - return instances_[id].obj_data.get(); + return instances_.find(id)->second.obj_data.get(); } -pxr::SdfPathVector InstancerData::prototypes() +pxr::SdfPathVector InstancerData::prototypes() const { pxr::SdfPathVector paths; for (auto &it : instances_) { @@ -184,7 +184,7 @@ void InstancerData::check_remove(std::set &available_objects) } } -void InstancerData::available_materials(std::set &paths) +void InstancerData::available_materials(std::set &paths) const { for (auto &it : instances_) { pxr::SdfPath mat_id = ((MeshData *)it.second.obj_data.get())->material_id(); diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index b8222214a08f..d6c6dbc0baa1 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -32,13 +32,13 @@ class InstancerData : public ObjectData { pxr::GfMatrix4d transform() override; bool update_visibility() override; - pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); - pxr::VtIntArray indices(pxr::SdfPath const &id); - ObjectData *object_data(pxr::SdfPath const &id); - pxr::SdfPathVector prototypes(); + pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; + pxr::VtIntArray indices(pxr::SdfPath const &id) const; + ObjectData *object_data(pxr::SdfPath const &id) const; + pxr::SdfPathVector prototypes() const; void check_update(Object *object); void check_remove(std::set &available_objects); - void available_materials(std::set &paths); + void available_materials(std::set &paths) const; private: pxr::SdfPath object_prim_id(Object *object) const; diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index c29a52bb4454..3ad09d9b84d4 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -94,7 +94,7 @@ void LightData::insert() void LightData::remove() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, prim_id); } diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 66d3dea23124..2d5071d938f7 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -77,24 +77,39 @@ void MaterialData::init() mtlx_path_ = pxr::SdfAssetPath(path, path); ID_LOG(2, "mtlx=%s", mtlx_path_.GetResolvedPath().c_str()); + + /* Calculate material network map */ + if (!path.empty()) { + pxr::HdRenderDelegate *render_delegate = scene_delegate_->GetRenderIndex().GetRenderDelegate(); + pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes(); + pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); + + pxr::HdMaterialNetworkMap network_map; + hdmtlx_convert_to_materialnetworkmap(path, shader_source_types, render_contexts, &network_map); + + material_network_map_ = network_map; + } + else { + material_network_map_ = pxr::VtValue(); + } } void MaterialData::insert() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + ID_LOG(2, ""); scene_delegate_->GetRenderIndex().InsertSprim( pxr::HdPrimTypeTokens->material, scene_delegate_, prim_id); } void MaterialData::remove() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id); } void MaterialData::update() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + ID_LOG(2, ""); init(); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, pxr::HdMaterial::AllDirty); @@ -112,23 +127,8 @@ pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const return ret; } -pxr::VtValue MaterialData::get_material_resource() +pxr::VtValue MaterialData::get_material_resource() const { - if (material_network_map_.IsEmpty()) { - const std::string &path = mtlx_path_.GetResolvedPath(); - if (!path.empty()) { - pxr::HdRenderDelegate *render_delegate = - scene_delegate_->GetRenderIndex().GetRenderDelegate(); - pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes(); - pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); - - pxr::HdMaterialNetworkMap network_map; - hdmtlx_convert_to_materialnetworkmap( - path, shader_source_types, render_contexts, &network_map); - - material_network_map_ = network_map; - } - } return material_network_map_; } diff --git a/source/blender/render/hydra/scene_delegate/material.h b/source/blender/render/hydra/scene_delegate/material.h index df97af4f614f..2f6371cd3438 100644 --- a/source/blender/render/hydra/scene_delegate/material.h +++ b/source/blender/render/hydra/scene_delegate/material.h @@ -29,7 +29,7 @@ class MaterialData : public IdData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - pxr::VtValue get_material_resource(); + pxr::VtValue get_material_resource() const; private: pxr::SdfAssetPath mtlx_path_; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 730c5f15f470..db497506c8f5 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -48,7 +48,7 @@ void MeshData::insert() return; } - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + ID_LOG(2, ""); scene_delegate_->GetRenderIndex().InsertRprim( pxr::HdPrimTypeTokens->mesh, scene_delegate_, prim_id); } @@ -59,7 +59,7 @@ void MeshData::remove() return; } - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); scene_delegate_->GetRenderIndex().RemoveRprim(prim_id); } @@ -95,7 +95,7 @@ void MeshData::update() remove(); return; } - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + ID_LOG(2, ""); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(prim_id, bits); } @@ -127,7 +127,7 @@ bool MeshData::update_visibility() return ret; } -pxr::HdMeshTopology MeshData::mesh_topology() +pxr::HdMeshTopology MeshData::mesh_topology() const { return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none, pxr::HdTokens->rightHanded, @@ -135,7 +135,7 @@ pxr::HdMeshTopology MeshData::mesh_topology() face_vertex_indices_); } -pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) const { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationVertex) { @@ -157,7 +157,7 @@ pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolatio return primvars; } -pxr::SdfPath MeshData::material_id() +pxr::SdfPath MeshData::material_id() const { if (!mat_data_) { return pxr::SdfPath(); @@ -216,11 +216,11 @@ void MeshData::write_material() mat_data_ = nullptr; return; } - pxr::SdfPath id = scene_delegate_->material_prim_id(mat); - mat_data_ = scene_delegate_->material_data(id); + pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat); + mat_data_ = scene_delegate_->material_data(p_id); if (!mat_data_) { - scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat, id); - mat_data_ = scene_delegate_->material_data(id); + scene_delegate_->materials_[p_id] = MaterialData::create(scene_delegate_, mat, p_id); + mat_data_ = scene_delegate_->material_data(p_id); } } diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index 6a4051ab0232..459411bc6a52 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -25,9 +25,9 @@ class MeshData : public ObjectData { pxr::VtValue get_data(pxr::TfToken const &key) const override; bool update_visibility() override; - pxr::HdMeshTopology mesh_topology(); - pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); - pxr::SdfPath material_id(); + pxr::HdMeshTopology mesh_topology() const; + pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; + pxr::SdfPath material_id() const; protected: void write_mesh(Mesh *mesh); diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 12685d7ab38a..8f2930a7836b 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -127,7 +127,7 @@ void WorldData::insert() void WorldData::remove() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id); } -- 2.30.2 From d170b0eaf2eaca4308e006d6522d7ab67d31eeef Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 03:07:54 +0300 Subject: [PATCH 6/8] make format --- source/blender/render/hydra/engine.h | 1 - .../hydra/scene_delegate/blender_scene_delegate.cc | 2 +- .../blender/render/hydra/scene_delegate/instancer.cc | 10 ++++++---- source/blender/render/hydra/scene_delegate/instancer.h | 4 +++- source/blender/render/hydra/scene_delegate/light.cc | 8 ++++---- source/blender/render/hydra/scene_delegate/light.h | 2 +- source/blender/render/hydra/scene_delegate/mesh.cc | 3 ++- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 07b65c8d5320..2f129a6fb4e8 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -48,7 +48,6 @@ class Engine { std::unique_ptr free_camera_delegate_; std::unique_ptr simple_light_task_delegate_; std::unique_ptr engine_; - }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 8d774120daac..b94964b73b76 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -150,7 +150,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const & return i_data->transform(); } -void BlenderSceneDelegate::populate(Depsgraph * deps, bContext * cont) +void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) { bool is_populated = depsgraph != nullptr; diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index af954ead0031..3b0d5728b96f 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -116,7 +116,8 @@ bool InstancerData::update_visibility() return ret; } -pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpolation interpolation) const +pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors( + pxr::HdInterpolation interpolation) const { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationInstance) { @@ -179,8 +180,8 @@ void InstancerData::check_remove(std::set &available_objects) } if (ret) { set_instances(); - scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(prim_id, - pxr::HdChangeTracker::AllDirty); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( + prim_id, pxr::HdChangeTracker::AllDirty); } } @@ -212,7 +213,8 @@ void InstancerData::set_instances() Instance *inst; pxr::SdfPath path; - ListBase *lb = object_duplilist(scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); + ListBase *lb = object_duplilist( + scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { path = object_prim_id(dupli->ob); auto it = instances_.find(path); diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index d6c6dbc0baa1..02c1b01c7f8f 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -53,7 +53,9 @@ using InstancerDataMap = class InstanceMeshData : public MeshData { public: - InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); + InstanceMeshData(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id); pxr::GfMatrix4d transform() override; }; diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 3ad09d9b84d4..d1ac864bff91 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -80,7 +80,7 @@ void LightData::init() break; } - p_type_ = prim_type(light); + prim_type_ = prim_type(light); /* TODO: temporary value, it should be delivered through Python UI */ data_[pxr::HdLightTokens->exposure] = 1.0f; @@ -89,13 +89,13 @@ void LightData::init() void LightData::insert() { ID_LOG(2, ""); - scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, prim_id); + scene_delegate_->GetRenderIndex().InsertSprim(prim_type_, scene_delegate_, prim_id); } void LightData::remove() { CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); - scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, prim_id); + scene_delegate_->GetRenderIndex().RemoveSprim(prim_type_, prim_id); } void LightData::update() @@ -103,7 +103,7 @@ void LightData::update() ID_LOG(2, ""); Light *light = (Light *)((Object *)id)->data; - if (prim_type(light) != p_type_) { + if (prim_type(light) != prim_type_) { remove(); init(); insert(); diff --git a/source/blender/render/hydra/scene_delegate/light.h b/source/blender/render/hydra/scene_delegate/light.h index 2d9a04ad6636..003f23997783 100644 --- a/source/blender/render/hydra/scene_delegate/light.h +++ b/source/blender/render/hydra/scene_delegate/light.h @@ -29,7 +29,7 @@ class LightData : public ObjectData { pxr::TfToken prim_type(Light *light); std::map data_; - pxr::TfToken p_type_; + pxr::TfToken prim_type_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index db497506c8f5..cf0e923906ff 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -135,7 +135,8 @@ pxr::HdMeshTopology MeshData::mesh_topology() const face_vertex_indices_); } -pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) const +pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors( + pxr::HdInterpolation interpolation) const { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationVertex) { -- 2.30.2 From f10d8de5c98fa4f1179c03c838840669dab948e2 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 03:45:10 +0300 Subject: [PATCH 7/8] Moving to use ObjectData::transform as a field --- .../scene_delegate/blender_scene_delegate.cc | 6 ++-- .../render/hydra/scene_delegate/instancer.cc | 32 +++++-------------- .../render/hydra/scene_delegate/instancer.h | 9 ------ .../render/hydra/scene_delegate/light.cc | 3 ++ .../render/hydra/scene_delegate/mesh.cc | 2 ++ .../render/hydra/scene_delegate/object.cc | 12 +++---- .../render/hydra/scene_delegate/object.h | 5 ++- .../render/hydra/scene_delegate/world.cc | 30 ++++++++--------- .../render/hydra/scene_delegate/world.h | 5 ++- 9 files changed, 45 insertions(+), 59 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index b94964b73b76..a18ad291da54 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -32,11 +32,11 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); ObjectData *obj_data = object_data(id); if (obj_data) { - return obj_data->transform(); + return obj_data->transform; } if (id == world_prim_id()) { - return world_data_->transform(); + return world_data_->transform; } return pxr::GfMatrix4d(); @@ -147,7 +147,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const & { CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText()); InstancerData *i_data = instancer_data(instancer_id); - return i_data->transform(); + return i_data->transform; } void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 3b0d5728b96f..948da2ca03fa 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -96,11 +96,6 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const return ret; } -pxr::GfMatrix4d InstancerData::transform() -{ - return pxr::GfMatrix4d(1.0); -} - bool InstancerData::update_visibility() { bool ret = ObjectData::update_visibility(); @@ -211,21 +206,22 @@ void InstancerData::set_instances() } int index = 0; Instance *inst; - pxr::SdfPath path; + pxr::SdfPath p_id; ListBase *lb = object_duplilist( scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { - path = object_prim_id(dupli->ob); - auto it = instances_.find(path); + p_id = object_prim_id(dupli->ob); + auto it = instances_.find(p_id); if (it == instances_.end()) { - inst = &instances_[path]; + inst = &instances_[p_id]; if (!is_supported(dupli->ob)) { continue; } - inst->obj_data = std::make_unique(scene_delegate_, dupli->ob, path); - inst->obj_data->init(); - inst->obj_data->insert(); + inst->obj_data = ObjectData::create(scene_delegate_, dupli->ob, p_id); + + /* Instance's transform should be identity */ + inst->obj_data->transform = pxr::GfMatrix4d(1.0); } else { inst = &it->second; @@ -248,16 +244,4 @@ void InstancerData::set_instances() } } -InstanceMeshData::InstanceMeshData(BlenderSceneDelegate *scene_delegate, - Object *object, - pxr::SdfPath const &prim_id) - : MeshData(scene_delegate, object, prim_id) -{ -} - -pxr::GfMatrix4d InstanceMeshData::transform() -{ - return pxr::GfMatrix4d(1.0); -} - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 02c1b01c7f8f..a4cf9f7bf534 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -29,7 +29,6 @@ class InstancerData : public ObjectData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - pxr::GfMatrix4d transform() override; bool update_visibility() override; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; @@ -51,12 +50,4 @@ class InstancerData : public ObjectData { using InstancerDataMap = pxr::TfHashMap, pxr::SdfPath::Hash>; -class InstanceMeshData : public MeshData { - public: - InstanceMeshData(BlenderSceneDelegate *scene_delegate, - Object *object, - pxr::SdfPath const &prim_id); - pxr::GfMatrix4d transform() override; -}; - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index d1ac864bff91..b14c07667893 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -84,6 +84,8 @@ void LightData::init() /* TODO: temporary value, it should be delivered through Python UI */ data_[pxr::HdLightTokens->exposure] = 1.0f; + + set_transform_to_object(); } void LightData::insert() @@ -116,6 +118,7 @@ void LightData::update() bits = pxr::HdLight::AllDirty; } else if (id->recalc & ID_RECALC_TRANSFORM) { + set_transform_to_object(); bits = pxr::HdLight::DirtyTransform; } scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits); diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index cf0e923906ff..a2a06b39d77a 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -40,6 +40,7 @@ void MeshData::init() } write_material(); + set_transform_to_object(); } void MeshData::insert() @@ -77,6 +78,7 @@ void MeshData::update() bits |= pxr::HdChangeTracker::DirtyMaterialId; } if (id->recalc & ID_RECALC_TRANSFORM) { + set_transform_to_object(); bits |= pxr::HdChangeTracker::DirtyTransform; } } diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 7af6a78257f3..7e5396cf8d8c 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -14,7 +14,7 @@ namespace blender::render::hydra { ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id) - : IdData(scene_delegate, (ID *)object, prim_id), visible(true) + : IdData(scene_delegate, (ID *)object, prim_id), transform(pxr::GfMatrix4d(1.0)), visible(true) { } @@ -64,11 +64,6 @@ bool ObjectData::is_supported(Object *object) return false; } -pxr::GfMatrix4d ObjectData::transform() -{ - return gf_matrix_from_transform(((Object *)id)->object_to_world); -} - bool ObjectData::update_visibility() { if (!scene_delegate_->view3d) { @@ -84,4 +79,9 @@ bool ObjectData::update_visibility() return ret; } +void ObjectData::set_transform_to_object() +{ + transform = gf_matrix_from_transform(((Object *)id)->object_to_world); +} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 513843286d27..5297c576e28b 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -23,10 +23,13 @@ class ObjectData : public IdData { pxr::SdfPath const &prim_id); static bool is_supported(Object *object); - virtual pxr::GfMatrix4d transform(); virtual bool update_visibility(); + pxr::GfMatrix4d transform; bool visible; + + protected: + void set_transform_to_object(); }; using ObjectDataMap = diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 8f2930a7836b..41697a9cf5a3 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -49,6 +49,8 @@ void WorldData::init() { ID_LOG(2, ""); + set_transform(); + World *world = (World *)id; data_.clear(); @@ -145,21 +147,6 @@ void WorldData::update(World *world) update(); } -pxr::GfMatrix4d WorldData::transform() -{ - pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), - pxr::GfVec3d()); - - /* TODO : do this check via RenderSettings*/ - if (scene_delegate_->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") { - transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), - pxr::GfVec3d()); - transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), - pxr::GfVec3d()); - } - return transform; -} - pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const { pxr::VtValue ret; @@ -170,4 +157,17 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const return ret; } +void WorldData::set_transform() +{ + transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d()); + + /* TODO : do this check via RenderSettings*/ + if (scene_delegate_->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") { + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), + pxr::GfVec3d()); + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), + pxr::GfVec3d()); + } +} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 564842b7c850..d29806ec1298 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -32,10 +32,13 @@ class WorldData : public IdData { void update() override; void update(World *world); - pxr::GfMatrix4d transform(); pxr::VtValue get_data(pxr::TfToken const &key) const override; + pxr::GfMatrix4d transform; + private: + void set_transform(); + std::map data_; }; -- 2.30.2 From 0bcbc3b942f740c56421a46b7ba4cd96ec60d7df Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 19 Apr 2023 04:09:50 +0300 Subject: [PATCH 8/8] Fixed update of removing world from scene. --- .../scene_delegate/blender_scene_delegate.cc | 38 +++++++------------ .../blender/render/hydra/scene_delegate/id.cc | 1 - 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index a18ad291da54..2cc06c447c33 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -326,34 +326,10 @@ void BlenderSceneDelegate::update_world() void BlenderSceneDelegate::check_updates() { - /* Working with updates */ bool do_update_collection = false; bool do_update_visibility = false; bool do_update_world = false; - unsigned int scene_recalc = scene->id.recalc; - if (scene_recalc) { - /* Checking scene updates */ - CLOG_INFO(LOG_BSD, - 2, - "Update: %s [%s]", - ((ID *)scene)->name, - std::bitset<32>(scene_recalc).to_string().c_str()); - - if (scene_recalc & ID_RECALC_BASE_FLAGS) { - do_update_visibility = true; - } - if (scene_recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) { - do_update_collection = true; - } - if (scene_recalc & ID_RECALC_AUDIO_VOLUME) { - if ((scene->world && !world_data_) || (!scene->world && world_data_)) { - do_update_world = true; - } - } - } - - /* Checking other objects updates */ DEGIDIterData data = {0}; data.graph = depsgraph; data.only_updated = true; @@ -383,6 +359,20 @@ void BlenderSceneDelegate::check_updates() } } break; + case ID_SCE: { + if (id->recalc & ID_RECALC_BASE_FLAGS) { + do_update_visibility = true; + } + if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) { + do_update_collection = true; + } + if (id->recalc & ID_RECALC_AUDIO_VOLUME) { + if ((scene->world && !world_data_) || (!scene->world && world_data_)) { + do_update_world = true; + } + } + } break; + default: break; } diff --git a/source/blender/render/hydra/scene_delegate/id.cc b/source/blender/render/hydra/scene_delegate/id.cc index 7a84eaee8eb1..90ce224dfa0d 100644 --- a/source/blender/render/hydra/scene_delegate/id.cc +++ b/source/blender/render/hydra/scene_delegate/id.cc @@ -3,7 +3,6 @@ #include "BKE_lib_id.h" -//#include "blender_scene_delegate.h" #include "id.h" namespace blender::render::hydra { -- 2.30.2