2008-07-25 07:31:37 +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
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
----------------------------------------------------------------------------------
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This code has been altered significantly from its original form, to support
|
|
|
|
several games based on the Quake III Arena engine, in the form of "Q3Map2."
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
------------------------------------------------------------------------------- */
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* marker */
|
|
|
|
#define MAP_C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dependencies */
|
|
|
|
#include "q3map2.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME: remove these vars */
|
|
|
|
|
|
|
|
/* undefine to make plane finding use linear sort (note: really slow) */
|
2012-03-17 20:01:54 +00:00
|
|
|
#define USE_HASHING
|
|
|
|
#define PLANE_HASHES 8192
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
plane_t *planehash[ PLANE_HASHES ];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_boxbevels;
|
|
|
|
int c_edgebevels;
|
|
|
|
int c_areaportals;
|
|
|
|
int c_detail;
|
|
|
|
int c_structural;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
PlaneEqual()
|
|
|
|
ydnar: replaced with variable epsilon for djbob
|
|
|
|
*/
|
|
|
|
|
|
|
|
qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ){
|
|
|
|
float ne, de;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get local copies */
|
|
|
|
ne = normalEpsilon;
|
|
|
|
de = distanceEpsilon;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* compare */
|
2011-01-10 06:15:47 +00:00
|
|
|
// We check equality of each component since we're using '<', not '<='
|
|
|
|
// (the epsilons may be zero). We want to use '<' intead of '<=' to be
|
|
|
|
// consistent with the true meaning of "epsilon", and also because other
|
|
|
|
// parts of the code uses this inequality.
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( p->dist == dist || fabs( p->dist - dist ) < de ) &&
|
|
|
|
( p->normal[0] == normal[0] || fabs( p->normal[0] - normal[0] ) < ne ) &&
|
|
|
|
( p->normal[1] == normal[1] || fabs( p->normal[1] - normal[1] ) < ne ) &&
|
|
|
|
( p->normal[2] == normal[2] || fabs( p->normal[2] - normal[2] ) < ne ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* different */
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPlaneToHash()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void AddPlaneToHash( plane_t *p ){
|
|
|
|
int hash;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
hash = ( PLANE_HASHES - 1 ) & (int) fabs( p->dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
p->hash_chain = planehash[hash];
|
|
|
|
planehash[hash] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
CreateNewFloatPlane
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int CreateNewFloatPlane( vec3_t normal, vec_t dist ){
|
|
|
|
plane_t *p, temp;
|
|
|
|
|
|
|
|
if ( VectorLength( normal ) < 0.5 ) {
|
|
|
|
Sys_Printf( "FloatPlane: bad normal\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a new plane
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( nummapplanes + 2 > MAX_MAP_PLANES ) {
|
|
|
|
Error( "MAX_MAP_PLANES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
p = &mapplanes[nummapplanes];
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( normal, p->normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
p->dist = dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
p->type = ( p + 1 )->type = PlaneTypeForNormal( p->normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorSubtract( vec3_origin, normal, ( p + 1 )->normal );
|
|
|
|
( p + 1 )->dist = -dist;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
nummapplanes += 2;
|
|
|
|
|
|
|
|
// allways put axial planes facing positive first
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->type < 3 ) {
|
|
|
|
if ( p->normal[0] < 0 || p->normal[1] < 0 || p->normal[2] < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// flip order
|
|
|
|
temp = *p;
|
2012-03-17 20:01:54 +00:00
|
|
|
*p = *( p + 1 );
|
|
|
|
*( p + 1 ) = temp;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPlaneToHash( p );
|
|
|
|
AddPlaneToHash( p + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
return nummapplanes - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPlaneToHash( p );
|
|
|
|
AddPlaneToHash( p + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
return nummapplanes - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapNormal()
|
|
|
|
Snaps a near-axial normal vector.
|
|
|
|
Returns qtrue if and only if the normal was adjusted.
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean SnapNormal( vec3_t normal ){
|
2011-01-12 03:21:31 +00:00
|
|
|
#if Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX
|
2012-03-17 20:01:54 +00:00
|
|
|
int i;
|
|
|
|
qboolean adjusted = qfalse;
|
2011-01-10 06:15:47 +00:00
|
|
|
|
|
|
|
// A change from the original SnapNormal() is that we snap each
|
|
|
|
// component that's close to 0. So for example if a normal is
|
|
|
|
// (0.707, 0.707, 0.0000001), it will get snapped to lie perfectly in the
|
|
|
|
// XY plane (its Z component will be set to 0 and its length will be
|
|
|
|
// normalized). The original SnapNormal() didn't snap such vectors - it
|
|
|
|
// only snapped vectors that were near a perfect axis.
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < 3; i++ )
|
2011-01-10 06:15:47 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( normal[i] != 0.0 && -normalEpsilon < normal[i] && normal[i] < normalEpsilon ) {
|
2011-01-10 06:15:47 +00:00
|
|
|
normal[i] = 0.0;
|
|
|
|
adjusted = qtrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( adjusted ) {
|
|
|
|
VectorNormalize( normal, normal );
|
2011-01-10 06:15:47 +00:00
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
return qfalse;
|
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2011-01-10 06:15:47 +00:00
|
|
|
// I would suggest that you uncomment the following code and look at the
|
|
|
|
// results:
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf("normalEpsilon is %f\n", normalEpsilon);
|
|
|
|
for (i = 0;; i++)
|
|
|
|
{
|
|
|
|
normal[0] = 1.0;
|
|
|
|
normal[1] = 0.0;
|
|
|
|
normal[2] = i * 0.000001;
|
|
|
|
VectorNormalize(normal, normal);
|
|
|
|
if (1.0 - normal[0] >= normalEpsilon) {
|
|
|
|
Sys_Printf("(%f %f %f)\n", normal[0], normal[1], normal[2]);
|
|
|
|
Error("SnapNormal: test completed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2011-01-10 06:15:47 +00:00
|
|
|
|
|
|
|
// When the normalEpsilon is 0.00001, the loop will break out when normal is
|
|
|
|
// (0.999990 0.000000 0.004469). In other words, this is the vector closest
|
|
|
|
// to axial that will NOT be snapped. Anything closer will be snaped. Now,
|
|
|
|
// 0.004469 is close to 1/225. The length of a circular quarter-arc of radius
|
|
|
|
// 1 is PI/2, or about 1.57. And 0.004469/1.57 is about 0.0028, or about
|
|
|
|
// 1/350. Expressed a different way, 1/350 is also about 0.26/90.
|
|
|
|
// This means is that a normal with an angle that is within 1/4 of a degree
|
|
|
|
// from axial will be "snapped". My belief is that the person who wrote the
|
|
|
|
// code below did not intend it this way. I think the person intended that
|
|
|
|
// the epsilon be measured against the vector components close to 0, not 1.0.
|
|
|
|
// I think the logic should be: if 2 of the normal components are within
|
|
|
|
// epsilon of 0, then the vector can be snapped to be perfectly axial.
|
|
|
|
// We may consider adjusting the epsilon to a larger value when we make this
|
|
|
|
// code fix.
|
|
|
|
|
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 ( fabs( normal[ i ] - 1 ) < normalEpsilon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorClear( normal );
|
|
|
|
normal[ i ] = 1;
|
2011-01-10 06:15:47 +00:00
|
|
|
return qtrue;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fabs( normal[ i ] - -1 ) < normalEpsilon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorClear( normal );
|
|
|
|
normal[ i ] = -1;
|
2011-01-10 06:15:47 +00:00
|
|
|
return qtrue;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-10 06:15:47 +00:00
|
|
|
return qfalse;
|
|
|
|
#endif
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapPlane()
|
|
|
|
snaps a plane to normal/distance epsilons
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void SnapPlane( vec3_t normal, vec_t *dist ){
|
2008-07-25 07:31:37 +00:00
|
|
|
// SnapPlane disabled by LordHavoc because it often messes up collision
|
|
|
|
// brushes made from triangles of embedded models, and it has little effect
|
|
|
|
// on anything else (axial planes are usually derived from snapped points)
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapPlane reenabled by namespace because of multiple reports of
|
|
|
|
q3map2-crashes which were triggered by this patch.
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
SnapNormal( normal );
|
|
|
|
|
2011-01-10 06:15:47 +00:00
|
|
|
// TODO: Rambetter has some serious comments here as well. First off,
|
|
|
|
// in the case where a normal is non-axial, there is nothing special
|
|
|
|
// about integer distances. I would think that snapping a distance might
|
|
|
|
// make sense for axial normals, but I'm not so sure about snapping
|
|
|
|
// non-axial normals. A shift by 0.01 in a plane, multiplied by a clipping
|
|
|
|
// against another plane that is 5 degrees off, and we introduce 0.1 error
|
|
|
|
// easily. A 0.1 error in a vertex is where problems start to happen, such
|
|
|
|
// as disappearing triangles.
|
|
|
|
|
|
|
|
// Second, assuming we have snapped the normal above, let's say that the
|
|
|
|
// plane we just snapped was defined for some points that are actually
|
|
|
|
// quite far away from normal * dist. Well, snapping the normal in this
|
|
|
|
// case means that we've just moved those points by potentially many units!
|
|
|
|
// Therefore, if we are going to snap the normal, we need to know the
|
|
|
|
// points we're snapping for so that the plane snaps with those points in
|
|
|
|
// mind (points remain close to the plane).
|
|
|
|
|
|
|
|
// I would like to know exactly which problems SnapPlane() is trying to
|
|
|
|
// solve so that we can better engineer it (I'm not saying that SnapPlane()
|
|
|
|
// should be removed altogether). Fix all this snapping code at some point!
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fabs( *dist - Q_rint( *dist ) ) < distanceEpsilon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*dist = Q_rint( *dist );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 06:15:47 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapPlaneImproved()
|
|
|
|
snaps a plane to normal/distance epsilons, improved code
|
|
|
|
*/
|
|
|
|
void SnapPlaneImproved( vec3_t normal, vec_t *dist, int numPoints, const vec3_t *points ){
|
|
|
|
int i;
|
|
|
|
vec3_t center;
|
|
|
|
vec_t distNearestInt;
|
|
|
|
|
|
|
|
if ( SnapNormal( normal ) ) {
|
|
|
|
if ( numPoints > 0 ) {
|
2011-01-10 06:15:47 +00:00
|
|
|
// Adjust the dist so that the provided points don't drift away.
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorClear( center );
|
|
|
|
for ( i = 0; i < numPoints; i++ )
|
2011-01-10 06:15:47 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorAdd( center, points[i], center );
|
2011-01-10 06:15:47 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < 3; i++ ) { center[i] = center[i] / numPoints; }
|
|
|
|
*dist = DotProduct( normal, center );
|
2011-01-10 06:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( VectorIsOnAxis( normal ) ) {
|
2011-01-10 06:15:47 +00:00
|
|
|
// Only snap distance if the normal is an axis. Otherwise there
|
|
|
|
// is nothing "natural" about snapping the distance to an integer.
|
2012-03-17 20:01:54 +00:00
|
|
|
distNearestInt = Q_rint( *dist );
|
|
|
|
if ( -distanceEpsilon < *dist - distNearestInt && *dist - distNearestInt < distanceEpsilon ) {
|
2011-01-10 06:15:47 +00:00
|
|
|
*dist = distNearestInt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
FindFloatPlane()
|
|
|
|
ydnar: changed to allow a number of test points to be supplied that
|
|
|
|
must be within an epsilon distance of the plane
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points )
|
|
|
|
|
|
|
|
#ifdef USE_HASHING
|
|
|
|
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int i, j, hash, h;
|
|
|
|
plane_t *p;
|
|
|
|
vec_t d;
|
|
|
|
|
|
|
|
|
2011-01-12 03:21:31 +00:00
|
|
|
#if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points );
|
2011-01-10 06:15:47 +00:00
|
|
|
#else
|
2007-11-04 03:34:51 +00:00
|
|
|
SnapPlane( normal, &dist );
|
2011-01-10 06:15:47 +00:00
|
|
|
#endif
|
|
|
|
/* hash the plane */
|
2012-03-17 20:01:54 +00:00
|
|
|
hash = ( PLANE_HASHES - 1 ) & (int) fabs( dist );
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* search the border bins as well */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = -1; i <= 1; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
h = ( hash + i ) & ( PLANE_HASHES - 1 );
|
|
|
|
for ( p = planehash[ h ]; p != NULL; p = p->hash_chain )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* do standard plane compare */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !PlaneEqual( p, normal, dist ) ) {
|
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
|
|
|
/* ydnar: uncomment the following line for old-style plane finding */
|
|
|
|
//% return p - mapplanes;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: test supplied points against this plane */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < numPoints; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2011-01-10 06:15:47 +00:00
|
|
|
// NOTE: When dist approaches 2^16, the resolution of 32 bit floating
|
|
|
|
// point number is greatly decreased. The distanceEpsilon cannot be
|
|
|
|
// very small when world coordinates extend to 2^16. Making the
|
|
|
|
// dot product here in 64 bit land will not really help the situation
|
|
|
|
// because the error will already be carried in dist.
|
2007-11-04 03:34:51 +00:00
|
|
|
d = DotProduct( points[ j ], normal ) - dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
d = fabs( d );
|
|
|
|
if ( d != 0.0 && d >= distanceEpsilon ) {
|
2011-01-10 06:15:47 +00:00
|
|
|
break; // Point is too far from plane.
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* found a matching plane */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( j >= numPoints ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return p - mapplanes;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* none found, so create a new one */
|
|
|
|
return CreateNewFloatPlane( normal, dist );
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int i;
|
|
|
|
plane_t *p;
|
|
|
|
|
2011-01-12 03:21:31 +00:00
|
|
|
#if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points );
|
2011-01-10 06:15:47 +00:00
|
|
|
#else
|
2007-11-04 03:34:51 +00:00
|
|
|
SnapPlane( normal, &dist );
|
2011-01-10 06:15:47 +00:00
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0, p = mapplanes; i < nummapplanes; i++, p++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( PlaneEqual( p, normal, dist ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return i;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2011-01-10 06:15:47 +00:00
|
|
|
// TODO: Note that the non-USE_HASHING code does not compute epsilons
|
|
|
|
// for the provided points. It should do that. I think this code
|
|
|
|
// is unmaintained because nobody sets USE_HASHING to off.
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
return CreateNewFloatPlane( normal, dist );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
MapPlaneFromPoints()
|
|
|
|
takes 3 points and finds the plane they lie in
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int MapPlaneFromPoints( vec3_t *p ){
|
2011-01-12 03:21:31 +00:00
|
|
|
#if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_accu_t paccu[3];
|
|
|
|
vec3_accu_t t1, t2, normalAccu;
|
|
|
|
vec3_t normal;
|
|
|
|
vec_t dist;
|
|
|
|
|
|
|
|
VectorCopyRegularToAccu( p[0], paccu[0] );
|
|
|
|
VectorCopyRegularToAccu( p[1], paccu[1] );
|
|
|
|
VectorCopyRegularToAccu( p[2], paccu[2] );
|
|
|
|
|
|
|
|
VectorSubtractAccu( paccu[0], paccu[1], t1 );
|
|
|
|
VectorSubtractAccu( paccu[2], paccu[1], t2 );
|
|
|
|
CrossProductAccu( t1, t2, normalAccu );
|
|
|
|
VectorNormalizeAccu( normalAccu, normalAccu );
|
2011-01-10 06:15:47 +00:00
|
|
|
// TODO: A 32 bit float for the plane distance isn't enough resolution
|
|
|
|
// if the plane is 2^16 units away from the origin (the "epsilon" approaches
|
|
|
|
// 0.01 in that case).
|
2012-03-17 20:01:54 +00:00
|
|
|
dist = (vec_t) DotProductAccu( paccu[0], normalAccu );
|
|
|
|
VectorCopyAccuToRegular( normalAccu, normal );
|
2011-01-10 06:15:47 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return FindFloatPlane( normal, dist, 3, p );
|
2011-01-10 06:15:47 +00:00
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t t1, t2, normal;
|
|
|
|
vec_t dist;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* calc plane normal */
|
|
|
|
VectorSubtract( p[ 0 ], p[ 1 ], t1 );
|
|
|
|
VectorSubtract( p[ 2 ], p[ 1 ], t2 );
|
|
|
|
CrossProduct( t1, t2, normal );
|
|
|
|
VectorNormalize( normal, normal );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* calc plane distance */
|
|
|
|
dist = DotProduct( p[ 0 ], normal );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* store the plane */
|
|
|
|
return FindFloatPlane( normal, dist, 3, p );
|
2011-01-10 06:15:47 +00:00
|
|
|
#endif
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SetBrushContents()
|
|
|
|
the content flags and compile flags on all sides of a brush should be the same
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SetBrushContents( brush_t *b ){
|
|
|
|
int contentFlags, compileFlags;
|
|
|
|
side_t *s;
|
|
|
|
int i;
|
|
|
|
qboolean mixed;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get initial compile flags from first side */
|
|
|
|
s = &b->sides[ 0 ];
|
|
|
|
contentFlags = s->contentFlags;
|
|
|
|
compileFlags = s->compileFlags;
|
|
|
|
b->contentShader = s->shaderInfo;
|
|
|
|
mixed = qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get the content/compile flags for every side in the brush */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1; i < b->numsides; i++, s++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = &b->sides[ i ];
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s->shaderInfo == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( s->contentFlags != contentFlags || s->compileFlags != compileFlags ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
mixed = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: getting rid of this stupid warning */
|
|
|
|
//% if( mixed )
|
|
|
|
//% Sys_FPrintf( SYS_VRB,"Entity %i, Brush %i: mixed face contentFlags\n", b->entitynum, b->brushnum );
|
|
|
|
|
|
|
|
/* check for detail & structural */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( compileFlags & C_DETAIL ) && ( compileFlags & C_STRUCTURAL ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
xml_Select( "Mixed detail and structural (defaulting to structural)", mapEnt->mapEntityNum, entitySourceBrushes, qfalse );
|
|
|
|
compileFlags &= ~C_DETAIL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* the fulldetail flag will cause detail brushes to be treated like normal brushes */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fulldetail ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
compileFlags &= ~C_DETAIL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* all translucent brushes that aren't specifically made structural will be detail */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( compileFlags & C_TRANSLUCENT ) && !( compileFlags & C_STRUCTURAL ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
compileFlags |= C_DETAIL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* detail? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( compileFlags & C_DETAIL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_detail++;
|
|
|
|
b->detail = qtrue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c_structural++;
|
|
|
|
b->detail = qfalse;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* opaque? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( compileFlags & C_TRANSLUCENT ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
b->opaque = qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
b->opaque = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* areaportal? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( compileFlags & C_AREAPORTAL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_areaportals++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set brush flags */
|
|
|
|
b->contentFlags = contentFlags;
|
|
|
|
b->compileFlags = compileFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
AddBrushBevels()
|
|
|
|
adds any additional planes necessary to allow the brush being
|
|
|
|
built to be expanded against axial bounding boxes
|
|
|
|
ydnar 2003-01-20: added mrelusive fixes
|
|
|
|
*/
|
|
|
|
|
|
|
|
void AddBrushBevels( void ){
|
|
|
|
int axis, dir;
|
|
|
|
int i, j, k, l, order;
|
|
|
|
side_t sidetemp;
|
|
|
|
side_t *s, *s2;
|
|
|
|
winding_t *w, *w2;
|
|
|
|
vec3_t normal;
|
|
|
|
float dist;
|
|
|
|
vec3_t vec, vec2;
|
|
|
|
float d, minBack;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// add the axial planes
|
|
|
|
//
|
|
|
|
order = 0;
|
|
|
|
for ( axis = 0; axis < 3; axis++ ) {
|
|
|
|
for ( dir = -1; dir <= 1; dir += 2, order++ ) {
|
|
|
|
// see if the plane is allready present
|
|
|
|
for ( i = 0, s = buildBrush->sides; i < buildBrush->numsides; i++, s++ )
|
|
|
|
{
|
|
|
|
/* ydnar: testing disabling of mre code */
|
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dir > 0 ) {
|
|
|
|
if ( mapplanes[s->planenum].normal[axis] >= 0.9999f ) {
|
|
|
|
break;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ( mapplanes[s->planenum].normal[axis] <= -0.9999f ) {
|
|
|
|
break;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( dir > 0 && mapplanes[ s->planenum ].normal[ axis ] == 1.0f ) ||
|
|
|
|
( dir < 0 && mapplanes[ s->planenum ].normal[ axis ] == -1.0f ) ) {
|
|
|
|
break;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( i == buildBrush->numsides ) {
|
|
|
|
// add a new side
|
|
|
|
if ( buildBrush->numsides == MAX_BUILD_SIDES ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
memset( s, 0, sizeof( *s ) );
|
|
|
|
buildBrush->numsides++;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorClear( normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
normal[axis] = dir;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dir == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: adding bevel plane snapping for fewer bsp planes */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bevelSnap > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = floor( buildBrush->maxs[ axis ] / bevelSnap ) * bevelSnap;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = buildBrush->maxs[ axis ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* ydnar: adding bevel plane snapping for fewer bsp planes */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bevelSnap > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = -ceil( buildBrush->mins[ axis ] / bevelSnap ) * bevelSnap;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = -buildBrush->mins[ axis ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s->planenum = FindFloatPlane( normal, dist, 0, NULL );
|
|
|
|
s->contentFlags = buildBrush->sides[ 0 ].contentFlags;
|
|
|
|
s->bevel = qtrue;
|
|
|
|
c_boxbevels++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the plane is not in it canonical order, swap it
|
|
|
|
if ( i != order ) {
|
|
|
|
sidetemp = buildBrush->sides[order];
|
|
|
|
buildBrush->sides[order] = buildBrush->sides[i];
|
|
|
|
buildBrush->sides[i] = sidetemp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// add the edge bevels
|
|
|
|
//
|
|
|
|
if ( buildBrush->numsides == 6 ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
return; // pure axial
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test the non-axial plane edges
|
|
|
|
for ( i = 6; i < buildBrush->numsides; i++ ) {
|
|
|
|
s = buildBrush->sides + i;
|
|
|
|
w = s->winding;
|
|
|
|
if ( !w ) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < w->numpoints; j++ ) {
|
|
|
|
k = ( j + 1 ) % w->numpoints;
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorSubtract( w->p[j], w->p[k], vec );
|
|
|
|
if ( VectorNormalize( vec, vec ) < 0.5f ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SnapNormal( vec );
|
|
|
|
for ( k = 0; k < 3; k++ ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( vec[k] == -1.0f || vec[k] == 1.0f || ( vec[k] == 0.0f && vec[( k + 1 ) % 3] == 0.0f ) ) {
|
|
|
|
break; // axial
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( k != 3 ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
continue; // only test non-axial edges
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* debug code */
|
|
|
|
//% Sys_Printf( "-------------\n" );
|
|
|
|
|
|
|
|
// try the six possible slanted axials from this edge
|
|
|
|
for ( axis = 0; axis < 3; axis++ ) {
|
|
|
|
for ( dir = -1; dir <= 1; dir += 2 ) {
|
|
|
|
// construct a plane
|
|
|
|
VectorClear( vec2 );
|
|
|
|
vec2[axis] = dir;
|
|
|
|
CrossProduct( vec, vec2, normal );
|
|
|
|
if ( VectorNormalize( normal, normal ) < 0.5f ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dist = DotProduct( w->p[j], normal );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// if all the points on all the sides are
|
|
|
|
// behind this plane, it is a proper edge bevel
|
|
|
|
for ( k = 0; k < buildBrush->numsides; k++ ) {
|
|
|
|
|
|
|
|
// if this plane has allready been used, skip it
|
|
|
|
if ( PlaneEqual( &mapplanes[buildBrush->sides[k].planenum], normal, dist ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
w2 = buildBrush->sides[k].winding;
|
|
|
|
if ( !w2 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
minBack = 0.0f;
|
|
|
|
for ( l = 0; l < w2->numpoints; l++ ) {
|
|
|
|
d = DotProduct( w2->p[l], normal ) - dist;
|
|
|
|
if ( d > 0.1f ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
break; // point in front
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
if ( d < minBack ) {
|
|
|
|
minBack = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if some point was at the front
|
|
|
|
if ( l != w2->numpoints ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no points at the back then the winding is on the bevel plane
|
|
|
|
if ( minBack > -0.1f ) {
|
|
|
|
//% Sys_Printf( "On bevel plane\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( k != buildBrush->numsides ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
continue; // wasn't part of the outer hull
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* debug code */
|
|
|
|
//% Sys_Printf( "n = %f %f %f\n", normal[ 0 ], normal[ 1 ], normal[ 2 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// add this plane
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( buildBrush->numsides == MAX_BUILD_SIDES ) {
|
|
|
|
xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
s2 = &buildBrush->sides[buildBrush->numsides];
|
|
|
|
buildBrush->numsides++;
|
|
|
|
memset( s2, 0, sizeof( *s2 ) );
|
|
|
|
|
|
|
|
s2->planenum = FindFloatPlane( normal, dist, 1, &w->p[ j ] );
|
|
|
|
s2->contentFlags = buildBrush->sides[0].contentFlags;
|
|
|
|
s2->bevel = qtrue;
|
|
|
|
c_edgebevels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
FinishBrush()
|
|
|
|
produces a final brush based on the buildBrush->sides array
|
|
|
|
and links it to the current entity
|
|
|
|
*/
|
|
|
|
|
|
|
|
brush_t *FinishBrush( void ){
|
|
|
|
brush_t *b;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* create windings for sides and bounds for brush */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !CreateBrushWindings( buildBrush ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* origin brushes are removed, but they set the rotation origin for the rest of the brushes in the entity.
|
|
|
|
after the entire entity is parsed, the planenums and texinfos will be adjusted for the origin brush */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( buildBrush->compileFlags & C_ORIGIN ) {
|
|
|
|
char string[ 32 ];
|
|
|
|
vec3_t origin;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numEntities == 1 ) {
|
|
|
|
Sys_Printf( "Entity %i, Brush %i: origin brushes not allowed in world\n",
|
|
|
|
mapEnt->mapEntityNum, entitySourceBrushes );
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
VectorAdd( buildBrush->mins, buildBrush->maxs, origin );
|
|
|
|
VectorScale( origin, 0.5, origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
sprintf( string, "%i %i %i", (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
SetKeyValue( &entities[ numEntities - 1 ], "origin", string );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( origin, entities[ numEntities - 1 ].origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* don't keep this brush */
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* determine if the brush is an area portal */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( buildBrush->compileFlags & C_AREAPORTAL ) {
|
|
|
|
if ( numEntities != 1 ) {
|
|
|
|
Sys_Printf( "Entity %i, Brush %i: areaportals only allowed in world\n", numEntities - 1, entitySourceBrushes );
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add bevel planes */
|
|
|
|
AddBrushBevels();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* keep it */
|
|
|
|
b = CopyBrush( buildBrush );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set map entity and brush numbering */
|
|
|
|
b->entityNum = mapEnt->mapEntityNum;
|
|
|
|
b->brushNum = entitySourceBrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set original */
|
|
|
|
b->original = b;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* link opaque brushes to head of list, translucent brushes to end */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->opaque || mapEnt->lastBrush == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
b->next = mapEnt->brushes;
|
|
|
|
mapEnt->brushes = b;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapEnt->lastBrush == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
mapEnt->lastBrush = b;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b->next = NULL;
|
|
|
|
mapEnt->lastBrush->next = b;
|
|
|
|
mapEnt->lastBrush = b;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* link colorMod volume brushes to the entity directly */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->contentShader != NULL &&
|
|
|
|
b->contentShader->colorMod != NULL &&
|
|
|
|
b->contentShader->colorMod->type == CM_VOLUME ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
b->nextColorModBrush = mapEnt->colorModBrushes;
|
|
|
|
mapEnt->colorModBrushes = b;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* return to sender */
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
TextureAxisFromPlane()
|
|
|
|
determines best orthagonal axis to project a texture onto a wall
|
|
|
|
(must be identical in radiant!)
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t baseaxis[18] =
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
{0,0,1}, {1,0,0}, {0,-1,0}, // floor
|
|
|
|
{0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling
|
|
|
|
{1,0,0}, {0,1,0}, {0,0,-1}, // west wall
|
|
|
|
{-1,0,0}, {0,1,0}, {0,0,-1}, // east wall
|
|
|
|
{0,1,0}, {1,0,0}, {0,0,-1}, // south wall
|
|
|
|
{0,-1,0}, {1,0,0}, {0,0,-1} // north wall
|
2007-11-04 03:34:51 +00:00
|
|
|
};
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ){
|
|
|
|
int bestaxis;
|
|
|
|
vec_t dot,best;
|
|
|
|
int i;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
best = 0;
|
|
|
|
bestaxis = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( i = 0 ; i < 6 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
dot = DotProduct( pln->normal, baseaxis[i * 3] );
|
|
|
|
if ( dot > best + 0.0001f ) { /* ydnar: bug 637 fix, suggested by jmonroe */
|
2007-11-04 03:34:51 +00:00
|
|
|
best = dot;
|
|
|
|
bestaxis = i;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
VectorCopy( baseaxis[bestaxis * 3 + 1], xv );
|
|
|
|
VectorCopy( baseaxis[bestaxis * 3 + 2], yv );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
QuakeTextureVecs()
|
|
|
|
creates world-to-texture mapping vecs for crappy quake plane arrangements
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t scale[ 2 ], vec_t mappingVecs[ 2 ][ 4 ] ){
|
|
|
|
vec3_t vecs[2];
|
|
|
|
int sv, tv;
|
|
|
|
vec_t ang, sinv, cosv;
|
|
|
|
vec_t ns, nt;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
|
|
TextureAxisFromPlane( plane, vecs[0], vecs[1] );
|
|
|
|
|
|
|
|
if ( !scale[0] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
scale[0] = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !scale[1] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
scale[1] = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// rotate axis
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( rotate == 0 ) {
|
|
|
|
sinv = 0 ; cosv = 1;
|
|
|
|
}
|
|
|
|
else if ( rotate == 90 ) {
|
|
|
|
sinv = 1 ; cosv = 0;
|
|
|
|
}
|
|
|
|
else if ( rotate == 180 ) {
|
|
|
|
sinv = 0 ; cosv = -1;
|
|
|
|
}
|
|
|
|
else if ( rotate == 270 ) {
|
|
|
|
sinv = -1 ; cosv = 0;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
else
|
2012-03-17 20:01:54 +00:00
|
|
|
{
|
2007-11-04 03:34:51 +00:00
|
|
|
ang = rotate / 180 * Q_PI;
|
2012-03-17 20:01:54 +00:00
|
|
|
sinv = sin( ang );
|
|
|
|
cosv = cos( ang );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( vecs[0][0] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sv = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( vecs[0][1] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sv = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
sv = 2;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( vecs[1][0] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
tv = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( vecs[1][1] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
tv = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
tv = 2;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0 ; i < 2 ; i++ ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
|
|
|
|
nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
|
|
|
|
vecs[i][sv] = ns;
|
|
|
|
vecs[i][tv] = nt;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
mappingVecs[i][j] = vecs[i][j] / scale[i];
|
|
|
|
|
|
|
|
mappingVecs[0][3] = shift[0];
|
|
|
|
mappingVecs[1][3] = shift[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRawBrush()
|
|
|
|
parses the sides into buildBrush->sides[], nothing else.
|
|
|
|
no validation, back plane removal, etc.
|
|
|
|
|
|
|
|
Timo - 08/26/99
|
|
|
|
added brush epairs parsing ( ignoring actually )
|
|
|
|
Timo - 08/04/99
|
|
|
|
added exclusive brush primitive parsing
|
|
|
|
Timo - 08/08/99
|
|
|
|
support for old brush format back in
|
|
|
|
NOTE: it would be "cleaner" to have seperate functions to parse between old and new brushes
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ParseRawBrush( qboolean onlyLights ){
|
|
|
|
side_t *side;
|
|
|
|
vec3_t planePoints[ 3 ];
|
|
|
|
int planenum;
|
|
|
|
shaderInfo_t *si;
|
|
|
|
vec_t shift[ 2 ];
|
|
|
|
vec_t rotate;
|
|
|
|
vec_t scale[ 2 ];
|
|
|
|
char name[ MAX_QPATH ];
|
|
|
|
char shader[ MAX_QPATH ];
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* initial setup */
|
|
|
|
buildBrush->numsides = 0;
|
|
|
|
buildBrush->detail = qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* bp */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
MatchToken( "{" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse sides */
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetToken( qtrue ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !strcmp( token, "}" ) ) {
|
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
|
|
|
/* ttimo : bp: here we may have to jump over brush epairs (only used in editor) */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
|
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strcmp( token, "(" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
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
|
|
|
GetToken( qtrue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UnGetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* test side count */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( buildBrush->numsides >= MAX_BUILD_SIDES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add side */
|
|
|
|
side = &buildBrush->sides[ buildBrush->numsides ];
|
|
|
|
memset( side, 0, sizeof( *side ) );
|
|
|
|
buildBrush->numsides++;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* read the three point plane definition */
|
|
|
|
Parse1DMatrix( 3, planePoints[ 0 ] );
|
|
|
|
Parse1DMatrix( 3, planePoints[ 1 ] );
|
|
|
|
Parse1DMatrix( 3, planePoints[ 2 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* bp: read the texture matrix */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Parse2DMatrix( 2, 3, (float*) side->texMat );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* read shader name */
|
|
|
|
GetToken( qfalse );
|
|
|
|
strcpy( name, token );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* bp */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
shift[ 0 ] = atof( token );
|
|
|
|
GetToken( qfalse );
|
|
|
|
shift[ 1 ] = atof( token );
|
|
|
|
GetToken( qfalse );
|
2012-03-17 20:01:54 +00:00
|
|
|
rotate = atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
GetToken( qfalse );
|
|
|
|
scale[ 0 ] = atof( token );
|
|
|
|
GetToken( qfalse );
|
|
|
|
scale[ 1 ] = atof( token );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set default flags and values */
|
|
|
|
sprintf( shader, "textures/%s", name );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( onlyLights ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
si = &shaderInfo[ 0 ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
si = ShaderInfoForShader( shader );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
side->shaderInfo = si;
|
|
|
|
side->surfaceFlags = si->surfaceFlags;
|
|
|
|
side->contentFlags = si->contentFlags;
|
|
|
|
side->compileFlags = si->compileFlags;
|
|
|
|
side->value = si->value;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: gs mods: bias texture shift */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( si->globalTexture == qfalse ) {
|
|
|
|
shift[ 0 ] -= ( floor( shift[ 0 ] / si->shaderWidth ) * si->shaderWidth );
|
|
|
|
shift[ 1 ] -= ( floor( shift[ 1 ] / si->shaderHeight ) * si->shaderHeight );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
historically, there are 3 integer values at the end of a brushside line in a .map file.
|
|
|
|
in quake 3, the only thing that mattered was the first of these three values, which
|
|
|
|
was previously the content flags. and only then did a single bit matter, the detail
|
|
|
|
bit. because every game has its own special flags for specifying detail, the
|
|
|
|
traditionally game-specified CONTENTS_DETAIL flag was overridden for Q3Map 2.3.0
|
|
|
|
by C_DETAIL, defined in q3map2.h. the value is exactly as it was before, but
|
|
|
|
is stored in compileFlags, as opposed to contentFlags, for multiple-game
|
|
|
|
portability. :sigh:
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( TokenAvailable() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get detail bit from map content flags */
|
|
|
|
GetToken( qfalse );
|
|
|
|
flags = atoi( token );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( flags & C_DETAIL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->compileFlags |= C_DETAIL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* historical */
|
|
|
|
GetToken( qfalse );
|
|
|
|
//% td.flags = atoi( token );
|
|
|
|
GetToken( qfalse );
|
|
|
|
//% td.value = atoi( token );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find the plane number */
|
|
|
|
planenum = MapPlaneFromPoints( planePoints );
|
|
|
|
side->planenum = planenum;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* bp: get the texture mapping for this texturedef / plane combination */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
QuakeTextureVecs( &mapplanes[ planenum ], shift, rotate, scale, side->vecs );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* bp */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
UnGetToken();
|
|
|
|
MatchToken( "}" );
|
|
|
|
MatchToken( "}" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
RemoveDuplicateBrushPlanes
|
|
|
|
returns false if the brush has a mirrored set of planes,
|
|
|
|
meaning it encloses no volume.
|
|
|
|
also removes planes without any normal
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean RemoveDuplicateBrushPlanes( brush_t *b ){
|
|
|
|
int i, j, k;
|
|
|
|
side_t *sides;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
sides = b->sides;
|
|
|
|
|
|
|
|
for ( i = 1 ; i < b->numsides ; i++ ) {
|
|
|
|
|
|
|
|
// check for a degenerate plane
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides[i].planenum == -1 ) {
|
|
|
|
xml_Select( "degenerate plane", b->entityNum, b->brushNum, qfalse );
|
2007-11-04 03:34:51 +00:00
|
|
|
// remove it
|
|
|
|
for ( k = i + 1 ; k < b->numsides ; k++ ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
sides[k - 1] = sides[k];
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
b->numsides--;
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for duplication and mirroring
|
|
|
|
for ( j = 0 ; j < i ; j++ ) {
|
|
|
|
if ( sides[i].planenum == sides[j].planenum ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
xml_Select( "duplicate plane", b->entityNum, b->brushNum, qfalse );
|
2007-11-04 03:34:51 +00:00
|
|
|
// remove the second duplicate
|
|
|
|
for ( k = i + 1 ; k < b->numsides ; k++ ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
sides[k - 1] = sides[k];
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
b->numsides--;
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides[i].planenum == ( sides[j].planenum ^ 1 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// mirror plane, brush is invalid
|
2012-03-17 20:01:54 +00:00
|
|
|
xml_Select( "mirrored plane", b->entityNum, b->brushNum, qfalse );
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseBrush()
|
|
|
|
parses a brush out of a map file and sets it up
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ParseBrush( qboolean onlyLights ){
|
|
|
|
brush_t *b;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* parse the brush out of the map */
|
|
|
|
ParseRawBrush( onlyLights );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* only go this far? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( onlyLights ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set some defaults */
|
|
|
|
buildBrush->portalareas[ 0 ] = -1;
|
|
|
|
buildBrush->portalareas[ 1 ] = -1;
|
|
|
|
buildBrush->entityNum = numMapEntities - 1;
|
|
|
|
buildBrush->brushNum = entitySourceBrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* if there are mirrored planes, the entire brush is invalid */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !RemoveDuplicateBrushPlanes( buildBrush ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get the content for the entire brush */
|
|
|
|
SetBrushContents( buildBrush );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* allow detail brushes to be removed */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( nodetail && ( buildBrush->compileFlags & C_DETAIL ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
//% FreeBrush( buildBrush );
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* allow liquid brushes to be removed */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( nowater && ( buildBrush->compileFlags & C_LIQUID ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
//% FreeBrush( buildBrush );
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: allow hint brushes to be removed */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( noHint && ( buildBrush->compileFlags & C_HINT ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
//% FreeBrush( buildBrush );
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* finish the brush */
|
|
|
|
b = FinishBrush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
MoveBrushesToWorld()
|
|
|
|
takes all of the brushes from the current entity and
|
|
|
|
adds them to the world's brush list
|
|
|
|
(used by func_group)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void MoveBrushesToWorld( entity_t *ent ){
|
|
|
|
brush_t *b, *next;
|
|
|
|
parseMesh_t *pm;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* move brushes */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = ent->brushes; b != NULL; b = next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get next brush */
|
|
|
|
next = b->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* link opaque brushes to head of list, translucent brushes to end */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->opaque || entities[ 0 ].lastBrush == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
b->next = entities[ 0 ].brushes;
|
|
|
|
entities[ 0 ].brushes = b;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( entities[ 0 ].lastBrush == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
entities[ 0 ].lastBrush = b;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b->next = NULL;
|
|
|
|
entities[ 0 ].lastBrush->next = b;
|
|
|
|
entities[ 0 ].lastBrush = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ent->brushes = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* ydnar: move colormod brushes */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ent->colorModBrushes != NULL ) {
|
|
|
|
for ( b = ent->colorModBrushes; b->nextColorModBrush != NULL; b = b->nextColorModBrush ) ;
|
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
b->nextColorModBrush = entities[ 0 ].colorModBrushes;
|
|
|
|
entities[ 0 ].colorModBrushes = ent->colorModBrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
ent->colorModBrushes = NULL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* move patches */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ent->patches != NULL ) {
|
|
|
|
for ( pm = ent->patches; pm->next != NULL; pm = pm->next ) ;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
pm->next = entities[ 0 ].patches;
|
|
|
|
entities[ 0 ].patches = ent->patches;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
ent->patches = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
AdjustBrushesForOrigin()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void AdjustBrushesForOrigin( entity_t *ent ){
|
|
|
|
|
|
|
|
int i;
|
|
|
|
side_t *s;
|
|
|
|
vec_t newdist;
|
|
|
|
brush_t *b;
|
|
|
|
parseMesh_t *p;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* walk brush list */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = ent->brushes; b != NULL; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* offset brush planes */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < b->numsides; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get brush side */
|
|
|
|
s = &b->sides[ i ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* offset side plane */
|
|
|
|
newdist = mapplanes[ s->planenum ].dist - DotProduct( mapplanes[ s->planenum ].normal, ent->origin );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find a new plane */
|
|
|
|
s->planenum = FindFloatPlane( mapplanes[ s->planenum ].normal, newdist, 0, NULL );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* rebuild brush windings (ydnar: just offsetting the winding above should be fine) */
|
|
|
|
CreateBrushWindings( b );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* walk patch list */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = ent->patches; p != NULL; p = p->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorSubtract( p->mesh.verts[ i ].xyz, ent->origin, p->mesh.verts[ i ].xyz );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SetEntityBounds() - ydnar
|
|
|
|
finds the bounds of an entity's brushes (necessary for terrain-style generic metashaders)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SetEntityBounds( entity_t *e ){
|
|
|
|
int i;
|
|
|
|
brush_t *b;
|
|
|
|
parseMesh_t *p;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
const char *value;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* walk the entity's brushes/patches and determine bounds */
|
|
|
|
ClearBounds( mins, maxs );
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = e->brushes; b; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
AddPointToBounds( b->mins, mins, maxs );
|
|
|
|
AddPointToBounds( b->maxs, mins, maxs );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = e->patches; p; p = p->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
AddPointToBounds( p->mesh.verts[ i ].xyz, mins, maxs );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* try to find explicit min/max key */
|
2012-03-17 20:01:54 +00:00
|
|
|
value = ValueForKey( e, "min" );
|
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
GetVectorForKey( e, "min", mins );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
value = ValueForKey( e, "max" );
|
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
GetVectorForKey( e, "max", maxs );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* store the bounds */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = e->brushes; b; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
VectorCopy( mins, b->eMins );
|
|
|
|
VectorCopy( maxs, b->eMaxs );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = e->patches; p; p = p->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
VectorCopy( mins, p->eMins );
|
|
|
|
VectorCopy( maxs, p->eMaxs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadEntityIndexMap() - ydnar
|
|
|
|
based on LoadAlphaMap() from terrain.c, a little more generic
|
|
|
|
*/
|
|
|
|
|
|
|
|
void LoadEntityIndexMap( entity_t *e ){
|
|
|
|
int i, size, numLayers, w, h;
|
|
|
|
const char *value, *indexMapFilename, *shader;
|
|
|
|
char ext[ MAX_QPATH ], offset[ 4096 ], *search, *space;
|
|
|
|
byte *pixels;
|
|
|
|
unsigned int *pixels32;
|
|
|
|
indexMap_t *im;
|
|
|
|
brush_t *b;
|
|
|
|
parseMesh_t *p;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* this only works with bmodel ents */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( e->brushes == NULL && e->patches == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* determine if there is an index map (support legacy "alphamap" key as well) */
|
|
|
|
value = ValueForKey( e, "_indexmap" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
value = ValueForKey( e, "alphamap" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
indexMapFilename = value;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get number of layers (support legacy "layers" key as well) */
|
|
|
|
value = ValueForKey( e, "_layers" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
value = ValueForKey( e, "layers" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" has missing \"_layers\" or \"layers\" key\n", indexMapFilename );
|
|
|
|
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
numLayers = atoi( value );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numLayers < 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" has < 1 layer (%d)\n", indexMapFilename, numLayers );
|
|
|
|
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get base shader name (support legacy "shader" key as well) */
|
|
|
|
value = ValueForKey( mapEnt, "_shader" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
value = ValueForKey( e, "shader" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" has missing \"_shader\" or \"shader\" key\n", indexMapFilename );
|
|
|
|
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
shader = value;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* note it */
|
|
|
|
Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get index map file extension */
|
|
|
|
ExtractFileExtension( indexMapFilename, ext );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle tga image */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( ext, "tga" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* load it */
|
|
|
|
Load32BitImage( indexMapFilename, &pixels32, &w, &h );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* convert to bytes */
|
|
|
|
size = w * h;
|
|
|
|
pixels = safe_malloc( size );
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < size; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
pixels[ i ] = ( ( pixels32[ i ] & 0xFF ) * numLayers ) / 256;
|
|
|
|
if ( pixels[ i ] >= numLayers ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
pixels[ i ] = numLayers - 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
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* free the 32 bit image */
|
|
|
|
free( pixels32 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* load it */
|
|
|
|
Load256Image( indexMapFilename, &pixels, NULL, &w, &h );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* debug code */
|
|
|
|
//% Sys_Printf( "-------------------------------" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* fix up out-of-range values */
|
|
|
|
size = w * h;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < size; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pixels[ i ] >= numLayers ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
pixels[ i ] = numLayers - 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* debug code */
|
|
|
|
//% if( (i % w) == 0 )
|
|
|
|
//% Sys_Printf( "\n" );
|
|
|
|
//% Sys_Printf( "%c", pixels[ i ] + '0' );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* debug code */
|
|
|
|
//% Sys_Printf( "\n-------------------------------\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* the index map must be at least 2x2 pixels */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( w < 2 || h < 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" is smaller than 2x2 pixels\n", indexMapFilename );
|
|
|
|
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
|
|
|
|
free( pixels );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new index map */
|
|
|
|
im = safe_malloc( sizeof( *im ) );
|
|
|
|
memset( im, 0, sizeof( *im ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set it up */
|
|
|
|
im->w = w;
|
|
|
|
im->h = h;
|
|
|
|
im->numLayers = numLayers;
|
|
|
|
strcpy( im->name, indexMapFilename );
|
|
|
|
strcpy( im->shader, shader );
|
|
|
|
im->pixels = pixels;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get height offsets */
|
|
|
|
value = ValueForKey( mapEnt, "_offsets" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
value = ValueForKey( e, "offsets" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* value is a space-seperated set of numbers */
|
|
|
|
strcpy( offset, value );
|
|
|
|
search = offset;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get each value */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < 256 && *search != '\0'; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
space = strstr( search, " " );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( space != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*space = '\0';
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
im->offsets[ i ] = atof( search );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( space == NULL ) {
|
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
|
|
|
search = space + 1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* store the index map in every brush/patch in the entity */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = e->brushes; b != NULL; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
b->im = im;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = e->patches; p != NULL; p = p->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
p->im = im;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseMapEntity()
|
|
|
|
parses a single entity out of a map file
|
|
|
|
*/
|
|
|
|
|
|
|
|
static qboolean ParseMapEntity( qboolean onlyLights ){
|
|
|
|
epair_t *ep;
|
|
|
|
const char *classname, *value;
|
|
|
|
float lightmapScale;
|
|
|
|
char shader[ MAX_QPATH ];
|
|
|
|
shaderInfo_t *celShader = NULL;
|
|
|
|
brush_t *brush;
|
|
|
|
parseMesh_t *patch;
|
|
|
|
qboolean funcGroup;
|
|
|
|
int castShadows, recvShadows;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* eof check */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetToken( qtrue ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* conformance check */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strcmp( token, "{" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: ParseEntity: { not found, found %s on line %d - last entity was at: <%4.2f, %4.2f, %4.2f>...\n"
|
2012-03-17 20:01:54 +00:00
|
|
|
"Continuing to process map, but resulting BSP may be invalid.\n",
|
|
|
|
token, scriptline, entities[ numEntities ].origin[ 0 ], entities[ numEntities ].origin[ 1 ], entities[ numEntities ].origin[ 2 ] );
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* range check */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numEntities >= MAX_MAP_ENTITIES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "numEntities == MAX_MAP_ENTITIES" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup */
|
|
|
|
entitySourceBrushes = 0;
|
|
|
|
mapEnt = &entities[ numEntities ];
|
|
|
|
numEntities++;
|
|
|
|
memset( mapEnt, 0, sizeof( *mapEnt ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: true entity numbering */
|
|
|
|
mapEnt->mapEntityNum = numMapEntities;
|
|
|
|
numMapEntities++;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* loop */
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get initial token */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetToken( qtrue ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: ParseEntity: EOF without closing brace\n"
|
2012-03-17 20:01:54 +00:00
|
|
|
"Continuing to process map, but resulting BSP may be invalid.\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !strcmp( token, "{" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse a brush or patch */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetToken( qtrue ) ) {
|
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
|
|
|
/* check */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "patchDef2" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
numMapPatches++;
|
|
|
|
ParsePatch( onlyLights );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( token, "terrainDef" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
//% ParseTerrain();
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "WARNING: Terrain entity parsing not supported in this build.\n" ); /* ydnar */
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( token, "brushDef" ) ) {
|
|
|
|
if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Old brush format not allowed in new brush format map" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
g_bBrushPrimit = BPRIMIT_NEWBRUSHES;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse brush primitive */
|
|
|
|
ParseBrush( onlyLights );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "New brush format not allowed in old brush format map" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
g_bBrushPrimit = BPRIMIT_OLDBRUSHES;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse old brush format */
|
|
|
|
UnGetToken();
|
|
|
|
ParseBrush( onlyLights );
|
|
|
|
}
|
|
|
|
entitySourceBrushes++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* parse a key / value pair */
|
|
|
|
ep = ParseEPair();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: 2002-07-06 fixed wolf bug with empty epairs */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
ep->next = mapEnt->epairs;
|
|
|
|
mapEnt->epairs = ep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: get classname */
|
|
|
|
classname = ValueForKey( mapEnt, "classname" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: only lights? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( onlyLights && Q_strncasecmp( classname, "light", 5 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
numEntities--;
|
|
|
|
return qtrue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: determine if this is a func_group */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( "func_group", classname ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
funcGroup = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
funcGroup = qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( funcGroup || mapEnt->mapEntityNum == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
//% Sys_Printf( "World: %d\n", mapEnt->mapEntityNum );
|
|
|
|
castShadows = WORLDSPAWN_CAST_SHADOWS;
|
|
|
|
recvShadows = WORLDSPAWN_RECV_SHADOWS;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* other entities don't cast any shadows, but recv worldspawn shadows */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//% Sys_Printf( "Entity: %d\n", mapEnt->mapEntityNum );
|
|
|
|
castShadows = ENTITY_CAST_SHADOWS;
|
|
|
|
recvShadows = ENTITY_RECV_SHADOWS;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get explicit shadow flags */
|
|
|
|
GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: get lightmap scaling value for this entity */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) ||
|
|
|
|
strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get lightmap scale from entity */
|
|
|
|
lightmapScale = FloatForKey( mapEnt, "lightmapscale" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( lightmapScale <= 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
lightmapScale = FloatForKey( mapEnt, "_lightmapscale" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( lightmapScale > 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
lightmapScale = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: get cel shader :) for this entity */
|
|
|
|
value = ValueForKey( mapEnt, "_celshader" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
value = ValueForKey( &entities[ 0 ], "_celshader" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sprintf( shader, "textures/%s", value );
|
|
|
|
celShader = ShaderInfoForShader( shader );
|
|
|
|
Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
celShader = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attach stuff to everything in the entity */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( brush = mapEnt->brushes; brush != NULL; brush = brush->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
brush->entityNum = mapEnt->mapEntityNum;
|
|
|
|
brush->castShadows = castShadows;
|
|
|
|
brush->recvShadows = recvShadows;
|
|
|
|
brush->lightmapScale = lightmapScale;
|
|
|
|
brush->celShader = celShader;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( patch = mapEnt->patches; patch != NULL; patch = patch->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
patch->entityNum = mapEnt->mapEntityNum;
|
|
|
|
patch->castShadows = castShadows;
|
|
|
|
patch->recvShadows = recvShadows;
|
|
|
|
patch->lightmapScale = lightmapScale;
|
|
|
|
patch->celShader = celShader;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: gs mods: set entity bounds */
|
|
|
|
SetEntityBounds( mapEnt );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: gs mods: load shader index map (equivalent to old terrain alphamap) */
|
|
|
|
LoadEntityIndexMap( mapEnt );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get entity origin and adjust brushes */
|
|
|
|
GetVectorForKey( mapEnt, "origin", mapEnt->origin );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapEnt->origin[ 0 ] || mapEnt->origin[ 1 ] || mapEnt->origin[ 2 ] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
AdjustBrushesForOrigin( mapEnt );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* group_info entities are just for editor grouping (fixme: leak!) */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( "group_info", classname ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
numEntities--;
|
|
|
|
return qtrue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* group entities are just for editor convenience, toss all brushes into worldspawn */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( funcGroup ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
MoveBrushesToWorld( mapEnt );
|
|
|
|
numEntities--;
|
|
|
|
return qtrue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* done */
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadMapFile()
|
|
|
|
loads a map file into a list of entities
|
|
|
|
*/
|
|
|
|
|
|
|
|
void LoadMapFile( char *filename, qboolean onlyLights ){
|
|
|
|
FILE *file;
|
|
|
|
brush_t *b;
|
|
|
|
int oldNumEntities, numMapBrushes;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* note it */
|
|
|
|
Sys_FPrintf( SYS_VRB, "--- LoadMapFile ---\n" );
|
|
|
|
Sys_Printf( "Loading %s\n", filename );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* hack */
|
|
|
|
file = SafeOpenRead( filename );
|
|
|
|
fclose( file );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* load the map file */
|
|
|
|
LoadScriptFile( filename, -1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( onlyLights ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
oldNumEntities = numEntities;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
numEntities = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* initial setup */
|
|
|
|
numMapDrawSurfs = 0;
|
|
|
|
c_detail = 0;
|
|
|
|
g_bBrushPrimit = BPRIMIT_UNDEFINED;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* allocate a very large temporary brush for building the brushes as they are loaded */
|
|
|
|
buildBrush = AllocBrush( MAX_BUILD_SIDES );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse the map file */
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( ParseMapEntity( onlyLights ) ) ;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* light loading */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( onlyLights ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit some statistics */
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d light entities\n", numEntities - oldNumEntities );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* set map bounds */
|
|
|
|
ClearBounds( mapMins, mapMaxs );
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = entities[ 0 ].brushes; b; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
AddPointToBounds( b->mins, mapMins, mapMaxs );
|
|
|
|
AddPointToBounds( b->maxs, mapMins, mapMaxs );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get brush counts */
|
|
|
|
numMapBrushes = CountBrushList( entities[ 0 ].brushes );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( (float) c_detail / (float) numMapBrushes < 0.10f && numMapBrushes > 500 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: Over 90 percent structural map detected. Compile time may be adversely affected.\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit some statistics */
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d total world brushes\n", numMapBrushes );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d detail brushes\n", c_detail );
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%9d patches\n", numMapPatches );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels );
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes );
|
|
|
|
Sys_Printf( "%9d areaportals\n", c_areaportals );
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n",
|
2012-03-17 20:01:54 +00:00
|
|
|
mapMins[ 0 ], mapMins[ 1 ], mapMins[ 2 ],
|
|
|
|
mapMaxs[ 0 ], mapMaxs[ 1 ], mapMaxs[ 2 ] );
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* write bogus map */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fakemap ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
WriteBSPBrushMap( "fakemap.map", entities[ 0 ].brushes );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|