Skip to content

Commit

Permalink
Update unit skeleton map with new structure to resolve errors seen wh…
Browse files Browse the repository at this point in the history
…ile exporting the exosuit and probably other models
  • Loading branch information
ryanjsims committed Jun 8, 2024
1 parent 7e5b004 commit 2996656
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion extractor/unit/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func remapMeshBones(mesh *unit.Mesh, mapping unit.SkeletonMap) {
for i := range mesh.BoneIndices {
for j := range mesh.BoneIndices[i] {
if mesh.BoneWeights[i][j] > 0 {
remapIndex := mapping.RemapData.Indices[mesh.BoneIndices[i][j]]
remapIndex := mapping.RemapList[0][mesh.BoneIndices[i][j]]
mesh.BoneIndices[i][j] = uint8(mapping.BoneIndices[remapIndex])
}
}
Expand Down
56 changes: 30 additions & 26 deletions stingray/unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,16 @@ type LODGroup struct {
}
}

type SkeletonRemap struct {
Unk00 uint32
Unk01 uint32
Count uint32
Indices []uint32
type RemapItem struct {
IndexDataOffset uint32
IndexCount uint32
}

type SkeletonMap struct {
Count uint32
// This appears to always be 16?
Unk00 uint32
Count uint32
Matrices [][4][4]float32
BoneIndices []uint32
RemapData SkeletonRemap
// Maybe inverse bind matrices?
Matrices [][4][4]float32
RemapList [][]uint32
}

type JointTransform struct {
Expand Down Expand Up @@ -214,12 +209,12 @@ type MeshHeader struct {
}

type MeshGroup struct {
Unk00 [4]byte
VertexOffset uint32
NumVertices uint32
IndexOffset uint32
NumIndices uint32
Unk01 [4]byte
GroupIdx uint32
VertexOffset uint32
NumVertices uint32
IndexOffset uint32
NumIndices uint32
RepeatGroupIdx uint32
}

type MeshInfo struct {
Expand Down Expand Up @@ -527,7 +522,8 @@ func LoadInfo(mainR io.ReadSeeker) (*Info, error) {
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].Count); err != nil {
return nil, err
}
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].Unk00); err != nil {
var matricesOffset uint32
if err := binary.Read(mainR, binary.LittleEndian, &matricesOffset); err != nil {
return nil, err
}
var indicesOffset uint32
Expand All @@ -538,6 +534,9 @@ func LoadInfo(mainR io.ReadSeeker) (*Info, error) {
if err := binary.Read(mainR, binary.LittleEndian, &remapOffset); err != nil {
return nil, err
}
if _, err := mainR.Seek(int64(hdr.SkeletonMapListOffset+skeletonMapOffset+matricesOffset), io.SeekStart); err != nil {
return nil, err
}
skeletonMapList[i].Matrices = make([][4][4]float32, skeletonMapList[i].Count)
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].Matrices); err != nil {
return nil, err
Expand All @@ -552,18 +551,23 @@ func LoadInfo(mainR io.ReadSeeker) (*Info, error) {
if _, err := mainR.Seek(int64(hdr.SkeletonMapListOffset+skeletonMapOffset+remapOffset), io.SeekStart); err != nil {
return nil, err
}
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].RemapData.Unk00); err != nil {
return nil, err
}
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].RemapData.Unk01); err != nil {
var remapListCount uint32
if err := binary.Read(mainR, binary.LittleEndian, &remapListCount); err != nil {
return nil, err
}
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].RemapData.Count); err != nil {
var remapListItems []RemapItem = make([]RemapItem, remapListCount)
if err := binary.Read(mainR, binary.LittleEndian, &remapListItems); err != nil {
return nil, err
}
skeletonMapList[i].RemapData.Indices = make([]uint32, skeletonMapList[i].RemapData.Count)
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].RemapData.Indices); err != nil {
return nil, err
skeletonMapList[i].RemapList = make([][]uint32, remapListCount)
for j := range remapListItems {
skeletonMapList[i].RemapList[j] = make([]uint32, remapListItems[j].IndexCount)
if _, err := mainR.Seek(int64(hdr.SkeletonMapListOffset+skeletonMapOffset+remapOffset+remapListItems[j].IndexDataOffset), io.SeekStart); err != nil {
return nil, err
}
if err := binary.Read(mainR, binary.LittleEndian, &skeletonMapList[i].RemapList[j]); err != nil {
return nil, err
}
}
}
}
Expand Down

0 comments on commit 2996656

Please sign in to comment.