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