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 9e0b2f6e7c81..e542a3e7d11b 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_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */ class BlenderSceneDelegate : public pxr::HdSceneDelegate { - friend MeshData; /* has access to materials_*/ + friend MeshData; /* has access to materials and instances */ 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 b05a12bdb604..d87e5e7a5625 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -51,9 +51,6 @@ void InstancerData::insert() { ID_LOG(2, ""); scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, prim_id); - for (auto &it : instances_) { - it.second.obj_data->insert(); - } } void InstancerData::remove() @@ -149,6 +146,7 @@ void InstancerData::check_update(Object *object) } ObjectData *obj_data = it->second.obj_data.get(); obj_data->update(); + obj_data->transform = pxr::GfMatrix4d(1.0); pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; if (object->id.recalc & ID_RECALC_TRANSFORM) { @@ -189,6 +187,13 @@ void InstancerData::available_materials(std::set &paths) const } } +void InstancerData::update_as_parent() +{ + set_instances(); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( + prim_id, pxr::HdChangeTracker::AllDirty); +} + pxr::SdfPath InstancerData::object_prim_id(Object *object) const { /* Making id of object in form like _ */ diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index a4cf9f7bf534..02affd283958 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -38,6 +38,7 @@ class InstancerData : public ObjectData { void check_update(Object *object); void check_remove(std::set &available_objects); void available_materials(std::set &paths) const; + void update_as_parent(); private: pxr::SdfPath object_prim_id(Object *object) const; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index c2797a05ae3c..7c9063288668 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -17,7 +17,7 @@ namespace blender::render::hydra { MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id) - : ObjectData(scene_delegate, object, prim_id) + : ObjectData(scene_delegate, object, prim_id), parent_(object->parent) { } @@ -65,8 +65,22 @@ void MeshData::remove() void MeshData::update() { - pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; Object *object = (Object *)id; + if (parent_ != object->parent) { + parent_ = object->parent; + + /* Looking for corresponded instancer and update it as parent */ + for (Object *ob = parent_; ob != nullptr; ob = ob->parent) { + pxr::SdfPath i_id = scene_delegate_->instancer_prim_id(ob); + InstancerData *i_data = scene_delegate_->instancer_data(i_id); + if (i_data) { + i_data->update_as_parent(); + break; + } + } + } + + pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { init(); bits = pxr::HdChangeTracker::AllDirty; diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index 459411bc6a52..8d551a14f119 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -29,7 +29,7 @@ class MeshData : public ObjectData { pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; pxr::SdfPath material_id() const; - protected: + private: void write_mesh(Mesh *mesh); void write_material(); void write_uv_maps(Mesh *mesh); @@ -43,6 +43,7 @@ class MeshData : public ObjectData { pxr::VtMatrix4dArray instances_; MaterialData *mat_data_ = nullptr; + Object *parent_; }; } // namespace blender::render::hydra