X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=scene.h;h=13de419f2542d4f300087babb87ebbe581df49d7;hb=4b8fc63f926737ca0593a4e471550f9f4995c538;hp=027f4bded5c3bd6b8dc9f2b9f1ed038a15b3ab2b;hpb=b4a83d4fcab39bee5a8cd6e8e6eec06314864e5b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/scene.h b/scene.h index 027f4bd..13de419 100644 --- a/scene.h +++ b/scene.h @@ -110,8 +110,8 @@ VG_STATIC void scene_add_mdl_submesh( scene_context *ctx, mdl_context *mdl, /* Transform and place vertices */ boxf bbxnew; - box_copy( sm->bbx, bbxnew ); - m4x3_transform_aabb( transform, bbxnew ); + box_init_inf( bbxnew ); + m4x3_expand_aabb_aabb( transform, bbxnew, sm->bbx ); box_concat( ctx->bbx, bbxnew ); m3x3f normal_matrix; @@ -133,11 +133,30 @@ VG_STATIC void scene_add_mdl_submesh( scene_context *ctx, mdl_context *mdl, v2_copy( src->uv, pvert->uv ); } - for( u32 i=0; iindice_count; i++ ) - dst_indices[i] = src_indices[i] + ctx->vertex_count; + u32 real_indices = 0; + for( u32 i=0; iindice_count/3; i++ ){ + u32 *tri = &src_indices[i*3]; + + v3f ab, ac, tn; + v3_sub( src_verts[tri[2]].co, src_verts[tri[0]].co, ab ); + v3_sub( src_verts[tri[1]].co, src_verts[tri[0]].co, ac ); + v3_cross( ac, ab, tn ); + + if( v3_length2( tn ) <= 0.00001f ) + continue; + + dst_indices[real_indices+0] = tri[0] + ctx->vertex_count; + dst_indices[real_indices+1] = tri[1] + ctx->vertex_count; + dst_indices[real_indices+2] = tri[2] + ctx->vertex_count; + + real_indices += 3; + } + + if( real_indices != sm->indice_count ) + vg_warn( "Zero area triangles in model\n" ); ctx->vertex_count += sm->vertex_count; - ctx->indice_count += sm->indice_count; + ctx->indice_count += real_indices; } /*