Hello.
We received an unusual task, to reuse the spine atlas, taking an element from the atlas and manipulating it, allowing it to change the texture.

There were 2 problems
1 - if you click in the Spine Atlas Asset "Apply Region Ac Texture Sprite Slised", then the atlas will not be divided correctly inside.
2 - On stage you need to assemble it all manually. Is it possible to somehow reuse Json running with animation for automatic assembly on stage?

    Related Discussions
    ...

    TheZero Since you seem to be going down a rather difficult path, I would like to confirm your reasons for doing this. Is it not possible to achieve what you (or your customer) want to do by repacking the textures after attaching sprites that are not included in the texture atlas, as demonstrated in Spine Examples/Other Examples/Mix and Match Equip?

    Or, since you mentioned "taking an element from the atlas and manipulating it", if you need to change the material of a specific slot, you can use SkeletonRenderer.CustomSlotMaterials as described in the Changing Materials Per Instance section in the documentation. Would this not help for what you want to do?

    It's quite a difficult task.
    Essentially, you need to do a drawing - a coloring book. The result of which will be transferred to the spine animation.

    I wrote several possible working options.
    But for the most universal thing, you need to break the Spine atlas into sprites and use them.

    Collecting them yourself is difficult and costly. Therefore, I would like to understand if I can use the Json that comes with the animation to parse its parameters, and put the sprites on the stage independently.

      Nate Sorry for my English.
      No, that's not quite it. I probably shouldn't have mentioned drawing because it would confuse things =)

      In general, I need to assemble a complete picture from the atlas (which is used in Spine).

      As I understand it, when importing into a project, your atlas is divided into sectors, and internally it is processed by arranging these sectors in the desired position and rotation.

      I need to do the same thing, only as sprites on the stage.

      Is it possible to use a Json file with animation for these purposes? If it’s easy, I’d like to find an implementation of how your bones are arranged - sprite inside SkeletonData

      TheZero

      Essentially, you need to do a drawing - a coloring book. The result of which will be transferred to the spine animation.

      From this term, it seems that the method as done in Spine Examples/Other Examples/Mix and Match Equip is still effective. Have you actually checked this example scene? Or if you have only seen the scene, examine EquipsVisualsComponentExample.cs.
      This scene doesn't involve extracting a sprite from the atlas, but I think the following thread may be helpful for that:
      https://esotericsoftware.com/forum/d/11568-extract-sprite-from-spine/5

      Sorry if I seem to doubt what you are saying and I am offended, but I think it is hard to maintain if you do things in too special a way, and it is hard for us to advise against it if any problems arise in the future.

      Thanks for the answers, I'll come back to the topic later.
      If you're wondering what exactly I do.

      Due to restrictions, I can't show you exactly what I need.

      Soon I will try to put together a demo example, so that you can understand more clearly what exactly I need.

      As for the coloring, I wanted to be specific, but I confused you, sorry =)

      Essentially, all I need is to arrange the atlas elements as SpriteRenderer , along the coordinates of which they would repeat the default animation pose.

      Isn't this what the Spine skeleton is already doing? Are you saying you want the images of a skeleton where each image is a GameObject rather than an attachment in the skeleton?

      Yes exactly

      To be more precise.
      I need to write a script that would create a GameObject with a SpriteRenderer element and put it in 1 of the images, and then set it all to a standard pose

      10 gün sonra

      @TheZero Sorry for the late reply. It's rather difficult to help based on the provided information, but hopefully it will provide some helpful input.

      TheZero 1 - if you click in the Spine Atlas Asset "Apply Region Ac Texture Sprite Slised", then the atlas will not be divided correctly inside.

      Thanks for reporting and sorry for the troubles! This is indeed a bug which seems to have remained unnoticed for quite some time! I've opened an issue ticket here for you to subscribe:
      EsotericSoftware/spine-runtimes2443
      We will post here on the forum once this issue has been fixed.

      TheZero 2 - On stage you need to assemble it all manually. Is it possible to somehow reuse Json running with animation for automatic assembly on stage?

      I'm not sure what you mean by "on stage". Do you mean at runtime in your game (as opposed to inside the Unity editor before building the game)?

      Essentially, all I need is to arrange the atlas elements as SpriteRenderer , along the coordinates of which they would repeat the default animation pose.

      I'm not sure that helps, but mentioning just in case: There is a skeleton baking functionality which builds a GameObject hierarchy of renderers:
      https://esotericsoftware.com/spine-unity#Skeleton-Baking
      However, these are not using SpriteRenderers.

      A different approach could be to assemble the skeleton atlas from the attachment images inside Unity, instead of in the Spine Editor:
      https://esotericsoftware.com/spine-unity#Advanced---Using-Unity-SpriteAtlas-as-Atlas-Provider
      While it's not recommended if it can be avoided, perhaps it helps with your use case.

        Harald
        Hello Harald,

        1. Regarding the bug with the incorrect distribution of atlas zones, the problem is that if you check the box in the Spine inspector, rotate in the atlas packaging settings. Then the generated atlas.json.txt will contain a rotate position, which actually affects the incorrect distribution of elements.
        2. I checked Skeleton Baking, it's almost what I need. I'll look at your code, maybe I can figure out how to translate this into the format I need. If it’s not difficult and you can tell me where exactly to look, it would be cool. (I need the code where you convert positions in order to create Gameobject blanks and assign a Sprite Renderer to them through the editor)

        Sorry for my English.

          TheZero If it’s not difficult and you can tell me where exactly to look, it would be cool. (I need the code where you convert positions in order to create Gameobject blanks and assign a Sprite Renderer to them through the editor)

          I'm afraid I don't know the code too well either, as it has been written a very long time ago (and not by me). It should be the BakeToPrefab() method that you're interested in, which can be found here:
          EsotericSoftware/spine-runtimesblob/4.1/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs#L185
          It basically stores everything in a prefab asset. The basic setup of attachments is mapped to MeshRenderers here and/or here if I'm not mistaken.

          Animations are baked by sampling each animation at discrete time-increments (float BakeIncrement here) and applies the animation to the skeleton (see here), then stores this skeleton pose (resulting in e.g. 60 rotation and position keys per second for each bone).

          There are no explicitly set GameObject positions, but instead animation curves are filled with keys that change the Transform position and rotation values, like here. Basically it's just the normal bone.X, bone.Y and bone.Rotation values (local transform values) that are read after the animation timelines have been applied to the skeleton.

          Basically you should be able to do something similar, applying the desired frame of an animation to the skeleton and then read all local bone transform values. This should already allow you to build the GameObject Transform hierarchy accordingly.

          Sorry for my English.

          No need to apologize.

            Harald
            Thanks for the answer, now I have an idea where to go.

            6 gün sonra

            @TheZero Regarding this issue regarding slicing the atlas texture resulting in wrong regions:
            Unfortunately Unity's Sprite slices do not support rotation (not even 90 degree rotation).
            If you must use Unity's Sprites via Apply region as texture sprite slices, please be sure to pack the skeleton atlas textures with Pack Settings Rotation disabled.