Implement instancing for light objects #35

Merged
Bogdan Nagirniak merged 18 commits from BLEN-395 into hydra-render 2023-05-04 15:12:27 +02:00
4 changed files with 24 additions and 22 deletions
Showing only changes of commit 946f3a2ae4 - Show all commits

View File

@ -33,11 +33,11 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
pxr::SdfPath i_id = instancer_prim_id(id); InstancerData *i_data = instancer_data(id, true);
if (!i_id.IsEmpty()) { if (i_data) {
InstancerData *i_data = instancer_data(i_id);
return i_data->get_transform(id); return i_data->get_transform(id);
} }
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
return obj_data->transform; return obj_data->transform;
@ -218,18 +218,6 @@ pxr::SdfPath BlenderSceneDelegate::instancer_prim_id(Object *object) const
return prim_id((ID *)object, "I"); return prim_id((ID *)object, "I");
} }
pxr::SdfPath BlenderSceneDelegate::instancer_prim_id(pxr::SdfPath const &child_id) const
{
int n = child_id.GetPathElementCount();
if (n == 3) {
return child_id.GetParentPath();
}
if (n == 4) {
return child_id.GetParentPath().GetParentPath();
}
return pxr::SdfPath();
}
pxr::SdfPath BlenderSceneDelegate::world_prim_id() const pxr::SdfPath BlenderSceneDelegate::world_prim_id() const
{ {
return GetDelegateID().AppendElementString("World"); return GetDelegateID().AppendElementString("World");
@ -241,7 +229,7 @@ ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
if (it != objects_.end()) { if (it != objects_.end()) {
return it->second.get(); return it->second.get();
} }
InstancerData *i_data = instancer_data(id.GetParentPath()); InstancerData *i_data = instancer_data(id, true);
if (i_data) { if (i_data) {
return i_data->object_data(id); return i_data->object_data(id);
} }
@ -267,9 +255,23 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const
return it->second.get(); return it->second.get();
} }
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id) const InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool child_id) const
{ {
auto it = instancers_.find(id); pxr::SdfPath p_id;
if (child_id) {
int n = id.GetPathElementCount();
if (n == 3) {
p_id = id.GetParentPath();
}
else if (n == 4) {
p_id = id.GetParentPath().GetParentPath();
}
}
else {
p_id = id;
}
auto it = instancers_.find(p_id);
if (it != instancers_.end()) { if (it != instancers_.end()) {
return it->second.get(); return it->second.get();
} }

View File

@ -64,14 +64,13 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
pxr::SdfPath object_prim_id(Object *object) const; pxr::SdfPath object_prim_id(Object *object) const;
pxr::SdfPath material_prim_id(Material *mat) const; pxr::SdfPath material_prim_id(Material *mat) const;
pxr::SdfPath instancer_prim_id(Object *object) const; pxr::SdfPath instancer_prim_id(Object *object) const;
pxr::SdfPath instancer_prim_id(pxr::SdfPath const &child_id) const;
pxr::SdfPath world_prim_id() const; pxr::SdfPath world_prim_id() const;
ObjectData *object_data(pxr::SdfPath const &id) const; ObjectData *object_data(pxr::SdfPath const &id) const;
MeshData *mesh_data(pxr::SdfPath const &id) const; MeshData *mesh_data(pxr::SdfPath const &id) const;
LightData *light_data(pxr::SdfPath const &id) const; LightData *light_data(pxr::SdfPath const &id) const;
MaterialData *material_data(pxr::SdfPath const &id) const; MaterialData *material_data(pxr::SdfPath const &id) const;
InstancerData *instancer_data(pxr::SdfPath const &id) const; InstancerData *instancer_data(pxr::SdfPath const &id, bool child_id = false) const;
void update_objects(Object *object); void update_objects(Object *object);
void update_instancers(Object *object); void update_instancers(Object *object);

View File

@ -225,6 +225,7 @@ void InstancerData::set_instances()
continue; continue;
} }
p_id = object_prim_id(dupli->ob); p_id = object_prim_id(dupli->ob);
if (ob->type == OB_LAMP) { if (ob->type == OB_LAMP) {
auto it = mesh_instances_.find(p_id); auto it = mesh_instances_.find(p_id);
if (it == mesh_instances_.end()) { if (it == mesh_instances_.end()) {

View File

@ -71,8 +71,8 @@ void MeshData::update()
/* Looking for corresponded instancer and update it as parent */ /* Looking for corresponded instancer and update it as parent */
for (Object *ob = parent_; ob != nullptr; ob = ob->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(
InstancerData *i_data = scene_delegate_->instancer_data(i_id); scene_delegate_->instancer_prim_id(ob));
if (i_data) { if (i_data) {
i_data->update_as_parent(); i_data->update_as_parent();
break; break;