diff options
author | Gaia Clary <gaia.clary@machinimatrix.org> | 2014-06-18 22:01:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-06-18 22:10:07 +0400 |
commit | bab75f8bf6a7b26e824f4d76d580940a1deb4489 (patch) | |
tree | e7f6c37891f2120e44f7ca156c3f75c39fcad576 /source/blender | |
parent | ef5d6edb4a87d17e95ccc9250bc019e8828eee58 (diff) |
Editmesh: add ability to show weights on wire T39054, D585
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 93 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 16 |
2 files changed, 106 insertions, 3 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 608d5d1b6dc..9c2d482c9be 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -152,6 +152,15 @@ typedef struct drawDMEdgesSelInterp_userData { unsigned char *lastCol; } drawDMEdgesSelInterp_userData; +typedef struct drawDMEdgesWeightInterp_userData { + int cd_dvert_offset; + int defgroup_tot; + int vgroup_index; + char weight_user; + float alert_color[3]; + +} drawDMEdgesWeightInterp_userData; + typedef struct drawDMFacesSel_userData { #ifdef WITH_FREESTYLE unsigned char *cols[4]; @@ -2420,6 +2429,79 @@ static void draw_dm_edges_sel_interp(BMEditMesh *em, DerivedMesh *dm, unsigned c dm->drawMappedEdgesInterp(dm, draw_dm_edges_sel_interp__setDrawOptions, draw_dm_edges_sel_interp__setDrawInterpOptions, &data); } +static void bm_color_from_weight(float col[3], BMVert *vert, drawDMEdgesWeightInterp_userData *data) +{ + MDeformVert *dvert = BM_ELEM_CD_GET_VOID_P(vert, data->cd_dvert_offset); + float weight = defvert_find_weight(dvert, data->vgroup_index); + + if ((weight == 0.0f) && + ((data->weight_user == OB_DRAW_GROUPUSER_ACTIVE) || + ((data->weight_user == OB_DRAW_GROUPUSER_ALL) && defvert_is_weight_zero(dvert, data->defgroup_tot)))) + { + copy_v3_v3(col, data->alert_color); + } + else { + weight_to_rgb(col, weight); + } +} + +static void draw_dm_edges_weight_interp__setDrawInterpOptions(void *userData, int index, float t) +{ + drawDMEdgesWeightInterp_userData *data = userData; + BMEdge *eed = BM_edge_at_index(((void **)userData)[0], index); + float col[3]; + + if (t == 0.0f) { + bm_color_from_weight(col, eed->v1, data); + } + else if (t == 1.0f) { + bm_color_from_weight(col, eed->v2, data); + } + else { + float col_v1[3]; + float col_v2[3]; + + bm_color_from_weight(col_v1, eed->v1, data); + bm_color_from_weight(col_v2, eed->v2, data); + interp_v3_v3v3(col, col_v1, col_v2, t); + } + + glColor3fv(col); +} + +static void draw_dm_edges_weight_interp(BMEditMesh *em, DerivedMesh *dm, const char weight_user) +{ + drawDMEdgesWeightInterp_userData data; + Object *ob = em->ob; + + data.cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + data.defgroup_tot = BLI_countlist(&ob->defbase); + data.vgroup_index = ob->actdef - 1; + data.weight_user = weight_user; + UI_GetThemeColor3fv(TH_VERTEX_UNREFERENCED, data.alert_color); + + glEnable(GL_BLEND); + dm->drawMappedEdgesInterp(dm, draw_dm_edges_sel_interp__setDrawOptions, draw_dm_edges_weight_interp__setDrawInterpOptions, &data); + glDisable(GL_BLEND); +} + +static bool draw_dm_edges_weight_check(Mesh *me, BMEditMesh *em, View3D *v3d) +{ + if ((me->drawflag & ME_DRAWEIGHT) && + (em->ob->actdef) && + (CustomData_has_layer(&em->bm->vdata, CD_MDEFORMVERT))) + { + if ((v3d->drawtype == OB_WIRE) || + (v3d->flag2 & V3D_SOLID_MATCAP) || + ((v3d->flag2 & V3D_OCCLUDE_WIRE) && (v3d->drawtype > OB_WIRE))) + { + return true; + } + } + + return false; +} + /* Draw only seam edges */ static DMDrawOption draw_dm_edges_seams__setDrawOptions(void *userData, int index) { @@ -2832,9 +2914,16 @@ static void draw_em_fancy_edges(BMEditMesh *em, Scene *scene, View3D *v3d, draw_dm_edges_sel(em, cageDM, wireCol, selCol, actCol, eed_act); } else if ((me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE)) { - if (cageDM->drawMappedEdgesInterp && (ts->selectmode & SCE_SELECT_VERTEX)) { + if (cageDM->drawMappedEdgesInterp && + ((ts->selectmode & SCE_SELECT_VERTEX) || (me->drawflag & ME_DRAWEIGHT))) + { glShadeModel(GL_SMOOTH); - draw_dm_edges_sel_interp(em, cageDM, wireCol, selCol); + if (draw_dm_edges_weight_check(me, em, v3d)) { + draw_dm_edges_weight_interp(em, cageDM, ts->weightuser); + } + else { + draw_dm_edges_sel_interp(em, cageDM, wireCol, selCol); + } glShadeModel(GL_FLAT); } else { diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index ce74c547610..5ec15a28c36 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -37,6 +37,7 @@ #include "DNA_customdata_types.h" #include "DNA_object_types.h" #include "DNA_group_types.h" +#include "DNA_mesh_types.h" #include "DNA_key_types.h" #include "DNA_lamp_types.h" #include "DNA_scene_types.h" @@ -2607,12 +2608,25 @@ static void view3d_draw_objects( /* set zbuffer after we draw clipping region */ if (v3d->drawtype > OB_WIRE) { v3d->zbuf = true; - glEnable(GL_DEPTH_TEST); } else { v3d->zbuf = false; } + /* special case (depth for wire color) */ + if (v3d->drawtype <= OB_WIRE) { + if (scene->obedit && scene->obedit->type == OB_MESH) { + Mesh *me = scene->obedit->data; + if (me->drawflag & ME_DRAWEIGHT) { + v3d->zbuf = true; + } + } + } + + if (v3d->zbuf) { + glEnable(GL_DEPTH_TEST); + } + if (!draw_offscreen) { /* needs to be done always, gridview is adjusted in drawgrid() now, but only for ortho views. */ rv3d->gridview = v3d->grid; |