[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56021] trunk/blender: Mesh Drawing:
Campbell Barton
ideasman42 at gmail.com
Sat Apr 13 22:20:26 CEST 2013
Revision: 56021
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56021
Author: campbellbarton
Date: 2013-04-13 20:20:21 +0000 (Sat, 13 Apr 2013)
Log Message:
-----------
Mesh Drawing:
Option to draw mesh vertex-weights in editmode, available from the 'Mesh Display' panel.
TODO: get this to work when modifiers are applied in solid mode (texface-solidmode is working).
Modified Paths:
--------------
trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
trunk/blender/source/blender/blenkernel/BKE_tessmesh.h
trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c
trunk/blender/source/blender/makesdna/DNA_mesh_types.h
trunk/blender/source/blender/makesrna/intern/rna_mesh.c
Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d.py 2013-04-13 18:11:27 UTC (rev 56020)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d.py 2013-04-13 20:20:21 UTC (rev 56021)
@@ -2554,6 +2554,8 @@
mesh = context.active_object.data
+ layout.prop(mesh, "show_weight")
+
split = layout.split()
with_freestyle = context.scene and bpy.app.build_options.freestyle
@@ -2571,7 +2573,7 @@
if not with_freestyle:
col.prop(mesh, "show_edge_seams", text="Seams")
col.prop(mesh, "show_edge_sharp", text="Sharp", text_ctxt=i18n_contexts.plural)
- col.prop(mesh, "show_edge_bevel_weight", text="Weights")
+ col.prop(mesh, "show_edge_bevel_weight", text="Bevel")
if with_freestyle:
col.prop(mesh, "show_freestyle_edge_marks", text="Edge Marks")
col.prop(mesh, "show_freestyle_face_marks", text="Face Marks")
Modified: trunk/blender/source/blender/blenkernel/BKE_tessmesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_tessmesh.h 2013-04-13 18:11:27 UTC (rev 56020)
+++ trunk/blender/source/blender/blenkernel/BKE_tessmesh.h 2013-04-13 20:20:21 UTC (rev 56021)
@@ -60,6 +60,8 @@
/*derivedmesh stuff*/
struct DerivedMesh *derivedFinal, *derivedCage;
CustomDataMask lastDataMask;
+ unsigned char (*derivedVertColor)[4];
+ int derivedVertColorLen;
/* index tables, to map indices to elements via
* EDBM_index_arrays_init and associated functions. don't
Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c 2013-04-13 18:11:27 UTC (rev 56020)
+++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c 2013-04-13 20:20:21 UTC (rev 56021)
@@ -1032,6 +1032,14 @@
} DMWeightColorInfo;
+static int dm_drawflag_calc(ToolSettings *ts)
+{
+ return ((ts->multipaint ? CALC_WP_MULTIPAINT :
+ /* CALC_WP_GROUP_USER_ACTIVE or CALC_WP_GROUP_USER_ALL*/
+ (1 << ts->weightuser)) |
+ (ts->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0));
+}
+
static void weightpaint_color(unsigned char r_col[4], DMWeightColorInfo *dm_wcinfo, const float input)
{
float colf[4];
@@ -1130,14 +1138,14 @@
* note that we could save some memory and allocate RGB only but then we'd need to
* re-arrange the colors when copying to the face since MCol has odd ordering,
* so leave this as is - campbell */
-static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const draw_flag, DMWeightColorInfo *dm_wcinfo)
+static void calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const draw_flag, DMWeightColorInfo *dm_wcinfo,
+ unsigned char (*r_wtcol_v)[4])
{
MDeformVert *dv = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
int numVerts = dm->getNumVerts(dm);
- unsigned char *wtcol_v = MEM_mallocN(sizeof(unsigned char) * numVerts * 4, "weightmap_v");
if (dv) {
- unsigned char *wc = wtcol_v;
+ unsigned char (*wc)[4] = r_wtcol_v;
unsigned int i;
/* variables for multipaint */
@@ -1151,8 +1159,8 @@
defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot);
}
- for (i = numVerts; i != 0; i--, wc += 4, dv++) {
- calc_weightpaint_vert_color(wc, dv, dm_wcinfo, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag);
+ for (i = numVerts; i != 0; i--, wc++, dv++) {
+ calc_weightpaint_vert_color((unsigned char *)wc, dv, dm_wcinfo, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag);
}
if (defbase_sel) {
@@ -1167,10 +1175,8 @@
else {
weightpaint_color((unsigned char *)&col_i, dm_wcinfo, 0.0f);
}
- fill_vn_i((int *)wtcol_v, numVerts, col_i);
+ fill_vn_i((int *)r_wtcol_v, numVerts, col_i);
}
-
- return wtcol_v;
}
/* return an array of vertex weight colors from given weights, caller must free.
@@ -1178,23 +1184,22 @@
* note that we could save some memory and allocate RGB only but then we'd need to
* re-arrange the colors when copying to the face since MCol has odd ordering,
* so leave this as is - campbell */
-static unsigned char *calc_colors_from_weights_array(const int num, float *weights)
+static void calc_colors_from_weights_array(const int num, const float *weights,
+ unsigned char (*r_wtcol_v)[4])
{
- unsigned char *wtcol_v = MEM_mallocN(sizeof(unsigned char) * num * 4, "weightmap_v");
- unsigned char *wc = wtcol_v;
+ unsigned char (*wc)[4] = r_wtcol_v;
int i;
- for (i = 0; i < num; i++, wc += 4, weights++)
- weightpaint_color((unsigned char *) wc, NULL, *weights);
-
- return wtcol_v;
+ for (i = 0; i < num; i++, wc++, weights++) {
+ weightpaint_color((unsigned char *)wc, NULL, *weights);
+ }
}
void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
float *weights, int num, const int *indices)
{
-
- unsigned char *wtcol_v;
+ BMEditMesh *em = (dm->type == DM_TYPE_EDITBMESH) ? BMEdit_FromObject(ob) : NULL;
+ unsigned char (*wtcol_v)[4];
unsigned char(*wtcol_l)[4] = CustomData_get_layer(dm->getLoopDataLayout(dm), CD_PREVIEW_MLOOPCOL);
MLoop *mloop = dm->getLoopArray(dm), *ml;
MPoly *mp = dm->getPolyArray(dm);
@@ -1202,6 +1207,20 @@
int totloop;
int i, j;
+ if (em) {
+ if (em->derivedVertColor && em->derivedVertColorLen == numVerts) {
+ wtcol_v = em->derivedVertColor;
+ }
+ else {
+ if (em->derivedVertColor) MEM_freeN(em->derivedVertColor);
+ wtcol_v = em->derivedVertColor = MEM_mallocN(sizeof(*wtcol_v) * numVerts, __func__);
+ em->derivedVertColorLen = numVerts;
+ }
+ }
+ else {
+ wtcol_v = MEM_mallocN(sizeof(*wtcol_v) * numVerts, __func__);
+ }
+
/* Weights are given by caller. */
if (weights) {
float *w = weights;
@@ -1215,46 +1234,51 @@
}
/* Convert float weights to colors. */
- wtcol_v = calc_colors_from_weights_array(numVerts, w);
+ calc_colors_from_weights_array(numVerts, w, wtcol_v);
if (indices)
MEM_freeN(w);
}
else {
/* No weights given, take them from active vgroup(s). */
- wtcol_v = calc_weightpaint_vert_array(ob, dm, draw_flag, &G_dm_wcinfo);
+ calc_weightpaint_vert_array(ob, dm, draw_flag, &G_dm_wcinfo, wtcol_v);
}
- /* now add to loops, so the data can be passed through the modifier stack */
- /* If no CD_PREVIEW_MLOOPCOL existed yet, we have to add a new one! */
- if (!wtcol_l) {
- BLI_array_declare(wtcol_l);
- totloop = 0;
- for (i = 0; i < dm->numPolyData; i++, mp++) {
- ml = mloop + mp->loopstart;
+ if (dm->type == DM_TYPE_EDITBMESH) {
+ /* editmesh draw function checks spesifically for this */
+ }
+ else {
+ /* now add to loops, so the data can be passed through the modifier stack */
+ /* If no CD_PREVIEW_MLOOPCOL existed yet, we have to add a new one! */
+ if (!wtcol_l) {
+ BLI_array_declare(wtcol_l);
+ totloop = 0;
+ for (i = 0; i < dm->numPolyData; i++, mp++) {
+ ml = mloop + mp->loopstart;
- BLI_array_grow_items(wtcol_l, mp->totloop);
- for (j = 0; j < mp->totloop; j++, ml++, totloop++) {
- copy_v4_v4_char((char *)&wtcol_l[totloop],
- (char *)&wtcol_v[4 * ml->v]);
+ BLI_array_grow_items(wtcol_l, mp->totloop);
+ for (j = 0; j < mp->totloop; j++, ml++, totloop++) {
+ copy_v4_v4_char((char *)&wtcol_l[totloop],
+ (char *)&wtcol_v[ml->v]);
+ }
}
+ CustomData_add_layer(&dm->loopData, CD_PREVIEW_MLOOPCOL, CD_ASSIGN, wtcol_l, totloop);
}
- CustomData_add_layer(&dm->loopData, CD_PREVIEW_MLOOPCOL, CD_ASSIGN, wtcol_l, totloop);
- }
- else {
- totloop = 0;
- for (i = 0; i < dm->numPolyData; i++, mp++) {
- ml = mloop + mp->loopstart;
+ else {
+ totloop = 0;
+ for (i = 0; i < dm->numPolyData; i++, mp++) {
+ ml = mloop + mp->loopstart;
- for (j = 0; j < mp->totloop; j++, ml++, totloop++) {
- copy_v4_v4_char((char *)&wtcol_l[totloop],
- (char *)&wtcol_v[4 * ml->v]);
+ for (j = 0; j < mp->totloop; j++, ml++, totloop++) {
+ copy_v4_v4_char((char *)&wtcol_l[totloop],
+ (char *)&wtcol_v[ml->v]);
+ }
}
}
+ MEM_freeN(wtcol_v);
+
+ dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
}
- MEM_freeN(wtcol_v);
-
- dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
}
@@ -1380,12 +1404,8 @@
int has_multires = mmd != NULL, multires_applied = 0;
int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt;
int sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm);
+ int draw_flag = dm_drawflag_calc(scene->toolsettings);
- const int draw_flag = ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT :
- /* CALC_WP_GROUP_USER_ACTIVE or CALC_WP_GROUP_USER_ALL*/
- (1 << scene->toolsettings->weightuser)) |
- (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0));
-
/* Generic preview only in object mode! */
const int do_mod_mcol = (ob->mode == OB_MODE_OBJECT);
#if 0 /* XXX Will re-enable this when we have global mod stack options. */
@@ -1909,7 +1929,15 @@
int i, numVerts = 0, cageIndex = modifiers_getCageIndex(scene, ob, NULL, 1);
CDMaskLink *datamasks, *curr;
int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
+ int draw_flag = dm_drawflag_calc(scene->toolsettings);
+ // const int do_mod_mcol = true; // (ob->mode == OB_MODE_OBJECT);
+#if 0 /* XXX Will re-enable this when we have global mod stack options. */
+ const int do_final_wmcol = (scene->toolsettings->weights_preview == WP_WPREVIEW_FINAL) && do_wmcol;
+#endif
+ const int do_final_wmcol = FALSE;
+ int do_init_wmcol = ((((Mesh *)ob->data)->drawflag & ME_DRAWEIGHT) && !do_final_wmcol);
+
modifiers_clearErrors(ob);
if (cage_r && cageIndex == -1) {
@@ -1992,6 +2020,10 @@
CDDM_apply_vert_coords(dm, deformedVerts);
CDDM_calc_normals(dm);
}
+
+ if (do_init_wmcol) {
+ DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
+ }
}
/* create an orco derivedmesh in parallel */
@@ -2089,11 +2121,19 @@
#if 0 // was added for bmesh but is not needed
(*final_r)->calcNormals(*final_r);
#endif
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list