[Bf-blender-cvs] [7b4103eed19] temp-T96710-pbvh-pixels: Attached canvas selection to texture painting.

Jeroen Bakker noreply at git.blender.org
Mon Apr 11 14:15:58 CEST 2022


Commit: 7b4103eed19c9cfa3660c7d7008c7d5cdca7b579
Author: Jeroen Bakker
Date:   Mon Apr 11 14:15:54 2022 +0200
Branches: temp-T96710-pbvh-pixels
https://developer.blender.org/rB7b4103eed19c9cfa3660c7d7008c7d5cdca7b579

Attached canvas selection to texture painting.

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

M	source/blender/blenkernel/intern/material.c
M	source/blender/editors/include/ED_paint.h
M	source/blender/editors/sculpt_paint/paint_canvas.cc
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc
M	source/blender/makesdna/DNA_material_types.h

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

diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index bc569956f66..4caaf314888 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1423,13 +1423,15 @@ static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
     case SH_NODE_TEX_IMAGE: {
       TexPaintSlot *slot = &ma->texpaintslot[index];
       slot->ima = (Image *)node->id;
-      slot->interp = ((NodeTexImage *)node->storage)->interpolation;
+      NodeTexImage *storage = (NodeTexImage *)node->storage;
+      slot->interp = storage->interpolation;
+      slot->image_user = &storage->iuser;
       /* for new renderer, we need to traverse the treeback in search of a UV node */
       bNode *uvnode = nodetree_uv_node_recursive(node);
 
       if (uvnode) {
-        NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage;
-        slot->uvname = storage->uv_map;
+        NodeShaderUVMap *uv_storage = (NodeShaderUVMap *)uvnode->storage;
+        slot->uvname = uv_storage->uv_map;
         /* set a value to index so UI knows that we have a valid pointer for the mesh */
         slot->valid = true;
       }
diff --git a/source/blender/editors/include/ED_paint.h b/source/blender/editors/include/ED_paint.h
index cd28fbe9687..59d667b758f 100644
--- a/source/blender/editors/include/ED_paint.h
+++ b/source/blender/editors/include/ED_paint.h
@@ -114,8 +114,10 @@ void ED_paintcurve_undo_push_end(struct bContext *C);
 void ED_paintcurve_undosys_type(struct UndoType *ut);
 
 /* paint_canvas.cc */
-struct Image *ED_paint_canvas_image_get(const struct PaintModeSettings *settings,
-                                        struct Object *ob);
+bool ED_paint_canvas_image_get(const struct PaintModeSettings *paint_mode_settings,
+                               struct Object *ob,
+                               struct Image **r_image,
+                               struct ImageUser **r_image_user);
 int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
                                           struct Object *ob);
 
diff --git a/source/blender/editors/sculpt_paint/paint_canvas.cc b/source/blender/editors/sculpt_paint/paint_canvas.cc
index 5683e3ff741..a94a5933d96 100644
--- a/source/blender/editors/sculpt_paint/paint_canvas.cc
+++ b/source/blender/editors/sculpt_paint/paint_canvas.cc
@@ -148,22 +148,35 @@ eV3DShadingColorType ED_paint_shading_color_override(bContext *C,
   return color_type;
 }
 
