Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SkeletonMapper Class Reference

Class that is able to map a low detail (ragdoll) skeleton to a high detail (animation) skeleton and vice versa. More...

#include <SkeletonMapper.h>

Inheritance diagram for SkeletonMapper:
RefTarget< SkeletonMapper >

Classes

class  Chain
 A joint chain that starts with a 1-on-1 mapped joint and ends with a 1-on-1 mapped joint with intermediate joints that cannot be mapped. More...
 
class  Locked
 Joints that should have their translation locked (fixed) More...
 
class  Mapping
 A joint that maps 1-on-1 to a joint in the other skeleton. More...
 
class  Unmapped
 Joints that could not be mapped from skeleton 1 to 2. More...
 

Public Types

using CanMapJoint = function< bool(const Skeleton *, int, const Skeleton *, int)>
 A function that is called to determine if a joint can be mapped from source to target skeleton. More...
 
using MappingVector = Array< Mapping >
 
using ChainVector = Array< Chain >
 
using UnmappedVector = Array< Unmapped >
 
using LockedVector = Array< Locked >
 

Public Member Functions

void Initialize (const Skeleton *inSkeleton1, const Mat44 *inNeutralPose1, const Skeleton *inSkeleton2, const Mat44 *inNeutralPose2, const CanMapJoint &inCanMapJoint=sDefaultCanMapJoint)
 
void LockTranslations (const Skeleton *inSkeleton2, const bool *inLockedTranslations, const Mat44 *inNeutralPose2)
 
void LockAllTranslations (const Skeleton *inSkeleton2, const Mat44 *inNeutralPose2)
 
void Map (const Mat44 *inPose1ModelSpace, const Mat44 *inPose2LocalSpace, Mat44 *outPose2ModelSpace) const
 
void MapReverse (const Mat44 *inPose2ModelSpace, Mat44 *outPose1ModelSpace) const
 
int GetMappedJointIdx (int inJoint1Idx) const
 Search through the directly mapped joints (mMappings) and find inJoint1Idx, returns the corresponding Joint2Idx or -1 if not found. More...
 
bool IsJointTranslationLocked (int inJoint2Idx) const
 Search through the locked translations (mLockedTranslations) and find if joint inJoint2Idx is locked. More...
 
Access to the mapped joints
const MappingVectorGetMappings () const
 
MappingVectorGetMappings ()
 
const ChainVectorGetChains () const
 
ChainVectorGetChains ()
 
const UnmappedVectorGetUnmapped () const
 
UnmappedVectorGetUnmapped ()
 
const LockedVectorGetLockedTranslations () const
 
LockedVectorGetLockedTranslations ()
 
- Public Member Functions inherited from RefTarget< SkeletonMapper >
 RefTarget ()=default
 Constructor. More...
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us More...
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator. More...
 
uint32 GetRefCount () const
 Get current refcount of this object. More...
 
void AddRef () const
 Add or release a reference to this object. More...
 
void Release () const
 

Static Public Member Functions

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. More...
 
- Static Public Member Functions inherited from RefTarget< SkeletonMapper >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION. More...
 

Additional Inherited Members

- Protected Attributes inherited from RefTarget< SkeletonMapper >
atomic< uint32mRefCount
 Current reference count. More...
 
- Static Protected Attributes inherited from RefTarget< SkeletonMapper >
static constexpr uint32 cEmbedded
 A large value that gets added to the refcount to mark the object as embedded. More...
 

Detailed Description

Class that is able to map a low detail (ragdoll) skeleton to a high detail (animation) skeleton and vice versa.

Member Typedef Documentation

◆ CanMapJoint

using SkeletonMapper::CanMapJoint = function<bool (const Skeleton *, int, const Skeleton *, int)>

A function that is called to determine if a joint can be mapped from source to target skeleton.

◆ ChainVector

◆ LockedVector

◆ MappingVector

◆ UnmappedVector

Member Function Documentation

◆ GetChains() [1/2]

ChainVector & SkeletonMapper::GetChains ( )
inline

◆ GetChains() [2/2]

const ChainVector & SkeletonMapper::GetChains ( ) const
inline

◆ GetLockedTranslations() [1/2]

LockedVector & SkeletonMapper::GetLockedTranslations ( )
inline

◆ GetLockedTranslations() [2/2]

const LockedVector & SkeletonMapper::GetLockedTranslations ( ) const
inline

◆ GetMappedJointIdx()

int SkeletonMapper::GetMappedJointIdx ( int  inJoint1Idx) const

Search through the directly mapped joints (mMappings) and find inJoint1Idx, returns the corresponding Joint2Idx or -1 if not found.

◆ GetMappings() [1/2]

MappingVector & SkeletonMapper::GetMappings ( )
inline

◆ GetMappings() [2/2]

