Loading...
Searching...
No Matches
mergingSceneIndex.h
1//
2// Copyright 2021 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_IMAGING_HD_MERGING_SCENE_H
8#define PXR_IMAGING_HD_MERGING_SCENE_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/filteringSceneIndex.h"
12#include "pxr/usd/sdf/pathTable.h"
14
15#include <limits>
16
17PXR_NAMESPACE_OPEN_SCOPE
18
21
30{
31public:
32
33 static HdMergingSceneIndexRefPtr New() {
34 return TfCreateRefPtr(new HdMergingSceneIndex);
35 }
36
39 {
41 HdSceneIndexBaseRefPtr scene;
52 size_t pos = std::numeric_limits<size_t>::max();
53 };
54
56 HD_API
58 const std::vector<InputScene> &inputScenes);
59
61 HD_API
63 const std::vector<HdSceneIndexBaseRefPtr> &sceneIndices);
64
69 HD_API
71 const HdSceneIndexBaseRefPtr &inputScene,
72 const SdfPath &activeInputSceneRoot);
73
74 HD_API
75 void InsertInputScene(
76 size_t pos,
77 const HdSceneIndexBaseRefPtr &inputScene,
78 const SdfPath &activeInputSceneRoot);
79
80 HD_API
81 void RemoveInputScene(const HdSceneIndexBaseRefPtr &sceneIndex);
82
84 HD_API
85 std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const override;
86
87 // satisfying HdSceneIndexBase
88 HD_API
89 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
90
91 HD_API
92 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
93
94protected:
95 HD_API
97
98private:
99
100 void _PrimsAdded(
101 const HdSceneIndexBase &sender,
103
104 void _PrimsRemoved(
105 const HdSceneIndexBase &sender,
107
108 void _PrimsDirtied(
109 const HdSceneIndexBase &sender,
111
112 friend class _Observer;
113
114 // Rebuild _inputsPathTable from the current contents of _inputs.
115 void _RebuildInputsPathTable();
116
117 // Add strict prefixes of activeInputSceneRoot's.
118 //
119 // If adding a scene inde at, e.g., /A/B/C, make
120 // AddedPrimEntries for /A and /A/B.
121 void _AddStrictPrefixesOfSceneRoots(
122 const std::vector<InputScene> &inputScenes,
124
125 bool _HasPrim(const SdfPath &path);
126
127 class _Observer : public HdSceneIndexObserver
128 {
129 public:
130 _Observer(HdMergingSceneIndex *owner)
131 : _owner(owner) {}
132
133 void PrimsAdded(
134 const HdSceneIndexBase &sender,
135 const AddedPrimEntries &entries) override;
136
137 void PrimsRemoved(
138 const HdSceneIndexBase &sender,
139 const RemovedPrimEntries &entries) override;
140
141 void PrimsDirtied(
142 const HdSceneIndexBase &sender,
143 const DirtiedPrimEntries &entries) override;
144
145 void PrimsRenamed(
146 const HdSceneIndexBase &sender,
147 const RenamedPrimEntries &entries) override;
148
149 private:
150 HdMergingSceneIndex *_owner;
151 };
152
153 _Observer _observer;
154
155 struct _InputEntry
156 {
157 HdSceneIndexBaseRefPtr sceneIndex;
158 SdfPath sceneRoot;
159
160 _InputEntry(const HdSceneIndexBaseRefPtr &sceneIndex,
161 const SdfPath &sceneRoot)
162 : sceneIndex(sceneIndex)
163 , sceneRoot(sceneRoot)
164 {
165 }
166 };
167
168 // We observe that most merging scene indexes have few inputs, such as 2.
169 // However, in the case of merging USD native instance prototypes in
170 // UsdImaging, we may have hundreds of inputs with non-overlapping
171 // sceneRoots . To avoid an O(N) scan over all inputs when N grows
172 // large, we use an SdfPathTable to store ordered sub-list of inputs
173 // that pertain to an input prim path or input ancestor path.
174 using _InputEntries = TfSmallVector<_InputEntry, 4>;
175 using _InputEntriesByPathTable = SdfPathTable<_InputEntries>;
176
177 // Look up the input entries potentially relevant to the given path.
178 const _InputEntries &_GetInputEntriesByPath(SdfPath const& path) const;
179
180 _InputEntries _inputs;
181 _InputEntriesByPathTable _inputsPathTable;
182
183};
184
185
186PXR_NAMESPACE_CLOSE_SCOPE
187
188#endif //PXR_IMAGING_HD_MERGING_SCENE_H
An abstract base class for scene indexes that have one or more input scene indexes which serve as a b...
Merges multiple scenes together.
SdfPath activeInputSceneRoot
The shallowest path at which prims in the scene should be considered.
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
HD_API void InsertInputScenes(const std::vector< InputScene > &inputScenes)
Adds given scenes.
size_t pos
The position where to insert the scene.
HD_API std::vector< HdSceneIndexBaseRefPtr > GetInputScenes() const override
satisfying HdFilteringSceneIndex
HdSceneIndexBaseRefPtr scene
The scene to add.
HD_API void RemoveInputScenes(const std::vector< HdSceneIndexBaseRefPtr > &sceneIndices)
Removes given scenes.
HD_API void AddInputScene(const HdSceneIndexBaseRefPtr &inputScene, const SdfPath &activeInputSceneRoot)
Adds a scene with activeInputSceneRoot specifying the shallowest path at which prims should be consid...
HD_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
Entry to add a scene to the merging scene index.
Abstract interface to scene data.
Definition: sceneIndex.h:54
Observer of scene data.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:66
#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:35