forked from blender/blender
Fix visibility of instancer object #43
@ -3,6 +3,7 @@
|
||||
|
||||
#include <bitset>
|
||||
|
||||
#include "BKE_object.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
@ -388,9 +389,10 @@ void BlenderSceneDelegate::check_updates()
|
||||
DEGIDIterData data = {0};
|
||||
data.graph = depsgraph;
|
||||
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)
|
||||
{
|
||||
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
|
||||
2,
|
||||
"Update: %s [%s]",
|
||||
@ -400,6 +402,11 @@ void BlenderSceneDelegate::check_updates()
|
||||
switch (GS(id->name)) {
|
||||
case ID_OB: {
|
||||
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_instancers(object);
|
||||
} break;
|
||||
@ -461,6 +468,8 @@ void BlenderSceneDelegate::add_new_objects()
|
||||
data.settings = &settings;
|
||||
data.graph = settings.depsgraph;
|
||||
data.flag = settings.flags;
|
||||
eEvaluationMode deg_mode = DEG_get_mode(depsgraph);
|
||||
|
||||
ITER_BEGIN (DEG_iterator_objects_begin,
|
||||
DEG_iterator_objects_next,
|
||||
DEG_iterator_objects_end,
|
||||
@ -468,7 +477,11 @@ void BlenderSceneDelegate::add_new_objects()
|
||||
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_instancers(object);
|
||||
}
|
||||
@ -487,6 +500,7 @@ void BlenderSceneDelegate::remove_unused_objects()
|
||||
data.settings = &settings;
|
||||
data.graph = settings.depsgraph;
|
||||
data.flag = settings.flags;
|
||||
|
||||
ITER_BEGIN (DEG_iterator_objects_begin,
|
||||
DEG_iterator_objects_next,
|
||||
DEG_iterator_objects_end,
|
||||
@ -566,6 +580,8 @@ void BlenderSceneDelegate::update_visibility()
|
||||
data.settings = &settings;
|
||||
data.graph = settings.depsgraph;
|
||||
data.flag = settings.flags;
|
||||
eEvaluationMode deg_mode = DEG_get_mode(depsgraph);
|
||||
|
||||
ITER_BEGIN (DEG_iterator_objects_begin,
|
||||
DEG_iterator_objects_next,
|
||||
DEG_iterator_objects_end,
|
||||
@ -573,7 +589,11 @@ void BlenderSceneDelegate::update_visibility()
|
||||
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))) {
|
||||
update_objects(object);
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
/* 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)) {
|
||||
continue;
|
||||
}
|
||||
if (!is_instance_visible(ob)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pxr::SdfPath p_id = object_prim_id(ob);
|
||||
if (ob->type == OB_LAMP) {
|
||||
|
@ -47,6 +47,7 @@ class InstancerData : public ObjectData {
|
||||
void update_double_sided(MaterialData *mat_data);
|
||||
|
||||
private:
|
||||
bool is_instance_visible(Object *object);
|
||||
pxr::SdfPath object_prim_id(Object *object) const;
|
||||
pxr::SdfPath light_prim_id(LightInstance const &inst, int index) const;
|
||||
int light_prim_id_index(pxr::SdfPath const &id) const;
|
||||
|
Loading…
Reference in New Issue
Block a user