stage.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_USD_STAGE_H
25 #define PXR_USD_USD_STAGE_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usd/api.h"
31 #include "pxr/usd/usd/common.h"
32 #include "pxr/usd/usd/editTarget.h"
34 #include "pxr/usd/usd/schemaRegistry.h"
36 #include "pxr/usd/usd/stagePopulationMask.h"
37 #include "pxr/usd/usd/primFlags.h"
38 
40 #include "pxr/base/tf/hashmap.h"
41 #include "pxr/base/tf/weakBase.h"
42 
43 #include "pxr/usd/ar/ar.h"
44 #include "pxr/usd/ar/notice.h"
46 #include "pxr/usd/sdf/notice.h"
47 #include "pxr/usd/sdf/path.h"
48 #include "pxr/usd/sdf/types.h"
49 #include "pxr/usd/pcp/cache.h"
50 #include "pxr/base/vt/value.h"
52 
53 #include <boost/optional.hpp>
54 
55 #include <tbb/concurrent_vector.h>
56 #include <tbb/concurrent_unordered_set.h>
57 #include <tbb/concurrent_hash_map.h>
58 #include <tbb/spin_rw_mutex.h>
59 
60 #include <functional>
61 #include <string>
62 #include <memory>
63 #include <unordered_map>
64 #include <utility>
65 
66 PXR_NAMESPACE_OPEN_SCOPE
67 
68 
69 class ArResolverContext;
70 class GfInterval;
72 class Usd_ClipCache;
73 class Usd_InstanceCache;
74 class Usd_InstanceChanges;
75 class Usd_InterpolatorBase;
76 class UsdResolveInfo;
77 class Usd_Resolver;
78 class UsdPrim;
79 class UsdPrimRange;
80 
81 SDF_DECLARE_HANDLES(SdfLayer);
82 
146 class UsdStage : public TfRefBase, public TfWeakBase {
147 public:
148 
149  // --------------------------------------------------------------------- //
153  // --------------------------------------------------------------------- //
154 
160  {
163  };
164 
175  //
187  USD_API
188  static UsdStageRefPtr
189  CreateNew(const std::string& identifier,
190  InitialLoadSet load = LoadAll);
192  USD_API
193  static UsdStageRefPtr
194  CreateNew(const std::string& identifier,
195  const SdfLayerHandle& sessionLayer,
196  InitialLoadSet load = LoadAll);
198  USD_API
199  static UsdStageRefPtr
200  CreateNew(const std::string& identifier,
201  const SdfLayerHandle& sessionLayer,
202  const ArResolverContext& pathResolverContext,
203  InitialLoadSet load = LoadAll);
205  USD_API
206  static UsdStageRefPtr
207  CreateNew(const std::string& identifier,
208  const ArResolverContext& pathResolverContext,
209  InitialLoadSet load = LoadAll);
210 
228  USD_API
229  static UsdStageRefPtr
232  USD_API
233  static UsdStageRefPtr
234  CreateInMemory(const std::string& identifier,
235  InitialLoadSet load = LoadAll);
237  USD_API
238  static UsdStageRefPtr
239  CreateInMemory(const std::string& identifier,
240  const ArResolverContext& pathResolverContext,
241  InitialLoadSet load = LoadAll);
243  USD_API
244  static UsdStageRefPtr
245  CreateInMemory(const std::string& identifier,
246  const SdfLayerHandle &sessionLayer,
247  InitialLoadSet load = LoadAll);
249  USD_API
250  static UsdStageRefPtr
251  CreateInMemory(const std::string& identifier,
252  const SdfLayerHandle &sessionLayer,
253  const ArResolverContext& pathResolverContext,
254  InitialLoadSet load = LoadAll);
255 
271  USD_API
272  static UsdStageRefPtr
273  Open(const std::string& filePath, InitialLoadSet load = LoadAll);
275  USD_API
276  static UsdStageRefPtr
277  Open(const std::string& filePath,
278  const ArResolverContext& pathResolverContext,
279  InitialLoadSet load = LoadAll);
280 
298  USD_API
299  static UsdStageRefPtr
300  OpenMasked(const std::string &filePath,
301  UsdStagePopulationMask const &mask,
302  InitialLoadSet load = LoadAll);
304  USD_API
305  static UsdStageRefPtr
306  OpenMasked(const std::string &filePath,
307  const ArResolverContext &pathResolverContext,
308  UsdStagePopulationMask const &mask,
309  InitialLoadSet load = LoadAll);
310 
339  USD_API
340  static UsdStageRefPtr
341  Open(const SdfLayerHandle& rootLayer,
342  InitialLoadSet load=LoadAll);
344  USD_API
345  static UsdStageRefPtr
346  Open(const SdfLayerHandle& rootLayer,
347  const SdfLayerHandle& sessionLayer,
348  InitialLoadSet load=LoadAll);
350  USD_API
351  static UsdStageRefPtr
352  Open(const SdfLayerHandle& rootLayer,
353  const ArResolverContext& pathResolverContext,
354  InitialLoadSet load=LoadAll);
356  USD_API
357  static UsdStageRefPtr
358  Open(const SdfLayerHandle& rootLayer,
359  const SdfLayerHandle& sessionLayer,
360  const ArResolverContext& pathResolverContext,
361  InitialLoadSet load=LoadAll);
362 
383  USD_API
384  static UsdStageRefPtr
385  OpenMasked(const SdfLayerHandle& rootLayer,
386  const UsdStagePopulationMask &mask,
387  InitialLoadSet load=LoadAll);
389  USD_API
390  static UsdStageRefPtr
391  OpenMasked(const SdfLayerHandle& rootLayer,
392  const SdfLayerHandle& sessionLayer,
393  const UsdStagePopulationMask &mask,
394  InitialLoadSet load=LoadAll);
396  USD_API
397  static UsdStageRefPtr
398  OpenMasked(const SdfLayerHandle& rootLayer,
399  const ArResolverContext& pathResolverContext,
400  const UsdStagePopulationMask &mask,
401  InitialLoadSet load=LoadAll);
403  USD_API
404  static UsdStageRefPtr
405  OpenMasked(const SdfLayerHandle& rootLayer,
406  const SdfLayerHandle& sessionLayer,
407  const ArResolverContext& pathResolverContext,
408  const UsdStagePopulationMask &mask,
409  InitialLoadSet load=LoadAll);
410 
411  USD_API
412  virtual ~UsdStage();
413 
431  USD_API
432  void Reload();
433 
442  USD_API
443  static bool
444  IsSupportedFile(const std::string& filePath);
445 
447 
448  // --------------------------------------------------------------------- //
457 
465  USD_API
466  void Save();
467 
475  USD_API
476  void SaveSessionLayers();
477 
479 
480  // --------------------------------------------------------------------- //
526 
528  USD_API
530 
536  USD_API
537  static void
539 
541 
542  // --------------------------------------------------------------------- //
571  // --------------------------------------------------------------------- //
572 
580  USD_API
583 
589  USD_API
590  void Unload(const SdfPath& path=SdfPath::AbsoluteRootPath());
591 
603  USD_API
604  void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet,
606 
617  USD_API
618  SdfPathSet GetLoadSet();
619 
639  USD_API
640  SdfPathSet FindLoadable(
641  const SdfPath& rootPath = SdfPath::AbsoluteRootPath());
642 
649  return _loadRules;
650  }
651 
661  USD_API
662  void SetLoadRules(UsdStageLoadRules const &rules);
663 
666  return _populationMask;
667  }
668 
670  USD_API
671  void SetPopulationMask(UsdStagePopulationMask const &mask);
672 
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 
711  USD_API
712  UsdPrim GetPseudoRoot() const;
713 
720  USD_API
721  UsdPrim GetDefaultPrim() const;
722 
730  USD_API
731  void SetDefaultPrim(const UsdPrim &prim);
732 
740  USD_API
741  void ClearDefaultPrim();
742 
750  USD_API
751  bool HasDefaultPrim() const;
752 
762  USD_API
763  UsdPrim GetPrimAtPath(const SdfPath &path) const;
764 
789  USD_API
790  UsdObject GetObjectAtPath(const SdfPath &path) const;
791 
800  USD_API
801  UsdProperty GetPropertyAtPath(const SdfPath &path) const;
802 
811  USD_API
812  UsdAttribute GetAttributeAtPath(const SdfPath &path) const;
813 
822  USD_API
823  UsdRelationship GetRelationshipAtPath(const SdfPath &path) const;
824 private:
825  // Return the primData object at \p path.
826  Usd_PrimDataConstPtr _GetPrimDataAtPath(const SdfPath &path) const;
827  Usd_PrimDataPtr _GetPrimDataAtPath(const SdfPath &path);
828 
829  // Return the primData object at \p path. If \p path indicates a prim
830  // beneath an instance, return the primData object for the corresponding
831  // prim in the instance's prototype.
832  Usd_PrimDataConstPtr
833  _GetPrimDataAtPathOrInPrototype(const SdfPath &path) const;
834 
836  std::vector<UsdPrim>
837  _GetInstancesForPrototype(const UsdPrim& prototype) const;
838 
839 public:
840 
857  USD_API
859 
864  USD_API
865  UsdPrimRange Traverse(const Usd_PrimFlagsPredicate &predicate);
866 
871  USD_API
873 
892  USD_API
893  UsdPrim OverridePrim(const SdfPath &path);
894 
918  USD_API
919  UsdPrim DefinePrim(const SdfPath &path,
920  const TfToken &typeName=TfToken());
921 
934  USD_API
935  UsdPrim CreateClassPrim(const SdfPath &rootPrimPath);
936 
958  USD_API
959  bool RemovePrim(const SdfPath& path);
960 
962 
963  // --------------------------------------------------------------------- //
967  // --------------------------------------------------------------------- //
968 
970  USD_API
971  SdfLayerHandle GetSessionLayer() const;
972 
974  USD_API
975  SdfLayerHandle GetRootLayer() const;
976 
981  USD_API
983 
993  USD_API
994  std::string
995  ResolveIdentifierToEditTarget(std::string const &identifier) const;
996 
1003  USD_API
1004  SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const;
1005 
1017  USD_API
1018  SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const;
1019 
1022  USD_API
1023  bool HasLocalLayer(const SdfLayerHandle &layer) const;
1024 
1026  USD_API
1027  const UsdEditTarget &GetEditTarget() const;
1028 
1032  USD_API
1034 
1038  USD_API
1039  UsdEditTarget GetEditTargetForLocalLayer(const SdfLayerHandle &layer);
1040 
1047  USD_API
1048  void SetEditTarget(const UsdEditTarget &editTarget);
1049 
1076  USD_API
1077  void MuteLayer(const std::string &layerIdentifier);
1078 
1081  USD_API
1082  void UnmuteLayer(const std::string &layerIdentifier);
1083 
1091  USD_API
1092  void MuteAndUnmuteLayers(const std::vector<std::string> &muteLayers,
1093  const std::vector<std::string> &unmuteLayers);
1094 
1096  USD_API
1097  const std::vector<std::string>& GetMutedLayers() const;
1098 
1103  USD_API
1104  bool IsLayerMuted(const std::string& layerIdentifier) const;
1105 
1107 
1108  // --------------------------------------------------------------------- //
1112  // --------------------------------------------------------------------- //
1113  // Future Work:
1114  // * Flatten sub-trees or individual prims
1115  // * Allow flattening of local LayerStack
1116  // * Move Flatten into a free-function to ensure it doesn't rely on
1117  // Stage internals.
1118 
1126  USD_API
1127  bool Export(const std::string &filename,
1128  bool addSourceFileComment=true,
1129  const SdfLayer::FileFormatArguments &args =
1131 
1139  USD_API
1140  bool ExportToString(std::string *result,
1141  bool addSourceFileComment=true) const;
1142 
1169  USD_API
1170  SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const;
1172 
1173 public:
1174  // --------------------------------------------------------------------- //
1182  // --------------------------------------------------------------------- //
1183 
1195  template <class T>
1196  bool GetMetadata(const TfToken &key, T *value) const;
1198  USD_API
1199  bool GetMetadata(const TfToken &key, VtValue *value) const;
1200 
1207  USD_API
1208  bool HasMetadata(const TfToken &key) const;
1209 
1218  USD_API
1219  bool HasAuthoredMetadata(const TfToken &key) const;
1220 
1229  template<typename T>
1230  bool SetMetadata(const TfToken &key, const T &value) const;
1232  USD_API
1233  bool SetMetadata(const TfToken &key, const VtValue &value) const;
1234 
1243  USD_API
1244  bool ClearMetadata(const TfToken &key) const;
1245 
1261  template<typename T>
1262  bool GetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
1263  T* value) const;
1265  USD_API
1266  bool GetMetadataByDictKey(
1267  const TfToken& key, const TfToken &keyPath, VtValue *value) const;
1268 
1279  USD_API
1280  bool HasMetadataDictKey(
1281  const TfToken& key, const TfToken &keyPath) const;
1282 
1291  USD_API
1293  const TfToken& key, const TfToken &keyPath) const;
1294 
1306  template<typename T>
1307  bool SetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
1308  const T& value) const;
1310  USD_API
1311  bool SetMetadataByDictKey(
1312  const TfToken& key, const TfToken &keyPath, const VtValue& value) const;
1313 
1325  USD_API
1327  const TfToken& key, const TfToken& keyPath) const;
1328 
1347  USD_API
1348  void WriteFallbackPrimTypes();
1349 
1351 
1352  // --------------------------------------------------------------------- //
1359  // --------------------------------------------------------------------- //
1363  USD_API
1364  double GetStartTimeCode() const;
1365 
1372  USD_API
1373  void SetStartTimeCode(double);
1374 
1378  USD_API
1379  double GetEndTimeCode() const;
1380 
1387  USD_API
1388  void SetEndTimeCode(double);
1389 
1392  USD_API
1393  bool HasAuthoredTimeCodeRange() const;
1394 
1410  USD_API
1411  double GetTimeCodesPerSecond() const;
1412 
1421  USD_API
1422  void SetTimeCodesPerSecond(double timeCodesPerSecond) const;
1423 
1433  USD_API
1434  double GetFramesPerSecond() const;
1435 
1444  USD_API
1445  void SetFramesPerSecond(double framesPerSecond) const;
1446 
1448 
1449  // --------------------------------------------------------------------- //
1495  // --------------------------------------------------------------------- //
1496 
1502  USD_API
1503  void SetColorConfiguration(const SdfAssetPath &colorConfig) const;
1504 
1509  USD_API
1511 
1516  USD_API
1517  void SetColorManagementSystem(const TfToken &cms) const;
1518 
1523  USD_API
1525 
1537  USD_API
1538  static void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration,
1539  TfToken *colorManagementSystem);
1540 
1554  USD_API
1555  static void
1556  SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration,
1557  const TfToken &colorManagementSystem);
1558 
1560 
1561  // --------------------------------------------------------------------- //
1568  // --------------------------------------------------------------------- //
1569 
1574  USD_API
1575  void SetInterpolationType(UsdInterpolationType interpolationType);
1576 
1579  USD_API
1581 
1583 
1584  // --------------------------------------------------------------------- //
1589  // --------------------------------------------------------------------- //
1590 
1592  USD_API
1593  std::vector<UsdPrim> GetPrototypes() const;
1594 
1596 
1597 private:
1598  struct _IncludePayloadsPredicate;
1599 
1600  // --------------------------------------------------------------------- //
1601  // Stage Construction & Initialization
1602  // --------------------------------------------------------------------- //
1603 
1604  UsdStage(const SdfLayerRefPtr& rootLayer,
1605  const SdfLayerRefPtr& sessionLayer,
1606  const ArResolverContext& pathResolverContext,
1607  const UsdStagePopulationMask& mask,
1608  InitialLoadSet load);
1609 
1610  // Helper for Open() overloads -- searches and publishes to bound caches.
1611  template <class... Args>
1612  static UsdStageRefPtr _OpenImpl(InitialLoadSet load, Args const &... args);
1613 
1614  // Releases resources used by this stage.
1615  void _Close();
1616 
1617  // Common ref ptr initialization, called by public, static constructors.
1618  //
1619  // This method will either return a valid refptr (if the stage is correctly
1620  // initialized) or it will return a null ref pointer, deleting the
1621  // raw stage pointer in the process.
1622  static UsdStageRefPtr
1623  _InstantiateStage(const SdfLayerRefPtr &rootLayer,
1624  const SdfLayerRefPtr &sessionLayer,
1625  const ArResolverContext &pathResolverContext,
1626  const UsdStagePopulationMask &mask,
1627  InitialLoadSet load);
1628 
1629  // --------------------------------------------------------------------- //
1630  // Spec Existence & Definition Helpers
1631  // --------------------------------------------------------------------- //
1632 
1633  SdfPropertySpecHandleVector
1634  _GetPropertyStack(const UsdProperty &prop, UsdTimeCode time) const;
1635 
1636  SdfPropertySpecHandle
1637  _GetSchemaPropertySpec(const UsdPrim &prim, const TfToken &propName) const;
1638 
1639  SdfPropertySpecHandle
1640  _GetSchemaPropertySpec(const UsdProperty &prop) const;
1641 
1642  template <class PropType>
1644  _GetSchemaPropertySpec(const UsdProperty &prop) const;
1645 
1646  SdfAttributeSpecHandle
1647  _GetSchemaAttributeSpec(const UsdAttribute &attr) const;
1648 
1649  SdfRelationshipSpecHandle
1650  _GetSchemaRelationshipSpec(const UsdRelationship &rel) const;
1651 
1652  SdfPrimSpecHandle
1653  _CreatePrimSpecForEditing(const UsdPrim& prim);
1654 
1655  template <class PropType>
1657  _CreatePropertySpecForEditing(const UsdProperty &prop);
1658 
1659  SdfPropertySpecHandle
1660  _CreatePropertySpecForEditing(const UsdProperty &prop);
1661 
1662  SdfAttributeSpecHandle
1663  _CreateAttributeSpecForEditing(const UsdAttribute &attr);
1664 
1665  SdfRelationshipSpecHandle
1666  _CreateRelationshipSpecForEditing(const UsdRelationship &rel);
1667 
1668  // Check if the given path is valid to use with the prim creation API,
1669  // like DefinePrim. If it is valid, returns (true, GetPrimAtPath(path)).
1670  // Otherwise, returns (false, UsdPrim()).
1671  std::pair<bool, UsdPrim>
1672  _IsValidPathForCreatingPrim(const SdfPath &path) const;
1673 
1674  // Validates that editing a specified prim is allowed. If editing is not
1675  // allowed, issues a coding error like "Cannot <operation> ..." and
1676  // returns false. Otherwise, returns true.
1677  bool _ValidateEditPrim(const UsdPrim &prim, const char* operation) const;
1678  bool _ValidateEditPrimAtPath(const SdfPath &primPath,
1679  const char* operation) const;
1680 
1681  UsdPrim _DefinePrim(const SdfPath &path, const TfToken &typeName);
1682 
1683  bool _RemoveProperty(const SdfPath& path);
1684 
1685  UsdProperty _FlattenProperty(const UsdProperty &srcProp,
1686  const UsdPrim &dstParent,
1687  const TfToken &dstName);
1688 
1689  // --------------------------------------------------------------------- //
1690  // Value & Metadata Authoring
1691  // --------------------------------------------------------------------- //
1692 
1693  // Trait that allows us to call the correct versions of _SetValue and
1694  // _SetMetadata for types whose values need to be mapped when written to
1695  // different edit targets.
1696  template <class T>
1697  struct _IsEditTargetMappable {
1698  static const bool value =
1699  std::is_same<T, SdfTimeCode>::value ||
1700  std::is_same<T, VtArray<SdfTimeCode>>::value ||
1701  std::is_same<T, SdfTimeSampleMap>::value ||
1702  std::is_same<T, VtDictionary>::value;
1703  };
1704 
1705  // Set value for types that don't need to be mapped for edit targets.
1706  template <class T>
1707  typename std::enable_if<!_IsEditTargetMappable<T>::value, bool>::type
1708  _SetValue(
1709  UsdTimeCode time, const UsdAttribute &attr, const T &newValue);
1710 
1711  // Set value for types that do need to be mapped for edit targets.
1712  template <class T>
1713  typename std::enable_if<_IsEditTargetMappable<T>::value, bool>::type
1714  _SetValue(
1715  UsdTimeCode time, const UsdAttribute &attr, const T &newValue);
1716 
1717  // Set value for dynamically typed VtValue. Will map the value across edit
1718  // targets if the held value type supports it.
1719  bool _SetValue(
1720  UsdTimeCode time, const UsdAttribute &attr, const VtValue &newValue);
1721 
1722  template <class T>
1723  bool _SetEditTargetMappedValue(
1724  UsdTimeCode time, const UsdAttribute &attr, const T &newValue);
1725 
1726  template <class T>
1727  bool _SetValueImpl(
1728  UsdTimeCode time, const UsdAttribute &attr, const T& value);
1729 
1730  bool _ClearValue(UsdTimeCode time, const UsdAttribute &attr);
1731 
1732  // Set metadata for types that don't need to be mapped across edit targets.
1733  template <class T>
1734  typename std::enable_if<!_IsEditTargetMappable<T>::value, bool>::type
1735  _SetMetadata(const UsdObject &object, const TfToken& key,
1736  const TfToken &keyPath, const T& value);
1737 
1738  // Set metadata for types that do need to be mapped for edit targets.
1739  template <class T>
1740  typename std::enable_if<_IsEditTargetMappable<T>::value, bool>::type
1741  _SetMetadata(const UsdObject &object, const TfToken& key,
1742  const TfToken &keyPath, const T& value);
1743 
1744  // Set metadata for dynamically typed VtValue. Will map the value across
1745  // edit targets if the held value type supports it.
1746  USD_API
1747  bool _SetMetadata(const UsdObject &object,
1748  const TfToken& key,
1749  const TfToken &keyPath,
1750  const VtValue& value);
1751 
1752  template <class T>
1753  bool _SetEditTargetMappedMetadata(
1754  const UsdObject &obj, const TfToken& fieldName,
1755  const TfToken &keyPath, const T &newValue);
1756 
1757  template <class T>
1758  bool _SetMetadataImpl(
1759  const UsdObject &obj, const TfToken& fieldName,
1760  const TfToken &keyPath, const T &value);
1761 
1762  bool _ClearMetadata(const UsdObject &obj, const TfToken& fieldName,
1763  const TfToken &keyPath=TfToken());
1764 
1765  // --------------------------------------------------------------------- //
1766  // Misc Internal Helpers
1767  // --------------------------------------------------------------------- //
1768 
1769  // Pcp helpers.
1770  PcpCache const *_GetPcpCache() const { return _cache.get(); }
1771  PcpCache *_GetPcpCache() { return _cache.get(); }
1772 
1773  // Returns the PrimIndex, using the read-only PcpCache API. We expect prims
1774  // to be composed during initial stage composition, so this method should
1775  // not be used in that context.
1776  const PcpPrimIndex* _GetPcpPrimIndex(const SdfPath& primPath) const;
1777 
1778  // Helper to report pcp errors.
1779  void _ReportPcpErrors(const PcpErrorVector &errors,
1780  const std::string &context) const;
1781  void _ReportErrors(const PcpErrorVector &errors,
1782  const std::vector<std::string>& otherErrors,
1783  const std::string &context) const;
1784 
1785  // --------------------------------------------------------------------- //
1786  // Scenegraph Composition & Change Processing
1787  // --------------------------------------------------------------------- //
1788 
1789  // Compose the prim indexes in the subtrees rooted at the paths in
1790  // \p primIndexPaths. If \p instanceChanges is given, returns
1791  // changes to prototypes and instances due to the discovery of new instances
1792  // during composition.
1793  void _ComposePrimIndexesInParallel(
1794  const std::vector<SdfPath>& primIndexPaths,
1795  const std::string& context,
1796  Usd_InstanceChanges* instanceChanges = nullptr);
1797 
1798  // Recompose the subtree rooted at \p prim: compose its type, flags, and
1799  // list of children, then invoke _ComposeSubtree on all its children.
1800  void _ComposeSubtree(
1801  Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1802  UsdStagePopulationMask const *mask,
1803  const SdfPath &primIndexPath = SdfPath());
1804  void _ComposeSubtreeImpl(
1805  Usd_PrimDataPtr prim, Usd_PrimDataConstPtr parent,
1806  UsdStagePopulationMask const *mask,
1807  const SdfPath &primIndexPath = SdfPath());
1808  void _ComposeSubtreesInParallel(
1809  const std::vector<Usd_PrimDataPtr> &prims,
1810  const std::vector<SdfPath> *primIndexPaths = nullptr);
1811 
1812  // Compose subtree rooted at \p prim under \p parent. This function
1813  // ensures that the appropriate prim index is specified for \p prim if
1814  // \p parent is in a prototype.
1815  void _ComposeChildSubtree(Usd_PrimDataPtr prim,
1816  Usd_PrimDataConstPtr parent,
1817  UsdStagePopulationMask const *mask);
1818 
1819  // Compose \p prim's list of children and make any modifications necessary
1820  // to its _children member and the stage's _primMap, including possibly
1821  // instantiating new prims, or destroying existing subtrees of prims. The
1822  // any newly created prims *do not* have their prim index, type, flags, or
1823  // children composed.
1824  //
1825  // Compose only \p prim's direct children if recurse=false. Otherwise
1826  // recompose every descendent of \p prim. Callers that pass recurse=false
1827  // should invoke _ComposeSubtree on any newly created prims to ensure caches
1828  // are correctly populated.
1829  void _ComposeChildren(Usd_PrimDataPtr prim,
1830  UsdStagePopulationMask const *mask, bool recurse);
1831 
1832  // Instantiate a prim instance. There must not already be an instance
1833  // at \p primPath.
1834  Usd_PrimDataPtr _InstantiatePrim(const SdfPath &primPath);
1835 
1836  // Instantiate a prototype prim and sets its parent to pseudoroot.
1837  // There must not already be a prototype at \p primPath.
1838  Usd_PrimDataPtr _InstantiatePrototypePrim(const SdfPath &primPath);
1839 
1840  // For \p prim and all of its descendants, remove from _primMap and empty
1841  // their _children vectors.
1842  void _DestroyPrim(Usd_PrimDataPtr prim);
1843 
1844  // Destroy the prim subtrees rooted at each path in \p paths. \p paths may
1845  // not contain any path that is a descendent of another path in \p paths.
1846  void _DestroyPrimsInParallel(const std::vector<SdfPath>& paths);
1847 
1848  // Invoke _DestroyPrim() on all of \p prim's direct children.
1849  void _DestroyDescendents(Usd_PrimDataPtr prim);
1850 
1851  // Returns true if the object at the given path is a descendant of
1852  // an instance prim, i.e. a prim beneath an instance prim, or a property
1853  // of a prim beneath an instance prim.
1854  bool _IsObjectDescendantOfInstance(const SdfPath& path) const;
1855 
1856  // If the given prim is an instance, returns the corresponding
1857  // prototype prim. Otherwise, returns an invalid prim.
1858  Usd_PrimDataConstPtr _GetPrototypeForInstance(Usd_PrimDataConstPtr p) const;
1859 
1860  // Returns the path of the Usd prim using the prim index at the given path.
1861  SdfPath _GetPrimPathUsingPrimIndexAtPath(const SdfPath& primIndexPath) const;
1862 
1863  // Update stage contents in response to changes in scene description.
1864  void _HandleLayersDidChange(const SdfNotice::LayersDidChangeSentPerLayer &);
1865 
1866  // Update stage contents in response to changes to the asset resolver.
1867  void _HandleResolverDidChange(const ArNotice::ResolverChanged &);
1868 
1869  // Process stage change information stored in _pendingChanges.
1870  // _pendingChanges will be set to nullptr by the end of the function.
1871  void _ProcessPendingChanges();
1872 
1873  // Remove scene description for the prim at \p fullPath in the current edit
1874  // target.
1875  bool _RemovePrim(const SdfPath& fullPath);
1876 
1877  SdfPrimSpecHandle _GetPrimSpec(const SdfPath& fullPath);
1878 
1879  // Find and return the defining spec type for the property spec at the given
1880  // path, or SdfSpecTypeUnknown if none exists. The defining spec type is
1881  // either the builtin definition's spec type, if the indicated property is
1882  // builtin, otherwise it's the strongest authored spec's type if one exists,
1883  // otherwise it's SdfSpecTypeUnknown.
1884  SdfSpecType _GetDefiningSpecType(Usd_PrimDataConstPtr primData,
1885  const TfToken &propName) const;
1886 
1887  // Helper to apply Pcp changes and recompose the scenegraph accordingly,
1888  // given an optional initial set of paths to recompose.
1889  void _Recompose(const PcpChanges &changes);
1890  template <class T>
1891  void _Recompose(const PcpChanges &changes, T *pathsToRecompose);
1892  template <class T>
1893  void _RecomposePrims(T *pathsToRecompose);
1894 
1895  // Helper for _Recompose to find the subtrees that need to be
1896  // fully recomposed and to recompose the name children of the
1897  // parents of these subtrees. Note that [start, finish) must be a
1898  // sorted range of paths with no descendent paths.
1899  template <class Iter>
1900  void _ComputeSubtreesToRecompose(Iter start, Iter finish,
1901  std::vector<Usd_PrimDataPtr>* recompose);
1902 
1903  // return true if the path is valid for load/unload operations.
1904  // This method will emit errors when invalid paths are encountered.
1905  bool _IsValidForLoad(const SdfPath& path) const;
1906  bool _IsValidForUnload(const SdfPath& path) const;
1907 
1908  // Discover all payloads in a given subtree, adding the path of each
1909  // discovered prim index to the \p primIndexPaths set. If specified,
1910  // the corresponding UsdPrim path will be added to the \p usdPrimPaths
1911  // set. The root path will be considered for inclusion in the result set.
1912  //
1913  // Note that some payloads may not be discoverable in until an ancestral
1914  // payload has been included. UsdStage::LoadAndUnload takes this into
1915  // account.
1916  void _DiscoverPayloads(const SdfPath& rootPath,
1917  UsdLoadPolicy policy,
1918  SdfPathSet* primIndexPaths,
1919  bool unloadedOnly = false,
1920  SdfPathSet* usdPrimPaths = nullptr) const;
1921 
1922  // ===================================================================== //
1923  // VALUE RESOLUTION //
1924  // ===================================================================== //
1925  // --------------------------------------------------------------------- //
1926  // Specialized Value Resolution
1927  // --------------------------------------------------------------------- //
1928 
1929  // Helpers for resolving values for metadata fields requiring
1930  // special behaviors.
1931  static SdfSpecifier _GetSpecifier(Usd_PrimDataConstPtr primData);
1932  static TfToken _GetKind(Usd_PrimDataConstPtr primData);
1933  static bool _IsActive(Usd_PrimDataConstPtr primData);
1934 
1935  // Custom is true if it is true anywhere in the stack.
1936  bool _IsCustom(const UsdProperty &prop) const;
1937 
1938  // Variability is determined by the weakest opinion in the stack.
1939  SdfVariability _GetVariability(const UsdProperty &prop) const;
1940 
1941  // Helper functions for resolving asset paths during value resolution.
1942  void _MakeResolvedAssetPaths(UsdTimeCode time, const UsdAttribute &attr,
1943  SdfAssetPath *assetPaths,
1944  size_t numAssetPaths,
1945  bool anchorAssetPathsOnly = false) const;
1946 
1947  void _MakeResolvedAssetPathsValue(UsdTimeCode time, const UsdAttribute &attr,
1948  VtValue *value,
1949  bool anchorAssetPathsOnly = false) const;
1950 
1951  void _MakeResolvedTimeCodes(UsdTimeCode time, const UsdAttribute &attr,
1952  SdfTimeCode *timeCodes,
1953  size_t numTimeCodes) const;
1954 
1955  void _MakeResolvedAttributeValue(UsdTimeCode time, const UsdAttribute &attr,
1956  VtValue *value) const;
1957 
1958  // --------------------------------------------------------------------- //
1959  // Metadata Resolution
1960  // --------------------------------------------------------------------- //
1961 
1962 public:
1963  // Trait that allows us to call the correct version of _GetMetadata for
1964  // types that require type specific value resolution as opposed to just
1965  // strongest opinion. These types also use type specific resolution
1966  // in _GetValue.
1967  template <class T>
1968  struct _HasTypeSpecificResolution {
1969  static const bool value =
1970  std::is_same<T, SdfAssetPath>::value ||
1971  std::is_same<T, VtArray<SdfAssetPath>>::value ||
1972  std::is_same<T, SdfTimeCode>::value ||
1973  std::is_same<T, VtArray<SdfTimeCode>>::value ||
1974  std::is_same<T, SdfTimeSampleMap>::value ||
1975  std::is_same<T, VtDictionary>::value;
1976  };
1977 
1978 private:
1979  // Get metadata for types that do not have type specific value resolution.
1980  template <class T>
1981  typename std::enable_if<!_HasTypeSpecificResolution<T>::value, bool>::type
1982  _GetMetadata(const UsdObject &obj,
1983  const TfToken& fieldName,
1984  const TfToken &keyPath,
1985  bool useFallbacks,
1986  T* result) const;
1987 
1988  // Get metadata for types that do have type specific value resolution.
1989  template <class T>
1990  typename std::enable_if<_HasTypeSpecificResolution<T>::value, bool>::type
1991  _GetMetadata(const UsdObject &obj,
1992  const TfToken& fieldName,
1993  const TfToken &keyPath,
1994  bool useFallbacks,
1995  T* result) const;
1996 
1997  // Get metadata as a dynamically typed VtValue. Will perform type specific
1998  // value resolution if the returned held type requires it.
1999  bool _GetMetadata(const UsdObject &obj,
2000  const TfToken& fieldName,
2001  const TfToken &keyPath,
2002  bool useFallbacks,
2003  VtValue* result) const;
2004 
2005  // Gets a metadata value using only strongest value resolution. It is
2006  // assumed that result is holding a value that does not require type
2007  // specific value resolution.
2008  USD_API
2009  bool _GetStrongestResolvedMetadata(const UsdObject &obj,
2010  const TfToken& fieldName,
2011  const TfToken &keyPath,
2012  bool useFallbacks,
2013  SdfAbstractDataValue* result) const;
2014 
2015  // Gets a metadata value with the type specific value resolution for the
2016  // type applied. This is only implemented for types that
2017  // _HasTypeSpecificResolution.
2018  template <class T>
2019  USD_API
2020  bool _GetTypeSpecificResolvedMetadata(const UsdObject &obj,
2021  const TfToken& fieldName,
2022  const TfToken &keyPath,
2023  bool useFallbacks,
2024  T* result) const;
2025 
2026  template <class Composer>
2027  void _GetAttrTypeImpl(const UsdAttribute &attr,
2028  const TfToken &fieldName,
2029  bool useFallbacks,
2030  Composer *composer) const;
2031 
2032  template <class Composer>
2033  void _GetAttrVariabilityImpl(const UsdAttribute &attr,
2034  bool useFallbacks,
2035  Composer *composer) const;
2036 
2037  template <class Composer>
2038  void _GetPropCustomImpl(const UsdProperty &prop,
2039  bool useFallbacks,
2040  Composer *composer) const;
2041 
2042  template <class Composer>
2043  bool _GetSpecialPropMetadataImpl(const UsdObject &obj,
2044  const TfToken &fieldName,
2045  const TfToken &keyPath,
2046  bool useFallbacks,
2047  Composer *composer) const;
2048  template <class Composer>
2049  bool _GetMetadataImpl(const UsdObject &obj,
2050  const TfToken& fieldName,
2051  const TfToken& keyPath,
2052  bool includeFallbacks,
2053  Composer *composer) const;
2054 
2055  template <class Composer>
2056  bool _GetGeneralMetadataImpl(const UsdObject &obj,
2057  const TfToken& fieldName,
2058  const TfToken& keyPath,
2059  bool includeFallbacks,
2060  Composer *composer) const;
2061 
2062  // NOTE: The "authoredOnly" flag is not yet in use, but when we have
2063  // support for prim-based metadata fallbacks, they should be ignored when
2064  // this flag is set to true.
2065  bool _HasMetadata(const UsdObject &obj, const TfToken& fieldName,
2066  const TfToken &keyPath, bool useFallbacks) const;
2067 
2069  _ListMetadataFields(const UsdObject &obj, bool useFallbacks) const;
2070 
2071  void _GetAllMetadata(const UsdObject &obj,
2072  bool useFallbacks,
2073  UsdMetadataValueMap* result,
2074  bool anchorAssetPathsOnly = false) const;
2075 
2076  // --------------------------------------------------------------------- //
2077  // Default & TimeSample Resolution
2078  // --------------------------------------------------------------------- //
2079 
2080  void _GetResolveInfo(const UsdAttribute &attr,
2081  UsdResolveInfo *resolveInfo,
2082  const UsdTimeCode *time = nullptr) const;
2083 
2084  template <class T> struct _ExtraResolveInfo;
2085 
2086  template <class T>
2087  void _GetResolveInfo(const UsdAttribute &attr,
2088  UsdResolveInfo *resolveInfo,
2089  const UsdTimeCode *time = nullptr,
2090  _ExtraResolveInfo<T> *extraInfo = nullptr) const;
2091 
2092  template <class T> struct _ResolveInfoResolver;
2093  struct _PropertyStackResolver;
2094 
2095  template <class Resolver>
2096  void _GetResolvedValueImpl(const UsdProperty &prop,
2097  Resolver *resolver,
2098  const UsdTimeCode *time = nullptr) const;
2099 
2100  bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2101  VtValue* result) const;
2102 
2103  template <class T>
2104  bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2105  T* result) const;
2106 
2107  template <class T>
2108  bool _GetValueImpl(UsdTimeCode time, const UsdAttribute &attr,
2109  Usd_InterpolatorBase* interpolator,
2110  T* value) const;
2111 
2113  _GetLayerWithStrongestValue(
2114  UsdTimeCode time, const UsdAttribute &attr) const;
2115 
2116 
2117 
2118  USD_API
2119  bool _GetValueFromResolveInfo(const UsdResolveInfo &info,
2120  UsdTimeCode time, const UsdAttribute &attr,
2121  VtValue* result) const;
2122 
2123  template <class T>
2124  USD_API
2125  bool _GetValueFromResolveInfo(const UsdResolveInfo &info,
2126  UsdTimeCode time, const UsdAttribute &attr,
2127  T* result) const;
2128 
2129  template <class T>
2130  bool _GetValueFromResolveInfoImpl(const UsdResolveInfo &info,
2131  UsdTimeCode time, const UsdAttribute &attr,
2132  Usd_InterpolatorBase* interpolator,
2133  T* value) const;
2134 
2135  // --------------------------------------------------------------------- //
2136  // Specialized Time Sample I/O
2137  // --------------------------------------------------------------------- //
2138 
2145  bool _GetTimeSamplesInInterval(const UsdAttribute &attr,
2146  const GfInterval& interval,
2147  std::vector<double>* times) const;
2148 
2149  bool _GetTimeSamplesInIntervalFromResolveInfo(
2150  const UsdResolveInfo &info,
2151  const UsdAttribute &attr,
2152  const GfInterval& interval,
2153  std::vector<double>* times) const;
2154 
2155  size_t _GetNumTimeSamples(const UsdAttribute &attr) const;
2156 
2157  size_t _GetNumTimeSamplesFromResolveInfo(const UsdResolveInfo &info,
2158  const UsdAttribute &attr) const;
2159 
2163  bool _GetBracketingTimeSamples(const UsdAttribute &attr,
2164  double desiredTime,
2165  bool authoredOnly,
2166  double* lower,
2167  double* upper,
2168  bool* hasSamples) const;
2169 
2170  bool _GetBracketingTimeSamplesFromResolveInfo(const UsdResolveInfo &info,
2171  const UsdAttribute &attr,
2172  double desiredTime,
2173  bool authoredOnly,
2174  double* lower,
2175  double* upper,
2176  bool* hasSamples) const;
2177 
2178  bool _ValueMightBeTimeVarying(const UsdAttribute &attr) const;
2179 
2180  bool _ValueMightBeTimeVaryingFromResolveInfo(const UsdResolveInfo &info,
2181  const UsdAttribute &attr) const;
2182 
2183  void _RegisterPerLayerNotices();
2184  void _RegisterResolverChangeNotice();
2185 
2186 private:
2187 
2188  // The 'pseudo root' prim.
2189  Usd_PrimDataPtr _pseudoRoot;
2190 
2191  // The stage's root layer.
2192  SdfLayerRefPtr _rootLayer;
2193 
2194  // Every UsdStage has an implicit, in-memory session layer.
2195  // This is to allow for runtime overrides such as variant selections.
2196  SdfLayerRefPtr _sessionLayer;
2197 
2198  // The stage's EditTarget.
2199  UsdEditTarget _editTarget;
2200  bool _editTargetIsLocalLayer;
2201 
2202  std::unique_ptr<PcpCache> _cache;
2203  std::unique_ptr<Usd_ClipCache> _clipCache;
2204  std::unique_ptr<Usd_InstanceCache> _instanceCache;
2205 
2206  TfHashMap<TfToken, TfToken, TfHash> _invalidPrimTypeToFallbackMap;
2207 
2208  size_t _usedLayersRevision;
2209 
2210  // A concurrent map from Path to Prim, for fast random access.
2211  struct _TbbHashEq {
2212  inline bool equal(SdfPath const &l, SdfPath const &r) const {
2213  return l == r;
2214  }
2215  inline size_t hash(SdfPath const &path) const {
2216  return path.GetHash();
2217  }
2218  };
2219  using PathToNodeMap = tbb::concurrent_hash_map<
2220  SdfPath, Usd_PrimDataIPtr, _TbbHashEq>;
2221  PathToNodeMap _primMap;
2222 
2223  // The interpolation type used for all attributes on the stage.
2224  UsdInterpolationType _interpolationType;
2225 
2226  typedef std::vector<
2227  std::pair<SdfLayerHandle, TfNotice::Key> > _LayerAndNoticeKeyVec;
2228  _LayerAndNoticeKeyVec _layersAndNoticeKeys;
2229  size_t _lastChangeSerialNumber;
2230 
2231  TfNotice::Key _resolverChangeKey;
2232 
2233  // Data for pending change processing.
2234  class _PendingChanges;
2235  _PendingChanges* _pendingChanges;
2236 
2237  boost::optional<WorkDispatcher> _dispatcher;
2238 
2239  // To provide useful aggregation of malloc stats, we bill everything
2240  // for this stage - from all access points - to this tag.
2241  char const *_mallocTagID;
2242 
2243  // The state used when instantiating the stage.
2244  const InitialLoadSet _initialLoadSet;
2245 
2246  // The population mask that applies to this stage.
2247  UsdStagePopulationMask _populationMask;
2248 
2249  // The load rules that apply to this stage.
2250  UsdStageLoadRules _loadRules;
2251 
2252  bool _isClosingStage;
2253  bool _isWritingFallbackPrimTypes;
2254 
2255  friend class UsdAPISchemaBase;
2256  friend class UsdAttribute;
2257  friend class UsdAttributeQuery;
2258  friend class UsdEditTarget;
2259  friend class UsdInherits;
2260  friend class UsdObject;
2261  friend class UsdPrim;
2262  friend class UsdProperty;
2263  friend class UsdRelationship;
2264  friend class UsdSpecializes;
2265  friend class UsdVariantSet;
2266  friend class UsdVariantSets;
2267  friend class Usd_FlattenAccess;
2268  friend class Usd_PcpCacheAccess;
2269  friend class Usd_PrimData;
2270  friend class Usd_StageOpenRequest;
2271  template <class T> friend struct Usd_AttrGetValueHelper;
2272  friend struct Usd_AttrGetUntypedValueHelper;
2273  template <class RefsOrPayloadsEditorType, class RefsOrPayloadsProxyType>
2274  friend struct Usd_ListEditImpl;
2275 };
2276 
2277 // UsdObject's typed metadata query relies on this specialization being
2278 // externally visible and exporting the primary template does not
2279 // automatically export this specialization.
2280 template <>
2281 USD_API
2282 bool
2283 UsdStage::_GetTypeSpecificResolvedMetadata(const UsdObject &obj,
2284  const TfToken& fieldName,
2285  const TfToken &keyPath,
2286  bool useFallbacks,
2287  SdfTimeSampleMap* result) const;
2288 
2289 template<typename T>
2290 bool
2291 UsdStage::GetMetadata(const TfToken& key, T* value) const
2292 {
2293  VtValue result;
2294  if (!GetMetadata(key, &result)){
2295  return false;
2296  }
2297 
2298  if (result.IsHolding<T>()){
2299  *value = result.UncheckedGet<T>();
2300  return true;
2301  } else {
2302  TF_CODING_ERROR("Requested type %s for stage metadatum %s does not"
2303  " match retrieved type %s",
2304  ArchGetDemangled<T>().c_str(),
2305  key.GetText(),
2306  result.GetTypeName().c_str());
2307  return false;
2308  }
2309 }
2310 
2311 template<typename T>
2312 bool
2313 UsdStage::SetMetadata(const TfToken& key, const T& value) const
2314 {
2315  VtValue in(value);
2316  return SetMetadata(key, in);
2317 }
2318 
2319 template<typename T>
2320 bool
2321 UsdStage::GetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
2322  T* value) const
2323 {
2324  VtValue result;
2325  if (!GetMetadataByDictKey(key, keyPath, &result)){
2326  return false;
2327  }
2328 
2329  if (result.IsHolding<T>()){
2330  *value = result.UncheckedGet<T>();
2331  return true;
2332  } else {
2333  TF_CODING_ERROR("Requested type %s for stage metadatum %s[%s] does not"
2334  " match retrieved type %s",
2335  ArchGetDemangled<T>().c_str(),
2336  key.GetText(),
2337  keyPath.GetText(),
2338  result.GetTypeName().c_str());
2339  return false;
2340  }
2341 }
2342 
2343 template<typename T>
2344 bool
2345 UsdStage::SetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
2346  const T& value) const
2347 {
2348  VtValue in(value);
2349  return SetMetadataByDictKey(key, keyPath, in);
2350 }
2351 
2352 // Get metadata for types that do not have type specific value resolution.
2353 template <class T>
2354 typename std::enable_if<
2355  !UsdStage::_HasTypeSpecificResolution<T>::value, bool>::type
2356 UsdStage::_GetMetadata(const UsdObject &obj,
2357  const TfToken& fieldName,
2358  const TfToken &keyPath,
2359  bool useFallbacks,
2360  T* result) const
2361 {
2362  // Since these types don't have type specific value resolution, we can just
2363  // get the strongest metadata value and be done.
2364  SdfAbstractDataTypedValue<T> out(result);
2365  return _GetStrongestResolvedMetadata(
2366  obj, fieldName, keyPath, useFallbacks, &out);
2367 }
2368 
2369 // Get metadata for types that do have type specific value resolution.
2370 template <class T>
2371 typename std::enable_if<
2372  UsdStage::_HasTypeSpecificResolution<T>::value, bool>::type
2373 UsdStage::_GetMetadata(const UsdObject &obj,
2374  const TfToken& fieldName,
2375  const TfToken &keyPath,
2376  bool useFallbacks,
2377  T* result) const
2378 {
2379  // Call the templated type specifice resolved metadata implementation that
2380  // will only be implemented for types that support it.
2381  return _GetTypeSpecificResolvedMetadata(
2382  obj, fieldName, keyPath, useFallbacks, result);
2383 }
2384 
2385 
2386 // Set metadata for types that don't need to be mapped across edit targets.
2387 template <class T>
2388 typename std::enable_if<!UsdStage::_IsEditTargetMappable<T>::value, bool>::type
2389 UsdStage::_SetMetadata(const UsdObject &object, const TfToken& key,
2390  const TfToken &keyPath, const T& value)
2391 {
2392  // Since we know that we don't need to map the value for edit targets,
2393  // we can just type erase the value and set the metadata as is.
2395  return _SetMetadataImpl<SdfAbstractDataConstValue>(
2396  object, key, keyPath, in);
2397 }
2398 
2399 // Set metadata for types that do need to be mapped for edit targets.
2400 template <class T>
2401 typename std::enable_if<UsdStage::_IsEditTargetMappable<T>::value, bool>::type
2402 UsdStage::_SetMetadata(const UsdObject &object, const TfToken& key,
2403  const TfToken &keyPath, const T& value)
2404 {
2405  return _SetEditTargetMappedMetadata(object, key, keyPath, value);
2406 }
2407 
2408 
2409 PXR_NAMESPACE_CLOSE_SCOPE
2410 
2411 #endif //PXR_USD_USD_STAGE_H
2412 
USD_API void ExpandPopulationMask(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...
static USD_API void SetGlobalVariantFallbacks(const PcpVariantFallbackMap &fallbacks)
Set the global variant fallback preferences used in new UsdStages.
A proxy class for applying listOp edits to the specializes list for a prim.
Definition: specializes.h:51
Handle-object returned by TfNotice::Register().
Definition: notice.h:256
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:94
Load no loadable prims.
Definition: stage.h:162
USD_API void SetStartTimeCode(double)
Sets the stage's start timeCode.
USD_API UsdPrimRange Traverse()
Traverse the active, loaded, defined, non-abstract prims on this stage depth-first.
USD_API UsdPrim GetPrimAtPath(const SdfPath &path) const
Return the UsdPrim at path, or an invalid UsdPrim if none exists.
USD_API ArResolverContext GetPathResolverContext() const
Return the path resolver context for all path resolution during composition of this stage.
static USD_API void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration, TfToken *colorManagementSystem)
Returns the global fallback values of 'colorConfiguration' and 'colorManagementSystem'.
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 SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const
Returns a single, anonymous, merged layer for this composite scene.
USD_API UsdPrim GetDefaultPrim() const
Return the root UsdPrim on this stage whose name is the root layer's defaultPrim metadata's value.
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:76
USD_API void SetLoadRules(UsdStageLoadRules const &rules)
Set the UsdStageLoadRules to govern payload inclusion on this stage.
Standard pointer typedefs.
USD_API void SetDefaultPrim(const UsdPrim &prim)
Set the default prim layer metadata in this stage's root layer.
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1077
USD_API void SetInterpolationType(UsdInterpolationType interpolationType)
Sets the interpolation type used during value resolution for all attributes on this stage.
Describes Pcp changes.
Definition: changes.h:173
bool SetMetadata(const TfToken &key, const T &value) const
Set the value of Stage metadatum key to value, if the stage's current UsdEditTarget is the root or se...
Definition: stage.h:2313
The fully-typed container for a field value in an SdfAbstractData.
Definition: abstractData.h:540
USD_API UsdObject GetObjectAtPath(const SdfPath &path) const
Return the UsdObject at path, or an invalid UsdObject if none exists.
USD_API UsdPrim OverridePrim(const SdfPath &path)
Attempt to ensure a UsdPrim at path exists on this stage.
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:394
Object for efficiently making repeated queries for attribute values.
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.
USD_API void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet, UsdLoadPolicy policy=UsdLoadWithDescendants)
Unload and load the given path sets.
USD_API SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const
Return this stage's local layers in strong-to-weak order.
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:2291
bool SetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, const T &value) const
Author value to the field identified by key and keyPath at the current EditTarget.
Definition: stage.h:2345
USD_API UsdPrim CreateClassPrim(const SdfPath &rootPrimPath)
Author an SdfPrimSpec with specifier == SdfSpecifierClass for the class at root prim path path at the...
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:85
static USD_API UsdStageRefPtr CreateInMemory(InitialLoadSet load=LoadAll)
Creates a new stage only in memory, analogous to creating an anonymous SdfLayer.
USD_API std::vector< UsdPrim > GetPrototypes() const
Returns all native instancing prototype prims.
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:93
USD_API void SetTimeCodesPerSecond(double timeCodesPerSecond) const
Sets the stage's timeCodesPerSecond value.
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,...
static USD_API bool IsSupportedFile(const std::string &filePath)
Indicates whether the specified file is supported by UsdStage.
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:146
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.
VT_API std::string GetTypeName() const
Return the type name of the held typeid.
Load a prim plus all its descendants.
Definition: common.h:118
A proxy class for applying listOp edits to the inherit paths list for a prim.
Definition: inherits.h:51
USD_API void Save()
Calls SdfLayer::Save on all dirty layers contributing to this stage except session layers and sublaye...
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(...
The base class for all API schemas.
Container for information about the source of an attribute's value, i.e.
Definition: resolveInfo.h:68
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
USD_API SdfAssetPath GetColorConfiguration() const
Returns the default color configuration used to interpret the per- attribute color-spaces in the comp...
SdfHandle is a smart ptr that calls IsDormant() on the pointed-to object as an extra expiration check...
UsdStagePopulationMask GetPopulationMask() const
Return this stage's population mask.
Definition: stage.h:665
Basic Sdf data types.
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
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 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 void UnmuteLayer(const std::string &layerIdentifier)
Unmute the layer identified by layerIdentifier if it had previously been muted.
USD_API double GetTimeCodesPerSecond() const
Returns the stage's timeCodesPerSecond value.
Value type that represents a time code.
Definition: timeCode.h:44
USD_API const std::vector< std::string > & GetMutedLayers() const
Returns a vector of all layers that have been muted on this stage.
A UsdVariantSet represents a single VariantSet in USD (e.g.
Definition: variantSets.h:56
USD_API bool HasAuthoredTimeCodeRange() const
Returns true if the stage has both start and end timeCodes authored in the session layer or the root ...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
USD_API const UsdEditTarget & GetEditTarget() const
Return the stage's EditTarget.
USD_API bool RemovePrim(const SdfPath &path)
Remove all scene description for the given path and its subtree in the current UsdEditTarget.
USD_API UsdProperty GetPropertyAtPath(const SdfPath &path) const
Return the UsdProperty at path, or an invalid UsdProperty if none exists.
USD_API double GetStartTimeCode() const
Returns the stage's start timeCode.
Base class for Usd scenegraph objects, providing common API.
Definition: object.h:130
Defines a mapping from scene graph paths to Sdf spec paths in a SdfLayer where edits should be direct...
Definition: editTarget.h:78
The fully-typed container for a field value in an SdfAbstractData.
Definition: abstractData.h:445
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.
This class represents rules that govern payload inclusion on UsdStages.
USD_API UsdPrim GetPseudoRoot() const
Return the stage's "pseudo-root" prim, whose name is defined by Usd.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:132
InitialLoadSet
Specifies the initial set of prims to load when opening a UsdStage.
Definition: stage.h:159
SdfSpecifier
An enum that identifies the possible specifiers for an SdfPrimSpec.
Definition: types.h:123
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to layer API.
Definition: layer.h:120
USD_API double GetFramesPerSecond() const
Returns the stage's framesPerSecond value.
USD_API SdfPathSet GetLoadSet()
Returns a set of all loaded paths.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
Notice sent when asset paths may resolve to a different path than before due to a change in the resol...
Definition: notice.h:65
A basic mathematical interval class.
Definition: interval.h:50
USD_API double GetEndTimeCode() const
Returns the stage's end timeCode.
USD_API SdfLayerHandle GetSessionLayer() const
Return this stage's root session layer.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
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 bool HasDefaultPrim() const
Return true if this stage's root layer has an authored opinion for the default prim layer metadata.
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
USD_API UsdPrimRange TraverseAll()
Traverse all the prims on this stage depth-first.
USD_API void SaveSessionLayers()
Calls SdfLayer::Save on all dirty session layers and sublayers of session layers contributing to this...
USD_API void SetPopulationMask(UsdStagePopulationMask const &mask)
Set this stage's population mask and recompose the stage.
SdfVariability
An enum that identifies variability types for attributes.
Definition: types.h:179
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:2321
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.
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 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 SetEndTimeCode(double)
Sets the stage's end timeCode.
UsdLoadPolicy
Controls UsdStage::Load() and UsdPrim::Load() behavior regarding whether or not descendant prims are ...
Definition: common.h:116
Contains an asset path and an optional resolved path.
Definition: assetPath.h:47
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 SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const
Return a vector of all of the layers currently consumed by this stage, as determined by the compositi...
Notice sent per-layer indicating all layers whose contents have changed within a single round of chan...
Definition: notice.h:110
Base class for UsdAttribute and UsdRelationship scenegraph objects.
Definition: property.h:55
An forward-iterable range that traverses a subtree of prims rooted at a given prim in depth-first ord...
Definition: primRange.h:118
USD_API UsdRelationship GetRelationshipAtPath(const SdfPath &path) const
Return the UsdAttribute at path, or an invalid UsdAttribute if none exists.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:91
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
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 bool ClearMetadataByDictKey(const TfToken &key, const TfToken &keyPath) const
Clear any authored value identified by key and keyPath at the current EditTarget.
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 void Reload()
Calls SdfLayer::Reload on all layers contributing to this stage, except session layers and sublayers ...
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.
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 SetFramesPerSecond(double framesPerSecond) const
Sets the stage's framesPerSecond value.
USD_API SdfPathSet FindLoadable(const SdfPath &rootPath=SdfPath::AbsoluteRootPath())
Returns an SdfPathSet of all paths that can be loaded.
USD_API void SetEditTarget(const UsdEditTarget &editTarget)
Set the stage's EditTarget.
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...
static USD_API void SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration, const TfToken &colorManagementSystem)
Sets the global fallback values of color configuration metadata which includes the 'colorConfiguratio...
USD_API void WriteFallbackPrimTypes()
Writes the fallback prim types defined in the schema registry to the stage as dictionary valued fallb...
UsdInterpolationType
Attribute value interpolation options.
Definition: interpolation.h:46
An asset resolver context allows clients to provide additional data to the resolver for use during re...
USD_API void MuteLayer(const std::string &layerIdentifier)
Mute the layer identified by layerIdentifier.
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...
UsdVariantSets represents the collection of VariantSets that are present on a UsdPrim.
Definition: variantSets.h:222
std::map< double, VtValue > SdfTimeSampleMap
A map from sample times to sample values.
Definition: types.h:296
USD_API SdfLayerHandle GetRootLayer() const
Return this stage's root layer.
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1049
UsdStageLoadRules const & GetLoadRules() const
Return the stage's current UsdStageLoadRules governing payload inclusion.
Definition: stage.h:648
static USD_API PcpVariantFallbackMap GetGlobalVariantFallbacks()
Get the global variant fallback preferences used in new UsdStages.
USD_API UsdInterpolationType GetInterpolationType() const
Returns the interpolation type used during value resolution for all attributes on this stage.
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
USD_API void ClearDefaultPrim()
Clear the default prim layer metadata in this stage's root layer.
char const * GetText() const
Return the text that this token represents.
Definition: token.h:196
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
USD_API UsdAttribute GetAttributeAtPath(const SdfPath &path) const
Return the UsdAttribute at path, or an invalid UsdAttribute if none exists.
This class represents a mask that may be applied to a UsdStage to limit the set of UsdPrim s it popul...
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap
Definition: types.h:188
USD_API void SetColorConfiguration(const SdfAssetPath &colorConfig) const
Sets the default color configuration to be used to interpret the per-attribute color-spaces in the co...
Load all loadable prims.
Definition: stage.h:161
USD_API UsdEditTarget GetEditTargetForLocalLayer(size_t i)
Return a UsdEditTarget for editing the layer at index i in the layer stack.