[Bf-blender-cvs] [e76de93f2e1] greasepencil-object: GPencil: Use parent matrix in Vertex Color modifier

Antonio Vazquez noreply at git.blender.org
Wed Nov 6 08:48:24 CET 2019


Commit: e76de93f2e11568622fa6322195e848f3b3ea6e1
Author: Antonio Vazquez
Date:   Wed Nov 6 08:48:09 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBe76de93f2e11568622fa6322195e848f3b3ea6e1

GPencil: Use parent matrix in Vertex Color modifier

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

M	source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
M	source/tools

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

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
index cd5f3a6a8d2..efdd4f102e1 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
@@ -94,9 +94,55 @@ static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
   }
 }
 
+static void gpencil_parent_location(const Depsgraph *depsgraph,
+                                    Object *ob,
+                                    bGPDlayer *gpl,
+                                    float diff_mat[4][4])
+{
+  Object *ob_eval = depsgraph != NULL ? DEG_get_evaluated_object(depsgraph, ob) : ob;
+  Object *obparent = gpl->parent;
+  Object *obparent_eval = depsgraph != NULL ? DEG_get_evaluated_object(depsgraph, obparent) :
+                                              obparent;
+
+  /* if not layer parented, try with object parented */
+  if (obparent_eval == NULL) {
+    if (ob_eval != NULL) {
+      copy_m4_m4(diff_mat, ob_eval->obmat);
+      return;
+    }
+    unit_m4(diff_mat);
+    return;
+  }
+  else {
+    if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) {
+      mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
+      add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
+      return;
+    }
+    else if (gpl->partype == PARBONE) {
+      bPoseChannel *pchan = BKE_pose_channel_find_name(obparent_eval->pose, gpl->parsubstr);
+      if (pchan) {
+        float tmp_mat[4][4];
+        mul_m4_m4m4(tmp_mat, obparent_eval->obmat, pchan->pose_mat);
+        mul_m4_m4m4(diff_mat, tmp_mat, gpl->inverse);
+        add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
+      }
+      else {
+        /* if bone not found use object (armature) */
+        mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
+        add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
+      }
+      return;
+    }
+    else {
+      unit_m4(diff_mat); /* not defined type */
+    }
+  }
+}
+
 /* deform stroke */
 static void deformStroke(GpencilModifierData *md,
-                         Depsgraph *UNUSED(depsgraph),
+                         Depsgraph *depsgraph,
                          Object *ob,
                          bGPDlayer *gpl,
                          bGPDframe *UNUSED(gpf),
@@ -126,6 +172,10 @@ static void deformStroke(GpencilModifierData *md,
 
   float radius_sqr = mmd->radius * mmd->radius;
   float coba_res[4];
+  float mat[4][4];
+
+  /* Get object matrix. */
+  gpencil_parent_location(depsgraph, ob, gpl, mat);
 
   /* loop points and apply deform */
   float target_loc[3];
@@ -138,7 +188,7 @@ static void deformStroke(GpencilModifierData *md,
 
     /* Calc world position of point. */
     float pt_loc[3];
-    mul_v3_m4v3(pt_loc, ob->obmat, &pt->x);
+    mul_v3_m4v3(pt_loc, mat, &pt->x);
 
     /* Cal distance to point (squared) */
     float dist_sqr = len_squared_v3v3(pt_loc, target_loc);
diff --git a/source/tools b/source/tools
index 24a26488775..2afbb8ec472 160000
--- a/source/tools
+++ b/source/tools
@@ -1 +1 @@
-Subproject commit 24a26488775dbe8cf2c1273d60a74c9d570d773c
+Subproject commit 2afbb8ec472cac5102eb239f57b006f8c9387685



More information about the Bf-blender-cvs mailing list