diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-27 16:42:48 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-27 16:42:48 +0400 |
commit | 083115c5e790d5c6e87a7a4a42daea70da1ded1b (patch) | |
tree | 75314e71ff24b7de4a8508e76662b3afbc3e5ddf /source/blender/editors | |
parent | e51ee75e826846d44dcbb7028ee44e8f3e7b6858 (diff) |
bmesh optimization: use offsets for deform-vert lookups to avoid customdata layer lookups within loops.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 7 | ||||
-rw-r--r-- | source/blender/editors/object/object_hook.c | 29 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 80 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_buttons.c | 55 |
4 files changed, 106 insertions, 65 deletions
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index e2fc91198a3..9edfffd67c3 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -3312,11 +3312,12 @@ static int edbm_select_ungrouped_poll(bContext *C) if (ED_operator_editmesh(C)) { Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); if ((em->selectmode & SCE_SELECT_VERTEX) == 0) { CTX_wm_operator_poll_msg_set(C, "Must be in vertex selection mode"); } - else if (obedit->defbase.first == NULL) { + else if (obedit->defbase.first == NULL || cd_dvert_offset == -1) { CTX_wm_operator_poll_msg_set(C, "No weights/vertex groups on object"); } else { @@ -3330,6 +3331,8 @@ static int edbm_select_ungrouped_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + BMVert *eve; BMIter iter; @@ -3339,7 +3342,7 @@ static int edbm_select_ungrouped_exec(bContext *C, wmOperator *op) BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { - MDeformVert *dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); /* no dv or dv set with no weight */ if (ELEM(NULL, dv, dv->dw)) { BM_vert_select_set(em->bm, eve, true); diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c index 861dd4003e1..04c67b8d3fa 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -102,11 +102,13 @@ static int return_editmesh_indexar(BMEditMesh *em, int *tot, int **indexar, floa return totvert; } -static int return_editmesh_vgroup(Object *obedit, BMEditMesh *em, char *name, float *cent) +static bool return_editmesh_vgroup(Object *obedit, BMEditMesh *em, char *name, float *cent) { + const int cd_dvert_offset = obedit->actdef ? CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT) : -1; + zero_v3(cent); - if (obedit->actdef) { + if (cd_dvert_offset != -1) { const int defgrp_index = obedit->actdef - 1; int totvert = 0; @@ -116,24 +118,22 @@ static int return_editmesh_vgroup(Object *obedit, BMEditMesh *em, char *name, fl /* find the vertices */ BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); - if (dvert) { - if (defvert_find_weight(dvert, defgrp_index) > 0.0f) { - add_v3_v3(cent, eve->co); - totvert++; - } + if (defvert_find_weight(dvert, defgrp_index) > 0.0f) { + add_v3_v3(cent, eve->co); + totvert++; } } if (totvert) { bDeformGroup *dg = BLI_findlink(&obedit->defbase, defgrp_index); BLI_strncpy(name, dg->name, sizeof(dg->name)); mul_v3_fl(cent, 1.0f / (float)totvert); - return 1; + return true; } } - return 0; + return false; } static void select_editbmesh_hook(Object *ob, HookModifierData *hmd) @@ -296,7 +296,7 @@ static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, flo return totvert; } -static int object_hook_index_array(Scene *scene, Object *obedit, int *tot, int **indexar, char *name, float *cent_r) +static bool object_hook_index_array(Scene *scene, Object *obedit, int *tot, int **indexar, char *name, float *cent_r) { *indexar = NULL; *tot = 0; @@ -319,11 +319,10 @@ static int object_hook_index_array(Scene *scene, Object *obedit, int *tot, int * /* check selected vertices first */ if (return_editmesh_indexar(em, tot, indexar, cent_r)) { - return 1; + return true; } else { - int ret = return_editmesh_vgroup(obedit, em, name, cent_r); - return ret; + return return_editmesh_vgroup(obedit, em, name, cent_r); } } case OB_CURVE: @@ -335,7 +334,7 @@ static int object_hook_index_array(Scene *scene, Object *obedit, int *tot, int * return return_editlattice_indexar(lt->editlatt->latt, tot, indexar, cent_r); } default: - return 0; + return false; } } diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 02481ec5222..f7d33fb4a5f 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -223,11 +223,13 @@ static bool ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int *dvert_t if (me->edit_btmesh) { BMEditMesh *em = me->edit_btmesh; + BMesh *bm = em->bm; + const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); BMIter iter; BMVert *eve; int i; - if (!CustomData_has_layer(&em->bm->vdata, CD_MDEFORMVERT)) { + if (cd_dvert_offset == -1) { return false; } @@ -240,13 +242,13 @@ static bool ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int *dvert_t if (use_vert_sel) { BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { (*dvert_arr)[i] = BM_elem_flag_test(eve, BM_ELEM_SELECT) ? - CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT) : NULL; + BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset) : NULL; i++; } } else { BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - (*dvert_arr)[i] = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + (*dvert_arr)[i] = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); i++; } } @@ -983,12 +985,19 @@ static float get_vert_def_nr(Object *ob, const int def_nr, const int vertnum) Mesh *me = ob->data; if (me->edit_btmesh) { + BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); /* warning, this lookup is _not_ fast */ - BMVert *eve = BM_vert_at_index(me->edit_btmesh->bm, vertnum); - if (!eve) { + BMVert *eve; + + EDBM_index_arrays_ensure(em, BM_VERT); + + if ((cd_dvert_offset != -1) || (eve = EDBM_vert_at_index(em, vertnum))) { + dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); + } + else { return 0.0f; } - dv = CustomData_bmesh_get(&me->edit_btmesh->bm->vdata, eve->head.data, CD_MDEFORMVERT); } else { if (me->dvert) { @@ -1052,12 +1061,13 @@ static void vgroup_select_verts(Object *ob, int select) if (me->edit_btmesh) { BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); BMIter iter; BMVert *eve; BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { - MDeformVert *dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); if (defvert_find_index(dv, def_nr)) { BM_vert_select_set(em->bm, eve, select); } @@ -1831,6 +1841,8 @@ static void vgroup_blend(Object *ob, const float fac) vg_users = MEM_callocN(sizeof(int) * dvert_tot, "vgroup_blend_i"); if (bm) { + const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); + BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) { sel1 = BM_elem_flag_test(eed->v1, BM_ELEM_SELECT); sel2 = BM_elem_flag_test(eed->v2, BM_ELEM_SELECT); @@ -1849,7 +1861,7 @@ static void vgroup_blend(Object *ob, const float fac) eve = eed->v1; } - dv = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT); + dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); dw = defvert_find_index(dv, def_nr); if (dw) { vg_weights[i1] += dw->weight; @@ -1860,7 +1872,7 @@ static void vgroup_blend(Object *ob, const float fac) BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT) && vg_users[i] > 0) { - dv = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT); + dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); dw = defvert_verify_index(dv, def_nr); dw->weight = (fac * (vg_weights[i] / (float)vg_users[i])) + (ifac * dw->weight); @@ -2152,9 +2164,10 @@ void ED_vgroup_mirror(Object *ob, BMEditMesh *em = me->edit_btmesh; if (em) { + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); BMIter iter; - if (!CustomData_has_layer(&em->bm->vdata, CD_MDEFORMVERT)) { + if (cd_dvert_offset == -1) { goto cleanup; } @@ -2167,11 +2180,10 @@ void ED_vgroup_mirror(Object *ob, sel_mirr = BM_elem_flag_test(eve_mirr, BM_ELEM_SELECT); if ((sel || sel_mirr) && (eve != eve_mirr)) { - dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); - dvert_mirr = CustomData_bmesh_get(&em->bm->vdata, eve_mirr->head.data, CD_MDEFORMVERT); - if (dvert && dvert_mirr) { - VGROUP_MIRR_OP; - } + dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); + dvert_mirr = BM_ELEM_CD_GET_VOID_P(eve_mirr, cd_dvert_offset); + + VGROUP_MIRR_OP; } /* don't use these again */ @@ -2402,11 +2414,13 @@ static void vgroup_active_remove_verts(Object *ob, const bool allverts, bDeformG if (me->edit_btmesh) { BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + BMVert *eve; BMIter iter; BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); if (dv && dv->dw && (allverts || BM_elem_flag_test(eve, BM_ELEM_SELECT))) { MDeformWeight *dw = defvert_find_index(dv, def_nr); @@ -2470,12 +2484,14 @@ static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *dg) if (ob->type == OB_MESH) { Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + BMIter iter; BMVert *eve; MDeformVert *dvert; BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); if (dvert) for (i = 0; i < dvert->totweight; i++) @@ -2598,6 +2614,8 @@ static void vgroup_assign_verts(Object *ob, const float weight) if (me->edit_btmesh) { BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + BMIter iter; BMVert *eve; @@ -2609,7 +2627,7 @@ static void vgroup_assign_verts(Object *ob, const float weight) if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { MDeformVert *dv; MDeformWeight *dw; - dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); /* can be NULL */ + dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); /* can be NULL */ dw = defvert_verify_index(dv, def_nr); if (dw) { dw->weight = weight; @@ -3615,13 +3633,17 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op) if (ob->mode == OB_MODE_EDIT) { if (ob->type == OB_MESH) { BMEditMesh *em = BKE_editmesh_from_object(ob); - BMIter iter; - BMVert *eve; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); - BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); - if (dvert && dvert->totweight) { - defvert_remap(dvert, sort_map, defbase_tot); + if (cd_dvert_offset != -1) { + BMIter iter; + BMVert *eve; + + BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { + dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); + if (dvert->totweight) { + defvert_remap(dvert, sort_map, defbase_tot); + } } } } @@ -3637,10 +3659,12 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op) ED_vgroup_give_array(ob->data, &dvert, &dvert_tot); /*create as necessary*/ - while (dvert && dvert_tot--) { - if (dvert->totweight) - defvert_remap(dvert, sort_map, defbase_tot); - dvert++; + if (dvert) { + while (dvert_tot--) { + if (dvert->totweight) + defvert_remap(dvert, sort_map, defbase_tot); + dvert++; + } } } diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index 828ef221e97..e5ebe70020e 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -774,25 +774,30 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float #define B_VGRP_PNL_EDIT_SINGLE 8 /* or greater */ #define B_VGRP_PNL_COPY_SINGLE 16384 /* or greater */ -static void act_vert_def(Object *ob, BMVert **eve, MDeformVert **dvert) +static void act_vert_def(Object *ob, BMVert **r_eve, MDeformVert **r_dvert) { if (ob && ob->mode & OB_MODE_EDIT && ob->type == OB_MESH && ob->defbase.first) { Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; - BMEditSelection *ese = (BMEditSelection *)em->bm->selected.last; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); - if (ese && ese->htype == BM_VERT) { - *eve = (BMVert *)ese->ele; - *dvert = CustomData_bmesh_get(&em->bm->vdata, (*eve)->head.data, CD_MDEFORMVERT); - return; + if (cd_dvert_offset != -1) { + BMEditSelection *ese = (BMEditSelection *)em->bm->selected.last; + + if (ese && ese->htype == BM_VERT) { + *r_eve = (BMVert *)ese->ele; + *r_dvert = BM_ELEM_CD_GET_VOID_P(*r_eve, cd_dvert_offset); + return; + } } } - *eve = NULL; - *dvert = NULL; + *r_eve = NULL; + *r_dvert = NULL; } -static void editvert_mirror_update(Object *ob, BMVert *eve, int def_nr, int index) +static void editvert_mirror_update(Object *ob, BMVert *eve, int def_nr, int index, + const int cd_dvert_offset) { Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; @@ -801,8 +806,8 @@ static void editvert_mirror_update(Object *ob, BMVert *eve, int def_nr, int inde eve_mirr = editbmesh_get_x_mirror_vert(ob, em, eve, eve->co, index); if (eve_mirr && eve_mirr != eve) { - MDeformVert *dvert_src = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); - MDeformVert *dvert_dst = CustomData_bmesh_get(&em->bm->vdata, eve_mirr->head.data, CD_MDEFORMVERT); + MDeformVert *dvert_src = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); + MDeformVert *dvert_dst = BM_ELEM_CD_GET_VOID_P(eve_mirr, cd_dvert_offset); if (dvert_dst) { if (def_nr == -1) { /* all vgroups, add groups where neded */ @@ -824,14 +829,17 @@ static void editvert_mirror_update(Object *ob, BMVert *eve, int def_nr, int inde static void vgroup_adjust_active(Object *ob, int def_nr) { + Mesh *me = ob->data; + BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); BMVert *eve_act; MDeformVert *dvert_act; act_vert_def(ob, &eve_act, &dvert_act); if (dvert_act) { - if (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X) - editvert_mirror_update(ob, eve_act, def_nr, -1); + if (me->editflag & ME_EDIT_MIRROR_X) + editvert_mirror_update(ob, eve_act, def_nr, -1, cd_dvert_offset); } } @@ -848,6 +856,8 @@ static void vgroup_copy_active_to_sel(Object *ob) else { Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + BMIter iter; BMVert *eve; MDeformVert *dvert; @@ -855,12 +865,12 @@ static void vgroup_copy_active_to_sel(Object *ob) BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT) && eve != eve_act) { - dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); if (dvert) { defvert_copy(dvert, dvert_act); if (me->editflag & ME_EDIT_MIRROR_X) - editvert_mirror_update(ob, eve, -1, index); + editvert_mirror_update(ob, eve, -1, index, cd_dvert_offset); } } @@ -883,6 +893,7 @@ static void vgroup_copy_active_to_sel_single(Object *ob, const int def_nr) else { Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); BMIter iter; BMVert *eve; MDeformVert *dv; @@ -900,26 +911,30 @@ static void vgroup_copy_active_to_sel_single(Object *ob, const int def_nr) eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); for (index = 0; eve; eve = BM_iter_step(&iter), index++) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT) && eve != eve_act) { - dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); + dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); dw = defvert_find_index(dv, def_nr); if (dw) { dw->weight = weight_act; if (me->editflag & ME_EDIT_MIRROR_X) { - editvert_mirror_update(ob, eve, -1, index); + editvert_mirror_update(ob, eve, -1, index, cd_dvert_offset); } } } } if (me->editflag & ME_EDIT_MIRROR_X) { - editvert_mirror_update(ob, eve_act, -1, -1); + editvert_mirror_update(ob, eve_act, -1, -1, cd_dvert_offset); } } } static void vgroup_normalize_active(Object *ob) { + Mesh *me = ob->data; + BMEditMesh *em = me->edit_btmesh; + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + BMVert *eve_act; MDeformVert *dvert_act; @@ -930,8 +945,8 @@ static void vgroup_normalize_active(Object *ob) defvert_normalize(dvert_act); - if (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X) - editvert_mirror_update(ob, eve_act, -1, -1); + if (me->editflag & ME_EDIT_MIRROR_X) + editvert_mirror_update(ob, eve_act, -1, -1, cd_dvert_offset); } static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event) |