Search Unity

Determine Triangles making up Mesh "face"

Discussion in 'Getting Started' started by snizkorod, Oct 29, 2015.

  1. snizkorod

    snizkorod

    Joined:
    Sep 24, 2015
    Posts:
    5
    I'm using an imported mesh for tile generation. Each "Tile" is nothing more than the manually positioned faces of the mesh (they are not all the same size, orientation etc.) but the triangulation of the mesh makes me lose track of the faces so i am recreating them via script. I'm unable to determine which triangles belong to which Face. I have tried to get a good algorithm going for a week now but cannot figure out how to procedurally determine where the original faces are...

    Here is my pseudo code:

    1. Get mesh triangles/ verts.
    2. get all edges that share vertices.
    3. grab a corner vertex
    4. get the first tile.
    5. For each tile edge (recursive call) complete the tile from the edge by
    - find the triangle the edge belongs to (easy, given triangles come in triplets)
    - find the opposing triangle ( STUCK HERE ) such that the pair completes the original face
    - repeat step 5 until no tiles left to create.

    Because im reliant on recursion and not position information to handle any bizarre face shape, i have no good way of knowing what the two triangles are that make up the face. I cannot make the distinction between 1 nearby triangle vs another other than that it shares edges with my current one.

    Is there any way to "mark" a mesh prior to import so that the original "mesh grid" has a distinction from the ones unity puts in when it triangulates the mesh? Is there a better approach to create hand-shaped tiles other than creating a bunch of objects (this is a need)
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I hate to see threads go without any responses, and I'm afraid of that happening here.

    Sorry to say I don't have the first clue how to help you with this. It's a pretty advanced topic, though, so you may have more luck in the Scripting section, where the big code kids hang out, rather than the Kiddie Pool here. :)

    Good luck! Whether you figure it out yourself or find assistance, I'd appreciate you posting back with your solution, even if it's pseudo code!
     
  3. snizkorod

    snizkorod

    Joined:
    Sep 24, 2015
    Posts:
    5
    Thank you very much for the reply. I manually went through and did a check to see if i could uniquely come up with an edge tile check and can see that there is no single condition where the face triangle wins out over the adjacent triangles.

    Instead i decided to just triangulate the mesh myself instead of letting unity do it - this way i know the orientation of each triangle from the get go. It's more upfront work but i cant see another way around my chosen workflow. Ill upload the code if i refine it enough for public use.
     
    Schneider21 likes this.
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    As this is the getting started thread, you may find one of the specific topics a better place. Maybe graphics??