Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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

Discussion in '2020.1 Beta' started by Deleted User, Dec 30, 2019.

  1. Deleted User

    Deleted User

    Guest

    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
     
    richardkettlewell likes this.
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    992
    This is accessible through the Sprite itself, rather than the SpriteSkin. You can retrieve the Sprite from the SpriteRenderer the SpriteSkin is using.

    Code (CSharp):
    1.  
    2. using UnityEngine.U2D;
    3.  
    4. Sprite sprite = spriteSkin.gameObject.GetComponent<SpriteRenderer>().sprite;
    5. sprite.SetBones(/*SpriteBone[]*/ bones);
    6. sprite.SetBindPoses(/*NativeArray<Matrix4x4>*/ bindPoses);
    7. sprite.SetVertexAttribute<Vector3>(VertexAttribute.Position, positions);
    8. sprite.SetVertexAttribute<BoneWeight>(VertexAttribute.BlendWeight, weights);
    9. sprite.SetVertexAttribute<Color32>(VertexAttribute.Color, colors);
    10.  
    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).
     
    Deleted User likes this.
  3. Deleted User

    Deleted User

    Guest

    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
     
  4. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    158
    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
     
  5. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    401
    What is your use case to be able to access the buffer?
     
  6. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    158
    @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
     
  7. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    158
    @Leo-Yaik Do you think we can get access to deformed verticles or maybe some 2d deformation collider? Thank you
     
  8. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    401
    Thanks for the feedback! We will look into how we can expose the deformed vertices.
     
    Deleted User and URocks like this.
  9. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    158
    That would be awesome, thank you
     
  10. Deleted User

    Deleted User

    Guest

    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
     
    DragonCoder and Leo-Yaik like this.
  11. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    158

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

    Thank you
     
  12. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    158
    @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
     
  13. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    401
    We are working on it for the up coming release.
     
    LeonhardP and URocks like this.
  14. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    130
    Any news on this? We're trying to create an outline mesh for a sprite skin and need access to the deformed vertices.
     
  15. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    401
  16. sterneck_moritz

    sterneck_moritz

    Joined:
    Mar 23, 2020
    Posts:
    8
    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). AutoGeo.PNG
     
    Xeavicous likes this.
  17. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    401
    Thanks for the feedback! We will look into this!
     
    sterneck_moritz likes this.
  18. Selemor

    Selemor

    Joined:
    Nov 11, 2018
    Posts:
    3
    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?
     
    Xeavicous likes this.
  19. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    401
    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.
     
    sterneck_moritz likes this.
  20. Cyprotic

    Cyprotic

    Joined:
    Mar 12, 2016
    Posts:
    2
    Is there any updates on the last topic? About the auto geometry feature script access?
     
    Xeavicous and DragonCoder like this.