mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 15:24:55 +08:00
[godot] Merge SpineAnimationStateDataResource and SpineSkeletonDataResource, test new SpineCollisionShapeProxy
This commit is contained in:
parent
da3b8db72a
commit
991b0a73fa
12
.gitignore
vendored
12
.gitignore
vendored
@ -164,8 +164,12 @@ spine-cocos2dx/example-v4/build-macos
|
||||
spine-cocos2dx/example/build-ios
|
||||
spine-cocos2dx/example/proj.android/app/.cxx
|
||||
spine-cocos2dx/example/build-win
|
||||
spine-godot/godot
|
||||
spine-godot/spine_godot/__pycache__
|
||||
spine-godot/spine_godot/spine-cpp
|
||||
spine-godot/godot-copy
|
||||
spine-godot/godot/*
|
||||
!spine-godot/godot/modules/
|
||||
spine-godot/godot/modules/*
|
||||
!spine-godot/godot/modules/spine_godot/
|
||||
spine-godot/godot/modules/spine_godot/*.o
|
||||
spine-godot/godot/modules/spine_godot/__pycache__
|
||||
spine-godot/godot/modules/spine_godot/spine-cpp
|
||||
spine-godot/godot/modules/godot-copy
|
||||
spine-godot/example/.import
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -59,7 +59,6 @@ void SpineCollisionShapeProxy::_notification(int p_what) {
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
if (!disabled) {
|
||||
if (sync_transform) synchronize_transform(get_spine_sprite());
|
||||
update_polygon_from_spine_sprite(get_spine_sprite());
|
||||
if (is_visible()) update();
|
||||
}
|
||||
} break;
|
||||
@ -85,40 +84,57 @@ String SpineCollisionShapeProxy::get_slot() const {
|
||||
|
||||
void SpineCollisionShapeProxy::set_slot(const String &slotName) {
|
||||
slot_name = slotName;
|
||||
spine::Slot *slot = get_spine_slot(slot_name);
|
||||
if (!slot) return;
|
||||
spine::Attachment *attachment = slot->getAttachment();
|
||||
if (!attachment) {
|
||||
print_line(vformat("Slot %s has no attachment set.", slot_name));
|
||||
return;
|
||||
}
|
||||
if (!attachment->getRTTI().isExactly(spine::BoundingBoxAttachment::rtti)) {
|
||||
print_line(vformat("Attachment in slot %s is not a bounding box attachment.", slot_name));
|
||||
return;
|
||||
}
|
||||
update_polygon_from_spine_sprite(get_spine_sprite());
|
||||
}
|
||||
|
||||
spine::Slot *SpineCollisionShapeProxy::get_spine_slot(const String &slotName) const {
|
||||
auto sprite = get_spine_sprite();
|
||||
if (sprite == NULL || slot_name.empty()) return NULL;
|
||||
if (!sprite->get_skeleton().is_valid()) return NULL;
|
||||
spine::Skeleton *skeleton = sprite->get_skeleton()->get_spine_object();
|
||||
spine::Slot *slot = skeleton->findSlot(spine::String(slot_name.utf8()));
|
||||
return slot;
|
||||
}
|
||||
|
||||
void SpineCollisionShapeProxy::update_polygon_from_spine_sprite(SpineSprite *sprite) {
|
||||
clear_polygon();
|
||||
if (sprite == NULL || slot_name.empty()) return;
|
||||
if (!sprite->get_skeleton().is_valid()) return;
|
||||
|
||||
spine::Skeleton *skeleton = sprite->get_skeleton()->get_spine_object();
|
||||
spine::Slot *slot = skeleton->findSlot(spine::String(slot_name.utf8()));
|
||||
spine::Slot *slot = get_spine_slot(slot_name);
|
||||
if (!slot) return;
|
||||
spine::Attachment *attachment = slot->getAttachment();
|
||||
if (!attachment) return;
|
||||
if(!attachment) return;
|
||||
|
||||
spine::Vector<float> vertices;
|
||||
if (attachment->getRTTI().isExactly(spine::BoundingBoxAttachment::rtti)) {
|
||||
auto *box = (spine::BoundingBoxAttachment *) attachment;
|
||||
vertices.setSize(box->getWorldVerticesLength(), 0);
|
||||
box->computeWorldVertices(*slot, vertices);
|
||||
scratch_vertices.setSize(box->getWorldVerticesLength(), 0);
|
||||
box->computeWorldVertices(*slot, scratch_vertices);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
polygon.resize(vertices.size() / 2);
|
||||
for (size_t j = 0; j < vertices.size(); j += 2) {
|
||||
polygon.set(j / 2, Vector2(vertices[j], -vertices[j + 1]));
|
||||
polygon.resize(scratch_vertices.size() / 2);
|
||||
for (size_t j = 0; j < scratch_vertices.size(); j += 2) {
|
||||
polygon.set(j / 2, Vector2(scratch_vertices[j], -scratch_vertices[j + 1]));
|
||||
}
|
||||
|
||||
set_polygon(polygon);
|
||||
_set("polygon", polygon);
|
||||
// set_polygon(polygon);
|
||||
}
|
||||
|
||||
void SpineCollisionShapeProxy::clear_polygon() {
|
||||
polygon.clear();
|
||||
set_polygon(polygon);
|
||||
_set("polygon", polygon);
|
||||
// set_polygon(polygon);
|
||||
}
|
||||
|
||||
void SpineCollisionShapeProxy::synchronize_transform(SpineSprite *sprite) {
|
||||
@ -136,12 +152,13 @@ void SpineCollisionShapeProxy::set_sync_transform(bool sync_transform) {
|
||||
|
||||
void SpineCollisionShapeProxy::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
PropertyInfo p;
|
||||
Vector<String> res;
|
||||
Vector<String> slot_names;
|
||||
p.name = "Slot";
|
||||
p.type = Variant::STRING;
|
||||
get_slot_list(res);
|
||||
if (res.empty()) res.push_back("None");
|
||||
p.hint_string = String(",").join(res);
|
||||
get_slot_names(slot_names);
|
||||
if (slot_names.empty())
|
||||
slot_names.push_back("None");
|
||||
p.hint_string = String(",").join(slot_names);
|
||||
p.hint = PROPERTY_HINT_ENUM;
|
||||
p_list->push_back(p);
|
||||
}
|
||||
@ -162,16 +179,16 @@ bool SpineCollisionShapeProxy::_set(const StringName &p_property, const Variant
|
||||
return false;
|
||||
}
|
||||
|
||||
void SpineCollisionShapeProxy::get_slot_list(Vector<String> &slotNames) const {
|
||||
void SpineCollisionShapeProxy::get_slot_names(Vector<String> &slot_names) const {
|
||||
if (get_spine_sprite() == nullptr) return;
|
||||
auto sprite = get_spine_sprite();
|
||||
if (!sprite->get_skeleton().is_valid()) return;
|
||||
|
||||
auto slots = sprite->get_skeleton()->get_slots();
|
||||
slots.resize(slotNames.size());
|
||||
for (size_t i = 0; i < slotNames.size(); ++i) {
|
||||
auto slot = (Ref<SpineSlot>) slotNames[i];
|
||||
slot_names.resize(slots.size());
|
||||
for (size_t i = 0; i < slots.size(); ++i) {
|
||||
auto slot = (Ref<SpineSlot>) slots[i];
|
||||
if (slot.is_valid())
|
||||
slots.set(i, slot->get_data()->get_slot_name());
|
||||
slot_names.set(i, slot->get_data()->get_slot_name());
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
#define GODOT_SPINECOLLISIONSHAPEPROXY_H
|
||||
|
||||
#include "scene/2d/collision_polygon_2d.h"
|
||||
#include <spine/spine.h>
|
||||
|
||||
class SpineSprite;
|
||||
class SpineAnimationState;
|
||||
@ -47,6 +48,8 @@ protected:
|
||||
|
||||
bool sync_transform;
|
||||
|
||||
spine::Vector<float> scratch_vertices;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
@ -56,13 +59,15 @@ protected:
|
||||
|
||||
SpineSprite *get_spine_sprite() const;
|
||||
|
||||
spine::Slot *get_spine_slot(const String &slotName) const;
|
||||
|
||||
void update_polygon_from_spine_sprite(SpineSprite *sprite);
|
||||
|
||||
void clear_polygon();
|
||||
|
||||
void synchronize_transform(SpineSprite *sprite);
|
||||
|
||||
void get_slot_list(Vector<String> &slotNames) const;
|
||||
void get_slot_names(Vector<String> &slot_names) const;
|
||||
|
||||
public:
|
||||
SpineCollisionShapeProxy();
|
||||
|
||||
@ -0,0 +1,457 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "SpineNewSkeletonDataResource.h"
|
||||
|
||||
void SpineNewSkeletonDataResource::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_atlas_res", "atlas_res"), &SpineNewSkeletonDataResource::set_atlas_res);
|
||||
ClassDB::bind_method(D_METHOD("get_atlas_res"), &SpineNewSkeletonDataResource::get_atlas_res);
|
||||
ClassDB::bind_method(D_METHOD("set_skeleton_file_res", "skeleton_file_res"), &SpineNewSkeletonDataResource::set_skeleton_file_res);
|
||||
ClassDB::bind_method(D_METHOD("get_skeleton_file_res"), &SpineNewSkeletonDataResource::get_skeleton_file_res);
|
||||
ClassDB::bind_method(D_METHOD("is_skeleton_data_loaded"), &SpineNewSkeletonDataResource::is_skeleton_data_loaded);
|
||||
ClassDB::bind_method(D_METHOD("find_animation", "animation_name"), &SpineNewSkeletonDataResource::find_animation);
|
||||
ClassDB::bind_method(D_METHOD("get_skeleton_name"), &SpineNewSkeletonDataResource::get_skeleton_name);
|
||||
ClassDB::bind_method(D_METHOD("set_skeleton_name", "skeleton_name"), &SpineNewSkeletonDataResource::set_skeleton_name);
|
||||
ClassDB::bind_method(D_METHOD("get_x"), &SpineNewSkeletonDataResource::get_x);
|
||||
ClassDB::bind_method(D_METHOD("set_x", "v"), &SpineNewSkeletonDataResource::set_x);
|
||||
ClassDB::bind_method(D_METHOD("get_y"), &SpineNewSkeletonDataResource::get_y);
|
||||
ClassDB::bind_method(D_METHOD("set_y", "v"), &SpineNewSkeletonDataResource::set_y);
|
||||
ClassDB::bind_method(D_METHOD("get_width"), &SpineNewSkeletonDataResource::get_width);
|
||||
ClassDB::bind_method(D_METHOD("get_height"), &SpineNewSkeletonDataResource::get_height);
|
||||
ClassDB::bind_method(D_METHOD("get_version"), &SpineNewSkeletonDataResource::get_version);
|
||||
ClassDB::bind_method(D_METHOD("get_fps"), &SpineNewSkeletonDataResource::get_fps);
|
||||
ClassDB::bind_method(D_METHOD("set_fps", "v"), &SpineNewSkeletonDataResource::set_fps);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("find_bone", "bone_name"), &SpineNewSkeletonDataResource::find_bone);
|
||||
ClassDB::bind_method(D_METHOD("find_slot", "slot_name"), &SpineNewSkeletonDataResource::find_slot);
|
||||
ClassDB::bind_method(D_METHOD("find_skin", "skin_name"), &SpineNewSkeletonDataResource::find_skin);
|
||||
ClassDB::bind_method(D_METHOD("find_event", "event_data_name"), &SpineNewSkeletonDataResource::find_event);
|
||||
ClassDB::bind_method(D_METHOD("find_ik_constraint_data", "constraint_name"), &SpineNewSkeletonDataResource::find_ik_constraint);
|
||||
ClassDB::bind_method(D_METHOD("find_transform_constraint_data", "constraint_name"), &SpineNewSkeletonDataResource::find_transform_constraint);
|
||||
ClassDB::bind_method(D_METHOD("find_path_constraint_data", "constraint_name"), &SpineNewSkeletonDataResource::find_path_constraint);
|
||||
ClassDB::bind_method(D_METHOD("get_all_bone_data"), &SpineNewSkeletonDataResource::get_bones);
|
||||
ClassDB::bind_method(D_METHOD("get_all_slot_data"), &SpineNewSkeletonDataResource::get_slots);
|
||||
ClassDB::bind_method(D_METHOD("get_skins"), &SpineNewSkeletonDataResource::get_skins);
|
||||
ClassDB::bind_method(D_METHOD("get_default_skin"), &SpineNewSkeletonDataResource::get_default_skin);
|
||||
ClassDB::bind_method(D_METHOD("set_default_skin", "v"), &SpineNewSkeletonDataResource::set_default_skin);
|
||||
ClassDB::bind_method(D_METHOD("get_all_event_data"), &SpineNewSkeletonDataResource::get_events);
|
||||
ClassDB::bind_method(D_METHOD("get_animations"), &SpineNewSkeletonDataResource::get_animations);
|
||||
ClassDB::bind_method(D_METHOD("get_all_ik_constraint_data"), &SpineNewSkeletonDataResource::get_ik_constraints);
|
||||
ClassDB::bind_method(D_METHOD("get_all_transform_constraint_data"), &SpineNewSkeletonDataResource::get_transform_constraints);
|
||||
ClassDB::bind_method(D_METHOD("get_all_path_constraint_data"), &SpineNewSkeletonDataResource::get_path_constraints);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("skeleton_data_loaded"));
|
||||
ADD_SIGNAL(MethodInfo("atlas_res_changed"));
|
||||
ADD_SIGNAL(MethodInfo("skeleton_file_res_changed"));
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
SpineNewSkeletonDataResource::SpineNewSkeletonDataResource() : valid(false), spine_object(false), skeleton_data(NULL) {
|
||||
}
|
||||
|
||||
SpineNewSkeletonDataResource::~SpineNewSkeletonDataResource() {
|
||||
if (skeleton_data && !spine_object) {
|
||||
delete skeleton_data;
|
||||
skeleton_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool SpineNewSkeletonDataResource::is_skeleton_data_loaded() const {
|
||||
return valid || spine_object;
|
||||
}
|
||||
|
||||
void SpineNewSkeletonDataResource::load_res(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary) {
|
||||
valid = false;
|
||||
if (skeleton_data) {
|
||||
delete skeleton_data;
|
||||
skeleton_data = NULL;
|
||||
}
|
||||
|
||||
if ((json.empty() && binary.empty()) || atlas == NULL) return;
|
||||
|
||||
spine::SkeletonData *skeletonData = NULL;
|
||||
if (!json.empty()) {
|
||||
spine::SkeletonJson skeletonJson(atlas);
|
||||
skeletonData = skeletonJson.readSkeletonData(json.utf8());
|
||||
if (!skeletonData) {
|
||||
print_error(String("Error while loading skeleton data: ") + get_path());
|
||||
print_error(String("Error message: ") + skeletonJson.getError().buffer());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
spine::SkeletonBinary skeletonBinary(atlas);
|
||||
skeletonData = skeletonBinary.readSkeletonData(binary.ptr(), binary.size());
|
||||
if (!skeletonData) {
|
||||
print_error(String("Error while loading skeleton data: ") + get_path());
|
||||
print_error(String("Error message: ") + skeletonBinary.getError().buffer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
skeleton_data = skeletonData;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
void SpineNewSkeletonDataResource::update_skeleton_data() {
|
||||
if (atlas_res.is_valid() && skeleton_file_res.is_valid()) {
|
||||
load_res(atlas_res->get_spine_atlas(), skeleton_file_res->get_json(), skeleton_file_res->get_binary());
|
||||
if (valid) {
|
||||
emit_signal("skeleton_data_loaded");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpineNewSkeletonDataResource::set_atlas_res(const Ref<SpineAtlasResource> &a) {
|
||||
atlas_res = a;
|
||||
valid = false;
|
||||
emit_signal("atlas_res_changed");
|
||||
update_skeleton_data();
|
||||
}
|
||||
Ref<SpineAtlasResource> SpineNewSkeletonDataResource::get_atlas_res() {
|
||||
return atlas_res;
|
||||
}
|
||||
|
||||
void SpineNewSkeletonDataResource::set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &s) {
|
||||
skeleton_file_res = s;
|
||||
valid = false;
|
||||
emit_signal("skeleton_file_res_changed");
|
||||
update_skeleton_data();
|
||||
}
|
||||
Ref<SpineSkeletonFileResource> SpineNewSkeletonDataResource::get_skeleton_file_res() {
|
||||
return skeleton_file_res;
|
||||
}
|
||||
|
||||
#define CHECK(x) \
|
||||
if (!is_skeleton_data_loaded()) { \
|
||||
ERR_PRINT("skeleton data has not loaded yet!"); \
|
||||
return x; \
|
||||
}
|
||||
|
||||
#define S_T(x) (spine::String(x.utf8()))
|
||||
Ref<SpineAnimation> SpineNewSkeletonDataResource::find_animation(const String &animation_name) {
|
||||
CHECK(NULL);
|
||||
if (animation_name.empty()) {
|
||||
return NULL;
|
||||
}
|
||||
auto a = skeleton_data->findAnimation(S_T(animation_name));
|
||||
if (!a) return NULL;
|
||||
Ref<SpineAnimation> sa(memnew(SpineAnimation));
|
||||
sa->set_spine_object(a);
|
||||
return sa;
|
||||
}
|
||||
String SpineNewSkeletonDataResource::get_skeleton_name() {
|
||||
CHECK("");
|
||||
return skeleton_data->getName().buffer();
|
||||
}
|
||||
|
||||
void SpineNewSkeletonDataResource::set_skeleton_name(const String &v) {
|
||||
CHECK();
|
||||
skeleton_data->setName(S_T(v));
|
||||
}
|
||||
|
||||
float SpineNewSkeletonDataResource::get_x() {
|
||||
CHECK(0);
|
||||
return skeleton_data->getX();
|
||||
}
|
||||
|
||||
void SpineNewSkeletonDataResource::set_x(float v) {
|
||||
CHECK();
|
||||
skeleton_data->setX(v);
|
||||
}
|
||||
float SpineNewSkeletonDataResource::get_y() {
|
||||
CHECK(0);
|
||||
return skeleton_data->getY();
|
||||
}
|
||||
void SpineNewSkeletonDataResource::set_y(float v) {
|
||||
CHECK();
|
||||
skeleton_data->setY(v);
|
||||
}
|
||||
float SpineNewSkeletonDataResource::get_width() {
|
||||
CHECK(0);
|
||||
return skeleton_data->getWidth();
|
||||
}
|
||||
float SpineNewSkeletonDataResource::get_height() {
|
||||
CHECK(0);
|
||||
return skeleton_data->getHeight();
|
||||
}
|
||||
String SpineNewSkeletonDataResource::get_version() {
|
||||
CHECK("error");
|
||||
return skeleton_data->getVersion().buffer();
|
||||
}
|
||||
float SpineNewSkeletonDataResource::get_fps() {
|
||||
CHECK(0);
|
||||
return skeleton_data->getFps();
|
||||
}
|
||||
void SpineNewSkeletonDataResource::set_fps(float v) {
|
||||
CHECK();
|
||||
skeleton_data->setFps(v);
|
||||
}
|
||||
|
||||
Ref<SpineBoneData> SpineNewSkeletonDataResource::find_bone(const String &bone_name) {
|
||||
if (bone_name.empty()) return NULL;
|
||||
auto b = skeleton_data->findBone(S_T(bone_name));
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
|
||||
Ref<SpineSlotData> SpineNewSkeletonDataResource::find_slot(const String &slot_name) {
|
||||
if (slot_name.empty()) return NULL;
|
||||
auto b = skeleton_data->findSlot(S_T(slot_name));
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineSlotData> gd_b(memnew(SpineSlotData));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
|
||||
Ref<SpineSkin> SpineNewSkeletonDataResource::find_skin(const String &skin_name) {
|
||||
if (skin_name.empty()) return NULL;
|
||||
auto b = skeleton_data->findSkin(S_T(skin_name));
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineSkin> gd_b(memnew(SpineSkin));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
|
||||
Ref<SpineEventData> SpineNewSkeletonDataResource::find_event(const String &event_data_name) {
|
||||
if (event_data_name.empty()) return NULL;
|
||||
auto b = skeleton_data->findEvent(S_T(event_data_name));
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineEventData> gd_b(memnew(SpineEventData));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
|
||||
Ref<SpineIkConstraintData> SpineNewSkeletonDataResource::find_ik_constraint(const String &constraint_name) {
|
||||
if (constraint_name.empty()) return NULL;
|
||||
auto b = skeleton_data->findIkConstraint(S_T(constraint_name));
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineIkConstraintData> gd_b(memnew(SpineIkConstraintData));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
Ref<SpineTransformConstraintData> SpineNewSkeletonDataResource::find_transform_constraint(const String &constraint_name) {
|
||||
if (constraint_name.empty()) return NULL;
|
||||
auto b = skeleton_data->findTransformConstraint(S_T(constraint_name));
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineTransformConstraintData> gd_b(memnew(SpineTransformConstraintData));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
Ref<SpinePathConstraintData> SpineNewSkeletonDataResource::find_path_constraint(const String &constraint_name) {
|
||||
if (constraint_name.empty()) return NULL;
|
||||
auto b = skeleton_data->findPathConstraint(S_T(constraint_name));
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpinePathConstraintData> gd_b(memnew(SpinePathConstraintData));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
|
||||
Array SpineNewSkeletonDataResource::get_bones() {
|
||||
auto bs = skeleton_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;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
Array SpineNewSkeletonDataResource::get_slots() {
|
||||
auto bs = skeleton_data->getSlots();
|
||||
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<SpineSlotData>(NULL);
|
||||
else {
|
||||
Ref<SpineSlotData> gd_b(memnew(SpineSlotData));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
Array SpineNewSkeletonDataResource::get_skins() const {
|
||||
auto bs = skeleton_data->getSkins();
|
||||
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<SpineSkin>(NULL);
|
||||
else {
|
||||
Ref<SpineSkin> gd_b(memnew(SpineSkin));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
|
||||
Ref<SpineSkin> SpineNewSkeletonDataResource::get_default_skin() {
|
||||
auto b = skeleton_data->getDefaultSkin();
|
||||
if (b == NULL) return NULL;
|
||||
Ref<SpineSkin> gd_b(memnew(SpineSkin));
|
||||
gd_b->set_spine_object(b);
|
||||
return gd_b;
|
||||
}
|
||||
void SpineNewSkeletonDataResource::set_default_skin(Ref<SpineSkin> v) {
|
||||
if (v.is_valid()) {
|
||||
skeleton_data->setDefaultSkin(v->get_spine_object());
|
||||
} else
|
||||
skeleton_data->setDefaultSkin(NULL);
|
||||
}
|
||||
|
||||
Array SpineNewSkeletonDataResource::get_events() {
|
||||
auto bs = skeleton_data->getEvents();
|
||||
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<SpineEventData>(NULL);
|
||||
else {
|
||||
Ref<SpineEventData> gd_b(memnew(SpineEventData));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
Array SpineNewSkeletonDataResource::get_animations() {
|
||||
auto bs = skeleton_data->getAnimations();
|
||||
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<SpineAnimation>(NULL);
|
||||
else {
|
||||
Ref<SpineAnimation> gd_b(memnew(SpineAnimation));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
Array SpineNewSkeletonDataResource::get_ik_constraints() {
|
||||
auto bs = skeleton_data->getIkConstraints();
|
||||
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<SpineIkConstraintData>(NULL);
|
||||
else {
|
||||
Ref<SpineIkConstraintData> gd_b(memnew(SpineIkConstraintData));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
Array SpineNewSkeletonDataResource::get_transform_constraints() {
|
||||
auto bs = skeleton_data->getTransformConstraints();
|
||||
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<SpineTransformConstraintData>(NULL);
|
||||
else {
|
||||
Ref<SpineTransformConstraintData> gd_b(memnew(SpineTransformConstraintData));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
Array SpineNewSkeletonDataResource::get_path_constraints() {
|
||||
auto bs = skeleton_data->getPathConstraints();
|
||||
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<SpinePathConstraintData>(NULL);
|
||||
else {
|
||||
Ref<SpinePathConstraintData> gd_b(memnew(SpinePathConstraintData));
|
||||
gd_b->set_spine_object(bs[i]);
|
||||
gd_bs[i] = gd_b;
|
||||
}
|
||||
}
|
||||
return gd_bs;
|
||||
}
|
||||
#undef S_T
|
||||
#undef CHECK_V
|
||||
#undef CHECK
|
||||
|
||||
//External feature functions
|
||||
void SpineNewSkeletonDataResource::get_animation_names(Vector<String> &res) const {
|
||||
res.clear();
|
||||
if (!is_skeleton_data_loaded()) {
|
||||
return;
|
||||
}
|
||||
auto as = skeleton_data->getAnimations();
|
||||
for (size_t i = 0; i < as.size(); ++i) {
|
||||
auto a = as[i];
|
||||
if (a) {
|
||||
res.push_back(a->getName().buffer());
|
||||
} else {
|
||||
res.push_back("");
|
||||
}
|
||||
}
|
||||
}
|
||||
void SpineNewSkeletonDataResource::get_skin_names(Vector<String> &res) const {
|
||||
res.clear();
|
||||
if (!is_skeleton_data_loaded()) return;
|
||||
auto as = get_skins();
|
||||
res.resize(as.size());
|
||||
for (size_t i = 0; i < as.size(); ++i) {
|
||||
auto a = Ref<SpineSkin>(as[i]);
|
||||
if (a.is_valid()) {
|
||||
res.set(i, a->get_skin_name());
|
||||
} else {
|
||||
res.set(i, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpineNewSkeletonDataResource::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
PropertyInfo p;
|
||||
Vector<String> res;
|
||||
|
||||
p.name = "animations";
|
||||
p.type = Variant::STRING;
|
||||
get_animation_names(res);
|
||||
p.hint_string = String(",").join(res);
|
||||
p.hint = PROPERTY_HINT_ENUM;
|
||||
p_list->push_back(p);
|
||||
|
||||
p.name = "skins";
|
||||
p.type = Variant::STRING;
|
||||
get_skin_names(res);
|
||||
p.hint_string = String(",").join(res);
|
||||
p.hint = PROPERTY_HINT_ENUM;
|
||||
p_list->push_back(p);
|
||||
}
|
||||
@ -0,0 +1,107 @@
|
||||
#ifndef GODOT_SPINENEWSKELETONDATARESOURCE_H
|
||||
#define GODOT_SPINENEWSKELETONDATARESOURCE_H
|
||||
|
||||
#include "SpineAtlasResource.h"
|
||||
#include "SpineSkeletonFileResource.h"
|
||||
#include "SpineAnimation.h"
|
||||
#include "SpineBoneData.h"
|
||||
#include "SpineSlotData.h"
|
||||
#include "SpineSkin.h"
|
||||
#include "SpineIkConstraintData.h"
|
||||
#include "SpineTransformConstraintData.h"
|
||||
#include "SpinePathConstraintData.h"
|
||||
#include "SpineEventData.h"
|
||||
|
||||
class SpineNewSkeletonDataResource : public Resource {
|
||||
GDCLASS(SpineNewSkeletonDataResource, Resource);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<SpineAtlasResource> atlas_res;
|
||||
Ref<SpineSkeletonFileResource> skeleton_file_res;
|
||||
bool valid;
|
||||
bool spine_object;
|
||||
|
||||
spine::SkeletonData *skeleton_data;
|
||||
|
||||
void update_skeleton_data();
|
||||
|
||||
public:
|
||||
SpineNewSkeletonDataResource();
|
||||
virtual ~SpineNewSkeletonDataResource();
|
||||
|
||||
inline void set_spine_object(spine::SkeletonData *s) {
|
||||
skeleton_data = s;
|
||||
if (s)
|
||||
spine_object = true;
|
||||
}
|
||||
inline spine::SkeletonData *get_spine_object() {
|
||||
return skeleton_data;
|
||||
}
|
||||
|
||||
void load_res(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary);
|
||||
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
void set_atlas_res(const Ref<SpineAtlasResource> &a);
|
||||
Ref<SpineAtlasResource> get_atlas_res();
|
||||
|
||||
void set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &s);
|
||||
Ref<SpineSkeletonFileResource> get_skeleton_file_res();
|
||||
|
||||
inline spine::SkeletonData *get_skeleton_data() { return skeleton_data; }
|
||||
|
||||
bool is_skeleton_data_loaded() const;
|
||||
|
||||
void get_animation_names(Vector<String> &l) const;
|
||||
void get_skin_names(Vector<String> &l) const;
|
||||
|
||||
Ref<SpineBoneData> find_bone(const String &bone_name);
|
||||
|
||||
Ref<SpineSlotData> find_slot(const String &slot_name);
|
||||
|
||||
Ref<SpineSkin> find_skin(const String &skin_name);
|
||||
|
||||
Ref<SpineEventData> find_event(const String &event_data_name);
|
||||
|
||||
Ref<SpineAnimation> find_animation(const String &animation_name);
|
||||
|
||||
Ref<SpineIkConstraintData> find_ik_constraint(const String &constraint_name);
|
||||
Ref<SpineTransformConstraintData> find_transform_constraint(const String &constraint_name);
|
||||
Ref<SpinePathConstraintData> find_path_constraint(const String &constraint_name);
|
||||
|
||||
Array get_bones();
|
||||
Array get_slots();
|
||||
Array get_skins() const;
|
||||
|
||||
Ref<SpineSkin> get_default_skin();
|
||||
void set_default_skin(Ref<SpineSkin> v);
|
||||
|
||||
Array get_events();
|
||||
Array get_animations();
|
||||
Array get_ik_constraints();
|
||||
Array get_transform_constraints();
|
||||
Array get_path_constraints();
|
||||
|
||||
String get_skeleton_name();
|
||||
void set_skeleton_name(const String &v);
|
||||
|
||||
float get_x();
|
||||
void set_x(float v);
|
||||
|
||||
float get_y();
|
||||
void set_y(float v);
|
||||
|
||||
float get_width();
|
||||
float get_height();
|
||||
|
||||
String get_version();
|
||||
|
||||
float get_fps();
|
||||
void set_fps(float v);
|
||||
};
|
||||
|
||||
|
||||
#endif //GODOT_SPINENEWSKELETONDATARESOURCE_H
|
||||
@ -30,10 +30,6 @@
|
||||
#ifndef GODOT_SPINESKELETONDATARESOURCE_H
|
||||
#define GODOT_SPINESKELETONDATARESOURCE_H
|
||||
|
||||
#include "core/variant_parser.h"
|
||||
|
||||
#include <spine/spine.h>
|
||||
|
||||
#include "SpineAtlasResource.h"
|
||||
#include "SpineSkeletonFileResource.h"
|
||||
#include "SpineAnimation.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user