forked from skn3/monkeyspine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspineskeleton.monkey
More file actions
180 lines (155 loc) · 4.34 KB
/
spineskeleton.monkey
File metadata and controls
180 lines (155 loc) · 4.34 KB
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
'see license.txt for source licenses
Strict
Import spine
Class SpineSkeleton
Field Data:SpineSkeletonData
Field Bones:SpineBone[]
Field Slots:SpineSlot[]
Field DrawOrder:SpineSlot[]
Field Skin:SpineSkin
Field R:float
Field G:float
Field B:float
Field A:float
Field Time:float
Field FlipX:bool
Field FlipY:bool
Method RootBone:SpineBone()
If Bones.Length = 0 Return Null
Return Bones[0]
End
Method New(data:SpineSkeletonData)
If data = Null Throw New SpineArgumentNullException("data cannot be null.")
Data = data
Bones = New SpineBone[Data.Bones.Length]
Slots = New SpineSlot[Data.Slots.Length]
DrawOrder = New SpineSlot[Data.Slots.Length]
Local bonesIndex:Int
Local parent:SpineBone
Local boneData:SpineBoneData
Local index:Int
Local indexOf:Int
Local bone:SpineBone
Local slot:SpineSlot
Local slotOrderIndex:Int
For index = 0 Until Data.Bones.Length
'find bone data and parent
boneData = Data.Bones[index]
parent = Null
If boneData.Parent
For indexOf = 0 Until Data.Bones.Length
If Data.Bones[indexOf] = boneData.Parent
parent = Bones[indexOf]
Exit
EndIf
Next
EndIf
'create new bone
Bones[bonesIndex] = New SpineBone(boneData, parent)
bonesIndex += 1
Next
For index = 0 Until Data.Slots.Length
bone = Null
For indexOf = 0 Until Data.Bones.Length
If Data.Bones[indexOf] = Data.Slots[index].BoneData
bone = Bones[indexOf]
Exit
EndIf
Next
slot = New SpineSlot(Data.Slots[index], Self, bone)
Slots[slotOrderIndex] = slot
DrawOrder[slotOrderIndex] = slot
slotOrderIndex += 1
Next
R = 1
G = 1
B = 1
A = 1
End
Method UpdateWorldTransform:Void()
For Local i:= 0 Until Bones.Length
Bones[i].UpdateWorldTransform(FlipX, FlipY)
Next
End
Method SetToBindPose:Void()
SetBonesToBindPose()
SetSlotsToBindPose()
End
Method SetBonesToBindPose:Void()
For Local i:= 0 Until Bones.Length
Bones[i].SetToBindPose()
Next
End
Method SetSlotsToBindPose:Void()
For Local i:= 0 Until Slots.Length
Slots[i].SetToBindPose(i)
Next
End
Method FindBone:SpineBone(boneName:String)
If boneName.Length = 0 Return Null
For Local i:= 0 Until Bones.Length
If Bones[i].Data.Name = boneName Return Bones[i]
Next
return null
End
Method FindBoneIndex:int(boneName:String)
If boneName.Length = 0 Return - 1
For Local i:= 0 Until Bones.Length
If Bones[i].Data.Name = boneName Return i
Next
Return -1
End
Method FindSlot:SpineSlot(slotName:String)
If slotName.Length = 0 Return Null
For Local i:= 0 Until Slots.Length
If Slots[i].Data.Name = slotName Return Slots[i]
Next
Return Null
End
Method FindSlotIndex:int(slotName:String)
If slotName.Length = 0 Return - 1
For Local i:= 0 Until Slots.Length
If Slots[i].Data.Name = slotName Return i
Next
Return -1
End
Method SetSkin:Void(skinName:String)
Local skin:SpineSkin = Data.FindSkin(skinName)
If skin = Null Throw New SpineException("Spine skin '" + skinName + "' not found")
SetSkin(skin)
End
Method SetSkin:Void(newSkin:SpineSkin)
If Skin <> Null And newSkin <> Null newSkin.AttachAll(Self, Skin)
Skin = newSkin
End
Method GetAttachment:SpineAttachment(slotName:String, attachmentName:String)
return GetAttachment(Data.FindSlotIndex(slotName), attachmentName)
End
Method GetAttachment:SpineAttachment(slotIndex:int, attachmentName:String)
If attachmentName.Length = 0 Return Null
If Skin <> Null
Local attachment:SpineAttachment = Skin.GetAttachment(slotIndex, attachmentName)
If attachment <> Null Return attachment
EndIf
If Data.DefaultSkin <> Null Return Data.DefaultSkin.GetAttachment(slotIndex, attachmentName)
return null
End
Method SetAttachment:Void(slotName:String, attachmentName:String)
If slotName.Length = 0 Throw New SpineArgumentNullException("slotName cannot be empty.")
For Local i:= 0 Until Slots.Length
If Slots[i].Data.Name = slotName
Local attachment:SpineAttachment = Null
If attachmentName <> ""
attachment = GetAttachment(i, attachmentName)
If attachment = Null Throw New SpineArgumentNullException("SpineAttachment not found: " + attachmentName + ", for slot: " + slotName)
EndIf
Slots[i].Attachment = attachment
return
EndIf
Next
throw new SpineException("SpineSlot not found: " + slotName)
End
Method Update:Void(delta:float)
Time += delta
End
End