All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
indexProxy.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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 USDIMAGING_INDEXPROXY_H
25 #define USDIMAGING_INDEXPROXY_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usdImaging/usdImaging/api.h"
31 #include "pxr/usdImaging/usdImaging/delegate.h"
32 
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/usd/usd/prim.h"
35 
36 #include "pxr/base/tf/token.h"
37 
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 
48 public:
70 
71 
75  USDIMAGING_API
76  void AddDependency(SdfPath const& cachePath,
77  UsdPrim const& usdPrim);
78 
89  USDIMAGING_API
90  void InsertRprim(TfToken const& primType,
91  SdfPath const& cachePath,
92  SdfPath const& parentPath,
93  UsdPrim const& usdPrim,
94  UsdImagingPrimAdapterSharedPtr adapter =
95  UsdImagingPrimAdapterSharedPtr());
96 
97  USDIMAGING_API
98  void InsertSprim(TfToken const& primType,
99  SdfPath const& cachePath,
100  UsdPrim const& usdPrim,
101  UsdImagingPrimAdapterSharedPtr adapter =
102  UsdImagingPrimAdapterSharedPtr());
103 
104  USDIMAGING_API
105  void InsertBprim(TfToken const& primType,
106  SdfPath const& cachePath,
107  UsdPrim const& usdPrim,
108  UsdImagingPrimAdapterSharedPtr adapter =
109  UsdImagingPrimAdapterSharedPtr());
110 
111  USDIMAGING_API
112  void InsertInstancer(SdfPath const& cachePath,
113  SdfPath const& parentPath,
114  UsdPrim const& usdPrim,
115  UsdImagingPrimAdapterSharedPtr adapter =
116  UsdImagingPrimAdapterSharedPtr());
117 
118  // Refresh the prim at the specified cache path.
119  USDIMAGING_API
120  void Refresh(SdfPath const& cachePath);
121 
122  // Refresh the HdInstancer at the specified cache path.
123  USDIMAGING_API
124  void RefreshInstancer(SdfPath const& instancerPath);
125 
126  //
127  // All removals are deferred to avoid surprises during change processing.
128  //
129 
130  // Removes the Rprim at the specified cache path.
131  void RemoveRprim(SdfPath const& cachePath) {
132  _rprimsToRemove.push_back(cachePath);
133  _hdPrimInfoToRemove.push_back(cachePath);
134  _RemoveDependencies(cachePath);
135  }
136 
137  // Removes the Sprim at the specified cache path.
138  void RemoveSprim(TfToken const& primType, SdfPath const& cachePath) {
139  _TypeAndPath primToRemove = {primType, cachePath};
140  _sprimsToRemove.push_back(primToRemove);
141  _hdPrimInfoToRemove.push_back(cachePath);
142  _RemoveDependencies(cachePath);
143  }
144 
145  // Removes the Bprim at the specified cache path.
146  void RemoveBprim(TfToken const& primType, SdfPath const& cachePath) {
147  _TypeAndPath primToRemove = {primType, cachePath};
148  _bprimsToRemove.push_back(primToRemove);
149  _hdPrimInfoToRemove.push_back(cachePath);
150  _RemoveDependencies(cachePath);
151  }
152 
153  // Removes the HdInstancer at the specified cache path.
154  void RemoveInstancer(SdfPath const& cachePath) {
155  _instancersToRemove.push_back(cachePath);
156  _hdPrimInfoToRemove.push_back(cachePath);
157  _RemoveDependencies(cachePath);
158  }
159 
160  USDIMAGING_API
161  void MarkRprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
162 
163  USDIMAGING_API
164  void MarkSprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
165 
166  USDIMAGING_API
167  void MarkBprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
168 
169  USDIMAGING_API
170  void MarkInstancerDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
171 
172  USDIMAGING_API
173  bool IsRprimTypeSupported(TfToken const& typeId) const;
174 
175  USDIMAGING_API
176  bool IsSprimTypeSupported(TfToken const& typeId) const;
177 
178  USDIMAGING_API
179  bool IsBprimTypeSupported(TfToken const& typeId) const;
180 
181  // Check if the given path has been populated yet.
182  USDIMAGING_API
183  bool IsPopulated(SdfPath const& cachePath) const;
184 
185  // Recursively repopulate the specified usdPath into the render index.
186  USDIMAGING_API
187  void Repopulate(SdfPath const& usdPath);
188 
189  USDIMAGING_API
190  UsdImagingPrimAdapterSharedPtr GetMaterialAdapter(
191  UsdPrim const& materialPrim);
192 
193 private:
194  friend class UsdImagingDelegate;
196  UsdImagingDelegate::_Worker* worker)
197  : _delegate(delegate)
198  , _worker(worker)
199  {}
200 
201  bool _AddHdPrimInfo(SdfPath const& cachePath,
202  UsdPrim const& usdPrim,
203  UsdImagingPrimAdapterSharedPtr const& adapter);
204 
205  // XXX: Workaround for some bugs in USD edit processing, and weird uses
206  // of HdPrimInfo by instanced prims. Remove the dependency between
207  // a hydra prim and whatever USD prim is in its primInfo.
208  friend class UsdImagingGprimAdapter;
209  void _RemovePrimInfoDependency(SdfPath const& cachePath);
210 
211  USDIMAGING_API
212  void _RemoveDependencies(SdfPath const& cachePath);
213 
214  SdfPathVector const& _GetUsdPathsToRepopulate() {
215  return _usdPathsToRepopulate;
216  }
217  void _ProcessRemovals();
218 
219  void _AddTask(SdfPath const& usdPath);
220 
221  struct _TypeAndPath {
222  TfToken primType;
223  SdfPath cachePath;
224  };
225 
226  typedef std::vector<_TypeAndPath> _TypeAndPathVector;
227 
228  typedef std::vector<UsdImagingDelegate::_DependencyMap::value_type>
229  _DependencyVector;
230 
231  UsdImagingDelegate* _delegate;
232  UsdImagingDelegate::_Worker* _worker;
233  SdfPathVector _usdPathsToRepopulate;
234  SdfPathVector _rprimsToRemove;
235  _TypeAndPathVector _sprimsToRemove;
236  _TypeAndPathVector _bprimsToRemove;
237  SdfPathVector _instancersToRemove;
238  SdfPathVector _hdPrimInfoToRemove;
239  _DependencyVector _dependenciesToRemove;
240 };
241 
242 
243 PXR_NAMESPACE_CLOSE_SCOPE
244 
245 #endif //USDIMAGING_INDEXPROXY_H
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
Delegate support for UsdGeomGrims.
Definition: gprimAdapter.h:48
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
USDIMAGING_API void AddDependency(SdfPath const &cachePath, UsdPrim const &usdPrim)
A note on paths/prims: the core function of UsdImagingIndexProxy and UsdImagingDelegate is to maintai...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
USDIMAGING_API void InsertRprim(TfToken const &primType, SdfPath const &cachePath, SdfPath const &parentPath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
Insert a hydra prim with the specified cache path.
The primary translation layer between the Hydra (Hd) core and the Usd scene graph.
Definition: delegate.h:86