[Bf-blender-cvs] [fb38f0daaee] greasepencil-refactor: GPencil: Basic parenting working

Antonio Vazquez noreply at git.blender.org
Tue Jan 28 23:00:05 CET 2020


Commit: fb38f0daaee922c96c99c505ffaa5da7056c6fb1
Author: Antonio Vazquez
Date:   Tue Jan 28 22:37:19 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBfb38f0daaee922c96c99c505ffaa5da7056c6fb1

GPencil: Basic parenting working

Still looks one frame late.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/gpencil_modifier.c
M	source/blender/blenkernel/intern/object_update.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 79fd26677d6..5b2ee2d6f76 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -329,6 +329,8 @@ void BKE_gpencil_parent_matrix_get(const struct Depsgraph *depsgraph,
                                    struct bGPDlayer *gpl,
                                    float diff_mat[4][4]);
 
+void BKE_gpencil_update_layer_parent(const struct Depsgraph *depsgraph, struct Object *ob);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 686bf43eaec..4386792d507 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -3896,4 +3896,51 @@ void BKE_gpencil_parent_matrix_get(const Depsgraph *depsgraph,
   }
 }
 
+void BKE_gpencil_update_layer_parent(const Depsgraph *depsgraph, Object *ob)
+{
+  if (ob->type != OB_GPENCIL) {
+    return;
+  }
+
+  bGPdata *gpd = (bGPdata *)ob->data;
+  bGPDspoint *pt;
+  int i;
+  float diff_mat[4][4];
+  float cur_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);
+
+      /* calculate new matrix */
+      if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) {
+        invert_m4_m4(cur_mat, ob_eval->obmat);
+      }
+      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);
+        }
+      }
+      /* 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]);
+
+        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);
+          }
+        }
+        /* set new parent matrix */
+        copy_m4_m4(gpl->inverse, cur_mat);
+      }
+    }
+  }
+}
 /** \} */
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index 954d710f994..6a0000b8ac5 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -445,7 +445,7 @@ void BKE_gpencil_eval_geometry(Depsgraph *depsgraph, bGPdata *gpd)
   int ctime = (int)DEG_get_ctime(depsgraph);
 
   /* update active frame */
-    LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     gpl->actframe = BKE_gpencil_layer_frame_get(gpl, ctime, GP_GETFRAME_USE_PREV);
   }
 
@@ -456,7 +456,7 @@ void BKE_gpencil_eval_geometry(Depsgraph *depsgraph, bGPdata *gpd)
      * so that editing tools work with copy-on-write
      * when the current frame changes
      */
-      LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_orig->layers) {
+    LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_orig->layers) {
       gpl->actframe = BKE_gpencil_layer_frame_get(gpl, ctime, GP_GETFRAME_USE_PREV);
     }
   }
@@ -897,10 +897,19 @@ void BKE_gpencil_prepare_eval_data(Depsgraph *depsgraph, Scene *scene, Object *o
   Object *ob_orig = (Object *)DEG_get_original_id(&ob->id);
   bGPdata *gpd_orig = (bGPdata *)ob_orig->data;
 
+  /* Need check if some layer is parented. */
+  bool do_parent = false;
+  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_orig->layers) {
+    if (gpl->parent != NULL) {
+      do_parent = true;
+      break;
+    }
+  }
+
   const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_eval);
   const bool do_modifiers = (bool)((!is_multiedit) && (ob->greasepencil_modifiers.first != NULL) &&
                                    (!GPENCIL_SIMPLIFY_MODIF(scene)));
-  if (!do_modifiers) {
+  if ((!do_modifiers) && (!do_parent)) {
     return;
   }
   DEG_debug_print_eval(depsgraph, __func__, gpd_eval->id.name, gpd_eval);
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index fa1c8551867..dbed508bc91 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -222,6 +222,7 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o
     case OB_GPENCIL: {
       BKE_gpencil_prepare_eval_data(depsgraph, scene, ob);
       BKE_gpencil_modifiers_calc(depsgraph, scene, ob);
+      BKE_gpencil_update_layer_parent(depsgraph, ob);
       break;
     }
   }



More information about the Bf-blender-cvs mailing list