diff --git a/include/qbsp/brushbsp.hh b/include/qbsp/brushbsp.hh index d62ecd26..5ba15cc6 100644 --- a/include/qbsp/brushbsp.hh +++ b/include/qbsp/brushbsp.hh @@ -98,6 +98,7 @@ enum tree_split_t FAST }; +vec_t BrushVolume(const bspbrush_t &brush); bspbrush_t::ptr BrushFromBounds(const aabb3d &bounds); void BrushBSP(tree_t &tree, mapentity_t &entity, const bspbrush_t::container &brushes, tree_split_t split_type); void ChopBrushes(bspbrush_t::container &brushes, bool allow_fragmentation); \ No newline at end of file diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 4d2608c9..ebef3dfa 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -366,6 +366,8 @@ public: setting_bool debugleak{this, "debugleak", false, &debugging_group, "write more diagnostic files for debugging leaks"}; setting_bool debugbspbrushes{ this, "debugbspbrushes", false, &debugging_group, "save bsp brushes after BrushBSP to a .map, for visualizing BSP splits"}; + setting_bool debugleafvolumes{this, "debugleafvolumes", false, &debugging_group, + "save bsp leaf volumes after BrushBSP to a .map, for visualizing BSP splits"}; setting_debugexpand debugexpand{this, "debugexpand", &debugging_group, "write expanded hull .map for debugging/inspecting hulls/brush bevelling"}; setting_bool keepprt{this, "keepprt", false, &debugging_group, "avoid deleting the .prt file on leaking maps"}; setting_bool includeskip{this, "includeskip", false, &common_format_group, diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 44f05337..1ce7aafc 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -152,6 +152,11 @@ static vec_t BrushVolume(T begin, T end) return volume; } +vec_t BrushVolume(const bspbrush_t &brush) +{ + return BrushVolume(brush.sides.begin(), brush.sides.end()); +} + //======================================================== /* @@ -554,7 +559,7 @@ static twosided SplitBrush(bspbrush_t::ptr brush, size_t planen } for (int i = 0; i < 2; i++) { - vec_t v1 = BrushVolume(result[i]->sides.begin(), result[i]->sides.end()); + vec_t v1 = BrushVolume(*result[i]); if (v1 < qbsp_options.microvolume.value()) { result[i] = nullptr; if (stats) { diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 2202792c..510662ef 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -402,6 +402,17 @@ static void GatherBspbrushes_r(node_t *node, bspbrush_t::container &container) GatherBspbrushes_r(node->children[1], container); } +static void GatherLeafVolumes_r(node_t *node, bspbrush_t::container &container) +{ + if (node->is_leaf) { + container.push_back(node->volume); + return; + } + + GatherLeafVolumes_r(node->children[0], container); + GatherLeafVolumes_r(node->children[1], container); +} + /* =============== ProcessEntity @@ -529,10 +540,17 @@ static void ProcessEntity(mapentity_t &entity, hull_index_t hullnum) if (map.is_world_entity(entity)) { // debug output of bspbrushes - if (qbsp_options.debugbspbrushes.value() && (!hullnum.has_value() || hullnum.value() == 0)) { - bspbrush_t::container all_bspbrushes; - GatherBspbrushes_r(tree.headnode, all_bspbrushes); - WriteBspBrushMap("first-brushbsp", all_bspbrushes); + if (!hullnum.has_value() || hullnum.value() == 0) { + if (qbsp_options.debugbspbrushes.value()) { + bspbrush_t::container all_bspbrushes; + GatherBspbrushes_r(tree.headnode, all_bspbrushes); + WriteBspBrushMap("first-brushbsp", all_bspbrushes); + } + if (qbsp_options.debugleafvolumes.value()) { + bspbrush_t::container all_bspbrushes; + GatherLeafVolumes_r(tree.headnode, all_bspbrushes); + WriteBspBrushMap("first-brushbsp-volumes", all_bspbrushes); + } } // flood fills from the void. @@ -545,10 +563,17 @@ static void ProcessEntity(mapentity_t &entity, hull_index_t hullnum) BrushBSP(tree, entity, brushes, tree_split_t::PRECISE); // debug output of bspbrushes - if (qbsp_options.debugbspbrushes.value() && (!hullnum.has_value() || hullnum.value() == 0)) { - bspbrush_t::container all_bspbrushes; - GatherBspbrushes_r(tree.headnode, all_bspbrushes); - WriteBspBrushMap("second-brushbsp", all_bspbrushes); + if (!hullnum.has_value() || hullnum.value() == 0) { + if (qbsp_options.debugbspbrushes.value()) { + bspbrush_t::container all_bspbrushes; + GatherBspbrushes_r(tree.headnode, all_bspbrushes); + WriteBspBrushMap("second-brushbsp", all_bspbrushes); + } + if (qbsp_options.debugleafvolumes.value()) { + bspbrush_t::container all_bspbrushes; + GatherLeafVolumes_r(tree.headnode, all_bspbrushes); + WriteBspBrushMap("second-brushbsp-volumes", all_bspbrushes); + } } // make the real portals for vis tracing