bon

Hi,

I have a big spine file with a character where I want to split up the atlas per LOD (close/mid/far) to optimize Unity imports so that there aren't 4+ atlas pngs in the binary export.

For instance, I'd like to select "export" in all the "close up" animations, and export only those images pieces used in the animation into the atlas, i.e. no legs. Is there a way to selectively export?

Or is there an API where I can modify the Spine file with code before calling the export?


Thanks,
Bonnie
bon
  • Сообщения: 6

Nate

You can pack the atlas separately from exporting JSON/binary:
Texture Packing - Spine User Guide: Packing

It would be easiest to organize your images in folders based on how you want them packed. If you really want to pack based on the data, then you can use the Spine Runtimes to load the data (api), inspect the animations you care about, see what attachments they use, and collect the image files you need to pack for those. To do the packing you could copy the images files to a temp folder and run Spine's texture packer.
Аватара пользователя
Nate

Nate
  • Сообщения: 10740

bon

Hi Nate!

In our example, when the "close up" is used in the game, we want to load the atlas without legs but include "R_arm". When the "far away" is used in the game, we want to load the atlas with legs, and also the same "R_arm".

So if we use folders, we'd have have a copy of the "R_arm" in both folders, but if we change "R_arm", we'd have to make sure it's updated in multiple places, and we'd also have to do some bookkeeping on the folders by hand, correct?

For the Spine Runtimes API solution, how would we do that? Would we:
1. export the skeletons normally
2. write a script with API to isolate the animation we want, collect the image files from the attachments into folders
3. re-pack the images based on folders

Would the exported skeleton data still work with the repacked atlas from step 1?
bon
  • Сообщения: 6

Nate

bon писал(а):So if we use folders, we'd have have a copy of the "R_arm" in both folders, but if we change "R_arm", we'd have to make sure it's updated in multiple places, and we'd also have to do some bookkeeping on the folders by hand, correct?
Correct.
bon писал(а):For the Spine Runtimes API solution, how would we do that?
Just as you described. :)
bon писал(а):Would the exported skeleton data still work with the repacked atlas from step 1?
Yes. In the data each attachment has a name and a path. Images are usually (it can be customized) found by using the path to find the matching named texture atlas region. If there is no path, use the attachment name. When you pack an atlas to have only a subset of images, the texture atlas region names are the same.
Аватара пользователя
Nate

Nate
  • Сообщения: 10740

bon

Cool, i'll give it a shot. Thanks Nate!

---

Hi Nate!

So I exported my character, then organized my image folders. I now have a folder that only contains everything but one article of clothing.

Then I repacked that particular folder to a new *png and *.atlas.txt that I then imported into Unity. I reattached the updated atlas file and now it's saying that the atlas is "missing regions", which is true, I took away the article of clothing. The skeleton is broken.

How can I fix this?


Thanks!
bon
  • Сообщения: 6

Nate

If I understand, you now have 2 atlases: one with everything and one with just one article of clothing. AtlasAttachmentLoader only loads one atlas. You'll need to implement your own AttachmentLoader to provide attachments atlas regions from multiple atlases. Please see here:
Loading Skeleton Data - Spine Runtimes Guide: JSON and binary data
Also take a look at the AtlasAttachmentLoader source file (for Unity it is in spine-csharp). It is very simple.
Аватара пользователя
Nate

Nate
  • Сообщения: 10740

bon

Ideally, it'd look like this:

1 skeleton, but 2 atlas:
  • atlas with images for character from the waist up and no coat
  • atlas with images for the character far away with a coat

Based on the lod, i want to load one or the other, but have the skeleton data work with either. This way our animator could in theory animate the character waving, but we can have that character close up or not, as well as with or without a coat without the imported png be low res or spawn lots of files.
bon
  • Сообщения: 6

Nick

Spine-1_YUuVu5P9rA.png


@bon
You can use two Skins for two exports but sharing the same skeleton.
Just uncheck "export" from other skins before exporting. That will only pack the sprites needed.

@Nate
Its an old discussion but I recently re-exporting many of my old projects and I realize I really want a way for command line to be able to override this check box, instead of doing lots of works to have the texture packed correctly for only certain skin. It was not a big issue until I got more and more multi-skin project which also require selective skin export.

http://esotericsoftware.com/forum/Spine-3-8-Export-attachments-atlas-maintaining-image-folders-13051

Remember 10 months ago I feature request the -skin command but end up doing something like modifying AtlasAttachmentLoader? While this workaround works, it is not really that recommended. It require modification to the runtime codes and I need to re-apply it everytime the runtime get updated. The workflow is also based on more complex texture packing verses a normal export script with an additional -skin. The code change I did could also prevent a true warning that a Region is really not found. The effort to do selective exporting on command line is a little too much. Thus I am here asking again if the -skin can be added to solve this issue once and for all.
У вас нет необходимых прав для просмотра вложений в этом сообщении.
Nick
  • Сообщения: 242

Nate

@bon, when the skeleton data is loaded, the AttachmentLoader has a chance to configure the attachments with atlas regions. This is optional, it can configure all, some, or none. However, by the time rendering occurs the attachments the will be rendered must have a region (see SkeletonRenderer). If they won't be rendered, they don't need a region.

You could write an AttachmentLoader that does not set any regions. Then, you could write code that takes your skeleton, goes through all the attachments, and sets the regions from either the close up atlas or the far away atlas. When you render, you can set the attachment visibility (for each slot or using skins) so only the close up or far away (or all) attachments are visible.

Or, you could load the skeleton data with the close up atlas or the far away atlas. This requires loading the skeleton twice, but that may be fine depending on your needs. AtlasAttachmentLoader gives an error when a region can't be found, so you'll need to customize it to not set a region if no region was found in the atlas.
Nick писал(а):Remember 10 months ago I feature request the -skin command
@Nick yes, though it was 7 months ago. ;) The post you linked is hard to follow and I'm not sure it's the most relevant thread. The thread where you mentioned a -skin parameter is here:
I tried to export with command line but not file is created.

@bon, note there is also AttachmentLoader explanation in that thread (from this post to the end):
I tried to export with command line but not file is created.: p62815
Nick писал(а):It require modification to the runtime codes and I need to re-apply it everytime the runtime get updated.
@Nick, you do not need to modify the runtimes, customizing the AttachmentLoader is part of the API. You can implement your own AttachmentLoader in your own codebase. That is much better than modifying AtlasAttachmentLoader in the runtimes. You can copy AtlasAttachmentLoader into your own code and modify it to your needs. For example, to remove making it an error when an atlas region is not found. It will still be an error if you try to render an attachment that doesn't have an atlas region.

@Nick I've added clarification here and also explained more about how I think your setup is best accomplished. @bon you may also find that useful.

Note the skeleton data is always going to contain everything. Exporting data, images, or video is what we call "export". The use case discussed here is really about 1) how to pack images into multiple atlases and 2) how to find those regions at runtime using AttachmentLoader. I wouldn't call that partial or selective export, or even export at all. Instead, we call that texture packing.
Аватара пользователя
Nate

Nate
  • Сообщения: 10740


Вернуться в Editor