XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Order of indices in triangle strip (Converting strip to list of triangles)

Last post 05-12-2008 4:18 PM by David Hunt. 2 replies.
  • 05-09-2008 7:38 PM

    Order of indices in triangle strip (Converting strip to list of triangles)

    How are the vertex indices supposed to be arranged for drawing a triangle strip as far as XNA/D3D are concerned? I am guessing that it would follow this formula:

    Let N be the index of the first vertex in an array of vertices.

    Triangle 1: N + 0, N + 1, N + 2
    Triangle 2: N + 1, N + 3, N + 2
    Triangle 3: N + 2, N + 3, N + 4
    Triangle 4: N + 3, N + 5, N + 3


    So basically even-numbered triangles have their second and third vertices swapped, otherwise it is fairly straightforward where the first index is dropped from the previous triangle and the other two are slid over.

    Does this seem right? I am trying to convert a triangle strip from a model into a triangle list (for a polysoup collision mesh). Here is a pseudo-code implementation:

    List<Triangle> triList = new List<Triangle>();
    int idx = 0;

    for (int i = 2; i < start + numelements; i++)
    {
    Triangle tri = new Triangle();
    bool isEven = (i % 2 == 0);  //is this an even or odd triangle?

    tri.v0 = i - 2;      //always two indexes back
    tri.v1 = isEven ? i : i - 1;  //alternate the order of the next two
    tri.v2 = isEven ? i - 1 : i;

    //if not degenerate add to the list
    if (tri.v0 != tri.v1 && tri.v1 != tri.v2 && tri.v2 != tri.v0)
    triList.add(tri);
    }

  • 05-10-2008 1:02 PM In reply to

    Re: Order of indices in triangle strip (Converting strip to list of triangles)

    That could be right.  It depends upon the modeling package used and the export settings used to create the model.

     

    I would say, let your code try to convert it.  Then display it with no culling on, in your game/engine/tool.  Hopefully, it still looks like the original model.  If so, then turn CullCounterClockwiseFace culling back on, to see if your winding order is correct for all faces.

  • 05-12-2008 4:18 PM In reply to

    Re: Order of indices in triangle strip (Converting strip to list of triangles)

Page 1 of 1 (3 items) Previous Next