[Bf-blender-cvs] [35d8726e4d6] temp-T96708-brush-texture-refactoring: Use mask_mtex for texture in sculpt/vertex paint.

Jeroen Bakker noreply at git.blender.org
Tue Apr 5 08:14:08 CEST 2022


Commit: 35d8726e4d65fa8b72f1c47ecc751aaa64380a6f
Author: Jeroen Bakker
Date:   Mon Apr 4 15:32:10 2022 +0200
Branches: temp-T96708-brush-texture-refactoring
https://developer.blender.org/rB35d8726e4d65fa8b72f1c47ecc751aaa64380a6f

Use mask_mtex for texture in sculpt/vertex paint.

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

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

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/blenloader/intern/versioning_300.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_expand.c
M	source/blender/makesdna/DNA_brush_types.h

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 9e40a8d364a..0e89b726461 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -482,7 +482,7 @@ class DisplayPanel(BrushPanel):
             icon='HIDE_OFF' if brush.use_cursor_overlay else 'HIDE_ON',
         )
 
-        if mode in {'PAINT_2D', 'PAINT_TEXTURE', 'PAINT_VERTEX', 'SCULPT'}:
+        if mode in {'PAINT_2D', 'PAINT_TEXTURE'}:
             row = col.row(align=True)
             row.prop(brush, "texture_overlay_alpha", text="Texture Opacity")
             row.prop(brush, "use_primary_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
@@ -492,7 +492,7 @@ class DisplayPanel(BrushPanel):
                     icon='HIDE_OFF' if brush.use_primary_overlay else 'HIDE_ON',
                 )
 
-        if mode in {'PAINT_TEXTURE', 'PAINT_2D'}:
+        if mode in {'PAINT_TEXTURE', 'PAINT_2D', 'PAINT_VERTEX', 'SCULPT'}:
             row = col.row(align=True)
             row.prop(brush, "mask_overlay_alpha", text="Mask Texture Opacity")
             row.prop(brush, "use_secondary_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index a0336f7e7bf..6a12829b732 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -60,9 +60,9 @@ class VIEW3D_HT_tool_header(Header):
 
         def draw_3d_brush_settings(layout, tool_mode):
             layout.popover("VIEW3D_PT_tools_brush_settings_advanced", text="Brush")
-            if tool_mode != 'PAINT_WEIGHT':
+            if tool_mode in ('PAINT_TEXTURE'):
                 layout.popover("VIEW3D_PT_tools_brush_texture")
-            if tool_mode == 'PAINT_TEXTURE':
+            if tool_mode in ('PAINT_TEXTURE', 'SCULPT', 'PAINT_VERTEX'):
                 layout.popover("VIEW3D_PT_tools_mask_texture")
             layout.popover("VIEW3D_PT_tools_brush_stroke")
             layout.popover("VIEW3D_PT_tools_brush_falloff")
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index df07fbb3198..1a3b7b0a76d 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -613,7 +613,7 @@ class VIEW3D_PT_tools_brush_texture(Panel, View3DPaintPanel):
                 (brush := settings.brush)
         ):
             if context.sculpt_object or context.vertex_paint_object:
-                return True
+                return False
             elif context.image_paint_object:
                 return (brush.image_tool == 'DRAW')
         return False
@@ -642,12 +642,14 @@ class VIEW3D_PT_tools_mask_texture(Panel, View3DPaintPanel, TextureMaskPanel):
     @classmethod
     def poll(cls, context):
         settings = cls.paint_settings(context)
-        return (settings and settings.brush and context.image_paint_object)
+        return settings and settings.brush and (
+            context.image_paint_object or context.sculpt_object or context.vertex_paint_object)
 
     def draw(self, context):
         layout = self.layout
 
