UsdGeomPrimvar UsdGeomPrimvarsAPI::FindPrimvarWithInheritance(const TfToken &name, const std::vector<UsdGeomPrimvar> &inheritedFromAncestors) const { TRACE_FUNCTION(); const UsdPrim &prim = GetPrim(); if (!prim) { TF_CODING_ERROR("FindPrimvarWithInheritance called on invalid prim: %s", UsdDescribe(prim).c_str()); return UsdGeomPrimvar(); } const TfToken attrName = UsdGeomPrimvar::_MakeNamespaced(name); UsdGeomPrimvar pv = GetPrimvar(attrName); if (pv.HasAuthoredValue()){ return pv; } for (UsdGeomPrimvar const &inherited : inheritedFromAncestors) { if (inherited.GetName() == attrName){ return inherited; } } return pv; }
bool UsdGeomPrimvarsAPI::HasPossiblyInheritedPrimvar(const TfToken &name) const { TRACE_FUNCTION(); UsdPrim prim = GetPrim(); if (!prim) { TF_CODING_ERROR("HasPossiblyInheritedPrimvar called on invalid prim: %s", UsdDescribe(prim).c_str()); return false; } UsdGeomPrimvar pv = GetPrimvar(name); if (pv.HasAuthoredValue()){ return true; } const TfToken attrName = UsdGeomPrimvar::_MakeNamespaced(name); if (attrName.IsEmpty()) { return false; } for (prim = prim.GetParent(); prim && !prim.IsPseudoRoot(); prim = prim.GetParent()) { UsdAttribute attr = prim.GetAttribute(attrName); if (attr.HasAuthoredValue() && UsdGeomPrimvar::IsPrimvar(attr)) { // Only constant primvars can be inherited. // Non-constant interpolation blocks inheritance. return UsdGeomPrimvar(attr).GetInterpolation() == UsdGeomTokens->constant; } } return false; }
UsdGeomPrimvar UsdGeomPrimvarsAPI::FindPrimvarWithInheritance(const TfToken &name) const { TRACE_FUNCTION(); const TfToken attrName = UsdGeomPrimvar::_MakeNamespaced(name); UsdPrim prim = GetPrim(); if (!prim) { TF_CODING_ERROR("FindPrimvarWithInheritance called on invalid prim: %s", UsdDescribe(prim).c_str()); return UsdGeomPrimvar(); } UsdGeomPrimvar localPv = GetPrimvar(name); if (localPv.HasAuthoredValue()){ return localPv; } for (prim = prim.GetParent(); prim && !prim.IsPseudoRoot(); prim = prim.GetParent()) { UsdAttribute attr = prim.GetAttribute(attrName); if (attr.HasAuthoredValue()) { if (UsdGeomPrimvar pv = UsdGeomPrimvar(attr)) { // Only constant primvars can be inherited. if (pv.GetInterpolation() == UsdGeomTokens->constant) { return pv; } else { // Non-constant interpolation blocks inheritance. return UsdGeomPrimvar(); } } } } return localPv; }
bool UsdGeomPrimvarsAPI::HasPrimvar(const TfToken &name) const { TfToken primvarName = UsdGeomPrimvar::_MakeNamespaced(name, /* quiet */true); const UsdPrim &prim = GetPrim(); if (!prim) { TF_CODING_ERROR("HasPrimvar called on invalid prim: %s", UsdDescribe(prim).c_str()); return false; } return primvarName.IsEmpty() ? false : UsdGeomPrimvar::IsPrimvar(prim.GetAttribute(primvarName)); }
std::vector<UsdGeomPrimvar> UsdGeomPrimvarsAPI::GetPrimvarsWithValues() const { const UsdPrim &prim = GetPrim(); if (!prim){ TF_CODING_ERROR("Called GetPrimvarsWithValues on invalid prim: %s", UsdDescribe(prim).c_str()); return std::vector<UsdGeomPrimvar>(); } return _MakePrimvars(prim.GetAuthoredPropertiesInNamespace( UsdGeomPrimvar::_GetNamespacePrefix()), [](UsdGeomPrimvar const &pv) { return pv.HasValue(); }); }
std::string Usd_DescribePrimData(const Usd_PrimData *p) { if (not p) return "null prim"; return TfStringPrintf( "%s%sprim <%s> %s", Usd_IsDead(p) ? "expired " : (p->_flags[Usd_PrimActiveFlag] ? "" : "inactive "), p->_typeName.IsEmpty() ? "" : TfStringPrintf("'%s' ", p->_typeName.GetText()).c_str(), p->_path.GetText(), p->_stage ? TfStringPrintf( "on stage %s", UsdDescribe(p->_stage).c_str()).c_str() : ""); }
std::vector<UsdGeomPrimvar> UsdGeomPrimvarsAPI::FindInheritablePrimvars() const { TRACE_FUNCTION(); // Assume the number of primvars is relatively bounded and // just use a vector to accumulate primvars up to the root prim. std::vector<UsdGeomPrimvar> primvars; const UsdPrim &prim = GetPrim(); if (!prim) { TF_CODING_ERROR("FindInheritablePrimvars called on invalid prim: %s", UsdDescribe(prim).c_str()); return primvars; } TfToken const& prefix = UsdGeomPrimvar::_GetNamespacePrefix(); _RecurseForInheritablePrimvars(prim, prefix, &primvars); return primvars; }
std::vector<UsdGeomPrimvar> UsdGeomPrimvarsAPI::FindIncrementallyInheritablePrimvars( const std::vector<UsdGeomPrimvar> &inheritedFromAncestors) const { TRACE_FUNCTION(); std::vector<UsdGeomPrimvar> primvars; const UsdPrim &prim = GetPrim(); if (!prim) { TF_CODING_ERROR("FindIncrementallyInheritablePrimvars called on invalid prim: %s", UsdDescribe(prim).c_str()); return primvars; } TfToken const& prefix = UsdGeomPrimvar::_GetNamespacePrefix(); _AddPrimToInheritedPrimvars(prim, prefix, &inheritedFromAncestors, &primvars, /* acceptAll = */ false); return primvars; }
std::vector<UsdGeomPrimvar> UsdGeomPrimvarsAPI::FindPrimvarsWithInheritance( const std::vector<UsdGeomPrimvar> &inheritedFromAncestors) const { TRACE_FUNCTION(); std::vector<UsdGeomPrimvar> primvars; const UsdPrim &prim = GetPrim(); if (!prim) { TF_CODING_ERROR("FindPrimvarsWithInheritance called on invalid prim: %s", UsdDescribe(prim).c_str()); return primvars; } TfToken const& prefix = UsdGeomPrimvar::_GetNamespacePrefix(); _AddPrimToInheritedPrimvars(prim, prefix, &inheritedFromAncestors, &primvars, /* acceptAll = */ true); // If this prim contributed no primvars, then `primvars` won't have // gotten a copy of `inheritedFromAncestors`, so ensure we compensate return primvars.empty() ? inheritedFromAncestors : primvars; }