level/csg4.c
/*	Builds a list of surfaces containing all of the faces
*/
Builds a list of surfaces containing all of the faces
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;
	for( b1 = tree->brushes; b1; b1 = b1->next ) 
	{
		CopyFacesToOutside( b1 );
		overwrite = false;
		for( b2 = tree->brushes; b2; b2 = b2->next )
		{
			if( b1 == b2 ) 	
			{
				overwrite = true;	
				continue;
			}
			for( i = 0; i < 3; i++ )
				if( b1->mins[i] > b2->maxs[i] || b1->maxs[i] < b2->mins[i] )
					break;
			if( i < 3 )
				continue;
			inside = outside;
			outside = NULL;
			for( f = b2->faces; f; f = f->next )
				ClipInside( f->planenum, f->planeside, overwrite );
			if( ((b1->contents == BSP_CONTENTS_SOLID) && (b2->contents <= BSP_CONTENTS_WATER)))
				FreeInside( b2->contents );
			else
				FreeInside( BSP_CONTENTS_SOLID );
		}
		if( b1->contents != BSP_CONTENTS_SOLID )
			SaveOutside( tree, true );	
		else
			SaveOutside( tree, false );
	}
	BuildSurfaces( tree );
	qprintf( "%5i brushfaces\n", numcsgbrushfaces );
	qprintf( "%5i csgfaces\n", numcsgfaces );
	qprintf( "%5i mergedfaces\n", numcsgmergefaces );
}
void CSGFaces ( tree_t * tree ) { int i ; bool overwrite ; brush_t * b1 , * b2 ; face_t * f ; qprintf ( " \n " ) ; memset ( tree -> validfaces , 0 , sizeof ( tree -> validfaces ) ) ; numcsgfaces = numcsgbrushfaces = numcsgmergefaces = 0 ; for ( b1 = tree -> brushes ; b1 ; b1 = b1 -> next ) { CopyFacesToOutside ( b1 ) ; overwrite = false ; for ( b2 = tree -> brushes ; b2 ; b2 = b2 -> next ) { if ( b1 == b2 ) { overwrite = true ; continue ; } for ( i = 0 ; i < 3 ; i ++ ) if ( b1 -> mins [ i ] > b2 -> maxs [ i ] || b1 -> maxs [ i ] < b2 -> mins [ i ] ) break ; if ( i < 3 ) continue ; inside = outside ; outside = NULL ; for ( f = b2 -> faces ; f ; f = f -> next ) ClipInside ( f -> planenum , f -> planeside , overwrite ) ; if ( ( ( b1 -> contents == BSP_CONTENTS_SOLID ) && ( b2 -> contents <= BSP_CONTENTS_WATER ) ) ) FreeInside ( b2 -> contents ) ; else FreeInside ( BSP_CONTENTS_SOLID ) ; } if ( b1 -> contents != BSP_CONTENTS_SOLID ) SaveOutside ( tree , true ) ; else SaveOutside ( tree , false ) ; } BuildSurfaces ( tree ) ; qprintf ( " \n " , numcsgbrushfaces ) ; qprintf ( " \n " , numcsgfaces ) ; qprintf ( " \n " , numcsgmergefaces ) ; }
Builds a list of surfaces containing all of the faces
Builds a list of surfaces containing all of the faces
// do the solid faces // set outside to a copy of the brush's faces // see if b2 needs to clip a chunk out of b1 // later brushes now overwrite // check bounding box first // divide faces by the planes of the new brush // these faces are continued in another brush, so get rid of them // all of the faces left in outside are real surface faces // mirror faces for inside view