Import a 3D Model and automatically assign and export animations
TypeScript
remove position keyframes in animation to preserve the skeleton's offset
Scott Petrovicecb4ff81a89b
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.tsindex d9a5293..89ae267 100644--- a/src/lib/processes/StepAnimationsListing.ts+++ b/src/lib/processes/StepAnimationsListing.ts@@ -79,10 +79,15 @@ export class StepAnimationsListing extends EventTarget {this.gltf_animation_loader = new GLTFLoader()this.gltf_animation_loader.load(animations_to_load_filepath, (gltf) => {-- // remove the animation position keyframes. That will mess up the skinning+ // load the animation clips into a new array+ // then, remove the animation position keyframes. That will mess up the skinning// process since we will be offsetting and moving the bone root positions- this.load_animation_clips(gltf.animations)+ this.animation_clips_loaded = this.deep_clone_animation_clips(gltf.animations)++ // only keep position tracks+ this.remove_position_tracks(this.animation_clips_loaded)++ console.log(this.animation_clips_loaded)// create user interface with all available animation clipsthis.ui.build_animation_clip_ui(this.animation_clips_loaded)@@ -94,6 +99,14 @@ export class StepAnimationsListing extends EventTarget {})}+ // mutates the animation clips passed in and only keeps rotation/quaternion tracks+ private remove_position_tracks (animation_clips: AnimationClip[]): void {+ animation_clips.forEach((animation_clip: AnimationClip) => {+ const rotation_tracks = animation_clip.tracks.filter(x => x.name.includes('quaternion'))+ animation_clip.tracks = rotation_tracks+ })+ }+private extend_arm_animations_by_percentage (percentage: number): void {// loop through each animation clip to update the tracksthis.animation_clips_loaded.forEach((animation_clip: AnimationClip) => {@@ -158,10 +171,6 @@ export class StepAnimationsListing extends EventTarget {})}- private load_animation_clips (animation_clips: AnimationClip[]): void {- this.animation_clips_loaded = this.deep_clone_animation_clips(animation_clips)- }-private add_event_listeners (): void {if (this.has_added_event_listeners) {return@@ -278,6 +287,7 @@ export class StepAnimationsListing extends EventTarget {})}+ /* this will mutate the animation clips passed in by effectively removing the position keyframes */private reduce_position_keyframes (animation_clips: AnimationClip[]): void {animation_clips.forEach((animation_clip, index) => {animation_clip.tracks.forEach((track) => {diff --git a/src/lib/processes/StepEditSkeleton.ts b/src/lib/processes/StepEditSkeleton.tsindex 22066b2..11f1c61 100644--- a/src/lib/processes/StepEditSkeleton.ts+++ b/src/lib/processes/StepEditSkeleton.ts@@ -4,6 +4,14 @@ import { Utility } from '../Utilities.ts'import { Vector3, Euler, Object3D, Skeleton, type Bone } from 'three'import { SkinningFormula } from '../enums/SkinningFormula.ts'+/*+ * StepEditSkeleton+ * Handles editing the skeleton of the model+ * Overview of workflow:+ * 1. Load original armature from model+ * 2. Create a skeleton that Three.js can use and we can manipulate+ * 3. Allow user to edit the three.js skeleton+ */export class StepEditSkeleton extends EventTarget {private readonly ui: UI// Original armature data from the model data. A Skeleton type object is not@@ -50,7 +58,6 @@ export class StepEditSkeleton extends EventTarget {this.add_event_listeners()}-private update_bind_button_text (): void {if (this.show_debug && this.ui.dom_bind_pose_button !== null) {this.ui.dom_bind_pose_button.innerHTML = 'Test Skinning'@@ -178,6 +185,7 @@ export class StepEditSkeleton extends EventTarget {return this.threejs_skeleton}+public apply_mirror_mode (selected_bone: Bone, transform_type: string): void {// if we are on the positive side mirror mode is enabled// we need to change the position of the bone on the other side of the mirror