All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  USDIMAGINGGL_API
98  void MarkDirty(UsdPrim const& prim,
99  SdfPath const& cachePath,
100  HdDirtyBits dirty,
101  UsdImagingIndexProxy* index) override;
102 
103  USDIMAGINGGL_API
104  void MarkTransformDirty(UsdPrim const& prim,
105  SdfPath const& cachePath,
106  UsdImagingIndexProxy* index) override;
107 
108  USDIMAGINGGL_API
109  void MarkVisibilityDirty(UsdPrim const& prim,
110  SdfPath const& cachePath,
111  UsdImagingIndexProxy* index) override;
112 
113  USDIMAGINGGL_API
114  void MarkMaterialDirty(UsdPrim const& prim,
115  SdfPath const& cachePath,
116  UsdImagingIndexProxy* index) override;
117 
118  // ---------------------------------------------------------------------- //
120  // ---------------------------------------------------------------------- //
121 
122  USDIMAGINGGL_API
123  VtValue Get(UsdPrim const& prim,
124  SdfPath const& cachePath,
125  TfToken const& key,
126  UsdTimeCode time,
127  VtIntArray *outIndices) const override;
128 
129  USDIMAGINGGL_API
130  HdCullStyle GetCullStyle(UsdPrim const& prim,
131  SdfPath const& cachePath,
132  UsdTimeCode time) const override;
133 
134  USDIMAGINGGL_API
135  VtValue GetTopology(UsdPrim const& prim,
136  SdfPath const& cachePath,
137  UsdTimeCode time) const override;
138 
139  USDIMAGINGGL_API
140  GfRange3d GetExtent(UsdPrim const& prim,
141  SdfPath const& cachePath,
142  UsdTimeCode time) const override;
143 
144  USDIMAGINGGL_API
145  bool GetDoubleSided(UsdPrim const& prim,
146  SdfPath const& cachePath,
147  UsdTimeCode time) const override;
148 
149  USDIMAGINGGL_API
150  GfMatrix4d GetTransform(UsdPrim const& prim,
151  SdfPath const& cachePath,
152  UsdTimeCode time,
153  bool ignoreRootTransform = false) const override;
154 
155  USDIMAGINGGL_API
156  SdfPath GetMaterialId(UsdPrim const& prim,
157  SdfPath const& cachePath,
158  UsdTimeCode time) const override;
159 
160  USDIMAGING_API
161  VtValue GetMaterialResource(UsdPrim const& prim,
162  SdfPath const& cachePath,
163  UsdTimeCode time) const override;
164 
165 protected:
166  USDIMAGINGGL_API
167  void _RemovePrim(SdfPath const& cachePath,
168  UsdImagingIndexProxy* index) override;
169 
170 private:
171  // For cards rendering, check if we're rendering any faces with 0 area;
172  // if so, issue a warning.
173  void _SanityCheckFaceSizes(SdfPath const& cachePath,
174  GfRange3d const& extents, uint8_t axes_mask)
175  const;
176 
177  void _ComputeGeometryData(UsdPrim const& prim,
178  SdfPath const& cachePath,
179  UsdTimeCode time,
180  TfToken const& drawMode,
181  VtValue* topology,
182  VtValue* points,
183  GfRange3d* extent,
184  VtValue* uv,
185  VtValue* assign) const;
186 
187  // Check whether the given cachePath is a path to the draw mode material.
188  bool _IsMaterialPath(SdfPath const& path) const;
189 
190  // Check whether the given cachePath is a path to a draw mode texture.
191  bool _IsTexturePath(SdfPath const& path) const;
192 
193  // Return true if prim has a time varying extent or extentsHint attribute.
194  bool _HasVaryingExtent(UsdPrim const& prim) const;
195 
196  // Check if any of the cards texture attributes are marked as time-varying.
197  void _CheckForTextureVariability(UsdPrim const& prim,
198  HdDirtyBits dirtyBits,
199  HdDirtyBits *timeVaryingBits) const;
200 
201  // Computes the extents of the given prim, using UsdGeomBBoxCache.
202  // The extents are computed for purposes default/proxy/render.
203  GfRange3d _ComputeExtent(UsdPrim const& prim,
204  const UsdTimeCode& timecode) const;
205 
206  // Generate geometry for "origin" draw mode.
207  void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
208  GfRange3d const& extents) const;
209 
210  // Generate geometry for "bounds" draw mode.
211  void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
212  GfRange3d const& extents) const;
213 
214  // Generate geometry for "cards" draw mode, with cardGeometry "cross".
215  void _GenerateCardsCrossGeometry(VtValue* topo, VtValue* points,
216  GfRange3d const& extents, uint8_t axes_mask) const;
217 
218  // Generate geometry for "cards" draw mode, with cardGeometry "box".
219  void _GenerateCardsBoxGeometry(VtValue* topo, VtValue* points,
220  GfRange3d const& extents, uint8_t axes_mask) const;
221 
222  // Generate geometry for "cards" draw mode, with cardGeometry "fromTexture".
223  void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
224  VtValue* uv, VtValue* assign, GfRange3d* extents,
225  UsdPrim const& prim) const;
226 
227  // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
228  // matrix out of image metadata.
229  bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
230  const;
231 
232  // Generate texture coordinates for cards "cross"/"box" mode.
233  void _GenerateTextureCoordinates(VtValue* uv, VtValue* assign,
234  uint8_t axes_mask) const;
235 
236  // Map from cachePath to what drawMode it was populated as.
237  using _DrawModeMap = TfHashMap<SdfPath, TfToken, SdfPath::Hash>;
238  _DrawModeMap _drawModeMap;
239 
240  // The default value of model:drawModeColor, fetched from the schema
241  // registry and stored for quick access...
242  GfVec3f _schemaColor;
243 };
244 
245 
246 PXR_NAMESPACE_CLOSE_SCOPE
247 
248 #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.
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, sampled over time.
Definition: attribute.h:176
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:65
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; 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:288
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:168
Delegate support for the drawMode attribute on UsdGeomModelAPI.