[Bf-blender-cvs] [99a5522a8a6] greasepencil-object: GPencil: Fix Parent layer not working

Antonio Vazquez noreply at git.blender.org
Tue Mar 17 12:17:57 CET 2020


Commit: 99a5522a8a6b8574f43795f54ac2e36812ecc242
Author: Antonio Vazquez
Date:   Tue Mar 17 10:50:00 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rB99a5522a8a6b8574f43795f54ac2e36812ecc242

GPencil: Fix Parent layer not working

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

M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc

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

diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index c0b40721ccc..0236d3c662b 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -4033,44 +4033,67 @@ void BKE_gpencil_update_layer_parent(const Depsgraph *depsgraph, Object *ob)
     return;
   }
 
+  /* Create matrix to rotate -90 degrees in X axis. */
+  const float matrix[4][4] = {1.0f,
+                              0.0f,
+                              0.0f,
+                              0.0f,
+                              0.0f,
+                              0.0f,
+                              -1.0f,
+                              0.0f,
+                              0.0f,
+                              1.0f,
+                              0.0f,
+                              0.0f,
+                              0.0f,
+                              0.0f,
+                              0.0f,
+                              1.0f};
+
   bGPdata *gpd = (bGPdata *)ob->data;
   bGPDspoint *pt;
   int i;
-  float diff_mat[4][4];
-  float cur_mat[4][4];
+  float cur_mat[4][4], icur_mat[4][4];
 
   LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     if ((gpl->parent != NULL) && (gpl->actframe != NULL)) {
-      Object *ob_eval = DEG_get_evaluated_object(depsgraph, gpl->parent);
-
+      Object *ob_parent = DEG_get_evaluated_object(depsgraph, gpl->parent);
       /* calculate new matrix */
       if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) {
-        invert_m4_m4(cur_mat, ob_eval->obmat);
+        mul_m4_m4m4(cur_mat, ob_parent->obmat, ob->imat);
+
+        invert_m4_m4(icur_mat, cur_mat);
+        mul_m4_m4m4(icur_mat, icur_mat, ob->imat);
       }
       else if (gpl->partype == PARBONE) {
-        bPoseChannel *pchan = BKE_pose_channel_find_name(ob_eval->pose, gpl->parsubstr);
-        if (pchan) {
-          float tmp_mat[4][4];
-          mul_m4_m4m4(tmp_mat, ob_eval->obmat, pchan->pose_mat);
-          invert_m4_m4(cur_mat, tmp_mat);
+        bPoseChannel *pchan = BKE_pose_channel_find_name(ob_parent->pose, gpl->parsubstr);
+        if (pchan != NULL) {
+          copy_m4_m4(cur_mat, ob->imat);
+          mul_m4_m4m4(cur_mat, cur_mat, ob_parent->obmat);
+          mul_m4_m4m4(cur_mat, cur_mat, pchan->pose_mat);
+
+          invert_m4_m4(icur_mat, cur_mat);
+          mul_m4_m4m4(icur_mat, icur_mat, ob->imat);
+
+          /* Rotate -90 degrees in X axis because GPencil default strokes orientation
+           * is to X/Z axis, but bones are X/Y. */
+          mul_m4_m4m4(cur_mat, cur_mat, matrix);
         }
       }
       /* only redo if any change */
-      if (!equals_m4m4(gpl->inverse, cur_mat)) {
-
-        /* first apply current transformation to all strokes */
-        BKE_gpencil_parent_matrix_get(depsgraph, ob, gpl, diff_mat);
-        /* undo local object */
-        sub_v3_v3(diff_mat[3], ob->obmat[3]);
+      bGPDlayer *gpl_active = (gpl->runtime.gpl_orig != NULL) ? gpl->runtime.gpl_orig : gpl;
 
+      if (!equals_m4m4(gpl->inverse, cur_mat)) {
         LISTBASE_FOREACH (bGPDstroke *, gps, &gpl->actframe->strokes) {
           for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
-            mul_m4_v3(diff_mat, &pt->x);
+            mul_m4_v3(cur_mat, &pt->x);
           }
         }
-        /* set new parent matrix */
-        copy_m4_m4(gpl->inverse, cur_mat);
       }
+
+      /* set new parent matrix */
+      copy_m4_m4(gpl_active->inverse, icur_mat);
     }
   }
 }
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 6791125d1e9..27d6db6a58f 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -2127,9 +2127,20 @@ void DepsgraphRelationBuilder::build_object_data_geometry_datablock(ID *obdata)
       /* Layer parenting need react to the parent object transformation. */
       LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
         if (gpl->parent != NULL) {
-          ComponentKey transform_key(&gpl->parent->id, NodeType::TRANSFORM);
           ComponentKey gpd_geom_key(&gpd->id, NodeType::GEOMETRY);
-          add_relation(transform_key, gpd_geom_key, "GPencil Parent Layer");
+
+          if (gpl->partype == PARBONE) {
+            ComponentKey bone_key(&gpl->parent->id, NodeType::BONE, gpl->parsubstr);
+            OperationKey armature_key(
+                &gpl->parent->id, NodeType::TRANSFORM, OperationCode::TRANSFORM_FINAL);
+
+            add_relation(bone_key, gpd_geom_key, "Bone Parent");
+            add_relation(armature_key, gpd_geom_key, "Armature Parent");
+          }
+          else {
+            ComponentKey transform_key(&gpl->parent->id, NodeType::TRANSFORM);
+            add_relation(transform_key, gpd_geom_key, "GPencil Parent Layer");
+          }
         }
       }
       break;



More information about the Bf-blender-cvs mailing list