Search Unity

Detecting / optimizing a Mesh that overlaps with itself

Discussion in 'Scripting' started by spajus, Sep 9, 2019.

  1. spajus

    spajus

    Joined:
    Jun 10, 2015
    Posts:
    47


    Hey, is there an optimal way to detect that Mesh intersects with itself (without just iterating through all it's triangles and checking if they intersect). Also, how would you optimize this mesh to fix the overlap? In my case it's always a chain of triangles, like in the picture (it's a procedurally generated race track).
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Do you really need to fix this? I imagine it causes a problem with texturing, but the same problem would exist if we fixed the overlap. To my knowledge there is no very efficient solution for this problem. It may be possible to efficiently check for "vertex density", by utilizing a quadtree or something along those lines, to figure out if such an overlap exists and then optimise based on that information, but i dont think it's worth it.

    I'd say the best way to fix the overlap, is to prevent it from happening in the first place. It should be comparably easy to alter the way you generate the racetracks in a way so that this can not happen, and it would fix all potential problems without any additional calculations required. Is that an option for you? If so, how do you generate your tracks?
     
  3. spajus

    spajus

    Joined:
    Jun 10, 2015
    Posts:
    47
    This is what I actually ended up doing.
     
  4. spajus

    spajus

    Joined:
    Jun 10, 2015
    Posts:
    47
    Tracks are generated by expanding a bezier curve. I am now checking angles between curve points, preventing sharp ones, and it works.