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/imaging/hd/sceneIndex.h"
13#include "pxr/usd/sdf/pathTable.h"
15
16#include <limits>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
22
31{
32public:
33
34 static HdMergingSceneIndexRefPtr New() {
35 return TfCreateRefPtr(new HdMergingSceneIndex);
36 }
37
40 {
42 HdSceneIndexBaseRefPtr scene;
53 size_t pos = std::numeric_limits<size_t>::max();
54 };
55
57 HD_API
59 const std::vector<InputScene> &inputScenes);
60
62 HD_API
64 const std::vector<HdSceneIndexBaseRefPtr> &sceneIndices);
65
70 HD_API
72 const HdSceneIndexBaseRefPtr &inputScene,
73 const SdfPath &activeInputSceneRoot);
74
75 HD_API
76 void InsertInputScene(
77 size_t pos,
78 const HdSceneIndexBaseRefPtr &inputScene,
79 const SdfPath &activeInputSceneRoot);
80
81 HD_API
82 void RemoveInputScene(const HdSceneIndexBaseRefPtr &sceneIndex);
83
85 HD_API
86 std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const override;
87
88 // satisfying HdSceneIndexBase
89 HD_API
90 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
91
92 HD_API
93 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
94
95protected:
96 HD_API
98
99private:
100
101 void _PrimsAdded(
102 const HdSceneIndexBase &sender,
104
105 void _PrimsRemoved(
106 const HdSceneIndexBase &sender,
108
109 void _PrimsDirtied(
110 const HdSceneIndexBase &sender,
112
113 friend class _Observer;
114
115 // Rebuild _inputsPathTable from the current contents of _inputs.
116 void _RebuildInputsPathTable();
117
118 // Add strict prefixes of activeInputSceneRoot's.
119 //
120 // If adding a scene inde at, e.g., /A/B/C, make
121 // AddedPrimEntries for /A and /A/B.
122 void _AddStrictPrefixesOfSceneRoots(
123 const std::vector<InputScene> &inputScenes,
125
126 bool _HasPrim(const SdfPath &path);
127
128 bool _HasOtherInputForPath(
129 const HdSceneIndexBase& sender, const SdfPath& path) const;
130
131 class _Observer : public HdSceneIndexObserver
132 {
133 public:
134 _Observer(HdMergingSceneIndex *owner)
135 : _owner(owner) {}
136
137 void PrimsAdded(
138 const HdSceneIndexBase &sender,
139 const AddedPrimEntries &entries) override;
140
141 void PrimsRemoved(
142 const HdSceneIndexBase &sender,
143 const RemovedPrimEntries &entries) override;
144
145 void PrimsDirtied(
146 const HdSceneIndexBase &sender,
147 const DirtiedPrimEntries &entries) override;
148
149 void PrimsRenamed(
150 const HdSceneIndexBase &sender,
151 const RenamedPrimEntries &entries) override;
152
153 private:
154 HdMergingSceneIndex *_owner;
155 };
156
157 _Observer _observer;
158
159 struct _InputEntry
160 {
161 HdSceneIndexBaseRefPtr sceneIndex;
162 SdfPath sceneRoot;
163
164 _InputEntry(const HdSceneIndexBaseRefPtr &sceneIndex,
165 const SdfPath &sceneRoot)
166 : sceneIndex(sceneIndex)
167 , sceneRoot(sceneRoot)
168 {
169 }
170 };
171
172 // We observe that most merging scene indexes have few inputs, such as 2.
173 // However, in the case of merging USD native instance prototypes in
174 // UsdImaging, we may have hundreds of inputs with non-overlapping
175 // sceneRoots . To avoid an O(N) scan over all inputs when N grows
176 // large, we use an SdfPathTable to store ordered sub-list of inputs
177 // that pertain to an input prim path or input ancestor path.
178 using _InputEntries = TfSmallVector<_InputEntry, 4>;
179 using _InputEntriesByPathTable = SdfPathTable<_InputEntries>;
180
181 // Look up the input entries potentially relevant to the given path.
182 const _InputEntries &_GetInputEntriesByPath(SdfPath const& path) const;
183
184 _InputEntries _inputs;
185 _InputEntriesByPathTable _inputsPathTable;
186
187};
188
189
190PXR_NAMESPACE_CLOSE_SCOPE
191
192#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:55
Observer of scene data.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
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:36