From d5a705873e11510950b899caebd43ba47d69ccfa Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Wed, 17 Mar 2021 09:21:32 +0100 Subject: Join curves: compensate for different bevel depths When joining curves, the resulting curve will inherit the bevel depth of the active curve, but the radii would stay the same which leads to changed appearance when joining. Now compensate for this taking the different bevel depths into account (if present). Was a feature request here (and I also think we had reports about this -- which were usually turned down as not-a-bug): https://blender.community/c/rightclickselect/bhhbbc/ Differential Revision: https://developer.blender.org/D10752 --- source/blender/editors/curve/editcurve.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source/blender/editors/curve') diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 33ef6a5d026..c3ec87dc0d9 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -6872,6 +6872,8 @@ int ED_curve_join_objects_exec(bContext *C, wmOperator *op) * See #object_join_exec for detailed comment on why the safe version is used. */ invert_m4_m4_safe_ortho(imat, ob_active->obmat); + Curve *cu_active = ob_active->data; + CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { if (ob_iter->type == ob_active->type) { if (ob_iter != ob_active) { @@ -6882,6 +6884,15 @@ int ED_curve_join_objects_exec(bContext *C, wmOperator *op) /* watch it: switch order here really goes wrong */ mul_m4_m4m4(cmat, imat, ob_iter->obmat); + /* Compensate for different bevel depth. */ + bool do_radius = false; + float compensate_radius = 0.0f; + if (cu->ext2 != 0.0f && cu_active->ext2 != 0.0f) { + float compensate_scale = mat4_to_scale(cmat); + compensate_radius = cu->ext2 / cu_active->ext2 * compensate_scale; + do_radius = true; + } + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { Nurb *newnu = BKE_nurb_duplicate(nu); if (ob_active->totcol) { /* TODO, merge material lists */ @@ -6895,6 +6906,11 @@ int ED_curve_join_objects_exec(bContext *C, wmOperator *op) if ((bezt = newnu->bezt)) { a = newnu->pntsu; while (a--) { + /* Compensate for different bevel depth. */ + if (do_radius) { + bezt->radius *= compensate_radius; + } + mul_m4_v3(cmat, bezt->vec[0]); mul_m4_v3(cmat, bezt->vec[1]); mul_m4_v3(cmat, bezt->vec[2]); -- cgit v1.2.3