[Bf-blender-cvs] [07032dd2189] master: Curves: add initial sculpt mode

Jacques Lucke noreply at git.blender.org
Tue Feb 15 12:34:40 CET 2022


Commit: 07032dd218922d2f1ba3275470bee01579f739c7
Author: Jacques Lucke
Date:   Tue Feb 15 12:32:15 2022 +0100
Branches: master
https://developer.blender.org/rB07032dd218922d2f1ba3275470bee01579f739c7

Curves: add initial sculpt mode

This adds a new sculpt mode to the experimental new curves object.
Currently, this mode can only be entered and exited, nothing else.
The main initial purpose of this node will be to use it for hair grooming.

The patch also adds the `editors/curves/` directory for the new curves
object, which will be necessary for many other things as well.

I added a completely new mode (`OB_MODE_SCULPT_CURVES`), because
`OB_MODE_SCULPT` seems to be rather specific to meshes, and reusing
it doesn't seem worth the trouble. The tools/brushes used in mesh vs.
curves sculpt mode are quite distinct as well.

I had to add DNA_userdef_enums.h to make the patch compile with C++
(forward declaration of enums isn't allowed). This follows the same
pattern that we use for other enums in dna.

Differential Revision: https://developer.blender.org/D14107

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/editors/CMakeLists.txt
A	source/blender/editors/curves/CMakeLists.txt
A	source/blender/editors/curves/intern/curves_ops.cc
A	source/blender/editors/include/ED_curves.h
M	source/blender/editors/include/ED_object.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/object/object_modes.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/util/CMakeLists.txt
M	source/blender/makesdna/DNA_object_enums.h
A	source/blender/makesdna/DNA_userdef_enums.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/rna_context.c
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/windowmanager/intern/wm_keymap_utils.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index cc2f821b049..e93d9179f82 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -823,7 +823,7 @@ class VIEW3D_MT_editor_menus(Menu):
                 layout.menu("VIEW3D_MT_select_paint_mask")
             elif mesh.use_paint_mask_vertex and mode_string in {'PAINT_WEIGHT', 'PAINT_VERTEX'}:
                 layout.menu("VIEW3D_MT_select_paint_mask_vertex")
-        elif mode_string != 'SCULPT':
+        elif mode_string not in ('SCULPT', 'SCULPT_CURVES'):
             layout.menu("VIEW3D_MT_select_%s" % mode_string.lower())
 
         if gp_edit:
@@ -866,7 +866,7 @@ class VIEW3D_MT_editor_menus(Menu):
                 layout.menu("VIEW3D_MT_edit_curve_segments")
 
         elif obj:
-            if mode_string != 'PAINT_TEXTURE':
+            if mode_string not in ('PAINT_TEXTURE', 'SCULPT_CURVES'):
                 layout.menu("VIEW3D_MT_%s" % mode_string.lower())
             if mode_string == 'SCULPT':
                 layout.menu("VIEW3D_MT_mask")
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index aca3f99d55f..dee163a9797 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -74,6 +74,7 @@ set(SRC_DNA_INC
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_text_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_texture_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_tracking_types.h
+  ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_userdef_enums.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_userdef_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_uuid_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_vec_types.h
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 80a500fe3c0..52de39f3ed9 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -118,8 +118,9 @@ typedef enum eContextObjectMode {
   CTX_MODE_SCULPT_GPENCIL,
   CTX_MODE_WEIGHT_GPENCIL,
   CTX_MODE_VERTEX_GPENCIL,
+  CTX_MODE_SCULPT_CURVES,
 } eContextObjectMode;
-#define CTX_MODE_NUM (CTX_MODE_VERTEX_GPENCIL + 1)
+#define CTX_MODE_NUM (CTX_MODE_SCULPT_CURVES + 1)
 
 /* Context */
 
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 3f524eaf230..d1374958763 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1198,6 +1198,9 @@ enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit,
       if (object_mode & OB_MODE_VERTEX_GPENCIL) {
         return CTX_MODE_VERTEX_GPENCIL;
       }
+      if (object_mode & OB_MODE_SCULPT_CURVES) {
+        return CTX_MODE_SCULPT_CURVES;
+      }
     }
   }
 
