[Bf-blender-cvs] [e0d1e667321] master: Fix T93868: GPencil material filter does not work with instances

Antonio Vazquez noreply at git.blender.org
Thu Dec 30 12:49:06 CET 2021


Commit: e0d1e66732156e01797dc2f1b7ce9fb507834903
Author: Antonio Vazquez
Date:   Thu Dec 30 12:48:51 2021 +0100
Branches: master
https://developer.blender.org/rBe0d1e66732156e01797dc2f1b7ce9fb507834903

Fix T93868: GPencil material filter does not work with instances

When the material is used in several objects, the filter by material is not working as expected because the internal pointers are different due eval version.

Now, the original version of the material is compared to keep same address.

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

M	source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h

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

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
index f6a85919de4..c583a45a27d 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
@@ -40,6 +40,8 @@
 #include "MOD_gpencil_modifiertypes.h"
 #include "MOD_gpencil_util.h"
 
+#include "DEG_depsgraph_query.h"
+
 void gpencil_modifier_type_init(GpencilModifierTypeInfo *types[])
 {
 #define INIT_GP_TYPE(typeName) \
@@ -73,7 +75,7 @@ void gpencil_modifier_type_init(GpencilModifierTypeInfo *types[])
 
 bool is_stroke_affected_by_modifier(Object *ob,
                                     char *mlayername,
-                                    const Material *material,
+                                    Material *material,
                                     const int mpassindex,
                                     const int gpl_passindex,
                                     const int minpoints,
@@ -84,8 +86,8 @@ bool is_stroke_affected_by_modifier(Object *ob,
                                     const bool inv3,
                                     const bool inv4)
 {
-  Material *ma = BKE_gpencil_material(ob, gps->mat_nr + 1);
-  MaterialGPencilStyle *gp_style = ma->gp_style;
+  Material *ma_gps = BKE_gpencil_material(ob, gps->mat_nr + 1);
+  MaterialGPencilStyle *gp_style = ma_gps->gp_style;
 
   /* omit if filter by layer */
   if (mlayername[0] != '\0') {
@@ -102,13 +104,16 @@ bool is_stroke_affected_by_modifier(Object *ob,
   }
   /* Omit if filter by material. */
   if (material != NULL) {
+    /* Requires to use the original material to compare the same pointer address. */
+    Material *ma_md_orig = (Material *)DEG_get_original_id(&material->id);
+    Material *ma_gps_orig = (Material *)DEG_get_original_id(&ma_gps->id);
     if (inv4 == false) {
-      if (material != ma) {
+      if (ma_md_orig != ma_gps_orig) {
         return false;
       }
     }
     else {
-      if (material == ma) {
+      if (ma_md_orig == ma_gps_orig) {
         return false;
       }
     }
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h
index 59ed11a02f3..722574929c0 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h
@@ -34,7 +34,7 @@ struct bGPDstroke;
  */
 bool is_stroke_affected_by_modifier(struct Object *ob,
                                     char *mlayername,
-                                    const struct Material *material,
+                                    struct Material *material,
                                     const int mpassindex,
                                     const int gpl_passindex,
                                     const int minpoints,



More information about the Bf-blender-cvs mailing list