Loading...
Searching...
No Matches
niPrototypePropagatingSceneIndex.h
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
27#include "pxr/usdImaging/usdImaging/api.h"
28
29#include "pxr/imaging/hd/dataSourceHash.h"
30#include "pxr/imaging/hd/filteringSceneIndex.h"
31
32PXR_NAMESPACE_OPEN_SCOPE
33
35
37
305{
306public:
307 using SceneIndexAppendCallback =
308 std::function<
309 HdSceneIndexBaseRefPtr(const HdSceneIndexBaseRefPtr &inputScene)>;
310
311 // instanceDataSourceNames are the names of the data sources of a native
312 // instance prim that need to have the same values for the instances to
313 // be aggregated. A copy of these data sources is bundled into the
314 // prim data source for the binding scope.
315 //
316 // When propagating a prototype by inserting the scene index isolating
317 // that prototype into the merging scene index implementing this scene
318 // index, we also call sceneIndexAppendCallback.
319 //
320 // The use case is for the UsdImagingDrawModeSceneIndex.
321 //
322 USDIMAGING_API
323 static UsdImagingNiPrototypePropagatingSceneIndexRefPtr New(
324 HdSceneIndexBaseRefPtr const &inputSceneIndex,
325 const TfTokenVector &instanceDataSourceNames,
326 const SceneIndexAppendCallback &sceneIndexAppendCallback);
327
328 USDIMAGING_API
330
331 USDIMAGING_API
332 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
333
334 USDIMAGING_API
335 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
336
337 USDIMAGING_API
338 std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const override;
339
340private:
341 class _SceneIndexCache;
342 using _SceneIndexCacheSharedPtr =
343 std::shared_ptr<_SceneIndexCache>;
344
345 class _MergingSceneIndexEntry;
346 using _MergingSceneIndexEntryUniquePtr =
347 std::unique_ptr<_MergingSceneIndexEntry>;
348
349 friend class _InstanceAggregationSceneIndexObserver;
350 class _InstanceAggregationSceneIndexObserver : public HdSceneIndexObserver
351 {
352 public:
353 _InstanceAggregationSceneIndexObserver(
355
356 void PrimsAdded(
357 const HdSceneIndexBase &sender,
358 const AddedPrimEntries &entries) override;
359 void PrimsDirtied(
360 const HdSceneIndexBase &sender,
361 const DirtiedPrimEntries &entries) override;
362 void PrimsRemoved(
363 const HdSceneIndexBase &sender,
364 const RemovedPrimEntries &entries) override;
365 void PrimsRenamed(
366 const HdSceneIndexBase &sender,
367 const RenamedPrimEntries &entries) override;
368
369 private:
371 };
372
373 friend class _MergingSceneIndexObserver;
374 class _MergingSceneIndexObserver : public HdSceneIndexObserver
375 {
376 public:
377 _MergingSceneIndexObserver(
379
380 void PrimsAdded(
381 const HdSceneIndexBase &sender,
382 const AddedPrimEntries &entries) override;
383 void PrimsDirtied(
384 const HdSceneIndexBase &sender,
385 const DirtiedPrimEntries &entries) override;
386 void PrimsRemoved(
387 const HdSceneIndexBase &sender,
388 const RemovedPrimEntries &entries) override;
389 void PrimsRenamed(
390 const HdSceneIndexBase &sender,
391 const RenamedPrimEntries &entries) override;
392
393 private:
395 };
396
397 // Use prototypeName to instantiate for "scene root".
398 static UsdImagingNiPrototypePropagatingSceneIndexRefPtr _New(
399 const TfToken &prototypeName,
400 HdContainerDataSourceHandle const &prototypeRootOverlayDs,
401 _SceneIndexCacheSharedPtr const &cache);
402
404 const TfToken &prototypeName,
405 HdContainerDataSourceHandle const &prototypeRootOverlayDs,
406 _SceneIndexCacheSharedPtr const &cache);
407
408 void _Populate(HdSceneIndexBaseRefPtr const &instanceAggregationSceneIndex);
409 void _AddPrim(const SdfPath &primPath);
410 void _RemovePrim(const SdfPath &primPath);
411
412 const TfToken _prototypeName;
413 const HdDataSourceHashType _prototypeRootOverlayDsHash;
414 _SceneIndexCacheSharedPtr const _cache;
415
416 HdMergingSceneIndexRefPtr _mergingSceneIndex;
417
418 std::map<SdfPath, _MergingSceneIndexEntryUniquePtr>
419 _instancersToMergingSceneIndexEntry;
420
421 HdSceneIndexBaseRefPtr _instanceAggregationSceneIndex;
422
423 _InstanceAggregationSceneIndexObserver
424 _instanceAggregationSceneIndexObserver;
425 _MergingSceneIndexObserver _mergingSceneIndexObserver;
426};
427
428PXR_NAMESPACE_CLOSE_SCOPE
429
430#endif
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:65
Observer of scene data.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
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) for the object at primPath.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:52
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457