7 #ifndef PXR_USD_USD_STAGE_H
8 #define PXR_USD_USD_STAGE_H
38 #include <tbb/concurrent_vector.h>
39 #include <tbb/concurrent_unordered_set.h>
40 #include <tbb/concurrent_hash_map.h>
41 #include <tbb/spin_rw_mutex.h>
47 #include <unordered_map>
56 class Usd_AssetPathContext;
58 class Usd_InstanceCache;
59 class Usd_InstanceChanges;
60 class Usd_InterpolatorBase;
178 static UsdStageRefPtr
183 static UsdStageRefPtr
185 const SdfLayerHandle& sessionLayer,
189 static UsdStageRefPtr
191 const SdfLayerHandle& sessionLayer,
196 static UsdStageRefPtr
219 static UsdStageRefPtr
223 static UsdStageRefPtr
228 static UsdStageRefPtr
234 static UsdStageRefPtr
236 const SdfLayerHandle &sessionLayer,
240 static UsdStageRefPtr
242 const SdfLayerHandle &sessionLayer,
262 static UsdStageRefPtr
266 static UsdStageRefPtr
267 Open(
const std::string& filePath,
289 static UsdStageRefPtr
295 static UsdStageRefPtr
330 static UsdStageRefPtr
331 Open(
const SdfLayerHandle& rootLayer,
335 static UsdStageRefPtr
336 Open(
const SdfLayerHandle& rootLayer,
337 const SdfLayerHandle& sessionLayer,
341 static UsdStageRefPtr
342 Open(
const SdfLayerHandle& rootLayer,
347 static UsdStageRefPtr
348 Open(
const SdfLayerHandle& rootLayer,
349 const SdfLayerHandle& sessionLayer,
374 static UsdStageRefPtr
380 static UsdStageRefPtr
382 const SdfLayerHandle& sessionLayer,
387 static UsdStageRefPtr
394 static UsdStageRefPtr
396 const SdfLayerHandle& sessionLayer,
656 return _populationMask;
679 std::function<
bool (
UsdRelationship const &)>
const &relPred =
nullptr,
680 std::function<
bool (
UsdAttribute const &)>
const &attrPred =
nullptr);
687 std::function<
bool (
UsdRelationship const &)>
const &relPred =
nullptr,
688 std::function<
bool (
UsdAttribute const &)>
const &attrPred =
nullptr);
839 _GetPrimDataAtPathOrInPrototype(
const SdfPath &
path)
const;
843 _GetInstancesForPrototype(
const UsdPrim& prototype)
const;
1018 SdfLayerHandleVector
GetLayerStack(
bool includeSessionLayers=
true)
const;
1032 SdfLayerHandleVector
GetUsedLayers(
bool includeClipLayers=
true)
const;
1091 void MuteLayer(
const std::string &layerIdentifier);
1096 void UnmuteLayer(
const std::string &layerIdentifier);
1107 const std::vector<std::string> &unmuteLayers);
1118 bool IsLayerMuted(
const std::string& layerIdentifier)
const;
1142 bool addSourceFileComment=
true,
1155 bool addSourceFileComment=
true)
const;
1243 template<
typename T>
1275 template<
typename T>
1320 template<
typename T>
1526 TfToken *colorManagementSystem);
1544 const TfToken &colorManagementSystem);
1585 struct _IncludePayloadsPredicate;
1598 template <
class... Args>
1609 static UsdStageRefPtr
1620 SdfPropertySpecHandleVector
1623 std::vector<std::pair<SdfPropertySpecHandle, SdfLayerOffset>>
1624 _GetPropertyStackWithLayerOffsets(
1627 static SdfPrimSpecHandleVector
1628 _GetPrimStack(
const UsdPrim &prim);
1630 static std::vector<std::pair<SdfPrimSpecHandle, SdfLayerOffset>>
1631 _GetPrimStackWithLayerOffsets(
const UsdPrim &prim);
1634 _GetSchemaProperty(
const UsdProperty &prop)
const;
1642 SdfAttributeSpecHandle
1643 _CreateNewSpecFromSchemaAttribute(
1647 SdfRelationshipSpecHandle
1648 _CreateNewSpecFromSchemaRelationship(
1652 template <
class PropType>
1654 _CreateNewPropertySpecFromSchema(
const UsdProperty &prop);
1657 _CreatePrimSpecForEditing(
const UsdPrim& prim);
1659 template <
class PropType>
1661 _CreatePropertySpecForEditing(
const UsdProperty &prop);
1663 SdfPropertySpecHandle
1664 _CreatePropertySpecForEditing(
const UsdProperty &prop);
1666 SdfAttributeSpecHandle
1667 _CreateAttributeSpecForEditing(
const UsdAttribute &attr);
1669 SdfRelationshipSpecHandle
1675 std::pair<bool, UsdPrim>
1676 _IsValidPathForCreatingPrim(
const SdfPath &path)
const;
1681 bool _ValidateEditPrim(
const UsdPrim &prim,
const char* operation)
const;
1682 bool _ValidateEditPrimAtPath(
const SdfPath &primPath,
1683 const char* operation)
const;
1687 bool _RemoveProperty(
const SdfPath& path);
1701 struct _IsEditTargetMappable {
1702 static const bool value =
1704 std::is_same<T, VtArray<SdfTimeCode>>
::value ||
1706 std::is_same<T, VtArray<SdfPathExpression>>
::value ||
1730 bool _SetEditTargetMappedValue(
1733 TfType _GetAttributeValueType(
1757 bool _SetMetadata(
const UsdObject &
object,
1763 bool _SetEditTargetMappedMetadata(
1765 const TfToken &keyPath,
const T &newValue);
1768 bool _SetMetadataImpl(
1780 PcpCache const *_GetPcpCache()
const {
return _cache.get(); }
1781 PcpCache *_GetPcpCache() {
return _cache.get(); }
1790 const std::string &context)
const;
1792 const std::vector<std::string>& otherErrors,
1793 const std::string &context)
const;
1803 void _ComposePrimIndexesInParallel(
1804 const std::vector<SdfPath>& primIndexPaths,
1805 const std::string& context,
1806 Usd_InstanceChanges* instanceChanges =
nullptr);
1810 void _ComposeSubtree(
1814 void _ComposeSubtreeImpl(
1818 void _ComposeSubtreesInParallel(
1819 const std::vector<Usd_PrimDataPtr> &prims,
1820 const std::vector<SdfPath> *primIndexPaths =
nullptr);
1860 void _DestroyPrimsInParallel(
const std::vector<SdfPath>& paths);
1868 bool _IsObjectDescendantOfInstance(
const SdfPath& path)
const;
1875 SdfPath _GetPrimPathUsingPrimIndexAtPath(
const SdfPath& primIndexPath)
const;
1893 bool _ProcessPendingChanges();
1897 bool _RemovePrim(
const SdfPath& fullPath);
1899 SdfPrimSpecHandle _GetPrimSpec(
const SdfPath& fullPath);
1907 const TfToken &propName)
const;
1913 void _Recompose(
const PcpChanges &changes,
T *pathsToRecompose);
1915 void _RecomposePrims(
T *pathsToRecompose);
1922 template <
class Iter>
1923 void _ComputeSubtreesToRecompose(Iter
start, Iter finish,
1924 std::vector<Usd_PrimDataPtr>* recompose);
1928 bool _IsValidForLoad(
const SdfPath& path)
const;
1929 bool _IsValidForUnload(
const SdfPath& path)
const;
1939 void _DiscoverPayloads(
const SdfPath& rootPath,
1942 bool unloadedOnly =
false,
1967 size_t numAssetPaths,
1968 bool anchorAssetPathsOnly =
false)
const;
1972 bool anchorAssetPathsOnly =
false)
const;
1976 size_t numTimeCodes)
const;
1978 void _MakeResolvedPathExpressions(
1981 size_t numPathExprs)
const;
1999 std::is_same<T, VtArray<SdfAssetPath>>
::value ||
2001 std::is_same<T, VtArray<SdfTimeCode>>
::value ||
2003 std::is_same<T, VtArray<SdfPathExpression>>
::value ||
2040 bool _GetStrongestResolvedMetadata(
const UsdObject &obj,
2051 bool _GetTypeSpecificResolvedMetadata(
const UsdObject &obj,
2057 template <
class Composer>
2061 Composer *composer)
const;
2063 template <
class Composer>
2066 Composer *composer)
const;
2068 template <
class Composer>
2071 Composer *composer)
const;
2073 template <
class Composer>
2074 bool _GetSpecialPropMetadataImpl(
const UsdObject &obj,
2078 Composer *composer)
const;
2079 template <
class Composer>
2080 bool _GetMetadataImpl(
const UsdObject &obj,
2083 bool includeFallbacks,
2084 Composer *composer)
const;
2086 template <
class Composer>
2087 bool _GetGeneralMetadataImpl(
const UsdObject &obj,
2090 bool includeFallbacks,
2091 Composer *composer)
const;
2097 const TfToken &keyPath,
bool useFallbacks)
const;
2100 _ListMetadataFields(
const UsdObject &obj,
bool useFallbacks)
const;
2102 void _GetAllMetadata(
const UsdObject &obj,
2105 bool anchorAssetPathsOnly =
false)
const;
2115 void _GetResolveInfoWithResolveTarget(
2121 template <
class T>
struct _ExtraResolveInfo;
2132 _ExtraResolveInfo<T> *extraInfo =
nullptr)
const;
2141 void _GetResolveInfoWithResolveTarget(
2146 _ExtraResolveInfo<T> *extraInfo =
nullptr)
const;
2153 template <
class T,
class MakeUsdResolverFn>
2157 _ExtraResolveInfo<T> *extraInfo,
2158 const MakeUsdResolverFn &makeUsdResolveFn)
const;
2160 template <
class T>
struct _ResolveInfoResolver;
2161 struct _PropertyStackResolver;
2163 template <
class Resolver,
class MakeUsdResolverFn>
2164 void _GetResolvedValueAtDefaultImpl(
2167 const MakeUsdResolverFn &makeUsdResolverFn)
const;
2169 template <
class Resolver,
class MakeUsdResolverFn>
2170 void _GetResolvedValueAtTimeImpl(
2174 const MakeUsdResolverFn &makeUsdResolverFn)
const;
2185 Usd_InterpolatorBase* interpolator,
2202 Usd_InterpolatorBase* interpolator,
2206 bool _GetDefaultValueFromResolveInfoImpl(
const UsdResolveInfo &info,
2223 bool _GetTimeSamplesInInterval(
const UsdAttribute &attr,
2225 std::vector<double>* times)
const;
2227 bool _GetTimeSamplesInIntervalFromResolveInfo(
2231 std::vector<double>* times)
const;
2233 size_t _GetNumTimeSamples(
const UsdAttribute &attr)
const;
2235 size_t _GetNumTimeSamplesFromResolveInfo(
const UsdResolveInfo &info,
2241 bool _GetBracketingTimeSamples(
const UsdAttribute &attr,
2246 bool* hasSamples)
const;
2248 bool _GetBracketingTimeSamplesFromResolveInfo(
const UsdResolveInfo &info,
2254 bool* hasSamples)
const;
2256 bool _ValueMightBeTimeVarying(
const UsdAttribute &attr)
const;
2258 bool _ValueMightBeTimeVaryingFromResolveInfo(
const UsdResolveInfo &info,
2261 void _RegisterPerLayerNotices();
2262 void _RegisterResolverChangeNotice();
2265 inline char const *_GetMallocTagId()
const;
2268 class _PendingChanges;
2275 class _NamespaceEditsChangeBlock {
2287 using ExpectedNamespaceEditChangeVector =
2288 std::vector<ExpectedNamespaceEditChange>;
2290 _NamespaceEditsChangeBlock(
const UsdStagePtr &stage,
2291 ExpectedNamespaceEditChangeVector &&expectedChanges);
2292 _NamespaceEditsChangeBlock(_NamespaceEditsChangeBlock &&);
2293 ~_NamespaceEditsChangeBlock();
2297 std::unique_ptr<_PendingChanges> _localPendingChanges;
2312 bool _editTargetIsLocalLayer;
2314 std::unique_ptr<PcpCache> _cache;
2315 std::unique_ptr<Usd_ClipCache> _clipCache;
2316 std::unique_ptr<Usd_InstanceCache> _instanceCache;
2320 size_t _usedLayersRevision;
2327 inline size_t hash(
SdfPath const &path)
const {
2331 using PathToNodeMap = tbb::concurrent_hash_map<
2333 PathToNodeMap _primMap;
2338 typedef std::vector<
2339 std::pair<SdfLayerHandle, TfNotice::Key> > _LayerAndNoticeKeyVec;
2340 _LayerAndNoticeKeyVec _layersAndNoticeKeys;
2341 size_t _lastChangeSerialNumber;
2346 _PendingChanges* _pendingChanges;
2348 std::optional<WorkDispatcher> _dispatcher;
2352 std::unique_ptr<std::string> _mallocTagID;
2363 bool _isClosingStage;
2364 bool _isWritingFallbackPrimTypes;
2387 template <
class RefsOrPayloadsEditorType,
class RefsOrPayloadsProxyType>
2397 UsdStage::_GetTypeSpecificResolvedMetadata(
const UsdObject &obj,
2403 template<
typename T>
2417 " match retrieved type %s",
2418 ArchGetDemangled<T>().
c_str(),
2425 template<
typename T>
2433 template<
typename T>
2447 TF_CODING_ERROR(
"Requested type %s for stage metadatum %s[%s] does not"
2448 " match retrieved type %s",
2449 ArchGetDemangled<T>().
c_str(),
2457 template<
typename T>
2468 typename std::enable_if<
2479 return _GetStrongestResolvedMetadata(
2480 obj, fieldName, keyPath, useFallbacks, &out);
2485 typename std::enable_if<
2487 UsdStage::_GetMetadata(
const UsdObject &obj,
2495 return _GetTypeSpecificResolvedMetadata(
2496 obj, fieldName, keyPath, useFallbacks, result);
2509 return _SetMetadataImpl<SdfAbstractDataConstValue>(
2519 return _SetEditTargetMappedMetadata(
object, key, keyPath, value);
2524 #endif //PXR_USD_USD_STAGE_H
TfDelegatedCountPtr< Usd_PrimData > Usd_PrimDataIPtr
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
GT_API const UT_StringHolder filename
USD_API void MuteAndUnmuteLayers(const std::vector< std::string > &muteLayers, const std::vector< std::string > &unmuteLayers)
virtual USD_API ~UsdStage()
static SDF_API const SdfPath & AbsoluteRootPath()
USD_API double GetFramesPerSecond() const
USD_API bool HasDefaultPrim() const
USD_API UsdPrim GetPrimAtPath(const SdfPath &path) const
T const & UncheckedGet() const &
USD_API void SetInterpolationType(UsdInterpolationType interpolationType)
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
USD_API std::vector< UsdPrim > GetPrototypes() const
Returns all native instancing prototype prims.
USD_API ArResolverContext GetPathResolverContext() const
USD_API double GetStartTimeCode() const
static USD_API UsdStageRefPtr CreateInMemory(InitialLoadSet load=LoadAll)
USD_API bool HasMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
GT_API const UT_StringHolder time
bool GetMetadata(const TfToken &key, T *value) const
USD_API UsdPrimRange Traverse()
USD_API bool Export(const std::string &filename, bool addSourceFileComment=true, const SdfLayer::FileFormatArguments &args=SdfLayer::FileFormatArguments()) const
GLsizei const GLfloat * value
SDF_DECLARE_HANDLES(SdfLayer)
GLsizei const GLchar *const * path
std::map< std::string, std::string > FileFormatArguments
SdfPrimSpecHandleVector oldPrimStack
USD_API UsdPrim CreateClassPrim(const SdfPath &rootPrimPath)
USD_API bool ClearMetadata(const TfToken &key) const
USD_API UsdRelationship GetRelationshipAtPath(const SdfPath &path) const
USD_API SdfPathSet GetLoadSet()
USD_API void Unload(const SdfPath &path=SdfPath::AbsoluteRootPath())
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
USD_API bool IsLayerMuted(const std::string &layerIdentifier) const
USD_API void SetDefaultPrim(const UsdPrim &prim)
**But if you need a result
USD_API void WriteFallbackPrimTypes()
USD_API void MuteLayer(const std::string &layerIdentifier)
friend struct Usd_ListEditImpl
USD_API SdfPathSet FindLoadable(const SdfPath &rootPath=SdfPath::AbsoluteRootPath())
static USD_API void SetGlobalVariantFallbacks(const PcpVariantFallbackMap &fallbacks)
size_t GetHash() const
Equality operator.
constexpr auto in(type t, int set) -> bool
bool SetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, const T &value) const
USD_API const UsdEditTarget & GetEditTarget() const
Return the stage's EditTarget.
GLenum GLuint GLint GLint layer
GLenum GLint GLint GLint GLint GLuint dstName
USD_API double GetEndTimeCode() const
USD_API SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const
USD_API UsdPrim GetDefaultPrim() const
USD_API void SetColorConfiguration(const SdfAssetPath &colorConfig) const
USD_API TfToken GetColorManagementSystem() const
GLint GLint GLsizei GLint GLenum GLenum type
bool GetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, T *value) const
USD_API UsdEditTarget GetEditTargetForLocalLayer(size_t i)
friend class Usd_AssetPathContext
USD_API SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const
USD_API void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet, UsdLoadPolicy policy=UsdLoadWithDescendants)
USD_API SdfLayerHandle GetSessionLayer() const
Return this stage's root session layer.
USD_API bool HasAuthoredMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
std::vector< TfToken > TfTokenVector
Convenience types.
USD_API bool HasAuthoredMetadata(const TfToken &key) const
static USD_API UsdStageRefPtr CreateNew(const std::string &identifier, InitialLoadSet load=LoadAll)
USD_API UsdProperty GetPropertyAtPath(const SdfPath &path) const
USD_API bool RemovePrim(const SdfPath &path)
USD_API void SetColorManagementSystem(const TfToken &cms) const
friend class Usd_TypeQueryAccess
std::map< class TfToken, VtValue, TfDictionaryLessThan > UsdMetadataValueMap
char const * GetText() const
friend struct Usd_AttrGetValueHelper
static USD_API UsdStageRefPtr Open(const std::string &filePath, InitialLoadSet load=LoadAll)
bool SetMetadata(const TfToken &key, const T &value) const
USD_API bool HasAuthoredTimeCodeRange() const
USD_API void SetLoadRules(UsdStageLoadRules const &rules)
std::vector< PcpErrorBasePtr > PcpErrorVector
USD_API void SetEditTarget(const UsdEditTarget &editTarget)
USD_API bool HasMetadata(const TfToken &key) const
USD_API void SetFramesPerSecond(double framesPerSecond) const
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
USD_API PcpErrorVector GetCompositionErrors() const
USD_API bool HasLocalLayer(const SdfLayerHandle &layer) const
USD_API void UnmuteLayer(const std::string &layerIdentifier)
USD_API std::string ResolveIdentifierToEditTarget(std::string const &identifier) const
USD_API void SetEndTimeCode(double)
USD_API UsdPrimRange TraverseAll()
std::vector< std::pair< SdfLayerHandle, SdfChangeList > > SdfLayerChangeListVec
USD_API void SetTimeCodesPerSecond(double timeCodesPerSecond) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
USD_API void ClearDefaultPrim()
USD_API SdfLayerHandle GetRootLayer() const
Return this stage's root layer.
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
USD_API UsdInterpolationType GetInterpolationType() const
friend class Usd_FlattenAccess
static USD_API bool IsSupportedFile(const std::string &filePath)
friend class Usd_PcpCacheAccess
USD_API UsdObject GetObjectAtPath(const SdfPath &path) const
UsdStageLoadRules const & GetLoadRules() const
friend struct Usd_AttrGetUntypedValueHelper
USD_API UsdPrim Load(const SdfPath &path=SdfPath::AbsoluteRootPath(), UsdLoadPolicy policy=UsdLoadWithDescendants)
static USD_API PcpVariantFallbackMap GetGlobalVariantFallbacks()
Get the global variant fallback preferences used in new UsdStages.
VT_API std::string GetTypeName() const
Return the type name of the held typeid.
#define PXR_NAMESPACE_CLOSE_SCOPE
USD_API SdfAssetPath GetColorConfiguration() const
USD_API const std::vector< std::string > & GetMutedLayers() const
Returns a vector of all layers that have been muted on this stage.
USD_API UsdPrim GetPseudoRoot() const
**If you just want to fire and args
friend class Usd_StageOpenRequest
OIIO_UTIL_API const char * c_str(string_view str)
USD_API UsdPrim DefinePrim(const SdfPath &path, const TfToken &typeName=TfToken())
UsdStagePopulationMask GetPopulationMask() const
Return this stage's population mask.
USD_API UsdPrim OverridePrim(const SdfPath &path)
static USD_API void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration, TfToken *colorManagementSystem)
static USD_API UsdStageRefPtr OpenMasked(const std::string &filePath, UsdStagePopulationMask const &mask, InitialLoadSet load=LoadAll)
USD_API double GetTimeCodesPerSecond() const
std::map< double, VtValue > SdfTimeSampleMap
A map from sample times to sample values.
USD_API void SetPopulationMask(UsdStagePopulationMask const &mask)
Set this stage's population mask and recompose the stage.
USD_API void SetStartTimeCode(double)
USD_API bool ClearMetadataByDictKey(const TfToken &key, const TfToken &keyPath) const
USD_API bool ExportToString(std::string *result, bool addSourceFileComment=true) const
USD_API void ExpandPopulationMask(Usd_PrimFlagsPredicate const &traversalPredicate, std::function< bool(UsdRelationship const &)> const &relPred=nullptr, std::function< bool(UsdAttribute const &)> const &attrPred=nullptr)
USD_API void SaveSessionLayers()
static USD_API void SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration, const TfToken &colorManagementSystem)
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
Load a prim plus all its descendants.
USD_API SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const
USD_API UsdAttribute GetAttributeAtPath(const SdfPath &path) const