drawModeAdapter.h
1 //
2 // Copyright 2016 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_USD_IMAGING_USD_IMAGING_GL_DRAW_MODE_ADAPTER_H
25 #define PXR_USD_IMAGING_USD_IMAGING_GL_DRAW_MODE_ADAPTER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usdImaging/usdImagingGL/api.h"
30 
31 PXR_NAMESPACE_OPEN_SCOPE
32 
33 
39 {
40 public:
42 
43  USDIMAGINGGL_API
45 
46  USDIMAGINGGL_API
47  ~UsdImagingGLDrawModeAdapter() override;
48 
53  UsdPrim const& prim,
54  UsdImagingIndexProxy* index,
55  UsdImagingInstancerContext const* instancerContext = NULL) override;
56 
57  // If the draw mode adapter is applied to a prim, it cuts off traversal of
58  // that prim's subtree.
59  bool ShouldCullChildren() const override;
60 
61  // Because draw mode can change usdImaging topology, we need to handle
62  // render index compatibility at a later point than adapter lookup.
63  bool IsSupported(UsdImagingIndexProxy const* index) const override;
64 
65  // Cards mode can be applied to instance prims, so we need to let the
66  // UsdImagingInstanceAdapter know we want special handling.
67  bool CanPopulateUsdInstance() const override;
68 
69  // ---------------------------------------------------------------------- //
71  // ---------------------------------------------------------------------- //
72 
73  USDIMAGINGGL_API
74  void TrackVariability(UsdPrim const& prim,
75  SdfPath const& cachePath,
76  HdDirtyBits* timeVaryingBits,
78  instancerContext = NULL) const override;
79 
80  USDIMAGINGGL_API
81  void UpdateForTime(UsdPrim const& prim,
82  SdfPath const& cachePath,
83  UsdTimeCode time,
84  HdDirtyBits requestedBits,
86  instancerContext = NULL) const override;
87 
88  // ---------------------------------------------------------------------- //
90  // ---------------------------------------------------------------------- //
91 
92  USDIMAGINGGL_API
93  HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
94  SdfPath const& cachePath,
95  TfToken const& property) override;
96 
97  // Note: Resync/Remove are overridden so that we can resync/remove the
98  // material and cards rprim together, since they are populated together.
99  USDIMAGINGGL_API
100  void ProcessPrimResync(SdfPath const& cachePath,
101  UsdImagingIndexProxy* index) override;
102 
103  USDIMAGINGGL_API
104  void ProcessPrimRemoval(SdfPath const& cachePath,
105  UsdImagingIndexProxy* index) override;
106 
107  USDIMAGINGGL_API
108  void MarkDirty(UsdPrim const& prim,
109  SdfPath const& cachePath,
110  HdDirtyBits dirty,
111  UsdImagingIndexProxy* index) override;
112 
113  USDIMAGINGGL_API
114  void MarkTransformDirty(UsdPrim const& prim,
115  SdfPath const& cachePath,
116  UsdImagingIndexProxy* index) override;
117 
118  USDIMAGINGGL_API
119  void MarkVisibilityDirty(UsdPrim const& prim,
120  SdfPath const& cachePath,
121  UsdImagingIndexProxy* index) override;
122 
123  USDIMAGINGGL_API
124  void MarkMaterialDirty(UsdPrim const& prim,
125  SdfPath const& cachePath,
126  UsdImagingIndexProxy* index) override;
127 
128  // ---------------------------------------------------------------------- //
130  // ---------------------------------------------------------------------- //
131 
132  USDIMAGINGGL_API
133  VtValue Get(UsdPrim const& prim,
134  SdfPath const& cachePath,
135  TfToken const& key,
136  UsdTimeCode time,
137  VtIntArray *outIndices) const override;
138 
139  USDIMAGINGGL_API
140  HdCullStyle GetCullStyle(UsdPrim const& prim,
141  SdfPath const& cachePath,
142  UsdTimeCode time) const override;
143 
144  USDIMAGINGGL_API
145  VtValue GetTopology(UsdPrim const& prim,
146  SdfPath const& cachePath,
147  UsdTimeCode time) const override;
148 
149  USDIMAGINGGL_API
150  GfRange3d GetExtent(UsdPrim const& prim,
151  SdfPath const& cachePath,
152  UsdTimeCode time) const override;
153 
154  USDIMAGINGGL_API
155  bool GetDoubleSided(UsdPrim const& prim,
156  SdfPath const& cachePath,
157  UsdTimeCode time) const override;
158 
159  USDIMAGINGGL_API
160  GfMatrix4d GetTransform(UsdPrim const& prim,
161  SdfPath const& cachePath,
162  UsdTimeCode time,
163  bool ignoreRootTransform = false) const override;
164 
165  USDIMAGINGGL_API
166  SdfPath GetMaterialId(UsdPrim const& prim,
167  SdfPath const& cachePath,
168  UsdTimeCode time) const override;
169 
170  USDIMAGING_API
171  VtValue GetMaterialResource(UsdPrim const& prim,
172  SdfPath const& cachePath,
173  UsdTimeCode time) const override;
174 
175 protected:
176  USDIMAGINGGL_API
177  void _RemovePrim(SdfPath const& cachePath,
178  UsdImagingIndexProxy* index) override;
179 
180 private:
181  // For cards rendering, check if we're rendering any faces with 0 area;
182  // if so, issue a warning.
183  void _SanityCheckFaceSizes(SdfPath const& cachePath,
184  GfRange3d const& extents, uint8_t axes_mask)
185  const;
186 
187  void _ComputeGeometryData(UsdPrim const& prim,
188  SdfPath const& cachePath,
189  UsdTimeCode time,
190  TfToken const& drawMode,
191  VtValue* topology,
192  VtValue* points,
193  GfRange3d* extent,
194  VtValue* uv,
195  VtValue* assign) const;
196 
197  // Check whether the given cachePath is a path to the draw mode material.
198  bool _IsMaterialPath(SdfPath const& path) const;
199 
200  // Check whether the given cachePath is a path to a draw mode texture.
201  bool _IsTexturePath(SdfPath const& path) const;
202 
203  // Return true if prim has a time varying extent or extentsHint attribute.
204  bool _HasVaryingExtent(UsdPrim const& prim) const;
205 
206  // Check if any of the cards texture attributes are marked as time-varying.
207  void _CheckForTextureVariability(UsdPrim const& prim,
208  HdDirtyBits dirtyBits,
209  HdDirtyBits *timeVaryingBits) const;
210 
211  // Computes the extents of the given prim, using UsdGeomBBoxCache.
212  // The extents are computed for purposes default/proxy/render.
213  GfRange3d _ComputeExtent(UsdPrim const& prim,
214  const UsdTimeCode& timecode) const;
215 
216  // Generate geometry for "origin" draw mode.
217  void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
218  GfRange3d const& extents) const;
219 
220  // Generate geometry for "bounds" draw mode.
221  void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
222  GfRange3d const& extents) const;
223 
224  // Generate geometry for "cards" draw mode, with cardGeometry "cross".
225  void _GenerateCardsCrossGeometry(VtValue* topo, VtValue* points,
226  GfRange3d const& extents, uint8_t axes_mask) const;
227 
228  // Generate geometry for "cards" draw mode, with cardGeometry "box".
229  void _GenerateCardsBoxGeometry(VtValue* topo, VtValue* points,
230  GfRange3d const& extents, uint8_t axes_mask) const;
231 
232  // Generate geometry for "cards" draw mode, with cardGeometry "fromTexture".
233  void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
234  VtValue* uv, VtValue* assign, GfRange3d* extents,
235  UsdPrim const& prim) const;
236 
237  // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
238  // matrix out of image metadata.
239  bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
240  const;
241 
242  // Generate texture coordinates for cards "cross"/"box" mode.
243  void _GenerateTextureCoordinates(VtValue* uv, VtValue* assign,
244  uint8_t axes_mask) const;
245 
246  // Map from cachePath to what drawMode it was populated as.
247  using _DrawModeMap = TfHashMap<SdfPath, TfToken, SdfPath::Hash>;
248  _DrawModeMap _drawModeMap;
249 
250  // Map from cachePath (of gprim) to what material it's bound to.
251  using _MaterialMap = TfHashMap<SdfPath, SdfPath, SdfPath::Hash>;
252  _MaterialMap _materialMap;
253 
254  // The default value of model:drawModeColor, fetched from the schema
255  // registry and stored for quick access...
256  GfVec3f _schemaColor;
257 };
258 
259 
260 PXR_NAMESPACE_CLOSE_SCOPE
261 
262 #endif // PXR_USD_IMAGING_USD_IMAGING_GL_DRAW_MODE_ADAPTER_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
USDIMAGINGGL_API HdCullStyle GetCullStyle(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Gets the cullstyle of a specific path in the scene graph.
USDIMAGINGGL_API void TrackVariability(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits *timeVaryingBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
For the given prim, variability is detected and stored in timeVaryingBits.
USDIMAGINGGL_API void ProcessPrimResync(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
When a PrimResync event occurs, the prim may have been deleted entirely, adapter plug-ins should over...
SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override
Called to populate the RenderIndex for this UsdPrim.
bool IsSupported(UsdImagingIndexProxy const *index) const override
Returns true if the adapter can be populated into the target index.
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
USDIMAGINGGL_API bool GetDoubleSided(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Reads double-sided from the given prim. If not authored, returns false.
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
USDIMAGINGGL_API void ProcessPrimRemoval(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
Removes all associated Rprims and dependencies from the render index without scheduling them for repo...
USDIMAGINGGL_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Gets the topology object of a specific Usd prim.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
Base class for all PrimAdapters.
Definition: primAdapter.h:67
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:132
USDIMAGINGGL_API void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
Populates the cache for the given prim, time and requestedBits.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
USDIMAGINGGL_API GfMatrix4d GetTransform(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, bool ignoreRootTransform=false) const override
Fetches the transform for the given prim at the given time from a pre-computed cache of prim transfor...
USDIMAGINGGL_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Reads the extent from the given prim.
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...
USDIMAGINGGL_API VtValue Get(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, VtIntArray *outIndices) const override
Gets the value of the parameter named key for the given prim (which has the given cache path) and giv...
USDIMAGINGGL_API HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &property) override
Returns a bit mask of attributes to be updated, or HdChangeTracker::AllDirty if the entire prim must ...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
Delegate support for the drawMode attribute on UsdGeomModelAPI.