Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Smoothing out edges of procedural mesh.

Discussion in 'Scripting' started by bfantonio1, Sep 2, 2020.

  1. bfantonio1

    bfantonio1

    Joined:
    Jul 16, 2020
    Posts:
    1
    Hello, I've made a script that generates a mesh with the data it receives from a 3d camera, but the edges look very bad (as in the image below)

    https://imgur.com/a/9V58hE6
    chunkyedges.png

    All mesh smoothing solutions I've found just help smooth out the surface of the mesh or make it more detailed, and not reduce the ´chunky´ edges, any clue how i could achieve this? Or if there's already code or an inbuilt Unity feature to deal with it.

    Thanks.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    This question is going to be fundamentally impossible to answer without seeing the code/algorithm used to generate the mesh. You'll probably need to add triangles connecting corner pieces, at least.
     
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,606
    What kind of data does the camera give you? How do you convert it into a mesh?
    Just based on this mesh it would seem pretty hard to "smooth out the edges", as this simple concept is hard to define for a computer, and also implies some assumption on how the shape should look like for any given edge.
    Given the source data you should be able to generate a somewhat smooth'ish mesh from it using algorithms like marching cubes (with interpolation) or similar approaches.
     
  4. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    quick idea though:

    - detect edge at the limit of the mesh
    - walk the edge and smooth by doing a low pass filter (basically keep in a circular buffer the last x vertices (the range is the smoothing frequency), compare the first and last vertices of the buffer, compute deviation of intermediate vertices to that line, using some threshold logic, either move them or link/ destroy vertices in harsh transition or high deviation)

    Something like that roughly, the details is up to you.