brought weight paint back.

This commit is contained in:
Joseph Eagar 2009-08-31 15:57:13 +00:00
parent 63051a87a3
commit 9a5ffc8c38
8 changed files with 120 additions and 83 deletions

@ -1784,23 +1784,45 @@ void vDM_ColorBand_store(ColorBand *coba)
static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm) static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm)
{ {
Mesh *me = ob->data; Mesh *me = ob->data;
MFace *mf = me->mface; MFace *mf = dm->getTessFaceArray(dm);
DMFaceIter *dfiter;
DMLoopIter *dliter;
ColorBand *coba= stored_cb; /* warning, not a local var */ ColorBand *coba= stored_cb; /* warning, not a local var */
unsigned char *wtcol; unsigned char *wtcol;
int i; unsigned char(*wlcol)[4] = NULL;
V_DECLARE(wlcol);
int i, totface=dm->getNumTessFaces(dm), totpoly=dm->getNumFaces, totloop;
int *origIndex = dm->getVertDataArray(dm, CD_ORIGINDEX);
wtcol = MEM_callocN (sizeof (unsigned char) * me->totface*4*4, "weightmap"); wtcol = MEM_callocN (sizeof (unsigned char) * totface*4*4, "weightmap");
memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4); /*first add colors to the tesselation faces*/
for (i=0; i<me->totface; i++, mf++) { memset(wtcol, 0x55, sizeof (unsigned char) * totface*4*4);
calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4]); for (i=0; i<totface; i++, mf++) {
calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4]); if (origIndex[mf->v1] != ORIGINDEX_NONE)
calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4]); calc_weightpaint_vert_color(ob, coba, origIndex[mf->v1], &wtcol[(i*4 + 0)*4]);
if (mf->v4) if (origIndex[mf->v2] != ORIGINDEX_NONE)
calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4]); calc_weightpaint_vert_color(ob, coba, origIndex[mf->v2], &wtcol[(i*4 + 1)*4]);
if (origIndex[mf->v3] != ORIGINDEX_NONE)
calc_weightpaint_vert_color(ob, coba, origIndex[mf->v3], &wtcol[(i*4 + 2)*4]);
if (mf->v4 && origIndex[mf->v4] != ORIGINDEX_NONE)
calc_weightpaint_vert_color(ob, coba, origIndex[mf->v4], &wtcol[(i*4 + 3)*4]);
} }
CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData); CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, totface);
/*now add to loops, so the data can be passed through the modifier stack*/
totloop = 0;
dfiter = dm->newFaceIter(dm);
for (; !dfiter->done; dfiter->step(dfiter)) {
dliter = dfiter->getLoopsIter(dfiter);
for (; !dliter->done; dliter->step(dliter), totloop++) {
V_GROW(wlcol);
calc_weightpaint_vert_color(ob, coba, origIndex[dliter->vindex], &wlcol[totloop]);
}
}
CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_ASSIGN, wlcol, totloop);
} }
/* new value for useDeform -1 (hack for the gameengine): /* new value for useDeform -1 (hack for the gameengine):

@ -1089,7 +1089,6 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
int cdindex, BMLoop *l3[3], int cdindex, BMLoop *l3[3],
int numCol, int numTex) int numCol, int numTex)
{ {
int i, j;
BMLoop *l; BMLoop *l;
BMFace *f = l3[0]->f; BMFace *f = l3[0]->f;
MTFace *texface; MTFace *texface;
@ -1097,6 +1096,7 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
MCol *mcol; MCol *mcol;
MLoopCol *mloopcol; MLoopCol *mloopcol;
MLoopUV *mloopuv; MLoopUV *mloopuv;
int i, j, hasWCol = CustomData_has_layer(&bm->ldata, CD_WEIGHT_MLOOPCOL);
for(i=0; i < numTex; i++){ for(i=0; i < numTex; i++){
texface = CustomData_get_n(facedata, CD_MTFACE, cdindex, i); texface = CustomData_get_n(facedata, CD_MTFACE, cdindex, i);
@ -1129,6 +1129,19 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
mcol[j].a = mloopcol->a; mcol[j].a = mloopcol->a;
} }
} }
if (hasWCol) {
mcol = CustomData_get(facedata, cdindex, CD_WEIGHT_MCOL);
for (j=0; j<3; j++) {
l = l3[j];
mloopcol = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_WEIGHT_MLOOPCOL);
mcol[j].r = mloopcol->r;
mcol[j].g = mloopcol->g;
mcol[j].b = mloopcol->b;
mcol[j].a = mloopcol->a;
}
}
} }
DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me) DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
@ -1166,14 +1179,8 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
CustomData_merge(&em->bm->pdata, &dm->polyData, CD_MASK_DERIVEDMESH, CustomData_merge(&em->bm->pdata, &dm->polyData, CD_MASK_DERIVEDMESH,
CD_CALLOC, dm->numPolyData); CD_CALLOC, dm->numPolyData);
/*add tesselation mface and mcol layers as necassary*/ /*add tesselation mface layers*/
for (i=0; i<numTex; i++) { CustomData_from_bmeshpoly(&dm->faceData, &dm->polyData, &dm->loopData, em->tottri);
CustomData_add_layer(&dm->faceData, CD_MTFACE, CD_CALLOC, NULL, em->tottri);
}
for (i=0; i<numCol; i++) {
CustomData_add_layer(&dm->faceData, CD_MCOL, CD_CALLOC, NULL, em->tottri);
}
/* set vert index */ /* set vert index */
eve = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL); eve = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);

