-static void scene_fix( scene *pscene )
-{
- buffer_fix( pscene->verts, pscene->vertex_count,
- &pscene->vertex_cap, sizeof( mdl_vert ));
-
- buffer_fix( pscene->indices, pscene->indice_count,
- &pscene->indice_cap, sizeof( mdl_vert ));
-}
-
-static void scene_upload( scene *pscene )
-{
- mesh_upload( &pscene->mesh,
- pscene->verts, pscene->vertex_count,
- pscene->indices, pscene->indice_count );
-
- vg_info( "Scene upload\n" );
- vg_info( " indices:%u\n", pscene->indice_count );
- vg_info( " verts:%u\n", pscene->vertex_count );
-}
-
-static void scene_bind( scene *pscene )
-{
- mesh_bind( &pscene->mesh );
-}
-
-static void scene_draw( scene *pscene )
-{
- mesh_drawn( 0, pscene->indice_count );
-}
-
-static void scene_free( scene *pscene )
-{
- free( pscene->verts );
- free( pscene->indices );
-
- /* TODO: bvh */
-}
-
-static void scene_register(void)
-{
-}
-
-/*
- * BVH implementation
- */
-
-static void scene_bh_expand_bound( void *user, boxf bound, u32 item_index )
-{
- scene *s = user;
- mdl_vert *pa = &s->verts[ s->indices[item_index*3+0] ],
- *pb = &s->verts[ s->indices[item_index*3+1] ],
- *pc = &s->verts[ s->indices[item_index*3+2] ];
-
- box_addpt( bound, pa->co );
- box_addpt( bound, pb->co );
- box_addpt( bound, pc->co );
-}
-
-static float scene_bh_centroid( void *user, u32 item_index, int axis )
-{
- scene *s = user;
- mdl_vert *pa = &s->verts[ s->indices[item_index*3+0] ],
- *pb = &s->verts[ s->indices[item_index*3+1] ],
- *pc = &s->verts[ s->indices[item_index*3+2] ];
-
- return (pa->co[axis] + pb->co[axis] + pc->co[axis]) * (1.0f/3.0f);
-}
-
-static void scene_bh_swap( void *user, u32 ia, u32 ib )
-{
- scene *s = user;
-
- u32 *ti = &s->indices[ia*3];
- u32 *tj = &s->indices[ib*3];
-
- u32 temp[3];
- temp[0] = ti[0];
- temp[1] = ti[1];
- temp[2] = ti[2];
-
- ti[0] = tj[0];
- ti[1] = tj[1];
- ti[2] = tj[2];
-
- tj[0] = temp[0];
- tj[1] = temp[1];
- tj[2] = temp[2];
-}
-
-static void scene_bh_debug( void *user, u32 item_index )
-{
- scene *s = user;
- u32 idx = item_index*3;
- mdl_vert *pa = &s->verts[ s->indices[ idx+0 ] ],
- *pb = &s->verts[ s->indices[ idx+1 ] ],
- *pc = &s->verts[ s->indices[ idx+2 ] ];
-
- vg_line( pa->co, pb->co, 0xff0000ff );
- vg_line( pb->co, pc->co, 0xff0000ff );
- vg_line( pc->co, pa->co, 0xff0000ff );
-}
-
-static int scene_bh_ray( void *user, u32 index, v3f co, v3f dir, ray_hit *hit )
-{
- scene *s = user;
- v3f positions[3];
-
- u32 *tri = &s->indices[ index*3 ];
-
- for( int i=0; i<3; i++ )
- v3_copy( s->verts[tri[i]].co, positions[i] );
-
- float t;
- if(ray_tri( positions, co, dir, &t ))
- {
- if( t < hit->dist )
- {
- hit->dist = t;
- hit->tri = tri;
- return 1;
- }
- }
-
- return 0;
-}
-
-static bh_system bh_system_scene =
-{
- .expand_bound = scene_bh_expand_bound,
- .item_centroid = scene_bh_centroid,
- .item_swap = scene_bh_swap,
- .item_debug = scene_bh_debug,
- .cast_ray = scene_bh_ray