~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/src/editmesh_add.c

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
701
701
        Transform();
702
702
}
703
703
 
704
 
 
705
 
 
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] )
707
707
{
708
 
        EditMesh *em = G.editMesh;
709
 
        Mesh *me;
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";
716
 
        
717
 
        if(G.scene->id.lib) return;
718
 
 
719
 
        /* this function also comes from an info window */
720
 
        if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
721
 
        if(G.vd==0) return;
722
 
 
723
 
        /* if editmode exists for other type, it exits */
724
 
        check_editmode(OB_MESH);
725
 
        
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);
729
 
        }
 
708
        int newob = 0;
 
709
        
 
710
        /* deselectall */
 
711
        EM_clear_flag_all(SELECT);
730
712
        
731
713
        /* if no obedit: new object and enter editmode */
732
714
        if(G.obedit==NULL) {
744
726
                setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
745
727
                newob= 1;
746
728
        }
747
 
        me= G.obedit->data;
748
 
        
749
 
        /* deselectall */
750
 
        EM_clear_flag_all(SELECT);
751
 
 
752
 
        totoud= tot; /* store, and restore when cube/plane */
 
729
        *me = G.obedit->data;
753
730
        
754
731
        /* imat and centre and size */
755
732
        Mat3CpyMat4(mat, G.obedit->obmat);
756
 
 
757
 
        curs= give_cursor();
758
 
        VECCOPY(cent, curs);
759
 
        cent[0]-= G.obedit->obmat[3][0];
760
 
        cent[1]-= G.obedit->obmat[3][1];
761
 
        cent[2]-= G.obedit->obmat[3][2];
762
 
 
763
 
        if(type!= 31) {
764
 
                Mat3CpyMat4(imat, G.vd->viewmat);
765
 
                Mat3MulVecfl(imat, cent);
766
 
                Mat3MulMat3(cmat, imat, mat);
767
 
                Mat3Inv(imat,cmat);
768
 
        } else {
769
 
                Mat3Inv(imat, mat);
770
 
        }
771
733
        
772
 
        /* ext==extrudeflag, tot==amount of vertices in basis */
773
 
 
774
 
        switch(type) {
775
 
        case 0:         /* plane */
776
 
                tot= 4;
777
 
                ext= 0;
778
 
                fill= 1;
779
 
                if(newob) rename_id((ID *)G.obedit, "Plane");
780
 
                if(newob) rename_id((ID *)me, "Plane");
781
 
                undostr="Add Plane";
782
 
                break;
783
 
        case 1:         /* cube  */
784
 
                tot= 4;
785
 
                ext= 1;
786
 
                fill= 1;
787
 
                if(newob) rename_id((ID *)G.obedit, "Cube");
788
 
                if(newob) rename_id((ID *)me, "Cube");
789
 
                undostr="Add Cube";
790
 
                break;
791
 
        case 4:         /* circle  */
792
 
                if(button(&tot,3,100,"Vertices:")==0) return;
793
 
                ext= 0;
794
 
                fill= 0;
795
 
                if(newob) rename_id((ID *)G.obedit, "Circle");
796
 
                if(newob) rename_id((ID *)me, "Circle");
797
 
                undostr="Add Circle";
798
 
                break;
799
 
        case 5:         /* cylinder  */
800
 
                if(button(&tot,3,100,"Vertices:")==0) return;
801
 
                ext= 1;
802
 
                fill= 1;
803
 
                if(newob) rename_id((ID *)G.obedit, "Cylinder");
804
 
                if(newob) rename_id((ID *)me, "Cylinder");
805
 
                undostr="Add Cylinder";
806
 
                break;
807
 
        case 6:         /* tube  */
808
 
                if(button(&tot,3,100,"Vertices:")==0) return;
809
 
                ext= 1;
810
 
                fill= 0;
811
 
                if(newob) rename_id((ID *)G.obedit, "Tube");
812
 
                if(newob) rename_id((ID *)me, "Tube");
813
 
                undostr="Add Tube";
814
 
                break;
815
 
        case 7:         /* cone  */
816
 
                if(button(&tot,3,100,"Vertices:")==0) return;
817
 
                ext= 0;
818
 
                fill= 1;
819
 
                if(newob) rename_id((ID *)G.obedit, "Cone");
820
 
                if(newob) rename_id((ID *)me, "Cone");
821
 
                undostr="Add Cone";
822
 
                break;
823
 
        case 10:        /* grid */
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");
828
 
                undostr="Add Grid";
829
 
                break;
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";
836
 
                break;
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";
842
 
                break;
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";
847
 
                break;
848
 
        }
