Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp	(revision 983)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/mesh.cpp	(revision 2090)
@@ -11,6 +11,8 @@
 using namespace	VMI;
 
-#define MAX_NUM_TRI 450
-
+#define OUTPUT_SEVERAL_GROUPS
+
+///////////////////////////////////////////////////////////////////////////////
+// list of integers
 void VMI::printItemList(int *list, int n) {
     int i;
@@ -35,4 +37,19 @@
         list[(*n)++] = item;
 }
+
+void VMI::delItem(int *list, int *n, int item) {
+    int i, j;
+    
+    for (i=0; i<*n; i++) {
+        if (list[i] == item) {
+            // delete it
+            for (j =i + 1 ; j<*n; j++)
+                list[j - 1] = list[j];
+            (*n)--;
+            i--; // Delete all ocurrencies of an item
+        }
+    }
+}
+///////////////////////////////////////////////////////////////////////////////
 
 int VMI::findEdge(Edge *e, GLuint num, GLuint _u, GLuint _v) {
@@ -56,4 +73,31 @@
 
     return found;
+}
+
+// Adds a new edge at the end of the mesh edge list
+Edge *VMI::addEdge(Edge *list, int *n, int u, int v, int *pos) {
+	  Edge *newList;
+
+		// Reallocate memory for the new edge
+    newList = (Edge *)realloc(list, ((*n) + 1) * sizeof(Edge));
+
+		// New vertex indices
+		newList[*n].u = u;
+    newList[*n].v = v;
+
+		// This edge has no triangle adjancency
+		newList[*n].numTriangles = 0;
+		newList[*n].triangles = NULL;
+		
+		// Enable the new edge
+		newList[*n].enable = TRUE;
+
+		// New edge position
+		*pos = *n;
+
+		// New number of edges
+	  (*n)++;
+
+		return newList;
 }
 
@@ -131,6 +175,8 @@
 Mesh *VMI::initMesh(GLMmodel* pmodel) {
 
-    GLuint i, j, v1, v2, v3, n, e, t;
+    GLuint i, j, curGroup, v1, v2, v3, n, m, t;
+    int e;
     Mesh *mesh;
+    GLMgroup *group;
 
     mesh = (Mesh *)malloc (sizeof(Mesh));
@@ -157,5 +203,4 @@
     printf("Adding vertices...");
     for (i=1; i<=pmodel->numvertices; i++) { // Vertices start at 1
-
         mesh->vertices[i - 1].x = pmodel->vertices[3 * i + 0];
         mesh->vertices[i - 1].y = pmodel->vertices[3 * i + 1];
@@ -170,4 +215,41 @@
 
     printf("Adding triangles...");
+
+#ifdef OUTPUT_SEVERAL_GROUPS
+    group = pmodel->groups;
+    curGroup=0; // current group
+    while(group) {
+        
+        for (i=0; i<group->numtriangles; i++) {
+            
+            t = group->triangles[i];
+
+            mesh->triangles[t].id = t;
+            mesh->triangles[t].group = curGroup; // set group
+            mesh->triangles[t].indices[0] = pmodel->triangles[t].vindices[0] - 1;
+            mesh->triangles[t].indices[1] = pmodel->triangles[t].vindices[1] - 1;
+            mesh->triangles[t].indices[2] = pmodel->triangles[t].vindices[2] - 1;
+            mesh->triangles[t].area = computeTriangleArea(mesh->vertices, &mesh->triangles[t]);
+            //printf("\n%d a: %f",i , mesh->triangles[i].area);
+            computeTriangleNormal(mesh->vertices, &mesh->triangles[t]);
+            
+            mesh->triangles[t].saliency = 0.0;
+            
+            mesh->triangles[t].enable = GL_TRUE;
+            
+            for (j=0; j<3; j++) {
+                // Adding triangle i adjacent to 3 vertices
+                v1 = mesh->triangles[t].indices[j];
+                
+                // Reallocate memory for the new adjacent triangle
+                mesh->vertices[v1].triangles = 
+					(GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));
+                addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, t);
+            }
+        }
+        curGroup++;
+        group = group->next;
+    }
+#else // One single group
     for (i=0; i<pmodel->numtriangles; i++) {
         mesh->triangles[i].id = i;
@@ -188,13 +270,16 @@
    
             // Reallocate memory for the new adjacent triangle
-            mesh->vertices[v1].triangles = (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));
+            mesh->vertices[v1].triangles = 
+			    (GLuint *)realloc(mesh->vertices[v1].triangles, (mesh->vertices[v1].numTriangles + 1) * sizeof(GLuint));
             addItem((int *)mesh->vertices[v1].triangles, (int *)&mesh->vertices[v1].numTriangles, i);
         }
     }
