f8ef5f2f64e41bc9e0db792283434f8592331a12
[blender.git] / source / blender / bmesh / operators / triangulateop.c
1 #include "MEM_guardedalloc.h"
2
3 #include "BKE_utildefines.h"
4
5 #include "bmesh.h"
6 #include "bmesh_private.h"
7 #include "BLI_arithb.h"
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #define EDGE_NEW        1
14 #define FACE_NEW        1
15
16 void triangulate_exec(BMesh *bmesh, BMOperator *op)
17 {
18         BMOpSlot *finput;
19         BMFace *face;
20         float (*projectverts)[3] = NULL;
21         V_DECLARE(projectverts);
22         void *projverts;
23         int i, lastlen=0, count = 0;
24         
25         finput = BMO_GetSlot(op, BMOP_ESUBDIVIDE_EDGES);
26
27         for (i=0; i<finput->len; i++) {
28                 face = ((BMFace**)finput->data.p)[i];
29
30                 if (lastlen < face->len) {
31                         V_RESET(projectverts);
32                         for (lastlen=0; lastlen<face->len; lastlen++) {
33                                 V_GROW(projectverts);
34                                 V_GROW(projectverts);
35                                 V_GROW(projectverts);
36                         }
37                 }
38                 
39                 BM_Triangulate_Face(bmesh, face, projectverts, EDGE_NEW, FACE_NEW);
40                 
41                 if (projverts != projectverts) MEM_freeN(projverts);
42         }
43         
44         BMO_Flag_To_Slot(bmesh, op, BMOP_TRIANG_NEW_EDGES, EDGE_NEW, BM_EDGE);
45         BMO_Flag_To_Slot(bmesh, op, BMOP_TRIANG_NEW_FACES, FACE_NEW, BM_FACE);
46 }