From 64694d43410a4bb3be5b515912cd23dee4865ce1 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 11 May 2023 14:52:56 +0300 Subject: [PATCH 01/19] Fixed setting visibility via checkboxes in outliner --- .../scene_delegate/blender_scene_delegate.cc | 26 ++++++++++--------- .../render/hydra/scene_delegate/object.cc | 17 +++++++++--- 2 files changed, 27 insertions(+), 16 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 fdd6c5476743..3d96b03b62ed 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -394,12 +394,10 @@ void BlenderSceneDelegate::check_updates() } break; case ID_SCE: { + do_update_collection = true; 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; @@ -428,8 +426,12 @@ void BlenderSceneDelegate::add_new_objects() { DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; - settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | - DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + + if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { + settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; + } + DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; @@ -473,7 +475,8 @@ void BlenderSceneDelegate::remove_unused_objects() ITER_END; /* Remove unused instancers */ - for (auto it = instancers_.begin(); it != instancers_.end(); ++it) { + for (auto it = instancers_.cbegin(), next_it = it; it != instancers_.cend(); it = next_it) { + ++next_it; if (available_objects.find(it->first.GetName()) != available_objects.end()) { /* Remove objects from instancers */ it->second->check_remove(available_objects); @@ -481,17 +484,16 @@ void BlenderSceneDelegate::remove_unused_objects() } it->second->remove(); instancers_.erase(it); - it = instancers_.begin(); } - + /* Remove unused objects */ - for (auto it = objects_.begin(); it != objects_.end(); ++it) { + for (auto it = objects_.cbegin(), next_it = it; it != objects_.cend(); it = next_it) { + ++next_it; if (available_objects.find(it->first.GetName()) != available_objects.end()) { continue; } it->second->remove(); objects_.erase(it); - it = objects_.begin(); } /* Remove unused materials */ @@ -509,13 +511,13 @@ void BlenderSceneDelegate::remove_unused_objects() for (auto &it : instancers_) { it.second->available_materials(available_materials); } - for (auto it = materials_.begin(); it != materials_.end(); ++it) { + for (auto it = materials_.cbegin(), next_it = it; it != materials_.cend(); it = next_it) { + ++next_it; if (available_materials.find(it->first) != available_materials.end()) { continue; } it->second->remove(); materials_.erase(it); - it = materials_.begin(); } } diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 3e750df0c72b..06f65dbda281 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -61,12 +61,21 @@ bool ObjectData::is_supported(Object *object) bool ObjectData::update_visibility() { - if (!scene_delegate_->view3d) { - return false; + bool prev_visible = visible; + + if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { + visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, (Object *)id); + } + if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL && parent_) { + visible = false; + } + Object *object = (Object *)id; + if (visible) { + visible = visible && scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? + object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT : + object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; } - bool prev_visible = visible; - visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, (Object *)id); bool ret = visible != prev_visible; if (ret) { ID_LOG(2, ""); -- 2.30.2 From e7257a8d140b7453465f88690d17319aabac0393 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 11 May 2023 16:00:23 +0300 Subject: [PATCH 02/19] fixed "show instancer Render" checkbox --- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3d96b03b62ed..b5dee3d410c1 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -289,6 +289,7 @@ void BlenderSceneDelegate::update_objects(Object *object) if (obj_data) { obj_data->update_parent(); obj_data->update(); + obj_data->update_visibility(); return; } if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { @@ -331,7 +332,6 @@ void BlenderSceneDelegate::update_instancers(Object *object) i_data = instancer_data(id); i_data->init(); i_data->insert(); - i_data->update_visibility(); } void BlenderSceneDelegate::update_world() -- 2.30.2 From 2dc662e266cbe058db424ad0703d84aa36f095be Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 11 May 2023 16:08:36 +0300 Subject: [PATCH 03/19] make format --- .../hydra/scene_delegate/blender_scene_delegate.cc | 9 +++------ source/blender/render/hydra/scene_delegate/object.cc | 3 ++- 2 files changed, 5 insertions(+), 7 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 8c3fe933981f..b11b203d91f8 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -438,12 +438,9 @@ void BlenderSceneDelegate::add_new_objects() { DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; - settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | + DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; - if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { - settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; - } - DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; @@ -497,7 +494,7 @@ void BlenderSceneDelegate::remove_unused_objects() it->second->remove(); instancers_.erase(it); } - + /* Remove unused objects */ for (auto it = objects_.cbegin(), next_it = it; it != objects_.cend(); it = next_it) { ++next_it; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 06f65dbda281..5a32eccd0a7d 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -71,7 +71,8 @@ bool ObjectData::update_visibility() } Object *object = (Object *)id; if (visible) { - visible = visible && scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? + visible = visible && + scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT : object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; } -- 2.30.2 From 4e2e5d6505ca17c48ad9c88c09c66180284c29c3 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 11 May 2023 16:10:02 +0300 Subject: [PATCH 04/19] removed newline --- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 1 - 1 file changed, 1 deletion(-) 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 b11b203d91f8..98f518c37ba8 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -440,7 +440,6 @@ void BlenderSceneDelegate::add_new_objects() 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}; data.settings = &settings; data.graph = settings.depsgraph; -- 2.30.2 From d27ca5d4feec481852f494d53f9a5dc2cda8e811 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 12 May 2023 18:02:50 +0300 Subject: [PATCH 05/19] Added static method ObjectData::is_visible --- .../scene_delegate/blender_scene_delegate.cc | 12 ++---- .../render/hydra/scene_delegate/object.cc | 37 ++++++++++++------- .../render/hydra/scene_delegate/object.h | 3 ++ 3 files changed, 31 insertions(+), 21 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 98f518c37ba8..05a2fe182037 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -304,9 +304,6 @@ void BlenderSceneDelegate::update_objects(Object *object) obj_data->update_visibility(); return; } - if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { - return; - } objects_[id] = ObjectData::create(this, object, id); obj_data = object_data(id); obj_data->update_parent(); @@ -337,9 +334,6 @@ void BlenderSceneDelegate::update_instancers(Object *object) if ((object->transflag & OB_DUPLI) == 0) { return; } - if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { - return; - } instancers_[id] = std::make_unique(this, object, id); i_data = instancer_data(id); i_data->init(); @@ -438,8 +432,10 @@ void BlenderSceneDelegate::add_new_objects() { DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; - settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | - DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { + settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; + } DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 5a32eccd0a7d..8147c88af8f1 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -59,23 +59,34 @@ bool ObjectData::is_supported(Object *object) return false; } +bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, + Object *object, + ObjectData *objectData) +{ + bool ret = true; + + if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { + ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); + } + if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::FINAL && + objectData && objectData->parent_) { + ret = false; + } + if (ret) { + ret = ret && + scene_delegate->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? + object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT : + object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + } + + return ret; +} + bool ObjectData::update_visibility() { bool prev_visible = visible; - if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { - visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, (Object *)id); - } - if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL && parent_) { - visible = false; - } - Object *object = (Object *)id; - if (visible) { - visible = visible && - scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? - object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT : - object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; - } + visible = is_visible(scene_delegate_, (Object *)id, this); bool ret = visible != prev_visible; if (ret) { diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index b6d5e4e48d5e..7da2fe1d3bb9 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -22,6 +22,9 @@ class ObjectData : public IdData { Object *object, pxr::SdfPath const &prim_id); static bool is_supported(Object *object); + static bool is_visible(BlenderSceneDelegate *scene_delegate, + Object *object, + ObjectData *objectData = nullptr); virtual bool update_visibility(); void update_parent(); -- 2.30.2 From 3c1e12670cec1f820e5fc584f4f06ec473a4ddb5 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 16 May 2023 19:28:54 +0300 Subject: [PATCH 06/19] to save code --- .../scene_delegate/blender_scene_delegate.cc | 72 ++++++++++++------- .../scene_delegate/blender_scene_delegate.h | 1 + .../render/hydra/scene_delegate/instancer.cc | 61 +++++++++++++++- .../render/hydra/scene_delegate/instancer.h | 5 ++ .../render/hydra/scene_delegate/mesh.cc | 1 + .../render/hydra/scene_delegate/object.cc | 22 +++--- .../render/hydra/scene_delegate/object.h | 3 +- 7 files changed, 123 insertions(+), 42 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 05a2fe182037..3ade540326b0 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -111,14 +111,26 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); + if (id == world_prim_id()) { return true; } - InstancerData *i_data = instancer_data(id, true); + InstancerData *i_data = instancer_data(id); if (i_data) { + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 3, + "%s %s %d", + id.GetText(), + i_data->id->name, + i_data->visible); return i_data->visible; } + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 1, + "%s %s %d", + id.GetText(), + object_data(id)->id->name, + object_data(id)->visible); return object_data(id)->visible; } @@ -324,6 +336,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) if (i_data) { if (object->transflag & OB_DUPLI) { i_data->update(); + i_data->update_visibility(); } else { i_data->remove(); @@ -338,6 +351,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) i_data = instancer_data(id); i_data->init(); i_data->insert(); + i_data->update_visibility(); } void BlenderSceneDelegate::update_world() @@ -400,7 +414,9 @@ void BlenderSceneDelegate::check_updates() } break; case ID_SCE: { - do_update_collection = true; + if (id->recalc & ID_RECALC_COPY_ON_WRITE && !(id->recalc & ID_RECALC_SELECT)) { + do_update_collection = true; + } if (id->recalc & ID_RECALC_BASE_FLAGS) { do_update_visibility = true; } @@ -433,9 +449,9 @@ void BlenderSceneDelegate::add_new_objects() DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; - if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { - settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; - } + //if (engine_type == BlenderSceneDelegate::EngineType::FINAL) { + // settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_DUPLI; + //} DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; @@ -479,25 +495,29 @@ void BlenderSceneDelegate::remove_unused_objects() ITER_END; /* Remove unused instancers */ - for (auto it = instancers_.cbegin(), next_it = it; it != instancers_.cend(); it = next_it) { - ++next_it; - if (available_objects.find(it->first.GetName()) != available_objects.end()) { + auto it_inst = instancers_.begin(); + while (it_inst != instancers_.end()) { + if (available_objects.find(it_inst->first.GetName()) != available_objects.end()) { /* Remove objects from instancers */ - it->second->check_remove(available_objects); - continue; + it_inst->second->check_remove(available_objects); + ++it_inst; + } + else { + it_inst->second->remove(); + instancers_.erase(it_inst++); } - it->second->remove(); - instancers_.erase(it); } /* Remove unused objects */ - for (auto it = objects_.cbegin(), next_it = it; it != objects_.cend(); it = next_it) { - ++next_it; - if (available_objects.find(it->first.GetName()) != available_objects.end()) { - continue; + auto it_obj = objects_.begin(); + while (it_obj != objects_.end()) { + if (available_objects.find(it_obj->first.GetName()) != available_objects.end()) { + ++it_obj; + } + else { + it_obj->second->remove(); + objects_.erase(it_obj++); } - it->second->remove(); - objects_.erase(it); } /* Remove unused materials */ @@ -515,13 +535,15 @@ void BlenderSceneDelegate::remove_unused_objects() for (auto &it : instancers_) { it.second->available_materials(available_materials); } - for (auto it = materials_.cbegin(), next_it = it; it != materials_.cend(); it = next_it) { - ++next_it; - if (available_materials.find(it->first) != available_materials.end()) { - continue; + auto it_mat = materials_.begin(); + while (it_mat != materials_.end()) { + if (available_materials.find(it_mat->first) != available_materials.end()) { + ++it_mat; + } + else { + it_mat->second->remove(); + materials_.erase(it_mat++); } - it->second->remove(); - materials_.erase(it); } } 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 11aef5cb3bd7..0a86949b74cd 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -23,6 +23,7 @@ extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; class BlenderSceneDelegate : public pxr::HdSceneDelegate { friend ObjectData; /* has access to instances */ + friend InstancerData; /* has access to instances */ friend MeshData; /* has access to materials */ friend MaterialData; /* has access to objects and instancers */ diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index e10cd9972574..ba37327ed7de 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -83,10 +83,67 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const return ret; } +bool InstancerData::is_duplicator_visible(BlenderSceneDelegate *scene_delegate, Object *object) +{ + bool ret = true; + + if (object->transflag & OB_DUPLI) { + int flag = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? + OB_DUPLI_FLAG_VIEWPORT : + OB_DUPLI_FLAG_RENDER; + ret = object->duplicator_visibility_flag & flag; + } + + return ret; +} + +bool InstancerData::update_duplicator_visibility() { + bool prev_visible = duplicator_visible; + + duplicator_visible = is_duplicator_visible(scene_delegate_, (Object *)id); + + bool ret = duplicator_visible != prev_visible; + if (ret) { + ID_LOG(2, ""); + } + return ret; +} + bool InstancerData::update_visibility() { bool ret = ObjectData::update_visibility(); - if (ret) { + bool dup_ret = update_duplicator_visibility(); + + if (dup_ret) { + for (Object *ob = (Object *)id; ob != nullptr; ob = ob->parent) { + InstancerData *obj_data = scene_delegate_->instancer_data( + scene_delegate_->instancer_prim_id(ob)); + if (obj_data) { + auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); + change_tracker.MarkInstancerDirty(obj_data->prim_id, + pxr::HdChangeTracker::DirtyVisibility); + for (auto &it : obj_data->mesh_instances_) { + auto a = it.first.GetText(); + auto b = prim_id.GetText(); + auto c = scene_delegate_->object_prim_id(((Object *)id)).GetText(); + auto d = obj_data->prim_id.GetText(); + //if (it.first.GetParentPath().GetName() == prim_id.GetName()) { + // it.second.data->visible = duplicator_visible; + // change_tracker.MarkRprimDirty(it.second.data->prim_id, + // pxr::HdChangeTracker::DirtyVisibility); + //} + + if (it.first.GetName() == scene_delegate_->object_prim_id(((Object *)id)).GetName()) { + it.second.data->visible = duplicator_visible; + change_tracker.MarkRprimDirty(it.second.data->prim_id, + pxr::HdChangeTracker::DirtyVisibility); + } + } + } + } + } + + if (!dup_ret && ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); for (auto &it : mesh_instances_) { @@ -103,7 +160,7 @@ bool InstancerData::update_visibility() } } } - return ret; + return true; } pxr::GfMatrix4d InstancerData::get_transform(pxr::SdfPath const &id) const diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index d0454903abf8..e554990a1d4f 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -32,8 +32,13 @@ class InstancerData : public ObjectData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; + bool update_visibility() override; + static bool is_duplicator_visible(BlenderSceneDelegate *scene_delegate, Object *object); + bool update_duplicator_visibility(); + bool duplicator_visible = true; + pxr::GfMatrix4d get_transform(pxr::SdfPath const &id) const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; pxr::VtIntArray indices(pxr::SdfPath const &id) const; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 0bae621a101b..1858b9e88736 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -118,6 +118,7 @@ pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const bool MeshData::update_visibility() { bool ret = ObjectData::update_visibility(); + if (ret) { ID_LOG(2, ""); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 8147c88af8f1..08647bfd6d65 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -2,6 +2,7 @@ * Copyright 2011-2022 Blender Foundation */ #include "BKE_object.h" +#include "DEG_depsgraph_query.h" #include "blender_scene_delegate.h" #include "light.h" @@ -59,24 +60,19 @@ bool ObjectData::is_supported(Object *object) return false; } -bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, - Object *object, - ObjectData *objectData) +bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) { bool ret = true; if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); + if (ret && object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; + } } - if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::FINAL && - objectData && objectData->parent_) { - ret = false; - } - if (ret) { - ret = ret && - scene_delegate->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? - object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT : - object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + + if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + ret = object->parent ? false : object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; } return ret; @@ -86,7 +82,7 @@ bool ObjectData::update_visibility() { bool prev_visible = visible; - visible = is_visible(scene_delegate_, (Object *)id, this); + visible = is_visible(scene_delegate_, (Object *)id); bool ret = visible != prev_visible; if (ret) { diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 7da2fe1d3bb9..24a0339cf8c7 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -23,8 +23,7 @@ class ObjectData : public IdData { pxr::SdfPath const &prim_id); static bool is_supported(Object *object); static bool is_visible(BlenderSceneDelegate *scene_delegate, - Object *object, - ObjectData *objectData = nullptr); + Object *object); virtual bool update_visibility(); void update_parent(); -- 2.30.2 From bde35497fc0a602d66b2fca58d297fb908b55d62 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 16 May 2023 19:49:20 +0300 Subject: [PATCH 07/19] fix for final render show instancer --- .../blender/render/hydra/scene_delegate/instancer.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index ba37327ed7de..17fd8f9ec098 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -127,11 +127,11 @@ bool InstancerData::update_visibility() auto b = prim_id.GetText(); auto c = scene_delegate_->object_prim_id(((Object *)id)).GetText(); auto d = obj_data->prim_id.GetText(); - //if (it.first.GetParentPath().GetName() == prim_id.GetName()) { - // it.second.data->visible = duplicator_visible; - // change_tracker.MarkRprimDirty(it.second.data->prim_id, - // pxr::HdChangeTracker::DirtyVisibility); - //} + if (it.first.GetParentPath().GetName() == prim_id.GetName() && ob == ((Object *)it.second.data->id)->parent) { + it.second.data->visible = duplicator_visible; + change_tracker.MarkRprimDirty(it.second.data->prim_id, + pxr::HdChangeTracker::DirtyVisibility); + } if (it.first.GetName() == scene_delegate_->object_prim_id(((Object *)id)).GetName()) { it.second.data->visible = duplicator_visible; -- 2.30.2 From 9cf2a09ea57f5fdbe195bf166edc20057a3aa19f Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 14:33:34 +0300 Subject: [PATCH 08/19] to save code --- .../scene_delegate/blender_scene_delegate.cc | 28 +++--------- .../render/hydra/scene_delegate/instancer.cc | 45 ++++++++++++++----- .../render/hydra/scene_delegate/instancer.h | 2 + .../render/hydra/scene_delegate/object.cc | 20 +++++++-- 4 files changed, 60 insertions(+), 35 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 3ade540326b0..d8728b44f6aa 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -111,26 +111,14 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { - + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); if (id == world_prim_id()) { return true; } - InstancerData *i_data = instancer_data(id); + InstancerData *i_data = instancer_data(id, true); if (i_data) { - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, - 3, - "%s %s %d", - id.GetText(), - i_data->id->name, - i_data->visible); return i_data->visible; } - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, - 1, - "%s %s %d", - id.GetText(), - object_data(id)->id->name, - object_data(id)->visible); return object_data(id)->visible; } @@ -336,7 +324,6 @@ void BlenderSceneDelegate::update_instancers(Object *object) if (i_data) { if (object->transflag & OB_DUPLI) { i_data->update(); - i_data->update_visibility(); } else { i_data->remove(); @@ -351,7 +338,6 @@ void BlenderSceneDelegate::update_instancers(Object *object) i_data = instancer_data(id); i_data->init(); i_data->insert(); - i_data->update_visibility(); } void BlenderSceneDelegate::update_world() @@ -414,9 +400,7 @@ void BlenderSceneDelegate::check_updates() } break; case ID_SCE: { - if (id->recalc & ID_RECALC_COPY_ON_WRITE && !(id->recalc & ID_RECALC_SELECT)) { - do_update_collection = true; - } + do_update_collection = true; if (id->recalc & ID_RECALC_BASE_FLAGS) { do_update_visibility = true; } @@ -449,9 +433,9 @@ void BlenderSceneDelegate::add_new_objects() DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; - //if (engine_type == BlenderSceneDelegate::EngineType::FINAL) { - // settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_DUPLI; - //} + if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { + settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; + } DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 17fd8f9ec098..00e069bde2b7 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -4,6 +4,9 @@ #include #include +#include "BKE_object.h" +#include "DEG_depsgraph_query.h" + #include "blender_scene_delegate.h" #include "instancer.h" @@ -109,10 +112,29 @@ bool InstancerData::update_duplicator_visibility() { return ret; } +bool InstancerData::update_instances_visibility() +{ + bool prev_visible = instances_visible; + + instances_visible = (BKE_object_visibility((Object *)id, DEG_get_mode(scene_delegate_->depsgraph)) & + OB_VISIBLE_INSTANCES); + + //if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + // instances_visible = false; + //} + + bool ret = instances_visible != prev_visible; + if (ret) { + ID_LOG(2, ""); + } + return ret; +} + bool InstancerData::update_visibility() { bool ret = ObjectData::update_visibility(); bool dup_ret = update_duplicator_visibility(); + bool inst_ret = update_instances_visibility(); if (dup_ret) { for (Object *ob = (Object *)id; ob != nullptr; ob = ob->parent) { @@ -127,14 +149,15 @@ bool InstancerData::update_visibility() auto b = prim_id.GetText(); auto c = scene_delegate_->object_prim_id(((Object *)id)).GetText(); auto d = obj_data->prim_id.GetText(); - if (it.first.GetParentPath().GetName() == prim_id.GetName() && ob == ((Object *)it.second.data->id)->parent) { - it.second.data->visible = duplicator_visible; - change_tracker.MarkRprimDirty(it.second.data->prim_id, - pxr::HdChangeTracker::DirtyVisibility); - } - + //if (it.first.GetParentPath().GetName() == prim_id.GetName() && ob == ((Object *)it.second.data->id)->parent) { + // it.second.data->visible = instances_visible; + // change_tracker.MarkRprimDirty(it.second.data->prim_id, + // pxr::HdChangeTracker::DirtyVisibility); + //} + + // update its own instances on clicking "Show instancer" checkbox if (it.first.GetName() == scene_delegate_->object_prim_id(((Object *)id)).GetName()) { - it.second.data->visible = duplicator_visible; + it.second.data->visible = duplicator_visible && obj_data->visible; change_tracker.MarkRprimDirty(it.second.data->prim_id, pxr::HdChangeTracker::DirtyVisibility); } @@ -143,11 +166,12 @@ bool InstancerData::update_visibility() } } - if (!dup_ret && ret) { + if (!dup_ret && (ret || inst_ret)) { + //if (ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); for (auto &it : mesh_instances_) { - it.second.data->visible = visible; + it.second.data->visible = scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL ? duplicator_visible : instances_visible; change_tracker.MarkRprimDirty(it.second.data->prim_id, pxr::HdChangeTracker::DirtyVisibility); } @@ -160,7 +184,7 @@ bool InstancerData::update_visibility() } } } - return true; + return ret || dup_ret || inst_ret; } pxr::GfMatrix4d InstancerData::get_transform(pxr::SdfPath const &id) const @@ -355,6 +379,7 @@ void InstancerData::set_instances() inst->data = std::make_unique(scene_delegate_, ob, p_id); inst->data->init(); inst->data->insert(); + inst->data->update_visibility(); } else { inst = &it->second; diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index e554990a1d4f..90a44fd83188 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -37,7 +37,9 @@ class InstancerData : public ObjectData { static bool is_duplicator_visible(BlenderSceneDelegate *scene_delegate, Object *object); bool update_duplicator_visibility(); + bool update_instances_visibility(); bool duplicator_visible = true; + bool instances_visible = true; pxr::GfMatrix4d get_transform(pxr::SdfPath const &id) const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 08647bfd6d65..a90b39afc032 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -72,9 +72,19 @@ bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object } if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::FINAL) { - ret = object->parent ? false : object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + if (object->parent) { + ret = false; + } } + bool self = (BKE_object_visibility(object, DEG_get_mode(scene_delegate->depsgraph)) & + OB_VISIBLE_SELF); + bool part = (BKE_object_visibility(object, DEG_get_mode(scene_delegate->depsgraph)) & + OB_VISIBLE_PARTICLES); + bool inst = (BKE_object_visibility(object, DEG_get_mode(scene_delegate->depsgraph)) & + OB_VISIBLE_INSTANCES); + return ret; } @@ -84,6 +94,10 @@ bool ObjectData::update_visibility() visible = is_visible(scene_delegate_, (Object *)id); + //if (((Object *)id)->parent && scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + // visible = false; + //} + bool ret = visible != prev_visible; if (ret) { ID_LOG(2, ""); @@ -94,7 +108,7 @@ bool ObjectData::update_visibility() void ObjectData::update_parent() { Object *object = (Object *)id; - if (parent_ != object->parent) { + //if (parent_ != object->parent) { ID_LOG(2, ""); parent_ = object->parent; @@ -107,7 +121,7 @@ void ObjectData::update_parent() break; } } - } + //} } void ObjectData::write_transform() -- 2.30.2 From bb1f33635f2a3d95993587f4180d7157bc222cbb Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 17:24:18 +0300 Subject: [PATCH 09/19] working example for viewport --- .../scene_delegate/blender_scene_delegate.cc | 22 +++++++++-- .../render/hydra/scene_delegate/instancer.cc | 39 +++++++------------ .../render/hydra/scene_delegate/object.cc | 8 +--- 3 files changed, 33 insertions(+), 36 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 d8728b44f6aa..93827bab230d 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -111,14 +111,26 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); + //CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); if (id == world_prim_id()) { return true; } InstancerData *i_data = instancer_data(id, true); if (i_data) { return i_data->visible; + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 1, + "%s %s %d", + id.GetText(), + i_data->id->name, + i_data->visible); } + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 1, + "%s %s %d", + id.GetText(), + object_data(id)->id->name, + object_data(id)->visible); return object_data(id)->visible; } @@ -324,6 +336,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) if (i_data) { if (object->transflag & OB_DUPLI) { i_data->update(); + i_data->update_visibility(); } else { i_data->remove(); @@ -338,6 +351,7 @@ void BlenderSceneDelegate::update_instancers(Object *object) i_data = instancer_data(id); i_data->init(); i_data->insert(); + i_data->update_visibility(); } void BlenderSceneDelegate::update_world() @@ -433,9 +447,9 @@ void BlenderSceneDelegate::add_new_objects() DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; - if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { - settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; - } + //if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { + // settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; + //} DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 00e069bde2b7..b386a619aaed 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -136,38 +136,25 @@ bool InstancerData::update_visibility() bool dup_ret = update_duplicator_visibility(); bool inst_ret = update_instances_visibility(); + visible = instances_visible; + if (dup_ret) { - for (Object *ob = (Object *)id; ob != nullptr; ob = ob->parent) { + Object *ob = ((Object *)id)->parent; + if (ob) { InstancerData *obj_data = scene_delegate_->instancer_data( scene_delegate_->instancer_prim_id(ob)); - if (obj_data) { - auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); - change_tracker.MarkInstancerDirty(obj_data->prim_id, - pxr::HdChangeTracker::DirtyVisibility); - for (auto &it : obj_data->mesh_instances_) { - auto a = it.first.GetText(); - auto b = prim_id.GetText(); - auto c = scene_delegate_->object_prim_id(((Object *)id)).GetText(); - auto d = obj_data->prim_id.GetText(); - //if (it.first.GetParentPath().GetName() == prim_id.GetName() && ob == ((Object *)it.second.data->id)->parent) { - // it.second.data->visible = instances_visible; - // change_tracker.MarkRprimDirty(it.second.data->prim_id, - // pxr::HdChangeTracker::DirtyVisibility); - //} - - // update its own instances on clicking "Show instancer" checkbox - if (it.first.GetName() == scene_delegate_->object_prim_id(((Object *)id)).GetName()) { - it.second.data->visible = duplicator_visible && obj_data->visible; - change_tracker.MarkRprimDirty(it.second.data->prim_id, - pxr::HdChangeTracker::DirtyVisibility); - } - } - } + obj_data->visible = duplicator_visible; + auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); + change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); + } + if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + visible = instances_visible; + auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); + change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); } } - if (!dup_ret && (ret || inst_ret)) { - //if (ret) { + if (ret || inst_ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); for (auto &it : mesh_instances_) { diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index a90b39afc032..5ca192286fb2 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -94,10 +94,6 @@ bool ObjectData::update_visibility() visible = is_visible(scene_delegate_, (Object *)id); - //if (((Object *)id)->parent && scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { - // visible = false; - //} - bool ret = visible != prev_visible; if (ret) { ID_LOG(2, ""); @@ -108,7 +104,7 @@ bool ObjectData::update_visibility() void ObjectData::update_parent() { Object *object = (Object *)id; - //if (parent_ != object->parent) { + if (parent_ != object->parent) { ID_LOG(2, ""); parent_ = object->parent; @@ -121,7 +117,7 @@ void ObjectData::update_parent() break; } } - //} + } } void ObjectData::write_transform() -- 2.30.2 From 7c37357cde76d52f7f0d9e05ffd7e83fe99f732a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 17:38:44 +0300 Subject: [PATCH 10/19] fixed for final if instancing disabled for object->parent --- source/blender/render/hydra/scene_delegate/object.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 5ca192286fb2..9484bbae4f4a 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -73,7 +73,7 @@ bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::FINAL) { ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; - if (object->parent) { + if (object->parent && (object->parent->transflag & OB_DUPLI)) { ret = false; } } -- 2.30.2 From 2c4b39c0f49100b11f08e2b9dbf451e4c36bf42e Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 18:04:37 +0300 Subject: [PATCH 11/19] clean up --- .../scene_delegate/blender_scene_delegate.cc | 12 ------------ .../render/hydra/scene_delegate/instancer.cc | 19 +++++-------------- .../render/hydra/scene_delegate/object.cc | 7 ------- 3 files changed, 5 insertions(+), 33 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 93827bab230d..be0bf8c23ddb 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -118,19 +118,7 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) InstancerData *i_data = instancer_data(id, true); if (i_data) { return i_data->visible; - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, - 1, - "%s %s %d", - id.GetText(), - i_data->id->name, - i_data->visible); } - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, - 1, - "%s %s %d", - id.GetText(), - object_data(id)->id->name, - object_data(id)->visible); return object_data(id)->visible; } diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index b386a619aaed..12780c33c878 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -119,10 +119,6 @@ bool InstancerData::update_instances_visibility() instances_visible = (BKE_object_visibility((Object *)id, DEG_get_mode(scene_delegate_->depsgraph)) & OB_VISIBLE_INSTANCES); - //if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { - // instances_visible = false; - //} - bool ret = instances_visible != prev_visible; if (ret) { ID_LOG(2, ""); @@ -136,29 +132,24 @@ bool InstancerData::update_visibility() bool dup_ret = update_duplicator_visibility(); bool inst_ret = update_instances_visibility(); - visible = instances_visible; - if (dup_ret) { Object *ob = ((Object *)id)->parent; + auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); if (ob) { InstancerData *obj_data = scene_delegate_->instancer_data( scene_delegate_->instancer_prim_id(ob)); obj_data->visible = duplicator_visible; - auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); - change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); - } - if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { - visible = instances_visible; - auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); - change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); + change_tracker.MarkInstancerDirty(obj_data->prim_id, pxr::HdChangeTracker::DirtyVisibility); } + visible = instances_visible; + change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); } if (ret || inst_ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); for (auto &it : mesh_instances_) { - it.second.data->visible = scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL ? duplicator_visible : instances_visible; + it.second.data->visible = visible; change_tracker.MarkRprimDirty(it.second.data->prim_id, pxr::HdChangeTracker::DirtyVisibility); } diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 9484bbae4f4a..58d424ce3bac 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -78,13 +78,6 @@ bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object } } - bool self = (BKE_object_visibility(object, DEG_get_mode(scene_delegate->depsgraph)) & - OB_VISIBLE_SELF); - bool part = (BKE_object_visibility(object, DEG_get_mode(scene_delegate->depsgraph)) & - OB_VISIBLE_PARTICLES); - bool inst = (BKE_object_visibility(object, DEG_get_mode(scene_delegate->depsgraph)) & - OB_VISIBLE_INSTANCES); - return ret; } -- 2.30.2 From 0b5dd935c573c157dd040bb1e6f168e647f017db Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 19:35:48 +0300 Subject: [PATCH 12/19] fix switching "Instansing" panel and "Render" checkbox --- .../scene_delegate/blender_scene_delegate.cc | 12 +++--------- .../render/hydra/scene_delegate/instancer.cc | 16 +++++++++++----- 2 files changed, 14 insertions(+), 14 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 be0bf8c23ddb..9c4dbd064380 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -111,7 +111,7 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { - //CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); if (id == world_prim_id()) { return true; } @@ -322,14 +322,8 @@ void BlenderSceneDelegate::update_instancers(Object *object) pxr::SdfPath id = instancer_prim_id(object); InstancerData *i_data = instancer_data(id); if (i_data) { - if (object->transflag & OB_DUPLI) { - i_data->update(); - i_data->update_visibility(); - } - else { - i_data->remove(); - instancers_.erase(id); - } + i_data->update(); + i_data->update_visibility(); return; } if ((object->transflag & OB_DUPLI) == 0) { diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 12780c33c878..003af79e3862 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -133,13 +133,19 @@ bool InstancerData::update_visibility() bool inst_ret = update_instances_visibility(); if (dup_ret) { - Object *ob = ((Object *)id)->parent; auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); + Object *ob = ((Object *)id)->parent; if (ob) { - InstancerData *obj_data = scene_delegate_->instancer_data( - scene_delegate_->instancer_prim_id(ob)); - obj_data->visible = duplicator_visible; - change_tracker.MarkInstancerDirty(obj_data->prim_id, pxr::HdChangeTracker::DirtyVisibility); + InstancerData *obj_data = scene_delegate_->instancer_data( + scene_delegate_->instancer_prim_id(ob)); + if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + obj_data->visible = duplicator_visible; + change_tracker.MarkInstancerDirty(obj_data->prim_id, + pxr::HdChangeTracker::DirtyVisibility); + } + else { + obj_data->update_visibility(); + } } visible = instances_visible; change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); -- 2.30.2 From 6b2f94c49317864d504af2fdfc5cc2dae0b153db Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 19:38:18 +0300 Subject: [PATCH 13/19] fix condition for "do_update_collection" --- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 9c4dbd064380..fc7e2d0a7208 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -396,7 +396,9 @@ void BlenderSceneDelegate::check_updates() } break; case ID_SCE: { - do_update_collection = true; + if (id->recalc & ID_RECALC_COPY_ON_WRITE && !(id->recalc & ID_RECALC_SELECT)) { + do_update_collection = true; + } if (id->recalc & ID_RECALC_BASE_FLAGS) { do_update_visibility = true; } -- 2.30.2 From c14978010efb2a71bafe7a70dfd85840d9786e00 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 19:44:33 +0300 Subject: [PATCH 14/19] clean up --- .../hydra/scene_delegate/blender_scene_delegate.cc | 3 --- source/blender/render/hydra/scene_delegate/instancer.h | 10 +++++----- source/blender/render/hydra/scene_delegate/mesh.cc | 1 - 3 files changed, 5 insertions(+), 9 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 fc7e2d0a7208..0831a5ff2e66 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -431,9 +431,6 @@ void BlenderSceneDelegate::add_new_objects() DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; - //if (engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { - // settings.flags |= DEG_ITER_OBJECT_FLAG_VISIBLE; - //} DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 90a44fd83188..79c50bf001b0 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -25,6 +25,7 @@ class InstancerData : public ObjectData { public: InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); static bool is_supported(Object *object); + static bool is_duplicator_visible(BlenderSceneDelegate *scene_delegate, Object *object); void init() override; void insert() override; @@ -33,13 +34,9 @@ class InstancerData : public ObjectData { pxr::VtValue get_data(pxr::TfToken const &key) const override; - bool update_visibility() override; - - static bool is_duplicator_visible(BlenderSceneDelegate *scene_delegate, Object *object); + bool update_visibility() override; bool update_duplicator_visibility(); bool update_instances_visibility(); - bool duplicator_visible = true; - bool instances_visible = true; pxr::GfMatrix4d get_transform(pxr::SdfPath const &id) const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; @@ -52,6 +49,9 @@ class InstancerData : public ObjectData { void update_as_parent(); void update_double_sided(MaterialData *mat_data); + bool duplicator_visible = true; + bool instances_visible = true; + private: pxr::SdfPath object_prim_id(Object *object) const; pxr::SdfPath light_prim_id(LightInstance const &inst, int index) const; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 1858b9e88736..0bae621a101b 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -118,7 +118,6 @@ pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const bool MeshData::update_visibility() { bool ret = ObjectData::update_visibility(); - if (ret) { ID_LOG(2, ""); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( -- 2.30.2 From 7d3c32e14016628763123770c0e8c85eeea15598 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 18 May 2023 19:46:09 +0300 Subject: [PATCH 15/19] make format --- .../scene_delegate/blender_scene_delegate.h | 6 ++--- .../render/hydra/scene_delegate/instancer.cc | 26 ++++++++++--------- .../render/hydra/scene_delegate/instancer.h | 4 +-- .../render/hydra/scene_delegate/object.h | 3 +-- 4 files changed, 20 insertions(+), 19 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 0a86949b74cd..d7eff5135869 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -22,10 +22,10 @@ namespace blender::render::hydra { extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; class BlenderSceneDelegate : public pxr::HdSceneDelegate { - friend ObjectData; /* has access to instances */ + friend ObjectData; /* has access to instances */ friend InstancerData; /* has access to instances */ - friend MeshData; /* has access to materials */ - friend MaterialData; /* has access to objects and instancers */ + friend MeshData; /* has access to materials */ + friend MaterialData; /* has access to objects and instancers */ 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 003af79e3862..749f7ce528af 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -100,7 +100,8 @@ bool InstancerData::is_duplicator_visible(BlenderSceneDelegate *scene_delegate, return ret; } -bool InstancerData::update_duplicator_visibility() { +bool InstancerData::update_duplicator_visibility() +{ bool prev_visible = duplicator_visible; duplicator_visible = is_duplicator_visible(scene_delegate_, (Object *)id); @@ -116,7 +117,8 @@ bool InstancerData::update_instances_visibility() { bool prev_visible = instances_visible; - instances_visible = (BKE_object_visibility((Object *)id, DEG_get_mode(scene_delegate_->depsgraph)) & + instances_visible = (BKE_object_visibility((Object *)id, + DEG_get_mode(scene_delegate_->depsgraph)) & OB_VISIBLE_INSTANCES); bool ret = instances_visible != prev_visible; @@ -136,16 +138,16 @@ bool InstancerData::update_visibility() auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); Object *ob = ((Object *)id)->parent; if (ob) { - InstancerData *obj_data = scene_delegate_->instancer_data( - scene_delegate_->instancer_prim_id(ob)); - if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { - obj_data->visible = duplicator_visible; - change_tracker.MarkInstancerDirty(obj_data->prim_id, - pxr::HdChangeTracker::DirtyVisibility); - } - else { - obj_data->update_visibility(); - } + InstancerData *obj_data = scene_delegate_->instancer_data( + scene_delegate_->instancer_prim_id(ob)); + if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + obj_data->visible = duplicator_visible; + change_tracker.MarkInstancerDirty(obj_data->prim_id, + pxr::HdChangeTracker::DirtyVisibility); + } + else { + obj_data->update_visibility(); + } } visible = instances_visible; change_tracker.MarkInstancerDirty(prim_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 79c50bf001b0..9c3beff76c59 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -33,8 +33,8 @@ class InstancerData : public ObjectData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - - bool update_visibility() override; + + bool update_visibility() override; bool update_duplicator_visibility(); bool update_instances_visibility(); diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 24a0339cf8c7..6ed40aa579a3 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -22,8 +22,7 @@ class ObjectData : public IdData { Object *object, pxr::SdfPath const &prim_id); static bool is_supported(Object *object); - static bool is_visible(BlenderSceneDelegate *scene_delegate, - Object *object); + static bool is_visible(BlenderSceneDelegate *scene_delegate, Object *object); virtual bool update_visibility(); void update_parent(); -- 2.30.2 From c02ec9b860755a6db634864b1906ecb62ae00a27 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 12:34:25 +0300 Subject: [PATCH 16/19] fix review comments --- .../scene_delegate/blender_scene_delegate.cc | 13 +++++++++++-- .../render/hydra/scene_delegate/instancer.cc | 15 +++++---------- .../blender/render/hydra/scene_delegate/object.cc | 9 ++------- 3 files changed, 18 insertions(+), 19 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 0831a5ff2e66..b36bc05f5e2f 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -322,8 +322,14 @@ void BlenderSceneDelegate::update_instancers(Object *object) pxr::SdfPath id = instancer_prim_id(object); InstancerData *i_data = instancer_data(id); if (i_data) { - i_data->update(); - i_data->update_visibility(); + if (object->transflag & OB_DUPLI) { + i_data->update(); + i_data->update_visibility(); + } + else { + i_data->remove(); + instancers_.erase(id); + } return; } if ((object->transflag & OB_DUPLI) == 0) { @@ -399,6 +405,9 @@ void BlenderSceneDelegate::check_updates() if (id->recalc & ID_RECALC_COPY_ON_WRITE && !(id->recalc & ID_RECALC_SELECT)) { do_update_collection = true; } + if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) { + do_update_collection = true; + } if (id->recalc & ID_RECALC_BASE_FLAGS) { do_update_visibility = true; } diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 749f7ce528af..5a082a572cdf 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -91,7 +91,7 @@ bool InstancerData::is_duplicator_visible(BlenderSceneDelegate *scene_delegate, bool ret = true; if (object->transflag & OB_DUPLI) { - int flag = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT ? + int flag = DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT ? OB_DUPLI_FLAG_VIEWPORT : OB_DUPLI_FLAG_RENDER; ret = object->duplicator_visibility_flag & flag; @@ -103,9 +103,7 @@ bool InstancerData::is_duplicator_visible(BlenderSceneDelegate *scene_delegate, bool InstancerData::update_duplicator_visibility() { bool prev_visible = duplicator_visible; - duplicator_visible = is_duplicator_visible(scene_delegate_, (Object *)id); - bool ret = duplicator_visible != prev_visible; if (ret) { ID_LOG(2, ""); @@ -116,11 +114,9 @@ bool InstancerData::update_duplicator_visibility() bool InstancerData::update_instances_visibility() { bool prev_visible = instances_visible; - - instances_visible = (BKE_object_visibility((Object *)id, - DEG_get_mode(scene_delegate_->depsgraph)) & - OB_VISIBLE_INSTANCES); - + instances_visible = BKE_object_visibility((Object *)id, + DEG_get_mode(scene_delegate_->depsgraph)) == + OB_VISIBLE_INSTANCES; bool ret = instances_visible != prev_visible; if (ret) { ID_LOG(2, ""); @@ -133,14 +129,13 @@ bool InstancerData::update_visibility() bool ret = ObjectData::update_visibility(); bool dup_ret = update_duplicator_visibility(); bool inst_ret = update_instances_visibility(); - if (dup_ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); Object *ob = ((Object *)id)->parent; if (ob) { InstancerData *obj_data = scene_delegate_->instancer_data( scene_delegate_->instancer_prim_id(ob)); - if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + if (DEG_get_mode(scene_delegate_->depsgraph) == DAG_EVAL_RENDER) { obj_data->visible = duplicator_visible; change_tracker.MarkInstancerDirty(obj_data->prim_id, pxr::HdChangeTracker::DirtyVisibility); diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 58d424ce3bac..a27b635b6718 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -63,30 +63,25 @@ bool ObjectData::is_supported(Object *object) bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) { bool ret = true; - - if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::VIEWPORT) { + if (DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT) { ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); if (ret && object->transflag & OB_DUPLI) { ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; } } - - if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::FINAL) { + else { ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; if (object->parent && (object->parent->transflag & OB_DUPLI)) { ret = false; } } - return ret; } bool ObjectData::update_visibility() { bool prev_visible = visible; - visible = is_visible(scene_delegate_, (Object *)id); - bool ret = visible != prev_visible; if (ret) { ID_LOG(2, ""); -- 2.30.2 From 51078d2063b4ffa56c4c5c9158d8b3463f71e470 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 12:34:55 +0300 Subject: [PATCH 17/19] make format --- .../hydra/scene_delegate/blender_scene_delegate.cc | 13 ++++++++----- .../render/hydra/scene_delegate/instancer.cc | 10 ++++++---- source/blender/render/hydra/scene_delegate/mesh.cc | 3 ++- 3 files changed, 16 insertions(+), 10 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 b36bc05f5e2f..63c13dec5d8b 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -372,8 +372,8 @@ void BlenderSceneDelegate::check_updates() DEGIDIterData data = {0}; data.graph = depsgraph; data.only_updated = true; - ITER_BEGIN ( - DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { + ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) + { CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, @@ -449,7 +449,8 @@ void BlenderSceneDelegate::add_new_objects() DEG_iterator_objects_end, &data, Object *, - object) { + object) + { update_objects(object); update_instancers(object); @@ -474,7 +475,8 @@ void BlenderSceneDelegate::remove_unused_objects() DEG_iterator_objects_end, &data, Object *, - object) { + object) + { if (ObjectData::is_supported(object)) { available_objects.insert(object_prim_id(object).GetName()); } @@ -558,7 +560,8 @@ void BlenderSceneDelegate::update_visibility() DEG_iterator_objects_end, &data, Object *, - object) { + object) + { if (!object_data(object_prim_id(object))) { update_objects(object); diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 5a082a572cdf..5d77baae1617 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -69,7 +69,8 @@ void InstancerData::update() Object *object = (Object *)id; if (id->recalc & ID_RECALC_GEOMETRY || (object->data && ((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) || - id->recalc & ID_RECALC_TRANSFORM) { + id->recalc & ID_RECALC_TRANSFORM) + { set_instances(); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( prim_id, pxr::HdChangeTracker::AllDirty); @@ -115,8 +116,8 @@ bool InstancerData::update_instances_visibility() { bool prev_visible = instances_visible; instances_visible = BKE_object_visibility((Object *)id, - DEG_get_mode(scene_delegate_->depsgraph)) == - OB_VISIBLE_INSTANCES; + DEG_get_mode(scene_delegate_->depsgraph)) == + OB_VISIBLE_INSTANCES; bool ret = instances_visible != prev_visible; if (ret) { ID_LOG(2, ""); @@ -236,7 +237,8 @@ void InstancerData::check_update(Object *object) if (l_it != light_instances_.end()) { Object *obj = (Object *)l_it->second.data->id; if (obj->id.recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY) || - ((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY) { + ((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY) + { set_instances(); } return; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 0bae621a101b..dcb47524b7d3 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -27,7 +27,8 @@ void MeshData::init() Object *object = (Object *)id; if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && - BLI_listbase_is_empty(&object->modifiers)) { + BLI_listbase_is_empty(&object->modifiers)) + { write_mesh((Mesh *)object->data); } else { -- 2.30.2 From ef7bb10a4d66b427df082fccdbb5bcd91a58a9b6 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 15:18:17 +0300 Subject: [PATCH 18/19] fixes --- .../scene_delegate/blender_scene_delegate.cc | 4 +++ .../render/hydra/scene_delegate/instancer.cc | 25 ++++++++----------- .../render/hydra/scene_delegate/object.cc | 4 ++- 3 files changed, 17 insertions(+), 16 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 63c13dec5d8b..12a7c2edb004 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -327,6 +327,10 @@ void BlenderSceneDelegate::update_instancers(Object *object) i_data->update_visibility(); } else { + InstancerData *parent_i_data = instancer_data(instancer_prim_id(object->parent)); + if (object->parent && parent_i_data) { + parent_i_data->update_visibility(); + } i_data->remove(); instancers_.erase(id); } diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 5d77baae1617..f0be14813ae4 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_instances_visibility() { bool prev_visible = instances_visible; instances_visible = BKE_object_visibility((Object *)id, - DEG_get_mode(scene_delegate_->depsgraph)) == + DEG_get_mode(scene_delegate_->depsgraph)) & OB_VISIBLE_INSTANCES; bool ret = instances_visible != prev_visible; if (ret) { @@ -130,20 +130,16 @@ bool InstancerData::update_visibility() bool ret = ObjectData::update_visibility(); bool dup_ret = update_duplicator_visibility(); bool inst_ret = update_instances_visibility(); - if (dup_ret) { + + Object *ob = ((Object *)id)->parent; + InstancerData *parent_i_data = scene_delegate_->instancer_data( + scene_delegate_->instancer_prim_id(ob)); + + if (dup_ret || (ob && parent_i_data && parent_i_data->visible != duplicator_visible)) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); - Object *ob = ((Object *)id)->parent; - if (ob) { - InstancerData *obj_data = scene_delegate_->instancer_data( - scene_delegate_->instancer_prim_id(ob)); - if (DEG_get_mode(scene_delegate_->depsgraph) == DAG_EVAL_RENDER) { - obj_data->visible = duplicator_visible; - change_tracker.MarkInstancerDirty(obj_data->prim_id, - pxr::HdChangeTracker::DirtyVisibility); - } - else { - obj_data->update_visibility(); - } + if (ob && parent_i_data) { + parent_i_data->visible = duplicator_visible; + change_tracker.MarkInstancerDirty(parent_i_data->prim_id, pxr::HdChangeTracker::DirtyVisibility); } visible = instances_visible; change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); @@ -362,7 +358,6 @@ void InstancerData::set_instances() inst->data = std::make_unique(scene_delegate_, ob, p_id); inst->data->init(); inst->data->insert(); - inst->data->update_visibility(); } else { inst = &it->second; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index a27b635b6718..0d5ec26ceff8 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -70,7 +70,9 @@ bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object } } else { - ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + if (object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + } if (object->parent && (object->parent->transflag & OB_DUPLI)) { ret = false; } -- 2.30.2 From 456b4e49dad2da6b57d4ea3b057d73db379d3a44 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 15:31:50 +0300 Subject: [PATCH 19/19] make format --- source/blender/render/hydra/scene_delegate/instancer.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index f0be14813ae4..60521e4e4e24 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -139,7 +139,8 @@ bool InstancerData::update_visibility() auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); if (ob && parent_i_data) { parent_i_data->visible = duplicator_visible; - change_tracker.MarkInstancerDirty(parent_i_data->prim_id, pxr::HdChangeTracker::DirtyVisibility); + change_tracker.MarkInstancerDirty(parent_i_data->prim_id, + pxr::HdChangeTracker::DirtyVisibility); } visible = instances_visible; change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); -- 2.30.2