-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdldata.go
143 lines (103 loc) · 3.15 KB
/
mdldata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package mdl
import (
"unsafe"
"github.com/takaya030/gomdl/studio"
)
// unpacked mdl data
type MdlData struct {
BaseBuf *byte
BaseBufSl []byte
Hdr *studio.Hdr
Bones *byte
BoneControllers *byte
BBoxes *byte
SeqDescs *byte
SeqGroups *byte
BodyParts *byte
Attachments *byte
Textures *byte
SkinRefs *byte
}
func NewMdlData(buf []byte) *MdlData {
md := new(MdlData)
// base buffer
md.BaseBuf = (*byte)(unsafe.Pointer(&buf[0]))
md.BaseBufSl = buf
// read hdr
h := studio.NewHdr(buf)
md.Hdr = h
// read bones
md.Bones = h.GetBonesPtr(buf)
// read bonecontrollers
md.BoneControllers = h.GetBoneControllersPtr(buf)
// read bboxes
md.BBoxes = h.GetHitBoxesPtr(buf)
// read seqdesc
md.SeqDescs = h.GetSeqsPtr(buf)
// read seqgroups
md.SeqGroups = h.GetSeqGroupsPtr(buf)
// read bodyparts
md.BodyParts = h.GetBodyPartsPtr(buf)
// read attachments
md.Attachments = h.GetAttachmentsPtr(buf)
// read textures
md.Textures = h.GetTexturesPtr(buf)
// read skinrefs
md.SkinRefs = h.GetSkinRefPtr(buf)
return md
}
func (md *MdlData) GetBone(idx int) *studio.Bone {
pbn := (*studio.Bone)(unsafe.Add(unsafe.Pointer(md.Bones), int(unsafe.Sizeof(studio.Bone{}))*idx))
return pbn
}
func (md *MdlData) GetBoneController(idx int) *studio.BoneController {
pbc := (*studio.BoneController)(unsafe.Add(unsafe.Pointer(md.BoneControllers), int(unsafe.Sizeof(studio.BoneController{}))*idx))
return pbc
}
func (md *MdlData) GetBBox(idx int) *studio.BBox {
pbb := (*studio.BBox)(unsafe.Add(unsafe.Pointer(md.BBoxes), int(unsafe.Sizeof(studio.BBox{}))*idx))
return pbb
}
func (md *MdlData) GetSeqDesc(idx int) *studio.SeqDesc {
psq := (*studio.SeqDesc)(unsafe.Add(unsafe.Pointer(md.SeqDescs), int(unsafe.Sizeof(studio.SeqDesc{}))*idx))
return psq
}
func (md *MdlData) GetSeqGroup(idx int) *studio.SeqGroup {
psg := (*studio.SeqGroup)(unsafe.Add(unsafe.Pointer(md.SeqGroups), int(unsafe.Sizeof(studio.SeqGroup{}))*idx))
return psg
}
func (md *MdlData) GetBodyPart(idx int) *studio.BodyPart {
pbp := (*studio.BodyPart)(unsafe.Add(unsafe.Pointer(md.BodyParts), int(unsafe.Sizeof(studio.BodyPart{}))*idx))
return pbp
}
func (md *MdlData) GetAttachment(idx int) *studio.Attachment {
pat := (*studio.Attachment)(unsafe.Add(unsafe.Pointer(md.Attachments), int(unsafe.Sizeof(studio.Attachment{}))*idx))
return pat
}
func (md *MdlData) GetTexture(idx int) *studio.Texture {
ptx := (*studio.Texture)(unsafe.Add(unsafe.Pointer(md.Textures), int(unsafe.Sizeof(studio.Texture{}))*idx))
return ptx
}
func (md *MdlData) GetSkinRef(idx int) *int16 {
var a int16
psr := (*int16)(unsafe.Add(unsafe.Pointer(md.SkinRefs), int(unsafe.Sizeof(a))*idx))
return psr
}
func (md *MdlData) GetNumSeq() int32 {
return md.Hdr.NumSeq
}
func (md *MdlData) GetNumBoneControllers() int32 {
return md.Hdr.NumBoneControllers
}
func (md *MdlData) GetNumBodyParts() int32 {
return md.Hdr.NumBodyParts
}
func (md *MdlData) GetNumBones() int32 {
return md.Hdr.NumBones
}
func (md *MdlData) GetTextureIndex() int32 {
return md.Hdr.TextureIndex
}
func (md *MdlData) GetNumTextures() int32 {
return md.Hdr.NumTextures
}