[godot] Clean-up SpineTimline, SpineConstants.

This commit is contained in:
Mario Zechner 2022-04-06 11:19:04 +02:00
parent 773173d589
commit cea5adfe1b
7 changed files with 55 additions and 69 deletions

View File

@ -1,8 +1,6 @@
extends SpineSprite extends SpineSprite
func _ready(): func test_spine_animation():
# Test SpineAnimation
var walkAnim: SpineAnimation = get_skeleton().get_data().find_animation("walk") var walkAnim: SpineAnimation = get_skeleton().get_data().find_animation("walk")
assert(walkAnim.get_name() == "walk") assert(walkAnim.get_name() == "walk")
var duration = walkAnim.get_duration() var duration = walkAnim.get_duration()
@ -10,6 +8,19 @@ func _ready():
assert(walkAnim.get_duration() == duration + 1) assert(walkAnim.get_duration() == duration + 1)
assert(walkAnim.get_timelines().size() == 39) assert(walkAnim.get_timelines().size() == 39)
var timeline: SpineTimeline = walkAnim.get_timelines()[0] var timeline: SpineTimeline = walkAnim.get_timelines()[0]
var propertyIds = timeline.getPropertyIds() var propertyIds = timeline.get_property_ids()
assert(walkAnim.has_timeline(propertyIds)) assert(walkAnim.has_timeline(propertyIds))
assert(!walkAnim.has_timeline([0])) assert(!walkAnim.has_timeline([0]))
func test_spine_timeline():
var walkAnim: SpineAnimation = get_skeleton().get_data().find_animation("walk")
var timeline: SpineTimeline = walkAnim.get_timelines()[0]
assert(timeline.get_duration() == 1)
assert(timeline.get_property_ids() == [4294967300])
assert(timeline.get_type() == "RotateTimeline")
func _ready():
test_spine_animation()
test_spine_timeline()
print("All tests passed")

View File

@ -219,75 +219,57 @@ material = SubResource( 20 )
[node name="rear-upper-arm" type="SpineSpriteMeshInstance2D" parent="."] [node name="rear-upper-arm" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 21 ) material = SubResource( 21 )
scale = Vector2( 0.7, 0.7 )
[node name="rear-bracer" type="SpineSpriteMeshInstance2D" parent="."] [node name="rear-bracer" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 22 ) material = SubResource( 22 )
scale = Vector2( 0.7, 0.7 )
[node name="gun" type="SpineSpriteMeshInstance2D" parent="."] [node name="gun" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 23 ) material = SubResource( 23 )
scale = Vector2( 0.7, 0.7 )
[node name="rear-foot" type="SpineSpriteMeshInstance2D" parent="."] [node name="rear-foot" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 24 ) material = SubResource( 24 )
scale = Vector2( 0.7, 0.7 )
[node name="rear-thigh" type="SpineSpriteMeshInstance2D" parent="."] [node name="rear-thigh" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 25 ) material = SubResource( 25 )
scale = Vector2( 0.7, 0.7 )
[node name="rear-shin" type="SpineSpriteMeshInstance2D" parent="."] [node name="rear-shin" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 26 ) material = SubResource( 26 )
scale = Vector2( 0.7, 0.7 )
[node name="neck" type="SpineSpriteMeshInstance2D" parent="."] [node name="neck" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 27 ) material = SubResource( 27 )
scale = Vector2( 0.7, 0.7 )
[node name="torso" type="SpineSpriteMeshInstance2D" parent="."] [node name="torso" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 28 ) material = SubResource( 28 )
scale = Vector2( 0.7, 0.7 )
[node name="front-upper-arm" type="SpineSpriteMeshInstance2D" parent="."] [node name="front-upper-arm" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 29 ) material = SubResource( 29 )
scale = Vector2( 0.7, 0.7 )
[node name="head" type="SpineSpriteMeshInstance2D" parent="."] [node name="head" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 30 ) material = SubResource( 30 )
scale = Vector2( 0.7, 0.7 )
[node name="eye" type="SpineSpriteMeshInstance2D" parent="."] [node name="eye" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 31 ) material = SubResource( 31 )
scale = Vector2( 0.7, 0.7 )
[node name="front-thigh" type="SpineSpriteMeshInstance2D" parent="."] [node name="front-thigh" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 32 ) material = SubResource( 32 )
scale = Vector2( 0.7, 0.7 )
[node name="front-foot" type="SpineSpriteMeshInstance2D" parent="."] [node name="front-foot" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 33 ) material = SubResource( 33 )
scale = Vector2( 0.7, 0.7 )
[node name="front-shin" type="SpineSpriteMeshInstance2D" parent="."] [node name="front-shin" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 34 ) material = SubResource( 34 )
scale = Vector2( 0.7, 0.7 )
[node name="mouth" type="SpineSpriteMeshInstance2D" parent="."] [node name="mouth" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 35 ) material = SubResource( 35 )
scale = Vector2( 0.7, 0.7 )
[node name="goggles" type="SpineSpriteMeshInstance2D" parent="."] [node name="goggles" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 36 ) material = SubResource( 36 )
scale = Vector2( 0.7, 0.7 )
[node name="front-bracer" type="SpineSpriteMeshInstance2D" parent="."] [node name="front-bracer" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 37 ) material = SubResource( 37 )
scale = Vector2( 0.7, 0.7 )
[node name="front-fist" type="SpineSpriteMeshInstance2D" parent="."] [node name="front-fist" type="SpineSpriteMeshInstance2D" parent="."]
material = SubResource( 38 ) material = SubResource( 38 )
scale = Vector2( 0.7, 0.7 )
[node name="muzzle" type="SpineSpriteMeshInstance2D" parent="."] [node name="muzzle" type="SpineSpriteMeshInstance2D" parent="."]
visible = false visible = false

