Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Hughes <khughes@pacific.edu>2006-04-23 22:19:37 +0400
committerKen Hughes <khughes@pacific.edu>2006-04-23 22:19:37 +0400
commita26ef5887711c98d8fbd37be6871c84b9f7d5d98 (patch)
treeafa9b61568788474d1bcd0a88decb8ec8f5592a6 /source/blender/src/editmesh_add.c
parente6db82ec04f1b70ee7cd73f6cada77d7dd962676 (diff)
===Tools===
Patch #4119, submitted by Lukas Steiblys (imbusy1). Mesh objects (created through the toolbox) which take user input such as number of verts, are not created if the user cancels input. Thanks for the patch!
Diffstat (limited to 'source/blender/src/editmesh_add.c')
-rw-r--r--source/blender/src/editmesh_add.c136
1 files changed, 76 insertions, 60 deletions
diff --git a/source/blender/src/editmesh_add.c b/source/blender/src/editmesh_add.c
index 6e82e82134e..5ae47c078c1 100644
--- a/source/blender/src/editmesh_add.c
+++ b/source/blender/src/editmesh_add.c
@@ -701,7 +701,38 @@ void adduplicate_mesh(void)
Transform();
}
+/* check whether an object to add mesh to exists, if not, create one
+* returns 1 if new object created, else 0 */
+int confirm_objectExists( Mesh **me, float mat[][3] )
+{
+ int newob = 0;
+
+ /* deselectall */
+ EM_clear_flag_all(SELECT);
+
+ /* if no obedit: new object and enter editmode */
+ if(G.obedit==NULL) {
+ /* add_object actually returns an object ! :-)
+ But it also stores the added object struct in
+ G.scene->basact->object (BASACT->object) */
+ add_object_draw(OB_MESH);
+
+ G.obedit= BASACT->object;
+
+ where_is_object(G.obedit);
+
+ make_editMesh();
+ setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
+ newob= 1;
+ }
+ *me = G.obedit->data;
+
+ /* imat and centre and size */
+ Mat3CpyMat4(mat, G.obedit->obmat);
+
+ return newob;
+}
void add_primitiveMesh(int type)
{
@@ -713,6 +744,7 @@ void add_primitiveMesh(int type)
static short tot=32, seg=32, subdiv=2;
short a, b, ext=0, fill=0, totoud, newob=0;
char *undostr="Add Primitive";
+ char *name=NULL;
if(G.scene->id.lib) return;
@@ -727,48 +759,9 @@ void add_primitiveMesh(int type)
G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT);
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
}
-
- /* if no obedit: new object and enter editmode */
- if(G.obedit==NULL) {
- /* add_object actually returns an object ! :-)
- But it also stores the added object struct in
- G.scene->basact->object (BASACT->object) */
-
- add_object_draw(OB_MESH);
-
- G.obedit= BASACT->object;
-
- where_is_object(G.obedit);
-
- make_editMesh();
- setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
- newob= 1;
- }
- me= G.obedit->data;
-
- /* deselectall */
- EM_clear_flag_all(SELECT);
totoud= tot; /* store, and restore when cube/plane */
- /* imat and centre and size */
- Mat3CpyMat4(mat, G.obedit->obmat);
-
- curs= give_cursor();
- VECCOPY(cent, curs);
- cent[0]-= G.obedit->obmat[3][0];
- cent[1]-= G.obedit->obmat[3][1];
- cent[2]-= G.obedit->obmat[3][2];
-
- if(type!= 31) {
- Mat3CpyMat4(imat, G.vd->viewmat);
- Mat3MulVecfl(imat, cent);
- Mat3MulMat3(cmat, imat, mat);
- Mat3Inv(imat,cmat);
- } else {
- Mat3Inv(imat, mat);
- }
-
/* ext==extrudeflag, tot==amount of vertices in basis */
switch(type) {
@@ -776,83 +769,106 @@ void add_primitiveMesh(int type)
tot= 4;
ext= 0;
fill= 1;
- if(newob) rename_id((ID *)G.obedit, "Plane");
- if(newob) rename_id((ID *)me, "Plane");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Plane";
undostr="Add Plane";
break;
case 1: /* cube */
tot= 4;
ext= 1;
fill= 1;
- if(newob) rename_id((ID *)G.obedit, "Cube");
- if(newob) rename_id((ID *)me, "Cube");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Cube";
undostr="Add Cube";
break;
case 4: /* circle */
if(button(&tot,3,100,"Vertices:")==0) return;
ext= 0;
fill= 0;
- if(newob) rename_id((ID *)G.obedit, "Circle");
- if(newob) rename_id((ID *)me, "Circle");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Circle";
undostr="Add Circle";
break;
case 5: /* cylinder */
if(button(&tot,3,100,"Vertices:")==0) return;
ext= 1;
fill= 1;
- if(newob) rename_id((ID *)G.obedit, "Cylinder");
- if(newob) rename_id((ID *)me, "Cylinder");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Cylinder";
undostr="Add Cylinder";
break;
case 6: /* tube */
if(button(&tot,3,100,"Vertices:")==0) return;
ext= 1;
fill= 0;
- if(newob) rename_id((ID *)G.obedit, "Tube");
- if(newob) rename_id((ID *)me, "Tube");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Tube";
undostr="Add Tube";
break;
case 7: /* cone */
if(button(&tot,3,100,"Vertices:")==0) return;
ext= 0;
fill= 1;
- if(newob) rename_id((ID *)G.obedit, "Cone");
- if(newob) rename_id((ID *)me, "Cone");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Cone";
undostr="Add Cone";
break;
case 10: /* grid */
if(button(&tot,2,100,"X res:")==0) return;
if(button(&seg,2,100,"Y res:")==0) return;
- if(newob) rename_id((ID *)G.obedit, "Grid");
- if(newob) rename_id((ID *)me, "Grid");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Grid";
undostr="Add Grid";
break;
case 11: /* UVsphere */
if(button(&seg,3,100,"Segments:")==0) return;
if(button(&tot,3,100,"Rings:")==0) return;
- if(newob) rename_id((ID *)G.obedit, "Sphere");
- if(newob) rename_id((ID *)me, "Sphere");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Sphere";
undostr="Add UV Sphere";
break;
case 12: /* Icosphere */
if(button(&subdiv,1,5,"Subdivision:")==0) return;
- if(newob) rename_id((ID *)G.obedit, "Sphere");
- if(newob) rename_id((ID *)me, "Sphere");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Sphere";
undostr="Add Ico Sphere";
break;
case 13: /* Monkey */
- if(newob) rename_id((ID *)G.obedit, "Suzanne");
- if(newob) rename_id((ID *)me, "Suzanne");
+ newob = confirm_objectExists( &me, mat );
+ if(newob) name = "Suzanne";
undostr="Add Monkey";
break;
+ default:
+ newob = confirm_objectExists( &me, mat );
+ break;
}
+ if( name!=NULL ) {
+ rename_id((ID *)G.obedit, name );
+ rename_id((ID *)me, name );
+ }
+
+ curs= give_cursor();
+ VECCOPY(cent, curs);
+ cent[0]-= G.obedit->obmat[3][0];
+ cent[1]-= G.obedit->obmat[3][1];
+ cent[2]-= G.obedit->obmat[3][2];
+
+ /* 31 is a prime number */
+ if(type!= 31) {
+ Mat3CpyMat4(imat, G.vd->viewmat);
+ Mat3MulVecfl(imat, cent);
+ Mat3MulMat3(cmat, imat, mat);
+ Mat3Inv(imat,cmat);
+ } else {
+ Mat3Inv(imat, mat);
+ }
+
dia= sqrt(2.0)*G.vd->grid;
d= -G.vd->grid;
phid= 2*M_PI/tot;
phi= .25*M_PI;
-
if(type<10) { /* all types except grid, sphere... */
if(ext==0 && type!=7) d= 0;