From f78ca97cfcce148eba96e656a235442d3e3e37d1 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sun, 1 Mar 2020 22:19:17 -0600 Subject: Bevel: Z-Up Custom Profile Orientation When beveling architectural objects like baseboards or crown mouldings that may consist of multiple islands, it's useful if the orientation is at least conistent. This changes the arbitrary decision of how the orientation should start at a chain beginning to use the highest side of the profile in the Z direction. Reviewed By: howardt Differential Revision: https://developer.blender.org/D6946 --- source/blender/bmesh/tools/bmesh_bevel.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source/blender/bmesh') diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 0ff89aa3127..e99f6699173 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -3132,22 +3132,22 @@ static EdgeHalf *next_edgehalf_bev(BevelParams *bp, */ static void regularize_profile_orientation(BevelParams *bp, BMEdge *bme) { - BevVert *start_bv; - BevVert *bv; - EdgeHalf *start_edgehalf, *edgehalf; - bool toward_bv; - - start_bv = find_bevvert(bp, bme->v1); - start_edgehalf = find_edge_half(start_bv, bme); + BevVert *start_bv = find_bevvert(bp, bme->v1); + EdgeHalf *start_edgehalf = find_edge_half(start_bv, bme); if (!start_edgehalf->is_bev || start_edgehalf->visited_rpo) { return; } - /* Pick a BoundVert on one side of the profile to use for the start of the profile. */ - start_edgehalf->leftv->is_profile_start = false; + /* Pick a BoundVert on one side of the profile to use for the starting side. Use the one highest + * on the Z axis because even any rule is better than an arbitrary decision. */ + bool right_highest = start_edgehalf->leftv->nv.co[2] < start_edgehalf->rightv->nv.co[2]; + start_edgehalf->leftv->is_profile_start = right_highest; start_edgehalf->visited_rpo = true; /* First loop starts in the away from BevVert direction and the second starts toward it. */ + bool toward_bv; + BevVert *bv; + EdgeHalf *edgehalf; for (int i = 0; i < 2; i++) { edgehalf = start_edgehalf; bv = start_bv; @@ -3160,11 +3160,11 @@ static void regularize_profile_orientation(BevelParams *bp, BMEdge *bme) * The direction relative to the BevVert switches every step, so also switch * the orientation every step. */ if (i == 0) { - edgehalf->leftv->is_profile_start = toward_bv; + edgehalf->leftv->is_profile_start = toward_bv ^ right_highest; } else { /* The opposite side as the first direction because we're moving the other way. */ - edgehalf->leftv->is_profile_start = !toward_bv; + edgehalf->leftv->is_profile_start = !toward_bv ^ right_highest; } /* The next jump will in the opposite direction relative to the BevVert. */ -- cgit v1.2.3