Adding access to (bone/geometry/weight) data from sprites

Quick Rundown: I am doing color-swapping, aka palette-swapping, on 2d-items within my project. However, I am also using the skeletal-system (sprite skin). These two ambitions collide, because when I replace the sprite, there is no way to access or set the bone-data for the new sprite, rendering the model useless

Access to the data within sprite-skin (i.e. bones/geometry/weights) and being able to interact with them THROUGH SCRIPT would go a very very very long way for workflow

Thank you for the consideration

1 Like

This is accessible through the Sprite itself, rather than the SpriteSkin. You can retrieve the Sprite from the SpriteRenderer the SpriteSkin is using.

using UnityEngine.U2D;

Sprite sprite = spriteSkin.gameObject.GetComponent<SpriteRenderer>().sprite;
sprite.SetBones(/*SpriteBone[]*/ bones);
sprite.SetBindPoses(/*NativeArray<Matrix4x4>*/ bindPoses);
sprite.SetVertexAttribute<Vector3>(VertexAttribute.Position, positions);
sprite.SetVertexAttribute<BoneWeight>(VertexAttribute.BlendWeight, weights);
sprite.SetVertexAttribute<Color32>(VertexAttribute.Color, colors);

This could be done in Runtime if you are dynamically creating your Sprite. In Editor, you will need to handle it through the PostProcessing of assets to persist it from your imported Texture (the same as how the Skinning Module in the Sprite Editor does it).

1 Like

Thank you for the quick response. I had no idea this API existed and it is very useful to have access. This saved me a bunch of worktime. I’ll mess around with it and see what I can do. Thanks again

Hi @ChuanXin is it possible to get deformed vertices from SpriteSkin or Sprite class. Because SpriteSkin class is an internal class and deformedVertices variable is only private so I don’t see any way to get deformed verticles.

Thanks a lot for the help

What is your use case to be able to access the buffer?

@Leo-Yaik I need to make 2D collider for deforming mesh, something like 2D soft body, and I know Uni2D was supporting it back then, but now there is no option to access deformed mesh so I even cant create my own 2d collider from a deformed mesh. And I know it will not be super fast, but still there should be the option.

Here you can see how it was working in Uni2d

@Leo-Yaik Do you think we can get access to deformed verticles or maybe some 2d deformation collider? Thank you

Thanks for the feedback! We will look into how we can expose the deformed vertices.

2 Likes

That would be awesome, thank you

If possible, can you also find a way to expose the “set” attribute for textures of the Sprite component?

We already have Sprite.texture {get;}, and I understand some complications can occur with texture-size. But if you make it a function and require that the new texture be the same size as the old, it will function the same way as Graphics.CopyTexture()

This will uncomplicate the process of color-swapping with textures and the sprite-texture process as a whole. Also, and really the most important part, it will make it faster (so much faster)

Thank you in advance for the consideration

2 Likes

@Leo-Yaik How it looks with the access to deformed verticles from SpriteSkin, do you have any estimated time?

Thank you

@Leo-Yaik I am sorry I am still asking about it, but for us is a very important feature and the only way to solve our problems is to expose the deformed verticles from spriteskin. Is there a big problem to do it? Thank you

We are working on it for the up coming release.

2 Likes

Any news on this? We’re trying to create an outline mesh for a sprite skin and need access to the deformed vertices.

yes, we already added this in 3.2.x and 4.2.x

https://docs.unity3d.com/Packages/com.unity.2d.animation@4.2/api/UnityEngine.U2D.Animation.SpriteSkin.html

Somehow related to this topic here. I love the “Auto Geometry” feature of the Skinning Editor as the geo it produces seems way better in terms of verts as the default generated geo. But it does get tedious if I would have to to this to every Sprite in the project manually.

So I would like to automate this step by creating an Editor Script that iterates over a given set of textures and applies the “Auto Geometry” to every Sprite. Sadly I could not find access to that functionality in any API.

Is this hidden in the API or did simply not find it… ?

Here’s a screenshot of the feature I’m talking about (With already applied Auto Geo).

1 Like

Thanks for the feedback! We will look into this!

2 Likes

Scripted access to the “Auto Geometry” feature would be super helpful on our project too. Any updates on whether this is likely in an upcoming release?

2 Likes

We are planning and working on some prototupe to improve the current Sprite tessellation. The work will probably include unifying the different tessellators we have.

We don’t have a definate timeline for this at the moment, we will share more once we have something more concrete.

2 Likes

Is there any updates on the last topic? About the auto geometry feature script access?

2 Likes