Import a 3D Model and automatically assign and export animations
TypeScript
try to use absolute paths for loading mirror icons to help retarget page load them. FIx exporting out mirrored animations on retargeted page
Scott Petrovic43b2f0b3ac64
diff --git a/src/lib/processes/animations-listing/AnimationSearch.ts b/src/lib/processes/animations-listing/AnimationSearch.tsindex 5da59ca..b868011 100644--- a/src/lib/processes/animations-listing/AnimationSearch.ts+++ b/src/lib/processes/animations-listing/AnimationSearch.ts@@ -20,9 +20,9 @@ export class AnimationSearch extends EventTarget {private static readonly mirror_mode_cycle: AnimationMirrorExportMode[] = ['none', 'mirrored', 'both']private static readonly mirror_mode_icons: Record<AnimationMirrorExportMode, string> = {- none: 'images/icons/mirror.svg',- mirrored: 'images/icons/mirror.svg',- both: 'images/icons/mirror-both.svg'+ none: '/images/icons/mirror.svg',+ mirrored: '/images/icons/mirror.svg',+ both: '/images/icons/mirror-both.svg'}constructor (filter_input_id: string, animation_list_container_id: string, theme_manager: ThemeManager, skeleton_type: SkeletonType) {diff --git a/src/lib/processes/animations-listing/AnimationUtility.ts b/src/lib/processes/animations-listing/AnimationUtility.tsindex bc82dba..2a292ed 100644--- a/src/lib/processes/animations-listing/AnimationUtility.ts+++ b/src/lib/processes/animations-listing/AnimationUtility.ts@@ -33,6 +33,21 @@ export class AnimationUtility {})}+ static create_mirrored_clip (source_clip: AnimationClip): AnimationClip {+ const mirrored_clip = AnimationUtility.deep_clone_animation_clip(source_clip)+ mirrored_clip.name = `${mirrored_clip.name}_mirror`++ AnimationUtility.apply_animation_mirroring([+ {+ original_animation_clip: AnimationUtility.deep_clone_animation_clip(mirrored_clip),+ display_animation_clip: mirrored_clip,+ metadata: { source_type: 'default-library', tags: [] }+ }+ ])++ return mirrored_clip+ }+/// 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.diff --git a/src/lib/processes/export-to-file/StepExportToFile.ts b/src/lib/processes/export-to-file/StepExportToFile.tsindex 0e26955..a9a0b4d 100644--- a/src/lib/processes/export-to-file/StepExportToFile.ts+++ b/src/lib/processes/export-to-file/StepExportToFile.ts@@ -25,34 +25,16 @@ export class StepExportToFile extends EventTarget {}if (selection.mirror_export_mode === 'mirrored') {- this.animation_clips_to_export.push(this.create_mirrored_clip(source_clip))+ this.animation_clips_to_export.push(AnimationUtility.create_mirrored_clip(source_clip))return}// Export both normal and mirrored variants.this.animation_clips_to_export.push(source_clip.clone())- this.animation_clips_to_export.push(this.create_mirrored_clip(source_clip))+ this.animation_clips_to_export.push(AnimationUtility.create_mirrored_clip(source_clip))})}- private create_mirrored_clip (source_clip: AnimationClip): AnimationClip {- const mirrored_clip = AnimationUtility.deep_clone_animation_clip(source_clip)- mirrored_clip.name = `${mirrored_clip.name}_mirror`-- AnimationUtility.apply_animation_mirroring([- {- original_animation_clip: AnimationUtility.deep_clone_animation_clip(mirrored_clip),- display_animation_clip: mirrored_clip,- metadata: {- source_type: 'default-library',- tags: []- }- }- ])-- return mirrored_clip- }-public export (skinned_meshes: SkinnedMesh[],filename: string = 'exported_model',diff --git a/src/retarget/RetargetAnimationListing.ts b/src/retarget/RetargetAnimationListing.tsindex f859ccd..b235902 100644--- a/src/retarget/RetargetAnimationListing.ts+++ b/src/retarget/RetargetAnimationListing.ts@@ -116,6 +116,7 @@ export class RetargetAnimationListing extends EventTarget {// if there are no animations selected disable the download buttonconst animations_selected_count: number = this.animation_search?.get_selected_animation_indices().length ?? 0+ const export_count: number = this.animation_search?.get_selected_export_animation_count() ?? 0if (this.export_button !== null) {this.export_button.disabled = animations_selected_count === 0@@ -124,7 +125,7 @@ export class RetargetAnimationListing extends EventTarget {// update the count inside the export/download buttonconst count_element = document.getElementById('animation-selection-count')if (count_element !== null) {- count_element.textContent = animations_selected_count.toString()+ count_element.textContent = export_count.toString()}}@@ -228,7 +229,7 @@ export class RetargetAnimationListing extends EventTarget {// send in all the selected animation clips for exportthis.step_export_retargeted_animations.set_animation_clips_to_export(this.animation_clips_loaded.map(clip => clip.display_animation_clip),- this.get_selected_animation_indices()+ this.animation_search?.get_selected_animation_export_selections() ?? [])// configure the export out step with retargeting info@@ -258,8 +259,9 @@ export class RetargetAnimationListing extends EventTarget {this.export_button.disabled = !is_any_checkbox_checked}// Update the count- if (this.animation_count_element != null) {- this.animation_count_element.textContent = this.get_selected_animation_indices().length.toString()+ const count_element = document.getElementById('animation-selection-count')+ if (count_element != null) {+ count_element.textContent = (this.animation_search?.get_selected_export_animation_count() ?? 0).toString()}})}diff --git a/src/retarget/steps/StepExportRetargetedAnimations.ts b/src/retarget/steps/StepExportRetargetedAnimations.tsindex 3f75877..277ed0e 100644--- a/src/retarget/steps/StepExportRetargetedAnimations.ts+++ b/src/retarget/steps/StepExportRetargetedAnimations.ts@@ -1,16 +1,33 @@import { type Scene, type AnimationClip } from 'three'import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter'import { AnimationRetargetService } from '../AnimationRetargetService'+import { AnimationUtility } from '../../lib/processes/animations-listing/AnimationUtility'+import { type AnimationExportSelection } from '../../lib/processes/animations-listing/interfaces/AnimationExportSelection'export class StepExportRetargetedAnimations extends EventTarget {public animation_clips_to_export: AnimationClip[] = []- public set_animation_clips_to_export (all_animations_clips: AnimationClip[], animation_checkboxes: number[]): void {+ public set_animation_clips_to_export (all_animations_clips: AnimationClip[], export_selections: AnimationExportSelection[]): void {this.animation_clips_to_export = []- animation_checkboxes.forEach((indx) => {- const original_clip: AnimationClip = all_animations_clips[indx]- const cloned_clip: AnimationClip = original_clip.clone()- this.animation_clips_to_export.push(cloned_clip)+ export_selections.forEach((selection) => {+ const source_clip: AnimationClip | undefined = all_animations_clips[selection.animation_index]+ if (source_clip === undefined) {+ return+ }++ if (selection.mirror_export_mode === 'none') {+ this.animation_clips_to_export.push(source_clip.clone())+ return+ }++ if (selection.mirror_export_mode === 'mirrored') {+ this.animation_clips_to_export.push(AnimationUtility.create_mirrored_clip(source_clip))+ return+ }++ // Export both normal and mirrored variants.+ this.animation_clips_to_export.push(source_clip.clone())+ this.animation_clips_to_export.push(AnimationUtility.create_mirrored_clip(source_clip))})}