[godot] Fix loading of atlas page PNGs for non-resource paths (user://, absolute). Closes #2814

This commit is contained in:
Mario Zechner 2025-05-06 16:10:55 +02:00
parent 480a4b18b7
commit 5b2d479d4b
2 changed files with 26 additions and 12 deletions

View File

@ -46,6 +46,23 @@
"program": "${workspaceFolder}/godot/bin/godot.macos.editor.dev.arm64" "program": "${workspaceFolder}/godot/bin/godot.macos.editor.dev.arm64"
} }
}, },
{
"type": "cppvsdbg",
"request": "launch",
"name": "debug scene extension",
"program": "godot/bin/godot.windows.editor.dev.x86_64.exe",
"args": ["--path", "example-v4-extension", "examples/13-load-from-disk/load-from-disk.tscn"],
"cwd": "${workspaceFolder}",
"preLaunchTask": "build-extension",
"linux": {
"type": "lldb",
"program": "${workspaceFolder}/godot/bin/godot.linux.editor.dev.x86_64"
},
"osx": {
"type": "lldb",
"program": "${workspaceFolder}/godot/bin/godot.macos.editor.dev.arm64"
}
},
{ {
"type": "cppvsdbg", "type": "cppvsdbg",
"request": "launch", "request": "launch",

View File

@ -140,23 +140,18 @@ public:
} }
void load(spine::AtlasPage &page, const spine::String &path) override { void load(spine::AtlasPage &page, const spine::String &path) override {
Error error = OK;
String fixed_path; String fixed_path;
fixed_path.parse_utf8(path.buffer()); fixed_path.parse_utf8(path.buffer());
bool is_resource = fix_path(fixed_path); bool is_resource = fix_path(fixed_path);
import_image_resource(fixed_path); import_image_resource(fixed_path);
#if SPINE_GODOT_EXTENSION
Ref<Texture2D> texture = ResourceLoader::get_singleton()->load(fixed_path, "", ResourceLoader::CACHE_MODE_REUSE);
#else
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
Ref<Texture2D> texture = get_texture_from_image(fixed_path, is_resource); Ref<Texture2D> texture = get_texture_from_image(fixed_path, is_resource);
#else #else
Ref<Texture> texture = get_texture_from_image(fixed_path, is_resource); Ref<Texture> texture = get_texture_from_image(fixed_path, is_resource);
#endif #endif
#endif if (!texture.is_valid()) {
if (error != OK || !texture.is_valid()) {
ERR_PRINT(vformat("Can't load texture: \"%s\"", fixed_path)); ERR_PRINT(vformat("Can't load texture: \"%s\"", fixed_path));
auto renderer_object = memnew(SpineRendererObject); auto renderer_object = memnew(SpineRendererObject);
renderer_object->texture = Ref<Texture>(nullptr); renderer_object->texture = Ref<Texture>(nullptr);
@ -170,17 +165,19 @@ public:
renderer_object->texture = texture; renderer_object->texture = texture;
renderer_object->normal_map = Ref<Texture>(nullptr); renderer_object->normal_map = Ref<Texture>(nullptr);
String new_path = vformat("%s/%s_%s", fixed_path.get_base_dir(), normal_map_prefix, fixed_path.get_file()); String normal_map_path = vformat("%s/%s_%s", fixed_path.get_base_dir(), normal_map_prefix, fixed_path.get_file());
is_resource = fix_path(normal_map_path);
#if SPINE_GODOT_EXTENSION #if SPINE_GODOT_EXTENSION
if (ResourceLoader::get_singleton()->exists(new_path)) { if (ResourceLoader::get_singleton()->exists(normal_map_path)) {
Ref<Texture> normal_map = ResourceLoader::get_singleton()->load(new_path); import_image_resource(normal_map_path);
Ref<Texture> normal_map = get_texture_from_image(normal_map_path, is_resource);
normal_maps->append(normal_map); normal_maps->append(normal_map);
renderer_object->normal_map = normal_map; renderer_object->normal_map = normal_map;
} }
#else #else
if (ResourceLoader::exists(new_path)) { if (ResourceLoader::exists(normal_map_path)) {
import_image_resource(new_path); import_image_resource(normal_map_path);
Ref<Texture> normal_map = get_texture_from_image(new_path, is_resource); Ref<Texture> normal_map = get_texture_from_image(normal_map_path, is_resource);
normal_maps->append(normal_map); normal_maps->append(normal_map);
renderer_object->normal_map = normal_map; renderer_object->normal_map = normal_map;
} }