PXR_NAMESPACE_OPEN_SCOPE


/* static */
MObject
UsdMayaTranslatorMaterial::Read(
        const TfToken& shadingMode,
        const UsdShadeMaterial& shadeMaterial,
        const UsdGeomGprim& boundPrim,
        UsdMayaPrimReaderContext* context)
{
    if (shadingMode == UsdMayaShadingModeTokens->none) {
        return MObject();
    }

    UsdMayaShadingModeImportContext c(shadeMaterial, boundPrim, context);

    MObject shadingEngine;

    if (c.GetCreatedObject(shadeMaterial.GetPrim(), &shadingEngine)) {
        return shadingEngine;
    }

    if (UsdMayaShadingModeImporter importer =
            UsdMayaShadingModeRegistry::GetImporter(shadingMode)) {
        shadingEngine = importer(&c);
    }

    if (!shadingEngine.isNull()) {
        c.AddCreatedObject(shadeMaterial.GetPrim(), shadingEngine);
    }

    return shadingEngine;
}
示例#2
0
/*static*/
SdfPath
UsdImaging_MaterialStrategy::GetBinding(UsdShadeMaterial const& material)
{
    TF_DEBUG(USDIMAGING_SHADERS).Msg("\t Look: %s\n", 
        material.GetPath().GetText());

    // ---------------------------------------------------------------------- //
    // Hydra-only shader style - displayLook:bxdf
    // ---------------------------------------------------------------------- //
    if (UsdRelationship matRel = UsdHydraLookAPI(material).GetBxdfRel()) {
        TF_DEBUG(USDIMAGING_SHADERS).Msg("\t LookRel: %s\n", 
                    matRel.GetPath().GetText());

        UsdShadeShader shader(
            UsdImaging_MaterialStrategy::GetTargetedShader(
                material.GetPrim(), 
                matRel));

        if (shader) {
            TF_DEBUG(USDIMAGING_SHADERS).Msg("\t UsdShade binding found: %s\n", 
                    shader.GetPath().GetText());
            return shader.GetPath();
        }
    }

    // ---------------------------------------------------------------------- //
    // Deprecated shader style - hydraLook:Surface
    // ---------------------------------------------------------------------- //
    TfToken hdSurf("hydraLook:surface");
    TfToken surfType("HydraPbsSurface");

    if (UsdRelationship matRel = material.GetPrim().GetRelationship(hdSurf)) {
        TF_DEBUG(USDIMAGING_SHADERS).Msg("\t LookRel: %s\n", 
                    matRel.GetPath().GetText());

        if (UsdPrim shader = 
            UsdImaging_MaterialStrategy::GetTargetedShader(
                material.GetPrim(), 
                matRel)) {

            if (TF_VERIFY(shader.GetTypeName() == surfType)) {
                TF_DEBUG(USDIMAGING_SHADERS).Msg(
                        "\t Deprecated binding found: %s\n", 
                        shader.GetPath().GetText());
                return shader.GetPath();
            }
        }
    }

    return SdfPath::EmptyPath();
}
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;
    }