forked from blender/blender
Support several instancers on one object #24
@ -375,8 +375,8 @@ void BlenderSceneDelegate::add_new_objects()
|
|||||||
|
|
||||||
void BlenderSceneDelegate::remove_unused_objects()
|
void BlenderSceneDelegate::remove_unused_objects()
|
||||||
{
|
{
|
||||||
/* Export of new visible objects which were not exported before */
|
/* Get available objects */
|
||||||
std::set<pxr::SdfPath> available_objects;
|
std::set<std::string> available_objects;
|
||||||
|
|
||||||
DEGObjectIterSettings settings = {0};
|
DEGObjectIterSettings settings = {0};
|
||||||
settings.depsgraph = depsgraph;
|
settings.depsgraph = depsgraph;
|
||||||
@ -394,14 +394,26 @@ void BlenderSceneDelegate::remove_unused_objects()
|
|||||||
if (!ObjectData::supported(object)) {
|
if (!ObjectData::supported(object)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
available_objects.insert(ObjectData::prim_id(this, object));
|
available_objects.insert(ObjectData::prim_id(this, object).GetName());
|
||||||
available_objects.insert(InstancerData::prim_id(this, object));
|
available_objects.insert(InstancerData::prim_id(this, object).GetName());
|
||||||
}
|
}
|
||||||
ITER_END;
|
ITER_END;
|
||||||
|
|
||||||
/* remove unused objects */
|
/* Remove unused instancers */
|
||||||
|
for (auto it = instancers.begin(); it != instancers.end(); ++it) {
|
||||||
|
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
|
||||||
|
/* Remove objects from instancers */
|
||||||
|
it->second->check_remove(available_objects);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
it->second->remove();
|
||||||
|
instancers.erase(it);
|
||||||
|
it = instancers.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove unused objects */
|
||||||
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
||||||
if (available_objects.find(it->first) != available_objects.end()) {
|
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
it->second->remove();
|
it->second->remove();
|
||||||
@ -409,7 +421,8 @@ void BlenderSceneDelegate::remove_unused_objects()
|
|||||||
it = objects.begin();
|
it = objects.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove unused materials */
|
|
||||||
|
/* Remove unused materials */
|
||||||
std::set<pxr::SdfPath> available_materials;
|
std::set<pxr::SdfPath> available_materials;
|
||||||
for (auto &it : objects) {
|
for (auto &it : objects) {
|
||||||
MeshData *m_data = dynamic_cast<MeshData *>(it.second.get());
|
MeshData *m_data = dynamic_cast<MeshData *>(it.second.get());
|
||||||
@ -442,6 +455,32 @@ void BlenderSceneDelegate::update_visibility()
|
|||||||
for (auto &it : instancers) {
|
for (auto &it : instancers) {
|
||||||
it.second->update_visibility(view3d);
|
it.second->update_visibility(view3d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add objects 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;
|
||||||
|
DEGObjectIterData data = {0};
|
||||||
|
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,
|
||||||
|
&data,
|
||||||
|
Object *,
|
||||||
|
object) {
|
||||||
|
|
||||||
|
if (!ObjectData::supported(object)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!object_data(ObjectData::prim_id(this, object))) {
|
||||||
|
add_update_object(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ITER_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::clear()
|
void BlenderSceneDelegate::clear()
|
||||||
|
@ -140,16 +140,23 @@ void InstancerData::check_update(Object *object)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstancerData::check_remove(pxr::SdfPath const &obj_id)
|
void InstancerData::check_remove(std::set<std::string> &available_objects)
|
||||||
{
|
{
|
||||||
pxr::SdfPath path = p_id.AppendElementString(obj_id.GetName());
|
bool ret = false;
|
||||||
auto it = instances.find(path);
|
for (auto it = instances.begin(); it != instances.end(); ++it) {
|
||||||
if (it == instances.end()) {
|
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
it->second.obj_data->remove();
|
||||||
|
instances.erase(it);
|
||||||
|
it = instances.begin();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
if (ret) {
|
||||||
set_instances();
|
set_instances();
|
||||||
scene_delegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
|
scene_delegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id,
|
||||||
p_id, pxr::HdChangeTracker::AllDirty);
|
pxr::HdChangeTracker::AllDirty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
|
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
|
||||||
@ -218,7 +225,7 @@ void InstancerData::insert()
|
|||||||
|
|
||||||
void InstancerData::remove()
|
void InstancerData::remove()
|
||||||
{
|
{
|
||||||
ID_LOG(2, "");
|
CLOG_INFO(LOG_BSD, 2, "%s", p_id.GetText());
|
||||||
for (auto &it : instances) {
|
for (auto &it : instances) {
|
||||||
it.second.obj_data->remove();
|
it.second.obj_data->remove();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class InstancerData : public ObjectData {
|
|||||||
ObjectData *object_data(pxr::SdfPath const &id);
|
ObjectData *object_data(pxr::SdfPath const &id);
|
||||||
pxr::SdfPathVector prototypes();
|
pxr::SdfPathVector prototypes();
|
||||||
void check_update(Object *object);
|
void check_update(Object *object);
|
||||||
void check_remove(pxr::SdfPath const &obj_id);
|
void check_remove(std::set<std::string> &available_objects);
|
||||||
void available_materials(std::set<pxr::SdfPath> &paths);
|
void available_materials(std::set<pxr::SdfPath> &paths);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -160,7 +160,7 @@ void LightData::insert()
|
|||||||
|
|
||||||
void LightData::remove()
|
void LightData::remove()
|
||||||
{
|
{
|
||||||
ID_LOG(2, "");
|
CLOG_INFO(LOG_BSD, 2, "%s", p_id.GetText());
|
||||||
scene_delegate->GetRenderIndex().RemoveSprim(p_type, p_id);
|
scene_delegate->GetRenderIndex().RemoveSprim(p_type, p_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ void MeshData::remove()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ID_LOG(2, "");
|
CLOG_INFO(LOG_BSD, 2, "%s", p_id.GetText());
|
||||||
scene_delegate->GetRenderIndex().RemoveRprim(p_id);
|
scene_delegate->GetRenderIndex().RemoveRprim(p_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user