View File

@ -31,7 +31,7 @@
#define GODOT_SPINEANIMATION_H #define GODOT_SPINEANIMATION_H
#include "SpineConstant.h" #include "SpineConstant.h"
#include "core/reference.h"
#include <spine/spine.h> #include <spine/spine.h>
class SpineEvent; class SpineEvent;
@ -51,19 +51,14 @@ public:
SpineAnimation(); SpineAnimation();
~SpineAnimation(); ~SpineAnimation();
inline void set_spine_object(spine::Animation *animation) { inline void set_spine_object(spine::Animation *animation) { this->animation = animation; }
this->animation = animation; inline spine::Animation *get_spine_object() { return animation; }
}
inline spine::Animation *get_spine_object() {
return animation;
}
// Vector<Ref<SpineEvent>> pEvents
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
Array get_timelines(); // Vector<Ref<SpineTimeline>> Array get_timelines();
bool has_timeline(Array ids);// Vector<SpineConstant::PropertyId> bool has_timeline(Array ids);
String get_name(); String get_name();

View File

@ -57,4 +57,5 @@ void SpineConstant::_bind_methods() {
BIND_ENUM_CONSTANT(Property_PathConstraintPosition); BIND_ENUM_CONSTANT(Property_PathConstraintPosition);
BIND_ENUM_CONSTANT(Property_PathConstraintSpacing); BIND_ENUM_CONSTANT(Property_PathConstraintSpacing);
BIND_ENUM_CONSTANT(Property_PathConstraintMix); BIND_ENUM_CONSTANT(Property_PathConstraintMix);
} BIND_ENUM_CONSTANT(Property_Sequence);
}

View File

@ -30,7 +30,7 @@
#ifndef GODOT_SPINECONSTANT_H #ifndef GODOT_SPINECONSTANT_H
#define GODOT_SPINECONSTANT_H #define GODOT_SPINECONSTANT_H
#include "core/variant_parser.h" #include "core/object.h"
class SpineConstant : public Object { class SpineConstant : public Object {
GDCLASS(SpineConstant, Object); GDCLASS(SpineConstant, Object);
@ -70,7 +70,8 @@ public:
Property_TransformConstraint = 1 << 15, Property_TransformConstraint = 1 << 15,
Property_PathConstraintPosition = 1 << 16, Property_PathConstraintPosition = 1 << 16,
Property_PathConstraintSpacing = 1 << 17, Property_PathConstraintSpacing = 1 << 17,
Property_PathConstraintMix = 1 << 18 Property_PathConstraintMix = 1 << 18,
Property_Sequence = 1 << 19
}; };
}; };

View File

