Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYimingWu <xp8110@outlook.com>2019-11-02 08:30:10 +0300
committerYimingWu <xp8110@outlook.com>2019-11-02 08:30:10 +0300
commitb5f072152dea8e78419ff8d2465aff85848cafc7 (patch)
tree3059d889fe966b3110a5fc226934cb9155ee65ff
parent2eefc89c63cc8a1dfa4b917d8e2455fbc0f07f40 (diff)
Gpencil: Add tip length to length modifier.
So that we can better align the tip points when extending and avoid jittering.
-rw-r--r--release/scripts/startup/bl_ui/properties_data_modifier.py2
-rw-r--r--source/blender/blenkernel/BKE_gpencil.h2
-rw-r--r--source/blender/blenkernel/intern/gpencil.c8
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencillength.c15
-rw-r--r--source/blender/makesdna/DNA_gpencil_modifier_types.h3
-rw-r--r--source/blender/makesrna/intern/rna_gpencil_modifier.c6
6 files changed, 23 insertions, 13 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 322833518cc..02d8f82b4a9 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -2346,6 +2346,8 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
col.prop(md, "percentage")
col = layout.column()
+ col.prop(md, "tip_length");
+
col.separator()
col.label(text="Material:")
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 2b5f8a2355d..564844f04e3 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -238,7 +238,7 @@ bool BKE_gpencil_smooth_stroke_uv(struct bGPDstroke *gps, int point_index, float
bool BKE_gpencil_close_stroke(struct bGPDstroke *gps);
void BKE_gpencil_dissolve_points(struct bGPDframe *gpf, struct bGPDstroke *gps, const short tag);
-bool BKE_gpencil_stretch_stroke(struct bGPDstroke *gps, const float dist);
+bool BKE_gpencil_stretch_stroke(struct bGPDstroke *gps, const float dist, const float tip_length);
bool BKE_gpencil_trim_stroke_points(struct bGPDstroke *gps,
const int index_from,
const int index_to);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 5e0c3d39db6..9fb287c2155 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1756,11 +1756,13 @@ bool BKE_gpencil_sample_stroke(bGPDstroke *gps, const float dist, const bool sel
* Backbone stretch similar to Freestyle.
* \param gps: Stroke to sample
* \param dist: Distance of one segment
+ * \param tip_length: Ignore tip jittering, set zero to use default value.
*/
-bool BKE_gpencil_stretch_stroke(bGPDstroke *gps, const float dist)
+bool BKE_gpencil_stretch_stroke(bGPDstroke *gps, const float dist, const float tip_length)
{
bGPDspoint *pt = gps->points, *last_pt, *second_last, *next_pt;
int i;
+ float threshold = (tip_length == 0 ? 0.001f : tip_length);
if (gps->totpoints < 2 || dist < FLT_EPSILON) {
return false;
@@ -1774,14 +1776,14 @@ bool BKE_gpencil_stretch_stroke(bGPDstroke *gps, const float dist)
float len2 = 0.0f;
i = 1;
- while (len1 < 0.001f && gps->totpoints > i) {
+ while (len1 < threshold && gps->totpoints > i) {
next_pt = &pt[i];
len1 = len_v3v3(&next_pt->x, &pt->x);
i++;
}
i = 2;
- while (len2 < 0.001f && gps->totpoints >= i) {
+ while (len2 < threshold && gps->totpoints >= i) {
second_last = &pt[gps->totpoints - i];
len2 = len_v3v3(&last_pt->x, &second_last->x);
i++;
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c
index f24a5fc135d..4828a0e3dd8 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c
@@ -71,20 +71,20 @@ static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
BKE_gpencil_modifier_copyData_generic(md, target);
}
-static void stretchOrShrinkStroke(bGPDstroke *gps, float length)
+static void stretchOrShrinkStroke(bGPDstroke *gps, float length, float tip_length)
{
if (length > 0.0f) {
- BKE_gpencil_stretch_stroke(gps, length);
+ BKE_gpencil_stretch_stroke(gps, length, tip_length);
}
else {
BKE_gpencil_shrink_stroke(gps, -length);
}
}
-static void applyLength(bGPDstroke *gps, float length, float percentage)
+static void applyLength(bGPDstroke *gps, float length, float percentage, float tip_length)
{
- stretchOrShrinkStroke(gps, length);
+ stretchOrShrinkStroke(gps, length, tip_length);
float len = BKE_gpencil_stroke_length(gps, true);
if (len < FLT_EPSILON) {
@@ -92,7 +92,7 @@ static void applyLength(bGPDstroke *gps, float length, float percentage)
}
float length2 = len * percentage / 2.0f; /* Srinking from two tips. */
- stretchOrShrinkStroke(gps, length2);
+ stretchOrShrinkStroke(gps, length2, tip_length);
}
static void bakeModifier(Main *UNUSED(bmain),
@@ -120,10 +120,9 @@ static void bakeModifier(Main *UNUSED(bmain),
lmd->flag & GP_MIRROR_INVERT_PASS,
lmd->flag & GP_MIRROR_INVERT_LAYERPASS,
lmd->flag & GP_MIRROR_INVERT_MATERIAL)) {
- applyLength(gps, lmd->length, lmd->percentage);
+ applyLength(gps, lmd->length, lmd->percentage, lmd->tip_length);
}
}
- return;
}
}
}
@@ -151,7 +150,7 @@ static void deformStroke(GpencilModifierData *md,
lmd->flag & GP_MIRROR_INVERT_PASS,
lmd->flag & GP_MIRROR_INVERT_LAYERPASS,
lmd->flag & GP_MIRROR_INVERT_MATERIAL)) {
- applyLength(gps, lmd->length, lmd->percentage);
+ applyLength(gps, lmd->length, lmd->percentage, lmd->tip_length);
}
}
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index e1e89521186..dc51e9669b2 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -657,9 +657,10 @@ typedef struct LengthGpencilModifierData {
int flag;
/** Custom index for passes. */
int layer_pass;
- char _pad[4];
float length;
float percentage;
+ /** This ignores tip jittering when extending stroke. */
+ float tip_length;
} 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 1d5195c8121..1308dae8c8f 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -1941,6 +1941,12 @@ static void rna_def_modifier_gpencillength(BlenderRNA *brna)
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");
+
+ prop = RNA_def_property(srna, "tip_length", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_float_default(prop, 0.01);
+ RNA_def_property_ui_text(prop, "Tip Length", "Ignore tip jittering when extending a stroke");
+ RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
}
static void rna_def_modifier_gpencilmultiply(BlenderRNA *brna)