Loading...
Searching...
No Matches
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
19PXR_NAMESPACE_OPEN_SCOPE
20
21using UsdImagingSceneIndexAppendCallback =
22 std::function<
23 HdSceneIndexBaseRefPtr(HdSceneIndexBaseRefPtr const &)>;
24
26TF_DECLARE_REF_PTRS(HdNoticeBatchingSceneIndex);
31
38{
39public:
41 using SceneIndexAppendCallback = std::function<
42 HdSceneIndexBaseRefPtr(
43 HdSceneIndexBaseRefPtr const &,
44 HdContainerDataSourceHandle const &sceneIndexCreateArgs)>;
45
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) {
80 if (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
143
145 const HdNoticeBatchingSceneIndexRefPtr &
147 return _postInstancingNoticeBatchingSceneIndex;
148 }
149
150private:
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
205PXR_NAMESPACE_CLOSE_SCOPE
206
207#endif
A mix-in class for scene indices that implement their behaviour by creating other scene indices (inte...
Abstract interface to scene data.
Definition sceneIndex.h:55
HD_API void _SendPrimsRemoved(const HdSceneIndexObserver::RemovedPrimEntries &entries)
Notify attached observers of prims removed from the scene.
HD_API void _SendPrimsRenamed(const HdSceneIndexObserver::RenamedPrimEntries &entries)
Notify attached observers of prims (and their descendents) which have been renamed or reparented.
HD_API void _SendPrimsAdded(const HdSceneIndexObserver::AddedPrimEntries &entries)
Notify attached observers of prims added to the scene.
HD_API void _SendPrimsDirtied(const HdSceneIndexObserver::DirtiedPrimEntries &entries)
Notify attached observers of datasource invalidations from the scene.
Observer of scene data.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
A scene index encapsulating the chain of scene indices (resolving, e.g., USD native instancing) that ...
Definition sceneIndex.h:38
static UsdImagingSceneIndexRefPtr New(HdContainerDataSourceHandle const &sceneIndexCreateArgs, const SceneIndexAppendCallbacks &sceneIndexAppendCallbacks={})
Create the chain of scene indices.
Definition sceneIndex.h:65
std::function< HdSceneIndexBaseRefPtr( HdSceneIndexBaseRefPtr const &, HdContainerDataSourceHandle const &sceneIndexCreateArgs)> SceneIndexAppendCallback
A callback to insert additional scene indices into the UsdImaging chain.
Definition sceneIndex.h:41
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
static UsdImagingSceneIndexRefPtr New(HdContainerDataSourceHandle const &sceneIndexCreateArgs, const UsdImagingSceneIndexAppendCallback &overridesSceneIndexCallback)
Definition sceneIndex.h:75
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
const HdNoticeBatchingSceneIndexRefPtr & GetPostInstancingNoticeBatchingSceneIndex() const
Can be used to batch notices.
Definition sceneIndex.h:146
USDIMAGING_API void ClearSelection()
Reset the scene index selection state.
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...
SceneIndexAppendCallback overridesSceneIndexCallback
Inserts scene indices right after the stage scene index (and its material caching scene index).
Definition sceneIndex.h:57
Callbacks a client can use to insert scene indices at specific points in the UsdImaging chain.
Definition sceneIndex.h:54
A simple scene index adding HdSelectionsSchema to all prims selected with AddSelection.
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
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition timeCode.h:73
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition declarePtrs.h:58
Small struct representing a 'prim' in the Hydra scene index.
Definition sceneIndex.h:36
Some scene indices in the chain of filtering scene indices created by UsdImagingCreateSceneIndices.