849
 
 
850
 
        dia= sqrt(2.0)*G.vd->grid;
851
 
        d= -G.vd->grid;
 
734
        return newob;
 
735
}
 
736
 
 
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,
 
739
        float cent[3])
 
740
{
 
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};
 
745
        short a, b;
 
746
 
852
747
        phid= 2*M_PI/tot;
853
748
        phi= .25*M_PI;
854
749
 
855
 
 
856
 
        if(type<10) {   /* all types except grid, sphere... */
 
750
        switch(type) {
 
751
        case 10: /*  grid */
 
752
                /* clear flags */
 
753
                eve= em->verts.first;
 
754
                while(eve) {
 
755
                        eve->f= 0;
 
756
                        eve= eve->next;
 
757
                }
 
758
                /* one segment first: the X axis */
 
759
                phi= 1.0; 
 
760
                phid= 2.0/((float)tot-1);
 
761
                for(a=0;a<tot;a++) {
 
762
                        vec[0]= cent[0]+dia*phi;
 
763
                        vec[1]= cent[1]- dia;
 
764
                        vec[2]= cent[2];
 
765
                        Mat3MulVecfl(imat,vec);
 
766
                        eve= addvertlist(vec);
 
767
                        eve->f= 1+2+4;
 
768
                        if (a) {
 
769
                                addedgelist(eve->prev, eve, NULL);
 
770
                        }
 
771
                        phi-=phid;
 
772
                }
 
773
                /* extrude and translate */
 
774
                vec[0]= vec[2]= 0.0;
 
775
                vec[1]= dia*phid;
 
776
                Mat3MulVecfl(imat, vec);
 
777
                for(a=0;a<seg-1;a++) {
 
778
                        extrudeflag_vert(2, nor);       // nor unused
 
779
                        translateflag(2, vec);
 
780
                }
 
781
                break;
 
782
        case 11: /*  UVsphere */
 
783
                
 
784
                /* clear all flags */
 
785
                eve= em->verts.first;
 
786
                while(eve) {
 
787
                        eve->f= 0;
 
788
                        eve= eve->next;
 
789
                }
 
790
                
 
791
                /* one segment first */
 
792
                phi= 0; 
 
793
                phid/=2;
 
794
                for(a=0; a<=tot; a++) {
 
795
                        vec[0]= dia*sin(phi);
 
796
                        vec[1]= 0.0;
 
797
                        vec[2]= dia*cos(phi);
 
798
                        eve= addvertlist(vec);
 
799
                        eve->f= 1+2+4;
 
800
                        if(a==0) v1= eve;
 
801
                        else addedgelist(eve->prev, eve, NULL);
 
802
                        phi+= phid;
 
803
                }
 
804
                
 
805
                /* extrude and rotate */
 
806
                phi= M_PI/seg;
 
807
                q[0]= cos(phi);
 
808
                q[3]= sin(phi);
 
809
                q[1]=q[2]= 0;
 
810
                QuatToMat3(q, cmat);
 
811
                
 
812
                for(a=0; a<seg; a++) {
 
813
                        extrudeflag_vert(2, nor); // nor unused
 
814
                        rotateflag(2, v1->co, cmat);
 
815
                }
 
816
 
 
817
                removedoublesflag(4, 0.0001);
 
818
 
 
819
                /* and now do imat */
 
820
                eve= em->verts.first;
 
821
                while(eve) {
 
822
                        if(eve->f & SELECT) {
 
823
                                VecAddf(eve->co,eve->co,cent);
 
824
                                Mat3MulVecfl(imat,eve->co);
 
825
                        }
 
826
                        eve= eve->next;
 
827
                }
 
828
                break;
 
829
        case 12: /* Icosphere */
 
830
                {
 
831
                        EditVert *eva[12];
 
832
                        EditEdge *eed;
 
833
                        
 
834
                        /* clear all flags */
 
835
                        eve= em->verts.first;
 
836
                        while(eve) {
 
837
                                eve->f= 0;
 
838
                                eve= eve->next;
 
839
                        }
 
840
                        dia/=200;
 
841
                        for(a=0;a<12;a++) {
 
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);
 
846
                                eva[a]->f= 1+2;
 
847
                        }
 
848
                        for(a=0;a<20;a++) {
 
849
                                EditFace *evtemp;
 
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);
 
854
                                evtemp->e1->f = 1+2;
 
855
                                evtemp->e2->f = 1+2;
 
856
                                evtemp->e3->f = 1+2;
 
857
                        }
 
858
 
 
859
                        dia*=200;
 
860
                        for(a=1; a<subdiv; a++) esubdivideflag(2, dia, 0,1,0);
 
861
                        /* and now do imat */
 
862
                        eve= em->verts.first;
 
863
                        while(eve) {
 
864
                                if(eve->f & 2) {
 
865
                                        VecAddf(eve->co,eve->co,cent);
 
866
                                        Mat3MulVecfl(imat,eve->co);
 
867
                                }
 
868
                                eve= eve->next;
 
869
                        }
 
870
                        
 
871
                        // Clear the flag 2 from the edges
 
872
                        for(eed=em->edges.first;eed;eed=eed->next){
 
873
                                if(eed->f & 2){
 
874
                                           eed->f &= !2;
 
875
                                }   
 
876
                        }
 
877
                }
 
