light: add -debugvert command

This commit is contained in:
Eric Wasylishen 2016-07-20 19:05:55 -06:00
parent 42c4195ad6
commit 4c59a00d2b
2 changed files with 50 additions and 0 deletions

View File

@ -228,6 +228,9 @@ extern sun_t *suns;
extern int dump_facenum;
extern bool dump_face;
extern int dump_vertnum;
extern bool dump_vert;
/* command-line options */

View File

@ -108,6 +108,11 @@ int dump_facenum = -1;
bool dump_face;
vec3_t dump_face_point = {0,0,0};
int dump_vertnum = -1;
bool dump_vert;
vec3_t dump_vert_point = {0,0,0};
void
GetFileSpace(byte **lightdata, byte **colordata, byte **deluxdata, int size)
{
@ -1237,6 +1242,44 @@ void FindDebugFace(const bsp2_t *bsp)
dump_facenum = facenum;
}
// returns the vert nearest the given point
static int
Vertex_NearestPoint(const bsp2_t *bsp, const vec3_t point)
{
int nearest_vert = -1;
vec_t nearest_dist = VECT_MAX;
for (int i=0; i<bsp->numvertexes; i++) {
const dvertex_t *vertex = &bsp->dvertexes[i];
vec3_t distvec;
VectorSubtract(vertex->point, point, distvec);
vec_t dist = VectorLength(distvec);
if (dist < nearest_dist) {
nearest_dist = dist;
nearest_vert = i;
}
}
return nearest_vert;
}
void FindDebugVert(const bsp2_t *bsp)
{
if (!dump_vert)
return;
int v = Vertex_NearestPoint(bsp, dump_vert_point);
const dvertex_t *vertex = &bsp->dvertexes[v];
logprint("FindDebugVert: dumping vert %d at %f %f %f\n", v,
vertex->point[0],
vertex->point[1],
vertex->point[2]);
dump_vertnum = v;
}
static void PrintUsage()
{
printf("usage: light [options] mapname.bsp\n"
@ -1581,6 +1624,9 @@ main(int argc, const char **argv)
} else if ( !strcmp( argv[ i ], "-debugface" ) ) {
ParseVec3(dump_face_point, &i, argc, argv);
dump_face = true;
} else if ( !strcmp( argv[ i ], "-debugvert" ) ) {
ParseVec3(dump_vert_point, &i, argc, argv);
dump_vert = true;
} else if ( !strcmp( argv[ i ], "-sunlight" ) ) {
sunlight.value = ParseVec(&i, argc, argv);
sunlight.locked = true;
@ -1691,6 +1737,7 @@ main(int argc, const char **argv)
LoadEntities(bsp);
FindDebugFace(bsp);
FindDebugVert(bsp);
modelinfo = (modelinfo_t *)malloc(bsp->nummodels * sizeof(*modelinfo));
FindModelInfo(bsp, lmscaleoverride);