@ -867,6 +867,9 @@ const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerSwap_mcol, layerDefault_mcol}, layerSwap_mcol, layerDefault_mcol},
{sizeof(MPoly), "MPoly", 1, "NGon Face", NULL, NULL, NULL, NULL, NULL}, {sizeof(MPoly), "MPoly", 1, "NGon Face", NULL, NULL, NULL, NULL, NULL},
{sizeof(MLoop), "MLoop", 1, "NGon Face-Vertex", NULL, NULL, NULL, NULL, NULL}, {sizeof(MLoop), "MLoop", 1, "NGon Face-Vertex", NULL, NULL, NULL, NULL, NULL},
{sizeof(MLoopCol), "MLoopCol", 1, "WeightLoopCol", NULL, NULL, layerInterp_mloopcol, NULL,
layerDefault_mloopcol, layerEqual_mloopcol, layerMultiply_mloopcol, layerInitMinMax_mloopcol,
layerAdd_mloopcol, layerDoMinMax_mloopcol, layerCopyValue_mloopcol},
}; };
const char *LAYERTYPENAMES[CD_NUMTYPES] = { const char *LAYERTYPENAMES[CD_NUMTYPES] = {
@ -890,7 +893,7 @@ const CustomDataMask CD_MASK_EDITMESH =
const CustomDataMask CD_MASK_DERIVEDMESH = const CustomDataMask CD_MASK_DERIVEDMESH =
CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE |
CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT |
CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_WEIGHT_MLOOPCOL |
CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT | CD_MASK_WEIGHT_MCOL; CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT | CD_MASK_WEIGHT_MCOL;
const CustomDataMask CD_MASK_BMESH = CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | const CustomDataMask CD_MASK_BMESH = CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR; CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR;
@ -2003,6 +2006,8 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
for(i=0; i < ldata->totlayer; i++){ for(i=0; i < ldata->totlayer; i++){
if(ldata->layers[i].type == CD_MLOOPCOL) if(ldata->layers[i].type == CD_MLOOPCOL)
CustomData_add_layer(fdata, CD_MCOL, CD_CALLOC, &(ldata->layers[i].name), total); CustomData_add_layer(fdata, CD_MCOL, CD_CALLOC, &(ldata->layers[i].name), total);
if (ldata->layers[i].type == CD_WEIGHT_MLOOPCOL)
CustomData_add_layer(fdata, CD_WEIGHT_MCOL, CD_CALLOC, &(ldata->layers[i].name), total);
} }
} }

@ -1409,7 +1409,7 @@ static void mesh_loops_to_corners(CustomData *fdata, CustomData *ldata,
MCol *mcol; MCol *mcol;
MLoopCol *mloopcol; MLoopCol *mloopcol;
MLoopUV *mloopuv; MLoopUV *mloopuv;
int i, j; int i, j, hasWCol = CustomData_has_layer(ldata, CD_WEIGHT_MLOOPCOL);
for(i=0; i < numTex; i++){ for(i=0; i < numTex; i++){
texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
@ -1440,6 +1440,18 @@ static void mesh_loops_to_corners(CustomData *fdata, CustomData *ldata,
mcol[j].a = mloopcol->a; mcol[j].a = mloopcol->a;
} }
} }
if (hasWCol) {
mcol = CustomData_get(fdata, findex, CD_WEIGHT_MCOL);
for (j=0; j<3; j++) {
mloopcol = CustomData_get(ldata, lindex[j], CD_WEIGHT_MLOOPCOL);
mcol[j].r = mloopcol->r;
mcol[j].g = mloopcol->g;
mcol[j].b = mloopcol->b;
mcol[j].a = mloopcol->a;
}
}
} }
/*this function recreates a tesselation. /*this function recreates a tesselation.

@ -133,10 +133,10 @@ BMEditMesh *CDDM_To_BMesh(DerivedMesh *dm, BMEditMesh *existing)
bmold = *bm; bmold = *bm;
/*merge custom data layout*/ /*merge custom data layout*/
CustomData_bmesh_merge(&dm->vertData, &bm->vdata, CD_MASK_BMESH|CD_MASK_ORIGINDEX, CD_CALLOC, bm, BM_VERT); CustomData_bmesh_merge(&dm->vertData, &bm->vdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_VERT);
CustomData_bmesh_merge(&dm->edgeData, &bm->edata, CD_MASK_BMESH|CD_MASK_ORIGINDEX, CD_CALLOC, bm, BM_EDGE); CustomData_bmesh_merge(&dm->edgeData, &bm->edata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_EDGE);
CustomData_bmesh_merge(&dm->loopData, &bm->ldata, CD_MASK_BMESH|CD_MASK_ORIGINDEX, CD_CALLOC, bm, BM_LOOP); CustomData_bmesh_merge(&dm->loopData, &bm->ldata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_LOOP);
CustomData_bmesh_merge(&dm->polyData, &bm->pdata, CD_MASK_BMESH|CD_MASK_ORIGINDEX, CD_CALLOC, bm, BM_FACE); CustomData_bmesh_merge(&dm->polyData, &bm->pdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_FACE);
/*needed later*/ /*needed later*/
numTex = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY); numTex = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);

