[Bf-blender-cvs] [0156a677c7d] master: Sculpt: New Cavity Automasking Mode

Joseph Eagar noreply at git.blender.org
Thu Sep 29 01:27:52 CEST 2022


Commit: 0156a677c7d13106a1d049d74fca43b5311eb53e
Author: Joseph Eagar
Date:   Wed Sep 28 16:22:34 2022 -0700
Branches: master
https://developer.blender.org/rB0156a677c7d13106a1d049d74fca43b5311eb53e

Sculpt: New Cavity Automasking Mode

Add new cavity automasking mode based on local mesh
curvature.  Cavity masking is a great way to quickly add
detail in crevices and the like.  It's meant to be used
with the Paint brush in color attribute mode.  It does
work with other brushes but the results can be unpredictable.

{F13131497}

The old "dirty mask" operator has been replace with a new
"mask from cavity" operator that shares the same code with
cavity automasking.

Differences from the sculpt-dev implementation:
    * It uses the word "cavity."  When I first implemented
this I wasn't aware
      this feature existed in other software (and other
paint modes in Blender),
      and for reasons that escape me today I initially
decided to call it a concave or
      concavity mask.
    * The cavity factor works a bit differently.  It's
      no longer non-linear and functions as a simple
      scale around 0.5f.
    * Supports custom curves.
    * Supports blurring.

Reviewed By: Julian Kaspar, Jeroen Bakker and Campbell Barton
Differential Revision: https://developer.blender.org/D15122
Ref D15122

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/brush.cc
M	source/blender/blenkernel/intern/paint.cc
M	source/blender/blenkernel/intern/scene.cc
M	source/blender/blenloader/intern/versioning_300.cc
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_automasking.cc
M	source/blender/editors/sculpt_paint/sculpt_expand.c
M	source/blender/editors/sculpt_paint/sculpt_filter_color.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mask.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_ops.c
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/makesdna/DNA_brush_defaults.h
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c
M	tests/python/bl_run_operators.py

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 9b1cf11f6e7..a4a328fce1a 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -943,8 +943,22 @@ def brush_settings_advanced(layout, context, brush, popover=False):
         # boundary edges/face sets automasking
         col.prop(brush, "use_automasking_boundary_edges", text="Mesh Boundary")
         col.prop(brush, "use_automasking_boundary_face_sets", text="Face Sets Boundary")
+        col.prop(brush, "use_automasking_cavity", text="Cavity")
+        col.prop(brush, "use_automasking_cavity_inverted", text="Cavity (Inverted)")
+
+        col.separator()
         col.prop(brush, "automasking_boundary_edges_propagation_steps")
 
+        if brush.use_automasking_cavity or brush.use_automasking_cavity_inverted:
+            col.separator()
+
+            col.prop(brush, "automasking_cavity_factor", text="Cavity Factor")
+            col.prop(brush, "automasking_cavity_blur_steps", text="Cavity Blur")
+            col.prop(brush, "use_automasking_custom_cavity_curve", text="Use Curve")
+
+            if brush.use_automasking_custom_cavity_curve:
+                col.template_curve_mapping(brush, "automasking_cavity_curve")
+
         layout.separator()
 
         # sculpt plane settings
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 092fae671e0..fcf00ee80f6 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3298,7 +3298,8 @@ class VIEW3D_MT_mask(Menu):
 
         layout.separator()
 
-        props = layout.operator("sculpt.dirty_mask", text='Dirty Mask')
+        props = layout.operator("sculpt.mask_from_cavity", text="Mask From Cavity")
+        props.use_automask_settings = False
 
         layout.separator()
 
@@ -5494,6 +5495,8 @@ class VIEW3D_MT_sculpt_automasking_pie(Menu):
         pie.prop(sculpt, "use_automasking_face_sets", text="Face Sets")
         pie.prop(sculpt, "use_automasking_boundary_edges", text="Mesh Boundary")
         pie.prop(sculpt, "use_automasking_boundary_face_sets", text="Face Sets Boundary")
