|
@@ -61,10 +61,12 @@ class GodotSpineTextureLoader : public spine::TextureLoader {
|
|
|
|
|
|
Array *textures;
|
|
|
Array *normal_maps;
|
|
|
+ Array *specular_maps;
|
|
|
String normal_map_prefix;
|
|
|
+ String specular_map_prefix;
|
|
|
|
|
|
public:
|
|
|
- GodotSpineTextureLoader(Array *_textures, Array *_normal_maps, const String &normal_map_prefix, bool is_importing) : textures(_textures), normal_maps(_normal_maps), normal_map_prefix(normal_map_prefix) {
|
|
|
+ GodotSpineTextureLoader(Array *_textures, Array *_normal_maps, Array *_specular_maps, const String &normal_map_prefix, const String &specular_map_prefix, bool is_importing) : textures(_textures), normal_maps(_normal_maps), specular_maps(_specular_maps), normal_map_prefix(normal_map_prefix), specular_map_prefix(specular_map_prefix) {
|
|
|
}
|
|
|
|
|
|
static bool fix_path(String &path) {
|
|
@@ -156,6 +158,7 @@ public:
|
|
|
auto renderer_object = memnew(SpineRendererObject);
|
|
|
renderer_object->texture = Ref<Texture>(nullptr);
|
|
|
renderer_object->normal_map = Ref<Texture>(nullptr);
|
|
|
+ renderer_object->specular_map = Ref<Texture>(nullptr);
|
|
|
page.texture = (void *) renderer_object;
|
|
|
return;
|
|
|
}
|
|
@@ -164,9 +167,12 @@ public:
|
|
|
auto renderer_object = memnew(SpineRendererObject);
|
|
|
renderer_object->texture = texture;
|
|
|
renderer_object->normal_map = Ref<Texture>(nullptr);
|
|
|
+ renderer_object->specular_map = Ref<Texture>(nullptr);
|
|
|
|
|
|
String normal_map_path = vformat("%s/%s_%s", fixed_path.get_base_dir(), normal_map_prefix, fixed_path.get_file());
|
|
|
+ String specular_map_path = vformat("%s/%s_%s", fixed_path.get_base_dir(), specular_map_prefix, fixed_path.get_file());
|
|
|
is_resource = fix_path(normal_map_path);
|
|
|
+ is_resource = fix_path(specular_map_path);
|
|
|
#if SPINE_GODOT_EXTENSION
|
|
|
if (ResourceLoader::get_singleton()->exists(normal_map_path)) {
|
|
|
import_image_resource(normal_map_path);
|
|
@@ -174,6 +180,13 @@ public:
|
|
|
normal_maps->append(normal_map);
|
|
|
renderer_object->normal_map = normal_map;
|
|
|
}
|
|
|
+
|
|
|
+ if (ResourceLoader::get_singleton()->exists(specular_map_path)) {
|
|
|
+ import_image_resource(specular_map_path);
|
|
|
+ Ref<Texture> specular_map = get_texture_from_image(specular_map_path, is_resource);
|
|
|
+ specular_maps->append(specular_map);
|
|
|
+ renderer_object->specular_map = specular_map;
|
|
|
+ }
|
|
|
#else
|
|
|
if (ResourceLoader::exists(normal_map_path)) {
|
|
|
import_image_resource(normal_map_path);
|
|
@@ -181,12 +194,20 @@ public:
|
|
|
normal_maps->append(normal_map);
|
|
|
renderer_object->normal_map = normal_map;
|
|
|
}
|
|
|
+
|
|
|
+ if (ResourceLoader::exists(specular_map_path)) {
|
|
|
+ import_image_resource(specular_map_path);
|
|
|
+ Ref<Texture> specular_map = get_texture_from_image(specular_map_path, is_resource);
|
|
|
+ specular_maps->append(specular_map);
|
|
|
+ renderer_object->specular_map = specular_map;
|
|
|
+ }
|
|
|
#endif
|
|
|
|
|
|
#if VERSION_MAJOR > 3
|
|
|
renderer_object->canvas_texture.instantiate();
|
|
|
renderer_object->canvas_texture->set_diffuse_texture(renderer_object->texture);
|
|
|
renderer_object->canvas_texture->set_normal_texture(renderer_object->normal_map);
|
|
|
+ renderer_object->canvas_texture->set_specular_texture(renderer_object->specular_map);
|
|
|
#endif
|
|
|
|
|
|
page.texture = (void *) renderer_object;
|
|
@@ -198,6 +219,7 @@ public:
|
|
|
auto renderer_object = (SpineRendererObject *) data;
|
|
|
if (renderer_object->texture.is_valid()) renderer_object->texture.unref();
|
|
|
if (renderer_object->normal_map.is_valid()) renderer_object->normal_map.unref();
|
|
|
+ if (renderer_object->specular_map.is_valid()) renderer_object->specular_map.unref();
|
|
|
#if VERSION_MAJOR > 3
|
|
|
if (renderer_object->canvas_texture.is_valid()) renderer_object->canvas_texture.unref();
|
|
|
#endif
|
|
@@ -210,13 +232,15 @@ 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_maps"), &SpineAtlasResource::get_normal_maps);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_specular_maps"), &SpineAtlasResource::get_specular_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_maps"), "", "get_normal_maps");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "specular_maps"), "", "get_specular_maps");
|
|
|
}
|
|
|
|
|
|
-SpineAtlasResource::SpineAtlasResource() : atlas(nullptr), texture_loader(nullptr), normal_map_prefix("n") {
|
|
|
+SpineAtlasResource::SpineAtlasResource() : atlas(nullptr), texture_loader(nullptr), normal_map_prefix("n"), specular_map_prefix("s") {
|
|
|
}
|
|
|
|
|
|
SpineAtlasResource::~SpineAtlasResource() {
|
|
@@ -231,6 +255,7 @@ void SpineAtlasResource::clear() {
|
|
|
texture_loader = nullptr;
|
|
|
textures.clear();
|
|
|
normal_maps.clear();
|
|
|
+ specular_maps.clear();
|
|
|
}
|
|
|
|
|
|
Array SpineAtlasResource::get_textures() {
|
|
@@ -241,6 +266,10 @@ Array SpineAtlasResource::get_normal_maps() {
|
|
|
return normal_maps;
|
|
|
}
|
|
|
|
|
|
+Array SpineAtlasResource::get_specular_maps() {
|
|
|
+ return specular_maps;
|
|
|
+}
|
|
|
+
|
|
|
String SpineAtlasResource::get_source_path() {
|
|
|
return source_path;
|
|
|
}
|
|
@@ -261,7 +290,7 @@ Error SpineAtlasResource::load_from_atlas_file_internal(const String &path, bool
|
|
|
#endif
|
|
|
|
|
|
clear();
|
|
|
- texture_loader = new GodotSpineTextureLoader(&textures, &normal_maps, normal_map_prefix, is_importing);
|
|
|
+ texture_loader = new GodotSpineTextureLoader(&textures, &normal_maps, &specular_maps, normal_map_prefix, specular_map_prefix, is_importing);
|
|
|
auto atlas_utf8 = atlas_data.utf8();
|
|
|
atlas = new spine::Atlas(atlas_utf8, atlas_utf8.length(), source_path.get_base_dir().utf8(), texture_loader);
|
|
|
if (atlas) return OK;
|
|
@@ -301,9 +330,10 @@ Error SpineAtlasResource::load_from_file(const String &path) {
|
|
|
source_path = content["source_path"];
|
|
|
atlas_data = content["atlas_data"];
|
|
|
normal_map_prefix = content["normal_texture_prefix"];
|
|
|
+ specular_map_prefix = content["specular_texture_prefix"];
|
|
|
|
|
|
clear();
|
|
|
- texture_loader = new GodotSpineTextureLoader(&textures, &normal_maps, normal_map_prefix, false);
|
|
|
+ texture_loader = new GodotSpineTextureLoader(&textures, &normal_maps, &specular_maps, normal_map_prefix, specular_map_prefix, false);
|
|
|
auto utf8 = atlas_data.utf8();
|
|
|
atlas = new spine::Atlas(utf8.ptr(), utf8.size(), source_path.get_base_dir().utf8(), texture_loader);
|
|
|
if (atlas) return OK;
|
|
@@ -334,6 +364,7 @@ Error SpineAtlasResource::save_to_file(const String &path) {
|
|
|
content["source_path"] = source_path;
|
|
|
content["atlas_data"] = atlas_data;
|
|
|
content["normal_texture_prefix"] = normal_map_prefix;
|
|
|
+ content["specular_texture_prefix"] = specular_map_prefix;
|
|
|
#if VERSION_MAJOR > 3
|
|
|
JSON *json = memnew(JSON);
|
|
|
file->store_string(json->stringify(content));
|
|
@@ -361,8 +392,10 @@ Error SpineAtlasResource::copy_from(const Ref<Resource> &p_resource) {
|
|
|
this->source_path = spineAtlas->source_path;
|
|
|
this->atlas_data = spineAtlas->atlas_data;
|
|
|
this->normal_map_prefix = spineAtlas->normal_map_prefix;
|
|
|
+ this->specular_map_prefix = spineAtlas->specular_map_prefix;
|
|
|
this->textures = spineAtlas->textures;
|
|
|
this->normal_maps = spineAtlas->normal_maps;
|
|
|
+ this->specular_maps = spineAtlas->specular_maps;
|
|
|
emit_signal(SNAME("skeleton_file_changed"));
|
|
|
|
|
|
return OK;
|