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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: vpaint.c,v 1.15 2004/04/19 22:05:37 ton Exp $
 
2
 * $Id: vpaint.c,v 1.28 2005/05/18 20:32:32 ton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
39
39
 
40
40
#ifdef WIN32
41
41
#include <io.h>
42
 
#include "BLI_winstuff.h"
43
42
#else
44
43
#include <unistd.h>
45
44
#endif   
55
54
#include "DNA_mesh_types.h"
56
55
#include "DNA_meshdata_types.h"
57
56
#include "DNA_object_types.h"
 
57
#include "DNA_object_force.h"
58
58
#include "DNA_screen_types.h"
59
59
#include "DNA_scene_types.h"
60
60
#include "DNA_view3d_types.h"
 
61
#include "DNA_userdef_types.h"
61
62
 
62
 
#include "BKE_utildefines.h"
63
 
#include "BKE_mesh.h"
64
63
#include "BKE_displist.h"
65
64
#include "BKE_global.h"
 
65
#include "BKE_mesh.h"
 
66
#include "BKE_object.h"
 
67
#include "BKE_utildefines.h"
66
68
 
67
69
#include "BIF_graphics.h"
68
70
#include "BIF_interface.h"
71
73
#include "BIF_space.h"
72
74
#include "BIF_screen.h"
73
75
#include "BIF_toolbox.h"
 
76
#include "BIF_glutil.h"
74
77
#include "BIF_gl.h"
75
78
 
76
79
#include "BDR_vpaint.h"
97
100
#define VP_SOFT         4
98
101
#define VP_NORMALS      8
99
102
 
100
 
#define MAXINDEX        65336
 
103
#define MAXINDEX        512000
101
104
 
102
105
VPaint Gvp= {1.0, 1.0, 1.0, 0.2, 25.0, 1.0, 1.0, 0, VP_AREA+VP_SOFT};
103
106
float vpimat[3][3];
104
 
unsigned int *vpaintundobuf=0;
 
107
unsigned int *vpaintundobuf= NULL;
105
108
int totvpaintundo;
106
 
short *indexar= 0;
 
109
int *indexar= NULL;
107
110
 
108
111
int totwpaintundo;
109
112
MDeformVert *wpaintundobuf=NULL;
110
113
 
111
 
/* Function prototypes */
112
 
int calc_vp_alpha_dl(DispList *disp, MVert *mvert, int vert, short *mval);
113
 
 
114
114
/* in contradiction to cpack drawing colors, the MCOL colors (vpaint colors) are per byte! 
115
115
   so not endian sensitive. Mcol = ABGR!!! so be cautious with cpack calls */
116
116
 
231
231
         */
232
232
        
233
233
        if(G.obedit) {
234
 
                error("Unable to perform function in EditMode");
 
234
                error("Unable to perform function in Edit Mode");
235
235
                return;
236
236
        }
237
237
        
244
244
                me->flag &= ~ME_TWOSIDED;
245
245
        }
246
246
        
247
 
        dl= ob->disp.first;