+        pie.prop(sculpt, "use_automasking_cavity", text="Cavity")
+        pie.prop(sculpt, "use_automasking_cavity_inverted", text="Cavity (Inverted)")
 
 
 class VIEW3D_MT_sculpt_face_sets_edit_pie(Menu):
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 12e05840cfa..153bce78ec2 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
-from bpy.types import Menu, Panel, UIList
+from bpy.types import Menu, Panel, UIList, WindowManager
 from bl_ui.properties_grease_pencil_common import (
     GreasePencilSculptAdvancedPanel,
     GreasePencilDisplayPanel,
@@ -939,7 +939,6 @@ class VIEW3D_PT_sculpt_voxel_remesh(Panel, View3DPaintPanel):
 
         layout.operator("object.voxel_remesh", text="Remesh")
 
-
 # TODO, move to space_view3d.py
 class VIEW3D_PT_sculpt_options(Panel, View3DPaintPanel):
     bl_context = ".sculpt_mode"  # dot on purpose (access from topbar)
@@ -967,10 +966,33 @@ class VIEW3D_PT_sculpt_options(Panel, View3DPaintPanel):
         col.separator()
 
         col = layout.column(heading="Auto-Masking", align=True)
+
         col.prop(sculpt, "use_automasking_topology", text="Topology")
         col.prop(sculpt, "use_automasking_face_sets", text="Face Sets")
         col.prop(sculpt, "use_automasking_boundary_edges", text="Mesh Boundary")
         col.prop(sculpt, "use_automasking_boundary_face_sets", text="Face Sets Boundary")
+        col.prop(sculpt, "use_automasking_cavity", text="Cavity")
+        col.prop(sculpt, "use_automasking_cavity_inverted", text="Cavity (Inverted)")
+
+        col.separator()
+        col.prop(sculpt.brush, "automasking_boundary_edges_propagation_steps")
+
+        if sculpt.use_automasking_cavity or sculpt.use_automasking_cavity_inverted:
+            col.separator()
+
+            col2 = col.column()
+            props = col2.operator("sculpt.mask_from_cavity", text="Mask From Cavity")
+            props.use_automask_settings = True
+
+            col2 = col.column()
+            
+            col2.prop(sculpt, "automasking_cavity_factor", text="Cavity Factor")
+            col2.prop(sculpt, "automasking_cavity_blur_steps", text="Cavity Blur")
+            
+            col2.prop(sculpt, "use_automasking_custom_cavity_curve", text="Use Curve")
+
+            if sculpt.use_automasking_custom_cavity_curve:
+                col2.template_curve_mapping(sculpt, "automasking_cavity_curve")
 
 
 class VIEW3D_PT_sculpt_options_gravity(Panel, View3DPaintPanel):
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 244c5d4609f..b6dd25d9f29 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -19,13 +19,13 @@ extern "C" {
 /* Blender major and minor version. */
 #define BLENDER_VERSION 304
 /* Blender patch version for bugfix releases. */
-#define BLENDER_VERSION_PATCH 0
+#define BLENDER_VERSION_PATCH 1
 /** Blender release cycle stage: alpha/beta/rc/release. */
 #define BLENDER_VERSION_CYCLE alpha
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 1
+#define BLENDER_FILE_SUBVERSION 2
 
 /* Minimum Blender version that supports reading file written with the current
  * version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index ed0969a6306..386fecfd278 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -52,6 +52,7 @@ struct Palette;
 struct PaletteColor;
 struct Scene;
 struct StrokeCache;
+struct Sculpt;
 struct SubdivCCG;
 struct Tex;
 struct ToolSettings;
@@ -473,6 +474,11 @@ typedef struct SculptBoundary {
   } twist;
 } SculptBoundary;
 
+typedef struct CavityMaskData {
+  float factor;
+  int stroke_id;
+} CavityMaskData;
+
 typedef struct SculptFakeNeighbors {
   bool use_fake_neighbors;
 
@@ -552,6 +558,9 @@ typedef struct SculptAttributePointers {
   /* BMesh */
   SculptAttribute *dyntopo_node_id_vertex;
   SculptAttribute *dyntopo_node_id_face;
+
+  SculptAttribute *stroke_id;
+  SculptAttribute *cavity;
 } SculptAttributePointers;
 
 typedef struct SculptSession {
@@ -743,6 +752,9 @@ typedef struct SculptSession {
    */
   char *last_paint_canvas_key;
 
+  uchar stroke_id;
+  int last_automasking_settings_hash;
+  uchar last_cavity_stroke_id;
 } SculptSession;
 
 void BKE_sculptsession_free(struct Object *ob);
@@ -900,6 +912,8 @@ bool BKE_paint_canvas_image_get(struct PaintModeSettings *settings,
                                 struct ImageUser **r_image_user);
 int BKE_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
                                            struct Object *ob);
+void BKE_sculpt_check_cavity_curves(struct Sculpt *sd);
+struct CurveMapping *BKE_sculpt_default_cavity_curve(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/brush.cc b/source/blender/blenkernel/intern/brush.cc
index 3708090f8ed..fb8a6785f64 100644
--- a/source/blender/blenkernel/intern/brush.cc
+++ b/source/blender/blenkernel/intern/brush.cc
@@ -72,6 +72,8 @@ static void brush_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
   }
 
   brush_dst->curve = BKE_curvemapping_copy(brush_src->curve);
+  brush_dst->automasking_cavity_curve = BKE_curvemapping_copy(brush_src->automasking_cavity_curve);
+
   if (brush_src->gpencil_settings != nullptr) {
     brush_dst->gpencil_settings = MEM_cnew(__func__, *(brush_src->gpencil_settings));
     brush_dst->gpencil_settings->curve_sensitivity = BKE_curvemapping_copy(
@@ -109,6 +111,7 @@ static void brush_free_data(ID *id)
     IMB_freeImBuf(brush->icon_imbuf);
   }
   BKE_curvemapping_free(brush->curve);
+  BKE_curvemapping_free(brush->automasking_cavity_curve);
 
   if (brush->gpencil_settings != nullptr) {
     BKE_curvemapping_free(brush->gpencil_settings->curve_sensitivity);
@@ -212,6 +215,10 @@ static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_addres
     BKE_curvemapping_blend_write(writer, brush->curve);
   }
 
+  if (brush->automasking_cavity_curve) {
+    BKE_curvemapping_blend_write(writer, brush->automasking_cavity_curve);
+  }
+
   if (brush->gpencil_settings) {
     BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
 
@@ -267,6 +274,14 @@ static void brush_blend_read_data(BlendDataReader *reader, ID *id)
     BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP);
   }
 
+  BLO_read_data_address(reader, &brush->automasking_cavity_curve);
+  if (brush->automasking_cavity_curve) {
+    BKE_curvemapping_blend_read(reader, brush->automasking_cavity_curve);
+  }
+  else {
+    brush->automasking_cavity_curve = BKE_sculpt_default_cavity_curve();
+  }
+
   /* grease pencil */
   BLO_read_data_address(reader, &brush->gpencil_settings);
   if (brush->gpencil_settings != nullptr) {
diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc
index a735250fd2a..08e49550426 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -2089,6 +2089,9 @@ void BKE_sculpt_toolsettings_data_ensure(Scene *scene)
   if (!sd->paint.tile_offset[2]) {
     sd->paint.tile_offset[2] = 1.0f;
   }
+  if (!sd->automasking_cavity_curve || !sd->automasking_cavity_curve_op) {
+    BKE_sculpt_check_cavity_curves(sd);
+  }
 }
 
 static bool check_sculpt_object_deformed(Object *object, const bool for_construction)
diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc
index 6d10d31e976..4af6409347d 100644
--- a/source/blender/blenkernel/intern/scene.c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list