sceneIndex.h
1 //
2 // Copyright 2026 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_SCENE_INDEX_H
8 #define PXR_USD_IMAGING_USD_IMAGING_SCENE_INDEX_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/usd/usd/timeCode.h"
13 
14 #include "pxr/usdImaging/usdImaging/api.h"
15 
16 #include "pxr/imaging/hd/filteringSceneIndex.h"
17 #include "pxr/imaging/hd/sceneIndex.h"
18 
19 PXR_NAMESPACE_OPEN_SCOPE
20 
21 using UsdImagingSceneIndexAppendCallback =
22  std::function<
23  HdSceneIndexBaseRefPtr(HdSceneIndexBaseRefPtr const &)>;
24 
26 TF_DECLARE_REF_PTRS(HdNoticeBatchingSceneIndex);
31 
38 {
39 public:
41  using SceneIndexAppendCallback = std::function<
42  HdSceneIndexBaseRefPtr(
43  HdSceneIndexBaseRefPtr const &,
44  HdContainerDataSourceHandle const &sceneIndexCreateArgs)>;
45 
54  {
58  };
59 
65  static UsdImagingSceneIndexRefPtr New(
66  HdContainerDataSourceHandle const &sceneIndexCreateArgs,
67  const SceneIndexAppendCallbacks &sceneIndexAppendCallbacks = {})
68  {
69  return TfCreateRefPtr(
71  sceneIndexCreateArgs, sceneIndexAppendCallbacks));
72  }
73 
75  static UsdImagingSceneIndexRefPtr New(
76  HdContainerDataSourceHandle const &sceneIndexCreateArgs,
77  const UsdImagingSceneIndexAppendCallback &
78  overridesSceneIndexCallback) {
79  SceneIndexAppendCallbacks callbacks;
80  if (overridesSceneIndexCallback) {
81  callbacks.overridesSceneIndexCallback =
82  [overridesSceneIndexCallback](
83  HdSceneIndexBaseRefPtr const &inputScene,
84  HdContainerDataSourceHandle const &) {
85  return overridesSceneIndexCallback(inputScene);
86  };
87  }
88  return New(sceneIndexCreateArgs, callbacks);
89  }
90 
91  USDIMAGING_API
93 
94  // ------------------------------------------------------------------------
95  // (Encapsulating) Scene index API
96 
97  USDIMAGING_API
98  HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
99 
100  USDIMAGING_API
101  SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
102 
103  USDIMAGING_API
104  HdSceneIndexBaseRefPtrVector GetEncapsulatedScenes() const override;
105 
106  // ------------------------------------------------------------------------
107  // App-facing API
108 
109  // Set the USD stage to pull data from. Note that this will delete all
110  // scene index prims and reset stage global data.
111  USDIMAGING_API
112  void SetStage(UsdStageRefPtr stage);
113 
114  // Set the time, and call PrimsDirtied for any time-varying attributes.
115  //
116  // PrimsDirtied is only called if the time is different from the last call
117  // or forceDirtyingTimeDeps is true.
118  USDIMAGING_API
119  void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps = false);
120 
121  // Return the current time.
122  USDIMAGING_API
123  UsdTimeCode GetTime() const;
124 
125  // Apply queued stage edits to imaging scene.
126  // If the USD stage is edited while the scene index is pulling from it,
127  // those edits get queued and deferred. Calling ApplyPendingUpdates will
128  // turn resync requests into PrimsAdded/PrimsRemoved, and property changes
129  // into PrimsDirtied.
130  USDIMAGING_API
131  void ApplyPendingUpdates();
132 
137  USDIMAGING_API
138  void AddSelection(const SdfPath &path);
139 
141  USDIMAGING_API
142  void ClearSelection();
143 
145  const HdNoticeBatchingSceneIndexRefPtr &
147  return _postInstancingNoticeBatchingSceneIndex;
148  }
149 
150 private:
151  class _Observer : public HdSceneIndexObserver
152  {
153  public:
154  _Observer(UsdImagingSceneIndex *owner)
155  : _owner(owner) {}
156 
157  void PrimsAdded(
158  const HdSceneIndexBase &sender,
159  const AddedPrimEntries &entries) override
160  {
161  _owner->_SendPrimsAdded(entries);
162  }
163 
164  void PrimsRemoved(
165  const HdSceneIndexBase &sender,
166  const RemovedPrimEntries &entries) override
167  {
168  _owner->_SendPrimsRemoved(entries);
169  }
170 
171  void PrimsDirtied(
172  const HdSceneIndexBase &sender,
173  const DirtiedPrimEntries &entries) override
174  {
175  _owner->_SendPrimsDirtied(entries);
176  }
177 
178  void PrimsRenamed(
179  const HdSceneIndexBase &sender,
180  const RenamedPrimEntries &entries) override
181  {
182  _owner->_SendPrimsRenamed(entries);
183  }
184  private:
185  UsdImagingSceneIndex * const _owner;
186  };
187 
188  USDIMAGING_API
190  HdContainerDataSourceHandle const &sceneIndexCreateArgs,
191  const SceneIndexAppendCallbacks &sceneIndexAppendCallbacks);
192 
193  USDIMAGING_API
195  const UsdImagingSceneIndices &sceneIndices);
196 
197  UsdImagingStageSceneIndexRefPtr _stageSceneIndex;
198  HdNoticeBatchingSceneIndexRefPtr _postInstancingNoticeBatchingSceneIndex;
199  UsdImagingSelectionSceneIndexRefPtr _selectionSceneIndex;
200  HdSceneIndexBaseRefPtr _finalSceneIndex;
201 
202  _Observer _observer;
203 };
204 
205 PXR_NAMESPACE_CLOSE_SCOPE
206 
207 #endif
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
A scene index consuming a UsdStage.
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:135
USDIMAGING_API void AddSelection(const SdfPath &path)
Given a path (including usd proxy path inside a native instance) of a USD prim, determine the corresp...
A mix-in class for scene indices that implement their behaviour by creating other scene indices (inte...
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
Some scene indices in the chain of filtering scene indices created by UsdImagingCreateSceneIndices.
Definition: sceneIndices.h:56
USDIMAGING_API void ClearSelection()
Reset the scene index selection state.
Observer of scene data.
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:73
Abstract interface to scene data.
Definition: sceneIndex.h:54
A simple scene index adding HdSelectionsSchema to all prims selected with AddSelection.
const HdNoticeBatchingSceneIndexRefPtr & GetPostInstancingNoticeBatchingSceneIndex() const
Can be used to batch notices.
Definition: sceneIndex.h:146
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
std::function< HdSceneIndexBaseRefPtr(HdSceneIndexBaseRefPtr const &, HdContainerDataSourceHandle const &sceneIndexCreateArgs)> SceneIndexAppendCallback
A callback to insert additional scene indices into the UsdImaging chain.
Definition: sceneIndex.h:44
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
Callbacks a client can use to insert scene indices at specific points in the UsdImaging chain.
Definition: sceneIndex.h:53
static UsdImagingSceneIndexRefPtr New(HdContainerDataSourceHandle const &sceneIndexCreateArgs, const UsdImagingSceneIndexAppendCallback &overridesSceneIndexCallback)
Definition: sceneIndex.h:75
SceneIndexAppendCallback overridesSceneIndexCallback
Inserts scene indices right after the stage scene index (and its material caching scene index).
Definition: sceneIndex.h:57
static UsdImagingSceneIndexRefPtr New(HdContainerDataSourceHandle const &sceneIndexCreateArgs, const SceneIndexAppendCallbacks &sceneIndexAppendCallbacks={})
Create the chain of scene indices.
Definition: sceneIndex.h:65
A scene index encapsulating the chain of scene indices (resolving, e.g., USD native instancing) that ...
Definition: sceneIndex.h:36