[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19503] branches/blender2.5/blender/source /blender: 2.5: weight paint mode fix for corrupted layer data, and added
Brecht Van Lommel
brecht at blender.org
Thu Apr 2 16:38:40 CEST 2009
Revision: 19503
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19503
Author: blendix
Date: 2009-04-02 16:38:40 +0200 (Thu, 02 Apr 2009)
Log Message:
-----------
2.5: weight paint mode fix for corrupted layer data, and added
a customdata layer specifically to store weightpaint colors
instead of abusing the vertex colors layers.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenkernel/intern/DerivedMesh.c
branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c
branches/blender2.5/blender/source/blender/blenkernel/intern/customdata.c
branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_draw.c
branches/blender2.5/blender/source/blender/makesdna/DNA_customdata_types.h
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/DerivedMesh.c 2009-04-02 11:30:27 UTC (rev 19502)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/DerivedMesh.c 2009-04-02 14:38:40 UTC (rev 19503)
@@ -1433,6 +1433,8 @@
return orco;
}
+/* orco custom data layer */
+
static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, EditMesh *em)
{
DerivedMesh *dm;
@@ -1484,6 +1486,96 @@
DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, orco);
}
+/* weight paint colors */
+
+/* Something of a hack, at the moment deal with weightpaint
+ * by tucking into colors during modifier eval, only in
+ * wpaint mode. Works ok but need to make sure recalc
+ * happens on enter/exit wpaint.
+ */
+
+void weight_to_rgb(float input, float *fr, float *fg, float *fb)
+{
+ float blend;
+
+ blend= ((input/2.0f)+0.5f);
+
+ if (input<=0.25f){ // blue->cyan
+ *fr= 0.0f;
+ *fg= blend*input*4.0f;
+ *fb= blend;
+ }
+ else if (input<=0.50f){ // cyan->green
+ *fr= 0.0f;
+ *fg= blend;
+ *fb= blend*(1.0f-((input-0.25f)*4.0f));
+ }
+ else if (input<=0.75){ // green->yellow
+ *fr= blend * ((input-0.50f)*4.0f);
+ *fg= blend;
+ *fb= 0.0f;
+ }
+ else if (input<=1.0){ // yellow->red
+ *fr= blend;
+ *fg= blend * (1.0f-((input-0.75f)*4.0f));
+ *fb= 0.0f;
+ }
+}
+
+static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col)
+{
+ Mesh *me = ob->data;
+ float colf[4], input = 0.0f;
+ int i;
+
+ if (me->dvert) {
+ for (i=0; i<me->dvert[vert].totweight; i++)
+ if (me->dvert[vert].dw[i].def_nr==ob->actdef-1)
+ input+=me->dvert[vert].dw[i].weight;
+ }
+
+ CLAMP(input, 0.0f, 1.0f);
+
+ if(coba)
+ do_colorband(coba, input, colf);
+ else
+ weight_to_rgb(input, colf, colf+1, colf+2);
+
+ col[3] = (unsigned char)(colf[0] * 255.0f);
+ col[2] = (unsigned char)(colf[1] * 255.0f);
+ col[1] = (unsigned char)(colf[2] * 255.0f);
+ col[0] = 255;
+}
+
+static ColorBand *stored_cb= NULL;
+
+void vDM_ColorBand_store(ColorBand *coba)
+{
+ stored_cb= coba;
+}
+
+static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm)
+{
+ Mesh *me = ob->data;
+ MFace *mf = me->mface;
+ ColorBand *coba= stored_cb; /* warning, not a local var */
+ unsigned char *wtcol;
+ int i;
+
+ wtcol = MEM_callocN (sizeof (unsigned char) * me->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]);
+ }
+
+ CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData);
+}
+
static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos)[3],
DerivedMesh **deform_r, DerivedMesh **final_r,
int useRenderParams, int useDeform,
@@ -1547,6 +1639,7 @@
*/
if (deform_r) {
*deform_r = CDDM_from_mesh(me, ob);
+
if(deformedVerts) {
CDDM_apply_vert_coords(*deform_r, deformedVerts);
CDDM_calc_normals(*deform_r);
@@ -1632,6 +1725,9 @@
CDDM_apply_vert_coords(dm, deformedVerts);
CDDM_calc_normals(dm);
}
+
+ if(dataMask & CD_MASK_WEIGHT_MCOL)
+ add_weight_mcol_dm(ob, dm);
}
/* create an orco derivedmesh in parallel */
@@ -1695,14 +1791,21 @@
CDDM_apply_vert_coords(finaldm, deformedVerts);
CDDM_calc_normals(finaldm);
+
+ if(dataMask & CD_MASK_WEIGHT_MCOL)
+ add_weight_mcol_dm(ob, finaldm);
} else if(dm) {
finaldm = dm;
} else {
finaldm = CDDM_from_mesh(me, ob);
+
if(deformedVerts) {
CDDM_apply_vert_coords(finaldm, deformedVerts);
CDDM_calc_normals(finaldm);
}
+
+ if(dataMask & CD_MASK_WEIGHT_MCOL)
+ add_weight_mcol_dm(ob, finaldm);
}
/* add an orco layer if needed */
@@ -1932,96 +2035,6 @@
MEM_freeN(deformedVerts);
}
-/***/
-
-
- /* Something of a hack, at the moment deal with weightpaint
- * by tucking into colors during modifier eval, only in
- * wpaint mode. Works ok but need to make sure recalc
- * happens on enter/exit wpaint.
- */
-
-void weight_to_rgb(float input, float *fr, float *fg, float *fb)
-{
- float blend;
-
- blend= ((input/2.0f)+0.5f);
-
- if (input<=0.25f){ // blue->cyan
- *fr= 0.0f;
- *fg= blend*input*4.0f;
- *fb= blend;
- }
- else if (input<=0.50f){ // cyan->green
- *fr= 0.0f;
- *fg= blend;
- *fb= blend*(1.0f-((input-0.25f)*4.0f));
- }
- else if (input<=0.75){ // green->yellow
- *fr= blend * ((input-0.50f)*4.0f);
- *fg= blend;
- *fb= 0.0f;
- }
- else if (input<=1.0){ // yellow->red
- *fr= blend;
- *fg= blend * (1.0f-((input-0.75f)*4.0f));
- *fb= 0.0f;
- }
-}
-static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col)
-{
- Mesh *me = ob->data;
- float colf[4], input = 0.0f;
- int i;
-
- if (me->dvert) {
- for (i=0; i<me->dvert[vert].totweight; i++)
- if (me->dvert[vert].dw[i].def_nr==ob->actdef-1)
- input+=me->dvert[vert].dw[i].weight;
- }
-
- CLAMP(input, 0.0f, 1.0f);
-
- if(coba)
- do_colorband(coba, input, colf);
- else
- weight_to_rgb(input, colf, colf+1, colf+2);
-
- col[3] = (unsigned char)(colf[0] * 255.0f);
- col[2] = (unsigned char)(colf[1] * 255.0f);
- col[1] = (unsigned char)(colf[2] * 255.0f);
- col[0] = 255;
-}
-
-static ColorBand *stored_cb= NULL;
-
-void vDM_ColorBand_store(ColorBand *coba)
-{
- stored_cb= coba;
-}
-
-static unsigned char *calc_weightpaint_colors(Object *ob)
-{
- Mesh *me = ob->data;
- MFace *mf = me->mface;
- ColorBand *coba= stored_cb; /* warning, not a local var */
- unsigned char *wtcol;
- int i;
-
- wtcol = MEM_callocN (sizeof (unsigned char) * me->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]);
- }
-
- return wtcol;
-}
-
static void clear_mesh_caches(Object *ob)
{
Mesh *me= ob->data;
@@ -2052,43 +2065,17 @@
static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask)
{
- Mesh *me = ob->data;
- float min[3], max[3];
- //int needMapping= 0;
-
Object *obact = scene->basact?scene->basact->object:NULL;
int editing = (FACESEL_PAINT_TEST)|(G.f & G_PARTICLEEDIT);
int needMapping = editing && (ob==obact);
+ float min[3], max[3];
clear_mesh_caches(ob);
- if( (G.f & G_WEIGHTPAINT) && ob==obact ) {
-// if(dataMask & CD_MASK_WEIGHTPAINT) {
- MCol *wpcol = (MCol*)calc_weightpaint_colors(ob);
- int layernum = CustomData_number_of_layers(&me->fdata, CD_MCOL);
- int prevactive = CustomData_get_active_layer(&me->fdata, CD_MCOL);
- int prevrender = CustomData_get_render_layer(&me->fdata, CD_MCOL);
+ mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform,
+ &ob->derivedFinal, 0, 1,
+ needMapping, dataMask, -1);
- /* ugly hack here, we temporarily add a new active mcol layer with
- weightpaint colors in it, that is then duplicated in CDDM_from_mesh */
- CustomData_add_layer(&me->fdata, CD_MCOL, CD_ASSIGN, wpcol, me->totface);
- CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum);
- CustomData_set_layer_render(&me->fdata, CD_MCOL, layernum);
-
- mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform,
- &ob->derivedFinal, 0, 1,
- needMapping, dataMask, -1);
-
- CustomData_free_layer_active(&me->fdata, CD_MCOL, me->totface);
- CustomData_set_layer_active(&me->fdata, CD_MCOL, prevactive);
- CustomData_set_layer_render(&me->fdata, CD_MCOL, prevrender);
- }
- else {
- mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform,
- &ob->derivedFinal, G.rendering, 1,
- needMapping, dataMask, -1);
- }
-
INIT_MINMAX(min, max);
ob->derivedFinal->getMinMax(ob->derivedFinal, min, max);
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c 2009-04-02 11:30:27 UTC (rev 19502)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c 2009-04-02 14:38:40 UTC (rev 19503)
@@ -482,10 +482,14 @@
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
MVert *mv = cddm->mvert;
MFace *mf = cddm->mface;
- MCol *mc = DM_get_face_data_layer(dm, CD_MCOL);
+ MCol *mc;
float *nors= dm->getFaceDataArray(dm, CD_NORMAL);
int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
+ mc = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
+ if(!mc)
+ mc = DM_get_face_data_layer(dm, CD_MCOL);
+
for(i = 0; i < dm->numFaceData; i++, mf++) {
int drawSmooth = (mf->flag & ME_SMOOTH);
@@ -926,13 +930,6 @@
index = CustomData_get_layer(&dm->faceData, CD_ORIGINDEX);
for(i = 0; i < mesh->totface; ++i, ++index)
*index = i;
-
- /* works in conjunction with hack during modifier calc, where active mcol
- layer with weight paint colors is temporarily added */
- /* XXX make this real but temporary layer */
-// if ((G.f & G_WEIGHTPAINT) &&
-// (ob && ob==(scene->basact?scene->basact->object:NULL)))
-// CustomData_duplicate_referenced_layer(&dm->faceData, CD_MCOL);
return dm;
}
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/customdata.c 2009-04-02 11:30:27 UTC (rev 19502)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/customdata.c 2009-04-02 14:38:40 UTC (rev 19503)
@@ -707,14 +707,16 @@
{sizeof(MLoopCol), "MLoopCol", 1, "Col", NULL, NULL, layerInterp_mloopcol, NULL, layerDefault_mloopcol},
{sizeof(float)*3*4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
{sizeof(MDisps), "MDisps", 1, NULL, layerCopy_mdisps,
- layerFree_mdisps, layerInterp_mdisps, layerSwap_mdisps, NULL}
+ layerFree_mdisps, layerInterp_mdisps, layerSwap_mdisps, NULL},
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list