Curves: support more curve type conversion options in edit mode

This adds a new `Handles` checkbox to the conversion operator that
affects how the conversion works in the following cases:
`Bezier -> Catmull Rom / Poly / Nurbs` and `Catmull Rom -> Nurbs`.
If enabled, three control points are added for each original control
point, otherwise only one.

-----

The images show the effect of the toggle. The top result is always the one with handles and the bottom one without.
* `Bezier -> Poly`
  ![image](/attachments/c4833568-fb8a-415e-b4fc-a8af2002ded8)
* `Bezier -> Catmull Rom`
  ![image](/attachments/df62e4c0-1a88-4f04-aa82-506bc40765a2)
* `Bezier -> Nurbs`
  ![image](/attachments/3b78d49d-c840-4c15-a342-050fb1f5c3f5)
* `Catmull Rom -> Nurbs`
  ![image](/attachments/de9a4c08-d442-4f97-a0e0-6393b0f0e6de)

Pull Request: https://projects.blender.org/blender/blender/pulls/120423
This commit is contained in:
Jacques Lucke
2024-04-25 10:56:43 +02:00
parent fa66b52d0a
commit 3f2c4db951
3 changed files with 190 additions and 5 deletions

View File

@@ -1394,6 +1394,7 @@ namespace curve_type_set {
static int exec(bContext *C, wmOperator *op)
{
const CurveType dst_type = CurveType(RNA_enum_get(op->ptr, "type"));
const bool use_handles = RNA_boolean_get(op->ptr, "use_handles");
for (Curves *curves_id : get_unique_editable_curves(*C)) {
bke::CurvesGeometry &curves = curves_id->geometry.wrap();
@@ -1403,7 +1404,13 @@ static int exec(bContext *C, wmOperator *op)
continue;
}
curves = geometry::convert_curves(curves, selection, dst_type, {});
geometry::ConvertCurvesOptions options;
options.convert_bezier_handles_to_poly_points = use_handles;
options.convert_bezier_handles_to_catmull_rom_points = use_handles;
options.keep_bezier_shape_as_nurbs = use_handles;
options.keep_catmull_rom_shape_as_nurbs = use_handles;
curves = geometry::convert_curves(curves, selection, dst_type, {}, options);
DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
@@ -1426,6 +1433,12 @@ static void CURVES_OT_curve_type_set(wmOperatorType *ot)
ot->prop = RNA_def_enum(
ot->srna, "type", rna_enum_curves_type_items, CURVE_TYPE_POLY, "Type", "Curve type");
RNA_def_boolean(ot->srna,
"use_handles",
false,
"Handles",
"Take handle information into account in the conversion");
}
namespace switch_direction {