Revision: 31182
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31182
Author:   nicholasbishop
Date:     2010-08-09 03:20:13 +0200 (Mon, 09 Aug 2010)

Log Message:
-----------
== Ptex ==

* Enabled drawing of ptex on a multires mesh
* Enabled ptex painting on a multires mesh

Note that the multires level doesn't effect the ptex resolution; multires has 
no effect on ptex other than making the display smoother.

Modified Paths:
--------------
    
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
    
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h
    branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c

Modified: 
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- 
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c  
    2010-08-08 23:46:49 UTC (rev 31181)
+++ 
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c  
    2010-08-09 01:20:13 UTC (rev 31182)
@@ -2490,17 +2490,24 @@
           we build a pbvh over the modified mesh, in other cases the base mesh
           is being sculpted, so we build a pbvh from that. */
        if(grid_pbvh) {
+               int leaf_limit = PBVH_DEFAULT_LEAF_LIMIT;
+
+               /* TODO: set leaf limit more intelligently */
+               if(ob->mode & OB_MODE_VERTEX_PAINT)
+                       leaf_limit = 1;
+
                ccgdm_create_grids(dm);
 
                gridSize = ccgDM_getGridSize(dm);
                numGrids = ccgDM_getNumGrids(dm);
                gridkey = ccgDM_getGridKey(dm);
 
-               ob->paint->pbvh= ccgdm->pbvh = 
BLI_pbvh_new(PBVH_DEFAULT_LEAF_LIMIT);
+               ob->paint->pbvh= ccgdm->pbvh = BLI_pbvh_new(leaf_limit);
                BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, 
ccgdm->gridAdjacency,
                                     numGrids, gridSize, gridkey, 
(void**)ccgdm->gridFaces,
                                     &me->vdata, &me->fdata,
-                                    ss ? &ss->hidden_areas : NULL);
+                                    ss ? &ss->hidden_areas : NULL,
+                                    me->mface, me->totface);
                ccgdm->pbvh_draw = 1;
        }
        else if(ob->type == OB_MESH) {

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h   
2010-08-08 23:46:49 UTC (rev 31181)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h   
2010-08-09 01:20:13 UTC (rev 31182)
@@ -51,6 +51,11 @@
        float (*co)[3];
 } PBVHProxyNode;
 
+typedef struct {
+       int face;
+       char offset;
+} GridToFace;
+
 /* Callbacks */
 
 /* returns 1 if the search should continue from this node, 0 otherwise */
@@ -77,7 +82,7 @@
                          struct DMGridAdjacency *gridadj, int totgrid,
                          int gridsize, struct GridKey *gridkey, void 
**gridfaces,
                          struct CustomData *vdata, struct CustomData *fdata,
-                         ListBase *hidden_areas);
+                         ListBase *hidden_areas, struct MFace *mface, int 
totface);
 void BLI_pbvh_free(PBVH *bvh);
 
 /* Hierarchical Search in the BVH, two methods:
@@ -143,6 +148,7 @@
 int BLI_pbvh_uses_grids(PBVH *bvh);
 
 void BLI_pbvh_get_customdata(PBVH *pbvh, struct CustomData **vdata, struct 
CustomData **fdata);
+GridToFace *BLI_pbvh_get_grid_face_map(PBVH *pbvh);
 
 void BLI_pbvh_node_get_faces(PBVH *bvh, PBVHNode *node,
                             struct MFace **faces,
@@ -150,7 +156,8 @@
                             int *totface);
 void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node,
        int **grid_indices, int *totgrid, int *maxgrid, int *gridsize,
-       struct DMGridData ***griddata, struct DMGridAdjacency **gridadj, struct 
GridKey **gridkey);
+       struct DMGridData ***griddata, struct DMGridAdjacency **gridadj,
+       struct GridKey **gridkey);
 void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node,
        int *uniquevert, int *totvert);
 void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node,

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c        
2010-08-08 23:46:49 UTC (rev 31181)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c        
2010-08-09 01:20:13 UTC (rev 31182)
@@ -122,6 +122,7 @@
        int totgrid;
        int gridsize;
        struct GridKey *gridkey;
+       GridToFace *grid_face_map;
 
        /* Used by both mesh and grid type */
        CustomData *vdata;
@@ -673,12 +674,32 @@
                pbvh_begin_build(bvh, totface, hidden_areas);
 }
 
