HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
piPrototypePropagatingSceneIndex.h
Go to the documentation of this file.
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_PI_PROTOTYPE_PROPAGATING_SCENE_INDEX_H
8 #define PXR_USD_IMAGING_USD_IMAGING_PI_PROTOTYPE_PROPAGATING_SCENE_INDEX_H
9 
11 
13 
15 
17 
18 namespace UsdImagingPiPrototypePropagatingSceneIndex_Impl
19 {
20 using _ContextSharedPtr = std::shared_ptr<struct _Context>;
21 using _InstancerObserverUniquePtr = std::unique_ptr<class _InstancerObserver>;
22 }
23 
24 /// \class UsdImagingPiPrototypePropagatingSceneIndex
25 ///
26 /// A scene index translating USD point instancers into Hydra instancers.
27 ///
28 /// It applies various USD semantics and populates the "instancedBy" schema,
29 /// including the prototypeRoot data source which is needed by the USD native
30 /// instancing scene index.
31 ///
32 /// To achieve various USD behaviors, it has a (recursive) instancer observer
33 /// that inserts copies of prototypes processed through the prototype scene
34 /// index into appropriate places in namespace.
35 ///
36 /// ---------------------------------------------------------------------------
37 ///
38 /// Example 1:
39 ///
40 /// USD:
41 ///
42 /// def PointInstancer "MyInstancer"
43 /// {
44 /// rel prototypes = [
45 /// </MyInstancer/MyPrototypes/MyPrototype> ]
46 /// def Scope "MyPrototypes"
47 /// {
48 /// def Xform "MyPrototype"
49 /// {
50 /// def Sphere "MySphere"
51 /// {
52 /// }
53 /// }
54 /// }
55 /// }
56 ///
57 /// Note that USD says that no geometry under a PointInstancer is drawn unless
58 /// it is targeted by a point instancer's prototype relationship.
59 ///
60 /// Inputs of the PointPropagatingSceneIndex:
61 ///
62 /// * _Context::mergingSceneIndex
63 /// (HdMergingSceneIndex)
64 /// * _Context::instancerSceneIndex
65 /// (HdRetainedSceneIndex, will rewrite prototypes of /MyInstancer to
66 /// [ /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55 ] )
67 /// * UsdImaging_PiPrototypeSceneIndex
68 /// (inserted by PointPropagatingSceneIndex::_instancerOberver
69 /// which was constructed with
70 /// instancer = ""
71 /// prototypeRoot = /
72 /// rerootedPrototypeRoot = /)
73 /// instancer = ""
74 /// prototypeRoot = /
75 /// * _Context::inputSceneIndex
76 /// (argument to PointPropagatingSceneIndex,
77 /// typically UsdImagingStageSceneIndex, maybe followed by
78 /// other filtering scene indices)
79 /// * UsdImagingRerootingSceneIndex
80 /// (inserted recursively by PointPropagatingSceneIndex::_instancerObserver::_subinstancerObservers
81 /// which was constructed with
82 /// instancer = /MyInstancer
83 /// prototypeRoot = /MyInstancer/MyPrototypes/MyPrototype
84 /// rerootedPrototypeRoot = /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55)
85 /// srcPrefix = /MyInstancer/MyPrototypes/MyPrototype
86 /// dstPrefix = /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55
87 /// * UsdImaging_PiPrototypeSceneIndex
88 /// instancer = /MyInstancer
89 /// prototypeRoot = /MyInstancer/MyPrototypes/MyPrototype
90 /// * UsdImagingRerootingSCeneIndex
91 /// srcPrefix = dstPrefix = /MyInstancer/MyPrototypes/MyPrototype
92 /// * _Context::inputSceneIndex
93 ///
94 /// PointPropagatingSceneIndex:
95 ///
96 /// /MyInstancer
97 /// primType: instancer
98 /// dataSource:
99 /// setting # [1]
100 /// prototypes = [/MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55]
101 ///
102 /// /MyInstancer/MyPrototypes
103 /// /MyInstancer/MyPrototypes/MyPrototype
104 /// /MyInstancer/MyPrototypes/MyPrototype/MySphere
105 /// primType: "" # [2]
106 /// dataSource: unchanged
107 ///
108 /// /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55 # [3]
109 /// primType: unchanged (from /MyInstancer/MyPrototypes/MyPrototype)
110 /// dataSource: (from /MyInstancer/MyPrototypes/MyPrototype)
111 /// setting # [4]
112 /// xform:resetXformStack = true
113 /// instancedBy:PrototypeRoot = /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55
114 /// instancedBy:paths = /MyInstancer
115 ///
116 /// /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55/MySphere
117 /// dataSource: (from /MyInstancer/MyPrototypes/MyPrototype/MySphere)
118 /// setting # [5]
119 /// instancedBy:PrototypeRoot = /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55
120 /// instancedBy:paths = /MyInstancer
121 ///
122 /// [1] Set through the retained scene index _Context::instancerSceneIndex to
123 /// point to the re-rooted copy of the prototype.
124 /// The prim entry was inserted by the (recursive) instancer observer
125 /// (instantiated with instancer = empty,
126 /// prototypeRoot = rerootedPrototypeRoot = /).
127 ///
128 /// [2] Forced by the prototype scene index (instantiated with
129 /// instancer = empty and prototypeRoot = /).
130 /// In general, the prototype scene index forces the prim
131 /// type to empty for all descendants of instancers within the prototypeRoot.
132 ///
133 /// [3] The re-rooted copy of /MyInstancer/MyPrototypes/MyPrototype inserted
134 /// by the instancer observer (instantiated with instancer = /MyInstancer,
135 /// prototypeRoot = /MyInstancer/MyPrototypes/MyPrototypes and
136 /// rerootedPrototypeRoot = /MyInstancer/MyPrototypes/MyPrototype/ForInstancer84e...f55
137 ///
138 /// [4] Set by the prototype scene index (instantiated with
139 /// instancer = /MyInstancer,
140 /// prototypeRoot = /MyInstancer/MyPrototypes/MyPrototypes).
141 ///
142 /// For the prototype root itself, it resets the xform stack so that the xform
143 /// of geometry within a prototype is relative to the root of the prototype.
144 /// Also see [5].
145 ///
146 /// [5] Set by the same prototype scene index.
147 ///
148 /// Sets instancedBy:prototypeRoot and instancedBy:paths on all prims that are
149 /// not descendants of an instancer within the prototype root.
150 ///
151 /// ---------------------------------------------------------------------------
152 ///
153 /// Example 2:
154 ///
155 /// USD:
156 ///
157 /// def PointInstancer "MyInstancer"
158 /// {
159 /// rel prototypes = [
160 /// </MyPrototypes/MyPrototype> ]
161 /// }
162 /// over "MyPrototypes"
163 /// {
164 /// def Xform "MyPrototype"
165 /// {
166 /// def Sphere "MySphere"
167 /// {
168 /// }
169 /// }
170 /// }
171 ///
172 /// Note that the USD specification says that even though
173 /// /MyPrototype/MyPrototype is under an "over", it will be drawn (through
174 /// an instancer) since it is targeted by a PointInstancers' prototypes
175 /// relationship. Furthermore, if "MyPrototypes" is changed from an "over" to
176 /// a "def", MySphere would be drawn twice: once in its own right and once
177 /// being instanced by /MyInstancers.
178 ///
179 /// PointPropagatingSceneIndex::
180 ///
181 /// /MyInstancer
182 /// primType: instancer
183 /// dataSource:
184 /// setting # [1]
185 /// prototypes = [/MyPrototypes/MyPrototype/ForInstancer4e6...f36]
186 ///
187 /// /MyPrototypes
188 /// /MyPrototypes/MyPrototype
189 /// /MyPrototypes/MyPrototype/MySphere
190 /// primType: "" # [2]
191 /// dataSource: unchanged
192 ///
193 /// /MyPrototypes/MyPrototype/ForInstancer4e6...f36 # [3]
194 /// primType: unchanged (from /MyPrototypes/MyPrototype)
195 /// dataSource: (from /MyPrototypes/MyPrototype)
196 /// settings # [4]
197 /// xform:resetXformStack = true
198 /// instancedBy:PrototypeRoot = /MyPrototypes/MyPrototype/ForInstancer4e6...f36
199 /// instancedBy:paths = /MyInstancer
200 ///
201 /// /MyPrototypes/MyPrototype/ForInstancer4e6...f36/MySphere
202 /// dataSource: (from /MyInstancer/MyPrototypes/MyPrototype/MySphere)
203 /// setting # [5]
204 /// instancedBy:PrototypeRoot = /MyPrototypes/MyPrototype/ForInstancer4e6...f36
205 /// instancedBy:paths = /MyInstancer
206 ///
207 /// [1] As [1] in Example 1.
208 ///
209 /// [2] Forced by the prototype scene index.
210 /// In general, the prototype scene index forces the prim type to
211 /// empty for all descendants of an over.
212 /// Note that we changed MyPrototypes from an "over" to a "def", there will be
213 /// prim's of type sphere in the scene index corresponding to the one USD prim:
214 /// one instanced through /MyInstancer and one not instanced.
215 ///
216 /// [3] The re-rooted copy of /MyPrototypes/MyPrototype inserted
217 /// by the instancer observer (instantiated with instancer = /MyInstancer,
218 /// prototypeRoot = /MyPrototypes/MyPrototypes and
219 /// rerootedPrototypeRoot = /MyPrototypes/MyPrototype/ForInstancer4e6...f36
220 ///
221 /// [4] Similar to [4] in Example 1.
222 ///
223 /// [5] Similar to [5] in Example 1.
224 ///
225 /// ---------------------------------------------------------------------------
226 ///
227 /// Example 3:
228 ///
229 /// USD:
230 ///
231 /// def PointInstancer "MyInstancer"
232 /// {
233 /// rel prototypes = [
234 /// </MyInstancer/MyPrototype> ]
235 /// def Xform "MyPrototype"
236 /// {
237 /// def PointInstancer "MyNestedInstancer"
238 /// {
239 /// rel prototypes = [
240 /// </MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype> ]
241 /// def Xform "MyNestedPrototype"
242 /// {
243 /// def Sphere "MySphere"
244 /// {
245 /// }
246 /// }
247 /// }
248 /// }
249 /// }
250 ///
251 /// Note that "MySphere" is instanced by two nested point instancers.
252 /// This will be realized by the PointPropagatingSceneIndex as follows:
253 /// PointPropagatingSceneIndex as follows:
254 ///
255 /// /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/ForInstancer8a2...51f/MySphere
256 /// is instanced by
257 /// /MyInstancer/MyPrototype/ForInstancer6a3...234/MyNestedInstancer
258 /// is instanced by
259 /// /MyInstancer
260 ///
261 /// PointPropagatingSceneIndex:
262 ///
263 /// /MyInstancer
264 /// primType: instancer
265 /// dataSource:
266 /// setting # [1]
267 /// prototypes = [/MyInstancer/MyPrototype/ForInstancer6a3...234]
268 ///
269 /// /MyInstancer/MyPrototype
270 /// /MyInstancer/MyPrototype/MyNestedInstancer
271 /// /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype
272 /// /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/MySphere
273 /// primType: "" # [2]
274 /// dataSource: unchanged
275 ///
276 /// /MyInstancer/MyPrototype/ForInstancer6a3...234 # [3]
277 /// primType: unchanged (from /MyInstancer/MyPrototype)
278 /// dataSource: (from /MyInstancer/MyPrototype)
279 /// settings # [4]
280 /// xform:resetXformStack = true
281 /// instancedBy:PrototypeRoot = /MyInstancer/MyPrototype/ForInstancer6a3...234
282 /// instancedBy:paths = /MyInstancer
283 ///
284 /// /MyInstancer/MyPrototype/ForInstancer6a3...234/MyNestedInstancer
285 /// primType: instancer
286 /// dataSource:
287 /// setting # [5]
288 /// prototypes = [/MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/ForInstancer8a2...51f]
289 /// instancedBy:PrototypeRoot = /MyInstancer/MyPrototype/ForInstancer6a3...234
290 /// instancedBy:paths = /MyInstancer
291 ///
292 /// /MyInstancer/MyPrototype/ForInstancer6a3...234/MyNestedInstancer/MyNestedPrototype
293 /// /MyInstancer/MyPrototype/ForInstancer6a3...234/MyNestedInstancer/MyNestedPrototype/MySphere
294 /// primType: "" # [6]
295 /// dataSource: unchanged
296 ///
297 /// /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/ForInstancer8a2...51f #[7]
298 /// primType: unchanged (from /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype)
299 /// dataSource: (from /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype)
300 /// settings # [8]
301 /// xform:resetXformStack = true
302 /// instancedBy:PrototypeRoot = /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/ForInstancer8a2...51f
303 /// instancedBy:paths = /MyInstancer/MyPrototype/ForInstancer6a3...234/MyNestedInstancer
304 ///
305 /// /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/ForInstancer8a2...51f/MySphere
306 /// primType: sphere
307 /// dataSource:
308 /// settings # [9]
309 /// instancedBy:PrototypeRoot = /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/ForInstancer8a2...51f
310 /// instancedBy:paths = /MyInstancer/MyPrototype/ForInstancer6a3...234/MyNestedInstancer
311 ///
312 /// [1] As [1] in Example 1.
313 ///
314 /// [2] As [2] in Example 1.
315 ///
316 /// [3] The re-rooted copy of /MyInstancer/MyPrototype inserted
317 /// by the instancer observer (instantiated with instancer = /MyInstancer,
318 /// prototypeRoot = /MyInstancer/MyPrototypes and
319 /// rerootedPrototypeRoot = /MyInstancer/MyPrototype/ForInstancer6a3...234).
320 ///
321 /// [4] Similar to [4] in Example 1.
322 ///
323 /// [5] Similar to [5] in Example 1.
324 ///
325 /// [6] The prototype scene index forced the empty prim types on
326 /// all descendants of an instancer within the prototype root.
327 ///
328 /// [7] The re-rooted copy of
329 /// /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype inserted
330 /// by the instancer observer (instantiated with
331 /// instancer = /MyInstancer/MyPrototype/MyNestedInstancer,
332 /// prototypeRoot = /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype,
333 /// rerootedPrototypeRoot = /MyInstancer/MyPrototype/MyNestedInstancer/MyNestedPrototype/ForInstancer8a2...51f)
334 ///
335 /// Note that this copy is inserted by the instancer observer for
336 /// /MyInstancer/MyPrototype.
337 ///
338 /// The instancer path is the path in the USD scene and will be changed by
339 /// a latter re-rooting scene index in the instancer observer.
340 ///
341 /// Note the hash at the end of the rerootedPrototypeRoot was computed from the
342 /// calling the instancer observer by combining its rerootedPrototypeRoot with
343 /// the path of the instancer within its prototypeRoot.
344 ///
345 /// [8] Similar to [4].
346 ///
347 /// [9] Similar to [5].
348 ///
352 {
353 public:
355  static UsdImagingPiPrototypePropagatingSceneIndexRefPtr New(
356  HdSceneIndexBaseRefPtr const &inputSceneIndex);
357 
359  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
360 
362  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
363 
365  std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const override;
366 
368  std::vector<HdSceneIndexBaseRefPtr> GetEncapsulatedScenes() const override;
369 
370 private:
372  const HdSceneIndexBaseRefPtr &inputSceneIndex);
373 
376  {
377  public:
380 
381  void PrimsAdded(
382  const HdSceneIndexBase &sender,
383  const AddedPrimEntries &entries) override;
384  void PrimsDirtied(
385  const HdSceneIndexBase &sender,
386  const DirtiedPrimEntries &entries) override;
387  void PrimsRemoved(
388  const HdSceneIndexBase &sender,
389  const RemovedPrimEntries &entries) override;
390  void PrimsRenamed(
391  const HdSceneIndexBase &sender,
392  const RenamedPrimEntries &entries) override;
393 
394  private:
396  };
397 
399  _ContextSharedPtr const _context;
400 
401  _MergingSceneIndexObserver _mergingSceneIndexObserver;
402 
404  _InstancerObserverUniquePtr const _instancerObserver;
405 };
406 
408 
409 #endif
410 
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
USDIMAGING_API std::vector< HdSceneIndexBaseRefPtr > GetEncapsulatedScenes() const override
std::unique_ptr< class _InstancerObserver > _InstancerObserverUniquePtr
#define USDIMAGING_API
Definition: api.h:23
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_REF_PTRS(UsdImagingPiPrototypePropagatingSceneIndex)
std::vector< class SdfPath > SdfPathVector
Definition: path.h:273
USDIMAGING_API std::vector< HdSceneIndexBaseRefPtr > GetInputScenes() const override
static USDIMAGING_API UsdImagingPiPrototypePropagatingSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputSceneIndex)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override