Make object visibility and instancing creation to be calculated via depsgraph #57

Merged
Bogdan Nagirniak merged 16 commits from BLEN-442 into hydra-render 2023-07-08 10:09:53 +02:00
5 changed files with 18 additions and 15 deletions
Showing only changes of commit 961a406367 - Show all commits

View File

@ -438,8 +438,7 @@ void BlenderSceneDelegate::update_collection()
DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph;
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_DUPLI;
settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS;

use macro DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS here

use macro `DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS` here
DEGObjectIterData data = {0};
data.settings = &settings;
data.graph = settings.depsgraph;

View File

@ -194,10 +194,17 @@ void InstancerData::post_update()
return res;
});
/* Update light intances and remove instances without transforms */
for (auto &l_inst : light_instances_.values()) {
update_light_instance(l_inst);
}
light_instances_.remove_if([&](auto item) { return item.value.transforms.empty(); });
/* Insert/remove/update instancer in RenderIndex */
pxr::HdRenderIndex &index = scene_delegate_->GetRenderIndex();
if (mesh_instances_.is_empty()) {
if (index.HasInstancer(prim_id)) {
/* Important: removing instancer when light_instances_ are empty too */
if (index.HasInstancer(prim_id) && light_instances_.is_empty()) {
index.RemoveInstancer(prim_id);
ID_LOG(1, "Remove instancer");
}
@ -212,12 +219,6 @@ void InstancerData::post_update()
ID_LOG(1, "Insert instancer");
}
}
/* Update light intances and remove instances without transforms */
for (auto &l_inst : light_instances_.values()) {
update_light_instance(l_inst);
}
light_instances_.remove_if([&](auto item) { return item.value.transforms.empty(); });
}
pxr::SdfPath InstancerData::object_prim_id(Object *object) const

View File

@ -42,6 +42,12 @@ class InstancerData : public IdData {
void available_materials(Set<pxr::SdfPath> &paths) const;
void update_double_sided(MaterialData *mat_data);
/* Following update functions are working together:

Please add comment why this is done in this way

Please add comment why this is done in this way
pre_update()
update_instance()
update_instance()
...
post_update() */
void pre_update();
void update_instance(Object *parent_ob, DupliObject *dupli);
void post_update();

View File

@ -176,11 +176,8 @@ void WorldData::write_transform()
{
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180),
pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), pxr::GfVec3d());
}
} // namespace blender::render::hydra