Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Remove root motion for now for previews

Scott Petrovic8a3caf9c538e
diff --git a/src/lib/Utilities.ts b/src/lib/Utilities.ts
index b9be797..4716a9c 100644
--- a/src/lib/Utilities.ts
+++ b/src/lib/Utilities.ts
@@ -296,4 +296,23 @@ export class Utility {
return new AnimationClip(clip.name, clip.duration, tracks)
})
}
+
+ /// Removes position tracks from animation clips, keeping only rotation tracks.
+ /// @param animation_clips - The animation clips to modify.
+ /// @param preserve_root_position - Whether to keep the root position track.
+ static clean_track_data (animation_clips: AnimationClip[], preserve_root_position: boolean = false): void {
+ animation_clips.forEach((animation_clip: AnimationClip) => {
+ // remove all position nodes except root
+ let rotation_tracks: KeyframeTrack[] = []
+
+ if (preserve_root_position) {
+ rotation_tracks = animation_clip.tracks.filter((x: KeyframeTrack) => x.name.includes('quaternion') || x.name.toLowerCase().includes('hips.position'))
+ } else {
+ rotation_tracks = animation_clip.tracks.filter((x: KeyframeTrack) => x.name.includes('quaternion') || x.name.includes('hips.position'))
+ }
+
+ animation_clip.tracks = rotation_tracks // update track data
+ // console.log(animation_clip.tracks) // UNUSED DEBUG CODE
+ })
+ }
}
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index c1a4cd6..7554d70 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -161,7 +161,8 @@ export class StepAnimationsListing extends EventTarget {
const cloned_anims: AnimationClip[] = Utility.deep_clone_animation_clips(gltf.animations)
// only keep position tracks
- this.remove_position_tracks(cloned_anims, true)
+ // this mutates the cloned_anims, so no need for returning anything
+ Utility.clean_track_data(cloned_anims, true)
// apply hip bone offset
this.apply_hip_bone_offset(cloned_anims)
@@ -193,25 +194,6 @@ export class StepAnimationsListing extends EventTarget {
this.play_animation(0) // play the first animation by default
}
- // mutates the animation clips passed in and only keeps rotation/quaternion tracks
- // also removes scale tracks
- private remove_position_tracks (animation_clips: AnimationClip[], preserve_root_position: boolean = false): void {
- animation_clips.forEach((animation_clip: AnimationClip) => {
- // remove all position nodes except root
- let rotation_tracks: KeyframeTrack[] = []
-
-
- if (preserve_root_position) {
- rotation_tracks = animation_clip.tracks.filter((x: KeyframeTrack) => x.name.includes('quaternion') || x.name.toLowerCase().includes('hips.position'))
- } else {
- rotation_tracks = animation_clip.tracks.filter((x: KeyframeTrack) => x.name.includes('quaternion') || x.name.includes('hips.position'))
- }
-
- animation_clip.tracks = rotation_tracks // update track data
- // console.log(animation_clip.tracks) // UNUSED DEBUG CODE
- })
- }
-
private apply_hip_bone_offset (animation_clips: AnimationClip[]): void {
// update the position keyframes for the hips bone
// this will be used for animations like falling
diff --git a/src/preview-generator/preview-generator.ts b/src/preview-generator/preview-generator.ts
index 393147f..cde9cae 100644
--- a/src/preview-generator/preview-generator.ts
+++ b/src/preview-generator/preview-generator.ts
@@ -6,6 +6,7 @@ import { WebMRecorder } from './webm-recorder.ts'
import { saveAs } from 'file-saver'
import JSZip from 'jszip'
+import { Utility } from '../lib/Utilities.ts'
import { Generators } from '../lib/Generators.ts'
import { ThemeManager } from '../lib/ThemeManager.ts'
@@ -37,7 +38,6 @@ class PreviewGenerator {
this.renderer_.toneMapping = THREE.ACESFilmicToneMapping // a bit softer of a look
this.renderer_.toneMappingExposure = 2.0 // tweak this value for brightness
-
document.body.appendChild(this.renderer_.domElement)
this.theme_manager = new ThemeManager()
@@ -50,8 +50,6 @@ class PreviewGenerator {
this.regenerate_floor_grid()
- console.log(this.scene_)
-
// Add orbit controls
this.controls_ = new OrbitControls(this.camera_, this.renderer_.domElement)
this.controls_.target.set(0, 0.4, 0)
@@ -107,7 +105,12 @@ class PreviewGenerator {
this.mixer_ = new THREE.AnimationMixer(this.new_skinned_mesh)
this.animation_clips = gltf.animations
- const clip = this.animation_clips[1]
+
+ // remove all root motion data. This is the same function that the animation listing
+ // does
+ Utility.clean_track_data(this.animation_clips)
+
+ const clip = this.animation_clips[0]
const action = this.mixer_.clipAction(clip)
action.reset()
action.play()
@@ -180,7 +183,7 @@ class PreviewGenerator {
this.current_animation_index_processing += 1
// for testing a few, change to something small like 5
- const temp_limit = 16 //this.animation_clips.length
+ const temp_limit = this.animation_clips.length
if (this.current_animation_index_processing < temp_limit) {
await this.process_animation_clip()