Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

store target mapping type to retargeting service

Scott Petrovic77d0e91f0684
diff --git a/src/retarget/AnimationRetargetService.ts b/src/retarget/AnimationRetargetService.ts
index b4abe91..eab9fb5 100644
--- a/src/retarget/AnimationRetargetService.ts
+++ b/src/retarget/AnimationRetargetService.ts
@@ -23,7 +23,6 @@ export class AnimationRetargetService {
* Get/set for the skeleton type. This will be the source of truth
* for other classes to grab this data
*/
- private skeleton_type: SkeletonType = SkeletonType.None
private source_armature: Group | null = null
public set_source_armature (armature: Group | null): void {
this.source_armature = armature
@@ -33,6 +32,7 @@ export class AnimationRetargetService {
return this.source_armature
}
+ private skeleton_type: SkeletonType = SkeletonType.None
public set_skeleton_type (type: SkeletonType): void {
this.skeleton_type = type
}
@@ -62,10 +62,19 @@ export class AnimationRetargetService {
* @returns A new animation clip retargeted for the target skeleton
*/
+ private target_mapping_type: TargetBoneMappingType = TargetBoneMappingType.None
+
+ public set_target_mapping_type (type: TargetBoneMappingType): void {
+ this.target_mapping_type = type
+ }
+
+ public get_target_mapping_type (): TargetBoneMappingType {
+ return this.target_mapping_type
+ }
+
public retarget_animation_clip (
source_clip: AnimationClip,
bone_mappings: Map<string, string>,
- target_mapping_type: TargetBoneMappingType,
target_skeleton_data: Scene | null = null,
target_skinned_meshes: SkinnedMesh[] = []
): AnimationClip {
@@ -107,7 +116,7 @@ export class AnimationRetargetService {
const retargeted_clip = new AnimationClip(`${source_clip.name}`, source_clip.duration, new_tracks)
// Apply Mixamo-specific corrections if needed
- if (target_mapping_type === TargetBoneMappingType.Mixamo) {
+ if (this.target_mapping_type === TargetBoneMappingType.Mixamo) {
this.apply_bone_rotation_correction(
retargeted_clip,
bone_mappings,
diff --git a/src/retarget/RetargetAnimationPreview.ts b/src/retarget/RetargetAnimationPreview.ts
index 1480d9d..abd725b 100644
--- a/src/retarget/RetargetAnimationPreview.ts
+++ b/src/retarget/RetargetAnimationPreview.ts
@@ -185,7 +185,6 @@ export class RetargetAnimationPreview extends EventTarget {
this.retargeted_animation_clip = AnimationRetargetService.getInstance().retarget_animation_clip(
this.current_animation_clip,
bone_mappings,
- this.step_bone_mapping.get_target_mapping_template(),
this.step_bone_mapping.get_target_skeleton_data(),
this.target_skinned_meshes
)
diff --git a/src/retarget/steps/StepExportRetargetedAnimations.ts b/src/retarget/steps/StepExportRetargetedAnimations.ts
index 2e4b176..95d042e 100644
--- a/src/retarget/steps/StepExportRetargetedAnimations.ts
+++ b/src/retarget/steps/StepExportRetargetedAnimations.ts
@@ -8,15 +8,14 @@ export class StepExportRetargetedAnimations extends EventTarget {
// Retargeting-related properties
private bone_mapping = new Map<string, string>()
- private target_mapping_type: TargetBoneMappingType = TargetBoneMappingType.None
+ // target_mapping_type is now managed by AnimationRetargetService singleton
private target_skeleton_data: Scene | null = null
private target_skinned_meshes: SkinnedMesh[] = []
private target_rig_scene: Scene | null = null
public setup_retargeting (target_rig_scene: Scene, meshes: SkinnedMesh[], bone_mapping: Map<string, string>,
- mapping_type: TargetBoneMappingType, skeleton_data: Scene | null): void {
+ skeleton_data: Scene | null): void {
this.bone_mapping = bone_mapping
- this.target_mapping_type = mapping_type
this.target_skeleton_data = skeleton_data
this.target_skinned_meshes = meshes
this.target_rig_scene = target_rig_scene
@@ -48,7 +47,6 @@ export class StepExportRetargetedAnimations extends EventTarget {
AnimationRetargetService.getInstance().retarget_animation_clip(
clip,
this.bone_mapping,
- this.target_mapping_type,
this.target_skeleton_data,
this.target_skinned_meshes // use the meshes being exported as the target
)