Curves: add edit mode operator to convert curve types
This operator shares the underlying code with the corresponding node. Pull Request: https://projects.blender.org/blender/blender/pulls/120269
This commit is contained in:
parent
7f68026990
commit
23265a2b6d
@ -5912,6 +5912,7 @@ class VIEW3D_MT_edit_curves(Menu):
|
||||
layout.operator("curves.attribute_set")
|
||||
layout.operator("curves.delete")
|
||||
layout.operator("curves.cyclic_toggle")
|
||||
layout.operator_menu_enum("curves.curve_type_set", "type")
|
||||
layout.template_node_operator_asset_menu_items(catalog_path=self.bl_label)
|
||||
|
||||
|
||||
|
@ -64,6 +64,7 @@
|
||||
#include "UI_resources.hh"
|
||||
|
||||
#include "GEO_reverse_uv_sampler.hh"
|
||||
#include "GEO_set_curve_type.hh"
|
||||
|
||||
/**
|
||||
* The code below uses a suffix naming convention to indicate the coordinate space:
|
||||
@ -1383,6 +1384,45 @@ static void CURVES_OT_cyclic_toggle(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
namespace curve_type_set {
|
||||
|
||||
static int exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
const CurveType dst_type = CurveType(RNA_enum_get(op->ptr, "type"));
|
||||
|
||||
for (Curves *curves_id : get_unique_editable_curves(*C)) {
|
||||
bke::CurvesGeometry &curves = curves_id->geometry.wrap();
|
||||
IndexMaskMemory memory;
|
||||
const IndexMask selection = retrieve_selected_curves(*curves_id, memory);
|
||||
if (selection.is_empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
curves = geometry::convert_curves(curves, selection, dst_type, {});
|
||||
|
||||
DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
|
||||
}
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
} // namespace curve_type_set
|
||||
|
||||
static void CURVES_OT_curve_type_set(wmOperatorType *ot)
|
||||
{
|
||||
ot->name = "Set Curve Type";
|
||||
ot->idname = __func__;
|
||||
ot->description = "Set type of selected curves";
|
||||
|
||||
ot->exec = curve_type_set::exec;
|
||||
ot->poll = editable_curves_in_edit_mode_poll;
|
||||
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
ot->prop = RNA_def_enum(
|
||||
ot->srna, "type", rna_enum_curves_type_items, CURVE_TYPE_POLY, "Type", "Curve type");
|
||||
}
|
||||
|
||||
void operatortypes_curves()
|
||||
{
|
||||
WM_operatortype_append(CURVES_OT_attribute_set);
|
||||
@ -1403,6 +1443,7 @@ void operatortypes_curves()
|
||||
WM_operatortype_append(CURVES_OT_duplicate);
|
||||
WM_operatortype_append(CURVES_OT_tilt_clear);
|
||||
WM_operatortype_append(CURVES_OT_cyclic_toggle);
|
||||
WM_operatortype_append(CURVES_OT_curve_type_set);
|
||||
}
|
||||
|
||||
void operatormacros_curves()
|
||||
|
Loading…
Reference in New Issue
Block a user