Skip to content

Commit

Permalink
[godot] Port 4.2 changes and expose in GDScript/C#
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Apr 4, 2024
1 parent 32bcbf6 commit e623140
Show file tree
Hide file tree
Showing 24 changed files with 1,570 additions and 592 deletions.
1,043 changes: 529 additions & 514 deletions spine-cpp/spine-cpp/src/spine/Skeleton.cpp

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions spine-godot/spine_godot/SpineAnimationTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ void SpineAnimationTrack::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_time_scale"), &SpineAnimationTrack::get_time_scale);
ClassDB::bind_method(D_METHOD("set_alpha", "alpha"), &SpineAnimationTrack::set_alpha);
ClassDB::bind_method(D_METHOD("get_alpha"), &SpineAnimationTrack::get_alpha);
ClassDB::bind_method(D_METHOD("set_attachment_threshold", "attachment_threshold"), &SpineAnimationTrack::set_attachment_threshold);
ClassDB::bind_method(D_METHOD("get_attachment_threshold"), &SpineAnimationTrack::get_attachment_threshold);
ClassDB::bind_method(D_METHOD("set_draw_order_threshold", "draw_order_threshold"), &SpineAnimationTrack::set_draw_order_threshold);
ClassDB::bind_method(D_METHOD("get_draw_order_threshold"), &SpineAnimationTrack::get_draw_order_threshold);
ClassDB::bind_method(D_METHOD("set_mix_attachment_threshold", "mix_attachment_threshold"), &SpineAnimationTrack::set_mix_attachment_threshold);
ClassDB::bind_method(D_METHOD("get_mix_attachment_threshold"), &SpineAnimationTrack::get_mix_attachment_threshold);
ClassDB::bind_method(D_METHOD("set_mix_draw_order_threshold", "mix_draw_order_threshold"), &SpineAnimationTrack::set_mix_draw_order_threshold);
ClassDB::bind_method(D_METHOD("get_mix_draw_order_threshold"), &SpineAnimationTrack::get_mix_draw_order_threshold);
ClassDB::bind_method(D_METHOD("set_mix_blend", "mix_blend"), &SpineAnimationTrack::set_mix_blend);
ClassDB::bind_method(D_METHOD("get_mix_blend"), &SpineAnimationTrack::get_mix_blend);
ClassDB::bind_method(D_METHOD("set_blend_tree_mode", "blend_tree_mode_enabled"), &SpineAnimationTrack::set_blend_tree_mode);
Expand Down Expand Up @@ -100,8 +100,8 @@ SpineAnimationTrack::SpineAnimationTrack() : loop(false),
shortest_rotation(false),
time_scale(1),
alpha(1),
attachment_threshold(0),
draw_order_threshold(0),
mix_attachment_threshold(0),
mix_draw_order_threshold(0),
mix_blend(SpineConstant::MixBlend_Replace),
blend_tree_mode(false),
debug(false),
Expand Down Expand Up @@ -301,8 +301,8 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
entry->setShortestRotation(shortest_rotation);
entry->setTimeScale(time_scale);
entry->setAlpha(alpha);
entry->setAttachmentThreshold(attachment_threshold);
entry->setDrawOrderThreshold(draw_order_threshold);
entry->setMixAttachmentThreshold(mix_attachment_threshold);
entry->setMixDrawOrderThreshold(mix_draw_order_threshold);
entry->setMixBlend((spine::MixBlend) mix_blend);

