[Bf-blender-cvs] [2d84662a134] greasepencil-object: GPencil: Fix error for wrong Potrace data
Antonio Vazquez
noreply at git.blender.org
Wed Sep 9 15:43:55 CEST 2020
Commit: 2d84662a1346d75388613a08ce86da75ff6ec640
Author: Antonio Vazquez
Date: Wed Sep 9 12:12:32 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB2d84662a1346d75388613a08ce86da75ff6ec640
GPencil: Fix error for wrong Potrace data
In some situations, Potrace can produce a wrong data and generate a very long stroke. Now the length is checked and removed if the length is too big.
===================================================================
M source/blender/editors/gpencil/gpencil_trace_ops.c
M source/blender/editors/gpencil/gpencil_trace_utils.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c b/source/blender/editors/gpencil/gpencil_trace_ops.c
index e2a20eee25e..6da198ef144 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -283,12 +283,12 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
100.0f);
RNA_def_float(ot->srna,
"sample",
- 0.05f,
- 0.001f,
+ 0.0f,
+ 0.0f,
100.0f,
"Sample",
- "Distance to sample points",
- 0.001f,
+ "Distance to sample points, zero to disable",
+ 0.0f,
100.0f);
RNA_def_float_factor(ot->srna,
"threshold",
diff --git a/source/blender/editors/gpencil/gpencil_trace_utils.c b/source/blender/editors/gpencil/gpencil_trace_utils.c
index efd5314fae9..fe28d21acd3 100644
--- a/source/blender/editors/gpencil/gpencil_trace_utils.c
+++ b/source/blender/editors/gpencil/gpencil_trace_utils.c
@@ -27,6 +27,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BKE_gpencil.h"
@@ -252,6 +253,7 @@ void ED_gpencil_trace_data_to_strokes(Main *bmain,
const int32_t resolution,
const int32_t thickness)
{
+#define MAX_LENGTH 100.0f
/* Find materials and create them if not found. */
int32_t mat_fill_idx = BKE_gpencil_material_find_index_by_name_prefix(ob, "Stroke");
int32_t mat_mask_idx = BKE_gpencil_material_find_index_by_name_prefix(ob, "Mask");
@@ -348,10 +350,26 @@ void ED_gpencil_trace_data_to_strokes(Main *bmain,
break;
}
}
- /* Resample stroke. Don't need to call to BKE_gpencil_stroke_geometry_update() because
- * the sample function already call that. */
- BKE_gpencil_stroke_sample(gps, MAX2(sample, 0.001f), false);
+ /* In some situations, Potrace can produce a wrong data and generate a very
+ * long stroke. Here the length is checked and removed if the length is too big. */
+ float length = BKE_gpencil_stroke_length(gps, true);
+ if (length <= MAX_LENGTH) {
+ if (sample > 0.0f) {
+ /* Resample stroke. Don't need to call to BKE_gpencil_stroke_geometry_update() because
+ * the sample function already call that. */
+ BKE_gpencil_stroke_sample(gps, sample, false);
+ }
+ else {
+ BKE_gpencil_stroke_geometry_update(gps);
+ }
+ }
+ else {
+ /* Remove too long strokes. */
+ BLI_remlink(&gpf->strokes, gps);
+ BKE_gpencil_free_stroke(gps);
+ }
path = path->next;
}
+#undef MAX_LENGTH
}
More information about the Bf-blender-cvs
mailing list