From 29acdb48899a25c32726ee8411088d8086a5cdb4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 Mar 2016 22:07:45 +1100 Subject: [PATCH] Mesh API: add BKE_mesh_vert_edge_vert_map_create Handy when you need to reference connected verts directly. --- source/blender/blenkernel/BKE_mesh_mapping.h | 3 ++ .../blender/blenkernel/intern/mesh_mapping.c | 43 +++++++++++++++++++ source/blender/editors/object/object_vgroup.c | 7 +-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h index c8a17008f5d..e4b2b8ae9b6 100644 --- a/source/blender/blenkernel/BKE_mesh_mapping.h +++ b/source/blender/blenkernel/BKE_mesh_mapping.h @@ -119,6 +119,9 @@ void BKE_mesh_vert_loop_map_create( void BKE_mesh_vert_edge_map_create( MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, int totvert, int totedge); +void BKE_mesh_vert_edge_vert_map_create( + MeshElemMap **r_map, int **r_mem, + const struct MEdge *medge, int totvert, int totedge); void BKE_mesh_edge_poly_map_create( MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, const int totedge, diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index 8dce3c372f6..c8bb2e0e758 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -304,6 +304,49 @@ void BKE_mesh_vert_edge_map_create(MeshElemMap **r_map, int **r_mem, *r_mem = indices; } +/** + * A version of #BKE_mesh_vert_edge_map_create that references connected vertices directly (not their edges). + */ +void BKE_mesh_vert_edge_vert_map_create( + MeshElemMap **r_map, int **r_mem, + const MEdge *medge, int totvert, int totedge) +{ + MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)totvert, "vert-edge map"); + int *indices = MEM_mallocN(sizeof(int[2]) * (size_t)totedge, "vert-edge map mem"); + int *i_pt = indices; + + int i; + + /* Count number of edges for each vertex */ + for (i = 0; i < totedge; i++) { + map[medge[i].v1].count++; + map[medge[i].v2].count++; + } + + /* Assign indices mem */ + for (i = 0; i < totvert; i++) { + map[i].indices = i_pt; + i_pt += map[i].count; + + /* Reset 'count' for use as index in last loop */ + map[i].count = 0; + } + + /* Find the users */ + for (i = 0; i < totedge; i++) { + const unsigned int v[2] = {medge[i].v1, medge[i].v2}; + + map[v[0]].indices[map[v[0]].count] = (int)v[1]; + map[v[1]].indices[map[v[1]].count] = (int)v[0]; + + map[v[0]].count++; + map[v[1]].count++; + } + + *r_map = map; + *r_mem = indices; +} + /** * Generates a map where the key is the edge and the value is a list of polygons that use that edge. * The lists are allocated from one memory pool. diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index cc147464445..4619f998a11 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1792,11 +1792,8 @@ static void vgroup_smooth_subset( for (int i = 0; i < dvert_tot; i++) { MVert *v = &me->mvert[i]; if (v->flag & SELECT) { - int j; - for (j = 0; j < emap[i].count; j++) { - MEdge *e = &me->medge[emap[i].indices[j]]; - const int i_other = (e->v1 == i ? e->v2 : e->v1); - MVert *v_other = &me->mvert[i_other]; + for (int j = 0; j < emap[i].count; j++) { + MVert *v_other = &me->mvert[emap[i].indices[j]]; if ((source == WEIGHT_SMOOTH_ALL) || (source == ((v_other->flag & SELECT) != 0))) {