- Edited
Export multiple texture files
I'm working on a mobile game in Unity with lots of art assets, so trying to minimize draw calls and reduce download file size. One use case is that I have a fancy patterned version of an outfit and another version that doesn't have patterns. Both of these can be plugged into the same material along with a threshold mask so different sections of the patterned version are revealed on top of the unpatterned version at different threshold values. We also use texture masking to apply different colors to specific sections of a texture. Current process is to pack the patterned version, then using Photoshop to manually create the unpatterned version and the texture masks.
So my questions are:
Is there a way to get Spine to export multiple textures where images with the same silhouette line up? Preferably with tight (polygonal) packing?
Texture masks don't need to be as detailed as the main texture. Is there a way to export from Spine so a 256x256 texture mask aligns with a 1024x1024 texture at runtime?
- Edited
sharizoid wrote1. Is there a way to get Spine to export multiple textures where images with the same silhouette line up? Preferably with tight (polygonal) packing?
One way to pack atlas pages separately is to pack by folder structure. You then organize your attachment images in folders (one folder for each separate atlas texture) and then use packing by Image folders
.
This posting here provides a quick overview about the different ways to export your atlas textures. The full documentation page about atlas texture packing can be found here:
Texture packing - Spine User Guide: Packing
In general we would suggest to use the Spine command line interface to export your skeleton and atlas assets, since this will allow you to re-export all your projects in one go after e.g. updating the Spine version from 4.0 to 4.1.
Note that you can specify -j
or --project
on the CLI when packing so it still uses meshes, and -p
or --pack
to specify the pack.json
file which contains the pack settings to be used. You can have a look at the Examples section here.
You could also use the command-line based solution described in this forum posting:
Nate wroteYou could write a script that exports your skeleton once, like normal, then swaps the images folder for the alternate (map) images folder, then exports again, then deletes the .json and .atlas file. The script could use a temp folder so it does both exports in a single run of Spine, to avoid the little bit of time for Spine to initialize.
sharizoid wroteTexture masks don't need to be as detailed as the main texture. Is there a way to export from Spine so a 256x256 texture mask aligns with a 1024x1024 texture at runtime?
The easiest solution would be to set the maximum Texture resolution (for each platform) in Unity in the Texture Inspector settings.
Thanks! Just to make sure I understand the process correctly, you'd setup multiple images folders, one containing one type of texture the other creating another. Corresponding images have the same names. In terms of texture packing the command line interface does the same as a pack.json file in each texture folder. The difference being that the command line lets you do multiple exports/imports at once.
So the script would be:
Spine -i <path to texture set A> [-j <path to project>]... -o <path to export folder> [-n <name>]
Spine -i <path to texture set B> [-j <path to project>]... -o <path to temp folder> [-n <name>]
if each subfolder in images has different pack.json settings, will leaving out -p path still read through each pack.json in those subfolders, or does running through command line restrict me to one pack.json?
The pack.json of each subfolder will be read without writing the path, but you can't pack texture atlases without -p
. So it would work if you replace the -n
with -p
in the example script you posted. The parameter for -p
is not only the path to the pack settings JSON file, but also can be set to the texture atlas name.
This is also explained in the user guide page that Harald pasted the link: Command line interface - Spine User Guide: Pack
I hope this will help.
Sadly, this did not work . The placement and rotated of the packed pieces is completely random, so the two textures do not align despite being the same size and using the same pack settings. Using Spine command line 4.0.55. Are there any other ways I can get them to align?
Spine's texture packer packs the same given the same inputs. If you have two sets of images that pack differently, the reasons are either your images are different (this is most likely) or the packer has a bug.
If you use Alias
it can change how images are packed if two images are the same in one set of images but not the other.
If you use whitespace stripping, that is OK, but you can temporarily disable it to see if it affects the difference between your sets of images.
Note you may not need the images to pack the same. At runtime Spine gets the regions from the atlas by name. Relying on the images to be in the exact same position so images can be swapped can work, but is not as flexible.
Ok I got it working. There's one texture that's still unaligned but I'm sure that's an images issue.
The problem is that I'm packing multiple texture sets (head, outfit, etc) and was pointing to the images folder instead of images/outfit, etc folder.
Solution that worked:
(for command line noobs)
In Windows Powershell navigate to C:\Program Files\Spine. If navigating down to program files from the C drive, cd "Program Files" avoids spacebar errors. Using Spine or Spine.com didn't work, needed to use ./Spine.com to run spine commands
./Spine.com -i <texture1 path to the directory the pack.json file is in(ex: localPath/images/outfit)> -j <project directory> -o <output path> -n <output file name> -p < texture1 pack.json file path>
./Spine.com -i <texture2 path to the directory the pack.json file is in(ex: localPath/images/outfit)> -j <project directory> -o <output path> -n <output file name> -p < texture2 pack.json file path>
...etc
My use case is that I'm actually creating 4 outfits from 2 textures input into a single material to save time & space, and using only 1 atlas file to store the multiple texture atlases. So I need to align the 2 outfits plus texture masks and atlas switching doesn't fit my use case.