Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Centralize retargeting animation logic to its own service.

Scott Petrovic723a63bedb0e
diff --git a/src/retarget/AnimationRetargetService.ts b/src/retarget/AnimationRetargetService.ts
new file mode 100644
index 0000000..e188d3e
--- /dev/null
+++ b/src/retarget/AnimationRetargetService.ts
@@ -0,0 +1,282 @@
+import { AnimationClip, Euler, type Object3D, Quaternion, QuaternionKeyframeTrack, Vector3, VectorKeyframeTrack, type Scene, type Group, type SkinnedMesh } from 'three'
+import { RetargetUtils } from './RetargetUtils.ts'
+import { TargetBoneMappingType } from './steps/StepBoneMapping.ts'
+
+/**
+ * AnimationRetargetService - Shared service for retargeting animations from one skeleton to another
+ * Used by both RetargetAnimationPreview and RetargetAnimationListing
+ */
+// eslint-disable-next-line @typescript-eslint/no-extraneous-class
+export class AnimationRetargetService {
+ /**
+ * Retarget an animation clip using bone mappings
+ * @param source_clip - The original animation clip from the source skeleton
+ * @param bone_mappings - Map of target bone name -> source bone name
+ * @param target_mapping_type - The type of target skeleton mapping (for applying corrections)
+ * @param source_armature - The source skeleton armature (for bone rotation corrections)
+ * @param target_skeleton_data - The target skeleton data (for bone rotation corrections)
+ * @param target_skinned_meshes - The target skinned meshes (for finding bones)
+ * @returns A new animation clip retargeted for the target skeleton
+ */
+ static retarget_animation_clip (
+ source_clip: AnimationClip,
+ bone_mappings: Map<string, string>,
+ target_mapping_type: TargetBoneMappingType,
+ source_armature: Group | null = null,
+ target_skeleton_data: Scene | null = null,
+ target_skinned_meshes: SkinnedMesh[] = []
+ ): AnimationClip {
+ const new_tracks: any[] = []
+
+ // Create a reverse mapping for easier lookup: source bone name -> target bone names[]
+ const reverse_mappings = new Map<string, string[]>()
+ bone_mappings.forEach((source_bone_name, target_bone_name) => {
+ if (!reverse_mappings.has(source_bone_name)) {
+ reverse_mappings.set(source_bone_name, [])
+ }
+ const target_list = reverse_mappings.get(source_bone_name)
+ if (target_list !== undefined) {
+ target_list.push(target_bone_name)
+ }
+ })
+
+ // Process each track in the source animation
+ source_clip.tracks.forEach((track) => {
+ // Parse the track name to get the bone name and property
+ // Track names are typically in format: "boneName.property" or ".bones[boneName].property"
+ const track_name_parts = this.parse_track_name(track.name)
+ if (track_name_parts === null) {
+ return
+ }
+
+ const { bone_name, property } = track_name_parts
+
+ // Check if this bone is mapped to any target bones
+ const target_bone_names = reverse_mappings.get(bone_name)
+ if (target_bone_names === undefined || target_bone_names.length === 0) {
+ return // Skip unmapped bones
+ }
+
+ // Create a track for each target bone this source bone maps to
+ target_bone_names.forEach((target_bone_name) => {
+ const new_track_name = RetargetUtils.create_track_name(target_bone_name, property)
+
+ // Clone the track with the new name
+ if (property === 'quaternion') {
+ const new_track = new QuaternionKeyframeTrack(
+ new_track_name,
+ track.times.slice(),
+ track.values.slice()
+ )
+ new_tracks.push(new_track)
+ } else if (property === 'position' || property === 'scale') {
+ const new_track = new VectorKeyframeTrack(
+ new_track_name,
+ track.times.slice(),
+ track.values.slice()
+ )
+ new_tracks.push(new_track)
+ }
+ })
+ })
+
+ // Create the retargeted animation clip
+ const retargeted_clip = new AnimationClip(
+ `${source_clip.name}_retargeted`,
+ source_clip.duration,
+ new_tracks
+ )
+
+ // Apply Mixamo-specific corrections if needed
+ if (target_mapping_type === TargetBoneMappingType.Mixamo) {
+ this.apply_bone_rotation_correction(
+ retargeted_clip,
+ bone_mappings,
+ source_armature,
+ target_skeleton_data,
+ target_skinned_meshes
+ )
+ }
+
+ console.log(`Retargeted animation: ${source_clip.name} (${new_tracks.length} tracks)`)
+ return retargeted_clip
+ }
+
+ /**
+ * Apply bone rotation correction for fixing bone roll delta between target and source skeleton
+ */
+ private static apply_bone_rotation_correction (
+ animation_clip: AnimationClip,
+ bone_mappings: Map<string, string>,
+ source_armature: Group | null,
+ target_skeleton_data: Scene | null,
+ target_skinned_meshes: SkinnedMesh[]
+ ): void {
+ bone_mappings.forEach((source_bone_name, target_bone_name) => {
+ const delta = this.calculate_bone_rotation_delta(
+ source_bone_name,
+ target_bone_name,
+ source_armature,
+ target_skeleton_data,
+ target_skinned_meshes
+ )
+
+ if (delta !== null) {
+ const delta_euler = new Euler().setFromQuaternion(delta)
+
+ this.rotate_bone_for_retargeting(animation_clip, [target_bone_name], delta_euler)
+ } else {
+ console.log(`Warning: delta is NULL when fixing bone roll. Skipping correction for bone: ${target_bone_name}`)
+ }
+ })
+
+ console.log('Applied Mixamo-specific corrections to retargeted animation (dynamically calculated)', animation_clip)
+ }
+
+ /**
+ * Calculate the bone roll delta between source and target bones in bind pose
+ * Bone roll is the rotation around the bone's primary axis (Y-axis in Three.js)
+ * @param source_bone_name - Name of the bone in the source skeleton
+ * @param target_bone_name - Name of the bone in the target skeleton
+ * @param source_armature - The source skeleton armature
+ * @param target_skeleton_data - The target skeleton data
+ * @param target_skinned_meshes - The target skinned meshes
+ * @returns The rotation difference as a quaternion (Y-axis only), or null if bones not found
+ */
+ private static calculate_bone_rotation_delta (
+ source_bone_name: string,
+ target_bone_name: string,
+ source_armature: Group | null,
+ target_skeleton_data: Scene | null,
+ target_skinned_meshes: SkinnedMesh[]
+ ): Quaternion | null {
+ if (source_armature === null || target_skeleton_data === null) {
+ console.warn('Cannot calculate rotation delta: missing skeleton data')
+ return null
+ }
+
+ // Find source bone and target bone with normalized matching
+ const source_bone = this.find_bone_by_name(source_armature, [], source_bone_name)
+ const target_bone = this.find_bone_by_name(target_skeleton_data, target_skinned_meshes, target_bone_name)
+
+ if (source_bone === null || target_bone === null) {
+ const source_label = source_bone === null ? 'null' : source_bone.name
+ const target_label = target_bone === null ? 'null' : target_bone.name
+ console.debug(`Cannot calculate rotation delta: bone not found (source: ${source_bone_name}=${source_label}, target: ${target_bone_name}=${target_label})`)
+ return null
+ }
+
+ // Local-space bind pose quaternions
+ const source_quat = new Quaternion().copy(source_bone.quaternion)
+ const target_quat = new Quaternion().copy(target_bone.quaternion)
+
+ // Relative local delta (target -> source)
+ const full_delta_quat = target_quat.clone().invert().multiply(source_quat)
+
+ // Extract only the twist around local Y (bone roll) via swing–twist decomposition
+ const axis_y = new Vector3(0, 1, 0)
+ const v = new Vector3(full_delta_quat.x, full_delta_quat.y, full_delta_quat.z)
+ const proj = axis_y.clone().multiplyScalar(v.dot(axis_y))
+ const twist_y = new Quaternion(proj.x, proj.y, proj.z, full_delta_quat.w).normalize()
+
+ return twist_y
+ }
+
+ /**
+ * Apply rotations to specific bones to correct them and normalize them for Mesh2Motion animations
+ */
+ private static rotate_bone_for_retargeting (
+ animation_clip: AnimationClip,
+ bone_match_pattern: string[],
+ rotate_obj: Euler
+ ): void {
+ // Find all shoulder quaternion tracks (e.g., mixamorigLeftShoulder.quaternion)
+ const tracks_to_change = animation_clip.tracks.filter(track =>
+ bone_match_pattern.some(pattern => track.name.toLowerCase().includes(pattern.toLowerCase())) && track.name.includes('quaternion')
+ ) as Array<{ name: string, times: Float32Array | number[], values: Float32Array | number[] }>
+
+ if (tracks_to_change.length === 0) return
+
+ // Object axis rotation amount. Final value is quaternion
+ const rotation_amount: Quaternion = new Quaternion().setFromEuler(rotate_obj)
+
+ for (const track of tracks_to_change) {
+ const name_info = this.parse_track_name(track.name)
+ if (name_info === null) continue
+
+ const values = track.values
+ for (let i = 0; i < values.length; i += 4) {
+ const original_quat: Quaternion = new Quaternion(
+ values[i], // x
+ values[i + 1], // y
+ values[i + 2], // z
+ values[i + 3] // w
+ )
+
+ // apply local-space correction
+ original_quat.multiply(rotation_amount)
+
+ values[i] = original_quat.x
+ values[i + 1] = original_quat.y
+ values[i + 2] = original_quat.z
+ values[i + 3] = original_quat.w
+ }
+ }
+ }
+
+ /**
+ * Find a bone by name in the skeleton hierarchy
+ */
+ private static find_bone_by_name (
+ root: Object3D,
+ skinned_meshes: SkinnedMesh[],
+ bone_name: string
+ ): Object3D | null {
+ let found_bone: Object3D | null = null
+
+ root.traverse((child) => {
+ if (found_bone !== null) return
+ if (child.name === bone_name) {
+ found_bone = child
+ }
+ })
+
+ if (found_bone !== null) return found_bone
+
+ skinned_meshes.forEach((mesh) => {
+ if (found_bone !== null) return
+ const match = mesh.skeleton?.bones.find((bone) => bone.name === bone_name)
+ if (match !== undefined) {
+ found_bone = match
+ }
+ })
+
+ return found_bone
+ }
+
+ /**
+ * Parse a track name to extract bone name and property
+ * Handles various formats like "boneName.property" or ".bones[boneName].property"
+ */
+ private static parse_track_name (track_name: string): { bone_name: string, property: string } | null {
+ // Try format: "boneName.property"
+ const simple_match = track_name.match(/^([^.]+)\.(.+)$/)
+ if (simple_match !== null) {
+ return {
+ bone_name: simple_match[1],
+ property: simple_match[2]
+ }
+ }
+
+ // Try format: ".bones[boneName].property"
+ const bones_match = track_name.match(/\.bones\[([^\]]+)\]\.(.+)$/)
+ if (bones_match !== null) {
+ return {
+ bone_name: bones_match[1],
+ property: bones_match[2]
+ }
+ }
+
+ return null
+ }
+}
diff --git a/src/retarget/RetargetAnimationListing.ts b/src/retarget/RetargetAnimationListing.ts
index de90d05..0b08676 100644
--- a/src/retarget/RetargetAnimationListing.ts
+++ b/src/retarget/RetargetAnimationListing.ts
@@ -1,10 +1,12 @@
import { AnimationPlayer } from '../lib/processes/animations-listing/AnimationPlayer.ts'
import { AnimationSearch } from '../lib/processes/animations-listing/AnimationSearch.ts'
import { AnimationLoader } from '../lib/processes/animations-listing/AnimationLoader.ts'
-import { type AnimationClip, AnimationMixer, type SkinnedMesh, Object3D, Object3DEventMap, Group } from 'three'
+import { type AnimationClip, AnimationMixer, type SkinnedMesh, Object3D, type Object3DEventMap, type Group } from 'three'
import { SkeletonType } from '../lib/enums/SkeletonType.ts'
-import { ThemeManager } from '../lib/ThemeManager.ts'
+import type { ThemeManager } from '../lib/ThemeManager.ts'
import { type TransformedAnimationClipPair } from '../lib/processes/animations-listing/interfaces/TransformedAnimationClipPair.ts'
+import { AnimationRetargetService } from './AnimationRetargetService.ts'
+import { type StepBoneMapping } from './steps/StepBoneMapping.ts'
/**
* RetargetAnimationListing - Handles animation listing and playback specifically for retargeting workflow
@@ -14,6 +16,7 @@ export class RetargetAnimationListing extends EventTarget {
private readonly theme_manager: ThemeManager
private readonly animation_player: AnimationPlayer
private readonly animation_loader: AnimationLoader = new AnimationLoader()
+ private readonly step_bone_mapping: StepBoneMapping
private animation_clips_loaded: TransformedAnimationClipPair[] = []
private animation_mixer: AnimationMixer = new AnimationMixer(new Object3D())
@@ -24,10 +27,11 @@ export class RetargetAnimationListing extends EventTarget {
public animation_search: AnimationSearch | null = null
- constructor (theme_manager: ThemeManager) {
+ constructor (theme_manager: ThemeManager, step_bone_mapping: StepBoneMapping) {
super()
this.theme_manager = theme_manager
this.animation_player = new AnimationPlayer()
+ this.step_bone_mapping = step_bone_mapping
}
public begin (skeleton_type: SkeletonType): void {
@@ -129,10 +133,10 @@ export class RetargetAnimationListing extends EventTarget {
if (animations_container !== null) {
animations_container.addEventListener('click', (event) => {
const target = event.target as HTMLElement
- const button = target.closest('.play') as HTMLButtonElement
+ const button = target.closest('.play')
if (button !== null) {
- const index = parseInt(button.dataset.index ?? '-1')
+ const index = parseInt((button as HTMLButtonElement).dataset.index ?? '-1')
if (index >= 0) {
this.play_animation(index)
}
@@ -153,18 +157,36 @@ export class RetargetAnimationListing extends EventTarget {
// Stop all current actions
this.animation_mixer.stopAllAction()
- // Create new actions for each skinned mesh
+ // Get bone mappings from the bone mapping step
+ const bone_mappings = this.step_bone_mapping.get_bone_mapping()
+
+ if (bone_mappings.size === 0) {
+ console.warn('No bone mappings available. Cannot play retargeted animation.')
+ return
+ }
+
+ // Retarget the animation using the shared service
+ const retargeted_clip = AnimationRetargetService.retarget_animation_clip(
+ display_clip,
+ bone_mappings,
+ this.step_bone_mapping.get_target_mapping_template(),
+ this.step_bone_mapping.get_source_armature(),
+ this.step_bone_mapping.get_target_skeleton_data(),
+ this.skinned_meshes_to_animate
+ )
+
+ // Create new actions for each skinned mesh with the retargeted animation
const actions = this.skinned_meshes_to_animate.map((mesh) => {
- const action = this.animation_mixer.clipAction(display_clip, mesh)
+ const action = this.animation_mixer.clipAction(retargeted_clip, mesh)
action.reset()
action.play()
return action
})
// Update the animation player UI
- this.animation_player.set_animation(display_clip, actions)
+ this.animation_player.set_animation(retargeted_clip, actions)
- console.log('Playing animation:', display_clip.name)
+ console.log('Playing retargeted animation:', retargeted_clip.name)
}
private add_event_listeners (): void {
diff --git a/src/retarget/RetargetAnimationPreview.ts b/src/retarget/RetargetAnimationPreview.ts
index 37120dc..ab0778a 100644
--- a/src/retarget/RetargetAnimationPreview.ts
+++ b/src/retarget/RetargetAnimationPreview.ts
@@ -1,9 +1,9 @@
-import { AnimationClip, AnimationMixer, Object3D, type Scene, type SkinnedMesh, VectorKeyframeTrack, QuaternionKeyframeTrack, type AnimationAction, Quaternion, Euler, Vector3 } from 'three'
+import { type AnimationClip, AnimationMixer, Object3D, type Scene, type SkinnedMesh, type AnimationAction } from 'three'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { AnimationUtility } from '../lib/processes/animations-listing/AnimationUtility.ts'
import type { StepBoneMapping } from './steps/StepBoneMapping.ts'
-import { TargetBoneMappingType } from './steps/StepBoneMapping.ts'
import { RetargetUtils } from './RetargetUtils.ts'
+import { AnimationRetargetService } from './AnimationRetargetService.ts'
/**
* RetargetAnimationPreview - Provides live preview of bone retargeting by automatically
@@ -164,10 +164,14 @@ export class RetargetAnimationPreview extends EventTarget {
return
}
- // Create retargeted animation clip
- this.retargeted_animation_clip = this.retarget_animation_clip(
+ // Create retargeted animation clip using shared service
+ this.retargeted_animation_clip = AnimationRetargetService.retarget_animation_clip(
this.current_animation_clip,
- bone_mappings
+ bone_mappings,
+ this.step_bone_mapping.get_target_mapping_template(),
+ this.step_bone_mapping.get_source_armature(),
+ this.step_bone_mapping.get_target_skeleton_data(),
+ this.target_skinned_meshes
)
// Apply the retargeted animation to all target skinned meshes
@@ -182,240 +186,6 @@ export class RetargetAnimationPreview extends EventTarget {
console.log('Preview animation updated and playing')
}
- /**
- * Retarget an animation clip using bone mappings
- * @param source_clip - The original animation clip from the source skeleton
- * @param bone_mappings - Map of target bone name -> source bone name
- * @returns A new animation clip retargeted for the target skeleton
- */
- private retarget_animation_clip (source_clip: AnimationClip, bone_mappings: Map<string, string>): AnimationClip {
- const new_tracks: any[] = []
-
- // Create a reverse mapping for easier lookup: source bone name -> target bone names[]
- const reverse_mappings = new Map<string, string[]>()
- bone_mappings.forEach((source_bone_name, target_bone_name) => {
- if (!reverse_mappings.has(source_bone_name)) {
- reverse_mappings.set(source_bone_name, [])
- }
- const target_list = reverse_mappings.get(source_bone_name)
- if (target_list !== undefined) {
- target_list.push(target_bone_name)
- }
- })
-
- // Process each track in the source animation
- source_clip.tracks.forEach((track) => {
- // Parse the track name to get the bone name and property
- // Track names are typically in format: "boneName.property" or ".bones[boneName].property"
- const track_name_parts = this.parse_track_name(track.name)
- if (track_name_parts === null) {
- return
- }
-
- const { bone_name, property } = track_name_parts
-
- // Check if this bone is mapped to any target bones
- const target_bone_names = reverse_mappings.get(bone_name)
- if (target_bone_names === undefined || target_bone_names.length === 0) {
- return // Skip unmapped bones
- }
-
- // Create a track for each target bone this source bone maps to
- target_bone_names.forEach((target_bone_name) => {
- const new_track_name = RetargetUtils.create_track_name(target_bone_name, property)
-
- // Clone the track with the new name
- if (property === 'quaternion') {
- const new_track = new QuaternionKeyframeTrack(
- new_track_name,
- track.times.slice(),
- track.values.slice()
- )
- new_tracks.push(new_track)
- } else if (property === 'position' || property === 'scale') {
- const new_track = new VectorKeyframeTrack(
- new_track_name,
- track.times.slice(),
- track.values.slice()
- )
- new_tracks.push(new_track)
- }
- })
- })
-
- // Create the retargeted animation clip
- const retargeted_clip = new AnimationClip(
- `${source_clip.name}_retargeted`,
- source_clip.duration,
- new_tracks
- )
-
- // Apply Mixamo-specific corrections
- const target_mapping_type = this.step_bone_mapping.get_target_mapping_template()
- if (target_mapping_type === TargetBoneMappingType.Mixamo) {
- this.apply_bone_rotation_correction(retargeted_clip)
- }
-
- console.log(`Retargeted animation: ${source_clip.name} (${new_tracks.length} tracks)`)
- return retargeted_clip
- }
-
- /**
- * Apply rotations to specific bones to correct them and normalize them for Mesh2Motion animations
- */
- private rotate_bone_for_retargeting (
- animation_clip: AnimationClip,
- bone_match_pattern: string[], rotate_obj: Euler): void {
- // Find all shoulder quaternion tracks (e.g., mixamorigLeftShoulder.quaternion)
- const tracks_to_change = animation_clip.tracks.filter(track =>
- bone_match_pattern.some(pattern => track.name.toLowerCase().includes(pattern.toLowerCase())) && track.name.includes('quaternion')
- ) as Array<{ name: string, times: Float32Array | number[], values: Float32Array | number[] }>
-
- if (tracks_to_change.length === 0) return
-
- // Object axis rotation amount. Final value is quaternion
- const rotation_amount: Quaternion = new Quaternion().setFromEuler(rotate_obj)
-
- for (const track of tracks_to_change) {
- const name_info = this.parse_track_name(track.name)
- if (name_info === null) continue
-
- const values = track.values
- for (let i = 0; i < values.length; i += 4) {
- const original_quat: Quaternion = new Quaternion(
- values[i], // x
- values[i + 1], // y
- values[i + 2], // z
- values[i + 3] // w
- )
-
- // apply local-space correction
- original_quat.multiply(rotation_amount)
-
- values[i] = original_quat.x
- values[i + 1] = original_quat.y
- values[i + 2] = original_quat.z
- values[i + 3] = original_quat.w
- }
- }
- }
-
- private find_bone_by_name (root: Object3D, skinned_meshes: SkinnedMesh[], bone_name: string): Object3D | null {
- let found_bone: Object3D | null = null
-
- root.traverse((child) => {
- if (found_bone !== null) return
- if (child.name === bone_name) {
- found_bone = child
- }
- })
-
- if (found_bone !== null) return found_bone
-
- skinned_meshes.forEach((mesh) => {
- if (found_bone !== null) return
- const match = mesh.skeleton?.bones.find((bone) => bone.name === bone_name)
- if (match !== undefined) {
- found_bone = match
- }
- })
-
- return found_bone
- }
-
- /**
- * Calculate the bone roll delta between source and target bones in bind pose
- * Bone roll is the rotation around the bone's primary axis (Y-axis in Three.js)
- * @param source_bone_name - Name of the bone in the source skeleton
- * @param target_bone_name - Name of the bone in the target skeleton
- * @returns The rotation difference as a quaternion (Y-axis only), or null if bones not found
- */
- private calculate_bone_rotation_delta (source_bone_name: string, target_bone_name: string): Quaternion | null {
- // Get both skeleton roots
- const source_armature = this.step_bone_mapping.get_source_armature()
- const target_skeleton_data = this.step_bone_mapping.get_target_skeleton_data()
-
- if (source_armature === null || target_skeleton_data === null) {
- console.warn('Cannot calculate rotation delta: missing skeleton data')
- return null
- }
-
- // Find source bone and target bone with normalized matching
- const source_bone = this.find_bone_by_name(source_armature, [], source_bone_name)
- const target_bone = this.find_bone_by_name(target_skeleton_data, this.target_skinned_meshes, target_bone_name)
-
- if (source_bone === null || target_bone === null) {
- const source_label = source_bone === null ? 'null' : source_bone.name
- const target_label = target_bone === null ? 'null' : target_bone.name
- console.debug(`Cannot calculate rotation delta: bone not found (source: ${source_bone_name}=${source_label}, target: ${target_bone_name}=${target_label})`)
- return null
- }
-
- // Local-space bind pose quaternions
- const source_quat = new Quaternion().copy(source_bone.quaternion)
- const target_quat = new Quaternion().copy(target_bone.quaternion)
-
- // Relative local delta (target -> source)
- const full_delta_quat = target_quat.clone().invert().multiply(source_quat)
-
- // Extract only the twist around local Y (bone roll) via swing–twist decomposition
- const axis_y = new Vector3(0, 1, 0)
- const v = new Vector3(full_delta_quat.x, full_delta_quat.y, full_delta_quat.z)
- const proj = axis_y.clone().multiplyScalar(v.dot(axis_y))
- const twist_y = new Quaternion(proj.x, proj.y, proj.z, full_delta_quat.w).normalize()
-
- return twist_y
- }
-
- /**
- * Apply bone rotation correction for fixing bone roll delta between target and source skeleton
- */
- private apply_bone_rotation_correction (animation_clip: AnimationClip): void {
- const bone_mappings = this.step_bone_mapping.get_bone_mapping()
-
- bone_mappings.forEach((source_bone_name, target_bone_name) => {
- const delta = this.calculate_bone_rotation_delta(source_bone_name, target_bone_name)
-
- if (delta !== null) {
- const delta_euler = new Euler().setFromQuaternion(delta)
-
- this.rotate_bone_for_retargeting(animation_clip, [target_bone_name], delta_euler)
- } else {
- console.log(`Warning: delta is NULL when fixing bone roll. Skipping correction for bone: ${target_bone_name}`)
- }
- })
-
- console.log('Applied Mixamo-specific corrections to retargeted animation (dynamically calculated)', animation_clip)
- }
-
- /**
- * Parse a track name to extract bone name and property
- * Handles various formats like "boneName.property" or ".bones[boneName].property"
- */
- private parse_track_name (track_name: string): { bone_name: string, property: string } | null {
- // Try format: "boneName.property"
- const simple_match = track_name.match(/^([^.]+)\.(.+)$/)
- if (simple_match !== null) {
- return {
- bone_name: simple_match[1],
- property: simple_match[2]
- }
- }
-
- // Try format: ".bones[boneName].property"
- const bones_match = track_name.match(/\.bones\[([^\]]+)\]\.(.+)$/)
- if (bones_match !== null) {
- return {
- bone_name: bones_match[1],
- property: bones_match[2]
- }
- }
-
- return null
- }
-
-
-
/**
* Update animation mixer on each frame
*/
diff --git a/src/retarget/retarget.ts b/src/retarget/retarget.ts
index 5406fc5..cc62203 100644
--- a/src/retarget/retarget.ts
+++ b/src/retarget/retarget.ts
@@ -100,7 +100,10 @@ class RetargetModule {
}
// load the animation listing step
- this.animation_listing_step = new RetargetAnimationListing(this.mesh2motion_engine.get_theme_manager())
+ this.animation_listing_step = new RetargetAnimationListing(
+ this.mesh2motion_engine.get_theme_manager(),
+ this.step_bone_mapping
+ )
this.animation_listing_step.begin(this.step_load_source_skeleton.get_skeleton_type())
this.animation_listing_step.load_and_apply_default_animation_to_skinned_mesh(retargetable_meshes)
}
@@ -129,6 +132,11 @@ class RetargetModule {
// Update animation preview
this.retarget_animation_preview.update(delta_time)
+
+ // Update animation listing if it exists
+ if (this.animation_listing_step !== null) {
+ this.animation_listing_step.frame_change(delta_time)
+ }
}
animate()