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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

What's the math behind Tesselation Detail in the Sprite Editor and SpriteUtility.GenerateOutline()?

Discussion in '2D' started by ArConstructor, Jun 18, 2018.

  1. ArConstructor

    ArConstructor

    Joined:
    May 27, 2010
    Posts:
    24
    I have a texture and a 2D skinned mesh, from which I'm trying to generate a dilated texture and the correspondingly expanded mesh (keeping the source vertices/triangles intact, only adding a skirt or triangles around the original mesh perimeter).

    The undocumented and unexposed (as of Unity 2018.1) method
    Code (CSharp):
    1. UnityEditor.Sprites.SpriteUtility.GenerateOutline(Texture2D texture, Rect rect, float detail, byte alphaTolerance, bool holeDetection, out Vector2[][] paths)
    seems like exactly what I want, but I'm having a hard time figuring out what measure the detail parameter is supposed to represent (average edge length? simplification factor? fractal dimension..? :confused:).

    I need to generate the triangle skirt with roughly the same tesselation detail as the source mesh, but I have no idea how to estimate the necessary detail value from the mesh. Any suggestions..?

    (This is going to be a part of an art pipeline, so asking artists to write down these numbers isn't really an option.)
     
  2. ArConstructor

    ArConstructor

    Joined:
    May 27, 2010
    Posts:
    24
    In the end, I decided to just treat it as a black box optimization problem and successively approximate the necessary level of detail (average edge length, in my case) with a primitive binary search.
    Still, knowing the math/logic behind GenerateOutline() would be pretty welcome :D