From 0263f95e59891c618a46371a4d8b6e92d4191c57 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 11 Jul 2017 17:54:28 -0600 Subject: [PATCH] qbsp: add -expand flag from q3map for testing hull1 expansion --- include/qbsp/qbsp.hh | 1 + include/qbsp/winding.hh | 1 - qbsp/map.cc | 82 +++++++++++++++++++++++++++++++++++++++++ qbsp/qbsp.cc | 3 ++ 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index efcc28c3..5ebbaa1e 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -358,6 +358,7 @@ public: bool fOmitDetailIllusionary; bool fOmitDetailFence; bool fForcePRT1; + bool fTestExpand; options_t() { memset(this, 0, sizeof(options_t)); diff --git a/include/qbsp/winding.hh b/include/qbsp/winding.hh index cf37735b..a8a29f16 100644 --- a/include/qbsp/winding.hh +++ b/include/qbsp/winding.hh @@ -37,7 +37,6 @@ typedef struct { winding_t *BaseWindingForPlane(const qbsp_plane_t *p); void CheckWinding(const winding_t *w); winding_t *NewWinding(int points); -void FreeWinding(winding_t *w); winding_t *CopyWinding(const winding_t *w); winding_t *ClipWinding(winding_t *in, const qbsp_plane_t *split, bool keepon); void DivideWinding(winding_t *in, const qbsp_plane_t *split, winding_t **front, diff --git a/qbsp/map.cc b/qbsp/map.cc index aa7ab4cd..df587dc6 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -1,6 +1,7 @@ /* Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1997 Greg Lewis + Copyright (C) 1999-2005 Id Software, Inc. 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 @@ -111,6 +112,7 @@ static texdef_valve_t TexDef_BSPToValve(const float in_vecs[2][4]); static qvec2f projectToAxisPlane(const vec3_t snapped_normal, qvec3f point); static texdef_quake_ed_noshift_t Reverse_QuakeEd(qmat2x2f M, const qbsp_plane_t *plane, bool preserveX); static void SetTexinfo_QuakeEd_New(const qbsp_plane_t *plane, const vec_t shift[2], vec_t rotate, const vec_t scale[2], float out_vecs[2][4]); +static void TestExpandBrushes(const mapentity_t *src); const mapface_t &mapbrush_t::face(int i) const { if (i < 0 || i >= this->numfaces) @@ -1757,6 +1759,10 @@ LoadMapFile(void) Message(msgStat, "%8d unique texnames", map.nummiptex()); Message(msgStat, "%8d texinfo", map.numtexinfo()); Message(msgLiteral, "\n"); + + if (options.fTestExpand) { + TestExpandBrushes (pWorldEnt()); + } } static texdef_valve_t @@ -2078,3 +2084,79 @@ WriteEntitiesToString(void) pCur[1] = '\n'; } } + +//==================================================================== + +/* +================== +WriteBspBrushMap + +from q3map +================== +*/ +static void +WriteBspBrushMap(char *name, const std::vector &list) +{ + FILE *f; + + logprint ("writing %s\n", name); + f = fopen (name, "wb"); + if (!f) + Error ("Can't write %s\b", name); + + fprintf (f, "{\n\"classname\" \"worldspawn\"\n"); + + for (brush_t *brush : list) + { + fprintf (f, "{\n"); + for (face_t *face = brush->faces; face; face = face->next) + { + // FIXME: Factor out this mess + qbsp_plane_t plane = map.planes.at(face->planenum); + if (face->planeside) { + VectorScale(plane.normal, -1, plane.normal); + plane.dist = -plane.dist; + } + + winding_t *w = BaseWindingForPlane(&plane); + + fprintf (f,"( %g %g %g ) ", w->points[0][0], w->points[0][1], w->points[0][2]); + fprintf (f,"( %g %g %g ) ", w->points[1][0], w->points[1][1], w->points[1][2]); + fprintf (f,"( %g %g %g ) ", w->points[2][0], w->points[2][1], w->points[2][2]); + + fprintf (f, "notexture 0 0 0 1 1\n" ); + + FreeMem(w, WINDING, 1); + } + fprintf (f, "}\n"); + } + fprintf (f, "}\n"); + + fclose (f); +} + +/* +================ +TestExpandBrushes + +Expands all the brush planes and saves a new map out to +allow visual inspection of the clipping bevels + +from q3map +================ +*/ +static void +TestExpandBrushes(const mapentity_t *src) +{ + std::vector hull1brushes; + + for (int i = 0; i < src->nummapbrushes; i++) { + const mapbrush_t *mapbrush = &src->mapbrush(i); + brush_t *hull1brush = LoadBrush(mapbrush, vec3_origin, 1); + + if (hull1brush != nullptr) + hull1brushes.push_back(hull1brush); + } + + WriteBspBrushMap("expanded.map", hull1brushes); +} diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 35426ae7..6d4903a0 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -686,6 +686,7 @@ PrintOptions(void) " -omitdetailillusionary func_detail_illusionary brushes are omitted from the compile\n" " -omitdetailfence func_detail_fence brushes are omitted from the compile\n" " -convert Convert a .MAP to a different .MAP format. fmt can be: quake, quake2, valve, bp (brush primitives).\n" + " -expand Write hull 1 expanded brushes to expanded.map for debugging\n" " sourcefile .MAP file to process\n" " destfile .BSP file to output\n"); @@ -884,6 +885,8 @@ ParseOptions(char *szOptions) options.fForcePRT1 = true; logprint("WARNING: Forcing creation of PRT1.\n"); logprint(" Only use this for viewing portals in a map editor.\n"); + } else if (!Q_strcasecmp(szTok, "expand")) { + options.fTestExpand = true; } else if (!Q_strcasecmp(szTok, "?") || !Q_strcasecmp(szTok, "help")) PrintOptions(); else