Loading...
Searching...
No Matches
skeletonAdapter.h
1//
2// Copyright 2018 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_SKEL_IMAGING_SKELETON_ADAPTER_H
8#define PXR_USD_IMAGING_USD_SKEL_IMAGING_SKELETON_ADAPTER_H
9
10#include "pxr/pxr.h"
11#include "pxr/usdImaging/usdImaging/instanceablePrimAdapter.h"
12#include "pxr/usdImaging/usdSkelImaging/api.h"
13
14#include "pxr/imaging/hd/meshTopology.h"
15
21
22#include <unordered_map>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
31{
32public:
34
36 : BaseAdapter()
37 {}
38
39 USDSKELIMAGING_API
41
42 USDSKELIMAGING_API
44 Populate(const UsdPrim& prim,
47 instancerContext=nullptr) override;
48
49 USDSKELIMAGING_API
50 bool IsSupported(const UsdImagingIndexProxy* index) const override;
51
52 // ---------------------------------------------------------------------- //
54 // ---------------------------------------------------------------------- //
55
57 USDSKELIMAGING_API
58 void TrackVariability(const UsdPrim& prim,
59 const SdfPath& cachePath,
60 HdDirtyBits* timeVaryingBits,
62 instancerContext = nullptr) const override;
63
65 USDSKELIMAGING_API
66 void UpdateForTime(const UsdPrim& prim,
67 const SdfPath& cachePath,
68 UsdTimeCode time,
69 HdDirtyBits requestedBits,
71 instancerContext=nullptr) const override;
72
73 // ---------------------------------------------------------------------- //
75 // ---------------------------------------------------------------------- //
76
77 USDSKELIMAGING_API
78 HdDirtyBits ProcessPropertyChange(const UsdPrim& prim,
79 const SdfPath& cachePath,
80 const TfToken& propertyName) override;
81
82 USDSKELIMAGING_API
83 void ProcessPrimResync(SdfPath const& primPath,
84 UsdImagingIndexProxy* index) override;
85
86 USDSKELIMAGING_API
87 void ProcessPrimRemoval(SdfPath const& primPath,
88 UsdImagingIndexProxy* index) override;
89
90 USDSKELIMAGING_API
91 void MarkDirty(const UsdPrim& prim,
92 const SdfPath& cachePath,
93 HdDirtyBits dirty,
94 UsdImagingIndexProxy* index) override;
95
96 USDSKELIMAGING_API
97 void MarkRefineLevelDirty(UsdPrim const& prim,
98 SdfPath const& cachePath,
99 UsdImagingIndexProxy* index) override;
100
101 USDSKELIMAGING_API
102 void MarkReprDirty(UsdPrim const& prim,
103 SdfPath const& cachePath,
104 UsdImagingIndexProxy* index) override;
105
106 USDSKELIMAGING_API
107 void MarkCullStyleDirty(UsdPrim const& prim,
108 SdfPath const& cachePath,
109 UsdImagingIndexProxy* index) override;
110
111 USDSKELIMAGING_API
112 void MarkRenderTagDirty(UsdPrim const& prim,
113 SdfPath const& cachePath,
114 UsdImagingIndexProxy* index) override;
115
116 USDSKELIMAGING_API
117 void MarkTransformDirty(const UsdPrim& prim,
118 const SdfPath& cachePath,
119 UsdImagingIndexProxy* index) override;
120
121 USDSKELIMAGING_API
122 void MarkVisibilityDirty(const UsdPrim& prim,
123 const SdfPath& cachePath,
124 UsdImagingIndexProxy* index) override;
125
126 USDSKELIMAGING_API
127 void MarkMaterialDirty(const UsdPrim& prim,
128 const SdfPath& cachePath,
129 UsdImagingIndexProxy* index) override;
130
131 // ---------------------------------------------------------------------- //
133 // ---------------------------------------------------------------------- //
134 USDSKELIMAGING_API
135 void InvokeComputation(SdfPath const& cachePath,
136 HdExtComputationContext* context) override;
137
138 // ---------------------------------------------------------------------- //
140 // ---------------------------------------------------------------------- //
141
142 USDSKELIMAGING_API
143 void RegisterSkelBinding(UsdSkelBinding const& binding);
144
145 // ---------------------------------------------------------------------- //
147 // ---------------------------------------------------------------------- //
148
149 USDSKELIMAGING_API
151 SdfPath const& cachePath,
152 UsdTimeCode time) const override;
153
154 USDSKELIMAGING_API
156 SdfPath const& cachePath,
157 UsdTimeCode time) const override;
158
159 USDSKELIMAGING_API
161 SdfPath const& cachePath,
162 UsdTimeCode time) const override;
163
164 USDSKELIMAGING_API
166 SdfPath const& cachePath,
167 TfToken const& instanceInheritablePurpose)
168 const override;
169
170 USDSKELIMAGING_API
171 bool GetDoubleSided(UsdPrim const& prim,
172 SdfPath const& cachePath,
173 UsdTimeCode time) const override;
174
175
176 USDSKELIMAGING_API
177 SdfPath GetMaterialId(UsdPrim const& prim,
178 SdfPath const& cachePath,
179 UsdTimeCode time) const override;
180
181
182 USDSKELIMAGING_API
183 const TfTokenVector &GetExtComputationSceneInputNames(
184 SdfPath const& cachePath) const override;
185
186 USDSKELIMAGING_API
187 HdExtComputationInputDescriptorVector
188 GetExtComputationInputs(UsdPrim const& prim,
189 SdfPath const& cachePath,
190 const UsdImagingInstancerContext *instancerContext)
191 const override;
192
193 USDSKELIMAGING_API
194 HdExtComputationOutputDescriptorVector
195 GetExtComputationOutputs(UsdPrim const& prim,
196 SdfPath const& cachePath,
197 const UsdImagingInstancerContext* instancerContext)
198 const override;
199
200 USDSKELIMAGING_API
201 HdExtComputationPrimvarDescriptorVector
202 GetExtComputationPrimvars(
203 UsdPrim const& prim,
204 SdfPath const& cachePath,
205 HdInterpolation interpolation,
206 const UsdImagingInstancerContext* instancerContext) const override;
207
208 USDSKELIMAGING_API
209 VtValue
210 GetExtComputationInput(
211 UsdPrim const& prim,
212 SdfPath const& cachePath,
213 TfToken const& name,
214 UsdTimeCode time,
215 const UsdImagingInstancerContext* instancerContext) const override;
216
217 USDSKELIMAGING_API
218 size_t
219 SampleExtComputationInput(
220 UsdPrim const& prim,
221 SdfPath const& cachePath,
222 TfToken const& name,
223 UsdTimeCode time,
224 const UsdImagingInstancerContext* instancerContext,
225 size_t maxSampleCount,
226 float *sampleTimes,
227 VtValue *sampleValues) override;
228
229 USDSKELIMAGING_API
230 std::string
231 GetExtComputationKernel(
232 UsdPrim const& prim,
233 SdfPath const& cachePath,
234 const UsdImagingInstancerContext* instancerContext) const override;
235
236
237 USDSKELIMAGING_API
238 VtValue Get(UsdPrim const& prim,
239 SdfPath const& cachePath,
240 TfToken const& key,
241 UsdTimeCode time,
242 VtIntArray *outIndices) const override;
243
244 // ---------------------------------------------------------------------- //
246 // ---------------------------------------------------------------------- //
247 USDSKELIMAGING_API
248 TfTokenVector GetImagingSubprims(UsdPrim const &prim) override;
249
250 USDSKELIMAGING_API
251 TfToken GetImagingSubprimType(
252 UsdPrim const &prim,
253 TfToken const &subprim) override;
254
255 USDSKELIMAGING_API
256 HdContainerDataSourceHandle GetImagingSubprimData(
257 UsdPrim const& prim,
258 TfToken const& subprim,
259 const UsdImagingDataSourceStageGlobals &stageGlobals) override;
260
261 USDSKELIMAGING_API
262 HdDataSourceLocatorSet InvalidateImagingSubprim(
263 UsdPrim const& prim,
264 TfToken const& subprim,
265 TfTokenVector const& properties,
266 UsdImagingPropertyInvalidationType invalidationType) override;
267
268protected:
269 // ---------------------------------------------------------------------- //
271 // ---------------------------------------------------------------------- //
272 void _RemovePrim(const SdfPath& cachePath,
273 UsdImagingIndexProxy* index) override;
274
275private:
276 enum class _ComputationType : uint8_t {
277 Points,
278 Normals
279 };
280
281 // ---------------------------------------------------------------------- //
283 // ---------------------------------------------------------------------- //
284 bool _IsCallbackForSkeleton(const UsdPrim& prim) const;
285
288 GfVec3f _GetSkeletonDisplayColor(const UsdPrim& prim,
289 UsdTimeCode time) const;
290
293 float _GetSkeletonDisplayOpacity(const UsdPrim& prim,
294 UsdTimeCode time) const;
295
296 void _TrackBoneMeshVariability(
297 const UsdPrim& prim,
298 const SdfPath& cachePath,
299 HdDirtyBits* timeVaryingBits,
301 instancerContext = nullptr) const;
302
303 void _UpdateBoneMeshForTime(
304 const UsdPrim& prim,
305 const SdfPath& cachePath,
306 UsdTimeCode time,
307 HdDirtyBits requestedBits,
308 const UsdImagingInstancerContext* instancerContext=nullptr) const;
309
310 // ---------------------------------------------------------------------- //
312 // ---------------------------------------------------------------------- //
313 bool _IsAffectedByTimeVaryingSkelAnim(const SdfPath& skinnedPrimPath)
314 const;
315
316 void _RemoveSkinnedPrimAndComputations(const SdfPath& cachePath,
317 UsdImagingIndexProxy* index);
318
319 // ---------------------------------------------------------------------- //
321 // ---------------------------------------------------------------------- //
322 bool _IsSkinningPointsComputationPath(const SdfPath& cachePath) const;
323
324 bool _IsSkinningNormalsComputationPath(const SdfPath& cachePath) const;
325
326 _ComputationType _GetSkinningComputationType(
327 const SdfPath& cachePath) const;
328
329 bool _IsSkinningPointsInputAggregatorComputationPath(
330 const SdfPath& cachePath) const;
331
332 bool _IsSkinningNormalsInputAggregatorComputationPath(
333 const SdfPath& cachePath) const;
334
335 void _TrackSkinningComputationVariability(
336 const UsdPrim& skinnedPrim,
337 const SdfPath& computationPath,
338 HdDirtyBits* timeVaryingBits,
340 instancerContext = nullptr) const;
341
342 VtVec3fArray _GetSkinnedPrimPoints(const UsdPrim& skinnedPrim,
343 const SdfPath& skinnedPrimCachePath,
344 UsdTimeCode time) const;
345
346 VtVec3fArray _GetSkinnedPrimNormals(const UsdPrim& skinnedPrim,
347 const SdfPath& skinnedPrimCachePath,
348 UsdTimeCode time) const;
349
350 VtIntArray _GetSkinnedPrimFaceVertexIndices(const UsdPrim& skinnedPrim,
351 const SdfPath& skinnedPrimCachePath,
352 UsdTimeCode time) const;
353
354 SdfPath _GetSkinningComputationPath(
355 const SdfPath& skinnedPrimPath,
356 _ComputationType computationType) const;
357
358 SdfPath _GetSkinningInputAggregatorComputationPath(
359 const SdfPath& skinnedPrimPath,
360 _ComputationType computationType) const;
361
362 // Static helper methods
363 static
364 std::string _LoadSkinningComputeKernel(const TfToken& kernelKey);
365
366 static
367 const std::string& _GetLBSSkinningComputeKernel(
368 _ComputationType computationType);
369
370 static
371 const std::string& _GetDQSSkinningComputeKernel(
372 _ComputationType computationType);
373
374 // ---------------------------------------------------------------------- //
376 // ---------------------------------------------------------------------- //
377 bool _IsSkinnedPrimPath(const SdfPath& cachePath) const;
378
379 void _TrackSkinnedPrimVariability(
380 const UsdPrim& prim,
381 const SdfPath& cachePath,
382 HdDirtyBits* timeVaryingBits,
384 instancerContext = nullptr) const;
385
386 void _UpdateSkinnedPrimForTime(
387 const UsdPrim& prim,
388 const SdfPath& cachePath,
389 UsdTimeCode time,
390 HdDirtyBits requestedBits,
391 const UsdImagingInstancerContext* instancerContext=nullptr) const;
392
393 // ---------------------------------------------------------------------- //
395 // ---------------------------------------------------------------------- //
396
397 VtValue
398 _GetExtComputationInputForSkinningComputation(
399 UsdPrim const& prim,
400 SdfPath const& cachePath,
401 TfToken const& name,
402 UsdTimeCode time,
403 const UsdImagingInstancerContext* instancerContext) const;
404
405 VtValue
406 _GetExtComputationInputForInputAggregator(
407 UsdPrim const& prim,
408 SdfPath const& cachePath,
409 TfToken const& name,
410 UsdTimeCode time,
411 const UsdImagingInstancerContext* instancerContext) const;
412
413 size_t
414 _SampleExtComputationInputForSkinningComputation(
415 UsdPrim const& prim,
416 SdfPath const& cachePath,
417 TfToken const& name,
418 UsdTimeCode time,
419 const UsdImagingInstancerContext* instancerContext,
420 size_t maxSampleCount,
421 float *sampleTimes,
422 VtValue *sampleValues);
423
424 size_t
425 _SampleExtComputationInputForInputAggregator(
426 UsdPrim const& prim,
427 SdfPath const& cachePath,
428 TfToken const& name,
429 UsdTimeCode time,
430 const UsdImagingInstancerContext* instancerContext,
431 size_t maxSampleCount,
432 float *sampleTimes,
433 VtValue *sampleValues);
434
437 double _GetDefaultSampleTime(UsdTimeCode time);
438
439 // ---------------------------------------------------------------------- //
441 // ---------------------------------------------------------------------- //
442 static
443 bool
444 _ExtractSkinningScaleXforms(
445 const VtMatrix4fArray& skinningXforms,
446 _ComputationType computationType,
447 VtMatrix3fArray* skinningScaleXforms);
448
449 static
450 bool
451 _ExtractSkinningDualQuats(
452 const VtMatrix4fArray& skinningXforms,
453 _ComputationType computationType,
454 VtVec4fArray* skinningDualQuats);
455
456 // ---------------------------------------------------------------------- //
458 // ---------------------------------------------------------------------- //
460 struct _SkelData {
461
462 UsdSkelSkeletonQuery skelQuery;
463 SdfPathSet skelRootPaths;
464
467 HdMeshTopology ComputeTopologyAndRestState();
468
470 VtVec3fArray ComputePoints(UsdTimeCode time) const;
471
474 TfToken ComputePurpose() const;
475
476 private:
477 // Cache of a mesh for a skeleton (at rest)
478 // TODO: Dedupe this infromation across UsdSkelSkeleton instances.
479 VtVec3fArray _boneMeshPoints;
480 VtIntArray _boneMeshJointIndices;
481 size_t _numJoints;
482 };
483
484 _SkelData* _GetSkelData(const SdfPath& cachePath) const;
485
486 UsdSkelCache _skelCache;
487 using _SkelDataMap =
488 std::unordered_map<SdfPath, std::shared_ptr<_SkelData>, SdfPath::Hash>;
489 _SkelDataMap _skelDataCache;
490
491 // Data for each skinned prim.
492 struct _SkinnedPrimData {
493 _SkinnedPrimData() = default;
494
498 _SkinnedPrimData(const SdfPath& skelPath,
499 const UsdSkelSkeletonQuery& skelQuery,
500 const UsdSkelSkinningQuery& skinningQuery,
501 const SdfPath& skelRootPath,
502 const UsdSkelImagingSkeletonAdapter* adapter);
503
504 std::shared_ptr<UsdSkelBlendShapeQuery> blendShapeQuery;
505 UsdSkelSkinningQuery skinningQuery;
506 UsdSkelAnimQuery animQuery;
507 SdfPath skelPath, skelRootPath;
508 bool hasJointInfluences = false;
509 TfToken normalsInterpolation;
510 };
511
512 const _SkinnedPrimData* _GetSkinnedPrimData(const SdfPath& cachePath) const;
513
514 using _SkinnedPrimDataMap =
515 std::unordered_map<SdfPath, _SkinnedPrimData, SdfPath::Hash>;
516 _SkinnedPrimDataMap _skinnedPrimDataCache;
517
518 // ---------------------------------------------------------------------- //
521 // ---------------------------------------------------------------------- //
522
523 using _SkelBindingMap =
524 std::unordered_map<SdfPath, UsdSkelBinding, SdfPath::Hash>;
525 _SkelBindingMap _skelBindingMap;
526};
527
528
529PXR_NAMESPACE_CLOSE_SCOPE
530
531#endif // USDSKELIMAGING_SKELETONADAPTER
532
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
Represents a set of data source locators closed under descendancy.
Interface class that defines the execution environment for the client to run a computation.
Topology data for meshes.
Definition: meshTopology.h:38
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:26
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
This class is used as a context object with global stage information, that gets passed down to dataso...
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
Class providing efficient queries of primitives that provide skel animation.
Definition: animQuery.h:38
Helper object that describes the binding of a skeleton to a set of skinnable objects.
Definition: binding.h:28
Thread-safe cache for accessing query objects for evaluating skeletal data.
Definition: cache.h:41
Prim adapter for UsdSkel's Skeleton.
USDSKELIMAGING_API void ProcessPrimResync(SdfPath const &primPath, UsdImagingIndexProxy *index) override
When a PrimResync event occurs, the prim may have been deleted entirely, adapter plug-ins should over...
USDSKELIMAGING_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...
USDSKELIMAGING_API TfToken GetPurpose(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &instanceInheritablePurpose) const override
Returns the purpose token for prim.
USDSKELIMAGING_API SdfPath Populate(const UsdPrim &prim, UsdImagingIndexProxy *index, const UsdImagingInstancerContext *instancerContext=nullptr) override
Called to populate the RenderIndex for this UsdPrim.
USDSKELIMAGING_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Gets the topology object of a specific Usd prim.
USDSKELIMAGING_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.
USDSKELIMAGING_API PxOsdSubdivTags GetSubdivTags(UsdPrim const &usdPrim, SdfPath const &cachePath, UsdTimeCode time) const override
Get the subdiv tags for this prim.
USDSKELIMAGING_API void ProcessPrimRemoval(SdfPath const &primPath, UsdImagingIndexProxy *index) override
Removes all associated Rprims and dependencies from the render index without scheduling them for repo...
USDSKELIMAGING_API HdDirtyBits ProcessPropertyChange(const UsdPrim &prim, const SdfPath &cachePath, const TfToken &propertyName) override
Returns a bit mask of attributes to be updated, or HdChangeTracker::AllDirty if the entire prim must ...
USDSKELIMAGING_API bool IsSupported(const UsdImagingIndexProxy *index) const override
Returns true if the adapter can be populated into the target index.
USDSKELIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Reads the extent from the given prim.
USDSKELIMAGING_API void TrackVariability(const UsdPrim &prim, const SdfPath &cachePath, HdDirtyBits *timeVaryingBits, const UsdImagingInstancerContext *instancerContext=nullptr) const override
Thread Safe.
USDSKELIMAGING_API void UpdateForTime(const UsdPrim &prim, const SdfPath &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, const UsdImagingInstancerContext *instancerContext=nullptr) const override
Thread Safe.
Primary interface to reading bound skeleton data.
Definition: skeletonQuery.h:54
Object used for querying resolved bindings for skinning.
Definition: skinningQuery.h:35
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
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:440