Loading...
Searching...
No Matches
primManagingSceneIndexObserver.h
Go to the documentation of this file.
1//
2// Copyright 2023 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_HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_H
8#define PXR_IMAGING_HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_H
9
11
12#include "pxr/imaging/hdsi/api.h"
13
14#include "pxr/imaging/hd/dataSource.h"
15#include "pxr/imaging/hd/sceneIndexObserver.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
19#define HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_TOKENS \
20 (primFactory)
21
22TF_DECLARE_PUBLIC_TOKENS(HdsiPrimManagingSceneIndexObserverTokens, HDSI_API,
23 HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_TOKENS);
24
26
49 : public HdSceneIndexObserver, public TfRefBase
50{
51public:
57 {
58 public:
59 HDSI_API
60 virtual ~PrimBase();
61
62 void Dirty(
63 const DirtiedPrimEntry &entry,
65 {
66 // NVI so that we can later implement things like a
67 // mutex guarding against Dirty from several threads
68 // on the same prim.
69 _Dirty(entry, observer);
70 }
71
72 private:
73 virtual void _Dirty(
74 const DirtiedPrimEntry &entry,
75 const HdsiPrimManagingSceneIndexObserver * observer) = 0;
76 };
77 using PrimBaseHandle = std::shared_ptr<PrimBase>;
78
84 {
85 public:
86 HDSI_API
87 virtual ~PrimFactoryBase();
88 virtual PrimBaseHandle CreatePrim(
89 const AddedPrimEntry &entry,
90 const HdsiPrimManagingSceneIndexObserver * observer) = 0;
91 };
92 using PrimFactoryBaseHandle = std::shared_ptr<PrimFactoryBase>;
93
98 static HdsiPrimManagingSceneIndexObserverRefPtr New(
99 HdSceneIndexBaseRefPtr const &sceneIndex,
100 HdContainerDataSourceHandle const &inputArgs) {
101 return TfCreateRefPtr(
103 sceneIndex, inputArgs));
104 }
105
106 HDSI_API
108
111 const HdSceneIndexBaseRefPtr &GetSceneIndex() const {
112 return _sceneIndex;
113 }
114
120 HDSI_API
121 const PrimBaseHandle &GetPrim(const SdfPath &primPath) const;
122
124 template<typename PrimType>
125 std::shared_ptr<PrimType> GetTypedPrim(const SdfPath &primPath) const
126 {
127 return std::dynamic_pointer_cast<PrimType>(GetPrim(primPath));
128 }
129
130protected:
132 const HdSceneIndexBase &sender,
133 const AddedPrimEntries &entries) override;
134
136 const HdSceneIndexBase &sender,
137 const DirtiedPrimEntries &entries) override;
138
140 const HdSceneIndexBase &sender,
141 const RemovedPrimEntries &entries) override;
142
144 const HdSceneIndexBase &sender,
145 const RenamedPrimEntries &entries) override;
146
147private:
148 HDSI_API
150 HdSceneIndexBaseRefPtr const &sceneIndex,
151 HdContainerDataSourceHandle const &inputArgs);
152
153 HdSceneIndexBaseRefPtr const _sceneIndex;
154 PrimFactoryBaseHandle const _primFactory;
155
156 // _prims defined after _primFactory so that all prims
157 // are destroyed before the handle to _primFactory is
158 // released.
159 std::map<SdfPath, PrimBaseHandle> _prims;
160};
161
162PXR_NAMESPACE_CLOSE_SCOPE
163
164#endif
Abstract interface to scene data.
Definition: sceneIndex.h:54
Observer of scene data.
Base class for prims managed by the observer.
Base class for a prim factory given to the observer.
A scene index observer that turns prims in the observed scene index into instances (of RAII subclasse...
const HdSceneIndexBaseRefPtr & GetSceneIndex() const
Get observed scene index.
void PrimsRemoved(const HdSceneIndexBase &sender, const RemovedPrimEntries &entries) override
A notification indicating prims have been removed from the scene.
void PrimsRenamed(const HdSceneIndexBase &sender, const RenamedPrimEntries &entries) override
A notification indicating prims (and their descendants) have been renamed or reparented.
HDSI_API const PrimBaseHandle & GetPrim(const SdfPath &primPath) const
Get managed prim at path.
void PrimsAdded(const HdSceneIndexBase &sender, const AddedPrimEntries &entries) override
A notification indicating prims have been added to the scene.
void PrimsDirtied(const HdSceneIndexBase &sender, const DirtiedPrimEntries &entries) override
A notification indicating prim datasources have been invalidated.
std::shared_ptr< PrimType > GetTypedPrim(const SdfPath &primPath) const
Get managed prim cast to a particular type.
static HdsiPrimManagingSceneIndexObserverRefPtr New(HdSceneIndexBaseRefPtr const &sceneIndex, HdContainerDataSourceHandle const &inputArgs)
C'tor.
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
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92
A notice indicating a prim of a given type was added to the scene.
A notice indicating a prim was invalidated.