Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Start using new bone naming for human with new animation pack

Scott Petrovic000eec829393
diff --git a/src/lib/processes/animations-listing/AnimationUtility.ts b/src/lib/processes/animations-listing/AnimationUtility.ts
index a17a88d..27209b9 100644
--- a/src/lib/processes/animations-listing/AnimationUtility.ts
+++ b/src/lib/processes/animations-listing/AnimationUtility.ts
@@ -46,12 +46,13 @@ export class AnimationUtility {
rotation_tracks = animation_clip.tracks
.filter((x: KeyframeTrack) => x.name.includes('quaternion') ||
x.name.toLowerCase().includes('hips.position') ||
+ x.name.toLowerCase().includes('pelvis.position') ||
x.name.toLowerCase().includes('root.position'))
- console.log('Preserving root position for clip: ' + animation_clip.name)
} else {
rotation_tracks = animation_clip.tracks
.filter((x: KeyframeTrack) => x.name.includes('quaternion') ||
- x.name.toLowerCase().includes('hips.position'))
+ x.name.toLowerCase().includes('hips.position') ||
+ x.name.toLowerCase().includes('pelvis.position'))
}
animation_clip.tracks = rotation_tracks // update track data
@@ -217,6 +218,7 @@ export class AnimationUtility {
if (track.name.includes('quaternion')) {
const is_center_bone = track_name_lower.includes('spine') ||
track_name_lower.includes('hips') ||
+ track_name_lower.includes('pelvis') ||
track_name_lower.includes('neck') ||
track_name_lower.includes('head') ||
track_name_lower.includes('torso') ||
@@ -264,7 +266,8 @@ export class AnimationUtility {
const track_name_lower = track.name.toLowerCase()
// Handle position tracks specifically for hips
- if (track.name.includes('position') && track_name_lower.includes('hips')) {
+ if (track.name.includes('position') &&
+ (track_name_lower.includes('hips') || track_name_lower.includes('pelvis'))) {
const values = track.values
const units_in_position = 3 // x, y, z
diff --git a/src/lib/processes/load-skeleton/HandHelper.ts b/src/lib/processes/load-skeleton/HandHelper.ts
index 8f16b86..fba2b83 100644
--- a/src/lib/processes/load-skeleton/HandHelper.ts
+++ b/src/lib/processes/load-skeleton/HandHelper.ts
@@ -85,6 +85,6 @@ export class HandHelper {
// they have the word 'tip' in the bone name
private is_end_tip_bone (bone_name: string): boolean {
// Look for bones that are finger tips - usually end with 'tip', 'end', or numbers like '3'
- return bone_name.toLowerCase().includes('tip')
+ return bone_name.toLowerCase().includes('leaf')
}
}
diff --git a/src/lib/solvers/SolverDistanceChildTargeting.ts b/src/lib/solvers/SolverDistanceChildTargeting.ts
index 29966fc..4f79282 100644
--- a/src/lib/solvers/SolverDistanceChildTargeting.ts
+++ b/src/lib/solvers/SolverDistanceChildTargeting.ts
@@ -248,7 +248,10 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver
// every vertex checks to see if it is below the hips area,
// so do this calculation once and cache it for the lookup later
private calculate_distance_to_bottom_of_hip (): number {
- const hip_bone_object: Bone | undefined = this.get_bone_master_data().find(b => b.name.toLowerCase().includes('hips'))
+ const hip_bone_object: Bone | undefined = this.get_bone_master_data().find(b => {
+ const name = b.name.toLowerCase()
+ return name.includes('hips') || name.includes('pelvis')
+ })
if (hip_bone_object === undefined) {
throw new Error('Hip bone not found')
}
@@ -285,7 +288,8 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver
// hip bones should have custom logic for distance. If the distance is too far away we should ignore it
// This will help with hips when left/right legs could be closer than knee bones
- if (this.skeleton_type === SkeletonType.Human && bone.name.includes('hips')) {
+ if (this.skeleton_type === SkeletonType.Human &&
+ (bone.name.includes('hips') || bone.name.includes('pelvis'))) {
// if the intersection point is lower than the vertex position, that means the vertex is below
// the hips area, and is part of the left or right leg...ignore that result
if (this.distance_to_bottom_of_hip !== null && this.distance_to_bottom_of_hip < vertex_position.y) {
diff --git a/src/retarget/bone-automap/BoneAutoMapper.ts b/src/retarget/bone-automap/BoneAutoMapper.ts
index 288398f..6ebece4 100644
--- a/src/retarget/bone-automap/BoneAutoMapper.ts
+++ b/src/retarget/bone-automap/BoneAutoMapper.ts
@@ -252,7 +252,7 @@ export class BoneAutoMapper {
*/
private static detect_bone_category (normalized_name: string): BoneCategory {
if (normalized_name.includes('spine') || normalized_name.includes('chest') || normalized_name.includes('neck') ||
- normalized_name.includes('head') || normalized_name.includes('hips')) {
+ normalized_name.includes('head') || normalized_name.includes('hips') || normalized_name.includes('pelvis')) {
return BoneCategory.Torso
}
diff --git a/src/retarget/bone-automap/MixamoMapper.ts b/src/retarget/bone-automap/MixamoMapper.ts
index b359b15..948c241 100644
--- a/src/retarget/bone-automap/MixamoMapper.ts
+++ b/src/retarget/bone-automap/MixamoMapper.ts
@@ -11,99 +11,99 @@ export class MixamoMapper {
*/
private static readonly BONE_MAP: Record<string, string> = {
// Torso
- 'DEF-hips': 'mixamorigHips',
- 'DEF-spine001': 'mixamorigSpine',
- 'DEF-spine002': 'mixamorigSpine1',
- 'DEF-spine003': 'mixamorigSpine2',
- 'DEF-neck': 'mixamorigNeck',
- 'DEF-head': 'mixamorigHead',
- 'DEF-headtip': 'mixamorigHeadTop_End',
+ pelvis: 'mixamorigHips',
+ spine_01: 'mixamorigSpine',
+ spine_02: 'mixamorigSpine1',
+ spine_03: 'mixamorigSpine2',
+ neck_01: 'mixamorigNeck',
+ head: 'mixamorigHead',
+ head_leaf: 'mixamorigHeadTop_End',
// Left Arm
- 'DEF-shoulderL': 'mixamorigLeftShoulder',
- 'DEF-upper_armL': 'mixamorigLeftArm',
- 'DEF-forearmL': 'mixamorigLeftForeArm',
- 'DEF-handL': 'mixamorigLeftHand',
+ clavicle_l: 'mixamorigLeftShoulder',
+ upperarm_l: 'mixamorigLeftArm',
+ lowerarm_l: 'mixamorigLeftForeArm',
+ hand_l: 'mixamorigLeftHand',
// Right Arm
- 'DEF-shoulderR': 'mixamorigRightShoulder',
- 'DEF-upper_armR': 'mixamorigRightArm',
- 'DEF-forearmR': 'mixamorigRightForeArm',
- 'DEF-handR': 'mixamorigRightHand',
+ clavicle_r: 'mixamorigRightShoulder',
+ upperarm_r: 'mixamorigRightArm',
+ lowerarm_r: 'mixamorigRightForeArm',
+ hand_r: 'mixamorigRightHand',
// Left Leg
- 'DEF-thighL': 'mixamorigLeftUpLeg',
- 'DEF-shinL': 'mixamorigLeftLeg',
- 'DEF-footL': 'mixamorigLeftFoot',
- 'DEF-toeL': 'mixamorigLeftToeBase',
- 'DEF-toe_tipL': 'mixamorigLeftToe_End',
+ thigh_l: 'mixamorigLeftUpLeg',
+ calf_l: 'mixamorigLeftLeg',
+ foot_l: 'mixamorigLeftFoot',
+ ball_l: 'mixamorigLeftToeBase',
+ ball_leaf_l: 'mixamorigLeftToe_End',
// Right Leg
- 'DEF-thighR': 'mixamorigRightUpLeg',
- 'DEF-shinR': 'mixamorigRightLeg',
- 'DEF-footR': 'mixamorigRightFoot',
- 'DEF-toeR': 'mixamorigRightToeBase',
- 'DEF-toe_tipR': 'mixamorigRightToe_End',
+ thigh_r: 'mixamorigRightUpLeg',
+ calf_r: 'mixamorigRightLeg',
+ foot_r: 'mixamorigRightFoot',
+ ball_r: 'mixamorigRightToeBase',
+ ball_leaf_r: 'mixamorigRightToe_End',
// Left Hand Fingers - Thumb
- 'DEF-thumb01L': 'mixamorigLeftHandThumb1',
- 'DEF-thumb02L': 'mixamorigLeftHandThumb2',
- 'DEF-thumb03L': 'mixamorigLeftHandThumb3',
- 'DEF-thumb_04_tipL': 'mixamorigLeftHandThumb4',
+ thumb_01_l: 'mixamorigLeftHandThumb1',
+ thumb_02_l: 'mixamorigLeftHandThumb2',
+ thumb_03_l: 'mixamorigLeftHandThumb3',
+ thumb_04_leaf_l: 'mixamorigLeftHandThumb4',
// Left Hand Fingers - Index
- 'DEF-f_index01L': 'mixamorigLeftHandIndex1',
- 'DEF-f_index02L': 'mixamorigLeftHandIndex2',
- 'DEF-f_index03L': 'mixamorigLeftHandIndex3',
- 'DEF-f_index04_tipL': 'mixamorigLeftHandIndex4',
+ index_01_l: 'mixamorigLeftHandIndex1',
+ index_02_l: 'mixamorigLeftHandIndex2',
+ index_03_l: 'mixamorigLeftHandIndex3',
+ index_04_leaf_l: 'mixamorigLeftHandIndex4',
// Left Hand Fingers - Middle
- 'DEF-f_middle01L': 'mixamorigLeftHandMiddle1',
- 'DEF-f_middle02L': 'mixamorigLeftHandMiddle2',
- 'DEF-f_middle03L': 'mixamorigLeftHandMiddle3',
- 'DEF-f_middle04_tipL': 'mixamorigLeftHandMiddle4',
+ middle_01_l: 'mixamorigLeftHandMiddle1',
+ middle_02_l: 'mixamorigLeftHandMiddle2',
+ middle_03_l: 'mixamorigLeftHandMiddle3',
+ middle_04_leaf_l: 'mixamorigLeftHandMiddle4',
// Left Hand Fingers - Ring
- 'DEF-f_ring01L': 'mixamorigLeftHandRing1',
- 'DEF-f_ring02L': 'mixamorigLeftHandRing2',
- 'DEF-f_ring03L': 'mixamorigLeftHandRing3',
- 'DEF-f_ring04_tipL': 'mixamorigLeftHandRing4',
+ ring_01_l: 'mixamorigLeftHandRing1',
+ ring_02_l: 'mixamorigLeftHandRing2',
+ ring_03_l: 'mixamorigLeftHandRing3',
+ ring_04_leaf_l: 'mixamorigLeftHandRing4',
// Left Hand Fingers - Pinky
- 'DEF-f_pinky01L': 'mixamorigLeftHandPinky1',
- 'DEF-f_pinky02L': 'mixamorigLeftHandPinky2',
- 'DEF-f_pinky03L': 'mixamorigLeftHandPinky3',
- 'DEF-f_pinky04_tipL': 'mixamorigLeftHandPinky4',
+ pinky_01_l: 'mixamorigLeftHandPinky1',
+ pinky_02_l: 'mixamorigLeftHandPinky2',
+ pinky_03_l: 'mixamorigLeftHandPinky3',
+ pinky_04_leaf_l: 'mixamorigLeftHandPinky4',
// Right Hand Fingers - Thumb
- 'DEF-thumb01R': 'mixamorigRightHandThumb1',
- 'DEF-thumb02R': 'mixamorigRightHandThumb2',
- 'DEF-thumb03R': 'mixamorigRightHandThumb3',
- 'DEF-thumb04_tipR': 'mixamorigRightHandThumb4',
+ thumb_01_r: 'mixamorigRightHandThumb1',
+ thumb_02_r: 'mixamorigRightHandThumb2',
+ thumb_03_r: 'mixamorigRightHandThumb3',
+ thumb_04_leaf_r: 'mixamorigRightHandThumb4',
// Right Hand Fingers - Index
- 'DEF-f_index01R': 'mixamorigRightHandIndex1',
- 'DEF-f_index02R': 'mixamorigRightHandIndex2',
- 'DEF-f_index03R': 'mixamorigRightHandIndex3',
- 'DEF-f_index04_tipR': 'mixamorigRightHandIndex4',
+ index_01_r: 'mixamorigRightHandIndex1',
+ index_02_r: 'mixamorigRightHandIndex2',
+ index_03_r: 'mixamorigRightHandIndex3',
+ index_04_leaf_r: 'mixamorigRightHandIndex4',
// Right Hand Fingers - Middle
- 'DEF-f_middle01R': 'mixamorigRightHandMiddle1',
- 'DEF-f_middle02R': 'mixamorigRightHandMiddle2',
- 'DEF-f_middle03R': 'mixamorigRightHandMiddle3',
- 'DEF-f_middle04_tipR': 'mixamorigRightHandMiddle4',
+ middle_01_r: 'mixamorigRightHandMiddle1',
+ middle_02_r: 'mixamorigRightHandMiddle2',
+ middle_03_r: 'mixamorigRightHandMiddle3',
+ middle_04_leaf_r: 'mixamorigRightHandMiddle4',
// Right Hand Fingers - Ring
- 'DEF-f_ring01R': 'mixamorigRightHandRing1',
- 'DEF-f_ring02R': 'mixamorigRightHandRing2',
- 'DEF-f_ring03R': 'mixamorigRightHandRing3',
- 'DEF-f_ring04_tipR': 'mixamorigRightHandRing4',
+ ring_01_r: 'mixamorigRightHandRing1',
+ ring_02_r: 'mixamorigRightHandRing2',
+ ring_03_r: 'mixamorigRightHandRing3',
+ ring_04_leaf_r: 'mixamorigRightHandRing4',
// Right Hand Fingers - Pinky
- 'DEF-f_pinky01R': 'mixamorigRightHandPinky1',
- 'DEF-f_pinky02R': 'mixamorigRightHandPinky2',
- 'DEF-f_pinky03R': 'mixamorigRightHandPinky3',
- 'DEF-f_pinky04_tipR': 'mixamorigRightHandPinky4'
+ pinky_01_r: 'mixamorigRightHandPinky1',
+ pinky_02_r: 'mixamorigRightHandPinky2',
+ pinky_03_r: 'mixamorigRightHandPinky3',
+ pinky_04_leaf_r: 'mixamorigRightHandPinky4'
}
/**
@@ -128,13 +128,13 @@ export class MixamoMapper {
// For each source bone (Mesh2Motion), find matching target bone (Mixamo)
for (const source_bone of source_bones) {
- const expected_mixamo_name = this.BONE_MAP[source_bone.name]
+ const expected_mixamo_name: string | undefined = this.BONE_MAP[source_bone.name]
- if (expected_mixamo_name) {
+ if (expected_mixamo_name !== undefined) {
// Find target bone with this Mixamo name
- const target_bone = target_bones.find(tb => tb.name === expected_mixamo_name)
+ const target_bone: BoneMetadata | undefined = target_bones.find(tb => tb.name === expected_mixamo_name)
- if (target_bone) {
+ if (target_bone !== undefined) {
mappings.set(target_bone.name, source_bone.name)
// console.log(`Mapped: ${target_bone.name} -> ${source_bone.name}`)
}
diff --git a/src/retarget/human-retargeting/HumanChainConfig.ts b/src/retarget/human-retargeting/HumanChainConfig.ts
index c037cb5..adef5aa 100644
--- a/src/retarget/human-retargeting/HumanChainConfig.ts
+++ b/src/retarget/human-retargeting/HumanChainConfig.ts
@@ -4,23 +4,23 @@ export class HumanChainConfig {
// Master list of human bone/joint names that we can use and part of the Mesh2Motion rig
// this will always be the source config we start with for retargeting
public static readonly mesh2motion_config: Record<string, string[]> = {
- pelvis: ['DEF-hips'],
- spine: ['DEF-spine001', 'DEF-spine002', 'DEF-spine003'],
- head: ['DEF-neck', 'DEF-head'],
- armL: ['DEF-upper_armL', 'DEF-forearmL', 'DEF-handL'],
- armR: ['DEF-upper_armR', 'DEF-forearmR', 'DEF-handR'],
- legL: ['DEF-thighL', 'DEF-shinL', 'DEF-footL'],
- legR: ['DEF-thighR', 'DEF-shinR', 'DEF-footR'],
- fingersThumbL: ['DEF-thumb01L', 'DEF-thumb02L', 'DEF-thumb03L', 'DEF-thumb04_tipL'],
- fingersThumbR: ['DEF-thumb01R', 'DEF-thumb02R', 'DEF-thumb03R', 'DEF-thumb04_tipR'],
- fingersIndexL: ['DEF-f_index01L', 'DEF-f_index02L', 'DEF-f_index03L', 'DEF-f_index04_tipL'],
- fingersIndexR: ['DEF-f_index01R', 'DEF-f_index02R', 'DEF-f_index03R', 'DEF-f_index04_tipR'],
- fingersMiddleL: ['DEF-f_middle01L', 'DEF-f_middle02L', 'DEF-f_middle03L', 'DEF-f_middle04_tipL'],
- fingersMiddleR: ['DEF-f_middle01R', 'DEF-f_middle02R', 'DEF-f_middle03R', 'DEF-f_middle04_tipR'],
- fingersRingL: ['DEF-f_ring01L', 'DEF-f_ring02L', 'DEF-f_ring03L', 'DEF-f_ring04_tipL'],
- fingersRingR: ['DEF-f_ring01R', 'DEF-f_ring02R', 'DEF-f_ring03R', 'DEF-f_ring04_tipR'],
- fingersPinkyL: ['DEF-f_pinky01L', 'DEF-f_pinky02L', 'DEF-f_pinky03L', 'DEF-f_pinky04_tipL'],
- fingersPinkyR: ['DEF-f_pinky01R', 'DEF-f_pinky02R', 'DEF-f_pinky03R', 'DEF-f_pinky04_tipR']
+ pelvis: ['pelvis'],
+ spine: ['spine_01', 'spine_02', 'spine_03'],
+ head: ['neck_01', 'head'],
+ armL: ['upperarm_l', 'lowerarm_l', 'hand_l'],
+ armR: ['upperarm_r', 'lowerarm_r', 'hand_r'],
+ legL: ['thigh_l', 'calf_l', 'foot_l', 'ball_l'],
+ legR: ['thigh_r', 'calf_r', 'foot_r', 'ball_r'],
+ fingersThumbL: ['thumb_01_l', 'thumb_02_l', 'thumb_03_l', 'thumb_04_leaf_l'],
+ fingersThumbR: ['thumb_01_r', 'thumb_02_r', 'thumb_03_r', 'thumb_04_leaf_r'],
+ fingersIndexL: ['index_01_l', 'index_02_l', 'index_03_l', 'index_04_leaf_l'],
+ fingersIndexR: ['index_01_r', 'index_02_r', 'index_03_r', 'index_04_leaf_r'],
+ fingersMiddleL: ['middle_01_l', 'middle_02_l', 'middle_03_l', 'middle_04_leaf_l'],
+ fingersMiddleR: ['middle_01_r', 'middle_02_r', 'middle_03_r', 'middle_04_leaf_r'],
+ fingersRingL: ['ring_01_l', 'ring_02_l', 'ring_03_l', 'ring_04_leaf_l'],
+ fingersRingR: ['ring_01_r', 'ring_02_r', 'ring_03_r', 'ring_04_leaf_r'],
+ fingersPinkyL: ['pinky_01_l', 'pinky_02_l', 'pinky_03_l', 'pinky_04_leaf_l'],
+ fingersPinkyR: ['pinky_01_r', 'pinky_02_r', 'pinky_03_r', 'pinky_04_leaf_r']
}
public static readonly mixamo_config: Record<string, string[]> = {
diff --git a/static/animations/human-addon-animations.glb b/static/animations/human-addon-animations.glb
index 9fc3d45..db0d4fd 100644
Binary files a/static/animations/human-addon-animations.glb and b/static/animations/human-addon-animations.glb differ
diff --git a/static/animations/human-base-animations.glb b/static/animations/human-base-animations.glb
index 91abd9b..2ec3923 100644
Binary files a/static/animations/human-base-animations.glb and b/static/animations/human-base-animations.glb differ
diff --git a/static/rigs/rig-human.glb b/static/rigs/rig-human.glb
index 613324c..a29dde8 100644
Binary files a/static/rigs/rig-human.glb and b/static/rigs/rig-human.glb differ