/* ================== CSGFaces Returns a list of surfaces containing all of the faces ================== */ surface_t * CSGFaces(void) { brush_t *b1, *b2; int i; bool overwrite; face_t *f; surface_t *surfhead; int iBrushes = 0; Message(msgProgress, "CSGFaces"); if (validfaces == NULL) validfaces = AllocMem(OTHER, sizeof(face_t *) * cPlanes, true); else memset(validfaces, 0, sizeof(face_t *) * cPlanes); csgfaces = brushfaces = csgmergefaces = 0; // do the solid faces for (b1 = pCurEnt->pBrushes; b1; b1 = b1->next) { // set outside to a copy of the brush's faces CopyFacesToOutside(b1); // Why is this necessary? overwrite = false; for (b2 = pCurEnt->pBrushes; b2; b2 = b2->next) { // check bounding box first for (i = 0; i < 3; i++) if (b1->mins[i] > b2->maxs[i] || b1->maxs[i] < b2->mins[i]) break; if (i < 3) continue; // see if b2 needs to clip a chunk out of b1 if (b1 == b2) { overwrite = true; continue; } // divide faces by the planes of the new brush inside = outside; outside = NULL; CheckInside(b2); for (f = b2->faces; f; f = f->next) ClipInside(f->planenum, f->planeside, overwrite); // these faces are continued in another brush, so get rid of them if (b1->contents == CONTENTS_SOLID && b2->contents <= CONTENTS_WATER) FreeInside(b2->contents); else FreeInside(CONTENTS_SOLID); } // all of the faces left in outside are real surface faces if (b1->contents != CONTENTS_SOLID) SaveOutside(true); // mirror faces for inside view else SaveOutside(false); iBrushes++; Message(msgPercent, iBrushes, pCurEnt->cBrushes); } surfhead = BuildSurfaces(); Message(msgStat, "%5i brushfaces", brushfaces); Message(msgStat, "%5i csgfaces", csgfaces); Message(msgStat, "%5i mergedfaces", csgmergefaces); return surfhead; }
/* ================== CSGFaces Returns a list of surfaces containing aall of the faces ================== */ surface_t *CSGFaces (brushset_t *bs) { brush_t *b1, *b2; int i; qboolean overwrite; face_t *f; surface_t *surfhead; qprintf ("---- CSGFaces ----\n"); memset (validfaces, 0, sizeof(validfaces)); csgfaces = brushfaces = csgmergefaces = 0; Draw_ClearWindow (); // // do the solid faces // for (b1 = bs->brushes ; b1 ; b1 = b1->next) { // set outside to a copy of the brush's faces CopyFacesToOutside (b1); overwrite = false; for (b2 = bs->brushes ; b2 ; b2 = b2->next) { // see if b2 needs to clip a chunk out of b1 if (b1 == b2) { overwrite = true; // later brushes now overwrite continue; } // check bounding box first for (i = 0 ; i < 3 ; i++) if (b1->mins[i] > b2->maxs[i] || b1->maxs[i] < b2->mins[i]) break; if (i < 3) continue; // divide faces by the planes of the new brush inside = outside; outside = NULL; for (f = b2->faces ; f ; f = f->next) ClipInside (f->planenum, f->planeside, overwrite); // these faces are continued in another brush, so get rid of them if (b1->contents == CONTENTS_SOLID && b2->contents <= CONTENTS_WATER) FreeInside (b2->contents); else FreeInside (CONTENTS_SOLID); } // all of the faces left in outside are real surface faces if (b1->contents != CONTENTS_SOLID) SaveOutside (true); // mirror faces for inside view else SaveOutside (false); } #if 0 if (!csgfaces) Error ("No faces"); #endif surfhead = BuildSurfaces (); qprintf ("%5i brushfaces\n", brushfaces); qprintf ("%5i csgfaces\n", csgfaces); qprintf ("%5i mergedfaces\n", csgmergefaces); return surfhead; }
/* Builds a list of surfaces containing all of the faces */ void CSGFaces( tree_t *tree ) { int i; bool overwrite; brush_t *b1, *b2; face_t *f; qprintf( "---- CSGFaces ----\n" ); memset( tree->validfaces, 0, sizeof( tree->validfaces ) ); numcsgfaces = numcsgbrushfaces = numcsgmergefaces = 0; // do the solid faces for( b1 = tree->brushes; b1; b1 = b1->next ) { // set outside to a copy of the brush's faces CopyFacesToOutside( b1 ); overwrite = false; for( b2 = tree->brushes; b2; b2 = b2->next ) { // see if b2 needs to clip a chunk out of b1 if( b1 == b2 ) { overwrite = true; // later brushes now overwrite continue; } // check bounding box first for( i = 0; i < 3; i++ ) if( b1->mins[i] > b2->maxs[i] || b1->maxs[i] < b2->mins[i] ) break; if( i < 3 ) continue; // divide faces by the planes of the new brush inside = outside; outside = NULL; for( f = b2->faces; f; f = f->next ) ClipInside( f->planenum, f->planeside, overwrite ); // these faces are continued in another brush, so get rid of them if( b1->contents == BSP_CONTENTS_SOLID && b2->contents <= BSP_CONTENTS_WATER ) FreeInside( b2->contents ); else FreeInside( BSP_CONTENTS_SOLID ); } // all of the faces left in outside are real surface faces if( b1->contents != BSP_CONTENTS_SOLID ) SaveOutside( tree, true ); // mirror faces for inside view else SaveOutside( tree, false ); } BuildSurfaces( tree ); qprintf( "%5i brushfaces\n", numcsgbrushfaces ); qprintf( "%5i csgfaces\n", numcsgfaces ); qprintf( "%5i mergedfaces\n", numcsgmergefaces ); }