All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utils.h
Go to the documentation of this file.
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_USD_SKEL_UTILS_H
25 #define PXR_USD_USD_SKEL_UTILS_H
26 
31 
32 #include "pxr/pxr.h"
33 #include "pxr/usd/usdSkel/api.h"
34 
35 #include "pxr/base/gf/quatf.h"
36 #include "pxr/base/gf/matrix3d.h"
37 #include "pxr/base/gf/matrix3f.h"
38 #include "pxr/base/gf/matrix4d.h"
39 #include "pxr/base/gf/matrix4f.h"
40 #include "pxr/base/gf/vec3h.h"
41 #include "pxr/base/gf/vec3h.h"
42 #include "pxr/base/tf/span.h"
43 #include "pxr/base/vt/array.h"
44 #include "pxr/base/vt/types.h"
45 
46 #include "pxr/usd/sdf/path.h"
47 
48 #include <cstddef>
49 
50 // XXX: Included for backwards compatibility.
51 #include "pxr/usd/usdSkel/bakeSkinning.h"
52 
53 
54 PXR_NAMESPACE_OPEN_SCOPE
55 
56 
57 class GfMatrix3f;
58 class GfRange3f;
59 class GfRotation;
60 class UsdPrim;
61 class UsdPrimRange;
62 class UsdRelationship;
63 class UsdSkelRoot;
64 class UsdSkelTopology;
65 
66 
69 
70 
72 USDSKEL_API
73 bool
75 
76 
80 USDSKEL_API
81 bool
82 UsdSkelIsSkinnablePrim(const UsdPrim& prim);
83 
84 
88 
89 
102 USDSKEL_API
103 bool
106  TfSpan<const GfMatrix4d> inverseXforms,
107  TfSpan<GfMatrix4d> jointLocalXforms,
108  const GfMatrix4d* rootInverseXform=nullptr);
109 
111 USDSKEL_API
112 bool
115  TfSpan<const GfMatrix4f> inverseXforms,
116  TfSpan<GfMatrix4f> jointLocalXforms,
117  const GfMatrix4f* rootInverseXform=nullptr);
118 
122 USDSKEL_API
123 bool
126  TfSpan<GfMatrix4d> jointLocalXforms,
127  const GfMatrix4d* rootInverseXform=nullptr);
128 
129 USDSKEL_API
130 bool
133  TfSpan<GfMatrix4f> jointLocalXforms,
134  const GfMatrix4f* rootInverseXform=nullptr);
135 
136 
139 USDSKEL_API
140 bool
142  const VtMatrix4dArray& xforms,
143  const VtMatrix4dArray& inverseXforms,
144  VtMatrix4dArray* jointLocalXforms,
145  const GfMatrix4d* rootInverseXform=nullptr);
146 
147 
148 
149 
152 USDSKEL_API
153 bool
155  const VtMatrix4dArray& xforms,
156  VtMatrix4dArray* jointLocalXforms,
157  const GfMatrix4d* rootInverseXform=nullptr);
158 
159 
162 USDSKEL_API
163 bool
165  const GfMatrix4d* xforms,
166  const GfMatrix4d* inverseXforms,
167  GfMatrix4d* jointLocalXforms,
168  const GfMatrix4d* rootInverseXform=nullptr);
169 
170 
171 
181 USDSKEL_API
182 bool
184  TfSpan<const GfMatrix4d> jointLocalXforms,
185  TfSpan<GfMatrix4d> xforms,
186  const GfMatrix4d* rootXform=nullptr);
187 
188 
190 USDSKEL_API
191 bool
193  TfSpan<const GfMatrix4f> jointLocalXforms,
194  TfSpan<GfMatrix4f> xforms,
195  const GfMatrix4f* rootXform=nullptr);
196 
197 
198 
201 USDSKEL_API
202 bool
204  const VtMatrix4dArray& jointLocalXforms,
205  VtMatrix4dArray* xforms,
206  const GfMatrix4d* rootXform=nullptr);
207 
208 
211 USDSKEL_API
212 bool
214  const GfMatrix4d* jointLocalXforms,
215  GfMatrix4d* xforms,
216  const GfMatrix4d* rootXform=nullptr);
217 
218 
223 template <typename Matrix4>
224 USDSKEL_API
225 bool
227  GfRange3f* extent,
228  float pad=0.0f,
229  const Matrix4* rootXform=nullptr);
230 
231 
232 
235 USDSKEL_API
236 bool
237 UsdSkelComputeJointsExtent(const VtMatrix4dArray& joints,
238  VtVec3fArray* extent,
239  float pad=0.0f,
240  const GfMatrix4d* rootXform=nullptr);
241 
242 
245 USDSKEL_API
246 bool
248  size_t numXforms,
249  VtVec3fArray* extent,
250  float pad=0.0f,
251  const GfMatrix4d* rootXform=nullptr);
252 
253 
255 
256 
261 
262 
265 template <typename Matrix4>
266 USDSKEL_API
267 bool
268 UsdSkelDecomposeTransform(const Matrix4& xform,
269  GfVec3f* translate,
270  GfRotation* rotate,
271  GfVec3h* scale);
272 
274 template <typename Matrix4>
275 USDSKEL_API
276 bool
277 UsdSkelDecomposeTransform(const Matrix4& xform,
278  GfVec3f* translate,
279  GfQuatf* rotate,
280  GfVec3h* scale);
281 
282 
285 USDSKEL_API
286 bool
288  TfSpan<GfVec3f> translations,
289  TfSpan<GfQuatf> rotations,
290  TfSpan<GfVec3h> scales);
291 
293 USDSKEL_API
294 bool
296  TfSpan<GfVec3f> translations,
297  TfSpan<GfQuatf> rotations,
298  TfSpan<GfVec3h> scales);
299 
300 
303 USDSKEL_API
304 bool
305 UsdSkelDecomposeTransforms(const VtMatrix4dArray& xforms,
306  VtVec3fArray* translations,
307  VtQuatfArray* rotations,
308  VtVec3hArray* scales);
309 
310 
313 USDSKEL_API
314 bool
316  GfVec3f* translations,
317  GfQuatf* rotations,
318  GfVec3h* scales,
319  size_t count);
320 
321 
324 template <typename Matrix4>
325 USDSKEL_API
326 void
327 UsdSkelMakeTransform(const GfVec3f& translate,
328  const GfMatrix3f& rotate,
329  const GfVec3h& scale,
330  Matrix4* xform);
331 
333 template <typename Matrix4>
334 USDSKEL_API
335 void
336 UsdSkelMakeTransform(const GfVec3f& translate,
337  const GfQuatf& rotate,
338  const GfVec3h& scale,
339  Matrix4* xform);
340 
343 USDSKEL_API
344 bool
346  TfSpan<const GfQuatf> rotations,
347  TfSpan<const GfVec3h> scales,
348  TfSpan<GfMatrix4d> xforms);
349 
350 
352 USDSKEL_API
353 bool
355  TfSpan<const GfQuatf> rotations,
356  TfSpan<const GfVec3h> scales,
357  TfSpan<GfMatrix4f> xforms);
358 
359 
362 USDSKEL_API
363 bool
364 UsdSkelMakeTransforms(const VtVec3fArray& translations,
365  const VtQuatfArray& rotations,
366  const VtVec3hArray& scales,
367  VtMatrix4dArray* xforms);
368 
371 USDSKEL_API
372 bool
373 UsdSkelMakeTransforms(const GfVec3f* translations,
374  const GfQuatf* rotations,
375  const GfVec3h* scales,
376  GfMatrix4d* xforms,
377  size_t count);
378 
379 
381 
382 
387 
388 
391 USDSKEL_API
392 bool
393 UsdSkelNormalizeWeights(TfSpan<float> weights, int numInfluencesPerComponent);
394 
395 
398 USDSKEL_API
399 bool
400 UsdSkelNormalizeWeights(VtFloatArray* weights, int numInfluencesPerComponent);
401 
402 
404 USDSKEL_API
405 bool
407  int numInfluencesPerComponent);
408 
411 USDSKEL_API
412 bool
413 UsdSkelSortInfluences(VtIntArray* indices, VtFloatArray* weights,
414  int numInfluencesPerComponent);
415 
416 
423 USDSKEL_API
424 bool
425 UsdSkelExpandConstantInfluencesToVarying(VtIntArray* indices, size_t size);
426 
428 USDSKEL_API
429 bool
430 UsdSkelExpandConstantInfluencesToVarying(VtFloatArray* weights, size_t size);
431 
438 USDSKEL_API
439 bool
440 UsdSkelResizeInfluences(VtIntArray* indices,
441  int srcNumInfluencesPerComponent,
442  int newNumInfluencesPerComponent);
443 
445 USDSKEL_API
446 bool
447 UsdSkelResizeInfluences(VtFloatArray* weights,
448  int srcNumInfluencesPerComponent,
449  int newNumInfluencesPerComponent);
450 
453 USDSKEL_API
454 bool
456  const TfSpan<const float>& weights,
457  TfSpan<GfVec2f> interleavedInfluences);
458 
459 
461 
462 
466 
467 
474 USDSKEL_API
475 bool
476 UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
477  TfSpan<const GfMatrix4d> jointXforms,
478  TfSpan<const int> jointIndices,
479  TfSpan<const float> jointWeights,
480  int numInfluencesPerPoint,
481  TfSpan<GfVec3f> points,
482  bool inSerial=false);
483 
485 USDSKEL_API
486 bool
487 UsdSkelSkinPointsLBS(const GfMatrix4f& geomBindTransform,
488  TfSpan<const GfMatrix4f> jointXforms,
489  TfSpan<const int> jointIndices,
490  TfSpan<const float> jointWeights,
491  int numInfluencesPerPoint,
492  TfSpan<GfVec3f> points,
493  bool inSerial=false);
494 
495 
497 USDSKEL_API
498 bool
499 UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
500  TfSpan<const GfMatrix4d> jointXforms,
501  TfSpan<const GfVec2f> influences,
502  int numInfluencesPerPoint,
503  TfSpan<GfVec3f> points,
504  bool inSerial=false);
505 
507 USDSKEL_API
508 bool
509 UsdSkelSkinPointsLBS(const GfMatrix4f& geomBindTransform,
510  TfSpan<const GfMatrix4f> jointXforms,
511  TfSpan<const GfVec2f> influences,
512  int numInfluencesPerPoint,
513  TfSpan<GfVec3f> points,
514  bool inSerial=false);
515 
516 
519 USDSKEL_API
520 bool
521 UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
522  const VtMatrix4dArray& jointXforms,
523  const VtIntArray& jointIndices,
524  const VtFloatArray& jointWeights,
525  int numInfluencesPerPoint,
526  VtVec3fArray* points);
527 
528 
531 USDSKEL_API
532 bool
533 UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
534  const GfMatrix4d* jointXforms,
535  size_t numJoints,
536  const int* jointIndices,
537  const float* jointWeights,
538  size_t numInfluences,
539  int numInfluencesPerPoint,
540  GfVec3f* points,
541  size_t numPoints,
542  bool inSerial=false);
543 
544 
554 USDSKEL_API
555 bool
556 UsdSkelSkinNormalsLBS(const GfMatrix3d& geomBindTransform,
557  TfSpan<const GfMatrix3d> jointXforms,
558  TfSpan<const int> jointIndices,
559  TfSpan<const float> jointWeights,
560  int numInfluencesPerPoint,
561  TfSpan<GfVec3f> normals,
562  bool inSerial=false);
563 
564 
566 USDSKEL_API
567 bool
568 UsdSkelSkinNormalsLBS(const GfMatrix3f& geomBindTransform,
569  TfSpan<const GfMatrix3f> jointXforms,
570  TfSpan<const int> jointIndices,
571  TfSpan<const float> jointWeights,
572  int numInfluencesPerPoint,
573  TfSpan<GfVec3f> normals,
574  bool inSerial=false);
575 
576 
578 USDSKEL_API
579 bool
580 UsdSkelSkinNormalsLBS(const GfMatrix3d& geomBindTransform,
581  TfSpan<const GfMatrix3d> jointXforms,
582  TfSpan<const GfVec2f> influences,
583  int numInfluencesPerPoint,
584  TfSpan<GfVec3f> normals,
585  bool inSerial=false);
586 
587 
589 USDSKEL_API
590 bool
591 UsdSkelSkinNormalsLBS(const GfMatrix3f& geomBindTransform,
592  TfSpan<const GfMatrix3f> jointXforms,
593  TfSpan<const GfVec2f> influences,
594  int numInfluencesPerPoint,
595  TfSpan<GfVec3f> normals,
596  bool inSerial=false);
597 
598 
604 USDSKEL_API
605 bool
606 UsdSkelSkinTransformLBS(const GfMatrix4d& geomBindTransform,
607  TfSpan<const GfMatrix4d> jointXforms,
608  TfSpan<const int> jointIndices,
609  TfSpan<const float> jointWeights,
610  GfMatrix4d* xform);
611 
613 USDSKEL_API
614 bool
615 UsdSkelSkinTransformLBS(const GfMatrix4f& geomBindTransform,
616  TfSpan<const GfMatrix4f> jointXforms,
617  TfSpan<const int> jointIndices,
618  TfSpan<const float> jointWeights,
619  GfMatrix4f* xform);
620 
623 USDSKEL_API
624 bool
625 UsdSkelSkinTransformLBS(const GfMatrix4d& geomBindTransform,
626  TfSpan<const GfMatrix4d> jointXforms,
627  TfSpan<const GfVec2f> influences,
628  GfMatrix4d* xform);
629 
631 USDSKEL_API
632 bool
633 UsdSkelSkinTransformLBS(const GfMatrix4f& geomBindTransform,
634  TfSpan<const GfMatrix4f> jointXforms,
635  TfSpan<const GfVec2f> influences,
636  GfMatrix4f* xform);
637 
640 USDSKEL_API
641 bool
642 UsdSkelSkinTransformLBS(const GfMatrix4d& geomBindTransform,
643  const GfMatrix4d* jointXforms,
644  size_t numJoints,
645  const int* jointIndices,
646  const float* jointWeights,
647  size_t numInfluences,
648  GfMatrix4d* xform);
649 
650 
656 USDSKEL_API
657 bool
658 UsdSkelApplyBlendShape(const float weight,
659  const TfSpan<const GfVec3f> offsets,
660  const TfSpan<const int> indices,
661  TfSpan<GfVec3f> points);
662 
663 
664 PXR_NAMESPACE_CLOSE_SCOPE
665 
666 
667 #endif // PXR_USD_USD_SKEL_UTILS_H
USDSKEL_API bool UsdSkelComputeJointLocalTransforms(const UsdSkelTopology &topology, TfSpan< const GfMatrix4d > xforms, TfSpan< const GfMatrix4d > inverseXforms, TfSpan< GfMatrix4d > jointLocalXforms, const GfMatrix4d *rootInverseXform=nullptr)
Compute joint transforms in joint-local space.
USDSKEL_API bool UsdSkelInterleaveInfluences(const TfSpan< const int > &indices, const TfSpan< const float > &weights, TfSpan< GfVec2f > interleavedInfluences)
Combine arrays of joint indices and weights into interleaved (index,weight) vectors.
Stores a 4x4 matrix of float elements.
Definition: matrix4f.h:88
Object holding information describing skeleton topology.
Definition: topology.h:45
USDSKEL_API bool UsdSkelDecomposeTransforms(TfSpan< const GfMatrix4d > xforms, TfSpan< GfVec3f > translations, TfSpan< GfQuatf > rotations, TfSpan< GfVec3h > scales)
Decompose an array of transforms into translate/rotate/scale components.
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
USDSKEL_API bool UsdSkelConcatJointTransforms(const UsdSkelTopology &topology, TfSpan< const GfMatrix4d > jointLocalXforms, TfSpan< GfMatrix4d > xforms, const GfMatrix4d *rootXform=nullptr)
Compute concatenated joint transforms.
USDSKEL_API bool UsdSkelIsSkinnablePrim(const UsdPrim &prim)
Returns true if prim is considered to be a skinnable primitive.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients...
Definition: quatf.h:60
USDSKEL_API bool UsdSkelExpandConstantInfluencesToVarying(VtIntArray *indices, size_t size)
Convert an array of constant influences (joint weights or indices) to an array of varying influences...
USDSKEL_API bool UsdSkelResizeInfluences(VtIntArray *indices, int srcNumInfluencesPerComponent, int newNumInfluencesPerComponent)
Resize the number of influences per component in a weight or indices array, which initially has srcNu...
USDSKEL_API bool UsdSkelNormalizeWeights(TfSpan< float > weights, int numInfluencesPerComponent)
Helper method to normalize weight values across each consecutive run of numInfluencesPerComponent ele...
Stores a 3x3 matrix of float elements.
Definition: matrix3f.h:82
USDSKEL_API void UsdSkelMakeTransform(const GfVec3f &translate, const GfMatrix3f &rotate, const GfVec3h &scale, Matrix4 *xform)
Create a transform from translate/rotate/scale components.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represents a range of contiguous elements.
Definition: span.h:87
Basic type: 3-dimensional floating point range.
Definition: range3f.h:64
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:132
USDSKEL_API bool UsdSkelSortInfluences(TfSpan< int > indices, TfSpan< float > weights, int numInfluencesPerComponent)
Sort joint influences such that highest weight values come first.
USDSKEL_API bool UsdSkelDecomposeTransform(const Matrix4 &xform, GfVec3f *translate, GfRotation *rotate, GfVec3h *scale)
Decompose a transform into translate/rotate/scale components.
USDSKEL_API bool UsdSkelComputeJointsExtent(TfSpan< const Matrix4 > joints, GfRange3f *extent, float pad=0.0f, const Matrix4 *rootXform=nullptr)
Compute an extent from a set of skel-space joint transform.
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
Defines all the types &quot;TYPED&quot; for which Vt creates a VtTYPEDArray typedef.
USDSKEL_API bool UsdSkelApplyBlendShape(const float weight, const TfSpan< const GfVec3f > offsets, const TfSpan< const int > indices, TfSpan< GfVec3f > points)
Apply a single blend shape to points.
Boundable prim type used to identify a scope beneath which skeletally-posed primitives are defined...
Definition: root.h:63
An forward-iterable range that traverses a subtree of prims rooted at a given prim in depth-first ord...
Definition: primRange.h:118
USDSKEL_API bool UsdSkelSkinTransformLBS(const GfMatrix4d &geomBindTransform, TfSpan< const GfMatrix4d > jointXforms, TfSpan< const int > jointIndices, TfSpan< const float > jointWeights, GfMatrix4d *xform)
Skin a transform using linear blend skinning (LBS).
USDSKEL_API bool UsdSkelMakeTransforms(TfSpan< const GfVec3f > translations, TfSpan< const GfQuatf > rotations, TfSpan< const GfVec3h > scales, TfSpan< GfMatrix4d > xforms)
Create transforms from arrays of components.
USDSKEL_API bool UsdSkelSkinPointsLBS(const GfMatrix4d &geomBindTransform, TfSpan< const GfMatrix4d > jointXforms, TfSpan< const int > jointIndices, TfSpan< const float > jointWeights, int numInfluencesPerPoint, TfSpan< GfVec3f > points, bool inSerial=false)
Skin points using linear blend skinning (LBS).
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:82
USDSKEL_API bool UsdSkelSkinNormalsLBS(const GfMatrix3d &geomBindTransform, TfSpan< const GfMatrix3d > jointXforms, TfSpan< const int > jointIndices, TfSpan< const float > jointWeights, int numInfluencesPerPoint, TfSpan< GfVec3f > normals, bool inSerial=false)
Skin normals using linear blend skinning (LBS).
USDSKEL_API bool UsdSkelIsSkelAnimationPrim(const UsdPrim &prim)
Returns true if prim is a valid skel animation source.
Basic type: 3-space rotation specification.
Definition: rotation.h:55
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:64