Fix visibility of instancer object #43

Merged
Bogdan Nagirniak merged 16 commits from BLEN-405_1 into hydra-render 2023-05-24 13:44:35 +02:00
Showing only changes of commit 0e028845b4 - Show all commits

View File

@ -188,8 +188,18 @@ pxr::SdfPathVector InstancerData::prototypes() const
void InstancerData::check_update(Object *object)
{
pxr::SdfPath path = object_prim_id(object);
/* Checking object in existing mesh_instances_ */
auto m_it = mesh_instances_.find(path);
if (m_it != mesh_instances_.end()) {
if (!is_instance_visible(object)) {
m_it->second.data->remove();
mesh_instances_.erase(m_it);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
prim_id, pxr::HdChangeTracker::AllDirty);
return;
}
m_it->second.data->update();
if (m_it->second.data->id->recalc & ID_RECALC_TRANSFORM) {
@ -200,8 +210,16 @@ void InstancerData::check_update(Object *object)
return;
}
/* Checking object in existing light_instances_ */
auto l_it = light_instances_.find(path);
if (l_it != light_instances_.end()) {
if (!is_instance_visible(object)) {
l_it->second.transforms.clear();
update_light_instance(l_it->second);
light_instances_.erase(l_it);
return;
}
Object *obj = (Object *)l_it->second.data->id;
if (obj->id.recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY) ||
((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY)
@ -210,6 +228,28 @@ void InstancerData::check_update(Object *object)
}
return;
}
/* Checking if object wasn't added to instances before */
if (is_supported(object) && is_instance_visible(object)) {
bool do_set_instances = false;
ListBase *lb = object_duplilist(
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
if (dupli->ob == object) {
do_set_instances = true;
break;
}
}
free_object_duplilist(lb);
if (do_set_instances) {
set_instances();
if (!mesh_instances_.empty()) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
prim_id, pxr::HdChangeTracker::AllDirty);
}
}
}
}
void InstancerData::check_remove(std::set<std::string> &available_objects)
@ -315,10 +355,7 @@ void InstancerData::set_instances()
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
Object *ob = dupli->ob;
if (!is_supported(ob)) {
continue;
}
if (!is_instance_visible(ob)) {
if (!is_supported(ob) || !is_instance_visible(ob)) {
continue;
}