Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

simplify file loading logic by putting entire path to load for animations

Scott Petrovic20be989ced90
diff --git a/src/lib/RigConfig.ts b/src/lib/RigConfig.ts
index 9bd9f37..510404a 100644
--- a/src/lib/RigConfig.ts
+++ b/src/lib/RigConfig.ts
@@ -25,7 +25,7 @@ export class RigConfig {
model_file: 'models/model-human.glb',
rig_file: 'rigs/rig-human.glb',
rig_display_name: 'Human',
- animation_files: ['human-base-animations.glb', 'human-addon-animations.glb'],
+ animation_files: ['../animations/human-base-animations.glb', '../animations/human-addon-animations.glb'],
animation_preview_folder: 'human',
has_hand_options: true,
has_head_weight_correction: true,
@@ -36,7 +36,7 @@ export class RigConfig {
model_file: 'models/model-fox.glb',
rig_file: 'rigs/rig-fox.glb',
rig_display_name: 'Fox',
- animation_files: ['fox-animations.glb'],
+ animation_files: ['../animations/fox-animations.glb'],
animation_preview_folder: 'fox',
has_hand_options: false,
has_head_weight_correction: false,
@@ -47,7 +47,7 @@ export class RigConfig {
model_file: 'models/model-bird.glb',
rig_file: 'rigs/rig-bird.glb',
rig_display_name: 'Bird',
- animation_files: ['bird-animations.glb'],
+ animation_files: ['../animations/bird-animations.glb'],
animation_preview_folder: 'bird',
has_hand_options: false,
has_head_weight_correction: false,
@@ -58,7 +58,7 @@ export class RigConfig {
model_file: 'models/model-dragon.glb',
rig_file: 'rigs/rig-dragon.glb',
rig_display_name: 'Dragon',
- animation_files: ['dragon-animations.glb'],
+ animation_files: ['../animations/dragon-animations.glb'],
animation_preview_folder: 'dragon',
has_hand_options: false,
has_head_weight_correction: false,
@@ -69,7 +69,7 @@ export class RigConfig {
model_file: 'models/model-kaiju.glb',
rig_file: 'rigs/rig-kaiju.glb',
rig_display_name: 'Kaiju',
- animation_files: ['kaiju-animations.glb'],
+ animation_files: ['../animations/kaiju-animations.glb'],
animation_preview_folder: 'kaiju',
has_hand_options: false,
has_head_weight_correction: false,
@@ -95,15 +95,13 @@ export class RigConfig {
/**
* 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[] {
+ static get_animation_file_paths (skeleton_type: SkeletonType): 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}`)
+ return config.animation_files
}
/**
@@ -143,10 +141,9 @@ export class RigConfig {
/** Video Preview HTML generation for Rig selection
* Populate a <select> with one <option> per animation file across all rigs.
- * base_path is prepended to each filename, e.g. '../animations/'.
* A placeholder option is always inserted first.
*/
- static populate_animation_file_select (select: HTMLSelectElement, base_path: string): void {
+ static populate_animation_file_select (select: HTMLSelectElement): void {
// configure the select
select.innerHTML = ''
const placeholder = document.createElement('option')
@@ -160,9 +157,10 @@ export class RigConfig {
for (const rig of this.all) {
for (const file of rig.animation_files) {
const option = document.createElement('option')
- option.value = `${base_path}${file}`
+ option.value = file
// derive a readable label from the filename, e.g. 'human-base-animations.glb' -> 'Human Base Animations'
const label = file
+ .replace(/\.\.\/animations\//i, '')
.replace(/\.glb$/i, '')
.split('-')
.map(w => w.charAt(0).toUpperCase() + w.slice(1))
diff --git a/src/lib/processes/animations-listing/AnimationLoader.ts b/src/lib/processes/animations-listing/AnimationLoader.ts
index 917566c..9816448 100644
--- a/src/lib/processes/animations-listing/AnimationLoader.ts
+++ b/src/lib/processes/animations-listing/AnimationLoader.ts
@@ -49,7 +49,8 @@ export class AnimationLoader extends EventTarget {
skeleton_type: SkeletonType,
skeleton_scale: number = 1.0
): Promise<TransformedAnimationClipPair[]> {
- const file_paths = RigConfig.get_animation_file_paths(skeleton_type, this.animations_file_path)
+ const configured_animation_files = RigConfig.get_animation_file_paths(skeleton_type)
+ const file_paths = configured_animation_files.map(f => `${this.animations_file_path}${f}`)
if (file_paths.length === 0) {
throw new Error(`No animation files found for skeleton type: ${skeleton_type}`)
diff --git a/src/preview-generator/preview-generator.ts b/src/preview-generator/preview-generator.ts
index ea39a0b..da93b5a 100644
--- a/src/preview-generator/preview-generator.ts
+++ b/src/preview-generator/preview-generator.ts
@@ -230,7 +230,7 @@ const app = new PreviewGenerator()
// Populate animation file dropdown from central rig config
const animation_file_dropdown = document.getElementById('animation-file-dropdown') as HTMLSelectElement | null
if (animation_file_dropdown !== null) {
- RigConfig.populate_animation_file_select(animation_file_dropdown, '../animations/')
+ RigConfig.populate_animation_file_select(animation_file_dropdown)
}
// look out for select change