Support several instancers on one object #24

Merged
Bogdan Nagirniak merged 16 commits from BLEN-383 into hydra-render 2023-04-19 02:46:24 +02:00
5 changed files with 65 additions and 19 deletions
Showing only changes of commit 44e7e31f45 - Show all commits

View File

@ -375,8 +375,8 @@ void BlenderSceneDelegate::add_new_objects()
void BlenderSceneDelegate::remove_unused_objects()
{
/* Export of new visible objects which were not exported before */
std::set<pxr::SdfPath> available_objects;
/* Get available objects */
std::set<std::string> available_objects;
DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph;
@ -394,14 +394,26 @@ void BlenderSceneDelegate::remove_unused_objects()
if (!ObjectData::supported(object)) {
continue;
}
available_objects.insert(ObjectData::prim_id(this, object));
available_objects.insert(InstancerData::prim_id(this, object));
available_objects.insert(ObjectData::prim_id(this, object).GetName());
available_objects.insert(InstancerData::prim_id(this, object).GetName());
}
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) {
if (available_objects.find(it->first) != available_objects.end()) {
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
continue;
}
it->second->remove();
@ -409,7 +421,8 @@ void BlenderSceneDelegate::remove_unused_objects()
it = objects.begin();
}
/* remove unused materials */
/* Remove unused materials */
std::set<pxr::SdfPath> available_materials;
for (auto &it : objects) {
MeshData *m_data = dynamic_cast<MeshData *>(it.second.get());
@ -442,6 +455,32 @@ void BlenderSceneDelegate::update_visibility()
for (auto &it : instancers) {
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()

View File

@ -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());
auto it = instances.find(path);
if (it == instances.end()) {
return;
bool ret = false;
for (auto it = instances.begin(); it != instances.end(); ++it) {
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
continue;
}
it->second.obj_data->remove();
instances.erase(it);
it = instances.begin();
ret = true;
}
if (ret) {
set_instances();
scene_delegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
p_id, pxr::HdChangeTracker::AllDirty);
scene_delegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id,
pxr::HdChangeTracker::AllDirty);
}
}
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
@ -218,7 +225,7 @@ void InstancerData::insert()
void InstancerData::remove()
{
ID_LOG(2, "");
CLOG_INFO(LOG_BSD, 2, "%s", p_id.GetText());
for (auto &it : instances) {
it.second.obj_data->remove();
}

View File

@ -36,7 +36,7 @@ class InstancerData : public ObjectData {
ObjectData *object_data(pxr::SdfPath const &id);
pxr::SdfPathVector prototypes();
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);
private:

View File

@ -160,7 +160,7 @@ void LightData::insert()
void LightData::remove()
{
ID_LOG(2, "");
CLOG_INFO(LOG_BSD, 2, "%s", p_id.GetText());
scene_delegate->GetRenderIndex().RemoveSprim(p_type, p_id);
}

View File

@ -201,7 +201,7 @@ void MeshData::remove()
return;
}
ID_LOG(2, "");
CLOG_INFO(LOG_BSD, 2, "%s", p_id.GetText());
scene_delegate->GetRenderIndex().RemoveRprim(p_id);
}