[Bf-blender-cvs] [903bdac3740] greasepencil-edit-curve: GPencil: Update last GSoC branch changes
Antonio Vazquez
noreply at git.blender.org
Fri Jun 12 11:25:08 CEST 2020
Commit: 903bdac374033826e49c78016e906751442804cb
Author: Antonio Vazquez
Date: Fri Jun 12 11:19:07 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB903bdac374033826e49c78016e906751442804cb
GPencil: Update last GSoC branch changes
===================================================================
M source/blender/blenkernel/BKE_gpencil_curve.h
M source/blender/blenkernel/intern/gpencil_curve.c
M source/blender/blenkernel/intern/gpencil_geom.c
M source/blender/editors/gpencil/gpencil_edit_curve.c
M source/blender/editors/gpencil/gpencil_select.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/makesdna/DNA_gpencil_types.h
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index f62be42858a..1d9c0f04477 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -46,6 +46,7 @@ void BKE_gpencil_convert_curve(struct Main *bmain,
struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps);
void BKE_gpencil_stroke_editcurve_update(struct bGPDstroke *gps);
void BKE_gpencil_selected_strokes_editcurve_update(struct bGPdata *gpd);
+void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 7019876cf10..a3cf3d03959 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -37,6 +37,7 @@
#include "BLT_translation.h"
#include "DNA_gpencil_types.h"
+#include "DNA_meshdata_types.h"
#include "BKE_collection.h"
#include "BKE_context.h"
@@ -462,6 +463,9 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps)
return NULL;
}
+ /* TODO: GPXX this should be a parameter */
+ float error_threshold = 0.1f;
+
float *points = MEM_callocN(sizeof(float) * gps->totpoints * POINT_DIM, __func__);
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
@@ -477,7 +481,7 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps)
int r = curve_fit_cubic_to_points_fl(points,
gps->totpoints,
POINT_DIM,
- 0.1f,
+ error_threshold,
CURVE_FIT_CALC_HIGH_QUALIY,
NULL,
0,
@@ -495,9 +499,13 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps)
for (int i = 0; i < r_cubic_array_len; i++) {
BezTriple *bezt = &editcurve->curve_points[i];
+ bGPDspoint *orig_pt = &gps->points[r_cubic_orig_index[i]];
for (int j = 0; j < 3; j++) {
copy_v3_v3(bezt->vec[j], &r_cubic_array[i * 3 * POINT_DIM + j * 3]);
}
+ bezt->radius = orig_pt->pressure;
+ bezt->weight = orig_pt->strength;
+
editcurve->point_index_array[i] = r_cubic_orig_index[i];
}
@@ -535,6 +543,9 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps)
gps->editcurve = editcurve;
}
+/**
+ * Update editcurve for all selected strokes.
+ */
void BKE_gpencil_selected_strokes_editcurve_update(bGPdata *gpd)
{
if (gpd == NULL) {
@@ -557,10 +568,91 @@ void BKE_gpencil_selected_strokes_editcurve_update(bGPdata *gpd)
}
BKE_gpencil_stroke_editcurve_update(gps);
+ if (gps->editcurve != NULL) {
+ gps->editcurve->resolution = gpd->editcurve_resolution;
+ }
}
}
}
}
}
+/**
+ * Recalculate stroke points with the editcurve of the stroke.
+ */
+void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps)
+{
+ if (gps == NULL || gps->editcurve == NULL) {
+ return;
+ }
+
+ bGPDcurve *editcurve = gps->editcurve;
+ BezTriple *bezt_array = editcurve->curve_points;
+ int bezt_array_len = editcurve->tot_curve_points;
+ int resolu = editcurve->resolution;
+ bool is_cyclic = gps->flag & GP_STROKE_CYCLIC;
+
+ const uint bezt_array_last = bezt_array_len - 1;
+ const uint stride = sizeof(float[3]);
+ const uint resolu_stride = resolu * stride;
+ const uint points_len = BKE_curve_calc_coords_axis_len(bezt_array_len, resolu, is_cyclic, true);
+
+ float(*points)[3] = MEM_mallocN((sizeof(float[3]) * points_len * (is_cyclic ? 2 : 1)), __func__);
+ float *points_offset;
+ for (int axis = 0; axis < 3; axis++) {
+ points_offset = &points[0][axis];
+ for (unsigned int i = 0; i < bezt_array_last; i++) {
+ const BezTriple *bezt_curr = &bezt_array[i];
+ const BezTriple *bezt_next = &bezt_array[i + 1];
+ BKE_curve_forward_diff_bezier(bezt_curr->vec[1][axis],
+ bezt_curr->vec[2][axis],
+ bezt_next->vec[0][axis],
+ bezt_next->vec[1][axis],
+ points_offset,
+ (int)resolu,
+ stride);
+ points_offset = POINTER_OFFSET(points_offset, resolu_stride);
+ }
+
+ if (is_cyclic) {
+ const BezTriple *bezt_curr = &bezt_array[bezt_array_last];
+ const BezTriple *bezt_next = &bezt_array[0];
+ BKE_curve_forward_diff_bezier(bezt_curr->vec[1][axis],
+ bezt_curr->vec[2][axis],
+ bezt_next->vec[0][axis],
+ bezt_next->vec[1][axis],
+ points_offset,
+ (int)resolu,
+ stride);
+ points_offset = POINTER_OFFSET(points_offset, stride);
+ }
+ else {
+ float *points_last = POINTER_OFFSET(&points[0][axis], bezt_array_last * resolu_stride);
+ *points_last = bezt_array[bezt_array_last].vec[1][axis];
+ points_offset = POINTER_OFFSET(points_offset, stride);
+ }
+ }
+
+ if (is_cyclic) {
+ memcpy(points[points_len], points[0], sizeof(float[3]) * points_len);
+ }
+
+ gps->totpoints = points_len;
+ gps->points = MEM_recallocN(gps->points, sizeof(bGPDspoint) * gps->totpoints);
+ if (gps->dvert != NULL) {
+ gps->dvert = MEM_recallocN(gps->dvert, sizeof(MDeformVert) * gps->totpoints);
+ }
+
+ for (int i = 0; i < points_len; i++) {
+ bGPDspoint *pt = &gps->points[i];
+ copy_v3_v3(&pt->x, points[i]);
+
+ pt->pressure = 1.0f;
+ pt->strength = 1.0f;
+ /* TODO: fill rest of data for point using interpolation */
+ }
+
+ MEM_freeN(points);
+}
+
/** \} */
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 911d5207c15..33dd1a9b7ca 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -41,6 +41,7 @@
#include "BKE_deform.h"
#include "BKE_gpencil.h"
+#include "BKE_gpencil_curve.h"
#include "BKE_gpencil_geom.h"
#include "BKE_object.h"
@@ -1200,6 +1201,13 @@ void BKE_gpencil_stroke_geometry_update(bGPdata *UNUSED(gpd), bGPDstroke *gps)
return;
}
+ if (gps->editcurve != NULL) {
+ if (gps->editcurve->flag & GP_CURVE_RECALC_GEOMETRY) {
+ BKE_gpencil_stroke_update_geometry_from_editcurve(gps);
+ gps->editcurve->flag &= ~GP_CURVE_RECALC_GEOMETRY;
+ }
+ }
+
if (gps->totpoints > 2) {
BKE_gpencil_stroke_fill_triangulate(gps);
}
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index a697c8b40ce..56a2ea4297d 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -79,6 +79,9 @@ static int gp_write_stroke_curve_data_exec(bContext *C, wmOperator *op)
BKE_gpencil_free_stroke_editcurve(gps);
}
BKE_gpencil_stroke_editcurve_update(gps);
+ if (gps->editcurve != NULL) {
+ gps->editcurve->resolution = gpd->editcurve_resolution;
+ }
}
}
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 2898e2d5d51..cb00ffb5fa6 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -227,18 +227,32 @@ static int gpencil_select_linked_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- /* select all points in selected strokes */
- CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
- if (gps->flag & GP_STROKE_SELECT) {
- bGPDspoint *pt;
- int i;
+ if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
+ if (gps->editcurve != NULL && gps->flag & GP_STROKE_SELECT) {
+ bGPDcurve *gpc = gps->editcurve;
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ BezTriple *bezt = &gpc->curve_points[i];
+ BEZT_SEL_ALL(bezt);
+ }
+ }
+ }
+ CTX_DATA_END;
+ }
+ else {
+ /* select all points in selected strokes */
+ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
+ if (gps->flag & GP_STROKE_SELECT) {
+ bGPDspoint *pt;
+ int i;
- for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
- pt->flag |= GP_SPOINT_SELECT;
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ pt->flag |= GP_SPOINT_SELECT;
+ }
}
}
+ CTX_DATA_END;
}
- CTX_DATA_END;
/* updates */
DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
@@ -691,50 +705,98 @@ static int gpencil_select_more_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED;
}
- CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
- if (gps->flag & GP_STROKE_SELECT) {
- bGPDspoint *pt;
- int i;
- bool prev_sel;
+ if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+ GP_EDITABLE_STROKES_BEGIN (gp_iter, C, gpl, gps) {
+ if (gps->editcurve != NULL && gps->flag & GP_STROKE_SELECT) {
+ bGPDcurve *editcurve = gps->editcurve;
+ BezTriple *bezt;
+ int i;
- /* First Pass: Go in forward order,
- * expanding selection if previous was selected (pre changes).
- * - This pass covers the "after" edges of selection islands
- */
- prev_sel = false;
- for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
- if (pt->flag & GP_SPOINT_SELECT) {
- /* selected point - just set flag for next point */
- prev_sel = true;
+ /* First Pass: Go in forward order,
+ * expanding selection if previous was selected (pre changes).
+ * - This pass covers the "after" edges of select
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list