mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 15:24:55 +08:00
Clean-up
This commit is contained in:
parent
5ec5544132
commit
48bdebcab4
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
||||
[remap]
|
||||
|
||||
importer="spine.atlas"
|
||||
type="SpineAtlasResource"
|
||||
path="res://.import/spineboy.atlas-ce2b95e2abaaca5faa7726fe317501ea.spatlas"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://spineboy.atlas"
|
||||
dest_files=[ "res://.import/spineboy.atlas-ce2b95e2abaaca5faa7726fe317501ea.spatlas" ]
|
||||
|
||||
[params]
|
||||
|
||||
normal_texture_prefix=""
|
||||
@ -1,17 +0,0 @@
|
||||
extends SpineSprite
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
self.get_animation_state().set_animation("walk", true, 0)
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
@ -1,10 +0,0 @@
|
||||
[gd_resource type="SpineSkeletonDataResource" load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://spineboy.atlas" type="SpineAtlasResource" id=1]
|
||||
[ext_resource path="res://spineboy-pro.spjson" type="SpineSkeletonJsonDataResource" id=2]
|
||||
|
||||
[resource]
|
||||
atlas_res = ExtResource( 1 )
|
||||
skeleton_json_res = ExtResource( 2 )
|
||||
animations = null
|
||||
skins = null
|
||||
14
spine-godot/example/spineboy/spineboy.atlas.import
Normal file
14
spine-godot/example/spineboy/spineboy.atlas.import
Normal file
@ -0,0 +1,14 @@
|
||||
[remap]
|
||||
|
||||
importer="spine.atlas"
|
||||
type="SpineAtlasResource"
|
||||
path="res://.import/spineboy.atlas-0160ebf51649da264b83de15c13561f4.spatlas"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://spineboy/spineboy.atlas"
|
||||
dest_files=[ "res://.import/spineboy.atlas-0160ebf51649da264b83de15c13561f4.spatlas" ]
|
||||
|
||||
[params]
|
||||
|
||||
normal_texture_prefix="n"
|
||||
|
Before Width: | Height: | Size: 243 KiB After Width: | Height: | Size: 243 KiB |
@ -2,15 +2,15 @@
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/spineboy.png-846f399ad53ae6f7ed8bbfe03f0b1f88.stex"
|
||||
path="res://.import/spineboy.png-a63588ec3a5ca6e83ef256edf38d798a.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://spineboy.png"
|
||||
dest_files=[ "res://.import/spineboy.png-846f399ad53ae6f7ed8bbfe03f0b1f88.stex" ]
|
||||
source_file="res://spineboy/spineboy.png"
|
||||
dest_files=[ "res://.import/spineboy.png-a63588ec3a5ca6e83ef256edf38d798a.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
[gd_resource type="SpineAnimationStateDataResource" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://spineboy.tres" type="SpineSkeletonDataResource" id=1]
|
||||
|
||||
[resource]
|
||||
skeleton = ExtResource( 1 )
|
||||
default_mix = 1.0
|
||||
@ -1,13 +1,4 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://spineboy.gd" type="Script" id=1]
|
||||
[ext_resource path="res://spineboyanimdata.tres" type="SpineAnimationStateDataResource" id=2]
|
||||
[gd_scene format=2]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
position = Vector2( 2.12469, 1.06235 )
|
||||
|
||||
[node name="SpineSprite" type="SpineSprite" parent="."]
|
||||
position = Vector2( 503.556, 465.311 )
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
animation_state_data_res = ExtResource( 2 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
@ -35,15 +35,15 @@
|
||||
class GodotSpineTextureLoader : public spine::TextureLoader {
|
||||
private:
|
||||
Array *textures, *normal_maps;
|
||||
String normal_maps_prefix;
|
||||
String normal_map_prefix;
|
||||
|
||||
public:
|
||||
GodotSpineTextureLoader(Array *t, Array *nt, const String &p) : textures(t), normal_maps(nt), normal_maps_prefix(p) {
|
||||
GodotSpineTextureLoader(Array *t, Array *nt, const String &p) : textures(t), normal_maps(nt), normal_map_prefix(p) {
|
||||
if (textures) textures->clear();
|
||||
if (normal_maps) normal_maps->clear();
|
||||
}
|
||||
|
||||
String fixPathIssue(const String &path) {
|
||||
String fix_path(const String &path) {
|
||||
if (path.size() > 5 && path[4] == '/' && path[5] == '/') return path;
|
||||
const String prefix = "res:/";
|
||||
auto i = path.find(prefix);
|
||||
@ -63,52 +63,40 @@ public:
|
||||
|
||||
virtual void load(spine::AtlasPage &page, const spine::String &path) {
|
||||
Error err = OK;
|
||||
auto fixed_path = fix_path(String(path.buffer()));
|
||||
|
||||
// print_line(String("Spine is loading texture: ") + String(path.buffer()));
|
||||
auto fixed_path = fixPathIssue(String(path.buffer()));
|
||||
// print_line("Fixed path: " + fixed_path);
|
||||
|
||||
// Load texture (e.g. tex.png)
|
||||
Ref<Texture> tex = ResourceLoader::load(fixed_path, "", false, &err);
|
||||
Ref<Texture> texture = ResourceLoader::load(fixed_path, "", false, &err);
|
||||
if (err != OK) {
|
||||
print_error(vformat("Can't load texture: \"%s\"", String(path.buffer())));
|
||||
page.setRendererObject((void *) memnew(SpineRendererObject{nullptr}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (textures) textures->append(tex);
|
||||
auto p_spine_renderer_object = memnew(SpineRendererObject);
|
||||
p_spine_renderer_object->tex = tex;
|
||||
if (textures) textures->append(texture);
|
||||
auto spine_renderer_object = memnew(SpineRendererObject);
|
||||
spine_renderer_object->texture = texture;
|
||||
|
||||
// Load normal texture (e.g. n_tex.png)
|
||||
String temppath = fixed_path;
|
||||
String newpath = vformat("%s/%s_%s", temppath.get_base_dir(), normal_maps_prefix, temppath.get_file());
|
||||
// print_line(vformat("try n tex: %s", newpath));
|
||||
if (ResourceLoader::exists(newpath)) {
|
||||
Ref<Texture> normal_tex = ResourceLoader::load(newpath);
|
||||
if (normal_maps) normal_maps->append(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(Variant(p_spine_renderer_object->tex)) + String(", ") + String(Variant(p_spine_renderer_object->normal_tex)));
|
||||
String temp_path = fixed_path;
|
||||
String new_path = vformat("%s/%s_%s", temp_path.get_base_dir(), normal_map_prefix, temp_path.get_file());
|
||||
if (ResourceLoader::exists(new_path)) {
|
||||
Ref<Texture> normal_map = ResourceLoader::load(new_path);
|
||||
if (normal_maps) normal_maps->append(normal_map);
|
||||
spine_renderer_object->normal_map = normal_map;
|
||||
}
|
||||
|
||||
page.setRendererObject((void *) p_spine_renderer_object);
|
||||
page.setRendererObject((void *) spine_renderer_object);
|
||||
|
||||
page.width = tex->get_width();
|
||||
page.height = tex->get_height();
|
||||
page.width = texture->get_width();
|
||||
page.height = texture->get_height();
|
||||
}
|
||||
|
||||
virtual void unload(void *p) {
|
||||
// print_line("I'm out.");
|
||||
auto p_spine_renderer_object = (SpineRendererObject *) p;
|
||||
Ref<Texture> &tex = p_spine_renderer_object->tex;
|
||||
Ref<Texture> &normal_tex = p_spine_renderer_object->normal_tex;
|
||||
|
||||
if (tex.is_valid()) tex.unref();
|
||||
if (normal_tex.is_valid()) normal_tex.unref();
|
||||
|
||||
memdelete(p_spine_renderer_object);
|
||||
auto spine_renderer_object = (SpineRendererObject *) p;
|
||||
Ref<Texture> &texture = spine_renderer_object->texture;
|
||||
if (texture.is_valid()) texture.unref();
|
||||
Ref<Texture> &normal_map = spine_renderer_object->normal_map;
|
||||
if (normal_map.is_valid()) normal_map.unref();
|
||||
memdelete(spine_renderer_object);
|
||||
}
|
||||
};
|
||||
|
||||
@ -123,20 +111,20 @@ void SpineAtlasResource::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_source_path"), &SpineAtlasResource::get_source_path);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_textures"), &SpineAtlasResource::get_textures);
|
||||
ClassDB::bind_method(D_METHOD("get_normal_textures"), &SpineAtlasResource::get_normal_textures);
|
||||
ClassDB::bind_method(D_METHOD("get_normal_maps"), &SpineAtlasResource::get_normal_maps);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "source_path"), "", "get_source_path");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures"), "", "get_textures");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "normal_textures"), "", "get_normal_textures");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "normal_maps"), "", "get_normal_maps");
|
||||
}
|
||||
|
||||
|
||||
Array SpineAtlasResource::get_textures() {
|
||||
return tex_list;
|
||||
return textures;
|
||||
}
|
||||
|
||||
Array SpineAtlasResource::get_normal_textures() {
|
||||
return ntex_list;
|
||||
Array SpineAtlasResource::get_normal_maps() {
|
||||
return normal_maps;
|
||||
}
|
||||
|
||||
String SpineAtlasResource::get_source_path() {
|
||||
@ -144,33 +132,25 @@ String SpineAtlasResource::get_source_path() {
|
||||
}
|
||||
|
||||
Error SpineAtlasResource::load_from_atlas_file(const String &p_path) {
|
||||
// print_line(vformat("Importing atlas file: %s", p_path));
|
||||
source_path = p_path;
|
||||
|
||||
Error err;
|
||||
|
||||
atlas_data = FileAccess::get_file_as_string(p_path, &err);
|
||||
if (err != OK) return err;
|
||||
|
||||
if (atlas) delete atlas;
|
||||
tex_list.clear();
|
||||
ntex_list.clear();
|
||||
atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&tex_list, &ntex_list, normal_texture_prefix));
|
||||
|
||||
// print_line(vformat("atlas loaded!"));
|
||||
|
||||
if (atlas)
|
||||
return OK;
|
||||
|
||||
tex_list.clear();
|
||||
ntex_list.clear();
|
||||
textures.clear();
|
||||
normal_maps.clear();
|
||||
atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&textures, &normal_maps, normal_texture_prefix));
|
||||
if (atlas) return OK;
|
||||
|
||||
textures.clear();
|
||||
normal_maps.clear();
|
||||
return ERR_FILE_UNRECOGNIZED;
|
||||
}
|
||||
|
||||
Error SpineAtlasResource::load_from_file(const String &p_path) {
|
||||
Error err;
|
||||
|
||||
String json_string = FileAccess::get_file_as_string(p_path, &err);
|
||||
if (err != OK) return err;
|
||||
|
||||
@ -179,26 +159,21 @@ Error SpineAtlasResource::load_from_file(const String &p_path) {
|
||||
JSON json;
|
||||
Variant result;
|
||||
err = json.parse(json_string, result, error_string, error_line);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
if (err != OK) return err;
|
||||
|
||||
Dictionary content = Dictionary(result);
|
||||
|
||||
source_path = content["source_path"];
|
||||
atlas_data = content["atlas_data"];
|
||||
normal_texture_prefix = content["normal_texture_prefix"];
|
||||
|
||||
if (atlas) delete atlas;
|
||||
tex_list.clear();
|
||||
ntex_list.clear();
|
||||
atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&tex_list, &ntex_list, normal_texture_prefix));
|
||||
textures.clear();
|
||||
normal_maps.clear();
|
||||
atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&textures, &normal_maps, normal_texture_prefix));
|
||||
if (atlas) return OK;
|
||||
|
||||
if (atlas)
|
||||
return OK;
|
||||
|
||||
tex_list.clear();
|
||||
ntex_list.clear();
|
||||
textures.clear();
|
||||
normal_maps.clear();
|
||||
return ERR_FILE_UNRECOGNIZED;
|
||||
}
|
||||
|
||||
@ -206,7 +181,6 @@ Error SpineAtlasResource::save_to_file(const String &p_path) {
|
||||
Error err;
|
||||
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
if (err != OK) {
|
||||
// print_line(vformat("save file err: %d", err));
|
||||
if (file) file->close();
|
||||
return err;
|
||||
}
|
||||
@ -216,8 +190,6 @@ Error SpineAtlasResource::save_to_file(const String &p_path) {
|
||||
content["atlas_data"] = atlas_data;
|
||||
content["normal_texture_prefix"] = normal_texture_prefix;
|
||||
|
||||
// print_line(vformat("storing source_path: %s", source_path));
|
||||
|
||||
file->store_string(JSON::print(content));
|
||||
file->close();
|
||||
|
||||
|
||||
@ -52,8 +52,8 @@ protected:
|
||||
String atlas_data;
|
||||
String normal_texture_prefix;
|
||||
|
||||
Array tex_list;
|
||||
Array ntex_list;
|
||||
Array textures;
|
||||
Array normal_maps;
|
||||
|
||||
public:
|
||||
inline String &get_atlas_data() { return atlas_data; }
|
||||
@ -69,7 +69,7 @@ public:
|
||||
|
||||
String get_source_path();
|
||||
Array get_textures();
|
||||
Array get_normal_textures();
|
||||
Array get_normal_maps();
|
||||
|
||||
SpineAtlasResource();
|
||||
virtual ~SpineAtlasResource();
|
||||
|
||||
@ -32,10 +32,9 @@
|
||||
|
||||
#include <scene/resources/texture.h>
|
||||
|
||||
|
||||
struct SpineRendererObject {
|
||||
Ref<Texture> tex;
|
||||
Ref<Texture> normal_tex;
|
||||
Ref<Texture> texture;
|
||||
Ref<Texture> normal_map;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -119,7 +119,6 @@ void SpineSkeletonDataResource::update_skeleton_data() {
|
||||
void SpineSkeletonDataResource::set_atlas_res(const Ref<SpineAtlasResource> &a) {
|
||||
atlas_res = a;
|
||||
valid = false;
|
||||
// print_line("atlas_res_changed emitted");
|
||||
emit_signal("atlas_res_changed");
|
||||
update_skeleton_data();
|
||||
}
|
||||
|
||||
@ -386,8 +386,8 @@ void SpineSprite::update_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
||||
spine::RegionAttachment *region_attachment = (spine::RegionAttachment *) attachment;
|
||||
|
||||
auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region_attachment->getRendererObject())->page->getRendererObject();
|
||||
tex = p_spine_renderer_object->tex;
|
||||
normal_tex = p_spine_renderer_object->normal_tex;
|
||||
tex = p_spine_renderer_object->texture;
|
||||
normal_tex = p_spine_renderer_object->normal_map;
|
||||
|
||||
v_num = 4;
|
||||
vertices.setSize(v_num * VERTEX_STRIDE, 0);
|
||||
@ -410,8 +410,8 @@ void SpineSprite::update_mesh_from_skeleton(Ref<SpineSkeleton> s) {
|
||||
spine::MeshAttachment *mesh = (spine::MeshAttachment *) attachment;
|
||||
|
||||
auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject();
|
||||
tex = p_spine_renderer_object->tex;
|
||||
normal_tex = p_spine_renderer_object->normal_tex;
|
||||
tex = p_spine_renderer_object->texture;
|
||||
normal_tex = p_spine_renderer_object->normal_map;
|
||||
|
||||
v_num = mesh->getWorldVerticesLength() / VERTEX_STRIDE;
|
||||
vertices.setSize(mesh->getWorldVerticesLength(), 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user