@ -2561,7 +2561,7 @@ void ccg_loops_to_corners(CustomData *fdata, CustomData *ldata,
MCol *mcol; MCol *mcol;
MLoopCol *mloopcol; MLoopCol *mloopcol;
MLoopUV *mloopuv; MLoopUV *mloopuv;
int i, j; int i, j, hasWCol = CustomData_has_layer(ldata, CD_WEIGHT_MLOOPCOL);
for(i=0; i < numTex; i++){ for(i=0; i < numTex; i++){
texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
@ -2592,6 +2592,18 @@ void ccg_loops_to_corners(CustomData *fdata, CustomData *ldata,
mcol[j].a = mloopcol->a; mcol[j].a = mloopcol->a;
} }
} }
if (hasWCol) {
mloopcol = CustomData_get(ldata, loopstart, CD_WEIGHT_MLOOPCOL);
mcol = CustomData_get(fdata, findex, CD_WEIGHT_MCOL);
for (j=0; j<4; j++, mloopcol++) {
mcol[j].r = mloopcol->r;
mcol[j].g = mloopcol->g;
mcol[j].b = mloopcol->b;
mcol[j].a = mloopcol->a;
}
}
} }
/*this function requires dm to be a CDDM*/ /*this function requires dm to be a CDDM*/

