Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

get animation file paths from Rig Config for better isolation

Scott Petrovic1e10b494a308
diff --git a/src/lib/RigConfig.ts b/src/lib/RigConfig.ts
index e6df223..037b149 100644
--- a/src/lib/RigConfig.ts
+++ b/src/lib/RigConfig.ts
@@ -108,6 +108,20 @@ export class RigConfig {
return this.by_skeleton_type(skeleton_type)?.rig_file
}
+ /**
+ * Get all configured animation file paths for a skeleton type.
+ * @param skeleton_type The skeleton type to retrieve animation files for
+ * @param base_path Optional base path to prepend (default: '/animations/')
+ * @returns Array of animation file paths, empty array if no files configured
+ */
+ static get_animation_file_paths (skeleton_type: SkeletonType, base_path: string = '/animations/'): string[] {
+ const config = this.by_skeleton_type(skeleton_type)
+ if (config === undefined || config.animation_files.length === 0) return []
+
+ const normalized_base_path = base_path.endsWith('/') ? base_path : `${base_path}/`
+ return config.animation_files.map(animation_file => `${normalized_base_path}${animation_file}`)
+ }
+
/**
* Populate a <select> with one <option> per rig using model display names.
* Existing options are replaced.
diff --git a/src/lib/processes/animations-listing/AnimationLoader.ts b/src/lib/processes/animations-listing/AnimationLoader.ts
index 6cf7236..917566c 100644
--- a/src/lib/processes/animations-listing/AnimationLoader.ts
+++ b/src/lib/processes/animations-listing/AnimationLoader.ts
@@ -1,7 +1,7 @@
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { type AnimationClip } from 'three'
import { AnimationUtility } from './AnimationUtility.ts'
-import { SkeletonType } from '../../enums/SkeletonType.ts'
+import { type SkeletonType } from '../../enums/SkeletonType.ts'
import { RigConfig } from '../../RigConfig.ts'
import { type AnimationClipMetadata, type TransformedAnimationClipPair } from './interfaces/TransformedAnimationClipPair.ts'
import { LoadError, NoAnimationsError } from './AnimationImportErrors.ts'
@@ -49,7 +49,7 @@ export class AnimationLoader extends EventTarget {
skeleton_type: SkeletonType,
skeleton_scale: number = 1.0
): Promise<TransformedAnimationClipPair[]> {
- const file_paths = this.get_animation_file_paths(skeleton_type)
+ const file_paths = RigConfig.get_animation_file_paths(skeleton_type, this.animations_file_path)
if (file_paths.length === 0) {
throw new Error(`No animation files found for skeleton type: ${skeleton_type}`)
@@ -218,19 +218,6 @@ export class AnimationLoader extends EventTarget {
})
}
- /**
- * Gets the file paths for animations based on skeleton type
- */
- private get_animation_file_paths (skeleton_type: SkeletonType): string[] {
- const base_path = this.animations_file_path
- const config = RigConfig.by_skeleton_type(skeleton_type)
- if (config === undefined) {
- console.error('Unknown skeleton type for loading animations:', skeleton_type)
- return []
- }
- return config.animation_files.map(f => `${base_path}${f}`)
- }
-
/**
* Processes raw animation clips from GLTF file
*/
diff --git a/src/retarget/RetargetAnimationPreview.ts b/src/retarget/RetargetAnimationPreview.ts
index 7f4e794..668277b 100644
--- a/src/retarget/RetargetAnimationPreview.ts
+++ b/src/retarget/RetargetAnimationPreview.ts
@@ -4,6 +4,7 @@ import { AnimationUtility } from '../lib/processes/animations-listing/AnimationU
import type { StepBoneMapping } from './steps/StepBoneMapping.ts'
import { RetargetUtils } from './RetargetUtils.ts'
import { AnimationRetargetService } from './AnimationRetargetService.ts'
+import { RigConfig } from '../lib/RigConfig.ts'
/**
* RetargetAnimationPreview - Provides live preview of bone retargeting by automatically
@@ -92,13 +93,15 @@ export class RetargetAnimationPreview extends EventTarget {
private async load_first_animation (): Promise<void> {
// get location of animation file to load that has preview animations
const source_skeleton_type = AnimationRetargetService.getInstance().get_skeleton_type()
- const animation_file_path = RetargetUtils.get_animation_file_path(source_skeleton_type)
+ const animation_file_paths = RigConfig.get_animation_file_paths(source_skeleton_type)
- if (animation_file_path === null) {
+ if (animation_file_paths.length === 0) {
console.log('No animation file found for skeleton type:', source_skeleton_type)
return
}
+ const animation_file_path = animation_file_paths[0]
+
// if we are coming back to this step and already loaded a default animation, skip reloading
// and just do the playing
if (this.current_animation_clip !== null) {
diff --git a/src/retarget/RetargetUtils.ts b/src/retarget/RetargetUtils.ts
index 8009331..132ec83 100644
--- a/src/retarget/RetargetUtils.ts
+++ b/src/retarget/RetargetUtils.ts
@@ -1,7 +1,5 @@
import { type Scene, Group, Skeleton, type SkinnedMesh, type Bone, type Object3D } from 'three'
import { ModalDialog } from '../lib/ModalDialog.ts'
-import { SkeletonType } from '../lib/enums/SkeletonType.ts'
-import { RigConfig } from '../lib/RigConfig.ts'
export interface TrackNameParts {
bone_name: string
@@ -115,15 +113,6 @@ export class RetargetUtils {
return all_bones_match
}
- /**
- * Get the animation file path based on skeleton type
- */
- static get_animation_file_path (skeleton_type: SkeletonType): string | null {
- const config = RigConfig.by_skeleton_type(skeleton_type)
- if (config === undefined || config.animation_files.length === 0) return null
- return `/animations/${config.animation_files[0]}`
- }
-
/**
* Parse a track name to extract bone name and property (e.g., "quaternion", "position", "scale")
* Handles various formats like "boneName.property" or ".bones[boneName].property"