as per discussion with ton, the editmesh accessors now live
[blender.git] / source / blender / editors / mesh / editmesh_add.c
1 /**
2  * $Id: 
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2004 by Blender Foundation.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30
31 #include <stdlib.h>
32 #include <string.h>
33 #include <math.h>
34
35 #include "MEM_guardedalloc.h"
36
37 #include "DNA_mesh_types.h"
38 #include "DNA_meshdata_types.h"
39 #include "DNA_object_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_userdef_types.h"
44 #include "DNA_view3d_types.h"
45 #include "DNA_windowmanager_types.h"
46
47 #include "RNA_types.h"
48 #include "RNA_define.h"
49 #include "RNA_access.h"
50
51 #include "BLI_blenlib.h"
52 #include "BLI_arithb.h"
53 #include "BLI_editVert.h"
54
55 #include "BKE_context.h"
56 #include "BKE_depsgraph.h"
57 #include "BKE_global.h"
58 #include "BKE_library.h"
59 #include "BKE_mesh.h"
60 #include "BKE_object.h"
61 #include "BKE_utildefines.h"
62 #include "BKE_report.h"
63
64 #include "BIF_retopo.h"
65
66 #include "WM_api.h"
67 #include "WM_types.h"
68
69 #include "ED_mesh.h"
70 #include "ED_util.h"
71 #include "ED_view3d.h"
72 #include "ED_screen.h"
73
74 #include "mesh_intern.h"
75
76 /* bpymenu removed XXX */
77
78 /* XXX */
79 #define add_numbut(a, b, c, d, e, f, g) {}
80 /* XXX */
81
82 static float icovert[12][3] = {
83         {0.0f,0.0f,-200.0f}, 
84         {144.72f, -105.144f,-89.443f},
85         {-55.277f, -170.128,-89.443f}, 
86         {-178.885f,0.0f,-89.443f},
87         {-55.277f,170.128f,-89.443f}, 
88         {144.72f,105.144f,-89.443f},
89         {55.277f,-170.128f,89.443f},
90         {-144.72f,-105.144f,89.443f},
91         {-144.72f,105.144f,89.443f},
92         {55.277f,170.128f,89.443f},
93         {178.885f,0.0f,89.443f},
94         {0.0f,0.0f,200.0f}
95 };
96 static short icoface[20][3] = {
97         {1,0,2},
98         {1,0,5},
99         {2,0,3},
100         {3,0,4},
101         {4,0,5},
102         {1,5,10},
103         {2,1,6},
104         {3,2,7},
105         {4,3,8},
106         {5,4,9},
107         {10,1,6},
108         {6,2,7},
109         {7,3,8},
110         {8,4,9},
111         {9,5,10},
112         {6,10,11},
113         {7,6,11},
114         {8,7,11},
115         {9,8,11},
116         {10,9,11}
117 };
118
119 /* *************** add-click-mesh (extrude) operator ************** */
120
121 static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event)
122 {
123         ViewContext vc;
124         EditVert *eve, *v1;
125         float min[3], max[3];
126         int done= 0;
127         
128         em_setup_viewcontext(C, &vc);
129         
130         INIT_MINMAX(min, max);
131         
132         for(v1= vc.em->verts.first;v1; v1=v1->next) {
133                 if(v1->f & SELECT) {
134                         DO_MINMAX(v1->co, min, max);
135                         done= 1;
136                 }
137         }
138
139         /* call extrude? */
140         if(done) {
141                 EditEdge *eed;
142                 float vec[3], cent[3], mat[3][3];
143                 float nor[3]= {0.0, 0.0, 0.0};
144                 
145                 /* check for edges that are half selected, use for rotation */
146                 done= 0;
147                 for(eed= vc.em->edges.first; eed; eed= eed->next) {
148                         if( (eed->v1->f & SELECT)+(eed->v2->f & SELECT) == SELECT ) {
149                                 if(eed->v1->f & SELECT) VecSubf(vec, eed->v1->co, eed->v2->co);
150                                 else VecSubf(vec, eed->v2->co, eed->v1->co);
151                                 VecAddf(nor, nor, vec);
152                                 done= 1;
153                         }
154                 }
155                 if(done) Normalize(nor);
156                 
157                 /* center */
158                 VecAddf(cent, min, max);
159                 VecMulf(cent, 0.5f);
160                 VECCOPY(min, cent);
161                 
162                 Mat4MulVecfl(vc.obedit->obmat, min);    // view space
163                 view3d_get_view_aligned_coordinate(&vc, min, event->mval);
164                 Mat4Invert(vc.obedit->imat, vc.obedit->obmat); 
165                 Mat4MulVecfl(vc.obedit->imat, min); // back in object space
166                 
167                 VecSubf(min, min, cent);
168                 
169                 /* calculate rotation */
170                 Mat3One(mat);
171                 if(done) {
172                         float dot;
173                         
174                         VECCOPY(vec, min);
175                         Normalize(vec);
176                         dot= INPR(vec, nor);
177
178                         if( fabs(dot)<0.999) {
179                                 float cross[3], si, q1[4];
180                                 
181                                 Crossf(cross, nor, vec);
182                                 Normalize(cross);
183                                 dot= 0.5f*saacos(dot);
184                                 si= (float)sin(dot);
185                                 q1[0]= (float)cos(dot);
186                                 q1[1]= cross[0]*si;
187                                 q1[2]= cross[1]*si;
188                                 q1[3]= cross[2]*si;
189                                 
190                                 QuatToMat3(q1, mat);
191                         }
192                 }
193                 
194                 extrudeflag(vc.obedit, vc.em, SELECT, nor);
195                 rotateflag(vc.em, SELECT, cent, mat);
196                 translateflag(vc.em, SELECT, min);
197                 
198                 recalc_editnormals(vc.em);
199         }
200         else {
201                 float mat[3][3],imat[3][3];
202                 float *curs= give_cursor(vc.scene, vc.v3d);
203                 
204                 VECCOPY(min, curs);
205                 view3d_get_view_aligned_coordinate(&vc, min, event->mval);
206                 
207                 eve= addvertlist(vc.em, 0, NULL);
208
209                 Mat3CpyMat4(mat, vc.obedit->obmat);
210                 Mat3Inv(imat, mat);
211                 
212                 VECCOPY(eve->co, min);
213                 Mat3MulVecfl(imat, eve->co);
214                 VecSubf(eve->co, eve->co, vc.obedit->obmat[3]);
215                 
216                 eve->f= SELECT;
217         }
218         
219         //retopo_do_all();
220         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit); 
221         DAG_object_flush_update(vc.scene, vc.obedit, OB_RECALC_DATA);
222         
223         return OPERATOR_FINISHED;
224 }
225
226 void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot)
227 {
228         /* identifiers */
229         ot->name= "Duplicate or Extrude at 3D Cursor";
230         ot->idname= "MESH_OT_dupli_extrude_cursor";
231         
232         /* api callbacks */
233         ot->invoke= dupli_extrude_cursor;
234         ot->poll= ED_operator_editmesh;
235         
236         /* flags */
237         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
238 }
239
240
241 /* ********************** */
242
243 /* selected faces get hidden edges */
244 int make_fgon(EditMesh *em, wmOperator *op, int make)
245 {
246         EditFace *efa;
247         EditEdge *eed;
248         EditVert *eve;
249         float *nor=NULL;        // reference
250         int done=0;
251         
252         if(make==0) {
253                 for(efa= em->faces.first; efa; efa= efa->next) {
254                         if(efa->f & SELECT) {
255                                 efa->fgonf= 0;
256                                 efa->e1->h &= ~EM_FGON;
257                                 efa->e2->h &= ~EM_FGON;
258                                 efa->e3->h &= ~EM_FGON;
259                                 if(efa->e4) efa->e4->h &= ~EM_FGON;
260                                 done= 1;
261                         }
262                 }
263                 EM_fgon_flags(em);      // redo flags and indices for fgons
264                 
265                 return done;
266         }
267
268         /* tagging edges. rule is:
269            - edge used by exactly 2 selected faces
270            - no vertices allowed with only tagged edges (return)
271            - face normals are allowed to difffer
272          
273         */
274         for(eed= em->edges.first; eed; eed= eed->next) {
275                 eed->f1= 0;     // amount of selected
276                 eed->f2= 0; // amount of unselected
277         }
278         
279         for(efa= em->faces.first; efa; efa= efa->next) {
280                 if(efa->f & SELECT) {
281                         if(nor==NULL) nor= efa->n;
282                         if(efa->e1->f1 < 3) efa->e1->f1++;
283                         if(efa->e2->f1 < 3) efa->e2->f1++;
284                         if(efa->e3->f1 < 3) efa->e3->f1++;
285                         if(efa->e4 && efa->e4->f1 < 3) efa->e4->f1++;
286                 }
287                 else {
288                         if(efa->e1->f2 < 3) efa->e1->f2++;
289                         if(efa->e2->f2 < 3) efa->e2->f2++;
290                         if(efa->e3->f2 < 3) efa->e3->f2++;
291                         if(efa->e4 && efa->e4->f2 < 3) efa->e4->f2++;
292                 }
293         }
294         // now eed->f1 becomes tagged edge
295         for(eed= em->edges.first; eed; eed= eed->next) {
296                 if(eed->f1==2 && eed->f2==0) eed->f1= 1;
297                 else eed->f1= 0;
298         }
299         
300         // no vertices allowed with only tagged edges
301         for(eve= em->verts.first; eve; eve= eve->next) eve->f1= 0;
302         for(eed= em->edges.first; eed; eed= eed->next) {
303                 if(eed->f1) {
304                         eed->v1->f1 |= 1;
305                         eed->v2->f1 |= 1;
306                 }
307                 else {
308                         eed->v1->f1 |= 2;
309                         eed->v2->f1 |= 2;
310                 }
311         }
312         for(eve= em->verts.first; eve; eve= eve->next) {
313                 if(eve->f1==1) break;
314         }
315         if(eve) {
316                 BKE_report(op->reports, RPT_ERROR, "Cannot make a polygon with interior vertices");
317                 return 0;
318         }
319         
320         // check for faces
321         if(nor==NULL) {
322                 BKE_report(op->reports, RPT_ERROR, "No faces were selected to make FGon");
323                 return 0;
324         }
325
326         // and there we go
327         for(eed= em->edges.first; eed; eed= eed->next) {
328                 if(eed->f1) {
329                         eed->h |= EM_FGON;
330                         done= 1;
331                 }
332         }
333         
334         if(done)
335                 EM_fgon_flags(em);      // redo flags and indices for fgons
336         return done;
337 }
338
339 static int make_fgon_exec(bContext *C, wmOperator *op)
340 {
341         Object *obedit= CTX_data_edit_object(C);
342         EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
343
344         if( make_fgon(em, op, 1) ) {
345                 DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);     
346         
347                 WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
348
349                 BKE_mesh_end_editmesh(obedit->data, em);
350                 return OPERATOR_FINISHED;
351         }
352
353         BKE_mesh_end_editmesh(obedit->data, em);
354         return OPERATOR_CANCELLED;
355 }
356
357 void MESH_OT_fgon_make(struct wmOperatorType *ot)
358 {
359         /* identifiers */
360         ot->name= "Make F-gon";
361         ot->idname= "MESH_OT_fgon_make";
362         
363         /* api callbacks */
364         ot->exec= make_fgon_exec;
365         ot->poll= ED_operator_editmesh;
366         
367         /* flags */
368         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
369 }
370
371 static int clear_fgon_exec(bContext *C, wmOperator *op)
372 {
373         Object *obedit= CTX_data_edit_object(C);
374         EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
375         
376         if( make_fgon(em, op, 0) ) {
377                 DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);     
378                 
379                 WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
380                 
381                 BKE_mesh_end_editmesh(obedit->data, em);
382                 return OPERATOR_FINISHED;
383         }
384
385         BKE_mesh_end_editmesh(obedit->data, em);
386         return OPERATOR_CANCELLED;
387 }
388
389 void MESH_OT_fgon_clear(struct wmOperatorType *ot)
390 {
391         /* identifiers */
392         ot->name= "Clear F-gon";
393         ot->idname= "MESH_OT_fgon_clear";
394         
395         /* api callbacks */
396         ot->exec= clear_fgon_exec;
397         ot->poll= ED_operator_editmesh;
398         
399         /* flags */
400         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
401 }
402
403 /* precondition; 4 vertices selected, check for 4 edges and create face */
404 static EditFace *addface_from_edges(EditMesh *em)
405 {
406         EditEdge *eed, *eedar[4]={NULL, NULL, NULL, NULL};
407         EditVert *v1=NULL, *v2=NULL, *v3=NULL, *v4=NULL;
408         int a;
409         
410         /* find the 4 edges */
411         for(eed= em->edges.first; eed; eed= eed->next) {
412                 if( (eed->f & SELECT) || (eed->v1->f & eed->v2->f & SELECT) ) {
413                         if(eedar[0]==NULL) eedar[0]= eed;
414                         else if(eedar[1]==NULL) eedar[1]= eed;
415                         else if(eedar[2]==NULL) eedar[2]= eed;
416                         else eedar[3]= eed;
417                         
418                 }
419         }
420         
421         
422         if(eedar[3]) {
423                 /* first 2 points */
424                 v1= eedar[0]->v1;
425                 v2= eedar[0]->v2;
426                 
427                 /* find the 2 edges connected to first edge */
428                 for(a=1; a<4; a++) {
429                         if( eedar[a]->v1 == v2) v3= eedar[a]->v2;
430                         else if(eedar[a]->v2 == v2) v3= eedar[a]->v1;
431                         else if( eedar[a]->v1 == v1) v4= eedar[a]->v2;
432                         else if(eedar[a]->v2 == v1) v4= eedar[a]->v1;
433                 }
434                 
435                 /* verify if last edge exists */
436                 if(v3 && v4) {
437                         for(a=1; a<4; a++) {
438                                 if( eedar[a]->v1==v3 && eedar[a]->v2==v4) break;
439                                 if( eedar[a]->v2==v3 && eedar[a]->v1==v4) break;
440                         }
441                         if(a!=4) {
442                                 return addfacelist(em, v1, v2, v3, v4, NULL, NULL);
443                         }
444                 }
445         }
446         return NULL;
447 }
448
449 /* ******************************* */
450
451 /* this also allows to prevent triangles being made in quads */
452 static int compareface_overlaps(EditFace *vl1, EditFace *vl2)
453 {
454         EditVert *v1, *v2, *v3, *v4;
455         int equal= 0;
456         
457         v1= vl2->v1;
458         v2= vl2->v2;
459         v3= vl2->v3;
460         v4= vl2->v4;
461         
462         if(vl1==vl2) return 0;
463         
464         if(v4==NULL && vl1->v4==NULL) {
465                 if(vl1->v1==v1 || vl1->v2==v1 || vl1->v3==v1) equal++;
466                 if(vl1->v1==v2 || vl1->v2==v2 || vl1->v3==v2) equal++;
467                 if(vl1->v1==v3 || vl1->v2==v3 || vl1->v3==v3) equal++;
468         }
469         else {
470                 if(vl1->v1==v1 || vl1->v2==v1 || vl1->v3==v1 || vl1->v4==v1) equal++;
471                 if(vl1->v1==v2 || vl1->v2==v2 || vl1->v3==v2 || vl1->v4==v2) equal++;
472                 if(vl1->v1==v3 || vl1->v2==v3 || vl1->v3==v3 || vl1->v4==v3) equal++;
473                 if(vl1->v1==v4 || vl1->v2==v4 || vl1->v3==v4 || vl1->v4==v4) equal++;
474         }
475
476         if(v4 && vl1->v4) {
477                 if(equal==4) return 1;
478         }
479         else 
480                 if(equal>=3) return 1;
481         
482         return 0;
483 }
484
485 /* checks for existance, and for tria overlapping inside quad */
486 static EditFace *exist_face_overlaps(EditMesh *em, EditVert *v1, EditVert *v2, EditVert *v3, EditVert *v4)
487 {
488         EditFace *efa, efatest;
489         
490         efatest.v1= v1;
491         efatest.v2= v2;
492         efatest.v3= v3;
493         efatest.v4= v4;
494         
495         efa= em->faces.first;
496         while(efa) {
497                 if(compareface_overlaps(&efatest, efa)) return efa;
498                 efa= efa->next;
499         }
500         return NULL;
501 }
502
503 /* will be new face smooth or solid? depends on smoothness of face neighbours
504  * of new face, if function return 1, then new face will be smooth, when functio
505  * will return zero, then new face will be solid */
506 static void fix_new_face(EditMesh *em, EditFace *eface)
507 {
508         struct EditFace *efa;
509         struct EditEdge *eed=NULL;
510         struct EditVert *v1 = eface->v1, *v2 = eface->v2, *v3 = eface->v3, *v4 = eface->v4;
511         struct EditVert *ev1=NULL, *ev2=NULL;
512         short smooth=0; /* "total smoothnes" of faces in neighbourhood */
513         short coef;     /* "weight" of smoothness */
514         short count=0;  /* number of edges with same direction as eface */
515         short vi00=0, vi01=0, vi10=0, vi11=0; /* vertex indexes */
516
517         efa = em->faces.first;
518
519         while(efa) {
520
521                 if(efa==eface) {
522                         efa = efa->next;
523                         continue;
524                 }
525
526                 coef = 0;
527                 ev1 = ev2 = NULL;
528                 eed = NULL;
529
530                 if(efa->v1==v1 || efa->v2==v1 || efa->v3==v1 || efa->v4==v1) {
531                         ev1 = v1;
532                         coef++;
533                 }
534                 if(efa->v1==v2 || efa->v2==v2 || efa->v3==v2 || efa->v4==v2) {
535                         if(ev1) ev2 = v2;
536                         else ev1 = v2;
537                         coef++;
538                 }
539                 if(efa->v1==v3 || efa->v2==v3 || efa->v3==v3 || efa->v4==v3) {
540                         if(coef<2) {
541                                 if(ev1) ev2 = v3;
542                                 else ev1 = v3;
543                         }
544                         coef++;
545                 }
546                 if((v4) && (efa->v1==v4 || efa->v2==v4 || efa->v3==v4 || efa->v4==v4)) {
547                         if(ev1 && coef<2) ev2 = v4;
548                         coef++;
549                 }
550
551                 /* "democracy" of smoothness */
552                 if(efa->flag & ME_SMOOTH)
553                         smooth += coef;
554                 else
555                         smooth -= coef;
556
557                 /* try to find edge using vertexes ev1 and ev2 */
558                 if((ev1) && (ev2) && (ev1!=ev2)) eed = findedgelist(em, ev1, ev2);
559
560                 /* has bordering edge of efa same direction as edge of eface ? */
561                 if(eed) {
562                         if(eed->v1==v1) vi00 = 1;
563                         else if(eed->v1==v2) vi00 = 2;
564                         else if(eed->v1==v3) vi00 = 3;
565                         else if(v4 && eed->v1==v4) vi00 = 4;
566
567                         if(eed->v2==v1) vi01 = 1;
568                         else if(eed->v2==v2) vi01 = 2;
569                         else if(eed->v2==v3) vi01 = 3;
570                         else if(v4 && eed->v2==v4) vi01 = 4;
571
572                         if(v4) {
573                                 if(vi01==1 && vi00==4) vi00 = 0;
574                                 if(vi01==4 && vi00==1) vi01 = 0;
575                         }
576                         else {
577                                 if(vi01==1 && vi00==3) vi00 = 0;
578                                 if(vi01==3 && vi00==1) vi01 = 0;
579                         }
580
581                         if(eed->v1==efa->v1) vi10 = 1;
582                         else if(eed->v1==efa->v2) vi10 = 2;
583                         else if(eed->v1==efa->v3) vi10 = 3;
584                         else if(efa->v4 && eed->v1==efa->v4) vi10 = 4;
585
586                         if(eed->v2==efa->v1) vi11 = 1;
587                         else if(eed->v2==efa->v2) vi11 = 2;
588                         else if(eed->v2==efa->v3) vi11 = 3;
589                         else if(efa->v4 && eed->v2==efa->v4) vi11 = 4;
590
591                         if(efa->v4) {
592                                 if(vi11==1 && vi10==4) vi10 = 0;
593                                 if(vi11==4 && vi10==1) vi11 = 0;
594                         }
595                         else {
596                                 if(vi11==1 && vi10==3) vi10 = 0;
597                                 if(vi11==3 && vi10==1) vi11 = 0;
598                         }
599
600                         if(((vi00>vi01) && (vi10>vi11)) ||
601                                 ((vi00<vi01) && (vi10<vi11)))
602                                 count++;
603                         else
604                                 count--;
605                 }
606
607                 efa = efa->next;
608         }
609
610         /* set up smoothness according voting of face in neighbourhood */
611         if(smooth >= 0)
612                 eface->flag |= ME_SMOOTH;
613         else
614                 eface->flag &= ~ME_SMOOTH;
615
616         /* flip face, when too much "face normals" in neighbourhood is different */
617         if(count > 0) {
618                 flipface(em, eface);
619         }
620 }
621
622 /* only adds quads or trias when there's edges already */
623 void addfaces_from_edgenet(EditMesh *em)
624 {
625         EditVert *eve1, *eve2, *eve3, *eve4;
626         
627         for(eve1= em->verts.first; eve1; eve1= eve1->next) {
628                 for(eve2= em->verts.first; (eve1->f & 1) && eve2; eve2= eve2->next) {
629                         if(findedgelist(em, eve1,eve2)) {
630                                 for(eve3= em->verts.first; (eve2->f & 1) && eve3; eve3= eve3->next) {
631                                         if((eve2!=eve3 && (eve3->f & 1) && findedgelist(em, eve1,eve3))) {
632                                                 EditEdge *sh_edge= NULL;
633                                                 EditVert *sh_vert= NULL;
634                                                 
635                                                 sh_edge= findedgelist(em, eve2,eve3);
636                                                 
637                                                 if(sh_edge) { /* Add a triangle */
638                                                         if(!exist_face_overlaps(em, eve1,eve2,eve3,NULL))
639                                                                 fix_new_face(em, addfacelist(em, eve1,eve2,eve3,NULL,NULL,NULL));
640                                                 }
641                                                 else { /* Check for a shared vertex */
642                                                         for(eve4= em->verts.first; eve4; eve4= eve4->next) {
643                                                                 if(eve4!=eve1 && eve4!=eve2 && eve4!=eve3 && (eve4->f & 1) &&
644                                                                    !findedgelist(em, eve1,eve4) && findedgelist(em, eve2,eve4) &&
645                                                                    findedgelist(em, eve3,eve4)) {
646                                                                         sh_vert= eve4;
647                                                                         break;
648                                                                 }
649                                                         }
650                                                         
651                                                         if(sh_vert) {
652                                                                 if(sh_vert) {
653                                                                         if(!exist_face_overlaps(em, eve1,eve2,eve4,eve3))
654                                                                                 fix_new_face(em, addfacelist(em, eve1,eve2,eve4,eve3,NULL,NULL));
655                                                                 }
656                                                         }
657                                                 }
658                                         }
659                                 }
660                         }
661                 }
662         }
663
664         EM_select_flush(em);
665         
666 // XXX  DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
667 }
668
669 static void addedgeface_mesh(EditMesh *em, wmOperator *op)
670 {
671         EditVert *eve, *neweve[4];
672         EditEdge *eed;
673         EditFace *efa;
674         short amount=0;
675
676         /* how many selected ? */
677         if(em->selectmode & SCE_SELECT_EDGE) {
678                 /* in edge mode finding selected vertices means flushing down edge codes... */
679                 /* can't make face with only edge selection info... */
680                 EM_selectmode_set(em);
681         }
682         
683         for(eve= em->verts.first; eve; eve= eve->next) {
684                 if(eve->f & SELECT) {
685                         amount++;
686                         if(amount>4) break;                     
687                         neweve[amount-1]= eve;
688                 }
689         }
690
691         if(amount==2) {
692                 eed= addedgelist(em, neweve[0], neweve[1], NULL);
693                 EM_select_edge(eed, 1);
694
695                 // XXX          DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
696                 return;
697         }
698         else if(amount > 4) {
699                 addfaces_from_edgenet(em);
700                 return;
701         }
702         else if(amount<2) {
703                 BKE_report(op->reports, RPT_ERROR, "More vertices are needed to make an edge/face");
704                 return;
705         }
706
707         efa= NULL; // check later
708
709         if(amount==3) {
710                 
711                 if(exist_face_overlaps(em, neweve[0], neweve[1], neweve[2], NULL)==0) {
712                         efa= addfacelist(em, neweve[0], neweve[1], neweve[2], 0, NULL, NULL);
713                         EM_select_face(efa, 1);
714                 }
715                 else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
716         }
717         else if(amount==4) {
718                 /* this test survives when theres 2 triangles */
719                 if(exist_face(em, neweve[0], neweve[1], neweve[2], neweve[3])==0) {
720                         int tria= 0;
721                         
722                         /* remove trias if they exist, 4 cases.... */
723                         if(exist_face(em, neweve[0], neweve[1], neweve[2], NULL)) tria++;
724                         if(exist_face(em, neweve[0], neweve[1], neweve[3], NULL)) tria++;
725                         if(exist_face(em, neweve[0], neweve[2], neweve[3], NULL)) tria++;
726                         if(exist_face(em, neweve[1], neweve[2], neweve[3], NULL)) tria++;
727                 
728                         if(tria==2) join_triangles(em);
729                         else if(exist_face_overlaps(em, neweve[0], neweve[1], neweve[2], neweve[3])==0) {
730                                  /* If there are 4 Verts, But more selected edges, we need to call addfaces_from_edgenet */
731                                         EditEdge *eedcheck;
732                                         int count;
733                                         count = 0;
734                                         for(eedcheck= em->edges.first; eedcheck; eedcheck= eedcheck->next) {
735                                                 if(eedcheck->f & SELECT) {
736                                                         count++;
737                                                 }
738                                         }       
739                                 
740                                 if(count++ > 4){
741                                         addfaces_from_edgenet(em);
742                                         return;
743                                 } else {
744                                 /* if 4 edges exist, we just create the face, convex or not */
745                                         efa= addface_from_edges(em);
746                                         if(efa==NULL) {
747                                                 
748                                                 /* the order of vertices can be anything, 6 cases to check */
749                                                 if( convex(neweve[0]->co, neweve[1]->co, neweve[2]->co, neweve[3]->co) ) {
750                                                         efa= addfacelist(em, neweve[0], neweve[1], neweve[2], neweve[3], NULL, NULL);
751                                                 }
752                                                 else if( convex(neweve[0]->co, neweve[2]->co, neweve[3]->co, neweve[1]->co) ) {
753                                                         efa= addfacelist(em, neweve[0], neweve[2], neweve[3], neweve[1], NULL, NULL);
754                                                 }
755                                                 else if( convex(neweve[0]->co, neweve[2]->co, neweve[1]->co, neweve[3]->co) ) {
756                                                         efa= addfacelist(em, neweve[0], neweve[2], neweve[1], neweve[3], NULL, NULL);
757                                                 }
758                                                 else if( convex(neweve[0]->co, neweve[1]->co, neweve[3]->co, neweve[2]->co) ) {
759                                                         efa= addfacelist(em, neweve[0], neweve[1], neweve[3], neweve[2], NULL, NULL);
760                                                 }
761                                                 else if( convex(neweve[0]->co, neweve[3]->co, neweve[2]->co, neweve[1]->co) ) {
762                                                         efa= addfacelist(em, neweve[0], neweve[3], neweve[2], neweve[1], NULL, NULL);
763                                                 }
764                                                 else if( convex(neweve[0]->co, neweve[3]->co, neweve[1]->co, neweve[2]->co) ) {
765                                                         efa= addfacelist(em, neweve[0], neweve[3], neweve[1], neweve[2], NULL, NULL);
766                                                 }
767                                                 else printf("cannot find nice quad from concave set of vertices\n");
768                                         }
769                                 }
770                         }
771                         else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
772                 }
773                 else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
774         }
775         
776         if(efa) {
777                 EM_select_face(efa, 1);
778
779                 fix_new_face(em, efa);
780                 
781                 recalc_editnormals(em);
782         }
783         }
784
785 static int addedgeface_mesh_exec(bContext *C, wmOperator *op)
786 {
787         Object *obedit= CTX_data_edit_object(C);
788         EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
789         
790         addedgeface_mesh(em, op);
791         
792         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
793         
794         DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);     
795         
796         BKE_mesh_end_editmesh(obedit->data, em);
797         return OPERATOR_FINISHED;
798 }
799
800 void MESH_OT_add_edge_face(wmOperatorType *ot)
801 {
802         /* identifiers */
803         ot->name= "Make Edge/Face";
804         ot->idname= "MESH_OT_add_edge_face";
805         
806         /* api callbacks */
807         ot->exec= addedgeface_mesh_exec;
808         ot->poll= ED_operator_editmesh;
809         
810         /* flags */
811         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
812         
813 }
814
815
816
817 /* ************************ primitives ******************* */
818
819 // HACK: these can also be found in cmoview.tga.c, but are here so that they can be found by linker
820 // this hack is only used so that scons+mingw + split-sources hack works
821         // ------------------------------- start copied code
822 /* these are not the monkeys you are looking for */
823 int monkeyo= 4;
824 int monkeynv= 271;
825 int monkeynf= 250;
826 signed char monkeyv[271][3]= {
827 {-71,21,98},{-63,12,88},{-57,7,74},{-82,-3,79},{-82,4,92},
828 {-82,17,100},{-92,21,102},{-101,12,95},{-107,7,83},
829 {-117,31,84},{-109,31,95},{-96,31,102},{-92,42,102},
830 {-101,50,95},{-107,56,83},{-82,66,79},{-82,58,92},
831 {-82,46,100},{-71,42,98},{-63,50,88},{-57,56,74},
832 {-47,31,72},{-55,31,86},{-67,31,97},{-66,31,99},
833 {-70,43,100},{-82,48,103},{-93,43,105},{-98,31,105},
834 {-93,20,105},{-82,31,106},{-82,15,103},{-70,20,100},
835 {-127,55,95},{-127,45,105},{-127,-87,94},{-127,-41,100},
836 {-127,-24,102},{-127,-99,92},{-127,52,77},{-127,73,73},
837 {-127,115,-70},{-127,72,-109},{-127,9,-106},{-127,-49,-45},
838 {-101,-24,72},{-87,-56,73},{-82,-89,73},{-80,-114,68},
839 {-85,-121,67},{-104,-124,71},{-127,-126,74},{-71,-18,68},
840 {-46,-5,69},{-21,19,57},{-17,55,76},{-36,62,80},
841 {-64,77,88},{-86,97,94},{-107,92,97},{-119,63,96},
842 {-106,53,99},{-111,39,98},{-101,12,95},{-79,2,90},
843 {-64,8,86},{-47,24,83},{-45,38,83},{-50,48,85},
844 {-72,56,92},{-95,60,97},{-127,-98,94},{-113,-92,94},
845 {-112,-107,91},{-119,-113,89},{-127,-114,88},{-127,-25,96},
846 {-127,-18,95},{-114,-19,95},{-111,-29,96},{-116,-37,95},
847 {-76,-6,86},{-48,7,80},{-34,26,77},{-32,48,84},
848 {-39,53,93},{-71,70,102},{-87,82,107},{-101,79,109},
849 {-114,55,108},{-111,-13,104},{-100,-57,91},{-95,-90,88},
850 {-93,-105,85},{-97,-117,81},{-106,-119,81},{-127,-121,82},
851 {-127,6,93},{-127,27,98},{-85,61,95},{-106,18,96},
852 {-110,27,97},{-112,-88,94},{-117,-57,96},{-127,-57,96},
853 {-127,-42,95},{-115,-35,100},{-110,-29,102},{-113,-17,100},
854 {-122,-16,100},{-127,-26,106},{-121,-19,104},{-115,-20,104},
855 {-113,-29,106},{-117,-32,103},{-127,-37,103},{-94,-40,71},
856 {-106,-31,91},{-104,-40,91},{-97,-32,71},{-127,-112,88},
857 {-121,-111,88},{-115,-105,91},{-115,-95,93},{-127,-100,84},
858 {-115,-96,85},{-115,-104,82},{-121,-109,81},{-127,-110,81},
859 {-105,28,100},{-103,20,99},{-84,55,97},{-92,54,99},
860 {-73,51,99},{-55,45,89},{-52,37,88},{-53,25,87},
861 {-66,13,92},{-79,8,95},{-98,14,100},{-104,38,100},
862 {-100,48,100},{-97,46,97},{-102,38,97},{-96,16,97},
863 {-79,11,93},{-68,15,90},{-57,27,86},{-56,36,86},
864 {-59,43,87},{-74,50,96},{-91,51,98},{-84,52,96},
865 {-101,22,96},{-102,29,96},{-113,59,78},{-102,85,79},
866 {-84,88,76},{-65,71,71},{-40,58,63},{-25,52,59},
867 {-28,21,48},{-50,0,53},{-71,-12,60},{-127,115,37},
868 {-127,126,-10},{-127,-25,-86},{-127,-59,24},{-127,-125,59},
869 {-127,-103,44},{-127,-73,41},{-127,-62,36},{-18,30,7},
870 {-17,41,-6},{-28,34,-56},{-68,56,-90},{-33,-6,9},
871 {-51,-16,-21},{-45,-1,-55},{-84,7,-85},{-97,-45,52},
872 {-104,-53,33},{-90,-91,49},{-95,-64,50},{-85,-117,51},
873 {-109,-97,47},{-111,-69,46},{-106,-121,56},{-99,-36,55},
874 {-100,-29,60},{-101,-22,64},{-100,-50,21},{-89,-40,-34},
875 {-83,-19,-69},{-69,111,-49},{-69,119,-9},{-69,109,30},
876 {-68,67,55},{-34,52,43},{-46,58,36},{-45,90,7},
877 {-25,72,16},{-25,79,-15},{-45,96,-25},{-45,87,-57},
878 {-25,69,-46},{-48,42,-75},{-65,3,-70},{-22,42,-26},
879 {-75,-22,19},{-72,-25,-27},{-13,52,-30},{-28,-18,-16},
880 {6,-13,-42},{37,7,-55},{46,41,-54},{31,65,-54},
881 {4,61,-40},{3,53,-37},{25,56,-50},{35,37,-52},
882 {28,10,-52},{5,-5,-39},{-21,-9,-17},{-9,46,-28},
883 {-6,39,-37},{-14,-3,-27},{6,0,-47},{25,12,-57},
884 {31,32,-57},{23,46,-56},{4,44,-46},{-19,37,-27},
885 {-20,22,-35},{-30,12,-35},{-22,11,-35},{-19,2,-35},
886 {-23,-2,-35},{-34,0,-9},{-35,-3,-22},{-35,5,-24},
887 {-25,26,-27},{-13,31,-34},{-13,30,-41},{-23,-2,-41},
888 {-18,2,-41},{-21,10,-41},{-29,12,-41},{-19,22,-41},
889 {6,42,-53},{25,44,-62},{34,31,-63},{28,11,-62},
890 {7,0,-54},{-14,-2,-34},{-5,37,-44},{-13,14,-42},
891 {-7,8,-43},{1,16,-47},{-4,22,-45},{3,30,-48},
892 {8,24,-49},{15,27,-50},{12,35,-50},{4,56,-62},
893 {33,60,-70},{48,38,-64},{41,7,-68},{6,-11,-63},
894 {-26,-16,-42},{-17,49,-49},
895 };
896
897 signed char monkeyf[250][4]= {
898 {27,4,5,26}, {25,4,5,24}, {3,6,5,4}, {1,6,5,2}, {5,6,7,4}, 
899 {3,6,7,2}, {5,8,7,6}, {3,8,7,4}, {7,8,9,6}, 
900 {5,8,9,4}, {7,10,9,8}, {5,10,9,6}, {9,10,11,8}, 
901 {7,10,11,6}, {9,12,11,10}, {7,12,11,8}, {11,6,13,12}, 
902 {5,4,13,12}, {3,-2,13,12}, {-3,-4,13,12}, {-5,-10,13,12}, 
903 {-11,-12,14,12}, {-13,-18,14,13}, {-19,4,5,13}, {10,12,4,4}, 
904 {10,11,9,9}, {8,7,9,9}, {7,5,6,6}, {6,3,4,4}, 
905 {5,1,2,2}, {4,-1,0,0}, {3,-3,-2,-2}, {22,67,68,23}, 
906 {20,65,66,21}, {18,63,64,19}, {16,61,62,17}, {14,59,60,15}, 
907 {12,19,48,57}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 
908 {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 
909 {18,19,48,47}, {18,-9,-8,47}, {18,27,45,46}, {26,55,43,44}, 
910 {24,41,42,54}, {22,39,40,23}, {20,37,38,21}, {18,35,36,19}, 
911 {16,33,34,17}, {14,31,32,15}, {12,39,30,13}, {11,48,45,38}, 
912 {8,36,-19,9}, {8,-20,44,47}, {42,45,46,43}, {18,19,40,39}, 
913 {16,17,38,37}, {14,15,36,35}, {32,44,43,33}, {12,33,32,42}, 
914 {19,44,43,42}, {40,41,42,-27}, {8,9,39,-28}, {15,43,42,16}, 
915 {13,43,42,14}, {11,43,42,12}, {9,-30,42,10}, {37,12,38,-32}, 
916 {-33,37,45,46}, {-33,40,41,39}, {38,40,41,37}, {36,40,41,35}, 
917 {34,40,41,33}, {36,39,38,37}, {35,40,39,38}, {1,2,14,21}, 
918 {1,2,40,13}, {1,2,40,39}, {1,24,12,39}, {-34,36,38,11}, 
919 {35,38,36,37}, {-37,8,35,37}, {-11,-12,-45,40}, {-11,-12,39,38}, 
920 {-11,-12,37,36}, {-11,-12,35,34}, {33,34,40,41}, {33,34,38,39}, 
921 {33,34,36,37}, {33,-52,34,35}, {33,37,36,34}, {33,35,34,34}, 
922 {8,7,37,36}, {-32,7,35,46}, {-34,-33,45,46}, {4,-33,43,34}, 
923 {-34,-33,41,42}, {-34,-33,39,40}, {-34,-33,37,38}, {-34,-33,35,36}, 
924 {-34,-33,33,34}, {-34,-33,31,32}, {-34,-4,28,30}, {-5,-34,28,27}, 
925 {-35,-44,36,27}, {26,35,36,45}, {24,25,44,45}, {25,23,44,42}, 
926 {25,24,41,40}, {25,24,39,38}, {25,24,37,36}, {25,24,35,34}, 
927 {25,24,33,32}, {25,24,31,30}, {15,24,29,38}, {25,24,27,26}, 
928 {23,12,37,26}, {11,12,35,36}, {-86,-59,36,-80}, {-60,-61,36,35}, 
929 {-62,-63,36,35}, {-64,-65,36,35}, {-66,-67,36,35}, {-68,-69,36,35}, 
930 {-70,-71,36,35}, {-72,-73,36,35}, {-74,-75,36,35}, {42,43,53,58}, 
931 {40,41,57,56}, {38,39,55,57}, {-81,-80,37,56}, {-83,-82,55,52}, 
932 {-85,-84,51,49}, {-87,-86,48,49}, {47,50,51,48}, {46,48,51,49}, 
933 {43,46,49,44}, {-92,-91,45,42}, {-23,49,50,-20}, {-94,40,48,-24}, 
934 {-96,-22,48,49}, {-97,48,21,-90}, {-100,36,50,23}, {22,49,48,-100}, 
935 {-101,47,46,22}, {21,45,35,25}, {33,34,44,41}, {13,14,28,24}, 
936 {-107,26,30,-106}, {14,46,45,15}, {14,44,43,-110}, {-111,42,23,-110}, 
937 {6,7,45,46}, {45,44,47,46}, {45,46,47,48}, {47,46,49,48}, 
938 {17,49,47,48}, {17,36,46,48}, {35,36,44,45}, {35,36,40,43}, 
939 {35,36,38,39}, {-4,-3,37,35}, {-123,34,33,1}, {-9,-8,-7,-6}, 
940 {-10,-7,32,-125}, {-127,-11,-126,-126}, {-7,-6,5,31}, {4,5,33,30}, 
941 {4,39,33,32}, {4,35,32,38}, {20,21,39,38}, {4,37,38,5}, 
942 {-11,-10,36,3}, {-11,15,14,35}, {13,16,34,34}, {-13,14,13,13}, 
943 {-3,1,30,29}, {-3,28,29,1}, {-2,31,28,-1}, {12,13,27,30}, 
944 {-2,26,12,12}, {35,29,42,36}, {34,35,36,33}, {32,35,36,31}, 
945 {30,35,36,29}, {28,35,36,27}, {26,35,36,25}, {34,39,38,35}, 
946 {32,39,38,33}, {30,39,38,31}, {28,39,38,29}, {26,39,38,27}, 
947 {25,31,32,38}, {-18,-17,45,44}, {-18,17,28,44}, {-24,-20,42,-23}, 
948 {11,35,27,14}, {25,28,39,41}, {37,41,40,38}, {34,40,36,35}, 
949 {32,40,39,33}, {30,39,31,40}, {21,29,39,22}, {-31,37,28,4}, 
950 {-32,33,35,36}, {32,33,34,34}, {18,35,36,48}, {34,25,40,35}, 
951 {24,25,38,39}, {24,25,36,37}, {24,25,34,35}, {24,25,32,33}, 
952 {24,13,41,31}, {17,11,41,35}, {15,16,34,35}, {13,14,34,35}, 
953 {11,12,34,35}, {9,10,34,35}, {7,8,34,35}, {26,25,37,36}, 
954 {35,36,37,38}, {37,36,39,38}, {37,38,39,40}, {25,31,36,39}, 
955 {18,34,35,30}, {17,22,30,33}, {19,29,21,20}, {16,26,29,17}, 
956 {24,29,28,25}, {22,31,28,23}, {20,31,30,21}, {18,31,30,19}, 
957 {16,30,17,17}, {-21,-22,35,34}, {-21,-22,33,32}, {-21,-22,31,30}, 
958 {-21,-22,29,28}, {-21,-22,27,26}, {-28,-22,25,31}, {24,28,29,30}, 
959 {23,24,26,27}, {23,24,25,25}, {-69,-35,-32,27}, {-70,26,25,-66}, 
960 {-68,-67,24,-33}, 
961 };
962         // ------------------------------- end copied code
963
964
965 #define PRIM_PLANE              0
966 #define PRIM_CUBE               1
967 #define PRIM_CIRCLE             4
968 #define PRIM_CYLINDER   5
969 #define PRIM_CONE               7
970 #define PRIM_GRID               10
971 #define PRIM_UVSPHERE   11
972 #define PRIM_ICOSPHERE  12
973 #define PRIM_MONKEY             13
974
975 static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int seg,
976                 int subdiv, float dia, float depth, int ext, int fill)
977 {
978         /*
979          * type - for the type of shape
980          * dia - the radius for cone,sphere cylinder etc.
981          * depth - 
982          * ext - extrude
983          * fill - end capping, and option to fill in circle
984          * cent[3] - center of the data. 
985          * */
986         EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
987         EditVert *eve, *v1=NULL, *v2, *v3, *v4=NULL, *vtop, *vdown;
988         float phi, phid, vec[3];
989         float q[4], cmat[3][3], nor[3]= {0.0, 0.0, 0.0};
990         short a, b;
991         
992         EM_clear_flag_all(em, SELECT);
993
994         phid= 2.0f*(float)M_PI/tot;
995         phi= .25f*(float)M_PI;
996
997         switch(type) {
998         case PRIM_GRID: /*  grid */
999                 /* clear flags */
1000                 eve= em->verts.first;
1001                 while(eve) {
1002                         eve->f= 0;
1003                         eve= eve->next;
1004                 }
1005                 /* one segment first: the X axis */
1006                 phi= 1.0; 
1007                 phid= 2.0/((float)tot-1);
1008                 for(a=0;a<tot;a++) {
1009                         vec[0]= dia*phi;
1010                         vec[1]= - dia;
1011                         vec[2]= 0.0f;
1012                         Mat4MulVecfl(mat,vec);
1013                         eve= addvertlist(em, vec, NULL);
1014                         eve->f= 1+2+4;
1015                         if (a) {
1016                                 addedgelist(em, eve->prev, eve, NULL);
1017                         }
1018                         phi-=phid;
1019                 }
1020                 /* extrude and translate */
1021                 vec[0]= vec[2]= 0.0;
1022                 vec[1]= dia*phid;
1023                 Mat4Mul3Vecfl(mat, vec);
1024                 
1025                 for(a=0;a<seg-1;a++) {
1026                         extrudeflag_vert(obedit, em, 2, nor);   // nor unused
1027                         translateflag(em, 2, vec);
1028                 }
1029                 break;
1030         case PRIM_UVSPHERE: /*  UVsphere */
1031                 
1032                 /* clear all flags */
1033                 eve= em->verts.first;
1034                 while(eve) {
1035                         eve->f= 0;
1036                         eve= eve->next;
1037                 }
1038                 
1039                 /* one segment first */
1040                 phi= 0; 
1041                 phid/=2;
1042                 for(a=0; a<=tot; a++) {
1043                         vec[0]= dia*sin(phi);
1044                         vec[1]= 0.0;
1045                         vec[2]= dia*cos(phi);
1046                         eve= addvertlist(em, vec, NULL);
1047                         eve->f= 1+2+4;
1048                         if(a==0) v1= eve;
1049                         else addedgelist(em, eve->prev, eve, NULL);
1050                         phi+= phid;
1051                 }
1052                 
1053                 /* extrude and rotate */
1054                 phi= M_PI/seg;
1055                 q[0]= cos(phi);
1056                 q[3]= sin(phi);
1057                 q[1]=q[2]= 0;
1058                 QuatToMat3(q, cmat);
1059                 
1060                 for(a=0; a<seg; a++) {
1061                         extrudeflag_vert(obedit, em, 2, nor); // nor unused
1062                         rotateflag(em, 2, v1->co, cmat);
1063                 }
1064
1065                 removedoublesflag(em, 4, 0, 0.0001);
1066
1067                 /* and now do imat */
1068                 eve= em->verts.first;
1069                 while(eve) {
1070                         if(eve->f & SELECT) {
1071                                 Mat4MulVecfl(mat,eve->co);
1072                         }
1073                         eve= eve->next;
1074                 }
1075                 break;
1076         case PRIM_ICOSPHERE: /* Icosphere */
1077                 {
1078                         EditVert *eva[12];
1079                         EditEdge *eed;
1080                         
1081                         /* clear all flags */
1082                         eve= em->verts.first;
1083                         while(eve) {
1084                                 eve->f= 0;
1085                                 eve= eve->next;
1086                         }
1087                         dia/=200;
1088                         for(a=0;a<12;a++) {
1089                                 vec[0]= dia*icovert[a][0];
1090                                 vec[1]= dia*icovert[a][1];
1091                                 vec[2]= dia*icovert[a][2];
1092                                 eva[a]= addvertlist(em, vec, NULL);
1093                                 eva[a]->f= 1+2;
1094                         }
1095                         for(a=0;a<20;a++) {
1096                                 EditFace *evtemp;
1097                                 v1= eva[ icoface[a][0] ];
1098                                 v2= eva[ icoface[a][1] ];
1099                                 v3= eva[ icoface[a][2] ];
1100                                 evtemp = addfacelist(em, v1, v2, v3, 0, NULL, NULL);
1101                                 evtemp->e1->f = 1+2;
1102                                 evtemp->e2->f = 1+2;
1103                                 evtemp->e3->f = 1+2;
1104                         }
1105
1106                         dia*=200;
1107                         for(a=1; a<subdiv; a++) esubdivideflag(obedit, em, 2, dia, 0,1,0);
1108                         /* and now do imat */
1109                         eve= em->verts.first;
1110                         while(eve) {
1111                                 if(eve->f & 2) {
1112                                         Mat4MulVecfl(mat,eve->co);
1113                                 }
1114                                 eve= eve->next;
1115                         }
1116                         
1117                         // Clear the flag 2 from the edges
1118                         for(eed=em->edges.first;eed;eed=eed->next){
1119                                 if(eed->f & 2){
1120                                            eed->f &= !2;
1121                                 }   
1122                         }
1123                 }
1124                 break;
1125         case PRIM_MONKEY: /* Monkey */
1126                 {
1127                         //extern int monkeyo, monkeynv, monkeynf;
1128                         //extern signed char monkeyf[][4];
1129                         //extern signed char monkeyv[][3];
1130                         EditVert **tv= MEM_mallocN(sizeof(*tv)*monkeynv*2, "tv");
1131                         int i;
1132
1133                         for (i=0; i<monkeynv; i++) {
1134                                 float v[3];
1135                                 v[0]= (monkeyv[i][0]+127)/128.0, v[1]= monkeyv[i][1]/128.0, v[2]= monkeyv[i][2]/128.0;
1136                                 tv[i]= addvertlist(em, v, NULL);
1137                                 tv[i]->f |= SELECT;
1138                                 tv[monkeynv+i]= (fabs(v[0]= -v[0])<0.001)?tv[i]:addvertlist(em, v, NULL);
1139                                 tv[monkeynv+i]->f |= SELECT;
1140                         }
1141                         for (i=0; i<monkeynf; i++) {
1142                                 addfacelist(em, tv[monkeyf[i][0]+i-monkeyo], tv[monkeyf[i][1]+i-monkeyo], tv[monkeyf[i][2]+i-monkeyo], (monkeyf[i][3]!=monkeyf[i][2])?tv[monkeyf[i][3]+i-monkeyo]:NULL, NULL, NULL);
1143                                 addfacelist(em, tv[monkeynv+monkeyf[i][2]+i-monkeyo], tv[monkeynv+monkeyf[i][1]+i-monkeyo], tv[monkeynv+monkeyf[i][0]+i-monkeyo], (monkeyf[i][3]!=monkeyf[i][2])?tv[monkeynv+monkeyf[i][3]+i-monkeyo]:NULL, NULL, NULL);
1144                         }
1145
1146                         MEM_freeN(tv);
1147
1148                         /* and now do imat */
1149                         for(eve= em->verts.first; eve; eve= eve->next) {
1150                                 if(eve->f & SELECT) {
1151                                         Mat4MulVecfl(mat,eve->co);
1152                                 }
1153                         }
1154                         recalc_editnormals(em);
1155                 }
1156                 break;
1157         default: /* all types except grid, sphere... */
1158                 if(type==PRIM_CONE);
1159                 else if(ext==0) 
1160                         depth= 0.0f;
1161         
1162                 /* vertices */
1163                 vtop= vdown= v1= v2= 0;
1164                 for(b=0; b<=ext; b++) {
1165                         for(a=0; a<tot; a++) {
1166                                 
1167                                 vec[0]= dia*sin(phi);
1168                                 vec[1]= dia*cos(phi);
1169                                 vec[2]= b?depth:-depth;
1170                                 
1171                                 Mat4MulVecfl(mat, vec);
1172                                 eve= addvertlist(em, vec, NULL);
1173                                 eve->f= SELECT;
1174                                 if(a==0) {
1175                                         if(b==0) v1= eve;
1176                                         else v2= eve;
1177                                 }
1178                                 phi+=phid;
1179                         }
1180                 }
1181                         
1182                 /* center vertices */
1183                 /* type PRIM_CONE can only have 1 one side filled
1184                  * if the cone has no capping, dont add vtop */
1185                 if((fill && type>1) || type == PRIM_CONE) {
1186                         vec[0]= vec[1]= 0.0f;
1187                         vec[2]= -depth;
1188                         Mat4MulVecfl(mat, vec);
1189                         vdown= addvertlist(em, vec, NULL);
1190                         if((ext || type==PRIM_CONE) && fill) {
1191                                 vec[0]= vec[1]= 0.0f;
1192                                 vec[2]= depth;
1193                                 Mat4MulVecfl(mat,vec);
1194                                 vtop= addvertlist(em, vec, NULL);
1195                         }
1196                 } else {
1197                         vdown= v1;
1198                         vtop= v2;
1199                 }
1200                 if(vtop) vtop->f= SELECT;
1201                 if(vdown) vdown->f= SELECT;
1202         
1203                 /* top and bottom face */
1204                 if(fill || type==PRIM_CONE) {
1205                         if(tot==4 && (type==0 || type==1)) {
1206                                 v3= v1->next->next;
1207                                 if(ext) v4= v2->next->next;
1208                                 
1209                                 addfacelist(em, v3, v1->next, v1, v3->next, NULL, NULL);
1210                                 if(ext) addfacelist(em, v2, v2->next, v4, v4->next, NULL, NULL);
1211                                 
1212                         }
1213                         else {
1214                                 v3= v1;
1215                                 v4= v2;
1216                                 for(a=1; a<tot; a++) {
1217                                         addfacelist(em, vdown, v3, v3->next, 0, NULL, NULL);
1218                                         v3= v3->next;
1219                                         if(ext && fill) {
1220                                                 addfacelist(em, vtop, v4, v4->next, 0, NULL, NULL);
1221                                                 v4= v4->next;
1222                                         }
1223                                 }
1224                                 if(type>1) {
1225                                         addfacelist(em, vdown, v3, v1, 0, NULL, NULL);
1226                                         if(ext) addfacelist(em, vtop, v4, v2, 0, NULL, NULL);
1227                                 }
1228                         }
1229                 }
1230                 else if(type==PRIM_CIRCLE) {  /* we need edges for a circle */
1231                         v3= v1;
1232                         for(a=1;a<tot;a++) {
1233                                 addedgelist(em, v3, v3->next, NULL);
1234                                 v3= v3->next;
1235                         }
1236                         addedgelist(em, v3, v1, NULL);
1237                 }
1238                 /* side faces */
1239                 if(ext) {
1240                         v3= v1;
1241                         v4= v2;
1242                         for(a=1; a<tot; a++) {
1243                                 addfacelist(em, v3, v3->next, v4->next, v4, NULL, NULL);
1244                                 v3= v3->next;
1245                                 v4= v4->next;
1246                         }
1247                         addfacelist(em, v3, v1, v2, v4, NULL, NULL);
1248                 }
1249                 else if(type==PRIM_CONE && fill) {
1250                         /* add the bottom flat area of the cone
1251                          * if capping is disabled dont bother */
1252                         v3= v1;
1253                         for(a=1; a<tot; a++) {
1254                                 addfacelist(em, vtop, v3->next, v3, 0, NULL, NULL);
1255                                 v3= v3->next;
1256                         }
1257                         addfacelist(em, vtop, v1, v3, 0, NULL, NULL);
1258                 }
1259         }
1260         
1261         EM_stats_update(em);
1262         /* simple selection flush OK, based on fact it's a single model */
1263         EM_select_flush(em); /* flushes vertex -> edge -> face selection */
1264         
1265         if(type!=0 && type!=13)
1266                 righthandfaces(em, 1);  /* otherwise monkey has eyes in wrong direction */
1267
1268         BKE_mesh_end_editmesh(obedit->data, em);
1269 }
1270
1271
1272 /* uses context to figure out transform for primitive */
1273 /* returns standard diameter */
1274 static float new_primitive_matrix(bContext *C, float primmat[][4])
1275 {
1276         Object *obedit= CTX_data_edit_object(C);
1277         Scene *scene = CTX_data_scene(C);
1278         View3D *v3d =CTX_wm_view3d(C);
1279         RegionView3D *rv3d= CTX_wm_region_view3d(C);
1280         float *curs, mat[3][3], vmat[3][3], cmat[3][3], imat[3][3];
1281         
1282         Mat4One(primmat);
1283         
1284         if(rv3d)
1285                 Mat3CpyMat4(vmat, rv3d->viewmat);
1286         else
1287                 Mat3One(vmat);
1288         
1289         /* inverse transform for view and object */
1290         Mat3CpyMat4(mat, obedit->obmat);
1291         Mat3MulMat3(cmat, vmat, mat);
1292         Mat3Inv(imat, cmat);
1293         Mat4CpyMat3(primmat, imat);
1294
1295         /* center */
1296         curs= give_cursor(scene, v3d);
1297         VECCOPY(primmat[3], curs);
1298         Mat3Inv(imat, mat);
1299         Mat3MulVecfl(imat, primmat[3]);
1300         VECSUB(primmat[3], primmat[3], obedit->obmat[3]);
1301         
1302         if(v3d) return v3d->grid;
1303         return 1.0f;
1304 }
1305
1306 /* ********* add primitive operators ************* */
1307
1308 static int add_primitive_plane_exec(bContext *C, wmOperator *op)
1309 {
1310         Object *obedit= CTX_data_edit_object(C);
1311         float dia, mat[4][4];
1312         
1313         dia= new_primitive_matrix(C, mat);
1314         /* plane (diameter of 1.41 makes it unit size) */
1315         dia*= sqrt(2.0f);
1316         
1317         make_prim(obedit, PRIM_PLANE, mat, 4, 0, 0, dia, 0.0f, 0, 1);
1318         
1319         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1320         
1321         return OPERATOR_FINISHED;       
1322 }
1323
1324 void MESH_OT_add_primitive_plane(wmOperatorType *ot)
1325 {
1326         /* identifiers */
1327         ot->name= "Add Plane";
1328         ot->idname= "MESH_OT_add_primitive_plane";
1329         
1330         /* api callbacks */
1331         ot->exec= add_primitive_plane_exec;
1332         ot->poll= ED_operator_editmesh;
1333         
1334         /* flags */
1335         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1336 }
1337
1338 static int add_primitive_cube_exec(bContext *C, wmOperator *op)
1339 {
1340         Object *obedit= CTX_data_edit_object(C);
1341         float dia, mat[4][4];
1342         
1343         dia= new_primitive_matrix(C, mat);
1344         /* plane (diameter of 1.41 makes it unit size) */
1345         dia*= sqrt(2.0f);
1346         
1347         make_prim(obedit, PRIM_CUBE, mat, 4, 0, 0, dia, 1.0f, 1, 1);
1348         
1349         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1350         
1351         return OPERATOR_FINISHED;       
1352 }
1353
1354 void MESH_OT_add_primitive_cube(wmOperatorType *ot)
1355 {
1356         /* identifiers */
1357         ot->name= "Add Cube";
1358         ot->idname= "MESH_OT_add_primitive_cube";
1359         
1360         /* api callbacks */
1361         ot->exec= add_primitive_cube_exec;
1362         ot->poll= ED_operator_editmesh;
1363         
1364         /* flags */
1365         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1366 }
1367
1368 static int add_primitive_circle_exec(bContext *C, wmOperator *op)
1369 {
1370         Object *obedit= CTX_data_edit_object(C);
1371         float dia, mat[4][4];
1372         
1373         dia= new_primitive_matrix(C, mat);
1374         dia *= RNA_float_get(op->ptr,"radius");
1375         
1376         make_prim(obedit, PRIM_CIRCLE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 0.0f, 0, 
1377                           RNA_boolean_get(op->ptr, "fill"));
1378         
1379         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1380         
1381         return OPERATOR_FINISHED;       
1382 }
1383
1384 void MESH_OT_add_primitive_circle(wmOperatorType *ot)
1385 {
1386         /* identifiers */
1387         ot->name= "Add Circle";
1388         ot->idname= "MESH_OT_add_primitive_circle";
1389         
1390         /* api callbacks */
1391         ot->exec= add_primitive_circle_exec;
1392         ot->poll= ED_operator_editmesh;
1393         
1394         /* flags */
1395         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1396         
1397         /* props */
1398         RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 3, 500);
1399         RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
1400         RNA_def_boolean(ot->srna, "fill", 0, "Fill", "");
1401 }
1402
1403 static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
1404 {
1405         Object *obedit= CTX_data_edit_object(C);
1406         float dia, mat[4][4];
1407         
1408         dia= new_primitive_matrix(C, mat);
1409         dia *= RNA_float_get(op->ptr, "radius");
1410         
1411         make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
1412                           RNA_float_get(op->ptr, "depth"), 1, 1);
1413         
1414         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1415         
1416         return OPERATOR_FINISHED;       
1417 }
1418
1419 void MESH_OT_add_primitive_cylinder(wmOperatorType *ot)
1420 {
1421         /* identifiers */
1422         ot->name= "Add Cylinder";
1423         ot->idname= "MESH_OT_add_primitive_cylinder";
1424         
1425         /* api callbacks */
1426         ot->exec= add_primitive_cylinder_exec;
1427         ot->poll= ED_operator_editmesh;
1428         
1429         /* flags */
1430         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1431         
1432         /* props */
1433         RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
1434         RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
1435         RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00);
1436 }
1437
1438 static int add_primitive_tube_exec(bContext *C, wmOperator *op)
1439 {
1440         Object *obedit= CTX_data_edit_object(C);
1441         float dia, mat[4][4];
1442         
1443         dia= new_primitive_matrix(C, mat);
1444         dia *= RNA_float_get(op->ptr, "radius");
1445         
1446         make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
1447                           RNA_float_get(op->ptr, "depth"), 1, 0);
1448         
1449         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1450         
1451         return OPERATOR_FINISHED;       
1452 }
1453
1454 void MESH_OT_add_primitive_tube(wmOperatorType *ot)
1455 {
1456         /* identifiers */
1457         ot->name= "Add Tube";
1458         ot->idname= "MESH_OT_add_primitive_tube";
1459         
1460         /* api callbacks */
1461         ot->exec= add_primitive_tube_exec;
1462         ot->poll= ED_operator_editmesh;
1463         
1464         /* flags */
1465         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1466         
1467         /* props */
1468         RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
1469         RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
1470         RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00);
1471 }
1472
1473 static int add_primitive_cone_exec(bContext *C, wmOperator *op)
1474 {
1475         Object *obedit= CTX_data_edit_object(C);
1476         float dia, mat[4][4];
1477         
1478         dia= new_primitive_matrix(C, mat);
1479         dia *= RNA_float_get(op->ptr, "radius");
1480         
1481         make_prim(obedit, PRIM_CONE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
1482                           RNA_float_get(op->ptr, "depth"), 0, RNA_boolean_get(op->ptr, "cap_end"));
1483         
1484         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1485         
1486         return OPERATOR_FINISHED;       
1487 }
1488
1489 void MESH_OT_add_primitive_cone(wmOperatorType *ot)
1490 {
1491         /* identifiers */
1492         ot->name= "Add Cone";
1493         ot->idname= "MESH_OT_add_primitive_cone";
1494         
1495         /* api callbacks */
1496         ot->exec= add_primitive_cone_exec;
1497         ot->poll= ED_operator_editmesh;
1498         
1499         /* flags */
1500         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1501         
1502         /* props */
1503         RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
1504         RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
1505         RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00);
1506         RNA_def_boolean(ot->srna, "cap_end", 0, "Cap End", "");
1507
1508 }
1509
1510 static int add_primitive_grid_exec(bContext *C, wmOperator *op)
1511 {
1512         Object *obedit= CTX_data_edit_object(C);
1513         float dia, mat[4][4];
1514         
1515         dia= new_primitive_matrix(C, mat);
1516         dia*= RNA_float_get(op->ptr, "size");
1517         
1518         make_prim(obedit, PRIM_GRID, mat, RNA_int_get(op->ptr, "x_subdivisions"), 
1519                           RNA_int_get(op->ptr, "y_subdivisions"), 0, dia, 0.0f, 0, 1);
1520         
1521         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1522         
1523         return OPERATOR_FINISHED;       
1524 }
1525
1526 void MESH_OT_add_primitive_grid(wmOperatorType *ot)
1527 {
1528         /* identifiers */
1529         ot->name= "Add Grid";
1530         ot->idname= "MESH_OT_add_primitive_grid";
1531         
1532         /* api callbacks */
1533         ot->exec= add_primitive_grid_exec;
1534         ot->poll= ED_operator_editmesh;
1535         
1536         /* flags */
1537         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1538         
1539         /* props */
1540         RNA_def_int(ot->srna, "x_subdivisions", 10, INT_MIN, INT_MAX, "X Subdivisions", "", 3, 1000);
1541         RNA_def_int(ot->srna, "y_subdivisions", 10, INT_MIN, INT_MAX, "Y Subdivisons", "", 3, 1000);
1542         RNA_def_float(ot->srna, "size", 1.0f, -FLT_MAX, FLT_MAX, "Size", "", 0.001, FLT_MAX);
1543 }
1544
1545 static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
1546 {
1547         Object *obedit= CTX_data_edit_object(C);
1548         float mat[4][4];
1549         
1550         new_primitive_matrix(C, mat);
1551         
1552         make_prim(obedit, PRIM_MONKEY, mat, 0, 0, 2, 0.0f, 0.0f, 0, 0);
1553         
1554         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1555         
1556         return OPERATOR_FINISHED;       
1557 }
1558
1559 void MESH_OT_add_primitive_monkey(wmOperatorType *ot)
1560 {
1561         /* identifiers */
1562         ot->name= "Add Monkey";
1563         ot->idname= "MESH_OT_add_primitive_monkey";
1564         
1565         /* api callbacks */
1566         ot->exec= add_primitive_monkey_exec;
1567         ot->poll= ED_operator_editmesh;
1568         
1569         /* flags */
1570         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1571 }
1572
1573 static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
1574 {
1575         Object *obedit= CTX_data_edit_object(C);
1576         float dia, mat[4][4];
1577         
1578         dia= new_primitive_matrix(C, mat);
1579         dia*= RNA_float_get(op->ptr, "size");
1580
1581         make_prim(obedit, PRIM_UVSPHERE, mat, RNA_int_get(op->ptr, "rings"), 
1582                           RNA_int_get(op->ptr, "segments"), 0, dia, 0.0f, 0, 0);
1583         
1584         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1585         
1586         return OPERATOR_FINISHED;       
1587 }
1588
1589 void MESH_OT_add_primitive_uv_sphere(wmOperatorType *ot)
1590 {
1591         /* identifiers */
1592         ot->name= "Add UV Sphere";
1593         ot->idname= "MESH_OT_add_primitive_uv_sphere";
1594         
1595         /* api callbacks */
1596         ot->exec= add_primitive_uvsphere_exec;
1597         ot->poll= ED_operator_editmesh;
1598         
1599         /* flags */
1600         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1601         
1602         /* props */
1603         RNA_def_int(ot->srna, "segments", 32, INT_MIN, INT_MAX, "Segments", "", 3, 500);
1604         RNA_def_int(ot->srna, "rings", 24, INT_MIN, INT_MAX, "Rings", "", 3, 500);
1605         RNA_def_float(ot->srna, "size", 1.0f, -FLT_MAX, FLT_MAX, "Size", "", 0.001, 100.00);
1606 }
1607
1608 static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
1609 {
1610         Object *obedit= CTX_data_edit_object(C);
1611         float dia, mat[4][4];
1612         
1613         dia= new_primitive_matrix(C, mat);
1614         dia*= RNA_float_get(op->ptr, "size");
1615         
1616         make_prim(obedit, PRIM_ICOSPHERE, mat, 0, 0, 
1617                           RNA_int_get(op->ptr, "subdivisions"), dia, 0.0f, 0, 0);
1618         
1619         WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
1620         
1621         return OPERATOR_FINISHED;       
1622 }
1623
1624 void MESH_OT_add_primitive_ico_sphere(wmOperatorType *ot)
1625 {
1626         /* identifiers */
1627         ot->name= "Add Ico Sphere";
1628         ot->idname= "MESH_OT_add_primitive_ico_sphere";
1629         
1630         /* api callbacks */
1631         ot->exec= add_primitive_icosphere_exec;
1632         ot->poll= ED_operator_editmesh;
1633         
1634         /* flags */
1635         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1636         
1637         /* props */
1638         RNA_def_int(ot->srna, "subdivisions", 2, 0, 6, "Subdivisions", "", 0, 8);
1639         RNA_def_float(ot->srna, "size", 1.0f, 0.0f, FLT_MAX, "Size", "", 0.001f, 100.00);
1640 }
1641