qbsp: import BaseWindingForNode from qbsp3

This commit is contained in:
Eric Wasylishen 2022-06-17 22:10:11 -06:00
parent 3e2045479b
commit af2dd987d8
3 changed files with 38 additions and 0 deletions

View File

@ -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

View File

@ -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<winding_t> BaseWindingForNode(node_t *node)
{
auto plane = map.planes.at(node->planenum);
std::optional<winding_t> 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

View File

@ -865,7 +865,9 @@ static void PartitionBrushes(std::vector<std::unique_ptr<brush_t>> 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;