From 434521a9e2cc417e932115a3bc40c42b9b77cd92 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 7 Apr 2022 13:02:03 +0200 Subject: Curves: improve Add menu for new curves object The goal is to make the Add menu more convenient for the new curves object. The following changes are done: * Add `curves` submenu. * Add an `Empty Hair` operator that also sets the surface object. * Rename the old operator to `Random`. It's mostly for testing at this point. Differential Revision: https://developer.blender.org/D14556 --- release/scripts/startup/bl_ui/space_view3d.py | 18 ++++++++- source/blender/editors/object/object_add.cc | 55 ++++++++++++++++++++++----- source/blender/editors/object/object_intern.h | 3 +- source/blender/editors/object/object_ops.c | 3 +- 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index dbb28513a51..b31e3209aea 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -2052,6 +2052,19 @@ class VIEW3D_MT_curve_add(Menu): layout.operator("curve.primitive_nurbs_path_add", text="Path", icon='CURVE_PATH') +class VIEW3D_MT_curves_add(Menu): + bl_idname = "VIEW3D_MT_curves_add" + bl_label = "Curves" + + def draw(self, _context): + layout = self.layout + + layout.operator_context = 'INVOKE_REGION_WIN' + + layout.operator("object.curves_empty_hair_add", text="Empty Hair", icon='CURVES_DATA') + layout.operator("object.curves_random_add", text="Random", icon='CURVES_DATA') + + class VIEW3D_MT_surface_add(Menu): bl_idname = "VIEW3D_MT_surface_add" bl_label = "Surface" @@ -2204,12 +2217,12 @@ class VIEW3D_MT_add(Menu): # layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE') layout.menu("VIEW3D_MT_curve_add", icon='OUTLINER_OB_CURVE') + if context.preferences.experimental.use_new_curves_type: + layout.menu("VIEW3D_MT_curves_add", icon='OUTLINER_OB_CURVES') # layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE') layout.menu("VIEW3D_MT_surface_add", icon='OUTLINER_OB_SURFACE') layout.menu("VIEW3D_MT_metaball_add", text="Metaball", icon='OUTLINER_OB_META') layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT') - if context.preferences.experimental.use_new_curves_type: - layout.operator("object.hair_curves_add", text="Hair Curves", icon='OUTLINER_OB_CURVES') if context.preferences.experimental.use_new_point_cloud_type: layout.operator("object.pointcloud_add", text="Point Cloud", icon='OUTLINER_OB_POINTCLOUD') layout.menu("VIEW3D_MT_volume_add", text="Volume", icon='OUTLINER_OB_VOLUME') @@ -7638,6 +7651,7 @@ classes = ( VIEW3D_MT_angle_control, VIEW3D_MT_mesh_add, VIEW3D_MT_curve_add, + VIEW3D_MT_curves_add, VIEW3D_MT_surface_add, VIEW3D_MT_edit_metaball_context_menu, VIEW3D_MT_metaball_add, diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index ba11483722e..b3c5879b4d0 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -2044,10 +2044,10 @@ void OBJECT_OT_speaker_add(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Add Hair Curves Operator +/** \name Add Curves Operator * \{ */ -static bool object_hair_curves_add_poll(bContext *C) +static bool object_curves_add_poll(bContext *C) { if (!U.experimental.use_new_curves_type) { return false; @@ -2055,7 +2055,7 @@ static bool object_hair_curves_add_poll(bContext *C) return ED_operator_objectmode(C); } -static int object_hair_curves_add_exec(bContext *C, wmOperator *op) +static int object_curves_random_add_exec(bContext *C, wmOperator *op) { using namespace blender; @@ -2075,16 +2075,16 @@ static int object_hair_curves_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void OBJECT_OT_hair_curves_add(wmOperatorType *ot) +void OBJECT_OT_curves_random_add(wmOperatorType *ot) { /* identifiers */ - ot->name = "Add Hair Curves"; - ot->description = "Add a hair curves object to the scene"; - ot->idname = "OBJECT_OT_hair_curves_add"; + ot->name = "Add Random Curves"; + ot->description = "Add a curves object with random curves to the scene"; + ot->idname = "OBJECT_OT_curves_random_add"; /* api callbacks */ - ot->exec = object_hair_curves_add_exec; - ot->poll = object_hair_curves_add_poll; + ot->exec = object_curves_random_add_exec; + ot->poll = object_curves_add_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -2092,6 +2092,43 @@ void OBJECT_OT_hair_curves_add(wmOperatorType *ot) ED_object_add_generic_props(ot, false); } +static int object_curves_empty_hair_add_exec(bContext *C, wmOperator *op) +{ + ushort local_view_bits; + float loc[3], rot[3]; + if (!ED_object_add_generic_get_opts( + C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) { + return OPERATOR_CANCELLED; + } + + Object *surface_ob = CTX_data_active_object(C); + + Object *object = ED_object_add_type(C, OB_CURVES, nullptr, loc, rot, false, local_view_bits); + object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */ + + if (surface_ob != nullptr && surface_ob->type == OB_MESH) { + Curves *curves_id = static_cast(object->data); + curves_id->surface = surface_ob; + id_us_plus(&surface_ob->id); + } + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_curves_empty_hair_add(wmOperatorType *ot) +{ + ot->name = "Add Empty Curves"; + ot->description = "Add an empty curve object to the scene with the selected mesh as surface"; + ot->idname = "OBJECT_OT_curves_empty_hair_add"; + + ot->exec = object_curves_empty_hair_add_exec; + ot->poll = object_curves_add_poll; + + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + ED_object_add_generic_props(ot, false); +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 9c44990d586..dd6e11abbf9 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -113,7 +113,8 @@ void OBJECT_OT_light_add(struct wmOperatorType *ot); void OBJECT_OT_effector_add(struct wmOperatorType *ot); void OBJECT_OT_camera_add(struct wmOperatorType *ot); void OBJECT_OT_speaker_add(struct wmOperatorType *ot); -void OBJECT_OT_hair_curves_add(struct wmOperatorType *ot); +void OBJECT_OT_curves_random_add(struct wmOperatorType *ot); +void OBJECT_OT_curves_empty_hair_add(struct wmOperatorType *ot); void OBJECT_OT_pointcloud_add(struct wmOperatorType *ot); /** * Only used as menu. diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index b390cb286ee..cf5c349228f 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -89,7 +89,8 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_light_add); WM_operatortype_append(OBJECT_OT_camera_add); WM_operatortype_append(OBJECT_OT_speaker_add); - WM_operatortype_append(OBJECT_OT_hair_curves_add); + WM_operatortype_append(OBJECT_OT_curves_random_add); + WM_operatortype_append(OBJECT_OT_curves_empty_hair_add); WM_operatortype_append(OBJECT_OT_pointcloud_add); WM_operatortype_append(OBJECT_OT_volume_add); WM_operatortype_append(OBJECT_OT_volume_import); -- cgit v1.2.3