Revision: 20597
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20597
Author:   yukishiro
Date:     2009-06-03 06:55:07 +0200 (Wed, 03 Jun 2009)

Log Message:
-----------
light paint brush paints red

Modified Paths:
--------------
    
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h
    
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
    
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_utils.c
    
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
    
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_draw.c

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h  
    2009-06-03 04:12:59 UTC (rev 20596)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_intern.h  
    2009-06-03 04:55:07 UTC (rev 20597)
@@ -29,6 +29,8 @@
 #ifndef ED_PAINT_INTERN_H
 #define ED_PAINT_INTERN_H
 
+#define MAXINDEX       512000
+
 struct Scene;
 struct Object;
 struct Mesh;
@@ -64,6 +66,7 @@
 void imapaint_pick_uv(struct Scene *scene, struct Object *ob, struct Mesh 
*mesh, unsigned int faceindex, int *xy, float *uv);
 
 void paint_sample_color(struct Scene *scene, struct ARegion *ar, int x, int y);
+int sample_backbuf_area(struct ViewContext *vc, int *indexar, int totface, int 
x, int y, float size);
 
 #endif /* ED_PAINT_INTERN_H */
 

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
===================================================================
--- 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c   
    2009-06-03 04:12:59 UTC (rev 20596)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c   
    2009-06-03 04:55:07 UTC (rev 20597)
@@ -36,6 +36,8 @@
 
 #include "PIL_time.h"
 #include "BLI_threads.h"
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
 
 #include "DNA_brush_types.h"
 #include "DNA_lightenv_types.h"
@@ -76,9 +78,6 @@
 
 #include "paint_intern.h"
 
-#define MAXINDEX       512000
-
-
 typedef struct ShJob {
        Scene *scene;
         View3D *v3d;
@@ -203,11 +202,11 @@
 
 static VPaint *new_lpaint()
 {
-       VPaint *vp= MEM_callocN(sizeof(VPaint), "VPaint");
+       VPaint *lp= MEM_callocN(sizeof(VPaint), "VPaint");
        
-       vp->gamma= vp->mul= 1.0f;
-       vp->flag= VP_AREA+VP_SOFT+VP_SPRAY; //TODO: not sure how to use flag 
for light brush
-       return vp;
+       lp->gamma= lp->mul= 1.0f;
+       lp->flag= VP_AREA+VP_SOFT+VP_SPRAY; //TODO: not sure how to use flag 
for light brush
+       return lp;
 }
 
 static int light_paint_toggle_exec(bContext *C, wmOperator *op)
@@ -286,6 +285,7 @@
        unsigned int paintcol;
        int *indexar;
        //float *vertexcosnos;
+       float vpimat[3][3];
 } PaintOperation;
 
 static void lpaint_exit(bContext *C, wmOperator *op)
@@ -299,6 +299,9 @@
 
 static int light_paint_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
+       ToolSettings *ts= CTX_data_tool_settings(C);
+       VPaint *lp= ts->lpaint;
+       
        switch(event->type) {
                case LEFTMOUSE:
                        if(event->val==0) { /* release */
@@ -308,7 +311,47 @@
                        /* pass on, first press gets painted too */
                        
                case MOUSEMOVE: 
-                       break;
+                {
+                       PaintOperation *pop= op->customdata;
+                       ViewContext *vc= &pop->vc;
+                        Scene *scene= vc->scene;
+                       Object *ob= vc->obact;
+                       Mesh *me= ob->data;
+                       float mat[4][4];
+                       int *indexar= pop->indexar;
+                        int totindex, index;
+                        short mval[2];
+
+                       view3d_operator_needs_opengl(C);
+
+                       /* load projection matrix */
+                       wmMultMatrix(ob->obmat);
+                       wmGetSingleMatrix(mat);
+                       wmLoadMatrix(vc->rv3d->viewmat);
+
+                       mval[0]= event->x - vc->ar->winrct.xmin;
+                       mval[1]= event->y - vc->ar->winrct.ymin;
+
+                        totindex= sample_backbuf_area(vc, indexar, 
me->totface, mval[0], mval[1], lp->brush->size);
+                       
+                       for(index=0; index<totindex; index++) {
+                               if(indexar[index] && 
indexar[index]<=me->totface) {
+                                       MFace *mface= ((MFace *)me->mface) + 
(indexar[index]-1);
+                                        DerivedMesh *dm = 
mesh_get_derived_final(scene, ob, vc->v3d->customdata_mask);
+                                        unsigned char *shcol= 
DM_get_face_data_layer(dm, CD_SH_MCOL);
+                                        unsigned int *mcol= (unsigned 
int*)shcol + 4*(indexar[index]-1);
+
+                                        *mcol = pop->paintcol;
+                                        *(mcol+1) = pop->paintcol;
+                                        *(mcol+2) = pop->paintcol;
+                                       if(mface->v4) {
+                                                *(mcol+3) = pop->paintcol;
+                                        }
+                                }
+                        }
+                       ED_region_tag_redraw(vc->ar);
+                }
+               break;
         }
 
        return OPERATOR_RUNNING_MODAL;
@@ -316,16 +359,21 @@
 static int light_paint_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        PaintOperation *pop;
-       ToolSettings *ts= CTX_data_tool_settings(C);
-       VPaint *lp= ts->lpaint;
+       Object *ob= CTX_data_active_object(C);
+       float mat[4][4], imat[4][4];
 
-        printf("invoked\n");
        op->customdata= pop = MEM_callocN(sizeof(struct PaintOperation), 
"LightPOP");
        view3d_set_viewcontext(C, &pop->vc);
 
        pop->indexar= get_indexarray();
-       pop->paintcol= lpaint_get_current_col(lp);
+       //pop->paintcol= lpaint_get_current_col(lp);
+       pop->paintcol = rgba_to_mcol(200, 0, 0, 1.0f);
 
+       /* some old cruft to sort out later */
+       Mat4MulMat4(mat, ob->obmat, pop->vc.rv3d->viewmat);
+       Mat4Invert(imat, mat);
+       Mat3CpyMat4(pop->vpimat, imat);
+
        light_paint_modal(C, op, event);
 
        WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_utils.c   
    2009-06-03 04:12:59 UTC (rev 20596)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_utils.c   
    2009-06-03 04:55:07 UTC (rev 20597)
@@ -1,7 +1,17 @@
 
 #include <math.h>
 #include <stdlib.h>
+#include <string.h>
 
+#ifdef WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif   
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
@@ -20,6 +30,9 @@
 
 #include "ED_view3d.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
 #include "paint_intern.h"
 
 /* 3D Paint */
@@ -180,3 +193,40 @@
        }
 }
 
