forked from blender/blender
Make object visibility and instancing creation to be calculated via depsgraph #57
@ -326,10 +326,13 @@ InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool
|
||||
p_id = id;
|
||||
}
|
||||
|
||||
auto i_data = instancers_.lookup_ptr(p_id);
|
||||
if (i_data) {
|
||||
return i_data->get();
|
||||
if (instancer_data_ && p_id == instancer_data_->prim_id) {
|
||||
return instancer_data_.get();
|
||||
}
|
||||
//auto i_data = instancers_.lookup_ptr(p_id);
|
||||
//if (i_data) {
|
||||
// return i_data->get();
|
||||
//}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -499,7 +502,8 @@ void BlenderSceneDelegate::add_new_objects()
|
||||
{
|
||||
DEGObjectIterSettings settings = {0};
|
||||
settings.depsgraph = depsgraph;
|
||||
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
|
||||
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
|
||||
DEG_ITER_OBJECT_FLAG_VISIBLE;
|
||||
DEGObjectIterData data = {0};
|
||||
data.settings = &settings;
|
||||
data.graph = settings.depsgraph;
|
||||
@ -519,9 +523,14 @@ void BlenderSceneDelegate::add_new_objects()
|
||||
object->id.name,
|
||||
std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str());
|
||||
update_objects(object);
|
||||
update_instancers(object);
|
||||
//update_instancers(object);
|
||||
}
|
||||
ITER_END;
|
||||
|
||||
instancer_data_ = std::make_unique<InstancerData>(
|
||||
this, nullptr, GetDelegateID().AppendElementString("Instancer"));
|
||||
instancer_data_->init();
|
||||
instancer_data_->insert();
|
||||
}
|
||||
|
||||
void BlenderSceneDelegate::remove_unused_objects()
|
||||
|
@ -97,6 +97,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
ObjectDataMap objects_;
|
||||
MaterialDataMap materials_;
|
||||
InstancerDataMap instancers_;
|
||||
std::unique_ptr<InstancerData> instancer_data_;
|
||||
std::unique_ptr<WorldData> world_data_;
|
||||
};
|
||||
|
||||
|
@ -56,9 +56,8 @@ template<class T> const T IdData::get_data(pxr::TfToken const &key) const
|
||||
#define ID_LOG(level, msg, ...) \
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, \
|
||||
level, \
|
||||
"%s (%s): " msg, \
|
||||
"%s: " msg, \
|
||||
prim_id.GetText(), \
|
||||
id->name, \
|
||||
##__VA_ARGS__);
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -349,11 +349,27 @@ void InstancerData::write_instances()
|
||||
l_inst.transforms.clear();
|
||||
}
|
||||
|
||||
ListBase *lb = object_duplilist(
|
||||
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
|
||||
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
||||
DEGObjectIterSettings s = {0};
|
||||
s.depsgraph = scene_delegate_->depsgraph;
|
||||
s.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
|
||||
DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_DUPLI;
|
||||
DEGObjectIterData d = {0};
|
||||
d.settings = &s;
|
||||
d.graph = s.depsgraph;
|
||||
d.flag = s.flags;
|
||||
ITER_BEGIN (DEG_iterator_objects_begin,
|
||||
DEG_iterator_objects_next,
|
||||
DEG_iterator_objects_end,
|
||||
&d,
|
||||
Object *,
|
||||
object)
|
||||
{
|
||||
if (d.dupli_object_current == nullptr) {
|
||||
continue;
|
||||
}
|
||||
DupliObject *dupli = d.dupli_object_current;
|
||||
Object *ob = dupli->ob;
|
||||
if (!is_supported(ob) || !is_instance_visible(ob)) {
|
||||
if (!is_supported(ob)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -381,7 +397,7 @@ void InstancerData::write_instances()
|
||||
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));
|
||||
}
|
||||
}
|
||||
free_object_duplilist(lb);
|
||||
ITER_END;
|
||||
|
||||
/* Remove mesh intances without indices */
|
||||
mesh_instances_.remove_if([&](auto item) {
|
||||
@ -393,8 +409,10 @@ void InstancerData::write_instances()
|
||||
});
|
||||
|
||||
/* Update light intances and remove instances without transforms */
|
||||
for (auto &l_inst : light_instances_.values()) {
|
||||
update_light_instance(l_inst);
|
||||
}
|
||||
light_instances_.remove_if([&](auto item) {
|
||||
update_light_instance(item.value);
|
||||
return item.value.transforms.empty();
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user