From 1ac4bf5a6b2bc56f22e8642cbf3d63496c7bbef0 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 15 Sep 2017 21:08:04 -0600 Subject: [PATCH] qbsp: hack to fix slightly off grid overlapping brushes having missing the overlapping parts deleted after CSG fixes https://github.com/ericwa/tyrutils-ericw/issues/174 --- qbsp/csg4.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/qbsp/csg4.cc b/qbsp/csg4.cc index 85a65946..e648339d 100644 --- a/qbsp/csg4.cc +++ b/qbsp/csg4.cc @@ -275,9 +275,29 @@ ClipInside(const face_t *clipface, bool precedence, while (face) { next = face->next; + /* HACK: Check for on-plane but not the same planenum + ( https://github.com/ericwa/tyrutils-ericw/issues/174 ) + */ + bool spurious_onplane = false; + { + vec_t dists[MAXEDGES + 1]; + int sides[MAXEDGES + 1]; + int counts[3]; + + CalcSides(&face->w, splitplane, sides, dists, counts); + if (counts[SIDE_ON] && !counts[SIDE_FRONT] && !counts[SIDE_BACK]) { + spurious_onplane = true; + } + } + /* Handle exactly on-plane faces */ - if (face->planenum == clipface->planenum) { - if (clipface->planeside != face->planeside || precedence) { + if (face->planenum == clipface->planenum || spurious_onplane) { + const plane_t faceplane = Face_Plane(face); + const plane_t clipfaceplane = Face_Plane(clipface); + const vec_t dp = DotProduct(faceplane.normal, clipfaceplane.normal); + const bool opposite = (dp < 0); + + if (opposite || precedence) { /* always clip off opposite facing */ frags[clipface->planeside] = NULL; frags[!clipface->planeside] = face;