UsdPrim PxrUsdMayaShadingModeExportContext::MakeStandardMaterialPrim( const AssignmentVector& assignmentsToBind, const std::string& name) const { UsdPrim ret; std::string materialName = name; if (materialName.empty()) { MStatus status; MFnDependencyNode seDepNode(_shadingEngine, &status); if (!status) { return ret; } MString seName = seDepNode.name(); materialName = MNamespace::stripNamespaceFromName(seName).asChar(); } materialName = PxrUsdMayaUtil::SanitizeName(materialName); UsdStageRefPtr stage = GetUsdStage(); if (UsdPrim materialParent = _GetMaterialParent(stage, assignmentsToBind)) { SdfPath materialPath = materialParent.GetPath().AppendChild( TfToken(materialName)); UsdShadeMaterial material = UsdShadeMaterial::Define( GetUsdStage(), materialPath); UsdPrim materialPrim = material.GetPrim(); // could use this to determine where we want to export. TF_FOR_ALL(iter, assignmentsToBind) { const SdfPath &boundPrimPath = iter->first; const VtIntArray &faceIndices = iter->second; UsdPrim boundPrim = stage->OverridePrim(boundPrimPath); if (faceIndices.empty()) { material.Bind(boundPrim); } else if (TfGetEnvSetting(PIXMAYA_EXPORT_OLD_STYLE_FACESETS)) { UsdGeomFaceSetAPI faceSet = material.CreateMaterialFaceSet( boundPrim); faceSet.AppendFaceGroup(faceIndices, materialPath); } else { // It might be worth adding a utility method for the following // block of code in core. UsdGeomSubset faceSubset = UsdShadeMaterial::CreateMaterialBindFaceSubset( UsdGeomImageable(boundPrim), /* subsetName */ TfToken(materialName), faceIndices); material.Bind(faceSubset.GetPrim()); UsdShadeMaterial::SetMaterialBindFaceSubsetsFamilyType( UsdGeomImageable(boundPrim), UsdGeomSubset::FamilyType::Partition); } } return materialPrim; }
static bool _AppendFaceGroup(const UsdGeomFaceSetAPI &self, object indices, const SdfPath &bindingTarget, const UsdTimeCode &time) { VtValue indicesVal = UsdPythonToSdfType(indices, SdfValueTypeNames->IntArray); if (indicesVal.IsHolding<VtIntArray>()) { return self.AppendFaceGroup(indicesVal.UncheckedGet<VtIntArray>(), bindingTarget, time); } return false; }