[Bf-blender-cvs] [0a13fde96d8] soc-2019-npr: Gpencil: Multiply modifier angle split functions

YimingWu noreply at git.blender.org
Wed Jul 3 06:00:02 CEST 2019


Commit: 0a13fde96d8b99641caa92737f1b492f409e5a7b
Author: YimingWu
Date:   Wed Jul 3 11:59:29 2019 +0800
Branches: soc-2019-npr
https://developer.blender.org/rB0a13fde96d8b99641caa92737f1b492f409e5a7b

Gpencil: Multiply modifier angle split functions

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 1bbf79f91d7..4f33fdae421 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -217,12 +217,12 @@ void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
 
 bool BKE_gpencil_sample_stroke(struct bGPDstroke *gps, float dist);
 bool BKE_gpencil_stretch_stroke(struct bGPDstroke *gps, float dist);
-bool BKE_gpencil_trim_stroke_points(bGPDstroke *gps, int index_from, int index_to);
+bool BKE_gpencil_trim_stroke_points(struct bGPDstroke *gps, int index_from, int index_to);
 bool BKE_gpencil_shrink_stroke(struct bGPDstroke *gps, float dist);
-bool BKE_gpencil_split_stroke(bGPDframe *gpf,
-                              bGPDstroke *gps,
+bool BKE_gpencil_split_stroke(struct bGPDframe *gpf,
+                              struct bGPDstroke *gps,
                               int before_index,
-                              bGPDstroke **remaining_gps);
+                              struct bGPDstroke **remaining_gps);
 bool BKE_gpencil_smooth_stroke(struct bGPDstroke *gps, int i, float inf);
 bool BKE_gpencil_smooth_stroke_strength(struct bGPDstroke *gps, int point_index, float influence);
 bool BKE_gpencil_smooth_stroke_thickness(struct bGPDstroke *gps, int point_index, float influence);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index af7e04e7561..889d73571dd 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1803,21 +1803,19 @@ bool BKE_gpencil_split_stroke(bGPDframe *gpf,
     return false;
   }
 
-  int new_count = gps->totpoints - before_index + 1;
+  int new_count = gps->totpoints - before_index;
   int old_count = before_index;
 
   /* Handle remaining segments first. */
 
   new_gps = BKE_gpencil_add_stroke(gpf, gps->mat_nr, new_count, gps->thickness);
 
-  new_pt = MEM_callocN(sizeof(bGPDspoint) * new_count, "gp_stroke_points_remaining");
+  new_pt = new_gps->points; /* Allocated from above. */
 
   for (int i = 0; i < new_count; i++) {
     memcpy(&new_pt[i], &pt[i + before_index], sizeof(bGPDspoint));
   }
 
-  new_gps->points = new_pt;
-
   if (gps->dvert) {
     new_dv = MEM_callocN(sizeof(MDeformVert) * new_count, "gp_stroke_dverts_remaining");
     for (int i = 0; i < new_count; i++) {
@@ -1834,11 +1832,12 @@ bool BKE_gpencil_split_stroke(bGPDframe *gpf,
     new_gps->dvert = new_dv;
   }
 
-  *remaining_gps = new_gps;
+  (*remaining_gps) = new_gps;
 
-  /* trim the original stroke into a shorter one */
+  /* Trim the original stroke into a shorter one. */
+  /* Keep the end point. */
 
-  BKE_gpencil_trim_stroke_points(gps, 0, new_count - 1);
+  BKE_gpencil_trim_stroke_points(gps, 0, old_count);
 
   return true;
 }
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
index c138551434f..d05b83875fc 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
@@ -76,8 +76,27 @@ static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
   BKE_gpencil_modifier_copyData_generic(md, target);
 }
 
-static void splitStroke(bGPDstroke *gps, float angle)
+static void splitStroke(bGPDframe *gpf, bGPDstroke *gps, float split_angle)
 {
+  bGPDspoint *pt = gps->points;
+  bGPDstroke *new_gps = gps;
+  int i;
+  volatile float angle;
+
+  if (split_angle <= FLT_EPSILON) {
+    return;
+  }
+
+  for (i = 1; i < new_gps->totpoints - 1; i++) {
+    angle = angle_v3v3v3(&pt[i - 1].x, &pt[i].x, &pt[i + 1].x);
+    if (angle < split_angle) {
+      if (BKE_gpencil_split_stroke(gpf, new_gps, i, &new_gps)) {
+        pt = new_gps->points;
+        i = 0;
+        continue; /* then i == 1 again */
+      }
+    }
+  }
 }
 
 static void duplicateStroke(bGPDstroke *gps, int count, float dist, float offsset)
@@ -94,10 +113,12 @@ static void bakeModifier(Main *UNUSED(bmain),
 
   for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
     for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-      MultiplyGpencilModifierData *lmd = (MultiplyGpencilModifierData *)md;
+      MultiplyGpencilModifierData *mmd = (MultiplyGpencilModifierData *)md;
       bGPDstroke *gps;
       for (gps = gpf->strokes.first; gps; gps = gps->next) {
-        /* deform goes here */
+        if (mmd->flags & GP_MULTIPLY_ENABLE_ANGLE_SPLITTING) {
+          splitStroke(gpf, gps, mmd->split_angle);
+        }
       }
       return;
     }
@@ -110,16 +131,18 @@ static void bakeModifier(Main *UNUSED(bmain),
 static void generateStrokes(
     GpencilModifierData *md, Depsgraph *depsgraph, Object *ob, bGPDlayer *gpl, bGPDframe *gpf)
 {
-  MultiplyGpencilModifierData *lmd = (MultiplyGpencilModifierData *)md;
+  MultiplyGpencilModifierData *mmd = (MultiplyGpencilModifierData *)md;
   bGPDstroke *gps;
   for (gps = gpf->strokes.first; gps; gps = gps->next) {
-    /* deform goes here */
+    if (mmd->flags & GP_MULTIPLY_ENABLE_ANGLE_SPLITTING) {
+      splitStroke(gpf, gps, mmd->split_angle);
+    }
   }
 }
 
 static void updateDepsgraph(GpencilModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
 {
-  MultiplyGpencilModifierData *lmd = (MultiplyGpencilModifierData *)md;
+  MultiplyGpencilModifierData *mmd = (MultiplyGpencilModifierData *)md;
 }
 
 static void foreachObjectLink(GpencilModifierData *md,



More information about the Bf-blender-cvs mailing list