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
2 changed files with 15 additions and 10 deletions
Showing only changes of commit e13eb5da52 - Show all commits

View File

@ -438,6 +438,9 @@ void BlenderSceneDelegate::update_collection()
if (!ObjectData::is_supported(object)) { if (!ObjectData::is_supported(object)) {
continue; continue;
} }
if (!ObjectData::is_visible(this, object)) {

use macro DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS here

use macro `DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS` here
continue;
}
available_objects.add(object_prim_id(object).GetName()); available_objects.add(object_prim_id(object).GetName());
pxr::SdfPath id = object_prim_id(object); pxr::SdfPath id = object_prim_id(object);
@ -458,6 +461,9 @@ void BlenderSceneDelegate::update_collection()
instancer_data_->init(); instancer_data_->init();
instancer_data_->insert(); instancer_data_->insert();
} }
else {
instancer_data_->update();
}
/* Remove unused objects */ /* Remove unused objects */
objects_.remove_if([&](auto item) { objects_.remove_if([&](auto item) {

View File

@ -86,16 +86,10 @@ void InstancerData::remove()
void InstancerData::update() void InstancerData::update()
{ {
ID_LOG(1, ""); ID_LOG(1, "");
Object *object = (Object *)id;
if (id->recalc & ID_RECALC_GEOMETRY ||
(object->data && ((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) ||
id->recalc & ID_RECALC_TRANSFORM)
{
write_instances(); write_instances();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
prim_id, pxr::HdChangeTracker::AllDirty); prim_id, pxr::HdChangeTracker::AllDirty);
} }
}
pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const
{ {
@ -370,7 +364,9 @@ void InstancerData::write_instances()
if (!is_supported(ob)) { if (!is_supported(ob)) {
continue; continue;
} }
if (!ObjectData::is_visible(scene_delegate_, d.dupli_parent)) {
continue;
}
pxr::SdfPath p_id = object_prim_id(ob); pxr::SdfPath p_id = object_prim_id(ob);
if (ob->type == OB_LAMP) { if (ob->type == OB_LAMP) {
LightInstance *inst = light_instance(p_id); LightInstance *inst = light_instance(p_id);
@ -390,6 +386,9 @@ void InstancerData::write_instances()
inst->data->init(); inst->data->init();
inst->data->insert(); inst->data->insert();
} }
else {
inst->data->update();
}
ID_LOG(2, "Mesh %s %d", inst->data->id->name, mesh_transforms_.size()); ID_LOG(2, "Mesh %s %d", inst->data->id->name, mesh_transforms_.size());
inst->indices.push_back(mesh_transforms_.size()); inst->indices.push_back(mesh_transforms_.size());
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat)); mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));