From a255fbd84e64e4f8bb6e6786b6f65579071742b6 Mon Sep 17 00:00:00 2001 From: Garux Date: Tue, 1 Aug 2017 13:35:36 +0300 Subject: [PATCH] Q3map2: * brush planes normals snap: +fix of vector-is-close-to-be-ON-axis case, was breaking slivers collisions, drawsurfs * alphamod scale: works now clean shiftBspMain --- tools/quake3/q3map2/main.c | 129 +++++++--------------------------- tools/quake3/q3map2/map.c | 6 +- tools/quake3/q3map2/shaders.c | 2 +- 3 files changed, 28 insertions(+), 109 deletions(-) diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index ae12f52d..98d77ef9 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -1508,7 +1508,7 @@ int ShiftBSPMain( int argc, char **argv ){ } } - /* get scale */ + /* get shift */ // if(argc-2 >= i) // always true scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] ); if ( argc - 3 >= i ) { @@ -1535,10 +1535,10 @@ int ShiftBSPMain( int argc, char **argv ){ Sys_Printf( "--- ShiftBSP ---\n" ); Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities ); - /* scale entity keys */ + /* shift entity keys */ for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) { - /* scale origin */ + /* shift origin */ GetVectorForKey( &entities[ i ], "origin", vec ); if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) { if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) { @@ -1556,7 +1556,7 @@ int ShiftBSPMain( int argc, char **argv ){ } - /* scale models */ + /* shift models */ for ( i = 0; i < numBSPModels; i++ ) { bspModels[ i ].mins[0] += scale[0]; @@ -1567,7 +1567,7 @@ int ShiftBSPMain( int argc, char **argv ){ bspModels[ i ].maxs[2] += scale[2]; } - /* scale nodes */ + /* shift nodes */ for ( i = 0; i < numBSPNodes; i++ ) { bspNodes[ i ].mins[0] += scale[0]; @@ -1578,7 +1578,7 @@ int ShiftBSPMain( int argc, char **argv ){ bspNodes[ i ].maxs[2] += scale[2]; } - /* scale leafs */ + /* shift leafs */ for ( i = 0; i < numBSPLeafs; i++ ) { bspLeafs[ i ].mins[0] += scale[0]; @@ -1588,117 +1588,36 @@ int ShiftBSPMain( int argc, char **argv ){ bspLeafs[ i ].maxs[1] += scale[1]; bspLeafs[ i ].maxs[2] += scale[2]; } -/* - if ( texscale ) { - Sys_Printf( "Using texture unlocking (and probably breaking texture alignment a lot)\n" ); - old_xyzst = safe_malloc( sizeof( *old_xyzst ) * numBSPDrawVerts * 5 ); - for ( i = 0; i < numBSPDrawVerts; i++ ) - { - old_xyzst[5 * i + 0] = bspDrawVerts[i].xyz[0]; - old_xyzst[5 * i + 1] = bspDrawVerts[i].xyz[1]; - old_xyzst[5 * i + 2] = bspDrawVerts[i].xyz[2]; - old_xyzst[5 * i + 3] = bspDrawVerts[i].st[0]; - old_xyzst[5 * i + 4] = bspDrawVerts[i].st[1]; - } - } -*/ - /* scale drawverts */ + + /* shift drawverts */ for ( i = 0; i < numBSPDrawVerts; i++ ) { bspDrawVerts[i].xyz[0] += scale[0]; bspDrawVerts[i].xyz[1] += scale[1]; bspDrawVerts[i].xyz[2] += scale[2]; -// bspDrawVerts[i].normal[0] /= scale[0]; -// bspDrawVerts[i].normal[1] /= scale[1]; -// bspDrawVerts[i].normal[2] /= scale[2]; -// VectorNormalize( bspDrawVerts[i].normal, bspDrawVerts[i].normal ); } -/* - if ( texscale ) { - for ( i = 0; i < numBSPDrawSurfaces; i++ ) - { - switch ( bspDrawSurfaces[i].surfaceType ) - { - case SURFACE_FACE: - case SURFACE_META: - if ( bspDrawSurfaces[i].numIndexes % 3 ) { - Error( "Not a triangulation!" ); - } - for ( j = bspDrawSurfaces[i].firstIndex; j < bspDrawSurfaces[i].firstIndex + bspDrawSurfaces[i].numIndexes; j += 3 ) - { - int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert, ib = bspDrawIndexes[j + 1] + bspDrawSurfaces[i].firstVert, ic = bspDrawIndexes[j + 2] + bspDrawSurfaces[i].firstVert; - bspDrawVert_t *a = &bspDrawVerts[ia], *b = &bspDrawVerts[ib], *c = &bspDrawVerts[ic]; - float *oa = &old_xyzst[ia * 5], *ob = &old_xyzst[ib * 5], *oc = &old_xyzst[ic * 5]; - // extrapolate: - // a->xyz -> oa - // b->xyz -> ob - // c->xyz -> oc - ExtrapolateTexcoords( - &oa[0], &oa[3], - &ob[0], &ob[3], - &oc[0], &oc[3], - a->xyz, a->st, - b->xyz, b->st, - c->xyz, c->st ); - } - break; - } - } - } -*/ - /* scale planes */ + + /* shift planes */ + + vec3_t point; for ( i = 0; i < numBSPPlanes; i++ ) { - if ( bspPlanes[ i ].dist > 0 ){ - if ( bspPlanes[ i ].normal[0] ){ - bspPlanes[ i ].dist += scale[0]; - continue; - } - else if ( bspPlanes[ i ].normal[1] ){ - bspPlanes[ i ].dist += scale[1]; - continue; - } - else if ( bspPlanes[ i ].normal[2] ){ - bspPlanes[ i ].dist += scale[2]; - continue; - } - } - else{ - if ( bspPlanes[ i ].normal[0] ){ - bspPlanes[ i ].dist -= scale[0]; - continue; - } - else if ( bspPlanes[ i ].normal[1] ){ - bspPlanes[ i ].dist -= scale[1]; - continue; - } - else if ( bspPlanes[ i ].normal[2] ){ - bspPlanes[ i ].dist -= scale[2]; - continue; - } + //find point on plane + for ( j=0; j<3; j++ ){ + if ( fabs( bspPlanes[ i ].normal[j] ) > 0.5 ){ + point[j] = bspPlanes[ i ].dist / bspPlanes[ i ].normal[j]; + point[(j+1)%3] = point[(j+2)%3] = 0; + break; + } } - } - - -/* if ( uniform ) { - for ( i = 0; i < numBSPPlanes; i++ ) - { - bspPlanes[ i ].dist += scale[0]; + //shift point + for ( j=0; j<3; j++ ){ + point[j] += scale[j]; } + //calc new plane dist + bspPlanes[ i ].dist = DotProduct( point, bspPlanes[ i ].normal ); } - else - { - for ( i = 0; i < numBSPPlanes; i++ ) - { -// bspPlanes[ i ].normal[0] /= scale[0]; -// bspPlanes[ i ].normal[1] /= scale[1]; -// bspPlanes[ i ].normal[2] /= scale[2]; - f = 1 / VectorLength( bspPlanes[i].normal ); - VectorScale( bspPlanes[i].normal, f, bspPlanes[i].normal ); - bspPlanes[ i ].dist *= f; - } - }*/ /* scale gridsize */ /* diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 7014ec44..8f56f9af 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -164,10 +164,10 @@ qboolean SnapNormal( vec3_t normal ){ // normalized). The original SnapNormal() didn't snap such vectors - it // only snapped vectors that were near a perfect axis. - //adjusting vectors, that were near a perfect axis, with bigger epsilon + //adjusting vectors, that are near perfect axis, with bigger epsilon //they cause precision errors - /* + if ( ( normal[0] != 0.0 || normal[1] != 0.0 ) && fabs(normal[0]) < 0.00025 && fabs(normal[1]) < 0.00025){ normal[0] = normal[1] = 0.0; adjusted = qtrue; @@ -180,7 +180,7 @@ qboolean SnapNormal( vec3_t normal ){ normal[2] = normal[1] = 0.0; adjusted = qtrue; } - */ + /* for ( i=0; i<30; i++ ) diff --git a/tools/quake3/q3map2/shaders.c b/tools/quake3/q3map2/shaders.c index 7127362a..8e3b4cb1 100644 --- a/tools/quake3/q3map2/shaders.c +++ b/tools/quake3/q3map2/shaders.c @@ -70,7 +70,7 @@ void ColorMod( colorMod_t *cm, int numVerts, bspDrawVert_t *drawVerts ){ VectorSet( mult, 1.0f, 1.0f, 1.0f ); mult[ 3 ] = 1.0f; VectorSet( add, 0.0f, 0.0f, 0.0f ); - mult[ 3 ] = 0.0f; + add[ 3 ] = 0.0f; /* switch on type */ switch ( cm2->type ) -- 2.39.2