+static GridToFace *pbvh_build_grid_face_map(MFace *mface, int totface, int 
totgrid)
+{
+       GridToFace *map, *gtf;
+       int i, j;
+
+       map = MEM_callocN(sizeof(GridToFace) * totgrid, "PBVH.grid_face_map");
+
+       for(i = 0, gtf = map; i < totface; ++i) {
+               int S = mface[i].v4 ? 4 : 3;
+
+               for(j = 0; j < S; ++j, ++gtf) {
+                       gtf->face = i;
+                       gtf->offset = j;
+               }
+       }
+
+       return map;
+}
+
 /* Do a full rebuild with on Grids data structure */
 void BLI_pbvh_build_grids(PBVH *bvh, DMGridData **grids,
                          DMGridAdjacency *gridadj,
                          int totgrid, int gridsize, GridKey *gridkey,
                          void **gridfaces, CustomData *vdata,
-                         CustomData *fdata, ListBase *hidden_areas)
+                         CustomData *fdata, ListBase *hidden_areas,
+                         MFace *mface, int totface)
 {
        bvh->grids= grids;
        bvh->gridadj= gridadj;
@@ -688,7 +709,8 @@
        bvh->gridkey= gridkey;
        bvh->vdata= vdata;
        bvh->fdata= fdata;
-       bvh->leaf_limit = 
MAX2(PBVH_DEFAULT_LEAF_LIMIT/((gridsize-1)*(gridsize-1)), 1);
+       bvh->leaf_limit = MAX2(bvh->leaf_limit/((gridsize-1)*(gridsize-1)), 1);
+       bvh->grid_face_map = pbvh_build_grid_face_map(mface, totface, totgrid);
 
        if(totgrid)
                pbvh_begin_build(bvh, totgrid, hidden_areas);
@@ -737,6 +759,9 @@
 {
        pbvh_free_nodes(bvh);
 
+       if(bvh->grid_face_map)
+               MEM_freeN(bvh->grid_face_map);
+
        MEM_freeN(bvh->prim_indices);
        MEM_freeN(bvh);
 }
@@ -1168,14 +1193,18 @@
                
                if(node->flag & PBVH_UpdateColorBuffers) {
                        if(bvh->grids) {
-                               
GPU_update_grid_color_buffers(node->draw_buffers,
-                                                             bvh->grids,
-                                                             
node->prim_indices,
-                                                             node->totprim,
-                                                             bvh->gridsize,
-                                                             bvh->gridkey,
-                                                             bvh->vdata,
-                                                             flags);
+                               if(flags & GPU_DRAW_ACTIVE_MCOL)
+                                       
GPU_update_grids_ptex(node->draw_buffers, bvh, node);
+                               else {
+                                       
GPU_update_grid_color_buffers(node->draw_buffers,
+                                                                     
bvh->grids,
+                                                                     
node->prim_indices,
+                                                                     
node->totprim,
+                                                                     
bvh->gridsize,
+                                                                     
bvh->gridkey,
+                                                                     
bvh->vdata,
+                                                                     flags);
+                               }
                        }
                        else {
                                if(flags & GPU_DRAW_ACTIVE_MCOL)
@@ -1329,7 +1358,12 @@
        if(fdata) *fdata = bvh->fdata;
 }
 
+GridToFace *BLI_pbvh_get_grid_face_map(PBVH *pbvh)
+{
+       return pbvh->grid_face_map;
+}
 
+
 /***************************** Node Access ***********************************/
 
 void BLI_pbvh_node_mark_update(PBVHNode *node)

Modified: 
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- 
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
  2010-08-08 23:46:49 UTC (rev 31181)
+++ 
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
  2010-08-09 01:20:13 UTC (rev 31182)
@@ -1696,7 +1696,7 @@
 }
 
 static void vpaint_ptex_from_quad(Brush *brush, PaintStroke *stroke, 
PaintStrokeTest *test,
-                                 MPtex *pt, int res[2], char *data,
+                                 MPtex *pt, int res[2], int rowlen, char *data,
                                  float v1[3], float v2[3], float v3[3], float 
v4[3])
                                  
 {
@@ -1706,8 +1706,8 @@
 
        layersize = pt->channels * ptex_data_size(pt->type);
 
-       sub_v3_v3v3(dtop, v1, v2);
-       sub_v3_v3v3(dbot, v4, v3);;
+       sub_v3_v3v3(dtop, v3, v4);
+       sub_v3_v3v3(dbot, v2, v1);;
        ustep = 1;
        if(res[0] != 1)
                ustep /= (res[0] - 1);
@@ -1719,10 +1719,10 @@
                vstep /= (res[1] - 1);
 
        for(v = 0, yinterp = 0; v < res[1]; ++v) {
-               copy_v3_v3(co_top, v2);
-               copy_v3_v3(co_bot, v3);
+               copy_v3_v3(co_top, v4);
+               copy_v3_v3(co_bot, v1);
 
-               for(u = 0; u < res[0]; ++u, data += layersize) {
+               for(u = 0; u < res[0]; ++u) {
                        float co[3];
 
                        interp_v3_v3v3(co, co_bot, co_top, yinterp);
@@ -1730,13 +1730,14 @@
                        if(paint_stroke_test(test, co)) {
                                float strength;
                                float fcol[4];
+                               char *elem = data + layersize*(v*rowlen + u);
                                        
                                strength = brush->alpha *
                                        paint_stroke_combined_strength(stroke, 
test->dist, co, 0);
                                
-                               ptex_elem_to_float4(pt->type, pt->channels, 
data, fcol);
+                               ptex_elem_to_float4(pt->type, pt->channels, 
elem, fcol);
                                vpaint_blend(brush, stroke, fcol, strength, co);
-                               ptex_elem_from_float4(pt->type, pt->channels, 
data, fcol);
+                               ptex_elem_from_float4(pt->type, pt->channels, 
elem, fcol);
                        }
 
                        add_v3_v3(co_bot, dbot);
@@ -1747,13 +1748,131 @@
        }
 }
 
-static void vpaint_nodes_faces(Brush *brush, PaintStroke *stroke,
-                              MFace *mface, MVert *mvert,
-                              CustomData *vdata, CustomData *fdata,
-                              int *face_indices, int totface)
+static void vpaint_node_grids(Brush *brush, PaintStroke *stroke,
+                             DMGridData **grids, GridKey *gridkey,
+                             GridToFace *grid_face_map,
+                             CustomData *fdata,
+                             int *grid_indices,
+                             int totgrid, int gridsize)
 {
        PaintStrokeTest test;
        MPtex *mptex;
+       int i, j;
+
+       mptex = CustomData_get_layer(fdata, CD_MPTEX);
+
+       paint_stroke_test_init(&test, stroke);
+
+       for(i = 0; i < totgrid; ++i) {
+               int g = grid_indices[i];
+               DMGridData *grid = grids[g];
+               GridToFace *gtf = &grid_face_map[g];
+               MPtex *pt = &mptex[gtf->face];
+               char *data = pt->data;
+               int layersize;
+               int ures, vres, res[2], rowlen;
+               int x, y, u, v, ustep, vstep, rot = 0;
+               int xstep, ystep, xstart, ystart, inverse;
+
+               layersize = pt->channels * ptex_data_size(pt->type);
+
+               if(pt->subfaces == 1) {
+                       ures = pt->res[0][0] / 2;
+                       vres = pt->res[0][1] / 2;
+                       rowlen = pt->res[0][0];
+
+                       if(gtf->offset == 1)
+                               data += layersize * ures;
+                       else if(gtf->offset == 3)
+                               data += layersize * vres * rowlen;
+                       else if(gtf->offset == 2)
+                               data += layersize * (vres * rowlen + ures);
+
+                       rot = gtf->offset;
+               }
+               else {
+                       ures = pt->res[gtf->offset][0];
+                       vres = pt->res[gtf->offset][1];
+                       rowlen = pt->res[gtf->offset][0];
+
+                       for(j = 0; j < gtf->offset; ++j)
+                               data += layersize * pt->res[j][0] * 
pt->res[j][1];
+               }
+
+               ustep = MAX2(ures / (gridsize - 1), 1);
+               vstep = MAX2(vres / (gridsize - 1), 1);
+               res[0] = ustep, res[1] = vstep;
+               
+               /* step through the grid in different directions based on
+                  grid rotation relative to the ptex */
+               switch(rot) {
+               case 0:
+                       xstep = -1;
+                       ystep = -1;
+                       inverse = 1;
+                       break;
+               case 1:
+                       xstep = 1;
+                       ystep = -1;
+                       inverse = 0;
+                       break;
+               case 2:
+                       xstep = 1;
+                       ystep = 1;
+                       inverse = 1;
+                       break;
+               case 3:
+                       xstep = -1;
+                       ystep = 1;
+                       inverse = 0;
+                       break;
+               }
+
+               if(xstep == 1)
+                       xstart = 0;
+               else
+                       xstart = gridsize - 1;
+               if(ystep == 1)
+                       ystart = 0;
+               else
+                       ystart = gridsize - 1;
+
+               for(v = 0, y = ystart; v < vres; v += vstep, y += ystep) {
+                       for(u = 0, x = xstart; u < ures; u += ustep, x += 
xstep) {
+                               int r = y, c = x, rstep = ystep, cstep = xstep;
+
+                               if(inverse) {
+                                       SWAP(int, r, c);
+                                       SWAP(int, rstep, cstep);
+                               }
+
+                               float *co[4] = {

@@ 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