[Bf-blender-cvs] [1aa8870b955] soc-2019-npr: Gpencil: Length modifier now handles relative lengths

YimingWu noreply at git.blender.org
Wed Jul 3 09:18:40 CEST 2019


Commit: 1aa8870b95575d2da3919dff12dc002589d577ec
Author: YimingWu
Date:   Wed Jul 3 15:08:44 2019 +0800
Branches: soc-2019-npr
https://developer.blender.org/rB1aa8870b95575d2da3919dff12dc002589d577ec

Gpencil: Length modifier now handles relative lengths

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencillength.c
M	source/blender/makesdna/DNA_gpencil_modifier_types.h
M	source/blender/makesrna/intern/rna_gpencil_modifier.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index bb4586e6e3a..81ee8a3dc37 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -2340,8 +2340,14 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "length")
     
     def GP_LENGTH(self, layout, ob, md):
-        col = layout.column()
+        sp = layout.split()
+        col = sp.column()
+        col.label(text="Absolute:")
         col.prop(md, "length")
+
+        col = sp.column()
+        col.label(text="Relative:")
+        col.prop(md, "percentage")
     
     def GP_MULTIPLY(self, layout, ob, md):
         sp = layout.split(factor = 0.5)
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 4f33fdae421..461e03bcd38 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -212,6 +212,7 @@ void BKE_gpencil_stroke_2d_flat_ref(const struct bGPDspoint *ref_points,
                                     float (*points2d)[2],
                                     const float scale,
                                     int *r_direction);
+float BKE_gpencil_stroke_length(const struct bGPDstroke *gps, bool use_3d);
 
 void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
 
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 889d73571dd..91aad469f67 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2376,6 +2376,28 @@ void BKE_gpencil_stroke_2d_flat_ref(const bGPDspoint *ref_points,
   *r_direction = (int)locy[2];
 }
 
+float BKE_gpencil_stroke_length(const bGPDstroke *gps, bool use_3d)
+{
+  if (!gps->points || gps->totpoints < 2) {
+    return 0;
+  }
+  float *last_pt = &gps->points[0].x;
+  int i;
+  bGPDspoint *pt;
+  float total_length = 0;
+  for (i = 1; i < gps->totpoints; i++) {
+    pt = &gps->points[i];
+    if (use_3d) {
+      total_length += len_v3v3(&pt->x, last_pt);
+    }
+    else {
+      total_length += len_v2v2(&pt->x, last_pt);
+    }
+    last_pt = &pt->x;
+  }
+  return total_length;
+}
+
 /**
  * Trim stroke to the first intersection or loop
  * \param gps: Stroke data
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c
index a3ae26efbbf..25a411908fe 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c
@@ -76,7 +76,7 @@ static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
   BKE_gpencil_modifier_copyData_generic(md, target);
 }
 
-static void deformStroke(bGPDstroke *gps, float length)
+static void stretchOrShrinkStroke(bGPDstroke *gps, float length)
 {
   if (length > 0) {
     BKE_gpencil_stretch_stroke(gps, length);
@@ -86,6 +86,20 @@ static void deformStroke(bGPDstroke *gps, float length)
   }
 }
 
+static void deformStroke(bGPDstroke *gps, float length, float percentage)
+{
+
+  stretchOrShrinkStroke(gps, length);
+
+  float len = BKE_gpencil_stroke_length(gps, 1);
+  if (len < FLT_EPSILON) {
+    return;
+  }
+  float length2 = len * percentage;
+
+  stretchOrShrinkStroke(gps, length2);
+}
+
 static void bakeModifier(Main *UNUSED(bmain),
                          Depsgraph *depsgraph,
                          GpencilModifierData *md,
@@ -99,7 +113,7 @@ static void bakeModifier(Main *UNUSED(bmain),
       LengthGpencilModifierData *lmd = (LengthGpencilModifierData *)md;
       bGPDstroke *gps;
       for (gps = gpf->strokes.first; gps; gps = gps->next) {
-        deformStroke(gps, lmd->length);
+        deformStroke(gps, lmd->length, lmd->percentage);
       }
       return;
     }
@@ -115,7 +129,7 @@ static void generateStrokes(
   LengthGpencilModifierData *lmd = (LengthGpencilModifierData *)md;
   bGPDstroke *gps;
   for (gps = gpf->strokes.first; gps; gps = gps->next) {
-    deformStroke(gps, lmd->length);
+    deformStroke(gps, lmd->length, lmd->percentage);
   }
 }
 
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index bb8e59871ac..b190d557d46 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -613,7 +613,7 @@ typedef struct SampleGpencilModifierData {
 typedef struct LengthGpencilModifierData {
   GpencilModifierData modifier;
   float length;
-  char _pad[4];
+  float percentage;
 } LengthGpencilModifierData;
 
 typedef struct MultiplyGpencilModifierData {
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index 85f1b850999..13c1f96fd1d 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -1734,10 +1734,14 @@ static void rna_def_modifier_gpencillength(BlenderRNA *brna)
   RNA_def_struct_ui_icon(srna, ICON_MOD_EDGESPLIT);
 
   prop = RNA_def_property(srna, "length", PROP_FLOAT, PROP_NONE);
-  RNA_def_property_float_sdna(prop, NULL, "length");
-  RNA_def_property_range(prop, -10, 10);
+  RNA_def_property_range(prop, -10.0f, 10.0f);
   RNA_def_property_ui_text(prop, "Length", "Length of each segment");
   RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+
+  prop = RNA_def_property(srna, "percentage", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_range(prop, -1.0f, 1.0f);
+  RNA_def_property_ui_text(prop, "Percentage", "Length based on the curve's original length");
+  RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
 }
 
 static void rna_def_modifier_gpencilmultiply(BlenderRNA *brna)



More information about the Bf-blender-cvs mailing list