Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

avoid crashing if parent isn't found in retargeting

Scott Petrovicb2ec3acd347f
diff --git a/src/retarget/human-retargeting/Pose.ts b/src/retarget/human-retargeting/Pose.ts
index 13e55bf..6625df3 100644
--- a/src/retarget/human-retargeting/Pose.ts
+++ b/src/retarget/human-retargeting/Pose.ts
@@ -69,18 +69,18 @@ export class Pose {
// Map Name to Index
this.nameIdx.set(j.name, j.index)
+ // Assign joint before parent-child linking so parent lookup never hits undefined
+ this.joints[i] = j
+
// Link up parent-child relationshop
if ((b.parent?.isBone)) {
const name_index: number | undefined = this.nameIdx.get(b.parent.name)
if (name_index !== undefined) {
j.pindex = name_index
+ this.joints[j.pindex].children.push(j.index)
}
-
- this.joints[j.pindex].children.push(j.index)
}
-
- this.joints[i] = j
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~