Skip to content

Commit

Permalink
Resolve #11
Browse files Browse the repository at this point in the history
There seems to be a situation where a remapMeshBones item is out of bounds. I don't exactly know why because I don't understand the file format, but throwing an error is better than panicking.
  • Loading branch information
xypwn committed Nov 6, 2024
1 parent a3a11fa commit 5782ab0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions extractor/unit/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,19 @@ func loadBoneMap(ctx extractor.Context) (*bones.BoneInfo, error) {
return boneInfo, err
}

func remapMeshBones(mesh *unit.Mesh, mapping unit.SkeletonMap) {
func remapMeshBones(mesh *unit.Mesh, mapping unit.SkeletonMap) error {
for i := range mesh.BoneIndices {
for j := range mesh.BoneIndices[i] {
if int(mesh.BoneIndices[i][j]) >= len(mapping.RemapList[0]) {
return fmt.Errorf("remapMeshBones: remap list item out of bounds")
}
if mesh.BoneWeights[i][j] > 0 {
remapIndex := mapping.RemapList[0][mesh.BoneIndices[i][j]]
mesh.BoneIndices[i][j] = uint8(mapping.BoneIndices[remapIndex])
}
}
}
return nil
}

// Adds the unit's skeleton to the gltf document
Expand Down Expand Up @@ -450,7 +454,9 @@ func ConvertOpts(ctx extractor.Context, imgOpts *ImageOptions) error {

if bonesEnabled {
if len(unitInfo.SkeletonMaps) > 0 {
remapMeshBones(&mesh, unitInfo.SkeletonMaps[0])
if err := remapMeshBones(&mesh, unitInfo.SkeletonMaps[0]); err != nil {
return err
}
}
skin = gltf.Index(addSkeleton(doc, unitInfo, boneInfo))
weights = modeler.WriteWeights(doc, mesh.BoneWeights)
Expand Down

0 comments on commit 5782ab0

Please sign in to comment.