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
4 changed files with 48 additions and 28 deletions
Showing only changes of commit 465ef3022b - Show all commits

View File

@ -300,6 +300,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
if (!ObjectData::is_supported(object)) {
return;
}
pxr::SdfPath id = object_prim_id(object);
ObjectData *obj_data = object_data(id);
if (obj_data) {
@ -308,12 +309,17 @@ void BlenderSceneDelegate::update_objects(Object *object)
obj_data->update_visibility();
return;
}
if (!ObjectData::is_visible(this, object)) {
/* Do not export new object if it is invisible */
return;
}
objects_[id] = ObjectData::create(this, object, id);
obj_data = object_data(id);
obj_data->update_parent();
obj_data->init();
obj_data->insert();
obj_data->update_visibility();
}
void BlenderSceneDelegate::update_instancers(Object *object)
@ -326,18 +332,26 @@ void BlenderSceneDelegate::update_instancers(Object *object)
pxr::SdfPath id = instancer_prim_id(object);
InstancerData *i_data = instancer_data(id);
if (i_data) {
if (object->transflag & OB_DUPLI) {
i_data->update();
}
else {
if ((object->transflag & OB_DUPLI) == 0) {
/* Object isn't instancer anymore and should be removed */
i_data->remove();
instancers_.erase(id);
}
return;
}
i_data->update();
return;
}
if ((object->transflag & OB_DUPLI) == 0) {
return;
}
if (!InstancerData::is_visible(this, object)) {
/* Do not export new instancer if it is invisible */
return;
}
instancers_[id] = std::make_unique<InstancerData>(this, object, id);
i_data = instancer_data(id);
i_data->init();
@ -536,16 +550,18 @@ void BlenderSceneDelegate::remove_unused_objects()
void BlenderSceneDelegate::update_visibility()
{
/* Updating visibility of existing objects/instancers */
for (auto &it : objects_) {
it.second->update_visibility();
it.second->update_parent();
}
for (auto &it : instancers_) {
it.second->update_visibility();
}
/* Add objects which were invisible before and not added yet */
/* Add objects/instancers which were invisible before and not added yet */
DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph;
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE |
DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
DEGObjectIterData data = {0};
data.settings = &settings;
data.graph = settings.depsgraph;

View File

@ -36,6 +36,17 @@ bool InstancerData::is_supported(Object *object)
return false;
}
bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object)
{
bool ret = true;
if (DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT) {
ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object);
}
else {
}
return ret;
}
bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate,
Object *object,
Object *child_object)
@ -101,11 +112,12 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const
return ret;
}
bool InstancerData::update_visibility(Object *child_object)
bool InstancerData::update_visibility()
{
bool prev_visible = visible;
visible = is_visible(scene_delegate_, (Object *)id, child_object);
visible = is_visible(scene_delegate_, (Object *)id);
bool ret = visible != prev_visible;
if (ret) {
auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker();
change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility);

View File

@ -25,6 +25,7 @@ class InstancerData : public ObjectData {
public:
InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
static bool is_supported(Object *object);
static bool is_visible(BlenderSceneDelegate *scene_delegate, Object *object);
static bool is_visible(BlenderSceneDelegate *scene_delegate,
Object *object,
Object *child_object);
@ -35,7 +36,7 @@ class InstancerData : public ObjectData {
void update() override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
bool update_visibility(Object *child_object);
bool update_visibility() override;
pxr::GfMatrix4d get_transform(pxr::SdfPath const &id) const;
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;

View File

@ -87,35 +87,26 @@ bool ObjectData::update_visibility()
{
bool prev_visible = visible;
visible = is_visible(scene_delegate_, (Object *)id);
bool ret = visible != prev_visible;
if (ret) {
ID_LOG(2, "");
}
return ret;
return visible != prev_visible;
}
void ObjectData::update_parent()
{
bool update_parent = false;
Object *object = (Object *)id;
if (parent_ != object->parent) {
ID_LOG(2, "");
parent_ = object->parent;
update_parent = true;
}
/* Looking for corresponded instancer and update it as parent */
for (Object *ob = parent_; ob != nullptr; ob = ob->parent) {
InstancerData *i_data = scene_delegate_->instancer_data(
scene_delegate_->instancer_prim_id(ob));
if (i_data) {
if (update_parent) {
i_data->update_as_parent();
}
i_data->update_visibility((Object *)id);
break;
}
}
}
}
void ObjectData::write_transform()