Copy GridPaintMask to vertex paint mask when applying multires.

Adds new subsurf_copy_grid_paint_mask() function similar to
subsurf_copy_grid_hidden().
This commit is contained in:
Nicholas Bishop
2012-05-10 20:34:23 +00:00
parent f4929ad609
commit 0f57b0f1e5
3 changed files with 57 additions and 1 deletions

View 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 */

View 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;

View 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);