-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.go
209 lines (178 loc) · 3.82 KB
/
data.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package spine
type SkeletonData struct {
Name string
Images string
Size Vector
Bones []*BoneData
Slots []*SlotData
Skins []*Skin
DefaultSkin *Skin
Events []*EventData
Animations []*Animation
// IKConstraints []*IKConstraintData
TransformConstraints []*TransformConstraintData
// PathConstraints []*PathConstraintData
}
func (skel *SkeletonData) FindBone(name string) *BoneData {
for _, bone := range skel.Bones {
if bone.Name == name {
return bone
}
}
return nil
}
func (skel *SkeletonData) FindSlot(name string) *SlotData {
for _, slot := range skel.Slots {
if slot.Name == name {
return slot
}
}
return nil
}
func (skel *SkeletonData) FindSkin(name string) *Skin {
for _, skin := range skel.Skins {
if skin.Name == name {
return skin
}
}
return nil
}
func (skel *SkeletonData) FindAnimation(name string) *Animation {
for _, anim := range skel.Animations {
if anim.Name == name {
return anim
}
}
return nil
}
func (skel *SkeletonData) FindTransformConstraint(name string) *TransformConstraintData {
for _, transform := range skel.TransformConstraints {
if transform.Name == name {
return transform
}
}
return nil
}
type BoneData struct {
Index int
Name string
Length float32
Parent *BoneData
Local Transform
Inherit Inherit
Color Color
Children []*BoneData
}
type Inherit byte
const (
InheritTranslation = Inherit(1 << iota)
InheritRotation
InheritScale
InheritReflection
InheritAll = InheritTranslation | InheritRotation | InheritScale | InheritReflection
InheritNoRotationOrReflection = InheritAll &^ (InheritRotation | InheritReflection)
InheritNoScale = InheritAll &^ InheritScale
InheritNoScaleOrReflection = InheritAll &^ (InheritScale | InheritReflection)
)
func parseInherit(s string) Inherit {
switch s {
default:
fallthrough
case "normal", "":
return InheritAll
case "onlyTranslation":
return InheritTranslation
case "noRotationOrReflection":
return InheritNoRotationOrReflection
case "noScale":
return InheritNoScale
case "noScaleOrReflection":
return InheritNoScaleOrReflection
}
}
type SlotData struct {
Index int
Name string
Bone *BoneData
Attachment string
Color Color
Dark Color
Blend BlendMode
}
type EventData struct {
Index int
Name string
Int int
Float float32
String string
}
type TransformConstraintData struct {
Index int
Name string
Order int
Bones []*BoneData
Target *BoneData
Mix TransformMix
Offset Transform
Relative bool
Local bool
}
type TransformMix struct {
Rotate float32
Translate float32
Scale float32
Shear float32
}
func LerpTransformMix(a, b TransformMix, p float32) TransformMix {
r := TransformMix{}
r.Rotate = lerp(a.Rotate, b.Rotate, p)
r.Translate = lerp(a.Translate, b.Translate, p)
r.Scale = lerp(a.Scale, b.Scale, p)
r.Shear = lerp(a.Shear, b.Shear, p)
return r
}
type Skin struct {
Name string
Attachments map[SkinSlot]Attachment
}
func NewSkin(name string) *Skin {
return &Skin{
Name: name,
Attachments: map[SkinSlot]Attachment{},
}
}
type SkinSlot struct {
SlotIndex int
Attachment string
}
func (skin *Skin) Attachment(slot int, attachmentName string) Attachment {
attach, ok := skin.Attachments[SkinSlot{slot, attachmentName}]
if !ok {
return nil
}
return attach
}
func (skin *Skin) AddAttachment(slot int, attachmentName string, attach Attachment) {
skin.Attachments[SkinSlot{slot, attachmentName}] = attach
}
type BlendMode byte
const (
Normal = BlendMode(iota)
Additive
Multiply
Screen
)
func parseBlendMode(s string) BlendMode {
switch s {
case "", "normal":
return Normal
case "additive":
return Additive
case "multiply":
return Multiply
case "screen":
return Screen
default:
return Normal
}
}