[Bf-blender-cvs] [740506c7af8] greasepencil-object: Add new option to simplify alternate points
Antonio Vazquez
noreply at git.blender.org
Sat Dec 9 20:52:29 CET 2017
Commit: 740506c7af8eee191d05fe5f77adb45d39ca54be
Author: Antonio Vazquez
Date: Sat Dec 9 20:52:20 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rB740506c7af8eee191d05fe5f77adb45d39ca54be
Add new option to simplify alternate points
THis option remove alternated vertex from stroke except the extremes
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil_modifier.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_gpencilsimplify.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index af3507d8170..d8695de98fc 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1639,10 +1639,12 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col = split.column()
row = col.row(align=True)
+ row.enabled = not md.simplify_alternate
row.prop(md, "factor")
row = col.row(align=True)
row.prop(md, "pass_index", text="Pass")
row.prop(md, "inverse_pass", text="", icon="ARROW_LEFTRIGHT")
+ col.prop(md, "simplify_alternate")
col = split.column()
col.label("Layer:")
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 65783df1345..8b3ef5af2ae 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -209,6 +209,7 @@ void BKE_gpencil_lattice_clear(struct Object *ob);
/* stroke geometry utilities */
void BKE_gpencil_stroke_normal(const struct bGPDstroke *gps, float r_normal[3]);
void BKE_gpencil_simplify_stroke(struct bGPDlayer *gpl, struct bGPDstroke *gps, float factor);
+void BKE_gpencil_simplify_alternate(struct bGPDlayer *gpl, struct bGPDstroke *gps, float factor);
void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index 9fc535bcd16..9bac39d4684 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -247,6 +247,46 @@ void BKE_gpencil_simplify_stroke(bGPDlayer *UNUSED(gpl), bGPDstroke *gps, float
MEM_SAFE_FREE(points2d);
}
+/* Simplify alternate vertex of stroke except extrems */
+void BKE_gpencil_simplify_alternate(bGPDlayer *UNUSED(gpl), bGPDstroke *gps, float factor)
+{
+ if (gps->totpoints < 5) {
+ return;
+ }
+
+ /* save points */
+ bGPDspoint *old_points = MEM_dupallocN(gps->points);
+
+ /* resize gps */
+ int newtot = (gps->totpoints - 2) / 2;
+ if (((gps->totpoints - 2) % 2) > 0) {
+ ++newtot;
+ }
+ newtot += 2;
+
+ gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * newtot);
+ gps->flag |= GP_STROKE_RECALC_CACHES;
+ gps->tot_triangles = 0;
+
+ int j = 0;
+ for (int i = 0; i < gps->totpoints; i++) {
+ bGPDspoint *old_pt = &old_points[i];
+ bGPDspoint *pt = &gps->points[j];
+
+ if ((i == 0) || (i == gps->totpoints - 1) || ((i % 2) > 0.0)) {
+ memcpy(pt, old_pt, sizeof(bGPDspoint));
+ j++;
+ }
+ else {
+ BKE_gpencil_free_point_weights(old_pt);
+ }
+ }
+
+ gps->totpoints = j;
+
+ MEM_SAFE_FREE(old_points);
+}
+
/* *************************************************** */
/* Modifier Utilities */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 3574bc720ab..b7ef98f0e6d 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1896,7 +1896,8 @@ typedef struct GpencilSimplifyModifierData {
typedef enum eGpencilSimplify_Flag {
GP_SIMPLIFY_INVERSE_LAYER = (1 << 0),
- GP_SIMPLIFY_INVERSE_PASS = (1 << 1),
+ GP_SIMPLIFY_INVERSE_PASS = (1 << 1),
+ GP_SIMPLIFY_ALTERNATE = (1 << 2),
} eGpencilSimplify_Flag;
typedef struct GpencilOffsetModifierData {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 20476476605..69750ec436a 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5149,6 +5149,12 @@ static void rna_def_modifier_gpencilsimplify(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_SIMPLIFY_INVERSE_PASS);
RNA_def_property_ui_text(prop, "Inverse Pass", "Inverse filter");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "simplify_alternate", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_SIMPLIFY_ALTERNATE);
+ RNA_def_property_ui_text(prop, "Alternated Vertices",
+ "Remove alternated vertices except extrems");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
static void rna_def_modifier_gpencilthick(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_gpencilsimplify.c b/source/blender/modifiers/intern/MOD_gpencilsimplify.c
index 5ffe51f3d68..3cc95d184d4 100644
--- a/source/blender/modifiers/intern/MOD_gpencilsimplify.c
+++ b/source/blender/modifiers/intern/MOD_gpencilsimplify.c
@@ -70,8 +70,13 @@ static void deformStroke(ModifierData *md, const EvaluationContext *UNUSED(eval_
return;
}
- /* simplify stroke using Ramer-Douglas-Peucker algorithm */
- BKE_gpencil_simplify_stroke(gpl, gps, mmd->factor);
+ if (mmd->flag & GP_SIMPLIFY_ALTERNATE) {
+ BKE_gpencil_simplify_alternate(gpl, gps, mmd->factor);
+ }
+ else {
+ /* simplify stroke using Ramer-Douglas-Peucker algorithm */
+ BKE_gpencil_simplify_stroke(gpl, gps, mmd->factor);
+ }
}
static void bakeModifierGP(const bContext *UNUSED(C), const EvaluationContext *eval_ctx,
More information about the Bf-blender-cvs
mailing list