/* ================= AddOriginalEdges ================= */ static void AddOriginalEdges( optimizeGroup_t *opt ) { mapTri_t *tri; optVertex_t *v[3]; int numTris; if ( dmapGlobals.verbose ) { common->Printf( "----\n" ); common->Printf( "%6i original tris\n", CountTriList( opt->triList ) ); } optBounds.Clear(); // allocate space for max possible edges numTris = CountTriList( opt->triList ); originalEdges = (originalEdges_t *)Mem_Alloc( numTris * 3 * sizeof( *originalEdges ), TAG_DMAP ); numOriginalEdges = 0; // add all unique triangle edges numOptVerts = 0; numOptEdges = 0; for ( tri = opt->triList ; tri ; tri = tri->next ) { v[0] = tri->optVert[0] = FindOptVertex( &tri->v[0], opt ); v[1] = tri->optVert[1] = FindOptVertex( &tri->v[1], opt ); v[2] = tri->optVert[2] = FindOptVertex( &tri->v[2], opt ); AddOriginalTriangle( v ); } }
/* ================== CountGroupListTris ================== */ int CountGroupListTris( const optimizeGroup_t *groupList ) { int c; c = 0; for ( ; groupList ; groupList = groupList->nextGroup ) { c += CountTriList( groupList->triList ); } return c; }
/* ==================== ShareMapTriVerts Converts independent triangles to shared vertex triangles ==================== */ srfTriangles_t *ShareMapTriVerts( const mapTri_t *tris ) { const mapTri_t *step; int count; int i, j; int numVerts; int numIndexes; srfTriangles_t *uTri; // unique the vertexes count = CountTriList( tris ); uTri = R_AllocStaticTriSurf(); R_AllocStaticTriSurfVerts( uTri, count * 3 ); R_AllocStaticTriSurfIndexes( uTri, count * 3 ); numVerts = 0; numIndexes = 0; for ( step = tris ; step ; step = step->next ) { for ( i = 0 ; i < 3 ; i++ ) { const idDrawVert *dv; dv = &step->v[i]; // search for a match for ( j = 0 ; j < numVerts ; j++ ) { if ( MatchVert( &uTri->verts[j], dv ) ) { break; } } if ( j == numVerts ) { numVerts++; uTri->verts[j].xyz = dv->xyz; uTri->verts[j].normal = dv->normal; uTri->verts[j].st[0] = dv->st[0]; uTri->verts[j].st[1] = dv->st[1]; } uTri->indexes[numIndexes++] = j; } } uTri->numVerts = numVerts; uTri->numIndexes = numIndexes; return uTri; }