patch level to not have zero areas
authorhgn <hgodden00@gmail.com>
Fri, 21 Jul 2023 22:25:27 +0000 (23:25 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 21 Jul 2023 22:25:27 +0000 (23:25 +0100)
player_replay.c
scene.h
world_gate.c

index fc57680b7060349d8355ee6d58f630ab1cdaec04..5237e5f5b5d3451019c83061c3e82e9e976985a5 100644 (file)
@@ -533,13 +533,12 @@ VG_STATIC void skaterift_replay_debug_info(void){
 
    player__debugtext( 1, "head @%u | tail @%u\n", head, tail );
 
-   for( u32 i=0; i<4; i++ ){
-      player__debugtext( 1, "[%u]: [%hu, %hu]\n", i,
-           replay->statehead->data_table[i][0],
-           replay->statehead->data_table[i][1] );
-   }
-
    if( replay->statehead ){
+      for( u32 i=0; i<4; i++ ){
+         player__debugtext( 1, "[%u]: [%hu, %hu]\n", i,
+              replay->statehead->data_table[i][0],
+              replay->statehead->data_table[i][1] );
+      }
       u32 state = (void *)replay->statehead - replay->data;
       player__debugtext( 1, "gs @%u\n", state );
       player__debugtext( 1, "gamestate_size: %hu\n", 
diff --git a/scene.h b/scene.h
index c53c7b3c3c383f8198a1877a3c19965d3fce3c9c..13de419f2542d4f300087babb87ebbe581df49d7 100644 (file)
--- a/scene.h
+++ b/scene.h
@@ -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; i<sm->indice_count; i++ )
-      dst_indices[i] = src_indices[i] + ctx->vertex_count;
+   u32 real_indices = 0;
+   for( u32 i=0; i<sm->indice_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;
 }
 
 /*
index 64333da9f6db11ca65626db0d1f60a216f4d0af1..f757cdf8e1b760d167299c080b1731501e9ae1f8 100644 (file)
@@ -151,6 +151,7 @@ VG_STATIC int render_gate( world_instance *world, world_instance *world_inside,
       m4x3_copy( gate->to_world, mmdl );
       
       if( gate->flags & k_ent_gate_custom_mesh ){
+         shader_model_gate_uMdl( mmdl );
          mesh_bind( &world->mesh_no_collide );
          for( u32 i=0; i<gate->submesh_count; i++ ){
             mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, 
@@ -161,13 +162,11 @@ VG_STATIC int render_gate( world_instance *world, world_instance *world_inside,
       else {
          m3x3_scale( mmdl, (v3f){ gate->dimensions[0], 
                                   gate->dimensions[1], 1.0f } );
-
+         shader_model_gate_uMdl( mmdl );
          mesh_bind( &world_gates.mesh );
          mdl_draw_submesh( &world_gates.sm_surface );
       }
 
-      shader_model_gate_uMdl( mmdl );
-
       glClear( GL_DEPTH_BUFFER_BIT );
       glStencilFunc( GL_EQUAL, 1, 0xFF );
       glStencilMask( 0x00 );