• Editor
  • Deterministic (or editable) names for exported texture files

Hello !

I'm looking for some kind of way to predict the name of the atlas pages exported by Spine.

The goal would be, in Unity, to override the Material using a specific atlas page, in order to swap it with another atlas page.

The thing is, when exporting from Spine, the exported texture names look like "avatar.png", "avatar_2.png"... making it difficult to know which atlas corresponds to which semantic part of a skeleton.


For example, let's say we have the following images folder hierarchy :

It would be nice after packing if the atlas page names looked like "avatar_base.png", "avatar_event_H.png", ("avatar_base_2.png" if needed, and so on...).

Therefore, we could for example make small edits on "avatar_base.png" and save an "avatar_alt.png".
At runtime, we could override the Material using "avatar_base.png" and swap it with "avatar_alt.png".


With the following example, that would mean we would have a "male.png" and a "female.png" atlas :

I spent quite some time reading the texture packing doc (http://fr.esotericsoftware.com/spine-texture-packer) and I feel like I'm missing something to get this workflow ^^"
Any help to achieve this would be highly appreciated ! 🙂

Hello,
it's great that you read the right docs already, did you also try to repeat this process and apply it to your files? If yes, what didn't work as you would have expected?

If you notice, the examples rely on the male and female avatar being in separate folders. Each folder has a .pack file in it and this allows to have the different results. You can also just run texture packer several times to have the different atlas names as you prefer them if it helps?

7 days later

So, I tried what I could from the Spine but never succeeded to achieve the desired workflow, which is : exporting the json+atlases+texture in the same time, with atlas names matching the folder hierarchy.

Erika wrote

You can also just run texture packer several times to have the different atlas names as you prefer them if it helps?

This would work... But the attachment paths lose the actual path.

In the Spine project, the image path contains the full path (e.g. "event_H/arm_L").
When exporting from Spine editor (with atlas packed per "Image folder"), the attachment paths also contain the full path.

However, when running texture packer for each image folder (from Spine GUI or from CLI), the paths are stripped from the attachments (e.g. "arm_L" instead of "event_H/arm_L").

Hence a little surprise in Unity when the SkeletonDataAsset couldn't resolve the atlases.

I found a user who had the same issue :
http://fr.esotericsoftware.com/forum/Mix-and-match-outfits-Addressables-loading-issue-16427?p=71940#p71940

pathfinder wrote

Besides this, a little question about exports. Since we are using a folder structure each export png is named after the skeleton (avatar_avatar_1, avatar_avatar_2), for organization purposes, how could we map the names to the folders used for the pngs? I saw that with a post build script could be possible, but I could not find some examples to base on.

So I'm a little disappointed this apparently common use case isn't implemented out-of-the-box in Spine, from GUI or CLI (that would be a really nice feature ! 🙂 )


I end up doing what is suggested here :

Harald wrote

So you could use a bash script to automatically setup directories and copy your images following the desired directory structure. E.g. for attachment names like "myskin/arm" you would below a top export directory "export" have a directory "myskin" where you place the attachment image "arm". Then you would run the texture packer via the command line interface on the "export" directory. Then you can continue with setup for the next atlas, export it via the CLI, and so on.

It works quite well (thanks Harald), but I have to say this is not the most intuitive and straightforward way to go ^^"

a year later

Hello, is there any update on being able to somehow force more relevant naming of atlases on Spine side?

I'm working on a project that has a constantly evolving stream of textures, and as far as I know, there is no way of naming the output atlases more appropriately than just "the chosen atlas name"_01 etc., it also doesn't help that all the numbers get shuffled around if you add or remove an atlas and re- export xD
Very confusing when trying to match normal maps with spine atlases on unity side, for example.

At the end of the previous message, there seems to be a round- about solution to the issue using a bash script, but i've never used one of these, and don't really understand it, so I'm hoping there is some way of predicting/ forcing the naming through folder structure or something??

Thanks in advance!

To match an atlas of normal maps, it's easiest to use images with the same pixel outlines and pack them with the same settings. Packing is deterministic so you can discard the normal map atlas file and use just the atlas images, which will match your diffuse images. Note this only works if the diffuse and normal images have pixels in the same positions with the same alpha.

The packer uses the filesystem's folder structure. To pack only some of your images but keep the path in the atlas, you'll need to copy the images to a temporary folder and pack that. This is done most easily using a shell script (batch file, Bash script, etc) and Spine's CLI. Packing (and exporting) is usually done many times, so using a script makes the process easier, is less error prone, and ensures all your projects are exported and the atlases and packed correctly. It also makes it easier to re-export all your projects, which you'll need to do if you move to a newer version of the Spine Runtimes.