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
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
1631 _GetSchemaAttribute(const UsdAttribute &attr) const;
1632
1634 _GetSchemaRelationship(const UsdRelationship &rel) const;
1635
1636 SdfAttributeSpecHandle
1637 _CreateNewSpecFromSchemaAttribute(
1638 const UsdPrim &prim,
1639 const UsdPrimDefinition::Attribute &attrDef);
1640
1641 SdfRelationshipSpecHandle
1642 _CreateNewSpecFromSchemaRelationship(
1643 const UsdPrim &prim,
1644 const UsdPrimDefinition::Relationship &relDef);
1645
1646 template <class PropType>
1648 _CreateNewPropertySpecFromSchema(const UsdProperty &prop);
1649
1650 SdfPrimSpecHandle
1651 _CreatePrimSpecForEditing(const UsdPrim& prim);
1652
1653 template <class PropType>
1655 _CreatePropertySpecForEditing(const UsdProperty &prop);
1656
1657 SdfPropertySpecHandle
1658 _CreatePropertySpecForEditing(const UsdProperty &prop);
1659
1660 SdfAttributeSpecHandle
1661 _CreateAttributeSpecForEditing(const UsdAttribute &attr);
1662
1663 SdfRelationshipSpecHandle
1664 _CreateRelationshipSpecForEditing(const UsdRelationship &rel);
1665
1666 // Check if the given path is valid to use with the prim creation API,
1667 // like DefinePrim. If it is valid, returns (true, GetPrimAtPath(path)).
1668 // Otherwise, returns (false, UsdPrim()).
1669 std::pair<bool, UsdPrim>
1670 _IsValidPathForCreatingPrim(const SdfPath &path) const;
1671
1672 // Validates that editing a specified prim is allowed. If editing is not
1673 // allowed, issues a coding error like "Cannot <operation> ..." and
1674 // returns false. Otherwise, returns true.
1675 bool _ValidateEditPrim(const UsdPrim &prim, const char* operation) const;
1676 bool _ValidateEditPrimAtPath(const SdfPath &primPath,
1677 const char* operation) const;
1678
1679 UsdPrim _DefinePrim(const SdfPath &path, const TfToken &typeName);
1680
1681 bool _RemoveProperty(const SdfPath& path);
1682
1683 UsdProperty _FlattenProperty(const UsdProperty &srcProp,
1684 const UsdPrim &dstParent,
1685 const TfToken &dstName);
1686
1687 // --------------------------------------------------------------------- //
1688 // Value & Metadata Authoring
1689 // --------------------------------------------------------------------- //
1690
1691 // Set value for dynamically typed VtValueRef. Will map the value across
1692 // edit targets if the held value type supports it.
1693 bool _SetValue(
1694 UsdTimeCode time, const UsdAttribute &attr, VtValueRef newValue);
1695
1696 TfToken _GetAttributeValueTypeNameToken(const UsdAttribute &attr) const;
1697 SdfValueTypeName _GetAttributeValueTypeName(const UsdAttribute &attr) const;
1698 TfType _GetAttributeValueType(const UsdAttribute &attr) const;
1699
1700 bool _ClearValue(UsdTimeCode time, const UsdAttribute &attr);
1701
1702 // Set metadata for dynamically typed VtValueRef. Will map the value across
1703 // edit targets if the value type supports it.
1704 USD_API
1705 bool _SetMetadata(const UsdObject &object,
1706 const TfToken& key,
1707 const TfToken &keyPath,
1708 VtValueRef value);
1709
1710 bool _ClearMetadata(const UsdObject &obj, const TfToken& fieldName,
1711 const TfToken &keyPath=TfToken());
1712
1713 // --------------------------------------------------------------------- //
1714 // Misc Internal Helpers
1715 // --------------------------------------------------------------------- //
1716
1717 // Pcp helpers.
1718 PcpCache const *_GetPcpCache() const { return _cache.get(); }
1719 PcpCache *_GetPcpCache() { return _cache.get(); }
1720
1721 // Returns the PrimIndex, using the read-only PcpCache API. We expect prims
1722 // to be composed during initial stage composition, so this method should
1723 // not be used in that context.
1724 const PcpPrimIndex* _GetPcpPrimIndex(const SdfPath& primPath) const;
1725
1726 // Helper to report pcp errors.
1727 void _ReportPcpErrors(const PcpErrorVector &errors,
1728 const std::string &context) const;
1729 void _ReportErrors(const PcpErrorVector &errors,
1730 const std::vector<std::string>& otherErrors,
1731 const std::string &context) const;
1732
1733 // --------------------------------------------------------------------- //
1734 // Scenegraph Composition & Change Processing
1735 // --------------------------------------------------------------------- //
1736
1737 // Compose the prim indexes in the subtrees rooted at the paths in
1738 // \p primIndexPaths. If \p instanceChanges is given, returns
1739 // changes to prototypes and instances due to the discovery of new instances
1740 // during composition.
1741 void _ComposePrimIndexesInParallel(
1742 const std::vector<SdfPath>& primIndexPaths,
1743 const std::string& context,
1744 Usd_InstanceChanges* instanceChanges = nullptr);
1745
1746 // Recompose the subtree rooted at \p prim: compose its type, flags, and
1747 // list of children, then invoke _ComposeSubtree on all its children.
1748 void _ComposeSubtree(
1749 Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1750 UsdStagePopulationMask const *mask,
1751 const SdfPath &primIndexPath = SdfPath());
1752 void _ComposeSubtreeImpl(
1753 Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1754 UsdStagePopulationMask const *mask,
1755 const SdfPath &primIndexPath = SdfPath());
1756 void _ComposeSubtreesInParallel(
1757 const std::vector<Usd_PrimDataPtr> &prims,
1758 const std::vector<SdfPath> *primIndexPaths = nullptr);
1759
1760 // Composes the full prim type info for the prim based on its type name
1761 // and applied API schemas.
1762 void _ComposePrimTypeInfoImpl(Usd_PrimDataPtr prim);
1763
1764 // Compose subtree rooted at \p prim under \p parent. This function
1765 // ensures that the appropriate prim index is specified for \p prim if
1766 // \p parent is in a prototype.
1767 void _ComposeChildSubtree(Usd_PrimDataPtr prim,
1768 Usd_PrimDataConstPtr parent,
1769 UsdStagePopulationMask const *mask);
1770
1771 // Compose \p prim's list of children and make any modifications necessary
1772 // to its _children member and the stage's _primMap, including possibly
1773 // instantiating new prims, or destroying existing subtrees of prims. The
1774 // any newly created prims *do not* have their prim index, type, flags, or
1775 // children composed.
1776 //
1777 // Compose only \p prim's direct children if recurse=false. Otherwise
1778 // recompose every descendent of \p prim. Callers that pass recurse=false
1779 // should invoke _ComposeSubtree on any newly created prims to ensure caches
1780 // are correctly populated.
1781 void _ComposeChildren(Usd_PrimDataPtr prim,
1782 UsdStagePopulationMask const *mask, bool recurse);
1783
1784 // Instantiate a prim instance. There must not already be an instance
1785 // at \p primPath.
1786 Usd_PrimDataPtr _InstantiatePrim(const SdfPath &primPath);
1787
1788 // Instantiate a prototype prim and sets its parent to pseudoroot.
1789 // There must not already be a prototype at \p primPath.
1790 Usd_PrimDataPtr _InstantiatePrototypePrim(const SdfPath &primPath);
1791
1792 // For \p prim and all of its descendants, remove from _primMap and empty
1793 // their _children vectors.
1794 void _DestroyPrim(Usd_PrimDataPtr prim);
1795
1796 // Destroy the prim subtrees rooted at each path in \p paths. \p paths may
1797 // not contain any path that is a descendent of another path in \p paths.
1798 void _DestroyPrimsInParallel(const std::vector<SdfPath>& paths);
1799
1800 // Invoke _DestroyPrim() on all of \p prim's direct children.
1801 void _DestroyDescendents(Usd_PrimDataPtr prim);
1802
1803 // Returns true if the object at the given path is a descendant of
1804 // an instance prim, i.e. a prim beneath an instance prim, or a property
1805 // of a prim beneath an instance prim.
1806 bool _IsObjectDescendantOfInstance(const SdfPath& path) const;
1807
1808 // If the given prim is an instance, returns the corresponding
1809 // prototype prim. Otherwise, returns an invalid prim.
1810 Usd_PrimDataConstPtr _GetPrototypeForInstance(Usd_PrimDataConstPtr p) const;
1811
1812 // Returns the path of the Usd prim using the prim index at the given path.
1813 SdfPath _GetPrimPathUsingPrimIndexAtPath(const SdfPath& primIndexPath) const;
1814
1815 // Responds to LayersDidChangeSentPerLayer event and update stage contents
1816 // in response to changes in scene description.
1817 void _HandleLayersDidChange(const SdfNotice::LayersDidChangeSentPerLayer &);
1818
1819 // Pushes changes through PCP to determine invalidation based on
1820 // composition metadata.
1821 // Note: This method will not perform any processing or notification
1822 // Refer to _ProcessPendingChanges()
1823 void _ComputePendingChanges(const SdfLayerChangeListVec &);
1824
1825 // Update stage contents in response to changes to the asset resolver.
1826 void _HandleResolverDidChange(const ArNotice::ResolverChanged &);
1827
1828 // Process stage change information stored in _pendingChanges.
1829 // _pendingChanges will be set to nullptr by the end of the function.
1830 // This function will return true if UsdNotice::ObjectsChanged and
1831 // UsdNotice::StageContentsChanged notices were sent during execution.
1832 bool _ProcessPendingChanges();
1833
1834 // Remove scene description for the prim at \p fullPath in the current edit
1835 // target.
1836 bool _RemovePrim(const SdfPath& fullPath);
1837
1838 SdfPrimSpecHandle _GetPrimSpec(const SdfPath& fullPath);
1839
1840 // Find and return the defining spec type for the property spec at the given
1841 // path, or SdfSpecTypeUnknown if none exists. The defining spec type is
1842 // either the builtin definition's spec type, if the indicated property is
1843 // builtin, otherwise it's the strongest authored spec's type if one exists,
1844 // otherwise it's SdfSpecTypeUnknown.
1845 SdfSpecType _GetDefiningSpecType(Usd_PrimDataConstPtr primData,
1846 const TfToken &propName) const;
1847
1848 // Helper to apply Pcp changes and recompose the scenegraph accordingly,
1849 // given an optional initial set of paths to recompose.
1850 void _Recompose(const PcpChanges &changes);
1851 template <class T>
1852 void _Recompose(const PcpChanges &changes, T *pathsToRecompose);
1853 template <class T>
1854 void _RecomposePrims(T *pathsToRecompose);
1855
1856 // Helper for _Recompose to find the subtrees that need to be
1857 // fully recomposed and to recompose the name children of the
1858 // parents of these subtrees. Note that [start, finish) must be a
1859 // sorted range of map iterators whose keys are paths with no descendent
1860 // paths. In C++20, consider using the ranges API to improve this.
1861 template <class Iter>
1862 void _ComputeSubtreesToRecompose(Iter start, Iter finish,
1863 std::vector<Usd_PrimDataPtr>* recompose);
1864
1865 // return true if the path is valid for load/unload operations.
1866 // This method will emit errors when invalid paths are encountered.
1867 bool _IsValidForLoad(const SdfPath& path) const;
1868 bool _IsValidForUnload(const SdfPath& path) const;
1869
1870 // Discover all payloads in a given subtree, adding the path of each
1871 // discovered prim index to the \p primIndexPaths set. If specified,
1872 // the corresponding UsdPrim path will be added to the \p usdPrimPaths
1873 // set. The root path will be considered for inclusion in the result set.
1874 //
1875 // Note that some payloads may not be discoverable in until an ancestral
1876 // payload has been included. UsdStage::LoadAndUnload takes this into
1877 // account.
1878 void _DiscoverPayloads(const SdfPath& rootPath,
1879 UsdLoadPolicy policy,
1880 SdfPathSet* primIndexPaths,
1881 bool unloadedOnly = false,
1882 SdfPathSet* usdPrimPaths = nullptr) const;
1883
1884 // ===================================================================== //
1885 // VALUE RESOLUTION //
1886 // ===================================================================== //
1887 // --------------------------------------------------------------------- //
1888 // Specialized Value Resolution
1889 // --------------------------------------------------------------------- //
1890
1891 // Helpers for resolving values for metadata fields requiring
1892 // special behaviors.
1893 static SdfSpecifier _GetSpecifier(Usd_PrimDataConstPtr primData);
1894 static TfToken _GetKind(Usd_PrimDataConstPtr primData);
1895 static bool _IsActive(Usd_PrimDataConstPtr primData);
1896
1897 // Custom is true if it is true anywhere in the stack.
1898 bool _IsCustom(const UsdProperty &prop) const;
1899
1900 // Variability is determined by the weakest opinion in the stack.
1901 SdfVariability _GetVariability(const UsdProperty &prop) const;
1902
1903 // Helper functions for resolving asset paths during value resolution.
1904 void _MakeResolvedAssetPaths(UsdTimeCode time, const UsdAttribute &attr,
1905 SdfAssetPath *assetPaths,
1906 size_t numAssetPaths,
1907 bool anchorAssetPathsOnly = false) const;
1908
1909 void _MakeResolvedAssetPathsValue(UsdTimeCode time, const UsdAttribute &attr,
1910 VtValue *value,
1911 bool anchorAssetPathsOnly = false) const;
1912
1913 void _MakeResolvedTimeCodes(UsdTimeCode time, const UsdAttribute &attr,
1914 SdfTimeCode *timeCodes,
1915 size_t numTimeCodes) const;
1916
1917 void _MakeResolvedPathExpressions(
1918 UsdTimeCode time, const UsdAttribute &attr,
1919 SdfPathExpression *pathExprs,
1920 size_t numPathExprs) const;
1921
1922 void _MakeResolvedAttributeValue(UsdTimeCode time, const UsdAttribute &attr,
1923 VtValue *value) const;
1924
1925 // --------------------------------------------------------------------- //
1926 // Metadata Resolution
1927 // --------------------------------------------------------------------- //
1928
1929public:
1930 // Trait that allows us to call the correct version of _GetMetadata for
1931 // types that require type specific value resolution as opposed to just
1932 // strongest opinion. These types also use type specific resolution
1933 // in _GetValue.
1934 template <class T>
1935 struct _HasTypeSpecificResolution {
1936 static const bool value =
1937 std::is_same<T, SdfAssetPath>::value ||
1938 std::is_same<T, VtArray<SdfAssetPath>>::value ||
1939 std::is_same<T, SdfTimeCode>::value ||
1940 std::is_same<T, VtArray<SdfTimeCode>>::value ||
1941 std::is_same<T, SdfPathExpression>::value ||
1942 std::is_same<T, VtArray<SdfPathExpression>>::value ||
1943 std::is_same<T, SdfTimeSampleMap>::value ||
1944 std::is_same<T, TsSpline>::value ||
1945 std::is_same<T, VtDictionary>::value;
1946 };
1947
1948private:
1949 // Get metadata as a dynamically typed VtValue. Will perform type specific
1950 // value resolution if the returned held type requires it.
1951 USD_API
1952 bool _GetMetadata(const UsdObject &obj,
1953 const TfToken& fieldName,
1954 const TfToken &keyPath,
1955 bool useFallbacks,
1956 VtValue* result) const;
1957
1958 USD_API
1959 bool _GetMetadata(const UsdObject &obj,
1960 const TfToken& fieldName,
1961 const TfToken &keyPath,
1962 bool useFallbacks,
1963 SdfAbstractDataValue *result,
1964 bool strongestOnly) const;
1965
1966 template <class T>
1967 bool _GetMetadata(const UsdObject &obj,
1968 const TfToken& fieldName,
1969 const TfToken &keyPath,
1970 bool useFallbacks,
1971 T* result) const {
1972 SdfAbstractDataTypedValue<T> out(result);
1973 const bool strongestOnly =
1976 return _GetMetadata(obj, fieldName, keyPath, useFallbacks, &out,
1977 strongestOnly);
1978 }
1979
1980 template <class Composer>
1981 void _GetAttrTypeImpl(const UsdAttribute &attr,
1982 const TfToken &fieldName,
1983 bool useFallbacks,
1984 Composer *composer) const;
1985
1986 template <class Composer>
1987 void _GetAttrVariabilityImpl(const UsdAttribute &attr,
1988 bool useFallbacks,
1989 Composer *composer) const;
1990
1991 template <class Composer>
1992 void _GetPropCustomImpl(const UsdProperty &prop,
1993 bool useFallbacks,
1994 Composer *composer) const;
1995
1996 template <class Composer>
1997 bool _GetSpecialPropMetadataImpl(const UsdObject &obj,
1998 const TfToken &fieldName,
1999 const TfToken &keyPath,
2000 bool useFallbacks,
2001 Composer *composer) const;
2002 template <class Composer>
2003 bool _GetMetadataImpl(const UsdObject &obj,
2004 const TfToken& fieldName,
2005 const TfToken& keyPath,
2006 bool includeFallbacks,
2007 Composer *composer) const;
2008
2009 template <class Composer>
2010 bool _GetGeneralMetadataImpl(const UsdObject &obj,
2011 const TfToken& fieldName,
2012 const TfToken& keyPath,
2013 bool includeFallbacks,
2014 Composer *composer) const;
2015
2016 // NOTE: The "authoredOnly" flag is not yet in use, but when we have
2017 // support for prim-based metadata fallbacks, they should be ignored when
2018 // this flag is set to true.
2019 bool _HasMetadata(const UsdObject &obj, const TfToken& fieldName,
2020 const TfToken &keyPath, bool useFallbacks) const;
2021
2023 _ListMetadataFields(const UsdObject &obj, bool useFallbacks) const;
2024
2025 void _GetAllMetadata(const UsdObject &obj,
2026 bool useFallbacks,
2027 UsdMetadataValueMap* result,
2028 bool anchorAssetPathsOnly = false) const;
2029
2030 // --------------------------------------------------------------------- //
2031 // Default & TimeSample Resolution
2032 // --------------------------------------------------------------------- //
2033
2034 void _GetResolveInfo(const UsdAttribute &attr,
2035 UsdResolveInfo *resolveInfo,
2036 const UsdTimeCode *time = nullptr) const;
2037
2038 void _GetResolveInfoWithResolveTarget(
2039 const UsdAttribute &attr,
2040 const UsdResolveTarget &resolveTarget,
2041 UsdResolveInfo *resolveInfo,
2042 const UsdTimeCode *time = nullptr) const;
2043
2044 template <class T> struct _ExtraResolveInfo;
2045
2046 // Gets the value resolve info for the given attribute. If time is provided,
2047 // the resolve info is evaluated for that specific time (which may be
2048 // default). Otherwise, if time is null, the resolve info is evaluated for
2049 // "any numeric time" and will not populate values in extraInfo that
2050 // require a specific time to be evaluated.
2051 template <class T>
2052 void _GetResolveInfo(const UsdAttribute &attr,
2053 UsdResolveInfo *resolveInfo,
2054 const UsdTimeCode *time = nullptr,
2055 _ExtraResolveInfo<T> *extraInfo = nullptr) const;
2056
2057 // Gets the value resolve info for the given attribute using the given
2058 // resolve target. If time is provided, the resolve info is evaluated for
2059 // that specific time (which may be default). Otherwise, if time is null,
2060 // the resolve info is evaluated for "any numeric time" and will not
2061 // populate values in extraInfo that require a specific time to be
2062 // evaluated.
2063 template <class T>
2064 void _GetResolveInfoWithResolveTarget(
2065 const UsdAttribute &attr,
2066 const UsdResolveTarget &resolveTarget,
2067 UsdResolveInfo *resolveInfo,
2068 const UsdTimeCode *time = nullptr,
2069 _ExtraResolveInfo<T> *extraInfo = nullptr) const;
2070
2071 // Shared implementation function for _GetResolveInfo and
2072 // _GetResolveInfoWithResolveTarget. The only difference between how these
2073 // two functions behave is in how they create the Usd_Resolver used for
2074 // iterating over nodes and layers, thus they provide this implementation
2075 // with the needed MakeUsdResolverFn to create the Usd_Resolver.
2076 template <class T, class MakeUsdResolverFn>
2077 void _GetResolveInfoImpl(const UsdAttribute &attr,
2078 UsdResolveInfo *resolveInfo,
2079 const UsdTimeCode *time,
2080 _ExtraResolveInfo<T> *extraInfo,
2081 const MakeUsdResolverFn &makeUsdResolveFn) const;
2082
2083 template <class T> struct _ResolveInfoResolver;
2084 struct _PropertyStackResolver;
2085
2086 template <class Resolver, class MakeUsdResolverFn>
2087 void _GetResolvedValueAtDefaultImpl(
2088 const UsdProperty &prop,
2089 Resolver *resolver,
2090 const MakeUsdResolverFn &makeUsdResolverFn) const;
2091
2092 template <class Resolver, class MakeUsdResolverFn>
2093 void _GetResolvedValueAtTimeImpl(
2094 const UsdProperty &prop,
2095 Resolver *resolver,
2096 const UsdTimeCode *time,
2097 const MakeUsdResolverFn &makeUsdResolverFn) const;
2098
2099 bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2100 VtValue* result) const;
2101
2102 template <class T>
2103 bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2104 T* result) const;
2105
2106 template <class T>
2107 bool _GetValueImpl(UsdTimeCode time, const UsdAttribute &attr,
2108 Usd_InterpolatorBase* interpolator,
2109 T* value) const;
2110
2111 USD_API
2112 bool _GetValueFromResolveInfo(const UsdResolveInfo &info,
2113 UsdTimeCode time, const UsdAttribute &attr,
2114 VtValue* result) const;
2115
2116 template <class T>
2117 USD_API
2118 bool _GetValueFromResolveInfo(const UsdResolveInfo &info,
2119 UsdTimeCode time, const UsdAttribute &attr,
2120 T* result) const;
2121
2122 template <class T>
2123 bool _GetValueFromResolveInfoImpl(const UsdResolveInfo &info,
2124 UsdTimeCode time, const UsdAttribute &attr,
2125 Usd_InterpolatorBase* interpolator,
2126 T* value) const;
2127
2128 template <class T>
2129 bool _GetDefaultValueFromResolveInfoImpl(const UsdResolveInfo &info,
2130 const UsdAttribute &attr,
2131 T* value) const;
2132
2133 Usd_AssetPathContext
2134 _GetAssetPathContext(UsdTimeCode time, const UsdAttribute &attr) const;
2135
2136 // --------------------------------------------------------------------- //
2137 // Specialized Time Sample I/O
2138 // --------------------------------------------------------------------- //
2139
2146 bool _GetTimeSamplesInInterval(const UsdAttribute &attr,
2147 const GfInterval& interval,
2148 std::vector<double>* times) const;
2149
2150 bool _GetTimeSamplesInIntervalFromResolveInfo(
2151 const UsdResolveInfo &info,
2152 const UsdAttribute &attr,
2153 const GfInterval& interval,
2154 std::vector<double>* times) const;
2155
2156 size_t _GetNumTimeSamples(const UsdAttribute &attr) const;
2157
2158 size_t _GetNumTimeSamplesFromResolveInfo(const UsdResolveInfo &info,
2159 const UsdAttribute &attr) const;
2160
2164 bool _GetBracketingTimeSamples(const UsdAttribute &attr,
2165 double desiredTime,
2166 bool authoredOnly,
2167 double* lower,
2168 double* upper,
2169 bool* hasSamples) const;
2170
2171 bool _GetBracketingTimeSamplesFromResolveInfo(const UsdResolveInfo &info,
2172 const UsdAttribute &attr,
2173 double desiredTime,
2174 bool authoredOnly,
2175 double* lower,
2176 double* upper,
2177 bool* hasSamples) const;
2178
2179 bool _ValueMightBeTimeVarying(const UsdAttribute &attr) const;
2180
2181 bool _ValueMightBeTimeVaryingFromResolveInfo(const UsdResolveInfo &info,
2182 const UsdAttribute &attr) const;
2183
2184 void _RegisterPerLayerNotices();
2185 void _RegisterResolverChangeNotice();
2186
2187 // Helper to obtain a malloc tag string for this stage.
2188 inline char const *_GetMallocTagId() const;
2189
2190private:
2191 class _PendingChanges;
2192
2193 // Change block for use by the UsdNamespaceEditor to allow it to indicate
2194 // to its dependent stages what the expected namespace edits are when the
2195 // stages handles notices from the changes the namespace editor performs.
2196 // The stage uses this provide additional information about prim resyncs
2197 // related to namespace edits in the ObjectsChanged notice it sends.
2198 class _NamespaceEditsChangeBlock {
2199 public:
2200 // Info about an expected namespace edit change from UsdNamespaceEditor.
2201 // This includes the original pre-edit prim stack of the prim at the old
2202 // path which is used to determine if the prim at the new path has the
2203 // same composed contents after the edits as the prim had originally at
2204 // the old path before the edits.
2205 struct ExpectedNamespaceEditChange {
2206 SdfPath oldPath;
2207 SdfPath newPath;
2208 SdfPrimSpecHandleVector oldPrimStack;
2209 };
2210 using ExpectedNamespaceEditChangeVector =
2211 std::vector<ExpectedNamespaceEditChange>;
2212
2213 _NamespaceEditsChangeBlock(const UsdStagePtr &stage,
2214 ExpectedNamespaceEditChangeVector &&expectedChanges);
2215 _NamespaceEditsChangeBlock(_NamespaceEditsChangeBlock &&);
2216 ~_NamespaceEditsChangeBlock();
2217
2218 private:
2219 UsdStagePtr _stage;
2220 std::unique_ptr<_PendingChanges> _localPendingChanges;
2221 };
2222
2223 // The 'pseudo root' prim.
2224 Usd_PrimDataPtr _pseudoRoot;
2225
2226 // The stage's root layer.
2227 SdfLayerRefPtr _rootLayer;
2228
2229 // Every UsdStage has an implicit, in-memory session layer.
2230 // This is to allow for runtime overrides such as variant selections.
2231 SdfLayerRefPtr _sessionLayer;
2232
2233 // The stage's EditTarget.
2234 UsdEditTarget _editTarget;
2235 bool _editTargetIsLocalLayer;
2236
2237 std::unique_ptr<PcpCache> _cache;
2238 std::unique_ptr<Usd_ClipCache> _clipCache;
2239 std::unique_ptr<Usd_InstanceCache> _instanceCache;
2240
2241 TfHashMap<TfToken, TfToken, TfHash> _invalidPrimTypeToFallbackMap;
2242
2243 size_t _usedLayersRevision;
2244
2245 // A concurrent map from Path to Prim, for fast random access.
2246 struct _TbbHashEq {
2247 inline bool equal(SdfPath const &l, SdfPath const &r) const {
2248 return l == r;
2249 }
2250 inline size_t hash(SdfPath const &path) const {
2251 return path.GetHash();
2252 }
2253 };
2254 using PathToNodeMap = tbb::concurrent_hash_map<
2255 SdfPath, Usd_PrimDataIPtr, _TbbHashEq>;
2256 PathToNodeMap _primMap;
2257
2258 // The interpolation type used for all attributes on the stage.
2259 UsdInterpolationType _interpolationType;
2260
2261 typedef std::vector<
2262 std::pair<SdfLayerHandle, TfNotice::Key> > _LayerAndNoticeKeyVec;
2263 _LayerAndNoticeKeyVec _layersAndNoticeKeys;
2264 size_t _lastChangeSerialNumber;
2265
2266 TfNotice::Key _resolverChangeKey;
2267
2268 // Data for pending change processing.
2269 _PendingChanges* _pendingChanges;
2270
2271 std::optional<WorkDispatcher> _dispatcher;
2272
2273 // To provide useful aggregation of malloc stats, we bill everything
2274 // for this stage - from all access points - to this tag.
2275 std::unique_ptr<std::string> _mallocTagID;
2276
2277 // The state used when instantiating the stage.
2278 const InitialLoadSet _initialLoadSet;
2279
2280 // The population mask that applies to this stage.
2281 UsdStagePopulationMask _populationMask;
2282
2283 // The load rules that apply to this stage.
2284 UsdStageLoadRules _loadRules;
2285
2286 bool _isClosingStage;
2287 bool _isWritingFallbackPrimTypes;
2288
2289 friend class UsdAPISchemaBase;
2290 friend class UsdAttribute;
2291 friend class UsdAttributeQuery;
2292 friend class UsdEditTarget;
2293 friend class UsdInherits;
2294 friend class UsdNamespaceEditor;
2295 friend class UsdObject;
2296 friend class UsdPrim;
2297 friend class UsdProperty;
2298 friend class UsdRelationship;
2299 friend class UsdSpecializes;
2300 friend class UsdVariantSet;
2301 friend class UsdVariantSets;
2302 friend class Usd_AssetPathContext;
2303 friend class Usd_FlattenAccess;
2304 friend class Usd_PcpCacheAccess;
2305 friend class Usd_PrimData;
2306 friend class Usd_StageOpenRequest;
2307 friend class Usd_TypeQueryAccess;
2308 template <class T> friend struct Usd_AttrGetValueHelper;
2309 friend struct Usd_AttrGetUntypedValueHelper;
2310 template <class RefsOrPayloadsEditorType, class RefsOrPayloadsProxyType>
2311 friend struct Usd_ListEditImpl;
2312};
2313
2314template<typename T>
2315bool
2316UsdStage::GetMetadata(const TfToken& key, T* value) const
2317{
2318 VtValue result;
2319 if (!GetMetadata(key, &result)){
2320 return false;
2321 }
2322
2323 if (result.IsHolding<T>()){
2324 *value = result.UncheckedGet<T>();
2325 return true;
2326 } else {
2327 TF_CODING_ERROR("Requested type %s for stage metadatum %s does not"
2328 " match retrieved type %s",
2329 ArchGetDemangled<T>().c_str(),
2330 key.GetText(),
2331 result.GetTypeName().c_str());
2332 return false;
2333 }
2334}
2335
2336template<typename T>
2337bool
2339 T* value) const
2340{
2341 VtValue result;
2342 if (!GetMetadataByDictKey(key, keyPath, &result)){
2343 return false;
2344 }
2345
2346 if (result.IsHolding<T>()){
2347 *value = result.UncheckedGet<T>();
2348 return true;
2349 } else {
2350 TF_CODING_ERROR("Requested type %s for stage metadatum %s[%s] does not"
2351 " match retrieved type %s",
2352 ArchGetDemangled<T>().c_str(),
2353 key.GetText(),
2354 keyPath.GetText(),
2355 result.GetTypeName().c_str());
2356 return false;
2357 }
2358}
2359
2360PXR_NAMESPACE_CLOSE_SCOPE
2361
2362#endif //PXR_USD_USD_STAGE_H
2363
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:99
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:2338
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:2316
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