Loading...
Searching...
No Matches
sceneIndex.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_SCENE_INDEX_H
8#define PXR_IMAGING_HD_SCENE_INDEX_H
9
10#include "pxr/pxr.h"
11
12#include <set>
13#include <unordered_map>
14
18
19
20#include "pxr/usd/sdf/path.h"
21
22#include "pxr/imaging/hd/api.h"
23#include "pxr/imaging/hd/dataSource.h"
24#include "pxr/imaging/hd/dataSourceLocator.h"
25#include "pxr/imaging/hd/sceneIndexObserver.h"
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29
35{
36 TfToken primType;
37 HdContainerDataSourceHandle dataSource;
38
41 bool IsDefined() const { return bool(dataSource); }
43 operator bool() const { return IsDefined(); }
44};
45
54{
55public:
56 HD_API
58
59 HD_API
60 ~HdSceneIndexBase() override;
61
62 // ------------------------------------------------------------------------
63 // Scene Observer API
64 // ------------------------------------------------------------------------
65
72 HD_API
73 void AddObserver(const HdSceneIndexObserverPtr &observer);
74
80 HD_API
81 void RemoveObserver(const HdSceneIndexObserverPtr &observer);
82
83 // ------------------------------------------------------------------------
84 // Scene Data API
85 // ------------------------------------------------------------------------
86
98 virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const = 0;
99
109 virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const = 0;
110
115 HdDataSourceBaseHandle GetDataSource(
116 const SdfPath &primPath,
117 const HdDataSourceLocator &locator) const
118 {
120 GetPrim(primPath).dataSource, locator);
121 }
122
123 // ------------------------------------------------------------------------
124 // System-wide API
125 // ------------------------------------------------------------------------
126
130 HD_API
132 const TfToken &messageType,
133 const HdDataSourceBaseHandle &args);
134
135 // ------------------------------------------------------------------------
136 // User Interface Utilities
137 // ------------------------------------------------------------------------
138
143 HD_API
144 std::string GetDisplayName() const;
145
149 HD_API
150 void SetDisplayName(const std::string &n);
151
155 HD_API
156 void AddTag(const TfToken &tag);
157
161 HD_API
162 void RemoveTag(const TfToken &tag);
163
167 HD_API
168 bool HasTag(const TfToken &tag) const;
169
173 HD_API
175
176protected:
177
186 HD_API
189
194 HD_API
197
205 HD_API
208
209
214 HD_API
217
218
222 HD_API
223 bool _IsObserved() const;
224
227 HD_API
228 virtual void _SystemMessage(
229 const TfToken &messageType,
230 const HdDataSourceBaseHandle &args);
231
232private:
233 void _RemoveExpiredObservers();
234
235 // Scoped (RAII) helper to manage tracking recursion depth,
236 // and to remove expired observers after completing delivery.
237 struct _NotifyScope;
238
239 // Registered observers, in order of registration.
240 using _Observers = std::vector<HdSceneIndexObserverPtr>;
241 _Observers _observers;
242
243 // Count of in-flight observer notifications
244 int _notifyDepth;
245
246 // Flag hinting that expired observers may exist.
247 bool _shouldRemoveExpiredObservers;
248
249 // User-visible label for this scene index
250 std::string _displayName;
251
252 // Tags used to categorize this scene index
254 _TagSet _tags;
255};
256
257
266 : public TfSingleton<HdSceneIndexNameRegistry>
267{
269
270 HdSceneIndexNameRegistry() = default;
271
272public:
273
276 HD_API
279 }
280
283 HD_API
285 const std::string &name, HdSceneIndexBasePtr instance);
286
289 HD_API
290 std::vector<std::string> GetRegisteredNames();
291
294 HD_API
295 HdSceneIndexBaseRefPtr GetNamedSceneIndex(const std::string &name);
296
297private:
298
299 using _NamedInstanceMap =
300 std::unordered_map<std::string, HdSceneIndexBasePtr>;
301
302 _NamedInstanceMap _namedInstances;
303};
304
305PXR_NAMESPACE_CLOSE_SCOPE
306
307#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:54
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:115
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).
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:267
static HD_API HdSceneIndexNameRegistry & GetInstance()
Returns the singleton-instance of this registry.
Definition: sceneIndex.h:277
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:274
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:56
Manage a single instance of an object (see.
Definition: singleton.h:105
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:120
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Standard pointer typedefs.
Manage a single instance of an object.
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
bool IsDefined() const
Does this prim returned by HdSceneIndex::GetPrim exist in the scene index?
Definition: sceneIndex.h:41
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440