Support several instancers on one object #24

Merged
Bogdan Nagirniak merged 16 commits from BLEN-383 into hydra-render 2023-04-19 02:46:24 +02:00
3 changed files with 29 additions and 7 deletions
Showing only changes of commit 038e480837 - Show all commits

View File

@ -170,10 +170,9 @@ void BlenderSceneDelegate::add_update_object(Object *object)
if ((object->transflag & OB_DUPLI) && InstancerData::supported(object)) {
add_update_instancer(object);
}
//InstancerData *i_data = instancer_data(object);
//if (i_data) {
// i_data->update();
//}
for (auto &it : instancers) {
it.second->check_update(object);
}
pxr::SdfPath id = ObjectData::prim_id(this, object);
ObjectData *obj_data = object_data(id);

View File

@ -114,7 +114,7 @@ pxr::SdfPathVector InstancerData::prototypes()
return paths;
}
void InstancerData::update(Object *object)
void InstancerData::check_update(Object *object)
{
pxr::SdfPath path = ObjectData::prim_id(scene_delegate, object);
path = p_id.AppendElementString(path.GetName());
@ -124,6 +124,28 @@ void InstancerData::update(Object *object)
}
ObjectData *obj_data = it->second.obj_data.get();
obj_data->update();
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
if (object->id.recalc & ID_RECALC_TRANSFORM) {
set_instances();
bits |= pxr::HdChangeTracker::DirtyTransform;
}
if (bits != pxr::HdChangeTracker::Clean) {
scene_delegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id, bits);
}
}
void InstancerData::check_remove(Object *object)
{
pxr::SdfPath path = ObjectData::prim_id(scene_delegate, object);
path = p_id.AppendElementString(path.GetName());
auto it = instances.find(path);
if (it == instances.end()) {
return;
}
set_instances();
scene_delegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
p_id, pxr::HdChangeTracker::AllDirty);
}
void InstancerData::set_instances()
@ -197,7 +219,7 @@ void InstancerData::update()
Object *object = (Object *)id;
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
init();
set_instances();
bits |= pxr::HdChangeTracker::AllDirty;
}
else if (id->recalc & ID_RECALC_TRANSFORM) {

View File

@ -35,7 +35,8 @@ class InstancerData : public ObjectData {
pxr::VtIntArray indices(pxr::SdfPath const &id);
ObjectData *object_data(pxr::SdfPath const &id);
pxr::SdfPathVector prototypes();
void update(Object *object);
void check_update(Object *object);
void check_remove(Object *object);
private:
void set_instances();