HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sceneIndexObserver.h
Go to the documentation of this file.
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_OBSERVER_H
8 #define PXR_IMAGING_HD_SCENE_INDEX_OBSERVER_H
9 
10 #include "pxr/pxr.h"
11 
13 
14 #include "pxr/usd/sdf/path.h"
15 
16 #include "pxr/imaging/hd/api.h"
18 
20 
21 class HdSceneIndexBase;
22 
25 
26 /// \class HdSceneIndexObserver
27 ///
28 /// Observer of scene data. From the time an observer is registered with
29 /// a scene index, the scene index will send it diffs as the scene changes.
30 ///
32 {
33 public:
34 
35  HD_API
36  virtual ~HdSceneIndexObserver();
37 
38  /// A notice indicating a prim of a given type was added to the scene.
39  /// Note that \p primPath might already exist in the scene, in which case
40  /// this acts as a resync or change-of-primtype notice.
42  {
45 
46  AddedPrimEntry() = default;
48  : primPath(primPath)
49  , primType(primType)
50  {
51  }
52  };
54 
55  //----------------------------------
56 
57  /// A notice indicating a prim subtree was removed from the scene.
58  /// Note that all prims which are descendants of \p primPath should be
59  /// removed as well.
61  {
63 
64  RemovedPrimEntry() = default;
66  : primPath(primPath)
67  {}
68  };
69 
71 
72  //----------------------------------
73 
74  /// A notice indicating a prim was invalidated. \p dirtyLocators identifies
75  /// a set of datasources for which data needs to be re-pulled. Locators
76  /// are hierarchical: if \p primvars was invalidated, \p primvars/color
77  /// was considered invalidated as well. This notice only affects the named
78  /// prim; descendants of \p primPath are unaffected.
80  {
83 
84  DirtiedPrimEntry() = default;
86  const SdfPath &primPath,
88  : primPath(primPath)
89  , dirtyLocators(dirtyLocators)
90  {}
91  };
92 
94 
95  //----------------------------------
96 
97  /// A notice indicating a prim (and its descendents) was renamed or
98  /// reparented.
100  {
103 
104  RenamedPrimEntry() = default;
106  const SdfPath &oldPrimPath,
107  const SdfPath &newPrimPath)
108  : oldPrimPath(oldPrimPath)
109  , newPrimPath(newPrimPath)
110  {}
111  };
112 
114 
115  //-------------------------------------------------------------------------
116 
117  /// A notification indicating prims have been added to the scene. The
118  /// set of scene prims compiled from added/removed notices should match
119  /// the set from a traversal based on \p sender.GetChildPrimNames. Each
120  /// prim has a path and type. It's possible for \p PrimsAdded to be called
121  /// for prims that already exist; in that case, observers should be sure to
122  /// update the prim type, in case it changed, and resync the prim. This
123  /// function is not expected to be threadsafe.
124  HD_API
125  virtual void PrimsAdded(
126  const HdSceneIndexBase &sender,
127  const AddedPrimEntries &entries) = 0;
128 
129  /// A notification indicating prims have been removed from the scene.
130  /// Note that this message is considered hierarchical; if \p /Path is
131  /// removed, \p /Path/child is considered removed as well. This function is
132  /// not expected to be threadsafe.
133  HD_API
134  virtual void PrimsRemoved(
135  const HdSceneIndexBase &sender,
136  const RemovedPrimEntries &entries) = 0;
137 
138  /// A notification indicating prim datasources have been invalidated.
139  /// This message is not considered hierarchical on \p primPath; if \p
140  /// /Path is dirtied, \p /Path/child is not necessarily dirtied. However
141  /// datasource locators are considered hierarchical: if \p primvars is
142  /// dirtied on a prim, \p primvars/color is considered dirtied as well.
143  /// This function is not expected to be threadsafe.
144  HD_API
145  virtual void PrimsDirtied(
146  const HdSceneIndexBase &sender,
147  const DirtiedPrimEntries &entries) = 0;
148 
149  /// A notification indicating prims (and their descendants) have been
150  /// renamed or reparented.
151  /// This function is not expected to be threadsafe.
152  HD_API
153  virtual void PrimsRenamed(
154  const HdSceneIndexBase &sender,
155  const RenamedPrimEntries &entries) = 0;
156 
157  /// A utility for converting prims renamed messages into equivalent removed
158  /// and added notices.
159  HD_API
161  const HdSceneIndexBase &sender,
162  const HdSceneIndexObserver::RenamedPrimEntries &renamedEntries,
163  HdSceneIndexObserver::RemovedPrimEntries *outputRemovedEntries,
164  HdSceneIndexObserver::AddedPrimEntries *outputAddedEntries);
165 
166  /// A utility for converting prims renamed messages into equivalent removed
167  /// and added notices at the observer level
168  HD_API
170  const HdSceneIndexBase &sender,
171  const HdSceneIndexObserver::RenamedPrimEntries &renamedEntries,
172  HdSceneIndexObserver *observer);
173 
174 
175 
176 
177 
178 };
179 
181 
182 #endif // PXR_IMAGING_HD_SCENE_INDEX_OBSERVER_H
virtual HD_API void PrimsDirtied(const HdSceneIndexBase &sender, const DirtiedPrimEntries &entries)=0
TF_DECLARE_WEAK_PTRS(HdSceneIndexObserver)
HdDataSourceLocatorSet dirtyLocators
RemovedPrimEntry()=default
#define HD_API
Definition: api.h:23
TF_DECLARE_WEAK_AND_REF_PTRS(HdSceneIndexBase)
SdfPath oldPrimPath
RemovedPrimEntry(const SdfPath &primPath)
Definition: token.h:70
virtual HD_API void PrimsRenamed(const HdSceneIndexBase &sender, const RenamedPrimEntries &entries)=0
SdfPath primPath
virtual HD_API void PrimsRemoved(const HdSceneIndexBase &sender, const RemovedPrimEntries &entries)=0
SdfPath newPrimPath
SdfPath primPath
AddedPrimEntry()=default
Definition: path.h:273
AddedPrimEntry(const SdfPath &primPath, const TfToken &primType)
TfToken primType
DirtiedPrimEntry(const SdfPath &primPath, const HdDataSourceLocatorSet &dirtyLocators)
virtual HD_API ~HdSceneIndexObserver()
DirtiedPrimEntry()=default
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual HD_API void PrimsAdded(const HdSceneIndexBase &sender, const AddedPrimEntries &entries)=0
SdfPath primPath
RenamedPrimEntry()=default
RenamedPrimEntry(const SdfPath &oldPrimPath, const SdfPath &newPrimPath)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static HD_API void ConvertPrimsRenamedToRemovedAndAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RenamedPrimEntries &renamedEntries, HdSceneIndexObserver::RemovedPrimEntries *outputRemovedEntries, HdSceneIndexObserver::AddedPrimEntries *outputAddedEntries)