diff options
author | Michael Kowalski <makowalski@nvidia.com> | 2022-08-01 19:14:05 +0300 |
---|---|---|
committer | Michael Kowalski <makowalski@nvidia.com> | 2022-08-01 19:14:05 +0300 |
commit | 0fade955ddc3b9fd143207d08b568612a2fb16b6 (patch) | |
tree | a2dcccc9a5ef501a6ac8d8b217980d0723f8158d | |
parent | 99f2b59fe6f09c9554ea2782f04d8a68786ef9d0 (diff) |
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
-rw-r--r-- | source/blender/io/usd/intern/usd_reader_mesh.cc | 17 |
1 files changed, 16 insertions, 1 deletions
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 |