forked from blender/blender
Implement instancing for light objects #35
@ -33,11 +33,11 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
|
||||
{
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
|
||||
|
||||
pxr::SdfPath i_id = instancer_prim_id(id);
|
||||
if (!i_id.IsEmpty()) {
|
||||
InstancerData *i_data = instancer_data(i_id);
|
||||
InstancerData *i_data = instancer_data(id, true);
|
||||
if (i_data) {
|
||||
return i_data->get_transform(id);
|
||||
}
|
||||
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (obj_data) {
|
||||
return obj_data->transform;
|
||||
@ -218,18 +218,6 @@ pxr::SdfPath BlenderSceneDelegate::instancer_prim_id(Object *object) const
|
||||
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
|
||||
{
|
||||
return GetDelegateID().AppendElementString("World");
|
||||
@ -241,7 +229,7 @@ ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
|
||||
if (it != objects_.end()) {
|
||||
return it->second.get();
|
||||
}
|
||||
InstancerData *i_data = instancer_data(id.GetParentPath());
|
||||
InstancerData *i_data = instancer_data(id, true);
|
||||
if (i_data) {
|
||||
return i_data->object_data(id);
|
||||
}
|
||||
@ -267,9 +255,23 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const
|
||||
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()) {
|
||||
return it->second.get();
|
||||
}
|
||||
|
@ -64,14 +64,13 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
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 instancer_prim_id(pxr::SdfPath const &child_id) 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;
|
||||
InstancerData *instancer_data(pxr::SdfPath const &id, bool child_id = false) const;
|
||||
|
||||
void update_objects(Object *object);
|
||||
void update_instancers(Object *object);
|
||||
|
@ -225,6 +225,7 @@ void InstancerData::set_instances()
|
||||
continue;
|
||||
}
|
||||
p_id = object_prim_id(dupli->ob);
|
||||
|
||||
if (ob->type == OB_LAMP) {
|
||||
auto it = mesh_instances_.find(p_id);
|
||||
if (it == mesh_instances_.end()) {
|
||||
|
@ -71,8 +71,8 @@ void MeshData::update()
|
||||
|
||||
/* 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);
|
||||
InstancerData *i_data = scene_delegate_->instancer_data(
|
||||
scene_delegate_->instancer_prim_id(ob));
|
||||
if (i_data) {
|
||||
i_data->update_as_parent();
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user