[Bf-blender-cvs] [49e8eccea75] usd-importer-T81257-merge: USD Import: Code cleanup.
makowalski
noreply at git.blender.org
Fri Apr 9 03:27:23 CEST 2021
Commit: 49e8eccea7534521b95373f1b5d63ea96b7777a7
Author: makowalski
Date: Thu Apr 8 21:19:01 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rB49e8eccea7534521b95373f1b5d63ea96b7777a7
USD Import: Code cleanup.
Per review for D10700, simplified conditionals in the material
creation logic. Added comments.
===================================================================
M source/blender/io/usd/intern/usd_reader_mesh.cc
===================================================================
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc
index 5dd402bea55..1cee5d8d211 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -109,49 +109,58 @@ static void assign_materials(Main *bmain,
}
}
+ if (!can_assign) {
+ return;
+ }
+
/* TODO(kevin): use global map? */
std::map<std::string, Material *> mat_map;
build_mat_map(bmain, mat_map);
- std::map<std::string, Material *>::iterator mat_iter;
+ blender::io::usd::USDMaterialReader mat_reader(params, bmain);
- if (can_assign) {
- it = mat_index_map.begin();
+ for (it = mat_index_map.begin(); it != mat_index_map.end(); ++it) {
+ std::string mat_name = it->first.GetName();
- blender::io::usd::USDMaterialReader mat_reader(params, bmain);
+ std::map<std::string, Material *>::iterator mat_iter = mat_map.find(mat_name);
- for (; it != mat_index_map.end(); ++it) {
- std::string mat_name = it->first.GetName();
- mat_iter = mat_map.find(mat_name.c_str());
+ Material *assigned_mat = nullptr;
- Material *assigned_mat = nullptr;
+ if (mat_iter == mat_map.end()) {
+ /* Blender material doesn't exist, so create it now. */
- if (mat_iter == mat_map.end()) {
+ /* Look up the USD material. */
+ pxr::UsdPrim prim = stage->GetPrimAtPath(it->first);
+ pxr::UsdShadeMaterial usd_mat(prim);
- // Look up the USD material.
- pxr::UsdPrim prim = stage->GetPrimAtPath(it->first);
- pxr::UsdShadeMaterial usd_mat(prim);
-
- if (usd_mat) {
- assigned_mat = mat_reader.add_material(usd_mat);
- if (assigned_mat) {
- mat_map[mat_name] = assigned_mat;
- }
- }
- else {
- std::cout << "WARNING: Couldn't get USD material " << it->first << std::endl;
- }
- }
- else {
- assigned_mat = mat_iter->second;
+ if (!usd_mat) {
+ std::cout << "WARNING: Couldn't construct USD material from prim " << it->first
+ << std::endl;
+ continue;
}
- if (assigned_mat) {
- BKE_object_material_assign(bmain, ob, assigned_mat, it->second, BKE_MAT_ASSIGN_OBDATA);
- }
- else {
- std::cout << "WARNING: Couldn't assign material " << mat_name << std::endl;
+ /* Add the Blender material. */
+ assigned_mat = mat_reader.add_material(usd_mat);
+
+ if (!assigned_mat) {
+ std::cout << "WARNING: Couldn't create Blender material from USD material " << it->first
+ << std::endl;
+ continue;
}
+
+ mat_map[mat_name] = assigned_mat;
+ }
+ else {
+ /* We found an existing Blender material. */
+ assigned_mat = mat_iter->second;
+ }
+
+ if (assigned_mat) {
+ BKE_object_material_assign(bmain, ob, assigned_mat, it->second, BKE_MAT_ASSIGN_OBDATA);
+ }
+ else {
+ /* This shouldn't happen. */
+ std::cout << "WARNING: Couldn't assign material " << mat_name << std::endl;
}
}
}
More information about the Bf-blender-cvs
mailing list