forked from blender/blender
Move to use blender::Map container instead std::unordered_map #47
@ -79,9 +79,9 @@ void InstancerData::remove()
|
||||
}
|
||||
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
|
||||
|
||||
for (auto &it : light_instances_) {
|
||||
it.second.transforms.clear();
|
||||
update_light_instance(it.second);
|
||||
for (auto &it : light_instances_.values()) {
|
||||
it.transforms.clear();
|
||||
update_light_instance(it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,10 +125,10 @@ bool InstancerData::update_visibility()
|
||||
}
|
||||
}
|
||||
char name[16];
|
||||
for (auto &it : light_instances_) {
|
||||
for (int i = 0; i < it.second.count; ++i) {
|
||||
for (auto &it : light_instances_.values()) {
|
||||
for (int i = 0; i < it.count; ++i) {
|
||||
snprintf(name, 16, "L_%08x", i);
|
||||
change_tracker.MarkRprimDirty(it.second.data->prim_id.AppendElementString(name),
|
||||
change_tracker.MarkRprimDirty(it.data->prim_id.AppendElementString(name),
|
||||
pxr::HdChangeTracker::DirtyVisibility);
|
||||
}
|
||||
}
|
||||
@ -215,7 +215,7 @@ void InstancerData::check_update(Object *object)
|
||||
if (!is_instance_visible(object)) {
|
||||
l_inst->transforms.clear();
|
||||
update_light_instance(*l_inst);
|
||||
light_instances_.erase(path);
|
||||
light_instances_.remove(path);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -254,31 +254,30 @@ void InstancerData::check_update(Object *object)
|
||||
void InstancerData::check_remove(std::set<std::string> &available_objects)
|
||||
{
|
||||
bool ret = false;
|
||||
for (auto it : mesh_instances_.items()) {
|
||||
if (available_objects.find(it.key.GetName()) != available_objects.end()) {
|
||||
continue;
|
||||
}
|
||||
it.value.data->remove();
|
||||
mesh_instances_.remove(it.key);
|
||||
auto it = mesh_instances_.items().begin();
|
||||
|
||||
mesh_instances_.remove_if([&](auto item) {
|
||||
bool res = available_objects.find(item.key.GetName()) == available_objects.end();
|
||||
if (res){
|
||||
item.value.data->remove();
|
||||
ret = true;
|
||||
}
|
||||
};
|
||||
return res;
|
||||
});
|
||||
|
||||
if (ret) {
|
||||
write_instances();
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
|
||||
prim_id, pxr::HdChangeTracker::AllDirty);
|
||||
}
|
||||
|
||||
for (auto it = light_instances_.begin(); it != light_instances_.end(); ++it) {
|
||||
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
|
||||
continue;
|
||||
}
|
||||
it->second.transforms.clear();
|
||||
update_light_instance(it->second);
|
||||
|
||||
light_instances_.erase(it);
|
||||
it = light_instances_.begin();
|
||||
}
|
||||
light_instances_.remove_if([&](auto item) {
|
||||
bool res = available_objects.find(item.key.GetName()) == available_objects.end();
|
||||
if (res){
|
||||
item.value.transforms.clear();
|
||||
update_light_instance(item.value);
|
||||
};
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
|
||||
@ -346,8 +345,8 @@ void InstancerData::write_instances()
|
||||
for (auto &it : mesh_instances_.values()) {
|
||||
it.indices.clear();
|
||||
}
|
||||
for (auto &it : light_instances_) {
|
||||
it.second.transforms.clear();
|
||||
for (auto &it : light_instances_.values()) {
|
||||
it.transforms.clear();
|
||||
}
|
||||
|
||||
ListBase *lb = object_duplilist(
|
||||
@ -362,7 +361,7 @@ void InstancerData::write_instances()
|
||||
if (ob->type == OB_LAMP) {
|
||||
LightInstance *inst = light_instance(p_id);
|
||||
if (!inst) {
|
||||
inst = &light_instances_[p_id];
|
||||
inst = light_instances_.lookup_ptr(p_id);
|
||||
Vasyl-Pidhirskyi marked this conversation as resolved
Outdated
|
||||
inst->data = std::make_unique<LightData>(scene_delegate_, ob, p_id);
|
||||
inst->data->init();
|
||||
}
|
||||
@ -390,13 +389,10 @@ void InstancerData::write_instances()
|
||||
mesh_instances_.remove_if([&](auto item) {return item.value.indices.empty();});
|
||||
Vasyl-Pidhirskyi marked this conversation as resolved
Outdated
Georgiy Markelov
commented
missed missed `.data->remove()`?
|
||||
|
||||
/* Update light intances and remove instances without transforms */
|
||||
for (auto it = light_instances_.begin(); it != light_instances_.end(); ++it) {
|
||||
update_light_instance(it->second);
|
||||
if (it->second.transforms.empty()) {
|
||||
light_instances_.erase(it);
|
||||
it = light_instances_.begin();
|
||||
}
|
||||
}
|
||||
light_instances_.remove_if([&](auto item) {
|
||||
update_light_instance(item.value);
|
||||
return item.value.transforms.empty();
|
||||
});
|
||||
}
|
||||
|
||||
void InstancerData::update_light_instance(LightInstance &inst)
|
||||
@ -465,11 +461,11 @@ InstancerData::MeshInstance *InstancerData::mesh_instance(pxr::SdfPath const &id
|
||||
|
||||
InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const
|
||||
{
|
||||
auto it = light_instances_.find(id.GetPathElementCount() == 4 ? id.GetParentPath() : id);
|
||||
if (it == light_instances_.end()) {
|
||||
auto it = light_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : id);
|
||||
if (it == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return const_cast<LightInstance *>(&it->second);
|
||||
return const_cast<LightInstance *>(it);
|
||||
}
|
||||
Vasyl-Pidhirskyi marked this conversation as resolved
Outdated
Georgiy Markelov
commented
if (!it) { if (!it) {
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -58,7 +58,7 @@ class InstancerData : public ObjectData {
|
||||
LightInstance *light_instance(pxr::SdfPath const &id) const;
|
||||
|
||||
Map<pxr::SdfPath, MeshInstance> mesh_instances_;
|
||||
pxr::TfHashMap<pxr::SdfPath, LightInstance, pxr::SdfPath::Hash> light_instances_;
|
||||
Map<pxr::SdfPath, LightInstance> light_instances_;
|
||||
pxr::VtMatrix4dArray mesh_transforms_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
lookup
instead oflookup_ptr
also crash here due toinst
is empty