mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[godot] Formatting
This commit is contained in:
parent
0b0800143a
commit
5ec5544132
@ -25,7 +25,9 @@ spotless {
|
|||||||
'spine-sfml/**/*.cpp',
|
'spine-sfml/**/*.cpp',
|
||||||
'spine-sfml/**/*.h',
|
'spine-sfml/**/*.h',
|
||||||
'spine-ue4/**/*.cpp',
|
'spine-ue4/**/*.cpp',
|
||||||
'spine-ue4/**/*.h'
|
'spine-ue4/**/*.h',
|
||||||
|
'spine-godot/spine_godot/**.h',
|
||||||
|
'spine-godot/spine_godot/**.cpp'
|
||||||
clangFormat("12.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
|
clangFormat("12.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,7 +51,4 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif//GODOT_SPINEEXTENSION_H
|
#endif//GODOT_SPINEEXTENSION_H
|
||||||
|
|||||||
@ -53,7 +53,6 @@ public:
|
|||||||
|
|
||||||
void set_sub_skin_names(Array v);
|
void set_sub_skin_names(Array v);
|
||||||
Array get_sub_skin_names();
|
Array get_sub_skin_names();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif//GODOT_PACKEDSPINESKINRESOURCE_H
|
#endif//GODOT_PACKEDSPINESKINRESOURCE_H
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
class ResourceFormatLoaderSpineAtlas : public ResourceFormatLoader {
|
class ResourceFormatLoaderSpineAtlas : public ResourceFormatLoader {
|
||||||
GDCLASS(ResourceFormatLoaderSpineAtlas, ResourceFormatLoader);
|
GDCLASS(ResourceFormatLoaderSpineAtlas, ResourceFormatLoader);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
|
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
|
||||||
virtual void get_recognized_extensions(List<String> *r_extensions) const;
|
virtual void get_recognized_extensions(List<String> *r_extensions) const;
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
class ResourceFormatLoaderSpineSkeletonJsonData : public ResourceFormatLoader {
|
class ResourceFormatLoaderSpineSkeletonJsonData : public ResourceFormatLoader {
|
||||||
GDCLASS(ResourceFormatLoaderSpineSkeletonJsonData, ResourceFormatLoader);
|
GDCLASS(ResourceFormatLoaderSpineSkeletonJsonData, ResourceFormatLoader);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
|
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
|
||||||
virtual void get_recognized_extensions(List<String> *r_extensions) const;
|
virtual void get_recognized_extensions(List<String> *r_extensions) const;
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
class ResourceFormatSaverSpineAtlas : public ResourceFormatSaver {
|
class ResourceFormatSaverSpineAtlas : public ResourceFormatSaver {
|
||||||
GDCLASS(ResourceFormatSaverSpineAtlas, ResourceFormatSaver);
|
GDCLASS(ResourceFormatSaverSpineAtlas, ResourceFormatSaver);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
|
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
|
||||||
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
|
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
class ResourceFormatSaverSpineSkeletonJsonData : public ResourceFormatSaver {
|
class ResourceFormatSaverSpineSkeletonJsonData : public ResourceFormatSaver {
|
||||||
GDCLASS(ResourceFormatSaverSpineSkeletonJsonData, ResourceFormatSaver);
|
GDCLASS(ResourceFormatSaverSpineSkeletonJsonData, ResourceFormatSaver);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
|
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
|
||||||
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
|
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
|
||||||
|
|||||||
@ -49,20 +49,17 @@ void SpineAnimationState::_bind_methods() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpineAnimationState::SpineAnimationState() : animation_state(NULL) {
|
SpineAnimationState::SpineAnimationState() : animation_state(NULL) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineAnimationState::~SpineAnimationState() {
|
SpineAnimationState::~SpineAnimationState() {
|
||||||
if(animation_state)
|
if (animation_state) {
|
||||||
{
|
|
||||||
delete animation_state;
|
delete animation_state;
|
||||||
animation_state = NULL;
|
animation_state = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResource> ad) {
|
void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResource> ad) {
|
||||||
if(animation_state)
|
if (animation_state) {
|
||||||
{
|
|
||||||
delete animation_state;
|
delete animation_state;
|
||||||
animation_state = NULL;
|
animation_state = NULL;
|
||||||
}
|
}
|
||||||
@ -71,28 +68,33 @@ void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResour
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpineAnimationState::reload_animation_state() {
|
void SpineAnimationState::reload_animation_state() {
|
||||||
if(!anim_state_data_res.is_valid())
|
if (!anim_state_data_res.is_valid()) {
|
||||||
{
|
|
||||||
ERR_PRINT(" Reload animation state fail, because anim_state_data_res not set!");
|
ERR_PRINT(" Reload animation state fail, because anim_state_data_res not set!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(animation_state)
|
if (animation_state) {
|
||||||
{
|
|
||||||
delete animation_state;
|
delete animation_state;
|
||||||
animation_state = NULL;
|
animation_state = NULL;
|
||||||
}
|
}
|
||||||
animation_state = new spine::AnimationState(anim_state_data_res->get_animation_state_data());
|
animation_state = new spine::AnimationState(anim_state_data_res->get_animation_state_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_V if(!animation_state){ERR_PRINT("The animation state is not loaded yet!");return;}
|
#define CHECK_V \
|
||||||
#define CHECK_X(x) if(!animation_state){ERR_PRINT("The animation state is not loaded yet!");return x;}
|
if (!animation_state) { \
|
||||||
|
ERR_PRINT("The animation state is not loaded yet!"); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
#define CHECK_X(x) \
|
||||||
|
if (!animation_state) { \
|
||||||
|
ERR_PRINT("The animation state is not loaded yet!"); \
|
||||||
|
return x; \
|
||||||
|
}
|
||||||
#define S_T(x) (spine::String(x.utf8()))
|
#define S_T(x) (spine::String(x.utf8()))
|
||||||
Ref<SpineTrackEntry> SpineAnimationState::set_animation(const String &anim_name, bool loop, uint64_t track) {
|
Ref<SpineTrackEntry> SpineAnimationState::set_animation(const String &anim_name, bool loop, uint64_t track) {
|
||||||
CHECK_X(NULL);
|
CHECK_X(NULL);
|
||||||
auto skeleton_data = anim_state_data_res->get_skeleton();
|
auto skeleton_data = anim_state_data_res->get_skeleton();
|
||||||
auto anim = skeleton_data->find_animation(anim_name);
|
auto anim = skeleton_data->find_animation(anim_name);
|
||||||
if(!anim.is_valid() || anim->get_spine_object() == NULL)
|
if (!anim.is_valid() || anim->get_spine_object() == NULL) {
|
||||||
{
|
|
||||||
ERR_PRINT(String("Can not find animation: ") + anim_name)
|
ERR_PRINT(String("Can not find animation: ") + anim_name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -105,8 +107,7 @@ Ref<SpineTrackEntry> SpineAnimationState::add_animation(const String &anim_name,
|
|||||||
CHECK_X(NULL);
|
CHECK_X(NULL);
|
||||||
auto skeleton_data = anim_state_data_res->get_skeleton();
|
auto skeleton_data = anim_state_data_res->get_skeleton();
|
||||||
auto anim = skeleton_data->find_animation(anim_name);
|
auto anim = skeleton_data->find_animation(anim_name);
|
||||||
if(!anim.is_valid() || anim->get_spine_object() == NULL)
|
if (!anim.is_valid() || anim->get_spine_object() == NULL) {
|
||||||
{
|
|
||||||
ERR_PRINT(String("Can not find animation: ") + anim_name)
|
ERR_PRINT(String("Can not find animation: ") + anim_name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,6 +46,7 @@ private:
|
|||||||
spine::AnimationState *animation_state;
|
spine::AnimationState *animation_state;
|
||||||
|
|
||||||
Ref<SpineAnimationStateDataResource> anim_state_data_res;
|
Ref<SpineAnimationStateDataResource> anim_state_data_res;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void load_animation_state(Ref<SpineAnimationStateDataResource> ad);
|
void load_animation_state(Ref<SpineAnimationStateDataResource> ad);
|
||||||
|
|
||||||
|
|||||||
@ -30,11 +30,9 @@
|
|||||||
#include "SpineAnimationStateDataResource.h"
|
#include "SpineAnimationStateDataResource.h"
|
||||||
|
|
||||||
SpineAnimationStateDataResource::SpineAnimationStateDataResource() : animation_state_data(NULL), animation_state_data_created(false), default_mix(0.5f) {
|
SpineAnimationStateDataResource::SpineAnimationStateDataResource() : animation_state_data(NULL), animation_state_data_created(false), default_mix(0.5f) {
|
||||||
|
|
||||||
}
|
}
|
||||||
SpineAnimationStateDataResource::~SpineAnimationStateDataResource() {
|
SpineAnimationStateDataResource::~SpineAnimationStateDataResource() {
|
||||||
if(animation_state_data)
|
if (animation_state_data) {
|
||||||
{
|
|
||||||
delete animation_state_data;
|
delete animation_state_data;
|
||||||
animation_state_data = NULL;
|
animation_state_data = NULL;
|
||||||
}
|
}
|
||||||
@ -63,27 +61,22 @@ void SpineAnimationStateDataResource::set_skeleton(const Ref<SpineSkeletonDataRe
|
|||||||
skeleton = s;
|
skeleton = s;
|
||||||
|
|
||||||
_on_skeleton_data_changed();
|
_on_skeleton_data_changed();
|
||||||
if(skeleton.is_valid())
|
if (skeleton.is_valid()) {
|
||||||
{
|
|
||||||
skeleton->connect("skeleton_data_loaded", this, "_on_skeleton_data_loaded");
|
skeleton->connect("skeleton_data_loaded", this, "_on_skeleton_data_loaded");
|
||||||
skeleton->connect("atlas_res_changed", this, "_on_skeleton_data_changed");
|
skeleton->connect("atlas_res_changed", this, "_on_skeleton_data_changed");
|
||||||
skeleton->connect("skeleton_json_res_changed", this, "_on_skeleton_data_changed");
|
skeleton->connect("skeleton_json_res_changed", this, "_on_skeleton_data_changed");
|
||||||
|
|
||||||
if(skeleton->is_skeleton_data_loaded())
|
if (skeleton->is_skeleton_data_loaded()) {
|
||||||
{
|
|
||||||
_on_skeleton_data_loaded();
|
_on_skeleton_data_loaded();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(animation_state_data)
|
if (animation_state_data) {
|
||||||
{
|
|
||||||
delete animation_state_data;
|
delete animation_state_data;
|
||||||
animation_state_data = NULL;
|
animation_state_data = NULL;
|
||||||
animation_state_data_created = false;
|
animation_state_data_created = false;
|
||||||
// print_line("Animation state data deleted.");
|
// print_line("Animation state data deleted.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Ref<SpineSkeletonDataResource> SpineAnimationStateDataResource::get_skeleton() {
|
Ref<SpineSkeletonDataResource> SpineAnimationStateDataResource::get_skeleton() {
|
||||||
return skeleton;
|
return skeleton;
|
||||||
@ -91,17 +84,16 @@ Ref<SpineSkeletonDataResource> SpineAnimationStateDataResource::get_skeleton() {
|
|||||||
|
|
||||||
void SpineAnimationStateDataResource::set_default_mix(float m) {
|
void SpineAnimationStateDataResource::set_default_mix(float m) {
|
||||||
default_mix = m;
|
default_mix = m;
|
||||||
if(!is_animation_state_data_created())
|
if (!is_animation_state_data_created()) {
|
||||||
{
|
|
||||||
// ERR_PRINT("'set_default_mix' fail. Animation state data is not created!");
|
// ERR_PRINT("'set_default_mix' fail. Animation state data is not created!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
animation_state_data->setDefaultMix(((m >= 0 && m <= 1) ? m : m <= 0 ? 0 : 1));
|
animation_state_data->setDefaultMix(((m >= 0 && m <= 1) ? m : m <= 0 ? 0
|
||||||
|
: 1));
|
||||||
// emit_signal("animation_state_data_changed");
|
// emit_signal("animation_state_data_changed");
|
||||||
}
|
}
|
||||||
float SpineAnimationStateDataResource::get_default_mix() {
|
float SpineAnimationStateDataResource::get_default_mix() {
|
||||||
if(!is_animation_state_data_created())
|
if (!is_animation_state_data_created()) {
|
||||||
{
|
|
||||||
// ERR_PRINT("'get_default_mix' fail. Animation state data is not created!");
|
// ERR_PRINT("'get_default_mix' fail. Animation state data is not created!");
|
||||||
return default_mix;
|
return default_mix;
|
||||||
}
|
}
|
||||||
@ -110,40 +102,34 @@ float SpineAnimationStateDataResource::get_default_mix() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpineAnimationStateDataResource::set_mix(const String &from, const String &to, float mix_duration) {
|
void SpineAnimationStateDataResource::set_mix(const String &from, const String &to, float mix_duration) {
|
||||||
if(!is_animation_state_data_created())
|
if (!is_animation_state_data_created()) {
|
||||||
{
|
|
||||||
ERR_PRINT("'set_mix' fail. Animation state data is not created!");
|
ERR_PRINT("'set_mix' fail. Animation state data is not created!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto anim_from = get_skeleton()->find_animation(from);
|
auto anim_from = get_skeleton()->find_animation(from);
|
||||||
auto anim_to = get_skeleton()->find_animation(to);
|
auto anim_to = get_skeleton()->find_animation(to);
|
||||||
if(!anim_from.is_valid())
|
if (!anim_from.is_valid()) {
|
||||||
{
|
|
||||||
ERR_PRINT("'set_mix' fail. From animation animation not found!");
|
ERR_PRINT("'set_mix' fail. From animation animation not found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!anim_to.is_valid())
|
if (!anim_to.is_valid()) {
|
||||||
{
|
|
||||||
ERR_PRINT("'set_mix' fail. To animation animation not found!");
|
ERR_PRINT("'set_mix' fail. To animation animation not found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
animation_state_data->setMix(anim_from->get_spine_object(), anim_to->get_spine_object(), mix_duration);
|
animation_state_data->setMix(anim_from->get_spine_object(), anim_to->get_spine_object(), mix_duration);
|
||||||
}
|
}
|
||||||
float SpineAnimationStateDataResource::get_mix(const String &from, const String &to) {
|
float SpineAnimationStateDataResource::get_mix(const String &from, const String &to) {
|
||||||
if(!is_animation_state_data_created())
|
if (!is_animation_state_data_created()) {
|
||||||
{
|
|
||||||
ERR_PRINT("'set_mix' fail. Animation state data is not created!");
|
ERR_PRINT("'set_mix' fail. Animation state data is not created!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto anim_from = get_skeleton()->find_animation(from);
|
auto anim_from = get_skeleton()->find_animation(from);
|
||||||
auto anim_to = get_skeleton()->find_animation(to);
|
auto anim_to = get_skeleton()->find_animation(to);
|
||||||
if(!anim_from.is_valid())
|
if (!anim_from.is_valid()) {
|
||||||
{
|
|
||||||
ERR_PRINT("'set_mix' fail. From animation animation not found!");
|
ERR_PRINT("'set_mix' fail. From animation animation not found!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!anim_to.is_valid())
|
if (!anim_to.is_valid()) {
|
||||||
{
|
|
||||||
ERR_PRINT("'set_mix' fail. To animation animation not found!");
|
ERR_PRINT("'set_mix' fail. To animation animation not found!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -162,8 +148,7 @@ void SpineAnimationStateDataResource::_on_skeleton_data_loaded() {
|
|||||||
|
|
||||||
void SpineAnimationStateDataResource::_on_skeleton_data_changed() {
|
void SpineAnimationStateDataResource::_on_skeleton_data_changed() {
|
||||||
animation_state_data_created = false;
|
animation_state_data_created = false;
|
||||||
if(animation_state_data)
|
if (animation_state_data) {
|
||||||
{
|
|
||||||
delete animation_state_data;
|
delete animation_state_data;
|
||||||
animation_state_data = NULL;
|
animation_state_data = NULL;
|
||||||
// print_line("Animation state data deleted.");
|
// print_line("Animation state data deleted.");
|
||||||
|
|||||||
@ -48,8 +48,8 @@ private:
|
|||||||
bool animation_state_data_created;
|
bool animation_state_data_created;
|
||||||
|
|
||||||
float default_mix;
|
float default_mix;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
void set_skeleton(const Ref<SpineSkeletonDataResource> &s);
|
void set_skeleton(const Ref<SpineSkeletonDataResource> &s);
|
||||||
Ref<SpineSkeletonDataResource> get_skeleton();
|
Ref<SpineSkeletonDataResource> get_skeleton();
|
||||||
|
|
||||||
|
|||||||
@ -34,31 +34,27 @@
|
|||||||
|
|
||||||
class GodotSpineTextureLoader : public spine::TextureLoader {
|
class GodotSpineTextureLoader : public spine::TextureLoader {
|
||||||
private:
|
private:
|
||||||
Array *tex_list, *ntex_list;
|
Array *textures, *normal_maps;
|
||||||
String normal_tex_prefix;
|
String normal_maps_prefix;
|
||||||
public:
|
|
||||||
|
|
||||||
GodotSpineTextureLoader(Array *t, Array *nt, const String &p):tex_list(t), ntex_list(nt), normal_tex_prefix(p){
|
public:
|
||||||
if (tex_list) tex_list->clear();
|
GodotSpineTextureLoader(Array *t, Array *nt, const String &p) : textures(t), normal_maps(nt), normal_maps_prefix(p) {
|
||||||
if (ntex_list) ntex_list->clear();
|
if (textures) textures->clear();
|
||||||
|
if (normal_maps) normal_maps->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
String fixPathIssue(const String &path) {
|
String fixPathIssue(const String &path) {
|
||||||
if (path.size() > 5 && path[4] == '/' && path[5] == '/') return path;
|
if (path.size() > 5 && path[4] == '/' && path[5] == '/') return path;
|
||||||
const String prefix = "res:/";
|
const String prefix = "res:/";
|
||||||
auto i = path.find(prefix);
|
auto i = path.find(prefix);
|
||||||
// print_line(String("Found i at ") + String(Variant(i)));
|
|
||||||
auto sub_str_pos = i + prefix.size() - 1;
|
auto sub_str_pos = i + prefix.size() - 1;
|
||||||
if (sub_str_pos < 0) return path;
|
if (sub_str_pos < 0) return path;
|
||||||
auto res = path.substr(sub_str_pos);
|
auto res = path.substr(sub_str_pos);
|
||||||
// print_line(String("rest of it: ") + res);
|
|
||||||
if(res.size() > 0)
|
if (res.size() > 0) {
|
||||||
{
|
if (res[0] != '/') {
|
||||||
if(res[0] != '/')
|
|
||||||
{
|
|
||||||
return prefix + "/" + res;
|
return prefix + "/" + res;
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
return prefix + res;
|
return prefix + res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,17 +76,17 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tex_list) tex_list->append(tex);
|
if (textures) textures->append(tex);
|
||||||
auto p_spine_renderer_object = memnew(SpineRendererObject);
|
auto p_spine_renderer_object = memnew(SpineRendererObject);
|
||||||
p_spine_renderer_object->tex = tex;
|
p_spine_renderer_object->tex = tex;
|
||||||
|
|
||||||
// Load normal texture (e.g. n_tex.png)
|
// Load normal texture (e.g. n_tex.png)
|
||||||
String temppath = fixed_path;
|
String temppath = fixed_path;
|
||||||
String newpath = vformat("%s/%s_%s", temppath.get_base_dir(), normal_tex_prefix, temppath.get_file());
|
String newpath = vformat("%s/%s_%s", temppath.get_base_dir(), normal_maps_prefix, temppath.get_file());
|
||||||
// print_line(vformat("try n tex: %s", newpath));
|
// print_line(vformat("try n tex: %s", newpath));
|
||||||
if (ResourceLoader::exists(newpath)) {
|
if (ResourceLoader::exists(newpath)) {
|
||||||
Ref<Texture> normal_tex = ResourceLoader::load(newpath);
|
Ref<Texture> normal_tex = ResourceLoader::load(newpath);
|
||||||
if (ntex_list) ntex_list->append(normal_tex);
|
if (normal_maps) normal_maps->append(normal_tex);
|
||||||
p_spine_renderer_object->normal_tex = normal_tex;
|
p_spine_renderer_object->normal_tex = normal_tex;
|
||||||
|
|
||||||
// print_line(String("From atlas resource load: ") + String(" ro ") + String(Variant((long long) p_spine_renderer_object)));
|
// print_line(String("From atlas resource load: ") + String(" ro ") + String(Variant((long long) p_spine_renderer_object)));
|
||||||
|
|||||||
@ -31,7 +31,6 @@
|
|||||||
#define GODOT_SPINEATLASRESOURCE_H
|
#define GODOT_SPINEATLASRESOURCE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "core/variant_parser.h"
|
#include "core/variant_parser.h"
|
||||||
|
|
||||||
#include <spine/SpineString.h>
|
#include <spine/SpineString.h>
|
||||||
@ -55,6 +54,7 @@ protected:
|
|||||||
|
|
||||||
Array tex_list;
|
Array tex_list;
|
||||||
Array ntex_list;
|
Array ntex_list;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline String &get_atlas_data() { return atlas_data; }
|
inline String &get_atlas_data() { return atlas_data; }
|
||||||
|
|
||||||
|
|||||||
@ -447,8 +447,7 @@ void SpineBone::apply_world_transform_2d(Variant o){
|
|||||||
node2d->set_transform(Transform2D(
|
node2d->set_transform(Transform2D(
|
||||||
get_a(), get_c(),
|
get_a(), get_c(),
|
||||||
get_b(), get_d(),
|
get_b(), get_d(),
|
||||||
get_world_x(), -get_world_y())
|
get_world_x(), -get_world_y()));
|
||||||
);
|
|
||||||
// Fix the rotation
|
// Fix the rotation
|
||||||
auto pos = node2d->get_position();
|
auto pos = node2d->get_position();
|
||||||
node2d->translate(-pos);
|
node2d->translate(-pos);
|
||||||
|
|||||||
@ -54,6 +54,7 @@ private:
|
|||||||
spine::Bone *bone;
|
spine::Bone *bone;
|
||||||
|
|
||||||
SpineSprite *the_sprite;
|
SpineSprite *the_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineBone();
|
SpineBone();
|
||||||
~SpineBone();
|
~SpineBone();
|
||||||
|
|||||||
@ -97,7 +97,6 @@ public:
|
|||||||
|
|
||||||
bool is_skin_required();
|
bool is_skin_required();
|
||||||
void set_skin_required(bool v);
|
void set_skin_required(bool v);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(SpineBoneData::TransformMode);
|
VARIANT_ENUM_CAST(SpineBoneData::TransformMode);
|
||||||
|
|||||||
@ -46,11 +46,9 @@ void SpineCollisionShapeProxy::_bind_methods() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpineCollisionShapeProxy::SpineCollisionShapeProxy() : sync_transform(true) {
|
SpineCollisionShapeProxy::SpineCollisionShapeProxy() : sync_transform(true) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineCollisionShapeProxy::~SpineCollisionShapeProxy() {
|
SpineCollisionShapeProxy::~SpineCollisionShapeProxy() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineCollisionShapeProxy::_notification(int p_what) {
|
void SpineCollisionShapeProxy::_notification(int p_what) {
|
||||||
@ -196,9 +194,3 @@ void SpineCollisionShapeProxy::_get_slot_list(Vector<String> &res) const {
|
|||||||
res.set(i, slot->get_data()->get_slot_name());
|
res.set(i, slot->get_data()->get_slot_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,7 @@ protected:
|
|||||||
String slot;
|
String slot;
|
||||||
|
|
||||||
bool sync_transform;
|
bool sync_transform;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||||
@ -60,6 +61,7 @@ protected:
|
|||||||
void _sync_transform(SpineSprite *sprite);
|
void _sync_transform(SpineSprite *sprite);
|
||||||
|
|
||||||
void _get_slot_list(Vector<String> &res) const;
|
void _get_slot_list(Vector<String> &res) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineCollisionShapeProxy();
|
SpineCollisionShapeProxy();
|
||||||
~SpineCollisionShapeProxy();
|
~SpineCollisionShapeProxy();
|
||||||
|
|||||||
@ -57,6 +57,4 @@ void SpineConstant::_bind_methods() {
|
|||||||
BIND_ENUM_CONSTANT(Property_PathConstraintPosition);
|
BIND_ENUM_CONSTANT(Property_PathConstraintPosition);
|
||||||
BIND_ENUM_CONSTANT(Property_PathConstraintSpacing);
|
BIND_ENUM_CONSTANT(Property_PathConstraintSpacing);
|
||||||
BIND_ENUM_CONSTANT(Property_PathConstraintMix);
|
BIND_ENUM_CONSTANT(Property_PathConstraintMix);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -37,6 +37,7 @@ class SpineConstant : public Object{
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum MixBlend {
|
enum MixBlend {
|
||||||
MixBlend_Setup = 0,
|
MixBlend_Setup = 0,
|
||||||
|
|||||||
@ -41,8 +41,10 @@ class SpineEvent : public Reference{
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
spine::Event *event;
|
spine::Event *event;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineEvent();
|
SpineEvent();
|
||||||
~SpineEvent();
|
~SpineEvent();
|
||||||
|
|||||||
@ -30,7 +30,6 @@
|
|||||||
#include "SpineEventData.h"
|
#include "SpineEventData.h"
|
||||||
|
|
||||||
void SpineEventData::_bind_methods() {
|
void SpineEventData::_bind_methods() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineEventData::SpineEventData() : event_data(NULL) {}
|
SpineEventData::SpineEventData() : event_data(NULL) {}
|
||||||
|
|||||||
@ -39,8 +39,10 @@ class SpineEventData : public Reference{
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const spine::EventData *event_data;
|
const spine::EventData *event_data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineEventData();
|
SpineEventData();
|
||||||
~SpineEventData();
|
~SpineEventData();
|
||||||
|
|||||||
@ -89,7 +89,6 @@ public:
|
|||||||
|
|
||||||
bool is_active();
|
bool is_active();
|
||||||
void set_active(bool v);
|
void set_active(bool v);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif//GODOT_SPINEIKCONSTRAINT_H
|
#endif//GODOT_SPINEIKCONSTRAINT_H
|
||||||
|
|||||||
@ -73,7 +73,6 @@ public:
|
|||||||
|
|
||||||
float get_softness();
|
float get_softness();
|
||||||
void set_softness(float v);
|
void set_softness(float v);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif//GODOT_SPINEIKCONSTRAINTDATA_H
|
#endif//GODOT_SPINEIKCONSTRAINTDATA_H
|
||||||
|
|||||||
@ -82,7 +82,6 @@ SpineRuntimeEditorPlugin::SpineRuntimeEditorPlugin(EditorNode *p_node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpineRuntimeEditorPlugin::~SpineRuntimeEditorPlugin() {
|
SpineRuntimeEditorPlugin::~SpineRuntimeEditorPlugin() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpineRuntimeEditorPlugin::handles(Object *p_object) const {
|
bool SpineRuntimeEditorPlugin::handles(Object *p_object) const {
|
||||||
|
|||||||
@ -40,7 +40,11 @@ public:
|
|||||||
String get_importer_name() const override { return "spine.atlas"; }
|
String get_importer_name() const override { return "spine.atlas"; }
|
||||||
String get_visible_name() const override { return "Spine Runtime Atlas"; }
|
String get_visible_name() const override { return "Spine Runtime Atlas"; }
|
||||||
void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("atlas"); }
|
void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("atlas"); }
|
||||||
String get_preset_name(int p_idx) const override {if (p_idx == 0) return "Default"; else return "Unknown";}
|
String get_preset_name(int p_idx) const override {
|
||||||
|
if (p_idx == 0) return "Default";
|
||||||
|
else
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
int get_preset_count() const override { return 1; }
|
int get_preset_count() const override { return 1; }
|
||||||
String get_save_extension() const override { return "spatlas"; }
|
String get_save_extension() const override { return "spatlas"; }
|
||||||
String get_resource_type() const override { return "SpineAtlasResource"; }
|
String get_resource_type() const override { return "SpineAtlasResource"; }
|
||||||
@ -56,7 +60,11 @@ public:
|
|||||||
String get_importer_name() const override { return "spine.json"; }
|
String get_importer_name() const override { return "spine.json"; }
|
||||||
String get_visible_name() const override { return "Spine Runtime Json"; }
|
String get_visible_name() const override { return "Spine Runtime Json"; }
|
||||||
void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("json"); }
|
void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("json"); }
|
||||||
String get_preset_name(int p_idx) const override {if (p_idx == 0) return "Default"; else return "Unknown";}
|
String get_preset_name(int p_idx) const override {
|
||||||
|
if (p_idx == 0) return "Default";
|
||||||
|
else
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
int get_preset_count() const override { return 1; }
|
int get_preset_count() const override { return 1; }
|
||||||
String get_save_extension() const override { return "spjson"; }
|
String get_save_extension() const override { return "spjson"; }
|
||||||
String get_resource_type() const override { return "SpineSkeletonJsonDataResource"; }
|
String get_resource_type() const override { return "SpineSkeletonJsonDataResource"; }
|
||||||
@ -72,6 +80,7 @@ class SpineRuntimeEditorPlugin : public EditorPlugin {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
SpineSpriteAnimateDialog *animate_dialog;
|
SpineSpriteAnimateDialog *animate_dialog;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineRuntimeEditorPlugin(EditorNode *p_node);
|
SpineRuntimeEditorPlugin(EditorNode *p_node);
|
||||||
~SpineRuntimeEditorPlugin();
|
~SpineRuntimeEditorPlugin();
|
||||||
|
|||||||
@ -133,20 +133,17 @@ void SpineSkeleton::_bind_methods() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpineSkeleton::SpineSkeleton() : skeleton(NULL), spine_object(false), the_sprite(nullptr) {
|
SpineSkeleton::SpineSkeleton() : skeleton(NULL), spine_object(false), the_sprite(nullptr) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineSkeleton::~SpineSkeleton() {
|
SpineSkeleton::~SpineSkeleton() {
|
||||||
if(skeleton && !spine_object)
|
if (skeleton && !spine_object) {
|
||||||
{
|
|
||||||
delete skeleton;
|
delete skeleton;
|
||||||
skeleton = NULL;
|
skeleton = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineSkeleton::load_skeleton(Ref<SpineSkeletonDataResource> sd) {
|
void SpineSkeleton::load_skeleton(Ref<SpineSkeletonDataResource> sd) {
|
||||||
if(skeleton && !spine_object)
|
if (skeleton && !spine_object) {
|
||||||
{
|
|
||||||
delete skeleton;
|
delete skeleton;
|
||||||
skeleton = NULL;
|
skeleton = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,8 +51,8 @@ private:
|
|||||||
bool spine_object;
|
bool spine_object;
|
||||||
|
|
||||||
SpineSprite *the_sprite;
|
SpineSprite *the_sprite;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
SpineSkeleton();
|
SpineSkeleton();
|
||||||
~SpineSkeleton();
|
~SpineSkeleton();
|
||||||
|
|
||||||
@ -129,7 +129,6 @@ public:
|
|||||||
|
|
||||||
float get_scale_y();
|
float get_scale_y();
|
||||||
void set_scale_y(float v);
|
void set_scale_y(float v);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif//GODOT_SPINESKELETON_H
|
#endif//GODOT_SPINESKELETON_H
|
||||||
|
|||||||
@ -75,11 +75,9 @@ void SpineSkeletonDataResource::_bind_methods() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpineSkeletonDataResource::SpineSkeletonDataResource() : valid(false), spine_object(false), skeleton_data(NULL) {
|
SpineSkeletonDataResource::SpineSkeletonDataResource() : valid(false), spine_object(false), skeleton_data(NULL) {
|
||||||
|
|
||||||
}
|
}
|
||||||
SpineSkeletonDataResource::~SpineSkeletonDataResource() {
|
SpineSkeletonDataResource::~SpineSkeletonDataResource() {
|
||||||
if(skeleton_data && !spine_object)
|
if (skeleton_data && !spine_object) {
|
||||||
{
|
|
||||||
delete skeleton_data;
|
delete skeleton_data;
|
||||||
skeleton_data = NULL;
|
skeleton_data = NULL;
|
||||||
}
|
}
|
||||||
@ -94,14 +92,12 @@ void SpineSkeletonDataResource::load_res(spine::Atlas *a, const String &json_str
|
|||||||
auto path = get_path();
|
auto path = get_path();
|
||||||
spine::SkeletonJson json(a);
|
spine::SkeletonJson json(a);
|
||||||
auto temp_skeleton_data = json.readSkeletonData(json_string.utf8());
|
auto temp_skeleton_data = json.readSkeletonData(json_string.utf8());
|
||||||
if(!temp_skeleton_data)
|
if (!temp_skeleton_data) {
|
||||||
{
|
|
||||||
print_error(String("Error happened while loading skeleton json data: ") + path);
|
print_error(String("Error happened while loading skeleton json data: ") + path);
|
||||||
print_error(String("Error msg: ") + json.getError().buffer());
|
print_error(String("Error msg: ") + json.getError().buffer());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(skeleton_data)
|
if (skeleton_data) {
|
||||||
{
|
|
||||||
delete skeleton_data;
|
delete skeleton_data;
|
||||||
skeleton_data = NULL;
|
skeleton_data = NULL;
|
||||||
}
|
}
|
||||||
@ -112,11 +108,9 @@ void SpineSkeletonDataResource::load_res(spine::Atlas *a, const String &json_str
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpineSkeletonDataResource::update_skeleton_data() {
|
void SpineSkeletonDataResource::update_skeleton_data() {
|
||||||
if(atlas_res.is_valid() && skeleton_json_res.is_valid())
|
if (atlas_res.is_valid() && skeleton_json_res.is_valid()) {
|
||||||
{
|
|
||||||
load_res(atlas_res->get_spine_atlas(), skeleton_json_res->get_json_string());
|
load_res(atlas_res->get_spine_atlas(), skeleton_json_res->get_json_string());
|
||||||
if(valid)
|
if (valid) {
|
||||||
{
|
|
||||||
emit_signal("skeleton_data_loaded");
|
emit_signal("skeleton_data_loaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,8 +144,16 @@ Ref<SpineSkeletonJsonDataResource> SpineSkeletonDataResource::get_skeleton_json_
|
|||||||
return skeleton_json_res;
|
return skeleton_json_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_V if(!is_skeleton_data_loaded()){ERR_PRINT("skeleton data has not loaded yet!");return;}
|
#define CHECK_V \
|
||||||
#define CHECK_X(x) if(!is_skeleton_data_loaded()){ERR_PRINT("skeleton data has not loaded yet!");return x;}
|
if (!is_skeleton_data_loaded()) { \
|
||||||
|
ERR_PRINT("skeleton data has not loaded yet!"); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
#define CHECK_X(x) \
|
||||||
|
if (!is_skeleton_data_loaded()) { \
|
||||||
|
ERR_PRINT("skeleton data has not loaded yet!"); \
|
||||||
|
return x; \
|
||||||
|
}
|
||||||
#define S_T(x) (spine::String(x.utf8()))
|
#define S_T(x) (spine::String(x.utf8()))
|
||||||
Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &animation_name) {
|
Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &animation_name) {
|
||||||
CHECK_X(NULL);
|
CHECK_X(NULL);
|
||||||
|
|||||||
@ -60,8 +60,8 @@ private:
|
|||||||
spine::SkeletonData *skeleton_data;
|
spine::SkeletonData *skeleton_data;
|
||||||
|
|
||||||
void update_skeleton_data();
|
void update_skeleton_data();
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
inline void set_spine_object(spine::SkeletonData *s) {
|
inline void set_spine_object(spine::SkeletonData *s) {
|
||||||
skeleton_data = s;
|
skeleton_data = s;
|
||||||
if (s)
|
if (s)
|
||||||
|
|||||||
@ -39,6 +39,7 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
String json_string;
|
String json_string;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline const String &get_json_string() { return json_string; }
|
inline const String &get_json_string() { return json_string; }
|
||||||
|
|
||||||
|
|||||||
@ -128,7 +128,6 @@ Ref<SpineSkinAttachmentMapEntries> SpineSkin::get_attachments(){
|
|||||||
Ref<SpineSkinAttachmentMapEntries> gd_es(memnew(SpineSkinAttachmentMapEntries));
|
Ref<SpineSkinAttachmentMapEntries> gd_es(memnew(SpineSkinAttachmentMapEntries));
|
||||||
gd_es->set_spine_object(es);
|
gd_es->set_spine_object(es);
|
||||||
return gd_es;
|
return gd_es;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array SpineSkin::get_bones() {
|
Array SpineSkin::get_bones() {
|
||||||
|
|||||||
@ -98,11 +98,9 @@ void SpineSprite::_bind_methods() {
|
|||||||
BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Manual);
|
BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Manual);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineSprite::SpineSprite() :
|
SpineSprite::SpineSprite() : select_track_id(0), empty_animation_duration(0.2f), skeleton_clipper(NULL),
|
||||||
select_track_id(0), empty_animation_duration(0.2f), skeleton_clipper(NULL),
|
|
||||||
overlap(false),
|
overlap(false),
|
||||||
process_mode(ProcessMode_Process)
|
process_mode(ProcessMode_Process) {
|
||||||
{
|
|
||||||
skeleton_clipper = new spine::SkeletonClipping();
|
skeleton_clipper = new spine::SkeletonClipping();
|
||||||
}
|
}
|
||||||
SpineSprite::~SpineSprite() {
|
SpineSprite::~SpineSprite() {
|
||||||
@ -162,13 +160,11 @@ void SpineSprite::update_bind_slot_nodes(){
|
|||||||
auto slot = skeleton->find_slot(slot_name);
|
auto slot = skeleton->find_slot(slot_name);
|
||||||
if (slot.is_valid()) {
|
if (slot.is_valid()) {
|
||||||
auto bone = slot->get_bone();
|
auto bone = slot->get_bone();
|
||||||
if(bone.is_valid())
|
if (bone.is_valid()) {
|
||||||
{
|
|
||||||
update_bind_slot_node_transform(bone, node2d);
|
update_bind_slot_node_transform(bone, node2d);
|
||||||
update_bind_slot_node_draw_order(slot_name, node2d);
|
update_bind_slot_node_draw_order(slot_name, node2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (a.get_type() == Variant::ARRAY) {
|
} else if (a.get_type() == Variant::ARRAY) {
|
||||||
@ -183,13 +179,11 @@ void SpineSprite::update_bind_slot_nodes(){
|
|||||||
auto slot = skeleton->find_slot(slot_name);
|
auto slot = skeleton->find_slot(slot_name);
|
||||||
if (slot.is_valid()) {
|
if (slot.is_valid()) {
|
||||||
auto bone = slot->get_bone();
|
auto bone = slot->get_bone();
|
||||||
if(bone.is_valid())
|
if (bone.is_valid()) {
|
||||||
{
|
|
||||||
update_bind_slot_node_transform(bone, node2d);
|
update_bind_slot_node_transform(bone, node2d);
|
||||||
update_bind_slot_node_draw_order(slot_name, node2d);
|
update_bind_slot_node_draw_order(slot_name, node2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,8 +252,7 @@ void SpineSprite::_on_animation_data_changed() {
|
|||||||
remove_mesh_instances();
|
remove_mesh_instances();
|
||||||
skeleton.unref();
|
skeleton.unref();
|
||||||
animation_state.unref();
|
animation_state.unref();
|
||||||
if(!animation_state_data_res.is_null())
|
if (!animation_state_data_res.is_null()) {
|
||||||
{
|
|
||||||
if (!animation_state_data_res->is_connected("animation_state_data_created", this, "_on_animation_data_created"))
|
if (!animation_state_data_res->is_connected("animation_state_data_created", this, "_on_animation_data_created"))
|
||||||
animation_state_data_res->connect("animation_state_data_created", this, "_on_animation_data_created");
|
animation_state_data_res->connect("animation_state_data_created", this, "_on_animation_data_created");
|
||||||
if (!animation_state_data_res->is_connected("skeleton_data_res_changed", this, "_on_animation_data_changed"))
|
if (!animation_state_data_res->is_connected("skeleton_data_res_changed", this, "_on_animation_data_changed"))
|
||||||
@ -267,8 +260,7 @@ void SpineSprite::_on_animation_data_changed() {
|
|||||||
if (!animation_state_data_res->is_connected("animation_state_data_changed", this, "_on_animation_data_changed"))
|
if (!animation_state_data_res->is_connected("animation_state_data_changed", this, "_on_animation_data_changed"))
|
||||||
animation_state_data_res->connect("animation_state_data_changed", this, "_on_animation_data_changed");
|
animation_state_data_res->connect("animation_state_data_changed", this, "_on_animation_data_changed");
|
||||||
|
|
||||||
if(animation_state_data_res->is_animation_state_data_created())
|
if (animation_state_data_res->is_animation_state_data_created()) {
|
||||||
{
|
|
||||||
_on_animation_data_created();
|
_on_animation_data_created();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,8 +275,7 @@ Ref<SpineAnimationState> SpineSprite::get_animation_state() {
|
|||||||
|
|
||||||
void SpineSprite::gen_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
void SpineSprite::gen_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
||||||
auto sk = s->get_spine_object();
|
auto sk = s->get_spine_object();
|
||||||
for(size_t i=0, n = sk->getSlots().size(); i < n; ++i)
|
for (size_t i = 0, n = sk->getSlots().size(); i < n; ++i) {
|
||||||
{
|
|
||||||
// creat a mesh instance 2d for every slot
|
// creat a mesh instance 2d for every slot
|
||||||
auto mesh_ins = memnew(SpineSpriteMeshInstance2D);
|
auto mesh_ins = memnew(SpineSpriteMeshInstance2D);
|
||||||
add_child(mesh_ins);
|
add_child(mesh_ins);
|
||||||
@ -323,8 +314,7 @@ void SpineSprite::gen_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpineSprite::remove_mesh_instances() {
|
void SpineSprite::remove_mesh_instances() {
|
||||||
for(size_t i=0;i < mesh_instances.size();++i)
|
for (size_t i = 0; i < mesh_instances.size(); ++i) {
|
||||||
{
|
|
||||||
remove_child(mesh_instances[i]);
|
remove_child(mesh_instances[i]);
|
||||||
memdelete(mesh_instances[i]);
|
memdelete(mesh_instances[i]);
|
||||||
}
|
}
|
||||||
@ -339,12 +329,10 @@ void SpineSprite::remove_redundant_mesh_instances() {
|
|||||||
auto node = get_child(i);
|
auto node = get_child(i);
|
||||||
// print_line(String("get a node: ") + node->get_name());
|
// print_line(String("get a node: ") + node->get_name());
|
||||||
if (node && node->is_class("SpineSpriteMeshInstance2D")) {
|
if (node && node->is_class("SpineSpriteMeshInstance2D")) {
|
||||||
if(mesh_instances.find((SpineSpriteMeshInstance2D*)node) == -1)
|
if (mesh_instances.find((SpineSpriteMeshInstance2D *) node) == -1) {
|
||||||
{
|
|
||||||
// print_line("marked clear");
|
// print_line("marked clear");
|
||||||
ms.push_back(node);
|
ms.push_back(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (size_t i = 0, n = ms.size(); i < n; ++i) {
|
for (size_t i = 0, n = ms.size(); i < n; ++i) {
|
||||||
@ -355,20 +343,21 @@ void SpineSprite::remove_redundant_mesh_instances() {
|
|||||||
// print_line("end clearing");
|
// print_line("end clearing");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEMP_COPY(t, get_res) do{auto &temp_uvs = get_res; \
|
#define TEMP_COPY(t, get_res) \
|
||||||
|
do { \
|
||||||
|
auto &temp_uvs = get_res; \
|
||||||
t.setSize(temp_uvs.size(), 0); \
|
t.setSize(temp_uvs.size(), 0); \
|
||||||
for(size_t j=0;j<t.size();++j) \
|
for (size_t j = 0; j < t.size(); ++j) { \
|
||||||
{ \
|
|
||||||
t[j] = temp_uvs[j]; \
|
t[j] = temp_uvs[j]; \
|
||||||
}}while(false);
|
} \
|
||||||
|
} while (false);
|
||||||
void SpineSprite::update_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
void SpineSprite::update_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
||||||
static const unsigned short VERTEX_STRIDE = 2;
|
static const unsigned short VERTEX_STRIDE = 2;
|
||||||
static const unsigned short UV_STRIDE = 2;
|
static const unsigned short UV_STRIDE = 2;
|
||||||
static unsigned short quad_indices[] = {0, 1, 2, 2, 3, 0};
|
static unsigned short quad_indices[] = {0, 1, 2, 2, 3, 0};
|
||||||
|
|
||||||
auto sk = s->get_spine_object();
|
auto sk = s->get_spine_object();
|
||||||
for(size_t i=0, n = sk->getSlots().size(); i < n; ++i)
|
for (size_t i = 0, n = sk->getSlots().size(); i < n; ++i) {
|
||||||
{
|
|
||||||
spine::Vector<float> vertices;
|
spine::Vector<float> vertices;
|
||||||
spine::Vector<float> uvs;
|
spine::Vector<float> uvs;
|
||||||
spine::Vector<unsigned short> indices;
|
spine::Vector<unsigned short> indices;
|
||||||
@ -393,8 +382,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
|||||||
Ref<Texture> normal_tex;
|
Ref<Texture> normal_tex;
|
||||||
size_t v_num = 0;
|
size_t v_num = 0;
|
||||||
|
|
||||||
if(attachment->getRTTI().isExactly(spine::RegionAttachment::rtti))
|
if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) {
|
||||||
{
|
|
||||||
spine::RegionAttachment *region_attachment = (spine::RegionAttachment *) attachment;
|
spine::RegionAttachment *region_attachment = (spine::RegionAttachment *) attachment;
|
||||||
|
|
||||||
auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region_attachment->getRendererObject())->page->getRendererObject();
|
auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region_attachment->getRendererObject())->page->getRendererObject();
|
||||||
@ -564,28 +552,22 @@ void SpineSprite::callback(spine::AnimationState *state, spine::EventType type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case spine::EventType_Start:
|
case spine::EventType_Start: {
|
||||||
{
|
|
||||||
emit_signal("animation_start", animation_state, gd_entry, gd_event);
|
emit_signal("animation_start", animation_state, gd_entry, gd_event);
|
||||||
} break;
|
} break;
|
||||||
case spine::EventType_Interrupt:
|
case spine::EventType_Interrupt: {
|
||||||
{
|
|
||||||
emit_signal("animation_interrupt", animation_state, gd_entry, gd_event);
|
emit_signal("animation_interrupt", animation_state, gd_entry, gd_event);
|
||||||
} break;
|
} break;
|
||||||
case spine::EventType_End:
|
case spine::EventType_End: {
|
||||||
{
|
|
||||||
emit_signal("animation_end", animation_state, gd_entry, gd_event);
|
emit_signal("animation_end", animation_state, gd_entry, gd_event);
|
||||||
} break;
|
} break;
|
||||||
case spine::EventType_Complete:
|
case spine::EventType_Complete: {
|
||||||
{
|
|
||||||
emit_signal("animation_complete", animation_state, gd_entry, gd_event);
|
emit_signal("animation_complete", animation_state, gd_entry, gd_event);
|
||||||
} break;
|
} break;
|
||||||
case spine::EventType_Dispose:
|
case spine::EventType_Dispose: {
|
||||||
{
|
|
||||||
emit_signal("animation_dispose", animation_state, gd_entry, gd_event);
|
emit_signal("animation_dispose", animation_state, gd_entry, gd_event);
|
||||||
} break;
|
} break;
|
||||||
case spine::EventType_Event:
|
case spine::EventType_Event: {
|
||||||
{
|
|
||||||
emit_signal("animation_event", animation_state, gd_entry, gd_event);
|
emit_signal("animation_event", animation_state, gd_entry, gd_event);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@ -664,8 +646,7 @@ void SpineSprite::set_overlap(bool v){
|
|||||||
overlap = v;
|
overlap = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineSprite::set_skin(Ref<PackedSpineSkinResource> v)
|
void SpineSprite::set_skin(Ref<PackedSpineSkinResource> v) {
|
||||||
{
|
|
||||||
if (v != skin && skin.is_valid()) {
|
if (v != skin && skin.is_valid()) {
|
||||||
if (skin->is_connected("property_changed", this, "_on_skin_property_changed"))
|
if (skin->is_connected("property_changed", this, "_on_skin_property_changed"))
|
||||||
skin->disconnect("property_changed", this, "_on_skin_property_changed");
|
skin->disconnect("property_changed", this, "_on_skin_property_changed");
|
||||||
@ -685,8 +666,7 @@ Ref<PackedSpineSkinResource> SpineSprite::get_skin(){
|
|||||||
void SpineSprite::update_runtime_skin() {
|
void SpineSprite::update_runtime_skin() {
|
||||||
auto new_skin = gen_spine_skin_from_packed_resource(skin);
|
auto new_skin = gen_spine_skin_from_packed_resource(skin);
|
||||||
|
|
||||||
if(new_skin.is_valid())
|
if (new_skin.is_valid()) {
|
||||||
{
|
|
||||||
skeleton->set_skin(new_skin);
|
skeleton->set_skin(new_skin);
|
||||||
skeleton->set_to_setup_pose();
|
skeleton->set_to_setup_pose();
|
||||||
}
|
}
|
||||||
@ -703,15 +683,13 @@ Ref<SpineSkin> SpineSprite::gen_spine_skin_from_packed_resource(Ref<PackedSpineS
|
|||||||
if (res->get_skin_name().empty())
|
if (res->get_skin_name().empty())
|
||||||
return NULL;
|
return NULL;
|
||||||
auto exist_skin = animation_state_data_res->get_skeleton()->find_skin(res->get_skin_name());
|
auto exist_skin = animation_state_data_res->get_skeleton()->find_skin(res->get_skin_name());
|
||||||
if(exist_skin.is_valid())
|
if (exist_skin.is_valid()) {
|
||||||
{
|
|
||||||
return exist_skin;
|
return exist_skin;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto new_skin = Ref<SpineSkin>(memnew(SpineSkin))->init(res->get_skin_name());
|
auto new_skin = Ref<SpineSkin>(memnew(SpineSkin))->init(res->get_skin_name());
|
||||||
auto sub_skin_names = res->get_sub_skin_names();
|
auto sub_skin_names = res->get_sub_skin_names();
|
||||||
for(size_t i=0;i<sub_skin_names.size();++i)
|
for (size_t i = 0; i < sub_skin_names.size(); ++i) {
|
||||||
{
|
|
||||||
auto skin_name = (String) sub_skin_names[i];
|
auto skin_name = (String) sub_skin_names[i];
|
||||||
auto sub_skin = animation_state_data_res->get_skeleton()->find_skin(skin_name);
|
auto sub_skin = animation_state_data_res->get_skeleton()->find_skin(skin_name);
|
||||||
if (sub_skin.is_valid())
|
if (sub_skin.is_valid())
|
||||||
@ -865,13 +843,20 @@ bool SpineSprite::_get(const StringName &p_property, Variant &r_value) const {
|
|||||||
r_value = dic[key];
|
r_value = dic[key];
|
||||||
} else {
|
} else {
|
||||||
if (key == "track_id") r_value = 0;
|
if (key == "track_id") r_value = 0;
|
||||||
else if (key == "animation") r_value = "";
|
else if (key == "animation")
|
||||||
else if (key == "loop") r_value = true;
|
r_value = "";
|
||||||
else if (key == "empty") r_value = false;
|
else if (key == "loop")
|
||||||
else if (key == "empty_animation_duration") r_value = 0.3;
|
r_value = true;
|
||||||
else if (key == "clear") r_value = false;
|
else if (key == "empty")
|
||||||
else if (key == "delay") r_value = 0;
|
r_value = false;
|
||||||
else return false;
|
else if (key == "empty_animation_duration")
|
||||||
|
r_value = 0.3;
|
||||||
|
else if (key == "clear")
|
||||||
|
r_value = false;
|
||||||
|
else if (key == "delay")
|
||||||
|
r_value = 0;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1027,13 +1012,9 @@ void SpineSprite::_validate_and_play_current_animations() {
|
|||||||
animation_state->set_animation(animation, loop, track_id);
|
animation_state->set_animation(animation, loop, track_id);
|
||||||
has_track[track_id] = true;
|
has_track[track_id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (track_cnt == 0) animation_state->clear_tracks();
|
if (track_cnt == 0) animation_state->clear_tracks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
class SpineSprite : public Node2D, public spine::AnimationStateListenerObject {
|
class SpineSprite : public Node2D, public spine::AnimationStateListenerObject {
|
||||||
GDCLASS(SpineSprite, Node2D);
|
GDCLASS(SpineSprite, Node2D);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
@ -52,14 +53,15 @@ protected:
|
|||||||
bool _set(const StringName &p_property, const Variant &p_value);
|
bool _set(const StringName &p_property, const Variant &p_value);
|
||||||
|
|
||||||
void _validate_and_play_current_animations();
|
void _validate_and_play_current_animations();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ProcessMode {
|
enum ProcessMode {
|
||||||
ProcessMode_Process,
|
ProcessMode_Process,
|
||||||
ProcessMode_Physics,
|
ProcessMode_Physics,
|
||||||
ProcessMode_Manual
|
ProcessMode_Manual
|
||||||
};
|
};
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
Ref<SpineAnimationStateDataResource> animation_state_data_res;
|
Ref<SpineAnimationStateDataResource> animation_state_data_res;
|
||||||
|
|
||||||
Ref<SpineSkeleton> skeleton;
|
Ref<SpineSkeleton> skeleton;
|
||||||
|
|||||||
@ -103,7 +103,6 @@ SpineSpriteAnimateDialog::SpineSpriteAnimateDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpineSpriteAnimateDialog::~SpineSpriteAnimateDialog() {
|
SpineSpriteAnimateDialog::~SpineSpriteAnimateDialog() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineSpriteAnimateDialog::set_animate_button(ToolButton *b) {
|
void SpineSpriteAnimateDialog::set_animate_button(ToolButton *b) {
|
||||||
@ -135,7 +134,12 @@ void SpineSpriteAnimateDialog::error(const String &text, const String &title) {
|
|||||||
error_dialog->popup_centered();
|
error_dialog->popup_centered();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ERROR_MSG(x) do{error(x);err=true;return;}while(false)
|
#define ERROR_MSG(x) \
|
||||||
|
do { \
|
||||||
|
error(x); \
|
||||||
|
err = true; \
|
||||||
|
return; \
|
||||||
|
} while (false)
|
||||||
void SpineSpriteAnimateDialog::load_data_from_sprite(SpineSprite *sprite, bool &err) {
|
void SpineSpriteAnimateDialog::load_data_from_sprite(SpineSprite *sprite, bool &err) {
|
||||||
if (sprite == nullptr) {
|
if (sprite == nullptr) {
|
||||||
ERROR_MSG("The sprite is null.");
|
ERROR_MSG("The sprite is null.");
|
||||||
@ -279,7 +283,6 @@ void SpineSpriteAnimateDialog::load_data_from_anim_player(AnimationPlayer *anim_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item = item->get_next();
|
item = item->get_next();
|
||||||
@ -330,8 +333,6 @@ void SpineSpriteAnimateDialog::_on_scene_tree_hide() {
|
|||||||
} else {
|
} else {
|
||||||
animate_dialog_override_button->set_visible(false);
|
animate_dialog_override_button->set_visible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineSpriteAnimateDialog::_on_animate_dialog_action(const String &act) {
|
void SpineSpriteAnimateDialog::_on_animate_dialog_action(const String &act) {
|
||||||
|
|||||||
@ -67,6 +67,7 @@ protected:
|
|||||||
void gen_new_animation_player(SpineSprite *sprite, bool &err);
|
void gen_new_animation_player(SpineSprite *sprite, bool &err);
|
||||||
void gen_animations(SpineSprite *sprite, AnimationPlayer *anim_player, const Dictionary &config, float min_duration, bool &err);
|
void gen_animations(SpineSprite *sprite, AnimationPlayer *anim_player, const Dictionary &config, float min_duration, bool &err);
|
||||||
Dictionary gen_current_animation_data(const String &animation, int64_t track_id, bool loop, bool clear, bool empty, bool empty_duration, float delay);
|
Dictionary gen_current_animation_data(const String &animation, int64_t track_id, bool loop, bool clear, bool empty, bool empty_duration, float delay);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineSpriteAnimateDialog();
|
SpineSpriteAnimateDialog();
|
||||||
~SpineSpriteAnimateDialog();
|
~SpineSpriteAnimateDialog();
|
||||||
|
|||||||
@ -41,6 +41,7 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
Ref<SpineSlot> slot;
|
Ref<SpineSlot> slot;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineSpriteMeshInstance2D();
|
SpineSpriteMeshInstance2D();
|
||||||
~SpineSpriteMeshInstance2D();
|
~SpineSpriteMeshInstance2D();
|
||||||
|
|||||||
@ -46,11 +46,9 @@ void SpineTimeline::_bind_methods() {
|
|||||||
|
|
||||||
|
|
||||||
SpineTimeline::SpineTimeline() : timeline(nullptr) {
|
SpineTimeline::SpineTimeline() : timeline(nullptr) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineTimeline::~SpineTimeline() {
|
SpineTimeline::~SpineTimeline() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha,
|
void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha,
|
||||||
@ -99,5 +97,3 @@ Array SpineTimeline::getPropertyIds() {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -41,10 +41,13 @@ class SpineEvent;
|
|||||||
|
|
||||||
class SpineTimeline : public Reference {
|
class SpineTimeline : public Reference {
|
||||||
GDCLASS(SpineTimeline, Reference);
|
GDCLASS(SpineTimeline, Reference);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
spine::Timeline *timeline;
|
spine::Timeline *timeline;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpineTimeline();
|
SpineTimeline();
|
||||||
~SpineTimeline();
|
~SpineTimeline();
|
||||||
|
|||||||
@ -131,7 +131,6 @@ void register_spine_godot_types(){
|
|||||||
|
|
||||||
json_skeleton_saver.instance();
|
json_skeleton_saver.instance();
|
||||||
ResourceSaver::add_resource_format_saver(json_skeleton_saver);
|
ResourceSaver::add_resource_format_saver(json_skeleton_saver);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_spine_godot_types() {
|
void unregister_spine_godot_types() {
|
||||||
|
|||||||
@ -29,4 +29,3 @@
|
|||||||
|
|
||||||
void register_spine_godot_types();
|
void register_spine_godot_types();
|
||||||
void unregister_spine_godot_types();
|
void unregister_spine_godot_types();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user