diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-02-23 07:44:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-02-23 07:44:28 +0300 |
commit | 64b328f22b3fbeeae5ef40c2eb9fd7ca5141bb8c (patch) | |
tree | e8577f56ad12f45e99f661c577c37edeb035fc8e /source/blender | |
parent | bc876f9ea401f2de404fbf303038a0185d0a77ba (diff) |
Edge/Vert Slide: avoid redundant loop angle calls
No need to calculate loop angle for each layer
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_interp.c | 10 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_interp.h | 3 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.c | 72 |
3 files changed, 49 insertions, 36 deletions
diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index 0c27da36448..b7a72e2e2ae 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -921,6 +921,7 @@ struct LoopWalkCtx { /* same for all groups */ int type; int cd_layer_offset; + const float *loop_weights; MemArena *arena; /* --- Per loop fan vars --- */ @@ -953,10 +954,11 @@ struct LoopGroupCD { static void bm_loop_walk_add(struct LoopWalkCtx *lwc, BMLoop *l) { - const float w = BM_loop_calc_face_angle(l); + const int i = BM_elem_index_get(l); + const float w = lwc->loop_weights[i]; BM_elem_flag_enable(l, BM_ELEM_INTERNAL_TAG); lwc->data_array[lwc->data_len] = BM_ELEM_CD_GET_VOID_P(l, lwc->cd_layer_offset); - lwc->data_index_array[lwc->data_len] = BM_elem_index_get(l); + lwc->data_index_array[lwc->data_len] = i; lwc->weight_array[lwc->data_len] = w; lwc->weight_accum += w; @@ -994,7 +996,8 @@ static void bm_loop_walk_data(struct LoopWalkCtx *lwc, BMLoop *l_walk) } } -LinkNode *BM_vert_loop_groups_data_layer_create(BMesh *bm, BMVert *v, int layer_n, MemArena *arena) +LinkNode *BM_vert_loop_groups_data_layer_create( + BMesh *bm, BMVert *v, int layer_n, const float *loop_weights, MemArena *arena) { struct LoopWalkCtx lwc; LinkNode *groups = NULL; @@ -1005,6 +1008,7 @@ LinkNode *BM_vert_loop_groups_data_layer_create(BMesh *bm, BMVert *v, int layer_ lwc.type = bm->ldata.layers[layer_n].type; lwc.cd_layer_offset = bm->ldata.layers[layer_n].offset; + lwc.loop_weights = loop_weights; lwc.arena = arena; loop_num = 0; diff --git a/source/blender/bmesh/intern/bmesh_interp.h b/source/blender/bmesh/intern/bmesh_interp.h index 117333b52e3..8493d401a32 100644 --- a/source/blender/bmesh/intern/bmesh_interp.h +++ b/source/blender/bmesh/intern/bmesh_interp.h @@ -56,7 +56,8 @@ void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source, void BM_face_multires_bounds_smooth(BMesh *bm, BMFace *f); struct LinkNode *BM_vert_loop_groups_data_layer_create( - BMesh *bm, BMVert *v, const int layer_n, struct MemArena *arena); + BMesh *bm, BMVert *v, const int layer_n, + const float *loop_weights, struct MemArena *arena); void BM_vert_loop_groups_data_layer_merge( BMesh *bm, struct LinkNode *groups, const int layer_n); void BM_vert_loop_groups_data_layer_merge_weights( diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 8421f4dd3fe..4c95bd899b7 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -5241,6 +5241,43 @@ static void slide_origdata_init_data( } } +static void slide_origdata_create_data_vert( + BMesh *bm, SlideOrigData *sod, + TransDataGenericSlideVert *sv) +{ + BMIter liter; + int j, l_num; + float *loop_weights; + + /* copy face data */ + // BM_ITER_ELEM (l, &liter, sv->v, BM_LOOPS_OF_VERT) { + BM_iter_init(&liter, bm, BM_LOOPS_OF_VERT, sv->v); + l_num = liter.count; + loop_weights = BLI_array_alloca(loop_weights, l_num); + for (j = 0; j < l_num; j++) { + BMLoop *l = BM_iter_step(&liter); + if (!BLI_ghash_haskey(sod->origfaces, l->f)) { + BMFace *f_copy = BM_face_copy(sod->bm_origfaces, bm, l->f, true, true); + BLI_ghash_insert(sod->origfaces, l->f, f_copy); + } + loop_weights[j] = BM_loop_calc_face_angle(l); + } + + /* store cd_loop_groups */ + if (l_num != 0) { + sv->cd_loop_groups = BLI_memarena_alloc(sod->arena, sod->layer_math_map_num * sizeof(void *)); + for (j = 0; j < sod->layer_math_map_num; j++) { + const int layer_nr = sod->layer_math_map[j]; + sv->cd_loop_groups[j] = BM_vert_loop_groups_data_layer_create(bm, sv->v, layer_nr, loop_weights, sod->arena); + } + } + else { + sv->cd_loop_groups = NULL; + } + + BLI_ghash_insert(sod->origverts, sv->v, sv); +} + static void slide_origdata_create_data( TransInfo *t, SlideOrigData *sod, TransDataGenericSlideVert *sv, unsigned int v_stride, unsigned int v_num) @@ -5250,9 +5287,7 @@ static void slide_origdata_create_data( BMesh *bm = em->bm; unsigned int i; - const int *layer_math_map; int layer_index_dst; - int layer_groups_array_size; int j; /* over alloc, only 'math' layers are indexed */ @@ -5264,41 +5299,14 @@ static void slide_origdata_create_data( } } BLI_assert(layer_index_dst != 0); - layer_math_map = sod->layer_math_map; - layer_groups_array_size = layer_index_dst * sizeof(void *); sod->layer_math_map_num = layer_index_dst; sod->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__); sod->origverts = BLI_ghash_ptr_new_ex(__func__, v_num); - for (i = 0; i < v_num; i++, sv = (void *)(((char *)sv) + v_stride)) { - BMIter fiter; - BMFace *f; - bool has_faces = false; - - /* copy face data */ - BM_ITER_ELEM (f, &fiter, sv->v, BM_FACES_OF_VERT) { - if (!BLI_ghash_haskey(sod->origfaces, f)) { - BMFace *f_copy = BM_face_copy(sod->bm_origfaces, bm, f, true, true); - BLI_ghash_insert(sod->origfaces, f, f_copy); - } - has_faces = true; - } - - /* store cd_loop_groups */ - if (has_faces) { - sv->cd_loop_groups = BLI_memarena_alloc(sod->arena, layer_groups_array_size); - for (j = 0; j < layer_index_dst; j++) { - const int layer_nr = layer_math_map[j]; - sv->cd_loop_groups[j] = BM_vert_loop_groups_data_layer_create(bm, sv->v, layer_nr, sod->arena); - } - } - else { - sv->cd_loop_groups = NULL; - } - - BLI_ghash_insert(sod->origverts, sv->v, sv); + for (i = 0; i < v_num; i++, sv = POINTER_OFFSET(sv, v_stride)) { + slide_origdata_create_data_vert(bm, sod, sv); } } } @@ -5370,7 +5378,7 @@ static void slide_origdata_interp_data( BMesh *bm = em->bm; unsigned int i; - for (i = 0; i < v_num; i++, sv = (void *)(((char *)sv) + v_stride)) { + for (i = 0; i < v_num; i++, sv = POINTER_OFFSET(sv, v_stride)) { if (sv->cd_loop_groups) { slide_origdata_interp_data_vert(sod, bm, is_final, sv); |