HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unboundMaterialPruningSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 #ifndef PXR_IMAGING_HDSI_UNBOUND_MATERIAL_PRUNING_SCENE_INDEX_H
7 #define PXR_IMAGING_HDSI_UNBOUND_MATERIAL_PRUNING_SCENE_INDEX_H
8 
9 #include "pxr/pxr.h"
10 
11 #include "pxr/imaging/hdsi/api.h"
13 
15 #include "pxr/usd/sdf/path.h"
16 #include "pxr/base/vt/array.h"
17 
18 #include <unordered_set>
19 
21 
22 #define HDSI_UNBOUND_MATERIAL_PRUNING_SCENE_INDEX_TOKENS \
23  (materialBindingPurposes)
24 
25 TF_DECLARE_PUBLIC_TOKENS(HdsiUnboundMaterialPruningSceneIndexTokens, HDSI_API,
27 
29 
30 ///
31 /// A scene index that prunes material prims that are not bound.
32 ///
33 /// The material binding purposes can be specified via a HdTokenArrayDataSource
34 /// for the `materialBindingPurposes` token in the input args.
35 /// If no binding purposes are specified, the scene index will leave unbound
36 /// materials as is.
37 ///
38 /// \note This scene index clears the prim type and data source for materials
39 /// that are not bound. It does not remove the prim altogether.
40 ///
43 {
44 public:
45  HDSI_API
46  static HdsiUnboundMaterialPruningSceneIndexRefPtr
47  New(HdSceneIndexBaseRefPtr const &inputSceneIndex,
48  HdContainerDataSourceHandle const &inputArgs);
49 
50 public: // HdSceneIndex overrides
51  HDSI_API
52  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
53  HDSI_API
54  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
55 
56 protected: // HdSingleInputFilteringSceneIndexBase overrides
57  HDSI_API
58  void _PrimsAdded(
59  const HdSceneIndexBase &sender,
60  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
61  HDSI_API
62  void _PrimsRemoved(
63  const HdSceneIndexBase &sender,
64  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
65  HDSI_API
66  void _PrimsDirtied(
67  const HdSceneIndexBase &sender,
68  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
69 
70 private:
71  HDSI_API
73  HdSceneIndexBaseRefPtr const &inputSceneIndex,
74  HdContainerDataSourceHandle const &inputArgs);
75  HDSI_API
76  ~HdsiUnboundMaterialPruningSceneIndex() override;
77 
78  // Traverse input scene to update internal tracking and
79  // discover and invalidate unbound materials.
80  void _PopulateFromInputSceneIndex();
81 
82  bool _IsBoundMaterial(const SdfPath &materialPath) const;
83  bool _WasAdded(const SdfPath &materialPath) const;
84 
85  const VtArray<TfToken> _bindingPurposes;
86  const HdDataSourceLocatorSet _bindingLocators;
87  std::unordered_set<SdfPath, SdfPath::Hash> _boundMaterialPaths;
88  std::unordered_set<SdfPath, SdfPath::Hash> _addedMaterialPaths;
89 };
90 
92 
93 #endif
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
HDSI_API void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override
HDSI_API void _PrimsDirtied(const HdSceneIndexBase &sender, const HdSceneIndexObserver::DirtiedPrimEntries &entries) override
std::vector< class SdfPath > SdfPathVector
#define HDSI_UNBOUND_MATERIAL_PRUNING_SCENE_INDEX_TOKENS
TF_DECLARE_WEAK_AND_REF_PTRS(HdsiUnboundMaterialPruningSceneIndex)
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Definition: path.h:280
#define HDSI_API
Definition: api.h:23
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
HDSI_API void _PrimsRemoved(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RemovedPrimEntries &entries) override
TF_DECLARE_PUBLIC_TOKENS(HdsiUnboundMaterialPruningSceneIndexTokens, HDSI_API, HDSI_UNBOUND_MATERIAL_PRUNING_SCENE_INDEX_TOKENS)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static HDSI_API HdsiUnboundMaterialPruningSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputSceneIndex, HdContainerDataSourceHandle const &inputArgs)