• Runtimes
  • Update skeleton texture dynamically

Hi. I'm using Spine Phaser runtime. I need to be able to draw on skeletons with a mouse. Can I change textures dynamically at runtime? So the drawing on skeleton will persist and deform correctly.

I was thinking about rendering to texture like in this example. And later assigning new texture to skeleton. But it seems like I need to render every slot image of the skeleton and overwrite texture in position of that slot on a texture. Feels complicated to me.

Is this right approach? Can you provide me with some examples of changing textures?

Related Discussions
...

This seems like mainly a Phaser question. Can you write an app without Spine that shows a simple, rectangular texture and allows you to draw on it? If so, then you can probably do the same to draw on the atlas textures that the spine-phaser runtime draws from. The hard part is probably deciding where on the atlas textures to do the drawing.

As you mentioned, you could render the whole skeleton to a texture, then draw on that, but that's drawing on a static image. It's not the same as drawing on the textures that the skeleton is using, as the skeleton could continue to animate. You can't render the whole skeleton and then somehow update the atlas textures from that. You'd lose information where the textures overlap.

  • tasco ответили на это сообщение.
    • Изменено

    Nate
    Thanks Nate! Yeah, sadly now I think it's very complicated task. For example when mesh deforms how can I render deformed image back to texture. Seems like everything must have original form and size in atlas. The solutions maybe in complex calculations with UVs and vertices positions..

    It is reasonably complex, but doable. To map a point on a deformed mesh texture to the same point on the undeformed texture, you'd use barycentric coordinates. You can find my functions for that here:
    libgdx/libgdxblob/master/gdx/src/com/badlogic/gdx/math/GeometryUtils.java#L27-L78

    First figure out which triangle the point is on. For each of that triangle's vertices, you have the positions and the U,V values. Plug that into the functions and you get the U,V values of the point on the undeformed texture. 🪄