From 718d545ff88f3092f4bd6baef3e3d5642109da0c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 15 Sep 2022 16:42:37 +1000 Subject: Cleanup: minor improvement to boundary check Use a byte flag instead of counting polys using edges (technically a fix for edges with USHRT_MAX+2 users). --- source/blender/modifiers/intern/MOD_correctivesmooth.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'source') diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index 4fdbe44281b..5e46e98263c 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -130,25 +130,24 @@ static void mesh_get_boundaries(Mesh *mesh, float *smooth_weights) const MEdge *medge = BKE_mesh_edges(mesh); const MPoly *mpoly = BKE_mesh_polys(mesh); const MLoop *mloop = BKE_mesh_loops(mesh); - uint mpoly_num, medge_num, i; - ushort *boundaries; - mpoly_num = (uint)mesh->totpoly; - medge_num = (uint)mesh->totedge; + const uint mpoly_num = (uint)mesh->totpoly; + const uint medge_num = (uint)mesh->totedge; - boundaries = MEM_calloc_arrayN(medge_num, sizeof(*boundaries), __func__); + /* Flag boundary edges so only boundaries are set to 1. */ + uint8_t *boundaries = MEM_calloc_arrayN(medge_num, sizeof(*boundaries), __func__); - /* count the number of adjacent faces */ - for (i = 0; i < mpoly_num; i++) { + for (uint i = 0; i < mpoly_num; i++) { const MPoly *p = &mpoly[i]; const int totloop = p->totloop; int j; for (j = 0; j < totloop; j++) { - boundaries[mloop[p->loopstart + j].e]++; + uint8_t *e_value = &boundaries[mloop[p->loopstart + j].e]; + *e_value |= (*e_value) + 1; } } - for (i = 0; i < medge_num; i++) { + for (uint i = 0; i < medge_num; i++) { if (boundaries[i] == 1) { smooth_weights[medge[i].v1] = 0.0f; smooth_weights[medge[i].v2] = 0.0f; -- cgit v1.2.3