[Bf-blender-cvs] [0fade955ddc] master: USD import: Handle material purpose

Michael Kowalski noreply at git.blender.org
Mon Aug 1 18:16:47 CEST 2022


Commit: 0fade955ddc3b9fd143207d08b568612a2fb16b6
Author: Michael Kowalski
Date:   Mon Aug 1 12:14:05 2022 -0400
Branches: master
https://developer.blender.org/rB0fade955ddc3b9fd143207d08b568612a2fb16b6

USD import: Handle material purpose

This is a partial fix for T90535.

USD allows binding materials generically as well as for a
specific purpose. I.e., purpose may be generic (unspecified)
or one of

- Full: truest representation of the scene
- Preview: lightweight material for preview

Curently, only generically bound materials, with unspecified
purpose (allPurpose), are imported. This issue is preventing
preview materials from being imported in the Alab scene.

This patch adds logic to attempt to fall back on importing
preview or full materials, in that order, if there is no
generic material bound to the mesh.

Reviewed by: Sybren

Differential Revision: https://developer.blender.org/D15352

===================================================================

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 45657525527..f65657b240c 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -64,7 +64,22 @@ static void build_mat_map(const Main *bmain, std::map<std::string, Material *> *
 
 static pxr::UsdShadeMaterial compute_bound_material(const pxr::UsdPrim &prim)
 {
-  return pxr::UsdShadeMaterialBindingAPI(prim).ComputeBoundMaterial();
+  pxr::UsdShadeMaterialBindingAPI api = pxr::UsdShadeMaterialBindingAPI(prim);
+
+  /* Compute generically bound ('allPurpose') materials. */
+  pxr::UsdShadeMaterial mtl = api.ComputeBoundMaterial();
+
+  /* If no generic material could be resolved, also check for 'preview' and
+   * 'full' purpose materials as fallbacks. */
+  if (!mtl) {
+    mtl = api.ComputeBoundMaterial(pxr::UsdShadeTokens->preview);
+  }
+
+  if (!mtl) {
+    mtl = api.ComputeBoundMaterial(pxr::UsdShadeTokens->full);
+  }
+
+  return mtl;
 }
 
 /* Returns an existing Blender material that corresponds to the USD



More information about the Bf-blender-cvs mailing list