Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Hook up mapping to have imported animations kind of working with simplified skeleton

Scott Petrovic323662450f05
diff --git a/src/lib/mapping/MixamoToSimple.ts b/src/lib/mapping/MixamoToSimple.ts
index 62c766f..91ee30b 100644
--- a/src/lib/mapping/MixamoToSimple.ts
+++ b/src/lib/mapping/MixamoToSimple.ts
@@ -1,52 +1,54 @@
-mixamorigHips
-mixamorigSpine
-mixamorigSpine1
-mixamorigSpine2
-mixamorigNeck
-mixamorigHead
-mixamorigRightShoulder
-mixamorigRightArm
-mixamorigRightForeArm
-mixamorigRightHand
-mixamorigRightHandThumb1
-mixamorigRightHandThumb2
-mixamorigRightHandThumb3
-mixamorigRightHandIndex1
-mixamorigRightHandIndex2
-mixamorigRightHandIndex3
-mixamorigRightHandMiddle1
-mixamorigRightHandMiddle2
-mixamorigRightHandMiddle3
-mixamorigRightHandRing1
-mixamorigRightHandRing2
-mixamorigRightHandRing3
-mixamorigRightHandPinky1
-mixamorigRightHandPinky2
-mixamorigRightHandPinky3
-mixamorigLeftShoulder
-mixamorigLeftArm
-mixamorigLeftForeArm
-mixamorigLeftHand
-mixamorigLeftHandThumb1
-mixamorigLeftHandThumb2
-mixamorigLeftHandThumb3
-mixamorigLeftHandIndex1
-mixamorigLeftHandIndex2
-mixamorigLeftHandIndex3
-mixamorigLeftHandMiddle1
-mixamorigLeftHandMiddle2
-mixamorigLeftHandMiddle3
-mixamorigLeftHandRing1
-mixamorigLeftHandRing2
-mixamorigLeftHandRing3
-mixamorigLeftHandPinky1
-mixamorigLeftHandPinky2
-mixamorigLeftHandPinky3
-mixamorigRightUpLeg
-mixamorigRightLeg
-mixamorigRightFoot
-mixamorigRightToeBase
-mixamorigLeftUpLeg
-mixamorigLeftLeg
-mixamorigLeftFoot
-mixamorigLeftToeBase
\ No newline at end of file
+export const MixamoToSimpleMapping = {
+ mixamorigHips: 'SpineBase',
+ mixamorigSpine: 'SpineLow',
+ mixamorigSpine1: 'SpineLow',
+ mixamorigSpine2: 'SpineMid',
+ mixamorigNeck: 'Neck',
+ mixamorigHead: 'Head',
+ mixamorigRightShoulder: 'R_Shoulder',
+ mixamorigRightArm: 'R_Arm',
+ mixamorigRightForeArm: 'R_Forearm',
+ mixamorigRightHand: 'R_HandBase',
+ mixamorigRightHandThumb1: 'R_ThumbBase',
+ mixamorigRightHandThumb2: 'R_ThumbMid',
+ mixamorigRightHandThumb3: 'R_ThumbTip',
+ mixamorigRightHandIndex1: 'R_PointerBase',
+ mixamorigRightHandIndex2: 'R_PointerMid',
+ mixamorigRightHandIndex3: 'R_PointerTip',
+ mixamorigRightHandMiddle1: 'R_FingersBase',
+ mixamorigRightHandMiddle2: 'R_FingersMid',
+ mixamorigRightHandMiddle3: 'R_FingersTip',
+ mixamorigRightHandRing1: '',
+ mixamorigRightHandRing2: '',
+ mixamorigRightHandRing3: '',
+ mixamorigRightHandPinky1: '',
+ mixamorigRightHandPinky2: '',
+ mixamorigRightHandPinky3: '',
+ mixamorigLeftShoulder: 'L_Shoulder',
+ mixamorigLeftArm: 'L_Arm',
+ mixamorigLeftForeArm: 'L_Forearm',
+ mixamorigLeftHand: 'L_HandBase',
+ mixamorigLeftHandThumb1: 'L_ThumbBase',
+ mixamorigLeftHandThumb2: 'L_ThumbMid',
+ mixamorigLeftHandThumb3: 'L_ThumbTip',
+ mixamorigLeftHandIndex1: 'L_PointerBase',
+ mixamorigLeftHandIndex2: 'L_PointerMid',
+ mixamorigLeftHandIndex3: 'L_PointerTip',
+ mixamorigLeftHandMiddle1: 'L_FingersBase',
+ mixamorigLeftHandMiddle2: 'L_FingersMid',
+ mixamorigLeftHandMiddle3: 'L_FingersTip',
+ mixamorigLeftHandRing1: '',
+ mixamorigLeftHandRing2: '',
+ mixamorigLeftHandRing3: '',
+ mixamorigLeftHandPinky1: '',
+ mixamorigLeftHandPinky2: '',
+ mixamorigLeftHandPinky3: '',
+ mixamorigRightUpLeg: 'R_UpLeg',
+ mixamorigRightLeg: 'R_Leg',
+ mixamorigRightFoot: 'R_Foot',
+ mixamorigRightToeBase: 'R_Toe',
+ mixamorigLeftUpLeg: 'L_UpLeg',
+ mixamorigLeftLeg: 'L_Leg',
+ mixamorigLeftFoot: 'L_Foot',
+ mixamorigLeftToeBase: 'L_Toe',
+};
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index 73ab522..b964d61 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -9,6 +9,7 @@ import { SkinnedMesh } from 'three';
import { QuaternionKeyframeTrack } from 'three';
import { KeyframeTrack } from 'three';
import { AnimationAction } from 'three';
+import { MixamoToSimpleMapping } from '../mapping/MixamoToSimple.js';
// Note: EventTarget is a built-ininterface and do not need to import it
export class StepAnimationsListing extends EventTarget
@@ -21,6 +22,7 @@ export class StepAnimationsListing extends EventTarget
private animation_mixer: AnimationMixer;
private skinned_meshes_to_animate: SkinnedMesh[] = []
private current_playing_index: number = 0
+ private skeleton_type: string = SkeletonType.BipedalSimple;
constructor()
{
@@ -52,8 +54,6 @@ export class StepAnimationsListing extends EventTarget
this.addEventListeners();
}
-
-
}
public instructions_text()
@@ -80,6 +80,7 @@ export class StepAnimationsListing extends EventTarget
public load_and_apply_default_animation_to_skinned_mesh(final_skinned_meshes, skeleton_type)
{
this.skinned_meshes_to_animate = final_skinned_meshes
+ this.skeleton_type = skeleton_type
let animations_to_load_filepath: string = ''
switch(skeleton_type)
@@ -261,7 +262,10 @@ export class StepAnimationsListing extends EventTarget
this.fbx_animation_loader.load(fbx_file, (fbx) => {
- const animations_for_scene = fbx.animations; // we only need the animations
+ let animations_for_scene = fbx.animations; // we only need the animations
+
+ // check to see if the animation is a mixamo skeleton. we will need this later for potential mapping
+ const is_mixamo_animation = animations_for_scene[0].name === 'mixamo.com';
// if name is just a website, update it so it is slightly more informative
animations_for_scene.forEach((animation_clip, index) => {
@@ -271,6 +275,42 @@ export class StepAnimationsListing extends EventTarget
}
})
+ // if we are, but we are using a simplified skeleton, we need to map the values to the correct bones
+ if(is_mixamo_animation && this.skeleton_type === SkeletonType.BipedalSimple)
+ {
+ // loop through each animation clip to update the tracks
+ animations_for_scene.forEach((animation_clip) => {
+ animation_clip.tracks.forEach((track) => {
+
+ // get the track name and replace it with our simplfied mapping
+ const mixamo_bone_name = track.name.split('.')[0];
+ const keyframe_type = track.name.split('.')[1];
+
+ const is_mappping_found = MixamoToSimpleMapping[mixamo_bone_name];
+
+ if (is_mappping_found)
+ {
+ track.name = MixamoToSimpleMapping[mixamo_bone_name] + '.' + keyframe_type;
+
+
+ // TODO: if track is a position track, we need to scale everything based off
+ // how much we imported the model at. Otherwise the position movement will be multiplied
+
+ }
+
+ })
+
+ console.log(animations_for_scene)
+
+
+ // filter out any tracks that contain the word mixamorig in it
+ // we don't need those since we are using a simplified skeleton
+ animation_clip.tracks = animation_clip.tracks.filter(x => x.name.indexOf('mixamorig') < 0);
+
+ });
+
+ }
+
// add the animations to the animation_clips_loaded
// update the UI with the new animation clips
this.append_animation_clips(animations_for_scene)