Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kowalski <makowalski@nvidia.com>2022-10-06 06:06:21 +0300
committerMichael Kowalski <makowalski@nvidia.com>2022-10-06 06:06:21 +0300
commit05e8eeda3c95c960b2481b85cd836194d78c95ad (patch)
tree07b2883339bb84e865ae1cccdd9cf76f1b7b1262 /source/blender/io/usd/intern/usd_reader_material.cc
parenta096248d1253e5a4436fbc4c2fc1d51539183fc0 (diff)
USD import unbound materials.
This addresses issue T97195. Added a new Unbound Materials USD import option, to import materials not assigned to any geometry.
Diffstat (limited to 'source/blender/io/usd/intern/usd_reader_material.cc')
-rw-r--r--source/blender/io/usd/intern/usd_reader_material.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc
index d1af4553083..6416f6861d4 100644
--- a/source/blender/io/usd/intern/usd_reader_material.cc
+++ b/source/blender/io/usd/intern/usd_reader_material.cc
@@ -757,4 +757,52 @@ void USDMaterialReader::convert_usd_primvar_reader_float2(
link_nodes(ntree, uv_map, "UV", dest_node, dest_socket_name);
}
+
+void build_material_map(const Main *bmain, std::map<std::string, Material *> *r_mat_map)
+{
+ if (r_mat_map == nullptr) {
+ return;
+ }
+
+ Material *material = static_cast<Material *>(bmain->materials.first);
+
+ for (; material; material = static_cast<Material *>(material->id.next)) {
+ (*r_mat_map)[pxr::TfMakeValidIdentifier(material->id.name + 2)] = material;
+ }
+}
+
+Material *find_existing_material(
+ const pxr::SdfPath &usd_mat_path,
+ const USDImportParams &params,
+ const std::map<std::string, Material *> &mat_map,
+ const std::map<std::string, std::string> &usd_path_to_mat_name)
+{
+ if (params.mtl_name_collision_mode == USD_MTL_NAME_COLLISION_MAKE_UNIQUE) {
+ /* Check if we've already created the Blender material with a modified name. */
+ std::map<std::string, std::string>::const_iterator path_to_name_iter =
+ usd_path_to_mat_name.find(usd_mat_path.GetAsString());
+
+ if (path_to_name_iter != usd_path_to_mat_name.end()) {
+ std::string mat_name = path_to_name_iter->second;
+ std::map<std::string, Material *>::const_iterator mat_iter = mat_map.find(mat_name);
+ if (mat_iter != mat_map.end()) {
+ return mat_iter->second;
+ }
+ /* We can't find the Blender material which was previously created for this USD
+ * material, which should never happen. */
+ BLI_assert_unreachable();
+ }
+ }
+ else {
+ std::string mat_name = usd_mat_path.GetName();
+ std::map<std::string, Material *>::const_iterator mat_iter = mat_map.find(mat_name);
+
+ if (mat_iter != mat_map.end()) {
+ return mat_iter->second;
+ }
+ }
+
+ return nullptr;
+}
+
} // namespace blender::io::usd