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/blenkernel/intern | |
parent | e51ee75e826846d44dcbb7028ee44e8f3e7b6858 (diff) |
bmesh optimization: use offsets for deform-vert lookups to avoid customdata layer lookups within loops.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 16 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 8 |
2 files changed, 11 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 13ee9328cf6..794e6481d34 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -1428,6 +1428,8 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, { EditDerivedBMesh *bmdm = MEM_callocN(sizeof(*bmdm), __func__); BMesh *bm = em->bm; + const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); + const int cd_skin_offset = CustomData_get_offset(&bm->vdata, CD_MVERT_SKIN); bmdm->em = em; @@ -1485,7 +1487,7 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, bmdm->vertexCos = vertexCos; - if (CustomData_has_layer(&bm->vdata, CD_MDEFORMVERT)) { + if (cd_dvert_offset != -1) { BMIter iter; BMVert *eve; int i; @@ -1494,11 +1496,11 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { DM_set_vert_data(&bmdm->dm, i, CD_MDEFORMVERT, - CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT)); + BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset)); } } - if (CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN)) { + if (cd_skin_offset != -1) { BMIter iter; BMVert *eve; int i; @@ -1507,8 +1509,7 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { DM_set_vert_data(&bmdm->dm, i, CD_MVERT_SKIN, - CustomData_bmesh_get(&bm->vdata, eve->head.data, - CD_MVERT_SKIN)); + BM_ELEM_CD_GET_VOID_P(eve, cd_skin_offset)); } } @@ -1538,9 +1539,8 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, /* following Mesh convention; we use vertex coordinate itself * for normal in this case */ - if (normalize_v3(no) == 0.0f) { - copy_v3_v3(no, vertexCos[i]); - normalize_v3(no); + if (UNLIKELY(normalize_v3(no) == 0.0f)) { + normalize_v3_v3(no, vertexCos[i]); } } } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 74bf36adc6e..dfa5fcff94c 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1067,12 +1067,10 @@ static float *get_weights_array(Object *ob, char *vgroup) weights = MEM_callocN(totvert * sizeof(float), "weights"); if (em) { + const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { - dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); - - if (dvert) { - weights[i] = defvert_find_weight(dvert, defgrp_index); - } + dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); + weights[i] = defvert_find_weight(dvert, defgrp_index); } } else { |