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;
    }
Exemple #2
0
// For now, this is only used by the mesh op.  If this logic needs to be
// accessed elsewhere, it should move down into usdKatana.
static void 
_CreateFaceSetsFromFaceSetAPI(
        const UsdPrim& prim,
        const PxrUsdKatanaUsdInPrivateData &data,
        FnKat::GeolibCookInterface& interface)
{
    UsdGeomFaceSetAPI faceSet = UsdShadeMaterial::GetMaterialFaceSet(prim);
    bool isPartition = faceSet.GetIsPartition();;
    if (!isPartition) {
        TF_WARN("Found face set on prim <%s> that is not a partition.", 
                prim.GetPath().GetText());
        // continue here?
    }

    const double currentTime = data.GetCurrentTime();

    VtIntArray faceCounts, faceIndices;
    faceSet.GetFaceCounts(&faceCounts, currentTime);
    faceSet.GetFaceIndices(&faceIndices, currentTime);

    SdfPathVector bindingTargets;
    faceSet.GetBindingTargets(&bindingTargets);

    size_t faceSetIdxStart = 0;
    for(size_t faceSetIdx = 0; faceSetIdx < faceCounts.size(); ++faceSetIdx) {
        size_t faceCount = faceCounts[faceSetIdx];

        FnKat::GroupBuilder faceSetAttrs;

        faceSetAttrs.set("type", FnKat::StringAttribute("faceset"));
        faceSetAttrs.set("materialAssign", FnKat::StringAttribute(
            PxrUsdKatanaUtils::ConvertUsdMaterialPathToKatLocation(
                bindingTargets[faceSetIdx], data)));

        FnKat::IntBuilder facesBuilder;
        {
            std::vector<int> faceIndicesVec(faceCount);
            for (size_t faceIndicesIdx = 0; faceIndicesIdx < faceCount; ++faceIndicesIdx)
            {
                faceIndicesVec[faceIndicesIdx] = 
                    faceIndices[faceSetIdxStart + faceIndicesIdx];
            }
            faceSetIdxStart += faceCount;
            facesBuilder.set(faceIndicesVec);
        }
        faceSetAttrs.set("geometry.faces", facesBuilder.build());

        std::string faceSetName = TfStringPrintf("faceset_%zu", faceSetIdx);

        FnKat::GroupBuilder staticSceneCreateAttrs;
        staticSceneCreateAttrs.set("a", faceSetAttrs.build());
        interface.createChild(
            faceSetName,
            "StaticSceneCreate",
            staticSceneCreateAttrs.build());
    }
}
Exemple #3
0
static SdfPathVector 
_GetBindingTargets(const UsdGeomFaceSetAPI &self)
{
    SdfPathVector bindings;
    self.GetBindingTargets(&bindings);
    return bindings;
}
Exemple #4
0
static bool 
_SetFaceIndices(const UsdGeomFaceSetAPI &self, object faceIndices, 
                    const UsdTimeCode &time)
{
    return self.SetFaceIndices(UsdPythonToSdfType(faceIndices, 
        SdfValueTypeNames->IntArray).UncheckedGet<VtIntArray>(), time);
}
Exemple #5
0
static  TfPyObjWrapper 
_GetFaceIndices(const UsdGeomFaceSetAPI &self, const UsdTimeCode &time)
{
    VtIntArray faceIndices;
    self.GetFaceIndices(&faceIndices, time);
    return UsdVtValueToPython(VtValue(faceIndices));
}
Exemple #6
0
static UsdAttribute
_CreateFaceIndicesAttr(UsdGeomFaceSetAPI &self, object defaultValue, bool writeSparsely)
{
    return self.CreateFaceIndicesAttr(
        UsdPythonToSdfType(defaultValue, SdfValueTypeNames->IntArray), 
        writeSparsely); 
}
Exemple #7
0
static UsdAttribute
_CreateIsPartitionAttr(UsdGeomFaceSetAPI &self, object defaultValue, bool writeSparsely)
{
    return self.CreateIsPartitionAttr(
        UsdPythonToSdfType(defaultValue, SdfValueTypeNames->Bool), 
        writeSparsely);
}
Exemple #8
0
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;
}
Exemple #9
0
/* deprecated */
USDLUX_API
SdfPath
UsdLuxLinkingAPI::GetLinkPathForFaceSet(const UsdGeomFaceSetAPI &faceSet)
{
    return faceSet.GetFaceIndicesAttr().GetPath();
}
Exemple #10
0
static boost::python::tuple 
_Validate(const UsdGeomFaceSetAPI &self) {
    std::string reason;
    bool result = self.Validate(&reason);
    return boost::python::make_tuple(result, reason);
}