Bevel: add new 'Absolute' mode for interpreting 'amount' value.

This mode is like Percent, but measures absolute distance along
adjacent edges instead of a percentage.
So, for example, if you use this mode with 2 segments and profile=1,
you will see the length that the bevel moves along unbeveled edges
between beveled ones will match the value specified.
Many users seem to expect this behavior, even though it means the
bevel width is uneven, so this option is for them.
This commit is contained in:
Howard Trickey 2020-06-19 17:56:01 -04:00
parent ab72cd2fc1
commit 466e716495
Notes: blender-bot 2023-02-14 09:33:11 +01:00
Referenced by issue #78053, Crash on startup on old laptop
7 changed files with 34 additions and 2 deletions

View File

@ -1724,6 +1724,7 @@ static BMO_FlagSet bmo_enum_bevel_offset_type[] = {
{BEVEL_AMT_WIDTH, "WIDTH"},
{BEVEL_AMT_DEPTH, "DEPTH"},
{BEVEL_AMT_PERCENT, "PERCENT"},
{BEVEL_AMT_ABSOLUTE, "ABSOLUTE"},
{0, NULL},
};

View File

@ -109,6 +109,7 @@ enum {
BEVEL_AMT_WIDTH,
BEVEL_AMT_DEPTH,
BEVEL_AMT_PERCENT,
BEVEL_AMT_ABSOLUTE,
};
/* Bevel face_strength_mode values: should match face_str mode enum in DNA_modifer_types.h */

View File

@ -5949,12 +5949,23 @@ static BevVert *bevel_vert_construct(BMesh *bm, BevelParams *bp, BMVert *v)
z = sinf(angle_v3v3v3(v1->co, v->co, v2->co));
e->offset_r_spec = BM_edge_calc_length(e->next->e) * bp->offset * z / 100.0f;
break;
case BEVEL_AMT_ABSOLUTE:
/* Like Percent, but the amount gives the absolute distance along adjacent edges. */
v1 = BM_edge_other_vert(e->prev->e, v);
v2 = BM_edge_other_vert(e->e, v);
z = sinf(angle_v3v3v3(v1->co, v->co, v2->co));
e->offset_l_spec = bp->offset * z;
v1 = BM_edge_other_vert(e->e, v);
v2 = BM_edge_other_vert(e->next->e, v);
z = sinf(angle_v3v3v3(v1->co, v->co, v2->co));
e->offset_r_spec = bp->offset * z;
break;
default:
BLI_assert(!"bad bevel offset kind");
e->offset_l_spec = bp->offset;
break;
}
if (bp->offset_type != BEVEL_AMT_PERCENT) {
if (bp->offset_type != BEVEL_AMT_PERCENT && bp->offset_type != BEVEL_AMT_ABSOLUTE) {
e->offset_r_spec = e->offset_l_spec;
}
if (bp->use_weights) {
@ -6000,6 +6011,10 @@ static BevVert *bevel_vert_construct(BMesh *bm, BevelParams *bp, BMVert *v)
e->offset_l_spec = BM_edge_calc_length(e->e) * bv->offset / 100.0f;
break;
}
case BEVEL_AMT_ABSOLUTE: {
e->offset_l_spec = bv->offset;
break;
}
}
e->offset_r_spec = e->offset_l_spec;
}
@ -7282,7 +7297,8 @@ void BM_mesh_bevel(BMesh *bm,
}
/* Perhaps do a pass to try to even out widths. */
if (!bp.vertex_only && bp.offset_adjust && bp.offset_type != BEVEL_AMT_PERCENT) {
if (!bp.vertex_only && bp.offset_adjust && bp.offset_type != BEVEL_AMT_PERCENT &&
bp.offset_type != BEVEL_AMT_ABSOLUTE) {
adjust_offsets(&bp, bm);
}

View File

@ -1012,6 +1012,11 @@ void MESH_OT_bevel(wmOperatorType *ot)
"Depth",
"Amount is perpendicular distance from original edge to bevel face"},
{BEVEL_AMT_PERCENT, "PERCENT", 0, "Percent", "Amount is percent of adjacent edge length"},
{BEVEL_AMT_ABSOLUTE,
"ABSOLUTE",
0,
"Absolute",
"Amount is absolute distance along adjacent edge"},
{0, NULL, 0, NULL, NULL},
};

View File

@ -446,6 +446,7 @@ enum {
MOD_BEVEL_AMT_WIDTH = 1,
MOD_BEVEL_AMT_DEPTH = 2,
MOD_BEVEL_AMT_PERCENT = 3,
MOD_BEVEL_AMT_ABSOLUTE = 4,
};
/* BevelModifierData->edge_flags */

View File

@ -3948,6 +3948,11 @@ static void rna_def_modifier_bevel(BlenderRNA *brna)
0,
"Percent",
"Amount is percent of adjacent edge length"},
{MOD_BEVEL_AMT_ABSOLUTE,
"ABSOLUTE",
0,
"Absolute",
"Amount is absolute distance along adjacent edge"},
{0, NULL, 0, NULL, NULL},
};

View File

@ -302,6 +302,9 @@ static void panel_draw(const bContext *C, Panel *panel)
case BEVEL_AMT_OFFSET:
offset_name = "Offset";
break;
case BEVEL_AMT_ABSOLUTE:
offset_name = "Absolute";
break;
}
uiItemR(col, &ptr, "width", 0, IFACE_(offset_name), ICON_NONE);
}