forked from bartvdbraak/blender
brought weight paint back.
This commit is contained in:
parent
63051a87a3
commit
9a5ffc8c38
@ -1784,23 +1784,45 @@ void vDM_ColorBand_store(ColorBand *coba)
|
||||
static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm)
|
||||
{
|
||||
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 */
|
||||
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);
|
||||
for (i=0; i<me->totface; i++, mf++) {
|
||||
calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4]);
|
||||
calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4]);
|
||||
calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4]);
|
||||
if (mf->v4)
|
||||
calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4]);
|
||||
/*first add colors to the tesselation faces*/
|
||||
memset(wtcol, 0x55, sizeof (unsigned char) * totface*4*4);
|
||||
for (i=0; i<totface; i++, mf++) {
|
||||
if (origIndex[mf->v1] != ORIGINDEX_NONE)
|
||||
calc_weightpaint_vert_color(ob, coba, origIndex[mf->v1], &wtcol[(i*4 + 0)*4]);
|
||||
if (origIndex[mf->v2] != ORIGINDEX_NONE)
|
||||
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):
|
||||
|
@ -1089,7 +1089,6 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
|
||||
int cdindex, BMLoop *l3[3],
|
||||
int numCol, int numTex)
|
||||
{
|
||||
int i, j;
|
||||
BMLoop *l;
|
||||
BMFace *f = l3[0]->f;
|
||||
MTFace *texface;
|
||||
@ -1097,6 +1096,7 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
|
||||
MCol *mcol;
|
||||
MLoopCol *mloopcol;
|
||||
MLoopUV *mloopuv;
|
||||
int i, j, hasWCol = CustomData_has_layer(&bm->ldata, CD_WEIGHT_MLOOPCOL);
|
||||
|
||||
for(i=0; i < numTex; 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;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -1166,14 +1179,8 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
|
||||
CustomData_merge(&em->bm->pdata, &dm->polyData, CD_MASK_DERIVEDMESH,
|
||||
CD_CALLOC, dm->numPolyData);
|
||||
|
||||
/*add tesselation mface and mcol layers as necassary*/
|
||||
for (i=0; i<numTex; i++) {
|
||||
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);
|
||||
}
|
||||
/*add tesselation mface layers*/
|
||||
CustomData_from_bmeshpoly(&dm->faceData, &dm->polyData, &dm->loopData, em->tottri);
|
||||
|
||||
/* set vert index */
|
||||
eve = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);
|
||||
|
@ -867,6 +867,9 @@ const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
|
||||
layerSwap_mcol, layerDefault_mcol},
|
||||
{sizeof(MPoly), "MPoly", 1, "NGon Face", 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] = {
|
||||
@ -890,7 +893,7 @@ const CustomDataMask CD_MASK_EDITMESH =
|
||||
const CustomDataMask CD_MASK_DERIVEDMESH =
|
||||
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_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;
|
||||
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;
|
||||
@ -2003,6 +2006,8 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
|
||||
for(i=0; i < ldata->totlayer; i++){
|
||||
if(ldata->layers[i].type == CD_MLOOPCOL)
|
||||
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;
|
||||
MLoopCol *mloopcol;
|
||||
MLoopUV *mloopuv;
|
||||
int i, j;
|
||||
int i, j, hasWCol = CustomData_has_layer(ldata, CD_WEIGHT_MLOOPCOL);
|
||||
|
||||
for(i=0; i < numTex; 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;
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
@ -133,10 +133,10 @@ BMEditMesh *CDDM_To_BMesh(DerivedMesh *dm, BMEditMesh *existing)
|
||||
bmold = *bm;
|
||||
|
||||
/*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->edgeData, &bm->edata, CD_MASK_BMESH|CD_MASK_ORIGINDEX, 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->polyData, &bm->pdata, CD_MASK_BMESH|CD_MASK_ORIGINDEX, CD_CALLOC, bm, BM_FACE);
|
||||
CustomData_bmesh_merge(&dm->vertData, &bm->vdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_VERT);
|
||||
CustomData_bmesh_merge(&dm->edgeData, &bm->edata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_EDGE);
|
||||
CustomData_bmesh_merge(&dm->loopData, &bm->ldata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_LOOP);
|
||||
CustomData_bmesh_merge(&dm->polyData, &bm->pdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_FACE);
|
||||
|
||||
/*needed later*/
|
||||
numTex = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
|
||||
|
@ -2561,7 +2561,7 @@ void ccg_loops_to_corners(CustomData *fdata, CustomData *ldata,
|
||||
MCol *mcol;
|
||||
MLoopCol *mloopcol;
|
||||
MLoopUV *mloopuv;
|
||||
int i, j;
|
||||
int i, j, hasWCol = CustomData_has_layer(ldata, CD_WEIGHT_MLOOPCOL);
|
||||
|
||||
for(i=0; i < numTex; 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;
|
||||
}
|
||||
}
|
||||
|
||||
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*/
|
||||
|
@ -1380,22 +1380,22 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
|
||||
|
||||
if(wp->flag & VP_COLINDEX) {
|
||||
for(index=0; index<totindex; index++) {
|
||||
if(indexar[index] && indexar[index]<=me->totface) {
|
||||
MFace *mface= ((MFace *)me->mface) + (indexar[index]-1);
|
||||
if(indexar[index] && indexar[index]<=me->totpoly) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((G.f & G_FACESELECT) && me->mface) {
|
||||
if((G.f & G_FACESELECT) && me->mpoly) {
|
||||
for(index=0; index<totindex; index++) {
|
||||
if(indexar[index] && indexar[index]<=me->totface) {
|
||||
MFace *mface= ((MFace *)me->mface) + (indexar[index]-1);
|
||||
if(indexar[index] && indexar[index]<=me->totpoly) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1411,13 +1411,14 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
|
||||
paintweight= ts->vgroup_weight;
|
||||
|
||||
for(index=0; index<totindex; index++) {
|
||||
if(indexar[index] && indexar[index]<=me->totface) {
|
||||
MFace *mface= me->mface + (indexar[index]-1);
|
||||
|
||||
(me->dvert+mface->v1)->flag= 1;
|
||||
(me->dvert+mface->v2)->flag= 1;
|
||||
(me->dvert+mface->v3)->flag= 1;
|
||||
if(mface->v4) (me->dvert+mface->v4)->flag= 1;
|
||||
if(indexar[index] && indexar[index]<=me->totpoly) {
|
||||
MPoly *mpoly= me->mpoly + (indexar[index]-1);
|
||||
MLoop *ml = me->mloop + mpoly->loopstart;
|
||||
int i;
|
||||
|
||||
for (i=0; i<mpoly->totloop; i++, ml++) {
|
||||
(me->dvert+ml->v)->flag = 1;
|
||||
}
|
||||
|
||||
if(wp->mode==VP_BLUR) {
|
||||
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)
|
||||
dw_func= get_defweight;
|
||||
|
||||
dw= dw_func(me->dvert+mface->v1, ob->actdef-1);
|
||||
if(dw) {paintweight+= dw->weight; totw++;}
|
||||
dw= dw_func(me->dvert+mface->v2, ob->actdef-1);
|
||||
if(dw) {paintweight+= dw->weight; totw++;}
|
||||
dw= dw_func(me->dvert+mface->v3, ob->actdef-1);
|
||||
if(dw) {paintweight+= dw->weight; totw++;}
|
||||
if(mface->v4) {
|
||||
dw= dw_func(me->dvert+mface->v4, ob->actdef-1);
|
||||
if(dw) {paintweight+= dw->weight; totw++;}
|
||||
ml = me->mloop + mpoly->loopstart;
|
||||
for (i=0; i<mpoly->totloop; i++, ml++) {
|
||||
dw = dw_func(me->dvert+ml->v, 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++) {
|
||||
|
||||
if(indexar[index] && indexar[index]<=me->totface) {
|
||||
MFace *mface= me->mface + (indexar[index]-1);
|
||||
|
||||
if((me->dvert+mface->v1)->flag) {
|
||||
alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval);
|
||||
if(alpha) {
|
||||
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(indexar[index] && indexar[index]<=me->totpoly) {
|
||||
MPoly *mpoly= me->mpoly + (indexar[index]-1);
|
||||
MLoop *ml=me->mloop+mpoly->loopstart;
|
||||
int i;
|
||||
|
||||
for (i=0; i<mpoly->totloop; i++, ml++) {
|
||||
if ((me->dvert+ml->v)->flag) {
|
||||
alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*ml->v, mval);
|
||||
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_MPOLY 21
|
||||
#define CD_MLOOP 22
|
||||
#define CD_NUMTYPES 23
|
||||
#define CD_WEIGHT_MLOOPCOL 23
|
||||
#define CD_NUMTYPES 24
|
||||
|
||||
/* Bits for CustomDataMask */
|
||||
#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_MPOLY (1 << CD_MPOLY)
|
||||
#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 */
|
||||
#define CD_MASK_WEIGHTPAINT (1 << CD_WEIGHTPAINT)
|
||||
|
Loading…
Reference in New Issue
Block a user