+#ifdef RIGIDBODY_DYNAMIC_MESH_EDGES
+ /* !experimental! build edge array on the fly. time could be improved! */
+
+ v3f co_picture[128*3];
+ int unique_cos = 0;
+
+ struct face_info
+ {
+ int unique_cos[3]; /* indexes co_picture array */
+ int collided;
+ v3f normal;
+ u32 element_id;
+ }
+ faces[128];
+
+ /* create geometry picture */
+ for( int i=0; i<len; i++ )
+ {
+ u32 *tri_indices = &sc->arrindices[ geo[i]*3 ];
+ struct face_info *inf = &faces[i];
+ inf->element_id = tri_indices[0];
+ inf->collided = 0;
+
+ for( int j=0; j<3; j++ )
+ {
+ struct mdl_vert *pvert = &sc->arrvertices[tri_indices[j]];
+
+ for( int k=0; k<unique_cos; k++ )
+ {
+ if( v3_dist( pvert->co, co_picture[k] ) < 0.01f*0.01f )
+ {
+ inf->unique_cos[j] = k;
+ goto next_vert;
+ }
+ }
+
+ inf->unique_cos[j] = unique_cos;
+ v3_copy( pvert->co, co_picture[ unique_cos ++ ] );
+next_vert:;
+ }
+
+ v3f ab, ac;
+ v3_sub( co_picture[inf->unique_cos[2]],
+ co_picture[inf->unique_cos[0]], ab );
+
+ v3_sub( co_picture[inf->unique_cos[1]],
+ co_picture[inf->unique_cos[0]], ac );
+ v3_cross( ac, ab, inf->normal );
+ v3_normalize( inf->normal );
+ }
+
+
+ /* build edges brute force */
+ int edge_picture[ 128*3 ][4];
+ int unique_edges = 0;
+
+ for( int i=0; i<len; i++ )
+ {
+ struct face_info *inf = &faces[i];
+
+ for( int j=0; j<3; j++ )
+ {
+ int i0 = j,
+ i1 = (j+1)%3,
+ e0 = VG_MIN( inf->unique_cos[i0], inf->unique_cos[i1] ),
+ e1 = VG_MAX( inf->unique_cos[i0], inf->unique_cos[i1] ),
+ matched = 0;
+
+ for( int k=0; k<unique_edges; k ++ )
+ {
+ int k0 = VG_MIN( edge_picture[k][0], edge_picture[k][1] ),
+ k1 = VG_MAX( edge_picture[k][0], edge_picture[k][1] );
+
+ /* matched ! */
+ if( (k0 == e0) && (k1 == e1) )
+ {
+ edge_picture[ k ][3] = i;
+ matched = 1;
+ break;
+ }
+ }
+
+ if( !matched )
+ {
+ /* create new edge */
+ edge_picture[ unique_edges ][0] = inf->unique_cos[i0];
+ edge_picture[ unique_edges ][1] = inf->unique_cos[i1];
+
+ edge_picture[ unique_edges ][2] = i;
+ edge_picture[ unique_edges ][3] = -1;
+
+ unique_edges ++;
+ }
+ }
+ }
+#endif
+
+ v3f tri[3];
+