@@ -1217,11 +1220,27 @@ enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
  * \note Must be aligned with above enum.
  */
 static const char *data_mode_strings[] = {
-    "mesh_edit",           "curve_edit",          "surface_edit",        "text_edit",
-    "armature_edit",       "mball_edit",          "lattice_edit",        "posemode",
-    "sculpt_mode",         "weightpaint",         "vertexpaint",         "imagepaint",
-    "particlemode",        "objectmode",          "greasepencil_paint",  "greasepencil_edit",
-    "greasepencil_sculpt", "greasepencil_weight", "greasepencil_vertex", NULL,
+    "mesh_edit",
+    "curve_edit",
+    "surface_edit",
+    "text_edit",
+    "armature_edit",
+    "mball_edit",
+    "lattice_edit",
+    "posemode",
+    "sculpt_mode",
+    "weightpaint",
+    "vertexpaint",
+    "imagepaint",
+    "particlemode",
+    "objectmode",
+    "greasepencil_paint",
+    "greasepencil_edit",
+    "greasepencil_sculpt",
+    "greasepencil_weight",
+    "greasepencil_vertex",
+    "curves_sculpt",
+    NULL,
 };
 BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings) == CTX_MODE_NUM + 1,
                   "Must have a string for each context mode")
diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt
index 2203c08dc50..9fff8bf861c 100644
--- a/source/blender/editors/CMakeLists.txt
+++ b/source/blender/editors/CMakeLists.txt
@@ -9,6 +9,7 @@ if(WITH_BLENDER)
   add_subdirectory(armature)
   add_subdirectory(asset)
   add_subdirectory(curve)
+  add_subdirectory(curves)
   add_subdirectory(geometry)
   add_subdirectory(gizmo_library)
   add_subdirectory(gpencil)
