Loading...
Searching...
No Matches
sceneIndex.h
1//
2// Copyright 2021 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_IMAGING_HD_SCENE_INDEX_H
25#define PXR_IMAGING_HD_SCENE_INDEX_H
26
27#include "pxr/pxr.h"
28
29#include <set>
30#include <unordered_map>
31
35
36
37#include "pxr/usd/sdf/path.h"
38
39#include "pxr/imaging/hd/api.h"
40#include "pxr/imaging/hd/dataSource.h"
41#include "pxr/imaging/hd/dataSourceLocator.h"
42#include "pxr/imaging/hd/sceneIndexObserver.h"
43
44PXR_NAMESPACE_OPEN_SCOPE
45
46
52{
53 TfToken primType;
54 HdContainerDataSourceHandle dataSource;
55};
56
65{
66public:
67 HD_API
69
70 HD_API
71 ~HdSceneIndexBase() override;
72
73 // ------------------------------------------------------------------------
74 // Scene Observer API
75 // ------------------------------------------------------------------------
76
83 HD_API
84 void AddObserver(const HdSceneIndexObserverPtr &observer);
85
91 HD_API
92 void RemoveObserver(const HdSceneIndexObserverPtr &observer);
93
94 // ------------------------------------------------------------------------
95 // Scene Data API
96 // ------------------------------------------------------------------------
97
102 virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const = 0;
103
110 virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const = 0;
111
116 HdDataSourceBaseHandle GetDataSource(
117 const SdfPath &primPath,
118 const HdDataSourceLocator &locator) const
119 {
121 GetPrim(primPath).dataSource, locator);
122 }
123
124 // ------------------------------------------------------------------------
125 // System-wide API
126 // ------------------------------------------------------------------------
127
131 HD_API
133 const TfToken &messageType,
134 const HdDataSourceBaseHandle &args);
135
136 // ------------------------------------------------------------------------
137 // User Interface Utilities
138 // ------------------------------------------------------------------------
139
144 HD_API
145 std::string GetDisplayName() const;
146
150 HD_API
151 void SetDisplayName(const std::string &n);
152
156 HD_API
157 void AddTag(const TfToken &tag);
158
162 HD_API
163 void RemoveTag(const TfToken &tag);
164
168 HD_API
169 bool HasTag(const TfToken &tag) const;
170
174 HD_API
176
177protected:
178
187 HD_API
190
195 HD_API
198
206 HD_API
209
210
215 HD_API
218
219
223 HD_API
224 bool _IsObserved() const;
225
228 HD_API
229 virtual void _SystemMessage(
230 const TfToken &messageType,
231 const HdDataSourceBaseHandle &args);
232
233private:
234 void _RemoveExpiredObservers();
235
236 // Scoped (RAII) helper to manage tracking recursion depth,
237 // and to remove expired observers after completing delivery.
238 struct _NotifyScope;
239
240 // Registered observers, in order of registration.
241 using _Observers = std::vector<HdSceneIndexObserverPtr>;
242 _Observers _observers;
243
244 // Count of in-flight observer notifications
245 int _notifyDepth;
246
247 // Flag hinting that expired observers may exist.
248 bool _shouldRemoveExpiredObservers;
249
250 // User-visible label for this scene index
251 std::string _displayName;
252
253 // Tags used to categorize this scene index
255 _TagSet _tags;
256};
257
258
267 : public TfSingleton<HdSceneIndexNameRegistry>
268{
270
271 HdSceneIndexNameRegistry() = default;
272
273public:
274
277 HD_API
280 }
281
284 HD_API
286 const std::string &name, HdSceneIndexBasePtr instance);
287
290 HD_API
291 std::vector<std::string> GetRegisteredNames();
292
295 HD_API
296 HdSceneIndexBaseRefPtr GetNamedSceneIndex(const std::string &name);
297
298private:
299
300 using _NamedInstanceMap =
301 std::unordered_map<std::string, HdSceneIndexBasePtr>;
302
303 _NamedInstanceMap _namedInstances;
304};
305
306PXR_NAMESPACE_CLOSE_SCOPE
307
308#endif // PXR_IMAGING_HD_SCENE_INDEX_H
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
Represents an object that can identify the location of a data source.
Abstract interface to scene data.
Definition: sceneIndex.h:65
HdDataSourceBaseHandle GetDataSource(const SdfPath &primPath, const HdDataSourceLocator &locator) const
A convenience function: look up the object at primPath, and if successful return the datasource at lo...
Definition: sceneIndex.h:116
virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const =0
Returns the paths of all scene index prims located immediately below primPath.
HD_API void _SendPrimsRemoved(const HdSceneIndexObserver::RemovedPrimEntries &entries)
Notify attached observers of prims removed from the scene.
HD_API void _SendPrimsRenamed(const HdSceneIndexObserver::RenamedPrimEntries &entries)
Notify attached observers of prims (and their descendents) which have been renamed or reparented.
HD_API void RemoveObserver(const HdSceneIndexObserverPtr &observer)
Removes an observer from this scene index; the given observer will no longer be forwarded notices.
HD_API void AddObserver(const HdSceneIndexObserverPtr &observer)
Adds an observer to this scene index.
HD_API bool _IsObserved() const
Returns whether the scene index has any registered observers; this information can be used to skip wo...
HD_API void _SendPrimsAdded(const HdSceneIndexObserver::AddedPrimEntries &entries)
Notify attached observers of prims added to the scene.
HD_API std::string GetDisplayName() const
Returns a value previously set by SetDisplayName.
HD_API void AddTag(const TfToken &tag)
Adds a specified tag token to a scene index instance.
virtual HD_API void _SystemMessage(const TfToken &messageType, const HdDataSourceBaseHandle &args)
Implement in order to react directly to system messages sent from downstream.
HD_API TfTokenVector GetTags() const
Returns all tag tokens currently added to a scene index instance.
HD_API void _SendPrimsDirtied(const HdSceneIndexObserver::DirtiedPrimEntries &entries)
Notify attached observers of datasource invalidations from the scene.
virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const =0
Returns a pair of (prim type, datasource) for the object at primPath.
HD_API void SystemMessage(const TfToken &messageType, const HdDataSourceBaseHandle &args)
Sends a message with optional arguments to this and any upstream input scene indices.
HD_API bool HasTag(const TfToken &tag) const
Returns true if a specified tag token has been added to a scene index instance.
HD_API void SetDisplayName(const std::string &n)
Allows for scene index instances to be identified in a more contextually relevant way.
HD_API void RemoveTag(const TfToken &tag)
Removes a specified tag token to a scene index instance.
A registry containing named instances of Hydra indexes.
Definition: sceneIndex.h:268
static HD_API HdSceneIndexNameRegistry & GetInstance()
Returns the singleton-instance of this registry.
Definition: sceneIndex.h:278
HD_API void RegisterNamedSceneIndex(const std::string &name, HdSceneIndexBasePtr instance)
Registers an instance of a scene index with a given name.
HD_API std::vector< std::string > GetRegisteredNames()
Returns the names of all registered scene indexes.
HD_API HdSceneIndexBaseRefPtr GetNamedSceneIndex(const std::string &name)
Returns the scene index that was registered with the given name.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:73
Manage a single instance of an object (see.
Definition: singleton.h:122
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:137
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
Standard pointer typedefs.
Manage a single instance of an object.
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:52
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457