MichelVictor

Hey there, I am creating a game with lots of skins so I want to use the Runtime Repacking to create new textures on the load screen. The thing is, I have a difuse atlas and a normalmap atlas, how can I repack both atlas and put it on the right place on a new material as explained in the end of this document:
spine-unity Mix and Match: Runtime Skins
MichelVictor
  • Сообщения: 52

badlogic

Out of the box, the spine-unity doesn't provide a way to also repack a normal map. The reason is that the extension method GetRepackedSkin() fetches the textures (and UVs into those textures) from the attachments in the skin. See spine-runtimes/AtlasUtilities.cs at 842dffbd8379b17e4d8a14d9fcac2bd6130b914c

Since we can't anticipate how you are applying normal maps on top of the default diffuse textures, we don't provide an out-of-the-box solution. How do you use your normal map atlas in combination with your diffuse atlas? Assuming the UVs into both atlases are the same, you could use the packing result from the packed diffuse atlas and pack your normal map atlas manually using those new UVs.
Аватара пользователя
badlogic

Mario
  • Сообщения: 2013

MichelVictor

Yes, in fact the normalmap will be exactly the same places as the diffuse map, I just need to know how to create this new atlas for the normalmap manually.
MichelVictor
  • Сообщения: 52

badlogic

You would have to modify the GetRepackedSkin() method, which is quite involved. spine-runtimes/AtlasUtilities.cs at 842dffbd8379b17e4d8a14d9fcac2bd6130b914c

Step 1. The method takes all the attachments from a skin and adds them and their textures to a handful of scratch arrays (texturesToPack, etc.). The attachments are also added to a new skin. All of this happens in lines 321 to 363.

Step 2. Once everything is collected, we generate a new texture and pack the collected texture regions from the attachments into it (lines 363 to 367). The result is a list of new UV coordinates for the repacked attachments stored in rects.

Step 3. These rects are converted to AtlasRegions (lines 381 to 386). An AtlasRegion describes on what texture and where on that texture an attachment is.

Step 4. The AtlasRegions are then set on the repacked attachments (lines 389-393), which makes the attachments point to the repacked texture.

You have 2 atlases, one for diffuse and one for normals. If you pass each to that method, they packing will not be the same, so the UVs don't line up. To make that work, you'd have to modify the method to take both atlases, perform steps 1 and 2 for the diffuse atlas, and then use the rects from step 2 to manually copy the texture parts of the normal map atlas to a new repackged normap map texture. Finally, you'd have to do steps 3 and 4 for the normal map atlas as well.
Аватара пользователя
badlogic

Mario
  • Сообщения: 2013


Вернуться в Unity