@ -1380,22 +1380,22 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
if(wp->flag & VP_COLINDEX) { if(wp->flag & VP_COLINDEX) {
for(index=0; index<totindex; index++) { for(index=0; index<totindex; index++) {
if(indexar[index] && indexar[index]<=me->totface) { if(indexar[index] && indexar[index]<=me->totpoly) {
MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); MPoly *mpoly= ((MPoly *)me->mpoly) + (indexar[index]-1);
if(mface->mat_nr!=ob->actcol-1) { if(mpoly->mat_nr!=ob->actcol-1) {
indexar[index]= 0; indexar[index]= 0;
} }
} }
} }
} }
if((G.f & G_FACESELECT) && me->mface) { if((G.f & G_FACESELECT) && me->mpoly) {
for(index=0; index<totindex; index++) { for(index=0; index<totindex; index++) {
if(indexar[index] && indexar[index]<=me->totface) { if(indexar[index] && indexar[index]<=me->totpoly) {
MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); MPoly *mpoly= ((MPoly *)me->mpoly) + (indexar[index]-1);
if((mface->flag & ME_FACE_SEL)==0) { if((mpoly->flag & ME_FACE_SEL)==0) {
indexar[index]= 0; indexar[index]= 0;
} }
} }
@ -1411,13 +1411,14 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
paintweight= ts->vgroup_weight; paintweight= ts->vgroup_weight;
for(index=0; index<totindex; index++) { for(index=0; index<totindex; index++) {
if(indexar[index] && indexar[index]<=me->totface) { if(indexar[index] && indexar[index]<=me->totpoly) {
MFace *mface= me->mface + (indexar[index]-1); MPoly *mpoly= me->mpoly + (indexar[index]-1);
MLoop *ml = me->mloop + mpoly->loopstart;
int i;
(me->dvert+mface->v1)->flag= 1; for (i=0; i<mpoly->totloop; i++, ml++) {
(me->dvert+mface->v2)->flag= 1; (me->dvert+ml->v)->flag = 1;
(me->dvert+mface->v3)->flag= 1; }
if(mface->v4) (me->dvert+mface->v4)->flag= 1;
if(wp->mode==VP_BLUR) { if(wp->mode==VP_BLUR) {
MDeformWeight *dw, *(*dw_func)(MDeformVert *, int) = verify_defweight; MDeformWeight *dw, *(*dw_func)(MDeformVert *, int) = verify_defweight;
@ -1425,15 +1426,13 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
if(wp->flag & VP_ONLYVGROUP) if(wp->flag & VP_ONLYVGROUP)
dw_func= get_defweight; dw_func= get_defweight;
dw= dw_func(me->dvert+mface->v1, ob->actdef-1); ml = me->mloop + mpoly->loopstart;
if(dw) {paintweight+= dw->weight; totw++;} for (i=0; i<mpoly->totloop; i++, ml++) {
dw= dw_func(me->dvert+mface->v2, ob->actdef-1); dw = dw_func(me->dvert+ml->v, ob->actdef-1);
if(dw) {paintweight+= dw->weight; totw++;} if (dw) {
dw= dw_func(me->dvert+mface->v3, ob->actdef-1); paintweight += dw->weight;
if(dw) {paintweight+= dw->weight; totw++;} totw++;
if(mface->v4) { }
dw= dw_func(me->dvert+mface->v4, ob->actdef-1);
if(dw) {paintweight+= dw->weight; totw++;}
} }
} }
} }
@ -1444,40 +1443,18 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
for(index=0; index<totindex; index++) { for(index=0; index<totindex; index++) {
if(indexar[index] && indexar[index]<=me->totface) { if(indexar[index] && indexar[index]<=me->totpoly) {
MFace *mface= me->mface + (indexar[index]-1); MPoly *mpoly= me->mpoly + (indexar[index]-1);
MLoop *ml=me->mloop+mpoly->loopstart;
int i;
if((me->dvert+mface->v1)->flag) { for (i=0; i<mpoly->totloop; i++, ml++) {
alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval); if ((me->dvert+ml->v)->flag) {
if(alpha) { alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*ml->v, mval);
do_weight_paint_vertex(wp, ob, mface->v1, alpha, paintweight, wpd->vgroup_mirror);
}
(me->dvert+mface->v1)->flag= 0;
}
if((me->dvert+mface->v2)->flag) {
alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval);
if(alpha) {
do_weight_paint_vertex(wp, ob, mface->v2, alpha, paintweight, wpd->vgroup_mirror);
}
(me->dvert+mface->v2)->flag= 0;
}
if((me->dvert+mface->v3)->flag) {
alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval);
if(alpha) {
do_weight_paint_vertex(wp, ob, mface->v3, alpha, paintweight, wpd->vgroup_mirror);
}
(me->dvert+mface->v3)->flag= 0;
}
if((me->dvert+mface->v4)->flag) {
if(mface->v4) {
alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval);
if(alpha) { if(alpha) {
do_weight_paint_vertex(wp, ob, mface->v4, alpha, paintweight, wpd->vgroup_mirror); do_weight_paint_vertex(wp, ob, ml->v, alpha, paintweight, wpd->vgroup_mirror);
} }
(me->dvert+mface->v4)->flag= 0; (me->dvert+ml->v)->flag= 0;
} }
} }
} }

@ -78,7 +78,8 @@ typedef struct CustomData {
#define CD_WEIGHT_MCOL 20 /* for displaying weightpaint colors */ #define CD_WEIGHT_MCOL 20 /* for displaying weightpaint colors */
#define CD_MPOLY 21 #define CD_MPOLY 21
#define CD_MLOOP 22 #define CD_MLOOP 22
#define CD_NUMTYPES 23 #define CD_WEIGHT_MLOOPCOL 23
#define CD_NUMTYPES 24
/* Bits for CustomDataMask */ /* Bits for CustomDataMask */
#define CD_MASK_MVERT (1 << CD_MVERT) #define CD_MASK_MVERT (1 << CD_MVERT)
@ -104,6 +105,7 @@ typedef struct CustomData {
#define CD_MASK_WEIGHT_MCOL (1 << CD_WEIGHT_MCOL) #define CD_MASK_WEIGHT_MCOL (1 << CD_WEIGHT_MCOL)
#define CD_MASK_MPOLY (1 << CD_MPOLY) #define CD_MASK_MPOLY (1 << CD_MPOLY)
#define CD_MASK_MLOOP (1 << CD_MLOOP) #define CD_MASK_MLOOP (1 << CD_MLOOP)
#define CD_MASK_WEIGHT_MLOOPCOL (1 << CD_WEIGHT_MLOOPCOL)
/* derivedmesh wants CustomDataMask for weightpaint too, is not customdata though */ /* derivedmesh wants CustomDataMask for weightpaint too, is not customdata though */
#define CD_MASK_WEIGHTPAINT (1 << CD_WEIGHTPAINT) #define CD_MASK_WEIGHTPAINT (1 << CD_WEIGHTPAINT)