summaryrefslogtreecommitdiff
path: root/src/game/world/bsp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/world/bsp.cpp')
-rw-r--r--src/game/world/bsp.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/game/world/bsp.cpp b/src/game/world/bsp.cpp
index 7f72e52..c33cac1 100644
--- a/src/game/world/bsp.cpp
+++ b/src/game/world/bsp.cpp
@@ -417,6 +417,10 @@ I32 bsp_build_nodes(
}
U8 bsp_edge_is_shared( BSP* bsp, VEC3 edge1a, VEC3 edge1b, VEC3 center, VEC3 ecross, U32 facei ) {
+ BSP_FACE* face = &bsp->faces[facei];
+ VEC3 n = bsp_face_get_normal( face );
+ U8 aligned = bsp_face_is_axis_aligned( face );
+
for( U32 i = 0; i < bsp->faces.size; ++i ) {
if( facei == i )
continue;
@@ -425,6 +429,12 @@ U8 bsp_edge_is_shared( BSP* bsp, VEC3 edge1a, VEC3 edge1b, VEC3 center, VEC3 ecr
if( other->verts.size < 3 )
continue;
+ VEC3 othern = bsp_face_get_normal( face );
+ F32 d = vec_dot( n, othern );
+ // dont create edge planes for planes that are axis-aligned and directly perpendicular
+ if( aligned && (d < BSP_NORM_EPSILON || d > 1.f - BSP_NORM_EPSILON) )
+ continue;
+
VEC3 otherc{};
for( U32 vi = 0; vi < other->verts.size; ++vi )
otherc += other->verts[vi].pos;
@@ -487,9 +497,6 @@ void bsp_gen_leaf_edges( BSP* bsp, I32 leaf_idx ) {
if( fabsf( vec_dot( cross, facen ) ) > 0.995f )
continue;
- if( !bsp_edge_is_shared( bsp, a, b, center, cross, faceidx ) )
- continue;
-
F32 d = vec_dot( cross, a );
BSP_PLANE plane = { cross, d };
U8 dupe = 0;
@@ -500,6 +507,9 @@ void bsp_gen_leaf_edges( BSP* bsp, I32 leaf_idx ) {
if( dupe )
continue;
+ if( !bsp_edge_is_shared( bsp, a, b, center, cross, faceidx ) )
+ continue;
+
BSP_EDGE e;
e.plane = plane;
e.face = faceidx;