[Bf-blender-cvs] [b8c0a6c999e] temp-T96710-pbvh-pixels: Rebuild pixels when active material or image changes.

Jeroen Bakker noreply at git.blender.org
Mon Apr 4 11:21:46 CEST 2022


Commit: b8c0a6c999e6d9263afbe2d358cc708f7d233cb6
Author: Jeroen Bakker
Date:   Mon Apr 4 11:21:19 2022 +0200
Branches: temp-T96710-pbvh-pixels
https://developer.blender.org/rBb8c0a6c999e6d9263afbe2d358cc708f7d233cb6

Rebuild pixels when active material or image changes.

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

M	source/blender/editors/include/ED_sculpt.h
M	source/blender/editors/sculpt_paint/CMakeLists.txt
A	source/blender/editors/sculpt_paint/sculpt_image.cc
M	source/blender/editors/space_view3d/space_view3d.c

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

diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h
index 3100c135db4..fbe71329423 100644
--- a/source/blender/editors/include/ED_sculpt.h
+++ b/source/blender/editors/include/ED_sculpt.h
@@ -17,6 +17,9 @@ struct UndoType;
 struct ViewContext;
 struct bContext;
 struct rcti;
+struct wmMsgSubscribeKey;
+struct wmMsgSubscribeValue;
+struct wmRegionMessageSubscribeParams;
 
 /* sculpt.c */
 
@@ -55,6 +58,11 @@ int ED_sculpt_face_sets_active_update_and_get(struct bContext *C,
 void ED_sculpt_undo_push_multires_mesh_begin(struct bContext *C, const char *str);
 void ED_sculpt_undo_push_multires_mesh_end(struct bContext *C, const char *str);
 
+/**
+ * Subscribe to messages that will trigger a PBVH update.
+ */
+void ED_sculpt_pbvh_message_subscribe(const struct wmRegionMessageSubscribeParams *params);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index 3b3f376970d..4f778534b46 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -65,6 +65,7 @@ set(SRC
   sculpt_filter_mask.c
   sculpt_filter_mesh.c
   sculpt_geodesic.c
+  sculpt_image.cc
   sculpt_mask_expand.c
   sculpt_mask_init.c
   sculpt_multiplane_scrape.c
diff --git a/source/blender/editors/sculpt_paint/sculpt_image.cc b/source/blender/editors/sculpt_paint/sculpt_image.cc
new file mode 100644
index 00000000000..66df4c45e70
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/sculpt_image.cc
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+#include "DNA_object_types.h"
+
+#include "BKE_context.h"
+#include "BKE_paint.h"
+#include "BKE_pbvh.h"
+#include "BKE_screen.h"
+
+#include "WM_message.h"
+#include "WM_types.h"
+
+extern "C" {
+
+static void sculpt_pbvh_do_msg_tag_rebuild_pixels(struct bContext *C,
+                                                  wmMsgSubscribeKey *UNUSED(msg_key),
+                                                  wmMsgSubscribeValue *UNUSED(msg_val))
+{
+  Object *ob = CTX_data_active_object(C);
+  if (ob == nullptr) {
+    return;
+  }
+  SculptSession *ss = ob->sculpt;
+  if (ss == nullptr) {
+    return;
+  }
+  BKE_pbvh_mark_update_pixels(ss->pbvh);
+}
+
+void ED_sculpt_pbvh_message_subscribe(const struct wmRegionMessageSubscribeParams *params)
+{
+  struct wmMsgBus *mbus = params->message_bus;
+
+  wmMsgSubscribeValue notify_msg = {
+      .owner = NULL,
+      .user_data = NULL,
+      .notify = sculpt_pbvh_do_msg_tag_rebuild_pixels,
+  };
+  WM_msg_subscribe_rna_anon_prop(mbus, Object, active_material_index, &notify_msg);
+  WM_msg_subscribe_rna_anon_prop(mbus, MeshUVLoopLayer, active, &notify_msg);
+  WM_msg_subscribe_rna_anon_type(mbus, Image, &notify_msg);
+  WM_msg_subscribe_rna_anon_type(mbus, UDIMTile, &notify_msg);
+}
+}
\ No newline at end of file
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 3f2fbb97de1..b235129fe76 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -46,6 +46,7 @@
 #include "ED_outliner.h"
 #include "ED_render.h"
 #include "ED_screen.h"
+#include "ED_sculpt.h"
 #include "ED_space_api.h"
 #include "ED_transform.h"
 #include "ED_undo.h"
@@ -1374,6 +1375,9 @@ static void view3d_main_region_message_subscribe(const wmRegionMessageSubscribeP
       case OB_MODE_PARTICLE_EDIT:
         WM_msg_subscribe_rna_anon_type(mbus, ParticleEdit, &msg_sub_value_region_tag_redraw);
         break;
+
+      case OB_MODE_SCULPT:
+        ED_sculpt_pbvh_message_subscribe(params);
       default:
         break;
     }



More information about the Bf-blender-cvs mailing list