Import a 3D Model and automatically assign and export animations
TypeScript
fix scaling bug with custom rigs
Scott Petrovice03a1003192d
diff --git a/src/retarget/AnimationRetargetService.ts b/src/retarget/AnimationRetargetService.tsindex 3c87e59..781e6c8 100644--- a/src/retarget/AnimationRetargetService.ts+++ b/src/retarget/AnimationRetargetService.ts@@ -94,6 +94,30 @@ export class AnimationRetargetService {: []}+ /**+ * Put the target back in its rest pose from the load-time snapshot.+ *+ * Do not use RetargetUtils.reset_skinned_mesh_to_rest_pose here. Large models are scaled down+ * after load (StepLoadTargetModel), and that function rebuilds bone locals from boneInverses+ * (pre-scale bind space) divided by the current, scaled-down parent world. The bones absorb the+ * inverse of the import scale and the model renders at its original huge size.+ * Fixed in b0b0701, regressed in b151ba2 when props called it on Continue.+ */+ public reset_target_to_rest_pose (): void {+ if (this.target_skinned_meshes.length === 0) return++ const bones = this.target_skinned_meshes[0].skeleton.bones+ if (bones.length !== this.target_rest_transforms.length) return++ bones.forEach((bone, index) => {+ const rest = this.target_rest_transforms[index]+ bone.position.copy(rest.position)+ bone.quaternion.copy(rest.quaternion)+ bone.scale.copy(rest.scale)+ })+ this.target_armature.updateMatrixWorld(true)+ }+public get_target_skinned_meshes (): SkinnedMesh[] {return this.target_skinned_meshes}diff --git a/src/retarget/RetargetAnimationListing.ts b/src/retarget/RetargetAnimationListing.tsindex 2256dcc..21cbfa5 100644--- a/src/retarget/RetargetAnimationListing.ts+++ b/src/retarget/RetargetAnimationListing.ts@@ -19,7 +19,6 @@ import { ModalDialog } from '../lib/ModalDialog.ts'import { type PropsManager } from '../lib/processes/animations-listing/props/PropsManager.ts'import { HandBoneResolver } from '../lib/processes/animations-listing/props/HandBoneResolver.ts'import { type PropSide } from '../lib/processes/animations-listing/props/PropSide.ts'-import { RetargetUtils } from './RetargetUtils.ts'/*** RetargetAnimationListing - Handles animation listing and playback specifically for retargeting workflow@@ -98,7 +97,7 @@ export class RetargetAnimationListing extends EventTarget {const retarget_service = AnimationRetargetService.getInstance()// the live preview leaves the target mid-animation, and grip frames are captured from the current pose- RetargetUtils.reset_skinned_mesh_to_rest_pose(retarget_service.get_target_armature())+ retarget_service.reset_target_to_rest_pose()this.props_manager.begin(retarget_service.get_skeleton_type(), this.target_to_source_height_ratio())this.props_manager.attach_to_skinned_meshes(diff --git a/src/retarget/RetargetAnimationPreview.ts b/src/retarget/RetargetAnimationPreview.tsindex 0ed0c3d..a380aa4 100644--- a/src/retarget/RetargetAnimationPreview.ts+++ b/src/retarget/RetargetAnimationPreview.ts@@ -1,4 +1,4 @@-import { type AnimationClip, AnimationMixer, Object3D, type Scene, type SkinnedMesh, type AnimationAction } from 'three'+import { type AnimationClip, AnimationMixer, Object3D, type SkinnedMesh, type AnimationAction } from 'three'import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js'import { AnimationUtility } from '../lib/processes/animations-listing/AnimationUtility.ts'@@ -166,10 +166,7 @@ export class RetargetAnimationPreview extends EventTarget {// with no mappings there is nothing to retarget, so show the rest pose instead of the source clipif (!this.has_something_to_retarget()) {this.retargeted_animation_clip = null- const target_armature: Scene | null = AnimationRetargetService.getInstance().get_target_armature()- if (target_armature !== null) {- RetargetUtils.reset_skinned_mesh_to_rest_pose(target_armature)- }+ AnimationRetargetService.getInstance().reset_target_to_rest_pose()return}diff --git a/src/retarget/RetargetUtils.ts b/src/retarget/RetargetUtils.tsindex 7f917ef..6536406 100644--- a/src/retarget/RetargetUtils.ts+++ b/src/retarget/RetargetUtils.ts@@ -46,6 +46,10 @@ export class RetargetUtils {* armature node's own transform, so the armature scale/rotation gets applied a* second time on the next updateMatrixWorld (e.g. an armature with scale 0.01* makes the model render at 1/100th the size the bounding box reports).+ *+ * Only safe right after load, before StepLoadTargetModel applies its import scale. After+ * that, the bones absorb the inverse of that scale and the model blows up. Use+ * AnimationRetargetService.reset_target_to_rest_pose for the retarget target instead.*/static reset_skinned_mesh_to_rest_pose (skinned_meshes_group: Object3D): void {// ensure non-bone parent (armature) world matrices are current