878
                break;
 
879
        case 13: /* Monkey */
 
880
                {
 
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");
 
885
                        EditFace *efa;
 
886
                        int i;
 
887
 
 
888
                        for (i=0; i<monkeynv; i++) {
 
889
                                float v[3];
 
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);
 
892
                                tv[i]->f |= SELECT;
 
893
                                tv[monkeynv+i]= (fabs(v[0]= -v[0])<0.001)?tv[i]:addvertlist(v);
 
894
                                tv[monkeynv+i]->f |= SELECT;
 
895
                        }
 
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);
 
899
                        }
 
900
 
 
901
                        MEM_freeN(tv);
 
902
 
 
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);
 
908
                                }
 
909
                        }
 
910
                        recalc_editnormals();
 
911
                }
 
912
                break;
 
913
        default: /* all types except grid, sphere... */
857
914
                if(ext==0 && type!=7) d= 0;
858
915
        
859
916
                /* vertices */
949
1006
                        }
950
1007
                        addfacelist(vtop, v1, v3, 0, NULL, NULL);
951
1008
                }
952
 
                
953
 
                if(type<2) tot= totoud;
954
 
                
955
 
        }
956
 
        else if(type==10) {     /*  grid */
957
 
                /* clear flags */
958
 
                eve= em->verts.first;
959
 
                while(eve) {
960
 
                        eve->f= 0;
961
 
                        eve= eve->next;
962
 
                }
963
 
                dia= G.vd->grid;
964
 
                /* one segment first: the X axis */
965
 
                phi= 1.0; 
966
 
                phid= 2.0/((float)tot-1);
967
 
                for(a=0;a<tot;a++) {
968
 
                        vec[0]= cent[0]+dia*phi;
969
 
                        vec[1]= cent[1]- dia;
970
 
                        vec[2]= cent[2];
971
 
                        Mat3MulVecfl(imat,vec);
972
 
                        eve= addvertlist(vec);
973
 
                        eve->f= 1+2+4;
974
 
                        if (a) {
975
 
                                addedgelist(eve->prev, eve, NULL);
976
 
                        }
977
 
                        phi-=phid;
978
 
                }
979
 
                /* extrude and translate */
980
 
                vec[0]= vec[2]= 0.0;
981
 
                vec[1]= dia*phid;
982
 
                Mat3MulVecfl(imat, vec);
983
 
                for(a=0;a<seg-1;a++) {
984
 
                        extrudeflag_vert(2, nor);       // nor unused
985
 
                        translateflag(2, vec);
986
 
                }
987
 
        }
