mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-25 22:23:42 +08:00
[godot] Prepare all classes for proper native object handling based on signals.
This commit is contained in:
parent
cb36ae34cd
commit
e807ef406c
@ -45,31 +45,28 @@ void SpineAnimation::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("has_timeline", "ids"), &SpineAnimation::has_timeline);
|
||||
}
|
||||
|
||||
SpineAnimation::SpineAnimation() : animation(nullptr) {
|
||||
}
|
||||
|
||||
String SpineAnimation::get_name() {
|
||||
SPINE_CHECK(animation, "")
|
||||
return animation->getName().buffer();
|
||||
SPINE_CHECK(spine_object, "")
|
||||
return spine_object->getName().buffer();
|
||||
}
|
||||
|
||||
float SpineAnimation::get_duration() {
|
||||
SPINE_CHECK(animation, 0)
|
||||
return animation->getDuration();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getDuration();
|
||||
}
|
||||
|
||||
void SpineAnimation::set_duration(float duration) {
|
||||
SPINE_CHECK(animation,)
|
||||
animation->setDuration(duration);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setDuration(duration);
|
||||
}
|
||||
|
||||
void SpineAnimation::apply(Ref<SpineSkeleton> skeleton, float last_time, float time, bool loop,
|
||||
Array events, float alpha, SpineConstant::MixBlend blend,
|
||||
SpineConstant::MixDirection direction) {
|
||||
SPINE_CHECK(animation,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine::Vector<spine::Event *> spineEvents;
|
||||
animation->apply(*(skeleton->get_spine_object()), last_time, time, loop, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
|
||||
for (int i = 0; i < spineEvents.size(); ++i) {
|
||||
spine_object->apply(*(skeleton->get_spine_object()), last_time, time, loop, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
|
||||
for (int i = 0; i < (int)spineEvents.size(); ++i) {
|
||||
auto event_ref = memnew(SpineEvent);
|
||||
event_ref->set_spine_object(spineEvents[i]);
|
||||
events.append(event_ref);
|
||||
@ -78,11 +75,11 @@ void SpineAnimation::apply(Ref<SpineSkeleton> skeleton, float last_time, float t
|
||||
|
||||
Array SpineAnimation::get_timelines() {
|
||||
Array result;
|
||||
SPINE_CHECK(animation, result)
|
||||
auto &timelines = animation->getTimelines();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto &timelines = spine_object->getTimelines();
|
||||
result.resize((int)timelines.size());
|
||||
|
||||
for (int i = 0; i < result.size(); ++i) {
|
||||
for (int i = 0; i < (int)result.size(); ++i) {
|
||||
auto timeline_ref = Ref<SpineTimeline>(memnew(SpineTimeline));
|
||||
timeline_ref->set_spine_object(timelines[i]);
|
||||
result.set(i, timeline_ref);
|
||||
@ -91,12 +88,12 @@ Array SpineAnimation::get_timelines() {
|
||||
}
|
||||
|
||||
bool SpineAnimation::has_timeline(Array ids) {
|
||||
SPINE_CHECK(animation, false)
|
||||
SPINE_CHECK(spine_object, false)
|
||||
spine::Vector<spine::PropertyId> property_ids;
|
||||
property_ids.setSize(ids.size(), 0);
|
||||
|
||||
for (int i = 0; i < property_ids.size(); ++i) {
|
||||
for (int i = 0; i < (int)property_ids.size(); ++i) {
|
||||
property_ids[i] = (spine::PropertyId) ids[i];
|
||||
}
|
||||
return animation->hasTimeline(property_ids);
|
||||
return spine_object->hasTimeline(property_ids);
|
||||
}
|
||||
|
||||
@ -37,23 +37,15 @@
|
||||
class SpineEvent;
|
||||
class SpineSkeleton;
|
||||
class SpineTimeline;
|
||||
class SpineSkeletonDataResource;
|
||||
|
||||
class SpineAnimation : public REFCOUNTED {
|
||||
class SpineAnimation : public REFCOUNTED, public SpineObjectWrapper<SpineSkeletonDataResource, spine::Animation> {
|
||||
GDCLASS(SpineAnimation, REFCOUNTED);
|
||||
|
||||
private:
|
||||
spine::Animation *animation;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
SpineAnimation();
|
||||
|
||||
void set_spine_object(spine::Animation *_animation) { this->animation = _animation; }
|
||||
|
||||
spine::Animation *get_spine_object() { return animation; }
|
||||
|
||||
void apply(Ref<SpineSkeleton> skeleton, float last_time, float time, bool loop, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
|
||||
|
||||
Array get_timelines();
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "SpineAnimationState.h"
|
||||
#include "SpineTrackEntry.h"
|
||||
|
||||
void SpineAnimationState::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("update", "delta"), &SpineAnimationState::update, DEFVAL(0));
|
||||
@ -46,19 +47,19 @@ void SpineAnimationState::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("enable_queue"), &SpineAnimationState::enable_queue);
|
||||
}
|
||||
|
||||
SpineAnimationState::SpineAnimationState() : animation_state(nullptr), skeleton_data_res(nullptr) {
|
||||
SpineAnimationState::SpineAnimationState() : animation_state(nullptr), sprite(nullptr) {
|
||||
}
|
||||
|
||||
SpineAnimationState::~SpineAnimationState() {
|
||||
delete animation_state;
|
||||
}
|
||||
|
||||
void SpineAnimationState::set_skeleton_data_res(const Ref<SpineSkeletonDataResource> &data_res) {
|
||||
void SpineAnimationState::set_spine_sprite(SpineSprite *_sprite) {
|
||||
delete animation_state;
|
||||
animation_state = nullptr;
|
||||
skeleton_data_res = data_res;
|
||||
if (!skeleton_data_res.is_valid() || !skeleton_data_res->is_skeleton_data_loaded()) return;
|
||||
animation_state = new spine::AnimationState(skeleton_data_res->get_animation_state_data());
|
||||
sprite = _sprite;
|
||||
if (!sprite || !sprite->get_skeleton_data_res().is_valid() || !sprite->get_skeleton_data_res()->is_skeleton_data_loaded()) return;
|
||||
animation_state = new spine::AnimationState(sprite->get_skeleton_data_res()->get_animation_state_data());
|
||||
}
|
||||
|
||||
void SpineAnimationState::update(float delta) {
|
||||
@ -68,6 +69,7 @@ void SpineAnimationState::update(float delta) {
|
||||
|
||||
bool SpineAnimationState::apply(Ref<SpineSkeleton> skeleton) {
|
||||
SPINE_CHECK(animation_state, false)
|
||||
if (!skeleton->get_spine_object()) return false;
|
||||
return animation_state->apply(*(skeleton->get_spine_object()));
|
||||
}
|
||||
|
||||
@ -91,7 +93,7 @@ Ref<SpineTrackEntry> SpineAnimationState::set_animation(const String &animation_
|
||||
}
|
||||
auto track_entry = animation_state->setAnimation(track, animation, loop);
|
||||
Ref<SpineTrackEntry> track_entry_ref(memnew(SpineTrackEntry));
|
||||
track_entry_ref->set_spine_object(track_entry);
|
||||
track_entry_ref->set_spine_object(sprite, track_entry);
|
||||
return track_entry_ref;
|
||||
}
|
||||
|
||||
@ -105,7 +107,7 @@ Ref<SpineTrackEntry> SpineAnimationState::add_animation(const String &animation_
|
||||
}
|
||||
auto track_entry = animation_state->addAnimation(track, animation, loop, delay);
|
||||
Ref<SpineTrackEntry> track_entry_ref(memnew(SpineTrackEntry));
|
||||
track_entry_ref->set_spine_object(track_entry);
|
||||
track_entry_ref->set_spine_object(sprite, track_entry);
|
||||
return track_entry_ref;
|
||||
}
|
||||
|
||||
@ -113,14 +115,14 @@ Ref<SpineTrackEntry> SpineAnimationState::set_empty_animation(int track_id, floa
|
||||
SPINE_CHECK(animation_state, nullptr)
|
||||
auto track_entry = animation_state->setEmptyAnimation(track_id, mix_duration);
|
||||
Ref<SpineTrackEntry> track_entry_ref(memnew(SpineTrackEntry));
|
||||
track_entry_ref->set_spine_object(track_entry);
|
||||
track_entry_ref->set_spine_object(sprite, track_entry);
|
||||
return track_entry_ref;
|
||||
}
|
||||
Ref<SpineTrackEntry> SpineAnimationState::add_empty_animation(int track_id, float mix_duration, float delay) {
|
||||
SPINE_CHECK(animation_state, nullptr)
|
||||
auto track_entry = animation_state->addEmptyAnimation(track_id, mix_duration, delay);
|
||||
Ref<SpineTrackEntry> track_entry_ref(memnew(SpineTrackEntry));
|
||||
track_entry_ref->set_spine_object(track_entry);
|
||||
track_entry_ref->set_spine_object(sprite, track_entry);
|
||||
return track_entry_ref;
|
||||
}
|
||||
void SpineAnimationState::set_empty_animations(float mix_duration) {
|
||||
@ -133,7 +135,7 @@ Ref<SpineTrackEntry> SpineAnimationState::get_current(int track_index) {
|
||||
auto track_entry = animation_state->getCurrent(track_index);
|
||||
if (!track_entry) return nullptr;
|
||||
Ref<SpineTrackEntry> track_entry_ref(memnew(SpineTrackEntry));
|
||||
track_entry_ref->set_spine_object(track_entry);
|
||||
track_entry_ref->set_spine_object(sprite, track_entry);
|
||||
return track_entry_ref;
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,8 @@
|
||||
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSkeleton.h"
|
||||
#include "SpineTrackEntry.h"
|
||||
|
||||
class SpineTrackEntry;
|
||||
|
||||
class SpineAnimationState : public REFCOUNTED {
|
||||
GDCLASS(SpineAnimationState, REFCOUNTED)
|
||||
@ -42,7 +43,7 @@ protected:
|
||||
|
||||
private:
|
||||
spine::AnimationState *animation_state;
|
||||
Ref<SpineSkeletonDataResource> skeleton_data_res;
|
||||
SpineSprite *sprite;
|
||||
|
||||
public:
|
||||
SpineAnimationState();
|
||||
@ -50,7 +51,7 @@ public:
|
||||
|
||||
spine::AnimationState *get_spine_object() { return animation_state; }
|
||||
|
||||
void set_skeleton_data_res(const Ref<SpineSkeletonDataResource> &skeleton_data_res);
|
||||
void set_spine_sprite(SpineSprite *sprite);
|
||||
|
||||
void update(float delta);
|
||||
|
||||
|
||||
@ -35,23 +35,20 @@ void SpineAttachment::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("copy"), &SpineAttachment::copy);
|
||||
}
|
||||
|
||||
SpineAttachment::SpineAttachment() : attachment(nullptr) {
|
||||
}
|
||||
|
||||
SpineAttachment::~SpineAttachment() {
|
||||
if (attachment) attachment->dereference();
|
||||
if (spine_object) spine_object->dereference();
|
||||
}
|
||||
|
||||
String SpineAttachment::get_attachment_name() {
|
||||
SPINE_CHECK(attachment, "")
|
||||
return attachment->getName().buffer();
|
||||
SPINE_CHECK(spine_object, "")
|
||||
return spine_object->getName().buffer();
|
||||
}
|
||||
|
||||
Ref<SpineAttachment> SpineAttachment::copy() {
|
||||
SPINE_CHECK(attachment, nullptr)
|
||||
auto copy = attachment->copy();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto copy = spine_object->copy();
|
||||
if (!copy) return nullptr;
|
||||
Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
|
||||
attachment_ref->set_spine_object(copy);
|
||||
attachment_ref->set_spine_object(get_spine_owner(), copy);
|
||||
return attachment_ref;
|
||||
}
|
||||
|
||||
@ -33,29 +33,17 @@
|
||||
#include "SpineCommon.h"
|
||||
#include <spine/spine.h>
|
||||
|
||||
class SpineSkeletonDataResource;
|
||||
|
||||
class SpineAttachment : public REFCOUNTED {
|
||||
class SpineAttachment : public REFCOUNTED, public SpineObjectWrapper<SpineSkeletonDataResource, spine::Attachment> {
|
||||
GDCLASS(SpineAttachment, REFCOUNTED)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::Attachment *attachment;
|
||||
|
||||
public:
|
||||
SpineAttachment();
|
||||
~SpineAttachment() override;
|
||||
|
||||
void set_spine_object(spine::Attachment *_attachment) {
|
||||
attachment = _attachment;
|
||||
if (attachment) attachment->reference();
|
||||
}
|
||||
|
||||
spine::Attachment *get_spine_object() {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
String get_attachment_name();
|
||||
|
||||
Ref<SpineAttachment> copy();
|
||||
|
||||
@ -43,7 +43,6 @@ void SpineBone::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_world_to_local_rotation_x"), &SpineBone::get_world_to_local_rotation_x);
|
||||
ClassDB::bind_method(D_METHOD("get_world_to_local_rotation_y"), &SpineBone::get_world_to_local_rotation_y);
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &SpineBone::get_data);
|
||||
ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineBone::get_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("get_parent"), &SpineBone::get_parent);
|
||||
ClassDB::bind_method(D_METHOD("get_children"), &SpineBone::get_children);
|
||||
ClassDB::bind_method(D_METHOD("get_x"), &SpineBone::get_x);
|
||||
@ -99,329 +98,319 @@ void SpineBone::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_global_transform", "global_transform"), &SpineBone::set_global_transform);
|
||||
}
|
||||
|
||||
SpineBone::SpineBone() : bone(nullptr), sprite(nullptr) {}
|
||||
|
||||
void SpineBone::update_world_transform() {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->updateWorldTransform();
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->updateWorldTransform();
|
||||
}
|
||||
|
||||
void SpineBone::set_to_setup_pose() {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setToSetupPose();
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setToSetupPose();
|
||||
}
|
||||
|
||||
Vector2 SpineBone::world_to_local(Vector2 world_position) {
|
||||
SPINE_CHECK(bone, Vector2())
|
||||
SPINE_CHECK(spine_object, Vector2())
|
||||
float x, y;
|
||||
bone->worldToLocal(world_position.x, world_position.y, x, y);
|
||||
spine_object->worldToLocal(world_position.x, world_position.y, x, y);
|
||||
return Vector2(x, y);
|
||||
}
|
||||
|
||||
Vector2 SpineBone::local_to_world(Vector2 local_position) {
|
||||
SPINE_CHECK(bone, Vector2())
|
||||
SPINE_CHECK(spine_object, Vector2())
|
||||
float x, y;
|
||||
bone->localToWorld(local_position.x, local_position.y, x, y);
|
||||
spine_object->localToWorld(local_position.x, local_position.y, x, y);
|
||||
return Vector2(x, y);
|
||||
}
|
||||
|
||||
float SpineBone::world_to_local_rotation(float world_rotation) {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->worldToLocalRotation(world_rotation);
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->worldToLocalRotation(world_rotation);
|
||||
}
|
||||
|
||||
float SpineBone::local_to_world_rotation(float local_rotation) {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->localToWorldRotation(local_rotation);
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->localToWorldRotation(local_rotation);
|
||||
}
|
||||
|
||||
void SpineBone::rotate_world(float degrees) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->rotateWorld(degrees);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->rotateWorld(degrees);
|
||||
}
|
||||
|
||||
float SpineBone::get_world_to_local_rotation_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldToLocalRotationX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldToLocalRotationX();
|
||||
}
|
||||
|
||||
float SpineBone::get_world_to_local_rotation_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldToLocalRotationY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldToLocalRotationY();
|
||||
}
|
||||
|
||||
Ref<SpineBoneData> SpineBone::get_data() {
|
||||
SPINE_CHECK(bone, nullptr)
|
||||
auto &bone_data = bone->getData();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto &bone_data = spine_object->getData();
|
||||
Ref<SpineBoneData> bone_data_ref(memnew(SpineBoneData));
|
||||
bone_data_ref->set_spine_object(&bone_data);
|
||||
bone_data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &bone_data);
|
||||
return bone_data_ref;
|
||||
}
|
||||
|
||||
Ref<SpineSkeleton> SpineBone::get_skeleton() {
|
||||
SPINE_CHECK(bone, nullptr)
|
||||
auto &skeleton = bone->getSkeleton();
|
||||
Ref<SpineSkeleton> skeleton_ref(memnew(SpineSkeleton));
|
||||
skeleton_ref->set_spine_object(sprite, &skeleton);
|
||||
return skeleton_ref;
|
||||
}
|
||||
|
||||
Ref<SpineBone> SpineBone::get_parent() {
|
||||
SPINE_CHECK(bone, nullptr)
|
||||
auto parent = bone->getParent();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto parent = spine_object->getParent();
|
||||
if (!parent) return nullptr;
|
||||
Ref<SpineBone> parent_ref(memnew(SpineBone));
|
||||
parent_ref->set_spine_object(sprite, parent);
|
||||
parent_ref->set_spine_object(get_spine_owner(), parent);
|
||||
return parent_ref;
|
||||
}
|
||||
|
||||
Array SpineBone::get_children() {
|
||||
Array result;
|
||||
SPINE_CHECK(bone, result)
|
||||
auto children = bone->getChildren();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto children = spine_object->getChildren();
|
||||
result.resize((int)children.size());
|
||||
for (int i = 0; i < children.size(); ++i) {
|
||||
auto child = children[i];
|
||||
Ref<SpineBone> bone_ref(memnew(SpineBone));
|
||||
bone_ref->set_spine_object(sprite, child);
|
||||
bone_ref->set_spine_object(get_spine_owner(), child);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
float SpineBone::get_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getX();
|
||||
}
|
||||
|
||||
void SpineBone::set_x(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setX(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getY();
|
||||
}
|
||||
|
||||
void SpineBone::set_y(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setY(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_rotation() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getRotation();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getRotation();
|
||||
}
|
||||
|
||||
void SpineBone::set_rotation(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setRotation(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setRotation(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_scale_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getScaleX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getScaleX();
|
||||
}
|
||||
|
||||
void SpineBone::set_scale_x(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setScaleX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setScaleX(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_scale_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getScaleY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getScaleY();
|
||||
}
|
||||
|
||||
void SpineBone::set_scale_y(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setScaleY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setScaleY(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_shear_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getShearX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getShearX();
|
||||
}
|
||||
|
||||
void SpineBone::set_shear_x(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setShearX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setShearX(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_shear_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getShearY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getShearY();
|
||||
}
|
||||
|
||||
void SpineBone::set_shear_y(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setShearY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setShearY(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_applied_rotation() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getAppliedRotation();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAppliedRotation();
|
||||
}
|
||||
|
||||
void SpineBone::set_applied_rotation(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setAppliedRotation(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAppliedRotation(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_a_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getAX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAX();
|
||||
}
|
||||
|
||||
void SpineBone::set_a_x(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setAX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAX(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_a_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getAY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAY();
|
||||
}
|
||||
|
||||
void SpineBone::set_a_y(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setAY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAY(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_a_scale_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getAScaleX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAScaleX();
|
||||
}
|
||||
|
||||
void SpineBone::set_a_scale_x(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setAScaleX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAScaleX(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_a_scale_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getAScaleY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAScaleY();
|
||||
}
|
||||
|
||||
void SpineBone::set_a_scale_y(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setAScaleY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAScaleY(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_a_shear_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getAShearX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAShearX();
|
||||
}
|
||||
|
||||
void SpineBone::set_a_shear_x(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setAShearX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAShearX(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_a_shear_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getAShearY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAShearY();
|
||||
}
|
||||
|
||||
void SpineBone::set_a_shear_y(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setAShearY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAShearY(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_a() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getA();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getA();
|
||||
}
|
||||
|
||||
void SpineBone::set_a(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setA(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setA(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_b() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getB();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getB();
|
||||
}
|
||||
|
||||
void SpineBone::set_b(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setB(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setB(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_c() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getC();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getC();
|
||||
}
|
||||
|
||||
void SpineBone::set_c(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setC(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setC(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_d() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getD();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getD();
|
||||
}
|
||||
|
||||
void SpineBone::set_d(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setD(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setD(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_world_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldX();
|
||||
}
|
||||
|
||||
void SpineBone::set_world_x(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setWorldX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setWorldX(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_world_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldY();
|
||||
}
|
||||
|
||||
void SpineBone::set_world_y(float v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setWorldY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setWorldY(v);
|
||||
}
|
||||
|
||||
float SpineBone::get_world_rotation_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldRotationX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldRotationX();
|
||||
}
|
||||
|
||||
float SpineBone::get_world_rotation_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldRotationY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldRotationY();
|
||||
}
|
||||
|
||||
|
||||
float SpineBone::get_world_scale_x() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldScaleX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldScaleX();
|
||||
}
|
||||
|
||||
float SpineBone::get_world_scale_y() {
|
||||
SPINE_CHECK(bone, 0)
|
||||
return bone->getWorldScaleY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getWorldScaleY();
|
||||
}
|
||||
|
||||
bool SpineBone::is_active() {
|
||||
SPINE_CHECK(bone, false)
|
||||
return bone->isActive();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->isActive();
|
||||
}
|
||||
void SpineBone::set_active(bool v) {
|
||||
SPINE_CHECK(bone,)
|
||||
bone->setActive(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setActive(v);
|
||||
}
|
||||
|
||||
// External feature functions
|
||||
void SpineBone::apply_world_transform_2d(const Variant &o) {
|
||||
SPINE_CHECK(bone,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
if (o.get_type() == Variant::OBJECT) {
|
||||
auto node2d = Object::cast_to<Node2D>(o.operator Object*());
|
||||
if (node2d) {
|
||||
@ -440,7 +429,7 @@ void SpineBone::apply_world_transform_2d(const Variant &o) {
|
||||
}
|
||||
|
||||
Transform2D SpineBone::get_transform() {
|
||||
SPINE_CHECK(bone, Transform2D())
|
||||
SPINE_CHECK(spine_object, Transform2D())
|
||||
Transform2D transform;
|
||||
transform.rotate(Math::deg2rad(-get_rotation()));
|
||||
transform.scale(Size2(get_scale_x(), get_scale_y()));
|
||||
@ -449,7 +438,7 @@ Transform2D SpineBone::get_transform() {
|
||||
}
|
||||
|
||||
void SpineBone::set_transform(Transform2D transform) {
|
||||
SPINE_CHECK(bone,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
Vector2 position = transform.get_origin();
|
||||
position.y *= -1;
|
||||
float rotation = Math::rad2deg(-transform.get_rotation());
|
||||
@ -463,21 +452,21 @@ void SpineBone::set_transform(Transform2D transform) {
|
||||
}
|
||||
|
||||
Transform2D SpineBone::get_global_transform() {
|
||||
SPINE_CHECK(bone, Transform2D())
|
||||
if (!sprite) return get_transform();
|
||||
if (!sprite->is_visible_in_tree()) return get_transform();
|
||||
SPINE_CHECK(spine_object, Transform2D())
|
||||
if (!get_spine_owner()) return get_transform();
|
||||
if (!get_spine_owner()->is_visible_in_tree()) return get_transform();
|
||||
Transform2D local;
|
||||
local.rotate(Math::deg2rad(-get_world_rotation_x()));
|
||||
local.scale(Vector2(get_world_scale_x(), get_world_scale_y()));
|
||||
local.set_origin(Vector2(get_world_x(), -get_world_y()));
|
||||
return sprite->get_global_transform() * local;
|
||||
return get_spine_owner()->get_global_transform() * local;
|
||||
}
|
||||
|
||||
void SpineBone::set_global_transform(Transform2D transform) {
|
||||
SPINE_CHECK(bone,)
|
||||
if (!sprite) set_transform(transform);
|
||||
if (!sprite->is_visible_in_tree()) return;
|
||||
transform = sprite->get_global_transform().affine_inverse() * transform;
|
||||
SPINE_CHECK(spine_object,)
|
||||
if (!get_spine_owner()) set_transform(transform);
|
||||
if (!get_spine_owner()->is_visible_in_tree()) return;
|
||||
transform = get_spine_owner()->get_global_transform().affine_inverse() * transform;
|
||||
Vector2 position = transform.get_origin();
|
||||
position.y *= -1;
|
||||
float rotation = world_to_local_rotation(Math::rad2deg(-transform.get_rotation()));
|
||||
|
||||
@ -38,23 +38,13 @@
|
||||
class SpineSkeleton;
|
||||
class SpineSprite;
|
||||
|
||||
class SpineBone : public REFCOUNTED {
|
||||
class SpineBone : public REFCOUNTED, public SpineObjectWrapper<SpineSprite, spine::Bone> {
|
||||
GDCLASS(SpineBone, REFCOUNTED)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::Bone *bone;
|
||||
SpineSprite *sprite;
|
||||
|
||||
public:
|
||||
SpineBone();
|
||||
|
||||
void set_spine_object(SpineSprite *_sprite, spine::Bone *_bone) { sprite = _sprite; bone = _bone; }
|
||||
spine::Bone *get_spine_object() { return bone; }
|
||||
SpineSprite *get_spine_sprite() { return sprite; }
|
||||
|
||||
void update_world_transform();
|
||||
|
||||
void set_to_setup_pose();
|
||||
@ -75,8 +65,6 @@ public:
|
||||
|
||||
Ref<SpineBoneData> get_data();
|
||||
|
||||
Ref<SpineSkeleton> get_skeleton();
|
||||
|
||||
Ref<SpineBone> get_parent();
|
||||
|
||||
Array get_children();
|
||||
|
||||
@ -58,135 +58,132 @@ void SpineBoneData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_color", "v"), &SpineBoneData::set_color);
|
||||
}
|
||||
|
||||
SpineBoneData::SpineBoneData() : bone_data(nullptr) {
|
||||
}
|
||||
|
||||
int SpineBoneData::get_index() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getIndex();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getIndex();
|
||||
}
|
||||
|
||||
String SpineBoneData::get_bone_name() {
|
||||
SPINE_CHECK(bone_data, "")
|
||||
return bone_data->getName().buffer();
|
||||
SPINE_CHECK(spine_object, "")
|
||||
return spine_object->getName().buffer();
|
||||
}
|
||||
|
||||
Ref<SpineBoneData> SpineBoneData::get_parent() {
|
||||
SPINE_CHECK(bone_data, nullptr)
|
||||
auto parent = bone_data->getParent();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto parent = spine_object->getParent();
|
||||
if (!parent) return nullptr;
|
||||
Ref<SpineBoneData> parent_ref(memnew(SpineBoneData));
|
||||
parent_ref->set_spine_object(parent);
|
||||
parent_ref->set_spine_object(get_spine_owner(), parent);
|
||||
return parent_ref;
|
||||
}
|
||||
|
||||
float SpineBoneData::get_length() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getLength();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getLength();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_length(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setLength(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setLength(v);
|
||||
}
|
||||
|
||||
float SpineBoneData::get_x() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getX();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_x(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setX(v);
|
||||
}
|
||||
|
||||
float SpineBoneData::get_y() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getY();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_y(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setY(v);
|
||||
}
|
||||
|
||||
float SpineBoneData::get_rotation() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getRotation();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getRotation();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_rotation(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setRotation(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setRotation(v);
|
||||
}
|
||||
|
||||
float SpineBoneData::get_scale_x() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getScaleX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getScaleX();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_scale_x(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setScaleX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setScaleX(v);
|
||||
}
|
||||
|
||||
float SpineBoneData::get_scale_y() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getScaleY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getScaleY();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_scale_y(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setScaleY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setScaleY(v);
|
||||
}
|
||||
|
||||
float SpineBoneData::get_shear_x() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getShearX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getShearX();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_shear_x(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setShearX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setShearX(v);
|
||||
}
|
||||
|
||||
float SpineBoneData::get_shear_y() {
|
||||
SPINE_CHECK(bone_data, 0)
|
||||
return bone_data->getShearY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getShearY();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_shear_y(float v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setShearY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setShearY(v);
|
||||
}
|
||||
|
||||
SpineConstant::TransformMode SpineBoneData::get_transform_mode() {
|
||||
SPINE_CHECK(bone_data, SpineConstant::TransformMode::TransformMode_Normal)
|
||||
return (SpineConstant::TransformMode) bone_data->getTransformMode();
|
||||
SPINE_CHECK(spine_object, SpineConstant::TransformMode::TransformMode_Normal)
|
||||
return (SpineConstant::TransformMode) spine_object->getTransformMode();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_transform_mode(SpineConstant::TransformMode v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setTransformMode((spine::TransformMode) v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setTransformMode((spine::TransformMode) v);
|
||||
}
|
||||
|
||||
bool SpineBoneData::is_skin_required() {
|
||||
SPINE_CHECK(bone_data, false)
|
||||
return bone_data->isSkinRequired();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->isSkinRequired();
|
||||
}
|
||||
|
||||
void SpineBoneData::set_skin_required(bool v) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->setSkinRequired(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setSkinRequired(v);
|
||||
}
|
||||
|
||||
Color SpineBoneData::get_color() {
|
||||
SPINE_CHECK(bone_data, Color())
|
||||
auto color = bone_data->getColor();
|
||||
SPINE_CHECK(spine_object, Color())
|
||||
auto color = spine_object->getColor();
|
||||
return Color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void SpineBoneData::set_color(Color color) {
|
||||
SPINE_CHECK(bone_data,)
|
||||
bone_data->getColor().set(color.r, color.g, color.b, color.a);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->getColor().set(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
@ -34,22 +34,15 @@
|
||||
#include "SpineConstant.h"
|
||||
#include <spine/BoneData.h>
|
||||
|
||||
class SpineBoneData : public REFCOUNTED {
|
||||
GDCLASS(SpineBoneData, REFCOUNTED);
|
||||
class SpineSkeletonDataResource;
|
||||
|
||||
class SpineBoneData : public REFCOUNTED, public SpineObjectWrapper<SpineSkeletonDataResource, spine::BoneData> {
|
||||
GDCLASS(SpineBoneData, REFCOUNTED)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::BoneData *bone_data;
|
||||
|
||||
public:
|
||||
SpineBoneData();
|
||||
|
||||
void set_spine_object(spine::BoneData *_bone_data) { bone_data = _bone_data; }
|
||||
|
||||
spine::BoneData *get_spine_object() { return bone_data; }
|
||||
|
||||
int get_index();
|
||||
|
||||
String get_bone_name();
|
||||
|
||||
@ -52,6 +52,8 @@
|
||||
#define VARIANT_FLOAT Variant::REAL
|
||||
#endif
|
||||
|
||||
#include "SpineObjectWrapper.h"
|
||||
|
||||
#define SPINE_CHECK(obj, ret) \
|
||||
if (!(obj)) { \
|
||||
ERR_PRINT("Native Spine object not set."); \
|
||||
|
||||
@ -39,30 +39,27 @@ void SpineConstraintData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_skin_required", "v"), &SpineConstraintData::set_skin_required);
|
||||
}
|
||||
|
||||
SpineConstraintData::SpineConstraintData() : constraint_data(nullptr) {
|
||||
}
|
||||
|
||||
String SpineConstraintData::get_constraint_name() {
|
||||
SPINE_CHECK(constraint_data, "")
|
||||
return constraint_data->getName().buffer();
|
||||
SPINE_CHECK(spine_object, "")
|
||||
return spine_object->getName().buffer();
|
||||
}
|
||||
|
||||
int SpineConstraintData::get_order() {
|
||||
SPINE_CHECK(constraint_data, 0)
|
||||
return (int)constraint_data->getOrder();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return (int)spine_object->getOrder();
|
||||
}
|
||||
|
||||
void SpineConstraintData::set_order(int v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
constraint_data->setOrder(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setOrder(v);
|
||||
}
|
||||
|
||||
bool SpineConstraintData::is_skin_required() {
|
||||
SPINE_CHECK(constraint_data, false)
|
||||
return constraint_data->isSkinRequired();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->isSkinRequired();
|
||||
}
|
||||
|
||||
void SpineConstraintData::set_skin_required(bool v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
constraint_data->setSkinRequired(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setSkinRequired(v);
|
||||
}
|
||||
|
||||
@ -33,25 +33,15 @@
|
||||
#include "SpineCommon.h"
|
||||
#include <spine/ConstraintData.h>
|
||||
|
||||
class SpineConstraintData : public REFCOUNTED {
|
||||
GDCLASS(SpineConstraintData, REFCOUNTED);
|
||||
class SpineSkeletonDataResource;
|
||||
|
||||
class SpineConstraintData : public REFCOUNTED, public SpineObjectWrapper<SpineSkeletonDataResource, spine::ConstraintData> {
|
||||
GDCLASS(SpineConstraintData, REFCOUNTED)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
spine::ConstraintData *constraint_data;
|
||||
|
||||
public:
|
||||
SpineConstraintData();
|
||||
|
||||
void set_spine_object(spine::ConstraintData *_constraint_data) {
|
||||
constraint_data = _constraint_data;
|
||||
}
|
||||
|
||||
spine::ConstraintData *get_spine_object() {
|
||||
return constraint_data;
|
||||
}
|
||||
|
||||
String get_constraint_name();
|
||||
|
||||
int get_order();
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "SpineIkConstraint.h"
|
||||
#include "SpineBone.h"
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSprite.h"
|
||||
|
||||
void SpineIkConstraint::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("update"), &SpineIkConstraint::update);
|
||||
@ -52,109 +53,107 @@ void SpineIkConstraint::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineIkConstraint::set_active);
|
||||
}
|
||||
|
||||
SpineIkConstraint::SpineIkConstraint() : ik_constraint(nullptr), sprite(nullptr) {
|
||||
}
|
||||
|
||||
void SpineIkConstraint::update() {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->update();
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->update();
|
||||
}
|
||||
|
||||
int SpineIkConstraint::get_order() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getOrder();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getOrder();
|
||||
}
|
||||
|
||||
Ref<SpineIkConstraintData> SpineIkConstraint::get_data() {
|
||||
SPINE_CHECK(ik_constraint, nullptr)
|
||||
auto &ik_constraint_data = ik_constraint->getData();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto &ik_constraint_data = spine_object->getData();
|
||||
Ref<SpineIkConstraintData> ik_constraint_data_ref(memnew(SpineIkConstraintData));
|
||||
ik_constraint_data_ref->set_spine_object(&ik_constraint_data);
|
||||
ik_constraint_data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &ik_constraint_data);
|
||||
return ik_constraint_data_ref;
|
||||
}
|
||||
|
||||
Array SpineIkConstraint::get_bones() {
|
||||
Array result;
|
||||
SPINE_CHECK(ik_constraint, result)
|
||||
auto &bones = ik_constraint->getBones();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto &bones = spine_object->getBones();
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
auto bone = bones[i];
|
||||
Ref<SpineBone> bone_ref(memnew(SpineBone));
|
||||
bone_ref->set_spine_object(sprite, bone);
|
||||
bone_ref->set_spine_object(get_spine_owner(), bone);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Ref<SpineBone> SpineIkConstraint::get_target() {
|
||||
SPINE_CHECK(ik_constraint, nullptr)
|
||||
auto target = ik_constraint->getTarget();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto target = spine_object->getTarget();
|
||||
if (!target) return nullptr;
|
||||
Ref<SpineBone> target_ref(memnew(SpineBone));
|
||||
target_ref->set_spine_object(sprite, target);
|
||||
target_ref->set_spine_object(get_spine_owner(), target);
|
||||
return target_ref;
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_target(Ref<SpineBone> v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
int SpineIkConstraint::get_bend_direction() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getBendDirection();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getBendDirection();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_bend_direction(int v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setBendDirection(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setBendDirection(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraint::get_compress() {
|
||||
SPINE_CHECK(ik_constraint, false)
|
||||
return ik_constraint->getCompress();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->getCompress();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_compress(bool v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setCompress(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setCompress(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraint::get_stretch() {
|
||||
SPINE_CHECK(ik_constraint, false)
|
||||
return ik_constraint->getStretch();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->getStretch();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_stretch(bool v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setStretch(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setStretch(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraint::get_mix() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getMix();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMix();
|
||||
}
|
||||
void SpineIkConstraint::set_mix(float v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setMix(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMix(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraint::get_softness() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getSoftness();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getSoftness();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_softness(float v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setSoftness(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setSoftness(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraint::is_active() {
|
||||
SPINE_CHECK(ik_constraint, false)
|
||||
return ik_constraint->isActive();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->isActive();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_active(bool v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setActive(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setActive(v);
|
||||
}
|
||||
|
||||
@ -36,23 +36,13 @@
|
||||
class SpineBone;
|
||||
class SpineSprite;
|
||||
|
||||
class SpineIkConstraint : public REFCOUNTED {
|
||||
class SpineIkConstraint : public REFCOUNTED, public SpineObjectWrapper<SpineSprite, spine::IkConstraint> {
|
||||
GDCLASS(SpineIkConstraint, REFCOUNTED);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::IkConstraint *ik_constraint;
|
||||
SpineSprite *sprite;
|
||||
|
||||
public:
|
||||
SpineIkConstraint();
|
||||
|
||||
void set_spine_object(SpineSprite *_sprite, spine::IkConstraint *_ik_constraint) { sprite = _sprite; ik_constraint = _ik_constraint; }
|
||||
spine::IkConstraint *get_spine_object() { return ik_constraint; }
|
||||
SpineSprite *get_spine_sprite() { return sprite; }
|
||||
|
||||
void update();
|
||||
|
||||
int get_order();
|
||||
|
||||
@ -50,87 +50,87 @@ void SpineIkConstraintData::_bind_methods() {
|
||||
|
||||
Array SpineIkConstraintData::get_bones() {
|
||||
Array result;
|
||||
SPINE_CHECK(constraint_data, result)
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto bones = get_spine_constraint_data()->getBones();
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
|
||||
bone_ref->set_spine_object(bones[i]);
|
||||
bone_ref->set_spine_object(get_spine_owner(), bones[i]);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Ref<SpineBoneData> SpineIkConstraintData::get_target() {
|
||||
SPINE_CHECK(constraint_data, nullptr)
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto target = get_spine_constraint_data()->getTarget();
|
||||
if (!target) return nullptr;
|
||||
Ref<SpineBoneData> target_ref(memnew(SpineBoneData));
|
||||
target_ref->set_spine_object(target);
|
||||
target_ref->set_spine_object(get_spine_owner(), target);
|
||||
return target_ref;
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_target(Ref<SpineBoneData> v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
get_spine_constraint_data()->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
int SpineIkConstraintData::get_bend_direction() {
|
||||
SPINE_CHECK(constraint_data, 0)
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return get_spine_constraint_data()->getBendDirection();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_bend_direction(int v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
get_spine_constraint_data()->setBendDirection(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraintData::get_compress() {
|
||||
SPINE_CHECK(constraint_data, false)
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return get_spine_constraint_data()->getCompress();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_compress(bool v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
get_spine_constraint_data()->setCompress(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraintData::get_stretch() {
|
||||
SPINE_CHECK(constraint_data, false)
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return get_spine_constraint_data()->getStretch();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_stretch(bool v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
get_spine_constraint_data()->setStretch(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraintData::get_uniform() {
|
||||
SPINE_CHECK(constraint_data, false)
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return get_spine_constraint_data()->getUniform();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_uniform(bool v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
get_spine_constraint_data()->setUniform(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraintData::get_mix() {
|
||||
SPINE_CHECK(constraint_data, 0)
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return get_spine_constraint_data()->getMix();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_mix(float v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
get_spine_constraint_data()->setMix(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraintData::get_softness() {
|
||||
SPINE_CHECK(constraint_data, 0)
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return get_spine_constraint_data()->getSoftness();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_softness(float v) {
|
||||
SPINE_CHECK(constraint_data,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
get_spine_constraint_data()->setSoftness(v);
|
||||
}
|
||||
|
||||
@ -31,19 +31,24 @@
|
||||
#define GODOT_SPINEOBJECTWRAPPER_H
|
||||
|
||||
template <typename OWNER, typename OBJECT> class SpineObjectWrapper {
|
||||
protected:
|
||||
Object *owner;
|
||||
OBJECT *object;
|
||||
OBJECT *spine_object;
|
||||
|
||||
public:
|
||||
SpineObjectWrapper(): owner(nullptr), object(nullptr) {};
|
||||
SpineObjectWrapper(): owner(nullptr), spine_object(nullptr) {};
|
||||
|
||||
void set_spine_object(OWNER *_owner, OBJECT *_object) {
|
||||
void set_spine_object(const OWNER *_owner, OBJECT *_object) {
|
||||
if (!_owner) {
|
||||
ERR_PRINT("Owner must not be null.");
|
||||
return;
|
||||
}
|
||||
owner = (Object*)_owner;
|
||||
object = _object;
|
||||
spine_object = _object;
|
||||
}
|
||||
|
||||
OBJECT *get_spine_object() {
|
||||
return object;
|
||||
return spine_object;
|
||||
}
|
||||
|
||||
OWNER *get_spine_owner() {
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "SpinePathConstraint.h"
|
||||
#include "SpineBone.h"
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSprite.h"
|
||||
|
||||
void SpinePathConstraint::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("update"), &SpinePathConstraint::update);
|
||||
@ -52,111 +53,108 @@ void SpinePathConstraint::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpinePathConstraint::set_active);
|
||||
}
|
||||
|
||||
SpinePathConstraint::SpinePathConstraint() : path_constraint(nullptr), sprite(nullptr) {
|
||||
}
|
||||
|
||||
void SpinePathConstraint::update() {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->update();
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->update();
|
||||
}
|
||||
|
||||
int SpinePathConstraint::get_order() {
|
||||
SPINE_CHECK(path_constraint, 0)
|
||||
return path_constraint->getOrder();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getOrder();
|
||||
}
|
||||
|
||||
float SpinePathConstraint::get_position() {
|
||||
SPINE_CHECK(path_constraint, 0)
|
||||
return path_constraint->getPosition();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getPosition();
|
||||
}
|
||||
|
||||
void SpinePathConstraint::set_position(float v) {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->setPosition(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setPosition(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraint::get_spacing() {
|
||||
SPINE_CHECK(path_constraint, 0)
|
||||
return path_constraint->getSpacing();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getSpacing();
|
||||
}
|
||||
|
||||
void SpinePathConstraint::set_spacing(float v) {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->setSpacing(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setSpacing(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraint::get_mix_rotate() {
|
||||
SPINE_CHECK(path_constraint, 0)
|
||||
return path_constraint->getMixRotate();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixRotate();
|
||||
}
|
||||
|
||||
void SpinePathConstraint::set_mix_rotate(float v) {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->setMixRotate(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixRotate(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraint::get_mix_x() {
|
||||
SPINE_CHECK(path_constraint, 0)
|
||||
return path_constraint->getMixX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixX();
|
||||
}
|
||||
|
||||
void SpinePathConstraint::set_mix_x(float v) {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->setMixX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixX(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraint::get_mix_y() {
|
||||
SPINE_CHECK(path_constraint, 0)
|
||||
return path_constraint->getMixY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixY();
|
||||
}
|
||||
|
||||
void SpinePathConstraint::set_mix_y(float v) {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->setMixY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixY(v);
|
||||
}
|
||||
|
||||
Array SpinePathConstraint::get_bones() {
|
||||
Array result;
|
||||
SPINE_CHECK(path_constraint, result)
|
||||
auto &bones = path_constraint->getBones();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto &bones = spine_object->getBones();
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
auto bone = bones[i];
|
||||
Ref<SpineBone> bone_ref(memnew(SpineBone));
|
||||
bone_ref->set_spine_object(sprite, bone);
|
||||
bone_ref->set_spine_object(get_spine_owner(), bone);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Ref<SpineSlot> SpinePathConstraint::get_target() {
|
||||
SPINE_CHECK(path_constraint, nullptr)
|
||||
auto target = path_constraint->getTarget();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto target = spine_object->getTarget();
|
||||
if (!target) return nullptr;
|
||||
Ref<SpineSlot> target_ref(memnew(SpineSlot));
|
||||
target_ref->set_spine_object(sprite, target);
|
||||
target_ref->set_spine_object(get_spine_owner(), target);
|
||||
return target_ref;
|
||||
}
|
||||
|
||||
void SpinePathConstraint::set_target(Ref<SpineSlot> v) {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
Ref<SpinePathConstraintData> SpinePathConstraint::get_data() {
|
||||
SPINE_CHECK(path_constraint, nullptr)
|
||||
auto &data = path_constraint->getData();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto &data = spine_object->getData();
|
||||
Ref<SpinePathConstraintData> data_ref(memnew(SpinePathConstraintData));
|
||||
data_ref->set_spine_object(&data);
|
||||
data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &data);
|
||||
return data_ref;
|
||||
}
|
||||
|
||||
bool SpinePathConstraint::is_active() {
|
||||
SPINE_CHECK(path_constraint, false)
|
||||
return path_constraint->isActive();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->isActive();
|
||||
}
|
||||
|
||||
void SpinePathConstraint::set_active(bool v) {
|
||||
SPINE_CHECK(path_constraint,)
|
||||
path_constraint->setActive(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setActive(v);
|
||||
}
|
||||
|
||||
@ -34,23 +34,13 @@
|
||||
#include "SpineSlot.h"
|
||||
#include <spine/PathConstraint.h>
|
||||
|
||||
class SpinePathConstraint : public REFCOUNTED {
|
||||
class SpinePathConstraint : public REFCOUNTED, public SpineObjectWrapper<SpineSprite, spine::PathConstraint> {
|
||||
GDCLASS(SpinePathConstraint, REFCOUNTED);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::PathConstraint *path_constraint;
|
||||
SpineSprite *sprite;
|
||||
|
||||
public:
|
||||
SpinePathConstraint();
|
||||
|
||||
void set_spine_object(SpineSprite *_sprite, spine::PathConstraint *_path_constraint) { sprite = _sprite; path_constraint = _path_constraint; }
|
||||
spine::PathConstraint *get_spine_object() { return path_constraint; }
|
||||
SpineSprite *get_spine_sprite() { return sprite; }
|
||||
|
||||
void update();
|
||||
|
||||
int get_order();
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
#include "SpinePathConstraintData.h"
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSkeletonDataResource.h"
|
||||
|
||||
void SpinePathConstraintData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_bones"), &SpinePathConstraintData::get_bones);
|
||||
@ -61,7 +62,7 @@ Array SpinePathConstraintData::get_bones() {
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
|
||||
bone_ref->set_spine_object(bones[i]);
|
||||
bone_ref->set_spine_object(get_spine_owner(), bones[i]);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
@ -72,7 +73,7 @@ Ref<SpineSlotData> SpinePathConstraintData::get_target() {
|
||||
auto slot = get_spine_constraint_data()->getTarget();
|
||||
if (!slot) return nullptr;
|
||||
Ref<SpineSlotData> slot_ref(memnew(SpineSlotData));
|
||||
slot_ref->set_spine_object(slot);
|
||||
slot_ref->set_spine_object(get_spine_owner(), slot);
|
||||
return slot_ref;
|
||||
}
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
#include "SpineSkeleton.h"
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSprite.h"
|
||||
|
||||
void SpineSkeleton::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineSkeleton::update_world_transform);
|
||||
@ -68,23 +69,23 @@ void SpineSkeleton::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_scale_y", "v"), &SpineSkeleton::set_scale_y);
|
||||
}
|
||||
|
||||
SpineSkeleton::SpineSkeleton() : skeleton(nullptr), sprite(nullptr), skeleton_data_res(nullptr) {
|
||||
SpineSkeleton::SpineSkeleton() : skeleton(nullptr), sprite(nullptr) {
|
||||
}
|
||||
|
||||
SpineSkeleton::~SpineSkeleton() {
|
||||
delete skeleton;
|
||||
}
|
||||
|
||||
void SpineSkeleton::set_skeleton_data_res(Ref<SpineSkeletonDataResource> data_res) {
|
||||
void SpineSkeleton::set_spine_sprite(SpineSprite *sprite) {
|
||||
delete skeleton;
|
||||
skeleton = nullptr;
|
||||
skeleton_data_res = data_res;
|
||||
if (!data_res.is_valid() || !data_res->is_skeleton_data_loaded()) return;
|
||||
skeleton = new spine::Skeleton(data_res->get_skeleton_data());
|
||||
if (!sprite || !sprite->get_skeleton_data_res().is_valid() || !sprite->get_skeleton_data_res()->is_skeleton_data_loaded()) return;
|
||||
skeleton = new spine::Skeleton(sprite->get_skeleton_data_res()->get_skeleton_data());
|
||||
}
|
||||
|
||||
Ref<SpineSkeletonDataResource> SpineSkeleton::get_skeleton_data_res() const {
|
||||
return skeleton_data_res;
|
||||
if (!sprite) return nullptr;
|
||||
return sprite->get_skeleton();
|
||||
}
|
||||
|
||||
void SpineSkeleton::update_world_transform() {
|
||||
@ -142,7 +143,7 @@ Ref<SpineAttachment> SpineSkeleton::get_attachment_by_slot_name(const String &sl
|
||||
auto attachment = skeleton->getAttachment(SPINE_STRING(slot_name), SPINE_STRING(attachment_name));
|
||||
if (!attachment) return nullptr;
|
||||
Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
|
||||
attachment_ref->set_spine_object(attachment);
|
||||
attachment_ref->set_spine_object(*sprite->get_skeleton_data_res(), attachment);
|
||||
return attachment_ref;
|
||||
}
|
||||
|
||||
@ -151,7 +152,7 @@ Ref<SpineAttachment> SpineSkeleton::get_attachment_by_slot_index(int slot_index,
|
||||
auto attachment = skeleton->getAttachment(slot_index, SPINE_STRING(attachment_name));
|
||||
if (!attachment) return nullptr;
|
||||
Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
|
||||
attachment_ref->set_spine_object(attachment);
|
||||
attachment_ref->set_spine_object(*sprite->get_skeleton_data_res(), attachment);
|
||||
return attachment_ref;
|
||||
}
|
||||
|
||||
@ -294,7 +295,7 @@ Ref<SpineSkin> SpineSkeleton::get_skin() {
|
||||
auto skin = skeleton->getSkin();
|
||||
if (!skin) return nullptr;
|
||||
Ref<SpineSkin> skin_ref(memnew(SpineSkin));
|
||||
skin_ref->set_spine_object(skin);
|
||||
skin_ref->set_spine_object(*sprite->get_skeleton_data_res(), skin);
|
||||
return skin_ref;
|
||||
}
|
||||
|
||||
|
||||
@ -55,18 +55,13 @@ class SpineSkeleton : public REFCOUNTED {
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void set_skeleton_data_res(Ref<SpineSkeletonDataResource> data_res);
|
||||
Ref<SpineSkeletonDataResource> get_skeleton_data_res() const;
|
||||
|
||||
void set_spine_object(SpineSprite *_sprite, spine::Skeleton *_skeleton) { sprite = _sprite; skeleton = _skeleton; }
|
||||
void set_spine_sprite(SpineSprite *sprite);
|
||||
spine::Skeleton *get_spine_object() { return skeleton; }
|
||||
void set_spine_sprite(SpineSprite *_sprite) { sprite = _sprite; }
|
||||
SpineSprite *get_spine_sprite() { return sprite; }
|
||||
Ref<SpineSkeletonDataResource> get_skeleton_data_res() const;
|
||||
|
||||
private:
|
||||
spine::Skeleton *skeleton;
|
||||
SpineSprite *sprite;
|
||||
Ref<SpineSkeletonDataResource> skeleton_data_res;
|
||||
spine::Vector<float> bounds_vertex_buffer;
|
||||
|
||||
public:
|
||||
|
||||
@ -285,7 +285,7 @@ Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &anim
|
||||
auto animation = skeleton_data->findAnimation(SPINE_STRING(animation_name));
|
||||
if (!animation) return nullptr;
|
||||
Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
|
||||
animation_ref->set_spine_object(animation);
|
||||
animation_ref->set_spine_object(this, animation);
|
||||
return animation_ref;
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ Ref<SpineBoneData> SpineSkeletonDataResource::find_bone(const String &bone_name)
|
||||
auto bone = skeleton_data->findBone(SPINE_STRING(bone_name));
|
||||
if (!bone) return nullptr;
|
||||
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
|
||||
bone_ref->set_spine_object(bone);
|
||||
bone_ref->set_spine_object(this, bone);
|
||||
return bone_ref;
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ Ref<SpineSlotData> SpineSkeletonDataResource::find_slot(const String &slot_name)
|
||||
auto slot = skeleton_data->findSlot(SPINE_STRING(slot_name));
|
||||
if (!slot) return nullptr;
|
||||
Ref<SpineSlotData> slot_ref(memnew(SpineSlotData));
|
||||
slot_ref->set_spine_object(slot);
|
||||
slot_ref->set_spine_object(this, slot);
|
||||
return slot_ref;
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ Ref<SpineSkin> SpineSkeletonDataResource::find_skin(const String &skin_name) con
|
||||
auto skin = skeleton_data->findSkin(SPINE_STRING(skin_name));
|
||||
if (!skin) return nullptr;
|
||||
Ref<SpineSkin> skin_ref(memnew(SpineSkin));
|
||||
skin_ref->set_spine_object(skin);
|
||||
skin_ref->set_spine_object(this, skin);
|
||||
return skin_ref;
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ Ref<SpineIkConstraintData> SpineSkeletonDataResource::find_ik_constraint(const S
|
||||
auto constraint = skeleton_data->findIkConstraint(SPINE_STRING(constraint_name));
|
||||
if (!constraint) return nullptr;
|
||||
Ref<SpineIkConstraintData> constraint_ref(memnew(SpineIkConstraintData));
|
||||
constraint_ref->set_spine_object(constraint);
|
||||
constraint_ref->set_spine_object(this, constraint);
|
||||
return constraint_ref;
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ Ref<SpineTransformConstraintData> SpineSkeletonDataResource::find_transform_cons
|
||||
auto constraint = skeleton_data->findTransformConstraint(SPINE_STRING(constraint_name));
|
||||
if (!constraint) return nullptr;
|
||||
Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData));
|
||||
constraint_ref->set_spine_object(constraint);
|
||||
constraint_ref->set_spine_object(this, constraint);
|
||||
return constraint_ref;
|
||||
}
|
||||
Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(const String &constraint_name) const {
|
||||
@ -354,7 +354,7 @@ Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(con
|
||||
auto constraint = skeleton_data->findPathConstraint(SPINE_STRING(constraint_name));
|
||||
if (constraint == nullptr) return nullptr;
|
||||
Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData));
|
||||
constraint_ref->set_spine_object(constraint);
|
||||
constraint_ref->set_spine_object(this, constraint);
|
||||
return constraint_ref;
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ Array SpineSkeletonDataResource::get_bones() const {
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
|
||||
bone_ref->set_spine_object(bones[i]);
|
||||
bone_ref->set_spine_object(this, bones[i]);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
@ -383,7 +383,7 @@ Array SpineSkeletonDataResource::get_slots() const {
|
||||
result.resize((int)slots.size());
|
||||
for (int i = 0; i < slots.size(); ++i) {
|
||||
Ref<SpineSlotData> slot_ref(memnew(SpineSlotData));
|
||||
slot_ref->set_spine_object(slots[i]);
|
||||
slot_ref->set_spine_object(this, slots[i]);
|
||||
result[i] = slot_ref;
|
||||
}
|
||||
return result;
|
||||
@ -396,7 +396,7 @@ Array SpineSkeletonDataResource::get_skins() const {
|
||||
result.resize((int)skins.size());
|
||||
for (int i = 0; i < skins.size(); ++i) {
|
||||
Ref<SpineSkin> skin_ref(memnew(SpineSkin));
|
||||
skin_ref->set_spine_object(skins[i]);
|
||||
skin_ref->set_spine_object(this, skins[i]);
|
||||
result[i] = skin_ref;
|
||||
}
|
||||
return result;
|
||||
@ -407,7 +407,7 @@ Ref<SpineSkin> SpineSkeletonDataResource::get_default_skin() const {
|
||||
auto skin = skeleton_data->getDefaultSkin();
|
||||
if (skin) return nullptr;
|
||||
Ref<SpineSkin> skin_ref(memnew(SpineSkin));
|
||||
skin_ref->set_spine_object(skin);
|
||||
skin_ref->set_spine_object(this, skin);
|
||||
return skin_ref;
|
||||
}
|
||||
|
||||
@ -436,7 +436,7 @@ Array SpineSkeletonDataResource::get_animations() const {
|
||||
result.resize((int)animations.size());
|
||||
for (int i = 0; i < animations.size(); ++i) {
|
||||
Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
|
||||
animation_ref->set_spine_object(animations[i]);
|
||||
animation_ref->set_spine_object(this, animations[i]);
|
||||
result[i] = animation_ref;
|
||||
}
|
||||
return result;
|
||||
@ -449,7 +449,7 @@ Array SpineSkeletonDataResource::get_ik_constraints() const {
|
||||
result.resize((int)constraints.size());
|
||||
for (int i = 0; i < constraints.size(); ++i) {
|
||||
Ref<SpineIkConstraintData> constraint_ref(memnew(SpineIkConstraintData));
|
||||
constraint_ref->set_spine_object(constraints[i]);
|
||||
constraint_ref->set_spine_object(this, constraints[i]);
|
||||
result[i] = constraint_ref;
|
||||
}
|
||||
return result;
|
||||
@ -462,7 +462,7 @@ Array SpineSkeletonDataResource::get_transform_constraints() const {
|
||||
result.resize((int)constraints.size());
|
||||
for (int i = 0; i < constraints.size(); ++i) {
|
||||
Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData));
|
||||
constraint_ref->set_spine_object(constraints[i]);
|
||||
constraint_ref->set_spine_object(this, constraints[i]);
|
||||
result[i] = constraint_ref;
|
||||
}
|
||||
return result;
|
||||
@ -475,7 +475,7 @@ Array SpineSkeletonDataResource::get_path_constraints() const {
|
||||
result.resize((int)constraints.size());
|
||||
for (int i = 0; i < constraints.size(); ++i) {
|
||||
Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData));
|
||||
constraint_ref->set_spine_object(constraints[i]);
|
||||
constraint_ref->set_spine_object(this, constraints[i]);
|
||||
result[i] = constraint_ref;
|
||||
}
|
||||
return result;
|
||||
|
||||
@ -31,9 +31,9 @@
|
||||
#include "SpineBoneData.h"
|
||||
#include "SpineConstraintData.h"
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSprite.h"
|
||||
|
||||
void SpineSkin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("init", "name"), &SpineSkin::init);
|
||||
ClassDB::bind_method(D_METHOD("set_attachment", "slot_index", "name", "attachment"), &SpineSkin::set_attachment);
|
||||
ClassDB::bind_method(D_METHOD("get_attachment", "slot_index", "name"), &SpineSkin::get_attachment);
|
||||
ClassDB::bind_method(D_METHOD("remove_attachment", "slot_index", "name"), &SpineSkin::remove_attachment);
|
||||
@ -47,47 +47,54 @@ void SpineSkin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_constraints"), &SpineSkin::get_constraints);
|
||||
}
|
||||
|
||||
SpineSkin::SpineSkin() : skin(nullptr), owns_skin(false) {
|
||||
SpineSkin::SpineSkin() : owns_skin(false) {
|
||||
}
|
||||
|
||||
SpineSkin::~SpineSkin() {
|
||||
if (owns_skin) delete skin;
|
||||
if (owns_skin) delete spine_object;
|
||||
}
|
||||
|
||||
Ref<SpineSkin> SpineSkin::init(const String &name) {
|
||||
if (skin) {
|
||||
Ref<SpineSkin> SpineSkin::init(const String &name, SpineSprite *sprite) {
|
||||
if (spine_object) {
|
||||
ERR_PRINT("Can not initialize an already initialized skin.");
|
||||
return this;
|
||||
}
|
||||
if (!sprite) {
|
||||
ERR_PRINT("Must provide a valid SpineSprite.");
|
||||
return this;
|
||||
}
|
||||
if (!sprite->get_skeleton_data_res().is_valid() || !sprite->get_skeleton_data_res()->is_skeleton_data_loaded()) {
|
||||
ERR_PRINT("SpineSkeletonDataResource on SpineSprite must be valid and loaded.");
|
||||
}
|
||||
owns_skin = true;
|
||||
skin = new spine::Skin(SPINE_STRING(name));
|
||||
set_spine_object(*sprite->get_skeleton_data_res(), new spine::Skin(SPINE_STRING(name)));
|
||||
return this;
|
||||
}
|
||||
|
||||
void SpineSkin::set_attachment(int slot_index, const String &name, Ref<SpineAttachment> attachment) {
|
||||
SPINE_CHECK(skin,)
|
||||
skin->setAttachment(slot_index, SPINE_STRING(name), attachment.is_valid() ? attachment->get_spine_object() : nullptr);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAttachment(slot_index, SPINE_STRING(name), attachment.is_valid() ? attachment->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
Ref<SpineAttachment> SpineSkin::get_attachment(int slot_index, const String &name) {
|
||||
SPINE_CHECK(skin, nullptr)
|
||||
auto attachment = skin->getAttachment(slot_index, SPINE_STRING(name));
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto attachment = spine_object->getAttachment(slot_index, SPINE_STRING(name));
|
||||
if (attachment) return nullptr;
|
||||
Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
|
||||
attachment_ref->set_spine_object(attachment);
|
||||
attachment_ref->set_spine_object(get_spine_owner(), attachment);
|
||||
return attachment_ref;
|
||||
}
|
||||
|
||||
void SpineSkin::remove_attachment(int slot_index, const String &name) {
|
||||
SPINE_CHECK(skin,)
|
||||
skin->removeAttachment(slot_index, SPINE_STRING(name));
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->removeAttachment(slot_index, SPINE_STRING(name));
|
||||
}
|
||||
|
||||
Array SpineSkin::find_names_for_slot(int slot_index) {
|
||||
Array result;
|
||||
SPINE_CHECK(skin, result)
|
||||
SPINE_CHECK(spine_object, result)
|
||||
spine::Vector<spine::String> names;
|
||||
skin->findNamesForSlot(slot_index, names);
|
||||
spine_object->findNamesForSlot(slot_index, names);
|
||||
result.resize((int)names.size());
|
||||
for (int i = 0; i < names.size(); ++i) {
|
||||
result[i] = names[i].buffer();
|
||||
@ -97,16 +104,16 @@ Array SpineSkin::find_names_for_slot(int slot_index) {
|
||||
|
||||
Array SpineSkin::find_attachments_for_slot(int slot_index) {
|
||||
Array result;
|
||||
SPINE_CHECK(skin, result)
|
||||
SPINE_CHECK(spine_object, result)
|
||||
spine::Vector<spine::Attachment *> attachments;
|
||||
skin->findAttachmentsForSlot(slot_index, attachments);
|
||||
spine_object->findAttachmentsForSlot(slot_index, attachments);
|
||||
result.resize((int)attachments.size());
|
||||
for (int i = 0; i < attachments.size(); ++i) {
|
||||
if (!attachments[i]) {
|
||||
result[i] = Ref<SpineAttachment>(nullptr);
|
||||
} else {
|
||||
Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
|
||||
attachment_ref->set_spine_object(attachments[i]);
|
||||
attachment_ref->set_spine_object(get_spine_owner(), attachments[i]);
|
||||
result[i] = attachment_ref;
|
||||
}
|
||||
}
|
||||
@ -114,39 +121,39 @@ Array SpineSkin::find_attachments_for_slot(int slot_index) {
|
||||
}
|
||||
|
||||
String SpineSkin::get_name() {
|
||||
SPINE_CHECK(skin, "")
|
||||
return skin->getName().buffer();
|
||||
SPINE_CHECK(spine_object, "")
|
||||
return spine_object->getName().buffer();
|
||||
}
|
||||
|
||||
void SpineSkin::add_skin(Ref<SpineSkin> other) {
|
||||
SPINE_CHECK(skin,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
if (!other.is_valid() || !other->get_spine_object()) {
|
||||
ERR_PRINT("other is not a valid SpineSkin.");
|
||||
return;
|
||||
}
|
||||
skin->addSkin(other->get_spine_object());
|
||||
spine_object->addSkin(other->get_spine_object());
|
||||
}
|
||||
|
||||
void SpineSkin::copy_skin(Ref<SpineSkin> other) {
|
||||
SPINE_CHECK(skin,)
|
||||
SPINE_CHECK(spine_object,)
|
||||
if (!other.is_valid() || !other->get_spine_object()) {
|
||||
ERR_PRINT("other is not a valid SpineSkin.");
|
||||
return;
|
||||
}
|
||||
skin->copySkin(other->get_spine_object());
|
||||
spine_object->copySkin(other->get_spine_object());
|
||||
}
|
||||
|
||||
Array SpineSkin::get_attachments() {
|
||||
Array result;
|
||||
SPINE_CHECK(skin, result)
|
||||
auto entries = skin->getAttachments();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto entries = spine_object->getAttachments();
|
||||
while(entries.hasNext()) {
|
||||
spine::Skin::AttachmentMap::Entry &entry = entries.next();
|
||||
Ref<SpineSkinEntry> entry_ref = memnew(SpineSkinEntry);
|
||||
Ref<SpineAttachment> attachment_ref = nullptr;
|
||||
if (entry._attachment) {
|
||||
attachment_ref = Ref<SpineAttachment>(memnew(SpineAttachment));
|
||||
attachment_ref->set_spine_object(entry._attachment);
|
||||
attachment_ref->set_spine_object(get_spine_owner(), entry._attachment);
|
||||
}
|
||||
entry_ref->init(entry._slotIndex, entry._name.buffer(), attachment_ref);
|
||||
result.push_back(entry_ref);
|
||||
@ -156,12 +163,12 @@ Array SpineSkin::get_attachments() {
|
||||
|
||||
Array SpineSkin::get_bones() {
|
||||
Array result;
|
||||
SPINE_CHECK(skin, result)
|
||||
auto bones = skin->getBones();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto bones = spine_object->getBones();
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
|
||||
bone_ref->set_spine_object(bones[i]);
|
||||
bone_ref->set_spine_object(get_spine_owner(), bones[i]);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
@ -169,12 +176,12 @@ Array SpineSkin::get_bones() {
|
||||
|
||||
Array SpineSkin::get_constraints() {
|
||||
Array result;
|
||||
SPINE_CHECK(skin, result)
|
||||
auto constraints = skin->getConstraints();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto constraints = spine_object->getConstraints();
|
||||
result.resize((int)constraints.size());
|
||||
for (int i = 0; i < constraints.size(); ++i) {
|
||||
Ref<SpineConstraintData> constraint_ref(memnew(SpineConstraintData));
|
||||
constraint_ref->set_spine_object(constraints[i]);
|
||||
constraint_ref->set_spine_object(get_spine_owner(), constraints[i]);
|
||||
result[i] = constraint_ref;
|
||||
}
|
||||
return result;
|
||||
|
||||
@ -33,24 +33,23 @@
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineAttachment.h"
|
||||
|
||||
class SpineSkin : public REFCOUNTED {
|
||||
class SpineSkeletonDataResource;
|
||||
class SpineSprite;
|
||||
|
||||
class SpineSkin : public REFCOUNTED, public SpineObjectWrapper<SpineSkeletonDataResource, spine::Skin> {
|
||||
GDCLASS(SpineSkin, REFCOUNTED);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::Skin *skin;
|
||||
bool owns_skin;
|
||||
|
||||
public:
|
||||
SpineSkin();
|
||||
~SpineSkin() override;
|
||||
|
||||
void set_spine_object(spine::Skin *s) { skin = s; }
|
||||
spine::Skin *get_spine_object() { return skin; }
|
||||
|
||||
Ref<SpineSkin> init(const String &name);
|
||||
Ref<SpineSkin> init(const String &name, SpineSprite *sprite);
|
||||
|
||||
void set_attachment(int slot_index, const String &name, Ref<SpineAttachment> attachment);
|
||||
|
||||
|
||||
@ -29,14 +29,14 @@
|
||||
|
||||
#include "SpineSlot.h"
|
||||
#include "SpineBone.h"
|
||||
#include "SpineSkeleton.h"
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSprite.h"
|
||||
#include "SpineSkeletonDataResource.h"
|
||||
|
||||
void SpineSlot::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineSlot::set_to_setup_pose);
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &SpineSlot::get_data);
|
||||
ClassDB::bind_method(D_METHOD("get_bone"), &SpineSlot::get_bone);
|
||||
ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineSlot::get_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("get_color"), &SpineSlot::get_color);
|
||||
ClassDB::bind_method(D_METHOD("set_color"), &SpineSlot::set_color);
|
||||
ClassDB::bind_method(D_METHOD("get_dark_color"), &SpineSlot::get_dark_color);
|
||||
@ -52,105 +52,94 @@ void SpineSlot::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_sequence_index", "v"), &SpineSlot::set_sequence_index);
|
||||
}
|
||||
|
||||
SpineSlot::SpineSlot() : slot(nullptr), sprite(nullptr) {
|
||||
}
|
||||
|
||||
void SpineSlot::set_to_setup_pose() {
|
||||
SPINE_CHECK(slot,)
|
||||
slot->setToSetupPose();
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setToSetupPose();
|
||||
}
|
||||
|
||||
Ref<SpineSlotData> SpineSlot::get_data() {
|
||||
SPINE_CHECK(slot, nullptr)
|
||||
auto &slot_data = slot->getData();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto &slot_data = spine_object->getData();
|
||||
Ref<SpineSlotData> slot_data_ref(memnew(SpineSlotData));
|
||||
slot_data_ref->set_spine_object(&slot_data);
|
||||
slot_data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &slot_data);
|
||||
return slot_data_ref;
|
||||
}
|
||||
|
||||
Ref<SpineBone> SpineSlot::get_bone() {
|
||||
SPINE_CHECK(slot, nullptr)
|
||||
auto &bone = slot->getBone();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto &bone = spine_object->getBone();
|
||||
Ref<SpineBone> bone_ref(memnew(SpineBone));
|
||||
bone_ref->set_spine_object(sprite, &bone);
|
||||
bone_ref->set_spine_object(get_spine_owner(), &bone);
|
||||
return bone_ref;
|
||||
}
|
||||
|
||||
Ref<SpineSkeleton> SpineSlot::get_skeleton() {
|
||||
SPINE_CHECK(slot, nullptr)
|
||||
auto &skeleton = slot->getSkeleton();
|
||||
Ref<SpineSkeleton> skeleton_ref(memnew(SpineSkeleton));
|
||||
skeleton_ref->set_spine_object(sprite, &skeleton);
|
||||
return skeleton_ref;
|
||||
}
|
||||
|
||||
Color SpineSlot::get_color() {
|
||||
SPINE_CHECK(slot, Color(0, 0, 0, 0))
|
||||
auto &color = slot->getColor();
|
||||
SPINE_CHECK(spine_object, Color(0, 0, 0, 0))
|
||||
auto &color = spine_object->getColor();
|
||||
return Color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void SpineSlot::set_color(Color v) {
|
||||
SPINE_CHECK(slot,)
|
||||
auto &color = slot->getColor();
|
||||
SPINE_CHECK(spine_object,)
|
||||
auto &color = spine_object->getColor();
|
||||
color.set(v.r, v.g, v.b, v.a);
|
||||
}
|
||||
|
||||
Color SpineSlot::get_dark_color() {
|
||||
SPINE_CHECK(slot, Color(0, 0, 0, 0))
|
||||
auto &color = slot->getDarkColor();
|
||||
SPINE_CHECK(spine_object, Color(0, 0, 0, 0))
|
||||
auto &color = spine_object->getDarkColor();
|
||||
return Color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void SpineSlot::set_dark_color(Color v) {
|
||||
SPINE_CHECK(slot,)
|
||||
auto &color = slot->getDarkColor();
|
||||
SPINE_CHECK(spine_object,)
|
||||
auto &color = spine_object->getDarkColor();
|
||||
color.set(v.r, v.g, v.b, v.a);
|
||||
}
|
||||
|
||||
bool SpineSlot::has_dark_color() {
|
||||
SPINE_CHECK(slot, false)
|
||||
return slot->hasDarkColor();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->hasDarkColor();
|
||||
}
|
||||
|
||||
Ref<SpineAttachment> SpineSlot::get_attachment() {
|
||||
SPINE_CHECK(slot, nullptr)
|
||||
auto attachment = slot->getAttachment();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto attachment = spine_object->getAttachment();
|
||||
if (!attachment) return nullptr;
|
||||
Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
|
||||
attachment_ref->set_spine_object(attachment);
|
||||
attachment_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), attachment);
|
||||
return attachment_ref;
|
||||
}
|
||||
|
||||
void SpineSlot::set_attachment(Ref<SpineAttachment> v) {
|
||||
SPINE_CHECK(slot,)
|
||||
slot->setAttachment(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAttachment(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
int SpineSlot::get_attachment_state() {
|
||||
SPINE_CHECK(slot, 0)
|
||||
return slot->getAttachmentState();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAttachmentState();
|
||||
}
|
||||
|
||||
void SpineSlot::set_attachment_state(int v) {
|
||||
SPINE_CHECK(slot,)
|
||||
slot->setAttachmentState(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAttachmentState(v);
|
||||
}
|
||||
|
||||
Array SpineSlot::get_deform() {
|
||||
Array result;
|
||||
SPINE_CHECK(slot, result)
|
||||
auto &deform = slot->getDeform();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto &deform = spine_object->getDeform();
|
||||
result.resize((int)deform.size());
|
||||
for (int i = 0; i < deform.size(); ++i) {
|
||||
for (int i = 0; i < (int)deform.size(); ++i) {
|
||||
result[i] = deform[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SpineSlot::set_deform(Array v) {
|
||||
SPINE_CHECK(slot,)
|
||||
auto &deform = slot->getDeform();
|
||||
SPINE_CHECK(spine_object,)
|
||||
auto &deform = spine_object->getDeform();
|
||||
deform.setSize(v.size(), 0);
|
||||
for (int i = 0; i < v.size(); ++i) {
|
||||
deform[i] = v[i];
|
||||
@ -158,11 +147,11 @@ void SpineSlot::set_deform(Array v) {
|
||||
}
|
||||
|
||||
int SpineSlot::get_sequence_index() {
|
||||
SPINE_CHECK(slot, 0)
|
||||
return slot->getAttachmentState();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAttachmentState();
|
||||
}
|
||||
|
||||
void SpineSlot::set_sequence_index(int v) {
|
||||
SPINE_CHECK(slot,)
|
||||
slot->setAttachmentState(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAttachmentState(v);
|
||||
}
|
||||
|
||||
@ -37,32 +37,21 @@
|
||||
|
||||
// Breaks cyclic dependency.
|
||||
class SpineSkeleton;
|
||||
class SpineSprite;
|
||||
|
||||
class SpineSlot : public REFCOUNTED {
|
||||
GDCLASS(SpineSlot, REFCOUNTED);
|
||||
class SpineSlot : public REFCOUNTED, public SpineObjectWrapper<SpineSprite, spine::Slot> {
|
||||
GDCLASS(SpineSlot, REFCOUNTED)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::Slot *slot;
|
||||
SpineSprite *sprite;
|
||||
|
||||
public:
|
||||
SpineSlot();
|
||||
|
||||
void set_spine_object(SpineSprite *_sprite, spine::Slot *_slot) { sprite = _sprite; slot = _slot; }
|
||||
spine::Slot *get_spine_object() { return slot; }
|
||||
SpineSprite *get_spine_sprite() { return sprite; }
|
||||
|
||||
void set_to_setup_pose();
|
||||
|
||||
Ref<SpineSlotData> get_data();
|
||||
|
||||
Ref<SpineBone> get_bone();
|
||||
|
||||
Ref<SpineSkeleton> get_skeleton();
|
||||
|
||||
Color get_color();
|
||||
|
||||
void set_color(Color v);
|
||||
|
||||
@ -47,75 +47,72 @@ void SpineSlotData::_bind_methods() {
|
||||
|
||||
}
|
||||
|
||||
SpineSlotData::SpineSlotData() : slot_data(nullptr) {
|
||||
}
|
||||
|
||||
int SpineSlotData::get_index() {
|
||||
SPINE_CHECK(slot_data, 0)
|
||||
return slot_data->getIndex();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getIndex();
|
||||
}
|
||||
|
||||
String SpineSlotData::get_name() {
|
||||
SPINE_CHECK(slot_data, String(""))
|
||||
return slot_data->getName().buffer();
|
||||
SPINE_CHECK(spine_object, String(""))
|
||||
return spine_object->getName().buffer();
|
||||
}
|
||||
|
||||
Ref<SpineBoneData> SpineSlotData::get_bone_data() {
|
||||
SPINE_CHECK(slot_data, nullptr)
|
||||
auto &bone_data = slot_data->getBoneData();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto &bone_data = spine_object->getBoneData();
|
||||
Ref<SpineBoneData> bone_data_ref(memnew(SpineBoneData));
|
||||
bone_data_ref->set_spine_object(&bone_data);
|
||||
bone_data_ref->set_spine_object(get_spine_owner(), &bone_data);
|
||||
return bone_data_ref;
|
||||
}
|
||||
|
||||
Color SpineSlotData::get_color() {
|
||||
SPINE_CHECK(slot_data, Color(0, 0, 0, 0))
|
||||
auto &color = slot_data->getColor();
|
||||
SPINE_CHECK(spine_object, Color(0, 0, 0, 0))
|
||||
auto &color = spine_object->getColor();
|
||||
return Color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void SpineSlotData::set_color(Color v) {
|
||||
SPINE_CHECK(slot_data,)
|
||||
auto &color = slot_data->getColor();
|
||||
SPINE_CHECK(spine_object,)
|
||||
auto &color = spine_object->getColor();
|
||||
color.set(v.r, v.g, v.b, v.a);
|
||||
}
|
||||
|
||||
Color SpineSlotData::get_dark_color() {
|
||||
SPINE_CHECK(slot_data, Color(0, 0, 0, 0))
|
||||
auto &color = slot_data->getDarkColor();
|
||||
SPINE_CHECK(spine_object, Color(0, 0, 0, 0))
|
||||
auto &color = spine_object->getDarkColor();
|
||||
return Color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void SpineSlotData::set_dark_color(Color v) {
|
||||
SPINE_CHECK(slot_data,)
|
||||
auto &color = slot_data->getDarkColor();
|
||||
SPINE_CHECK(spine_object,)
|
||||
auto &color = spine_object->getDarkColor();
|
||||
color.set(v.r, v.g, v.b, v.a);
|
||||
}
|
||||
|
||||
bool SpineSlotData::has_dark_color() {
|
||||
SPINE_CHECK(slot_data, false)
|
||||
return slot_data->hasDarkColor();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->hasDarkColor();
|
||||
}
|
||||
|
||||
void SpineSlotData::set_has_dark_color(bool v) {
|
||||
SPINE_CHECK(slot_data,)
|
||||
slot_data->setHasDarkColor(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setHasDarkColor(v);
|
||||
}
|
||||
|
||||
String SpineSlotData::get_attachment_name() {
|
||||
SPINE_CHECK(slot_data, "")
|
||||
return slot_data->getAttachmentName().buffer();
|
||||
SPINE_CHECK(spine_object, "")
|
||||
return spine_object->getAttachmentName().buffer();
|
||||
}
|
||||
void SpineSlotData::set_attachment_name(const String &v) {
|
||||
SPINE_CHECK(slot_data,)
|
||||
slot_data->setAttachmentName(SPINE_STRING(v));
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAttachmentName(SPINE_STRING(v));
|
||||
}
|
||||
|
||||
SpineConstant::BlendMode SpineSlotData::get_blend_mode() {
|
||||
SPINE_CHECK(slot_data, SpineConstant::BlendMode_Normal)
|
||||
return (SpineConstant::BlendMode)slot_data->getBlendMode();
|
||||
SPINE_CHECK(spine_object, SpineConstant::BlendMode_Normal)
|
||||
return (SpineConstant::BlendMode)spine_object->getBlendMode();
|
||||
}
|
||||
void SpineSlotData::set_blend_mode(SpineConstant::BlendMode v) {
|
||||
SPINE_CHECK(slot_data,)
|
||||
slot_data->setBlendMode((spine::BlendMode) v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setBlendMode((spine::BlendMode) v);
|
||||
}
|
||||
|
||||
@ -34,21 +34,15 @@
|
||||
#include "SpineBoneData.h"
|
||||
#include <spine/SlotData.h>
|
||||
|
||||
class SpineSlotData : public REFCOUNTED {
|
||||
GDCLASS(SpineSlotData, REFCOUNTED);
|
||||
class SpineSkeletonDataResource;
|
||||
|
||||
class SpineSlotData : public REFCOUNTED, public SpineObjectWrapper<SpineSkeletonDataResource, spine::SlotData> {
|
||||
GDCLASS(SpineSlotData, REFCOUNTED)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::SlotData *slot_data;
|
||||
|
||||
public:
|
||||
SpineSlotData();
|
||||
|
||||
void set_spine_object(spine::SlotData *s) { slot_data = s; }
|
||||
spine::SlotData *get_spine_object() { return slot_data; }
|
||||
|
||||
int get_index();
|
||||
|
||||
String get_name();
|
||||
|
||||
@ -129,11 +129,10 @@ void SpineSprite::on_skeleton_data_changed() {
|
||||
|
||||
if (skeleton_data_res.is_valid() && skeleton_data_res->is_skeleton_data_loaded()) {
|
||||
skeleton = Ref<SpineSkeleton>(memnew(SpineSkeleton));
|
||||
skeleton->set_skeleton_data_res(skeleton_data_res);
|
||||
skeleton->set_spine_sprite(this);
|
||||
|
||||
animation_state = Ref<SpineAnimationState>(memnew(SpineAnimationState));
|
||||
animation_state->set_skeleton_data_res(skeleton_data_res);
|
||||
animation_state->set_spine_sprite(this);
|
||||
if (animation_state->get_spine_object()) animation_state->get_spine_object()->setListener(this);
|
||||
|
||||
animation_state->update(0);
|
||||
@ -452,7 +451,7 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> skeleton) {
|
||||
|
||||
void SpineSprite::callback(spine::AnimationState *state, spine::EventType type, spine::TrackEntry *entry, spine::Event *event) {
|
||||
Ref<SpineTrackEntry> entry_ref = Ref<SpineTrackEntry>(memnew(SpineTrackEntry));
|
||||
entry_ref->set_spine_object(entry);
|
||||
entry_ref->set_spine_object(this, entry);
|
||||
|
||||
Ref<SpineEvent> event_ref(nullptr);
|
||||
if (event) {
|
||||
@ -511,6 +510,12 @@ void SpineSprite::set_update_mode(SpineSprite::UpdateMode v) {
|
||||
set_physics_process_internal(update_mode == UpdateMode_Physics);
|
||||
}
|
||||
|
||||
Ref<SpineSkin> SpineSprite::new_skin(const String& name) {
|
||||
auto skin = memnew(SpineSkin);
|
||||
skin->init(name, this);
|
||||
return skin;
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
Rect2 SpineSprite::_edit_get_rect() const {
|
||||
if (skeleton_data_res.is_valid() && skeleton_data_res->is_skeleton_data_loaded()) {
|
||||
|
||||
@ -93,6 +93,8 @@ public:
|
||||
|
||||
void set_update_mode(UpdateMode v);
|
||||
|
||||
Ref<SpineSkin> new_skin(const String &name);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Rect2 _edit_get_rect() const;
|
||||
virtual bool _edit_use_rect() const;
|
||||
|
||||
@ -50,6 +50,7 @@ SpineTimeline::SpineTimeline() : timeline(nullptr) {
|
||||
void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float last_time, float time, Array events, float alpha,
|
||||
SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) {
|
||||
SPINE_CHECK(timeline,)
|
||||
if (!skeleton->get_spine_object()) return;
|
||||
spine::Vector<spine::Event *> spine_events;
|
||||
spine_events.setSize((int)events.size(), nullptr);
|
||||
for (int i = 0; i < events.size(); ++i) {
|
||||
|
||||
@ -79,254 +79,252 @@ void SpineTrackEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_track_complete"), &SpineTrackEntry::get_track_complete);
|
||||
}
|
||||
|
||||
SpineTrackEntry::SpineTrackEntry() : track_entry(nullptr) {
|
||||
}
|
||||
|
||||
int SpineTrackEntry::get_track_index() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getTrackIndex();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getTrackIndex();
|
||||
}
|
||||
|
||||
Ref<SpineAnimation> SpineTrackEntry::get_animation() {
|
||||
SPINE_CHECK(track_entry, nullptr)
|
||||
auto animation = track_entry->getAnimation();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto animation = spine_object->getAnimation();
|
||||
if (!animation) return nullptr;
|
||||
Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
|
||||
animation_ref->set_spine_object(animation);
|
||||
animation_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), animation);
|
||||
return animation_ref;
|
||||
}
|
||||
|
||||
Ref<SpineTrackEntry> SpineTrackEntry::get_previous() {
|
||||
SPINE_CHECK(track_entry, nullptr)
|
||||
auto previous = track_entry->getPrevious();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto previous = spine_object->getPrevious();
|
||||
if (!previous) return nullptr;
|
||||
Ref<SpineTrackEntry> previous_ref(memnew(SpineTrackEntry));
|
||||
previous_ref->set_spine_object(previous);
|
||||
previous_ref->set_spine_object(get_spine_owner(), previous);
|
||||
return previous_ref;
|
||||
}
|
||||
|
||||
bool SpineTrackEntry::get_loop() {
|
||||
SPINE_CHECK(track_entry, false)
|
||||
return track_entry->getLoop();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->getLoop();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_loop(bool v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setLoop(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setLoop(v);
|
||||
}
|
||||
|
||||
bool SpineTrackEntry::get_hold_previous() {
|
||||
SPINE_CHECK(track_entry, false)
|
||||
return track_entry->getHoldPrevious();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->getHoldPrevious();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_hold_previous(bool v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setHoldPrevious(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setHoldPrevious(v);
|
||||
}
|
||||
|
||||
bool SpineTrackEntry::get_reverse() {
|
||||
SPINE_CHECK(track_entry, false)
|
||||
return track_entry->getReverse();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->getReverse();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_reverse(bool v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setReverse(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setReverse(v);
|
||||
}
|
||||
|
||||
bool SpineTrackEntry::get_shortest_rotation() {
|
||||
SPINE_CHECK(track_entry, false)
|
||||
return track_entry->getShortestRotation();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->getShortestRotation();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_shortest_rotation(bool v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setShortestRotation(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setShortestRotation(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_delay() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getDelay();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getDelay();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_delay(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setDelay(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setDelay(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_track_time() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getTrackTime();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getTrackTime();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_track_time(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setTrackTime(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setTrackTime(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_track_end() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getTrackEnd();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getTrackEnd();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_track_end(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setTrackEnd(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setTrackEnd(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_animation_start() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getAnimationStart();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAnimationStart();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_animation_start(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setAnimationStart(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAnimationStart(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_animation_end() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getAnimationEnd();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAnimationEnd();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_animation_end(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setAnimationEnd(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAnimationEnd(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_animation_last() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getAnimationLast();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAnimationLast();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_animation_last(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setAnimationLast(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAnimationLast(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_animation_time() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getAnimationTime();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAnimationTime();
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_time_scale() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getTimeScale();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getTimeScale();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_time_scale(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setTimeScale(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setTimeScale(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_alpha() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getAlpha();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAlpha();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_alpha(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setAlpha(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAlpha(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_event_threshold() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getEventThreshold();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getEventThreshold();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_event_threshold(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setEventThreshold(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setEventThreshold(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_attachment_threshold() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getAttachmentThreshold();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getAttachmentThreshold();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_attachment_threshold(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setAttachmentThreshold(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setAttachmentThreshold(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_draw_order_threshold() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getDrawOrderThreshold();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getDrawOrderThreshold();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_draw_order_threshold(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setDrawOrderThreshold(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setDrawOrderThreshold(v);
|
||||
}
|
||||
|
||||
Ref<SpineTrackEntry> SpineTrackEntry::get_next() {
|
||||
SPINE_CHECK(track_entry, nullptr)
|
||||
auto next = track_entry->getNext();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto next = spine_object->getNext();
|
||||
if (!next) return nullptr;
|
||||
Ref<SpineTrackEntry> next_ref(memnew(SpineTrackEntry));
|
||||
next_ref->set_spine_object(next);
|
||||
next_ref->set_spine_object(get_spine_owner(), next);
|
||||
return next_ref;
|
||||
}
|
||||
|
||||
bool SpineTrackEntry::is_complete() {
|
||||
SPINE_CHECK(track_entry, false)
|
||||
return track_entry->isComplete();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->isComplete();
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_mix_time() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getMixTime();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixTime();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_mix_time(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setMixTime(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixTime(v);
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_mix_duration() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getMixDuration();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixDuration();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_mix_duration(float v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setMixDuration(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixDuration(v);
|
||||
}
|
||||
|
||||
SpineConstant::MixBlend SpineTrackEntry::get_mix_blend() {
|
||||
SPINE_CHECK(track_entry, SpineConstant::MixBlend_Setup)
|
||||
return (SpineConstant::MixBlend)track_entry->getMixBlend();
|
||||
SPINE_CHECK(spine_object, SpineConstant::MixBlend_Setup)
|
||||
return (SpineConstant::MixBlend)spine_object->getMixBlend();
|
||||
}
|
||||
|
||||
void SpineTrackEntry::set_mix_blend(SpineConstant::MixBlend v) {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->setMixBlend((spine::MixBlend) v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixBlend((spine::MixBlend) v);
|
||||
}
|
||||
|
||||
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_from() {
|
||||
SPINE_CHECK(track_entry, nullptr)
|
||||
auto mixing_from = track_entry->getMixingFrom();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto mixing_from = spine_object->getMixingFrom();
|
||||
if (!mixing_from) return nullptr;
|
||||
Ref<SpineTrackEntry> mixing_from_ref(memnew(SpineTrackEntry));
|
||||
mixing_from_ref->set_spine_object(mixing_from);
|
||||
mixing_from_ref->set_spine_object(get_spine_owner(), mixing_from);
|
||||
return mixing_from_ref;
|
||||
}
|
||||
|
||||
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_to() {
|
||||
SPINE_CHECK(track_entry, nullptr)
|
||||
auto mixing_to = track_entry->getMixingTo();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto mixing_to = spine_object->getMixingTo();
|
||||
if (!mixing_to) return nullptr;
|
||||
Ref<SpineTrackEntry> mixing_to_ref(memnew(SpineTrackEntry));
|
||||
mixing_to_ref->set_spine_object(mixing_to);
|
||||
mixing_to_ref->set_spine_object(get_spine_owner(), mixing_to);
|
||||
return mixing_to_ref;
|
||||
}
|
||||
|
||||
void SpineTrackEntry::reset_rotation_directions() {
|
||||
SPINE_CHECK(track_entry,)
|
||||
track_entry->resetRotationDirections();
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->resetRotationDirections();
|
||||
}
|
||||
|
||||
float SpineTrackEntry::get_track_complete() {
|
||||
SPINE_CHECK(track_entry, 0)
|
||||
return track_entry->getTrackComplete();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getTrackComplete();
|
||||
}
|
||||
|
||||
@ -35,21 +35,15 @@
|
||||
#include "SpineConstant.h"
|
||||
#include <spine/AnimationState.h>
|
||||
|
||||
class SpineTrackEntry : public REFCOUNTED {
|
||||
#include "SpineSprite.h"
|
||||
|
||||
class SpineTrackEntry : public REFCOUNTED, public SpineObjectWrapper<SpineSprite, spine::TrackEntry> {
|
||||
GDCLASS(SpineTrackEntry, REFCOUNTED);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::TrackEntry *track_entry;
|
||||
|
||||
public:
|
||||
SpineTrackEntry();
|
||||
|
||||
void set_spine_object(spine::TrackEntry *_track_entry) { this->track_entry = _track_entry; }
|
||||
spine::TrackEntry *get_spine_object() { return track_entry; }
|
||||
|
||||
int get_track_index();
|
||||
|
||||
Ref<SpineAnimation> get_animation();
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
#include "SpineTransformConstraint.h"
|
||||
#include "SpineCommon.h"
|
||||
#include "SpineSprite.h"
|
||||
|
||||
void SpineTransformConstraint::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("update"), &SpineTransformConstraint::update);
|
||||
@ -52,121 +53,118 @@ void SpineTransformConstraint::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineTransformConstraint::set_active);
|
||||
}
|
||||
|
||||
SpineTransformConstraint::SpineTransformConstraint() : transform_constraint(nullptr), sprite(nullptr) {
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::update() {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->update();
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->update();
|
||||
}
|
||||
|
||||
int SpineTransformConstraint::get_order() {
|
||||
SPINE_CHECK(transform_constraint, 0)
|
||||
return transform_constraint->getOrder();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getOrder();
|
||||
}
|
||||
|
||||
Ref<SpineTransformConstraintData> SpineTransformConstraint::get_data() {
|
||||
SPINE_CHECK(transform_constraint, nullptr)
|
||||
auto &data = transform_constraint->getData();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto &data = spine_object->getData();
|
||||
Ref<SpineTransformConstraintData> data_ref(memnew(SpineTransformConstraintData));
|
||||
data_ref->set_spine_object(&data);
|
||||
data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &data);
|
||||
return data_ref;
|
||||
}
|
||||
|
||||
Array SpineTransformConstraint::get_bones() {
|
||||
Array result;
|
||||
SPINE_CHECK(transform_constraint, result)
|
||||
auto &bones = transform_constraint->getBones();
|
||||
SPINE_CHECK(spine_object, result)
|
||||
auto &bones = spine_object->getBones();
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
auto bone = bones[i];
|
||||
Ref<SpineBone> bone_ref(memnew(SpineBone));
|
||||
bone_ref->set_spine_object(sprite, bone);
|
||||
bone_ref->set_spine_object(get_spine_owner(), bone);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Ref<SpineBone> SpineTransformConstraint::get_target() {
|
||||
SPINE_CHECK(transform_constraint, nullptr)
|
||||
auto target = transform_constraint->getTarget();
|
||||
SPINE_CHECK(spine_object, nullptr)
|
||||
auto target = spine_object->getTarget();
|
||||
if (!target) return nullptr;
|
||||
Ref<SpineBone> target_ref(memnew(SpineBone));
|
||||
target_ref->set_spine_object(sprite, target);
|
||||
target_ref->set_spine_object(get_spine_owner(), target);
|
||||
return target_ref;
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_target(Ref<SpineBone> v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
float SpineTransformConstraint::get_mix_rotate() {
|
||||
SPINE_CHECK(transform_constraint, 0)
|
||||
return transform_constraint->getMixRotate();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixRotate();
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_mix_rotate(float v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setMixRotate(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixRotate(v);
|
||||
}
|
||||
|
||||
float SpineTransformConstraint::get_mix_x() {
|
||||
SPINE_CHECK(transform_constraint, 0)
|
||||
return transform_constraint->getMixX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixX();
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_mix_x(float v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setMixX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixX(v);
|
||||
}
|
||||
|
||||
float SpineTransformConstraint::get_mix_y() {
|
||||
SPINE_CHECK(transform_constraint, 0)
|
||||
return transform_constraint->getMixY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixY();
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_mix_y(float v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setMixY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixY(v);
|
||||
}
|
||||
|
||||
float SpineTransformConstraint::get_mix_scale_x() {
|
||||
SPINE_CHECK(transform_constraint, 0)
|
||||
return transform_constraint->getMixScaleX();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixScaleX();
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_mix_scale_x(float v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setMixScaleX(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixScaleX(v);
|
||||
}
|
||||
|
||||
float SpineTransformConstraint::get_mix_scale_y() {
|
||||
SPINE_CHECK(transform_constraint, 0)
|
||||
return transform_constraint->getMixScaleY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixScaleY();
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_mix_scale_y(float v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setMixScaleY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixScaleY(v);
|
||||
}
|
||||
|
||||
float SpineTransformConstraint::get_mix_shear_y() {
|
||||
SPINE_CHECK(transform_constraint, 0)
|
||||
return transform_constraint->getMixShearY();
|
||||
SPINE_CHECK(spine_object, 0)
|
||||
return spine_object->getMixShearY();
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_mix_shear_y(float v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setMixShearY(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setMixShearY(v);
|
||||
}
|
||||
|
||||
bool SpineTransformConstraint::is_active() {
|
||||
SPINE_CHECK(transform_constraint, false)
|
||||
return transform_constraint->isActive();
|
||||
SPINE_CHECK(spine_object, false)
|
||||
return spine_object->isActive();
|
||||
}
|
||||
|
||||
void SpineTransformConstraint::set_active(bool v) {
|
||||
SPINE_CHECK(transform_constraint,)
|
||||
transform_constraint->setActive(v);
|
||||
SPINE_CHECK(spine_object,)
|
||||
spine_object->setActive(v);
|
||||
}
|
||||
|
||||
@ -35,23 +35,13 @@
|
||||
#include "SpineBone.h"
|
||||
#include <spine/TransformConstraint.h>
|
||||
|
||||
class SpineTransformConstraint : public REFCOUNTED {
|
||||
GDCLASS(SpineTransformConstraint, REFCOUNTED);
|
||||
class SpineTransformConstraint : public REFCOUNTED, public SpineObjectWrapper<SpineSprite, spine::TransformConstraint> {
|
||||
GDCLASS(SpineTransformConstraint, REFCOUNTED)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
spine::TransformConstraint *transform_constraint;
|
||||
SpineSprite *sprite;
|
||||
|
||||
public:
|
||||
SpineTransformConstraint();
|
||||
|
||||
void set_spine_object(SpineSprite *_sprite, spine::TransformConstraint *_transform_constraint) { sprite = _sprite; transform_constraint = _transform_constraint; }
|
||||
spine::TransformConstraint *get_spine_object() { return transform_constraint; }
|
||||
SpineSprite *get_spine_sprite() { return sprite; }
|
||||
|
||||
void update();
|
||||
|
||||
int get_order();
|
||||
|
||||
@ -54,9 +54,9 @@ Array SpineTransformConstraintData::get_bones() {
|
||||
SPINE_CHECK(get_spine_constraint_data(), result)
|
||||
auto bones = get_spine_constraint_data()->getBones();
|
||||
result.resize((int)bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
for (int i = 0; i < (int)bones.size(); ++i) {
|
||||
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
|
||||
bone_ref->set_spine_object(bones[i]);
|
||||
bone_ref->set_spine_object(get_spine_owner(), bones[i]);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return result;
|
||||
@ -67,7 +67,7 @@ Ref<SpineBoneData> SpineTransformConstraintData::get_target() {
|
||||
auto bone = get_spine_constraint_data()->getTarget();
|
||||
if (!bone) return nullptr;
|
||||
Ref<SpineBoneData> slot_ref(memnew(SpineBoneData));
|
||||
slot_ref->set_spine_object(bone);
|
||||
slot_ref->set_spine_object(get_spine_owner(), bone);
|
||||
return slot_ref;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user