diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_subsurf.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 39 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_multires.c | 15 |
3 files changed, 57 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index 60a1e6ab68f..9bb815c3e7d 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -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 */ diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index c6b3a8d3aba..3d5bc6051c5 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -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; diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c index 13028953c1c..ae5ac9ac718 100644 --- a/source/blender/modifiers/intern/MOD_multires.c +++ b/source/blender/modifiers/intern/MOD_multires.c @@ -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); |