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