diff --git a/source/blender/editors/curves/CMakeLists.txt b/source/blender/editors/curves/CMakeLists.txt
new file mode 100644
index 00000000000..d2b7dacbc20
--- /dev/null
+++ b/source/blender/editors/curves/CMakeLists.txt
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set(INC
+  ../include
+  ../../blenkernel
+  ../../blenlib
+  ../../blentranslation
+  ../../depsgraph
+  ../../makesdna
+  ../../makesrna
+  ../../windowmanager
+  ../../../../intern/guardedalloc
+)
+
+set(SRC
+  intern/curves_ops.cc
+)
+
+set(LIB
+  bf_blenkernel
+  bf_blenlib
+)
+
+blender_add_lib(bf_editor_curves "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc
new file mode 100644
index 00000000000..fdda8e636f7
--- /dev/null
+++ b/source/blender/editors/curves/intern/curves_ops.cc
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup edcurves
+ */
+
+#include "BLI_utildefines.h"
+
+#include "ED_curves.h"
+#include "ED_object.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BKE_context.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_types.h"
+
+static bool curves_sculptmode_toggle_poll(bContext *C)
+{
+  Object *ob = CTX_data_active_object(C);
+  if (ob == nullptr) {
+    return false;
+  }
+  if (ob->type != OB_CURVES) {
+    return false;
+  }
+  return true;
+}
+
+static int curves_sculptmode_toggle_exec(bContext *C, wmOperator *op)
+{
+  Object *ob = CTX_data_active_object(C);
+  const bool is_mode_set = ob->mode == OB_MODE_SCULPT_CURVES;
+
+  if (is_mode_set) {
+    if (!ED_object_mode_compat_set(C, ob, OB_MODE_SCULPT_CURVES, op->reports)) {
+      return OPERATOR_CANCELLED;
+    }
+  }
+
+  if (is_mode_set) {
+    ob->mode = OB_MODE_OBJECT;
+  }
+  else {
+    ob->mode = OB_MODE_SCULPT_CURVES;
+  }
+
+  WM_event_add_notifier(C, NC_SCENE | ND_MODE, nullptr);
+  return OPERATOR_CANCELLED;
+}
+
+static void CURVES_OT_sculptmode_toggle(wmOperatorType *ot)
+{
+  ot->name = "Curve Sculpt Mode Toggle";
+  ot->idname = "CURVES_OT_sculptmode_toggle";
+  ot->description = "Enter/Exit sculpt mode for curves";
+
+  ot->exec = curves_sculptmode_toggle_exec;
+  ot->poll = curves_sculptmode_toggle_poll;
+
+  ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
+}
+
+void ED_operatortypes_curves()
+{
+  WM_operatortype_append(CURVES_OT_sculptmode_toggle);
+}
diff --git a/source/blender/editors/include/ED_curves.h b/source/blender/editors/include/ED_curves.h
new file mode 100644
index 00000000000..7316b045646
--- /dev/null
+++ b/source/blender/editors/include/ED_curves.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup editors
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void ED_operatortypes_curves(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h
index 53d6d88f5b9..abadbe5a5c6 100644
--- a/source/blender/editors/include/ED_object.h
+++ b/source/blender/editors/include/ED_object.h
@@ -9,6 +9,7 @@
 
 #include "BLI_compiler_attrs.h"
 #include "DNA_object_enums.h"
+#include "DNA_userdef_enums.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index e7e2706d5f9..e277aa2e629 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -2354,6 +2354,7 @@ int UI_icon_from_object_mode(const int mode)
       return ICON_EDITMODE_HLT;
     case OB_MODE_SCULPT:
     case OB_MODE_SCULPT_GPENCIL:
+    case OB_MODE_SCULPT_CURVES:
       return ICON_SCULPTMODE_HLT;
     case OB_MODE_VERTEX_PAINT:
     case OB_MODE_VERTEX_GPENCIL:
diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c
index c586527973d..509e496c39a 100644
--- a/source/blender/editors/object/object_modes.c
+++ b/source/blender/editors/object/object_modes.c
@@ -94,6 +94,9 @@ static const char *object_mode_op_string(eObjectMode mode)
   if (mode == OB_MODE_VERTEX_GPENCIL) {
     return "GPENCIL_OT_vertexmode_toggle";
   }
+  if (mode == OB_MODE_SCULPT_CURVES) {
+    return "CURVES_OT_sculptmode_toggle";
+  }
   return NULL;
 }
 
@@ -139,6 +142,11 @@ bool ED_object_mode_compat_test(const Object *ob, eObjectMode mode)
         return true;
       }
       break;
+    case OB_CURVES:
+      if (mode & (OB_MODE_SCULPT_CURVES)) {
+        return true;
+      }
+      break;
   }
 
   return false;
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index d27782877ce..897091731a4 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -28,6 +28,7 @@
 #include "ED_asset.h"
 #include "ED_clip.h"
 #include "ED_curve.h"
+#include "ED_curves.h"
 #include "ED_fileselect.h"
 #include "ED_geometry.h"
 #include "ED_gizmo_library.h"
@@ -99,6 +100,7 @@ void ED_spacetypes_init(void)
   ED_operatortypes_paint();
   ED_operatortypes_physics();
   ED_operatortypes_curve();
+  ED_operatortypes_curves();
   ED_operatortypes_armature();
   ED_operatortypes_marker();
   ED_operatortypes_metaball();
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt
index b01a696edc5..2300e664dfa 100644
--- a/source/blender/editors/util/CMakeLists.txt
+++ b/source/blender/editors/util/CMakeLists.txt
@@ -39,6 +39,7 @@ set(SRC
   ../include/ED_buttons.h
   ../include/ED_clip.h
   ../include/ED_curve.h
+  ../include/ED_curves.h
   ../include/ED_datafiles.h
   ../in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list