-    //printf("\n");
+    printf("\n");
+#endif
     printf("Ok\n");
 
     mesh->numTriangles = pmodel->numtriangles;
     mesh->currentNumTriangles = pmodel->numtriangles;
+    printf("Number of triangles: %d\n", mesh->numTriangles);
 
     mesh->edges = (Edge *)malloc (sizeof(Edge) * mesh->numTriangles * 3);  // E = 3 T / 2
@@ -205,11 +290,4 @@
     }
     
-    // Init edges
-    for (i=0; i<mesh->numTriangles * 3; i++) {
-        
-        mesh->edges[i].triangles    = NULL;
-        mesh->edges[i].numTriangles = 0;
-    }
-
     printf("Adding edges...");
     n = 0;
@@ -221,76 +299,66 @@
         v3 = mesh->triangles[i].indices[2];
         
+        /////////////////////////////////////////////////////////////////////////////////
+		// edge (v1,v2)
         if ((e = findEdge(mesh->edges, n, v1, v2)) == -1) {
             mesh->edges[n].u = v1;
             mesh->edges[n].v = v2;
+						mesh->edges[n].triangles    = NULL;
+        		mesh->edges[n].numTriangles = 0;
             mesh->edges[n].enable = GL_TRUE;
-            
-            // Reallocate memory for the new adjacent triangle
-            mesh->edges[n].triangles = (GLuint *)realloc(mesh->edges[n].triangles, (mesh->edges[n].numTriangles + 1) * sizeof(GLuint));
-            // Adding triangle i adjacent to edge n
-            addItem((int *)mesh->edges[n].triangles, (int *)&mesh->edges[n].numTriangles, i);
-            //printf("n:%d i:%d\n", n, i);
-            
-            // Adding edge n adjacent to triangle i
-            addItem((int *)mesh->triangles[i].edges, (int *)&t, n);
+            m = n;
             n++;
-        } else {
-            // Reallocate memory for the new adjacent triangle
-            mesh->edges[e].triangles = (GLuint *)realloc(mesh->edges[e].triangles, (mesh->edges[e].numTriangles + 1) * sizeof(GLuint));
-            // Adding triangle i adjacent to edge e
-            addItem((int *)mesh->edges[e].triangles, (int *)&mesh->edges[e].numTriangles, i);
-            //printf("n:%d i:%d\n", e, i);
-            
-            // Adding edge e adjacent to triangle i
-            addItem((int *)mesh->triangles[i].edges, (int *)&t, e);
-        }
+        } else m = e;
+		// Reallocate memory for the new adjacent triangle
+        mesh->edges[m].triangles = 
+			(GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));
+        // Adding triangle i adjacent to edge m
+        addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);
+        //printf("n:%d i:%d\n", m, i);
+        
+        // Adding edge m adjacent to triangle i
+        addItem((int *)mesh->triangles[i].edges, (int *)&t, m);
+
+        /////////////////////////////////////////////////////////////////////////////////
+        // edge (v2,v3)
         if (( e = findEdge(mesh->edges, n, v2, v3)) == -1) {
             mesh->edges[n].u = v2;
             mesh->edges[n].v = v3;
+						mesh->edges[n].triangles    = NULL;
+        		mesh->edges[n].numTriangles = 0;
             mesh->edges[n].enable = GL_TRUE;
-            
-            // Reallocate memory for the new adjacent triangle
-            mesh->edges[n].triangles = (GLuint *)realloc(mesh->edges[n].triangles, (mesh->edges[n].numTriangles + 1) * sizeof(GLuint));
-            // Adding triangle i adjacent to edge n
-            addItem((int *)mesh->edges[n].triangles, (int *)&mesh->edges[n].numTriangles, i);
-            //printf("n:%d i:%d\n", n, i);
-            
-            // Adding edge n adjacent to triangle i
-            addItem((int *)mesh->triangles[i].edges, (int *)&t, n);
+            m = n;
             n++;
-        } else {
-            // Reallocate memory for the new adjacent triangle
-            mesh->edges[e].triangles = (GLuint *)realloc(mesh->edges[e].triangles, (mesh->edges[e].numTriangles + 1) * sizeof(GLuint));
-            // Adding triangle i adjacent to edge e
-            addItem((int *)mesh->edges[e].triangles, (int *)&mesh->edges[e].numTriangles, i);
-            //printf("n:%d i:%d\n", e, i);
-            
-            // Adding edge e adjacent to triangle i
-            addItem((int *)mesh->triangles[i].edges, (int *)&t, e);
-        }
+        } else m = e;
+		// Reallocate memory for the new adjacent triangle
+        mesh->edges[m].triangles = 
+			(GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));
+        // Adding triangle i adjacent to edge m
+        addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);
+        //printf("n:%d i:%d\n", m, i);
+        
+        // Adding edge m adjacent to triangle i
+        addItem((int *)mesh->triangles[i].edges, (int *)&t, m);
+
+        /////////////////////////////////////////////////////////////////////////////////
+        // edge (v3,v1)
         if ((e = findEdge(mesh->edges, n, v3, v1)) == -1) {
             mesh->edges[n].u = v3;
             mesh->edges[n].v = v1;
+						mesh->edges[n].triangles    = NULL;
+        		mesh->edges[n].numTriangles = 0;
             mesh->edges[n].enable = GL_TRUE;
-            
-            // Reallocate memory for the new adjacent triangle
-            mesh->edges[n].triangles = (GLuint *)realloc(mesh->edges[n].triangles, (mesh->edges[n].numTriangles + 1) * sizeof(GLuint));
-            // Adding triangle i adjacent to edge n
-            addItem((int *)mesh->edges[n].triangles, (int *)&mesh->edges[n].numTriangles, i);
-            //printf("n:%d i:%d\n", n, i);
-            
-            // Adding edge n adjacent to triangle i
-            addItem((int *)mesh->triangles[i].edges, (int *)&t, n);
+            m = n;
             n++;
-        } else  {
-            // Reallocate memory for the new adjacent triangle
-            mesh->edges[e].triangles = (GLuint *)realloc(mesh->edges[e].triangles, (mesh->edges[e].numTriangles + 1) * sizeof(GLuint));
-            // Adding triangle i adjacent to edge e
-            addItem((int *)mesh->edges[e].triangles, (int *)&mesh->edges[e].numTriangles, i);
-            //printf("n:%d i:%d\n", e, i);
-            
-            // Adding edge e adjacent to triangle i
-            addItem((int *)mesh->triangles[i].edges, (int *)&t, e);
-        }
+        } else m = e;
+		// Reallocate memory for the new adjacent triangle
+        mesh->edges[m].triangles = 
+			(GLuint *)realloc(mesh->edges[m].triangles, (mesh->edges[m].numTriangles + 1) * sizeof(GLuint));
+        // Adding triangle i adjacent to edge m
+        addItem((int *)mesh->edges[m].triangles, (int *)&mesh->edges[m].numTriangles, i);
+        //printf("n:%d i:%d\n", m, i);
+        
+        // Adding edge m adjacent to triangle i
+        addItem((int *)mesh->triangles[i].edges, (int *)&t, m);
     }
     printf("Ok\n");