-Image *ED_paint_canvas_image_get(const struct PaintModeSettings *settings, struct Object *ob)
+bool ED_paint_canvas_image_get(const PaintModeSettings *settings,
+                               Object *ob,
+                               Image **r_image,
+                               ImageUser **r_image_user)
 {
+  *r_image = nullptr;
+  *r_image_user = nullptr;
+
   switch (settings->canvas_source) {
     case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE:
-      return nullptr;
+      break;
+
     case PAINT_CANVAS_SOURCE_IMAGE:
-      return settings->canvas_image;
+      *r_image = settings->canvas_image;
+      /* TODO: Should we have an image user inside the paint mode settings? */
+      break;
+
     case PAINT_CANVAS_SOURCE_MATERIAL: {
       TexPaintSlot *slot = get_active_slot(ob);
       if (slot == nullptr) {
         break;
       }
-      return slot->ima;
+
+      *r_image = slot->ima;
+      *r_image_user = slot->image_user;
+      break;
     }
   }
-  return nullptr;
+  return *r_image != nullptr;
 }
 
 int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 8146f497d72..e978afb5eb0 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2189,7 +2189,8 @@ void SCULPT_calc_area_normal_and_center(
 static float brush_strength(const Sculpt *sd,
                             const StrokeCache *cache,
                             const float feather,
-                            const UnifiedPaintSettings *ups)
+                            const UnifiedPaintSettings *ups,
+                            const PaintModeSettings *UNUSED(paint_mode_settings))
 {
   const Scene *scene = cache->vc->scene;
   const Brush *brush = BKE_paint_brush((Paint *)&sd->paint);
@@ -2754,26 +2755,29 @@ static void update_brush_local_mat(Sculpt *sd, Object *ob)
 /** \name Texture painting
  * \{ */
 
-static bool sculpt_needs_pbvh_pixels(const Brush *brush,
+static bool sculpt_needs_pbvh_pixels(const PaintModeSettings *paint_mode_settings,
+                                     const Brush *brush,
                                      Object *ob /*, const PaintModeSettings *settings*/)
 {
   if (brush->sculpt_tool == SCULPT_TOOL_PAINT /*&& U.experimental.use_sculpt_texture_paint*/) {
     Image *image;
     ImageUser *image_user;
-    return SCULPT_paint_image_canvas_get(ob, &image, &image_user);
+    return SCULPT_paint_image_canvas_get(paint_mode_settings, ob, &image, &image_user);
   }
 
   return false;
 }
 
-static void sculpt_pbvh_update_pixels(SculptSession *ss, Object *ob)
+static void sculpt_pbvh_update_pixels(const PaintModeSettings *paint_mode_settings,
+                                      SculptSession *ss,
+                                      Object *ob)
 {
   BLI_assert(ob->type == OB_MESH);
   Mesh *mesh = (Mesh *)ob->data;
 
   Image *image;
   ImageUser *image_user;
-  if (!SCULPT_paint_image_canvas_get(ob, &image, &image_user)) {
+  if (!SCULPT_paint_image_canvas_get(paint_mode_settings, ob, &image, &image_user)) {
     return;
   }
 
@@ -3115,7 +3119,8 @@ void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float (*vertCos)[3])
 static void sculpt_topology_update(Sculpt *sd,
                                    Object *ob,
                                    Brush *brush,
-                                   UnifiedPaintSettings *UNUSED(ups))
+                                   UnifiedPaintSettings *UNUSED(ups),
+                                   PaintModeSettings *UNUSED(paint_mode_settings))
 {
   SculptSession *ss = ob->sculpt;
 
@@ -3210,7 +3215,11 @@ static void do_brush_action_task_cb(void *__restrict userdata,
   }
 }
 
-static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups)
+static void do_brush_action(Sculpt *sd,
+                            Object *ob,
+                            Brush *brush,
+                            UnifiedPaintSettings *ups,
+                            PaintModeSettings *paint_mode_settings)
 {
   SculptSession *ss = ob->sculpt;
   int totnode;
@@ -3249,8 +3258,8 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
     nodes = sculpt_pbvh_gather_generic(ob, sd, brush, use_original, radius_scale, &totnode);
   }
 
-  if (sculpt_needs_pbvh_pixels(brush, ob)) {
-    sculpt_pbvh_update_pixels(ss, ob);
+  if (sculpt_needs_pbvh_pixels(paint_mode_settings, brush, ob)) {
+    sculpt_pbvh_update_pixels(paint_mode_settings, ss, ob);
   }
 
   /* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode deforms the
@@ -3443,7 +3452,7 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
       SCULPT_do_displacement_smear_brush(sd, ob, nodes, totnode);
       break;
     case SCULPT_TOOL_PAINT:
-      SCULPT_do_paint_brush(sd, ob, nodes, totnode);
+      SCULPT_do_paint_brush(paint_mode_settings, sd, ob, nodes, totnode);
       break;
     case SCULPT_TOOL_SMEAR:
       SCULPT_do_smear_brush(sd, ob, nodes, totnode);
@@ -3748,10 +3757,18 @@ void SCULPT_cache_calc_brushdata_symm(StrokeCache *cache,
   }
 }
 
-typedef void (*BrushActionFunc)(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups);
+typedef void (*BrushActionFunc)(Sculpt *sd,
+                                Object *ob,
+                                Brush *brush,
+                                UnifiedPaintSettings *ups,
+                                PaintModeSettings *paint_mode_settings);
 
-static void do_tiled(
-    Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, BrushActionFunc action)
+static void do_tiled(Sculpt *sd,
+                     Object *ob,
+                     Brush *brush,
+                     UnifiedPaintSettings *ups,
+                     PaintModeSettings *paint_mode_settings,
+                     BrushActionFunc action)
 {
   SculptSession *ss = ob->sculpt;
   StrokeCache *cache = ss->cache;
@@ -3785,7 +3802,7 @@ static void do_tiled(
 
   /* First do the "un-tiled" position to initialize the stroke for this location. */
   cache->tile_pass = 0;
-  action(sd, ob, brush, ups);
+  action(sd, ob, brush, ups, paint_mode_settings);
 
   /* Now do it for all the tiles. */
   copy_v3_v3_int(cur, start);
@@ -3804,7 +3821,7 @@ static void do_tiled(
           cache->plane_offset[dim] = cur[dim] * step[dim];
           cache->initial_location[dim] = cur[dim] * step[dim] + original_initial_location[dim];
         }
-        action(sd, ob, brush, ups);
+        action(sd, ob, brush, ups, paint_mode_settings);
       }
     }
   }
@@ -3814,6 +3831,7 @@ static void do_radial_symmetry(Sculpt *sd,
                                Object *ob,
                                Brush *brush,
                                UnifiedPaintSettings *ups,
+                               PaintModeSettings *paint_mode_settings,
                                BrushActionFunc action,
                                const char symm,
                                const int axis,
@@ -3825,7 +3843,7 @@ static void do_radial_symmetry(Sculpt *sd,
     const float angle = 2.0f * M_PI * i / sd->radial_symm[axis - 'X'];
     ss->cache->radial_symmetry_pass = i;
     SCULPT_cache_calc_brushdata_symm(ss->cache, symm, axis, angle);
-    do_tiled(sd, ob, brush, ups, action);
+    do_tiled(sd, ob, brush, ups, paint_mode_settings, action);
   }
 }
 
@@ -3847,7 +3865,8 @@ static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob)
 static void do_symmetrical_brush_actions(Sculpt *sd,
                                          Object *ob,
             

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list