- for( int j=i+1; j<new_polys-1; j++ )
- {
- for( int k=j+1; k<new_polys; k++ )
- {
- cxr_polygon *ptri = &pullmesh->polys[ pullmesh_new_start+i ],
- *ptrj = &pullmesh->polys[ pullmesh_new_start+j ],
- *ptrk = &pullmesh->polys[ pullmesh_new_start+k ];
-
- v4f planei, planej, planek;
- normal_to_plane(ptri->normal,ptri->center,planei);
- normal_to_plane(ptrj->normal,ptrj->center,planej);
- normal_to_plane(ptrk->normal,ptrk->center,planek);
-
- v3f intersect;
-
- if( plane_intersect(planei,planej,planek,intersect) )
- {
- // cxr_debug_box( intersect, 0.05, colour_error );
-
- // Make sure this point is within the convex region, otherwise treat
- // it as a degenerate case
-
- int point_valid = 1;
- for( int l=0; l<pullmesh->abpolys.count; l++ )
- {
- cxr_polygon *ptrl = &pullmesh->polys[l];
- v4f planel;
-
- normal_to_plane(ptrl->normal, ptrl->center, planel);
-
- if( plane_polarity( planel, intersect ) > 0.01 )
- {
- cxr_log( "degen vert, planes %d, %d, %d [max:%d]\n", i,j,k, new_polys );
- *error = CXR_ERROR_DEGEN_IMPLICIT;
-
- cxr_debug_poly( pullmesh, ptri, colours_random[3] );
- cxr_debug_poly( pullmesh, ptrj, colours_random[1] );
- cxr_debug_poly( pullmesh, ptrk, colours_random[2] );
-
- point_valid = 0;
- break;
- }
- }
-
- if( !point_valid ) continue;
-
- // Extend faces to include this point
- int nvertid = abverts->count;
- cxr_ab_push( abverts, intersect );
-
- ptrj->loop_start += 1;
- ptrk->loop_start += 2;
-
- cxr_ab_reserve( &pullmesh->abloops, 3);
-
- int newi = ptri->loop_start+ptri->loop_total,
- newj = ptrj->loop_start+ptrj->loop_total,
- newk = ptrk->loop_start+ptrk->loop_total;
-
- cxr_loop
- *lloopi = cxr_ab_empty_at(&pullmesh->abloops, newi),
- *lloopj = cxr_ab_empty_at(&pullmesh->abloops, newj),
- *lloopk = cxr_ab_empty_at(&pullmesh->abloops, newk);
-
- lloopi->index = nvertid;
- lloopi->edge_index = 0;
- lloopi->poly_left = pullmesh_new_start+i;
- lloopi->poly_right = -1;
-
- lloopj->index = nvertid;
- lloopj->poly_left = pullmesh_new_start+j;
- lloopj->edge_index = 0;
- lloopj->poly_right = -1;
-
- lloopk->index = nvertid;
- lloopk->edge_index = 0;
- lloopk->poly_left = pullmesh_new_start+k;
- lloopk->poly_right = -1;
-
- v2_zero(lloopi->uv);
- v2_zero(lloopj->uv);
- v2_zero(lloopk->uv);
-
- ptri->loop_total ++;
- ptrj->loop_total ++;
- ptrk->loop_total ++;
-
- // Adjust centers of faces
- v3_lerp( ptri->center, intersect, 1.0/(double)ptri->loop_total, ptri->center );
- v3_lerp( ptrj->center, intersect, 1.0/(double)ptrj->loop_total, ptrj->center );
- v3_lerp( ptrk->center, intersect, 1.0/(double)ptrk->loop_total, ptrk->center );
- }
- }
- }