[godot] Add SkeletonData::set_reference_scale/get_reference_scale

This commit is contained in:
Mario Zechner 2024-04-04 16:39:32 +02:00
parent 236bc61519
commit eecca2bdfa
2 changed files with 280 additions and 146 deletions

View File

@ -32,7 +32,8 @@
#include "core/io/marshalls.h"
void SpineAnimationMix::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_from", "from"), &SpineAnimationMix::set_from);
ClassDB::bind_method(D_METHOD("set_from", "from"),
&SpineAnimationMix::set_from);
ClassDB::bind_method(D_METHOD("get_from"), &SpineAnimationMix::get_from);
ClassDB::bind_method(D_METHOD("set_to", "to"), &SpineAnimationMix::set_to);
ClassDB::bind_method(D_METHOD("get_to"), &SpineAnimationMix::get_to);
@ -48,90 +49,127 @@ void SpineAnimationMix::_bind_methods() {
#endif
}
SpineAnimationMix::SpineAnimationMix() : from(""), to(""), mix(0) {
}
SpineAnimationMix::SpineAnimationMix() : from(""), to(""), mix(0) {}
void SpineAnimationMix::set_from(const String &_from) {
this->from = _from;
}
void SpineAnimationMix::set_from(const String &_from) { this->from = _from; }
String SpineAnimationMix::get_from() {
return from;
}
String SpineAnimationMix::get_from() { return from; }
void SpineAnimationMix::set_to(const String &_to) {
this->to = _to;
}
void SpineAnimationMix::set_to(const String &_to) { this->to = _to; }
String SpineAnimationMix::get_to() {
return to;
}
String SpineAnimationMix::get_to() { return to; }
void SpineAnimationMix::set_mix(float _mix) {
this->mix = _mix;
}
void SpineAnimationMix::set_mix(float _mix) { this->mix = _mix; }
float SpineAnimationMix::get_mix() {
return mix;
}
float SpineAnimationMix::get_mix() { return mix; }
void SpineSkeletonDataResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_skeleton_data_loaded"), &SpineSkeletonDataResource::is_skeleton_data_loaded);
ClassDB::bind_method(D_METHOD("set_atlas_res", "atlas_res"), &SpineSkeletonDataResource::set_atlas_res);
ClassDB::bind_method(D_METHOD("get_atlas_res"), &SpineSkeletonDataResource::get_atlas_res);
ClassDB::bind_method(D_METHOD("set_skeleton_file_res", "skeleton_file_res"), &SpineSkeletonDataResource::set_skeleton_file_res);
ClassDB::bind_method(D_METHOD("get_skeleton_file_res"), &SpineSkeletonDataResource::get_skeleton_file_res);
ClassDB::bind_method(D_METHOD("set_default_mix", "default_mix"), &SpineSkeletonDataResource::set_default_mix);
ClassDB::bind_method(D_METHOD("get_default_mix"), &SpineSkeletonDataResource::get_default_mix);
ClassDB::bind_method(D_METHOD("set_animation_mixes", "mixes"), &SpineSkeletonDataResource::set_animation_mixes);
ClassDB::bind_method(D_METHOD("get_animation_mixes"), &SpineSkeletonDataResource::get_animation_mixes);
ClassDB::bind_method(D_METHOD("is_skeleton_data_loaded"),
&SpineSkeletonDataResource::is_skeleton_data_loaded);
ClassDB::bind_method(D_METHOD("set_atlas_res", "atlas_res"),
&SpineSkeletonDataResource::set_atlas_res);
ClassDB::bind_method(D_METHOD("get_atlas_res"),
&SpineSkeletonDataResource::get_atlas_res);
ClassDB::bind_method(D_METHOD("set_skeleton_file_res", "skeleton_file_res"),
&SpineSkeletonDataResource::set_skeleton_file_res);
ClassDB::bind_method(D_METHOD("get_skeleton_file_res"),
&SpineSkeletonDataResource::get_skeleton_file_res);
ClassDB::bind_method(D_METHOD("set_default_mix", "default_mix"),
&SpineSkeletonDataResource::set_default_mix);
ClassDB::bind_method(D_METHOD("get_default_mix"),
&SpineSkeletonDataResource::get_default_mix);
ClassDB::bind_method(D_METHOD("set_animation_mixes", "mixes"),
&SpineSkeletonDataResource::set_animation_mixes);
ClassDB::bind_method(D_METHOD("get_animation_mixes"),
&SpineSkeletonDataResource::get_animation_mixes);
// Spine API
ClassDB::bind_method(D_METHOD("find_bone", "bone_name"), &SpineSkeletonDataResource::find_bone);
ClassDB::bind_method(D_METHOD("find_slot", "slot_name"), &SpineSkeletonDataResource::find_slot);
ClassDB::bind_method(D_METHOD("find_skin", "skin_name"), &SpineSkeletonDataResource::find_skin);
ClassDB::bind_method(D_METHOD("find_event", "event_data_name"), &SpineSkeletonDataResource::find_event);
ClassDB::bind_method(D_METHOD("find_animation", "animation_name"), &SpineSkeletonDataResource::find_animation);
ClassDB::bind_method(D_METHOD("find_ik_constraint_data", "constraint_name"), &SpineSkeletonDataResource::find_ik_constraint);
ClassDB::bind_method(D_METHOD("find_transform_constraint_data", "constraint_name"), &SpineSkeletonDataResource::find_transform_constraint);
ClassDB::bind_method(D_METHOD("find_path_constraint_data", "constraint_name"), &SpineSkeletonDataResource::find_path_constraint);
ClassDB::bind_method(D_METHOD("get_skeleton_name"), &SpineSkeletonDataResource::get_skeleton_name);
ClassDB::bind_method(D_METHOD("get_bones"), &SpineSkeletonDataResource::get_bones);
ClassDB::bind_method(D_METHOD("get_slots"), &SpineSkeletonDataResource::get_slots);
ClassDB::bind_method(D_METHOD("get_skins"), &SpineSkeletonDataResource::get_skins);
ClassDB::bind_method(D_METHOD("get_default_skin"), &SpineSkeletonDataResource::get_default_skin);
ClassDB::bind_method(D_METHOD("set_default_skin", "skin"), &SpineSkeletonDataResource::set_default_skin);
ClassDB::bind_method(D_METHOD("get_events"), &SpineSkeletonDataResource::get_events);
ClassDB::bind_method(D_METHOD("get_animations"), &SpineSkeletonDataResource::get_animations);
ClassDB::bind_method(D_METHOD("get_ik_constraints"), &SpineSkeletonDataResource::get_ik_constraints);
ClassDB::bind_method(D_METHOD("get_transform_constraints"), &SpineSkeletonDataResource::get_transform_constraints);
ClassDB::bind_method(D_METHOD("get_path_constraints"), &SpineSkeletonDataResource::get_path_constraints);
ClassDB::bind_method(D_METHOD("find_bone", "bone_name"),
&SpineSkeletonDataResource::find_bone);
ClassDB::bind_method(D_METHOD("find_slot", "slot_name"),
&SpineSkeletonDataResource::find_slot);
ClassDB::bind_method(D_METHOD("find_skin", "skin_name"),
&SpineSkeletonDataResource::find_skin);
ClassDB::bind_method(D_METHOD("find_event", "event_data_name"),
&SpineSkeletonDataResource::find_event);
ClassDB::bind_method(D_METHOD("find_animation", "animation_name"),
&SpineSkeletonDataResource::find_animation);
ClassDB::bind_method(D_METHOD("find_ik_constraint_data", "constraint_name"),
&SpineSkeletonDataResource::find_ik_constraint);
ClassDB::bind_method(
D_METHOD("find_transform_constraint_data", "constraint_name"),
&SpineSkeletonDataResource::find_transform_constraint);
ClassDB::bind_method(D_METHOD("find_path_constraint_data", "constraint_name"),
&SpineSkeletonDataResource::find_path_constraint);
ClassDB::bind_method(D_METHOD("get_skeleton_name"),
&SpineSkeletonDataResource::get_skeleton_name);
ClassDB::bind_method(D_METHOD("get_bones"),
&SpineSkeletonDataResource::get_bones);
ClassDB::bind_method(D_METHOD("get_slots"),
&SpineSkeletonDataResource::get_slots);
ClassDB::bind_method(D_METHOD("get_skins"),
&SpineSkeletonDataResource::get_skins);
ClassDB::bind_method(D_METHOD("get_default_skin"),
&SpineSkeletonDataResource::get_default_skin);
ClassDB::bind_method(D_METHOD("set_default_skin", "skin"),
&SpineSkeletonDataResource::set_default_skin);
ClassDB::bind_method(D_METHOD("get_events"),
&SpineSkeletonDataResource::get_events);
ClassDB::bind_method(D_METHOD("get_animations"),
&SpineSkeletonDataResource::get_animations);
ClassDB::bind_method(D_METHOD("get_ik_constraints"),
&SpineSkeletonDataResource::get_ik_constraints);
ClassDB::bind_method(D_METHOD("get_transform_constraints"),
&SpineSkeletonDataResource::get_transform_constraints);
ClassDB::bind_method(D_METHOD("get_path_constraints"),
&SpineSkeletonDataResource::get_path_constraints);
ClassDB::bind_method(D_METHOD("get_x"), &SpineSkeletonDataResource::get_x);
ClassDB::bind_method(D_METHOD("get_y"), &SpineSkeletonDataResource::get_y);
ClassDB::bind_method(D_METHOD("get_width"), &SpineSkeletonDataResource::get_width);
ClassDB::bind_method(D_METHOD("get_height"), &SpineSkeletonDataResource::get_height);
ClassDB::bind_method(D_METHOD("get_version"), &SpineSkeletonDataResource::get_version);
ClassDB::bind_method(D_METHOD("get_hash"), &SpineSkeletonDataResource::get_hash);
ClassDB::bind_method(D_METHOD("get_images_path"), &SpineSkeletonDataResource::get_images_path);
ClassDB::bind_method(D_METHOD("get_audio_path"), &SpineSkeletonDataResource::get_audio_path);
ClassDB::bind_method(D_METHOD("get_fps"), &SpineSkeletonDataResource::get_fps);
ClassDB::bind_method(D_METHOD("update_skeleton_data"), &SpineSkeletonDataResource::update_skeleton_data);
ClassDB::bind_method(D_METHOD("get_width"),
&SpineSkeletonDataResource::get_width);
ClassDB::bind_method(D_METHOD("get_height"),
&SpineSkeletonDataResource::get_height);
ClassDB::bind_method(D_METHOD("get_version"),
&SpineSkeletonDataResource::get_version);
ClassDB::bind_method(D_METHOD("get_hash"),
&SpineSkeletonDataResource::get_hash);
ClassDB::bind_method(D_METHOD("get_images_path"),
&SpineSkeletonDataResource::get_images_path);
ClassDB::bind_method(D_METHOD("get_audio_path"),
&SpineSkeletonDataResource::get_audio_path);
ClassDB::bind_method(D_METHOD("get_fps"),
&SpineSkeletonDataResource::get_fps);
ClassDB::bind_method(D_METHOD("get_reference_scale"),
&SpineSkeletonDataResource::get_reference_scale);
ClassDB::bind_method(D_METHOD("set_reference_scale", "reference_scale"),
&SpineSkeletonDataResource::set_reference_scale);
ClassDB::bind_method(D_METHOD("update_skeleton_data"),
&SpineSkeletonDataResource::update_skeleton_data);
ADD_SIGNAL(MethodInfo("skeleton_data_changed"));
ADD_SIGNAL(MethodInfo("_internal_spine_objects_invalidated"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "atlas_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAtlasResource"), "set_atlas_res", "get_atlas_res");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_file_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonFileResource"), "set_skeleton_file_res", "get_skeleton_file_res");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "atlas_res",
PropertyHint::PROPERTY_HINT_RESOURCE_TYPE,
"SpineAtlasResource"),
"set_atlas_res", "get_atlas_res");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_file_res",
PropertyHint::PROPERTY_HINT_RESOURCE_TYPE,
"SpineSkeletonFileResource"),
"set_skeleton_file_res", "get_skeleton_file_res");
#if VERSION_MAJOR > 3
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "default_mix"), "set_default_mix", "get_default_mix");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "default_mix"), "set_default_mix",
"get_default_mix");
#else
ADD_PROPERTY(PropertyInfo(Variant::REAL, "default_mix"), "set_default_mix", "get_default_mix");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "default_mix"), "set_default_mix",
"get_default_mix");
#endif
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animation_mixes"), "set_animation_mixes", "get_animation_mixes");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animation_mixes"),
"set_animation_mixes", "get_animation_mixes");
}
SpineSkeletonDataResource::SpineSkeletonDataResource() : default_mix(0), skeleton_data(nullptr), animation_state_data(nullptr) {
}
SpineSkeletonDataResource::SpineSkeletonDataResource()
: default_mix(0), skeleton_data(nullptr), animation_state_data(nullptr) {}
SpineSkeletonDataResource::~SpineSkeletonDataResource() {
delete skeleton_data;
@ -151,7 +189,8 @@ void SpineSkeletonDataResource::update_skeleton_data() {
emit_signal(SNAME("_internal_spine_objects_invalidated"));
if (atlas_res.is_valid() && skeleton_file_res.is_valid()) {
load_resources(atlas_res->get_spine_atlas(), skeleton_file_res->get_json(), skeleton_file_res->get_binary());
load_resources(atlas_res->get_spine_atlas(), skeleton_file_res->get_json(),
skeleton_file_res->get_binary());
}
emit_signal(SNAME("skeleton_data_changed"));
#ifdef TOOLS_ENABLED
@ -159,8 +198,11 @@ void SpineSkeletonDataResource::update_skeleton_data() {
#endif
}
void SpineSkeletonDataResource::load_resources(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary) {
if ((EMPTY(json) && EMPTY(binary)) || atlas == nullptr) return;
void SpineSkeletonDataResource::load_resources(spine::Atlas *atlas,
const String &json,
const Vector<uint8_t> &binary) {
if ((EMPTY(json) && EMPTY(binary)) || atlas == nullptr)
return;
spine::SkeletonData *data;
if (!EMPTY(json)) {
@ -189,15 +231,23 @@ bool SpineSkeletonDataResource::is_skeleton_data_loaded() const {
return skeleton_data != nullptr;
}
void SpineSkeletonDataResource::set_atlas_res(const Ref<SpineAtlasResource> &atlas) {
void SpineSkeletonDataResource::set_atlas_res(
const Ref<SpineAtlasResource> &atlas) {
atlas_res = atlas;
if (atlas_res.is_valid()) {
#if VERSION_MAJOR > 3
if (!atlas_res->is_connected(SNAME("skeleton_atlas_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data)))
atlas_res->connect(SNAME("skeleton_atlas_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data));
if (!atlas_res->is_connected(
SNAME("skeleton_atlas_changed"),
callable_mp(this,
&SpineSkeletonDataResource::update_skeleton_data)))
atlas_res->connect(
SNAME("skeleton_atlas_changed"),
callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data));
#else
if (!atlas_res->is_connected(SNAME("skeleton_atlas_changed"), this, SNAME("update_skeleton_data")))
atlas_res->connect(SNAME("skeleton_atlas_changed"), this, SNAME("update_skeleton_data"));
if (!atlas_res->is_connected(SNAME("skeleton_atlas_changed"), this,
SNAME("update_skeleton_data")))
atlas_res->connect(SNAME("skeleton_atlas_changed"), this,
SNAME("update_skeleton_data"));
#endif
}
update_skeleton_data();
@ -207,27 +257,38 @@ Ref<SpineAtlasResource> SpineSkeletonDataResource::get_atlas_res() {
return atlas_res;
}
void SpineSkeletonDataResource::set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &skeleton_file) {
void SpineSkeletonDataResource::set_skeleton_file_res(
const Ref<SpineSkeletonFileResource> &skeleton_file) {
skeleton_file_res = skeleton_file;
if (skeleton_file_res.is_valid()) {
#if VERSION_MAJOR > 3
if (!skeleton_file_res->is_connected(SNAME("skeleton_file_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data)))
skeleton_file_res->connect(SNAME("skeleton_file_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data));
if (!skeleton_file_res->is_connected(
SNAME("skeleton_file_changed"),
callable_mp(this,
&SpineSkeletonDataResource::update_skeleton_data)))
skeleton_file_res->connect(
SNAME("skeleton_file_changed"),
callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data));
#else
if (!skeleton_file_res->is_connected(SNAME("skeleton_file_changed"), this, SNAME("update_skeleton_data")))
skeleton_file_res->connect(SNAME("skeleton_file_changed"), this, SNAME("update_skeleton_data"));
if (!skeleton_file_res->is_connected(SNAME("skeleton_file_changed"), this,
SNAME("update_skeleton_data")))
skeleton_file_res->connect(SNAME("skeleton_file_changed"), this,
SNAME("update_skeleton_data"));
#endif
}
update_skeleton_data();
}
Ref<SpineSkeletonFileResource> SpineSkeletonDataResource::get_skeleton_file_res() {
Ref<SpineSkeletonFileResource>
SpineSkeletonDataResource::get_skeleton_file_res() {
return skeleton_file_res;
}
void SpineSkeletonDataResource::get_animation_names(Vector<String> &animation_names) const {
void SpineSkeletonDataResource::get_animation_names(
Vector<String> &animation_names) const {
animation_names.clear();
if (!is_skeleton_data_loaded()) return;
if (!is_skeleton_data_loaded())
return;
auto animations = skeleton_data->getAnimations();
for (size_t i = 0; i < animations.size(); ++i) {
auto animation = animations[i];
@ -235,9 +296,11 @@ void SpineSkeletonDataResource::get_animation_names(Vector<String> &animation_na
}
}
void SpineSkeletonDataResource::get_skin_names(Vector<String> &skin_names) const {
void SpineSkeletonDataResource::get_skin_names(
Vector<String> &skin_names) const {
skin_names.clear();
if (!is_skeleton_data_loaded()) return;
if (!is_skeleton_data_loaded())
return;
auto skins = skeleton_data->getSkins();
for (size_t i = 0; i < skins.size(); ++i) {
auto skin = skins[i];
@ -247,7 +310,8 @@ void SpineSkeletonDataResource::get_skin_names(Vector<String> &skin_names) const
void SpineSkeletonDataResource::get_slot_names(Vector<String> &slot_names) {
slot_names.clear();
if (!is_skeleton_data_loaded()) return;
if (!is_skeleton_data_loaded())
return;
auto slots = skeleton_data->getSlots();
for (size_t i = 0; i < slots.size(); ++i) {
auto slot = slots[i];
@ -257,7 +321,8 @@ void SpineSkeletonDataResource::get_slot_names(Vector<String> &slot_names) {
void SpineSkeletonDataResource::get_bone_names(Vector<String> &bone_names) {
bone_names.clear();
if (!is_skeleton_data_loaded()) return;
if (!is_skeleton_data_loaded())
return;
auto bones = skeleton_data->getBones();
for (size_t i = 0; i < bones.size(); ++i) {
auto bone = bones[i];
@ -270,9 +335,7 @@ void SpineSkeletonDataResource::set_default_mix(float _default_mix) {
update_mixes();
}
float SpineSkeletonDataResource::get_default_mix() {
return default_mix;
}
float SpineSkeletonDataResource::get_default_mix() { return default_mix; }
void SpineSkeletonDataResource::set_animation_mixes(Array _animation_mixes) {
for (int i = 0; i < _animation_mixes.size(); i++) {
@ -292,111 +355,154 @@ Array SpineSkeletonDataResource::get_animation_mixes() {
}
void SpineSkeletonDataResource::update_mixes() {
if (!is_skeleton_data_loaded()) return;
if (!is_skeleton_data_loaded())
return;
animation_state_data->clear();
animation_state_data->setDefaultMix(default_mix);
for (int i = 0; i < animation_mixes.size(); i++) {
Ref<SpineAnimationMix> mix = animation_mixes[i];
spine::Animation *from = skeleton_data->findAnimation(mix->get_from().utf8().ptr());
spine::Animation *to = skeleton_data->findAnimation(mix->get_to().utf8().ptr());
spine::Animation *from =
skeleton_data->findAnimation(mix->get_from().utf8().ptr());
spine::Animation *to =
skeleton_data->findAnimation(mix->get_to().utf8().ptr());
if (!from) {
ERR_PRINT(vformat("Failed to set animation mix %s->%s. Animation %s does not exist in skeleton.", from, to, from));
ERR_PRINT(vformat("Failed to set animation mix %s->%s. Animation %s does "
"not exist in skeleton.",
from, to, from));
continue;
}
if (!to) {
ERR_PRINT(vformat("Failed to set animation mix %s->%s. Animation %s does not exist in skeleton.", from, to, to));
ERR_PRINT(vformat("Failed to set animation mix %s->%s. Animation %s does "
"not exist in skeleton.",
from, to, to));
continue;
}
animation_state_data->setMix(from, to, mix->get_mix());
}
}
Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &animation_name) const {
Ref<SpineAnimation>
SpineSkeletonDataResource::find_animation(const String &animation_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(animation_name)) return nullptr;
auto animation = skeleton_data->findAnimation(SPINE_STRING_TMP(animation_name));
if (!animation) return nullptr;
if (EMPTY(animation_name))
return nullptr;
auto animation =
skeleton_data->findAnimation(SPINE_STRING_TMP(animation_name));
if (!animation)
return nullptr;
Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
animation_ref->set_spine_object(this, animation);
return animation_ref;
}
Ref<SpineBoneData> SpineSkeletonDataResource::find_bone(const String &bone_name) const {
Ref<SpineBoneData>
SpineSkeletonDataResource::find_bone(const String &bone_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(bone_name)) return nullptr;
if (EMPTY(bone_name))
return nullptr;
auto bone = skeleton_data->findBone(SPINE_STRING_TMP(bone_name));
if (!bone) return nullptr;
if (!bone)
return nullptr;
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
bone_ref->set_spine_object(this, bone);
return bone_ref;
}
Ref<SpineSlotData> SpineSkeletonDataResource::find_slot(const String &slot_name) const {
Ref<SpineSlotData>
SpineSkeletonDataResource::find_slot(const String &slot_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(slot_name)) return nullptr;
if (EMPTY(slot_name))
return nullptr;
auto slot = skeleton_data->findSlot(SPINE_STRING_TMP(slot_name));
if (!slot) return nullptr;
if (!slot)
return nullptr;
Ref<SpineSlotData> slot_ref(memnew(SpineSlotData));
slot_ref->set_spine_object(this, slot);
return slot_ref;
}
Ref<SpineSkin> SpineSkeletonDataResource::find_skin(const String &skin_name) const {
Ref<SpineSkin>
SpineSkeletonDataResource::find_skin(const String &skin_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(skin_name)) return nullptr;
if (EMPTY(skin_name))
return nullptr;
auto skin = skeleton_data->findSkin(SPINE_STRING_TMP(skin_name));
if (!skin) return nullptr;
if (!skin)
return nullptr;
Ref<SpineSkin> skin_ref(memnew(SpineSkin));
skin_ref->set_spine_object(this, skin);
return skin_ref;
}
Ref<SpineEventData> SpineSkeletonDataResource::find_event(const String &event_data_name) const {
Ref<SpineEventData>
SpineSkeletonDataResource::find_event(const String &event_data_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(event_data_name)) return nullptr;
if (EMPTY(event_data_name))
return nullptr;
auto event = skeleton_data->findEvent(SPINE_STRING_TMP(event_data_name));
if (!event) return nullptr;
if (!event)
return nullptr;
Ref<SpineEventData> event_ref(memnew(SpineEventData));
event_ref->set_spine_object(this, event);
return event_ref;
}
Ref<SpineIkConstraintData> SpineSkeletonDataResource::find_ik_constraint(const String &constraint_name) const {
Ref<SpineIkConstraintData> SpineSkeletonDataResource::find_ik_constraint(
const String &constraint_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(constraint_name)) return nullptr;
auto constraint = skeleton_data->findIkConstraint(SPINE_STRING_TMP(constraint_name));
if (!constraint) return nullptr;
if (EMPTY(constraint_name))
return nullptr;
auto constraint =
skeleton_data->findIkConstraint(SPINE_STRING_TMP(constraint_name));
if (!constraint)
return nullptr;
Ref<SpineIkConstraintData> constraint_ref(memnew(SpineIkConstraintData));
constraint_ref->set_spine_object(this, constraint);
return constraint_ref;
}
Ref<SpineTransformConstraintData> SpineSkeletonDataResource::find_transform_constraint(const String &constraint_name) const {
Ref<SpineTransformConstraintData>
SpineSkeletonDataResource::find_transform_constraint(
const String &constraint_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(constraint_name)) return nullptr;
auto constraint = skeleton_data->findTransformConstraint(SPINE_STRING_TMP(constraint_name));
if (!constraint) return nullptr;
Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData));
if (EMPTY(constraint_name))
return nullptr;
auto constraint =
skeleton_data->findTransformConstraint(SPINE_STRING_TMP(constraint_name));
if (!constraint)
return nullptr;
Ref<SpineTransformConstraintData> constraint_ref(
memnew(SpineTransformConstraintData));
constraint_ref->set_spine_object(this, constraint);
return constraint_ref;
}
Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(const String &constraint_name) const {
Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(
const String &constraint_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(constraint_name)) return nullptr;
auto constraint = skeleton_data->findPathConstraint(SPINE_STRING_TMP(constraint_name));
if (constraint == nullptr) return nullptr;
if (EMPTY(constraint_name))
return nullptr;
auto constraint =
skeleton_data->findPathConstraint(SPINE_STRING_TMP(constraint_name));
if (constraint == nullptr)
return nullptr;
Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData));
constraint_ref->set_spine_object(this, constraint);
return constraint_ref;
}
Ref<SpinePhysicsConstraintData> SpineSkeletonDataResource::find_physics_constraint(const String &constraint_name) const {
Ref<SpinePhysicsConstraintData>
SpineSkeletonDataResource::find_physics_constraint(
const String &constraint_name) const {
SPINE_CHECK(skeleton_data, nullptr)
if (EMPTY(constraint_name)) return nullptr;
auto constraint = skeleton_data->findPhysicsConstraint(SPINE_STRING_TMP(constraint_name));
if (constraint == nullptr) return nullptr;
Ref<SpinePhysicsConstraintData> constraint_ref(memnew(SpinePhysicsConstraintData));
if (EMPTY(constraint_name))
return nullptr;
auto constraint =
skeleton_data->findPhysicsConstraint(SPINE_STRING_TMP(constraint_name));
if (constraint == nullptr)
return nullptr;
Ref<SpinePhysicsConstraintData> constraint_ref(
memnew(SpinePhysicsConstraintData));
constraint_ref->set_spine_object(this, constraint);
return constraint_ref;
}
@ -448,7 +554,8 @@ Array SpineSkeletonDataResource::get_skins() const {
Ref<SpineSkin> SpineSkeletonDataResource::get_default_skin() const {
SPINE_CHECK(skeleton_data, nullptr)
auto skin = skeleton_data->getDefaultSkin();
if (skin) return nullptr;
if (skin)
return nullptr;
Ref<SpineSkin> skin_ref(memnew(SpineSkin));
skin_ref->set_spine_object(this, skin);
return skin_ref;
@ -456,7 +563,9 @@ Ref<SpineSkin> SpineSkeletonDataResource::get_default_skin() const {
void SpineSkeletonDataResource::set_default_skin(Ref<SpineSkin> skin) {
SPINE_CHECK(skeleton_data, )
skeleton_data->setDefaultSkin(skin.is_valid() && skin->get_spine_object() ? skin->get_spine_object() : nullptr);
skeleton_data->setDefaultSkin(skin.is_valid() && skin->get_spine_object()
? skin->get_spine_object()
: nullptr);
}
Array SpineSkeletonDataResource::get_events() const {
@ -504,7 +613,8 @@ Array SpineSkeletonDataResource::get_transform_constraints() const {
auto constraints = skeleton_data->getTransformConstraints();
result.resize((int) constraints.size());
for (int i = 0; i < constraints.size(); ++i) {
Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData));
Ref<SpineTransformConstraintData> constraint_ref(
memnew(SpineTransformConstraintData));
constraint_ref->set_spine_object(this, constraints[i]);
result[i] = constraint_ref;
}
@ -517,7 +627,8 @@ Array SpineSkeletonDataResource::get_path_constraints() const {
auto constraints = skeleton_data->getPathConstraints();
result.resize((int) constraints.size());
for (int i = 0; i < constraints.size(); ++i) {
Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData));
Ref<SpinePathConstraintData> constraint_ref(
memnew(SpinePathConstraintData));
constraint_ref->set_spine_object(this, constraints[i]);
result[i] = constraint_ref;
}
@ -530,7 +641,8 @@ Array SpineSkeletonDataResource::get_physics_constraints() const {
auto constraints = skeleton_data->getPhysicsConstraints();
result.resize((int) constraints.size());
for (int i = 0; i < constraints.size(); ++i) {
Ref<SpinePhysicsConstraintData> constraint_ref(memnew(SpinePhysicsConstraintData));
Ref<SpinePhysicsConstraintData> constraint_ref(
memnew(SpinePhysicsConstraintData));
constraint_ref->set_spine_object(this, constraints[i]);
result[i] = constraint_ref;
}
@ -581,4 +693,13 @@ float SpineSkeletonDataResource::get_fps() const {
SPINE_CHECK(skeleton_data, 0)
return skeleton_data->getFps();
}
//
float SpineSkeletonDataResource::get_reference_scale() const {
SPINE_CHECK(skeleton_data, 100);
return skeleton_data->getReferenceScale();
}
void SpineSkeletonDataResource::set_reference_scale(float reference_scale) {
SPINE_CHECK(skeleton_data, )
skeleton_data->setReferenceScale(reference_scale);
}

View File

@ -29,17 +29,17 @@
#pragma once
#include "SpineAtlasResource.h"
#include "SpineSkeletonFileResource.h"
#include "SpineAnimation.h"
#include "SpineAtlasResource.h"
#include "SpineBoneData.h"
#include "SpineSlotData.h"
#include "SpineSkin.h"
#include "SpineEventData.h"
#include "SpineIkConstraintData.h"
#include "SpineTransformConstraintData.h"
#include "SpinePathConstraintData.h"
#include "SpinePhysicsConstraintData.h"
#include "SpineEventData.h"
#include "SpineSkeletonFileResource.h"
#include "SpineSkin.h"
#include "SpineSlotData.h"
#include "SpineTransformConstraintData.h"
class SpineAnimationMix : public Resource {
GDCLASS(SpineAnimationMix, Resource)
@ -84,7 +84,8 @@ private:
void update_skeleton_data();
void load_resources(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary);
void load_resources(spine::Atlas *atlas, const String &json,
const Vector<uint8_t> &binary);
public:
SpineSkeletonDataResource();
@ -95,12 +96,15 @@ public:
void set_atlas_res(const Ref<SpineAtlasResource> &atlas);
Ref<SpineAtlasResource> get_atlas_res();
void set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &skeleton_file);
void
set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &skeleton_file);
Ref<SpineSkeletonFileResource> get_skeleton_file_res();
spine::SkeletonData *get_skeleton_data() const { return skeleton_data; }
spine::AnimationStateData *get_animation_state_data() const { return animation_state_data; }
spine::AnimationStateData *get_animation_state_data() const {
return animation_state_data;
}
void get_animation_names(Vector<String> &animation_names) const;
@ -118,7 +122,8 @@ public:
Array get_animation_mixes();
// Used by SpineEditorPropertyAnimationMix(es) to update the underlying AnimationState
// Used by SpineEditorPropertyAnimationMix(es) to update the underlying
// AnimationState
void update_mixes();
// Spine API
@ -132,13 +137,17 @@ public:
Ref<SpineAnimation> find_animation(const String &animation_name) const;
Ref<SpineIkConstraintData> find_ik_constraint(const String &constraint_name) const;
Ref<SpineIkConstraintData>
find_ik_constraint(const String &constraint_name) const;
Ref<SpineTransformConstraintData> find_transform_constraint(const String &constraint_name) const;
Ref<SpineTransformConstraintData>
find_transform_constraint(const String &constraint_name) const;
Ref<SpinePathConstraintData> find_path_constraint(const String &constraint_name) const;
Ref<SpinePathConstraintData>
find_path_constraint(const String &constraint_name) const;
Ref<SpinePhysicsConstraintData> find_physics_constraint(const String &constraint_name) const;
Ref<SpinePhysicsConstraintData>
find_physics_constraint(const String &constraint_name) const;
String get_skeleton_name() const;
@ -181,4 +190,8 @@ public:
String get_audio_path() const;
float get_fps() const;
float get_reference_scale() const;
void set_reference_scale(float reference_scale);
};