988
 
        else if(type==11) {     /*  UVsphere */
989
 
                
990
 
                /* clear all flags */
991
 
                eve= em->verts.first;
992
 
                while(eve) {
993
 
                        eve->f= 0;
994
 
                        eve= eve->next;
995
 
                }
996
 
                
997
 
                /* one segment first */
998
 
                phi= 0; 
999
 
                phid/=2;
1000
 
                for(a=0; a<=tot; a++) {
1001
 
                        vec[0]= dia*sin(phi);
1002
 
                        vec[1]= 0.0;
1003
 
                        vec[2]= dia*cos(phi);
1004
 
                        eve= addvertlist(vec);
1005
 
                        eve->f= 1+2+4;
1006
 
                        if(a==0) v1= eve;
1007
 
                        else addedgelist(eve->prev, eve, NULL);
1008
 
                        phi+= phid;
1009
 
                }
1010
 
                
1011
 
                /* extrude and rotate */
1012
 
                phi= M_PI/seg;
1013
 
                q[0]= cos(phi);
1014
 
                q[3]= sin(phi);
1015
 
                q[1]=q[2]= 0;
1016
 
                QuatToMat3(q, cmat);
1017
 
                
1018
 
                for(a=0; a<seg; a++) {
1019
 
                        extrudeflag_vert(2, nor); // nor unused
1020
 
                        rotateflag(2, v1->co, cmat);
1021
 
                }
1022
 
 
1023
 
                removedoublesflag(4, 0.0001);
1024
 
 
1025
 
                /* and now do imat */
1026
 
                eve= em->verts.first;
1027
 
                while(eve) {
1028
 
                        if(eve->f & SELECT) {
1029
 
                                VecAddf(eve->co,eve->co,cent);
1030
 
                                Mat3MulVecfl(imat,eve->co);
1031
 
                        }
1032
 
                        eve= eve->next;
1033
 
                }
1034
 
        }
1035
 
        else if(type==12) {     /* Icosphere */
1036
 
                EditVert *eva[12];
1037
 
        EditEdge *eed;
1038
 
        
1039
 
                /* clear all flags */
1040
 
                eve= em->verts.first;
1041
 
                while(eve) {
1042
 
                        eve->f= 0;
1043
 
                        eve= eve->next;
1044
 
                }
1045
 
                dia/=200;
1046
 
                for(a=0;a<12;a++) {
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);
1051
 
                        eva[a]->f= 1+2;
1052
 
                }
1053
 
                for(a=0;a<20;a++) {
1054
 
                    EditFace *evtemp;
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;
1062
 
                }
1063
 
 
1064
 
                dia*=200;
1065
 
                for(a=1; a<subdiv; a++) esubdivideflag(2, dia, 0,1,0);
1066
 
                /* and now do imat */
1067
 
                eve= em->verts.first;
1068
 
                while(eve) {
1069
 
                        if(eve->f & 2) {
1070
 
                                VecAddf(eve->co,eve->co,cent);
1071
 
                                Mat3MulVecfl(imat,eve->co);
1072
 
                        }
1073
 
                        eve= eve->next;
1074
 
                }
1075
 
                
1076
 
                // Clear the flag 2 from the edges
1077
 
                for(eed=em->edges.first;eed;eed=eed->next){
1078
 
            if(eed->f & 2){
1079
 
                   eed->f &= !2;
1080
 
            }   
1081
 
        }
1082
 
                
1083
 
                
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");
1089
 
                EditFace *efa;
1090
 
                int i;
1091
 
 
1092
 
                for (i=0; i<monkeynv; i++) {
1093
 
                        float v[3];
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);
1096
 
                        tv[i]->f |= SELECT;
1097
 
                        tv[monkeynv+i]= (fabs(v[0]= -v[0])<0.001)?tv[i]:addvertlist(v);
1098
 
                        tv[monkeynv+i]->f |= SELECT;
1099
 
                }
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);
1103
 
                }
1104
 
 
1105
 
                MEM_freeN(tv);
1106
 
 
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);
1112
 
                        }
1113
 
                }
1114
 
                recalc_editnormals();
1115
 
        }
1116
 
        
 
1009
        }
 
1010
        /* simple selection flush OK, based on fact it's a single model */
 
1011
        EM_select_flush(); /* flushes vertex -> edge -> face selection */
 
1012
        
 
1013
        if(type!=0 && type!=13)
 
1014
                righthandfaces(1);      /* otherwise monkey has eyes in wrong direction */
 
1015
}
 
1016
 
 
1017
void add_primitiveMesh(int type)
 
1018
{
 
1019
        Mesh *me;
 
1020
        float *curs, d, dia, phi, phid, cent[3], imat[3][3], mat[3][3];
 
1021
        float cmat[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";
 
1025
        char *name=NULL;
 
1026
        
 
1027
        if(G.scene->id.lib) return;
 
1028
 
 
1029
        /* this function also comes from an info window */
 
1030
        if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
 
1031
        if(G.vd==0) return;
 
1032
 
 
1033
        /* if editmode exists for other type, it exits */
 
1034
        check_editmode(OB_MESH);
 
1035
        
 
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);
 
1039
        }
 
