part 1 of cleaning up my little array macro library to be a formal API. also removed...
[blender.git] / source / blender / bmesh / operators / triangulateop.c
index f8ef5f2f64e41bc9e0db792283434f8592331a12..1951e9dffa0d3f13be964604c2552d5e4f7322f3 100644 (file)
@@ -5,6 +5,7 @@
 #include "bmesh.h"
 #include "bmesh_private.h"
 #include "BLI_arithb.h"
+#include "BLI_array.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #define EDGE_NEW       1
 #define FACE_NEW       1
 
-void triangulate_exec(BMesh *bmesh, BMOperator *op)
+void triangulate_exec(BMesh *bm, BMOperator *op)
 {
-       BMOpSlot *finput;
-       BMFace *face;
+       BMOIter siter;
+       BMFace *face, **newfaces = NULL;
+       BLI_array_declare(newfaces);
        float (*projectverts)[3] = NULL;
-       V_DECLARE(projectverts);
-       void *projverts;
+       BLI_array_declare(projectverts);
        int i, lastlen=0, count = 0;
        
-       finput = BMO_GetSlot(op, BMOP_ESUBDIVIDE_EDGES);
-
-       for (i=0; i<finput->len; i++) {
-               face = ((BMFace**)finput->data.p)[i];
-
+       face = BMO_IterNew(&siter, bm, op, "faces", BM_FACE);
+       for (; face; face=BMO_IterStep(&siter)) {
                if (lastlen < face->len) {
-                       V_RESET(projectverts);
+                       BLI_array_empty(projectverts);
+                       BLI_array_empty(newfaces);
                        for (lastlen=0; lastlen<face->len; lastlen++) {
-                               V_GROW(projectverts);
-                               V_GROW(projectverts);
-                               V_GROW(projectverts);
+                               BLI_array_growone(projectverts);
+                               BLI_array_growone(projectverts);
+                               BLI_array_growone(projectverts);
+                               BLI_array_growone(newfaces);
                        }
                }
                
-               BM_Triangulate_Face(bmesh, face, projectverts, EDGE_NEW, FACE_NEW);
-               
-               if (projverts != projectverts) MEM_freeN(projverts);
+               BM_Triangulate_Face(bm, face, projectverts, EDGE_NEW, 
+                                   FACE_NEW, newfaces);
+
+               BMO_Insert_MapPointer(bm, op, "facemap", 
+                                     face, face);
+               for (i=0; newfaces[i]; i++) {
+                       BMO_Insert_MapPointer(bm, op, "facemap", 
+                                             newfaces[i], face);
+
+               }
        }
        
-       BMO_Flag_To_Slot(bmesh, op, BMOP_TRIANG_NEW_EDGES, EDGE_NEW, BM_EDGE);
-       BMO_Flag_To_Slot(bmesh, op, BMOP_TRIANG_NEW_FACES, FACE_NEW, BM_FACE);
+       BMO_Flag_To_Slot(bm, op, "edgeout", EDGE_NEW, BM_EDGE);
+       BMO_Flag_To_Slot(bm, op, "faceout", FACE_NEW, BM_FACE);
+       
+       BLI_array_free(projectverts);
+       BLI_array_free(newfaces);
 }
\ No newline at end of file