HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
niPrototypePropagatingSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_IMAGING_USD_IMAGING_NI_PROTOTYPE_PROPAGATING_SCENE_INDEX_H
25 #define PXR_USD_IMAGING_USD_IMAGING_NI_PROTOTYPE_PROPAGATING_SCENE_INDEX_H
26 
28 
30 
32 
34 
36 
37 /// \class UsdImagingNiPrototypePropagatingSceneIndex
38 ///
39 /// A scene index implementing USD native instancing. If combined
40 /// with the UsdImagingPiPrototypePropagatingSceneIndex, the native
41 /// instancing scene index has to be run after the point instancing
42 /// scene index.
43 ///
44 /// This scene index uses the UsdImgingNiInstanceAggregationSceneIndex
45 /// to find all instances, aggregate them and insert instancers for
46 /// each set of aggregated instances. This scene index then inserts
47 /// copies of the corresponding USD prototype underneath each of these
48 /// instancers. Each of these copies is actually a
49 /// UsdImagingNiPrototypePropagatingSceneIndex itself. This way, we can
50 /// handle nested native instancing. In other words, we can call the
51 /// UsdImagingNiPrototypePropagatingSceneIndex for a USD prototype and
52 /// it will find the instances within that prototype.
53 ///
54 /// The instancing scene index uses the instancedBy:prototypeRoot
55 /// of the input scene index during aggregation.
56 /// Typically, the input scene index will be a
57 /// UsdImagingPiPrototypePropagatingSceneIndex which populates
58 /// instancedBy:prototypeRoot based on which point instancer is
59 /// instancing a prim.
60 ///
61 /// This scene index is implemented by a merging scene index.
62 /// One input to the merging scene index is the
63 /// UsdImaging_NiPrototypeSceneIndex which prepares the prototype
64 /// for which this scene index was created.
65 /// Another input to the merging scene index is the
66 /// UsdImaging_NiInstanceAggregationSceneIndex that will insert the
67 /// instancers for the instances within this prototype.
68 /// The _InstanceAggregationSceneIndexObserver will observe the
69 /// latter scene index to add
70 /// respective UsdImagingNiPrototypePropagatingSceneIndex's under
71 /// each instancer.
72 ///
73 /// Example 1 (also see Example 1 in niInstanceAggregationSceneIndex.h)
74 ///
75 /// USD:
76 ///
77 /// def Xform "MyPrototype"
78 /// {
79 /// def Cube "MyCube"
80 /// {
81 /// }
82 /// }
83 ///
84 /// def "Cube_1" (
85 /// instanceable = true
86 /// references = </MyPrototype>
87 /// {
88 /// }
89 ///
90 /// Inputs of the UsdImagingNiPrototypePropagatingSceneIndex(inputSceneIndex):
91 ///
92 /// * HdMergingSceneIndex
93 /// * UsdImaging_NiPrototypeSceneIndex
94 /// forPrototype = false
95 /// * UsdImaging_NiPrototypePruningSceneIndex
96 /// forPrototype = false
97 /// * inputSceneIndex (typically a UsdImagingPiPrototypePropagatingSceneIndex)
98 /// * UsdImaging_NiInstanceAggregationSceneIndex
99 /// forPrototype = false
100 /// * UsdImaging_NiPrototypePruningSceneIndex
101 /// [... as above]
102 /// * UsdImagingRerootingSceneIndex
103 /// (inserted by _InstanceAggregationSceneIndexObserver::PrimsAdded
104 /// through _MergingSceneIndexEntry)
105 /// srcPrefix = /UsdNiInstancer
106 /// dstPrefix = /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer
107 /// * UsdImagingNiPrototypePropagatingSceneIndex
108 /// prototypeName = __Prototype_1
109 /// * HdMergingSceneIndex
110 /// * UsdImaging_NiPrototypeSceneIndex
111 /// forPrototype = true
112 /// * UsdImagingRerootingSceneIndex
113 /// srcPrefix = /__PrototypeRoot1
114 /// dstPrefix = /UsdNiInstancer/UsdNiPrototype
115 /// * inputSceneIndex
116 /// * UsdImaging_NiInstanceAggregationSceneIndex
117 /// forPrototype = true
118 /// * UsdImagingRerootingSceneIndex
119 /// [... as just above]
120 ///
121 /// UsdImagingNiPrototypePropagatingSceneIndex
122 ///
123 /// /Cube_1
124 /// primType: ""
125 /// dataSource:
126 /// instance: # Useful for translating Usd proxy paths for selection.
127 /// # See corresponding example in niInstanceAggregationIndex
128 /// # for more details.
129 /// instancer: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer
130 /// prototypeId: 0
131 /// instanceId: 0
132 /// /MyPrototype # Not referenced from a different file, so appears here
133 /// # as non-prototype as well
134 /// primType: ""
135 /// /MyPrototype/MyCube
136 /// primType: cube
137 /// /UsdNiPropagatedPrototypes
138 /// /UsdNiPropagatedPrototypes/NoBindings
139 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1
140 /// primType: ""
141 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer
142 /// primType: instancer
143 /// dataSource:
144 /// instancerTopology:
145 /// instanceIndices:
146 /// i0: [ 0 ]
147 /// prototypes: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdNiPrototype
148 /// instanceLocations: [ /Cube_1 ] # for picking
149 /// primvars:
150 /// instanceTransform:
151 /// primvarValue: [ identity matrix ]
152 /// interpolation: instance
153 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdNiPrototype
154 /// primType: ""
155 /// dataSource:
156 /// instancedBy:
157 /// paths: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer ]
158 /// prototypeRoot: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1 /UsdNiInstancer/UsdNiPrototype
159 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdNiPrototype/MyCube
160 /// primType: cube
161 /// dataSource:
162 /// instancedBy:
163 /// paths: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer ]
164 /// prototypeRoot: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_1 /UsdNiInstancer/UsdNiPrototype
165 ///
166 /// Example 2:
167 ///
168 /// def Xform "MyNestedPrototype" # Will become USD prototype /__Prototype_1
169 /// {
170 /// def Cube "MyCube"
171 /// {
172 /// }
173 /// }
174 ///
175 /// def Xform "MyPrototype" # Will become USD prototype /__Prototype_2
176 /// {
177 /// def "MyNestedInstance" (
178 /// instanceable = true
179 /// references = </MyNestedPrototype> )
180 /// {
181 /// }
182 /// }
183 ///
184 /// def Xform "MyInstance" (
185 /// instanceable = true
186 /// references = </MyPrototype>)
187 /// {
188 ///
189 /// }
190 ///
191 /// UsdImagingNiPrototypePropagatingSceneIndex
192 ///
193 /// ...
194 /// /MyInstance
195 /// primType: ""
196 /// dataSource:
197 /// instance:
198 /// instancer: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer
199 /// prototypeId: 0
200 /// instanceId: 0
201 /// /UsdNiPropagatedPrototypes
202 /// /UsdNiPropagatedPrototypes/NoBindings
203 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2
204 /// primType: ""
205 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer
206 /// primType: instancer
207 /// dataSource:
208 /// instanerTopology:
209 /// prototypes: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype ]
210 /// ...
211 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/_Prototype_2
212 /// primType: ""
213 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/_Prototype_2/MyNestedInstance
214 /// primType: ""
215 /// dataSource:
216 /// instancer: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer
217 /// prototypeId: 0
218 /// instanceId: 0
219 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes
220 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings
221 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1
222 /// primType: ""
223 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer
224 /// primType: instancer
225 /// dataSource:
226 /// instanerTopology:
227 /// prototypes: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdPiPrototype ]
228 /// ...
229 /// instancedBy:
230 /// paths: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer ]
231 /// prototypeRoot: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype
232 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdPiPrototype
233 /// primType: ""
234 /// dataSource:
235 /// instancedBy:
236 /// paths: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer ]
237 /// prototypeRoot: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdPiPrototype
238 /// /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdPiPrototype/MyCube
239 /// primType: "cube"
240 /// dataSource:
241 /// instancedBy:
242 /// paths: [ /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/UsdPiPrototype/UsdNiInstancer ]
243 /// prototypeRoot: /UsdNiPropagatedPrototypes/NoBindings/__Prototype_2/UsdNiInstancer/UsdPiPrototype/UsdNiPropagatedPrototypes/NoBindings/__Prototype_1/UsdNiInstancer/UsdPiPrototype
244 /// ...
245 ///
246 ///
249 {
250 public:
251 
253  static UsdImagingNiPrototypePropagatingSceneIndexRefPtr New(
254  HdSceneIndexBaseRefPtr const &inputSceneIndex);
255 
257  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
258 
260  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
261 
263  std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const override;
264 
265 private:
266  class _SceneIndexCache;
267  using _SceneIndexCacheSharedPtr =
268  std::shared_ptr<_SceneIndexCache>;
269 
270  class _MergingSceneIndexEntry;
271  using _MergingSceneIndexEntryUniquePtr =
272  std::unique_ptr<_MergingSceneIndexEntry>;
273 
276  {
277  public:
280 
281  void PrimsAdded(
282  const HdSceneIndexBase &sender,
283  const AddedPrimEntries &entries) override;
284  void PrimsDirtied(
285  const HdSceneIndexBase &sender,
286  const DirtiedPrimEntries &entries) override;
287  void PrimsRemoved(
288  const HdSceneIndexBase &sender,
289  const RemovedPrimEntries &entries) override;
290  void PrimsRenamed(
291  const HdSceneIndexBase &sender,
292  const RenamedPrimEntries &entries) override;
293 
294  private:
296  };
297 
300  {
301  public:
304 
305  void PrimsAdded(
306  const HdSceneIndexBase &sender,
307  const AddedPrimEntries &entries) override;
308  void PrimsDirtied(
309  const HdSceneIndexBase &sender,
310  const DirtiedPrimEntries &entries) override;
311  void PrimsRemoved(
312  const HdSceneIndexBase &sender,
313  const RemovedPrimEntries &entries) override;
314  void PrimsRenamed(
315  const HdSceneIndexBase &sender,
316  const RenamedPrimEntries &entries) override;
317 
318  private:
320  };
321 
322  // Use prototypeName to instantiate for "scene root".
323  static UsdImagingNiPrototypePropagatingSceneIndexRefPtr _New(
324  const TfToken &prototypeName,
325  _SceneIndexCacheSharedPtr const &cache);
326 
328  const TfToken &prototypeName,
329  _SceneIndexCacheSharedPtr const &cache);
330 
331  void _Populate(HdSceneIndexBaseRefPtr const &instanceAggregationSceneIndex);
332  void _AddPrim(const SdfPath &primPath);
333  void _RemovePrim(const SdfPath &primPath);
334 
335  const TfToken _prototypeName;
336  _SceneIndexCacheSharedPtr const _cache;
337 
338  HdMergingSceneIndexRefPtr const _mergingSceneIndex;
339 
340  std::map<SdfPath, _MergingSceneIndexEntryUniquePtr>
341  _instancersToMergingSceneIndexEntry;
342 
344  _instanceAggregationSceneIndexObserver;
345  _MergingSceneIndexObserver _mergingSceneIndexObserver;
346 };
347 
349 
350 #endif
#define USDIMAGING_API
Definition: api.h:40
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_REF_PTRS(HdMergingSceneIndex)
Definition: token.h:87
USDIMAGING_API std::vector< HdSceneIndexBaseRefPtr > GetInputScenes() const override
Definition: path.h:291
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:212
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static USDIMAGING_API UsdImagingNiPrototypePropagatingSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputSceneIndex)