29 #include "../../../idlib/precompiled.h"
80 #define SNAP_FRACTIONS 32
84 #define VERTEX_EPSILON ( 1.0 / SNAP_FRACTIONS )
86 #define COLINEAR_EPSILON ( 1.8 * VERTEX_EPSILON )
99 static int numHashVerts, numTotalVerts;
100 static int hashIntMins[3], hashIntScale[3];
118 for ( i = 0 ; i < 3 ; i++ ) {
120 block[
i] = ( iv[
i] - hashIntMins[
i] ) / hashIntScale[i];
121 if ( block[i] < 0 ) {
130 for ( hv = hashVerts[block[0]][block[1]][block[2]] ; hv ; hv = hv->
next ) {
132 if ( hv->
iv[0] == iv[0] && hv->
iv[1] == iv[1] && hv->
iv[2] == iv[2] ) {
137 for ( i = 0 ; i < 3 ; i++ ) {
139 d = hv->
iv[
i] - iv[
i];
140 if ( d < -1 || d > 1 ) {
154 hv->
next = hashVerts[block[0]][block[1]][block[2]];
155 hashVerts[block[0]][block[1]][block[2]] = hv;
181 static void HashBlocksForTri(
const mapTri_t *tri,
int blocks[2][3] ) {
191 for ( i = 0 ; i < 3 ; i++ ) {
192 blocks[0][
i] = ( bounds[0][
i] - 1.0 - hashBounds[0][
i] ) / hashScale[i];
193 if ( blocks[0][i] < 0 ) {
195 }
else if ( blocks[0][i] >=
HASH_BINS ) {
199 blocks[1][
i] = ( bounds[1][
i] + 1.0 - hashBounds[0][
i] ) / hashScale[i];
200 if ( blocks[1][i] < 0 ) {
202 }
else if ( blocks[1][i] >=
HASH_BINS ) {
223 memset( hashVerts, 0,
sizeof( hashVerts ) );
230 for ( group = groupList ; group ; group = group->
nextGroup ) {
239 for ( i = 0 ; i < 3 ; i++ ) {
240 hashBounds[0][
i] = floor( hashBounds[0][i] - 1 );
241 hashBounds[1][
i] = ceil( hashBounds[1][i] + 1 );
244 hashScale[
i] = ( hashBounds[1][
i] - hashBounds[0][
i] ) /
HASH_BINS;
246 if ( hashIntScale[i] < 1 ) {
252 for ( group = groupList ; group ; group = group->
nextGroup ) {
258 for ( vert = 0 ; vert < 3 ; vert++ ) {
280 for ( hv = hashVerts[i][j][k] ; hv ; hv =
next ) {
287 memset( hashVerts, 0,
sizeof( hashVerts ) );
323 for ( i = 0 ; i < 3 ; i++ ) {
333 if ( d <= 0 || d >= len ) {
349 split.
st[0] = v1->
st[0] + frac * ( v2->
st[0] - v1->
st[0] );
350 split.
st[1] = v1->
st[1] + frac * ( v2->
st[1] - v1->
st[1] );
358 new1->
v[(i+1)%3] = split;
415 HashBlocksForTri( tri, blocks );
416 for ( i = blocks[0][0] ; i <= blocks[1][0] ; i++ ) {
417 for ( j = blocks[0][1] ; j <= blocks[1][1] ; j++ ) {
418 for ( k = blocks[0][2] ; k <= blocks[1][2] ; k++ ) {
419 for ( hv = hashVerts[i][j][k] ; hv ; hv = hv->
next ) {
425 a = FixTriangleAgainstHashVert( test, hv );
454 for ( ; groupList ; groupList = groupList->
nextGroup ) {
470 int startCount, endCount;
484 common->
Printf(
"----- FixAreaGroupsTjunctions -----\n" );
490 for ( group = groupList ; group ; group = group->
nextGroup ) {
497 for ( tri = group->
triList ; tri ; tri = tri->
next ) {
498 fixed = FixTriangleAgainstHash( tri );
520 for ( i = 0 ; i < e->
numAreas ; i++ ) {
541 memset( hashVerts, 0,
sizeof( hashVerts ) );
548 for ( areaNum = 0 ; areaNum < e->
numAreas ; areaNum++ ) {
559 for ( i = 0 ; i < 3 ; i++ ) {
560 hashBounds[0][
i] = floor( hashBounds[0][i] - 1 );
561 hashBounds[1][
i] = ceil( hashBounds[1][i] + 1 );
564 hashScale[
i] = ( hashBounds[1][
i] - hashBounds[0][
i] ) /
HASH_BINS;
566 if ( hashIntScale[i] < 1 ) {
572 for ( areaNum = 0 ; areaNum < e->
numAreas ; areaNum++ ) {
580 for ( vert = 0 ; vert < 3 ; vert++ ) {
600 if ( !strstr( modelName,
".lwo" ) && !strstr( modelName,
".ase" ) && !strstr( modelName,
".ma" ) ) {
612 if ( angle != 0.0
f ) {
626 memset( &mapTri, 0,
sizeof( mapTri ) );
632 for (
int j = 0 ; j < tri->
numVerts ; j += 3 ) {
643 for ( areaNum = 0 ; areaNum < e->
numAreas ; areaNum++ ) {
652 mapTri_t *fixed = FixTriangleAgainstHash( tri );
float GetFloat(const char *key, const char *defaultString="0") const
bool FromPoints(const idVec3 &p1, const idVec3 &p2, const idVec3 &p3, bool fixDegenerate=true)
mapTri_t * CopyMapTri(const mapTri_t *tri)
#define VectorSubtract(a, b, c)
const idMaterial * shader
void FixAreaGroupsTjunctions(optimizeGroup_t *groupList)
const struct hashVert_s * hashVert[3]
void FreeTri(mapTri_t *tri)
void FixEntityTjunctions(uEntity_t *e)
void FreeTJunctionHash(void)
struct hashVert_s * GetHashVert(idVec3 &v)
mapTri_t * MergeTriLists(mapTri_t *a, mapTri_t *b)
int Icmp(const char *text) const
void FreeTriList(mapTri_t *a)
int CountGroupListTris(const optimizeGroup_t *groupList)
struct optimizeGroup_s * groups
bool AddPoint(const idVec3 &v)
GLfloat GLfloat GLfloat v2
const char * GetString(const char *key, const char *defaultString="") const
srfTriangles_t * geometry
virtual idRenderModel * FindModel(const char *modelName)=0
idVec3 GetVector(const char *key, const char *defaultString=NULL) const
virtual const modelSurface_t * Surface(int surfaceNum) const =0
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
GLfloat GLfloat GLfloat GLfloat v3
idRenderModelManager * renderModelManager
void HashTriangles(optimizeGroup_t *groupList)
const idMaterial * material
idMat3 ToMat3(void) const
int CountTriList(const mapTri_t *list)
struct optimizeGroup_s * nextGroup
const idMaterial * material
void * Mem_Alloc(const int size)
#define VectorMA(v, s, b, o)
idMat3 GetMatrix(const char *key, const char *defaultString=NULL) const
dmapGlobals_t dmapGlobals
void FixGlobalTjunctions(uEntity_t *e)
bool IsDiscrete(void) const
struct hashVert_s hashVert_t
virtual int NumSurfaces() const =0