Copy GridPaintMask to vertex paint mask when applying multires.
authorNicholas Bishop <nicholasbishop@gmail.com>
Thu, 10 May 2012 20:34:23 +0000 (20:34 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Thu, 10 May 2012 20:34:23 +0000 (20:34 +0000)
Adds new subsurf_copy_grid_paint_mask() function similar to
subsurf_copy_grid_hidden().

source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/modifiers/intern/MOD_multires.c

index 60a1e6ab68f1343511a47801b850c78cbeebdf58..9bb815c3e7d6ac46223459d4007317981c1429f5 100644 (file)
@@ -83,6 +83,10 @@ void subsurf_copy_grid_hidden(struct DerivedMesh *dm,
                                                          struct MVert *mvert,
                                                          const struct MDisps *mdisps);
 
+void subsurf_copy_grid_paint_mask(struct DerivedMesh *dm,
+                                                                 const struct MPoly *mpoly, float *paint_mask,
+                                                                 const struct GridPaintMask *grid_paint_mask);
+
 typedef enum MultiresModifiedFlags {
        /* indicates the grids have been sculpted on, so MDisps
         * have to be updated */
index c6b3a8d3aba1b5cbf98942a073a7f956587cb6f0..3d5bc6051c5e302f6e95cb1de36973f322b49fc9 100644 (file)
@@ -1047,6 +1047,45 @@ void subsurf_copy_grid_hidden(DerivedMesh *dm, const MPoly *mpoly,
        }
 }
 
+/* Translate GridPaintMask into vertex paint masks. Assumes vertices
+   are in the order output by ccgDM_copyFinalVertArray. */
+void subsurf_copy_grid_paint_mask(DerivedMesh *dm, const MPoly *mpoly,
+                                                                 float *paint_mask,
+                                                                 const GridPaintMask *grid_paint_mask)
+{
+       CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)dm;
+       CCGSubSurf *ss = ccgdm->ss;
+       int level = ccgSubSurf_getSubdivisionLevels(ss);
+       int gridSize = ccgSubSurf_getGridSize(ss);
+       int edgeSize = ccgSubSurf_getEdgeSize(ss);
+       int totface = ccgSubSurf_getNumFaces(ss);
+       int i, j, x, y, factor, gpm_gridsize;
+       
+       for(i = 0; i < totface; i++) {
+               CCGFace *f = ccgdm->faceMap[i].face;
+               const MPoly *p = &mpoly[i];
+               
+               for(j = 0; j < p->totloop; j++) {
+                       const GridPaintMask *gpm = &grid_paint_mask[p->loopstart + j];
+                       if(!gpm->data)
+                               continue;
+
+                       factor = ccg_factor(level, gpm->level);
+                       gpm_gridsize = ccg_gridsize(gpm->level);
+                       
+                       for(y = 0; y < gridSize; y++) {
+                               for(x = 0; x < gridSize; x++) {
+                                       int vndx, offset;
+                                       
+                                       vndx = getFaceIndex(ss, f, j, x, y, edgeSize, gridSize);
+                                       offset = y*factor * gpm_gridsize + x*factor;
+                                       paint_mask[vndx] = gpm->data[offset];
+                               }
+                       }
+               }
+       }
+}
+
 static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
index 13028953c1cf3ce22c89ca3789006ffa1e87c5b8..ae5ac9ac7188cd51b29c0ebcb0f4a15ae10eb3d3 100644 (file)
@@ -100,10 +100,14 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
                
                cddm = CDDM_copy(result);
 
-               /* copy hidden flag to vertices */
+               /* copy hidden/masks to vertices */
                if (!useRenderParams) {
                        struct MDisps *mdisps;
+                       struct GridPaintMask *grid_paint_mask;
+                       
                        mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
+                       grid_paint_mask = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK);
+                       
                        if (mdisps) {
                                subsurf_copy_grid_hidden(result, me->mpoly,
                                                         cddm->getVertArray(cddm),
@@ -116,6 +120,15 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
                                                                 cddm->getPolyArray(cddm),
                                                                 cddm->getNumPolys(cddm));
                        }
+                       if(grid_paint_mask) {
+                               float *paint_mask = CustomData_add_layer(&cddm->vertData,
+                                                                                                                CD_PAINT_MASK,
+                                                                                                                CD_CALLOC, NULL,
+                                                                                                                cddm->getNumVerts(cddm));
+
+                               subsurf_copy_grid_paint_mask(result, me->mpoly,
+                                                                                        paint_mask, grid_paint_mask);
+                       }
                }
 
                result->release(result);