HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 /// \file usd/stage.h
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"
21 #include "pxr/usd/usd/primFlags.h"
22 
24 #include "pxr/base/tf/hashmap.h"
25 #include "pxr/base/tf/type.h"
26 #include "pxr/base/tf/weakBase.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"
35 #include "pxr/usd/pcp/cache.h"
36 #include "pxr/base/vt/value.h"
38 
39 #include <tbb/concurrent_hash_map.h>
40 #include <tbb/spin_rw_mutex.h>
41 
42 #include <functional>
43 #include <string>
44 #include <memory>
45 #include <optional>
46 #include <unordered_map>
47 #include <utility>
48 
50 
51 class ArResolverContext;
52 class GfInterval;
54 class TsSpline;
55 class Usd_AssetPathContext;
56 class Usd_ClipCache;
57 class Usd_InstanceCache;
58 class Usd_InstanceChanges;
59 class Usd_Interpolator;
60 class Usd_Resolver;
61 class UsdResolveInfo;
62 class UsdResolveTarget;
63 class UsdPrim;
64 class UsdPrimRange;
65 
67 
68 /// \class UsdStage
69 ///
70 /// The outermost container for scene description, which owns and presents
71 /// composed prims as a scenegraph, following the composition recipe
72 /// recursively described in its associated "root layer".
73 ///
74 /// USD derives its persistent-storage scalability by combining and reusing
75 /// simple compositions into richer aggregates using referencing and layering
76 /// with sparse overrides. Ultimately, every composition (i.e. "scene") is
77 /// identifiable by its root layer, i.e. the <tt>.usd</tt> file, and a scene
78 /// is instantiated in an application on a UsdStage that presents a composed
79 /// view of the scene's root layer. Each simple composition referenced into
80 /// a larger composition could be presented on its own UsdStage, at the same
81 /// (or not) time that it is participating in the larger composition on its
82 /// own UsdStage; all of the underlying layers will be shared by the two
83 /// stages, while each maintains its own scenegraph of composed prims.
84 ///
85 /// A UsdStage has sole ownership over the UsdPrim 's with which it is populated,
86 /// and retains \em shared ownership (with other stages and direct clients of
87 /// SdfLayer's, via the Sdf_LayerRegistry that underlies all SdfLayer creation
88 /// methods) of layers. It provides roughly five categories of API that
89 /// address different aspects of scene management:
90 ///
91 /// - \ref Usd_lifetimeManagement "Stage lifetime management" methods for
92 /// constructing and initially populating a UsdStage from an existing layer
93 /// file, or one that will be created as a result, in memory or on the
94 /// filesystem.
95 /// - \ref Usd_workingSetManagement "Load/unload working set management" methods
96 /// that allow you to specify which \ref Usd_Payloads "payloads" should be
97 /// included and excluded from the stage's composition.
98 /// - \ref Usd_variantManagement "Variant management" methods to manage
99 /// policy for which variant to use when composing prims that provide
100 /// a named variant set, but do not specify a selection.
101 /// - \ref Usd_primManagement "Prim access, creation, and mutation" methods
102 /// that allow you to find, create, or remove a prim identified by a path on
103 /// the stage. This group also provides methods for efficiently traversing the
104 /// prims on the stage.
105 /// - \ref Usd_layerManagement "Layers and EditTargets" methods provide access
106 /// to the layers in the stage's <em>root LayerStack</em> (i.e. the root layer
107 /// and all of its recursive sublayers), and the ability to set a UsdEditTarget
108 /// into which all subsequent mutations to objects associated with the stage
109 /// (e.g. prims, properties, etc) will go.
110 /// - \ref Usd_stageSerialization "Serialization" methods for "flattening" a
111 /// composition (to varying degrees), and exporting a completely flattened
112 /// view of the stage to a string or file. These methods can be very useful
113 /// for targeted asset optimization and debugging, though care should be
114 /// exercized with large scenes, as flattening defeats some of the benefits of
115 /// referenced scene description, and may produce very large results,
116 /// especially in file formats that do not support data de-duplication, like
117 /// the usda text format!
118 ///
119 /// \section Usd_SessionLayer Stage Session Layers
120 ///
121 /// Each UsdStage can possess an optional "session layer". The purpose of
122 /// a session layer is to hold ephemeral edits that modify a UsdStage's contents
123 /// or behavior in a way that is useful to the client, but should not be
124 /// considered as permanent mutations to be recorded upon export. A very
125 /// common use of session layers is to make variant selections, to pick a
126 /// specific LOD or shading variation, for example. The session layer is
127 /// also frequently used to override the visibility of geometry
128 /// and assets in the scene. A session layer, if present, contributes to a
129 /// UsdStage's identity, for purposes of stage-caching, etc.
130 ///
131 /// To edit content in a session layer, get the layer's edit target using
132 /// stage->GetEditTargetForLocalLayer(stage->GetSessionLayer()) and set that
133 /// target in the stage by calling SetEditTarget() or creating a UsdEditContext.
134 ///
135 class UsdStage : public TfRefBase, public TfWeakBase {
136 public:
137 
138  // --------------------------------------------------------------------- //
139  /// \anchor Usd_lifetimeManagement
140  /// \name Lifetime Management
141  /// @{
142  // --------------------------------------------------------------------- //
143 
144  /// \enum InitialLoadSet
145  ///
146  /// Specifies the initial set of prims to load when opening a UsdStage.
147  ///
149  {
150  LoadAll, ///< Load all loadable prims
151  LoadNone ///< Load no loadable prims
152  };
153 
154  /// Create a new stage with root layer \p identifier, destroying
155  /// potentially existing files with that identifier; it is considered an
156  /// error if an existing, open layer is present with this identifier.
157  ///
158  /// \sa SdfLayer::CreateNew()
159  ///
160  /// Invoking an overload that does not take a \p sessionLayer argument will
161  /// create a stage with an anonymous in-memory session layer. To create a
162  /// stage without a session layer, pass TfNullPtr (or None in python) as the
163  /// \p sessionLayer argument.
164  //
165  /// The initial set of prims to load on the stage can be specified
166  /// using the \p load parameter. \sa UsdStage::InitialLoadSet.
167  ///
168  /// If \p pathResolverContext is provided it will be bound when creating the
169  /// root layer at \p identifier and whenever asset path resolution is done
170  /// for this stage, regardless of what other context may be bound at that
171  /// time. Otherwise Usd will create the root layer with no context bound,
172  /// then create a context for all future asset path resolution for the stage
173  /// by calling ArResolver::CreateDefaultContextForAsset with the root
174  /// layer's repository path if the layer has one, otherwise its resolved
175  /// path.
176  USD_API
177  static UsdStageRefPtr
178  CreateNew(const std::string& identifier,
179  InitialLoadSet load = LoadAll);
180  /// \overload
181  USD_API
182  static UsdStageRefPtr
183  CreateNew(const std::string& identifier,
184  const SdfLayerHandle& sessionLayer,
185  InitialLoadSet load = LoadAll);
186  /// \overload
187  USD_API
188  static UsdStageRefPtr
189  CreateNew(const std::string& identifier,
190  const SdfLayerHandle& sessionLayer,
191  const ArResolverContext& pathResolverContext,
192  InitialLoadSet load = LoadAll);
193  /// \overload
194  USD_API
195  static UsdStageRefPtr
196  CreateNew(const std::string& identifier,
197  const ArResolverContext& pathResolverContext,
198  InitialLoadSet load = LoadAll);
199 
200  /// Creates a new stage only in memory, analogous to creating an
201  /// anonymous SdfLayer.
202  ///
203  /// If \p pathResolverContext is provided it will be bound when creating the
204  /// root layer at \p identifier and whenever asset path resolution is done
205  /// for this stage, regardless of what other context may be bound at that
206  /// time. Otherwise Usd will create the root layer with no context bound,
207  /// then create a context for all future asset path resolution for the stage
208  /// by calling ArResolver::CreateDefaultContext.
209  ///
210  /// The initial set of prims to load on the stage can be specified
211  /// using the \p load parameter. \sa UsdStage::InitialLoadSet.
212  ///
213  /// Invoking an overload that does not take a \p sessionLayer argument will
214  /// create a stage with an anonymous in-memory session layer. To create a
215  /// stage without a session layer, pass TfNullPtr (or None in python) as the
216  /// \p sessionLayer argument.
217  USD_API
218  static UsdStageRefPtr
220  /// \overload
221  USD_API
222  static UsdStageRefPtr
223  CreateInMemory(const std::string& identifier,
224  InitialLoadSet load = LoadAll);
225  /// \overload
226  USD_API
227  static UsdStageRefPtr
228  CreateInMemory(const std::string& identifier,
229  const ArResolverContext& pathResolverContext,
230  InitialLoadSet load = LoadAll);
231  /// \overload
232  USD_API
233  static UsdStageRefPtr
234  CreateInMemory(const std::string& identifier,
235  const SdfLayerHandle &sessionLayer,
236  InitialLoadSet load = LoadAll);
237  /// \overload
238  USD_API
239  static UsdStageRefPtr
240  CreateInMemory(const std::string& identifier,
241  const SdfLayerHandle &sessionLayer,
242  const ArResolverContext& pathResolverContext,
243  InitialLoadSet load = LoadAll);
244 
245  /// Attempt to find a matching existing stage in a cache if
246  /// UsdStageCacheContext objects exist on the stack. Failing that, create a
247  /// new stage and recursively compose prims defined within and referenced by
248  /// the layer at \p filePath, which must already exist.
249  ///
250  /// The initial set of prims to load on the stage can be specified
251  /// using the \p load parameter. \sa UsdStage::InitialLoadSet.
252  ///
253  /// If \p pathResolverContext is provided it will be bound when opening the
254  /// root layer at \p filePath and whenever asset path resolution is done for
255  /// this stage, regardless of what other context may be bound at that
256  /// time. Otherwise Usd will open the root layer with no context bound, then
257  /// create a context for all future asset path resolution for the stage by
258  /// calling ArResolver::CreateDefaultContextForAsset with the layer's
259  /// repository path if the layer has one, otherwise its resolved path.
260  USD_API
261  static UsdStageRefPtr
262  Open(const std::string& filePath, InitialLoadSet load = LoadAll);
263  /// \overload
264  USD_API
265  static UsdStageRefPtr
266  Open(const std::string& filePath,
267  const ArResolverContext& pathResolverContext,
268  InitialLoadSet load = LoadAll);
269 
270  /// Create a new stage and recursively compose prims defined within and
271  /// referenced by the layer at \p filePath which must already exist, subject
272  /// to \p mask.
273  ///
274  /// These OpenMasked() methods do not automatically consult or populate
275  /// UsdStageCache s.
276  ///
277  /// The initial set of prims to load on the stage can be specified
278  /// using the \p load parameter. \sa UsdStage::InitialLoadSet.
279  ///
280  /// If \p pathResolverContext is provided it will be bound when opening the
281  /// root layer at \p filePath and whenever asset path resolution is done for
282  /// this stage, regardless of what other context may be bound at that
283  /// time. Otherwise Usd will open the root layer with no context bound, then
284  /// create a context for all future asset path resolution for the stage by
285  /// calling ArResolver::CreateDefaultContextForAsset with the layer's
286  /// repository path if the layer has one, otherwise its resolved path.
287  USD_API
288  static UsdStageRefPtr
289  OpenMasked(const std::string &filePath,
291  InitialLoadSet load = LoadAll);
292  /// \overload
293  USD_API
294  static UsdStageRefPtr
295  OpenMasked(const std::string &filePath,
296  const ArResolverContext &pathResolverContext,
298  InitialLoadSet load = LoadAll);
299 
300  /// Open a stage rooted at \p rootLayer.
301  ///
302  /// Attempt to find a stage that matches the passed arguments in a
303  /// UsdStageCache if UsdStageCacheContext objects exist on the calling
304  /// stack. If a matching stage is found, return that stage. Otherwise,
305  /// create a new stage rooted at \p rootLayer.
306  ///
307  /// Invoking an overload that does not take a \p sessionLayer argument will
308  /// create a stage with an anonymous in-memory session layer. To create a
309  /// stage without a session layer, pass TfNullPtr (or None in python) as the
310  /// \p sessionLayer argument.
311  ///
312  /// The initial set of prims to load on the stage can be specified
313  /// using the \p load parameter. \sa UsdStage::InitialLoadSet.
314  ///
315  /// If \p pathResolverContext is provided it will be bound when whenever
316  /// asset path resolution is done for this stage, regardless of what other
317  /// context may be bound at that time. Otherwise Usd will create a context
318  /// for all future asset path resolution for the stage by calling
319  /// ArResolver::CreateDefaultContextForAsset with the layer's repository
320  /// path if the layer has one, otherwise its resolved path.
321  ///
322  /// When searching for a matching stage in bound UsdStageCache s, only the
323  /// provided arguments matter for cache lookup. For example, if only a root
324  /// layer (or a root layer file path) is provided, the first stage found in
325  /// any cache that has that root layer is returned. So, for example if you
326  /// require that the stage have no session layer, you must explicitly
327  /// specify TfNullPtr (or None in python) for the sessionLayer argument.
328  USD_API
329  static UsdStageRefPtr
330  Open(const SdfLayerHandle& rootLayer,
331  InitialLoadSet load=LoadAll);
332  /// \overload
333  USD_API
334  static UsdStageRefPtr
335  Open(const SdfLayerHandle& rootLayer,
336  const SdfLayerHandle& sessionLayer,
337  InitialLoadSet load=LoadAll);
338  /// \overload
339  USD_API
340  static UsdStageRefPtr
341  Open(const SdfLayerHandle& rootLayer,
342  const ArResolverContext& pathResolverContext,
343  InitialLoadSet load=LoadAll);
344  /// \overload
345  USD_API
346  static UsdStageRefPtr
347  Open(const SdfLayerHandle& rootLayer,
348  const SdfLayerHandle& sessionLayer,
349  const ArResolverContext& pathResolverContext,
350  InitialLoadSet load=LoadAll);
351 
352  /// Open a stage rooted at \p rootLayer and with limited population subject
353  /// to \p mask.
354  ///
355  /// These OpenMasked() methods do not automatically consult or populate
356  /// UsdStageCache s.
357  ///
358  /// Invoking an overload that does not take a \p sessionLayer argument will
359  /// create a stage with an anonymous in-memory session layer. To create a
360  /// stage without a session layer, pass TfNullPtr (or None in python) as the
361  /// \p sessionLayer argument.
362  ///
363  /// The initial set of prims to load on the stage can be specified
364  /// using the \p load parameter. \sa UsdStage::InitialLoadSet.
365  ///
366  /// If \p pathResolverContext is provided it will be bound when whenever
367  /// asset path resolution is done for this stage, regardless of what other
368  /// context may be bound at that time. Otherwise Usd will create a context
369  /// for all future asset path resolution for the stage by calling
370  /// ArResolver::CreateDefaultContextForAsset with the layer's repository
371  /// path if the layer has one, otherwise its resolved path.
372  USD_API
373  static UsdStageRefPtr
374  OpenMasked(const SdfLayerHandle& rootLayer,
376  InitialLoadSet load=LoadAll);
377  /// \overload
378  USD_API
379  static UsdStageRefPtr
380  OpenMasked(const SdfLayerHandle& rootLayer,
381  const SdfLayerHandle& sessionLayer,
383  InitialLoadSet load=LoadAll);
384  /// \overload
385  USD_API
386  static UsdStageRefPtr
387  OpenMasked(const SdfLayerHandle& rootLayer,
388  const ArResolverContext& pathResolverContext,
390  InitialLoadSet load=LoadAll);
391  /// \overload
392  USD_API
393  static UsdStageRefPtr
394  OpenMasked(const SdfLayerHandle& rootLayer,
395  const SdfLayerHandle& sessionLayer,
396  const ArResolverContext& pathResolverContext,
398  InitialLoadSet load=LoadAll);
399 
400  USD_API
401  virtual ~UsdStage();
402 
403  /// Calls SdfLayer::Reload on all layers contributing to this stage,
404  /// except session layers and sublayers of session layers.
405  ///
406  /// This includes non-session sublayers, references and payloads.
407  /// Note that reloading anonymous layers clears their content, so
408  /// invoking Reload() on a stage constructed via CreateInMemory()
409  /// will clear its root layer.
410  ///
411  /// \note This method is considered a mutation, which has potentially
412  /// global effect! Unlike the various Load() methods whose actions
413  /// affect only **this stage**, Reload() may cause layers to change their
414  /// contents, and because layers are global resources shared by
415  /// potentially many Stages, calling Reload() on one stage may result in
416  /// a mutation to any number of stages. In general, unless you are
417  /// highly confident your stage is the only consumer of its layers, you
418  /// should only call Reload() when you are assured no other threads may
419  /// be reading from any Stages.
420  USD_API
421  void Reload();
422 
423  /// Indicates whether the specified file is supported by UsdStage.
424  ///
425  /// This function is a cheap way to determine whether a
426  /// file might be open-able with UsdStage::Open. It is
427  /// purely based on the given \p filePath and does not
428  /// open the file or perform analysis on the contents.
429  /// As such, UsdStage::Open may still fail even if this
430  /// function returns true.
431  USD_API
432  static bool
433  IsSupportedFile(const std::string& filePath);
434 
435  /// @}
436 
437  // --------------------------------------------------------------------- //
438  /// \anchor Usd_layerSerialization
439  /// \name Layer Serialization
440  ///
441  /// Functions for saving changes to layers that contribute opinions to
442  /// this stage. Layers may also be saved by calling SdfLayer::Save or
443  /// exported to a new file by calling SdfLayer::Export.
444  ///
445  /// @{
446 
447  /// Calls SdfLayer::Save on all dirty layers contributing to this stage
448  /// except session layers and sublayers of session layers.
449  ///
450  /// This function will emit a warning and skip each dirty anonymous
451  /// layer it encounters, since anonymous layers cannot be saved with
452  /// SdfLayer::Save. These layers must be manually exported by calling
453  /// SdfLayer::Export.
454  USD_API
455  void Save();
456 
457  /// Calls SdfLayer::Save on all dirty session layers and sublayers of
458  /// session layers contributing to this stage.
459  ///
460  /// This function will emit a warning and skip each dirty anonymous
461  /// layer it encounters, since anonymous layers cannot be saved with
462  /// SdfLayer::Save. These layers must be manually exported by calling
463  /// SdfLayer::Export.
464  USD_API
465  void SaveSessionLayers();
466 
467  /// @}
468 
469  // --------------------------------------------------------------------- //
470  /// \anchor Usd_variantManagement
471  /// \name Variant Management
472  ///
473  /// These methods provide control over the policy to use when composing
474  /// prims that specify a variant set but do not specify a selection.
475  ///
476  /// The first is to declare a list of preferences in plugInfo.json
477  /// metadata on a plugin using this structure:
478  ///
479  /// \code{.json}
480  /// "UsdVariantFallbacks": { # top level key
481  /// "shadingComplexity": [ # example variant set
482  /// "full", # example fallback #1
483  /// "light" # example fallback #2
484  /// ]
485  /// },
486  /// \endcode
487  ///
488  /// This example ensures that we will get the "full" shadingComplexity
489  /// for any prim with a shadingComplexity VariantSet that doesn't
490  /// otherwise specify a selection, \em and has a "full" variant; if its
491  /// shadingComplexity does not have a "full" variant, but \em does have
492  /// a "light" variant, then the selection will be "light". In other
493  /// words, the entries in the "shadingComplexity" list in the plugInfo.json
494  /// represent a priority-ordered list of fallback selections.
495  ///
496  /// The plugin metadata is discovered and applied before the first
497  /// UsdStage is constructed in a given process. It can be defined
498  /// in any plugin. However, if multiple plugins express contrary
499  /// lists for the same named variant set, the result is undefined.
500  ///
501  /// The plugin metadata approach is useful for ensuring that sensible
502  /// default behavior applies across a pipeline without requiring
503  /// every script and binary to explicitly configure every VariantSet
504  /// that subscribes to fallback in the pipeline.
505  /// There may be times when you want to override this behavior in a
506  /// particular script -- for example, a pipeline script that knows
507  /// it wants to entirely ignore shading in order to minimize
508  /// processing time -- which motivates the second approach.
509  ///
510  /// SetGlobalVariantFallbacks() provides a way to override, for
511  /// the entire process, which fallbacks to use in subsequently
512  /// constructed UsdStage instances.
513  ///
514  /// @{
515 
516  /// Get the global variant fallback preferences used in new UsdStages.
517  USD_API
519 
520  /// Set the global variant fallback preferences used in new
521  /// UsdStages. This overrides any fallbacks configured in plugin
522  /// metadata, and only affects stages created after this call.
523  ///
524  /// \note This does not affect existing UsdStages.
525  USD_API
526  static void
528 
529  /// @}
530 
531  // --------------------------------------------------------------------- //
532  /// \anchor Usd_workingSetManagement
533  /// \name Working Set Management
534  ///
535  /// The following rules apply to all Load/Unload methods:
536  ///
537  /// - Loading an already loaded prim is legal, though may result in
538  /// some recomposition cost. Similarly, unloading an unloaded prim
539  /// is legal.
540  /// - Specifying a path that does not target a prim is legal as long it
541  /// has an ancestor present in the scene graph (other than the
542  /// absolute root). If the given path has no such ancestor, it is an
543  /// error.
544  /// - Specifying a path to an inactive prim is an error.
545  /// - Specifying a path to a prototype prim or a prim within a
546  /// prototype is an error.
547  ///
548  /// If an instance prim (or a path identifying a prim descendant to an
549  /// instance) is encountered during a Load/Unload operation, these functions
550  /// may cause instancing to change on the stage in order to ensure that no
551  /// other instances are affected. The load/unload rules that affect a given
552  /// prim hierarchy are considered when determining which prims can be
553  /// instanced together. Instance sharing occurs when different instances
554  /// have equivalent load rules.
555  ///
556  /// The GetLoadRules() and SetLoadRules() provide direct low-level access to
557  /// the UsdStageLoadRules that govern payload inclusion on a stage.
558  ///
559  /// @{
560  // --------------------------------------------------------------------- //
561 
562  /// Modify this stage's load rules to load the prim at \p path, its
563  /// ancestors, and all of its descendants if \p policy is
564  /// UsdLoadWithDescendants. If \p policy is UsdLoadWithoutDescendants, then
565  /// payloads on descendant prims are not loaded.
566  ///
567  /// See \ref Usd_workingSetManagement "Working Set Management" for more
568  /// information.
569  USD_API
572 
573  /// Modify this stage's load rules to unload the prim and its descendants
574  /// specified by \p path.
575  ///
576  /// See \ref Usd_workingSetManagement "Working Set Management" for more
577  /// information.
578  USD_API
580 
581  /// Unload and load the given path sets. The effect is as if the unload set
582  /// were processed first followed by the load set.
583  ///
584  /// This is equivalent to calling UsdStage::Unload for each item in the
585  /// unloadSet followed by UsdStage::Load for each item in the loadSet,
586  /// however this method is more efficient as all operations are committed in
587  /// a single batch. The \p policy argument is described in the
588  /// documentation for Load().
589  ///
590  /// See \ref Usd_workingSetManagement "Working Set Management" for more
591  /// information.
592  USD_API
593  void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet,
595 
596  /// Returns a set of all loaded paths.
597  ///
598  /// The paths returned are both those that have been explicitly loaded and
599  /// those that were loaded as a result of dependencies, ancestors or
600  /// descendants of explicitly loaded paths.
601  ///
602  /// This method does not return paths to inactive prims.
603  ///
604  /// See \ref Usd_workingSetManagement "Working Set Management" for more
605  /// information.
606  USD_API
608 
609  /// Returns an SdfPathSet of all paths that can be loaded.
610  ///
611  /// Note that this method does not return paths to inactive prims as they
612  /// cannot be loaded.
613  ///
614  /// The set returned includes loaded and unloaded paths. To determine the
615  /// set of unloaded paths, one can diff this set with the current load set,
616  /// for example:
617  /// \code
618  /// SdfPathSet loaded = stage->GetLoadSet(),
619  /// all = stage->FindLoadable(),
620  /// result;
621  /// std::set_difference(loaded.begin(), loaded.end(),
622  /// all.begin(), all.end(),
623  /// std::inserter(result, result.end()));
624  /// \endcode
625  ///
626  /// See \ref Usd_workingSetManagement "Working Set Management" for more
627  /// information.
628  USD_API
630  const SdfPath& rootPath = SdfPath::AbsoluteRootPath());
631 
632  /// Return the stage's current UsdStageLoadRules governing payload
633  /// inclusion.
634  ///
635  /// See \ref Usd_workingSetManagement "Working Set Management" for more
636  /// information.
638  return _loadRules;
639  }
640 
641  /// Set the UsdStageLoadRules to govern payload inclusion on this stage.
642  /// This rebuilds the stage's entire prim hierarchy to follow \p rules.
643  ///
644  /// Note that subsequent calls to Load(), Unload(), LoadAndUnload() will
645  /// modify this stages load rules as described in the documentation for
646  /// those member functions.
647  ///
648  /// See \ref Usd_workingSetManagement "Working Set Management" for more
649  /// information.
650  USD_API
651  void SetLoadRules(UsdStageLoadRules const &rules);
652 
653  /// Return this stage's population mask.
655  return _populationMask;
656  }
657 
658  /// Set this stage's population mask and recompose the stage.
659  USD_API
661 
662  /// Expand this stage's population mask to include the targets of all
663  /// relationships that pass \p relPred and connections to all attributes
664  /// that pass \p attrPred recursively. The attributes and relationships are
665  /// those on all the prims found by traversing the stage according to \p
666  /// traversalPredicate. If \p relPred is null, include all relationship
667  /// targets; if \p attrPred is null, include all connections.
668  ///
669  /// This function can be used, for example, to expand a population mask for
670  /// a given prim to include bound materials, if those bound materials are
671  /// expressed as relationships or attribute connections.
672  ///
673  /// See also UsdPrim::FindAllRelationshipTargetPaths() and
674  /// UsdPrim::FindAllAttributeConnectionPaths().
675  USD_API
677  Usd_PrimFlagsPredicate const &traversalPredicate,
678  std::function<bool (UsdRelationship const &)> const &relPred = nullptr,
679  std::function<bool (UsdAttribute const &)> const &attrPred = nullptr);
680 
681  /// \overload
682  /// This convenience overload invokes ExpandPopulationMask() with the
683  /// UsdPrimDefaultPredicate traversal predicate.
684  USD_API
686  std::function<bool (UsdRelationship const &)> const &relPred = nullptr,
687  std::function<bool (UsdAttribute const &)> const &attrPred = nullptr);
688 
689  /// @}
690 
691  // --------------------------------------------------------------------- //
692  /// \anchor Usd_primManagement
693  /// \name Prim Access, Creation and Mutation
694  /// All of the methods in this group that accept a prim path as argument
695  /// require paths in the namespace of the stage's root layer, \em regardless
696  /// of what the currently active UsdEditTarget is set to. In other words,
697  /// a UsdStage always presents a composed view of its scene, and all
698  /// prim operations are specified in the composed namespace.
699  /// @{
700  // --------------------------------------------------------------------- //
701 
702  /// Return the stage's "pseudo-root" prim, whose name is defined by Usd.
703  ///
704  /// The stage's named root prims are namespace children of this prim,
705  /// which exists to make the namespace hierarchy a tree instead of a
706  /// forest. This simplifies algorithms that want to traverse all prims.
707  /// Note that the \ref Usd_stageMetadata "stage metadata" is accesible
708  /// through the pseudo root.
709  ///
710  /// A UsdStage always has a pseudo-root prim, unless there was an error
711  /// opening or creating the stage, in which case this method returns
712  /// an invalid UsdPrim.
713  USD_API
714  UsdPrim GetPseudoRoot() const;
715 
716  /// Return the UsdPrim on this stage whose path is the root layer's
717  /// defaultPrim metadata's value. Return an invalid prim if there is no
718  /// such prim or if the root layer's defaultPrim metadata is unset or is not
719  /// a valid prim path. Note that this function will return the prim on the
720  /// stage whose path is the root layer's GetDefaultPrimAsPath() if that path
721  /// is not empty and a prim at that path exists on the stage.
722  /// See also SdfLayer::GetDefaultPrimAsPath().
723  USD_API
724  UsdPrim GetDefaultPrim() const;
725 
726  /// Set the default prim layer metadata in this stage's root layer. This
727  /// is shorthand for:
728  /// \code
729  /// stage->GetRootLayer()->SetDefaultPrim(prim.GetName());
730  /// \endcode
731  /// If prim is a root prim, otherwise
732  /// \code
733  /// stage->GetRootLayer()->SetDefaultPrim(prim.GetPath().GetAsToken());
734  /// \endcode
735  /// Note that this function always authors to the stage's root layer.
736  /// To author to a different layer, use the SdfLayer::SetDefaultPrim() API.
737  USD_API
738  void SetDefaultPrim(const UsdPrim &prim);
739 
740  /// Clear the default prim layer metadata in this stage's root layer. This
741  /// is shorthand for:
742  /// \code
743  /// stage->GetRootLayer()->ClearDefaultPrim();
744  /// \endcode
745  /// Note that this function always authors to the stage's root layer. To
746  /// author to a different layer, use the SdfLayer::SetDefaultPrim() API.
747  USD_API
748  void ClearDefaultPrim();
749 
750  /// Return true if this stage's root layer has an authored opinion for the
751  /// default prim layer metadata. This is shorthand for:
752  /// \code
753  /// stage->GetRootLayer()->HasDefaultPrim();
754  /// \endcode
755  /// Note that this function only consults the stage's root layer. To
756  /// consult a different layer, use the SdfLayer::HasDefaultPrim() API.
757  USD_API
758  bool HasDefaultPrim() const;
759 
760  /// Return the UsdPrim at \p path, or an invalid UsdPrim if none exists.
761  ///
762  /// If \p path indicates a prim beneath an instance, returns an instance
763  /// proxy prim if a prim exists at the corresponding path in that instance's
764  /// prototype.
765  ///
766  /// Unlike OverridePrim() and DefinePrim(), this method will never author
767  /// scene description, and therefore is safe to use as a "reader" in the Usd
768  /// multi-threading model.
769  USD_API
770  UsdPrim GetPrimAtPath(const SdfPath &path) const;
771 
772  /// Return the UsdObject at \p path, or an invalid UsdObject if none exists.
773  ///
774  /// If \p path indicates a prim beneath an instance, returns an instance
775  /// proxy prim if a prim exists at the corresponding path in that instance's
776  /// prototype. If \p path indicates a property beneath a child of an
777  /// instance, returns a property whose parent prim is an instance proxy
778  /// prim.
779  ///
780  /// Example:
781  ///
782  /// \code
783  ///if (UsdObject obj = stage->GetObjectAtPath(path)) {
784  /// if (UsdPrim prim = obj.As<UsdPrim>()) {
785  /// // Do things with prim
786  /// }
787  /// else if (UsdProperty prop = obj.As<UsdProperty>()) {
788  /// // Do things with property. We can also cast to
789  /// // UsdRelationship or UsdAttribute using this same pattern.
790  /// }
791  ///}
792  ///else {
793  /// // No object at specified path
794  ///}
795  /// \endcode
796  USD_API
797  UsdObject GetObjectAtPath(const SdfPath &path) const;
798 
799  /// Return the UsdProperty at \p path, or an invalid UsdProperty
800  /// if none exists.
801  ///
802  /// This is equivalent to
803  /// \code{.cpp}
804  /// stage.GetObjectAtPath(path).As<UsdProperty>();
805  /// \endcode
806  /// \sa GetObjectAtPath(const SdfPath&) const
807  USD_API
809 
810  /// Return the UsdAttribute at \p path, or an invalid UsdAttribute
811  /// if none exists.
812  ///
813  /// This is equivalent to
814  /// \code{.cpp}
815  /// stage.GetObjectAtPath(path).As<UsdAttribute>();
816  /// \endcode
817  /// \sa GetObjectAtPath(const SdfPath&) const
818  USD_API
820 
821  /// Return the UsdAttribute at \p path, or an invalid UsdAttribute
822  /// if none exists.
823  ///
824  /// This is equivalent to
825  /// \code{.cpp}
826  /// stage.GetObjectAtPath(path).As<UsdRelationship>();
827  /// \endcode
828  /// \sa GetObjectAtPath(const SdfPath&) const
829  USD_API
831 private:
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.
840  _GetPrimDataAtPathOrInPrototype(const SdfPath &path) const;
841 
842  /// See documentation on UsdPrim::GetInstances()
843  std::vector<UsdPrim>
844  _GetInstancesForPrototype(const UsdPrim& prototype) const;
845 
846 public:
847 
848  /// Traverse the active, loaded, defined, non-abstract prims on this stage
849  /// depth-first.
850  ///
851  /// Traverse() returns a UsdPrimRange , which allows low-latency
852  /// traversal, with the ability to prune subtrees from traversal. It
853  /// is python iterable, so in its simplest form, one can do:
854  ///
855  /// \code{.py}
856  /// for prim in stage.Traverse():
857  /// print prim.GetPath()
858  /// \endcode
859  ///
860  /// If either a pre-and-post-order traversal or a traversal rooted at a
861  /// particular prim is desired, construct a UsdPrimRange directly.
862  ///
863  /// You'll need to use the returned UsdPrimRange's iterator to perform
864  /// actions such as pruning subtrees. See the "Using Usd.PrimRange in
865  /// python" section in UsdPrimRange for more details and examples.
866  ///
867  /// This is equivalent to UsdPrimRange::Stage() .
868  USD_API
870 
871  /// \overload
872  /// Traverse the prims on this stage subject to \p predicate.
873  ///
874  /// This is equivalent to UsdPrimRange::Stage() .
875  USD_API
876  UsdPrimRange Traverse(const Usd_PrimFlagsPredicate &predicate);
877 
878  /// Traverse all the prims on this stage depth-first.
879  ///
880  /// \sa Traverse()
881  /// \sa UsdPrimRange::Stage()
882  USD_API
884 
885  /// Attempt to ensure a \a UsdPrim at \p path exists on this stage.
886  ///
887  /// If a prim already exists at \p path, return it. Otherwise author
888  /// \a SdfPrimSpecs with \a specifier == \a SdfSpecifierOver and empty
889  /// \a typeName at the current EditTarget to create this prim and any
890  /// nonexistent ancestors, then return it.
891  ///
892  /// The given \a path must be an absolute prim path that does not contain
893  /// any variant selections.
894  ///
895  /// If it is impossible to author any of the necessary PrimSpecs, (for
896  /// example, in case \a path cannot map to the current UsdEditTarget's
897  /// namespace) issue an error and return an invalid \a UsdPrim.
898  ///
899  /// If an ancestor of \p path identifies an \a inactive prim, author scene
900  /// description as described above but return an invalid prim, since the
901  /// resulting prim is descendant to an inactive prim.
902  ///
903  USD_API
905 
906  /// Attempt to ensure a \a UsdPrim at \p path is defined (according to
907  /// UsdPrim::IsDefined()) on this stage.
908  ///
909  /// If a prim at \p path is already defined on this stage and \p typeName is
910  /// empty or equal to the existing prim's typeName, return that prim.
911  /// Otherwise author an \a SdfPrimSpec with \a specifier ==
912  /// \a SdfSpecifierDef and \p typeName for the prim at \p path at the
913  /// current EditTarget. Author \a SdfPrimSpec s with \p specifier ==
914  /// \a SdfSpecifierDef and empty typeName at the current EditTarget for any
915  /// nonexistent, or existing but not \a Defined ancestors.
916  ///
917  /// The given \a path must be an absolute prim path that does not contain
918  /// any variant selections.
919  ///
920  /// If it is impossible to author any of the necessary PrimSpecs (for
921  /// example, in case \a path cannot map to the current UsdEditTarget's
922  /// namespace or one of the ancestors of \p path is inactive on the
923  /// UsdStage), issue an error and return an invalid \a UsdPrim.
924  ///
925  /// Note that this method may return a defined prim whose typeName does not
926  /// match the supplied \p typeName, in case a stronger typeName opinion
927  /// overrides the opinion at the current EditTarget.
928  ///
929  USD_API
931  const TfToken &typeName=TfToken());
932 
933  /// Author an \a SdfPrimSpec with \a specifier == \a SdfSpecifierClass for
934  /// the class at root prim path \p path at the current EditTarget. The
935  /// current EditTarget must have UsdEditTarget::IsLocalLayer() == true.
936  ///
937  /// The given \a path must be an absolute, root prim path that does not
938  /// contain any variant selections.
939  ///
940  /// If a defined (UsdPrim::IsDefined()) non-class prim already exists at
941  /// \p path, issue an error and return an invalid UsdPrim.
942  ///
943  /// If it is impossible to author the necessary PrimSpec, issue an error
944  /// and return an invalid \a UsdPrim.
945  USD_API
946  UsdPrim CreateClassPrim(const SdfPath &rootPrimPath);
947 
948  /// Remove all scene description for the given \p path and its subtree
949  /// <em>in the current UsdEditTarget</em>.
950  ///
951  /// This method does not do what you might initially think! Calling this
952  /// function will not necessarily cause the UsdPrim at \p path on this
953  /// stage to disappear. Completely eradicating a prim from a composition
954  /// can be an involved process, involving edits to many contributing layers,
955  /// some of which (in many circumstances) will not be editable by a client.
956  /// This method is a surgical instrument that \em can be used iteratively
957  /// to effect complete removal of a prim and its subtree from namespace,
958  /// assuming the proper permissions are acquired, but more commonly it
959  /// is used to perform layer-level operations; e.g.: ensuring that a given
960  /// layer (as expressed by a UsdEditTarget) provides no opinions for a
961  /// prim and its subtree.
962  ///
963  /// Generally, if your eye is attracted to this method, you probably want
964  /// to instead use UsdPrim::SetActive(false) , which will provide the
965  /// \ref Usd_ActiveInactive "composed effect" of removing the prim and
966  /// its subtree from the composition, without actually removing any
967  /// scene description, which as a bonus, means that the effect is
968  /// reversible at a later time!
969  USD_API
970  bool RemovePrim(const SdfPath& path);
971 
972  /// @}
973 
974  // --------------------------------------------------------------------- //
975  /// \anchor Usd_layerManagement
976  /// \name Layers and EditTargets
977  /// @{
978  // --------------------------------------------------------------------- //
979 
980  /// Return this stage's root session layer.
981  USD_API
982  SdfLayerHandle GetSessionLayer() const;
983 
984  /// Return this stage's root layer.
985  USD_API
986  SdfLayerHandle GetRootLayer() const;
987 
988  /// Return the path resolver context for all path resolution during
989  /// composition of this stage. Useful for external clients that want to
990  /// resolve paths with the same context as this stage, or create new
991  /// stages with the same context.
992  USD_API
994 
995  /// Resolve the given identifier using this stage's
996  /// ArResolverContext and the layer of its GetEditTarget()
997  /// as an anchor for relative references (e.g. \@./siblingFile.usd\@).
998  ///
999  /// \return a non-empty string containing either the same
1000  /// identifier that was passed in (if the identifier refers to an
1001  /// already-opened layer or an "anonymous", in-memory layer), or a resolved
1002  /// layer filepath. If the identifier was not resolvable, return the
1003  /// empty string.
1004  USD_API
1005  std::string
1006  ResolveIdentifierToEditTarget(std::string const &identifier) const;
1007 
1008  /// Return a PcpErrorVector containing all composition errors encountered
1009  /// when composing the prims and layer stacks on this stage.
1010  USD_API
1012 
1013  /// \a includeSessionLayers is true, return the linearized strong-to-weak
1014  /// sublayers rooted at the stage's session layer followed by the linearized
1015  /// strong-to-weak sublayers rooted at this stage's root layer. If
1016  /// \a includeSessionLayers is false, omit the sublayers rooted at this
1017  /// stage's session layer.
1018  USD_API
1019  SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const;
1020 
1021  /// Return a vector of all of the layers \em currently consumed by this
1022  /// stage, as determined by the composition arcs that were traversed to
1023  /// compose and populate the stage.
1024  ///
1025  /// The list of consumed layers will change with the stage's load-set and
1026  /// variant selections, so the return value should be considered only
1027  /// a snapshot. The return value will include the stage's session layer,
1028  /// if it has one. If \a includeClipLayers is true, we will also include
1029  /// all of the layers that this stage has had to open so far to perform
1030  /// value resolution of attributes affected by
1031  /// \ref Usd_Page_ValueClips "Value Clips"
1032  USD_API
1033  SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const;
1034 
1035  /// Return true if \a layer is one of the layers in this stage's local,
1036  /// root layerStack.
1037  USD_API
1038  bool HasLocalLayer(const SdfLayerHandle &layer) const;
1039 
1040  /// Return the stage's EditTarget.
1041  USD_API
1042  const UsdEditTarget &GetEditTarget() const;
1043 
1044  /// Return a UsdEditTarget for editing the layer at index \a i in the
1045  /// layer stack. This edit target will incorporate any layer time
1046  /// offset that applies to the sublayer.
1047  USD_API
1049 
1050  /// Return a UsdEditTarget for editing the given local \a layer.
1051  /// If the given layer appears more than once in the layer stack,
1052  /// the time offset to the first occurrence will be used.
1053  USD_API
1054  UsdEditTarget GetEditTargetForLocalLayer(const SdfLayerHandle &layer);
1055 
1056  /// Set the stage's EditTarget. If \a editTarget.IsLocalLayer(), check to
1057  /// see if it's a layer in this stage's local LayerStack. If not, issue an
1058  /// error and do nothing. If \a editTarget is invalid, issue an error
1059  /// and do nothing. If \a editTarget differs from the stage's current
1060  /// EditTarget, set the EditTarget and send
1061  /// UsdNotice::StageChangedEditTarget. Otherwise do nothing.
1062  USD_API
1063  void SetEditTarget(const UsdEditTarget &editTarget);
1064 
1065  /// Mute the layer identified by \p layerIdentifier. Muted layers are
1066  /// ignored by the stage; they do not participate in value resolution
1067  /// or composition and do not appear in any LayerStack. If the root
1068  /// layer of a reference or payload LayerStack is muted, the behavior
1069  /// is as if the muted layer did not exist, which means a composition
1070  /// error will be generated.
1071  ///
1072  /// A canonical identifier for each layer in \p layersToMute will be
1073  /// computed using ArResolver::CreateIdentifier using the stage's root
1074  /// layer as the anchoring asset. Any layer encountered during composition
1075  /// with the same identifier will be considered muted and ignored.
1076  ///
1077  /// Note that muting a layer will cause this stage to release all
1078  /// references to that layer. If no other client is holding on to
1079  /// references to that layer, it will be unloaded. In this case, if
1080  /// there are unsaved edits to the muted layer, those edits are lost.
1081  /// Since anonymous layers are not serialized, muting an anonymous
1082  /// layer will cause that layer and its contents to be lost in this
1083  /// case.
1084  ///
1085  /// Muting a layer that has not been used by this stage is not an error.
1086  /// If that layer is encountered later, muting will take effect and that
1087  /// layer will be ignored.
1088  ///
1089  /// The root layer of this stage may not be muted; attempting to do so
1090  /// will generate a coding error.
1091  USD_API
1092  void MuteLayer(const std::string &layerIdentifier);
1093 
1094  /// Unmute the layer identified by \p layerIdentifier if it had
1095  /// previously been muted.
1096  USD_API
1097  void UnmuteLayer(const std::string &layerIdentifier);
1098 
1099  /// Mute and unmute the layers identified in \p muteLayers and
1100  /// \p unmuteLayers.
1101  ///
1102  /// This is equivalent to calling UsdStage::UnmuteLayer for each layer
1103  /// in \p unmuteLayers followed by UsdStage::MuteLayer for each layer
1104  /// in \p muteLayers, however this method is more efficient as all
1105  /// operations are committed in a single batch.
1106  USD_API
1107  void MuteAndUnmuteLayers(const std::vector<std::string> &muteLayers,
1108  const std::vector<std::string> &unmuteLayers);
1109 
1110  /// Returns a vector of all layers that have been muted on this stage.
1111  USD_API
1112  const std::vector<std::string>& GetMutedLayers() const;
1113 
1114  /// Returns true if the layer specified by \p layerIdentifier is
1115  /// muted in this cache, false otherwise. See documentation on
1116  /// MuteLayer for details on how \p layerIdentifier is compared to the
1117  /// layers that have been muted.
1118  USD_API
1119  bool IsLayerMuted(const std::string& layerIdentifier) const;
1120 
1121  /// @}
1122 
1123  // --------------------------------------------------------------------- //
1124  /// \anchor Usd_stageSerialization
1125  /// \name Flatten & Export Utilities
1126  /// @{
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 
1134  /// Writes out the composite scene as a single flattened layer into
1135  /// \a filename.
1136  ///
1137  /// If addSourceFileComment is true, a comment in the output layer
1138  /// will mention the input layer it was generated from.
1139  ///
1140  /// See UsdStage::Flatten for details of the flattening transformation.
1141  USD_API
1142  bool Export(const std::string &filename,
1143  bool addSourceFileComment=true,
1146 
1147  /// Writes the composite scene as a flattened Usd text
1148  /// representation into the given \a string.
1149  ///
1150  /// If addSourceFileComment is true, a comment in the output layer
1151  /// will mention the input layer it was generated from.
1152  ///
1153  /// See UsdStage::Flatten for details of the flattening transformation.
1154  USD_API
1155  bool ExportToString(std::string *result,
1156  bool addSourceFileComment=true) const;
1157 
1158  /// Returns a single, anonymous, merged layer for this composite
1159  /// scene.
1160  ///
1161  /// Specifically, this function removes **most** composition metadata and
1162  /// authors the resolved values for each object directly into the flattened
1163  /// layer.
1164  ///
1165  /// All VariantSets are removed and only the currently selected variants
1166  /// will be present in the resulting layer.
1167  ///
1168  /// Class prims will still exist, however all inherits arcs will have
1169  /// been removed and the inherited data will be copied onto each child
1170  /// object. Composition arcs authored on the class itself will be flattened
1171  /// into the class.
1172  ///
1173  /// Flatten preserves
1174  /// \ref Usd_Page_ScenegraphInstancing "scenegraph instancing" by creating
1175  /// independent roots for each prototype currently composed on this stage,
1176  /// and adding a single internal reference arc on each instance prim to its
1177  /// corresponding prototype.
1178  ///
1179  /// Time samples across sublayer offsets will will have the time offset and
1180  /// scale applied to each time index.
1181  ///
1182  /// Finally, any deactivated prims will be pruned from the result.
1183  ///
1184  USD_API
1185  SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const;
1186  /// @}
1187 
1188 public:
1189  // --------------------------------------------------------------------- //
1190  /// \anchor Usd_stageMetadata
1191  /// \name Stage Metadata
1192  /// Stage metadata applies to the entire contents of the stage, and is
1193  /// recorded only in the stage's root or primary session-layer. Most of
1194  /// the other, specific metadata methods on UsdStage are defined in terms
1195  /// of these generic methods.
1196  /// @{
1197  // --------------------------------------------------------------------- //
1198 
1199  /// Return in \p value an authored or fallback value (if one was defined
1200  /// for the given metadatum) for Stage metadatum \p key. Order of
1201  /// resolution is session layer, followed by root layer, else fallback to
1202  /// the SdfSchema.
1203  ///
1204  /// \return true if we successfully retrieved a value of the requested type;
1205  /// false if \p key is not allowed as layer metadata or no value was found.
1206  /// Generates a coding error if we retrieved a stored value of a type other
1207  /// than the requested type
1208  ///
1209  /// \sa \ref Usd_OM_Metadata
1210  template <class T>
1211  bool GetMetadata(const TfToken &key, T *value) const;
1212  /// \overload
1213  USD_API
1214  bool GetMetadata(const TfToken &key, VtValue *value) const;
1215 
1216  /// Returns true if the \a key has a meaningful value, that is, if
1217  /// GetMetadata() will provide a value, either because it was authored
1218  /// or because the Stage metadata was defined with a meaningful fallback
1219  /// value.
1220  ///
1221  /// Returns false if \p key is not allowed as layer metadata.
1222  USD_API
1223  bool HasMetadata(const TfToken &key) const;
1224 
1225  /// Returns \c true if the \a key has an authored value, \c false if no
1226  /// value was authored or the only value available is the SdfSchema's
1227  /// metadata fallback.
1228  ///
1229  /// \note If a value for a metadatum \em not legal to author on layers
1230  /// is present in the root or session layer (which could happen through
1231  /// hand-editing or use of certain low-level API's), this method will
1232  /// still return \c false.
1233  USD_API
1234  bool HasAuthoredMetadata(const TfToken &key) const;
1235 
1236  /// Set the value of Stage metadatum \p key to \p value, if the stage's
1237  /// current UsdEditTarget is the root or session layer.
1238  ///
1239  /// If the current EditTarget is any other layer, raise a coding error.
1240  /// \return true if authoring was successful, false otherwise.
1241  /// Generates a coding error if \p key is not allowed as layer metadata.
1242  ///
1243  /// \sa \ref Usd_OM_Metadata
1244  USD_API
1245  bool SetMetadata(const TfToken &key, VtValueRef value) const;
1246 
1247  /// Clear the value of stage metadatum \p key, if the stage's
1248  /// current UsdEditTarget is the root or session layer.
1249  ///
1250  /// If the current EditTarget is any other layer, raise a coding error.
1251  /// \return true if authoring was successful, false otherwise.
1252  /// Generates a coding error if \p key is not allowed as layer metadata.
1253  ///
1254  /// \sa \ref Usd_OM_Metadata
1255  USD_API
1256  bool ClearMetadata(const TfToken &key) const;
1257 
1258  /// Resolve the requested dictionary sub-element \p keyPath of
1259  /// dictionary-valued metadatum named \p key, returning the resolved
1260  /// value.
1261  ///
1262  /// If you know you need just a small number of elements from a dictionary,
1263  /// accessing them element-wise using this method can be much less
1264  /// expensive than fetching the entire dictionary with GetMetadata(key).
1265  ///
1266  /// \return true if we successfully retrieved a value of the requested type;
1267  /// false if \p key is not allowed as layer metadata or no value was found.
1268  /// Generates a coding error if we retrieved a stored value of a type other
1269  /// than the requested type
1270  ///
1271  /// The \p keyPath is a ':'-separated path addressing an element
1272  /// in subdictionaries. If \p keyPath is empty, returns an empty VtValue.
1273  template<typename T>
1274  bool GetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
1275  T* value) const;
1276  /// overload
1277  USD_API
1278  bool GetMetadataByDictKey(
1279  const TfToken& key, const TfToken &keyPath, VtValue *value) const;
1280 
1281  /// Return true if there exists any authored or fallback opinion for
1282  /// \p key and \p keyPath.
1283  ///
1284  /// The \p keyPath is a ':'-separated path identifying a value in
1285  /// subdictionaries stored in the metadata field at \p key. If
1286  /// \p keyPath is empty, returns \c false.
1287  ///
1288  /// Returns false if \p key is not allowed as layer metadata.
1289  ///
1290  /// \sa \ref Usd_Dictionary_Type
1291  USD_API
1292  bool HasMetadataDictKey(
1293  const TfToken& key, const TfToken &keyPath) const;
1294 
1295  /// Return true if there exists any authored opinion (excluding
1296  /// fallbacks) for \p key and \p keyPath.
1297  ///
1298  /// The \p keyPath is a ':'-separated path identifying a value in
1299  /// subdictionaries stored in the metadata field at \p key. If
1300  /// \p keyPath is empty, returns \c false.
1301  ///
1302  /// \sa \ref Usd_Dictionary_Type
1303  USD_API
1305  const TfToken& key, const TfToken &keyPath) const;
1306 
1307  /// Author \p value to the field identified by \p key and \p keyPath
1308  /// at the current EditTarget.
1309  ///
1310  /// The \p keyPath is a ':'-separated path identifying a value in
1311  /// subdictionaries stored in the metadata field at \p key. If
1312  /// \p keyPath is empty, no action is taken.
1313  ///
1314  /// \return true if the value is authored successfully, false otherwise.
1315  /// Generates a coding error if \p key is not allowed as layer metadata.
1316  ///
1317  /// \sa \ref Usd_Dictionary_Type
1318  USD_API
1319  bool SetMetadataByDictKey(
1320  const TfToken& key, const TfToken &keyPath, VtValueRef value) const;
1321 
1322  /// Clear any authored value identified by \p key and \p keyPath
1323  /// at the current EditTarget.
1324  ///
1325  /// The \p keyPath is a ':'-separated path identifying a path in
1326  /// subdictionaries stored in the metadata field at \p key. If
1327  /// \p keyPath is empty, no action is taken.
1328  ///
1329  /// \return true if the value is cleared successfully, false otherwise.
1330  /// Generates a coding error if \p key is not allowed as layer metadata.
1331  ///
1332  /// \sa \ref Usd_Dictionary_Type
1333  USD_API
1335  const TfToken& key, const TfToken& keyPath) const;
1336 
1337  /// Writes the fallback prim types defined in the schema registry to the
1338  /// stage as dictionary valued fallback prim type metadata. If the stage
1339  /// already has fallback prim type metadata, the fallback types from the
1340  /// schema registry will be added to the existing metadata, only for types
1341  /// that are already present in the dictionary, i.e. this won't overwrite
1342  /// existing fallback entries.
1343  ///
1344  /// The current edit target determines whether the metadata is written to
1345  /// the root layer or the session layer. If the edit target specifies
1346  /// another layer besides these, this will produce an error.
1347  ///
1348  /// This function can be used at any point before calling Save or Export on
1349  /// a stage to record the fallback types for the current schemas. This
1350  /// allows another version of Usd to open this stage and treat prim types it
1351  /// doesn't recognize as a type it does recognize defined for it in this
1352  /// metadata.
1353  ///
1354  /// \sa \ref Usd_OM_FallbackPrimTypes UsdSchemaRegistry::GetFallbackPrimTypes
1355  USD_API
1356  void WriteFallbackPrimTypes();
1357 
1358  /// @}
1359 
1360  // --------------------------------------------------------------------- //
1361  /// \anchor Usd_timeCodeAPI
1362  /// \name TimeCode API
1363  /// Methods for managing the Stage's active timeSample range, time units,
1364  /// and intended rate of playback. See \ref Usd_OM_UsdTimeCode for more
1365  /// on time and TimeCodes in USD.
1366  /// @{
1367  // --------------------------------------------------------------------- //
1368  /// Returns the stage's start timeCode. If the stage has an associated
1369  /// session layer with a start timeCode opinion, this value is returned.
1370  /// Otherwise, the start timeCode opinion from the root layer is returned.
1371  USD_API
1372  double GetStartTimeCode() const;
1373 
1374  /// Sets the stage's start timeCode.
1375  ///
1376  /// The start timeCode is set in the current EditTarget, if it is the root
1377  /// layer of the stage or the session layer associated with the stage. If
1378  /// the current EditTarget is neither, a warning is issued and the start
1379  /// timeCode is not set.
1380  USD_API
1381  void SetStartTimeCode(double);
1382 
1383  /// Returns the stage's end timeCode. If the stage has an associated
1384  /// session layer with an end timeCode opinion, this value is returned.
1385  /// Otherwise, the end timeCode opinion from the root layer is returned.
1386  USD_API
1387  double GetEndTimeCode() const;
1388 
1389  /// Sets the stage's end timeCode.
1390  ///
1391  /// The end timeCode is set in the current EditTarget, if it is the root
1392  /// layer of the stage or the session layer associated with the stage. If
1393  /// the current EditTarget is neither, a warning is issued and the end
1394  /// timeCode is not set.
1395  USD_API
1396  void SetEndTimeCode(double);
1397 
1398  /// Returns true if the stage has both start and end timeCodes
1399  /// authored in the session layer or the root layer of the stage.
1400  USD_API
1401  bool HasAuthoredTimeCodeRange() const;
1402 
1403  /// Returns the stage's timeCodesPerSecond value.
1404  ///
1405  /// The timeCodesPerSecond value scales the time ordinate for the samples
1406  /// contained in the stage to seconds. If timeCodesPerSecond is 24, then a
1407  /// sample at time ordinate 24 should be viewed exactly one second after the
1408  /// sample at time ordinate 0.
1409  ///
1410  /// Like SdfLayer::GetTimeCodesPerSecond, this accessor uses a dynamic
1411  /// fallback to framesPerSecond. The order of precedence is:
1412  ///
1413  /// \li timeCodesPerSecond from session layer
1414  /// \li timeCodesPerSecond from root layer
1415  /// \li framesPerSecond from session layer
1416  /// \li framesPerSecond from root layer
1417  /// \li fallback value of 24
1418  USD_API
1419  double GetTimeCodesPerSecond() const;
1420 
1421  /// Sets the stage's timeCodesPerSecond value.
1422  ///
1423  /// The timeCodesPerSecond value is set in the current EditTarget, if it
1424  /// is the root layer of the stage or the session layer associated with the
1425  /// stage. If the current EditTarget is neither, a warning is issued and no
1426  /// value is set.
1427  ///
1428  /// \sa GetTimeCodesPerSecond()
1429  USD_API
1430  void SetTimeCodesPerSecond(double timeCodesPerSecond) const;
1431 
1432  /// Returns the stage's framesPerSecond value.
1433  ///
1434  /// This makes an advisory statement about how the contained data can be
1435  /// most usefully consumed and presented. It's primarily an indication of
1436  /// the expected playback rate for the data, but a timeline editing tool
1437  /// might also want to use this to decide how to scale and label its
1438  /// timeline.
1439  ///
1440  /// The default value of framesPerSecond is 24.
1441  USD_API
1442  double GetFramesPerSecond() const;
1443 
1444  /// Sets the stage's framesPerSecond value.
1445  ///
1446  /// The framesPerSecond value is set in the current EditTarget, if it
1447  /// is the root layer of the stage or the session layer associated with the
1448  /// stage. If the current EditTarget is neither, a warning is issued and no
1449  /// value is set.
1450  ///
1451  /// \sa GetFramesPerSecond()
1452  USD_API
1453  void SetFramesPerSecond(double framesPerSecond) const;
1454 
1455  /// @}
1456 
1457  // --------------------------------------------------------------------- //
1458  /// \anchor Usd_ColorConfigurationAPI
1459  /// \name Color Configuration API
1460  ///
1461  /// Methods for authoring and querying the display color configuration
1462  /// encoded in layer metadata. This color configuration information is
1463  /// stored as a convenience for use in pipeline tools and is unrelated
1464  /// to color space information associated with Usd attributes or textures.
1465  ///
1466  /// Site-wide fallback values for the colorConfiguration and
1467  /// colorManagementSystem metadata can be set in the plugInfo.json file of
1468  /// a plugin using this structure:
1469  ///
1470  /// \code{.json}
1471  /// "UsdColorConfigFallbacks": {
1472  /// "colorConfiguration" = "https://path/to/color/config.ocio",
1473  /// "colorManagementSystem" : "OpenColorIO"
1474  /// }
1475  /// \endcode
1476  ///
1477  /// @{
1478  // --------------------------------------------------------------------- //
1479 
1480  /// Sets the default color configuration to be used for querying color
1481  /// configuration metadata stored in a layer. This data is informational
1482  /// for use in pipeline tools.
1483  ///
1484  /// \ref Usd_ColorConfigurationAPI "Color Configuration API"
1485  USD_API
1486  void SetColorConfiguration(const SdfAssetPath &colorConfig) const;
1487 
1488  /// Returns the default color configuration stored in layer metadata.
1489  ///
1490  /// \ref Usd_ColorConfigurationAPI "Color Configuration API"
1491  USD_API
1493 
1494  /// Sets the name of the color management system used to interpret the
1495  /// color configuration file pointed at by the colorConfiguration metadata.
1496  ///
1497  /// \ref Usd_ColorConfigurationAPI "Color Configuration API"
1498  USD_API
1499  void SetColorManagementSystem(const TfToken &cms) const;
1500 
1501  /// Sets the name of the color management system to be used for loading
1502  /// and interpreting the color configuration file.
1503  ///
1504  /// \ref Usd_ColorConfigurationAPI "Color Configuration API"
1505  USD_API
1507 
1508  /// Returns the global fallback values of 'colorConfiguration' and
1509  /// 'colorManagementSystem'. These are set in the plugInfo.json file
1510  /// of a plugin, but can be overridden by calling the static method
1511  /// SetColorConfigFallbacks().
1512  ///
1513  /// The python wrapping of this method returns a tuple containing
1514  /// (colorConfiguration, colorManagementSystem).
1515  ///
1516  /// \sa SetColorConfigFallbacks,
1517  /// \ref Usd_ColorConfigurationAPI "Color Configuration API"
1518  USD_API
1519  static void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration,
1520  TfToken *colorManagementSystem);
1521 
1522  /// Sets the global fallback values of color configuration metadata which
1523  /// includes the 'colorConfiguration' asset path and the name of the
1524  /// color management system. This overrides any fallback values authored
1525  /// in plugInfo files.
1526  ///
1527  /// If the specified value of \p colorConfiguration or
1528  /// \p colorManagementSystem is empty, then the corresponding fallback
1529  /// value isn't set. In other words, for this call to have an effect,
1530  /// at least one value must be non-empty. Additionally, these can't be
1531  /// reset to empty values.
1532  ///
1533  /// \sa GetColorConfigFallbacks()
1534  /// \ref Usd_ColorConfigurationAPI "Color Configuration API"
1535  USD_API
1536  static void
1537  SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration,
1538  const TfToken &colorManagementSystem);
1539 
1540  /// @}
1541 
1542  // --------------------------------------------------------------------- //
1543  /// \anchor Usd_interpolation
1544  /// \name Attribute Value Interpolation
1545  /// Controls the interpolation behavior when retrieving attribute
1546  /// values. The default behavior is linear interpolation.
1547  /// See \ref Usd_AttributeInterpolation for more details.
1548  /// @{
1549  // --------------------------------------------------------------------- //
1550 
1551  /// Sets the interpolation type used during value resolution
1552  /// for all attributes on this stage. Changing this will cause a
1553  /// UsdNotice::StageContentsChanged notice to be sent, as values at
1554  /// times where no samples are authored may have changed.
1555  USD_API
1556  void SetInterpolationType(UsdInterpolationType interpolationType);
1557 
1558  /// Returns the interpolation type used during value resolution
1559  /// for all attributes on this stage.
1560  USD_API
1562 
1563  /// @}
1564 
1565  // --------------------------------------------------------------------- //
1566  /// \anchor Usd_instancing
1567  /// \name Instancing
1568  /// See \ref Usd_Page_ScenegraphInstancing for more details.
1569  /// @{
1570  // --------------------------------------------------------------------- //
1571 
1572  /// Returns all native instancing prototype prims.
1573  USD_API
1574  std::vector<UsdPrim> GetPrototypes() const;
1575 
1576  /// @}
1577 
1578 private:
1579  struct _IncludePayloadsPredicate;
1580 
1581  // --------------------------------------------------------------------- //
1582  // Stage Construction & Initialization
1583  // --------------------------------------------------------------------- //
1584 
1585  UsdStage(const SdfLayerRefPtr& rootLayer,
1586  const SdfLayerRefPtr& sessionLayer,
1587  const ArResolverContext& pathResolverContext,
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,
1608  InitialLoadSet load);
1609 
1610  // --------------------------------------------------------------------- //
1611  // Spec Existence & Definition Helpers
1612  // --------------------------------------------------------------------- //
1613 
1614  SdfPropertySpecHandleVector
1615  _GetPropertyStack(const UsdProperty &prop, UsdTimeCode time) const;
1616 
1617  std::vector<std::pair<SdfPropertySpecHandle, SdfLayerOffset>>
1618  _GetPropertyStackWithLayerOffsets(
1619  const UsdProperty &prop, UsdTimeCode time) const;
1620 
1621  static SdfPrimSpecHandleVector
1622  _GetPrimStack(const UsdPrim &prim);
1623 
1624  static std::vector<std::pair<SdfPrimSpecHandle, SdfLayerOffset>>
1625  _GetPrimStackWithLayerOffsets(const UsdPrim &prim);
1626 
1628  _GetSchemaProperty(const UsdProperty &prop) const;
1629 
1630  USD_API
1632  _GetSchemaAttribute(const UsdAttribute &attr) const;
1633 
1635  _GetSchemaRelationship(const UsdRelationship &rel) const;
1636 
1637  SdfAttributeSpecHandle
1638  _CreateNewSpecFromSchemaAttribute(
1639  const UsdPrim &prim,
1640  const UsdPrimDefinition::Attribute &attrDef);
1641 
1642  SdfRelationshipSpecHandle
1643  _CreateNewSpecFromSchemaRelationship(
1644  const UsdPrim &prim,
1645  const UsdPrimDefinition::Relationship &relDef);
1646 
1647  template <class PropType>
1649  _CreateNewPropertySpecFromSchema(const UsdProperty &prop);
1650 
1651  SdfPrimSpecHandle
1652  _CreatePrimSpecForEditing(const UsdPrim& prim);
1653 
1654  template <class PropType>
1656  _CreatePropertySpecForEditing(const UsdProperty &prop);
1657 
1658  SdfPropertySpecHandle
1659  _CreatePropertySpecForEditing(const UsdProperty &prop);
1660 
1661  SdfAttributeSpecHandle
1662  _CreateAttributeSpecForEditing(const UsdAttribute &attr);
1663 
1664  SdfRelationshipSpecHandle
1665  _CreateRelationshipSpecForEditing(const UsdRelationship &rel);
1666 
1667  // Check if the given path is valid to use with the prim creation API,
1668  // like DefinePrim. If it is valid, returns (true, GetPrimAtPath(path)).
1669  // Otherwise, returns (false, UsdPrim()).
1670  std::pair<bool, UsdPrim>
1671  _IsValidPathForCreatingPrim(const SdfPath &path) const;
1672 
1673  // Validates that editing a specified prim is allowed. If editing is not
1674  // allowed, issues a coding error like "Cannot <operation> ..." and
1675  // returns false. Otherwise, returns true.
1676  bool _ValidateEditPrim(const UsdPrim &prim, const char* operation) const;
1677  bool _ValidateEditPrimAtPath(const SdfPath &primPath,
1678  const char* operation) const;
1679 
1680  UsdPrim _DefinePrim(const SdfPath &path, const TfToken &typeName);
1681 
1682  bool _RemoveProperty(const SdfPath& path);
1683 
1684  UsdProperty _FlattenProperty(const UsdProperty &srcProp,
1685  const UsdPrim &dstParent,
1686  const TfToken &dstName);
1687 
1688  // --------------------------------------------------------------------- //
1689  // Value & Metadata Authoring
1690  // --------------------------------------------------------------------- //
1691 
1692  // Set value for dynamically typed VtValueRef. Will map the value across
1693  // edit targets if the held value type supports it.
1694  bool _SetValue(
1695  UsdTimeCode time, const UsdAttribute &attr, VtValueRef newValue);
1696 
1697  TfToken _GetAttributeValueTypeNameToken(const UsdAttribute &attr) const;
1698  SdfValueTypeName _GetAttributeValueTypeName(const UsdAttribute &attr) const;
1699  TfType _GetAttributeValueType(const UsdAttribute &attr) const;
1700 
1701  bool _ClearValue(UsdTimeCode time, const UsdAttribute &attr);
1702 
1703  // Set metadata for dynamically typed VtValueRef. Will map the value across
1704  // edit targets if the value type supports it.
1705  USD_API
1706  bool _SetMetadata(const UsdObject &object,
1707  const TfToken& key,
1708  const TfToken &keyPath,
1709  VtValueRef value);
1710 
1711  bool _ClearMetadata(const UsdObject &obj, const TfToken& fieldName,
1712  const TfToken &keyPath=TfToken());
1713 
1714  // --------------------------------------------------------------------- //
1715  // Misc Internal Helpers
1716  // --------------------------------------------------------------------- //
1717 
1718  // Pcp helpers.
1719  PcpCache const *_GetPcpCache() const { return _cache.get(); }
1720  PcpCache *_GetPcpCache() { return _cache.get(); }
1721 
1722  // Returns the PrimIndex, using the read-only PcpCache API. We expect prims
1723  // to be composed during initial stage composition, so this method should
1724  // not be used in that context.
1725  const PcpPrimIndex* _GetPcpPrimIndex(const SdfPath& primPath) const;
1726 
1727  // Helper to report pcp errors.
1728  void _ReportPcpErrors(const PcpErrorVector &errors,
1729  const std::string &context) const;
1730  void _ReportErrors(const PcpErrorVector &errors,
1731  const std::vector<std::string>& otherErrors,
1732  const std::string &context) const;
1733 
1734  // --------------------------------------------------------------------- //
1735  // Scenegraph Composition & Change Processing
1736  // --------------------------------------------------------------------- //
1737 
1738  // Compose the prim indexes in the subtrees rooted at the paths in
1739  // \p primIndexPaths. If \p instanceChanges is given, returns
1740  // changes to prototypes and instances due to the discovery of new instances
1741  // during composition.
1742  void _ComposePrimIndexesInParallel(
1743  const std::vector<SdfPath>& primIndexPaths,
1744  const std::string& context,
1745  Usd_InstanceChanges* instanceChanges = nullptr);
1746 
1747  // Recompose the subtree rooted at \p prim: compose its type, flags, and
1748  // list of children, then invoke _ComposeSubtree on all its children.
1749  void _ComposeSubtree(
1752  const SdfPath &primIndexPath = SdfPath());
1753  void _ComposeSubtreeImpl(
1755  UsdStagePopulationMask const *mask,
1756  const SdfPath &primIndexPath = SdfPath());
1757  void _ComposeSubtreesInParallel(
1758  const std::vector<Usd_PrimDataPtr> &prims,
1759  const std::vector<SdfPath> *primIndexPaths = nullptr);
1760 
1761  // Composes the full prim type info for the prim based on its type name
1762  // and applied API schemas.
1763  void _ComposePrimTypeInfoImpl(Usd_PrimDataPtr prim);
1764 
1765  // Compose subtree rooted at \p prim under \p parent. This function
1766  // ensures that the appropriate prim index is specified for \p prim if
1767  // \p parent is in a prototype.
1768  void _ComposeChildSubtree(Usd_PrimDataPtr prim,
1769  Usd_PrimDataConstPtr parent,
1770  UsdStagePopulationMask const *mask);
1771 
1772  // Compose \p prim's list of children and make any modifications necessary
1773  // to its _children member and the stage's _primMap, including possibly
1774  // instantiating new prims, or destroying existing subtrees of prims. The
1775  // any newly created prims *do not* have their prim index, type, flags, or
1776  // children composed.
1777  //
1778  // Compose only \p prim's direct children if recurse=false. Otherwise
1779  // recompose every descendent of \p prim. Callers that pass recurse=false
1780  // should invoke _ComposeSubtree on any newly created prims to ensure caches
1781  // are correctly populated.
1782  void _ComposeChildren(Usd_PrimDataPtr prim,
1783  UsdStagePopulationMask const *mask, bool recurse);
1784 
1785  // Instantiate a prim instance. There must not already be an instance
1786  // at \p primPath.
1787  Usd_PrimDataPtr _InstantiatePrim(const SdfPath &primPath);
1788 
1789  // Instantiate a prototype prim and sets its parent to pseudoroot.
1790  // There must not already be a prototype at \p primPath.
1791  Usd_PrimDataPtr _InstantiatePrototypePrim(const SdfPath &primPath);
1792 
1793  // For \p prim and all of its descendants, remove from _primMap and empty
1794  // their _children vectors.
1795  void _DestroyPrim(Usd_PrimDataPtr prim);
1796 
1797  // Destroy the prim subtrees rooted at each path in \p paths. \p paths may
1798  // not contain any path that is a descendent of another path in \p paths.
1799  void _DestroyPrimsInParallel(const std::vector<SdfPath>& paths);
1800 
1801  // Invoke _DestroyPrim() on all of \p prim's direct children.
1802  void _DestroyDescendents(Usd_PrimDataPtr prim);
1803 
1804  // Returns true if the object at the given path is a descendant of
1805  // an instance prim, i.e. a prim beneath an instance prim, or a property
1806  // of a prim beneath an instance prim.
1807  bool _IsObjectDescendantOfInstance(const SdfPath& path) const;
1808 
1809  // If the given prim is an instance, returns the corresponding
1810  // prototype prim. Otherwise, returns an invalid prim.
1811  Usd_PrimDataConstPtr _GetPrototypeForInstance(Usd_PrimDataConstPtr p) const;
1812 
1813  // Returns the path of the Usd prim using the prim index at the given path.
1814  SdfPath _GetPrimPathUsingPrimIndexAtPath(const SdfPath& primIndexPath) const;
1815 
1816  // Responds to LayersDidChangeSentPerLayer event and update stage contents
1817  // in response to changes in scene description.
1818  void _HandleLayersDidChange(const SdfNotice::LayersDidChangeSentPerLayer &);
1819 
1820  // Pushes changes through PCP to determine invalidation based on
1821  // composition metadata.
1822  // Note: This method will not perform any processing or notification
1823  // Refer to _ProcessPendingChanges()
1824  void _ComputePendingChanges(const SdfLayerChangeListVec &);
1825 
1826  // Update stage contents in response to changes to the asset resolver.
1827  void _HandleResolverDidChange(const ArNotice::ResolverChanged &);
1828 
1829  // Process stage change information stored in _pendingChanges.
1830  // _pendingChanges will be set to nullptr by the end of the function.
1831  // This function will return true if UsdNotice::ObjectsChanged and
1832  // UsdNotice::StageContentsChanged notices were sent during execution.
1833  bool _ProcessPendingChanges();
1834 
1835  // Remove scene description for the prim at \p fullPath in the current edit
1836  // target.
1837  bool _RemovePrim(const SdfPath& fullPath);
1838 
1839  SdfPrimSpecHandle _GetPrimSpec(const SdfPath& fullPath);
1840 
1841  // Find and return the defining spec type for the property spec at the given
1842  // path, or SdfSpecTypeUnknown if none exists. The defining spec type is
1843  // either the builtin definition's spec type, if the indicated property is
1844  // builtin, otherwise it's the strongest authored spec's type if one exists,
1845  // otherwise it's SdfSpecTypeUnknown.
1846  SdfSpecType _GetDefiningSpecType(Usd_PrimDataConstPtr primData,
1847  const TfToken &propName) const;
1848 
1849  // Helper to apply Pcp changes and recompose the scenegraph accordingly,
1850  // given an optional initial set of paths to recompose.
1851  void _Recompose(const PcpChanges &changes);
1852  template <class T>
1853  void _Recompose(const PcpChanges &changes, T *pathsToRecompose);
1854  template <class T>
1855  void _RecomposePrims(T *pathsToRecompose);
1856 
1857  // Helper for _Recompose to find the subtrees that need to be
1858  // fully recomposed and to recompose the name children of the
1859  // parents of these subtrees. Note that [start, finish) must be a
1860  // sorted range of map iterators whose keys are paths with no descendent
1861  // paths. In C++20, consider using the ranges API to improve this.
1862  template <class Iter>
1863  void _ComputeSubtreesToRecompose(Iter start, Iter finish,
1864  std::vector<Usd_PrimDataPtr>* recompose);
1865 
1866  // return true if the path is valid for load/unload operations.
1867  // This method will emit errors when invalid paths are encountered.
1868  bool _IsValidForLoad(const SdfPath& path) const;
1869  bool _IsValidForUnload(const SdfPath& path) const;
1870 
1871  // Discover all payloads in a given subtree, adding the path of each
1872  // discovered prim index to the \p primIndexPaths set. If specified,
1873  // the corresponding UsdPrim path will be added to the \p usdPrimPaths
1874  // set. The root path will be considered for inclusion in the result set.
1875  //
1876  // Note that some payloads may not be discoverable in until an ancestral
1877  // payload has been included. UsdStage::LoadAndUnload takes this into
1878  // account.
1879  void _DiscoverPayloads(const SdfPath& rootPath,
1880  UsdLoadPolicy policy,
1881  SdfPathSet* primIndexPaths,
1882  bool unloadedOnly = false,
1883  SdfPathSet* usdPrimPaths = nullptr) const;
1884 
1885  // ===================================================================== //
1886  // VALUE RESOLUTION //
1887  // ===================================================================== //
1888  // --------------------------------------------------------------------- //
1889  // Specialized Value Resolution
1890  // --------------------------------------------------------------------- //
1891 
1892  // Helpers for resolving values for metadata fields requiring
1893  // special behaviors.
1894  static SdfSpecifier _GetSpecifier(Usd_PrimDataConstPtr primData);
1895  static TfToken _GetKind(Usd_PrimDataConstPtr primData);
1896  static bool _IsActive(Usd_PrimDataConstPtr primData);
1897 
1898  // Custom is true if it is true anywhere in the stack.
1899  bool _IsCustom(const UsdProperty &prop) const;
1900 
1901  // Variability is determined by the weakest opinion in the stack.
1902  SdfVariability _GetVariability(const UsdProperty &prop) const;
1903 
1904  // Helper functions for resolving asset paths during value resolution.
1905  void _MakeResolvedAssetPaths(UsdTimeCode time, const UsdAttribute &attr,
1906  SdfAssetPath *assetPaths,
1907  size_t numAssetPaths,
1908  bool anchorAssetPathsOnly = false) const;
1909 
1910  void _MakeResolvedAssetPathsValue(UsdTimeCode time, const UsdAttribute &attr,
1911  VtValue *value,
1912  bool anchorAssetPathsOnly = false) const;
1913 
1914  // --------------------------------------------------------------------- //
1915  // Metadata Resolution
1916  // --------------------------------------------------------------------- //
1917 
1918 public:
1919  // Trait that allows us to call the correct version of _GetMetadata for
1920  // types that require type specific value resolution as opposed to just
1921  // strongest opinion. These types also use type specific resolution
1922  // in _GetValue.
1923  template <class T>
1925  static const bool value =
1927  std::is_same<T, VtArray<SdfAssetPath>>::value ||
1929  std::is_same<T, VtArray<SdfTimeCode>>::value ||
1931  std::is_same<T, VtArray<SdfPathExpression>>::value ||
1935  };
1936 
1937 private:
1938  // Get metadata as a dynamically typed VtValue. Will perform type specific
1939  // value resolution if the returned held type requires it.
1940  USD_API
1941  bool _GetMetadata(const UsdObject &obj,
1942  const TfToken& fieldName,
1943  const TfToken &keyPath,
1944  bool useFallbacks,
1945  VtValue* result) const;
1946 
1947  USD_API
1948  bool _GetMetadata(const UsdObject &obj,
1949  const TfToken& fieldName,
1950  const TfToken &keyPath,
1951  bool useFallbacks,
1953  bool strongestOnly) const;
1954 
1955  template <class T>
1956  bool _GetMetadata(const UsdObject &obj,
1957  const TfToken& fieldName,
1958  const TfToken &keyPath,
1959  bool useFallbacks,
1960  T* result) const {
1961  SdfAbstractDataTypedValue<T> out(result);
1962  const bool strongestOnly =
1965  return _GetMetadata(obj, fieldName, keyPath, useFallbacks, &out,
1966  strongestOnly);
1967  }
1968 
1969  template <class Composer>
1970  void _GetAttrTypeImpl(const UsdAttribute &attr,
1971  const TfToken &fieldName,
1972  bool useFallbacks,
1973  Composer *composer) const;
1974 
1975  template <class Composer>
1976  void _GetAttrVariabilityImpl(const UsdAttribute &attr,
1977  bool useFallbacks,
1978  Composer *composer) const;
1979 
1980  template <class Composer>
1981  void _GetPropCustomImpl(const UsdProperty &prop,
1982  bool useFallbacks,
1983  Composer *composer) const;
1984 
1985  template <class Composer>
1986  bool _GetSpecialPropMetadataImpl(const UsdObject &obj,
1987  const TfToken &fieldName,
1988  const TfToken &keyPath,
1989  bool useFallbacks,
1990  Composer *composer) const;
1991  template <class Composer>
1992  bool _GetMetadataImpl(const UsdObject &obj,
1993  const TfToken& fieldName,
1994  const TfToken& keyPath,
1995  bool includeFallbacks,
1996  Composer *composer) const;
1997 
1998  template <class Composer>
1999  bool _GetGeneralMetadataImpl(const UsdObject &obj,
2000  const TfToken& fieldName,
2001  const TfToken& keyPath,
2002  bool includeFallbacks,
2003  Composer *composer) const;
2004 
2005  // NOTE: The "authoredOnly" flag is not yet in use, but when we have
2006  // support for prim-based metadata fallbacks, they should be ignored when
2007  // this flag is set to true.
2008  bool _HasMetadata(const UsdObject &obj, const TfToken& fieldName,
2009  const TfToken &keyPath, bool useFallbacks) const;
2010 
2012  _ListMetadataFields(const UsdObject &obj, bool useFallbacks) const;
2013 
2014  void _GetAllMetadata(const UsdObject &obj,
2015  bool useFallbacks,
2017  bool anchorAssetPathsOnly = false) const;
2018 
2019  // --------------------------------------------------------------------- //
2020  // Default & TimeSample Resolution
2021  // --------------------------------------------------------------------- //
2022 
2023  struct _ExtraResolveInfo;
2024 
2025  // Gets the value resolve info for the given attribute. If time is provided,
2026  // the resolve info is evaluated for that specific time (which may be
2027  // default). Otherwise, if time is null, the resolve info is evaluated for
2028  // "any numeric time" and will not populate values in extraInfo that
2029  // require a specific time to be evaluated.
2030  void _GetResolveInfo(const UsdAttribute &attr,
2031  UsdResolveInfo *resolveInfo,
2032  const UsdTimeCode *time = nullptr,
2033  _ExtraResolveInfo *extraInfo = nullptr) const;
2034 
2035  // Gets the value resolve info for the given attribute using the given
2036  // resolve target. If time is provided, the resolve info is evaluated for
2037  // that specific time (which may be default). Otherwise, if time is null,
2038  // the resolve info is evaluated for "any numeric time" and will not
2039  // populate values in extraInfo that require a specific time to be
2040  // evaluated.
2041  void _GetResolveInfoWithResolveTarget(
2042  const UsdAttribute &attr,
2043  const UsdResolveTarget &resolveTarget,
2044  UsdResolveInfo *resolveInfo,
2045  const UsdTimeCode *time = nullptr,
2046  _ExtraResolveInfo *extraInfo = nullptr) const;
2047 
2048  // Shared implementation function for _GetResolveInfo and
2049  // _GetResolveInfoWithResolveTarget. The only difference between how these
2050  // two functions behave is in how they create the Usd_Resolver used for
2051  // iterating over nodes and layers, thus they provide this implementation
2052  // with the needed MakeUsdResolverFn to create the Usd_Resolver.
2053  template <class MakeUsdResolverFn>
2054  void _GetResolveInfoImpl(const UsdAttribute &attr,
2055  UsdResolveInfo *resolveInfo,
2056  const UsdTimeCode *time,
2057  _ExtraResolveInfo *extraInfo,
2058  const MakeUsdResolverFn &makeUsdResolveFn) const;
2059 
2060  struct _BracketingSamplesResolver;
2061  struct _PropertyStackResolver;
2062  struct _ResolveInfoResolver;
2063  struct _SamplesInIntervalResolver;
2064  struct _TimeSampleMapResolver;
2065 
2066  bool _GetTimeSampleMap(const UsdAttribute &attr,
2067  SdfTimeSampleMap *out,
2068  bool forFlattening=false) const;
2069 
2070  template <class Resolver, class MakeUsdResolverFn>
2071  void _GetResolvedValueAtDefaultImpl(
2072  const UsdProperty &prop,
2073  Resolver *resolver,
2074  const MakeUsdResolverFn &makeUsdResolverFn) const;
2075 
2076  template <class Resolver, class MakeUsdResolverFn>
2077  void _GetResolvedValueAtTimeImpl(
2078  const UsdProperty &prop,
2079  Resolver *resolver,
2080  const UsdTimeCode *time,
2081  const MakeUsdResolverFn &makeUsdResolverFn) const;
2082 
2083  bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2084  VtValue* result) const;
2085 
2086  USD_API
2087  bool _GetValue(UsdTimeCode time, const UsdAttribute &attr,
2088  SdfAbstractDataValue* result) const;
2089 
2090  template <class T>
2091  bool _GetValueImpl(UsdTimeCode time, const UsdAttribute &attr,
2092  Usd_Interpolator const &interpolator,
2093  T* value) const;
2094 
2095  USD_API
2096  bool _GetValueFromResolveInfo(
2097  const UsdResolveInfo &info,
2098  UsdTimeCode time, const UsdAttribute &attr,
2099  VtValue* result,
2100  const UsdResolveTarget *resolveTarget = nullptr) const;
2101 
2102  USD_API
2103  bool _GetValueFromResolveInfo(
2104  const UsdResolveInfo &info,
2105  UsdTimeCode time, const UsdAttribute &attr,
2107  const UsdResolveTarget *resolveTarget = nullptr) const;
2108 
2109  // If `resolveTarget` is not null, then `infoIn` must have been obtained
2110  // with it (see _GetResolveInfoWithResolveTarget).
2111  //
2112  // If `extraInfo` is not null, then `infoIn` must be a complete resolve info
2113  // obtained for the specific `time`.
2114  template <class T>
2115  bool _GetValueFromResolveInfoImpl(
2116  UsdTimeCode time, const UsdAttribute &attr,
2117  Usd_Interpolator const &interpolator,
2118  const UsdResolveInfo &infoIn, const UsdResolveTarget *resolveTarget,
2119  const _ExtraResolveInfo *extraInfo, T *result) const;
2120 
2121  bool _GetCompletedResolveInfo(const UsdAttribute &attr,
2122  UsdTimeCode time,
2123  const UsdResolveTarget *resolveTarget,
2124  const UsdResolveInfo &infoIn,
2125  UsdResolveInfo *infoOut,
2126  _ExtraResolveInfo *extraInfoOut) const;
2127 
2129  _GetAssetPathContext(UsdTimeCode time, const UsdAttribute &attr) const;
2130 
2131  // --------------------------------------------------------------------- //
2132  // Specialized Time Sample I/O
2133  // --------------------------------------------------------------------- //
2134 
2135  /// Gets the set of time samples authored for a given attribute
2136  /// within the \p interval. The interval may have any combination
2137  /// of open/infinite and closed/finite endpoints; it may not have
2138  /// open/finite endpoints, however, this restriction may be lifted
2139  /// in the future.
2140  /// Returns false on an error.
2141  bool _GetTimeSamplesInInterval(
2142  const UsdAttribute &attr,
2143  const GfInterval& interval,
2144  std::vector<double>* times,
2145  const UsdResolveInfo *resolveInfo=nullptr,
2146  const UsdResolveTarget *resolveTarget=nullptr) const;
2147 
2148  size_t _GetNumTimeSamples(
2149  const UsdAttribute &attr,
2150  const UsdResolveInfo *resolveInfo=nullptr,
2151  const UsdResolveTarget *resolveTarget=nullptr) const;
2152 
2153  /// Gets the bracketing times around a desiredTime. Only false on error
2154  /// or if no value exists (default or timeSamples). See
2155  /// UsdAttribute::GetBracketingTimeSamples for details.
2156  bool _GetBracketingTimeSamples(
2157  const UsdAttribute &attr,
2158  double desiredTime,
2159  double* lower,
2160  double* upper,
2161  bool* hasSamples,
2162  const UsdResolveInfo *resolveInfo=nullptr,
2163  const UsdResolveTarget *resolveTarget=nullptr) const;
2164 
2165  bool _ValueMightBeTimeVarying(const UsdAttribute &attr) const;
2166 
2167  bool _ValueMightBeTimeVaryingFromResolveInfo(
2168  const UsdResolveInfo &info,
2169  const UsdAttribute &attr) const;
2170 
2171  void _RegisterPerLayerNotices();
2172  void _RegisterResolverChangeNotice();
2173 
2174  // Helper to obtain a malloc tag string for this stage.
2175  inline char const *_GetMallocTagId() const;
2176 
2177 private:
2178  class _PendingChanges;
2179 
2180  // Change block for use by the UsdNamespaceEditor to allow it to indicate
2181  // to its dependent stages what the expected namespace edits are when the
2182  // stages handles notices from the changes the namespace editor performs.
2183  // The stage uses this provide additional information about prim resyncs
2184  // related to namespace edits in the ObjectsChanged notice it sends.
2185  class _NamespaceEditsChangeBlock {
2186  public:
2187  // Info about an expected namespace edit change from UsdNamespaceEditor.
2188  // This includes the original pre-edit prim stack of the prim at the old
2189  // path which is used to determine if the prim at the new path has the
2190  // same composed contents after the edits as the prim had originally at
2191  // the old path before the edits.
2195  SdfPrimSpecHandleVector oldPrimStack;
2196  };
2197  using ExpectedNamespaceEditChangeVector =
2198  std::vector<ExpectedNamespaceEditChange>;
2199 
2200  _NamespaceEditsChangeBlock(const UsdStagePtr &stage,
2201  ExpectedNamespaceEditChangeVector &&expectedChanges);
2202  _NamespaceEditsChangeBlock(_NamespaceEditsChangeBlock &&);
2203  ~_NamespaceEditsChangeBlock();
2204 
2205  private:
2206  UsdStagePtr _stage;
2207  std::unique_ptr<_PendingChanges> _localPendingChanges;
2208  };
2209 
2210  // The 'pseudo root' prim.
2211  Usd_PrimDataPtr _pseudoRoot;
2212 
2213  // The stage's root layer.
2214  SdfLayerRefPtr _rootLayer;
2215 
2216  // Every UsdStage has an implicit, in-memory session layer.
2217  // This is to allow for runtime overrides such as variant selections.
2218  SdfLayerRefPtr _sessionLayer;
2219 
2220  // The stage's EditTarget.
2221  UsdEditTarget _editTarget;
2222  bool _editTargetIsLocalLayer;
2223 
2224  std::unique_ptr<PcpCache> _cache;
2225  std::unique_ptr<Usd_ClipCache> _clipCache;
2226  std::unique_ptr<Usd_InstanceCache> _instanceCache;
2227 
2228  TfHashMap<TfToken, TfToken, TfHash> _invalidPrimTypeToFallbackMap;
2229 
2230  size_t _usedLayersRevision;
2231 
2232  // A concurrent map from Path to Prim, for fast random access.
2233  struct _TbbHashEq {
2234  inline bool equal(SdfPath const &l, SdfPath const &r) const {
2235  return l == r;
2236  }
2237  inline size_t hash(SdfPath const &path) const {
2238  return path.GetHash();
2239  }
2240  };
2241  using PathToNodeMap = tbb::concurrent_hash_map<
2242  SdfPath, Usd_PrimDataIPtr, _TbbHashEq>;
2243  PathToNodeMap _primMap;
2244 
2245  // The interpolation type used for all attributes on the stage.
2246  UsdInterpolationType _interpolationType;
2247 
2248  typedef std::vector<
2249  std::pair<SdfLayerHandle, TfNotice::Key> > _LayerAndNoticeKeyVec;
2250  _LayerAndNoticeKeyVec _layersAndNoticeKeys;
2251  size_t _lastChangeSerialNumber;
2252 
2253  TfNotice::Key _resolverChangeKey;
2254 
2255  // Data for pending change processing.
2256  _PendingChanges* _pendingChanges;
2257 
2258  std::optional<WorkDispatcher> _dispatcher;
2259 
2260  // To provide useful aggregation of malloc stats, we bill everything
2261  // for this stage - from all access points - to this tag.
2262  std::unique_ptr<std::string> _mallocTagID;
2263 
2264  // The state used when instantiating the stage.
2265  const InitialLoadSet _initialLoadSet;
2266 
2267  // The population mask that applies to this stage.
2268  UsdStagePopulationMask _populationMask;
2269 
2270  // The load rules that apply to this stage.
2271  UsdStageLoadRules _loadRules;
2272 
2273  bool _isClosingStage;
2274  bool _isWritingFallbackPrimTypes;
2275 
2276  friend class UsdAPISchemaBase;
2277  friend class UsdAttribute;
2278  friend class UsdAttributeQuery;
2279  friend class UsdEditTarget;
2280  friend class UsdInherits;
2281  friend class UsdNamespaceEditor;
2282  friend class UsdObject;
2283  friend class UsdPrim;
2284  friend class UsdProperty;
2285  friend class UsdRelationship;
2286  friend class UsdSpecializes;
2287  friend class UsdVariantSet;
2288  friend class UsdVariantSets;
2289  friend class Usd_AssetPathContext;
2290  friend class Usd_FlattenAccess;
2291  friend class Usd_PcpCacheAccess;
2292  friend class Usd_PrimData;
2293  friend class Usd_StageOpenRequest;
2294  friend class Usd_TypeQueryAccess;
2295  template <class T> friend struct Usd_AttrGetValueHelper;
2297  template <class RefsOrPayloadsEditorType, class RefsOrPayloadsProxyType>
2298  friend struct Usd_ListEditImpl;
2299 };
2300 
2301 template<typename T>
2302 bool
2304 {
2305  VtValue result;
2306  if (!GetMetadata(key, &result)){
2307  return false;
2308  }
2309 
2310  if (result.IsHolding<T>()){
2311  *value = result.UncheckedGet<T>();
2312  return true;
2313  } else {
2314  TF_CODING_ERROR("Requested type %s for stage metadatum %s does not"
2315  " match retrieved type %s",
2316  ArchGetDemangled<T>().c_str(),
2317  key.GetText(),
2318  result.GetTypeName().c_str());
2319  return false;
2320  }
2321 }
2322 
2323 template<typename T>
2324 bool
2325 UsdStage::GetMetadataByDictKey(const TfToken& key, const TfToken &keyPath,
2326  T* value) const
2327 {
2328  VtValue result;
2329  if (!GetMetadataByDictKey(key, keyPath, &result)){
2330  return false;
2331  }
2332 
2333  if (result.IsHolding<T>()){
2334  *value = result.UncheckedGet<T>();
2335  return true;
2336  } else {
2337  TF_CODING_ERROR("Requested type %s for stage metadatum %s[%s] does not"
2338  " match retrieved type %s",
2339  ArchGetDemangled<T>().c_str(),
2340  key.GetText(),
2341  keyPath.GetText(),
2342  result.GetTypeName().c_str());
2343  return false;
2344  }
2345 }
2346 
2348 
2349 #endif //PXR_USD_USD_STAGE_H
2350 
TfDelegatedCountPtr< Usd_PrimData > Usd_PrimDataIPtr
UsdLoadPolicy
Definition: common.h:99
Definition: layer.h:81
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
Definition: strutil.h:500
GT_API const UT_StringHolder filename
USD_API void MuteAndUnmuteLayers(const std::vector< std::string > &muteLayers, const std::vector< std::string > &unmuteLayers)
virtual USD_API ~UsdStage()
static SDF_API const SdfPath & AbsoluteRootPath()
USD_API double GetFramesPerSecond() const
#define USD_API
Definition: api.h:23
USD_API bool HasDefaultPrim() const
USD_API UsdPrim GetPrimAtPath(const SdfPath &path) const
T const & UncheckedGet() const &
Definition: value.h:1046
USD_API void SetInterpolationType(UsdInterpolationType interpolationType)
USD_API std::vector< UsdPrim > GetPrototypes() const
Returns all native instancing prototype prims.
USD_API void Save()
USD_API ArResolverContext GetPathResolverContext() const
USD_API double GetStartTimeCode() const
static USD_API UsdStageRefPtr CreateInMemory(InitialLoadSet load=LoadAll)
USD_API bool HasMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
GT_API const UT_StringHolder time
bool GetMetadata(const TfToken &key, T *value) const
Definition: stage.h:2303
USD_API UsdPrimRange Traverse()
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
USD_API bool Export(const std::string &filename, bool addSourceFileComment=true, const SdfLayer::FileFormatArguments &args=SdfLayer::FileFormatArguments()) const
GLuint start
Definition: glcorearb.h:475
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
std::map< std::string, std::string > FileFormatArguments
Definition: layer.h:107
USD_API UsdPrim CreateClassPrim(const SdfPath &rootPrimPath)
#define TF_CODING_ERROR
USD_API bool ClearMetadata(const TfToken &key) const
USD_API UsdRelationship GetRelationshipAtPath(const SdfPath &path) const
USD_API SdfPathSet GetLoadSet()
USD_API void Unload(const SdfPath &path=SdfPath::AbsoluteRootPath())
Definition: cache.h:76
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
Definition: ImathFun.h:105
USD_API bool IsLayerMuted(const std::string &layerIdentifier) const
USD_API void SetDefaultPrim(const UsdPrim &prim)
**But if you need a result
Definition: thread.h:622
USD_API void WriteFallbackPrimTypes()
InitialLoadSet
Definition: stage.h:148
USD_API void MuteLayer(const std::string &layerIdentifier)
friend struct Usd_ListEditImpl
Definition: stage.h:2298
USD_API SdfPathSet FindLoadable(const SdfPath &rootPath=SdfPath::AbsoluteRootPath())
SDF_DECLARE_HANDLES(SdfLayer)
static USD_API void SetGlobalVariantFallbacks(const PcpVariantFallbackMap &fallbacks)
size_t GetHash() const
Equality operator.
Definition: path.h:966
USD_API const UsdEditTarget & GetEditTarget() const
Return the stage's EditTarget.
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
GLenum GLint GLint GLint GLint GLuint dstName
Definition: glcorearb.h:2510
USD_API double GetEndTimeCode() const
USD_API SdfLayerRefPtr Flatten(bool addSourceFileComment=true) const
USD_API UsdPrim GetDefaultPrim() const
USD_API void SetColorConfiguration(const SdfAssetPath &colorConfig) const
USD_API TfToken GetColorManagementSystem() const
Definition: token.h:70
bool GetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, T *value) const
Definition: stage.h:2325
USD_API UsdEditTarget GetEditTargetForLocalLayer(size_t i)
friend class Usd_AssetPathContext
Definition: stage.h:2289
USD_API SdfLayerHandleVector GetLayerStack(bool includeSessionLayers=true) const
USD_API void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet, UsdLoadPolicy policy=UsdLoadWithDescendants)
USD_API SdfLayerHandle GetSessionLayer() const
Return this stage's root session layer.
GLint GLuint mask
Definition: glcorearb.h:124
Definition: prim.h:116
USD_API bool HasAuthoredMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
SdfSpecifier
Definition: types.h:103
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USD_API bool HasAuthoredMetadata(const TfToken &key) const
Definition: path.h:280
static USD_API UsdStageRefPtr CreateNew(const std::string &identifier, InitialLoadSet load=LoadAll)
USD_API UsdProperty GetPropertyAtPath(const SdfPath &path) const
USD_API bool RemovePrim(const SdfPath &path)
USD_API void SetColorManagementSystem(const TfToken &cms) const
friend class Usd_TypeQueryAccess
Definition: stage.h:2294
std::map< class TfToken, VtValue, TfDictionaryLessThan > UsdMetadataValueMap
Definition: common.h:64
char const * GetText() const
Definition: token.h:179
friend struct Usd_AttrGetValueHelper
Definition: stage.h:2295
static USD_API UsdStageRefPtr Open(const std::string &filePath, InitialLoadSet load=LoadAll)
USD_API bool HasAuthoredTimeCodeRange() const
USD_API void SetLoadRules(UsdStageLoadRules const &rules)
std::vector< PcpErrorBasePtr > PcpErrorVector
Definition: errors.h:65
USD_API bool SetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, VtValueRef value) const
USD_API bool SetMetadata(const TfToken &key, VtValueRef value) const
USD_API void SetEditTarget(const UsdEditTarget &editTarget)
USD_API bool HasMetadata(const TfToken &key) const
USD_API void SetFramesPerSecond(double framesPerSecond) const
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
Definition: path.h:199
SdfVariability
Definition: types.h:159
USD_API PcpErrorVector GetCompositionErrors() const
USD_API bool HasLocalLayer(const SdfLayerHandle &layer) const
USD_API void UnmuteLayer(const std::string &layerIdentifier)
USD_API std::string ResolveIdentifierToEditTarget(std::string const &identifier) const
USD_API void SetEndTimeCode(double)
USD_API void Reload()
USD_API UsdPrimRange TraverseAll()
std::vector< std::pair< SdfLayerHandle, SdfChangeList > > SdfLayerChangeListVec
Definition: changeList.h:25
USD_API void SetTimeCodesPerSecond(double timeCodesPerSecond) const
USD_API void ClearDefaultPrim()
USD_API SdfLayerHandle GetRootLayer() const
Return this stage's root layer.
SdfSpecType
Definition: types.h:71
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
Definition: strutil.h:493
USD_API UsdInterpolationType GetInterpolationType() const
friend class Usd_FlattenAccess
Definition: stage.h:2290
static USD_API bool IsSupportedFile(const std::string &filePath)
friend class Usd_PcpCacheAccess
Definition: stage.h:2291
USD_API UsdObject GetObjectAtPath(const SdfPath &path) const
bool IsHolding() const
Definition: value.h:1002
UsdStageLoadRules const & GetLoadRules() const
Definition: stage.h:637
Load all loadable prims.
Definition: stage.h:150
friend struct Usd_AttrGetUntypedValueHelper
Definition: stage.h:2296
USD_API UsdPrim Load(const SdfPath &path=SdfPath::AbsoluteRootPath(), UsdLoadPolicy policy=UsdLoadWithDescendants)
static USD_API PcpVariantFallbackMap GetGlobalVariantFallbacks()
Get the global variant fallback preferences used in new UsdStages.
VT_API std::string GetTypeName() const
Return the type name of the held typeid.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API SdfAssetPath GetColorConfiguration() const
USD_API const std::vector< std::string > & GetMutedLayers() const
Returns a vector of all layers that have been muted on this stage.
USD_API UsdPrim GetPseudoRoot() const
**If you just want to fire and args
Definition: thread.h:618
Definition: type.h:47
friend class Usd_StageOpenRequest
Definition: stage.h:2293
UsdInterpolationType
Definition: interpolation.h:27
OIIO_UTIL_API const char * c_str(string_view str)
USD_API UsdPrim DefinePrim(const SdfPath &path, const TfToken &typeName=TfToken())
UsdStagePopulationMask GetPopulationMask() const
Return this stage's population mask.
Definition: stage.h:654
GLboolean r
Definition: glcorearb.h:1222
USD_API UsdPrim OverridePrim(const SdfPath &path)
static USD_API void GetColorConfigFallbacks(SdfAssetPath *colorConfiguration, TfToken *colorManagementSystem)
static USD_API UsdStageRefPtr OpenMasked(const std::string &filePath, UsdStagePopulationMask const &mask, InitialLoadSet load=LoadAll)
USD_API double GetTimeCodesPerSecond() const
std::map< double, VtValue > SdfTimeSampleMap
A map from sample times to sample values.
Definition: types.h:280
USD_API void SetPopulationMask(UsdStagePopulationMask const &mask)
Set this stage's population mask and recompose the stage.
USD_API void SetStartTimeCode(double)
USD_API bool ClearMetadataByDictKey(const TfToken &key, const TfToken &keyPath) const
USD_API bool ExportToString(std::string *result, bool addSourceFileComment=true) const
USD_API void ExpandPopulationMask(Usd_PrimFlagsPredicate const &traversalPredicate, std::function< bool(UsdRelationship const &)> const &relPred=nullptr, std::function< bool(UsdAttribute const &)> const &attrPred=nullptr)
Definition: value.h:89
USD_API void SaveSessionLayers()
static USD_API void SetColorConfigFallbacks(const SdfAssetPath &colorConfiguration, const TfToken &colorManagementSystem)
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
Definition: types.h:189
Load a prim plus all its descendants.
Definition: common.h:101
USD_API SdfLayerHandleVector GetUsedLayers(bool includeClipLayers=true) const
USD_API UsdAttribute GetAttributeAtPath(const SdfPath &path) const
Load no loadable prims.
Definition: stage.h:151