-        brush = context.tool_settings.image_paint.brush
+        settings = self.paint_settings(context)
+        brush = settings.brush
 
         col = layout.column()
         mask_tex_slot = brush.mask_texture_slot
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 1f3b0606dfd..1651ea243f2 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -25,7 +25,7 @@ extern "C" {
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 9
+#define BLENDER_FILE_SUBVERSION 10
 
 /* 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/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index d2b8c4330bc..12c7652a95b 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -34,6 +34,7 @@
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_text_types.h"
+#include "DNA_texture_defaults.h"
 #include "DNA_workspace_types.h"
 
 #include "BKE_action.h"
@@ -2549,6 +2550,19 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
     }
   }
 
+  if (!MAIN_VERSION_ATLEAST(bmain, 302, 10)) {
+    /* Sculpting brushes used mtex for masking, image brushes used mtex for coloring and mask_mtex
+     * for masking. Converting sculpting brushes to use mask_tex for masking to make tools more
+     * compatible with each other. */
+    MTex default_texture = _DNA_DEFAULT_MTex;
+    LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
+      if (brush->sculpt_tool != 0) {
+        memcpy(&brush->mask_mtex, &brush->mtex, sizeof(MTex));
+        memcpy(&brush->mtex, &default_texture, sizeof(MTex));
+      }
+    }
+  }
+
   /**
    * Versioning code until next subversion bump goes here.
    *
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index e82ac058281..fe172d5e7ae 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1231,7 +1231,7 @@ static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush
                SCULPT_TOOL_ELASTIC_DEFORM,
                SCULPT_TOOL_THUMB) ||
 
-          (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA)) ||
+          (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_AREA)) ||
          sculpt_brush_use_topology_rake(ss, brush);
 }
 
@@ -2336,7 +2336,7 @@ float SCULPT_brush_strength_factor(SculptSession *ss,
 {
   StrokeCache *cache = ss->cache;
   const Scene *scene = cache->vc->scene;
-  const MTex *mtex = &br->mtex;
+  const MTex *mtex = &br->mask_mtex;
   float avg = 1.0f;
   float rgba[4];
   float point[3];
@@ -2383,7 +2383,7 @@ float SCULPT_brush_strength_factor(SculptSession *ss,
       x += br->mtex.ofs[0];
       y += br->mtex.ofs[1];
 
-      avg = paint_get_tex_pixel(&br->mtex, x, y, ss->tex_pool, thread_id);
+      avg = paint_get_tex_pixel(&br->mask_mtex, x, y, ss->tex_pool, thread_id);
 
       avg += br->texture_sample_bias;
     }
@@ -3260,7 +3260,7 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
     update_sculpt_normal(sd, ob, nodes, totnode);
   }
 
-  if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) {
+  if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_AREA) {
     update_brush_local_mat(sd, ob);
   }
 
@@ -3780,7 +3780,7 @@ static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob)
 {
   SculptSession *ss = ob->sculpt;
   Brush *brush = BKE_paint_brush(&sd->paint);
-  MTex *mtex = &brush->mtex;
+  MTex *mtex = &brush->mask_mtex;
 
   if (ss->multires.active && mtex->tex && mtex->tex->type == TEX_NOISE) {
     multires_stitch_grids(ob);
@@ -4929,7 +4929,7 @@ bool SCULPT_stroke_get_location(bContext *C, float out[3], const float mouse[2])
 static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession *ss)
 {
   Brush *brush = BKE_paint_brush(&sd->paint);
-  MTex *mtex = &brush->mtex;
+  MTex *mtex = &brush->mask_mtex;
 
   /* Init mtex nodes. */
   if (mtex->tex && mtex->tex->nodetree) {
@@ -5262,7 +5262,7 @@ static void sculpt_stroke_update_step(bContext *C,
 static void sculpt_brush_exit_tex(Sculpt *sd)
 {
   Brush *brush = BKE_paint_brush(&sd->paint);
-  MTex *mtex = &brush->mtex;
+  MTex *mtex = &brush->mask_mtex;
 
   if (mtex->tex && mtex->tex->nodetree) {
     ntreeTexEndExecTree(mtex->tex->nodetree->execdata);
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 2ef35d540b9..b5eec705283 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -173,7 +173,7 @@ static float sculpt_expand_falloff_value_vertex_get(SculptSession *ss,
     return expand_cache->vert_falloff[v];
   }
 
-  if (!expand_cache->brush->mtex.tex) {
+  if (!expand_cache->brush->mask_mtex.tex) {
     return expand_cache->vert_falloff[v];
   }
 
@@ -197,7 +197,7 @@ static float sculpt_expand_max_vertex_falloff_get(ExpandCache *expand_cache)
     return expand_cache->max_vert_falloff;
   }
 
-  if (!expand_cache->brush->mtex.tex) {
+  if (!expand_cache->brush->mask_mtex.tex) {
     return expand_cache->max_vert_falloff;
   }
 
@@ -1833,13 +1833,13 @@ static int sculpt_expand_modal(bContext *C, wmOperator *op, const wmEvent *event
       }
       case SCULPT_EXPAND_MODAL_TEXTURE_DISTORTION_INCREASE: {
         if (expand_cache->texture_distortion_strength == 0.0f) {
-          if (expand_cache->brush->mtex.tex == NULL) {
+          if (expand_cache->brush->mask_mtex.tex == NULL) {
             BKE_report(op->reports,
                        RPT_WARNING,
                        "Active brush does not contain any texture to distort the expand boundary");
             break;
           }
-          if (expand_cache->brush->mtex.brush_map_mode != MTEX_MAP_MODE_3D) {
+          if (expand_cache->brush->mask_mtex.brush_map_mode != MTEX_MAP_MODE_3D) {
             BKE_report(op->reports,
                        RPT_WARNING,
                        "Texture mapping not set to 3D, results may be unpredictable");
@@ -2003,7 +2003,7 @@ static void sculpt_expand_cache_initial_config_set(bContext *C,
   IMB_colormanagement_srgb_to_scene_linear_v3(expand_cache->fill_color);
 
   expand_cache->scene = CTX_data_scene(C);
-  expand_cache->mtex = &expand_cache->brush->mtex;
+  expand_cache->mtex = &expand_cache->brush->mask_mtex;
   expand_cache->texture_distortion_strength = 0.0f;
   expand_cache->blend_mode = expand_cache->brush->blend;
 }
diff --git a/source/blender/makesdna/DNA_brush

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list