Skip to content

Commit

Permalink
fix: Fix combineSkeletons, collectSkinIndexAttrs
Browse files Browse the repository at this point in the history
The continue statement is not working as intended

I also forgot to set the new attribute when we found an already registered skin index attribute

I had to change eslint `@typescript-eslint/naming-convention` rule in order to use `_` for parameter names
  • Loading branch information
0b5vr committed Jan 15, 2025
1 parent 0689d9c commit 771f39b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"format": ["camelCase"]
},
{
"selector": "variable",
"selector": "variableLike",
"format": ["camelCase", "UPPER_CASE"],
"leadingUnderscore": "allow"
},
Expand Down
20 changes: 11 additions & 9 deletions packages/three-vrm/src/VRMUtils/combineSkeletons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function collectSkinIndexAttrs(
>();

for (const mesh of meshes) {
let skinIndexAttr = mesh.geometry.getAttribute('skinIndex');
const skinIndexAttr = mesh.geometry.getAttribute('skinIndex');

// Get or create a map for the skin index attribute
let newSkinIndexBonesMap = skinIndexNewSkinIndexBonesMapMap.get(skinIndexAttr);
Expand All @@ -279,17 +279,19 @@ function collectSkinIndexAttrs(
}

// Check if the bone set is already registered
for (const bones of newSkinIndexBonesMap.values()) {
if (arrayEquals(bones, mesh.skeleton.bones)) {
continue;
}
// If the bone set is already registered, reuse the skin index attribute
let newSkinIndexAttr = Array.from(newSkinIndexBonesMap).find(([_, bones]) =>
arrayEquals(bones, mesh.skeleton.bones),
)?.[0];

// If there is no matching bone set, clone the skin index attribute
if (newSkinIndexAttr == null) {
newSkinIndexAttr = skinIndexAttr.clone();
newSkinIndexBonesMap.set(newSkinIndexAttr, mesh.skeleton.bones);
skinIndexBonesPairSet.add([newSkinIndexAttr, mesh.skeleton.bones]);
}

// There is no matching bone set, so clone the skin index attribute
skinIndexAttr = skinIndexAttr.clone();
mesh.geometry.setAttribute('skinIndex', skinIndexAttr);
newSkinIndexBonesMap.set(skinIndexAttr, mesh.skeleton.bones);
skinIndexBonesPairSet.add([skinIndexAttr, mesh.skeleton.bones]);
}

return skinIndexBonesPairSet;
Expand Down

0 comments on commit 771f39b

Please sign in to comment.