Revision: 39124
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39124
Author:   jwilkins
Date:     2011-08-07 10:18:22 +0000 (Sun, 07 Aug 2011)
Log Message:
-----------
Revision: 30825
Author: nicholasbishop
Date: 1:38:24 AM, Wednesday, July 28, 2010
Message:
== VPaint ==

* Blur brush works for multires now

----
Modified : 
/branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
Modified : /branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
Modified : /branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
Modified : 
/branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c

--
jwilkins:
vpaint currently does not work with multires right now due to some regression 
caused by the refactoring, but I'm going to push on and fix any problems with 
this after I figure out what is causing vpaint and multires not to work 
together.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
    branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c 
2011-08-07 09:13:37 UTC (rev 39123)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c 
2011-08-07 10:18:22 UTC (rev 39124)
@@ -1132,8 +1132,15 @@
 
 void multires_stitch_grids(Object *ob)
 {
-       /* utility for smooth brush */
-       if(ob && ob->derivedFinal) {
+       DerivedMesh *dm;
+
+       if(!ob)
+               return;
+
+       dm = ob->derivedFinal;
+
+       /* utility for smooth/blur brushes */
+       if(dm && dm->type == DM_TYPE_CCGDM) {
                CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)ob->derivedFinal;
                CCGFace **faces;
                int totface;
@@ -1142,6 +1149,7 @@
                        BLI_pbvh_get_grid_updates(ccgdm->pbvh, 0, 
(void***)&faces, &totface);
 
                        if(totface) {
+                               /* TODO: could improve performance by limiting 
to e.g. just coords or just colors */
                                ccgSubSurf_stitchFaces(ccgdm->ss, 0, faces, 
totface);
                                MEM_freeN(faces);
                        }

Modified: branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h   2011-08-07 
09:13:37 UTC (rev 39123)
+++ branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h   2011-08-07 
10:18:22 UTC (rev 39124)
@@ -140,7 +140,9 @@
                         PBVH_UpdateOriginalBB |
                         PBVH_UpdateVertBuffers |
                         PBVH_UpdateColorBuffers |
-                        PBVH_UpdateRedraw
+                        PBVH_UpdateRedraw,
+
+       PBVH_NeedsColorStitch = 128
 } PBVHNodeFlags;
 
 void BLI_pbvh_node_mark_update(PBVHNode *node);

Modified: branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c        
2011-08-07 09:13:37 UTC (rev 39123)
+++ branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c        
2011-08-07 10:18:22 UTC (rev 39124)
@@ -1293,7 +1293,7 @@
        pbvh_iter_begin(&iter, bvh, NULL, NULL);
 
        while((node=pbvh_iter_next(&iter))) {
-               if(node->flag & PBVH_UpdateNormals) {
+               if(node->flag & (PBVH_UpdateNormals|PBVH_NeedsColorStitch)) {
                        for(i = 0; i < node->totprim; ++i) {
                                face= bvh->gridfaces[node->prim_indices[i]];
                                if(!BLI_ghash_lookup(map, face))
@@ -1302,6 +1302,8 @@
 
                        if(clear)
                                node->flag &= ~PBVH_UpdateNormals;
+
+                       node->flag &= ~PBVH_NeedsColorStitch;
                }
        }
 

Modified: 
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c  
2011-08-07 09:13:37 UTC (rev 39123)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c  
2011-08-07 10:18:22 UTC (rev 39124)
@@ -22,7 +22,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s):  Nicholas Bishop, Jason Wilkins
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -1800,6 +1800,91 @@
        }
 }
 