1040
 
 
1041
        totoud= tot; /* store, and restore when cube/plane */
 
1042
        
 
1043
        /* ext==extrudeflag, tot==amount of vertices in basis */
 
1044
 
 
1045
        switch(type) {
 
1046
        case 0:         /* plane */
 
1047
                tot= 4;
 
1048
                ext= 0;
 
1049
                fill= 1;
 
1050
                newob = confirm_objectExists( &me, mat );
 
1051
                if(newob) name = "Plane";
 
1052
                undostr="Add Plane";
 
1053
                break;
 
1054
        case 1:         /* cube  */
 
1055
                tot= 4;
 
1056
                ext= 1;
 
1057
                fill= 1;
 
1058
                newob = confirm_objectExists( &me, mat );
 
1059
                if(newob) name = "Cube";
 
1060
                undostr="Add Cube";
 
1061
                break;
 
1062
        case 4:         /* circle  */
 
1063
                if(button(&tot,3,100,"Vertices:")==0) return;
 
1064
                ext= 0;
 
1065
                fill= 0;
 
1066
                newob = confirm_objectExists( &me, mat );
 
1067
                if(newob) name = "Circle";
 
1068
                undostr="Add Circle";
 
1069
                break;
 
1070
        case 5:         /* cylinder  */
 
1071
                if(button(&tot,3,100,"Vertices:")==0) return;
 
1072
                ext= 1;
 
1073
                fill= 1;
 
1074
                newob = confirm_objectExists( &me, mat );
 
1075
                if(newob) name = "Cylinder";
 
1076
                undostr="Add Cylinder";
 
1077
                break;
 
1078
        case 6:         /* tube  */
 
1079
                if(button(&tot,3,100,"Vertices:")==0) return;
 
1080
                ext= 1;
 
1081
                fill= 0;
 
1082
                newob = confirm_objectExists( &me, mat );
 
1083
                if(newob) name = "Tube";
 
1084
                undostr="Add Tube";
 
1085
                break;
 
1086
        case 7:         /* cone  */
 
1087
                if(button(&tot,3,100,"Vertices:")==0) return;
 
1088
                ext= 0;
 
1089
                fill= 1;
 
1090
                newob = confirm_objectExists( &me, mat );
 
1091
                if(newob) name = "Cone";
 
1092
                undostr="Add Cone";
 
1093
                break;
 
1094
        case 10:        /* grid */
 
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";
 
1099
                undostr="Add Grid";
 
1100
                break;
 
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";
 
1107
                break;
 
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";
 
1113
                break;
 
1114
        case 13:        /* Monkey */
 
1115
                newob = confirm_objectExists( &me, mat );
 
1116
                if(newob) name = "Suzanne";
 
1117
                undostr="Add Monkey";
 
1118
                break;
 
1119
        default:
 
1120
                newob = confirm_objectExists( &me, mat );
 
1121
                break;
 
1122
        }
 
1123
 
 
1124
        if( name!=NULL ) {
 
1125
                rename_id((ID *)G.obedit, name );
 
1126
                rename_id((ID *)me, name );
 
1127
        }
 
1128
 
 
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];
 
1134
 
 
1135
        Mat3CpyMat4(imat, G.vd->viewmat);
 
1136
        Mat3MulVecfl(imat, cent);
 
1137
        Mat3MulMat3(cmat, imat, mat);
 
1138
        Mat3Inv(imat,cmat);
 
1139
 
 
1140
        dia= G.vd->grid;
 
1141
        if(type == 0 || type == 1) /* plane, cube (diameter of 1.41 makes it unit size) */
 
1142
                dia *= sqrt(2.0);
 
1143
 
 
1144
        d= -G.vd->grid;
 
1145
        phid= 2*M_PI/tot;
 
1146
        phi= .25*M_PI;
 
1147
 
 
1148
        make_prim(type, imat, tot, seg, subdiv, dia, d,
 
1149
        ext, fill, cent);
 
1150
 
 
1151
        if(type<2) tot = totoud;
 
1152
 
1117
1153
        // simple selection flush OK, based on fact it's a single model
1118
1154
        EM_select_flush(); // flushes vertex -> edge -> face selection
1119
1155