if (debug) print_line(String("Setting animation {0} with mix_duration {1} on track {2} on {3}").format(varray(animation_name, mix_duration, track_index, sprite->get_name())).utf8().ptr());
Expand Down Expand Up @@ -406,8 +406,8 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
entry->setReverse(reverse);
entry->setShortestRotation(shortest_rotation);
entry->setAlpha(alpha);
entry->setAttachmentThreshold(attachment_threshold);
entry->setDrawOrderThreshold(draw_order_threshold);
entry->setMixAttachmentThreshold(mix_attachment_threshold);
entry->setMixDrawOrderThreshold(mix_draw_order_threshold);
entry->setMixBlend((spine::MixBlend) mix_blend);
#endif
} else {
Expand All @@ -426,8 +426,8 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
entry->setShortestRotation(shortest_rotation);
entry->setTimeScale(time_scale);
entry->setAlpha(alpha);
entry->setAttachmentThreshold(attachment_threshold);
entry->setDrawOrderThreshold(draw_order_threshold);
entry->setMixAttachmentThreshold(mix_attachment_threshold);
entry->setMixDrawOrderThreshold(mix_draw_order_threshold);
entry->setMixBlend((spine::MixBlend) mix_blend);

if (debug) print_line(String("Setting animation {0} with mix_duration {1} on track {2} on {3}").format(varray(animation_name, mix_duration, track_index, sprite->get_name())).utf8().ptr());
Expand Down Expand Up @@ -515,20 +515,20 @@ float SpineAnimationTrack::get_alpha() {
return alpha;
}

void SpineAnimationTrack::set_attachment_threshold(float _attachment_threshold) {
attachment_threshold = _attachment_threshold;
void SpineAnimationTrack::set_mix_attachment_threshold(float _mix_attachment_threshold) {
mix_attachment_threshold = _mix_attachment_threshold;
}

float SpineAnimationTrack::get_attachment_threshold() {
return attachment_threshold;
float SpineAnimationTrack::get_mix_attachment_threshold() {
return mix_attachment_threshold;
}

void SpineAnimationTrack::set_draw_order_threshold(float _draw_order_threshold) {
draw_order_threshold = _draw_order_threshold;
void SpineAnimationTrack::set_mix_draw_order_threshold(float _mix_draw_order_threshold) {
mix_draw_order_threshold = _mix_draw_order_threshold;
}

float SpineAnimationTrack::get_draw_order_threshold() {
return draw_order_threshold;
float SpineAnimationTrack::get_mix_draw_order_threshold() {
return mix_draw_order_threshold;
}

void SpineAnimationTrack::set_mix_blend(SpineConstant::MixBlend _blend) {
Expand Down
12 changes: 6 additions & 6 deletions spine-godot/spine_godot/SpineAnimationTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class SpineAnimationTrack : public Node {
bool shortest_rotation;
float time_scale;
float alpha;
float attachment_threshold;
float draw_order_threshold;
float mix_attachment_threshold;
float mix_draw_order_threshold;
SpineConstant::MixBlend mix_blend;
bool blend_tree_mode;
bool debug;
Expand Down Expand Up @@ -113,13 +113,13 @@ class SpineAnimationTrack : public Node {

float get_alpha();

void set_attachment_threshold(float _attachment_threshold);
void set_mix_attachment_threshold(float _mix_attachment_threshold);

float get_attachment_threshold();
float get_mix_attachment_threshold();

void set_draw_order_threshold(float _draw_order_threshold);
void set_mix_draw_order_threshold(float _mix_draw_order_threshold);

float get_draw_order_threshold();
float get_mix_draw_order_threshold();

void set_mix_blend(SpineConstant::MixBlend _blend);

Expand Down
29 changes: 29 additions & 0 deletions spine-godot/spine_godot/SpineBone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*****************************************************************************/

#include "SpineBone.h"
#include "SpineConstant.h"
#include "SpineSprite.h"
#include "SpineSkeleton.h"
#include "SpineCommon.h"
Expand All @@ -36,7 +37,9 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineBone::update_world_transform);
ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineBone::set_to_setup_pose);
ClassDB::bind_method(D_METHOD("world_to_local", "world_position"), &SpineBone::world_to_local);
ClassDB::bind_method(D_METHOD("world_to_parent", "world_position"), &SpineBone::world_to_parent);
ClassDB::bind_method(D_METHOD("local_to_world", "local_position"), &SpineBone::local_to_world);
ClassDB::bind_method(D_METHOD("parent_to_world", "local_position"), &SpineBone::parent_to_world);
ClassDB::bind_method(D_METHOD("world_to_local_rotation", "world_rotation"), &SpineBone::world_to_local_rotation);
ClassDB::bind_method(D_METHOD("local_to_world_rotation", "local_rotation"), &SpineBone::local_to_world_rotation);
ClassDB::bind_method(D_METHOD("rotate_world"), &SpineBone::rotate_world);
Expand Down Expand Up @@ -91,6 +94,8 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_world_scale_y"), &SpineBone::get_world_scale_y);
ClassDB::bind_method(D_METHOD("is_active"), &SpineBone::is_active);
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineBone::set_active);
ClassDB::bind_method(D_METHOD("set_inherit", "v"), &SpineBone::set_inherit);
ClassDB::bind_method(D_METHOD("get_inherit"), &SpineBone::get_inherit);
ClassDB::bind_method(D_METHOD("get_transform"), &SpineBone::get_transform);
ClassDB::bind_method(D_METHOD("set_transform", "local_transform"), &SpineBone::set_transform);
ClassDB::bind_method(D_METHOD("get_global_transform"), &SpineBone::get_global_transform);
Expand All @@ -114,13 +119,27 @@ Vector2 SpineBone::world_to_local(Vector2 world_position) {
return Vector2(x, y);
}

Vector2 SpineBone::world_to_parent(Vector2 world_position) {
SPINE_CHECK(get_spine_object(), Vector2())
float x, y;
get_spine_object()->worldToParent(world_position.x, world_position.y, x, y);
return Vector2(x, y);
}

Vector2 SpineBone::local_to_world(Vector2 local_position) {
SPINE_CHECK(get_spine_object(), Vector2())
float x, y;
get_spine_object()->localToWorld(local_position.x, local_position.y, x, y);
return Vector2(x, y);
}

Vector2 SpineBone::parent_to_world(Vector2 local_position) {
SPINE_CHECK(get_spine_object(), Vector2())
float x, y;
get_spine_object()->parentToWorld(local_position.x, local_position.y, x, y);
return Vector2(x, y);
}

float SpineBone::world_to_local_rotation(float world_rotation) {
SPINE_CHECK(get_spine_object(), 0)
return get_spine_object()->worldToLocalRotation(world_rotation);
Expand Down Expand Up @@ -407,6 +426,16 @@ void SpineBone::set_active(bool v) {
get_spine_object()->setActive(v);
}

SpineConstant::Inherit SpineBone::get_inherit() {
SPINE_CHECK(get_spine_object(), SpineConstant::Inherit_Normal);
return (SpineConstant::Inherit) get_spine_object()->getInherit();
}

void SpineBone::set_inherit(SpineConstant::Inherit inherit) {
SPINE_CHECK(get_spine_object(), );
get_spine_object()->setInherit((spine::Inherit) inherit);
}

Transform2D SpineBone::get_transform() {
SPINE_CHECK(get_spine_object(), Transform2D())
Transform2D transform;
Expand Down
9 changes: 9 additions & 0 deletions spine-godot/spine_godot/SpineBone.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "SpineCommon.h"
#include "SpineBoneData.h"
#include "SpineConstant.h"
#include "scene/2d/node_2d.h"
#include <spine/Bone.h>

Expand All @@ -50,8 +51,12 @@ class SpineBone : public SpineSpriteOwnedObject<spine::Bone> {

Vector2 world_to_local(Vector2 world_position);

Vector2 world_to_parent(Vector2 world_position);

Vector2 local_to_world(Vector2 local_position);

Vector2 parent_to_world(Vector2 local_position);

float world_to_local_rotation(float world_rotation);

float local_to_world_rotation(float local_rotation);
Expand Down Expand Up @@ -160,6 +165,10 @@ class SpineBone : public SpineSpriteOwnedObject<spine::Bone> {

void set_active(bool v);

SpineConstant::Inherit get_inherit();

void set_inherit(SpineConstant::Inherit inherit);

// External feature functions
void apply_world_transform_2d(const Variant &o);

Expand Down
32 changes: 25 additions & 7 deletions spine-godot/spine_godot/SpineBoneData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ void SpineBoneData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shear_x", "v"), &SpineBoneData::set_shear_x);
ClassDB::bind_method(D_METHOD("get_shear_y"), &SpineBoneData::get_shear_y);
ClassDB::bind_method(D_METHOD("set_shear_y", "v"), &SpineBoneData::set_shear_y);
ClassDB::bind_method(D_METHOD("get_transform_mode"), &SpineBoneData::get_transform_mode);
ClassDB::bind_method(D_METHOD("set_transform_mode", "v"), &SpineBoneData::set_transform_mode);
ClassDB::bind_method(D_METHOD("get_inherit"), &SpineBoneData::get_inherit);
ClassDB::bind_method(D_METHOD("set_inherit", "v"), &SpineBoneData::set_inherit);
ClassDB::bind_method(D_METHOD("is_skin_required"), &SpineBoneData::is_skin_required);
ClassDB::bind_method(D_METHOD("set_skin_required", "v"), &SpineBoneData::set_skin_required);
ClassDB::bind_method(D_METHOD("get_color"), &SpineBoneData::get_color);
ClassDB::bind_method(D_METHOD("set_color", "v"), &SpineBoneData::set_color);
ClassDB::bind_method(D_METHOD("get_icon"), &SpineBoneData::get_icon);
ClassDB::bind_method(D_METHOD("set_visible", "v"), &SpineBoneData::set_visible);
ClassDB::bind_method(D_METHOD("is_visible"), &SpineBoneData::is_visible);
}

int SpineBoneData::get_index() {
Expand Down Expand Up @@ -157,14 +160,14 @@ void SpineBoneData::set_shear_y(float v) {
get_spine_object()->setShearY(v);
}

SpineConstant::TransformMode SpineBoneData::get_transform_mode() {
SPINE_CHECK(get_spine_object(), SpineConstant::TransformMode::TransformMode_Normal)
return (SpineConstant::TransformMode) get_spine_object()->getTransformMode();
SpineConstant::Inherit SpineBoneData::get_inherit() {
SPINE_CHECK(get_spine_object(), SpineConstant::Inherit::Inherit_Normal)
return (SpineConstant::Inherit) get_spine_object()->getInherit();
}

void SpineBoneData::set_transform_mode(SpineConstant::TransformMode v) {
void SpineBoneData::set_inherit(SpineConstant::Inherit v) {
SPINE_CHECK(get_spine_object(), )
get_spine_object()->setTransformMode((spine::TransformMode) v);
get_spine_object()->setInherit((spine::Inherit) v);
}

bool SpineBoneData::is_skin_required() {
Expand All @@ -187,3 +190,18 @@ void SpineBoneData::set_color(Color color) {
SPINE_CHECK(get_spine_object(), )
get_spine_object()->getColor().set(color.r, color.g, color.b, color.a);
}

String SpineBoneData::get_icon() {
SPINE_CHECK(get_spine_object(), "")
return get_spine_object()->getIcon().buffer();
}

bool SpineBoneData::is_visible() {
SPINE_CHECK(get_spine_object(), true)
return get_spine_object()->isVisible();
}

void SpineBoneData::set_visible(bool v) {
SPINE_CHECK(get_spine_object(), )
get_spine_object()->setVisible(v);
}
10 changes: 8 additions & 2 deletions spine-godot/spine_godot/SpineBoneData.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class SpineBoneData : public SpineSkeletonDataResourceOwnedObject<spine::BoneDat

void set_shear_y(float v);

SpineConstant::TransformMode get_transform_mode();
SpineConstant::Inherit get_inherit();

void set_transform_mode(SpineConstant::TransformMode v);
void set_inherit(SpineConstant::Inherit v);

bool is_skin_required();

Expand All @@ -91,4 +91,10 @@ class SpineBoneData : public SpineSkeletonDataResourceOwnedObject<spine::BoneDat
Color get_color();

void set_color(Color color);

String get_icon();

bool is_visible();

void set_visible(bool v);
};
4 changes: 2 additions & 2 deletions spine-godot/spine_godot/SpineBoneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void SpineBoneNode::init_transform(SpineSprite *sprite) {
if (!sprite) return;
if (bone_mode == SpineConstant::BoneMode_Drive) return;
sprite->get_skeleton()->set_to_setup_pose();
sprite->get_skeleton()->update_world_transform();
sprite->get_skeleton()->update_world_transform(SpineConstant::Physics_Update);
Transform2D global_transform = sprite->get_global_bone_transform(bone_name);
set_global_transform(global_transform);
update_transform(sprite);
Expand Down Expand Up @@ -259,7 +259,7 @@ void SpineBoneNode::set_enabled(bool _enabled) {
auto sprite = find_parent_sprite();
if (!sprite) return;
sprite->get_skeleton()->set_to_setup_pose();
sprite->get_skeleton()->update_world_transform();
sprite->get_skeleton()->update_world_transform(SpineConstant::Physics_Update);
}
}

Expand Down
15 changes: 10 additions & 5 deletions spine-godot/spine_godot/SpineConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ void SpineConstant::_bind_methods() {
BIND_ENUM_CONSTANT(Property_PathConstraintMix)
BIND_ENUM_CONSTANT(Property_Sequence)

BIND_ENUM_CONSTANT(TransformMode_Normal)
BIND_ENUM_CONSTANT(TransformMode_OnlyTranslation)
BIND_ENUM_CONSTANT(TransformMode_NoRotationOrReflection)
BIND_ENUM_CONSTANT(TransformMode_NoScale)
BIND_ENUM_CONSTANT(TransformMode_NoScaleOrReflection)
BIND_ENUM_CONSTANT(Inherit_Normal)
BIND_ENUM_CONSTANT(Inherit_OnlyTranslation)
BIND_ENUM_CONSTANT(Inherit_NoRotationOrReflection)
BIND_ENUM_CONSTANT(Inherit_NoScale)
BIND_ENUM_CONSTANT(Inherit_NoScaleOrReflection)

BIND_ENUM_CONSTANT(PositionMode_Fixed)
BIND_ENUM_CONSTANT(PositionMode_Percent)
Expand All @@ -87,4 +87,9 @@ void SpineConstant::_bind_methods() {

BIND_ENUM_CONSTANT(BoneMode_Follow)
BIND_ENUM_CONSTANT(BoneMode_Drive)

BIND_ENUM_CONSTANT(Physics_None);
BIND_ENUM_CONSTANT(Physics_Reset);
BIND_ENUM_CONSTANT(Physics_Update);
BIND_ENUM_CONSTANT(Physics_Pose);
}
22 changes: 15 additions & 7 deletions spine-godot/spine_godot/SpineConstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ class SpineConstant : public Object {
Property_Sequence = 1 << 19
};

enum TransformMode {
TransformMode_Normal = 0,
TransformMode_OnlyTranslation,
TransformMode_NoRotationOrReflection,
TransformMode_NoScale,
TransformMode_NoScaleOrReflection
enum Inherit {
Inherit_Normal = 0,
Inherit_OnlyTranslation,
Inherit_NoRotationOrReflection,
Inherit_NoScale,
Inherit_NoScaleOrReflection
};

enum PositionMode {
Expand Down Expand Up @@ -115,15 +115,23 @@ class SpineConstant : public Object {
BoneMode_Follow,
BoneMode_Drive
};

enum Physics {
Physics_None,
Physics_Reset,
Physics_Update,
Physics_Pose
};
};

VARIANT_ENUM_CAST(SpineConstant::MixBlend)
VARIANT_ENUM_CAST(SpineConstant::MixDirection)
VARIANT_ENUM_CAST(SpineConstant::PropertyId)
VARIANT_ENUM_CAST(SpineConstant::TransformMode)
VARIANT_ENUM_CAST(SpineConstant::Inherit)
VARIANT_ENUM_CAST(SpineConstant::PositionMode)
VARIANT_ENUM_CAST(SpineConstant::SpacingMode)
VARIANT_ENUM_CAST(SpineConstant::RotateMode)
VARIANT_ENUM_CAST(SpineConstant::BlendMode)
VARIANT_ENUM_CAST(SpineConstant::UpdateMode)
VARIANT_ENUM_CAST(SpineConstant::BoneMode)
VARIANT_ENUM_CAST(SpineConstant::Physics)
2 changes: 1 addition & 1 deletion spine-godot/spine_godot/SpineIkConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void SpineIkConstraint::_bind_methods() {

void SpineIkConstraint::update() {
SPINE_CHECK(get_spine_object(), )
get_spine_object()->update();
get_spine_object()->update(spine::Physics_Update);
}

int SpineIkConstraint::get_order() {
Expand Down
Loading

0 comments on commit e623140

Please sign in to comment.