forked from blender/blender
Implement instancing for light objects #35
@ -307,6 +307,15 @@ void BlenderSceneDelegate::update_instancers(Object *object)
|
|||||||
i_data->update_visibility();
|
i_data->update_visibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BlenderSceneDelegate::update_instancer_as_parent(Object *object)
|
||||||
|
{
|
||||||
|
pxr::SdfPath id = instancer_prim_id(object);
|
||||||
|
InstancerData *i_data = instancer_data(id);
|
||||||
|
if (i_data) {
|
||||||
|
i_data->update_as_parent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::update_world()
|
void BlenderSceneDelegate::update_world()
|
||||||
{
|
{
|
||||||
World *world = scene->world;
|
World *world = scene->world;
|
||||||
|
@ -74,6 +74,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
|
|
||||||
void update_objects(Object *object);
|
void update_objects(Object *object);
|
||||||
void update_instancers(Object *object);
|
void update_instancers(Object *object);
|
||||||
|
void update_instancer_as_parent(Object *object);
|
||||||
void update_world();
|
void update_world();
|
||||||
void check_updates();
|
void check_updates();
|
||||||
void add_new_objects();
|
void add_new_objects();
|
||||||
|
@ -51,9 +51,6 @@ void InstancerData::insert()
|
|||||||
{
|
{
|
||||||
ID_LOG(2, "");
|
ID_LOG(2, "");
|
||||||
scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, prim_id);
|
scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, prim_id);
|
||||||
for (auto &it : instances_) {
|
|
||||||
it.second.obj_data->insert();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstancerData::remove()
|
void InstancerData::remove()
|
||||||
@ -149,6 +146,7 @@ void InstancerData::check_update(Object *object)
|
|||||||
}
|
}
|
||||||
ObjectData *obj_data = it->second.obj_data.get();
|
ObjectData *obj_data = it->second.obj_data.get();
|
||||||
obj_data->update();
|
obj_data->update();
|
||||||
|
obj_data->transform = pxr::GfMatrix4d(1.0);
|
||||||
|
|
||||||
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
||||||
if (object->id.recalc & ID_RECALC_TRANSFORM) {
|
if (object->id.recalc & ID_RECALC_TRANSFORM) {
|
||||||
@ -189,6 +187,13 @@ void InstancerData::available_materials(std::set<pxr::SdfPath> &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
|
pxr::SdfPath InstancerData::object_prim_id(Object *object) const
|
||||||
{
|
{
|
||||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||||
|
@ -38,6 +38,7 @@ class InstancerData : public ObjectData {
|
|||||||
void check_update(Object *object);
|
void check_update(Object *object);
|
||||||
void check_remove(std::set<std::string> &available_objects);
|
void check_remove(std::set<std::string> &available_objects);
|
||||||
void available_materials(std::set<pxr::SdfPath> &paths) const;
|
void available_materials(std::set<pxr::SdfPath> &paths) const;
|
||||||
|
void update_as_parent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfPath object_prim_id(Object *object) const;
|
pxr::SdfPath object_prim_id(Object *object) const;
|
||||||
|
@ -65,8 +65,16 @@ void MeshData::remove()
|
|||||||
|
|
||||||
void MeshData::update()
|
void MeshData::update()
|
||||||
{
|
{
|
||||||
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
|
||||||
Object *object = (Object *)id;
|
Object *object = (Object *)id;
|
||||||
|
if ((id->recalc & ID_RECALC_TRANSFORM) && parent_ != object->parent) {
|
||||||
|
/* parent was changed */
|
||||||
|
parent_ = object->parent;
|
||||||
|
if (parent_) {
|
||||||
|
scene_delegate_->update_instancer_as_parent(parent_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
||||||
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
|
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
|
||||||
init();
|
init();
|
||||||
bits = pxr::HdChangeTracker::AllDirty;
|
bits = pxr::HdChangeTracker::AllDirty;
|
||||||
|
@ -13,7 +13,10 @@ namespace blender::render::hydra {
|
|||||||
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
|
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
|
||||||
Object *object,
|
Object *object,
|
||||||
pxr::SdfPath const &prim_id)
|
pxr::SdfPath const &prim_id)
|
||||||
: IdData(scene_delegate, (ID *)object, prim_id), transform(pxr::GfMatrix4d(1.0)), visible(true)
|
: IdData(scene_delegate, (ID *)object, prim_id),
|
||||||
|
transform(pxr::GfMatrix4d(1.0)),
|
||||||
|
visible(true),
|
||||||
|
parent_(object->parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,9 @@ class ObjectData : public IdData {
|
|||||||
bool visible;
|
bool visible;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void write_transform();
|
virtual void write_transform();
|
||||||
|
|
||||||
|
Object *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ObjectDataMap =
|
using ObjectDataMap =
|
||||||
|
Loading…
Reference in New Issue
Block a user