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_hash_map.h>
40#include <tbb/spin_rw_mutex.h>
41
42#include <functional>
43#include <string>
44#include <memory>
45#include <optional>
46#include <unordered_map>
47#include <utility>
48
49PXR_NAMESPACE_OPEN_SCOPE
50
52class GfInterval;
54class TsSpline;
55class Usd_AssetPathContext;
56class Usd_ClipCache;
57class Usd_InstanceCache;
58class Usd_InstanceChanges;
59class Usd_Interpolator;
60class Usd_Resolver;
61class UsdResolveInfo;
63class UsdPrim;
64class UsdPrimRange;
65
66SDF_DECLARE_HANDLES(SdfLayer);
67
135class UsdStage : public TfRefBase, public TfWeakBase {
136public:
137
138 // --------------------------------------------------------------------- //
142 // --------------------------------------------------------------------- //
143
149 {
151 LoadNone
152 };
153
164 //
176 USD_API
177 static UsdStageRefPtr
178 CreateNew(const std::string& identifier,
179 InitialLoadSet load = LoadAll);
181 USD_API
182 static UsdStageRefPtr
183 CreateNew(const std::string& identifier,
184 const SdfLayerHandle& sessionLayer,
185 InitialLoadSet load = LoadAll);
187 USD_API
188 static UsdStageRefPtr
189 CreateNew(const std::string& identifier,
190 const SdfLayerHandle& sessionLayer,
191 const ArResolverContext& pathResolverContext,
192 InitialLoadSet load = LoadAll);
194 USD_API
195 static UsdStageRefPtr
196 CreateNew(const std::string& identifier,
197 const ArResolverContext& pathResolverContext,
198 InitialLoadSet load = LoadAll);
199
217 USD_API
218 static UsdStageRefPtr
221 USD_API
222 static UsdStageRefPtr
223 CreateInMemory(const std::string& identifier,
224 InitialLoadSet load = LoadAll);
226 USD_API
227 static UsdStageRefPtr
228 CreateInMemory(const std::string& identifier,
229 const ArResolverContext& pathResolverContext,
230 InitialLoadSet load = LoadAll);
232 USD_API
233 static UsdStageRefPtr
234 CreateInMemory(const std::string& identifier,
235 const SdfLayerHandle &sessionLayer,
236 InitialLoadSet load = LoadAll);
238 USD_API
239 static UsdStageRefPtr
240 CreateInMemory(const std::string& identifier,
241 const SdfLayerHandle &sessionLayer,
242 const ArResolverContext& pathResolverContext,
243 InitialLoadSet load = LoadAll);
244
260 USD_API
261 static UsdStageRefPtr
262 Open(const std::string& filePath, InitialLoadSet load = LoadAll);
264 USD_API
265 static UsdStageRefPtr
266 Open(const std::string& filePath,
267 const ArResolverContext& pathResolverContext,
268 InitialLoadSet load = LoadAll);
269
287 USD_API
288 static UsdStageRefPtr
289 OpenMasked(const std::string &filePath,
290 UsdStagePopulationMask const &mask,
291 InitialLoadSet load = LoadAll);
293 USD_API
294 static UsdStageRefPtr
295 OpenMasked(const std::string &filePath,
296 const ArResolverContext &pathResolverContext,
297 UsdStagePopulationMask const &mask,
298 InitialLoadSet load = LoadAll);
299
328 USD_API
329 static UsdStageRefPtr
330 Open(const SdfLayerHandle& rootLayer,
333 USD_API
334 static UsdStageRefPtr
335 Open(const SdfLayerHandle& rootLayer,
336 const SdfLayerHandle& sessionLayer,
339 USD_API
340 static UsdStageRefPtr
341 Open(const SdfLayerHandle& rootLayer,
342 const ArResolverContext& pathResolverContext,
345 USD_API
346 static UsdStageRefPtr
347 Open(const SdfLayerHandle& rootLayer,
348 const SdfLayerHandle& sessionLayer,
349 const ArResolverContext& pathResolverContext,
351
372 USD_API
373 static UsdStageRefPtr
374 OpenMasked(const SdfLayerHandle& rootLayer,
375 const UsdStagePopulationMask &mask,
378 USD_API
379 static UsdStageRefPtr
380 OpenMasked(const SdfLayerHandle& rootLayer,
381 const SdfLayerHandle& sessionLayer,
382 const UsdStagePopulationMask &mask,
385 USD_API
386 static UsdStageRefPtr
387 OpenMasked(const SdfLayerHandle& rootLayer,
388 const ArResolverContext& pathResolverContext,
389 const UsdStagePopulationMask &mask,
392 USD_API
393 static UsdStageRefPtr
394 OpenMasked(const SdfLayerHandle& rootLayer,
395 const SdfLayerHandle& sessionLayer,
396 const ArResolverContext& pathResolverContext,
397 const UsdStagePopulationMask &mask,
399
400 USD_API
401 virtual ~UsdStage();
402
420 USD_API
421 void Reload();
422
431 USD_API
432 static bool
433 IsSupportedFile(const std::string& filePath);
434
436
437 // --------------------------------------------------------------------- //
446
454 USD_API
455 void Save();
456
464 USD_API
466
468
469 // --------------------------------------------------------------------- //
515
517 USD_API
519
525 USD_API
526 static void
528
530
531 // --------------------------------------------------------------------- //
560 // --------------------------------------------------------------------- //
561
569 USD_API
572
578 USD_API
580
592 USD_API
593 void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet,
595
606 USD_API
607 SdfPathSet GetLoadSet();
608
628 USD_API
629 SdfPathSet FindLoadable(
630 const SdfPath& rootPath = SdfPath::AbsoluteRootPath());
631
638 return _loadRules;
639 }
640
650 USD_API
651 void SetLoadRules(UsdStageLoadRules const &rules);
652
655 return _populationMask;
656 }
657
659 USD_API
661
675 USD_API
677 Usd_PrimFlagsPredicate const &traversalPredicate,
678 std::function<bool (UsdRelationship const &)> const &relPred = nullptr,
679 std::function<bool (UsdAttribute const &)> const &attrPred = nullptr);
680
684 USD_API
686 std::function<bool (UsdRelationship const &)> const &relPred = nullptr,
687 std::function<bool (UsdAttribute const &)> const &attrPred = nullptr);
688
690
691 // --------------------------------------------------------------------- //
700 // --------------------------------------------------------------------- //
701
713 USD_API
715
723 USD_API
725
737 USD_API
738 void SetDefaultPrim(const UsdPrim &prim);
739
747 USD_API
749
757 USD_API
758 bool HasDefaultPrim() const;
759
769 USD_API
770 UsdPrim GetPrimAtPath(const SdfPath &path) const;
771
796 USD_API
798
807 USD_API
809
818 USD_API
820
829 USD_API
831private:
832 // Return the primData object at \p path.
833 Usd_PrimDataConstPtr _GetPrimDataAtPath(const SdfPath &path) const;
834 Usd_PrimDataPtr _GetPrimDataAtPath(const SdfPath &path);
835
836 // Return the primData object at \p path. If \p path indicates a prim
837 // beneath an instance, return the primData object for the corresponding
838 // prim in the instance's prototype.
839 Usd_PrimDataConstPtr
840 _GetPrimDataAtPathOrInPrototype(const SdfPath &path) const;
841
843 std::vector<UsdPrim>
844 _GetInstancesForPrototype(const UsdPrim& prototype) const;
845
846public:
847
868 USD_API
870
875 USD_API
876 UsdPrimRange Traverse(const Usd_PrimFlagsPredicate &predicate);
877
882 USD_API
884
903 USD_API
905
929 USD_API
931 const TfToken &typeName=TfToken());
932
945 USD_API
946 UsdPrim CreateClassPrim(const SdfPath &rootPrimPath);
947
969 USD_API
970 bool RemovePrim(const SdfPath& path);
971
973
974 // --------------------------------------------------------------------- //
978 // --------------------------------------------------------------------- //
979
981 USD_API
982 SdfLayerHandle GetSessionLayer() const;
983
985 USD_API
986 SdfLayerHandle GetRootLayer() const;
987
992 USD_API
994
1004 USD_API
1005 std::string
1006 ResolveIdentifierToEditTarget(std::string const &identifier) const;
1007
1010 USD_API
1011 PcpErrorVector GetCompositionErrors() const;
1012
1018 USD_API
1019 SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const;
1020
1032 USD_API
1033 SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const;
1034
1037 USD_API
1038 bool HasLocalLayer(const SdfLayerHandle &layer) const;
1039
1041 USD_API
1043
1047 USD_API
1049
1053 USD_API
1054 UsdEditTarget GetEditTargetForLocalLayer(const SdfLayerHandle &layer);
1055
1062 USD_API
1063 void SetEditTarget(const UsdEditTarget &editTarget);
1064
1091 USD_API
1092 void MuteLayer(const std::string &layerIdentifier);
1093
1096 USD_API
1097 void UnmuteLayer(const std::string &layerIdentifier);
1098
1106 USD_API
1107 void MuteAndUnmuteLayers(const std::vector<std::string> &muteLayers,
1108 const std::vector<std::string> &unmuteLayers);
1109
1111 USD_API
1112 const std::vector<std::string>& GetMutedLayers() const;
1113
1118 USD_API
1119 bool IsLayerMuted(const std::string& layerIdentifier) const;
1120
1122
1123 // --------------------------------------------------------------------- //
1127 // --------------------------------------------------------------------- //
1128 // Future Work:
1129 // * Flatten sub-trees or individual prims
1130 // * Allow flattening of local LayerStack
1131 // * Move Flatten into a free-function to ensure it doesn't rely on
1132 // Stage internals.
1133
1141 USD_API
1142 bool Export(const std::string &filename,
1143 bool addSourceFileComment=true,
1144 const SdfLayer::FileFormatArguments &args =
1146
1154 USD_API
1155 bool ExportToString(std::string *result,
1156 bool addSourceFileComment=true) const;
1157
1184 USD_API
1185 SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const;
1187
1188public:
1189 // --------------------------------------------------------------------- //
1197 // --------------------------------------------------------------------- //
1198
1210 template <class T>
1211 bool GetMetadata(const TfToken &key, T *value) const;
1213 USD_API
1214 bool GetMetadata(const TfToken &key, VtValue *value) const;
1215
1222 USD_API
1223 bool HasMetadata(const TfToken &key) const;
1224
1233 USD_API
1234 bool HasAuthoredMetadata(const TfToken &key) const;
1235
1244 USD_API
1245 bool SetMetadata(const TfToken &key, VtValueRef value) const;
1246
1255 USD_API
1256 bool ClearMetadata(const TfToken &key) const;
1257
1273 template<typename T>
1274 bool GetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
1275 T* value) const;
1277 USD_API
1279 const TfToken& key, const TfToken &keyPath, VtValue *value) const;
1280
1291 USD_API
1293 const TfToken& key, const TfToken &keyPath) const;
1294
1303 USD_API
1305 const TfToken& key, const TfToken &keyPath) const;
1306
1318 USD_API
1320 const TfToken& key, const TfToken &keyPath, VtValueRef value) const;
1321
1333 USD_API
1335 const TfToken& key, const TfToken& keyPath) const;
1336
1355 USD_API
1357
1359
1360 // --------------------------------------------------------------------- //
1367 // --------------------------------------------------------------------- //
1371 USD_API
1372 double GetStartTimeCode() const;
1373
1380 USD_API
1381 void SetStartTimeCode(double);
1382
1386 USD_API
1387 double GetEndTimeCode() const;
1388
1395 USD_API
1396 void SetEndTimeCode(double);
1397
1400 USD_API
1402
1418 USD_API
1420
1429 USD_API
1430 void SetTimeCodesPerSecond(double timeCodesPerSecond) const;
1431
1441 USD_API
1442 double GetFramesPerSecond() const;
1443
1452 USD_API
1453 void SetFramesPerSecond(double framesPerSecond) const;
1454
1456
1457 // --------------------------------------------------------------------- //
1478 // --------------------------------------------------------------------- //
1479
1485 USD_API
1486 void SetColorConfiguration(const SdfAssetPath &colorConfig) const;
1487
1491 USD_API
1493
1498 USD_API
1499 void SetColorManagementSystem(const TfToken &cms) const;
1500
1505 USD_API
1507
1518 USD_API
1519 static void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration,
1520 TfToken *colorManagementSystem);
1521
1535 USD_API
1536 static void
1537 SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration,
1538 const TfToken &colorManagementSystem);
1539
1541
1542 // --------------------------------------------------------------------- //
1549 // --------------------------------------------------------------------- //
1550
1555 USD_API
1557
1560 USD_API
1562
1564
1565 // --------------------------------------------------------------------- //
1570 // --------------------------------------------------------------------- //
1571
1573 USD_API
1574 std::vector<UsdPrim> GetPrototypes() const;
1575
1577
1578private:
1579 struct _IncludePayloadsPredicate;
1580
1581 // --------------------------------------------------------------------- //
1582 // Stage Construction & Initialization
1583 // --------------------------------------------------------------------- //
1584
1585 UsdStage(const SdfLayerRefPtr& rootLayer,
1586 const SdfLayerRefPtr& sessionLayer,
1587 const ArResolverContext& pathResolverContext,
1588 const UsdStagePopulationMask& mask,
1589 InitialLoadSet load);
1590
1591 // Helper for Open() overloads -- searches and publishes to bound caches.
1592 template <class... Args>
1593 static UsdStageRefPtr _OpenImpl(InitialLoadSet load, Args const &... args);
1594
1595 // Releases resources used by this stage.
1596 void _Close();
1597
1598 // Common ref ptr initialization, called by public, static constructors.
1599 //
1600 // This method will either return a valid refptr (if the stage is correctly
1601 // initialized) or it will return a null ref pointer, deleting the
1602 // raw stage pointer in the process.
1603 static UsdStageRefPtr
1604 _InstantiateStage(const SdfLayerRefPtr &rootLayer,
1605 const SdfLayerRefPtr &sessionLayer,
1606 const ArResolverContext &pathResolverContext,
1607 const UsdStagePopulationMask &mask,
1608 InitialLoadSet load);
1609
1610 // --------------------------------------------------------------------- //
1611 // Spec Existence & Definition Helpers
1612 // --------------------------------------------------------------------- //
1613
1614 SdfPropertySpecHandleVector
1615 _GetPropertyStack(const UsdProperty &prop, UsdTimeCode time) const;
1616
1617 std::vector<std::pair<SdfPropertySpecHandle, SdfLayerOffset>>
1618 _GetPropertyStackWithLayerOffsets(
1619 const UsdProperty &prop, UsdTimeCode time) const;
1620
1621 static SdfPrimSpecHandleVector
1622 _GetPrimStack(const UsdPrim &prim);
1623
1624 static std::vector<std::pair<SdfPrimSpecHandle, SdfLayerOffset>>
1625 _GetPrimStackWithLayerOffsets(const UsdPrim &prim);
1626
1628 _GetSchemaProperty(const UsdProperty &prop) const;
1629
1630 USD_API
1632 _GetSchemaAttribute(const UsdAttribute &attr) const;
1633
1635 _GetSchemaRelationship(const UsdRelationship &rel) const;
1636
1637 SdfAttributeSpecHandle
1638 _CreateNewSpecFromSchemaAttribute(
1639 const UsdPrim &prim,
1640 const UsdPrimDefinition::Attribute &attrDef);
1641
1642 SdfRelationshipSpecHandle
1643 _CreateNewSpecFromSchemaRelationship(
1644 const UsdPrim &prim,
1645 const UsdPrimDefinition::Relationship &relDef);
1646
1647 template <class PropType>
1649 _CreateNewPropertySpecFromSchema(const UsdProperty &prop);
1650
1651 SdfPrimSpecHandle
1652 _CreatePrimSpecForEditing(const UsdPrim& prim);
1653
1654 template <class PropType>
1656 _CreatePropertySpecForEditing(const UsdProperty &prop);
1657
1658 SdfPropertySpecHandle
1659 _CreatePropertySpecForEditing(const UsdProperty &prop);
1660
1661 SdfAttributeSpecHandle
1662 _CreateAttributeSpecForEditing(const UsdAttribute &attr);
1663
1664 SdfRelationshipSpecHandle
1665 _CreateRelationshipSpecForEditing(const UsdRelationship &rel);
1666
1667 // Check if the given path is valid to use with the prim creation API,
1668 // like DefinePrim. If it is valid, returns (true, GetPrimAtPath(path)).
1669 // Otherwise, returns (false, UsdPrim()).
1670 std::pair<bool, UsdPrim>
1671 _IsValidPathForCreatingPrim(const SdfPath &path) const;
1672
1673 // Validates that editing a specified prim is allowed. If editing is not
1674 // allowed, issues a coding error like "Cannot <operation> ..." and
1675 // returns false. Otherwise, returns true.
1676 bool _ValidateEditPrim(const UsdPrim &prim, const char* operation) const;
1677 bool _ValidateEditPrimAtPath(const SdfPath &primPath,
1678 const char* operation) const;
1679
1680 UsdPrim _DefinePrim(const SdfPath &path, const TfToken &typeName);
1681
1682 bool _RemoveProperty(const SdfPath& path);
1683
1684 UsdProperty _FlattenProperty(const UsdProperty &srcProp,
1685 const UsdPrim &dstParent,
1686 const TfToken &dstName);
1687
1688 // --------------------------------------------------------------------- //
1689 // Value & Metadata Authoring
1690 // --------------------------------------------------------------------- //
1691
1692 // Set value for dynamically typed VtValueRef. Will map the value across
1693 // edit targets if the held value type supports it.
1694 bool _SetValue(
1695 UsdTimeCode time, const UsdAttribute &attr, VtValueRef newValue);
1696
1697 TfToken _GetAttributeValueTypeNameToken(const UsdAttribute &attr) const;
1698 SdfValueTypeName _GetAttributeValueTypeName(const UsdAttribute &attr) const;
1699 TfType _GetAttributeValueType(const UsdAttribute &attr) const;
1700
1701 bool _ClearValue(UsdTimeCode time, const UsdAttribute &attr);
1702
1703 // Set metadata for dynamically typed VtValueRef. Will map the value across
1704 // edit targets if the value type supports it.
1705 USD_API
1706 bool _SetMetadata(const UsdObject &object,
1707 const TfToken& key,
1708 const TfToken &keyPath,
1709 VtValueRef value);
1710
1711 bool _ClearMetadata(const UsdObject &obj, const TfToken& fieldName,
1712 const TfToken &keyPath=TfToken());
1713
1714 // --------------------------------------------------------------------- //
1715 // Misc Internal Helpers
1716 // --------------------------------------------------------------------- //
1717
1718 // Pcp helpers.
1719 PcpCache const *_GetPcpCache() const { return _cache.get(); }
1720 PcpCache *_GetPcpCache() { return _cache.get(); }
1721
1722 // Returns the PrimIndex, using the read-only PcpCache API. We expect prims
1723 // to be composed during initial stage composition, so this method should
1724 // not be used in that context.
1725 const PcpPrimIndex* _GetPcpPrimIndex(const SdfPath& primPath) const;
1726
1727 // Helper to report pcp errors.
1728 void _ReportPcpErrors(const PcpErrorVector &errors,
1729 const std::string &context) const;
1730 void _ReportErrors(const PcpErrorVector &errors,
1731 const std::vector<std::string>& otherErrors,
1732 const std::string &context) const;
1733
1734 // --------------------------------------------------------------------- //
1735 // Scenegraph Composition & Change Processing
1736 // --------------------------------------------------------------------- //
1737
1738 // Compose the prim indexes in the subtrees rooted at the paths in
1739 // \p primIndexPaths. If \p instanceChanges is given, returns
1740 // changes to prototypes and instances due to the discovery of new instances
1741 // during composition.
1742 void _ComposePrimIndexesInParallel(
1743 const std::vector<SdfPath>& primIndexPaths,
1744 const std::string& context,
1745 Usd_InstanceChanges* instanceChanges = nullptr);
1746
1747 // Recompose the subtree rooted at \p prim: compose its type, flags, and
1748 // list of children, then invoke _ComposeSubtree on all its children.
1749 void _ComposeSubtree(
1750 Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1751 UsdStagePopulationMask const *mask,
1752 const SdfPath &primIndexPath = SdfPath());
1753 void _ComposeSubtreeImpl(
1754 Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1755 UsdStagePopulationMask const *mask,
1756 const SdfPath &primIndexPath = SdfPath());
1757 void _ComposeSubtreesInParallel(
1758 const std::vector<Usd_PrimDataPtr> &prims,
1759 const std::vector<SdfPath> *primIndexPaths = nullptr);
1760
1761 // Composes the full prim type info for the prim based on its type name
1762 // and applied API schemas.
1763 void _ComposePrimTypeInfoImpl(Usd_PrimDataPtr prim);
1764
1765 // Compose subtree rooted at \p prim under \p parent. This function
1766 // ensures that the appropriate prim index is specified for \p prim if
1767 // \p parent is in a prototype.
1768 void _ComposeChildSubtree(Usd_PrimDataPtr prim,
1769 Usd_PrimDataConstPtr parent,
1770 UsdStagePopulationMask const *mask);
1771
1772 // Compose \p prim's list of children and make any modifications necessary
1773 // to its _children member and the stage's _primMap, including possibly
1774 // instantiating new prims, or destroying existing subtrees of prims. The
1775 // any newly created prims *do not* have their prim index, type, flags, or
1776 // children composed.
1777 //
1778 // Compose only \p prim's direct children if recurse=false. Otherwise
1779 // recompose every descendent of \p prim. Callers that pass recurse=false
1780 // should invoke _ComposeSubtree on any newly created prims to ensure caches
1781 // are correctly populated.
1782 void _ComposeChildren(Usd_PrimDataPtr prim,
1783 UsdStagePopulationMask const *mask, bool recurse);
1784
1785 // Instantiate a prim instance. There must not already be an instance
1786 // at \p primPath.
1787 Usd_PrimDataPtr _InstantiatePrim(const SdfPath &primPath);
1788
1789 // Instantiate a prototype prim and sets its parent to pseudoroot.
1790 // There must not already be a prototype at \p primPath.
1791 Usd_PrimDataPtr _InstantiatePrototypePrim(const SdfPath &primPath);
1792
1793 // For \p prim and all of its descendants, remove from _primMap and empty
1794 // their _children vectors.
1795 void _DestroyPrim(Usd_PrimDataPtr prim);
1796
1797 // Destroy the prim subtrees rooted at each path in \p paths. \p paths may
1798 // not contain any path that is a descendent of another path in \p paths.
1799 void _DestroyPrimsInParallel(const std::vector<SdfPath>& paths);
1800
1801 // Invoke _DestroyPrim() on all of \p prim's direct children.
1802 void _DestroyDescendents(Usd_PrimDataPtr prim);
1803
1804 // Returns true if the object at the given path is a descendant of
1805 // an instance prim, i.e. a prim beneath an instance prim, or a property
1806 // of a prim beneath an instance prim.
1807 bool _IsObjectDescendantOfInstance(const SdfPath& path) const;
1808
1809 // If the given prim is an instance, returns the corresponding
1810 // prototype prim. Otherwise, returns an invalid prim.
1811 Usd_PrimDataConstPtr _GetPrototypeForInstance(Usd_PrimDataConstPtr p) const;
1812
1813 // Returns the path of the Usd prim using the prim index at the given path.
1814 SdfPath _GetPrimPathUsingPrimIndexAtPath(const SdfPath& primIndexPath) const;
1815
1816 // Responds to LayersDidChangeSentPerLayer event and update stage contents
1817 // in response to changes in scene description.
1818 void _HandleLayersDidChange(const SdfNotice::LayersDidChangeSentPerLayer &);
1819
1820 // Pushes changes through PCP to determine invalidation based on
1821 // composition metadata.
1822 // Note: This method will not perform any processing or notification
1823 // Refer to _ProcessPendingChanges()
1824 void _ComputePendingChanges(const SdfLayerChangeListVec &);
1825
1826 // Update stage contents in response to changes to the asset resolver.
1827 void _HandleResolverDidChange(const ArNotice::ResolverChanged &);
1828
1829 // Process stage change information stored in _pendingChanges.
1830 // _pendingChanges will be set to nullptr by the end of the function.
1831 // This function will return true if UsdNotice::ObjectsChanged and
1832 // UsdNotice::StageContentsChanged notices were sent during execution.
1833 bool _ProcessPendingChanges();
1834
1835 // Remove scene description for the prim at \p fullPath in the current edit
1836 // target.
1837 bool _RemovePrim(const SdfPath& fullPath);
1838
1839 SdfPrimSpecHandle _GetPrimSpec(const SdfPath& fullPath);
1840
1841 // Find and return the defining spec type for the property spec at the given
1842 // path, or SdfSpecTypeUnknown if none exists. The defining spec type is
1843 // either the builtin definition's spec type, if the indicated property is
1844 // builtin, otherwise it's the strongest authored spec's type if one exists,
1845 // otherwise it's SdfSpecTypeUnknown.
1846 SdfSpecType _GetDefiningSpecType(Usd_PrimDataConstPtr primData,
1847 const TfToken &propName) const;
1848
1849 // Helper to apply Pcp changes and recompose the scenegraph accordingly,
1850 // given an optional initial set of paths to recompose.
1851 void _Recompose(const PcpChanges &changes);
1852 template <class T>
1853 void _Recompose(const PcpChanges &changes, T *pathsToRecompose);
1854 template <class T>
1855 void _RecomposePrims(T *pathsToRecompose);
1856
1857 // Helper for _Recompose to find the subtrees that need to be
1858 // fully recomposed and to recompose the name children of the
1859 // parents of these subtrees. Note that [start, finish) must be a
1860 // sorted range of map iterators whose keys are paths with no descendent
1861 // paths. In C++20, consider using the ranges API to improve this.
1862 template <class Iter>
1863 void _ComputeSubtreesToRecompose(Iter start, Iter finish,
1864 std::vector<Usd_PrimDataPtr>* recompose);
1865
1866 // return true if the path is valid for load/unload operations.
1867 // This method will emit errors when invalid paths are encountered.
1868 bool _IsValidForLoad(const SdfPath& path) const;
1869 bool _IsValidForUnload(const SdfPath& path) const;
1870
1871 // Discover all payloads in a given subtree, adding the path of each
1872 // discovered prim index to the \p primIndexPaths set. If specified,
1873 // the corresponding UsdPrim path will be added to the \p usdPrimPaths
1874 // set. The root path will be considered for inclusion in the result set.
1875 //
1876 // Note that some payloads may not be discoverable in until an ancestral
1877 // payload has been included. UsdStage::LoadAndUnload takes this into
1878 // account.
1879 void _DiscoverPayloads(const SdfPath& rootPath,
1880 UsdLoadPolicy policy,
1881 SdfPathSet* primIndexPaths,
1882 bool unloadedOnly = false,
1883 SdfPathSet* usdPrimPaths = nullptr) const;
1884
1885 // ===================================================================== //
1886 // VALUE RESOLUTION //
1887 // ===================================================================== //
1888 // --------------------------------------------------------------------- //
1889 // Specialized Value Resolution
1890 // --------------------------------------------------------------------- //
1891
1892 // Helpers for resolving values for metadata fields requiring
1893 // special behaviors.
1894 static SdfSpecifier _GetSpecifier(Usd_PrimDataConstPtr primData);
1895 static TfToken _GetKind(Usd_PrimDataConstPtr primData);
1896 static bool _IsActive(Usd_PrimDataConstPtr primData);
1897
1898 // Custom is true if it is true anywhere in the stack.
1899 bool _IsCustom(const UsdProperty &prop) const;
1900
1901 // Variability is determined by the weakest opinion in the stack.
1902 SdfVariability _GetVariability(const UsdProperty &prop) const;
1903
1904 // Helper functions for resolving asset paths during value resolution.
1905 void _MakeResolvedAssetPaths(UsdTimeCode time, const UsdAttribute &attr,
1906 SdfAssetPath *assetPaths,
1907 size_t numAssetPaths,
1908 bool anchorAssetPathsOnly = false) const;
1909
1910 void _MakeResolvedAssetPathsValue(UsdTimeCode time, const UsdAttribute &attr,
1911 VtValue *value,
1912 bool anchorAssetPathsOnly = false) const;
1913
1914 // --------------------------------------------------------------------- //
1915 // Metadata Resolution
1916 // --------------------------------------------------------------------- //
1917
1918public:
1919 // Trait that allows us to call the correct version of _GetMetadata for
1920 // types that require type specific value resolution as opposed to just
1921 // strongest opinion. These types also use type specific resolution
1922 // in _GetValue.
1923 template <class T>
1924 struct _HasTypeSpecificResolution {
1925 static const bool value =
1926 std::is_same<T, SdfAssetPath>::value ||
1927 std::is_same<T, VtArray<SdfAssetPath>>::value ||
1928 std::is_same<T, SdfTimeCode>::value ||
1929 std::is_same<T, VtArray<SdfTimeCode>>::value ||
1930 std::is_same<T, SdfPathExpression>::value ||
1931 std::is_same<T, VtArray<SdfPathExpression>>::value ||
1932 std::is_same<T, SdfTimeSampleMap>::value ||
1933 std::is_same<T, TsSpline>::value ||
1934 std::is_same<T, VtDictionary>::value;
1935 };
1936
1937private:
1938 // Get metadata as a dynamically typed VtValue. Will perform type specific
1939 // value resolution if the returned held type requires it.
1940 USD_API
1941 bool _GetMetadata(const UsdObject &obj,
1942 const TfToken& fieldName,
1943 const TfToken &keyPath,
1944 bool useFallbacks,
1945 VtValue* result) const;
1946
1947 USD_API
1948 bool _GetMetadata(const UsdObject &obj,
1949 const TfToken& fieldName,
1950 const TfToken &keyPath,
1951 bool useFallbacks,
1952 SdfAbstractDataValue *result,
1953 bool strongestOnly) const;
1954
1955 template <class T>
1956 bool _GetMetadata(const UsdObject &obj,
1957 const TfToken& fieldName,
1958 const TfToken &keyPath,
1959 bool useFallbacks,
1960 T* result) const {
1961 SdfAbstractDataTypedValue<T> out(result);
1962 const bool strongestOnly =
1965 return _GetMetadata(obj, fieldName, keyPath, useFallbacks, &out,
1966 strongestOnly);
1967 }
1968
1969 template <class Composer>
1970 void _GetAttrTypeImpl(const UsdAttribute &attr,
1971 const TfToken &fieldName,
1972 bool useFallbacks,
1973 Composer *composer) const;
1974
1975 template <class Composer>
1976 void _GetAttrVariabilityImpl(const UsdAttribute &attr,
1977 bool useFallbacks,
1978 Composer *composer) const;
1979
1980 template <class Composer>
1981 void _GetPropCustomImpl(const UsdProperty &prop,
1982 bool useFallbacks,
1983 Composer *composer) const;
1984
1985 template <class Composer>
1986 bool _GetSpecialPropMetadataImpl(const UsdObject &obj,
1987 const TfToken &fieldName,
1988 const TfToken &keyPath,
1989 bool useFallbacks,
1990 Composer *composer) const;
1991 template <class Composer>
1992 bool _GetMetadataImpl(const UsdObject &obj,
1993 const TfToken& fieldName,
1994 const TfToken& keyPath,
1995 bool includeFallbacks,
1996 Composer *composer) const;
1997
1998 template <class Composer>
1999 bool _GetGeneralMetadataImpl(const UsdObject &obj,
2000 const TfToken& fieldName,
2001 const TfToken& keyPath,
2002 bool includeFallbacks,
2003 Composer *composer) const;
2004
2005 // NOTE: The "authoredOnly" flag is not yet in use, but when we have
2006 // support for prim-based metadata fallbacks, they should be ignored when
2007 // this flag is set to true.
2008 bool _HasMetadata(const UsdObject &obj, const TfToken& fieldName,
2009 const TfToken &keyPath, bool useFallbacks) const;
2010
2012 _ListMetadataFields(const UsdObject &obj, bool useFallbacks) const;
2013
2014 void _GetAllMetadata(const UsdObject &obj,
2015 bool useFallbacks,
2016 UsdMetadataValueMap* result,
2017 bool anchorAssetPathsOnly = false) const;
2018
2019 // --------------------------------------------------------------------- //
2020 // Default & TimeSample Resolution
2021 // --------------------------------------------------------------------- //
2022
2023 struct _ExtraResolveInfo;
2024
2025 // Gets the value resolve info for the given attribute. If time is provided,
2026 // the resolve info is evaluated for that specific time (which may be
2027 // default). Otherwise, if time is null, the resolve info is evaluated for
2028 // "any numeric time" and will not populate values in extraInfo that
2029 // require a specific time to be evaluated.
2030 void _GetResolveInfo(const UsdAttribute &attr,
2031 UsdResolveInfo *resolveInfo,
2032 const UsdTimeCode *time = nullptr,
2033 _ExtraResolveInfo *extraInfo = nullptr) const;
2034
2035 // Gets the value resolve info for the given attribute using the given
2036 // resolve target. If time is provided, the resolve info is evaluated for
2037 // that specific time (which may be default). Otherwise, if time is null,
2038 // the resolve info is evaluated for "any numeric time" and will not
2039 // populate values in extraInfo that require a specific time to be
2040 // evaluated.
2041 void _GetResolveInfoWithResolveTarget(
2042 const UsdAttribute &attr,
2043 const UsdResolveTarget &resolveTarget,
2044 UsdResolveInfo *resolveInfo,
2045 const UsdTimeCode *time = nullptr,
2046 _ExtraResolveInfo *extraInfo = nullptr) const;
2047
2048 // Shared implementation function for _GetResolveInfo and
2049 // _GetResolveInfoWithResolveTarget. The only difference between how these
2050 // two functions behave is in how they create the Usd_Resolver used for
2051 // iterating over nodes and layers, thus they provide this implementation
2052 // with the needed MakeUsdResolverFn to create the Usd_Resolver.
2053 template <class MakeUsdResolverFn>
2054 void _GetResolveInfoImpl(const UsdAttribute &attr,
2055 UsdResolveInfo *resolveInfo,
2056 const UsdTimeCode *time,
2057 _ExtraResolveInfo *extraInfo,
2058 const MakeUsdResolverFn &makeUsdResolveFn) const;
2059
2060 struct _BracketingSamplesResolver;
2061 struct _PropertyStackResolver;
2062 struct _ResolveInfoResolver;
2063 struct _SamplesInIntervalResolver;
2064 struct _TimeSampleMapResolver;
2065
2066 bool _GetTimeSampleMap(const UsdAttribute &attr,
2067 SdfTimeSampleMap *out,
2068 bool forFlattening=false) const;
2069
2070 template <class Resolver, class MakeUsdResolverFn>
2071 void _GetResolvedValueAtDefaultImpl(
2072 const UsdProperty &prop,
2073 Resolver *resolver,
2074 const MakeUsdResolverFn &makeUsdResolverFn) const;
2075
2076 template <class Resolver, class MakeUsdResolverFn>
2077 void _GetResolvedValueAtTimeImpl(
2078 const UsdProperty &prop,
2079 Resolver *resolver,
2080 const UsdTimeCode *time,
2081 const MakeUsdResolverFn &makeUsdResolverFn) const;
2082
2083 bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2084 VtValue* result) const;
2085
2086 USD_API
2087 bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2088 SdfAbstractDataValue* result) const;
2089
2090 template <class T>
2091 bool _GetValueImpl(UsdTimeCode time, const UsdAttribute &attr,
2092 Usd_Interpolator const &interpolator,
2093 T* value) const;
2094
2095 USD_API
2096 bool _GetValueFromResolveInfo(
2097 const UsdResolveInfo &info,
2098 UsdTimeCode time, const UsdAttribute &attr,
2099 VtValue* result,
2100 const UsdResolveTarget *resolveTarget = nullptr) const;
2101
2102 USD_API
2103 bool _GetValueFromResolveInfo(
2104 const UsdResolveInfo &info,
2105 UsdTimeCode time, const UsdAttribute &attr,
2106 SdfAbstractDataValue* result,
2107 const UsdResolveTarget *resolveTarget = nullptr) const;
2108
2109 // If `resolveTarget` is not null, then `infoIn` must have been obtained
2110 // with it (see _GetResolveInfoWithResolveTarget).
2111 //
2112 // If `extraInfo` is not null, then `infoIn` must be a complete resolve info
2113 // obtained for the specific `time`.
2114 template <class T>
2115 bool _GetValueFromResolveInfoImpl(
2116 UsdTimeCode time, const UsdAttribute &attr,
2117 Usd_Interpolator const &interpolator,
2118 const UsdResolveInfo &infoIn, const UsdResolveTarget *resolveTarget,
2119 const _ExtraResolveInfo *extraInfo, T *result) const;
2120
2121 bool _GetCompletedResolveInfo(const UsdAttribute &attr,
2122 UsdTimeCode time,
2123 const UsdResolveTarget *resolveTarget,
2124 const UsdResolveInfo &infoIn,
2125 UsdResolveInfo *infoOut,
2126 _ExtraResolveInfo *extraInfoOut) const;
2127
2128 Usd_AssetPathContext
2129 _GetAssetPathContext(UsdTimeCode time, const UsdAttribute &attr) const;
2130
2131 // --------------------------------------------------------------------- //
2132 // Specialized Time Sample I/O
2133 // --------------------------------------------------------------------- //
2134
2141 bool _GetTimeSamplesInInterval(
2142 const UsdAttribute &attr,
2143 const GfInterval& interval,
2144 std::vector<double>* times,
2145 const UsdResolveInfo *resolveInfo=nullptr,
2146 const UsdResolveTarget *resolveTarget=nullptr) const;
2147
2148 size_t _GetNumTimeSamples(
2149 const UsdAttribute &attr,
2150 const UsdResolveInfo *resolveInfo=nullptr,
2151 const UsdResolveTarget *resolveTarget=nullptr) const;
2152
2156 bool _GetBracketingTimeSamples(
2157 const UsdAttribute &attr,
2158 double desiredTime,
2159 double* lower,
2160 double* upper,
2161 bool* hasSamples,
2162 const UsdResolveInfo *resolveInfo=nullptr,
2163 const UsdResolveTarget *resolveTarget=nullptr) const;
2164
2165 bool _ValueMightBeTimeVarying(const UsdAttribute &attr) const;
2166
2167 bool _ValueMightBeTimeVaryingFromResolveInfo(
2168 const UsdResolveInfo &info,
2169 const UsdAttribute &attr) const;
2170
2171 void _RegisterPerLayerNotices();
2172 void _RegisterResolverChangeNotice();
2173
2174 // Helper to obtain a malloc tag string for this stage.
2175 inline char const *_GetMallocTagId() const;
2176
2177private:
2178 class _PendingChanges;
2179
2180 // Change block for use by the UsdNamespaceEditor to allow it to indicate
2181 // to its dependent stages what the expected namespace edits are when the
2182 // stages handles notices from the changes the namespace editor performs.
2183 // The stage uses this provide additional information about prim resyncs
2184 // related to namespace edits in the ObjectsChanged notice it sends.
2185 class _NamespaceEditsChangeBlock {
2186 public:
2187 // Info about an expected namespace edit change from UsdNamespaceEditor.
2188 // This includes the original pre-edit prim stack of the prim at the old
2189 // path which is used to determine if the prim at the new path has the
2190 // same composed contents after the edits as the prim had originally at
2191 // the old path before the edits.
2192 struct ExpectedNamespaceEditChange {
2193 SdfPath oldPath;
2194 SdfPath newPath;
2195 SdfPrimSpecHandleVector oldPrimStack;
2196 };
2197 using ExpectedNamespaceEditChangeVector =
2198 std::vector<ExpectedNamespaceEditChange>;
2199
2200 _NamespaceEditsChangeBlock(const UsdStagePtr &stage,
2201 ExpectedNamespaceEditChangeVector &&expectedChanges);
2202 _NamespaceEditsChangeBlock(_NamespaceEditsChangeBlock &&);
2203 ~_NamespaceEditsChangeBlock();
2204
2205 private:
2206 UsdStagePtr _stage;
2207 std::unique_ptr<_PendingChanges> _localPendingChanges;
2208 };
2209
2210 // The 'pseudo root' prim.
2211 Usd_PrimDataPtr _pseudoRoot;
2212
2213 // The stage's root layer.
2214 SdfLayerRefPtr _rootLayer;
2215
2216 // Every UsdStage has an implicit, in-memory session layer.
2217 // This is to allow for runtime overrides such as variant selections.
2218 SdfLayerRefPtr _sessionLayer;
2219
2220 // The stage's EditTarget.
2221 UsdEditTarget _editTarget;
2222 bool _editTargetIsLocalLayer;
2223
2224 std::unique_ptr<PcpCache> _cache;
2225 std::unique_ptr<Usd_ClipCache> _clipCache;
2226 std::unique_ptr<Usd_InstanceCache> _instanceCache;
2227
2228 TfHashMap<TfToken, TfToken, TfHash> _invalidPrimTypeToFallbackMap;
2229
2230 size_t _usedLayersRevision;
2231
2232 // A concurrent map from Path to Prim, for fast random access.
2233 struct _TbbHashEq {
2234 inline bool equal(SdfPath const &l, SdfPath const &r) const {
2235 return l == r;
2236 }
2237 inline size_t hash(SdfPath const &path) const {
2238 return path.GetHash();
2239 }
2240 };
2241 using PathToNodeMap = tbb::concurrent_hash_map<
2242 SdfPath, Usd_PrimDataIPtr, _TbbHashEq>;
2243 PathToNodeMap _primMap;
2244
2245 // The interpolation type used for all attributes on the stage.
2246 UsdInterpolationType _interpolationType;
2247
2248 typedef std::vector<
2249 std::pair<SdfLayerHandle, TfNotice::Key> > _LayerAndNoticeKeyVec;
2250 _LayerAndNoticeKeyVec _layersAndNoticeKeys;
2251 size_t _lastChangeSerialNumber;
2252
2253 TfNotice::Key _resolverChangeKey;
2254
2255 // Data for pending change processing.
2256 _PendingChanges* _pendingChanges;
2257
2258 std::optional<WorkDispatcher> _dispatcher;
2259
2260 // To provide useful aggregation of malloc stats, we bill everything
2261 // for this stage - from all access points - to this tag.
2262 std::unique_ptr<std::string> _mallocTagID;
2263
2264 // The state used when instantiating the stage.
2265 const InitialLoadSet _initialLoadSet;
2266
2267 // The population mask that applies to this stage.
2268 UsdStagePopulationMask _populationMask;
2269
2270 // The load rules that apply to this stage.
2271 UsdStageLoadRules _loadRules;
2272
2273 bool _isClosingStage;
2274 bool _isWritingFallbackPrimTypes;
2275
2276 friend class UsdAPISchemaBase;
2277 friend class UsdAttribute;
2278 friend class UsdAttributeQuery;
2279 friend class UsdEditTarget;
2280 friend class UsdInherits;
2281 friend class UsdNamespaceEditor;
2282 friend class UsdObject;
2283 friend class UsdPrim;
2284 friend class UsdProperty;
2285 friend class UsdRelationship;
2286 friend class UsdSpecializes;
2287 friend class UsdVariantSet;
2288 friend class UsdVariantSets;
2289 friend class Usd_AssetPathContext;
2290 friend class Usd_FlattenAccess;
2291 friend class Usd_PcpCacheAccess;
2292 friend class Usd_PrimData;
2293 friend class Usd_StageOpenRequest;
2294 friend class Usd_TypeQueryAccess;
2295 template <class T> friend struct Usd_AttrGetValueHelper;
2296 friend struct Usd_AttrGetUntypedValueHelper;
2297 template <class RefsOrPayloadsEditorType, class RefsOrPayloadsProxyType>
2298 friend struct Usd_ListEditImpl;
2299};
2300
2301template<typename T>
2302bool
2303UsdStage::GetMetadata(const TfToken& key, T* value) const
2304{
2305 VtValue result;
2306 if (!GetMetadata(key, &result)){
2307 return false;
2308 }
2309
2310 if (result.IsHolding<T>()){
2311 *value = result.UncheckedGet<T>();
2312 return true;
2313 } else {
2314 TF_CODING_ERROR("Requested type %s for stage metadatum %s does not"
2315 " match retrieved type %s",
2316 ArchGetDemangled<T>().c_str(),
2317 key.GetText(),
2318 result.GetTypeName().c_str());
2319 return false;
2320 }
2321}
2322
2323template<typename T>
2324bool
2326 T* value) const
2327{
2328 VtValue result;
2329 if (!GetMetadataByDictKey(key, keyPath, &result)){
2330 return false;
2331 }
2332
2333 if (result.IsHolding<T>()){
2334 *value = result.UncheckedGet<T>();
2335 return true;
2336 } else {
2337 TF_CODING_ERROR("Requested type %s for stage metadatum %s[%s] does not"
2338 " match retrieved type %s",
2339 ArchGetDemangled<T>().c_str(),
2340 key.GetText(),
2341 keyPath.GetText(),
2342 result.GetTypeName().c_str());
2343 return false;
2344 }
2345}
2346
2347PXR_NAMESPACE_CLOSE_SCOPE
2348
2349#endif //PXR_USD_USD_STAGE_H
2350
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:493
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:428
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
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:281
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
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:135
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:654
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:149
@ LoadAll
Load all loadable prims.
Definition: stage.h:150
@ LoadNone
Load no loadable prims.
Definition: stage.h:151
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:2325
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:2303
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:637
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
std::map< double, VtValue > SdfTimeSampleMap
A map from sample times to sample values.
Definition: types.h:280