From af2dd987d884ef0bc107fab9b10511c76052c00a Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 17 Jun 2022 22:10:11 -0600 Subject: [PATCH] qbsp: import BaseWindingForNode from qbsp3 --- include/qbsp/qbsp.hh | 1 + qbsp/portals.cc | 33 +++++++++++++++++++++++++++++++++ qbsp/solidbsp.cc | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 2a39f6d7..5c4e5ce5 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -355,6 +355,7 @@ struct portal_t; struct node_t { aabb3d bounds; // bounding volume, not just points inside + node_t *parent; // information for decision nodes int planenum; // -1 = leaf node diff --git a/qbsp/portals.cc b/qbsp/portals.cc index d5c36d37..ab9b241f 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -225,6 +225,39 @@ static void CheckLeafPortalConsistancy(node_t *node) //============================================================================ +/* +================ +BaseWindingForNode + +Creates a winding from the given node plane, clipped by all parent nodes. +================ +*/ +#define BASE_WINDING_EPSILON 0.001 +#define SPLIT_WINDING_EPSILON 0.001 + +std::optional BaseWindingForNode(node_t *node) +{ + auto plane = map.planes.at(node->planenum); + + std::optional w = BaseWindingForPlane(plane); + + // clip by all the parents + for (node_t *np = node->parent; np && w; ) + { + plane = map.planes.at(np->planenum); + + const side_t keep = (np->children[0] == node) ? + SIDE_FRONT : SIDE_BACK; + + w = w->clip(plane, BASE_WINDING_EPSILON, false)[keep]; + + node = np; + np = np->parent; + } + + return w; +} + /* ================ CutNodePortals_r diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index eb6a92f6..cbd4fc3e 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -865,7 +865,9 @@ static void PartitionBrushes(std::vector> brushes, node splitnodes++; node->children[0] = new node_t{}; + node->children[0]->parent = node; node->children[1] = new node_t{}; + node->children[1]->parent = node; node->planenum = FindPositivePlane(split->planenum); node->detail_separator = AllDetail(brushes); @@ -933,9 +935,11 @@ tree_t *BrushBSP(mapentity_t *entity, bool midsplit) headnode->children[0] = new node_t{}; headnode->children[0]->planenum = PLANENUM_LEAF; headnode->children[0]->contents = options.target_game->create_empty_contents(); + headnode->children[0]->parent = headnode; headnode->children[1] = new node_t{}; headnode->children[1]->planenum = PLANENUM_LEAF; headnode->children[1]->contents = options.target_game->create_empty_contents(); + headnode->children[1]->parent = headnode; tree->headnode = headnode; tree->bounds = headnode->bounds;