@ -28,38 +28,34 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineTimeline.h" #include "SpineTimeline.h"
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineEvent.h" #include "SpineEvent.h"
// enable more than 5 arguments of a method bind function
#include "core/method_bind_ext.gen.inc" #include "core/method_bind_ext.gen.inc"
void SpineTimeline::_bind_methods() { void SpineTimeline::_bind_methods() {
ClassDB::bind_method(D_METHOD("apply", "skeleton", "lastTime", "time", "pEvents", "alpha", "blend", "direction"), &SpineTimeline::apply); ClassDB::bind_method(D_METHOD("apply", "skeleton", "last_time", "time", "events", "alpha", "blend", "direction"), &SpineTimeline::apply);
ClassDB::bind_method(D_METHOD("get_frame_entries"), &SpineTimeline::get_frame_entries); ClassDB::bind_method(D_METHOD("get_frame_entries"), &SpineTimeline::get_frame_entries);
ClassDB::bind_method(D_METHOD("get_frame_count"), &SpineTimeline::get_frame_count); ClassDB::bind_method(D_METHOD("get_frame_count"), &SpineTimeline::get_frame_count);
ClassDB::bind_method(D_METHOD("get_frames"), &SpineTimeline::get_frames); ClassDB::bind_method(D_METHOD("get_frames"), &SpineTimeline::get_frames);
ClassDB::bind_method(D_METHOD("get_duration"), &SpineTimeline::get_duration); ClassDB::bind_method(D_METHOD("get_duration"), &SpineTimeline::get_duration);
ClassDB::bind_method(D_METHOD("getPropertyIds"), &SpineTimeline::getPropertyIds); ClassDB::bind_method(D_METHOD("get_property_ids"), &SpineTimeline::get_property_ids);
ClassDB::bind_method(D_METHOD("get_type"), &SpineTimeline::get_type);
} }
SpineTimeline::SpineTimeline() : timeline(NULL) {
SpineTimeline::SpineTimeline() : timeline(nullptr) {
} }
SpineTimeline::~SpineTimeline() { SpineTimeline::~SpineTimeline() {
} }
void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha, void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array events, float alpha,
SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) {
spine::Vector<spine::Event *> events; spine::Vector<spine::Event *> spineEvents;
events.setSize(pEvents.size(), nullptr); spineEvents.setSize(events.size(), nullptr);
for (size_t i = 0; i < events.size(); ++i) { for (size_t i = 0; i < events.size(); ++i) {
events[i] = ((Ref<SpineEvent>) pEvents[i])->get_spine_object(); events[i] = ((Ref<SpineEvent>) spineEvents[i])->get_spine_object();
} }
timeline->apply(*(skeleton->get_spine_object()), lastTime, time, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
timeline->apply(*(skeleton->get_spine_object()), lastTime, time, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
} }
int64_t SpineTimeline::get_frame_entries() { int64_t SpineTimeline::get_frame_entries() {
@ -72,28 +68,32 @@ int64_t SpineTimeline::get_frame_count() {
Array SpineTimeline::get_frames() { Array SpineTimeline::get_frames() {
auto &frames = timeline->getFrames(); auto &frames = timeline->getFrames();
Array res; Array result;
res.resize(frames.size()); result.resize(frames.size());
for (size_t i = 0; i < res.size(); ++i) { for (size_t i = 0; i < result.size(); ++i) {
res[i] = frames[i]; result[i] = frames[i];
} }
return res; return result;
} }
float SpineTimeline::get_duration() { float SpineTimeline::get_duration() {
return timeline->getDuration(); return timeline->getDuration();
} }
Array SpineTimeline::getPropertyIds() { Array SpineTimeline::get_property_ids() {
auto &ids = timeline->getPropertyIds(); auto &ids = timeline->getPropertyIds();
Array res; Array result;
res.resize(ids.size()); result.resize(ids.size());
for (size_t i = 0; i < res.size(); ++i) { for (size_t i = 0; i < result.size(); ++i) {
res[i] = (int64_t) ids[i]; result[i] = (int64_t) ids[i];
} }
return res; return result;
}
String SpineTimeline::get_type() {
return timeline->getRTTI().getClassName();
} }

View File

@ -30,11 +30,9 @@
#ifndef GODOT_SPINETIMELINE_H #ifndef GODOT_SPINETIMELINE_H
#define GODOT_SPINETIMELINE_H #define GODOT_SPINETIMELINE_H
#include "core/variant_parser.h"
#include "spine/Timeline.h" #include "spine/Timeline.h"
#include "SpineConstant.h" #include "SpineConstant.h"
#include "core/reference.h"
class SpineSkeleton; class SpineSkeleton;
class SpineEvent; class SpineEvent;
@ -52,24 +50,22 @@ public:
SpineTimeline(); SpineTimeline();
~SpineTimeline(); ~SpineTimeline();
inline void set_spine_object(spine::Timeline *v) { timeline = v; } inline void set_spine_object(spine::Timeline *timeline) { this->timeline = timeline; }
inline spine::Timeline *get_spine_object() { return timeline; } inline spine::Timeline *get_spine_object() { return timeline; }
// Vector<Event *> void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
int64_t get_frame_entries(); int64_t get_frame_entries();
int64_t get_frame_count(); int64_t get_frame_count();
// Vector<float>
Array get_frames(); Array get_frames();
float get_duration(); float get_duration();
// Vector <PropertyId> Array get_property_ids();
Array getPropertyIds();
String get_type();
}; };
#endif//GODOT_SPINETIMELINE_H #endif//GODOT_SPINETIMELINE_H