+int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x, int 
y, float size)
+{
+       ImBuf *ibuf;
+       int a, tot=0, index;
+       
+       if(totface+4>=MAXINDEX) return 0;
+       
+       if(size>64.0) size= 64.0;
+       
+       ibuf= view3d_read_backbuf(vc, x-size, y-size, x+size, y+size);
+       if(ibuf) {
+               unsigned int *rt= ibuf->rect;
+
+               memset(indexar, 0, sizeof(int)*totface+4);      /* plus 2! 
first element is total, +2 was giving valgrind errors, +4 seems ok */
+               
+               size= ibuf->x*ibuf->y;
+               while(size--) {
+                               
+                       if(*rt) {
+                               index= WM_framebuffer_to_index(*rt);
+                               if(index>0 && index<=totface)
+                                       indexar[index] = 1;
+                       }
+               
+                       rt++;
+               }
+               
+               for(a=1; a<=totface; a++) {
+                       if(indexar[a]) indexar[tot++]= a;
+               }
+
+               IMB_freeImBuf(ibuf);
+       }
+       
+       return tot;
+}
+

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_vertex.c  
    2009-06-03 04:12:59 UTC (rev 20596)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_vertex.c  
    2009-06-03 04:55:07 UTC (rev 20597)
@@ -28,14 +28,7 @@
  */
 
 #include <math.h>
-#include <string.h>
 
-#ifdef WIN32
-#include <io.h>
-#else
-#include <unistd.h>
-#endif   
-
 #include "MEM_guardedalloc.h"
 
 #include "IMB_imbuf.h"
@@ -78,9 +71,6 @@
 #include "BKE_object.h"
 #include "BKE_utildefines.h"
 
-#include "WM_api.h"
-#include "WM_types.h"
-
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
@@ -90,6 +80,11 @@
 #include "ED_util.h"
 #include "ED_view3d.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "paint_intern.h"
+
        /* vp->mode */
 #define VP_MIX 0
 #define VP_ADD 1
@@ -99,7 +94,6 @@
 #define VP_LIGHTEN     5
 #define VP_DARKEN      6
 
-#define MAXINDEX       512000
 
 /* XXX */
 static void error() {}
@@ -760,43 +754,6 @@
 }
 
 
-static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int 
x, int y, float size)
-{
-       struct ImBuf *ibuf;
-       int a, tot=0, index;
-       
-       if(totface+4>=MAXINDEX) return 0;
-       
-       if(size>64.0) size= 64.0;
-       
-       ibuf= view3d_read_backbuf(vc, x-size, y-size, x+size, y+size);
-       if(ibuf) {
-               unsigned int *rt= ibuf->rect;
-
-               memset(indexar, 0, sizeof(int)*totface+4);      /* plus 2! 
first element is total, +2 was giving valgrind errors, +4 seems ok */
-               
-               size= ibuf->x*ibuf->y;
-               while(size--) {
-                               
-                       if(*rt) {
-                               index= WM_framebuffer_to_index(*rt);
-                               if(index>0 && index<=totface)
-                                       indexar[index] = 1;
-                       }
-               
-                       rt++;
-               }
-               
-               for(a=1; a<=totface; a++) {
-                       if(indexar[a]) indexar[tot++]= a;
-               }
-
-               IMB_freeImBuf(ibuf);
-       }
-       
-       return tot;
-}
-
 static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], 
float *vert_nor, short *mval)
 {
        float fac, dx, dy;

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c    
    2009-06-03 04:12:59 UTC (rev 20596)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c    
    2009-06-03 04:55:07 UTC (rev 20597)
@@ -2293,7 +2293,7 @@
                 color[1] = mat->g;
                 color[2] = mat->b;
         } else {
-              color[0] = color[1] = color[2] = 0.8;
+                color[0] = color[1] = color[2] = 0.8;
         }
 
         brightness[0] = brightness[1] = brightness[2] = 0;
@@ -2323,10 +2323,10 @@
 
         for (i=0; i<totface; i++, mf++) {
                 calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 
+ 0) * 4]);
-                calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 
+ 1) * 4]);
-                calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 
+ 2) * 4]);
+                calc_sh_vert_color(ob, mf->v2, mco, env->shcoeffs, &shcol[(i*4 
+ 1) * 4]);
+                calc_sh_vert_color(ob, mf->v3, mco, env->shcoeffs, &shcol[(i*4 
+ 2) * 4]);
                 if (mf->v4)
-                        calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, 
&shcol[(i*4 + 3) * 4]);
+                        calc_sh_vert_color(ob, mf->v4, mco, env->shcoeffs, 
&shcol[(i*4 + 3) * 4]);
         }
 }
 

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/view3d_draw.c
===================================================================

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to