706
void add_primitiveMesh(int type)
704
/* check whether an object to add mesh to exists, if not, create one
705
* returns 1 if new object created, else 0 */
706
int confirm_objectExists( Mesh **me, float mat[][3] )
708
EditMesh *em = G.editMesh;
710
EditVert *eve, *v1=NULL, *v2, *v3, *v4=NULL, *vtop, *vdown;
711
float *curs, d, dia, phi, phid, cent[3], vec[3], imat[3][3], mat[3][3];
712
float q[4], cmat[3][3], nor[3]= {0.0, 0.0, 0.0};
713
static short tot=32, seg=32, subdiv=2;
714
short a, b, ext=0, fill=0, totoud, newob=0;
715
char *undostr="Add Primitive";
717
if(G.scene->id.lib) return;
719
/* this function also comes from an info window */
720
if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
723
/* if editmode exists for other type, it exits */
724
check_editmode(OB_MESH);
726
if(G.f & (G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT)) {
727
G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT);
728
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
711
EM_clear_flag_all(SELECT);
731
713
/* if no obedit: new object and enter editmode */
732
714
if(G.obedit==NULL) {
744
726
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
750
EM_clear_flag_all(SELECT);
752
totoud= tot; /* store, and restore when cube/plane */
729
*me = G.obedit->data;
754
731
/* imat and centre and size */
755
732
Mat3CpyMat4(mat, G.obedit->obmat);
759
cent[0]-= G.obedit->obmat[3][0];
760
cent[1]-= G.obedit->obmat[3][1];
761
cent[2]-= G.obedit->obmat[3][2];
764
Mat3CpyMat4(imat, G.vd->viewmat);
765
Mat3MulVecfl(imat, cent);
766
Mat3MulMat3(cmat, imat, mat);
772
/* ext==extrudeflag, tot==amount of vertices in basis */
779
if(newob) rename_id((ID *)G.obedit, "Plane");
780
if(newob) rename_id((ID *)me, "Plane");
787
if(newob) rename_id((ID *)G.obedit, "Cube");
788
if(newob) rename_id((ID *)me, "Cube");
792
if(button(&tot,3,100,"Vertices:")==0) return;
795
if(newob) rename_id((ID *)G.obedit, "Circle");
796
if(newob) rename_id((ID *)me, "Circle");
797
undostr="Add Circle";
799
case 5: /* cylinder */
800
if(button(&tot,3,100,"Vertices:")==0) return;
803
if(newob) rename_id((ID *)G.obedit, "Cylinder");
804
if(newob) rename_id((ID *)me, "Cylinder");
805
undostr="Add Cylinder";
808
if(button(&tot,3,100,"Vertices:")==0) return;
811
if(newob) rename_id((ID *)G.obedit, "Tube");
812
if(newob) rename_id((ID *)me, "Tube");
816
if(button(&tot,3,100,"Vertices:")==0) return;
819
if(newob) rename_id((ID *)G.obedit, "Cone");
820
if(newob) rename_id((ID *)me, "Cone");
824
if(button(&tot,2,100,"X res:")==0) return;
825
if(button(&seg,2,100,"Y res:")==0) return;
826
if(newob) rename_id((ID *)G.obedit, "Grid");
827
if(newob) rename_id((ID *)me, "Grid");
830
case 11: /* UVsphere */
831
if(button(&seg,3,100,"Segments:")==0) return;
832
if(button(&tot,3,100,"Rings:")==0) return;
833
if(newob) rename_id((ID *)G.obedit, "Sphere");
834
if(newob) rename_id((ID *)me, "Sphere");
835
undostr="Add UV Sphere";
837
case 12: /* Icosphere */
838
if(button(&subdiv,1,5,"Subdivision:")==0) return;
839
if(newob) rename_id((ID *)G.obedit, "Sphere");
840
if(newob) rename_id((ID *)me, "Sphere");
841
undostr="Add Ico Sphere";
843
case 13: /* Monkey */
844
if(newob) rename_id((ID *)G.obedit, "Suzanne");
845
if(newob) rename_id((ID *)me, "Suzanne");
846
undostr="Add Monkey";
850
dia= sqrt(2.0)*G.vd->grid;
737
void make_prim(int type, float imat[3][3], short tot, short seg,
738
short subdiv, float dia, float d, short ext, short fill,
741
EditMesh *em = G.editMesh;
742
EditVert *eve, *v1=NULL, *v2, *v3, *v4=NULL, *vtop, *vdown;
743
float phi, phid, vec[3];
744
float q[4], cmat[3][3], nor[3]= {0.0, 0.0, 0.0};
852
747
phid= 2*M_PI/tot;
856
if(type<10) { /* all types except grid, sphere... */
753
eve= em->verts.first;
758
/* one segment first: the X axis */
760
phid= 2.0/((float)tot-1);
762
vec[0]= cent[0]+dia*phi;
763
vec[1]= cent[1]- dia;
765
Mat3MulVecfl(imat,vec);
766
eve= addvertlist(vec);
769
addedgelist(eve->prev, eve, NULL);
773
/* extrude and translate */
776
Mat3MulVecfl(imat, vec);
777
for(a=0;a<seg-1;a++) {
778
extrudeflag_vert(2, nor); // nor unused
779
translateflag(2, vec);
782
case 11: /* UVsphere */
784
/* clear all flags */
785
eve= em->verts.first;
791
/* one segment first */
794
for(a=0; a<=tot; a++) {
795
vec[0]= dia*sin(phi);
797
vec[2]= dia*cos(phi);
798
eve= addvertlist(vec);
801
else addedgelist(eve->prev, eve, NULL);
805
/* extrude and rotate */
812
for(a=0; a<seg; a++) {
813
extrudeflag_vert(2, nor); // nor unused
814
rotateflag(2, v1->co, cmat);
817
removedoublesflag(4, 0.0001);
819
/* and now do imat */
820
eve= em->verts.first;
822
if(eve->f & SELECT) {
823
VecAddf(eve->co,eve->co,cent);
824
Mat3MulVecfl(imat,eve->co);
829
case 12: /* Icosphere */
834
/* clear all flags */
835
eve= em->verts.first;
842
vec[0]= dia*icovert[a][0];
843
vec[1]= dia*icovert[a][1];
844
vec[2]= dia*icovert[a][2];
845
eva[a]= addvertlist(vec);
850
v1= eva[ icoface[a][0] ];
851
v2= eva[ icoface[a][1] ];
852
v3= eva[ icoface[a][2] ];
853
evtemp = addfacelist(v1, v2, v3, 0, NULL, NULL);
860
for(a=1; a<subdiv; a++) esubdivideflag(2, dia, 0,1,0);
861
/* and now do imat */
862
eve= em->verts.first;
865
VecAddf(eve->co,eve->co,cent);
866
Mat3MulVecfl(imat,eve->co);
871
// Clear the flag 2 from the edges
872
for(eed=em->edges.first;eed;eed=eed->next){
879
case 13: /* Monkey */
881
extern int monkeyo, monkeynv, monkeynf;
882
extern signed char monkeyf[][4];
883
extern signed char monkeyv[][3];
884
EditVert **tv= MEM_mallocN(sizeof(*tv)*monkeynv*2, "tv");
888
for (i=0; i<monkeynv; i++) {
890
v[0]= (monkeyv[i][0]+127)/128.0, v[1]= monkeyv[i][1]/128.0, v[2]= monkeyv[i][2]/128.0;
891
tv[i]= addvertlist(v);
893
tv[monkeynv+i]= (fabs(v[0]= -v[0])<0.001)?tv[i]:addvertlist(v);
894
tv[monkeynv+i]->f |= SELECT;
896
for (i=0; i<monkeynf; i++) {
897
efa= addfacelist(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);
898
efa= addfacelist(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);
903
/* and now do imat */
904
for(eve= em->verts.first; eve; eve= eve->next) {
905
if(eve->f & SELECT) {
906
VecAddf(eve->co,eve->co,cent);
907
Mat3MulVecfl(imat,eve->co);
910
recalc_editnormals();
913
default: /* all types except grid, sphere... */
857
914
if(ext==0 && type!=7) d= 0;
950
1007
addfacelist(vtop, v1, v3, 0, NULL, NULL);
953
if(type<2) tot= totoud;
956
else if(type==10) { /* grid */
958
eve= em->verts.first;
964
/* one segment first: the X axis */
966
phid= 2.0/((float)tot-1);
968
vec[0]= cent[0]+dia*phi;
969
vec[1]= cent[1]- dia;
971
Mat3MulVecfl(imat,vec);
972
eve= addvertlist(vec);
975
addedgelist(eve->prev, eve, NULL);
979
/* extrude and translate */
982
Mat3MulVecfl(imat, vec);
983
for(a=0;a<seg-1;a++) {
984
extrudeflag_vert(2, nor); // nor unused
985
translateflag(2, vec);
988
else if(type==11) { /* UVsphere */
990
/* clear all flags */
991
eve= em->verts.first;
997
/* one segment first */
1000
for(a=0; a<=tot; a++) {
1001
vec[0]= dia*sin(phi);
1003
vec[2]= dia*cos(phi);
1004
eve= addvertlist(vec);
1007
else addedgelist(eve->prev, eve, NULL);
1011
/* extrude and rotate */
1016
QuatToMat3(q, cmat);
1018
for(a=0; a<seg; a++) {
1019
extrudeflag_vert(2, nor); // nor unused
1020
rotateflag(2, v1->co, cmat);
1023
removedoublesflag(4, 0.0001);
1025
/* and now do imat */
1026
eve= em->verts.first;
1028
if(eve->f & SELECT) {
1029
VecAddf(eve->co,eve->co,cent);
1030
Mat3MulVecfl(imat,eve->co);
1035
else if(type==12) { /* Icosphere */
1039
/* clear all flags */
1040
eve= em->verts.first;
1047
vec[0]= dia*icovert[a][0];
1048
vec[1]= dia*icovert[a][1];
1049
vec[2]= dia*icovert[a][2];
1050
eva[a]= addvertlist(vec);
1055
v1= eva[ icoface[a][0] ];
1056
v2= eva[ icoface[a][1] ];
1057
v3= eva[ icoface[a][2] ];
1058
evtemp = addfacelist(v1, v2, v3, 0, NULL, NULL);
1059
evtemp->e1->f = 1+2;
1060
evtemp->e2->f = 1+2;
1061
evtemp->e3->f = 1+2;
1065
for(a=1; a<subdiv; a++) esubdivideflag(2, dia, 0,1,0);
1066
/* and now do imat */
1067
eve= em->verts.first;
1070
VecAddf(eve->co,eve->co,cent);
1071
Mat3MulVecfl(imat,eve->co);
1076
// Clear the flag 2 from the edges
1077
for(eed=em->edges.first;eed;eed=eed->next){
1084
} else if (type==13) { /* Monkey */
1085
extern int monkeyo, monkeynv, monkeynf;
1086
extern signed char monkeyf[][4];
1087
extern signed char monkeyv[][3];
1088
EditVert **tv= MEM_mallocN(sizeof(*tv)*monkeynv*2, "tv");
1092
for (i=0; i<monkeynv; i++) {
1094
v[0]= (monkeyv[i][0]+127)/128.0, v[1]= monkeyv[i][1]/128.0, v[2]= monkeyv[i][2]/128.0;
1095
tv[i]= addvertlist(v);
1097
tv[monkeynv+i]= (fabs(v[0]= -v[0])<0.001)?tv[i]:addvertlist(v);
1098
tv[monkeynv+i]->f |= SELECT;
1100
for (i=0; i<monkeynf; i++) {
1101
efa= addfacelist(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);
1102
efa= addfacelist(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);
1107
/* and now do imat */
1108
for(eve= em->verts.first; eve; eve= eve->next) {
1109
if(eve->f & SELECT) {
1110
VecAddf(eve->co,eve->co,cent);
1111
Mat3MulVecfl(imat,eve->co);
1114
recalc_editnormals();
1010
/* simple selection flush OK, based on fact it's a single model */
1011
EM_select_flush(); /* flushes vertex -> edge -> face selection */
1013
if(type!=0 && type!=13)
1014
righthandfaces(1); /* otherwise monkey has eyes in wrong direction */
1017
void add_primitiveMesh(int type)
1020
float *curs, d, dia, phi, phid, cent[3], imat[3][3], mat[3][3];
1022
static short tot=32, seg=32, subdiv=2;
1023
short ext=0, fill=0, totoud, newob=0;
1024
char *undostr="Add Primitive";
1027
if(G.scene->id.lib) return;
1029
/* this function also comes from an info window */
1030
if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
1033
/* if editmode exists for other type, it exits */
1034
check_editmode(OB_MESH);
1036
if(G.f & (G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT)) {
1037
G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT);
1038
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
1041
totoud= tot; /* store, and restore when cube/plane */
1043
/* ext==extrudeflag, tot==amount of vertices in basis */
1050
newob = confirm_objectExists( &me, mat );
1051
if(newob) name = "Plane";
1052
undostr="Add Plane";
1058
newob = confirm_objectExists( &me, mat );
1059
if(newob) name = "Cube";
1062
case 4: /* circle */
1063
if(button(&tot,3,100,"Vertices:")==0) return;
1066
newob = confirm_objectExists( &me, mat );
1067
if(newob) name = "Circle";
1068
undostr="Add Circle";
1070
case 5: /* cylinder */
1071
if(button(&tot,3,100,"Vertices:")==0) return;
1074
newob = confirm_objectExists( &me, mat );
1075
if(newob) name = "Cylinder";
1076
undostr="Add Cylinder";
1079
if(button(&tot,3,100,"Vertices:")==0) return;
1082
newob = confirm_objectExists( &me, mat );
1083
if(newob) name = "Tube";
1087
if(button(&tot,3,100,"Vertices:")==0) return;
1090
newob = confirm_objectExists( &me, mat );
1091
if(newob) name = "Cone";
1095
if(button(&tot,2,100,"X res:")==0) return;
1096
if(button(&seg,2,100,"Y res:")==0) return;
1097
newob = confirm_objectExists( &me, mat );
1098
if(newob) name = "Grid";
1101
case 11: /* UVsphere */
1102
if(button(&seg,3,100,"Segments:")==0) return;
1103
if(button(&tot,3,100,"Rings:")==0) return;
1104
newob = confirm_objectExists( &me, mat );
1105
if(newob) name = "Sphere";
1106
undostr="Add UV Sphere";
1108
case 12: /* Icosphere */
1109
if(button(&subdiv,1,5,"Subdivision:")==0) return;
1110
newob = confirm_objectExists( &me, mat );
1111
if(newob) name = "Sphere";
1112
undostr="Add Ico Sphere";
1114
case 13: /* Monkey */
1115
newob = confirm_objectExists( &me, mat );
1116
if(newob) name = "Suzanne";
1117
undostr="Add Monkey";
1120
newob = confirm_objectExists( &me, mat );
1125
rename_id((ID *)G.obedit, name );
1126
rename_id((ID *)me, name );
1129
curs= give_cursor();
1130
VECCOPY(cent, curs);
1131
cent[0]-= G.obedit->obmat[3][0];
1132
cent[1]-= G.obedit->obmat[3][1];
1133
cent[2]-= G.obedit->obmat[3][2];
1135
Mat3CpyMat4(imat, G.vd->viewmat);
1136
Mat3MulVecfl(imat, cent);
1137
Mat3MulMat3(cmat, imat, mat);
1141
if(type == 0 || type == 1) /* plane, cube (diameter of 1.41 makes it unit size) */
1148
make_prim(type, imat, tot, seg, subdiv, dia, d,
1151
if(type<2) tot = totoud;
1117
1153
// simple selection flush OK, based on fact it's a single model
1118
1154
EM_select_flush(); // flushes vertex -> edge -> face selection