Skip to content

Commit

Permalink
Merge pull request #1549 from pixiv/collider-not-found
Browse files Browse the repository at this point in the history
change: Handle SpringBone collider out of index error
  • Loading branch information
0b5vr authored Dec 18, 2024
2 parents 75cb499 + 9873183 commit d21d2b4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/three-vrm-springbone/src/VRMSpringBoneLoaderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ export class VRMSpringBoneLoaderPlugin implements GLTFLoaderPlugin {

const colliders = extension.colliders?.map((schemaCollider, iCollider) => {
const node = threeNodes[schemaCollider.node!];

// Some models put `-1` to the node index of colliders
if (node == null) {
console.warn(
`VRMSpringBoneLoaderPlugin: The collider #${iCollider} attempted to use the node #${schemaCollider.node} but not found`,
);
return null;
}

const schemaShape = schemaCollider.shape!;

// TODO: separate into several functions
Expand Down Expand Up @@ -176,13 +185,14 @@ export class VRMSpringBoneLoaderPlugin implements GLTFLoaderPlugin {

const colliderGroups = extension.colliderGroups?.map(
(schemaColliderGroup, iColliderGroup): VRMSpringBoneColliderGroup => {
const cols = (schemaColliderGroup.colliders ?? []).map((iCollider) => {
const cols = (schemaColliderGroup.colliders ?? []).flatMap((iCollider) => {
const col = colliders?.[iCollider];

if (col == null) {
throw new Error(
console.warn(
`VRMSpringBoneLoaderPlugin: The colliderGroup #${iColliderGroup} attempted to use a collider #${iCollider} but not found`,
);
return [];
}

return col;
Expand Down

0 comments on commit d21d2b4

Please sign in to comment.