v3f co; /* 3*32 */
v2f uv; /* 2*32 */
i8 norm[4]; /* 4*8 */
- u16 unused[4];
+ u16 flags; /* only for the cpu. its junk on the gpu */
+ u16 unused[3];
};
#pragma pack(pop)
/* 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;
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 *src = &src_indices[i*3],
+ *dst = &dst_indices[real_indices];
+
+ v3f ab, ac, tn;
+ v3_sub( src_verts[src[2]].co, src_verts[src[0]].co, ab );
+ v3_sub( src_verts[src[1]].co, src_verts[src[0]].co, ac );
+ v3_cross( ac, ab, tn );
+
+#if 0
+ if( v3_length2( tn ) <= 0.00001f )
+ continue;
+#endif
+
+ dst[0] = src[0] + ctx->vertex_count;
+ dst[1] = src[1] + ctx->vertex_count;
+ dst[2] = src[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;
}
/*
ctx->submesh.vertex_start = ctx->vertex_count;
}
+VG_STATIC void scene_set_vertex_flags( scene_context *ctx,
+ u32 start, u32 count, u16 flags ){
+ for( u32 i=0; i<count; i++ )
+ ctx->arrvertices[ start + i ].flags = flags;
+}
+
struct scene_upload_info{
scene_context *ctx;
glmesh *mesh;
vg_line( pc->co, pa->co, 0xff0000ff );
}
+#if 0
VG_STATIC int scene_bh_ray( void *user, u32 index, v3f co,
v3f dir, ray_hit *hit )
{
return 0;
}
+#endif
VG_STATIC void scene_bh_closest( void *user, u32 index, v3f point, v3f closest )
{
.item_closest = scene_bh_closest,
.item_swap = scene_bh_swap,
.item_debug = scene_bh_debug,
- .cast_ray = scene_bh_ray
};
/*
* An extra step is added onto the end to calculate the hit normal
*/
VG_STATIC int scene_raycast( scene_context *s, bh_tree *bh,
- v3f co, v3f dir, ray_hit *hit )
+ v3f co, v3f dir, ray_hit *hit, u16 ignore )
{
- int count = bh_ray( bh, co, dir, hit );
+ hit->tri = NULL;
+
+ bh_iter it;
+ bh_iter_init_ray( 0, &it, co, dir, hit->dist );
+ i32 idx;
+
+ while( bh_next( bh, &it, &idx ) ){
+ u32 *tri = &s->arrindices[ idx*3 ];
+
+ if( s->arrvertices[tri[0]].flags & ignore ) continue;
+
+ v3f vs[3];
+ for( u32 i=0; i<3; i++ )
+ v3_copy( s->arrvertices[tri[i]].co, vs[i] );
+
+ f32 t;
+ if( ray_tri( vs, co, dir, &t ) ){
+ if( t < hit->dist ){
+ hit->dist = t;
+ hit->tri = tri;
+ }
+ }
+ }
- if( count ){
+ if( hit->tri ){
v3f v0, v1;
float *pa = s->arrvertices[hit->tri[0]].co,
v3_muladds( co, dir, hit->dist, hit->pos );
}
- return count;
+ return hit->tri?1:0;
}
VG_STATIC bh_tree *scene_bh_create( void *lin_alloc, scene_context *s )