Loading...
Searching...
No Matches
skeletonAdapter.h
1//
2// Copyright 2018 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_SKEL_IMAGING_SKELETON_ADAPTER_H
25#define PXR_USD_IMAGING_USD_SKEL_IMAGING_SKELETON_ADAPTER_H
26
27#include "pxr/pxr.h"
28#include "pxr/usdImaging/usdImaging/instanceablePrimAdapter.h"
29#include "pxr/usdImaging/usdSkelImaging/api.h"
30
31#include "pxr/imaging/hd/meshTopology.h"
32
38
39#include <unordered_map>
40
41
42PXR_NAMESPACE_OPEN_SCOPE
43
44
49class UsdSkelImagingSkeletonAdapter : public UsdImagingInstanceablePrimAdapter
50{
51public:
52 using BaseAdapter = UsdImagingInstanceablePrimAdapter;
53
54 UsdSkelImagingSkeletonAdapter()
55 : BaseAdapter()
56 {}
57
58 USDSKELIMAGING_API
59 virtual ~UsdSkelImagingSkeletonAdapter();
60
61 USDSKELIMAGING_API
63 Populate(const UsdPrim& prim,
66 instancerContext=nullptr) override;
67
68 USDSKELIMAGING_API
69 bool IsSupported(const UsdImagingIndexProxy* index) const override;
70
71 // ---------------------------------------------------------------------- //
73 // ---------------------------------------------------------------------- //
74
76 USDSKELIMAGING_API
77 void TrackVariability(const UsdPrim& prim,
78 const SdfPath& cachePath,
79 HdDirtyBits* timeVaryingBits,
81 instancerContext = nullptr) const override;
82
84 USDSKELIMAGING_API
85 void UpdateForTime(const UsdPrim& prim,
86 const SdfPath& cachePath,
87 UsdTimeCode time,
88 HdDirtyBits requestedBits,
90 instancerContext=nullptr) const override;
91
92 // ---------------------------------------------------------------------- //
94 // ---------------------------------------------------------------------- //
95
96 USDSKELIMAGING_API
97 HdDirtyBits ProcessPropertyChange(const UsdPrim& prim,
98 const SdfPath& cachePath,
99 const TfToken& propertyName) override;
100
101 USDSKELIMAGING_API
102 void ProcessPrimResync(SdfPath const& primPath,
103 UsdImagingIndexProxy* index) override;
104
105 USDSKELIMAGING_API
106 void ProcessPrimRemoval(SdfPath const& primPath,
107 UsdImagingIndexProxy* index) override;
108
109 USDSKELIMAGING_API
110 void MarkDirty(const UsdPrim& prim,
111 const SdfPath& cachePath,
112 HdDirtyBits dirty,
113 UsdImagingIndexProxy* index) override;
114
115 USDSKELIMAGING_API
116 void MarkRefineLevelDirty(UsdPrim const& prim,
117 SdfPath const& cachePath,
118 UsdImagingIndexProxy* index) override;
119
120 USDSKELIMAGING_API
121 void MarkReprDirty(UsdPrim const& prim,
122 SdfPath const& cachePath,
123 UsdImagingIndexProxy* index) override;
124
125 USDSKELIMAGING_API
126 void MarkCullStyleDirty(UsdPrim const& prim,
127 SdfPath const& cachePath,
128 UsdImagingIndexProxy* index) override;
129
130 USDSKELIMAGING_API
131 void MarkRenderTagDirty(UsdPrim const& prim,
132 SdfPath const& cachePath,
133 UsdImagingIndexProxy* index) override;
134
135 USDSKELIMAGING_API
136 void MarkTransformDirty(const UsdPrim& prim,
137 const SdfPath& cachePath,
138 UsdImagingIndexProxy* index) override;
139
140 USDSKELIMAGING_API
141 void MarkVisibilityDirty(const UsdPrim& prim,
142 const SdfPath& cachePath,
143 UsdImagingIndexProxy* index) override;
144
145 USDSKELIMAGING_API
146 void MarkMaterialDirty(const UsdPrim& prim,
147 const SdfPath& cachePath,
148 UsdImagingIndexProxy* index) override;
149
150 // ---------------------------------------------------------------------- //
152 // ---------------------------------------------------------------------- //
153 USDSKELIMAGING_API
154 void InvokeComputation(SdfPath const& cachePath,
155 HdExtComputationContext* context) override;
156
157 // ---------------------------------------------------------------------- //
159 // ---------------------------------------------------------------------- //
160
161 USDSKELIMAGING_API
162 void RegisterSkelBinding(UsdSkelBinding const& binding);
163
164 // ---------------------------------------------------------------------- //
166 // ---------------------------------------------------------------------- //
167
168 USDSKELIMAGING_API
170 SdfPath const& cachePath,
171 UsdTimeCode time) const override;
172
173 USDSKELIMAGING_API
174 VtValue GetTopology(UsdPrim const& prim,
175 SdfPath const& cachePath,
176 UsdTimeCode time) const override;
177
178 USDSKELIMAGING_API
179 GfRange3d GetExtent(UsdPrim const& prim,
180 SdfPath const& cachePath,
181 UsdTimeCode time) const override;
182
183 USDSKELIMAGING_API
184 TfToken GetPurpose(UsdPrim const& prim,
185 SdfPath const& cachePath,
186 TfToken const& instanceInheritablePurpose)
187 const override;
188
189 USDSKELIMAGING_API
190 bool GetDoubleSided(UsdPrim const& prim,
191 SdfPath const& cachePath,
192 UsdTimeCode time) const override;
193
194
195 USDSKELIMAGING_API
196 SdfPath GetMaterialId(UsdPrim const& prim,
197 SdfPath const& cachePath,
198 UsdTimeCode time) const override;
199
200
201 USDSKELIMAGING_API
202 const TfTokenVector &GetExtComputationSceneInputNames(
203 SdfPath const& cachePath) const override;
204
205 USDSKELIMAGING_API
206 HdExtComputationInputDescriptorVector
207 GetExtComputationInputs(UsdPrim const& prim,
208 SdfPath const& cachePath,
209 const UsdImagingInstancerContext *instancerContext)
210 const override;
211
212 HdExtComputationOutputDescriptorVector
213 GetExtComputationOutputs(UsdPrim const& prim,
214 SdfPath const& cachePath,
215 const UsdImagingInstancerContext* instancerContext)
216 const override;
217
218 HdExtComputationPrimvarDescriptorVector
219 GetExtComputationPrimvars(
220 UsdPrim const& prim,
221 SdfPath const& cachePath,
222 HdInterpolation interpolation,
223 const UsdImagingInstancerContext* instancerContext) const override;
224
225 USDIMAGING_API
226 VtValue
227 GetExtComputationInput(
228 UsdPrim const& prim,
229 SdfPath const& cachePath,
230 TfToken const& name,
231 UsdTimeCode time,
232 const UsdImagingInstancerContext* instancerContext) const override;
233
234 USDIMAGING_API
235 size_t
236 SampleExtComputationInput(
237 UsdPrim const& prim,
238 SdfPath const& cachePath,
239 TfToken const& name,
240 UsdTimeCode time,
241 const UsdImagingInstancerContext* instancerContext,
242 size_t maxSampleCount,
243 float *sampleTimes,
244 VtValue *sampleValues) override;
245
246 USDIMAGING_API
247 std::string
248 GetExtComputationKernel(
249 UsdPrim const& prim,
250 SdfPath const& cachePath,
251 const UsdImagingInstancerContext* instancerContext) const override;
252
253
254 USDSKELIMAGING_API
255 VtValue Get(UsdPrim const& prim,
256 SdfPath const& cachePath,
257 TfToken const& key,
258 UsdTimeCode time,
259 VtIntArray *outIndices) const override;
260
261protected:
262 // ---------------------------------------------------------------------- //
264 // ---------------------------------------------------------------------- //
265 void _RemovePrim(const SdfPath& cachePath,
266 UsdImagingIndexProxy* index) override;
267
268private:
269 // ---------------------------------------------------------------------- //
271 // ---------------------------------------------------------------------- //
272 bool _IsCallbackForSkeleton(const UsdPrim& prim) const;
273
276 GfVec3f _GetSkeletonDisplayColor(const UsdPrim& prim,
277 UsdTimeCode time) const;
278
281 float _GetSkeletonDisplayOpacity(const UsdPrim& prim,
282 UsdTimeCode time) const;
283
284 void _TrackBoneMeshVariability(
285 const UsdPrim& prim,
286 const SdfPath& cachePath,
287 HdDirtyBits* timeVaryingBits,
289 instancerContext = nullptr) const;
290
291 void _UpdateBoneMeshForTime(
292 const UsdPrim& prim,
293 const SdfPath& cachePath,
294 UsdTimeCode time,
295 HdDirtyBits requestedBits,
296 const UsdImagingInstancerContext* instancerContext=nullptr) const;
297
298 // ---------------------------------------------------------------------- //
300 // ---------------------------------------------------------------------- //
301 bool _IsAffectedByTimeVaryingSkelAnim(const SdfPath& skinnedPrimPath)
302 const;
303
304 void _RemoveSkinnedPrimAndComputations(const SdfPath& cachePath,
305 UsdImagingIndexProxy* index);
306
307 // ---------------------------------------------------------------------- //
309 // ---------------------------------------------------------------------- //
310 bool _IsSkinningComputationPath(const SdfPath& cachePath) const;
311
312 bool
313 _IsSkinningInputAggregatorComputationPath(const SdfPath& cachePath)const;
314
315 void _TrackSkinningComputationVariability(
316 const UsdPrim& skinnedPrim,
317 const SdfPath& computationPath,
318 HdDirtyBits* timeVaryingBits,
320 instancerContext = nullptr) const;
321
322 VtVec3fArray _GetSkinnedPrimPoints(const UsdPrim& skinnedPrim,
323 const SdfPath& skinnedPrimCachePath,
324 UsdTimeCode time) const;
325
326 SdfPath _GetSkinningComputationPath(const SdfPath& skinnedPrimPath) const;
327
328 SdfPath _GetSkinningInputAggregatorComputationPath(
329 const SdfPath& skinnedPrimPath) const;
330
331 // Static helper methods
332 static
333 std::string _LoadSkinningComputeKernel(const TfToken& kernelKey);
334
335 static
336 const std::string& _GetLBSSkinningComputeKernel();
337
338 static
339 const std::string& _GetDQSSkinningComputeKernel();
340
341 // ---------------------------------------------------------------------- //
343 // ---------------------------------------------------------------------- //
344 bool _IsSkinnedPrimPath(const SdfPath& cachePath) const;
345
346 void _TrackSkinnedPrimVariability(
347 const UsdPrim& prim,
348 const SdfPath& cachePath,
349 HdDirtyBits* timeVaryingBits,
351 instancerContext = nullptr) const;
352
353 void _UpdateSkinnedPrimForTime(
354 const UsdPrim& prim,
355 const SdfPath& cachePath,
356 UsdTimeCode time,
357 HdDirtyBits requestedBits,
358 const UsdImagingInstancerContext* instancerContext=nullptr) const;
359
360 // ---------------------------------------------------------------------- //
362 // ---------------------------------------------------------------------- //
363
364 VtValue
365 _GetExtComputationInputForSkinningComputation(
366 UsdPrim const& prim,
367 SdfPath const& cachePath,
368 TfToken const& name,
369 UsdTimeCode time,
370 const UsdImagingInstancerContext* instancerContext) const;
371
372 VtValue
373 _GetExtComputationInputForInputAggregator(
374 UsdPrim const& prim,
375 SdfPath const& cachePath,
376 TfToken const& name,
377 UsdTimeCode time,
378 const UsdImagingInstancerContext* instancerContext) const;
379
380 size_t
381 _SampleExtComputationInputForSkinningComputation(
382 UsdPrim const& prim,
383 SdfPath const& cachePath,
384 TfToken const& name,
385 UsdTimeCode time,
386 const UsdImagingInstancerContext* instancerContext,
387 size_t maxSampleCount,
388 float *sampleTimes,
389 VtValue *sampleValues);
390
391 size_t
392 _SampleExtComputationInputForInputAggregator(
393 UsdPrim const& prim,
394 SdfPath const& cachePath,
395 TfToken const& name,
396 UsdTimeCode time,
397 const UsdImagingInstancerContext* instancerContext,
398 size_t maxSampleCount,
399 float *sampleTimes,
400 VtValue *sampleValues);
401
402
403 // ---------------------------------------------------------------------- //
405 // ---------------------------------------------------------------------- //
407 struct _SkelData {
408
409 UsdSkelSkeletonQuery skelQuery;
410 SdfPathSet skelRootPaths;
411
414 HdMeshTopology ComputeTopologyAndRestState();
415
417 VtVec3fArray ComputePoints(UsdTimeCode time) const;
418
421 TfToken ComputePurpose() const;
422
423 private:
424 // Cache of a mesh for a skeleton (at rest)
425 // TODO: Dedupe this infromation across UsdSkelSkeleton instances.
426 VtVec3fArray _boneMeshPoints;
427 VtIntArray _boneMeshJointIndices;
428 size_t _numJoints;
429 };
430
431 _SkelData* _GetSkelData(const SdfPath& cachePath) const;
432
433 UsdSkelCache _skelCache;
434 using _SkelDataMap =
435 std::unordered_map<SdfPath, std::shared_ptr<_SkelData>, SdfPath::Hash>;
436 _SkelDataMap _skelDataCache;
437
438 // Data for each skinned prim.
439 struct _SkinnedPrimData {
440 _SkinnedPrimData() = default;
441
445 _SkinnedPrimData(const SdfPath& skelPath,
446 const UsdSkelSkeletonQuery& skelQuery,
447 const UsdSkelSkinningQuery& skinningQuery,
448 const SdfPath& skelRootPath);
449
450 std::shared_ptr<UsdSkelBlendShapeQuery> blendShapeQuery;
451 UsdSkelSkinningQuery skinningQuery;
452 UsdSkelAnimQuery animQuery;
453 SdfPath skelPath, skelRootPath;
454 bool hasJointInfluences = false;
455 };
456
457 const _SkinnedPrimData* _GetSkinnedPrimData(const SdfPath& cachePath) const;
458
459 using _SkinnedPrimDataMap =
460 std::unordered_map<SdfPath, _SkinnedPrimData, SdfPath::Hash>;
461 _SkinnedPrimDataMap _skinnedPrimDataCache;
462
463 // ---------------------------------------------------------------------- //
466 // ---------------------------------------------------------------------- //
467
468 using _SkelBindingMap =
469 std::unordered_map<SdfPath, UsdSkelBinding, SdfPath::Hash>;
470 _SkelBindingMap _skelBindingMap;
471};
472
473
474PXR_NAMESPACE_CLOSE_SCOPE
475
476#endif // USDSKELIMAGING_SKELETONADAPTER
477
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
Interface class that defines the execution environment for the client to run a computation.
Topology data for meshes.
Definition: meshTopology.h:55
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:43
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
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.
virtual USDIMAGING_API void ProcessPrimResync(SdfPath const &cachePath, UsdImagingIndexProxy *index)
When a PrimResync event occurs, the prim may have been deleted entirely, adapter plug-ins should over...
virtual USDIMAGING_API VtValue Get(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, VtIntArray *outIndices) const
Gets the value of the parameter named key for the given prim (which has the given cache path) and giv...
virtual HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &propertyName)=0
Returns a bit mask of attributes to be updated, or HdChangeTracker::AllDirty if the entire prim must ...
virtual SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=nullptr)=0
Called to populate the RenderIndex for this UsdPrim.
virtual void TrackVariability(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits *timeVaryingBits, UsdImagingInstancerContext const *instancerContext=nullptr) const =0
For the given prim, variability is detected and stored in timeVaryingBits.
virtual USDIMAGING_API void ProcessPrimRemoval(SdfPath const &cachePath, UsdImagingIndexProxy *index)
Removes all associated Rprims and dependencies from the render index without scheduling them for repo...
virtual USDIMAGING_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Gets the topology object of a specific Usd prim.
virtual USDIMAGING_API TfToken GetPurpose(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &instanceInheritablePurpose) const
Returns the purpose token for prim.
virtual bool IsSupported(UsdImagingIndexProxy const *index) const
Returns true if the adapter can be populated into the target index.
Definition: primAdapter.h:685
virtual USDIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Reads the extent from the given prim.
virtual void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=nullptr) const =0
Populates the cache for the given prim, time and requestedBits.
virtual USDIMAGING_API PxOsdSubdivTags GetSubdivTags(UsdPrim const &usdPrim, SdfPath const &cachePath, UsdTimeCode time) const
Get the subdiv tags for this prim.
virtual USDIMAGING_API bool GetDoubleSided(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Reads double-sided from the given prim. If not authored, returns false.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
Class providing efficient queries of primitives that provide skel animation.
Definition: animQuery.h:55
Helper object that describes the binding of a skeleton to a set of skinnable objects.
Definition: binding.h:45
Thread-safe cache for accessing query objects for evaluating skeletal data.
Definition: cache.h:58
Primary interface to reading bound skeleton data.
Definition: skeletonQuery.h:71
Object used for querying resolved bindings for skinning.
Definition: skinningQuery.h:52
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...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457