@@ -322,5 +390,5 @@
     printf("------------------------\n");
     for (i=0; i<mesh->numEdges; i++) {
-        printf("e%d (%d,%d)\n", i, mesh->edges[i].u, mesh->edges[i].v);
+        printf("e%d (%d,%d) %d\n", i, mesh->edges[i].u, mesh->edges[i].v, mesh->edges[i].enable);
         printf("  t(%d)[", mesh->edges[i].numTriangles);
         if (mesh->edges[i].triangles != NULL) {
@@ -329,5 +397,5 @@
                 printf(",%d", mesh->edges[i].triangles[j]);
             }
-        }
+				}
         printf("]\n");
     }
@@ -336,6 +404,6 @@
     printf("------------------------\n");
     for (i=0; i<mesh->numTriangles; i++) {
-        printf("t%d (%d,%d,%d)\n", i, mesh->triangles[i].indices[0], mesh->triangles[i].indices[1],
-                                     mesh->triangles[i].indices[2]);
+        printf("t%d (%d,%d,%d) %d\n", i, mesh->triangles[i].indices[0], mesh->triangles[i].indices[1],
+                                     mesh->triangles[i].indices[2],  mesh->triangles[i].enable);
         printf("  e(3)[");
         printf("%d", mesh->triangles[i].edges[0]);
@@ -385,79 +453,62 @@
 
 int *VMI::trianglesAdjToEdge(Mesh *mesh, int e, int *n) {
-    int triangles[MAX_NUM_TRI];
-    int i, n0, n1, n2, 
+    int i, n0, n1, n2, num = 0, t, 
         u = mesh->edges[e].u, 
         v = mesh->edges[e].v;
-    int *list, num = 0;
-
-    for (i=0; i<(int)mesh->numTriangles; i++) {
-        
-        if (mesh->triangles[i].enable == TRUE) {
-            
-            n0 = mesh->triangles[i].indices[0];
-            n1 = mesh->triangles[i].indices[1];
-            n2 = mesh->triangles[i].indices[2];
+    int *triangles = NULL;
+
+	if ((mesh->vertices[u].numTriangles + 
+         mesh->vertices[v].numTriangles) > 0)
+		 triangles = (int *)malloc((mesh->vertices[u].numTriangles + 
+                                    mesh->vertices[v].numTriangles) * sizeof(int));
+
+    for (i=0; i<(int)mesh->vertices[u].numTriangles; i++) {
+
+        t = mesh->vertices[u].triangles[i];
+        
+        if (mesh->triangles[t].enable == TRUE) {
+            
+            n0 = mesh->triangles[t].indices[0];
+            n1 = mesh->triangles[t].indices[1];
+            n2 = mesh->triangles[t].indices[2];
             
             if ((n0 == v) || (n1 == v) || (n2 == v) ||
                 (n0 == u) || (n1 == u) || (n2 == u))
                 
-                triangles[num++] = i;
-        }
-    }
-
-    list = (int*) malloc (sizeof(int) * num);
-    if (NULL == list) {
-        fprintf (stderr, "no more memory for list");
-        exit(1);
-    }
-
-    memcpy(list, triangles, sizeof(int) * num);
-
+                addItem(triangles, &num, t);
+        }
+    }
+
+    for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) {
+
+        t = mesh->vertices[v].triangles[i];
+        
+        if (mesh->triangles[t].enable == TRUE) {
+            
+            n0 = mesh->triangles[t].indices[0];
+            n1 = mesh->triangles[t].indices[1];
+            n2 = mesh->triangles[t].indices[2];
+            
+            if ((n0 == v) || (n1 == v) || (n2 == v) ||
+                (n0 == u) || (n1 == u) || (n2 == u))
+                
+                addItem(triangles, &num, t);
+        }
+    }
     *n = num;
 
-    return list;
-}
-
-int *VMI::trianglesAdjToVertex(Mesh *mesh, int v, int *n) {
-    int triangles[MAX_NUM_TRI];
-    int i, n0, n1, n2;
-    int *list, num = 0;
-
-    for (i=0; i<(int)mesh->numTriangles; i++) {
-        
-        if (mesh->triangles[i].enable == TRUE) {
-            
-            n0 = mesh->triangles[i].indices[0];
-            n1 = mesh->triangles[i].indices[1];
-            n2 = mesh->triangles[i].indices[2];
-            
-            if ((n0 == v) || (n1 == v) || (n2 == v))
-                
-                triangles[num++] = i;
-        }
-    }
-
-    list = (int*) malloc (sizeof(int) * num);
-    if (NULL == list) {
-        fprintf (stderr, "no more memory for list");
-        exit(1);
-    }
-
-    memcpy(list, triangles, sizeof(int) * num);
-
-    *n = num;
-
-    return list;
+    return triangles;
 }
 
 int *VMI::verticesAdjToVertex(Mesh *mesh, int v, int *n) {
-    int numTr;
-    int *triangles = trianglesAdjToVertex(mesh, v, &numTr);
-    int *vertices = (int*) malloc (sizeof(int) * numTr * 2);
+    int *vertices = NULL;
     int i, t, n0, n1, n2;
     int num = 0;
 
-    for (i=0; i<numTr; i++) {
-        t = triangles[i];
+	if (mesh->vertices[v].numTriangles > 0)
+		vertices = (int*)malloc(sizeof(int) * mesh->vertices[v].numTriangles * 2);
+
+    for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) {
+        t = mesh->vertices[v].triangles[i];
 
         n0 = mesh->triangles[t].indices[0];
@@ -469,22 +520,35 @@
         if (n2 != v) addItem(vertices, &num, n2);
     }
-
     *n = num;
 
-    free(triangles);
-
     return vertices;
 }
 
 int *VMI::edgesAdjToVertex(Mesh *mesh, int v, int *n) {
-    int numTr;
-    int *triangles = trianglesAdjToVertex(mesh, v, &numTr);
-    int *edges = (int*) malloc (sizeof(int) * numTr * 2);
-    int i, t, n0, n1, n2, e;
+    int *edges = NULL;
+    int i, t, e;
+#ifndef USE_EDGE_ADJACENCY
+    int n0, n1, n2;
+#else
+    int j;
+#endif
     int num = 0;
 
-    for (i=0; i<numTr; i++) {
-        t = triangles[i];
-
+	if (mesh->vertices[v].numTriangles > 0) 
+		edges = (int*)malloc(sizeof(int) * mesh->vertices[v].numTriangles * 2);
+
+    for (i=0; i<(int)mesh->vertices[v].numTriangles; i++) {
+
+        t = mesh->vertices[v].triangles[i];
+
+#ifdef USE_EDGE_ADJACENCY
+        for (j=0; j<3; j++) {
+            e = mesh->triangles[t].edges[j];
+            
+            if ((int)mesh->edges[e].u == v || (int)mesh->edges[e].v == v)
+                
+                addItem(edges, &num, e);
+        }
+#else
         n0 = mesh->triangles[t].indices[0];
         n1 = mesh->triangles[t].indices[1];
@@ -498,44 +562,50 @@
         
         if (((n0 == v) || (n2 == v)) &&
-            ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) addItem(edges, &num, e);  
-    }
-
+            ((e = findEdge(mesh->edges, mesh->numEdges, n0, n2)) != -1)) addItem(edges, &num, e);
+
+#endif
+    }
     *n = num;
 
