2002-09-19 18:51:19 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program 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.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program 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.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
See file, 'COPYING', for details.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2002-09-19 19:12:16 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2002-09-19 19:12:16 +00:00
|
|
|
#include "compat.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
#include "bsp5.h"
|
2003-09-03 22:00:08 +00:00
|
|
|
#include "options.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
input
|
|
|
|
-----
|
|
|
|
vertexes
|
|
|
|
edges
|
|
|
|
faces
|
|
|
|
|
|
|
|
output
|
|
|
|
------
|
|
|
|
smaller set of vertexes
|
|
|
|
smaller set of edges
|
|
|
|
regions
|
|
|
|
? triangulated regions
|
|
|
|
face to region mapping numbers
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_EDGES_IN_REGION 32
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int firstedge;
|
|
|
|
vec3_t region_mins, region_maxs;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
AddPointToRegion (vec3_t p)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (p[i] < region_mins[i])
|
|
|
|
region_mins[i] = p[i];
|
|
|
|
if (p[i] > region_maxs[i])
|
|
|
|
region_maxs[i] = p[i];
|
2002-09-19 17:14:23 +00:00
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
AddFaceToRegionSize (face_t *f)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-09-08 03:00:53 +00:00
|
|
|
for (i = 0; i < f->points->numpoints; i++)
|
|
|
|
AddPointToRegion (f->points->points[i]);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static qboolean
|
2002-09-19 18:51:19 +00:00
|
|
|
CanJoinFaces (face_t *f, face_t *f2)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
2002-09-19 18:51:19 +00:00
|
|
|
vec3_t oldmins, oldmaxs;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
if (f2->planenum != f->planenum
|
2002-09-19 17:14:23 +00:00
|
|
|
|| f2->planeside != f->planeside || f2->texturenum != f->texturenum)
|
2002-09-19 16:58:48 +00:00
|
|
|
return false;
|
|
|
|
if (f2->outputnumber != -1)
|
|
|
|
return false;
|
2002-09-19 17:14:23 +00:00
|
|
|
if (f2->contents[0] != f->contents[0]) { // does this ever happen?
|
2002-09-19 18:51:19 +00:00
|
|
|
// they shouldn't share.
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("CanJoinFaces: edge with different contents");
|
|
|
|
return false;
|
|
|
|
}
|
2002-09-23 16:27:17 +00:00
|
|
|
// check size constraints
|
2002-09-19 17:14:23 +00:00
|
|
|
if (!(bsp->texinfo[f->texturenum].flags & TEX_SPECIAL)) {
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorCopy (region_mins, oldmins);
|
|
|
|
VectorCopy (region_maxs, oldmaxs);
|
|
|
|
AddFaceToRegionSize (f2);
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2003-09-03 22:00:08 +00:00
|
|
|
if (region_maxs[i] - region_mins[i] > options.subdivide_size) {
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorCopy (oldmins, region_mins);
|
|
|
|
VectorCopy (oldmaxs, region_maxs);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
} else {
|
2003-09-08 03:00:53 +00:00
|
|
|
if (bsp->numsurfedges - firstedge + f2->points->numpoints
|
2002-09-19 18:51:19 +00:00
|
|
|
> MAX_EDGES_IN_REGION)
|
2002-09-19 17:14:23 +00:00
|
|
|
return false; // a huge water or sky polygon
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// check edge count constraints
|
2002-09-19 16:58:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
RecursiveGrowRegion (dface_t *r, face_t *f)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
face_t *f2;
|
2002-09-19 18:51:19 +00:00
|
|
|
int e, i;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (f->outputnumber == bsp->numfaces)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (f->outputnumber != -1)
|
|
|
|
Sys_Error ("RecursiveGrowRegion: region collision");
|
|
|
|
f->outputnumber = bsp->numfaces;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// add edges
|
2003-09-08 03:00:53 +00:00
|
|
|
for (i = 0; i < f->points->numpoints; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
e = f->edges[i];
|
2002-09-19 17:14:23 +00:00
|
|
|
if (!edgefaces[abs (e)][0])
|
|
|
|
continue; // edge has allready been removed
|
2002-09-19 16:58:48 +00:00
|
|
|
if (e > 0)
|
|
|
|
f2 = edgefaces[e][1];
|
|
|
|
else
|
|
|
|
f2 = edgefaces[-e][0];
|
2002-09-19 17:14:23 +00:00
|
|
|
if (f2 && f2->outputnumber == bsp->numfaces) {
|
|
|
|
edgefaces[abs (e)][0] = NULL;
|
|
|
|
edgefaces[abs (e)][1] = NULL;
|
|
|
|
continue; // allready merged
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
if (f2 && CanJoinFaces (f, f2)) { // remove the edge and merge the
|
|
|
|
// faces
|
|
|
|
edgefaces[abs (e)][0] = NULL;
|
|
|
|
edgefaces[abs (e)][1] = NULL;
|
2002-09-19 16:58:48 +00:00
|
|
|
RecursiveGrowRegion (r, f2);
|
2002-09-19 17:14:23 +00:00
|
|
|
} else {
|
|
|
|
// emit a surfedge
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->numsurfedges == MAX_MAP_SURFEDGES)
|
|
|
|
Sys_Error ("numsurfedges == MAX_MAP_SURFEDGES");
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddSurfEdge (bsp, e);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
int edgemapping[MAX_MAP_EDGES];
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
typedef struct {
|
|
|
|
int numedges;
|
|
|
|
int edges[2];
|
2002-09-19 16:58:48 +00:00
|
|
|
} checkpoint_t;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
checkpoint_t checkpoints[MAX_MAP_VERTS];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
CountRealNumbers (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int c, i;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
qprintf ("%5i regions\n", bsp->numfaces - firstmodelface);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
c = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = firstmodelface; i < bsp->numfaces; i++)
|
2002-09-19 16:58:48 +00:00
|
|
|
c += bsp->faces[i].numedges;
|
|
|
|
qprintf ("%5i real marksurfaces\n", c);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
c = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = firstmodeledge; i < bsp->numedges; i++)
|
2002-09-19 16:58:48 +00:00
|
|
|
if (edgefaces[i][0])
|
2002-09-19 17:14:23 +00:00
|
|
|
c++; // not removed
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
qprintf ("%5i real edges\n", c);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
GrowNodeRegion_r (node_t * node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
dface_t r;
|
2002-09-19 17:14:23 +00:00
|
|
|
face_t *f;
|
|
|
|
int i;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
if (node->planenum == PLANENUM_LEAF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
node->firstface = bsp->numfaces;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (f = node->faces; f; f = f->next) {
|
2003-02-04 23:26:26 +00:00
|
|
|
if (f->texturenum < 0)
|
|
|
|
continue;
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// if (f->outputnumber != -1)
|
|
|
|
// continue; // allready grown into an earlier region
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// emit a region
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->numfaces == MAX_MAP_FACES)
|
|
|
|
Sys_Error ("MAX_MAP_FACES");
|
|
|
|
f->outputnumber = bsp->numfaces;
|
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
r.planenum = node->outputplanenum;
|
|
|
|
r.side = f->planeside;
|
|
|
|
r.texinfo = f->texturenum;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < MAXLIGHTMAPS; i++)
|
2002-09-19 20:39:33 +00:00
|
|
|
r.styles[i] = 255;
|
|
|
|
r.lightofs = -1;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
// add the face and mergable neighbors to it
|
2002-09-19 16:58:48 +00:00
|
|
|
#if 0
|
|
|
|
ClearRegionSize ();
|
|
|
|
AddFaceToRegionSize (f);
|
|
|
|
RecursiveGrowRegion (r, f);
|
|
|
|
#endif
|
2002-09-19 20:39:33 +00:00
|
|
|
r.firstedge = firstedge = bsp->numsurfedges;
|
2003-09-08 03:00:53 +00:00
|
|
|
for (i = 0; i < f->points->numpoints; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->numsurfedges == MAX_MAP_SURFEDGES)
|
|
|
|
Sys_Error ("numsurfedges == MAX_MAP_SURFEDGES");
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddSurfEdge (bsp, f->edges[i]);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
r.numedges = bsp->numsurfedges - r.firstedge;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddFace (bsp, &r);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node->numfaces = bsp->numfaces - node->firstface;
|
|
|
|
|
|
|
|
GrowNodeRegion_r (node->children[0]);
|
|
|
|
GrowNodeRegion_r (node->children[1]);
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2002-09-19 18:51:19 +00:00
|
|
|
GrowNodeRegions (node_t *headnode)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
|
|
|
qprintf ("---- GrowRegions ----\n");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
GrowNodeRegion_r (headnode);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// RemoveColinearEdges ();
|
2002-09-19 16:58:48 +00:00
|
|
|
CountRealNumbers ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
Turn the faces on a plane into optimal non-convex regions
|
|
|
|
The edges may still be split later as a result of tjunctions
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
vec3_t dir;
|
|
|
|
vec3_t origin;
|
|
|
|
vec3_t p[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
for all faces
|
|
|
|
for all edges
|
|
|
|
for all edges so far
|
|
|
|
if overlap
|
|
|
|
split
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|