Loading...
Searching...
No Matches
stage.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_USD_STAGE_H
8#define PXR_USD_USD_STAGE_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/usd/api.h"
14#include "pxr/usd/usd/common.h"
15#include "pxr/usd/usd/editTarget.h"
17#include "pxr/usd/usd/schemaRegistry.h"
19#include "pxr/usd/usd/stagePopulationMask.h"
20#include "pxr/usd/usd/primDefinition.h"
22
24#include "pxr/base/tf/hashmap.h"
25#include "pxr/base/tf/type.h"
27
28#include "pxr/usd/ar/ar.h"
29#include "pxr/usd/ar/notice.h"
31#include "pxr/usd/sdf/notice.h"
32#include "pxr/usd/sdf/path.h"
33#include "pxr/usd/sdf/types.h"
34#include "pxr/usd/sdf/valueTypeName.h"
35#include "pxr/usd/pcp/cache.h"
36#include "pxr/base/vt/value.h"
38
39#include <tbb/concurrent_vector.h>
40#include <tbb/concurrent_unordered_set.h>
41#include <tbb/concurrent_hash_map.h>
42#include <tbb/spin_rw_mutex.h>
43
44#include <functional>
45#include <string>
46#include <memory>
47#include <optional>
48#include <unordered_map>
49#include <utility>
50
51PXR_NAMESPACE_OPEN_SCOPE
52
54class GfInterval;
56class TsSpline;
57class Usd_AssetPathContext;
58class Usd_ClipCache;
59class Usd_InstanceCache;
60class Usd_InstanceChanges;
61class Usd_InterpolatorBase;
62class Usd_Resolver;
63class UsdResolveInfo;
65class UsdPrim;
66class UsdPrimRange;
67
68SDF_DECLARE_HANDLES(SdfLayer);
69
137class UsdStage : public TfRefBase, public TfWeakBase {
138public:
139
140 // --------------------------------------------------------------------- //
144 // --------------------------------------------------------------------- //
145
151 {
153 LoadNone
154 };
155
166 //
178 USD_API
179 static UsdStageRefPtr
180 CreateNew(const std::string& identifier,
181 InitialLoadSet load = LoadAll);
183 USD_API
184 static UsdStageRefPtr
185 CreateNew(const std::string& identifier,
186 const SdfLayerHandle& sessionLayer,
187 InitialLoadSet load = LoadAll);
189 USD_API
190 static UsdStageRefPtr
191 CreateNew(const std::string& identifier,
192 const SdfLayerHandle& sessionLayer,
193 const ArResolverContext& pathResolverContext,
194 InitialLoadSet load = LoadAll);
196 USD_API
197 static UsdStageRefPtr
198 CreateNew(const std::string& identifier,
199 const ArResolverContext& pathResolverContext,
200 InitialLoadSet load = LoadAll);
201
219 USD_API
220 static UsdStageRefPtr
223 USD_API
224 static UsdStageRefPtr
225 CreateInMemory(const std::string& identifier,
226 InitialLoadSet load = LoadAll);
228 USD_API
229 static UsdStageRefPtr
230 CreateInMemory(const std::string& identifier,
231 const ArResolverContext& pathResolverContext,
232 InitialLoadSet load = LoadAll);
234 USD_API
235 static UsdStageRefPtr
236 CreateInMemory(const std::string& identifier,
237 const SdfLayerHandle &sessionLayer,
238 InitialLoadSet load = LoadAll);
240 USD_API
241 static UsdStageRefPtr
242 CreateInMemory(const std::string& identifier,
243 const SdfLayerHandle &sessionLayer,
244 const ArResolverContext& pathResolverContext,
245 InitialLoadSet load = LoadAll);
246
262 USD_API
263 static UsdStageRefPtr
264 Open(const std::string& filePath, InitialLoadSet load = LoadAll);
266 USD_API
267 static UsdStageRefPtr
268 Open(const std::string& filePath,
269 const ArResolverContext& pathResolverContext,
270 InitialLoadSet load = LoadAll);
271
289 USD_API
290 static UsdStageRefPtr
291 OpenMasked(const std::string &filePath,
292 UsdStagePopulationMask const &mask,
293 InitialLoadSet load = LoadAll);
295 USD_API
296 static UsdStageRefPtr
297 OpenMasked(const std::string &filePath,
298 const ArResolverContext &pathResolverContext,
299 UsdStagePopulationMask const &mask,
300 InitialLoadSet load = LoadAll);
301
330 USD_API
331 static UsdStageRefPtr
332 Open(const SdfLayerHandle& rootLayer,
335 USD_API
336 static UsdStageRefPtr
337 Open(const SdfLayerHandle& rootLayer,
338 const SdfLayerHandle& sessionLayer,
341 USD_API
342 static UsdStageRefPtr
343 Open(const SdfLayerHandle& rootLayer,
344 const ArResolverContext& pathResolverContext,
347 USD_API
348 static UsdStageRefPtr
349 Open(const SdfLayerHandle& rootLayer,
350 const SdfLayerHandle& sessionLayer,
351 const ArResolverContext& pathResolverContext,
353
374 USD_API
375 static UsdStageRefPtr
376 OpenMasked(const SdfLayerHandle& rootLayer,
377 const UsdStagePopulationMask &mask,
380 USD_API
381 static UsdStageRefPtr
382 OpenMasked(const SdfLayerHandle& rootLayer,
383 const SdfLayerHandle& sessionLayer,
384 const UsdStagePopulationMask &mask,
387 USD_API
388 static UsdStageRefPtr
389 OpenMasked(const SdfLayerHandle& rootLayer,
390 const ArResolverContext& pathResolverContext,
391 const UsdStagePopulationMask &mask,
394 USD_API
395 static UsdStageRefPtr
396 OpenMasked(const SdfLayerHandle& rootLayer,
397 const SdfLayerHandle& sessionLayer,
398 const ArResolverContext& pathResolverContext,
399 const UsdStagePopulationMask &mask,
401
402 USD_API
403 virtual ~UsdStage();
404
422 USD_API
423 void Reload();
424
433 USD_API
434 static bool
435 IsSupportedFile(const std::string& filePath);
436
438
439 // --------------------------------------------------------------------- //
448
456 USD_API
457 void Save();
458
466 USD_API
468
470
471 // --------------------------------------------------------------------- //
517
519 USD_API
521
527 USD_API
528 static void
530
532
533 // --------------------------------------------------------------------- //
562 // --------------------------------------------------------------------- //
563
571 USD_API
574
580 USD_API
582
594 USD_API
595 void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet,
597
608 USD_API
609 SdfPathSet GetLoadSet();
610
630 USD_API
631 SdfPathSet FindLoadable(
632 const SdfPath& rootPath = SdfPath::AbsoluteRootPath());
633
640 return _loadRules;
641 }
642
652 USD_API
653 void SetLoadRules(UsdStageLoadRules const &rules);
654
657 return _populationMask;
658 }
659
661 USD_API
663
677 USD_API
679 Usd_PrimFlagsPredicate const &traversalPredicate,
680 std::function<bool (UsdRelationship const &)> const &relPred = nullptr,
681 std::function<bool (UsdAttribute const &)> const &attrPred = nullptr);
682
686 USD_API
688 std::function<bool (UsdRelationship const &)> const &relPred = nullptr,
689 std::function<bool (UsdAttribute const &)> const &attrPred = nullptr);
690
692
693 // --------------------------------------------------------------------- //
702 // --------------------------------------------------------------------- //
703
715 USD_API
717
725 USD_API
727
739 USD_API
740 void SetDefaultPrim(const UsdPrim &prim);
741
749 USD_API
751
759 USD_API
760 bool HasDefaultPrim() const;
761
771 USD_API
772 UsdPrim GetPrimAtPath(const SdfPath &path) const;
773
798 USD_API
800
809 USD_API
811
820 USD_API
822
831 USD_API
833private:
834 // Return the primData object at \p path.
835 Usd_PrimDataConstPtr _GetPrimDataAtPath(const SdfPath &path) const;
836 Usd_PrimDataPtr _GetPrimDataAtPath(const SdfPath &path);
837
838 // Return the primData object at \p path. If \p path indicates a prim
839 // beneath an instance, return the primData object for the corresponding
840 // prim in the instance's prototype.
841 Usd_PrimDataConstPtr
842 _GetPrimDataAtPathOrInPrototype(const SdfPath &path) const;
843
845 std::vector<UsdPrim>
846 _GetInstancesForPrototype(const UsdPrim& prototype) const;
847
848public:
849
870 USD_API
872
877 USD_API
878 UsdPrimRange Traverse(const Usd_PrimFlagsPredicate &predicate);
879
884 USD_API
886
905 USD_API
907
931 USD_API
933 const TfToken &typeName=TfToken());
934
947 USD_API
948 UsdPrim CreateClassPrim(const SdfPath &rootPrimPath);
949
971 USD_API
972 bool RemovePrim(const SdfPath& path);
973
975
976 // --------------------------------------------------------------------- //
980 // --------------------------------------------------------------------- //
981
983 USD_API
984 SdfLayerHandle GetSessionLayer() const;
985
987 USD_API
988 SdfLayerHandle GetRootLayer() const;
989
994 USD_API
996
1006 USD_API
1007 std::string
1008 ResolveIdentifierToEditTarget(std::string const &identifier) const;
1009
1012 USD_API
1013 PcpErrorVector GetCompositionErrors() const;
1014
1020 USD_API
1021 SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const;
1022
1034 USD_API
1035 SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const;
1036
1039 USD_API
1040 bool HasLocalLayer(const SdfLayerHandle &layer) const;
1041
1043 USD_API
1045
1049 USD_API
1051
1055 USD_API
1056 UsdEditTarget GetEditTargetForLocalLayer(const SdfLayerHandle &layer);
1057
1064 USD_API
1065 void SetEditTarget(const UsdEditTarget &editTarget);
1066
1093 USD_API
1094 void MuteLayer(const std::string &layerIdentifier);
1095
1098 USD_API
1099 void UnmuteLayer(const std::string &layerIdentifier);
1100
1108 USD_API
1109 void MuteAndUnmuteLayers(const std::vector<std::string> &muteLayers,
1110 const std::vector<std::string> &unmuteLayers);
1111
1113 USD_API
1114 const std::vector<std::string>& GetMutedLayers() const;
1115
1120 USD_API
1121 bool IsLayerMuted(const std::string& layerIdentifier) const;
1122
1124
1125 // --------------------------------------------------------------------- //
1129 // --------------------------------------------------------------------- //
1130 // Future Work:
1131 // * Flatten sub-trees or individual prims
1132 // * Allow flattening of local LayerStack
1133 // * Move Flatten into a free-function to ensure it doesn't rely on
1134 // Stage internals.
1135
1143 USD_API
1144 bool Export(const std::string &filename,
1145 bool addSourceFileComment=true,
1146 const SdfLayer::FileFormatArguments &args =
1148
1156 USD_API
1157 bool ExportToString(std::string *result,
1158 bool addSourceFileComment=true) const;
1159
1186 USD_API
1187 SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const;
1189
1190public:
1191 // --------------------------------------------------------------------- //
1199 // --------------------------------------------------------------------- //
1200
1212 template <class T>
1213 bool GetMetadata(const TfToken &key, T *value) const;
1215 USD_API
1216 bool GetMetadata(const TfToken &key, VtValue *value) const;
1217
1224 USD_API
1225 bool HasMetadata(const TfToken &key) const;
1226
1235 USD_API
1236 bool HasAuthoredMetadata(const TfToken &key) const;
1237
1246 USD_API
1247 bool SetMetadata(const TfToken &key, VtValueRef value) const;
1248
1257 USD_API
1258 bool ClearMetadata(const TfToken &key) const;
1259
1275 template<typename T>
1276 bool GetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
1277 T* value) const;
1279 USD_API
1281 const TfToken& key, const TfToken &keyPath, VtValue *value) const;
1282
1293 USD_API
1295 const TfToken& key, const TfToken &keyPath) const;
1296
1305 USD_API
1307 const TfToken& key, const TfToken &keyPath) const;
1308
1320 USD_API
1322 const TfToken& key, const TfToken &keyPath, VtValueRef value) const;
1323
1335 USD_API
1337 const TfToken& key, const TfToken& keyPath) const;
1338
1357 USD_API
1359
1361
1362 // --------------------------------------------------------------------- //
1369 // --------------------------------------------------------------------- //
1373 USD_API
1374 double GetStartTimeCode() const;
1375
1382 USD_API
1383 void SetStartTimeCode(double);
1384
1388 USD_API
1389 double GetEndTimeCode() const;
1390
1397 USD_API
1398 void SetEndTimeCode(double);
1399
1402 USD_API
1404
1420 USD_API
1422
1431 USD_API
1432 void SetTimeCodesPerSecond(double timeCodesPerSecond) const;
1433
1443 USD_API
1444 double GetFramesPerSecond() const;
1445
1454 USD_API
1455 void SetFramesPerSecond(double framesPerSecond) const;
1456
1458
1459 // --------------------------------------------------------------------- //
1480 // --------------------------------------------------------------------- //
1481
1487 USD_API
1488 void SetColorConfiguration(const SdfAssetPath &colorConfig) const;
1489
1493 USD_API
1495
1500 USD_API
1501 void SetColorManagementSystem(const TfToken &cms) const;
1502
1507 USD_API
1509
1520 USD_API
1521 static void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration,
1522 TfToken *colorManagementSystem);
1523
1537 USD_API
1538 static void
1539 SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration,
1540 const TfToken &colorManagementSystem);
1541
1543
1544 // --------------------------------------------------------------------- //
1551 // --------------------------------------------------------------------- //
1552
1557 USD_API
1559
1562 USD_API
1564
1566
1567 // --------------------------------------------------------------------- //
1572 // --------------------------------------------------------------------- //
1573
1575 USD_API
1576 std::vector<UsdPrim> GetPrototypes() const;
1577
1579
1580private:
1581 struct _IncludePayloadsPredicate;
1582
1583 // --------------------------------------------------------------------- //
1584 // Stage Construction & Initialization
1585 // --------------------------------------------------------------------- //
1586
1587 UsdStage(const SdfLayerRefPtr& rootLayer,
1588 const SdfLayerRefPtr& sessionLayer,
1589 const ArResolverContext& pathResolverContext,
1590 const UsdStagePopulationMask& mask,
1591 InitialLoadSet load);
1592
1593 // Helper for Open() overloads -- searches and publishes to bound caches.
1594 template <class... Args>
1595 static UsdStageRefPtr _OpenImpl(InitialLoadSet load, Args const &... args);
1596
1597 // Releases resources used by this stage.
1598 void _Close();
1599
1600 // Common ref ptr initialization, called by public, static constructors.
1601 //
1602 // This method will either return a valid refptr (if the stage is correctly
1603 // initialized) or it will return a null ref pointer, deleting the
1604 // raw stage pointer in the process.
1605 static UsdStageRefPtr
1606 _InstantiateStage(const SdfLayerRefPtr &rootLayer,
1607 const SdfLayerRefPtr &sessionLayer,
1608 const ArResolverContext &pathResolverContext,
1609 const UsdStagePopulationMask &mask,
1610 InitialLoadSet load);
1611
1612 // --------------------------------------------------------------------- //
1613 // Spec Existence & Definition Helpers
1614 // --------------------------------------------------------------------- //
1615
1616 SdfPropertySpecHandleVector
1617 _GetPropertyStack(const UsdProperty &prop, UsdTimeCode time) const;
1618
1619 std::vector<std::pair<SdfPropertySpecHandle, SdfLayerOffset>>
1620 _GetPropertyStackWithLayerOffsets(
1621 const UsdProperty &prop, UsdTimeCode time) const;
1622
1623 static SdfPrimSpecHandleVector
1624 _GetPrimStack(const UsdPrim &prim);
1625
1626 static std::vector<std::pair<SdfPrimSpecHandle, SdfLayerOffset>>
1627 _GetPrimStackWithLayerOffsets(const UsdPrim &prim);
1628
1630 _GetSchemaProperty(const UsdProperty &prop) const;
1631
1632 USD_API
1634 _GetSchemaAttribute(const UsdAttribute &attr) const;
1635
1637 _GetSchemaRelationship(const UsdRelationship &rel) const;
1638
1639 SdfAttributeSpecHandle
1640 _CreateNewSpecFromSchemaAttribute(
1641 const UsdPrim &prim,
1642 const UsdPrimDefinition::Attribute &attrDef);
1643
1644 SdfRelationshipSpecHandle
1645 _CreateNewSpecFromSchemaRelationship(
1646 const UsdPrim &prim,
1647 const UsdPrimDefinition::Relationship &relDef);
1648
1649 template <class PropType>
1651 _CreateNewPropertySpecFromSchema(const UsdProperty &prop);
1652
1653 SdfPrimSpecHandle
1654 _CreatePrimSpecForEditing(const UsdPrim& prim);
1655
1656 template <class PropType>
1658 _CreatePropertySpecForEditing(const UsdProperty &prop);
1659
1660 SdfPropertySpecHandle
1661 _CreatePropertySpecForEditing(const UsdProperty &prop);
1662
1663 SdfAttributeSpecHandle
1664 _CreateAttributeSpecForEditing(const UsdAttribute &attr);
1665
1666 SdfRelationshipSpecHandle
1667 _CreateRelationshipSpecForEditing(const UsdRelationship &rel);
1668
1669 // Check if the given path is valid to use with the prim creation API,
1670 // like DefinePrim. If it is valid, returns (true, GetPrimAtPath(path)).
1671 // Otherwise, returns (false, UsdPrim()).
1672 std::pair<bool, UsdPrim>
1673 _IsValidPathForCreatingPrim(const SdfPath &path) const;
1674
1675 // Validates that editing a specified prim is allowed. If editing is not
1676 // allowed, issues a coding error like "Cannot <operation> ..." and
1677 // returns false. Otherwise, returns true.
1678 bool _ValidateEditPrim(const UsdPrim &prim, const char* operation) const;
1679 bool _ValidateEditPrimAtPath(const SdfPath &primPath,
1680 const char* operation) const;
1681
1682 UsdPrim _DefinePrim(const SdfPath &path, const TfToken &typeName);
1683
1684 bool _RemoveProperty(const SdfPath& path);
1685
1686 UsdProperty _FlattenProperty(const UsdProperty &srcProp,
1687 const UsdPrim &dstParent,
1688 const TfToken &dstName);
1689
1690 // --------------------------------------------------------------------- //
1691 // Value & Metadata Authoring
1692 // --------------------------------------------------------------------- //
1693
1694 // Set value for dynamically typed VtValueRef. Will map the value across
1695 // edit targets if the held value type supports it.
1696 bool _SetValue(
1697 UsdTimeCode time, const UsdAttribute &attr, VtValueRef newValue);
1698
1699 TfToken _GetAttributeValueTypeNameToken(const UsdAttribute &attr) const;
1700 SdfValueTypeName _GetAttributeValueTypeName(const UsdAttribute &attr) const;
1701 TfType _GetAttributeValueType(const UsdAttribute &attr) const;
1702
1703 bool _ClearValue(UsdTimeCode time, const UsdAttribute &attr);
1704
1705 // Set metadata for dynamically typed VtValueRef. Will map the value across
1706 // edit targets if the value type supports it.
1707 USD_API
1708 bool _SetMetadata(const UsdObject &object,
1709 const TfToken& key,
1710 const TfToken &keyPath,
1711 VtValueRef value);
1712
1713 bool _ClearMetadata(const UsdObject &obj, const TfToken& fieldName,
1714 const TfToken &keyPath=TfToken());
1715
1716 // --------------------------------------------------------------------- //
1717 // Misc Internal Helpers
1718 // --------------------------------------------------------------------- //
1719
1720 // Pcp helpers.
1721 PcpCache const *_GetPcpCache() const { return _cache.get(); }
1722 PcpCache *_GetPcpCache() { return _cache.get(); }
1723
1724 // Returns the PrimIndex, using the read-only PcpCache API. We expect prims
1725 // to be composed during initial stage composition, so this method should
1726 // not be used in that context.
1727 const PcpPrimIndex* _GetPcpPrimIndex(const SdfPath& primPath) const;
1728
1729 // Helper to report pcp errors.
1730 void _ReportPcpErrors(const PcpErrorVector &errors,
1731 const std::string &context) const;
1732 void _ReportErrors(const PcpErrorVector &errors,
1733 const std::vector<std::string>& otherErrors,
1734 const std::string &context) const;
1735
1736 // --------------------------------------------------------------------- //
1737 // Scenegraph Composition & Change Processing
1738 // --------------------------------------------------------------------- //
1739
1740 // Compose the prim indexes in the subtrees rooted at the paths in
1741 // \p primIndexPaths. If \p instanceChanges is given, returns
1742 // changes to prototypes and instances due to the discovery of new instances
1743 // during composition.
1744 void _ComposePrimIndexesInParallel(
1745 const std::vector<SdfPath>& primIndexPaths,
1746 const std::string& context,
1747 Usd_InstanceChanges* instanceChanges = nullptr);
1748
1749 // Recompose the subtree rooted at \p prim: compose its type, flags, and
1750 // list of children, then invoke _ComposeSubtree on all its children.
1751 void _ComposeSubtree(
1752 Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1753 UsdStagePopulationMask const *mask,
1754 const SdfPath &primIndexPath = SdfPath());
1755 void _ComposeSubtreeImpl(
1756 Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1757 UsdStagePopulationMask const *mask,
1758 const SdfPath &primIndexPath = SdfPath());
1759 void _ComposeSubtreesInParallel(
1760 const std::vector<Usd_PrimDataPtr> &prims,
1761 const std::vector<SdfPath> *primIndexPaths = nullptr);
1762
1763 // Composes the full prim type info for the prim based on its type name
1764 // and applied API schemas.
1765 void _ComposePrimTypeInfoImpl(Usd_PrimDataPtr prim);
1766
1767 // Compose subtree rooted at \p prim under \p parent. This function
1768 // ensures that the appropriate prim index is specified for \p prim if
1769 // \p parent is in a prototype.
1770 void _ComposeChildSubtree(Usd_PrimDataPtr prim,
1771 Usd_PrimDataConstPtr parent,
1772 UsdStagePopulationMask const *mask);
1773
1774 // Compose \p prim's list of children and make any modifications necessary
1775 // to its _children member and the stage's _primMap, including possibly
1776 // instantiating new prims, or destroying existing subtrees of prims. The
1777 // any newly created prims *do not* have their prim index, type, flags, or
1778 // children composed.
1779 //
1780 // Compose only \p prim's direct children if recurse=false. Otherwise
1781 // recompose every descendent of \p prim. Callers that pass recurse=false
1782 // should invoke _ComposeSubtree on any newly created prims to ensure caches
1783 // are correctly populated.
1784 void _ComposeChildren(Usd_PrimDataPtr prim,
1785 UsdStagePopulationMask const *mask, bool recurse);
1786
1787 // Instantiate a prim instance. There must not already be an instance
1788 // at \p primPath.
1789 Usd_PrimDataPtr _InstantiatePrim(const SdfPath &primPath);
1790
1791 // Instantiate a prototype prim and sets its parent to pseudoroot.
1792 // There must not already be a prototype at \p primPath.
1793 Usd_PrimDataPtr _InstantiatePrototypePrim(const SdfPath &primPath);
1794
1795 // For \p prim and all of its descendants, remove from _primMap and empty
1796 // their _children vectors.
1797 void _DestroyPrim(Usd_PrimDataPtr prim);
1798
1799 // Destroy the prim subtrees rooted at each path in \p paths. \p paths may
1800 // not contain any path that is a descendent of another path in \p paths.
1801 void _DestroyPrimsInParallel(const std::vector<SdfPath>& paths);
1802
1803 // Invoke _DestroyPrim() on all of \p prim's direct children.
1804 void _DestroyDescendents(Usd_PrimDataPtr prim);
1805
1806 // Returns true if the object at the given path is a descendant of
1807 // an instance prim, i.e. a prim beneath an instance prim, or a property
1808 // of a prim beneath an instance prim.
1809 bool _IsObjectDescendantOfInstance(const SdfPath& path) const;
1810
1811 // If the given prim is an instance, returns the corresponding
1812 // prototype prim. Otherwise, returns an invalid prim.
1813 Usd_PrimDataConstPtr _GetPrototypeForInstance(Usd_PrimDataConstPtr p) const;
1814
1815 // Returns the path of the Usd prim using the prim index at the given path.
1816 SdfPath _GetPrimPathUsingPrimIndexAtPath(const SdfPath& primIndexPath) const;
1817
1818 // Responds to LayersDidChangeSentPerLayer event and update stage contents
1819 // in response to changes in scene description.
1820 void _HandleLayersDidChange(const SdfNotice::LayersDidChangeSentPerLayer &);
1821
1822 // Pushes changes through PCP to determine invalidation based on
1823 // composition metadata.
1824 // Note: This method will not perform any processing or notification
1825 // Refer to _ProcessPendingChanges()
1826 void _ComputePendingChanges(const SdfLayerChangeListVec &);
1827
1828 // Update stage contents in response to changes to the asset resolver.
1829 void _HandleResolverDidChange(const ArNotice::ResolverChanged &);
1830
1831 // Process stage change information stored in _pendingChanges.
1832 // _pendingChanges will be set to nullptr by the end of the function.
1833 // This function will return true if UsdNotice::ObjectsChanged and
1834 // UsdNotice::StageContentsChanged notices were sent during execution.
1835 bool _ProcessPendingChanges();
1836
1837 // Remove scene description for the prim at \p fullPath in the current edit
1838 // target.
1839 bool _RemovePrim(const SdfPath& fullPath);
1840
1841 SdfPrimSpecHandle _GetPrimSpec(const SdfPath& fullPath);
1842
1843 // Find and return the defining spec type for the property spec at the given
1844 // path, or SdfSpecTypeUnknown if none exists. The defining spec type is
1845 // either the builtin definition's spec type, if the indicated property is
1846 // builtin, otherwise it's the strongest authored spec's type if one exists,
1847 // otherwise it's SdfSpecTypeUnknown.
1848 SdfSpecType _GetDefiningSpecType(Usd_PrimDataConstPtr primData,
1849 const TfToken &propName) const;
1850
1851 // Helper to apply Pcp changes and recompose the scenegraph accordingly,
1852 // given an optional initial set of paths to recompose.
1853 void _Recompose(const PcpChanges &changes);
1854 template <class T>
1855 void _Recompose(const PcpChanges &changes, T *pathsToRecompose);
1856 template <class T>
1857 void _RecomposePrims(T *pathsToRecompose);
1858
1859 // Helper for _Recompose to find the subtrees that need to be
1860 // fully recomposed and to recompose the name children of the
1861 // parents of these subtrees. Note that [start, finish) must be a
1862 // sorted range of map iterators whose keys are paths with no descendent
1863 // paths. In C++20, consider using the ranges API to improve this.
1864 template <class Iter>
1865 void _ComputeSubtreesToRecompose(Iter start, Iter finish,
1866 std::vector<Usd_PrimDataPtr>* recompose);
1867
1868 // return true if the path is valid for load/unload operations.
1869 // This method will emit errors when invalid paths are encountered.
1870 bool _IsValidForLoad(const SdfPath& path) const;
1871 bool _IsValidForUnload(const SdfPath& path) const;
1872
1873 // Discover all payloads in a given subtree, adding the path of each
1874 // discovered prim index to the \p primIndexPaths set. If specified,
1875 // the corresponding UsdPrim path will be added to the \p usdPrimPaths
1876 // set. The root path will be considered for inclusion in the result set.
1877 //
1878 // Note that some payloads may not be discoverable in until an ancestral
1879 // payload has been included. UsdStage::LoadAndUnload takes this into
1880 // account.
1881 void _DiscoverPayloads(const SdfPath& rootPath,
1882 UsdLoadPolicy policy,
1883 SdfPathSet* primIndexPaths,
1884 bool unloadedOnly = false,
1885 SdfPathSet* usdPrimPaths = nullptr) const;
1886
1887 // ===================================================================== //
1888 // VALUE RESOLUTION //
1889 // ===================================================================== //
1890 // --------------------------------------------------------------------- //
1891 // Specialized Value Resolution
1892 // --------------------------------------------------------------------- //
1893
1894 // Helpers for resolving values for metadata fields requiring
1895 // special behaviors.
1896 static SdfSpecifier _GetSpecifier(Usd_PrimDataConstPtr primData);
1897 static TfToken _GetKind(Usd_PrimDataConstPtr primData);
1898 static bool _IsActive(Usd_PrimDataConstPtr primData);
1899
1900 // Custom is true if it is true anywhere in the stack.
1901 bool _IsCustom(const UsdProperty &prop) const;
1902
1903 // Variability is determined by the weakest opinion in the stack.
1904 SdfVariability _GetVariability(const UsdProperty &prop) const;
1905
1906 // Helper functions for resolving asset paths during value resolution.
1907 void _MakeResolvedAssetPaths(UsdTimeCode time, const UsdAttribute &attr,
1908 SdfAssetPath *assetPaths,
1909 size_t numAssetPaths,
1910 bool anchorAssetPathsOnly = false) const;
1911
1912 void _MakeResolvedAssetPathsValue(UsdTimeCode time, const UsdAttribute &attr,
1913 VtValue *value,
1914 bool anchorAssetPathsOnly = false) const;
1915
1916 void _MakeResolvedTimeCodes(UsdTimeCode time, const UsdAttribute &attr,
1917 SdfTimeCode *timeCodes,
1918 size_t numTimeCodes) const;
1919
1920 void _MakeResolvedPathExpressions(
1921 UsdTimeCode time, const UsdAttribute &attr,
1922 SdfPathExpression *pathExprs,
1923 size_t numPathExprs) const;
1924
1925 void _MakeResolvedAttributeValue(UsdTimeCode time, const UsdAttribute &attr,
1926 VtValue *value) const;
1927
1928 // --------------------------------------------------------------------- //
1929 // Metadata Resolution
1930 // --------------------------------------------------------------------- //
1931
1932public:
1933 // Trait that allows us to call the correct version of _GetMetadata for
1934 // types that require type specific value resolution as opposed to just
1935 // strongest opinion. These types also use type specific resolution
1936 // in _GetValue.
1937 template <class T>
1938 struct _HasTypeSpecificResolution {
1939 static const bool value =
1940 std::is_same<T, SdfAssetPath>::value ||
1941 std::is_same<T, VtArray<SdfAssetPath>>::value ||
1942 std::is_same<T, SdfTimeCode>::value ||
1943 std::is_same<T, VtArray<SdfTimeCode>>::value ||
1944 std::is_same<T, SdfPathExpression>::value ||
1945 std::is_same<T, VtArray<SdfPathExpression>>::value ||
1946 std::is_same<T, SdfTimeSampleMap>::value ||
1947 std::is_same<T, TsSpline>::value ||
1948 std::is_same<T, VtDictionary>::value;
1949 };
1950
1951private:
1952 // Get metadata as a dynamically typed VtValue. Will perform type specific
1953 // value resolution if the returned held type requires it.
1954 USD_API
1955 bool _GetMetadata(const UsdObject &obj,
1956 const TfToken& fieldName,
1957 const TfToken &keyPath,
1958 bool useFallbacks,
1959 VtValue* result) const;
1960
1961 USD_API
1962 bool _GetMetadata(const UsdObject &obj,
1963 const TfToken& fieldName,
1964 const TfToken &keyPath,
1965 bool useFallbacks,
1966 SdfAbstractDataValue *result,
1967 bool strongestOnly) const;
1968
1969 template <class T>
1970 bool _GetMetadata(const UsdObject &obj,
1971 const TfToken& fieldName,
1972 const TfToken &keyPath,
1973 bool useFallbacks,
1974 T* result) const {
1975 SdfAbstractDataTypedValue<T> out(result);
1976 const bool strongestOnly =
1979 return _GetMetadata(obj, fieldName, keyPath, useFallbacks, &out,
1980 strongestOnly);
1981 }
1982
1983 template <class Composer>
1984 void _GetAttrTypeImpl(const UsdAttribute &attr,
1985 const TfToken &fieldName,
1986 bool useFallbacks,
1987 Composer *composer) const;
1988
1989 template <class Composer>
1990 void _GetAttrVariabilityImpl(const UsdAttribute &attr,
1991 bool useFallbacks,
1992 Composer *composer) const;
1993
1994 template <class Composer>
1995 void _GetPropCustomImpl(const UsdProperty &prop,
1996 bool useFallbacks,
1997 Composer *composer) const;
1998
1999 template <class Composer>
2000 bool _GetSpecialPropMetadataImpl(const UsdObject &obj,
2001 const TfToken &fieldName,
2002 const TfToken &keyPath,
2003 bool useFallbacks,
2004 Composer *composer) const;
2005 template <class Composer>
2006 bool _GetMetadataImpl(const UsdObject &obj,
2007 const TfToken& fieldName,
2008 const TfToken& keyPath,
2009 bool includeFallbacks,
2010 Composer *composer) const;
2011
2012 template <class Composer>
2013 bool _GetGeneralMetadataImpl(const UsdObject &obj,
2014 const TfToken& fieldName,
2015 const TfToken& keyPath,
2016 bool includeFallbacks,
2017 Composer *composer) const;
2018
2019 // NOTE: The "authoredOnly" flag is not yet in use, but when we have
2020 // support for prim-based metadata fallbacks, they should be ignored when
2021 // this flag is set to true.
2022 bool _HasMetadata(const UsdObject &obj, const TfToken& fieldName,
2023 const TfToken &keyPath, bool useFallbacks) const;
2024
2026 _ListMetadataFields(const UsdObject &obj, bool useFallbacks) const;
2027
2028 void _GetAllMetadata(const UsdObject &obj,
2029 bool useFallbacks,
2030 UsdMetadataValueMap* result,
2031 bool anchorAssetPathsOnly = false) const;
2032
2033 // --------------------------------------------------------------------- //
2034 // Default & TimeSample Resolution
2035 // --------------------------------------------------------------------- //
2036
2037 void _GetResolveInfo(const UsdAttribute &attr,
2038 UsdResolveInfo *resolveInfo,
2039 const UsdTimeCode *time = nullptr) const;
2040
2041 void _GetResolveInfoWithResolveTarget(
2042 const UsdAttribute &attr,
2043 const UsdResolveTarget &resolveTarget,
2044 UsdResolveInfo *resolveInfo,
2045 const UsdTimeCode *time = nullptr) const;
2046
2047 template <class T> struct _ExtraResolveInfo;
2048
2049 // Gets the value resolve info for the given attribute. If time is provided,
2050 // the resolve info is evaluated for that specific time (which may be
2051 // default). Otherwise, if time is null, the resolve info is evaluated for
2052 // "any numeric time" and will not populate values in extraInfo that
2053 // require a specific time to be evaluated.
2054 template <class T>
2055 void _GetResolveInfo(const UsdAttribute &attr,
2056 UsdResolveInfo *resolveInfo,
2057 const UsdTimeCode *time = nullptr,
2058 _ExtraResolveInfo<T> *extraInfo = nullptr) const;
2059
2060 // Gets the value resolve info for the given attribute using the given
2061 // resolve target. If time is provided, the resolve info is evaluated for
2062 // that specific time (which may be default). Otherwise, if time is null,
2063 // the resolve info is evaluated for "any numeric time" and will not
2064 // populate values in extraInfo that require a specific time to be
2065 // evaluated.
2066 template <class T>
2067 void _GetResolveInfoWithResolveTarget(
2068 const UsdAttribute &attr,
2069 const UsdResolveTarget &resolveTarget,
2070 UsdResolveInfo *resolveInfo,
2071 const UsdTimeCode *time = nullptr,
2072 _ExtraResolveInfo<T> *extraInfo = nullptr) const;
2073
2074 // Shared implementation function for _GetResolveInfo and
2075 // _GetResolveInfoWithResolveTarget. The only difference between how these
2076 // two functions behave is in how they create the Usd_Resolver used for
2077 // iterating over nodes and layers, thus they provide this implementation
2078 // with the needed MakeUsdResolverFn to create the Usd_Resolver.
2079 template <class T, class MakeUsdResolverFn>
2080 void _GetResolveInfoImpl(const UsdAttribute &attr,
2081 UsdResolveInfo *resolveInfo,
2082 const UsdTimeCode *time,
2083 _ExtraResolveInfo<T> *extraInfo,
2084 const MakeUsdResolverFn &makeUsdResolveFn) const;
2085
2086 template <class T> struct _ResolveInfoResolver;
2087 struct _PropertyStackResolver;
2088
2089 template <class Resolver, class MakeUsdResolverFn>
2090 void _GetResolvedValueAtDefaultImpl(
2091 const UsdProperty &prop,
2092 Resolver *resolver,
2093 const MakeUsdResolverFn &makeUsdResolverFn) const;
2094
2095 template <class Resolver, class MakeUsdResolverFn>
2096 void _GetResolvedValueAtTimeImpl(
2097 const UsdProperty &prop,
2098 Resolver *resolver,
2099 const UsdTimeCode *time,
2100 const MakeUsdResolverFn &makeUsdResolverFn) const;
2101
2102 bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2103 VtValue* result) const;
2104
2105 template <class T>
2106 bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2107 T* result) const;
2108
2109 template <class T>
2110 bool _GetValueImpl(UsdTimeCode time, const UsdAttribute &attr,
2111 Usd_InterpolatorBase* interpolator,
2112 T* value) const;
2113
2114 USD_API
2115 bool _GetValueFromResolveInfo(const UsdResolveInfo &info,
2116 UsdTimeCode time, const UsdAttribute &attr,
2117 VtValue* result) const;
2118
2119 template <class T>
2120 USD_API
2121 bool _GetValueFromResolveInfo(const UsdResolveInfo &info,
2122 UsdTimeCode time, const UsdAttribute &attr,
2123 T* result) const;
2124
2125 template <class T>
2126 bool _GetValueFromResolveInfoImpl(const UsdResolveInfo &info,
2127 UsdTimeCode time, const UsdAttribute &attr,
2128 Usd_InterpolatorBase* interpolator,
2129 T* value) const;
2130
2131 template <class T>
2132 bool _GetDefaultValueFromResolveInfoImpl(const UsdResolveInfo &info,
2133 const UsdAttribute &attr,
2134 T* value) const;
2135
2136 Usd_AssetPathContext
2137 _GetAssetPathContext(UsdTimeCode time, const UsdAttribute &attr) const;
2138
2139 // --------------------------------------------------------------------- //
2140 // Specialized Time Sample I/O
2141 // --------------------------------------------------------------------- //
2142
2149 bool _GetTimeSamplesInInterval(const UsdAttribute &attr,
2150 const GfInterval& interval,
2151 std::vector<double>* times) const;
2152
2153 bool _GetTimeSamplesInIntervalFromResolveInfo(
2154 const UsdResolveInfo &info,
2155 const UsdAttribute &attr,
2156 const GfInterval& interval,
2157 std::vector<double>* times) const;
2158
2159 size_t _GetNumTimeSamples(const UsdAttribute &attr) const;
2160
2161 size_t _GetNumTimeSamplesFromResolveInfo(const UsdResolveInfo &info,
2162 const UsdAttribute &attr) const;
2163
2167 bool _GetBracketingTimeSamples(const UsdAttribute &attr,
2168 double desiredTime,
2169 bool authoredOnly,
2170 double* lower,
2171 double* upper,
2172 bool* hasSamples) const;
2173
2174 bool _GetBracketingTimeSamplesFromResolveInfo(const UsdResolveInfo &info,
2175 const UsdAttribute &attr,
2176 double desiredTime,
2177 bool authoredOnly,
2178 double* lower,
2179 double* upper,
2180 bool* hasSamples) const;
2181
2182 bool _ValueMightBeTimeVarying(const UsdAttribute &attr) const;
2183
2184 bool _ValueMightBeTimeVaryingFromResolveInfo(const UsdResolveInfo &info,
2185 const UsdAttribute &attr) const;
2186
2187 void _RegisterPerLayerNotices();
2188 void _RegisterResolverChangeNotice();
2189
2190 // Helper to obtain a malloc tag string for this stage.
2191 inline char const *_GetMallocTagId() const;
2192
2193private:
2194 class _PendingChanges;
2195
2196 // Change block for use by the UsdNamespaceEditor to allow it to indicate
2197 // to its dependent stages what the expected namespace edits are when the
2198 // stages handles notices from the changes the namespace editor performs.
2199 // The stage uses this provide additional information about prim resyncs
2200 // related to namespace edits in the ObjectsChanged notice it sends.
2201 class _NamespaceEditsChangeBlock {
2202 public:
2203 // Info about an expected namespace edit change from UsdNamespaceEditor.
2204 // This includes the original pre-edit prim stack of the prim at the old
2205 // path which is used to determine if the prim at the new path has the
2206 // same composed contents after the edits as the prim had originally at
2207 // the old path before the edits.
2208 struct ExpectedNamespaceEditChange {
2209 SdfPath oldPath;
2210 SdfPath newPath;
2211 SdfPrimSpecHandleVector oldPrimStack;
2212 };
2213 using ExpectedNamespaceEditChangeVector =
2214 std::vector<ExpectedNamespaceEditChange>;
2215
2216 _NamespaceEditsChangeBlock(const UsdStagePtr &stage,
2217 ExpectedNamespaceEditChangeVector &&expectedChanges);
2218 _NamespaceEditsChangeBlock(_NamespaceEditsChangeBlock &&);
2219 ~_NamespaceEditsChangeBlock();
2220
2221 private:
2222 UsdStagePtr _stage;
2223 std::unique_ptr<_PendingChanges> _localPendingChanges;
2224 };
2225
2226 // The 'pseudo root' prim.
2227 Usd_PrimDataPtr _pseudoRoot;
2228
2229 // The stage's root layer.
2230 SdfLayerRefPtr _rootLayer;
2231
2232 // Every UsdStage has an implicit, in-memory session layer.
2233 // This is to allow for runtime overrides such as variant selections.
2234 SdfLayerRefPtr _sessionLayer;
2235
2236 // The stage's EditTarget.
2237 UsdEditTarget _editTarget;
2238 bool _editTargetIsLocalLayer;
2239
2240 std::unique_ptr<PcpCache> _cache;
2241 std::unique_ptr<Usd_ClipCache> _clipCache;
2242 std::unique_ptr<Usd_InstanceCache> _instanceCache;
2243
2244 TfHashMap<TfToken, TfToken, TfHash> _invalidPrimTypeToFallbackMap;
2245
2246 size_t _usedLayersRevision;
2247
2248 // A concurrent map from Path to Prim, for fast random access.
2249 struct _TbbHashEq {
2250 inline bool equal(SdfPath const &l, SdfPath const &r) const {
2251 return l == r;
2252 }
2253 inline size_t hash(SdfPath const &path) const {
2254 return path.GetHash();
2255 }
2256 };
2257 using PathToNodeMap = tbb::concurrent_hash_map<
2258 SdfPath, Usd_PrimDataIPtr, _TbbHashEq>;
2259 PathToNodeMap _primMap;
2260
2261 // The interpolation type used for all attributes on the stage.
2262 UsdInterpolationType _interpolationType;
2263
2264 typedef std::vector<
2265 std::pair<SdfLayerHandle, TfNotice::Key> > _LayerAndNoticeKeyVec;
2266 _LayerAndNoticeKeyVec _layersAndNoticeKeys;
2267 size_t _lastChangeSerialNumber;
2268
2269 TfNotice::Key _resolverChangeKey;
2270
2271 // Data for pending change processing.
2272 _PendingChanges* _pendingChanges;
2273
2274 std::optional<WorkDispatcher> _dispatcher;
2275
2276 // To provide useful aggregation of malloc stats, we bill everything
2277 // for this stage - from all access points - to this tag.
2278 std::unique_ptr<std::string> _mallocTagID;
2279
2280 // The state used when instantiating the stage.
2281 const InitialLoadSet _initialLoadSet;
2282
2283 // The population mask that applies to this stage.
2284 UsdStagePopulationMask _populationMask;
2285
2286 // The load rules that apply to this stage.
2287 UsdStageLoadRules _loadRules;
2288
2289 bool _isClosingStage;
2290 bool _isWritingFallbackPrimTypes;
2291
2292 friend class UsdAPISchemaBase;
2293 friend class UsdAttribute;
2294 friend class UsdAttributeQuery;
2295 friend class UsdEditTarget;
2296 friend class UsdInherits;
2297 friend class UsdNamespaceEditor;
2298 friend class UsdObject;
2299 friend class UsdPrim;
2300 friend class UsdProperty;
2301 friend class UsdRelationship;
2302 friend class UsdSpecializes;
2303 friend class UsdVariantSet;
2304 friend class UsdVariantSets;
2305 friend class Usd_AssetPathContext;
2306 friend class Usd_FlattenAccess;
2307 friend class Usd_PcpCacheAccess;
2308 friend class Usd_PrimData;
2309 friend class Usd_StageOpenRequest;
2310 friend class Usd_TypeQueryAccess;
2311 template <class T> friend struct Usd_AttrGetValueHelper;
2312 friend struct Usd_AttrGetUntypedValueHelper;
2313 template <class RefsOrPayloadsEditorType, class RefsOrPayloadsProxyType>
2314 friend struct Usd_ListEditImpl;
2315};
2316
2317template<typename T>
2318bool
2319UsdStage::GetMetadata(const TfToken& key, T* value) const
2320{
2321 VtValue result;
2322 if (!GetMetadata(key, &result)){
2323 return false;
2324 }
2325
2326 if (result.IsHolding<T>()){
2327 *value = result.UncheckedGet<T>();
2328 return true;
2329 } else {
2330 TF_CODING_ERROR("Requested type %s for stage metadatum %s does not"
2331 " match retrieved type %s",
2332 ArchGetDemangled<T>().c_str(),
2333 key.GetText(),
2334 result.GetTypeName().c_str());
2335 return false;
2336 }
2337}
2338
2339template<typename T>
2340bool
2342 T* value) const
2343{
2344 VtValue result;
2345 if (!GetMetadataByDictKey(key, keyPath, &result)){
2346 return false;
2347 }
2348
2349 if (result.IsHolding<T>()){
2350 *value = result.UncheckedGet<T>();
2351 return true;
2352 } else {
2353 TF_CODING_ERROR("Requested type %s for stage metadatum %s[%s] does not"
2354 " match retrieved type %s",
2355 ArchGetDemangled<T>().c_str(),
2356 key.GetText(),
2357 keyPath.GetText(),
2358 result.GetTypeName().c_str());
2359 return false;
2360 }
2361}
2362
2363PXR_NAMESPACE_CLOSE_SCOPE
2364
2365#endif //PXR_USD_USD_STAGE_H
2366
Notice sent when asset paths may resolve to a different path than before due to a change in the resol...
Definition: notice.h:50
An asset resolver context allows clients to provide additional data to the resolver for use during re...
A basic mathematical interval class.
Definition: interval.h:33
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:77
Describes Pcp changes.
Definition: changes.h:219
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:62
The fully-typed container for a field value in an SdfAbstractData.
Definition: abstractData.h:482
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:417
Contains an asset path and optional evaluated and resolved paths.
Definition: assetPath.h:79
SdfHandle is a smart ptr that calls IsDormant() on the pointed-to object as an extra expiration check...
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:84
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to layer API.
Definition: layer.h:107
Notice sent per-layer indicating all layers whose contents have changed within a single round of chan...
Definition: notice.h:94
Objects of this class represent a logical expression syntax tree consisting of SdfPathPattern s,...
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
Value type that represents a time code.
Definition: timeCode.h:29
Represents a value type name, i.e.
Definition: valueTypeName.h:72
Stores a pointer to a ValueType which uses TfDelegatedCountIncrement and TfDelegatedCountDecrement to...
Handle-object returned by TfNotice::Register().
Definition: notice.h:243
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:56
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
char const * GetText() const
Return the text that this token represents.
Definition: token.h:179
TfType represents a dynamic runtime type.
Definition: type.h:48
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
A mathematical description of a curved function from time to value.
Definition: spline.h:60
The base class for all API schemas.
Definition: apiSchemaBase.h:95
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:183
Object for efficiently making repeated queries for attribute values.
Defines a mapping from scene graph paths to Sdf spec paths in a SdfLayer where edits should be direct...
Definition: editTarget.h:64
A proxy class for applying listOp edits to the inherit paths list for a prim.
Definition: inherits.h:34
Base class for Usd scenegraph objects, providing common API.
Definition: object.h:116
Accessor to a attribute's definition in the prim definition.
Accessor to a property's definition in the prim definition.
Accessor to a relationship's definition in the prim definition.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
An forward-iterable range that traverses a subtree of prims rooted at a given prim in depth-first ord...
Definition: primRange.h:102
Base class for UsdAttribute and UsdRelationship scenegraph objects.
Definition: property.h:38
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:111
Container for information about the source of an attribute's value, i.e.
Definition: resolveInfo.h:55
Defines a subrange of nodes and layers within a prim's prim index to consider when performing value r...
Definition: resolveTarget.h:56
A proxy class for applying listOp edits to the specializes list for a prim.
Definition: specializes.h:34
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:137
USD_API void SetEndTimeCode(double)
Sets the stage's end timeCode.
USD_API void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet, UsdLoadPolicy policy=UsdLoadWithDescendants)
Unload and load the given path sets.
USD_API void WriteFallbackPrimTypes()
Writes the fallback prim types defined in the schema registry to the stage as dictionary valued fallb...
static USD_API void SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration, const TfToken &colorManagementSystem)
Sets the global fallback values of color configuration metadata which includes the 'colorConfiguratio...
static USD_API UsdStageRefPtr Open(const SdfLayerHandle &rootLayer, const SdfLayerHandle &sessionLayer, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool ExportToString(std::string *result, bool addSourceFileComment=true) const
Writes the composite scene as a flattened Usd text representation into the given string.
static USD_API UsdStageRefPtr OpenMasked(const SdfLayerHandle &rootLayer, const UsdStagePopulationMask &mask, InitialLoadSet load=LoadAll)
Open a stage rooted at rootLayer and with limited population subject to mask.
static USD_API UsdStageRefPtr CreateNew(const std::string &identifier, const SdfLayerHandle &sessionLayer, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API std::vector< UsdPrim > GetPrototypes() const
Returns all native instancing prototype prims.
USD_API bool HasAuthoredMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
Return true if there exists any authored opinion (excluding fallbacks) for key and keyPath.
USD_API bool SetMetadata(const TfToken &key, VtValueRef value) const
Set the value of Stage metadatum key to value, if the stage's current UsdEditTarget is the root or se...
USD_API UsdPrim OverridePrim(const SdfPath &path)
Attempt to ensure a UsdPrim at path exists on this stage.
USD_API void SetPopulationMask(UsdStagePopulationMask const &mask)
Set this stage's population mask and recompose the stage.
USD_API void UnmuteLayer(const std::string &layerIdentifier)
Unmute the layer identified by layerIdentifier if it had previously been muted.
USD_API SdfPathSet GetLoadSet()
Returns a set of all loaded paths.
USD_API PcpErrorVector GetCompositionErrors() const
Return a PcpErrorVector containing all composition errors encountered when composing the prims and la...
static USD_API PcpVariantFallbackMap GetGlobalVariantFallbacks()
Get the global variant fallback preferences used in new UsdStages.
USD_API void ExpandPopulationMask(std::function< bool(UsdRelationship const &)> const &relPred=nullptr, std::function< bool(UsdAttribute const &)> const &attrPred=nullptr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool HasAuthoredMetadata(const TfToken &key) const
Returns true if the key has an authored value, false if no value was authored or the only value avail...
USD_API UsdEditTarget GetEditTargetForLocalLayer(size_t i)
Return a UsdEditTarget for editing the layer at index i in the layer stack.
USD_API SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const
Return a vector of all of the layers currently consumed by this stage, as determined by the compositi...
USD_API bool GetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, VtValue *value) const
overload
USD_API double GetEndTimeCode() const
Returns the stage's end timeCode.
static USD_API UsdStageRefPtr CreateInMemory(const std::string &identifier, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
UsdStagePopulationMask GetPopulationMask() const
Return this stage's population mask.
Definition: stage.h:656
USD_API bool Export(const std::string &filename, bool addSourceFileComment=true, const SdfLayer::FileFormatArguments &args=SdfLayer::FileFormatArguments()) const
Writes out the composite scene as a single flattened layer into filename.
static USD_API UsdStageRefPtr CreateNew(const std::string &identifier, InitialLoadSet load=LoadAll)
Create a new stage with root layer identifier, destroying potentially existing files with that identi...
USD_API UsdPrim GetPseudoRoot() const
Return the stage's "pseudo-root" prim, whose name is defined by Usd.
USD_API double GetFramesPerSecond() const
Returns the stage's framesPerSecond value.
USD_API std::string ResolveIdentifierToEditTarget(std::string const &identifier) const
Resolve the given identifier using this stage's ArResolverContext and the layer of its GetEditTarget(...
USD_API void ExpandPopulationMask(Usd_PrimFlagsPredicate const &traversalPredicate, std::function< bool(UsdRelationship const &)> const &relPred=nullptr, std::function< bool(UsdAttribute const &)> const &attrPred=nullptr)
Expand this stage's population mask to include the targets of all relationships that pass relPred and...
USD_API UsdProperty GetPropertyAtPath(const SdfPath &path) const
Return the UsdProperty at path, or an invalid UsdProperty if none exists.
static USD_API UsdStageRefPtr CreateInMemory(const std::string &identifier, const SdfLayerHandle &sessionLayer, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API UsdPrim DefinePrim(const SdfPath &path, const TfToken &typeName=TfToken())
Attempt to ensure a UsdPrim at path is defined (according to UsdPrim::IsDefined()) on this stage.
USD_API void SetTimeCodesPerSecond(double timeCodesPerSecond) const
Sets the stage's timeCodesPerSecond value.
USD_API UsdAttribute GetAttributeAtPath(const SdfPath &path) const
Return the UsdAttribute at path, or an invalid UsdAttribute if none exists.
USD_API UsdPrim GetDefaultPrim() const
Return the UsdPrim on this stage whose path is the root layer's defaultPrim metadata's value.
USD_API bool HasDefaultPrim() const
Return true if this stage's root layer has an authored opinion for the default prim layer metadata.
USD_API UsdPrimRange Traverse(const Usd_PrimFlagsPredicate &predicate)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USD_API void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration, TfToken *colorManagementSystem)
Returns the global fallback values of 'colorConfiguration' and 'colorManagementSystem'.
USD_API UsdPrim GetPrimAtPath(const SdfPath &path) const
Return the UsdPrim at path, or an invalid UsdPrim if none exists.
USD_API UsdInterpolationType GetInterpolationType() const
Returns the interpolation type used during value resolution for all attributes on this stage.
USD_API UsdPrimRange TraverseAll()
Traverse all the prims on this stage depth-first.
USD_API bool IsLayerMuted(const std::string &layerIdentifier) const
Returns true if the layer specified by layerIdentifier is muted in this cache, false otherwise.
USD_API void SetColorManagementSystem(const TfToken &cms) const
Sets the name of the color management system used to interpret the color configuration file pointed a...
USD_API void ClearDefaultPrim()
Clear the default prim layer metadata in this stage's root layer.
InitialLoadSet
Specifies the initial set of prims to load when opening a UsdStage.
Definition: stage.h:151
@ LoadAll
Load all loadable prims.
Definition: stage.h:152
@ LoadNone
Load no loadable prims.
Definition: stage.h:153
static USD_API UsdStageRefPtr CreateNew(const std::string &identifier, const SdfLayerHandle &sessionLayer, const ArResolverContext &pathResolverContext, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USD_API UsdStageRefPtr CreateInMemory(InitialLoadSet load=LoadAll)
Creates a new stage only in memory, analogous to creating an anonymous SdfLayer.
USD_API void SetDefaultPrim(const UsdPrim &prim)
Set the default prim layer metadata in this stage's root layer.
USD_API double GetTimeCodesPerSecond() const
Returns the stage's timeCodesPerSecond value.
static USD_API UsdStageRefPtr OpenMasked(const SdfLayerHandle &rootLayer, const SdfLayerHandle &sessionLayer, const ArResolverContext &pathResolverContext, const UsdStagePopulationMask &mask, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API double GetStartTimeCode() const
Returns the stage's start timeCode.
USD_API void MuteLayer(const std::string &layerIdentifier)
Mute the layer identified by layerIdentifier.
USD_API const std::vector< std::string > & GetMutedLayers() const
Returns a vector of all layers that have been muted on this stage.
USD_API bool HasMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
Return true if there exists any authored or fallback opinion for key and keyPath.
USD_API UsdPrim CreateClassPrim(const SdfPath &rootPrimPath)
Author an SdfPrimSpec with specifier == SdfSpecifierClass for the class at root prim path path at the...
USD_API void SaveSessionLayers()
Calls SdfLayer::Save on all dirty session layers and sublayers of session layers contributing to this...
static USD_API UsdStageRefPtr CreateInMemory(const std::string &identifier, const SdfLayerHandle &sessionLayer, const ArResolverContext &pathResolverContext, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USD_API UsdStageRefPtr OpenMasked(const SdfLayerHandle &rootLayer, const ArResolverContext &pathResolverContext, const UsdStagePopulationMask &mask, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API UsdObject GetObjectAtPath(const SdfPath &path) const
Return the UsdObject at path, or an invalid UsdObject if none exists.
USD_API SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const
includeSessionLayers is true, return the linearized strong-to-weak sublayers rooted at the stage's se...
static USD_API UsdStageRefPtr CreateNew(const std::string &identifier, const ArResolverContext &pathResolverContext, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USD_API bool IsSupportedFile(const std::string &filePath)
Indicates whether the specified file is supported by UsdStage.
static USD_API UsdStageRefPtr CreateInMemory(const std::string &identifier, const ArResolverContext &pathResolverContext, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API void MuteAndUnmuteLayers(const std::vector< std::string > &muteLayers, const std::vector< std::string > &unmuteLayers)
Mute and unmute the layers identified in muteLayers and unmuteLayers.
USD_API void SetColorConfiguration(const SdfAssetPath &colorConfig) const
Sets the default color configuration to be used for querying color configuration metadata stored in a...
USD_API bool HasLocalLayer(const SdfLayerHandle &layer) const
Return true if layer is one of the layers in this stage's local, root layerStack.
USD_API void SetFramesPerSecond(double framesPerSecond) const
Sets the stage's framesPerSecond value.
static USD_API UsdStageRefPtr Open(const SdfLayerHandle &rootLayer, const ArResolverContext &pathResolverContext, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool GetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, T *value) const
Resolve the requested dictionary sub-element keyPath of dictionary-valued metadatum named key,...
Definition: stage.h:2341
USD_API SdfAssetPath GetColorConfiguration() const
Returns the default color configuration stored in layer metadata.
static USD_API UsdStageRefPtr Open(const std::string &filePath, InitialLoadSet load=LoadAll)
Attempt to find a matching existing stage in a cache if UsdStageCacheContext objects exist on the sta...
USD_API void Reload()
Calls SdfLayer::Reload on all layers contributing to this stage, except session layers and sublayers ...
USD_API bool RemovePrim(const SdfPath &path)
Remove all scene description for the given path and its subtree in the current UsdEditTarget.
USD_API bool HasAuthoredTimeCodeRange() const
Returns true if the stage has both start and end timeCodes authored in the session layer or the root ...
USD_API void SetEditTarget(const UsdEditTarget &editTarget)
Set the stage's EditTarget.
USD_API UsdEditTarget GetEditTargetForLocalLayer(const SdfLayerHandle &layer)
Return a UsdEditTarget for editing the given local layer.
USD_API void SetLoadRules(UsdStageLoadRules const &rules)
Set the UsdStageLoadRules to govern payload inclusion on this stage.
USD_API void SetInterpolationType(UsdInterpolationType interpolationType)
Sets the interpolation type used during value resolution for all attributes on this stage.
bool GetMetadata(const TfToken &key, T *value) const
Return in value an authored or fallback value (if one was defined for the given metadatum) for Stage ...
Definition: stage.h:2319
static USD_API UsdStageRefPtr Open(const SdfLayerHandle &rootLayer, InitialLoadSet load=LoadAll)
Open a stage rooted at rootLayer.
static USD_API UsdStageRefPtr OpenMasked(const std::string &filePath, const ArResolverContext &pathResolverContext, UsdStagePopulationMask const &mask, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USD_API UsdStageRefPtr Open(const std::string &filePath, const ArResolverContext &pathResolverContext, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API ArResolverContext GetPathResolverContext() const
Return the path resolver context for all path resolution during composition of this stage.
USD_API TfToken GetColorManagementSystem() const
Sets the name of the color management system to be used for loading and interpreting the color config...
USD_API UsdPrimRange Traverse()
Traverse the active, loaded, defined, non-abstract prims on this stage depth-first.
UsdStageLoadRules const & GetLoadRules() const
Return the stage's current UsdStageLoadRules governing payload inclusion.
Definition: stage.h:639
static USD_API void SetGlobalVariantFallbacks(const PcpVariantFallbackMap &fallbacks)
Set the global variant fallback preferences used in new UsdStages.
static USD_API UsdStageRefPtr OpenMasked(const std::string &filePath, UsdStagePopulationMask const &mask, InitialLoadSet load=LoadAll)
Create a new stage and recursively compose prims defined within and referenced by the layer at filePa...
USD_API void Save()
Calls SdfLayer::Save on all dirty layers contributing to this stage except session layers and sublaye...
USD_API SdfPathSet FindLoadable(const SdfPath &rootPath=SdfPath::AbsoluteRootPath())
Returns an SdfPathSet of all paths that can be loaded.
USD_API bool HasMetadata(const TfToken &key) const
Returns true if the key has a meaningful value, that is, if GetMetadata() will provide a value,...
USD_API SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const
Returns a single, anonymous, merged layer for this composite scene.
USD_API SdfLayerHandle GetRootLayer() const
Return this stage's root layer.
static USD_API UsdStageRefPtr OpenMasked(const SdfLayerHandle &rootLayer, const SdfLayerHandle &sessionLayer, const UsdStagePopulationMask &mask, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API UsdRelationship GetRelationshipAtPath(const SdfPath &path) const
Return the UsdAttribute at path, or an invalid UsdAttribute if none exists.
USD_API UsdPrim Load(const SdfPath &path=SdfPath::AbsoluteRootPath(), UsdLoadPolicy policy=UsdLoadWithDescendants)
Modify this stage's load rules to load the prim at path, its ancestors, and all of its descendants if...
USD_API void Unload(const SdfPath &path=SdfPath::AbsoluteRootPath())
Modify this stage's load rules to unload the prim and its descendants specified by path.
USD_API void SetStartTimeCode(double)
Sets the stage's start timeCode.
USD_API bool GetMetadata(const TfToken &key, VtValue *value) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USD_API UsdStageRefPtr Open(const SdfLayerHandle &rootLayer, const SdfLayerHandle &sessionLayer, const ArResolverContext &pathResolverContext, InitialLoadSet load=LoadAll)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool ClearMetadata(const TfToken &key) const
Clear the value of stage metadatum key, if the stage's current UsdEditTarget is the root or session l...
USD_API SdfLayerHandle GetSessionLayer() const
Return this stage's root session layer.
USD_API const UsdEditTarget & GetEditTarget() const
Return the stage's EditTarget.
USD_API bool SetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, VtValueRef value) const
Author value to the field identified by key and keyPath at the current EditTarget.
USD_API bool ClearMetadataByDictKey(const TfToken &key, const TfToken &keyPath) const
Clear any authored value identified by key and keyPath at the current EditTarget.
This class represents rules that govern payload inclusion on UsdStages.
This class represents a mask that may be applied to a UsdStage to limit the set of UsdPrim s it popul...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
A UsdVariantSet represents a single VariantSet in USD (e.g.
Definition: variantSets.h:39
UsdVariantSets represents the collection of VariantSets that are present on a UsdPrim.
Definition: variantSets.h:205
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
VT_API std::string GetTypeName() const
Return the type name of the held typeid.
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1002
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1046
A non-owning type-erased view of a value, interoperating with VtValue.
Definition: valueRef.h:65
UsdLoadPolicy
Controls UsdStage::Load() and UsdPrim::Load() behavior regarding whether or not descendant prims are ...
Definition: common.h:99
@ UsdLoadWithDescendants
Load a prim plus all its descendants.
Definition: common.h:101
Standard pointer typedefs.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:68
UsdInterpolationType
Attribute value interpolation options.
Definition: interpolation.h:28
A trait indicating whether VtValue compose-over functionality can be registered for a type.
Definition: traits.h:137
A trait indicating whether VtValue transform functionality can be registered for a type.
Definition: traits.h:147
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap
Definition: types.h:189
Basic Sdf data types.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:71
SdfSpecifier
An enum that identifies the possible specifiers for an SdfPrimSpec.
Definition: types.h:103
SdfVariability
An enum that identifies variability types for attributes.
Definition: types.h:159