29 #include "../../../idlib/precompiled.h"
34 #define BRUSH_EPSILON 0.1f
35 #define BRUSH_PLANE_NORMAL_EPSILON 0.00001f
36 #define BRUSH_PLANE_DIST_EPSILON 0.01f
38 #define OUTPUT_UPDATE_TIME 500 // update every 500 msec
50 static int lastUpdateTime;
55 va_start( argPtr,
string );
59 lastUpdateTime = time;
133 *front = *back =
NULL;
135 winding->
Split( splitPlane, 0.0
f, &frontWinding, &backWinding );
137 if ( frontWinding ) {
139 (*front)->winding = frontWinding;
140 (*front)->flags =
flags;
145 (*back)->winding = backWinding;
146 (*back)->flags =
flags;
149 if ( frontWinding && backWinding ) {
152 else if ( frontWinding ) {
199 for ( i = 0; i <
sides.
Num(); i++ ) {
201 if (
sides[i]->winding ) {
222 for ( i = 0; i <
sides.
Num(); i++ ) {
249 for ( i = 0; i < 3; i++ ) {
273 for ( i = 0; i <
sides.
Num(); i++ ) {
296 for ( i = 0; i < 3; i++ ) {
316 for ( i = 0; i < sideList.
Num(); i++ ) {
333 idVec3 normal, axialNormal;
339 for ( i = 1; i < 3; i++ ) {
345 if ( windingPlane.
Normal()[bestAxis] > 0.0f ) {
346 axialNormal[bestAxis] = 1.0f;
349 axialNormal[bestAxis] = -1.0f;
354 normal = ( w[
j].ToVec3() - w[
i].ToVec3() ).Cross( axialNormal );
364 for ( i = 0; i <
sides.
Num(); i++ ) {
388 for ( axis = 0; axis < 3; axis++ ) {
389 for ( dir = -1; dir <= 1; dir += 2 ) {
393 plane.
SetDist( dir * bounds[(dir == 1)][axis] );
408 bool transformed =
false;
411 for ( i = 0; i <
sides.
Num(); i++ ) {
417 for ( i = 0; i <
sides.
Num(); i++ ) {
418 sides[
i]->plane.TranslateSelf( origin );
436 float d, area, volume;
440 for ( i = 0; i <
sides.
Num(); i++ ) {
449 corner = (*w)[0].ToVec3();
458 d = -( corner *
sides[
i]->plane.Normal() -
sides[
i]->plane.Dist() );
463 return ( volume * ( 1.0
f / 3.0
f ) );
478 for ( i = 0; i < b->
sides.
Num() &&
in; i++ ) {
506 int i,
j, k,
l, m, seperatingPlane;
512 for ( i = 0; i < 3; i++ ) {
522 seperatingPlane = -1;
527 if ( seperatingPlane != -1 ) {
535 if ( seperatingPlane == -1 ) {
542 for ( i = 0; i < 2; i++ ) {
549 if ( !( ( brushes[i]->
GetSide(k)->GetPlaneNum() ^ seperatingPlane ) >> 1 ) ) {
563 if ( !( ( brushes[j]->
GetSide(l)->GetPlaneNum() ^ seperatingPlane ) >> 1 ) ) {
568 if ( plane->
Distance( (*w)[m].ToVec3() ) > 0.1
f ) {
621 float dist, maxBack, maxFront, *maxBackWinding, *maxFrontWinding;
647 maxBackWinding = (
float *) _alloca16(
sides.
Num() *
sizeof(
float) );
648 maxFrontWinding = (
float *) _alloca16(
sides.
Num() *
sizeof(
float) );
650 maxFront = maxBack = 0.0f;
651 for ( i = 0; i <
sides.
Num(); i++ ) {
660 maxBackWinding[
i] = 10.0f;
661 maxFrontWinding[
i] = -10.0f;
665 dist = plane.
Distance( (*w)[j].ToVec3() );
666 if ( dist > maxFrontWinding[i] ) {
667 maxFrontWinding[
i] = dist;
669 if ( dist < maxBackWinding[i] ) {
670 maxBackWinding[
i] = dist;
674 if ( maxFrontWinding[i] > maxFront ) {
675 maxFront = maxFrontWinding[
i];
677 if ( maxBackWinding[i] < maxBack ) {
678 maxBack = maxBackWinding[
i];
698 for ( i = 0; i <
sides.
Num() && mid; i++ ) {
707 else if ( mid->
IsHuge() ) {
719 if ( maxFront > - maxBack ) {
733 if ( !front && !back ) {
747 for ( i = 0; i <
sides.
Num(); i++ ) {
760 (*back)->sides.Append( side->
Copy() );
764 side->
Split( plane, &frontSide, &backSide );
766 (*front)->sides.Append( frontSide );
773 (*front)->sides.Append( side );
776 (*back)->sides.Append( backSide );
783 (*back)->sides.Append( side );
791 (*front)->sides.Append( side );
792 (*front)->windingsValid =
true;
793 (*front)->BoundBrush(
this );
798 (*back)->sides.Append( side );
799 (*back)->windingsValid =
true;
800 (*back)->BoundBrush(
this );
810 #define BRUSH_BEVEL_EPSILON 0.1f
824 for ( axis = 0; axis < 3; axis++ ) {
826 for ( dir = -1; dir <= 1; dir += 2, order++ ) {
829 for ( i = 0; i <
sides.
Num(); i++ ) {
836 if (
sides[i]->plane.
Normal()[axis] <= -0.9999f ) {
860 for ( i = 0; i <
sides.
Num(); i++ ) {
869 vec = (*w)[
j].ToVec3() - (*w)[k].ToVec3();
873 for ( k = 0; k < 3; k++ ) {
874 if ( vec[k] == 1.0
f || vec[k] == -1.0
f || (vec[k] == 0.0
f && vec[(k+1)%3] == 0.0
f) ) {
883 for ( axis = 0; axis < 3; axis++ ) {
885 for ( dir = -1; dir <= 1; dir += 2 ) {
890 normal = vec.
Cross( normal );
899 for ( k = 0; k <
sides.
Num(); k++ ) {
906 w2 =
sides[k]->winding;
912 d = plane.
Distance( (*w2)[l].ToVec3() );
921 if ( l < w2->GetNumPoints() ) {
956 for ( i = 0; i <
sides.
Num(); i++ ) {
959 for ( j = 0; j < 3; j++ ) {
1003 for ( i = 0; i <
sides.
Num(); i++ ) {
1076 for ( brush = list.
head; brush; brush = next ) {
1116 for ( brush = list.
head; brush; brush = next ) {
1198 for ( brush =
head; brush; brush = brush->
next ) {
1212 for ( brush =
head; brush; brush = next ) {
1231 if ( !useBrushSavedPlaneSide ) {
1233 b->
Split( plane, planeNum, &front, &back );
1246 b->
Split( plane, planeNum, &front, &back );
1274 #ifdef OUTPUT_CHOP_STATS
1281 for ( b1 = this->
Head(); b1; b1 = this->
Head() ) {
1283 for ( b2 = b1->
next; b2; b2 = next ) {
1287 for ( i = 0; i < 3; i++ ) {
1306 if ( j < b2->GetNumSides() ) {
1310 if ( i < b1->GetNumSides() ) {
1321 if ( !ChopAllowed || ChopAllowed( b2, b1 ) ) {
1335 if ( !ChopAllowed || ChopAllowed( b1, b2 ) ) {
1354 if ( c1 > 2 && c2 > 2 ) {
1378 #ifdef OUTPUT_CHOP_STATS
1386 #ifdef OUTPUT_CHOP_STATS
1408 for ( b1 =
Head(); b1; b1 = b1->
next ) {
1410 for ( b2 =
Head(); b2; b2 = nextb2 ) {
1411 nextb2 = b2->
Next();
1421 if ( b1->
TryMerge( b2, planeList ) ) {
1471 planeList.
Resize( 512, 128 );
1521 texture =
"textures/washroom/btile01";
1579 for ( b = brushList.
Head();
b; b = b->
Next() ) {
idBrushMap(const idStr &fileName, const idStr &ext)
#define BRUSH_PLANE_DIST_EPSILON
#define BRUSH_PLANESIDE_BOTH
void AddBevelsForAxialBox(void)
idStr & SetFileExtension(const char *extension)
float GetArea(void) const
assert(prefInfo.fullscreenBtn)
const idVec3 & Normal(void) const
bool Compare(const idPlane &p) const
#define BRUSH_BEVEL_EPSILON
void Transform(const idVec3 &origin, const idMat3 &axis)
#define BRUSH_PLANE_NORMAL_EPSILON
idList< idBrushSide * > sides
float Distance(const idVec3 &v) const
void CreatePlaneList(idPlaneSet &planeList) const
const idWinding * GetWinding(void) const
bool Subtract(const idBrush *b, idBrushList &list) const
bool RemoveSidesWithoutWinding(void)
float GetVolume(void) const
int Sys_Milliseconds(void)
void ExpandForAxialBox(const idBounds &bounds)
idBrush * Copy(void) const
idFileSystem * fileSystem
void Split(const idPlane &plane, int planeNum, idBrushList &frontList, idBrushList &backList, bool useBrushSavedPlaneSide=false)
int Split(const idPlane &splitPlane, idBrushSide **front, idBrushSide **back) const
void Chop(bool(*ChopAllowed)(idBrush *b1, idBrush *b2))
idBrushSide * Copy(void) const
idBrushSide * GetSide(int i) const
idWinding * Reverse(void) const
void SetNormal(const idVec3 &normal)
idWinding * Clip(const idPlane &plane, const float epsilon=ON_EPSILON, const bool keepOn=false)
idVec3 Cross(const idVec3 &a) const
bool IsRotated(void) const
const int CURRENT_MAP_VERSION
int FindPlane(const idPlane &plane, const float normalEps, const float distEps)
int PlaneSide(const idPlane &plane, const float epsilon=ON_EPSILON) const
bool AddPoint(const idVec3 &v)
void Delete(idBrush *brush)
idBrush * Head(void) const
bool FromWinding(const idWinding &w, const idPlane &windingPlane)
bool CreateWindings(void)
GLdouble GLdouble GLint GLint order
int GetNumPoints(void) const
GLubyte GLubyte GLubyte GLubyte w
void SetDist(const float dist)
idStr & StripFileExtension(void)
void Remove(idBrush *brush)
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
void AddToTail(idBrush *brush)
static float Fabs(float f)
float PlaneDistance(const idPlane &plane) const
const idBounds & GetBounds(void) const
virtual idFile * OpenFileWrite(const char *relativePath, const char *basePath="fs_savepath")=0
virtual int WriteFloatString(const char *fmt,...) id_attribute((format(printf
#define OUTPUT_UPDATE_TIME
void WriteBrushList(const idBrushList &brushList)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
void WriteBrushMap(const idStr &fileName, const idStr &ext) const
void AddToFront(idBrush *brush)
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
void BoundBrush(const idBrush *original=NULL)
idBrush * Next(void) const
int Split(const idPlane &plane, const float epsilon, idWinding **front, idWinding **back) const
int Append(const type &obj)
void SetPlaneNum(int num)
bool RemoveIndex(int index)
idBrushList * Copy(void) const
idWinding * Copy(void) const
const idPlane & GetPlane(void) const
int vsprintf(idStr &string, const char *fmt, va_list argptr)
const char * c_str(void) const
void SetFlagOnFacingBrushSides(const idPlane &plane, int flag)
void Merge(bool(*MergeAllowed)(idBrush *b1, idBrush *b2))
void DisplayRealTimeString(char *string,...)
bool FromBounds(const idBounds &bounds)
int GetNumSides(void) const
virtual void CloseFile(idFile *f)=0
int PlaneSide(const idPlane &plane, const float epsilon=ON_EPSILON) const
bool MergeAllowed(idBrush *b1, idBrush *b2)
virtual void Error(const char *fmt,...) id_attribute((format(printf
void WriteBrush(const idBrush *brush)
idBounds GetBounds(void) const
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
bool FromSides(idList< idBrushSide * > &sideList)
bool TryMerge(const idBrush *brush, const idPlaneSet &planeList)
#define BRUSH_PLANESIDE_FRONT
void FitThroughPoint(const idVec3 &p)
int Split(const idPlane &plane, int planeNum, idBrush **front, idBrush **back) const