Modifying AtlasAttachmentLoader would work yeah. Or you can pass the attachment loader when you create the SkeletonJson or SkeletonBinary. There is a constructor that takes an AttachmentLoader.
Nick yazdıI don't see I could pass a new AtlasAttachmentLoader to the runtime. It is making its instance internally.
Coming back after some time to make this part clear. If you create a SkeletonJson or SkeletonBinary with the constructor taking a TextureAtlas, then it uses AtlasAttachmentLoader:
var textureAtlas = ...
var loader = new SkeletonJson(textureAtlas); // Uses AtlasAttachmentLoader.
However, you can provide your own AttachmentLoader to the constructor. Eg:
var loader = new SkeletonJson(new MyCustomAttachmentLoader());
That way your AttachmentLoader implementation is in your codebase and you don't need to modify the runtimes. You can pass your AttachmentLoader any number of atlases or whatever is necessary.
Also, I've reading through this thread again. I think the best solution is to pack each atlas and use your own AttachmentLoader. For example, if your images are like this:
images/skin1/head/red.png
images/skin2/head/green.png
Then you might want to run the packer on each skin folder. That would give you multiple atlases and names in each atlas relative to the packed folder, eg head/red.png
or head/green.png
.
Next, the AtlasAttachmentLoader has this code to find a mesh's atlas region (varies a little per runtime):
public MeshAttachment newMeshAttachment (Skin skin, String name, String path) {
AtlasRegion region = atlas.findRegion(path);
if (region == null) throw new RuntimeException("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
MeshAttachment attachment = new MeshAttachment(name);
attachment.setRegion(region);
return attachment;
}
That won't find any regions because the name
parameter will be the name in Spine, which is relative to the images
folder, eg skin1/head/red.png
while our atlas has the name head/red.png
. However, the skin is passed in, so we could easily fix it by changing this line (in a copy of AtlasAttachmentLoader):
AtlasRegion region = atlas.findRegion(skin.getName() + "/" + path);
Next, if needed we can customize how to handle a region not being found. We could throw an error, as the code above does, or we could do something like, like look in additional atlases.
Or, we could return null
, which means the skeleton will not have the mesh attachment at all. Note that if the mesh is a source mesh and you need to use one of its linked meshes, it will cause an error to return null
.
Or, we could just return the attachment without setting its region. That is the safest, as you can still use its linked meshes, but it means trying to render the regionless attachment will fail. That is probably fine, since if you don't have a region for the attachment, it's probably because you won't be rendering it.