All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
drawModeAdapter.h
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"
12#include "pxr/usdImaging/usdImaging/api.h"
13#include "pxr/usdImaging/usdImaging/instanceablePrimAdapter.h"
14
15PXR_NAMESPACE_OPEN_SCOPE
16
17
24{
25public:
27
29
33 USDIMAGING_API
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.
41 USDIMAGING_API
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.
46 USDIMAGING_API
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.
51 USDIMAGING_API
52 bool CanPopulateUsdInstance() const override;
53
54 // ---------------------------------------------------------------------- //
56 // ---------------------------------------------------------------------- //
57
58 USDIMAGING_API
59 void TrackVariability(UsdPrim const& prim,
60 SdfPath const& cachePath,
61 HdDirtyBits* timeVaryingBits,
63 instancerContext = NULL) const override;
64
65 USDIMAGING_API
66 void UpdateForTime(UsdPrim const& prim,
67 SdfPath const& cachePath,
68 UsdTimeCode time,
69 HdDirtyBits requestedBits,
71 instancerContext = NULL) const override;
72
73 // ---------------------------------------------------------------------- //
75 // ---------------------------------------------------------------------- //
76
77 USDIMAGING_API
78 HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
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.
84 USDIMAGING_API
85 void ProcessPrimResync(SdfPath const& cachePath,
86 UsdImagingIndexProxy* index) override;
87
88 USDIMAGING_API
89 void ProcessPrimRemoval(SdfPath const& cachePath,
90 UsdImagingIndexProxy* index) override;
91
92 USDIMAGING_API
93 void MarkDirty(UsdPrim const& prim,
94 SdfPath const& cachePath,
95 HdDirtyBits dirty,
96 UsdImagingIndexProxy* index) override;
97
98 USDIMAGING_API
99 void MarkTransformDirty(UsdPrim const& prim,
100 SdfPath const& cachePath,
101 UsdImagingIndexProxy* index) override;
102
103 USDIMAGING_API
104 void MarkVisibilityDirty(UsdPrim const& prim,
105 SdfPath const& cachePath,
106 UsdImagingIndexProxy* index) override;
107
108 USDIMAGING_API
109 void MarkMaterialDirty(UsdPrim const& prim,
110 SdfPath const& cachePath,
111 UsdImagingIndexProxy* index) override;
112
113 // ---------------------------------------------------------------------- //
115 // ---------------------------------------------------------------------- //
116
117 USDIMAGING_API
118 VtValue Get(UsdPrim const& prim,
119 SdfPath const& cachePath,
120 TfToken const& key,
121 UsdTimeCode time,
122 VtIntArray *outIndices) const override;
123
124 USDIMAGING_API
125 HdCullStyle GetCullStyle(UsdPrim const& prim,
126 SdfPath const& cachePath,
127 UsdTimeCode time) const override;
128
129 USDIMAGING_API
131 SdfPath const& cachePath,
132 UsdTimeCode time) const override;
133
134 USDIMAGING_API
136 SdfPath const& cachePath,
137 UsdTimeCode time) const override;
138
139 USDIMAGING_API
140 bool GetDoubleSided(UsdPrim const& prim,
141 SdfPath const& cachePath,
142 UsdTimeCode time) const override;
143
144 USDIMAGING_API
146 SdfPath const& cachePath,
147 UsdTimeCode time,
148 bool ignoreRootTransform = false) const override;
149
150 USDIMAGING_API
151 SdfPath GetMaterialId(UsdPrim const& prim,
152 SdfPath const& cachePath,
153 UsdTimeCode time) const override;
154
155 USDIMAGING_API
156 VtValue GetMaterialResource(UsdPrim const& prim,
157 SdfPath const& cachePath,
158 UsdTimeCode time) const override;
159
160protected:
161 USDIMAGING_API
162 void _RemovePrim(SdfPath const& cachePath,
163 UsdImagingIndexProxy* index) override;
164
165private:
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,
174 UsdTimeCode time,
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.
227 using _DrawModeMap = TfHashMap<SdfPath, TfToken, SdfPath::Hash>;
228 _DrawModeMap _drawModeMap;
229
230 // Map from cachePath (of gprim) to what material it's bound to.
231 using _MaterialSet = TfHashSet<SdfPath, SdfPath::Hash>;
232 using _MaterialMap = TfHashMap<SdfPath, _MaterialSet, SdfPath::Hash>;
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
241PXR_NAMESPACE_CLOSE_SCOPE
242
243#endif // PXR_USD_IMAGING_USD_IMAGING_DRAW_MODE_ADAPTER_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:160
Delegate support for the drawMode attribute on UsdGeomModelAPI.
USDIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Reads the extent from the given prim.
USDIMAGING_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 ...
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
Gets the topology object of a specific Usd prim.
USDIMAGING_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...
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 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.
USDIMAGING_API bool IsSupported(UsdImagingIndexProxy const *index) const override
Returns true if the adapter can be populated into the target index.
USDIMAGING_API SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override
Called to populate the RenderIndex for this UsdPrim.
USDIMAGING_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.
USDIMAGING_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...
USDIMAGING_API void ProcessPrimRemoval(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
Removes all associated Rprims and dependencies from the render index without scheduling them for repo...
USDIMAGING_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...
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:30
An abstract adapter class for prims that are instanceable.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:67
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...