Import a 3D Model and automatically assign and export animations
TypeScript
move the rig type calculation out of the clean_track_data to allow retargeting to send custom bone names in
Scott Petrovicf6a528a7be76
diff --git a/src/lib/processes/animations-listing/AnimationLoader.ts b/src/lib/processes/animations-listing/AnimationLoader.tsindex 3c54fb2..9797225 100644--- a/src/lib/processes/animations-listing/AnimationLoader.ts+++ b/src/lib/processes/animations-listing/AnimationLoader.ts@@ -230,11 +230,19 @@ export class AnimationLoader extends EventTarget {skeleton_scale: number,metadata_override: Partial<AnimationClipMetadata> = {}): TransformedAnimationClipPair[] {++ if(this.skeleton_type === null) {+ throw new Error('Skeleton type is not set (process_loaded_animations). Cannot process animations.')+ }+// Deep clone the animations to avoid modifying originalsconst cloned_animations = AnimationUtility.deep_clone_animation_clips(raw_animations)+ const position_tracking_bone_name: string | undefined =+ RigConfig.by_skeleton_type(this.skeleton_type)?.position_tracking_bone_name+// Clean track data (remove position tracks except for specific cases)- AnimationUtility.clean_track_data(cloned_animations, this.skeleton_type)+ AnimationUtility.clean_track_data(cloned_animations, this.skeleton_type, position_tracking_bone_name)// Apply skeleton scaling to position keyframesAnimationUtility.apply_skeleton_scale_to_position_keyframes(cloned_animations, skeleton_scale)diff --git a/src/lib/processes/animations-listing/AnimationUtility.ts b/src/lib/processes/animations-listing/AnimationUtility.tsindex 2a292ed..4320331 100644--- a/src/lib/processes/animations-listing/AnimationUtility.ts+++ b/src/lib/processes/animations-listing/AnimationUtility.ts@@ -51,18 +51,16 @@ export class AnimationUtility {/// 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[], skeleton_type: SkeletonType): void {+ static clean_track_data (animation_clips: AnimationClip[], skeleton_type: SkeletonType,+ position_tracking_bone_name: string | undefined ): void {+animation_clips.forEach((animation_clip: AnimationClip) => {- // remove all position nodes except root- let rotation_tracks: KeyframeTrack[] = []-+// does the animation clip name include "RM". This indicates a root motion clip and we can keep the root position trackconst preserve_root_position: boolean = animation_clip.name.toLowerCase().endsWith('rm')-- // get position tracking bone name for normal movement (probably hips or head in the case of a snake)- const position_tracking_bone_name: string | undefined =- RigConfig.by_skeleton_type(skeleton_type)?.position_tracking_bone_name-++ // 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') ||diff --git a/src/preview-generator/preview-generator.ts b/src/preview-generator/preview-generator.tsindex 6406721..8302ccc 100644--- a/src/preview-generator/preview-generator.ts+++ b/src/preview-generator/preview-generator.ts@@ -12,6 +12,7 @@ import { ThemeManager } from '../lib/ThemeManager.ts'import { AnimationUtility } from '../lib/processes/animations-listing/AnimationUtility.ts'import { DOMUtilities } from '../lib/DOMUtilities.ts'import { SkeletonType } from '../lib/enums/SkeletonType.ts'+import { RigConfig } from '../lib/RigConfig.ts'class PreviewGenerator {private readonly renderer_: THREE.WebGLRenderer@@ -137,7 +138,10 @@ class PreviewGenerator {// TODO: with cleaning up data, the fox sitting has a weird height offset// I would think the cleanup should work with all skeleton typesif (file_to_load.includes('human')) {- AnimationUtility.clean_track_data(this.animation_clips, SkeletonType.Human )+ const position_tracking_bone_name: string | undefined =+ RigConfig.by_skeleton_type(SkeletonType.Human)?.position_tracking_bone_name++ AnimationUtility.clean_track_data(this.animation_clips, SkeletonType.Human, position_tracking_bone_name)}const clip = this.animation_clips[0]diff --git a/src/retarget/RetargetAnimationPreview.ts b/src/retarget/RetargetAnimationPreview.tsindex 08f4188..f46aafd 100644--- a/src/retarget/RetargetAnimationPreview.ts+++ b/src/retarget/RetargetAnimationPreview.ts@@ -122,11 +122,14 @@ export class RetargetAnimationPreview extends EventTarget {if (this.current_animation_clip !== null) {console.log('Loaded animation:', this.current_animation_clip.name)+ const skeleton_type = AnimationRetargetService.getInstance().get_skeleton_type()+ const position_tracking_bone_name: string | undefined =+ RigConfig.by_skeleton_type(skeleton_type)?.position_tracking_bone_name+// Clean up the animation track data before using it// This removes unnecessary position tracks and keeps only rotation dataAnimationUtility.clean_track_data([this.current_animation_clip],- AnimationRetargetService.getInstance().get_skeleton_type()- )+ skeleton_type, position_tracking_bone_name)}this.update_preview_animation()resolve()