Commit: 3190be57ebd510653958e189b621ce59401555ad
Author: Antonio Vazquez
Date: Sat Aug 8 18:52:49 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB3190be57ebd510653958e189b621ce59401555ad
GPencil: Apply GSoC changes
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/gpencil_curve.c
M source/blender/editors/gpencil/annotate_paint.c
M source/blender/editors/gpencil/editaction_gpencil.c
M source/blender/editors/gpencil/gpencil_data.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_interpolate.c
M source/blender/editors/gpencil/gpencil_sculpt_paint.c
M source/blender/editors/gpencil/gpencil_select.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/transform/transform_convert_gpencil.c
M source/blender/editors/transform/transform_generics.c
M source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
M source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c
M source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h
b/source/blender/blenkernel/BKE_gpencil.h
index 0b55e81db06..a2ad4f7dc2a 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -114,7 +114,9 @@ struct bGPDframe *BKE_gpencil_frame_duplicate(const struct
bGPDframe *gpf_src);
struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);
void BKE_gpencil_frame_copy_strokes(struct bGPDframe *gpf_src, struct
bGPDframe *gpf_dst);
struct bGPDcurve *BKE_gpencil_stroke_curve_duplicate(struct bGPDcurve
*gpc_src);
-struct bGPDstroke *BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src,
const bool dup_points);
+struct bGPDstroke *BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src,
+ const bool dup_points,
+ const bool dup_curve);
struct bGPdata *BKE_gpencil_copy(struct Main *bmain, const struct bGPdata
*gpd);
diff --git a/source/blender/blenkernel/intern/gpencil.c
b/source/blender/blenkernel/intern/gpencil.c
index 6cdeb9fe4e7..04f988413ae 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -536,7 +536,6 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char
name[])
gpd->flag |= GP_DATA_VIEWALIGN;
/* always enable object onion skin switch */
gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
-
/* GP object specific settings */
ARRAY_SET_ITEMS(gpd->line_color, 0.6f, 0.6f, 0.6f, 0.5f);
@@ -731,9 +730,10 @@ bGPDcurve *BKE_gpencil_stroke_curve_duplicate(bGPDcurve
*gpc_src)
* Make a copy of a given grease-pencil stroke.
* \param gps_src: Source grease pencil strokes.
* \param dup_points: Duplicate points data.
+ * \param dup_curve: Duplicate curve data.
* \return Pointer to new stroke.
*/
-bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src, const bool
dup_points)
+bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src, const bool
dup_points, const bool dup_curve)
{
bGPDstroke *gps_dst = NULL;
@@ -753,7 +753,7 @@ bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke
*gps_src, const bool dup_poi
}
}
- if (gps_src->editcurve != NULL) {
+ if (dup_curve && gps_src->editcurve != NULL) {
gps_dst->editcurve =
BKE_gpencil_stroke_curve_duplicate(gps_src->editcurve);
}
@@ -784,7 +784,7 @@ bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe
*gpf_src)
BLI_listbase_clear(&gpf_dst->strokes);
LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) {
/* make copy of source stroke */
- gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true);
+ gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true, true);
BLI_addtail(&gpf_dst->strokes, gps_dst);
}
@@ -809,7 +809,7 @@ void BKE_gpencil_frame_copy_strokes(bGPDframe *gpf_src,
struct bGPDframe *gpf_ds
BLI_listbase_clear(&gpf_dst->strokes);
LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) {
/* make copy of source stroke */
- gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true);
+ gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true, true);
BLI_addtail(&gpf_dst->strokes, gps_dst);
}
}
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c
b/source/blender/blenkernel/intern/gpencil_curve.c
index d53e712326b..633cb755577 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -55,6 +55,10 @@
#define COORD_FITTING_INFLUENCE 20.0f
+/* -------------------------------------------------------------------- */
+/** \name Convert to curve object
+ * \{ */
+
/* Helper: Check materials with same color. */
static int gpencil_check_same_material_color(Object *ob_gp, const float
color[4], Material **r_mat)
{
@@ -466,15 +470,46 @@ void BKE_gpencil_convert_curve(Main *bmain,
DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Editcurve kernel functions
+ * \{ */
+
/**
* Creates a bGPDcurve by doing a cubic curve fitting on the grease pencil
stroke points.
*/
bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float
error_threshold)
{
-#define POINT_DIM 9
if (gps->totpoints < 1) {
return NULL;
}
+ else if (gps->totpoints == 1) {
+ bGPDcurve *editcurve = BKE_gpencil_stroke_editcurve_new(1);
+ bGPDspoint *pt = &gps->points[0];
+ bGPDcurve_point *cpt = &editcurve->curve_points[0];
+ BezTriple *bezt = &cpt->bezt;
+
+ float tmp_vec[3];
+ for (int j = 0; j < 3; j++) {
+ copy_v3_v3(tmp_vec, &pt->x);
+ tmp_vec[0] += (j - 1);
+ copy_v3_v3(bezt->vec[j], tmp_vec);
+ }
+
+ cpt->pressure = pt->pressure;
+ cpt->strength = pt->strength;
+ copy_v4_v4(cpt->vert_color, pt->vert_color);
+
+ /* default handle type */
+ bezt->h1 |= HD_ALIGN;
+ bezt->h2 |= HD_ALIGN;
+
+ cpt->point_index = 0;
+
+ return editcurve;
+ }
+#define POINT_DIM 9
float *points = MEM_callocN(sizeof(float) * gps->totpoints * POINT_DIM,
__func__);
float diag_length = len_v3v3(gps->boundbox_min, gps->boundbox_max);
@@ -766,7 +801,7 @@ static float
*gpencil_stroke_points_from_editcurve_adaptive_resolu(
const uint num_segments = (is_cyclic) ? curve_point_array_len :
curve_point_array_len - 1;
int *segment_point_lengths = MEM_callocN(sizeof(int) * num_segments,
__func__);
- uint points_len = 0;
+ uint points_len = 1;
for (int i = 0; i < cpt_last; i++) {
bGPDcurve_point *cpt = &curve_point_array[i];
bGPDcurve_point *cpt_next = &curve_point_array[i + 1];
@@ -786,7 +821,6 @@ static float
*gpencil_stroke_points_from_editcurve_adaptive_resolu(
segment_point_lengths[cpt_last] = segment_resolu;
points_len += segment_resolu;
}
- points_len += 1;
float(*r_points)[9] = MEM_callocN((stride * points_len * (is_cyclic ? 2 :
1)), __func__);
float *points_offset = &r_points[0][0];
@@ -873,6 +907,33 @@ void
BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps,
bGPDcurve *editcurve = gps->editcurve;
bGPDcurve_point *curve_point_array = editcurve->curve_points;
int curve_point_array_len = editcurve->tot_curve_points;
+ if (curve_point_array_len == 0) {
+ return;
+ }
+ else if (curve_point_array_len == 1) {
+ bGPDcurve_point *cpt = &curve_point_array[0];
+ /* resize stroke point array */
+ gps->totpoints = 1;
+ gps->points = MEM_recallocN(gps->points, sizeof(bGPDspoint) *
gps->totpoints);
+ if (gps->dvert != NULL) {
+ gps->dvert = MEM_recallocN(gps->dvert, sizeof(MDeformVert) *
gps->totpoints);
+ }
+
+ bGPDspoint *pt = &gps->points[0];
+ copy_v3_v3(&pt->x, &cpt->bezt.vec[0]);
+
+ pt->pressure = cpt->pressure;
+ pt->strength = cpt->strength;
+
+ copy_v4_v4(pt->vert_color, &cpt->vert_color);
+
+ /* deselect */
+ pt->flag &= ~GP_SPOINT_SELECT;
+ gps->flag &= ~GP_STROKE_SELECT;
+
+ return;
+ }
+
bool is_cyclic = gps->flag & GP_STROKE_CYCLIC;
int points_len = 0;
@@ -927,7 +988,7 @@ void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke
*gps)
bool changed = false;
bGPDcurve *gpc = gps->editcurve;
- if (gpc->tot_curve_points < 1) {
+ if (gpc->tot_curve_points < 2) {
return;
}
diff --git a/source/blender/editors/gpencil/annotate_paint.c
b/source/blender/editors/gpencil/annotate_paint.c
index 237e99ac7d0..8eb08709b94 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -910,7 +910,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
int totarrowpoints = runtime.arrow_end_style;
/* Setting up arrow stroke. */
- bGPDstroke *e_arrow_gps = BKE_gpencil_stroke_duplicate(gps, false);
+ bGPDstroke *e_arrow_gps = BKE_gpencil_stroke_duplicate(gps, false,
false);
annotation_stroke_arrow_allocate(e_arrow_gps, totarrowpoints);
/* Set pointer to first non-initialized point. */
@@ -931,7 +931,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
int totarrowpoints = runtime.arrow_start_style;
/* Setting up arrow stroke. */
- bGPDstroke *s_arrow_gps = BKE_gpencil_stroke_duplicate(gps, false);
+ bGPDstroke *s_arrow_gps = BKE_gpencil_stroke_duplicate(gps, false,
false);
annotation_stroke_arrow_allocate(s_arrow_gps, totarrowpoints);
/* Set pointer to first non-initialized point. */
diff --git a/source/blender/editors/gpencil/editaction_gpencil.c
b/source/blender/editors/gpencil/editaction_gpencil.c
index 752b8a74f4f..afb92ca7742 100644
--- a/source/blender/editors/gpencil/editaction_gpencil.c
+++ b/source/blender/editors/gpencil/editaction_gpencil.c
@@ -486,7 +486,7 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const
short offset_mode)
*/
for (gps = gpfs->strokes.first; gps; gps = gps->next) {
/* make a copy of stroke, then of its points array */
- gpsn = BKE_gpencil_stroke_duplicate(gps, true);
+ gpsn = BKE_gpencil_stroke_duplicate(gps, true, true);
/* append stroke to frame */
BLI_addtail(&gpf->strokes, gpsn);
diff --git a/source/blender/editors/gpencil/gpencil_data.c
b/source/blender/editors/gpencil/gpencil_data.c
index 9aac655afef..6b2f547b6a6 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -580,7 +580,7 @@ static int gpencil_layer_duplicate_object_exec(bContext *C,
wmOperator *op)
LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) {
/* Make copy of source stroke. */
- bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true);
+ bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true, true);
/* Check if material is in destination object,
* otherwise add the slot with the material. */
diff --git a/source/blender/editors/gpencil/gpencil_edit.c
b/source/blender/editors/gpencil/gpencil_edit.c
index 9abd83ef6e1..dce0f7698d7 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -862,7 +
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs