[Bf-blender-cvs] [7bf8459c139] temp-T96709-painting-target: Added sticky_shading_color (temporarily until paint mode has been added).
Jeroen Bakker
noreply at git.blender.org
Tue Apr 5 11:33:06 CEST 2022
Commit: 7bf8459c139972caa4f91a2ee8dddd70ba416a0c
Author: Jeroen Bakker
Date: Tue Apr 5 10:22:03 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rB7bf8459c139972caa4f91a2ee8dddd70ba416a0c
Added sticky_shading_color (temporarily until paint mode has been added).
===================================================================
M source/blender/blenkernel/BKE_paint.h
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_filter_color.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 8ab89b6c244..e98304f4dc4 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -634,6 +634,14 @@ typedef struct SculptSession {
*/
char needs_flush_to_id;
+ /**
+ * Some tools follows the shading chosen by the last used tool canvas.
+ * When not set the viewport shading color would be used.
+ *
+ * NOTE: This setting is temporarily until paint mode is added.
+ */
+ bool sticky_shading_color;
+
} SculptSession;
void BKE_sculptsession_free(struct Object *ob);
diff --git a/source/blender/editors/include/ED_paint.h b/source/blender/editors/include/ED_paint.h
index d3ea8ecaa3d..b6f0ba8947c 100644
--- a/source/blender/editors/include/ED_paint.h
+++ b/source/blender/editors/include/ED_paint.h
@@ -133,6 +133,9 @@ void ED_paint_do_msg_notify_active_tool_changed(struct bContext *C,
struct wmMsgSubscribeKey *msg_key,
struct wmMsgSubscribeValue *msg_val);
+/* Store the last used tool in the sculpt session. */
+void ED_paint_tool_update_sticky_shading_color(struct bContext *C, struct Object *ob);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/sculpt_paint/paint_canvas.cc b/source/blender/editors/sculpt_paint/paint_canvas.cc
index 85135aa6b4f..24b5223d825 100644
--- a/source/blender/editors/sculpt_paint/paint_canvas.cc
+++ b/source/blender/editors/sculpt_paint/paint_canvas.cc
@@ -10,6 +10,7 @@
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_material.h"
+#include "BKE_paint.h"
#include "DEG_depsgraph.h"
@@ -42,12 +43,86 @@ extern "C" {
using namespace blender;
using namespace blender::ed::sculpt_paint::canvas;
+/* Does the paint tool with the given idname uses a canvas. */
+static bool paint_tool_uses_canvas(StringRef idname)
+{
+ /* TODO(jbakker): complete this list. */
+ return ELEM(idname, "builtin_brush.Paint", "builtin.color_filter");
+}
+
+static bool paint_tool_shading_color_follows_last_used(StringRef idname)
+{
+ /* TODO(jbakker): complete this list. */
+ return ELEM(idname, "builtin_brush.Mask");
+}
+
+void ED_paint_tool_update_sticky_shading_color(struct bContext *C, struct Object *ob)
+{
+ if (ob == nullptr || ob->sculpt == nullptr) {
+ return;
+ }
+
+ bToolRef *tref = WM_toolsystem_ref_from_context(C);
+ if (tref == nullptr) {
+ return;
+ }
+ /* Do not modify when tool follows lat used tool. */
+ if (paint_tool_shading_color_follows_last_used(tref->idname)) {
+ return;
+ }
+
+ ob->sculpt->sticky_shading_color = paint_tool_uses_canvas(tref->idname);
+}
+
+static bool paint_tool_shading_color_follows_last_used_tool(struct bContext *C, struct Object *ob)
+{
+ if (ob == nullptr || ob->sculpt == nullptr) {
+ return false;
+ }
+
+ bToolRef *tref = WM_toolsystem_ref_from_context(C);
+ if (tref == nullptr) {
+ return false;
+ }
+
+ return paint_tool_shading_color_follows_last_used(tref->idname);
+}
+
+bool ED_paint_tool_use_canvas(struct bContext *C, struct Object *ob)
+{
+ /* Quick exit, only sculpt tools can use canvas. */
+ if (ob == nullptr || ob->sculpt == nullptr) {
+ return false;
+ }
+
+ bToolRef *tref = WM_toolsystem_ref_from_context(C);
+ if (tref != nullptr) {
+ return paint_tool_uses_canvas(tref->idname);
+ }
+
+ return false;
+}
+
+static bool paint_tool_last_used_tool_used_canvas(struct Object *ob)
+{
+ if (ob == nullptr || ob->sculpt == nullptr) {
+ return false;
+ }
+ return ob->sculpt->sticky_shading_color;
+}
+
eV3DShadingColorType ED_paint_shading_color_override(bContext *C,
const PaintModeSettings *settings,
Object *ob,
eV3DShadingColorType orig_color_type)
{
- if (!ED_paint_tool_use_canvas(C, ob)) {
+ /* NOTE: This early exit is temporarily, until a paint mode has been added.
+ * For better integration with the vertex paint in sculpt mode we sticky
+ * with the last stoke when using tools like masking.
+ */
+ if (!ED_paint_tool_use_canvas(C, ob) &&
+ !(paint_tool_shading_color_follows_last_used_tool(C, ob) &&
+ ob->sculpt->sticky_shading_color)) {
return orig_color_type;
}
@@ -142,26 +217,6 @@ int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settin
return -1;
}
-bool ED_paint_tool_use_canvas(struct bContext *C, struct Object *ob)
-{
- /* Quick exit, only sculpt tools can use canvas. */
- if (ob == nullptr || ob->sculpt == nullptr) {
- return false;
- }
-
- bToolRef *tref = WM_toolsystem_ref_from_context(C);
- if (tref != nullptr) {
- if (STREQ(tref->idname, "builtin_brush.Paint")) {
- return true;
- }
- if (STREQ(tref->idname, "builtin.color_filter")) {
- return true;
- }
- }
-
- return false;
-}
-
void ED_paint_do_msg_notify_active_tool_changed(struct bContext *C,
struct wmMsgSubscribeKey *msg_key,
struct wmMsgSubscribeValue *msg_val)
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index e82ac058281..524b6db7a56 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -69,6 +69,7 @@
#include "WM_types.h"
#include "ED_object.h"
+#include "ED_paint.h"
#include "ED_screen.h"
#include "ED_sculpt.h"
#include "ED_view3d.h"
@@ -4976,6 +4977,8 @@ static void sculpt_brush_stroke_init(bContext *C, wmOperator *op)
* earlier steps modifying the data. */
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
BKE_sculpt_update_object_for_edit(depsgraph, ob, is_smooth, need_mask, needs_colors);
+
+ ED_paint_tool_update_sticky_shading_color(C, ob);
}
static void sculpt_restore_mesh(Sculpt *sd, Object *ob)
diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.c b/source/blender/editors/sculpt_paint/sculpt_filter_color.c
index 377f1e0ed32..2c7a27a6924 100644
--- a/source/blender/editors/sculpt_paint/sculpt_filter_color.c
+++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.c
@@ -36,6 +36,7 @@
#include "WM_types.h"
#include "ED_object.h"
+#include "ED_paint.h"
#include "ED_screen.h"
#include "ED_sculpt.h"
#include "paint_intern.h"
@@ -291,6 +292,7 @@ static int sculpt_color_filter_invoke(bContext *C, wmOperator *op, const wmEvent
FilterCache *filter_cache = ss->filter_cache;
filter_cache->active_face_set = SCULPT_FACE_SET_NONE;
filter_cache->automasking = SCULPT_automasking_cache_init(sd, NULL, ob);
+ ED_paint_tool_update_sticky_shading_color(C, ob);
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
More information about the Bf-blender-cvs
mailing list