Loading...
Searching...
No Matches
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_DRAW_MODE_ADAPTER_H
25#define PXR_USD_IMAGING_USD_IMAGING_DRAW_MODE_ADAPTER_H
26
27#include "pxr/pxr.h"
28#include "pxr/usdImaging/usdImaging/api.h"
30
31PXR_NAMESPACE_OPEN_SCOPE
32
33
39{
40public:
42
43 USDIMAGING_API
45
46 USDIMAGING_API
48
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 // ---------------------------------------------------------------------- //
71 // ---------------------------------------------------------------------- //
72
73 USDIMAGING_API
74 void TrackVariability(UsdPrim const& prim,
75 SdfPath const& cachePath,
76 HdDirtyBits* timeVaryingBits,
78 instancerContext = NULL) const override;
79
80 USDIMAGING_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 USDIMAGING_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 USDIMAGING_API
100 void ProcessPrimResync(SdfPath const& cachePath,
101 UsdImagingIndexProxy* index) override;
102
103 USDIMAGING_API
104 void ProcessPrimRemoval(SdfPath const& cachePath,
105 UsdImagingIndexProxy* index) override;
106
107 USDIMAGING_API
108 void MarkDirty(UsdPrim const& prim,
109 SdfPath const& cachePath,
110 HdDirtyBits dirty,
111 UsdImagingIndexProxy* index) override;
112
113 USDIMAGING_API
114 void MarkTransformDirty(UsdPrim const& prim,
115 SdfPath const& cachePath,
116 UsdImagingIndexProxy* index) override;
117
118 USDIMAGING_API
119 void MarkVisibilityDirty(UsdPrim const& prim,
120 SdfPath const& cachePath,
121 UsdImagingIndexProxy* index) override;
122
123 USDIMAGING_API
124 void MarkMaterialDirty(UsdPrim const& prim,
125 SdfPath const& cachePath,
126 UsdImagingIndexProxy* index) override;
127
128 // ---------------------------------------------------------------------- //
130 // ---------------------------------------------------------------------- //
131
132 USDIMAGING_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 USDIMAGING_API
140 HdCullStyle GetCullStyle(UsdPrim const& prim,
141 SdfPath const& cachePath,
142 UsdTimeCode time) const override;
143
144 USDIMAGING_API
146 SdfPath const& cachePath,
147 UsdTimeCode time) const override;
148
149 USDIMAGING_API
151 SdfPath const& cachePath,
152 UsdTimeCode time) const override;
153
154 USDIMAGING_API
155 bool GetDoubleSided(UsdPrim const& prim,
156 SdfPath const& cachePath,
157 UsdTimeCode time) const override;
158
159 USDIMAGING_API
161 SdfPath const& cachePath,
162 UsdTimeCode time,
163 bool ignoreRootTransform = false) const override;
164
165 USDIMAGING_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
175protected:
176 USDIMAGING_API
177 void _RemovePrim(SdfPath const& cachePath,
178 UsdImagingIndexProxy* index) override;
179
180private:
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) 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.
242 using _DrawModeMap = TfHashMap<SdfPath, TfToken, SdfPath::Hash>;
243 _DrawModeMap _drawModeMap;
244
245 // Map from cachePath (of gprim) to what material it's bound to.
246 using _MaterialSet = TfHashSet<SdfPath, SdfPath::Hash>;
247 using _MaterialMap = TfHashMap<SdfPath, _MaterialSet, SdfPath::Hash>;
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
256PXR_NAMESPACE_CLOSE_SCOPE
257
258#endif // PXR_USD_IMAGING_USD_IMAGING_DRAW_MODE_ADAPTER_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
Delegate support for the drawMode attribute on UsdGeomModelAPI.
SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override
Called to populate the RenderIndex for this UsdPrim.
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.
bool IsSupported(UsdImagingIndexProxy const *index) const override
Returns true if the adapter can be populated into the target index.
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:47
Base class for all PrimAdapters.
Definition: primAdapter.h:70
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:84
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...