2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include "qbsp.h"
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_nodes;
|
|
|
|
int c_nonvis;
|
|
|
|
int c_active_brushes;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// if a brush just barely pokes onto the other side,
|
|
|
|
// let it slide by without chopping
|
2012-03-17 20:01:54 +00:00
|
|
|
#define PLANESIDE_EPSILON 0.001
|
2007-11-04 03:34:51 +00:00
|
|
|
//0.1
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define PSIDE_FRONT 1
|
|
|
|
#define PSIDE_BACK 2
|
|
|
|
#define PSIDE_BOTH ( PSIDE_FRONT | PSIDE_BACK )
|
|
|
|
#define PSIDE_FACING 4
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FindBrushInTree( node_t *node, int brushnum ){
|
|
|
|
bspbrush_t *b;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->planenum == PLANENUM_LEAF ) {
|
|
|
|
for ( b = node->brushlist ; b ; b = b->next )
|
|
|
|
if ( b->original->brushnum == brushnum ) {
|
|
|
|
Sys_Printf( "here\n" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
FindBrushInTree( node->children[0], brushnum );
|
|
|
|
FindBrushInTree( node->children[1], brushnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
DrawBrushList
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void DrawBrushList( bspbrush_t *brush, node_t *node ){
|
|
|
|
int i;
|
|
|
|
side_t *s;
|
|
|
|
|
|
|
|
GLS_BeginScene();
|
|
|
|
for ( ; brush ; brush = brush->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = &brush->sides[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !s->winding ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( s->texinfo == TEXINFO_NODE ) {
|
|
|
|
GLS_Winding( s->winding, 1 );
|
|
|
|
}
|
|
|
|
else if ( !s->visible ) {
|
|
|
|
GLS_Winding( s->winding, 2 );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
GLS_Winding( s->winding, 0 );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
GLS_EndScene();
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
WriteBrushList
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void WriteBrushList( char *name, bspbrush_t *brush, qboolean onlyvis ){
|
|
|
|
int i;
|
|
|
|
side_t *s;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
Sys_FPrintf( SYS_VRB, "writing %s\n", name );
|
|
|
|
f = SafeOpenWrite( name );
|
|
|
|
|
|
|
|
for ( ; brush ; brush = brush->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = &brush->sides[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !s->winding ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( onlyvis && !s->visible ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
OutputWinding( brush->sides[i].winding, f );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( f );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void PrintBrush( bspbrush_t *brush ){
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "brush: %p\n", brush );
|
|
|
|
for ( i = 0; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
pw( brush->sides[i].winding );
|
|
|
|
Sys_Printf( "\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
BoundBrush
|
|
|
|
|
|
|
|
Sets the mins/maxs based on the windings
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void BoundBrush( bspbrush_t *brush ){
|
|
|
|
int i, j;
|
|
|
|
winding_t *w;
|
|
|
|
|
|
|
|
ClearBounds( brush->mins, brush->maxs );
|
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
w = brush->sides[i].winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
for ( j = 0 ; j < w->numpoints ; j++ )
|
|
|
|
AddPointToBounds( w->p[j], brush->mins, brush->maxs );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
CreateBrushWindings
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void CreateBrushWindings( bspbrush_t *brush ){
|
|
|
|
int i, j;
|
|
|
|
winding_t *w;
|
|
|
|
side_t *side;
|
|
|
|
plane_t *plane;
|
|
|
|
|
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
side = &brush->sides[i];
|
|
|
|
plane = &mapplanes[side->planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
w = BaseWindingForPlane( plane->normal, plane->dist );
|
|
|
|
for ( j = 0 ; j < brush->numsides && w; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i == j ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( brush->sides[j].bevel ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
plane = &mapplanes[brush->sides[j].planenum ^ 1];
|
|
|
|
ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON);
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
side->winding = w;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
BoundBrush( brush );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
BrushFromBounds
|
|
|
|
|
|
|
|
Creates a new axial brush
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
bspbrush_t *BrushFromBounds( vec3_t mins, vec3_t maxs ){
|
|
|
|
bspbrush_t *b;
|
|
|
|
int i;
|
|
|
|
vec3_t normal;
|
|
|
|
vec_t dist;
|
|
|
|
|
|
|
|
b = AllocBrush( 6 );
|
2007-11-04 03:34:51 +00:00
|
|
|
b->numsides = 6;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorClear( normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
normal[i] = 1;
|
|
|
|
dist = maxs[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
b->sides[i].planenum = FindFloatPlane( normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
normal[i] = -1;
|
|
|
|
dist = -mins[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
b->sides[3 + i].planenum = FindFloatPlane( normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CreateBrushWindings( b );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
BrushVolume
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
vec_t BrushVolume( bspbrush_t *brush ){
|
|
|
|
int i;
|
|
|
|
winding_t *w;
|
|
|
|
vec3_t corner;
|
|
|
|
vec_t d, area, volume;
|
|
|
|
plane_t *plane;
|
|
|
|
|
|
|
|
if ( !brush ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// grab the first valid point as the corner
|
|
|
|
|
|
|
|
w = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
w = brush->sides[i].winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
VectorCopy( w->p[0], corner );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// make tetrahedrons to all other faces
|
|
|
|
|
|
|
|
volume = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
w = brush->sides[i].winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
plane = &mapplanes[brush->sides[i].planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
d = -( DotProduct( corner, plane->normal ) - plane->dist );
|
|
|
|
area = WindingArea( w );
|
|
|
|
volume += d * area;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
volume /= 3;
|
|
|
|
return volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
CountBrushList
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int CountBrushList( bspbrush_t *brushes ){
|
|
|
|
int c;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
c = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( ; brushes ; brushes = brushes->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
c++;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
AllocTree
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
tree_t *AllocTree( void ){
|
|
|
|
tree_t *tree;
|
|
|
|
|
|
|
|
tree = malloc( sizeof( *tree ) );
|
|
|
|
memset( tree, 0, sizeof( *tree ) );
|
|
|
|
ClearBounds( tree->mins, tree->maxs );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
AllocNode
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
node_t *AllocNode( void ){
|
|
|
|
node_t *node;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
node = malloc( sizeof( *node ) );
|
|
|
|
memset( node, 0, sizeof( *node ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
AllocBrush
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
bspbrush_t *AllocBrush( int numsides ){
|
|
|
|
bspbrush_t *bb;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = (int)&( ( (bspbrush_t *)0 )->sides[numsides] );
|
|
|
|
bb = malloc( c );
|
|
|
|
memset( bb, 0, c );
|
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_active_brushes++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return bb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
FreeBrush
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void FreeBrush( bspbrush_t *brushes ){
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0 ; i < brushes->numsides ; i++ )
|
|
|
|
if ( brushes->sides[i].winding ) {
|
|
|
|
FreeWinding( brushes->sides[i].winding );
|
|
|
|
}
|
|
|
|
free( brushes );
|
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_active_brushes--;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
FreeBrushList
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void FreeBrushList( bspbrush_t *brushes ){
|
|
|
|
bspbrush_t *next;
|
|
|
|
|
|
|
|
for ( ; brushes ; brushes = next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
next = brushes->next;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FreeBrush( brushes );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
CopyBrush
|
|
|
|
|
|
|
|
Duplicates the brush, the sides, and the windings
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
bspbrush_t *CopyBrush( bspbrush_t *brush ){
|
2007-11-04 03:34:51 +00:00
|
|
|
bspbrush_t *newbrush;
|
2012-03-17 20:01:54 +00:00
|
|
|
int size;
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
size = (int)&( ( (bspbrush_t *)0 )->sides[brush->numsides] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
newbrush = AllocBrush( brush->numsides );
|
|
|
|
memcpy( newbrush, brush, size );
|
|
|
|
|
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( brush->sides[i].winding ) {
|
|
|
|
newbrush->sides[i].winding = CopyWinding( brush->sides[i].winding );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return newbrush;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
PointInLeaf
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
*/
|
|
|
|
node_t *PointInLeaf( node_t *node, vec3_t point ){
|
|
|
|
vec_t d;
|
|
|
|
plane_t *plane;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( node->planenum != PLANENUM_LEAF )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
plane = &mapplanes[node->planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
d = DotProduct( point, plane->normal ) - plane->dist;
|
|
|
|
if ( d > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
node = node->children[0];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
node = node->children[1];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
BoxOnPlaneSide
|
|
|
|
|
|
|
|
Returns PSIDE_FRONT, PSIDE_BACK, or PSIDE_BOTH
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
int BoxOnPlaneSide( vec3_t mins, vec3_t maxs, plane_t *plane ){
|
|
|
|
int side;
|
|
|
|
int i;
|
|
|
|
vec3_t corners[2];
|
|
|
|
vec_t dist1, dist2;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// axial planes are easy
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( plane->type < 3 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( maxs[plane->type] > plane->dist + PLANESIDE_EPSILON ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side |= PSIDE_FRONT;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( mins[plane->type] < plane->dist - PLANESIDE_EPSILON ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side |= PSIDE_BACK;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return side;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the proper leading and trailing verts for the box
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( plane->normal[i] < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
corners[0][i] = mins[i];
|
|
|
|
corners[1][i] = maxs[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
corners[1][i] = mins[i];
|
|
|
|
corners[0][i] = maxs[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dist1 = DotProduct( plane->normal, corners[0] ) - plane->dist;
|
|
|
|
dist2 = DotProduct( plane->normal, corners[1] ) - plane->dist;
|
2007-11-04 03:34:51 +00:00
|
|
|
side = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist1 >= PLANESIDE_EPSILON ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side = PSIDE_FRONT;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( dist2 < PLANESIDE_EPSILON ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side |= PSIDE_BACK;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return side;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
QuickTestBrushToPlanenum
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
*/
|
|
|
|
int QuickTestBrushToPlanenum( bspbrush_t *brush, int planenum, int *numsplits ){
|
|
|
|
int i, num;
|
|
|
|
plane_t *plane;
|
|
|
|
int s;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
*numsplits = 0;
|
|
|
|
|
|
|
|
// if the brush actually uses the planenum,
|
|
|
|
// we can tell the side for sure
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
num = brush->sides[i].planenum;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( num >= 0x10000 ) {
|
|
|
|
Error( "bad planenum" );
|
|
|
|
}
|
|
|
|
if ( num == planenum ) {
|
|
|
|
return PSIDE_BACK | PSIDE_FACING;
|
|
|
|
}
|
|
|
|
if ( num == ( planenum ^ 1 ) ) {
|
|
|
|
return PSIDE_FRONT | PSIDE_FACING;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// box on plane side
|
|
|
|
plane = &mapplanes[planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
s = BoxOnPlaneSide( brush->mins, brush->maxs, plane );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// if both sides, count the visible faces split
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s == PSIDE_BOTH ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*numsplits += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
TestBrushToPlanenum
|
|
|
|
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
int TestBrushToPlanenum( bspbrush_t *brush, int planenum,
|
|
|
|
int *numsplits, qboolean *hintsplit, int *epsilonbrush ){
|
|
|
|
int i, j, num;
|
|
|
|
plane_t *plane;
|
|
|
|
int s;
|
|
|
|
winding_t *w;
|
|
|
|
vec_t d, d_front, d_back;
|
|
|
|
int front, back;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
*numsplits = 0;
|
|
|
|
*hintsplit = false;
|
|
|
|
|
|
|
|
// if the brush actually uses the planenum,
|
|
|
|
// we can tell the side for sure
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
num = brush->sides[i].planenum;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( num >= 0x10000 ) {
|
|
|
|
Error( "bad planenum" );
|
|
|
|
}
|
|
|
|
if ( num == planenum ) {
|
|
|
|
return PSIDE_BACK | PSIDE_FACING;
|
|
|
|
}
|
|
|
|
if ( num == ( planenum ^ 1 ) ) {
|
|
|
|
return PSIDE_FRONT | PSIDE_FACING;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// box on plane side
|
|
|
|
plane = &mapplanes[planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
s = BoxOnPlaneSide( brush->mins, brush->maxs, plane );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s != PSIDE_BOTH ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return s;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// if both sides, count the visible faces split
|
|
|
|
d_front = d_back = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( brush->sides[i].texinfo == TEXINFO_NODE ) {
|
|
|
|
continue; // on node, don't worry about splits
|
|
|
|
}
|
|
|
|
if ( !brush->sides[i].visible ) {
|
|
|
|
continue; // we don't care about non-visible
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
w = brush->sides[i].winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
front = back = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < w->numpoints; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
d = DotProduct( w->p[j], plane->normal ) - plane->dist;
|
|
|
|
if ( d > d_front ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
d_front = d;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( d < d_back ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
d_back = d;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d > 0.1 ) { // PLANESIDE_EPSILON)
|
2007-11-04 03:34:51 +00:00
|
|
|
front = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( d < -0.1 ) { // PLANESIDE_EPSILON)
|
2007-11-04 03:34:51 +00:00
|
|
|
back = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( front && back ) {
|
|
|
|
if ( !( brush->sides[i].surf & SURF_SKIP ) ) {
|
|
|
|
( *numsplits )++;
|
|
|
|
if ( brush->sides[i].surf & SURF_HINT ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*hintsplit = true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( d_front > 0.0 && d_front < 1.0 )
|
|
|
|
|| ( d_back < 0.0 && d_back > -1.0 ) ) {
|
|
|
|
( *epsilonbrush )++;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *numsplits == 0 ) { // didn't really need to be split
|
|
|
|
if ( front ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
s = PSIDE_FRONT;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( back ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
s = PSIDE_BACK;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
s = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
WindingIsTiny
|
|
|
|
|
|
|
|
Returns true if the winding would be crunched out of
|
|
|
|
existance by the vertex snapping.
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
#define EDGE_LENGTH 0.2
|
|
|
|
qboolean WindingIsTiny( winding_t *w ){
|
2007-11-04 03:34:51 +00:00
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( WindingArea( w ) < 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return false;
|
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
int i, j;
|
|
|
|
vec_t len;
|
|
|
|
vec3_t delta;
|
|
|
|
int edges;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
edges = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < w->numpoints ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
j = i == w->numpoints - 1 ? 0 : i + 1;
|
|
|
|
VectorSubtract( w->p[j], w->p[i], delta );
|
|
|
|
len = (float) VectorLength( delta );
|
|
|
|
if ( len > EDGE_LENGTH ) {
|
|
|
|
if ( ++edges == 3 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return false;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
WindingIsHuge
|
|
|
|
|
|
|
|
Returns true if the winding still has one of the points
|
|
|
|
from basewinding for plane
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
qboolean WindingIsHuge( winding_t *w ){
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for ( i = 0 ; i < w->numpoints ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
|
|
|
if ( w->p[i][j] < -8000 || w->p[i][j] > 8000 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
Leafnode
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void LeafNode( node_t *node, bspbrush_t *brushes ){
|
|
|
|
bspbrush_t *b;
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
node->planenum = PLANENUM_LEAF;
|
|
|
|
node->contents = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = brushes ; b ; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// if the brush is solid and all of its sides are on nodes,
|
|
|
|
// it eats everything
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->original->contents & CONTENTS_SOLID ) {
|
|
|
|
for ( i = 0 ; i < b->numsides ; i++ )
|
|
|
|
if ( b->sides[i].texinfo != TEXINFO_NODE ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( i == b->numsides ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
node->contents = CONTENTS_SOLID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node->contents |= b->original->contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->brushlist = brushes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CheckPlaneAgainstParents( int pnum, node_t *node ){
|
|
|
|
node_t *p;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = node->parent ; p ; p = p->parent )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->planenum == pnum ) {
|
|
|
|
Error( "Tried parent" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean CheckPlaneAgainstVolume( int pnum, node_t *node ){
|
|
|
|
bspbrush_t *front, *back;
|
|
|
|
qboolean good;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SplitBrush( node->volume, pnum, &front, &back );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
good = ( front && back );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( front ) {
|
|
|
|
FreeBrush( front );
|
|
|
|
}
|
|
|
|
if ( back ) {
|
|
|
|
FreeBrush( back );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return good;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
SelectSplitSide
|
|
|
|
|
|
|
|
Using a hueristic, choses one of the sides out of the brushlist
|
|
|
|
to partition the brushes with.
|
|
|
|
Returns NULL if there are no valid planes to split with..
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
side_t *SelectSplitSide( bspbrush_t *brushes, node_t *node ){
|
|
|
|
int value, bestvalue;
|
|
|
|
bspbrush_t *brush, *test;
|
|
|
|
side_t *side, *bestside;
|
|
|
|
int i, j, pass, numpasses;
|
|
|
|
int pnum;
|
|
|
|
int s;
|
|
|
|
int front, back, both, facing, splits;
|
|
|
|
int bsplits;
|
|
|
|
int bestsplits;
|
|
|
|
int epsilonbrush;
|
|
|
|
qboolean hintsplit;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
bestside = NULL;
|
|
|
|
bestvalue = -99999;
|
|
|
|
bestsplits = 0;
|
|
|
|
|
|
|
|
// the search order goes: visible-structural, visible-detail,
|
|
|
|
// nonvisible-structural, nonvisible-detail.
|
|
|
|
// If any valid plane is available in a pass, no further
|
|
|
|
// passes will be tried.
|
|
|
|
numpasses = 4;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pass = 0 ; pass < numpasses ; pass++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( brush = brushes ; brush ; brush = brush->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( pass & 1 ) && !( brush->original->contents & CONTENTS_DETAIL ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !( pass & 1 ) && ( brush->original->contents & CONTENTS_DETAIL ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
side = brush->sides + i;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( side->bevel ) {
|
|
|
|
continue; // never use a bevel as a spliter
|
|
|
|
}
|
|
|
|
if ( !side->winding ) {
|
|
|
|
continue; // nothing visible, so it can't split
|
|
|
|
}
|
|
|
|
if ( side->texinfo == TEXINFO_NODE ) {
|
|
|
|
continue; // allready a node splitter
|
|
|
|
}
|
|
|
|
if ( side->tested ) {
|
|
|
|
continue; // we allready have metrics for this plane
|
|
|
|
}
|
|
|
|
if ( side->surf & SURF_SKIP ) {
|
|
|
|
continue; // skip surfaces are never chosen
|
|
|
|
}
|
|
|
|
if ( side->visible ^ ( pass < 2 ) ) {
|
|
|
|
continue; // only check visible faces on first pass
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
pnum = side->planenum;
|
2012-03-17 20:01:54 +00:00
|
|
|
pnum &= ~1; // allways use positive facing plane
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CheckPlaneAgainstParents( pnum, node );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !CheckPlaneAgainstVolume( pnum, node ) ) {
|
|
|
|
continue; // would produce a tiny volume
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
front = 0;
|
|
|
|
back = 0;
|
|
|
|
both = 0;
|
|
|
|
facing = 0;
|
|
|
|
splits = 0;
|
|
|
|
epsilonbrush = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( test = brushes ; test ; test = test->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
s = TestBrushToPlanenum( test, pnum, &bsplits, &hintsplit, &epsilonbrush );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
splits += bsplits;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bsplits && ( s & PSIDE_FACING ) ) {
|
|
|
|
Error( "PSIDE_FACING with splits" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
test->testside = s;
|
|
|
|
// if the brush shares this face, don't bother
|
|
|
|
// testing that facenum as a splitter again
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s & PSIDE_FACING ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
facing++;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < test->numsides ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( test->sides[j].planenum & ~1 ) == pnum ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
test->sides[j].tested = true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s & PSIDE_FRONT ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
front++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( s & PSIDE_BACK ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
back++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( s == PSIDE_BOTH ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
both++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// give a value estimate for using this plane
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
value = 5 * facing - 5 * splits - abs( front - back );
|
2007-11-04 03:34:51 +00:00
|
|
|
// value = -5*splits;
|
|
|
|
// value = 5*facing - 5*splits;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapplanes[pnum].type < 3 ) {
|
|
|
|
value += 5; // axial is better
|
|
|
|
}
|
|
|
|
value -= epsilonbrush * 1000; // avoid!
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// never split a hint side except with another hint
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( hintsplit && !( side->surf & SURF_HINT ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
value = -9999999;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// save off the side test so we don't need
|
|
|
|
// to recalculate it when we actually seperate
|
|
|
|
// the brushes
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value > bestvalue ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bestvalue = value;
|
|
|
|
bestside = side;
|
|
|
|
bestsplits = splits;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( test = brushes ; test ; test = test->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
test->side = test->testside;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we found a good plane, don't bother trying any
|
|
|
|
// other passes
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bestside ) {
|
|
|
|
if ( pass > 1 ) {
|
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_nonvis++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( pass > 0 ) {
|
|
|
|
node->detail_seperator = true; // not needed for vis
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// clear all the tested flags we set
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( brush = brushes ; brush ; brush = brush->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
brush->sides[i].tested = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestside;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
BrushMostlyOnSide
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
int BrushMostlyOnSide( bspbrush_t *brush, plane_t *plane ){
|
|
|
|
int i, j;
|
|
|
|
winding_t *w;
|
|
|
|
vec_t d, max;
|
|
|
|
int side;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
max = 0;
|
|
|
|
side = PSIDE_FRONT;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
w = brush->sides[i].winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
for ( j = 0 ; j < w->numpoints ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
d = DotProduct( w->p[j], plane->normal ) - plane->dist;
|
|
|
|
if ( d > max ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
max = d;
|
|
|
|
side = PSIDE_FRONT;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( -d > max ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
max = -d;
|
|
|
|
side = PSIDE_BACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return side;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
SplitBrush
|
|
|
|
|
|
|
|
Generates two new brushes, leaving the original
|
|
|
|
unchanged
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void SplitBrush( bspbrush_t *brush, int planenum,
|
|
|
|
bspbrush_t **front, bspbrush_t **back ){
|
|
|
|
bspbrush_t *b[2];
|
|
|
|
int i, j;
|
|
|
|
winding_t *w, *cw[2], *midwinding;
|
|
|
|
plane_t *plane, *plane2;
|
|
|
|
side_t *s, *cs;
|
|
|
|
float d, d_front, d_back;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
*front = *back = NULL;
|
|
|
|
plane = &mapplanes[planenum];
|
|
|
|
|
|
|
|
// check all points
|
|
|
|
d_front = d_back = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
w = brush->sides[i].winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
for ( j = 0 ; j < w->numpoints ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
d = DotProduct( w->p[j], plane->normal ) - plane->dist;
|
|
|
|
if ( d > 0 && d > d_front ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
d_front = d;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( d < 0 && d < d_back ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
d_back = d;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d_front < 0.1 ) { // PLANESIDE_EPSILON)
|
|
|
|
// only on back
|
|
|
|
*back = CopyBrush( brush );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d_back > -0.1 ) { // PLANESIDE_EPSILON)
|
|
|
|
// only on front
|
|
|
|
*front = CopyBrush( brush );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a new winding from the split plane
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
w = BaseWindingForPlane( plane->normal, plane->dist );
|
|
|
|
for ( i = 0 ; i < brush->numsides && w ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
plane2 = &mapplanes[brush->sides[i].planenum ^ 1];
|
2012-03-17 20:01:54 +00:00
|
|
|
ChopWindingInPlace( &w, plane2->normal, plane2->dist, 0 ); // PLANESIDE_EPSILON);
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w || WindingIsTiny( w ) ) { // the brush isn't really split
|
|
|
|
int side;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
side = BrushMostlyOnSide( brush, plane );
|
|
|
|
if ( side == PSIDE_FRONT ) {
|
|
|
|
*front = CopyBrush( brush );
|
|
|
|
}
|
|
|
|
if ( side == PSIDE_BACK ) {
|
|
|
|
*back = CopyBrush( brush );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( WindingIsHuge( w ) ) {
|
|
|
|
Sys_FPrintf( SYS_VRB, "WARNING: huge winding\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
midwinding = w;
|
|
|
|
|
|
|
|
// split it for real
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
b[i] = AllocBrush( brush->numsides + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
b[i]->original = brush->original;
|
|
|
|
}
|
|
|
|
|
|
|
|
// split all the current windings
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = &brush->sides[i];
|
|
|
|
w = s->winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
ClipWindingEpsilon( w, plane->normal, plane->dist,
|
|
|
|
0 /*PLANESIDE_EPSILON*/, &cw[0], &cw[1] );
|
|
|
|
for ( j = 0 ; j < 2 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !cw[j] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( WindingIsTiny( cw[j] ) ) {
|
|
|
|
FreeWinding( cw[j] );
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
cs = &b[j]->sides[b[j]->numsides];
|
|
|
|
b[j]->numsides++;
|
|
|
|
*cs = *s;
|
|
|
|
// cs->planenum = s->planenum;
|
|
|
|
// cs->texinfo = s->texinfo;
|
|
|
|
// cs->visible = s->visible;
|
|
|
|
// cs->original = s->original;
|
|
|
|
cs->winding = cw[j];
|
|
|
|
cs->tested = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// see if we have valid polygons on both sides
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
BoundBrush( b[i] );
|
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b[i]->mins[j] < -4096 || b[i]->maxs[j] > 4096 ) {
|
|
|
|
Sys_FPrintf( SYS_VRB, "bogus brush after clip\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b[i]->numsides < 3 || j < 3 ) {
|
|
|
|
FreeBrush( b[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
b[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( b[0] && b[1] ) ) {
|
|
|
|
if ( !b[0] && !b[1] ) {
|
|
|
|
Sys_FPrintf( SYS_VRB, "split removed brush\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
|
|
|
Sys_FPrintf( SYS_VRB, "split not on both sides\n" );
|
|
|
|
}
|
|
|
|
if ( b[0] ) {
|
|
|
|
FreeBrush( b[0] );
|
|
|
|
*front = CopyBrush( brush );
|
|
|
|
}
|
|
|
|
if ( b[1] ) {
|
|
|
|
FreeBrush( b[1] );
|
|
|
|
*back = CopyBrush( brush );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the midwinding to both sides
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
cs = &b[i]->sides[b[i]->numsides];
|
|
|
|
b[i]->numsides++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cs->planenum = planenum ^ i ^ 1;
|
2007-11-04 03:34:51 +00:00
|
|
|
cs->texinfo = TEXINFO_NODE;
|
|
|
|
cs->visible = false;
|
|
|
|
cs->tested = false;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i == 0 ) {
|
|
|
|
cs->winding = CopyWinding( midwinding );
|
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
cs->winding = midwinding;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
vec_t v1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
v1 = BrushVolume( b[i] );
|
|
|
|
if ( v1 < 1.0 ) {
|
|
|
|
FreeBrush( b[i] );
|
|
|
|
b[i] = NULL;
|
|
|
|
Sys_FPrintf( SYS_VRB, "tiny volume after clip\n" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*front = b[0];
|
|
|
|
*back = b[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
SplitBrushList
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void SplitBrushList( bspbrush_t *brushes,
|
|
|
|
node_t *node, bspbrush_t **front, bspbrush_t **back ){
|
|
|
|
bspbrush_t *brush, *newbrush, *newbrush2;
|
|
|
|
side_t *side;
|
|
|
|
int sides;
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
*front = *back = NULL;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( brush = brushes ; brush ; brush = brush->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
sides = brush->side;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides == PSIDE_BOTH ) { // split into two brushes
|
|
|
|
SplitBrush( brush, node->planenum, &newbrush, &newbrush2 );
|
|
|
|
if ( newbrush ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
newbrush->next = *front;
|
|
|
|
*front = newbrush;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( newbrush2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
newbrush2->next = *back;
|
|
|
|
*back = newbrush2;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
newbrush = CopyBrush( brush );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// if the planenum is actualy a part of the brush
|
|
|
|
// find the plane and flag it as used so it won't be tried
|
|
|
|
// as a splitter again
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides & PSIDE_FACING ) {
|
|
|
|
for ( i = 0 ; i < newbrush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
side = newbrush->sides + i;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( side->planenum & ~1 ) == node->planenum ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->texinfo = TEXINFO_NODE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides & PSIDE_FRONT ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
newbrush->next = *front;
|
|
|
|
*front = newbrush;
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides & PSIDE_BACK ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
newbrush->next = *back;
|
|
|
|
*back = newbrush;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
BuildTree_r
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
node_t *BuildTree_r( node_t *node, bspbrush_t *brushes ){
|
|
|
|
node_t *newnode;
|
|
|
|
side_t *bestside;
|
|
|
|
int i;
|
|
|
|
bspbrush_t *children[2];
|
|
|
|
|
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_nodes++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( drawflag ) {
|
|
|
|
DrawBrushList( brushes, node );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// find the best plane to use as a splitter
|
2012-03-17 20:01:54 +00:00
|
|
|
bestside = SelectSplitSide( brushes, node );
|
|
|
|
if ( !bestside ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// leaf node
|
|
|
|
node->side = NULL;
|
|
|
|
node->planenum = -1;
|
2012-03-17 20:01:54 +00:00
|
|
|
LeafNode( node, brushes );
|
2007-11-04 03:34:51 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is a splitplane node
|
|
|
|
node->side = bestside;
|
2012-03-17 20:01:54 +00:00
|
|
|
node->planenum = bestside->planenum & ~1; // always use front facing
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SplitBrushList( brushes, node, &children[0], &children[1] );
|
|
|
|
FreeBrushList( brushes );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// allocate children before recursing
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
newnode = AllocNode();
|
2007-11-04 03:34:51 +00:00
|
|
|
newnode->parent = node;
|
|
|
|
node->children[i] = newnode;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SplitBrush( node->volume, node->planenum, &node->children[0]->volume,
|
|
|
|
&node->children[1]->volume );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// recursively process children
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
node->children[i] = BuildTree_r( node->children[i], children[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
BrushBSP
|
|
|
|
|
|
|
|
The incoming list will be freed before exiting
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
tree_t *BrushBSP( bspbrush_t *brushlist, vec3_t mins, vec3_t maxs ){
|
|
|
|
node_t *node;
|
|
|
|
bspbrush_t *b;
|
|
|
|
int c_faces, c_nonvisfaces;
|
|
|
|
int c_brushes;
|
|
|
|
tree_t *tree;
|
|
|
|
int i;
|
|
|
|
vec_t volume;
|
|
|
|
|
|
|
|
Sys_FPrintf( SYS_VRB, "--- BrushBSP ---\n" );
|
|
|
|
|
|
|
|
tree = AllocTree();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
c_faces = 0;
|
|
|
|
c_nonvisfaces = 0;
|
|
|
|
c_brushes = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = brushlist ; b ; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
c_brushes++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
volume = BrushVolume( b );
|
|
|
|
if ( volume < microvolume ) {
|
|
|
|
Sys_Printf( "WARNING: entity %i, brush %i: microbrush\n",
|
|
|
|
b->original->entitynum, b->original->brushnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < b->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->sides[i].bevel ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !b->sides[i].winding ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( b->sides[i].texinfo == TEXINFO_NODE ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( b->sides[i].visible ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_faces++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
c_nonvisfaces++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPointToBounds( b->mins, tree->mins, tree->maxs );
|
|
|
|
AddPointToBounds( b->maxs, tree->mins, tree->maxs );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%5i brushes\n", c_brushes );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i visible faces\n", c_faces );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i nonvisible faces\n", c_nonvisfaces );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
c_nodes = 0;
|
|
|
|
c_nonvis = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
node = AllocNode();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
node->volume = BrushFromBounds( mins, maxs );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
tree->headnode = node;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
node = BuildTree_r( node, brushlist );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i visible nodes\n", c_nodes / 2 - c_nonvis );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i nonvis nodes\n", c_nonvis );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i leafs\n", ( c_nodes + 1 ) / 2 );
|
2007-11-04 03:34:51 +00:00
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
{ // debug code
|
|
|
|
static node_t *tnode;
|
|
|
|
vec3_t p;
|
|
|
|
|
|
|
|
p[0] = -1469;
|
|
|
|
p[1] = -118;
|
|
|
|
p[2] = 119;
|
|
|
|
tnode = PointInLeaf( tree->headnode, p );
|
|
|
|
Sys_Printf( "contents: %i\n", tnode->contents );
|
|
|
|
p[0] = 0;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
#endif
|
|
|
|
return tree;
|
|
|
|
}
|