bool GusdXformWrapper:: initUsdPrim(const UsdStagePtr& stage, const SdfPath& path, bool asOverride) { bool newPrim = true; if( asOverride ) { UsdPrim existing = stage->GetPrimAtPath( path ); if( existing ) { // Note that we are creating a Xformable rather than a Xform. // If we are writing an overlay and the ROP sees a geometry packed prim, // we want to write just the xform. In that case we can use a xform // wrapper to write the xform on any prim type. m_usdXformForWrite = UsdGeomXformable(stage->OverridePrim( path )); newPrim = false; } else { m_usdXformForWrite = UsdGeomXform::Define( stage, path ); // Make sure our ancestors have proper types. UsdPrim p = m_usdXformForWrite.GetPrim().GetParent(); while( p && p.GetTypeName().IsEmpty() ) { UsdGeomXform::Define( stage, p.GetPath() ); p = p.GetParent(); } } } else { m_usdXformForWrite = UsdGeomXform::Define( stage, path ); } if( !m_usdXformForWrite || !m_usdXformForWrite.GetPrim().IsValid() ) { TF_WARN( "Unable to create %s xform '%s'.", newPrim ? "new" : "override", path.GetText() ); } return bool(m_usdXformForWrite); }
bool GusdScopeWrapper:: initUsdPrim(const UsdStagePtr& stage, const SdfPath& path, bool asOverride) { bool newPrim = true; if( asOverride ) { UsdPrim existing = stage->GetPrimAtPath( path ); if( existing ) { // Note that we are creating a Xformable rather than a Xform. // If we are writing an overlay and the ROP sees a geometry packed prim, // we want to write just the xform. In that case we can use a xform // wrapper to write the xform on any prim type. m_usdScopeForWrite = UsdGeomScope(stage->OverridePrim( path )); newPrim = false; } else { m_usdScopeForWrite = UsdGeomScope::Define( stage, path ); } } else { m_usdScopeForWrite = UsdGeomScope::Define( stage, path ); } if( !m_usdScopeForWrite || !m_usdScopeForWrite.GetPrim().IsValid() ) { TF_WARN( "Unable to create %s scope '%s'.", newPrim ? "new" : "override", path.GetText() ); } return bool(m_usdScopeForWrite); }
/* static */ UsdSchemaExamplesSimple UsdSchemaExamplesSimple::Get(const UsdStagePtr &stage, const SdfPath &path) { if (not stage) { TF_CODING_ERROR("Invalid stage"); return UsdSchemaExamplesSimple(); } return UsdSchemaExamplesSimple(stage->GetPrimAtPath(path)); }
/* static */ UsdContrivedDerived UsdContrivedDerived::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdContrivedDerived(); } return UsdContrivedDerived(stage->GetPrimAtPath(path)); }
/* static */ UsdSkelRoot UsdSkelRoot::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdSkelRoot(); } return UsdSkelRoot(stage->GetPrimAtPath(path)); }
/* static */ UsdShadeShader UsdShadeShader::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdShadeShader(); } return UsdShadeShader(stage->GetPrimAtPath(path)); }
/* static */ UsdRiLightPortalAPI UsdRiLightPortalAPI::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdRiLightPortalAPI(); } return UsdRiLightPortalAPI(stage->GetPrimAtPath(path)); }
/* static */ UsdGeomXformable UsdGeomXformable::Get(const UsdStagePtr &stage, const SdfPath &path) { if (not stage) { TF_CODING_ERROR("Invalid stage"); return UsdGeomXformable(); } return UsdGeomXformable(stage->GetPrimAtPath(path)); }
/* static */ UsdGeomPointBased UsdGeomPointBased::Get(const UsdStagePtr &stage, const SdfPath &path) { if (not stage) { TF_CODING_ERROR("Invalid stage"); return UsdGeomPointBased(); } return UsdGeomPointBased(stage->GetPrimAtPath(path)); }
/* static */ UsdContrivedEmptyMultipleApplyAPI UsdContrivedEmptyMultipleApplyAPI::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdContrivedEmptyMultipleApplyAPI(); } return UsdContrivedEmptyMultipleApplyAPI(stage->GetPrimAtPath(path)); }
/* static */ UsdGeomSphere UsdGeomSphere::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdGeomSphere(); } return UsdGeomSphere(stage->GetPrimAtPath(path)); }
/* static */ UsdGeomNurbsCurves UsdGeomNurbsCurves::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdGeomNurbsCurves(); } return UsdGeomNurbsCurves(stage->GetPrimAtPath(path)); }
/* static */ UsdHydraPrimvar UsdHydraPrimvar::Get(const UsdStagePtr &stage, const SdfPath &path) { if (not stage) { TF_CODING_ERROR("Invalid stage"); return UsdHydraPrimvar(); } return UsdHydraPrimvar(stage->GetPrimAtPath(path)); }
/* static */ UsdUISceneGraphPrimAPI UsdUISceneGraphPrimAPI::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdUISceneGraphPrimAPI(); } return UsdUISceneGraphPrimAPI(stage->GetPrimAtPath(path)); }
/* static */ UsdGeomXformCommonAPI UsdGeomXformCommonAPI::Get(const UsdStagePtr &stage, const SdfPath &path) { if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdGeomXformCommonAPI(); } UsdGeomXformable xformable(stage->GetPrimAtPath(path)); return UsdGeomXformCommonAPI(xformable); }
/// Finds the rootmost ancestor of the prim at \p path that is an Xform /// or SkelRoot type prim. The result may be the prim itself. static UsdPrim _FindRootmostXformOrSkelRoot(const UsdStagePtr& stage, const SdfPath& path) { UsdPrim currentPrim = stage->GetPrimAtPath(path); UsdPrim rootmost; while (currentPrim) { if (currentPrim.IsA<UsdGeomXform>()) { rootmost = currentPrim; } else if (currentPrim.IsA<UsdSkelRoot>()) { rootmost = currentPrim; } currentPrim = currentPrim.GetParent(); } return rootmost; }
/* static */ UsdUISceneGraphPrimAPI UsdUISceneGraphPrimAPI::Apply(const UsdStagePtr &stage, const SdfPath &path) { // Ensure we have a valid stage, path and prim if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdUISceneGraphPrimAPI(); } if (path == SdfPath::AbsoluteRootPath()) { TF_CODING_ERROR("Cannot apply an api schema on the pseudoroot"); return UsdUISceneGraphPrimAPI(); } auto prim = stage->GetPrimAtPath(path); if (!prim) { TF_CODING_ERROR("Prim at <%s> does not exist.", path.GetText()); return UsdUISceneGraphPrimAPI(); } TfToken apiName("SceneGraphPrimAPI"); // Get the current listop at the edit target UsdEditTarget editTarget = stage->GetEditTarget(); SdfPrimSpecHandle primSpec = editTarget.GetPrimSpecForScenePath(path); SdfTokenListOp listOp = primSpec->GetInfo(UsdTokens->apiSchemas) .UncheckedGet<SdfTokenListOp>(); // Append our name to the prepend list, if it doesnt exist locally TfTokenVector prepends = listOp.GetPrependedItems(); if (std::find(prepends.begin(), prepends.end(), apiName) != prepends.end()) { return UsdUISceneGraphPrimAPI(); } SdfTokenListOp prependListOp; prepends.push_back(apiName); prependListOp.SetPrependedItems(prepends); auto result = listOp.ApplyOperations(prependListOp); if (!result) { TF_CODING_ERROR("Failed to prepend api name to current listop."); return UsdUISceneGraphPrimAPI(); } // Set the listop at the current edit target and return the API prim primSpec->SetInfo(UsdTokens->apiSchemas, VtValue(*result)); return UsdUISceneGraphPrimAPI(prim); }
AlembicChaser( UsdStagePtr stage, const UsdMayaChaserRegistry::FactoryContext::DagToUsdMap& dagToUsd, const std::map<std::string, std::string>& attrPrefixes, const std::map<std::string, std::string>& primvarPrefixes) : _stage(stage) , _dagToUsd(dagToUsd) { for (const auto& p: dagToUsd) { const MDagPath& dag = p.first; const SdfPath& usdPrimPath = p.second; UsdPrim usdPrim = stage->GetPrimAtPath(usdPrimPath); if (!dag.isValid() || !usdPrim) { continue; } _primEntries.push_back(_PrimEntry(dag, usdPrim)); _GatherPrefixedAttrs(attrPrefixes, primvarPrefixes, dag, &(_primEntries.back().attrs)); } }
/// Finds the existing SkelRoot which is shared by all \p paths. /// If no SkelRoot is found, and \p config is "auto", then attempts to /// find a common ancestor of \p paths which can be converted to SkelRoot. /// \p outMadeSkelRoot must be non-null; it will be set to indicate whether /// any auto-typename change actually occurred (true) or whether there was /// already a SkelRoot, so no renaming was necessary (false). /// If an existing, common SkelRoot cannot be found for all paths, and if /// it's not possible to create one, returns an empty SdfPath. static SdfPath _VerifyOrMakeSkelRoot(const UsdStagePtr& stage, const SdfPath& path, const TfToken& config) { if (config != UsdMayaJobExportArgsTokens->auto_ && config != UsdMayaJobExportArgsTokens->explicit_) { return SdfPath(); } // Only try to auto-rename to SkelRoot if we're not already a // descendant of one. Otherwise, verify that the user tagged it in a sane // way. if (UsdSkelRoot root = UsdSkelRoot::Find(stage->GetPrimAtPath(path))) { // Verify that the SkelRoot isn't nested in another SkelRoot. // This is necessary because UsdSkel doesn't handle nested skel roots // very well currently; this restriction may be loosened in the future. if (UsdSkelRoot root2 = UsdSkelRoot::Find(root.GetPrim().GetParent())) { TF_RUNTIME_ERROR("The SkelRoot <%s> is nested inside another " "SkelRoot <%s>. This might cause unexpected behavior.", root.GetPath().GetText(), root2.GetPath().GetText()); return SdfPath(); } else { return root.GetPath(); } } else if(config == UsdMayaJobExportArgsTokens->auto_) { // If auto-generating the SkelRoot, find the rootmost // UsdGeomXform and turn it into a SkelRoot. // XXX: It might be good to also consider model hierarchy here, and not // go past our ancestor component when trying to generate the SkelRoot. // (Example: in a scene with /World, /World/Char_1, /World/Char_2, we // might want SkelRoots to stop at Char_1 and Char_2.) Unfortunately, // the current structure precludes us from accessing model hierarchy // here. if (UsdPrim root = _FindRootmostXformOrSkelRoot(stage, path)) { UsdSkelRoot::Define(stage, root.GetPath()); return root.GetPath(); } else { if (path.IsRootPrimPath()) { // This is the most common problem when we can't obtain a // SkelRoot. // Show a nice error with useful information about root prims. TF_RUNTIME_ERROR("The prim <%s> is a root prim, so it has no " "ancestors that can be converted to a SkelRoot. (USD " "requires that skinned meshes and skeletons be " "encapsulated under a SkelRoot.) Try grouping this " "prim under a parent group.", path.GetText()); } else { // Show generic error as a last resort if we don't know exactly // what went wrong. TF_RUNTIME_ERROR("Could not find an ancestor of the prim <%s> " "that can be converted to a SkelRoot. (USD requires " "that skinned meshes and skeletons be encapsulated " "under a SkelRoot.)", path.GetText()); } return SdfPath(); } } return SdfPath(); }