Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SkeletonMapper.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2022 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
13class JPH_EXPORT SkeletonMapper : public RefTarget<SkeletonMapper>
14{
15public:
17 class Mapping
18 {
19 public:
20 Mapping() = default;
21 Mapping(int inJointIdx1, int inJointIdx2, Mat44Arg inJoint1To2) : mJointIdx1(inJointIdx1), mJointIdx2(inJointIdx2), mJoint1To2(inJoint1To2), mJoint2To1(inJoint1To2.Inversed())
22 {
23 // Ensure bottom right element is 1 (numerical imprecision in the inverse can make this not so)
24 mJoint2To1(3, 3) = 1.0f;
25 }
26
31 };
32
34 class Chain
35 {
36 public:
37 Chain() = default;
38 Chain(Array<int> &&inJointIndices1, Array<int> &&inJointIndices2) : mJointIndices1(std::move(inJointIndices1)), mJointIndices2(std::move(inJointIndices2)) { }
39
42 };
43
46 {
47 public:
48 Unmapped() = default;
49 Unmapped(int inJointIdx, int inParentJointIdx) : mJointIdx(inJointIdx), mParentJointIdx(inParentJointIdx) { }
50
53 };
54
56 class Locked
57 {
58 public:
62 };
63
65 using CanMapJoint = function<bool (const Skeleton *, int, const Skeleton *, int)>;
66
68 static bool sDefaultCanMapJoint(const Skeleton *inSkeleton1, int inIndex1, const Skeleton *inSkeleton2, int inIndex2)
69 {
70 return inSkeleton1->GetJoint(inIndex1).mName == inSkeleton2->GetJoint(inIndex2).mName;
71 }
72
81 void Initialize(const Skeleton *inSkeleton1, const Mat44 *inNeutralPose1, const Skeleton *inSkeleton2, const Mat44 *inNeutralPose2, const CanMapJoint &inCanMapJoint = sDefaultCanMapJoint);
82
90 void LockTranslations(const Skeleton *inSkeleton2, const bool *inLockedTranslations, const Mat44 *inNeutralPose2);
91
98 void LockAllTranslations(const Skeleton *inSkeleton2, const Mat44 *inNeutralPose2);
99
107 void Map(const Mat44 *inPose1ModelSpace, const Mat44 *inPose2LocalSpace, Mat44 *outPose2ModelSpace) const;
108
112 void MapReverse(const Mat44 *inPose2ModelSpace, Mat44 *outPose1ModelSpace) const;
113
115 int GetMappedJointIdx(int inJoint1Idx) const;
116
118 bool IsJointTranslationLocked(int inJoint2Idx) const;
119
124
127 const MappingVector & GetMappings() const { return mMappings; }
128 MappingVector & GetMappings() { return mMappings; }
129 const ChainVector & GetChains() const { return mChains; }
130 ChainVector & GetChains() { return mChains; }
131 const UnmappedVector & GetUnmapped() const { return mUnmapped; }
132 UnmappedVector & GetUnmapped() { return mUnmapped; }
133 const LockedVector & GetLockedTranslations() const { return mLockedTranslations; }
134 LockedVector & GetLockedTranslations() { return mLockedTranslations; }
136
137private:
139 MappingVector mMappings;
140 ChainVector mChains;
141 UnmappedVector mUnmapped;
142 LockedVector mLockedTranslations;
143};
144
#define JPH_EXPORT
Definition: Core.h:227
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
Definition: Reference.h:35
String mName
Name of the joint.
Definition: Skeleton.h:33
Resource that contains the joint hierarchy for a skeleton.
Definition: Skeleton.h:18
const Joint & GetJoint(int inJoint) const
Definition: Skeleton.h:45
A joint chain that starts with a 1-on-1 mapped joint and ends with a 1-on-1 mapped joint with interme...
Definition: SkeletonMapper.h:35
Chain(Array< int > &&inJointIndices1, Array< int > &&inJointIndices2)
Definition: SkeletonMapper.h:38
Array< int > mJointIndices1
Joint chain from skeleton 1.
Definition: SkeletonMapper.h:40
Array< int > mJointIndices2
Corresponding joint chain from skeleton 2.
Definition: SkeletonMapper.h:41
Joints that should have their translation locked (fixed)
Definition: SkeletonMapper.h:57
int mJointIdx
Joint index of joint with locked translation (in skeleton 2)
Definition: SkeletonMapper.h:59
Vec3 mTranslation
Translation of neutral pose.
Definition: SkeletonMapper.h:61
int mParentJointIdx
Parent joint index of joint with locked translation (in skeleton 2)
Definition: SkeletonMapper.h:60
A joint that maps 1-on-1 to a joint in the other skeleton.
Definition: SkeletonMapper.h:18
Mat44 mJoint1To2
Transforms this joint from skeleton 1 to 2.
Definition: SkeletonMapper.h:29
Mat44 mJoint2To1
Inverse of the transform above.
Definition: SkeletonMapper.h:30
Mapping(int inJointIdx1, int inJointIdx2, Mat44Arg inJoint1To2)
Definition: SkeletonMapper.h:21
int mJointIdx1
Index of joint from skeleton 1.
Definition: SkeletonMapper.h:27
int mJointIdx2
Corresponding index of joint from skeleton 2.
Definition: SkeletonMapper.h:28
Joints that could not be mapped from skeleton 1 to 2.
Definition: SkeletonMapper.h:46
Unmapped(int inJointIdx, int inParentJointIdx)
Definition: SkeletonMapper.h:49
int mJointIdx
Joint index of unmappable joint.
Definition: SkeletonMapper.h:51
int mParentJointIdx
Parent joint index of unmappable joint.
Definition: SkeletonMapper.h:52
Class that is able to map a low detail (ragdoll) skeleton to a high detail (animation) skeleton and v...
Definition: SkeletonMapper.h:14
MappingVector & GetMappings()
Definition: SkeletonMapper.h:128
const MappingVector & GetMappings() const
Definition: SkeletonMapper.h:127
Array< Chain > ChainVector
Definition: SkeletonMapper.h:121
const UnmappedVector & GetUnmapped() const
Definition: SkeletonMapper.h:131
ChainVector & GetChains()
Definition: SkeletonMapper.h:130
static bool sDefaultCanMapJoint(const Skeleton *inSkeleton1, int inIndex1, const Skeleton *inSkeleton2, int inIndex2)
Default function that checks if the names of the joints are equal.
Definition: SkeletonMapper.h:68
function< bool(const Skeleton *, int, const Skeleton *, int)> CanMapJoint
A function that is called to determine if a joint can be mapped from source to target skeleton.
Definition: SkeletonMapper.h:65
Array< Mapping > MappingVector
Definition: SkeletonMapper.h:120
Array< Locked > LockedVector
Definition: SkeletonMapper.h:123
LockedVector & GetLockedTranslations()
Definition: SkeletonMapper.h:134
const ChainVector & GetChains() const
Definition: SkeletonMapper.h:129
UnmappedVector & GetUnmapped()
Definition: SkeletonMapper.h:132
Array< Unmapped > UnmappedVector
Definition: SkeletonMapper.h:122
const LockedVector & GetLockedTranslations() const
Definition: SkeletonMapper.h:133
Definition: Vec3.h:16
Definition: Reference.h:204