Maltakreuz

I am making customasable player for rpg. So armors, races, weapons, haircuts etc. All is stored in one large rig with skins and optional attachments. I am not sure when exactly it became so slow, but now it takes ~25 minutes to pack all the stuff. Is it really intended so? I have updated Spine from pretty old version to last (3.8.84) recently and atlas packing seems to be much slower then before (but i am not sure). Braking workflow for that long becames really annoying.

1) Is it normal, that it takes so much time? 7 atlases 2048x2048 ( My PC is i5-4690k, 16RAM, GTX960 if it somehow matters)
2) Any workaround? Of course i am using Fast-checkbox, here are my atlas packing settings:



P.S. Just in case, so a typical atlas page looks like now:


3) Just curious: Why could it be THAT slow? Task of placing 700 rotated rects tightly packed of course requires some CPU time, but 25 minutes...?

4) Is any max limit on atlasses? I am exporting as JSON into Unity. And everytime i am a little bit afraid after adding few more sprites the whole rig will not work anymore.

5) Is Spine a java-programm? Maybe it just needs more RAM with -xmx12gb or like this?
アバター
Maltakreuz
  • 記事: 41

Nate

RAM is unlikely to be a problem, especially if you check Limit memory. When checked it reads the image files twice, but avoids having them all in memory at once. If Spine is not crashing from out of memory errors, there's no problem with memory.

Your screenshot shows Packing: Polygons, which can be intense for your CPU. I've not seen it take 25 minutes, which I agree is excessive, but polygon packing is a hard problem. It makes use of all available CPU cores, but it still has a lot of work to do. It is a relatively new feature and we plan to improve it in the future, but for now if you are not packing images used by meshes or don't need to save the extra space that polygon packing can save, then I suggest changing to Packing: Rectangles. Using that you probably don't need Fast checked and unchecking it may pack more tightly.

There's no max limit on atlases except for how much GPU memory is available. For that you'll have to decide what devices you are targeting, where mobile devices are more limited. If needed you may be able to load only the images you need for a given level, or however it makes sense to load/unload images for your app.
アバター
Nate

Nate
  • 記事: 9642

Maltakreuz

Nate さんが書きました:...I suggest changing to Packing: Rectangles....
But then it will be probably not 8 atlases, but 28 or like that? I am not targeting mobile devices, but i am not sure Unity and Spine Runtime will work correctly with such amount of sprites in RAM.

But it is also not some bug or bad configuration, or unlucky input data. It is also really avarage packing time for 700 sprites? Well if so, at least it is not some art of bug.

Upd: ah, sorry. You are right, it is not rect-position problem, but polygon positioning problem that is probably much complexer. (i am assuming some sort of controlled-brutforce which search for best alligment available is used here)
アバター
Maltakreuz
  • 記事: 41

Nate

Polygon packing only gives tighter packing for images used by meshes. From your screenshot it looks like nearly all your images are rectangular. Give it a try, it should complete in maybe ~10 seconds and then you'll know. :)

It's not impossible for it to be a bug that polygon packing takes so long, but since it does complete eventually my first guess is that Spine simply puts too much effort into placing the polygons in the most efficient way it can find. Packing is a very hard problem because Spine can't try every possible solution. If it tried, you may be waiting until the heat death of the universe because the possible configurations grow unbelievably fast. :nerd: Other programs like Texture Packer Pro (which is compatible with Spine BTW, though not free) can pack polygons in little time, mostly by not trying to find such an optimal solution. However, the solution they do find is usually reasonable enough, so that is probably the path Spine should take.
アバター
Nate

Nate
  • 記事: 9642

Maltakreuz

Nate さんが書きました:Polygon packing only gives tighter packing for images used by meshes
Ah... thats how it works. At least i am not wondering why so much free space in axe-sprite is just wasted. Well i will try it then.

upd: It looks like a solution to me. Now it is 9 atlases instead of 8. Well i hope this will not break unity/spine_runtime. Unity creates a separate material for each texture atlas and i am not sure about consequences having many materials in render of player. But assuming nothing good. I mixed up Rectangle packing and Grid packing. It is not 28 atlases also, only 9 (+1 to polygons). So it is defenitiv a solution for me now. At least in development i can just use Rectangle packing. Thank you.
アバター
Maltakreuz
  • 記事: 41

Nate

Having many images is bad because 1) it takes up memory, and 2) it increases draw calls. Even having just 2 images can increase draw calls:
In most graphics APIs (eg, OpenGL), a texture is bound, some drawing is done, another texture is bound, more drawing is done, etc. Binding the texture is relatively expensive, so it is ideal to store many smaller images on a larger image, bind the larger texture once, then draw portions of it many times.
The (somewhat simplified) reason to avoid draw calls is that when you want to draw from a different texture, the app needs to wait for the GPU to finish rendering the previous texture. Some number of draw calls is OK (depends on the hardware, but maybe 60-100 for weak devices) but at some point the app may be waiting for the GPU so much that there's not enough time to finish a frame to keep the target frame rate (eg 60fps). There is a little more description here:
Metrics - Spine User Guide: Draw calls

When you render a skeleton, the worst case is every attachment comes from a different texture atlas page, so you have a draw call per attachment. You can use folders to control which images go together on an atlas page to try to reduce draw calls:
Texture Packing - Spine User Guide: Folder structure
アバター
Nate

Nate
  • 記事: 9642

Maltakreuz

Nate さんが書きました:Having many images is bad because...
Yes, it is nothing good probably. But there is not much i can do. The reason for 9 pages is typical RPG armor/weapons system, where each item type has a power progression from weak to strong.
Nate さんが書きました:You can use folders to control which images go together on an atlas page to try to reduce draw calls:
Probably player wears good stuff at the end of game and cheap stuff at the beginning, so grouping folders from weak to strong should work better then just grouping items just by type.

But i am not targeting mobile devices so i hope ~150 batches and 7k tris is still acepptable for main character on typical PC today (this is difference by switching player on/off).

アバター
Maltakreuz
  • 記事: 41


Return to Editor