+// 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;
+}
+