assorted crap
[carveJwlIkooP6JGAAIwe30JlM.git] / scene.h
diff --git a/scene.h b/scene.h
index 5d436875cfd3187a7efd04ec980f5ee55699d2ce..7fc29f3ad94c8e2a2019d6d964bd76b99aa00537 100644 (file)
--- a/scene.h
+++ b/scene.h
@@ -4,6 +4,7 @@
 #include "common.h"
 #include "model.h"
 #include "bvh.h"
+#include "distq.h"
 
 typedef struct scene scene;
 
@@ -100,6 +101,10 @@ VG_STATIC void scene_add_submesh( scene *pscene, mdl_context *mdl,
       pvert->colour[1] = src->colour[1];
       pvert->colour[2] = src->colour[2];
       pvert->colour[3] = src->colour[3];
+      pvert->weights[0] = src->weights[0];
+      pvert->weights[1] = src->weights[1];
+      pvert->weights[2] = src->weights[2];
+      pvert->weights[3] = src->weights[3];
       v2_copy( src->uv, pvert->uv );
    }
 
@@ -296,10 +301,23 @@ VG_STATIC int scene_bh_ray( void *user, u32 index, v3f co,
    return 0;
 }
 
+VG_STATIC void scene_bh_closest( void *user, u32 index, v3f point, v3f closest )
+{
+   scene *s = user;
+
+   v3f positions[3];
+   u32 *tri = &s->arrindices[ index*3 ];
+   for( int i=0; i<3; i++ )
+      v3_copy( s->arrvertices[tri[i]].co, positions[i] );
+
+   closest_on_triangle_1( point, positions, closest );
+}
+
 VG_STATIC bh_system bh_system_scene = 
 {
    .expand_bound = scene_bh_expand_bound,
    .item_centroid = scene_bh_centroid,
+   .item_closest = scene_bh_closest,
    .item_swap = scene_bh_swap,
    .item_debug = scene_bh_debug,
    .cast_ray = scene_bh_ray