-    free(triangles);
-
     return edges;
 }
 
 int *VMI::edgesAdjToVertices(Mesh *mesh, int *vertices, int numVertices, int *n) {
-    int edges[MAX_NUM_TRI*2];
-    int i, j, v, num = 0, e;
-    int *list, numEdges;
-
-    for (i=0; i<numVertices; i++) {
-        v = vertices[i];
-
-        list = edgesAdjToVertex(mesh, v, &numEdges);
-
-        for (j=0; j<numEdges; j++) {
-            e = list[j];
-            
-            addItem(edges, &num, e);
-        }
+    int *edges = NULL;
+    int i, j, num = 0;
+    int *list = NULL, numEdges;
+
+    if (numVertices > 0) {
+        // Add the first
+        list = edgesAdjToVertex(mesh, vertices[0], &numEdges);
+
+        // Allocate memory
+        edges = (int *)malloc(numEdges * sizeof(int));
+
+        memcpy(edges, list, sizeof(int) * numEdges);
 
         free(list);
-    }
-
-    list = (int*) malloc (sizeof(int) * num);
-    if (NULL == list) {
-        fprintf (stderr, "no more memory for list");
-        exit(1);
-    }
-
-    memcpy(list, edges, sizeof(int) * num);
-
+
+        num = numEdges;
+
+        // Add the rest
+        for (i=1; i<numVertices; i++) {
+
+            list = edgesAdjToVertex(mesh, vertices[i], &numEdges);
+
+            // Reallocate memory
+			if (numEdges > 0) {
+
+                edges = (int *)realloc(edges, (num + numEdges + 1) * sizeof(int));
+                
+                for (j=0; j<numEdges; j++)
+                    addItem(edges, &num, list[j]);
+			}
+            free(list);
+        }
+    }
     *n = num;
 
-    return list;
+    return edges;
 }
 
