-
Notifications
You must be signed in to change notification settings - Fork 3
/
spine.h
238 lines (195 loc) · 8.46 KB
/
spine.h
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*************************************************************************/
/* spine.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifdef MODULE_SPINE_ENABLED
#ifndef SPINE_H
#define SPINE_H
#include "scene/2d/node_2d.h"
#include "scene/resources/shape_2d.h"
#include <spine/spine.h>
#include "spine_batcher.h"
#include "core/array.h"
class CollisionObject2D;
class Spine : public Node2D {
OBJ_TYPE(Spine, Node2D);
public:
enum AnimationProcessMode {
ANIMATION_PROCESS_FIXED,
ANIMATION_PROCESS_IDLE,
};
enum DebugAttachmentMode {
DEBUG_ATTACHMENT_REGION,
DEBUG_ATTACHMENT_MESH,
DEBUG_ATTACHMENT_SKINNED_MESH,
DEBUG_ATTACHMENT_BOUNDING_BOX,
};
class SpineResource : public Resource {
OBJ_TYPE(SpineResource, Resource);
public:
SpineResource();
~SpineResource();
spAtlas *atlas;
spSkeletonData *data;
};
private:
Ref<SpineResource> res;
spSkeleton* skeleton;
spBone* root_bone;
spAnimationState* state;
mutable Vector<float> world_verts;
float speed_scale;
String autoplay;
AnimationProcessMode animation_process_mode;
bool processing;
bool active;
bool playing;
bool forward;
int skip_frames;
int frames_to_skip;
float process_delta;
bool debug_bones;
bool debug_attachment_region;
bool debug_attachment_mesh;
bool debug_attachment_skinned_mesh;
bool debug_attachment_bounding_box;
List<uint64_t> debug_avarage_animate_ticks;
String current_animation;
bool loop;
String skin;
Color modulate;
bool flip_x, flip_y;
SpineBatcher batcher;
// fx slots (always show on top)
Node2D *fx_node;
SpineBatcher fx_batcher;
CharString fx_slot_prefix;
float current_pos;
typedef struct AttachmentNode {
List<AttachmentNode>::Element *E;
spBone *bone;
WeakRef *ref;
Vector2 ofs;
Vector2 scale;
real_t rot;
} AttachmentNode;
typedef List<AttachmentNode> AttachmentNodes;
AttachmentNodes attachment_nodes;
static void spine_animation_callback(spAnimationState* p_state, spEventType p_type, spTrackEntry* p_track, spEvent* p_event);
void _on_animation_state_event(int p_track, spEventType p_type, spEvent *p_event, int p_loop_count);
void _spine_dispose();
void _animation_process(float p_delta);
void _animation_draw();
void _set_process(bool p_process, bool p_force = false);
void _on_fx_draw();
protected:
static Array *invalid_names;
bool _set(const StringName& p_name, const Variant& p_value);
bool _get(const StringName& p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:
static Array get_invalid_names();
// set/get spine resource
void set_resource(Ref<SpineResource> p_data);
Ref<SpineResource> get_resource();
bool has(const String& p_name);
void mix(const String& p_from, const String& p_to, real_t p_duration);
bool play(const String& p_name, real_t p_cunstom_scale = 1.0f, bool p_loop = false, int p_track = 0, int p_delay = 0);
bool add(const String& p_name, real_t p_cunstom_scale = 1.0f, bool p_loop = false, int p_track = 0, int p_delay = 0);
void clear(int p_track = -1);
void stop();
bool is_playing(int p_track = 0) const;
float get_animation_length(String p_animation) const;
void set_forward(bool p_forward = true);
bool is_forward() const;
void set_skip_frames(int p_skip_frames);
int get_skip_frames() const;
String get_current_animation(int p_track = 0) const;
void stop_all();
void reset();
void seek(float p_pos);
float tell() const;
void set_active(bool p_active);
bool is_active() const;
void set_speed(float p_speed);
float get_speed() const;
void set_autoplay(const String& p_name);
String get_autoplay() const;
void set_modulate(const Color& p_color);
Color get_modulate() const;
void set_flip_x(bool p_flip);
void set_flip_y(bool p_flip);
bool is_flip_x() const;
bool is_flip_y() const;
void set_animation_process_mode(AnimationProcessMode p_mode);
AnimationProcessMode get_animation_process_mode() const;
/* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are
* attached if the corresponding attachment from the old skin was attached. If there was no old skin, each slot's setup mode
* attachment is attached from the new skin. Returns false if the skin was not found.
* @param skin May be 0.*/
bool set_skin(const String& p_name);
//spAttachment* get_attachment(const char* slotName, const char* attachmentName) const;
Dictionary get_skeleton() const;
/* Returns null if the slot or attachment was not found. */
Dictionary get_attachment(const String& p_slot_name, const String& p_attachment_name) const;
/* Returns null if the bone was not found. */
Dictionary get_bone(const String& p_bone_name) const;
/* Returns null if the slot was not found. */
Dictionary get_slot(const String& p_slot_name) const;
/* Returns false if the slot or attachment was not found. */
bool set_attachment(const String& p_slot_name, const Variant& p_attachment);
// bind node to bone, auto update pos/rotate/scale
bool has_attachment_node(const String& p_bone_name, const Variant& p_node);
bool add_attachment_node(const String& p_bone_name, const Variant& p_node, const Vector2& p_ofs = Vector2(0, 0), const Vector2& p_scale = Vector2(1, 1), const real_t p_rot = 0);
bool remove_attachment_node(const String& p_bone_name, const Variant& p_node);
// get spine bounding box
Ref<Shape2D> get_bounding_box(const String& p_slot_name, const String& p_attachment_name);
// bind collision object 2d to spine bounding box
bool add_bounding_box(const String& p_bone_name, const String& p_slot_name, const String& p_attachment_name, const Variant& p_node, const Vector2& p_ofs = Vector2(0, 0), const Vector2& p_scale = Vector2(1, 1), const real_t p_rot = 0);
bool remove_bounding_box(const String& p_bone_name, const Variant& p_node);
void set_fx_slot_prefix(const String& p_prefix);
String get_fx_slot_prefix() const;
void set_debug_bones(bool p_enable);
bool is_debug_bones() const;
void set_debug_attachment(DebugAttachmentMode p_mode, bool p_enable);
bool is_debug_attachment(DebugAttachmentMode p_mode) const;
float get_debug_animate_ticks_msec() const;
//void seek(float p_time, bool p_update = false);
//void seek_delta(float p_time, float p_delta);
//float get_current_animation_pos() const;
//float get_current_animation_length() const;
//void advance(float p_time);
virtual Rect2 get_item_rect() const;
Spine();
virtual ~Spine();
};
VARIANT_ENUM_CAST(Spine::AnimationProcessMode);
VARIANT_ENUM_CAST(Spine::DebugAttachmentMode);
#endif // SPINE_H
#endif // MODULE_SPINE_ENABLED