mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[godot] Clean-up SpineIkConstraintData and SpineIkConstraint
This commit is contained in:
parent
45e087feb3
commit
7edeb29aaa
@ -28,7 +28,6 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "SpineBoneData.h"
|
||||
#include <spine/BoneData.h>
|
||||
#include "common.h"
|
||||
|
||||
void SpineBoneData::_bind_methods() {
|
||||
|
||||
@ -32,10 +32,7 @@
|
||||
|
||||
#include "core/reference.h"
|
||||
#include "SpineConstant.h"
|
||||
|
||||
namespace spine {
|
||||
class BoneData;
|
||||
}
|
||||
#include <spine/BoneData.h>
|
||||
|
||||
class SpineBoneData : public Reference {
|
||||
GDCLASS(SpineBoneData, Reference);
|
||||
|
||||
@ -41,16 +41,15 @@ class SpineConstraintData : public Reference {
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
|
||||
spine::ConstraintData *constraint_data;
|
||||
|
||||
public:
|
||||
SpineConstraintData();
|
||||
~SpineConstraintData();
|
||||
|
||||
void set_spine_object(spine::ConstraintData *c) {
|
||||
constraint_data = c;
|
||||
void set_spine_object(spine::ConstraintData *_constraint_data) {
|
||||
constraint_data = _constraint_data;
|
||||
}
|
||||
|
||||
spine::ConstraintData *get_spine_object() {
|
||||
|
||||
@ -29,9 +29,9 @@
|
||||
|
||||
#include "SpineIkConstraint.h"
|
||||
#include "SpineBone.h"
|
||||
#include "common.h"
|
||||
|
||||
void SpineIkConstraint::_bind_methods() {
|
||||
// ClassDB::bind_method(D_METHOD("apply"), &SpineIkConstraint::apply);
|
||||
ClassDB::bind_method(D_METHOD("update"), &SpineIkConstraint::update);
|
||||
ClassDB::bind_method(D_METHOD("get_order"), &SpineIkConstraint::get_order);
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &SpineIkConstraint::get_data);
|
||||
@ -52,95 +52,112 @@ void SpineIkConstraint::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineIkConstraint::set_active);
|
||||
}
|
||||
|
||||
SpineIkConstraint::SpineIkConstraint() : ik_constraint(NULL) {}
|
||||
SpineIkConstraint::~SpineIkConstraint() {}
|
||||
SpineIkConstraint::SpineIkConstraint() : ik_constraint(nullptr) {
|
||||
}
|
||||
|
||||
// void SpineIkConstraint::apply(){
|
||||
// ik_constraint->apply();
|
||||
// }
|
||||
SpineIkConstraint::~SpineIkConstraint() {
|
||||
}
|
||||
|
||||
void SpineIkConstraint::update() {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->update();
|
||||
}
|
||||
|
||||
int SpineIkConstraint::get_order() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getOrder();
|
||||
}
|
||||
|
||||
Ref<SpineIkConstraintData> SpineIkConstraint::get_data() {
|
||||
auto &ikc = ik_constraint->getData();
|
||||
Ref<SpineIkConstraintData> gd_ikc(memnew(SpineIkConstraintData));
|
||||
gd_ikc->set_spine_object(&ikc);
|
||||
return gd_ikc;
|
||||
SPINE_CHECK(ik_constraint, nullptr)
|
||||
auto &ik_constraint_data = ik_constraint->getData();
|
||||
Ref<SpineIkConstraintData> ik_constraint_data_ref(memnew(SpineIkConstraintData));
|
||||
ik_constraint_data_ref->set_spine_object(&ik_constraint_data);
|
||||
return ik_constraint_data_ref;
|
||||
}
|
||||
|
||||
Array SpineIkConstraint::get_bones() {
|
||||
auto &bs = ik_constraint->getBones();
|
||||
Array gd_bs;
|
||||
gd_bs.resize(bs.size());
|
||||
for (size_t i = 0; i < bs.size(); ++i) {
|
||||
auto b = bs[i];
|
||||
if (b == NULL) gd_bs[i] = Ref<SpineBone>(NULL);
|
||||
Ref<SpineBone> gd_b(memnew(SpineBone));
|
||||
gd_b->set_spine_object(b);
|
||||
gd_bs[i] = gd_b;
|
||||
Array result;
|
||||
SPINE_CHECK(ik_constraint, result)
|
||||
auto &bones = ik_constraint->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(bone);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return gd_bs;
|
||||
return result;
|
||||
}
|
||||
|
||||
Ref<SpineBone> SpineIkConstraint::get_target() {
|
||||
auto b = ik_constraint->getTarget();
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineBone> gd_b(memnew(SpineBone));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
SPINE_CHECK(ik_constraint, nullptr)
|
||||
auto target = ik_constraint->getTarget();
|
||||
if (!target) return nullptr;
|
||||
Ref<SpineBone> target_ref(memnew(SpineBone));
|
||||
target_ref->set_spine_object(target);
|
||||
return target_ref;
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_target(Ref<SpineBone> v) {
|
||||
if (v.is_valid()) {
|
||||
ik_constraint->setTarget(v->get_spine_object());
|
||||
} else {
|
||||
ik_constraint->setTarget(NULL);
|
||||
}
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
int SpineIkConstraint::get_bend_direction() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getBendDirection();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_bend_direction(int v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setBendDirection(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraint::get_compress() {
|
||||
SPINE_CHECK(ik_constraint, false)
|
||||
return ik_constraint->getCompress();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_compress(bool v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setCompress(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraint::get_stretch() {
|
||||
SPINE_CHECK(ik_constraint, false)
|
||||
return ik_constraint->getStretch();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_stretch(bool v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setStretch(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraint::get_mix() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getMix();
|
||||
}
|
||||
void SpineIkConstraint::set_mix(float v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setMix(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraint::get_softness() {
|
||||
SPINE_CHECK(ik_constraint, 0)
|
||||
return ik_constraint->getSoftness();
|
||||
}
|
||||
|
||||
void SpineIkConstraint::set_softness(float v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setSoftness(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraint::is_active() {
|
||||
SPINE_CHECK(ik_constraint, nullptr)
|
||||
return ik_constraint->isActive();
|
||||
}
|
||||
void SpineIkConstraint::set_active(bool v) {
|
||||
SPINE_CHECK(ik_constraint,)
|
||||
ik_constraint->setActive(v);
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,10 +30,6 @@
|
||||
#ifndef GODOT_SPINEIKCONSTRAINT_H
|
||||
#define GODOT_SPINEIKCONSTRAINT_H
|
||||
|
||||
#include "core/variant_parser.h"
|
||||
|
||||
#include <spine/spine.h>
|
||||
|
||||
#include "SpineIkConstraintData.h"
|
||||
|
||||
class SpineBone;
|
||||
@ -51,16 +47,10 @@ public:
|
||||
SpineIkConstraint();
|
||||
~SpineIkConstraint();
|
||||
|
||||
inline void set_spine_object(spine::IkConstraint *ic) {
|
||||
ik_constraint = ic;
|
||||
}
|
||||
inline spine::IkConstraint *get_spine_object() {
|
||||
return ik_constraint;
|
||||
}
|
||||
|
||||
// The spine-runtime-cpp 4.0 seems to not have a apply function implementation.
|
||||
// void apply();
|
||||
void set_spine_object(spine::IkConstraint *_ik_constraint) { ik_constraint = _ik_constraint; }
|
||||
|
||||
spine::IkConstraint *get_spine_object() { return ik_constraint; }
|
||||
|
||||
void update();
|
||||
|
||||
int get_order();
|
||||
@ -70,24 +60,31 @@ public:
|
||||
Array get_bones();
|
||||
|
||||
Ref<SpineBone> get_target();
|
||||
|
||||
void set_target(Ref<SpineBone> v);
|
||||
|
||||
int get_bend_direction();
|
||||
|
||||
void set_bend_direction(int v);
|
||||
|
||||
bool get_compress();
|
||||
|
||||
void set_compress(bool v);
|
||||
|
||||
bool get_stretch();
|
||||
|
||||
void set_stretch(bool v);
|
||||
|
||||
float get_mix();
|
||||
|
||||
void set_mix(float v);
|
||||
|
||||
float get_softness();
|
||||
|
||||
void set_softness(float v);
|
||||
|
||||
bool is_active();
|
||||
|
||||
void set_active(bool v);
|
||||
};
|
||||
|
||||
|
||||
@ -29,8 +29,10 @@
|
||||
|
||||
#include "SpineIkConstraintData.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void SpineIkConstraintData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_all_bone_data"), &SpineIkConstraintData::get_bones);
|
||||
ClassDB::bind_method(D_METHOD("get_bones"), &SpineIkConstraintData::get_bones);
|
||||
ClassDB::bind_method(D_METHOD("get_target"), &SpineIkConstraintData::get_target);
|
||||
ClassDB::bind_method(D_METHOD("set_target", "v"), &SpineIkConstraintData::set_target);
|
||||
ClassDB::bind_method(D_METHOD("get_bend_direction"), &SpineIkConstraintData::get_bend_direction);
|
||||
@ -51,73 +53,88 @@ SpineIkConstraintData::SpineIkConstraintData() {}
|
||||
SpineIkConstraintData::~SpineIkConstraintData() {}
|
||||
|
||||
Array SpineIkConstraintData::get_bones() {
|
||||
auto bs = get_spine_data()->getBones();
|
||||
Array gd_bs;
|
||||
gd_bs.resize(bs.size());
|
||||
for (size_t i = 0; i < bs.size(); ++i) {
|
||||
if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL);
|
||||
else {
|
||||
Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
Array result;
|
||||
SPINE_CHECK(constraint_data, 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]);
|
||||
result[i] = bone_ref;
|
||||
}
|
||||
return gd_bs;
|
||||
return result;
|
||||
}
|
||||
|
||||
Ref<SpineBoneData> SpineIkConstraintData::get_target() {
|
||||
auto b = get_spine_data()->getTarget();
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
SPINE_CHECK(constraint_data, nullptr)
|
||||
auto target = get_spine_constraint_data()->getTarget();
|
||||
if (!target) return nullptr;
|
||||
Ref<SpineBoneData> target_ref(memnew(SpineBoneData));
|
||||
target_ref->set_spine_object(target);
|
||||
return target_ref;
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_target(Ref<SpineBoneData> v) {
|
||||
if (v.is_valid()) {
|
||||
get_spine_data()->setTarget(v->get_spine_object());
|
||||
} else {
|
||||
get_spine_data()->setTarget(NULL);
|
||||
}
|
||||
SPINE_CHECK(constraint_data,)
|
||||
get_spine_constraint_data()->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
|
||||
}
|
||||
|
||||
int SpineIkConstraintData::get_bend_direction() {
|
||||
return get_spine_data()->getBendDirection();
|
||||
SPINE_CHECK(constraint_data, 0)
|
||||
return get_spine_constraint_data()->getBendDirection();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_bend_direction(int v) {
|
||||
get_spine_data()->setBendDirection(v);
|
||||
SPINE_CHECK(constraint_data,)
|
||||
get_spine_constraint_data()->setBendDirection(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraintData::get_compress() {
|
||||
return get_spine_data()->getCompress();
|
||||
SPINE_CHECK(constraint_data, false)
|
||||
return get_spine_constraint_data()->getCompress();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_compress(bool v) {
|
||||
get_spine_data()->setCompress(v);
|
||||
SPINE_CHECK(constraint_data,)
|
||||
get_spine_constraint_data()->setCompress(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraintData::get_stretch() {
|
||||
return get_spine_data()->getStretch();
|
||||
SPINE_CHECK(constraint_data, false)
|
||||
return get_spine_constraint_data()->getStretch();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_stretch(bool v) {
|
||||
get_spine_data()->setStretch(v);
|
||||
SPINE_CHECK(constraint_data,)
|
||||
get_spine_constraint_data()->setStretch(v);
|
||||
}
|
||||
|
||||
bool SpineIkConstraintData::get_uniform() {
|
||||
return get_spine_data()->getUniform();
|
||||
SPINE_CHECK(constraint_data, false)
|
||||
return get_spine_constraint_data()->getUniform();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_uniform(bool v) {
|
||||
get_spine_data()->setUniform(v);
|
||||
SPINE_CHECK(constraint_data,)
|
||||
get_spine_constraint_data()->setUniform(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraintData::get_mix() {
|
||||
return get_spine_data()->getMix();
|
||||
SPINE_CHECK(constraint_data, 0)
|
||||
return get_spine_constraint_data()->getMix();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_mix(float v) {
|
||||
get_spine_data()->setMix(v);
|
||||
SPINE_CHECK(constraint_data,)
|
||||
get_spine_constraint_data()->setMix(v);
|
||||
}
|
||||
|
||||
float SpineIkConstraintData::get_softness() {
|
||||
return get_spine_data()->getSoftness();
|
||||
SPINE_CHECK(constraint_data, 0)
|
||||
return get_spine_constraint_data()->getSoftness();
|
||||
}
|
||||
|
||||
void SpineIkConstraintData::set_softness(float v) {
|
||||
get_spine_data()->setSoftness(v);
|
||||
}
|
||||
SPINE_CHECK(constraint_data,)
|
||||
get_spine_constraint_data()->setSoftness(v);
|
||||
}
|
||||
|
||||
@ -30,16 +30,15 @@
|
||||
#ifndef GODOT_SPINEIKCONSTRAINTDATA_H
|
||||
#define GODOT_SPINEIKCONSTRAINTDATA_H
|
||||
|
||||
#include "core/variant_parser.h"
|
||||
|
||||
#include <spine/spine.h>
|
||||
|
||||
#include "SpineConstraintData.h"
|
||||
#include "SpineBoneData.h"
|
||||
#include <spine/IkConstraintData.h>
|
||||
|
||||
class SpineIkConstraintData : public SpineConstraintData {
|
||||
GDCLASS(SpineIkConstraintData, SpineConstraintData);
|
||||
GDCLASS(SpineIkConstraintData, SpineConstraintData)
|
||||
|
||||
spine::IkConstraintData *get_spine_constraint_data() { return (spine::IkConstraintData *)get_spine_object(); }
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
@ -47,31 +46,34 @@ public:
|
||||
SpineIkConstraintData();
|
||||
~SpineIkConstraintData();
|
||||
|
||||
virtual inline spine::IkConstraintData *get_spine_data() {
|
||||
return (spine::IkConstraintData *) SpineConstraintData::get_spine_object();
|
||||
}
|
||||
|
||||
Array get_bones();
|
||||
|
||||
Ref<SpineBoneData> get_target();
|
||||
|
||||
void set_target(Ref<SpineBoneData> v);
|
||||
|
||||
int get_bend_direction();
|
||||
|
||||
void set_bend_direction(int v);
|
||||
|
||||
bool get_compress();
|
||||
|
||||
void set_compress(bool v);
|
||||
|
||||
bool get_stretch();
|
||||
|
||||
void set_stretch(bool v);
|
||||
|
||||
bool get_uniform();
|
||||
|
||||
void set_uniform(bool v);
|
||||
|
||||
float get_mix();
|
||||
|
||||
void set_mix(float v);
|
||||
|
||||
float get_softness();
|
||||
|
||||
void set_softness(float v);
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user