248
 
        
249
 
        if(dl==0 || dl->col1==NULL) {
250
 
                shadeDispList(ob);
 
247
        /* but subsurf vertex colors are wrong */
 
248
        if (me->flag & ME_SUBSURF) {
 
249
                if(me->mcol) MEM_freeN(me->mcol);
 
250
                me->mcol= MEM_callocN(4*me->totface*sizeof(MCol), "mcol");
 
251
        }
 
252
        else {
251
253
                dl= ob->disp.first;
 
254
                
 
255
                if(dl==NULL || dl->col1==NULL) {
 
256
                        shadeDispList(ob);
 
257
                        dl= find_displist(&ob->disp, DL_VERTCOL);
 
258
                }
 
259
                if(dl && dl->col1) {
 
260
                        if(me->mcol) MEM_freeN(me->mcol);
 
261
                        me->mcol= MEM_dupallocN(dl->col1);
 
262
                }
252
263
        }
253
 
        if(dl && dl->col1) {
 
264
        
 
265
        if(me->mcol) {
254
266
                int i;
255
 
                
256
 
                if(me->mcol) MEM_freeN(me->mcol);
257
 
                
258
 
                me->mcol= MEM_dupallocN(dl->col1);
259
 
                if (me->mcol) {
260
 
                        for (i=0; i<me->totface*4; i++) {
261
 
                                MCol *mcol= &me->mcol[i];
262
 
                                mcol->a= 255;
263
 
                        }
 
267
                for (i=0; i<me->totface*4; i++) {
 
268
                        MCol *mcol= &me->mcol[i];
 
269
                        mcol->a= 255;
264
270
                }
265
271
                
266
272
                if(me->tface) mcol_to_tface(me, 1);
267
273
        }
 
274
        
268
275
        freedisplist(&(ob->disp));
269
276
        
270
277
        
329
336
 
330
337
        ob= OBACT;
331
338
        me= get_mesh(ob);
 
339
        if(ob->id.lib) return;
 
340
 
332
341
        if(me==0 || me->totface==0) return;
333
342
 
334
343
        if(me->tface) tface_to_mcol(me);
343
352
                *to= paintcol;
344
353
                to++; 
345
354
        }
 
355
        BIF_undo_push("Clear vertex colors");
346
356
        allqueue(REDRAWVIEW3D, 0);
347
357
        if(me->tface) mcol_to_tface(me, 1);
348
358
}
373
383
                        tf[i].col[3] = paintcol;
374
384
                }
375
385
        }
 
386
        BIF_undo_push("Clear vertex colors");
376
387
        allqueue(REDRAWVIEW3D, 0);
377
388
}
378
389
 
456
467
        Gvp.b /= 255.0;
457
468
 
458
469
        allqueue(REDRAWBUTSEDIT, 0);
 
470
        addqueue(curarea->win, REDRAW, 1); // needed for when panel is open...
459
471
}
460
472
 
461
473
void init_vertexpaint()
462
474
{
463
475
        
464
 
        indexar= MEM_mallocN(sizeof(short)*MAXINDEX + 2, "vertexpaint");
 
476
        indexar= MEM_mallocN(sizeof(int)*MAXINDEX + 2, "vertexpaint");
465
477
}
466
478
 
467
479
 
610
622
        size= (y2-y1)*(x2-x1);
611
623
        if(size<=0) return 0;
612
624
 
613
 
        memset(indexar, 0, 2*totvpaintundo+2);  /* plus 2! first element is total */
 
625
        memset(indexar, 0, sizeof(int)*totvpaintundo+2);        /* plus 2! first element is total */
614
626
        
615
627
        while(size--) {
616
628
                        
687
699
 
688
700
}
689
701
 
690
 
int calc_vp_alpha_dl(DispList *disp, MVert *mvert, int vert, short *mval)
 
