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
3 changed files with 56 additions and 3 deletions
Showing only changes of commit af51ff7dfe - Show all commits

View File

@ -3,6 +3,7 @@
#include <bitset> #include <bitset>
#include "BKE_object.h"
#include "DEG_depsgraph_query.h" #include "DEG_depsgraph_query.h"
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
@ -388,9 +389,10 @@ void BlenderSceneDelegate::check_updates()
DEGIDIterData data = {0}; DEGIDIterData data = {0};
data.graph = depsgraph; data.graph = depsgraph;
data.only_updated = true; data.only_updated = true;
eEvaluationMode deg_mode = DEG_get_mode(depsgraph);
ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
2, 2,
"Update: %s [%s]", "Update: %s [%s]",
@ -400,6 +402,11 @@ void BlenderSceneDelegate::check_updates()
switch (GS(id->name)) { switch (GS(id->name)) {
case ID_OB: { case ID_OB: {
Object *object = (Object *)id; Object *object = (Object *)id;
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
2,
"Visibility: %s [%s]",
object->id.name,
std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str());
update_objects(object); update_objects(object);
update_instancers(object); update_instancers(object);
} break; } break;
@ -461,6 +468,8 @@ void BlenderSceneDelegate::add_new_objects()
data.settings = &settings; data.settings = &settings;
data.graph = settings.depsgraph; data.graph = settings.depsgraph;
data.flag = settings.flags; data.flag = settings.flags;
eEvaluationMode deg_mode = DEG_get_mode(depsgraph);
ITER_BEGIN (DEG_iterator_objects_begin, ITER_BEGIN (DEG_iterator_objects_begin,
DEG_iterator_objects_next, DEG_iterator_objects_next,
DEG_iterator_objects_end, DEG_iterator_objects_end,
@ -468,7 +477,11 @@ void BlenderSceneDelegate::add_new_objects()
Object *, Object *,
object) object)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
2,
"Visibility: %s [%s]",
object->id.name,
std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str());
update_objects(object); update_objects(object);
update_instancers(object); update_instancers(object);
} }
@ -487,6 +500,7 @@ void BlenderSceneDelegate::remove_unused_objects()
data.settings = &settings; data.settings = &settings;
data.graph = settings.depsgraph; data.graph = settings.depsgraph;
data.flag = settings.flags; data.flag = settings.flags;
ITER_BEGIN (DEG_iterator_objects_begin, ITER_BEGIN (DEG_iterator_objects_begin,
DEG_iterator_objects_next, DEG_iterator_objects_next,
DEG_iterator_objects_end, DEG_iterator_objects_end,
@ -566,6 +580,8 @@ void BlenderSceneDelegate::update_visibility()
data.settings = &settings; data.settings = &settings;
data.graph = settings.depsgraph; data.graph = settings.depsgraph;
data.flag = settings.flags; data.flag = settings.flags;
eEvaluationMode deg_mode = DEG_get_mode(depsgraph);
ITER_BEGIN (DEG_iterator_objects_begin, ITER_BEGIN (DEG_iterator_objects_begin,
DEG_iterator_objects_next, DEG_iterator_objects_next,
DEG_iterator_objects_end, DEG_iterator_objects_end,
@ -573,7 +589,11 @@ void BlenderSceneDelegate::update_visibility()
Object *, Object *,
object) object)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
2,
"Visibility: %s [%s]",
object->id.name,
std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str());
if (!object_data(object_prim_id(object))) { if (!object_data(object_prim_id(object))) {
update_objects(object); update_objects(object);
} }

View File

@ -257,6 +257,35 @@ void InstancerData::update_double_sided(MaterialData *mat_data)
} }
} }
bool InstancerData::is_instance_visible(Object *object)
{
bool ret = true;
eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph);
if (deg_mode == DAG_EVAL_VIEWPORT) {
ret = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, object);
if (ret && object->transflag & OB_DUPLI) {
ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT;
}
}
else {
int vis = BKE_object_visibility(object, deg_mode);
ret = vis & OB_VISIBLE_SELF;
if (ret && object->transflag & OB_DUPLI) {
ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER;
}
//if (ret) {
// /* If some of parent object is instacer, then object is invisible in Final render */
// for (Object *ob = object->parent; ob != nullptr; ob = ob->parent) {
// if (ob->transflag & OB_DUPLI) {
// ret = false;
// break;
// }
// }
//}
}
return ret;
}
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> */
@ -296,6 +325,9 @@ void InstancerData::set_instances()
if (!is_supported(ob)) { if (!is_supported(ob)) {
continue; continue;
} }
if (!is_instance_visible(ob)) {
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) {

View File

@ -47,6 +47,7 @@ class InstancerData : public ObjectData {
void update_double_sided(MaterialData *mat_data); void update_double_sided(MaterialData *mat_data);
private: private:
bool is_instance_visible(Object *object);
pxr::SdfPath object_prim_id(Object *object) const; pxr::SdfPath object_prim_id(Object *object) const;
pxr::SdfPath light_prim_id(LightInstance const &inst, int index) const; pxr::SdfPath light_prim_id(LightInstance const &inst, int index) const;
int light_prim_id_index(pxr::SdfPath const &id) const; int light_prim_id_index(pxr::SdfPath const &id) const;