Game Development Reference
In-Depth Information
The ReducePolygons function creates an array of quadric pairs using
the CreateValidPairsArray function and then calculates the optimum
location for the contraction target using CalculateVDash . At this stage, the
list of QUADRICPAIRS is sorted into a new list based on the calculated
error. Then the function enters a loop where an edge is removed at each
iteration until the target polygon total is achieved. The removal of an edge
may delete one or more polygons. The RemoveEdge function returns the
number of polygons that have been removed from the mesh. When a
vertex is removed, we set the valid flag for the quadric with the same
index to false to indicate that it is no longer used in the target mesh. On
completion of the algorithm, we must tidy up the data, because we have
a vertex list that now contains gaps indicated by the invalid flag. The
function call StreamlineMesh takes the quadric list and recreates a mesh
based on the current state of the vertex list.
BOOL CToon3DObject::ReducePolygons(int polyTotal){
if (polyTotal >= oi.numpoints) return FALSE;
if (morph) usemorph = FALSE;
//Save original mesh data so we can restore the original
if (pi.numpoints==0) CreatePatchInfo();
CQuadric *q = new CQuadric[oi.numpoints], k;
if (!q) return FALSE;
int i, j, n, pTotal, qpTotal, count, vTotal;
QUADRICPAIR *qp = NULL, *qparray;
//Calculate the Quadric matrices for each vertex
for (int ptindex=0; ptindex < oi.numpoints; ptindex++){
ply = oi.plys;
for(i=0; i<oi.numpolygons; i++){
if (ply->p[0] == ptindex || ply->p[1] == ptindex ||
ply->p[2] == ptindex || ply->p[3] == ptindex){
Search Nedrilad ::

Custom Search