Import a 3D Model and automatically assign and export animations
TypeScript
Only applyChain to bones that have bone mappings
Scott Petrovica6dfcfbd8ae1
diff --git a/src/retarget/human-retargeting/Retargeter.ts b/src/retarget/human-retargeting/Retargeter.tsindex 140a0eb..5322e1d 100644--- a/src/retarget/human-retargeting/Retargeter.ts+++ b/src/retarget/human-retargeting/Retargeter.ts@@ -38,28 +38,23 @@ export class Retargeter {// Run Animationthis.mixer.update(delta_time)- // Compute vectors from animation source- this.applyScaledTranslation('pelvis') // apply position scaling for hips- this.applyChain('pelvis')- this.applyEndInterp('spine')- this.applyChain('head')-- this.applyChain('armL')- this.applyChain('armR')- this.applyChain('legL')- this.applyChain('legR')-- // fingers- this.applyChain('fingersThumbL')- this.applyChain('fingersThumbR')- this.applyChain('fingersIndexL')- this.applyChain('fingersIndexR')- this.applyChain('fingersMiddleL')- this.applyChain('fingersMiddleR')- this.applyChain('fingersRingL')- this.applyChain('fingersRingR')- this.applyChain('fingersPinkyL')- this.applyChain('fingersPinkyR')+ // get a list of all the chains that exist. This list is generated+ // from the config file when the Rig is built.+ for (const chain_name of Object.keys(this.srcRig.chains)) {+ // special chain that also has root motion+ if (chain_name === 'pelvis') {+ // Compute vectors from animation source+ this.applyScaledTranslation(chain_name) // apply position scaling for hips+ }++ // spine gets more fancy algorithm with using interpolation between first and+ // last bones in chain+ if (chain_name === 'spine' && this.is_full_chain('spine')) {+ this.applyEndInterp('spine')+ } else {+ this.applyChain(chain_name)+ }+ }// Run Additives if any existfor (const i of this.additives) {@@ -450,4 +445,19 @@ export class Retargeter {return target_rot}// #endregion++ /**+ * Determines if a given chain has values in every slot. This will mess up the+ * interpolation calculations if trying applyEndInterp(). Use more simple applyChain() instead.+ * @param chain_name string key for chain+ * @returns boolean+ */+ private is_full_chain (chain_name: string): boolean {+ const chain = this.tarRig.chains[chain_name]+ if (chain.length === 0) {+ return false+ }++ return chain.every((item) => item.idx !== -1)+ }}diff --git a/src/retarget/human-retargeting/Rig.ts b/src/retarget/human-retargeting/Rig.tsindex ade29a2..dc20a77 100644--- a/src/retarget/human-retargeting/Rig.ts+++ b/src/retarget/human-retargeting/Rig.ts@@ -35,6 +35,12 @@ export class Rig {continue}+ // if all values in chain is empty, no point in building the rig item+ const all_values_empty = chain_names.every(name => name === '')+ if (all_values_empty) {+ continue+ }+switch (k) {case 'pelvis' :this.buildItem(k, chain_names, new Vec3(0, 0, 1), new Vec3(0, 1, 0))@@ -106,7 +112,8 @@ export class Rig {for (const n of names) {j = this.tpose.getJoint(n)if (j === null) {- console.log('Error - Rig.buildLimb : Joint name not found in tpose, ', n)+ // some bones won't be mapped, so they will just be empty placeholders+ // console.log('Error - Rig.buildLimb : Joint name not found in tpose, ', n)continue}