Import a 3D Model and automatically assign and export animations
TypeScript
Fix the errors for the human retargeter
Scott Petrovicbed5adb2d7ae
diff --git a/src/retarget/bone-automap/MixamoMapper.ts b/src/retarget/bone-automap/MixamoMapper.tsindex 61bd93a..b359b15 100644--- a/src/retarget/bone-automap/MixamoMapper.ts+++ b/src/retarget/bone-automap/MixamoMapper.ts@@ -124,7 +124,7 @@ export class MixamoMapper {static map_mixamo_bones (source_bones: BoneMetadata[], target_bones: BoneMetadata[]): Map<string, string> {const mappings = new Map<string, string>()- console.log('=== MIXAMO DIRECT MAPPING ===')+ // console.log('=== MIXAMO DIRECT MAPPING ===')// For each source bone (Mesh2Motion), find matching target bone (Mixamo)for (const source_bone of source_bones) {@@ -136,7 +136,7 @@ export class MixamoMapper {if (target_bone) {mappings.set(target_bone.name, source_bone.name)- console.log(`Mapped: ${target_bone.name} -> ${source_bone.name}`)+ // console.log(`Mapped: ${target_bone.name} -> ${source_bone.name}`)}}}diff --git a/src/retarget/human-retargeting/Pose.ts b/src/retarget/human-retargeting/Pose.tsindex 3655126..72a69be 100644--- a/src/retarget/human-retargeting/Pose.ts+++ b/src/retarget/human-retargeting/Pose.ts@@ -191,23 +191,19 @@ export class Pose {* @returns world transform of joint*/getWorld (joint_idx: number, out_transform = new Transform()): Transform {- let joint: Joint | null = this.getJoint(joint_idx)-- if (joint === null) {- if (joint_idx === -1) {- out_transform.fromMul(this.rootOffset, this.poseOffset)- } else {- console.error('Pose.getWorld - joint not found', joint_idx)- }-+ // index of -1 indicates root bone for armature+ if (joint_idx === -1) {+ out_transform.fromMul(this.rootOffset, this.poseOffset)return out_transform}- // Work up the heirarchy till the root bone- if (joint.local === undefined) {- console.error('Pose.getWorld - joint.local is undefined', joint)+ let joint: Joint | null = this.getJoint(joint_idx)+ if (joint === null) {+ console.error('Pose.getWorld - joint not found', joint_idx)+ return out_transform // abort early}+ // Work up the heirarchy till the root boneout_transform.copy(joint.local)while (joint.pindex !== -1) {joint = this.joints[joint.pindex]@@ -216,7 +212,7 @@ export class Pose {// Add offsetout_transform.pmul(this.poseOffset)- .pmul(this.rootOffset)+ .pmul(this.rootOffset)return out_transform}diff --git a/src/retarget/human-retargeting/Retargeter.ts b/src/retarget/human-retargeting/Retargeter.tsindex c3b35af..9b1876f 100644--- a/src/retarget/human-retargeting/Retargeter.ts+++ b/src/retarget/human-retargeting/Retargeter.ts@@ -59,7 +59,7 @@ export class Retargeter {// Apply SwingTwist to each joint of a chain, 1 to 1 mappings// k = chain key like 'pelvis', 'armL', etc- applyChain (k: string): void {+ public applyChain (k: string): void {const src: RigItem[] = this.srcRig.chains[k]const tar: RigItem[] = this.tarRig.chains[k]if (src === null || tar === null) {@@ -148,7 +148,7 @@ export class Retargeter {// Interp start & end SwingTwist vectors over a chain// k = chain key like 'spine', etc- applyEndInterp (k: string): void {+ public applyEndInterp (k: string): void {if (this.srcRig === null || this.tarRig === null || this.pose === null) {console.warn('Retargeter: Missing srcRig, tarRig, or pose.')return@@ -207,7 +207,9 @@ export class Retargeter {}// Compute offset translation & scale it to fit better on target- applyScaledTranslation (k: string): void {+ // this will correspond to the hip/root movement that drives root motion+ // this will only be applied to one chain, usually the 'pelvis' chain+ public applyScaledTranslation (k: string): void {// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// get chain root itemsconst src: RigItem = this.srcRig.chains[k][0]