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. Dismiss Notice

Mesh generation: One mesh is visible only in 1 view

Discussion in 'Editor & General Support' started by einstyle, Apr 21, 2020.

  1. einstyle

    einstyle

    Joined:
    May 19, 2017
    Posts:
    8
    Hi,
    I generated 3 meshes, but one of the 3 is not visible (triangle 0 1 3).

    EDITED:
    OK, after trying different disposition of vertices in _Vertices2, it seems I got it working (the green triangle in attachment) - but I need an explanation of why it is working. Can someone please advice?

    Vector3[] __vertices = new Vector3[] { _vertices[2], _vertices[1], _vertices[0] };
    int[] __tris = new int[] {0, 1, 2};
    Vector3[] __normals = new Vector3[] { -Vector3.forward, -Vector3.forward, -Vector3.forward };
    GenerateMesh(__vertices, __tris, __normals);

    Vector3[] __vertices1 = new Vector3[] { _vertices[2], _vertices[0], _vertices[3] };
    int[] __tris1 = new int[] {0, 1, 2};
    Vector3[] __normals1 = new Vector3[] { -Vector3.forward, -Vector3.forward, -Vector3.forward };
    GenerateMesh(__vertices1, __tris1, __normals1);

    Vector3[] __vertices2 = new Vector3[] { _vertices[0], _vertices[1], _vertices[3] };
    int[] __tris2 = new int[] { 0, 1, 2 };
    Vector3[] __normals2 = new Vector3[] { -Vector3.forward, -Vector3.forward, -Vector3.forward };
    GenerateMesh(__vertices2, __tris2, __normals2);

    P.S. I need to generate one triangle per time (that's why I invoke Generate mesh 3 times instead of 1)
     

    Attached Files:

    Last edited: Apr 21, 2020
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,357
    Could it be vertex winding order? Unity assumes that vertices are always specified in clockwise order, so if you specify the vertices in counter-clockwise order (relative to the camera) then your triangle will be facing away from the camera, making it invisible.
     
    einstyle likes this.
  3. einstyle

    einstyle

    Joined:
    May 19, 2017
    Posts:
    8
    Yeah that seems to be it. Thanks!