stageSceneIndex.h
1 //
2 // Copyright 2022 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_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
8 #define PXR_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/usdImaging/usdImaging/api.h"
13 #include "pxr/usdImaging/usdImaging/dataSourceStageGlobals.h"
15 #include "pxr/usdImaging/usdImaging/types.h"
16 
17 #include "pxr/imaging/hd/sceneIndex.h"
18 
19 #include "pxr/usd/usd/notice.h"
20 #include "pxr/usd/usd/stage.h"
21 
22 #include <mutex>
23 #include <set>
24 
25 PXR_NAMESPACE_OPEN_SCOPE
26 
27 using UsdImagingPrimAdapterSharedPtr =
28  std::shared_ptr<class UsdImagingPrimAdapter>;
29 class UsdImaging_AdapterManager;
30 
32 
42 {
43 public:
44  static UsdImagingStageSceneIndexRefPtr New(
45  HdContainerDataSourceHandle const &inputArgs = nullptr) {
46  return TfCreateRefPtr(new UsdImagingStageSceneIndex(inputArgs));
47  }
48 
49  USDIMAGING_API
51 
52  // ------------------------------------------------------------------------
53  // Scene index API
54 
55  USDIMAGING_API
56  HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
57 
58  USDIMAGING_API
59  SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
60 
63 
67  USDIMAGING_API
68  void SetStage(UsdStageRefPtr stage) override;
69 
73  USDIMAGING_API
74  void SetTime(UsdTimeCode time) override;
75 
80  USDIMAGING_API
81  void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps);
82 
84  USDIMAGING_API
85  UsdTimeCode GetTime() const override;
86 
92  USDIMAGING_API
93  void ApplyPendingUpdates() override;
94 
96 
97 private:
98  USDIMAGING_API
99  UsdImagingStageSceneIndex(HdContainerDataSourceHandle const &inputArgs);
100 
101  Usd_PrimFlagsPredicate _GetPrimPredicate() const;
102 
103  void _ApplyPendingResyncs();
104  void _ComputeDirtiedEntries(
105  const std::map<SdfPath, TfTokenVector> &pathToUsdProperties,
106  SdfPathVector * primPathsToResync,
107  UsdImagingPropertyInvalidationType invalidationType,
108  HdSceneIndexObserver::DirtiedPrimEntries * dirtiedPrims) const;
109 
110  class _StageGlobals : public UsdImagingDataSourceStageGlobals
111  {
112  public:
113  // Datasource-facing API
114  void FlagAsTimeVarying(
115  const SdfPath & hydraPath,
116  const HdDataSourceLocator & locator) const override;
117 
118  void FlagAsAssetPathDependent(
119  const SdfPath & usdPath) const override;
120 
121  UsdTimeCode GetTime() const override;
122 
123  // Scene index-facing API
124  void SetTime(UsdTimeCode time,
126 
127  void RemoveAssetPathDependentsUnder(const SdfPath &path);
128 
129  void InvalidateAssetPathDependentsUnder(
130  const SdfPath &path,
131  std::vector<SdfPath> *primsToInvalidate,
132  std::map<SdfPath, TfTokenVector> *propertiesToInvalidate) const;
133 
134  void Clear();
135 
136  private:
137  struct _PathHashCompare {
138  static bool equal(const SdfPath &a, const SdfPath &b) {
139  return a == b;
140  }
141  static size_t hash(const SdfPath &p) {
142  return hash_value(p);
143  }
144  };
145  using _VariabilityMap = tbb::concurrent_hash_map<SdfPath,
146  HdDataSourceLocatorSet, _PathHashCompare>;
147  mutable _VariabilityMap _timeVaryingLocators;
148 
149  using _AssetPathDependentsSet = std::set<SdfPath>;
150  mutable _AssetPathDependentsSet _assetPathDependents;
151  mutable std::mutex _assetPathDependentsMutex;
152 
153  UsdTimeCode _time;
154  };
155 
156  const bool _includeUnloadedPrims;
157 
158  UsdStageRefPtr _stage;
159  _StageGlobals _stageGlobals;
160 
161  void _SetTime(UsdTimeCode time);
162 
163  // Population
164  void _Populate();
165  void _PopulateSubtree(UsdPrim subtreeRoot,
167 
168  // Edit processing
169  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const& notice,
170  UsdStageWeakPtr const& sender);
171  TfNotice::Key _objectsChangedNoticeKey;
172 
173  // Keep track of populated paths for use in _ApplyPendingResyncs().
174  SdfPathSet _populatedPaths;
175 
176  // Note: resync paths mean we remove the whole subtree and repopulate.
177  SdfPathVector _usdPrimsToResync;
178  // Property changes get converted into PrimsDirtied messages.
179  std::map<SdfPath, TfTokenVector> _usdPropertiesToUpdate;
180  std::map<SdfPath, TfTokenVector> _usdPropertiesToResync;
181 
182  using _PrimAdapterPair = std::pair<UsdPrim, UsdImagingPrimAdapterSharedPtr>;
183  using _PrimAdapterPairVec = std::vector<_PrimAdapterPair>;
184  _PrimAdapterPairVec _FindResponsibleAncestors(const UsdPrim &prim) const;
185  bool _HasResponsibleAncestor(const UsdPrim &prim) const;
186 
187  std::unique_ptr<UsdImaging_AdapterManager> const _adapterManager;
188 };
189 
190 PXR_NAMESPACE_CLOSE_SCOPE
191 
192 #endif
Handle-object returned by TfNotice::Register().
Definition: notice.h:243
USDIMAGING_API void SetTime(UsdTimeCode time) override
Set the time, and call PrimsDirtied for any time-varying attributes.
A scene index consuming a UsdStage.
An interface for initial scene indices that populate the Hydra scene with prims and data sources from...
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
Represents an object that can identify the location of a data source.
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:73
This class is used as a context object with global stage information, that gets passed down to dataso...
USDIMAGING_API void ApplyPendingUpdates() override
Apply queued stage edits to imaging scene.
USDIMAGING_API void SetStage(UsdStageRefPtr stage) override
Set the USD stage to pull data from.
Notice sent in response to authored changes that affect UsdObjects.
Definition: notice.h:111
Represents a set of data source locators closed under descendancy.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:116
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
USDIMAGING_API UsdTimeCode GetTime() const override
Return the current time.
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58