Search Unity

Challenges with MeshWriteData

Discussion in 'UI Toolkit' started by taylank, Jul 19, 2019.

  1. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    I am trying to use generateVisualContent delegate to create a procedural line mesh, and I am having some issues. So imagine a vertical line segment from A (bottom) to B(top). I want to draw a line from start to end with a width value. So say w = 5 * Vector2.right.

    So my vertices for a given segment should be:
    0: A.position + w
    1: A.position - w
    2: B.position - w
    3: B.position - w
    4: B.position + w
    5. A.position + w

    Right?

    I set these vertices with the SetAllVertices method, followed by a series of SetNextIndex calls from 0 to 5. Then nothing appears on screen. Interestingly when I set the indices in reverse order, from 5 to 0, I get something.

    upload_2019-7-18_19-28-29.png

    Half my mesh is now visible, but I can't figure out why the other half (the second triangle) is not appearing at all. I tried changing the order of the vertices and I think I tried pretty much every combination, but still no luck. I feel like I'm doing some dumb mistake and it's driving me crazy. HALP!
     
  2. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    Oh nevermind, I'm an idiot. I had the wrong z depth on the last vertex.