[Bf-blender-cvs] [a3c4e90969e] greasepencil-object: GPencil: First steps to implement spread for a segment
Antonio Vazquez
noreply at git.blender.org
Wed Jun 24 16:01:37 CEST 2020
Commit: a3c4e90969eee43afd86e3247a780e920f82131e
Author: Antonio Vazquez
Date: Tue Jun 23 17:21:23 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rBa3c4e90969eee43afd86e3247a780e920f82131e
GPencil: First steps to implement spread for a segment
Still not working. Keep this commit to save the current status.
===================================================================
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index eacf0d80be7..2abfb392711 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -3758,6 +3758,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
for (int r = 0; r < 5; r++) {
gp_smooth_segment(p->gpd, 0.15f, size_before - 1, size_after - 1);
}
+ /* Spread the points if needed. */
+ ED_gpencil_stroke_buffer_spread_segment(
+ p->brush, &p->gsc, size_before - 1, size_after - 1);
}
/* finish painting operation if anything went wrong just now */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 83286b78620..2db8ef27116 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -3094,7 +3094,7 @@ static void gpencil_copy_buffer_point(tGPspoint *pt_from, tGPspoint *pt_dst)
}
/**
- * Spread last buffer point to get more topoly
+ * Spread last buffer point to get more topology
* @param brush Current brush
* @param gpd Current datablock
*/
@@ -3124,3 +3124,43 @@ void ED_gpencil_stroke_buffer_spread(Brush *brush, GP_SpaceConversion *gsc)
/* Spread the points. */
gpencil_spread_points(brush, gsc, spread, last_index);
}
+
+/**
+ * Spread a segment of buffer points to get more topology.
+ * This function assumes the segment is at the end of the stroke.
+ *
+ * @param brush Current brush
+ * @param gpd Current datablock
+ * @param from_index Index of the first point to spread
+ * @param to_index Index of the last point to spread
+ */
+void ED_gpencil_stroke_buffer_spread_segment(struct Brush *brush,
+ struct GP_SpaceConversion *gsc,
+ int from_index,
+ int to_index)
+{
+ bGPdata *gpd = gsc->gpd;
+ const int spread = brush->gpencil_settings->draw_spread;
+ if (spread == 0) {
+ return;
+ }
+
+ const int totpoints = to_index - from_index;
+
+ /* Increase the buffer size to hold the new points.
+ * As the function add 1, add only spread point minus 1. */
+ gpd->runtime.sbuffer_used += (spread * totpoints) - 1;
+ gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+ gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false);
+ /* Increment counters after expand buffer. */
+ gpd->runtime.sbuffer_used++;
+
+ /* Move original points to the right index depending of spread value. */
+ for (int i = totpoints; i > 0; i--) {
+ tGPspoint *pt_orig = ((tGPspoint *)(gpd->runtime.sbuffer) + from_index + i);
+ tGPspoint *pt_dst = ((tGPspoint *)(gpd->runtime.sbuffer) + from_index + (spread * i));
+ gpencil_copy_buffer_point(pt_orig, pt_dst);
+ }
+
+ /* Copy each point is his segment. */
+}
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 7ebf7501851..78c49af3bf0 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -357,6 +357,10 @@ bool ED_gpencil_stroke_point_is_inside(struct bGPDstroke *gps,
const float diff_mat[4][4]);
void ED_gpencil_stroke_buffer_spread(struct Brush *brush, struct GP_SpaceConversion *gsc);
+void ED_gpencil_stroke_buffer_spread_segment(struct Brush *brush,
+ struct GP_SpaceConversion *gsc,
+ int from_index,
+ int to_index);
#ifdef __cplusplus
}
More information about the Bf-blender-cvs
mailing list