@@ -563,4 +633,34 @@
 }
 
+// Adds a new vertex at the end of the mesh vertex list
+Vertex *VMI::addVertex(Vertex *list, int *n, float x, float y, float z, int *pos) {
+	  Vertex *newList;
+
+		// Reallocate memory for the new vertex
+    newList = (Vertex *)realloc(list, ((*n) + 1) * sizeof(Vertex));
+
+		// New Vertex coordinates
+		newList[*n].x = x;
+    newList[*n].y = y;
+    newList[*n].z = z;
+
+		// This vertex has no triangle adjancency
+		newList[*n].numTriangles = 0;
+		newList[*n].triangles = NULL;
+	
+    // Enable the new vertex
+		newList[*n].enable = TRUE;
+
+		// New vertex position
+		*pos = *n;
+
+		// New number of vertices
+	  (*n)++;
+		
+		return newList;
+}
+
+
+
 void VMI::updateModel(GLMmodel* pmodel, Mesh *mesh, GLuint numVertices, GLuint numTriangles) {
     GLuint i , v1, v2 ,v3, numV = 1, numT = 0;
@@ -569,13 +669,9 @@
     
     if (pmodel->vertices != NULL) free(pmodel->vertices);
-
     pmodel->vertices = (GLfloat *)calloc ((numVertices + 1) * 3,  sizeof(GLfloat));
-    
 
     if (pmodel->triangles != NULL) free(pmodel->triangles);
-
     pmodel->triangles = (GLMtriangle *)malloc (numTriangles * sizeof(GLMtriangle));
 
-    
     for (i=0; i<mesh->numTriangles; i++) {
         if (mesh->triangles[i].enable) {
@@ -630,6 +726,42 @@
 
 void VMI::saveModel(char *filename, GLMmodel* pmodel, Mesh *mesh) {
-    GLuint i;
-
+    GLuint i, j, g, numT = 0;
+    GLMgroup *group;
+
+#ifdef OUTPUT_SEVERAL_GROUPS
+    // The output model maintains groups
+
+    // Empty all groups
+    group = pmodel->groups;
+    while(group) {
+        // Free memory for triangles
+        free(group->triangles);
+
+        // Reset group
+        group->triangles = NULL;
+        group->numtriangles = 0;
+
+        group = group->next;
+    }
+    // Fill all groups
+    for (i=0; i<mesh->numTriangles; i++) {
+
+        if (mesh->triangles[i].enable) {
+            g = mesh->triangles[i].group;
+
+            // Get group
+            group = pmodel->groups;
+            for (j=0; j <g; j++)
+                group = group->next;
+
+            // Reallocate memory for triangles
+            group->triangles = (GLuint *)realloc(group->triangles, (group->numtriangles + 1) * sizeof(GLuint));
+            // Add triangle into group
+            addItem((int *)group->triangles, (int *)&group->numtriangles, numT);
+
+            numT++;
+        }
+    }
+#else
     // The output model contains only one group
     pmodel->numgroups = 1;
@@ -646,4 +778,5 @@
     for (i=0; i<mesh->currentNumTriangles; i++)
         pmodel->groups->triangles[i] = i;
+#endif
 
     updateModel(pmodel, mesh, mesh->currentNumTriangles * 3, mesh->currentNumTriangles);
