Move to use blender::Map container instead std::unordered_map #47

Merged
Bogdan Nagirniak merged 17 commits from Vasyl-Pidhirskyi/blender_bn:BLEN-418 into hydra-render 2023-06-02 12:02:46 +02:00
8 changed files with 39 additions and 42 deletions
Showing only changes of commit f603bf3e02 - Show all commits

View File

@ -218,7 +218,6 @@ void BlenderSceneDelegate::clear()
it->remove();
}
BogdanNagirniak marked this conversation as resolved Outdated

rename val -> obj_data, i_data, m_data

rename `val` -> `obj_data`, `i_data`, `m_data`
objects_.clear();
instancers_.clear();
materials_.clear_and_shrink();
@ -548,26 +547,25 @@ void BlenderSceneDelegate::remove_unused_objects()
/* Remove unused instancers */
instancers_.remove_if([&](auto item) {
bool ret = available_objects.find(item.key.GetName()) == available_objects.end();
if (ret){
item.value->remove();
}
else{
item.value->check_remove(available_objects);
}
return ret;
bool ret = available_objects.find(item.key.GetName()) == available_objects.end();
if (ret) {
item.value->remove();
}
else {
item.value->check_remove(available_objects);
}
return ret;
});
/* Remove unused objects */
objects_.remove_if([&](auto item) {
objects_.remove_if([&](auto item) {
bool ret = available_objects.find(item.key.GetName()) == available_objects.end();
if (ret){
item.value->remove();
}
return ret;
if (ret) {
item.value->remove();
}
return ret;
});
/* Remove unused materials */
std::set<pxr::SdfPath> available_materials;
for (auto &it : objects_.values()) {
@ -586,10 +584,10 @@ void BlenderSceneDelegate::remove_unused_objects()
materials_.remove_if([&](auto item) {
bool ret = available_materials.find(item.key) == available_materials.end();
if (ret){
item.value->remove();
}
return ret;
if (ret) {
item.value->remove();
}
return ret;
});
}

View File

@ -199,7 +199,8 @@ void CurvesData::write_material()
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
mat_data_ = scene_delegate_->material_data(p_id);
if (!mat_data_) {
scene_delegate_->materials_.add_overwrite(p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
scene_delegate_->materials_.add_overwrite(
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

seems like here should be add_new.

seems like here should be `add_new`.
p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
mat_data_ = scene_delegate_->material_data(p_id);
mat_data_->init();
mat_data_->insert();

View File

@ -7,8 +7,8 @@
#include <pxr/base/vt/value.h>
#include <pxr/usd/sdf/path.h>
#include "DNA_ID.h"
#include "BLI_hash.hh"
#include "DNA_ID.h"
template<> struct blender::DefaultHash<pxr::SdfPath> {
uint64_t operator()(const pxr::SdfPath &value) const

View File

@ -257,11 +257,11 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
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 (res) {
item.value.data->remove();
ret = true;
};
return res;
});
if (ret) {
@ -272,11 +272,11 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
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;
if (res) {
item.value.transforms.clear();
update_light_instance(item.value);
};
return res;
});
}
@ -386,12 +386,12 @@ void InstancerData::write_instances()
free_object_duplilist(lb);
/* Remove mesh intances without indices */
mesh_instances_.remove_if([&](auto item) {return item.value.indices.empty();});
mesh_instances_.remove_if([&](auto item) { return item.value.indices.empty(); });
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

missed .data->remove()?

missed `.data->remove()`?
/* Update light intances and remove instances without transforms */
light_instances_.remove_if([&](auto item) {
update_light_instance(item.value);
return item.value.transforms.empty();
update_light_instance(item.value);
return item.value.transforms.empty();
});
}

View File

@ -62,7 +62,6 @@ class InstancerData : public ObjectData {
pxr::VtMatrix4dArray mesh_transforms_;
};
using InstancerDataMap =
Map<pxr::SdfPath, std::unique_ptr<InstancerData>>;
using InstancerDataMap = Map<pxr::SdfPath, std::unique_ptr<InstancerData>>;
} // namespace blender::render::hydra

View File

@ -7,8 +7,8 @@
#include <pxr/usd/sdf/assetPath.h>
#include <pxr/usd/sdf/path.h>
#include "DNA_material_types.h"
#include "BLI_map.hh"
#include "DNA_material_types.h"
#include "id.h"

View File

@ -304,8 +304,8 @@ void MeshData::write_materials()
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
m.mat_data = scene_delegate_->material_data(p_id);
if (!m.mat_data) {
scene_delegate_->materials_.add_overwrite(p_id,
std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
scene_delegate_->materials_.add_overwrite(
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

seems like here should be add_new.

seems like here should be `add_new`.

lookup_or_add_default

`lookup_or_add_default`

implemented via lookup_or_add

implemented via `lookup_or_add`
p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
m.mat_data = scene_delegate_->material_data(p_id);
m.mat_data->init();
m.mat_data->insert();

View File

@ -7,8 +7,8 @@
#include <pxr/base/gf/matrix4d.h>
#include "BKE_layer.h"
#include "DNA_object_types.h"
#include "BLI_map.hh"
#include "DNA_object_types.h"
#include "id.h"
#include "material.h"
@ -37,8 +37,7 @@ class ObjectData : public IdData {
Object *parent_ = nullptr;
};
using ObjectDataMap =
Map<pxr::SdfPath, std::unique_ptr<ObjectData>>;
using ObjectDataMap = Map<pxr::SdfPath, std::unique_ptr<ObjectData>>;
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]);