HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drawModeAdapter.h
Go to the documentation of this file.
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_DRAW_MODE_ADAPTER_H
25 #define PXR_USD_IMAGING_USD_IMAGING_DRAW_MODE_ADAPTER_H
26 
27 #include "pxr/pxr.h"
30 
32 
33 
34 /// \class UsdImagingDrawModeAdapter
35 ///
36 /// Delegate support for the drawMode attribute on UsdGeomModelAPI.
37 ///
39 {
40 public:
42 
45 
47  ~UsdImagingDrawModeAdapter() override;
48 
49  /// Called to populate the RenderIndex for this UsdPrim. The adapter is
50  /// expected to create one or more Rprims in the render index using the
51  /// given proxy.
53  UsdPrim const& prim,
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  // ---------------------------------------------------------------------- //
70  /// \name Parallel Setup and Resolve
71  // ---------------------------------------------------------------------- //
72 
74  void TrackVariability(UsdPrim const& prim,
75  SdfPath const& cachePath,
76  HdDirtyBits* timeVaryingBits,
78  instancerContext = NULL) const override;
79 
81  void UpdateForTime(UsdPrim const& prim,
82  SdfPath const& cachePath,
84  HdDirtyBits requestedBits,
86  instancerContext = NULL) const override;
87 
88  // ---------------------------------------------------------------------- //
89  /// \name Change Processing
90  // ---------------------------------------------------------------------- //
91 
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.
100  void ProcessPrimResync(SdfPath const& cachePath,
101  UsdImagingIndexProxy* index) override;
102 
104  void ProcessPrimRemoval(SdfPath const& cachePath,
105  UsdImagingIndexProxy* index) override;
106 
108  void MarkDirty(UsdPrim const& prim,
109  SdfPath const& cachePath,
110  HdDirtyBits dirty,
111  UsdImagingIndexProxy* index) override;
112 
114  void MarkTransformDirty(UsdPrim const& prim,
115  SdfPath const& cachePath,
116  UsdImagingIndexProxy* index) override;
117 
119  void MarkVisibilityDirty(UsdPrim const& prim,
120  SdfPath const& cachePath,
121  UsdImagingIndexProxy* index) override;
122 
124  void MarkMaterialDirty(UsdPrim const& prim,
125  SdfPath const& cachePath,
126  UsdImagingIndexProxy* index) override;
127 
128  // ---------------------------------------------------------------------- //
129  /// \name Data access
130  // ---------------------------------------------------------------------- //
131 
133  VtValue Get(UsdPrim const& prim,
134  SdfPath const& cachePath,
135  TfToken const& key,
137  VtIntArray *outIndices) const override;
138 
140  HdCullStyle GetCullStyle(UsdPrim const& prim,
141  SdfPath const& cachePath,
142  UsdTimeCode time) const override;
143 
145  VtValue GetTopology(UsdPrim const& prim,
146  SdfPath const& cachePath,
147  UsdTimeCode time) const override;
148 
150  GfRange3d GetExtent(UsdPrim const& prim,
151  SdfPath const& cachePath,
152  UsdTimeCode time) const override;
153 
155  bool GetDoubleSided(UsdPrim const& prim,
156  SdfPath const& cachePath,
157  UsdTimeCode time) const override;
158 
160  GfMatrix4d GetTransform(UsdPrim const& prim,
161  SdfPath const& cachePath,
163  bool ignoreRootTransform = false) const override;
164 
166  SdfPath GetMaterialId(UsdPrim const& prim,
167  SdfPath const& cachePath,
168  UsdTimeCode time) const override;
169 
171  VtValue GetMaterialResource(UsdPrim const& prim,
172  SdfPath const& cachePath,
173  UsdTimeCode time) const override;
174 
175 protected:
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,
190  TfToken const& drawMode,
191  VtValue* topology,
192  VtValue* points,
193  GfRange3d* extent,
194  VtValue* uv) const;
195 
196  // Check whether the given cachePath is a path to the draw mode material.
197  bool _IsMaterialPath(SdfPath const& path) const;
198 
199  // Check whether the given cachePath is a path to a draw mode texture.
200  bool _IsTexturePath(SdfPath const& path) const;
201 
202  // Return true if prim has a time varying extent or extentsHint attribute.
203  bool _HasVaryingExtent(UsdPrim const& prim) const;
204 
205  // Check if any of the cards texture attributes are marked as time-varying.
206  void _CheckForTextureVariability(UsdPrim const& prim,
207  HdDirtyBits dirtyBits,
208  HdDirtyBits *timeVaryingBits) const;
209 
210  // Computes the extents of the given prim, using UsdGeomBBoxCache.
211  // The extents are computed for purposes default/proxy/render.
212  GfRange3d _ComputeExtent(UsdPrim const& prim,
213  const UsdTimeCode& timecode) const;
214 
215  // Generate geometry for "origin" draw mode.
216  void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
217  GfRange3d const& extents) const;
218 
219  // Generate geometry for "bounds" draw mode.
220  void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
221  GfRange3d const& extents) const;
222 
223  // Generate geometry for "cards" draw mode, cardGeometry "cross" or "box".
224  void _GenerateCardsGeometry(VtValue* topo, VtValue* points,
225  GfRange3d const& extents, uint8_t axes_mask, TfToken cardGeometry,
226  bool generateSubsets, UsdPrim const& prim) const;
227 
228  // Generate geometry for "cards" draw mode, cardGeometry "fromTexture".
229  void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
230  VtValue* uv, GfRange3d* extents,
231  UsdPrim const& prim) const;
232 
233  // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
234  // matrix out of image metadata.
235  bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
236  const;
237 
238  // Generate texture coordinates for cards "cross"/"box" mode.
239  void _GenerateTextureCoordinates(VtValue* uv, uint8_t axes_mask) const;
240 
241  // Map from cachePath to what drawMode it was populated as.
243  _DrawModeMap _drawModeMap;
244 
245  // Map from cachePath (of gprim) to what material it's bound to.
248  _MaterialMap _materialMap;
249 
250  // The default value of model:drawModeColor, fetched from the schema
251  // registry and stored for quick access...
252  GfVec3f _schemaColor;
253 };
254 
255 
257 
258 #endif // PXR_USD_IMAGING_USD_IMAGING_DRAW_MODE_ADAPTER_H
USDIMAGING_API GfMatrix4d GetTransform(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, bool ignoreRootTransform=false) const override
HdCullStyle
Definition: enums.h:122
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
USDIMAGING_API VtValue GetMaterialResource(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
The root transform provided by the delegate.
#define USDIMAGING_API
Definition: api.h:40
GA_API const UT_StringHolder uv
GT_API const UT_StringHolder time
USDIMAGING_API void ProcessPrimResync(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
USDIMAGING_API void TrackVariability(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits *timeVaryingBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
uint32_t HdDirtyBits
Definition: types.h:158
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
Definition: vec3f.h:62
USDIMAGING_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.
USDIMAGING_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override
Definition: token.h:87
USDIMAGING_API void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
bool ShouldCullChildren() const override
GT_API const UT_StringHolder topology
USDIMAGING_API HdCullStyle GetCullStyle(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Gets the cullstyle of a specific path in the scene graph.
bool IsSupported(UsdImagingIndexProxy const *index) const override
Returns true if the adapter can be populated into the target index.
Definition: prim.h:133
USDIMAGING_API UsdImagingDrawModeAdapter()
Definition: path.h:290
USDIMAGING_API void ProcessPrimRemoval(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
USDIMAGING_API SdfPath GetMaterialId(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
The root transform provided by the delegate.
USDIMAGING_API void MarkDirty(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits dirty, UsdImagingIndexProxy *index) override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
USDIMAGING_API void MarkVisibilityDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
USDIMAGING_API void MarkTransformDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
USDIMAGING_API void MarkMaterialDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
USDIMAGING_API HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &property) override
USDIMAGING_API ~UsdImagingDrawModeAdapter() override
bool CanPopulateUsdInstance() const override
USDIMAGING_API void _RemovePrim(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
Provides to paramName->UsdAttribute value mappings.
Definition: value.h:164
USDIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
USDIMAGING_API VtValue Get(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, VtIntArray *outIndices) const override