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
4 changed files with 24 additions and 18 deletions
Showing only changes of commit cc456bf8d4 - Show all commits

View File

@ -217,13 +217,11 @@ void BlenderSceneDelegate::clear()
for (auto &it : instancers_) {
it.second->remove();
}
for (auto &it : materials_) {
it.second->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();
materials_.clear_and_shrink();
depsgraph = nullptr;
context = nullptr;
@ -297,11 +295,11 @@ LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) const
MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const
{
auto it = materials_.find(id);
if (it == materials_.end()) {
const std::unique_ptr<MaterialData> *value = materials_.lookup_ptr(id);
if (value == nullptr) {
return nullptr;
}
return it->second.get();
return value->get();
}
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool child_id) const
@ -585,14 +583,14 @@ void BlenderSceneDelegate::remove_unused_objects()
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;
}
it->second->remove();
materials_.erase(it);
it = materials_.begin();
materials_.remove_if([&](auto item) {
bool ret = available_materials.find(item.key) == available_materials.end();
if (ret){
item.value->remove();
}
return ret;
});
}
void BlenderSceneDelegate::update_visibility()

View File

@ -8,6 +8,7 @@
#include "BKE_context.h"
#include "DEG_depsgraph.h"
#include "BLI_hash.hh"
#include "CLG_log.h"
@ -18,6 +19,13 @@
#include "object.h"
#include "world.h"
template<> struct blender::DefaultHash<pxr::SdfPath> {
uint64_t operator()(const pxr::SdfPath &value) const
{
return pxr::SdfPath::Hash()(value);
}
};
namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;

View File

@ -8,6 +8,7 @@
#include <pxr/usd/sdf/path.h>
#include "DNA_material_types.h"
#include "BLI_map.hh"
#include "id.h"
@ -37,7 +38,6 @@ class MaterialData : public IdData {
pxr::VtValue material_network_map_;
};
using MaterialDataMap =
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<MaterialData>, pxr::SdfPath::Hash>;
using MaterialDataMap = Map<pxr::SdfPath, std::unique_ptr<MaterialData>>;
} // namespace blender::render::hydra

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_[p_id] = std::make_unique<MaterialData>(
scene_delegate_, mat, p_id);
scene_delegate_->materials_.add_overwrite(p_id,
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`
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();