Not for the upcoming Spine 4.2 release which we'll likely publish this week. However, if you folks can send a PR, I can see if I can get it into the next patch release. It will need quite some testing on my end, as it does modify a crucial code path.
Loading Spine Sprite at runtime
I encountered the same issue. Could you please provide guidance on how to load a texture but only for Godot version 3.5.3, as the necessary methods are not present in the Godot *.cpp files?
Ref<Image> image=Image::load_from_file(fixed_path);
texture = ImageTexture::create_from_image(image);
I have figured out the image loading part, now I just need to turn it into a texture.
old:
Ref<Image> image=Image::load_from_file(fixed_path);
new:
Ref<Image> image;
image.instance();
ImageLoader::load_image(fixed_path, image);
I was able to make a similar modification for version 3.5.3, and it works!!
const String prefix = "res:/";
auto i = fixed_path.find(prefix);
Ref<ImageTexture> texture;
if (i < 0) {
Ref<Image> image;
image.instance();
image->load(fixed_path);
texture.instance();
texture->create_from_image(image);
} else {
texture = ResourceLoader::load(fixed_path, "", false, &error);
}
Fix:
const String prefix = "res:/";
auto i = fixed_path.find(prefix);
Ref<Texture> texture;
if (i < 0) {
Ref<Image> image;
image.instance();
image->load(fixed_path);
Ref<ImageTexture> image_texture;
image_texture.instance();
image_texture->create_from_image(image);
texture = image_texture;
} else {
texture = ResourceLoader::load(fixed_path, "", false, &error);
}
Fix GDScript for Godot 3.x
extends Node
class_name SpineSpriteFileLoader
const known_atlasses = {}
const known_skeletons = {}
static func _load_spine_atlas(atlas_path:String) -> SpineAtlasResource:
var atlas_res:SpineAtlasResource = null
if known_atlasses.has(atlas_path) and known_atlasses[atlas_path].get_ref() != null:
atlas_res = known_atlasses[atlas_path].get_ref()
else:
atlas_res = SpineAtlasResource.new()
var error = atlas_res.load_from_atlas_file(atlas_path)
if error != OK:
printerr("Failure loading atlas@"+atlas_path,error)
known_atlasses[atlas_path] = weakref(atlas_res)
return atlas_res
static func _load_spine_skeleton(skeleton_json_path:String) -> SpineSkeletonFileResource:
var skeleton_file_res:SpineSkeletonFileResource = null
if known_skeletons.has(skeleton_json_path) and known_skeletons[skeleton_json_path].get_ref() != null:
skeleton_file_res = known_skeletons[skeleton_json_path].get_ref()
else:
skeleton_file_res = SpineSkeletonFileResource.new()
var error = skeleton_file_res.load_from_file(skeleton_json_path)
if error != OK:
printerr("Failure loading json-spine! ",error)
known_skeletons[skeleton_json_path] = weakref(skeleton_file_res)
return skeleton_file_res
static func load_spine_sprite(atlas_path:String, skeletonm_json_path:String) -> SpineSprite:
var atlas_res:SpineAtlasResource = _load_spine_atlas(atlas_path)
var skeleton_file_res:SpineSkeletonFileResource=_load_spine_skeleton(skeletonm_json_path)
var skeleton_data_res:SpineSkeletonDataResource = SpineSkeletonDataResource.new()
skeleton_data_res.skeleton_file_res = skeleton_file_res
skeleton_data_res.atlas_res = atlas_res
var sprite:SpineSprite = SpineSprite.new()
sprite.skeleton_data_res = skeleton_data_res
return sprite
Thanks for the investigation. I'll be adding both of your suggestions to our build this week.
Thanks Mario. I know you asked for a pull request. I can still do that but if you can manage without one I would appreciate it as I have never done one before and was still reading up.
No need for a pull request, I'll manage to do it without one.
I've noticed some strange behavior, most likely it's an error that needs to be fixed, but unfortunately, I haven't been able to find a solution for it. I'm writing about it in this thread because it's related to it. If we have a scene with a spine object that was loaded from the file system rather than from the game's resources, then upon reloading, the spine object will be empty. If you have a quick solution for this, I would greatly appreciate it.
I'm afraid I do not have a quick solution. Can you please provide me with an example project to reproduce the issue? Just a scene + gdscript + assets would do.