This is a partial fix for T90535. This code was originally reviewed in D13297, but is now split into a separate patch, as suggested by Sybren in that review.
USD allows binding materials generically as well as for a specific purpose:
https://graphics.pixar.com/usd/release/api/class_usd_shade_material_binding_a_p_i.html#details
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.
The issue can be reproduced with the attached file, materialPurposeTest.usda, which contains three meshes, Plane_AllPurposeMtl, Plane_FullMtl and Plane_PreviewMtl, which resolve to materials with purpose allPurpose (Red), Full (Blue) and Preview (Green), respectively. Without this change, only Plane_AllPurposeMtl has a material assigned.