+static void vpaint_nodes_grids_smooth(
+       struct Brush *brush,
+       struct BrushSpace *bspace,
+       struct PaintStroke *stroke,
+       struct DMGridData **grids,
+       struct CustomData *vdata,
+       struct GridKey *gridkey,
+       int *grid_indices,
+       int totgrid,
+       int gridsize,
+       int active,
+       float center[3],
+       float radius,
+       float radius_squared)
+{
+       int i, j, x, y, x2, y2;
+
+       /* TODO: this could be better optimized like sculpt,
+          just doing the simplest smooth for now */
+
+       for(i = 0; i < totgrid; ++i) {
+               DMGridData *grid = grids[grid_indices[i]], *act_elem, *elem;
+
+               for(y = 0; y < gridsize; ++y) {
+                       for(x = 0; x < gridsize; ++x) {
+                               float avg_col[4] = {0, 0, 0, 0};
+                               float *act_col, strength, mask;
+                               float *co, dist_squared, dist;
+                               int totcol = 0;
+
+                               act_elem = GRIDELEM_AT(grid, y*gridsize + x, 
gridkey);
+
+                               co = GRIDELEM_CO(act_elem, gridkey);
+                               dist_squared = len_squared_v3v3(center, co);
+
+                               if(dist_squared > radius_squared)
+                                       continue;
+
+                               dist = sqrtf(dist_squared);
+
+                               for(y2 = -1; y2 <= 1; y2+=2) {
+                                       if(y + y2 < 0 || y + y2 >= gridsize)
+                                               continue;
+
+                                       for(x2 = -1; x2 <= 1; x2+=2) {
+                                               if(x + x2 < 0 || x + x2 >= 
gridsize)
+                                                       continue;
+
+                                               elem = GRIDELEM_AT(grid, 
(y+y2)*gridsize + (x+x2), gridkey);
+
+                                               ++totcol;
+                                               for(j = 0; j < 4; ++j)
+                                                       avg_col[j] += 
GRIDELEM_COLOR(elem, gridkey)[active][j];
+                                       }
+                               }
+
+                               mask= paint_mask_from_gridelem(
+                                       act_elem,
+                                       gridkey,
+                                       vdata);
+
+                               strength=
+                                       brush->alpha *
+                                       tex_strength(
+                                               brush,
+                                               bspace,
+                                               stroke,
+                                               co,
+                                               mask,
+                                               dist,
+                                               radius);
+
+                               act_col= GRIDELEM_COLOR(act_elem, 
gridkey)[active];
+
+                               for(j = 0; j < 4; ++j) {
+                                       act_col[j]=
+                                               interpf(avg_col[j] / totcol, 
act_col[j], strength);
+                               }
+                       }
+               }
+       }
+
+       /* be sure to stitch grids after */
+}
+
 static void vpaint_nodes_faces_smooth(
        struct Brush *brush,
        struct BrushSpace *bspace,
@@ -1920,6 +2005,7 @@
 {
        PBVH *pbvh = ob->paint->pbvh;
        Brush *brush = paint_brush(&vp->paint);
+       int blur = brush->vertexpaint_tool == VERTEX_PAINT_TOOL_BLUR;
        int n;
 
        for(n = 0; n < totnode; ++n) {
@@ -1962,22 +2048,43 @@
                        int active= vpaint_find_gridkey_active_layer(fdata, 
gridkey);
 
                        if(active != -1) {
-                               vpaint_nodes_grids(
-                                       brush,
-                                       bspace,
-                                       stroke,
-                                       grids,
-                                       vdata,
-                                       gridkey,
-                                       grid_indices,
-                                       totgrid,
-                                       gridsize,
-                                       active,
-                                       center,
-                                       radius);
+                               if(blur) {
+                                       vpaint_nodes_grids_smooth(
+                                               brush,
+                                               bspace,
+                                               stroke,
+                                               grids,
+                                               vdata,
+                                               gridkey,
+                                               grid_indices,
+                                               totgrid,
+                                               gridsize,
+                                               active,
+                                               center,
+                                               radius,
+                                               radius*radius);
+
+                                       BLI_pbvh_node_set_flags(nodes[n],
+                                                               
SET_INT_IN_POINTER(PBVH_NeedsColorStitch));
+                               }
+                               else {
+                                       vpaint_nodes_grids(
+                                               brush,
+                                               bspace,
+                                               stroke,
+                                               grids,
+                                               vdata,
+                                               gridkey,
+                                               grid_indices,
+                                               totgrid,
+                                               gridsize,
+                                               active,
+                                               center,
+                                               radius);
+                               }
                        }
                }
-               else if (brush->vertexpaint_tool == VERTEX_PAINT_TOOL_BLUR) {
+               else if (blur) {
                        dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
                        fmap= dm->getFaceMap ? dm->getFaceMap(ob, dm) : NULL;
 
@@ -2018,7 +2125,7 @@
 typedef struct {
        int hit_index;
        int grid_hit_index;
-       PBVHNode *node;
+       struct PBVHNode *node;
 } VPaintColorOneFaceHitData;
 
 void vpaint_color_one_face_raycast_cb(PBVHNode *node, PaintRaycastData 
*hit_data, float* tmin)
@@ -2155,7 +2262,8 @@
 static void vpaint_stroke_update_step(const bContext *C, struct PaintStroke 
*stroke)
 {
        struct Object *ob= CTX_data_active_object(C);
-       Brush *brush= paint_brush(&(CTX_data_tool_settings(C)->vpaint->paint));
+       struct VPaint *vp= CTX_data_tool_settings(C)->vpaint;
+       Brush *brush= paint_brush(&(vp->paint));
 
        /* first step is handled by paint_bspace_init */
        if (!paint_stroke_first_step(stroke)) {
@@ -2174,6 +2282,9 @@
 
                paint_stroke_apply(C, stroke);
 
+               if(paint_brush(&vp->paint)->vertexpaint_tool == 
VERTEX_PAINT_TOOL_BLUR)
+                       multires_stitch_grids(ob);
+
                multires_mark_as_modified(ob);
 
                /* XXX

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

Reply via email to