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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Official 2D Sprite Shape 4.1.1 for Unity 2020.1

Discussion in '2D' started by rustum, May 18, 2020.

  1. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    2D Sprite Shape 4.1.1 is now available for the latest beta of Unity 2020.1.
    This versions includes Stretched Corners and Sprite Shape mesh baking functionality.

    Stretched Corners
    We’ve added Stretched corners as a new option for Corner’s in the Sprite Shape Controller.
    Stretched Corners.png
    This feature allows the Sprite Shape to form corners by stretching Sprites between adjacent edges between the corner point and its neighbours. To enable this option, select the Stretched option from the Corner dropdown menu, and ensure the following criteria are met:
    1. Both the selected and adjacent points have the same Height.
    2. Sprites rendered at the Corner point and its neighbouring points must have the same Sprite pivot position.
    Please note that scripting support for this new Corner mode will be available in a later release.

    SpriteShape mesh baking
    SpriteShape mesh baking allows storage of mesh data at editor time and the ability to reload it at runtime to avoid unnecessary runtime mesh generation.

    This is helpful in cases where:
    • You have a static SpriteShape that never gets modified in runtime.
    • You have a SpriteShape used with prefabs.
    • You want to avoid SpriteShape generation at runtime to save CPU cycles
    Some things to consider:
    • Since data is stored in a SpriteShape Component, scene size can increase if it contains a lot of SpriteShape objects with massive geometry.
    • SpriteShapes baked in such a way cannot be dynamically modified during Runtime.
     
    RemDust likes this.
  2. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,284
    Nice.
    Although 4.1.1 doesn't show up in 2019.3. I can still change the manifest manually and it does seem to work in 2019.3.

    Any reason why 4.1.1 is not available officially for 2019.3?
    Is this a bad idea enabling 4.1.1 in 2019.3?
     
    RemDust likes this.
  3. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    619
    Stretched Corners is only available in 4.1.1 and above (4.* versions are designed for 2020.1). However we have backported BakeMesh functionality to 3.* versions and it should be available soon (for 2019.3).

    Please note 4.* versions might work on 2019.3 but its not recommended to use them as there may be changes in the API or functionality.
     
  4. liamrobertson

    liamrobertson

    Joined:
    Oct 28, 2015
    Posts:
    7
    Can you explain more about the mesh baking? How do we use this?
     
  5. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    404
    Hey, the video about this feature on this page here is broken:
    https://unity.com/releases/2020-1/artist-tools

    Is there any way to do this with curved lines too? I just played a little with Sprite shape, but when using Continous lines, I dont seem to get the transitions between different sprites on different angles. Am I missing something?

    Cause it seems like a great way to build a 2D lake in a top down game line ours, but i want the edge facing side and down to have a different sprite and would love for it to transition nicely from the top sprite.

    Thanks for your awesome work!
     
  6. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    Is there some example how to bake Spriteshape mesh? I cant figure it out. There is a
    public JobHandle BakeMesh() method on spriteShapeController, but i dont see how i get refference to the generated mesh @rustum
     
  7. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    619
    Please take a look at this video for more info on Baking SpriteShape Geometry :
     
  8. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    Thank you for reply, I saw this video, but still It dont answer the question. How I can get the actual refference of the generated mesh. What I see is that the mesh is somehow stored in SpriteShape controller, but I cant get the actual mesh from it.There is not Spriteshape.mesh variable. Can you please add this featurem without is is somehow useless... Thank you
     
  9. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    619
    @URocks please take a look at :
    com.unity.2d.spriteshape\Runtime\SpriteShapeGeometryCache.cs
    which is part of the SpriteShape Package. This is where the mesh data (position/uv/traingles etc..) is stored when SpriteShape Cache Geometry is enabled.
     
  10. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    I checked it, but the class is internal so I cant access it from any script. But even if it would be accesible, I see positions, uvs but I cant see triangles, so I dont think I can recreate actual mesh from it... So how we can use it?
     
  11. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    619
    Please use SpriteShapeGeometryCache.cs mentioned above as reference to implementing custom mesh load/store.

    m_IndexArray stores the triangle data. Thanks.
     
  12. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    @Venkify Thank you for your help, I will try it.
     
  13. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    @Venkify I tryed your suggestion, but still I cant get the whole mesh. I only got One segment of spriteshape recreated. My problem is in the code you seggested inside SpriteShapeGeometryCache.cs. I dont know how to get this variable
    "NativeArray<UnityEngine.U2D.SpriteShapeSegment> m_GeomArrayCache".

    This one holds the segment count of the spriteshape and also counts of indexes. Can you please give me code snipped how to get this information. Thank you very much.
     
  14. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    @Venkify I found the solution I can get it with SpriteShapeRenderer.GetSegments(int dataSize).

    is there some way to get the dataSize number, so i dont neet to put some quessing number?

    Thanks a lot