From 79f76c85442a9a8405d73b5a86c6f63f45c4dc2e Mon Sep 17 00:00:00 2001 From: Howard Trickey Date: Tue, 29 Jan 2019 07:21:59 -0500 Subject: Bevel - better corner shapes for inner arc miters. The subdivision method for getting corner shapes has a fullness parameter which had been set by eye before. This change uses fullness as found by offline search process to best match the superellipsoid octant in the cube corner case (except cube corner case is still handled by other code). This somewhat improves the look of cube corners with inner arc miters, however. --- source/blender/bmesh/tools/bmesh_bevel.c | 45 ++++++++++++++++++++++++-------- source/tools | 2 +- 2 files changed, 35 insertions(+), 12 deletions(-) (limited to 'source') diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 5d4082aded4..159520d6d67 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -209,6 +209,7 @@ typedef struct BevelParams { float offset; /* blender units to offset each side of a beveled edge */ int offset_type; /* how offset is measured; enum defined in bmesh_operators.h */ int seg; /* number of segments in beveled edge profile */ + float profile; /* user profile setting */ float pro_super_r; /* superellipse parameter for edge profile */ bool vertex_only; /* bevel vertices only */ bool use_weights; /* bevel amount affected by weights on edges or verts */ @@ -3592,7 +3593,23 @@ static VMesh *adj_vmesh(BevelParams *bp, BevVert *bv) float co[3], coa[3], cob[3], dir[3]; BoundVert *bndv; MemArena *mem_arena = bp->mem_arena; - float r, fac, fullness; + float r, p, fullness; + /* best fullness for circles, segs = 2,4,6,8,10 */ +#define CIRCLE_FULLNESS_SEGS 11 + static const float circle_fullness[CIRCLE_FULLNESS_SEGS] = { + 0.0f, /* nsegs ==1 */ + 0.559f, /* 2 */ + 0.642f, /* 3 */ + 0.551f, /* 4 */ + 0.646f, /* 5 */ + 0.624f, /* 6 */ + 0.646f, /* 7 */ + 0.619f, /* 8 */ + 0.647f, /* 9 */ + 0.639f, /* 10 */ + 0.647f, /* 11 */ + }; + n = bv->vmesh->count; /* Same bevel as that of 3 edges of vert in a cube */ @@ -3624,20 +3641,25 @@ static VMesh *adj_vmesh(BevelParams *bp, BevVert *bv) mul_v3_fl(co, 1.0f / (float)n); sub_v3_v3v3(cob, co, coa); add_v3_v3(cob, co); + + /* An offline optimization process found fullness that let to closest fit to sphere as + * a function of r and ns (for case of cube corner) */ r = bp->pro_super_r; - if (r == 1.0f) + p = bp->profile; + if (r == PRO_LINE_R) { fullness = 0.0f; - else if (r > 1.0f) { - if (bp->vertex_only) - fac = 0.25f; - else if (r == PRO_SQUARE_R) - fac = -2.0; - else - fac = 0.5f; - fullness = 1.0f - fac / r; + } + else if (r == PRO_CIRCLE_R && ns > 0 && ns <= CIRCLE_FULLNESS_SEGS) { + fullness = circle_fullness[ns - 1]; } else { - fullness = r - 1.0f; + /* linear regression fit found best linear function, separately for even/odd segs */ + if (ns % 2 == 0) { + fullness = 2.4506f * p - 0.00000300f * ns - 0.6266f; + } + else { + fullness = 2.3635f * p + 0.000152f * ns - 0.6060f; + } } sub_v3_v3v3(dir, coa, co); if (len_squared_v3(dir) > BEVEL_EPSILON_SQ) @@ -6030,6 +6052,7 @@ void BM_mesh_bevel( bp.offset = offset; bp.offset_type = offset_type; bp.seg = segments; + bp.profile = profile; bp.pro_super_r = -log(2.0) / log(sqrt(profile)); /* convert to superellipse exponent */ bp.vertex_only = vertex_only; bp.use_weights = use_weights; diff --git a/source/tools b/source/tools index aef8f32086b..83428cbf0a8 160000 --- a/source/tools +++ b/source/tools @@ -1 +1 @@ -Subproject commit aef8f32086b9393d286c49cbe5a51ae465fe0589 +Subproject commit 83428cbf0a8d7e0bdd7a91c00124381c1db42e70 -- cgit v1.2.3