- Modifié
'Flatten paths' but for skeleton?
I'm working on an automated setup for exporting skeletons and their atlases separately (because a few atlases are shared by many skeletons). It's mostly working, but the issue is that the skeleton data is looking for regions named like "both/Arm" and "both/Leg", whereas the atlas has all of its regions named like "Arm" and "Leg". The packing settings have combineSubdirectories
and flattenPaths
both set to false; the difference in names comes from the fact that the .spine file's skeleton.images
property is set to one directory higher than the atlas's -i
is. I can't raise the atlas's -i
location, because there's other folders that I don't want exported; making the .spine file's atlas root one directory lower would work in theory, but I don't know of a safe way to change that now that the .spine file has already been created and set up with it set where it is.
What possible ways are there to resolve this situation? The two possibilities that come to mind for me are:
- Is there a way to set a property like
flattenPaths
on the SKELETON'S (rather than the atlas's) export, so that the skeleton will just look for "Arm" rather than "both/Arm"? - If not: is there a way to change the root folder that the .spine file looks for images beneath, without breaking all of the (many, many) regions that have already been created?
You could copy your images into a temp folder and pack the atlas from there.
You could pack the atlas as part of data export, using Attachments
mode so it only packs the attachments in use by the skeletons. This is somewhat less flexible though because pack.json
files are not used.
You could provide an AttachmentLoader at runtime to resolve attachment paths to atlas regions any way you like. For example, you could add the both/
prefix before looking in the atlas. More info here:
Loading Skeleton Data - Spine Runtimes Guide: AttachmentLoader
Moving things into a temp folder would technically work, but that's a lot of data to move around on every export just to make this work...
Packing the atlas as part of data export isn't an option; the point is to export the skeletons and atlases separately.
AttachmentLoader looks like it would work, but it also looks fairly complex and I'm having a hard time finding examples...
In searching around, I found another thread mentioning using the Spine GUI's "find and replace" feature to change all of the paths, and then change the image folder location, and this works! It's just unfortunate that it needs to be done manually for each file; is there any way to perform something like that from the CLI, or as a batch operation that spans multiple files, other than I guess exporting every file as JSON, and modifying the JSON values directly, and then importing them back into .spine files?
FWIW, copying the images to a temp folder is unlikely to take very long.
The AttachmentLoader is the standard way of customizing how attachment names/paths are mapped to texture atlas names. It's very easy, just copy/paste the source for AtlasAttachmentLoader (from whichever runtime you are using), rename the class, then everywhere you see TextureAtlas findRegion
called, add the both/
prefix. Then you use your attachment loader like this:
loader = new SkeletonJson(new YourAttachmentLoader(atlas));
I'm not sure how a CLI parameter would work well. If we strip all the folder prefixes from the texture atlas names, the names still need to be unique else we'd need to stop with an error. It seems easier to solve the problem by adjusting your organization. Doing that doesn't seem terribly onerous.
You could pack one folder higher and use pack.json
files containing {ignore:true}
so you don't pack other folders. Or you could move those other folders elsewhere. Or you could add a new folder so you have:
images/nopack1
images/nopack2
images/skeletons/both/Arm.png
images/skeletons/both/Leg.png
Then you'd pack images/skeletons
and set the images path of your Spine projects to images/skeletons
.
Most people with a similar problem have the opposite: they want to strip a prefix. They have image folders like this:
root/skeleton1/images
root/skeleton2/images
They pack root
and don't want the skeleton1/
or skeleton2/
prefixes in the atlas because it's not there in the Spine project. The easiest answer is to set both the Spine project and the texture packer to the same folder. Then you won't have any of these issues. The tree even has a Hide skeleton names setting to reduce clutter when doing that.
Oh wow
I didn't realise about pack.json
having an ignore:true
setting; temporarily putting one of those in each of the other folders would absolutely be the simplest workaround at this point, I think. I've just implemented this in my script and it worked perfectly; thank you!