forked from blender/blender
Fix visibility of instancer object #43
@ -301,9 +301,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
|
||||
if (obj_data) {
|
||||
obj_data->update_parent();
|
||||
obj_data->update();
|
||||
return;
|
||||
}
|
||||
if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) {
|
||||
obj_data->update_visibility();
|
||||
return;
|
||||
}
|
||||
objects_[id] = ObjectData::create(this, object, id);
|
||||
@ -336,14 +334,10 @@ void BlenderSceneDelegate::update_instancers(Object *object)
|
||||
if ((object->transflag & OB_DUPLI) == 0) {
|
||||
return;
|
||||
}
|
||||
if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) {
|
||||
return;
|
||||
}
|
||||
instancers_[id] = std::make_unique<InstancerData>(this, object, id);
|
||||
i_data = instancer_data(id);
|
||||
i_data->init();
|
||||
i_data->insert();
|
||||
i_data->update_visibility();
|
||||
}
|
||||
|
||||
void BlenderSceneDelegate::update_world()
|
||||
@ -388,8 +382,8 @@ void BlenderSceneDelegate::check_updates()
|
||||
switch (GS(id->name)) {
|
||||
case ID_OB: {
|
||||
Object *object = (Object *)id;
|
||||
update_objects(object);
|
||||
update_instancers(object);
|
||||
update_objects(object);
|
||||
} break;
|
||||
|
||||
case ID_MA: {
|
||||
@ -406,6 +400,10 @@ void BlenderSceneDelegate::check_updates()
|
||||
} break;
|
||||
|
||||
case ID_SCE: {
|
||||
if (id->recalc & ID_RECALC_COPY_ON_WRITE && !(id->recalc & ID_RECALC_SELECT)) {
|
||||
do_update_collection = true;
|
||||
do_update_visibility = true;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_BASE_FLAGS) {
|
||||
do_update_visibility = true;
|
||||
}
|
||||
@ -440,7 +438,7 @@ void BlenderSceneDelegate::add_new_objects()
|
||||
{
|
||||
DEGObjectIterSettings settings = {0};
|
||||
settings.depsgraph = depsgraph;
|
||||
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE |
|
||||
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
|
||||
DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
|
||||
DEGObjectIterData data = {0};
|
||||
data.settings = &settings;
|
||||
@ -535,9 +533,7 @@ void BlenderSceneDelegate::update_visibility()
|
||||
{
|
||||
for (auto &it : objects_) {
|
||||
it.second->update_visibility();
|
||||
}
|
||||
for (auto &it : instancers_) {
|
||||
it.second->update_visibility();
|
||||
it.second->update_parent();
|
||||
}
|
||||
|
||||
/* Add objects which were invisible before and not added yet */
|
||||
|
@ -4,6 +4,9 @@
|
||||
#include <pxr/base/gf/vec2f.h>
|
||||
#include <pxr/imaging/hd/light.h>
|
||||
|
||||
#include "BKE_object.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "instancer.h"
|
||||
|
||||
@ -33,6 +36,23 @@ bool InstancerData::is_supported(Object *object)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
Object *child_object)
|
||||
{
|
||||
bool ret = true;
|
||||
eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph);
|
||||
ret = BKE_object_visibility(object, deg_mode) & (OB_VISIBLE_SELF | OB_VISIBLE_INSTANCES);
|
||||
if (ret && child_object && child_object->transflag & OB_DUPLI)
|
||||
{
|
||||
int flag = deg_mode == DAG_EVAL_VIEWPORT ? OB_DUPLI_FLAG_VIEWPORT : OB_DUPLI_FLAG_RENDER;
|
||||
|
||||
ret = child_object->duplicator_visibility_flag & flag;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void InstancerData::init()
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
@ -83,9 +103,12 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool InstancerData::update_visibility()
|
||||
bool InstancerData::update_visibility(Object *child_object)
|
||||
{
|
||||
bool ret = ObjectData::update_visibility();
|
||||
bool prev_visible = visible;
|
||||
visible = is_visible(scene_delegate_, (Object *)id, child_object);
|
||||
bool ret = visible != prev_visible;
|
||||
|
||||
if (ret) {
|
||||
auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker();
|
||||
change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
||||
|
@ -25,6 +25,9 @@ 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,
|
||||
Object *child_object);
|
||||
|
||||
void init() override;
|
||||
void insert() override;
|
||||
@ -32,7 +35,7 @@ class InstancerData : public ObjectData {
|
||||
void update() override;
|
||||
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
bool update_visibility() override;
|
||||
bool update_visibility(Object *child_object);
|
||||
|
||||
pxr::GfMatrix4d get_transform(pxr::SdfPath const &id) const;
|
||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
||||
|
@ -2,6 +2,7 @@
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#include "BKE_object.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "light.h"
|
||||
@ -59,14 +60,31 @@ bool ObjectData::is_supported(Object *object)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjectData::update_visibility()
|
||||
{
|
||||
if (!scene_delegate_->view3d) {
|
||||
return false;
|
||||
bool ObjectData::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);
|
||||
if (ret && object->transflag & OB_DUPLI) {
|
||||
ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT;
|
||||
}
|
||||
}
|
||||
/*
|
||||
else {
|
||||
if (object->transflag & OB_DUPLI) {
|
||||
ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER;
|
||||
}
|
||||
if (object->parent && (object->parent->transflag & OB_DUPLI)) {
|
||||
ret = false;
|
||||
}
|
||||
}*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObjectData::update_visibility()
|
||||
{
|
||||
bool prev_visible = visible;
|
||||
visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, (Object *)id);
|
||||
visible = is_visible(scene_delegate_, (Object *)id);
|
||||
bool ret = visible != prev_visible;
|
||||
if (ret) {
|
||||
ID_LOG(2, "");
|
||||
@ -76,19 +94,24 @@ bool ObjectData::update_visibility()
|
||||
|
||||
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();
|
||||
break;
|
||||
}
|
||||
i_data->update_visibility((Object *)id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ class ObjectData : public IdData {
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id);
|
||||
static bool is_supported(Object *object);
|
||||
static bool is_visible(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
|
||||
virtual bool update_visibility();
|
||||
void update_parent();
|
||||
|
Loading…
Reference in New Issue
Block a user