702
static int calc_vp_alpha_dl(DispList *disp, MVert *mvert, int vert, short *mval)
691
703
/* Lets us do soft vertex painting onto a deformed mesh */
692
704
{
693
705
        float fac, dx, dy, nor[3];
777
789
        TFace *tface;
778
790
        float mat[4][4], imat[4][4];
779
791
        int index, totindex;
780
 
        short mval[2], mvalo[2], firsttime=1;
 
792
        short mval[2], mvalo[2], firsttime=1, mousebut;
781
793
        MDeformWeight   *dw, *uw;
782
794
        extern float editbutvweight;
783
795
        DispList *dl;
787
799
        if(G.obedit) return;
788
800
        if(G.obpose) return;
789
801
        
790
 
        if(indexar==0) init_vertexpaint();
 
802
        if(indexar==NULL) init_vertexpaint();
791
803
        
792
804
        ob= OBACT;
 
805
        if(ob->id.lib) return;
 
806
 
793
807
        me= get_mesh(ob);
794
808
        if (!me->dvert){
795
809
                return;
796
810
        }
797
811
        if(me==0 || me->totface==0) return;
798
 
        if(ob->lay & G.vd->lay); else error("Active object not in this layer!");
 
812
        if(ob->lay & G.vd->lay); else error("Active object is not in this layer");
799
813
        
800
814
        persp(PERSP_VIEW);
801
815
        /* imat for normals */
818
832
        mvalo[0]= mval[0];
819
833
        mvalo[1]= mval[1];
820
834
        
821
 
        while (get_mbut() & L_MOUSE) {
 
835
        if (U.flag & USER_LMOUSESELECT) mousebut = R_MOUSE;
 
836
        else mousebut = L_MOUSE;
 
837
        
 
838
        while (get_mbut() & mousebut) {
822
839
                getmouseco_areawin(mval);
823
840
                
824
841
                if(firsttime || mval[0]!=mvalo[0] || mval[1]!=mvalo[1]) {
825
842
                        
826
 
                        if(firsttime) draw_sel_circle(mval, 0, Gvp.size, Gvp.size, 0);
827
 
                        else draw_sel_circle(mval, mvalo, Gvp.size, Gvp.size, 0);
828
 
 
829
843
                        firsttime= 0;
830
844
                        
831
845
                        /* which faces are involved */
907
921
                else BIF_wait_for_statechange();
908
922
                
909
923
                if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1]) {
910
 
//                      makeDispList(ob);
 
924
 
911
925
                        scrarea_do_windraw(curarea);
 
926
 
 
927
                        /* draw circle in backbuf! */
 
928
                        persp(PERSP_WIN);
 
929
                        fdrawXORcirc((float)mval[0], (float)mval[1], Gvp.size);
 
930
                        persp(PERSP_VIEW);
 
931
 
912
932
                        screen_swapbuffers();
913
933
                        backdrawview3d(0);
914
 
                        draw_sel_circle(mval, 0, Gvp.size, Gvp.size, 0);
915
934
        
916
935
                        mvalo[0]= mval[0];
917
936
                        mvalo[1]= mval[1];
923
942
                me->mcol= 0;
924
943
        }
925
944
        
926
 
        /* clear circle */
927
 
        draw_sel_circle(0, mvalo, 0, Gvp.size, 1);
928
 
        
929
945
        makeDispList(ob);
 
946
        // this flag is event for softbody to refresh weightpaint values
 
947
        if(ob->soft) ob->softflag |= OB_SB_REDO;
930
948
        
931
949
        allqueue(REDRAWVIEW3D, 0);
932
950
 
938
956
        Mesh *me;
939
957
        MFace *mface;
940
958
        TFace *tface;
 
959
        DispList *dl;
941
960
        float mat[4][4], imat[4][4];
942
961
        unsigned int paintcol=0, *mcol, fcol1, fcol2;
943
962
        int index, alpha, totindex, total;
944
 
        short mval[2], mvalo[2], firsttime=1;
 
963
        short mval[2], mvalo[2], firsttime=1, mousebut;
945
964
        
946
965
        if((G.f & G_VERTEXPAINT)==0) return;
947
966
        if(G.obedit) return;
948
967
        
949
 
        if(indexar==0) init_vertexpaint();
 
968
        if(indexar==NULL) init_vertexpaint();
950
969
        
951
970
        ob= OBACT;
 
971
        if(ob->id.lib) return;
 
972
 
952
973
        me= get_mesh(ob);
953
 
        if(me==0 || me->totface==0) return;
954
 
        if(ob->lay & G.vd->lay); else error("Active object not in this layer!");
 
974
        if(me==NULL || me->totface==0) return;
 
975
        if(ob->lay & G.vd->lay); else error("Active object is not in this layer");
955
976
        
956
977
        if(me->tface==NULL && me->mcol==NULL) make_vertexcol();
957
978
 
979
1000
        mvalo[0]= mval[0];
980
1001
        mvalo[1]= mval[1];
981
1002
        
982
 
        while (get_mbut() & L_MOUSE) {
 
1003
        if (U.flag & USER_LMOUSESELECT) mousebut = R_MOUSE;
 
1004
        else mousebut = L_MOUSE;
 
1005
        
 
1006
        while (get_mbut() & mousebut) {
983
1007
                getmouseco_areawin(mval);
984
1008
                
985
1009
                if(firsttime || mval[0]!=mvalo[0] || mval[1]!=mvalo[1]) {
986
1010
                        
987
 
                        if(firsttime) draw_sel_circle(mval, 0, Gvp.size, Gvp.size, 0);
988
 
                        else draw_sel_circle(mval, mvalo, Gvp.size, Gvp.size, 0);
989
 
 
990
1011
                        firsttime= 0;
991
1012
 
992
1013
                        /* which faces are involved */
1025
1046
                                        }                                       
1026
1047
                                }
1027
1048
                        }
1028
 
                        
 
1049
 
 
1050
                        dl= find_displist(&ob->disp, DL_VERTS);
 
1051
 
1029
1052
                        for(index=0; index<totindex; index++) {
1030
1053
 
1031
1054
                                if(indexar[index] && indexar[index]<=me->totface) {
1047
1070
                                        
1048
1071
                                        total= 0;
1049
1072
                                        
1050
 
                                        total+= alpha= calc_vp_alpha(me->mvert+mface->v1, mval);
 
1073
                                        total+= alpha= calc_vp_alpha_dl(dl, me->mvert, mface->v1, mval);
1051
1074
                                        if(alpha) vpaint_blend( mcol, paintcol, alpha);
1052
1075
                                        
1053
 
                                        total+= alpha= calc_vp_alpha(me->mvert+mface->v2, mval);
 
1076
                                        total+= alpha= calc_vp_alpha_dl(dl, me->mvert, mface->v2, mval);
1054
1077
                                        if(alpha) vpaint_blend( mcol+1, paintcol, alpha);
1055
1078
        
1056
 
                                        total+= alpha= calc_vp_alpha(me->mvert+mface->v3, mval);
 
1079
                                        total+= alpha= calc_vp_alpha_dl(dl, me->mvert, mface->v3, mval);
1057
1080
                                        if(alpha) vpaint_blend( mcol+2, paintcol, alpha);
1058
1081
 
1059
1082
                                        if(mface->v4) {
1060
 
                                                total+= alpha= calc_vp_alpha(me->mvert+mface->v4, mval);
 
1083
                                                total+= alpha= calc_vp_alpha_dl(dl, me->mvert, mface->v4, mval);
1061
1084
                                                if(alpha) vpaint_blend( mcol+3, paintcol, alpha);
1062
1085
                                        }
1063
1086
                                        
1073
1096
                        
1074
1097
                        MTC_Mat4SwapMat4(G.vd->persmat, mat);
1075
1098
                        
1076
 
                }
1077
 
                else BIF_wait_for_statechange();
1078
 
                
1079
 
                if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1]) {
1080
1099
                        do_shared_vertexcol(me);
1081
1100
                        if(me->tface) {
1082
1101
                                mcol_to_tface(me, 0);
1083
1102
                        }
1084
1103
        
1085
1104
                        scrarea_do_windraw(curarea);
 
1105
 
 
1106
                        /* draw circle in backbuf! */
 
1107
                        persp(PERSP_WIN);
 
1108
                        fdrawXORcirc((float)mval[0], (float)mval[1], Gvp.size);
 
1109
                        persp(PERSP_VIEW);
 
1110
 
1086
1111
                        screen_swapbuffers();
1087
 
                        draw_sel_circle(mval, 0, Gvp.size, Gvp.size, 0);
1088
1112
                        backdrawview3d(0);
1089
 
        
 
1113
                        
1090
1114
                        mvalo[0]= mval[0];
1091
1115
                        mvalo[1]= mval[1];
1092
1116
                }
 
1117
                else BIF_wait_for_statechange();
1093
1118
        }
1094
1119
        
1095
1120
        if(me->tface) {
1097
1122
                me->mcol= 0;
1098
1123
        }
1099
1124
        
1100
 
        /* clear circle */
1101
 
        draw_sel_circle(0, mvalo, 0, Gvp.size, 1);
1102
 
        
1103
1125
        allqueue(REDRAWVIEW3D, 0);
1104
1126
}
1105
1127
 
1110
1132
        
1111
1133
        scrarea_queue_headredraw(curarea);
1112
1134
        ob= OBACT;
 
1135
        if(ob->id.lib) return;
1113
1136
        me= get_mesh(ob);
1114
1137
                
1115
1138
        if(me && me->totface>=MAXINDEX) {
1146
1169
        
1147
1170
        scrarea_queue_headredraw(curarea);
1148
1171
        ob= OBACT;
 
1172
        if(ob->id.lib) {
 
1173
                G.f &= ~G_VERTEXPAINT;
 
1174
                return;
 
1175
        }
 
1176
        
1149
1177
        me= get_mesh(ob);
1150
1178
        
1151
1179
        if(me && me->totface>=MAXINDEX) {