diff --git a/include/qbsp/brushbsp.hh b/include/qbsp/brushbsp.hh index 4bd88c3d..32aa23ba 100644 --- a/include/qbsp/brushbsp.hh +++ b/include/qbsp/brushbsp.hh @@ -35,7 +35,9 @@ struct face_t; class mapentity_t; struct tree_t; -bool WindingIsTiny(const winding_t &w, double size = 0.2); +constexpr vec_t EDGE_LENGTH_EPSILON = 0.2; + +bool WindingIsTiny(const winding_t &w, double size = EDGE_LENGTH_EPSILON); std::unique_ptr BrushFromBounds(const aabb3d &bounds); std::unique_ptr BrushBSP(std::vector> brushlist); diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 595b20c5..92a04942 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -177,10 +177,10 @@ struct mapdata_t { // insert each vert at floor(pos[axis]) and floor(pos[axis]) + 1 (for each axis) // so e.g. a vert at (0.99, 0.99, 0.99) shows up if we search at (1.01, 1.01, 1.01) - // this is a bit wasteful, since it inserts 8 copies of each vert. - for (int32_t x = 0; x <= 1; x++) { - for (int32_t y = 0; y <= 1; y++) { - for (int32_t z = 0; z <= 1; z++) { + // this is a bit wasteful.. + for (int32_t x = -1; x <= 1; x++) { + for (int32_t y = -1; y <= 1; y++) { + for (int32_t z = -1; z <= 1; z++) { const qvec3i h{floor(point[0]) + x, floor(point[1]) + y, floor(point[2]) + z}; hashverts[h].push_front({ point, num }); } diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 9567ce3e..d445658b 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -355,12 +355,8 @@ Returns true if the winding would be crunched out of existance by the vertex snapping. ================ */ -#define EDGE_LENGTH 0.2 bool WindingIsTiny(const winding_t &w, double size) { -#if 0 - return w.area() < size; -#else int edges = 0; for (size_t i = 0; i < w.size(); i++) { size_t j = (i + 1) % w.size(); @@ -372,7 +368,6 @@ bool WindingIsTiny(const winding_t &w, double size) } } return true; -#endif } /* @@ -386,9 +381,10 @@ from basewinding for plane bool WindingIsHuge(const winding_t &w) { for (size_t i = 0; i < w.size(); i++) { - for (size_t j = 0; j < 3; j++) + for (size_t j = 0; j < 3; j++) { if (fabs(w[i][j]) > qbsp_options.worldextent.value()) return true; + } } return false; } diff --git a/qbsp/faces.cc b/qbsp/faces.cc index eb6bdb53..ffba872a 100644 --- a/qbsp/faces.cc +++ b/qbsp/faces.cc @@ -54,20 +54,10 @@ static void MergeNodeFaces(node_t *node) /* ============= EmitVertex -NOTE: modifies input to be rounded! ============= */ -inline void EmitVertex(qvec3d &vert, size_t &vert_id) +inline void EmitVertex(const qvec3d &vert, size_t &vert_id) { - // if we're extremely close to an integral point, - // snap us to it. - for (auto &v : vert) { - double rounded = Q_rint(v); - if (fabs(v - rounded) < ZERO_EPSILON) { - v = rounded; - } - } - // already added if (auto v = map.find_emitted_hash_vector(vert)) { vert_id = *v; @@ -80,7 +70,7 @@ inline void EmitVertex(qvec3d &vert, size_t &vert_id) map.bsp.dvertexes.emplace_back(vert); } -// snap windings & output final vertices +// output final vertices static void EmitFaceVertices(face_t *f) { if (ShouldOmitFace(f)) { diff --git a/qbsp/tjunc.cc b/qbsp/tjunc.cc index 56953441..298c8a4a 100644 --- a/qbsp/tjunc.cc +++ b/qbsp/tjunc.cc @@ -60,7 +60,7 @@ TestEdge Can be recursively reentered ========== */ -inline void TestEdge (vec_t start, vec_t end, size_t p1, size_t p2, size_t startvert, const std::vector &edge_verts, const qvec3d &edge_start, const qvec3d &edge_dir, std::vector &superface) +inline void TestEdge(vec_t start, vec_t end, size_t p1, size_t p2, size_t startvert, const std::vector &edge_verts, const qvec3d &edge_start, const qvec3d &edge_dir, std::vector &superface) { if (p1 == p2) { // degenerate edge @@ -194,12 +194,27 @@ inline void SplitFaceIntoFragments(std::vector &superface, std::vector &face, float angle_epsilon) +{ + if (AngleOfTriangle(map.bsp.dvertexes[v0], map.bsp.dvertexes[v1], map.bsp.dvertexes[v2]) < angle_epsilon || + AngleOfTriangle(map.bsp.dvertexes[v1], map.bsp.dvertexes[v2], map.bsp.dvertexes[v0]) < angle_epsilon || + AngleOfTriangle(map.bsp.dvertexes[v2], map.bsp.dvertexes[v0], map.bsp.dvertexes[v1]) < angle_epsilon) { + return false; + } + + return true; } /* @@ -274,7 +289,7 @@ static std::vector> RetopologizeFace(const std::vector