yet more stability improvements
authorhgn <hgodden00@gmail.com>
Fri, 8 Apr 2022 20:27:25 +0000 (21:27 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 8 Apr 2022 20:27:25 +0000 (21:27 +0100)
__init__.py
src/convexer.c

index cb377479815524c85b349b0ecaae0271bbaa5401..624bce098f7740768c3f6e2204ff5c4b25e67bdb 100644 (file)
@@ -636,6 +636,16 @@ cxr_entities = {
          "enabled": {"type": "int", "default": 1 },
       })
    },
+   "info_player_terrorist":
+   {
+      "gizmo": [],
+      "allow": ('EMPTY',),
+      "keyvalues": ent_baseclass([ent_transform],\
+      {
+         "priority": {"type": "int", "default": 0 },
+         "enabled": {"type": "int", "default": 1 },
+      })
+   },
    "light": { "keyvalues": ent_lights },
    "light_spot": { "keyvalues": ent_lights },
    # SUN
index 5fac72984d2f489a9aefdc7632d39e8c0489871e..28f705616accda1f5cde14c0a25b5b6ad25a8096 100644 (file)
@@ -762,6 +762,48 @@ static struct cxr_mesh *cxr_pull_island(struct cxr_mesh *mesh)
    return newmesh;
 }
 
+// Does some checks to determine if solid is valid or not
+static int cxr_valid_solid( struct cxr_mesh *mesh, struct cxr_auto_buffer *abverts, int *solid, int len )
+{
+   // Invalid 1: Similar normals
+   // Invalid 2: Co-planar point, that is not referenced by the polygon.
+   //
+   for( int i=0; i<len; i++ )
+   {
+      struct cxr_polygon *polyi = cxr_ab_ptr(&mesh->polys,solid[i]);
+      
+      v4f plane;
+      normal_to_plane(polyi->normal, polyi->center, plane);
+
+      for( int j=0; j<len; j++ )
+      {
+         if( i==j ) continue;
+         
+         struct cxr_polygon *polyj = cxr_ab_ptr(&mesh->polys,solid[j]);
+
+         for( int k=0; k<polyj->loop_total; k++ )
+         {
+            struct cxr_loop *lpj = cxr_ab_ptr(&mesh->loops, polyj->loop_start+k);
+            
+            // Make sure this point isnt in our original poly
+            for( int l=0; l<polyi->loop_total; l++ )
+            {
+               struct cxr_loop *lpi = cxr_ab_ptr(&mesh->loops, polyi->loop_start+l);
+               if( lpi->index == lpj->index )
+                  goto IL_SKIP_VERTEX;
+            }
+            
+            if( fabs(plane_polarity(plane,cxr_ab_ptr(abverts,lpj->index))) < 0.001 )
+               return 0;
+
+IL_SKIP_VERTEX:;
+         }
+      }
+   }
+
+   return 1;
+}
+
 // Return best availible solid from mesh, and patch existing mesh to fill the gap
 // creted by it. 
 //
@@ -912,7 +954,7 @@ IL_TAG_NEXT_VERT:;
          edge_tagged[i] = 1;
    }
 
-   
+#if 0
    for( int i=0; i<vert_buffer->count; i++ )
       if( vertex_tagged[i] )
          cxr_debug_box( vertices[i], 0.03, (v4f){0.0,0.0,0.0,1.0});
@@ -926,7 +968,7 @@ IL_TAG_NEXT_VERT:;
       if( hot_edge[i] )
          cxr_debug_line( vertices[ edge->i0 ], vertices[ edge->i1 ], (v4f){0.0,1.0,1.0,1.0});
    }
-   
+#endif
 
    // count regions
    int *faces_tagged = malloc(mesh->polys.count*sizeof(int));
@@ -1014,9 +1056,17 @@ IL_TAG_NEXT_VERT:;
                      IL_SKIP_SIMILAR_PLANES:;
                   }
 
-                  solid[ solid_len ++ ] = loop->poly_right;
-                  faces_tagged[ loop->poly_right ] = i;
-                  changed = 1;
+                  // Check for vertices in the new poly that exist on a current plane.
+                  //  this condition is an invalid configuration and should not be added.
+
+                  solid[ solid_len ] = loop->poly_right;
+
+                  if( cxr_valid_solid(mesh,vert_buffer,solid,solid_len+1 ) )
+                  {
+                     faces_tagged[ loop->poly_right ] = i;
+                     changed = 1;
+                     solid_len ++;
+                  }
                }
 
                IL_SKIP_PLANE_ADD:;
@@ -2697,6 +2747,19 @@ CXR_API i32 cxr_convert_mesh_to_vmf(struct cxr_input_mesh *src, struct cxr_vdf *
             cxr_debug_mesh( solid->pmesh, cxr_ab_ptr(&abverts,0), colours_random[cxr_range(i,8)] );
       }
    }
+   
+   if( error )
+   {
+      for( int i=0; i<solids.count; i++ )
+      {
+         struct solidinf *solid = cxr_ab_ptr(&solids,i);
+         cxr_free_mesh( solid->pmesh );
+      }
+
+      cxr_ab_free( &abverts );
+      cxr_ab_free( &solids );
+      return error;
+   }
 
    // Turn all those solids into VMF brushes
    // --------------------------------------