Loading...
Searching...
No Matches
niPrototypePropagatingSceneIndex.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_NI_PROTOTYPE_PROPAGATING_SCENE_INDEX_H
8#define PXR_USD_IMAGING_USD_IMAGING_NI_PROTOTYPE_PROPAGATING_SCENE_INDEX_H
9
10#include "pxr/usdImaging/usdImaging/api.h"
11
12#include "pxr/imaging/hd/dataSourceHash.h"
13#include "pxr/imaging/hd/filteringSceneIndex.h"
14
15PXR_NAMESPACE_OPEN_SCOPE
16
18
20
289{
290public:
291 using SceneIndexAppendCallback =
292 std::function<
293 HdSceneIndexBaseRefPtr(const HdSceneIndexBaseRefPtr &inputScene)>;
294
295 // instanceDataSourceNames are the names of the data sources of a native
296 // instance prim that need to have the same values for the instances to
297 // be aggregated. A copy of these data sources is bundled into the
298 // prim data source for the binding scope.
299 //
300 // When propagating a prototype by inserting the scene index isolating
301 // that prototype into the merging scene index implementing this scene
302 // index, we also call sceneIndexAppendCallback.
303 //
304 // The use case is for the UsdImagingDrawModeSceneIndex.
305 //
306 USDIMAGING_API
307 static UsdImagingNiPrototypePropagatingSceneIndexRefPtr New(
308 HdSceneIndexBaseRefPtr const &inputSceneIndex,
309 const TfTokenVector &instanceDataSourceNames,
310 const SceneIndexAppendCallback &sceneIndexAppendCallback);
311
312 USDIMAGING_API
314
315 USDIMAGING_API
316 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
317
318 USDIMAGING_API
319 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
320
321 USDIMAGING_API
322 std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const override;
323
324 USDIMAGING_API
325 std::vector<HdSceneIndexBaseRefPtr> GetEncapsulatedScenes() const override;
326
327private:
328 class _SceneIndexCache;
329 using _SceneIndexCacheSharedPtr =
330 std::shared_ptr<_SceneIndexCache>;
331
332 class _MergingSceneIndexOperations;
333
334 friend class _InstanceAggregationSceneIndexObserver;
335 class _InstanceAggregationSceneIndexObserver : public HdSceneIndexObserver
336 {
337 public:
338 _InstanceAggregationSceneIndexObserver(
340
341 void PrimsAdded(
342 const HdSceneIndexBase &sender,
343 const AddedPrimEntries &entries) override;
344 void PrimsDirtied(
345 const HdSceneIndexBase &sender,
346 const DirtiedPrimEntries &entries) override;
347 void PrimsRemoved(
348 const HdSceneIndexBase &sender,
349 const RemovedPrimEntries &entries) override;
350 void PrimsRenamed(
351 const HdSceneIndexBase &sender,
352 const RenamedPrimEntries &entries) override;
353
354 private:
356 };
357
358 friend class _MergingSceneIndexObserver;
359 class _MergingSceneIndexObserver : public HdSceneIndexObserver
360 {
361 public:
362 _MergingSceneIndexObserver(
364
365 void PrimsAdded(
366 const HdSceneIndexBase &sender,
367 const AddedPrimEntries &entries) override;
368 void PrimsDirtied(
369 const HdSceneIndexBase &sender,
370 const DirtiedPrimEntries &entries) override;
371 void PrimsRemoved(
372 const HdSceneIndexBase &sender,
373 const RemovedPrimEntries &entries) override;
374 void PrimsRenamed(
375 const HdSceneIndexBase &sender,
376 const RenamedPrimEntries &entries) override;
377
378 private:
380 };
381
382 // Use prototypeName to instantiate for "scene root".
383 static UsdImagingNiPrototypePropagatingSceneIndexRefPtr _New(
384 HdSceneIndexBaseRefPtr const &inputSceneIndex,
385 const TfToken &prototypeName,
386 HdContainerDataSourceHandle const &prototypeRootOverlayDs,
387 _SceneIndexCacheSharedPtr const &cache);
388
390 HdSceneIndexBaseRefPtr const &inputSceneIndex,
391 const TfToken &prototypeName,
392 HdContainerDataSourceHandle const &prototypeRootOverlayDs,
393 _SceneIndexCacheSharedPtr const &cache);
394
395 void _Populate(HdSceneIndexBaseRefPtr const &instanceAggregationSceneIndex);
396 void _PrimsAdded(
398 void _AddPrim(
399 const SdfPath &primPath,
400 _MergingSceneIndexOperations * mergingSceneIndexOperations);
401 void _PrimsRemoved(
403 void _RemovePrim(const SdfPath &primPath,
404 _MergingSceneIndexOperations * mergingSceneIndexOperations);
405
406private: // data
407
408 const HdSceneIndexBaseRefPtr _inputSceneIndex;
409 const TfToken _prototypeName;
410 const HdDataSourceHashType _prototypeRootOverlayDsHash;
411 const _SceneIndexCacheSharedPtr _cache;
412
413 HdMergingSceneIndexRefPtr _mergingSceneIndex;
414
415 // Propagated prototypes in the _mergingSceneIndex.
416 //
417 // This map needs to be kept in sync with the HdMergingSceneIndex.
418 // There might be a way to avoid the redundant representation.
419 std::map<SdfPath, HdSceneIndexBaseRefPtr>
420 _instancersToPropagatedPrototypeSceneIndex;
421
422 HdSceneIndexBaseRefPtr _instanceAggregationSceneIndex;
423
424 _InstanceAggregationSceneIndexObserver
425 _instanceAggregationSceneIndexObserver;
426 _MergingSceneIndexObserver _mergingSceneIndexObserver;
427};
428
429PXR_NAMESPACE_CLOSE_SCOPE
430
431#endif
A mix-in class for scene indices that implement their behaviour by creating other scene indices (inte...
An abstract base class for scene indexes that have one or more input scene indexes which serve as a b...
Merges multiple scenes together.
Abstract interface to scene data.
Definition sceneIndex.h:55
Observer of scene data.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
A scene index implementing USD native instancing.
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
#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
std::vector< TfToken > TfTokenVector
Convenience types.
Definition token.h:489