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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_IMAGING_USD_IMAGING_DRAW_MODE_ADAPTER_H
8 #define PXR_USD_IMAGING_USD_IMAGING_DRAW_MODE_ADAPTER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/sdf/path.h"
14 
16 
17 
18 /// \class UsdImagingDrawModeAdapter
19 ///
20 /// Delegate support for the drawMode attribute on UsdGeomModelAPI.
21 ///
24 {
25 public:
27 
29 
30  /// Called to populate the RenderIndex for this UsdPrim. The adapter is
31  /// expected to create one or more Rprims in the render index using the
32  /// given proxy.
35  UsdPrim const& prim,
37  UsdImagingInstancerContext const* instancerContext = NULL) override;
38 
39  // If the draw mode adapter is applied to a prim, it cuts off traversal of
40  // that prim's subtree.
42  bool ShouldCullChildren() const override;
43 
44  // Because draw mode can change usdImaging topology, we need to handle
45  // render index compatibility at a later point than adapter lookup.
47  bool IsSupported(UsdImagingIndexProxy const* index) const override;
48 
49  // Cards mode can be applied to instance prims, so we need to let the
50  // UsdImagingInstanceAdapter know we want special handling.
52  bool CanPopulateUsdInstance() const override;
53 
54  // ---------------------------------------------------------------------- //
55  /// \name Parallel Setup and Resolve
56  // ---------------------------------------------------------------------- //
57 
59  void TrackVariability(UsdPrim const& prim,
60  SdfPath const& cachePath,
61  HdDirtyBits* timeVaryingBits,
63  instancerContext = NULL) const override;
64 
66  void UpdateForTime(UsdPrim const& prim,
67  SdfPath const& cachePath,
69  HdDirtyBits requestedBits,
71  instancerContext = NULL) const override;
72 
73  // ---------------------------------------------------------------------- //
74  /// \name Change Processing
75  // ---------------------------------------------------------------------- //
76 
79  SdfPath const& cachePath,
80  TfToken const& property) override;
81 
82  // Note: Resync/Remove are overridden so that we can resync/remove the
83  // material and cards rprim together, since they are populated together.
85  void ProcessPrimResync(SdfPath const& cachePath,
86  UsdImagingIndexProxy* index) override;
87 
89  void ProcessPrimRemoval(SdfPath const& cachePath,
90  UsdImagingIndexProxy* index) override;
91 
93  void MarkDirty(UsdPrim const& prim,
94  SdfPath const& cachePath,
95  HdDirtyBits dirty,
96  UsdImagingIndexProxy* index) override;
97 
99  void MarkTransformDirty(UsdPrim const& prim,
100  SdfPath const& cachePath,
101  UsdImagingIndexProxy* index) override;
102 
104  void MarkVisibilityDirty(UsdPrim const& prim,
105  SdfPath const& cachePath,
106  UsdImagingIndexProxy* index) override;
107 
109  void MarkMaterialDirty(UsdPrim const& prim,
110  SdfPath const& cachePath,
111  UsdImagingIndexProxy* index) override;
112 
113  // ---------------------------------------------------------------------- //
114  /// \name Data access
115  // ---------------------------------------------------------------------- //
116 
118  VtValue Get(UsdPrim const& prim,
119  SdfPath const& cachePath,
120  TfToken const& key,
122  VtIntArray *outIndices) const override;
123 
125  HdCullStyle GetCullStyle(UsdPrim const& prim,
126  SdfPath const& cachePath,
127  UsdTimeCode time) const override;
128 
130  VtValue GetTopology(UsdPrim const& prim,
131  SdfPath const& cachePath,
132  UsdTimeCode time) const override;
133 
135  GfRange3d GetExtent(UsdPrim const& prim,
136  SdfPath const& cachePath,
137  UsdTimeCode time) const override;
138 
140  bool GetDoubleSided(UsdPrim const& prim,
141  SdfPath const& cachePath,
142  UsdTimeCode time) const override;
143 
145  GfMatrix4d GetTransform(UsdPrim const& prim,
146  SdfPath const& cachePath,
148  bool ignoreRootTransform = false) const override;
149 
151  SdfPath GetMaterialId(UsdPrim const& prim,
152  SdfPath const& cachePath,
153  UsdTimeCode time) const override;
154 
156  VtValue GetMaterialResource(UsdPrim const& prim,
157  SdfPath const& cachePath,
158  UsdTimeCode time) const override;
159 
160 protected:
162  void _RemovePrim(SdfPath const& cachePath,
163  UsdImagingIndexProxy* index) override;
164 
165 private:
166  // For cards rendering, check if we're rendering any faces with 0 area;
167  // if so, issue a warning.
168  void _SanityCheckFaceSizes(SdfPath const& cachePath,
169  GfRange3d const& extents, uint8_t axes_mask)
170  const;
171 
172  void _ComputeGeometryData(UsdPrim const& prim,
173  SdfPath const& cachePath,
175  TfToken const& drawMode,
176  VtValue* topology,
177  VtValue* points,
178  GfRange3d* extent,
179  VtValue* uv) const;
180 
181  // Check whether the given cachePath is a path to the draw mode material.
182  bool _IsMaterialPath(SdfPath const& path) const;
183 
184  // Check whether the given cachePath is a path to a draw mode texture.
185  bool _IsTexturePath(SdfPath const& path) const;
186 
187  // Return true if prim has a time varying extent or extentsHint attribute.
188  bool _HasVaryingExtent(UsdPrim const& prim) const;
189 
190  // Check if any of the cards texture attributes are marked as time-varying.
191  void _CheckForTextureVariability(UsdPrim const& prim,
192  HdDirtyBits dirtyBits,
193  HdDirtyBits *timeVaryingBits) const;
194 
195  // Computes the extents of the given prim, using UsdGeomBBoxCache.
196  // The extents are computed for purposes default/proxy/render.
197  GfRange3d _ComputeExtent(UsdPrim const& prim,
198  const UsdTimeCode& timecode) const;
199 
200  // Generate geometry for "origin" draw mode.
201  void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
202  GfRange3d const& extents) const;
203 
204  // Generate geometry for "bounds" draw mode.
205  void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
206  GfRange3d const& extents) const;
207 
208  // Generate geometry for "cards" draw mode, cardGeometry "cross" or "box".
209  void _GenerateCardsGeometry(VtValue* topo, VtValue* points,
210  GfRange3d const& extents, uint8_t axes_mask, TfToken cardGeometry,
211  bool generateSubsets, UsdPrim const& prim) const;
212 
213  // Generate geometry for "cards" draw mode, cardGeometry "fromTexture".
214  void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
215  VtValue* uv, GfRange3d* extents,
216  UsdPrim const& prim) const;
217 
218  // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
219  // matrix out of image metadata.
220  bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
221  const;
222 
223  // Generate texture coordinates for cards "cross"/"box" mode.
224  void _GenerateTextureCoordinates(VtValue* uv, uint8_t axes_mask) const;
225 
226  // Map from cachePath to what drawMode it was populated as.
228  _DrawModeMap _drawModeMap;
229 
230  // Map from cachePath (of gprim) to what material it's bound to.
233  _MaterialMap _materialMap;
234 
235  // The default value of model:drawModeColor, fetched from the schema
236  // registry and stored for quick access...
237  GfVec3f _schemaColor;
238 };
239 
240 
242 
243 #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:105
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:23
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:143
USDIMAGING_API SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override
USDIMAGING_API bool ShouldCullChildren() const override
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
Definition: vec3f.h:45
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
Definition: token.h:70
USDIMAGING_API void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=NULL) 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.
USDIMAGING_API bool CanPopulateUsdInstance() const override
Definition: prim.h:116
Definition: path.h:273
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:1425
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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 bool IsSupported(UsdImagingIndexProxy const *index) const override
Returns true if the adapter can be populated into the target index.
USDIMAGING_API void _RemovePrim(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
Returns whether custom shading of prims is enabled.
Definition: value.h:146
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