return count;
}
+static int bvh_select_triangles( scene *s, boxf box, u32 *triangles, int len )
+{
+ vg_line_boxf( box, 0xffffff00 );
+
+ /* TODO: use this stack system on the raycast function */
+ int count = 0;
+ u32 stack[100];
+ u32 depth = 1;
+
+ stack[0] = 0;
+ stack[1] = s->bvh.nodes[0].il;
+ stack[2] = s->bvh.nodes[0].ir;
+
+ while(depth)
+ {
+ bvh_node *inode = &s->bvh.nodes[ stack[depth] ];
+ if( box_overlap( inode->bbx, box ) )
+ {
+ if( inode->count )
+ {
+ if( count + inode->count >= len )
+ return count;
+
+ for( u32 i=0; i<inode->count; i++ )
+ triangles[ count ++ ] = (inode->start+i)*3;
+
+ depth --;
+ }
+ else
+ {
+ if( depth+1 >= vg_list_size(stack) )
+ {
+ vg_error( "Maximum stack reached!" );
+ return count;
+ }
+
+ stack[depth] = inode->il;
+ stack[depth+1] = inode->ir;
+ depth ++;
+ }
+ }
+ else
+ {
+ depth --;
+ }
+ }
+
+ return count;
+}
+
static int bvh_scene_sample_node_h( scene *s, u32 inode, v3f pos, v3f norm )
{
bvh_node *node = &s->bvh.nodes[ inode ];