bsputil: Check that face verticies lie on the face plane

Yet another consistency check.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-08-18 16:34:27 +09:30
parent c2fbde6af7
commit 33eff1ded9
1 changed files with 34 additions and 0 deletions

View File

@ -106,6 +106,39 @@ PrintModelInfo(const bspdata_t *bsp)
}
}
/*
* Quick hack to check verticies of faces lie on the correct plane
*/
#define ON_EPSILON 0.01
vec3_t vec3_origin = { 0, 0, 0 };
static void
CheckBSPFacesPlanar(const bspdata_t *bsp)
{
int i, j;
for (i = 0; i < bsp->numfaces; i++) {
const dface_t *face = &bsp->dfaces[i];
dplane_t plane = bsp->dplanes[face->planenum];
if (face->side) {
VectorSubtract(vec3_origin, plane.normal, plane.normal);
plane.dist = -plane.dist;
}
for (j = 0; j < face->numedges; j++) {
const int edgenum = bsp->dsurfedges[face->firstedge + j];
const int vertnum = (edgenum >= 0) ? bsp->dedges[edgenum].v[0] : bsp->dedges[-edgenum].v[1];
const float *point = bsp->dvertexes[vertnum].point;
const float dist = DotProduct(plane.normal, point) - plane.dist;
if (dist < -ON_EPSILON || dist > ON_EPSILON)
printf("WARNING: face %d, point %d off plane by %f\n",
face - bsp->dfaces, j, dist);
}
}
}
static void
CheckBSPFile(const bspdata_t *bsp)
{
@ -282,6 +315,7 @@ main(int argc, char **argv)
} else if (!strcmp(argv[i], "--check")) {
printf("Beginning BSP data check...\n");
CheckBSPFile(&bsp);
CheckBSPFacesPlanar(&bsp);
printf("Done.\n");
} else if (!strcmp(argv[i], "--modelinfo")) {
PrintModelInfo(&bsp);