const MappingVector & SkeletonMapper::GetMappings ( ) const
inline

◆ GetUnmapped() [1/2]

UnmappedVector & SkeletonMapper::GetUnmapped ( )
inline

◆ GetUnmapped() [2/2]

const UnmappedVector & SkeletonMapper::GetUnmapped ( ) const
inline

◆ Initialize()

JPH_NAMESPACE_BEGIN void SkeletonMapper::Initialize ( const Skeleton inSkeleton1,
const Mat44 inNeutralPose1,
const Skeleton inSkeleton2,
const Mat44 inNeutralPose2,
const CanMapJoint inCanMapJoint = sDefaultCanMapJoint 
)

Initialize the skeleton mapper. Skeleton 1 should be the (low detail) ragdoll skeleton and skeleton 2 the (high detail) animation skeleton. We assume that each joint in skeleton 1 can be mapped to a joint in skeleton 2 (if not mapping from animation skeleton to ragdoll skeleton will be undefined). Skeleton 2 should have the same hierarchy as skeleton 1 but can contain extra joints between those in skeleton 1 and it can have extra joints at the root and leaves of the skeleton.

Parameters
inSkeleton1Source skeleton to map from.
inNeutralPose1Neutral pose of the source skeleton (model space)
inSkeleton2Target skeleton to map to.
inNeutralPose2Neutral pose of the target skeleton (model space), inNeutralPose1 and inNeutralPose2 must match as closely as possible, preferably the position of the mappable joints should be identical.
inCanMapJointFunction that checks if joints in skeleton 1 and skeleton 2 are equal.

◆ IsJointTranslationLocked()

bool SkeletonMapper::IsJointTranslationLocked ( int  inJoint2Idx) const

Search through the locked translations (mLockedTranslations) and find if joint inJoint2Idx is locked.

◆ LockAllTranslations()

void SkeletonMapper::LockAllTranslations ( const Skeleton inSkeleton2,
const Mat44 inNeutralPose2 
)

After Initialize(), this can be called to lock the translation of all joints in skeleton 2 below the first mapped joint to those of the neutral pose. Because constraints are never 100% rigid, there's always a little bit of stretch in the ragdoll when the ragdoll is under stress. Locking the translations of the pose will remove the visual stretch from the ragdoll but will introduce a difference between the physical simulation and the visual representation.

Parameters
inSkeleton2Target skeleton to map to.
inNeutralPose2Neutral pose to take reference translations from

◆ LockTranslations()

void SkeletonMapper::LockTranslations ( const Skeleton inSkeleton2,
const bool *  inLockedTranslations,
const Mat44 inNeutralPose2 
)

This can be called so lock the translation of a specified set of joints in skeleton 2. Because constraints are never 100% rigid, there's always a little bit of stretch in the ragdoll when the ragdoll is under stress. Locking the translations of the pose will remove the visual stretch from the ragdoll but will introduce a difference between the physical simulation and the visual representation.

Parameters
inSkeleton2Target skeleton to map to.
inLockedTranslationsAn array of bools the size of inSkeleton2->GetJointCount(), for each joint indicating if the joint is locked.
inNeutralPose2Neutral pose to take reference translations from

◆ Map()

void SkeletonMapper::Map ( const Mat44 inPose1ModelSpace,
const Mat44 inPose2LocalSpace,
Mat44 outPose2ModelSpace 
) const

Map a pose. Joints that were directly mappable will be copied in model space from pose 1 to pose 2. Any joints that are only present in skeleton 2 will get their model space transform calculated through the local space transforms of pose 2. Joints that are part of a joint chain between two mapped joints will be reoriented towards the next joint in skeleton 1. This means that it is possible for unmapped joints to have some animation, but very extreme animation poses will show artifacts.

Parameters
inPose1ModelSpacePose on skeleton 1 in model space
inPose2LocalSpacePose on skeleton 2 in local space (used for the joints that cannot be mapped)
outPose2ModelSpaceModel space pose on skeleton 2 (the output of the mapping)

◆ MapReverse()

void SkeletonMapper::MapReverse ( const Mat44 inPose2ModelSpace,
Mat44 outPose1ModelSpace 
) const

Reverse map a pose, this will only use the mappings and not the chains (it assumes that all joints in skeleton 1 are mapped)

Parameters
inPose2ModelSpaceModel space pose on skeleton 2
outPose1ModelSpaceWhen the function returns this will contain the model space pose for skeleton 1

◆ sDefaultCanMapJoint()

static bool SkeletonMapper::sDefaultCanMapJoint ( const Skeleton inSkeleton1,
int  inIndex1,
const Skeleton inSkeleton2,
int  inIndex2 
)
inlinestatic

Default function that checks if the names of the joints are equal.


The documentation for this class was generated from the following files: