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/usd/sdf/path.h"
29#include "pxr/usdImaging/usdImaging/api.h"
30#include "pxr/usdImaging/usdImaging/instanceablePrimAdapter.h"
31
32PXR_NAMESPACE_OPEN_SCOPE
33
34
41{
42public:
44
46
50 USDIMAGING_API
52 UsdPrim const& prim,
54 UsdImagingInstancerContext const* instancerContext = NULL) override;
55
56 // If the draw mode adapter is applied to a prim, it cuts off traversal of
57 // that prim's subtree.
58 USDIMAGING_API
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 USDIMAGING_API
64 bool IsSupported(UsdImagingIndexProxy const* index) const override;
65
66 // Cards mode can be applied to instance prims, so we need to let the
67 // UsdImagingInstanceAdapter know we want special handling.
68 USDIMAGING_API
69 bool CanPopulateUsdInstance() const override;
70
71 // ---------------------------------------------------------------------- //
73 // ---------------------------------------------------------------------- //
74
75 USDIMAGING_API
76 void TrackVariability(UsdPrim const& prim,
77 SdfPath const& cachePath,
78 HdDirtyBits* timeVaryingBits,
80 instancerContext = NULL) const override;
81
82 USDIMAGING_API
83 void UpdateForTime(UsdPrim const& prim,
84 SdfPath const& cachePath,
85 UsdTimeCode time,
86 HdDirtyBits requestedBits,
88 instancerContext = NULL) const override;
89
90 // ---------------------------------------------------------------------- //
92 // ---------------------------------------------------------------------- //
93
94 USDIMAGING_API
95 HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
96 SdfPath const& cachePath,
97 TfToken const& property) override;
98
99 // Note: Resync/Remove are overridden so that we can resync/remove the
100 // material and cards rprim together, since they are populated together.
101 USDIMAGING_API
102 void ProcessPrimResync(SdfPath const& cachePath,
103 UsdImagingIndexProxy* index) override;
104
105 USDIMAGING_API
106 void ProcessPrimRemoval(SdfPath const& cachePath,
107 UsdImagingIndexProxy* index) override;
108
109 USDIMAGING_API
110 void MarkDirty(UsdPrim const& prim,
111 SdfPath const& cachePath,
112 HdDirtyBits dirty,
113 UsdImagingIndexProxy* index) override;
114
115 USDIMAGING_API
116 void MarkTransformDirty(UsdPrim const& prim,
117 SdfPath const& cachePath,
118 UsdImagingIndexProxy* index) override;
119
120 USDIMAGING_API
121 void MarkVisibilityDirty(UsdPrim const& prim,
122 SdfPath const& cachePath,
123 UsdImagingIndexProxy* index) override;
124
125 USDIMAGING_API
126 void MarkMaterialDirty(UsdPrim const& prim,
127 SdfPath const& cachePath,
128 UsdImagingIndexProxy* index) override;
129
130 // ---------------------------------------------------------------------- //
132 // ---------------------------------------------------------------------- //
133
134 USDIMAGING_API
135 VtValue Get(UsdPrim const& prim,
136 SdfPath const& cachePath,
137 TfToken const& key,
138 UsdTimeCode time,
139 VtIntArray *outIndices) const override;
140
141 USDIMAGING_API
142 HdCullStyle GetCullStyle(UsdPrim const& prim,
143 SdfPath const& cachePath,
144 UsdTimeCode time) const override;
145
146 USDIMAGING_API
148 SdfPath const& cachePath,
149 UsdTimeCode time) const override;
150
151 USDIMAGING_API
153 SdfPath const& cachePath,
154 UsdTimeCode time) const override;
155
156 USDIMAGING_API
157 bool GetDoubleSided(UsdPrim const& prim,
158 SdfPath const& cachePath,
159 UsdTimeCode time) const override;
160
161 USDIMAGING_API
163 SdfPath const& cachePath,
164 UsdTimeCode time,
165 bool ignoreRootTransform = false) const override;
166
167 USDIMAGING_API
168 SdfPath GetMaterialId(UsdPrim const& prim,
169 SdfPath const& cachePath,
170 UsdTimeCode time) const override;
171
172 USDIMAGING_API
173 VtValue GetMaterialResource(UsdPrim const& prim,
174 SdfPath const& cachePath,
175 UsdTimeCode time) const override;
176
177protected:
178 USDIMAGING_API
179 void _RemovePrim(SdfPath const& cachePath,
180 UsdImagingIndexProxy* index) override;
181
182private:
183 // For cards rendering, check if we're rendering any faces with 0 area;
184 // if so, issue a warning.
185 void _SanityCheckFaceSizes(SdfPath const& cachePath,
186 GfRange3d const& extents, uint8_t axes_mask)
187 const;
188
189 void _ComputeGeometryData(UsdPrim const& prim,
190 SdfPath const& cachePath,
191 UsdTimeCode time,
192 TfToken const& drawMode,
193 VtValue* topology,
194 VtValue* points,
195 GfRange3d* extent,
196 VtValue* uv) const;
197
198 // Check whether the given cachePath is a path to the draw mode material.
199 bool _IsMaterialPath(SdfPath const& path) const;
200
201 // Check whether the given cachePath is a path to a draw mode texture.
202 bool _IsTexturePath(SdfPath const& path) const;
203
204 // Return true if prim has a time varying extent or extentsHint attribute.
205 bool _HasVaryingExtent(UsdPrim const& prim) const;
206
207 // Check if any of the cards texture attributes are marked as time-varying.
208 void _CheckForTextureVariability(UsdPrim const& prim,
209 HdDirtyBits dirtyBits,
210 HdDirtyBits *timeVaryingBits) const;
211
212 // Computes the extents of the given prim, using UsdGeomBBoxCache.
213 // The extents are computed for purposes default/proxy/render.
214 GfRange3d _ComputeExtent(UsdPrim const& prim,
215 const UsdTimeCode& timecode) const;
216
217 // Generate geometry for "origin" draw mode.
218 void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
219 GfRange3d const& extents) const;
220
221 // Generate geometry for "bounds" draw mode.
222 void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
223 GfRange3d const& extents) const;
224
225 // Generate geometry for "cards" draw mode, cardGeometry "cross" or "box".
226 void _GenerateCardsGeometry(VtValue* topo, VtValue* points,
227 GfRange3d const& extents, uint8_t axes_mask, TfToken cardGeometry,
228 bool generateSubsets, UsdPrim const& prim) const;
229
230 // Generate geometry for "cards" draw mode, cardGeometry "fromTexture".
231 void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
232 VtValue* uv, GfRange3d* extents,
233 UsdPrim const& prim) const;
234
235 // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
236 // matrix out of image metadata.
237 bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
238 const;
239
240 // Generate texture coordinates for cards "cross"/"box" mode.
241 void _GenerateTextureCoordinates(VtValue* uv, uint8_t axes_mask) const;
242
243 // Map from cachePath to what drawMode it was populated as.
244 using _DrawModeMap = TfHashMap<SdfPath, TfToken, SdfPath::Hash>;
245 _DrawModeMap _drawModeMap;
246
247 // Map from cachePath (of gprim) to what material it's bound to.
248 using _MaterialSet = TfHashSet<SdfPath, SdfPath::Hash>;
249 using _MaterialMap = TfHashMap<SdfPath, _MaterialSet, SdfPath::Hash>;
250 _MaterialMap _materialMap;
251
252 // The default value of model:drawModeColor, fetched from the schema
253 // registry and stored for quick access...
254 GfVec3f _schemaColor;
255};
256
257
258PXR_NAMESPACE_CLOSE_SCOPE
259
260#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:290
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.
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:47
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: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...