pfdTMesher.c improvement

New Message Reply Date view Thread view Subject view Author view

ROBERT_REIF++at++ntsc.navy.mil
Thu, 16 Oct 97 11:59:18 EST


A few weeks ago I was having problems getting the Performer tmesher
to convert some coplanar triangles into triangle strips. I looked
into the problem and discovered that the tmesher was able to retessellate
some quads into triangles that could be striped. It does this by
retessellating future quads as they are added to the strip. However, if
the strip starts out wrong, the retessellation code wont help.

I am providing some changes to the file pfdTMesher.c which will go back
and fix a triangle strip consisting of a quad that starts out tessellated
wrong.

This change has shown an improvement in triangle strip lengths in almost
every file I have tried it on.

This change has not been exhaustively tested so if you try it and find
problems, please let me know.

Thanks,

Bob Reif

diff to file pfdTMesher.c:

683a684,783
> /*
> * Check if strip consists of a quad and retessellate the quad if possible.
> */
>
> static int
> swapTriList(int primsInStrip, TriList * triList)
> {
> Tri * tri1, * tri2;
> int i, j;
> ushort vi, vj;
>
> /* must be two primitives in strip to retessellate */
> if (primsInStrip != 2)
> return 0;
>
> /* check for a quad */
> tri1 = triList->next;
> tri2 = tri1->next;
>
> /* just check for simple strips now */
> if (tri1->adjCount != 1 || tri2->adjCount != 1)
> return 0;
>
> if (!(tri1->flags & NORM_OK))
> computeNormal(tri1);
>
> if (!(tri2->flags & NORM_OK))
> computeNormal(tri2);
>
> /* Make sure two triangles are coplanar */
> if (!PFALMOST_EQUAL_VEC3(tri1->norm, tri2->norm, SORTOF))
> return 0;
>
> /* Make sure PER_PRIM colors of the two triangles are the same */
> if (CBind == PFGS_PER_PRIM &&
> !PFALMOST_EQUAL_VEC4(Colors[Cindex[tri1->id]],
> Colors[Cindex[tri2->id]], SORTOF))
> return 0;
>
> i = notCommon(tri1, tri2);
> j = notCommon(tri2, tri1);
>
> vi = tri1->vert[i];
> vj = tri2->vert[j];
>
> /* Make sure vertex colors are the same */
> if (CBind == PFGS_PER_VERTEX &&
> (!PFALMOST_EQUAL_VEC4(Colors[Cindex[vi]],
> Colors[Cindex[vj]], SORTOF) ||
> !PFALMOST_EQUAL_VEC4(Colors[Cindex[vi]],
> Colors[Cindex[(vj+1) % 3]], SORTOF)))
> return 0;
>
> /* Make sure two triangles form convex quad */
> if (concaveCheck(tri1->norm, vi, tri1->vert[NextVertIndex[i]],
> vj, tri2->vert[NextVertIndex[j]]))
> return 0;
>
> /* retessellate quad in strip */
> if (tri1->adj[0])
> {
> tri1->vert[2] = vj;
> NextEdge = 0;
> }
> else if (tri1->adj[1])
> {
> tri1->vert[0] = vj;
> NextEdge = 1;
> }
> else
> {
> tri1->vert[1] = vj;
> NextEdge = 2;
> }
>
> if (tri2->adj[0])
> {
> Tri * tmp = tri2->adj[0];
> tri2->vert[0] = vi;
> tri2->adj[0] = tri2->adj[2];
> tri2->adj[2] = tmp;
> }
> else if (tri2->adj[1])
> {
> Tri * tmp = tri2->adj[1];
> tri2->vert[1] = vi;
> tri2->adj[1] = tri2->adj[0];
> tri2->adj[0] = tmp;
> }
> else
> {
> Tri * tmp = tri2->adj[2];
> tri2->vert[2] = vi;
> tri2->adj[2] = tri2->adj[1];
> tri2->adj[1] = tmp;
> }
>
> return 1;
> }
>
846,849c946,976
< if (primType == PFGS_TRIS)
     < tri = getNextTri(tri);
     < else
     < tri = getNextLine(tri);
     ---
> if (Retessellate)
> {
> Tri * newtri;
>
> if (primType == PFGS_TRIS)
> newtri = getNextTri(tri);
> else
> newtri = getNextLine(tri);
>
> /* check if triangle has adjacencies but not added
     to strip */
> if (!newtri && tri->adjCount)
> {
> /* retesselate strip if possible */
> if (swapTriList(primsInStrip, newTriList))
> {
> if (primType == PFGS_TRIS)
> newtri = getNextTri(tri);
> else
> newtri = getNextLine(tri);
> }
> }
>
> tri = newtri;
> }
> else
> {
> if (primType == PFGS_TRIS)
> tri = getNextTri(tri);
> else
> tri = getNextLine(tri);
> }
      

=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:56:05 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.