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
3 changed files with 16 additions and 2 deletions
Showing only changes of commit 87625b0da8 - Show all commits

View File

@ -147,8 +147,8 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
/* remove unused materials */
std::set<pxr::SdfPath> available_materials;
for (auto &obj : objects) {
MeshData *m_data = dynamic_cast<MeshData *>(obj.second.get());
for (auto &it : objects) {
MeshData *m_data = dynamic_cast<MeshData *>(it.second.get());
if (!m_data) {
continue;
}
@ -157,6 +157,9 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
available_materials.insert(mat_id);
}
}
for (auto &it : instancers) {
it.second->available_materials(available_materials);
}
for (auto it = materials.begin(); it != materials.end(); ++it) {
if (available_materials.find(it->first) != available_materials.end()) {
continue;

View File

@ -152,6 +152,16 @@ void InstancerData::check_remove(pxr::SdfPath const &obj_id)
p_id, pxr::HdChangeTracker::AllDirty);
}
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
{
for (auto &it : instances) {
pxr::SdfPath mat_id = ((MeshData *)it.second.obj_data.get())->material_id();
if (!mat_id.IsEmpty()) {
paths.insert(mat_id);
}
}
}
void InstancerData::set_instances()
{
transforms.clear();

View File

@ -37,6 +37,7 @@ class InstancerData : public ObjectData {
pxr::SdfPathVector prototypes();
void check_update(Object *object);
void check_remove(pxr::SdfPath const &obj_id);
void available_materials(std::set<pxr::SdfPath> &paths);
private:
void set_instances();