[Bf-blender-cvs] [cf4c3a72edc] soc-2020-greasepencil-curve: GPencil: Add curve point data structure
Falk David
noreply at git.blender.org
Fri Jun 12 13:52:54 CEST 2020
Commit: cf4c3a72edc20f269a8cac40d716258d9751e191
Author: Falk David
Date: Fri Jun 12 13:34:47 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rBcf4c3a72edc20f269a8cac40d716258d9751e191
GPencil: Add curve point data structure
The BezTriple in bGPDcurve was changed to a new data structure: bGPDcurve_point. The RNA properties where adapted to support the new data structure.
===================================================================
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/gpencil_curve.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_gpencil_types.h
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 8d81528fdcf..28b209ba676 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -187,7 +187,6 @@ void BKE_gpencil_free_stroke_editcurve(bGPDstroke *gps)
return;
}
MEM_freeN(editcurve->curve_points);
- MEM_freeN(editcurve->point_index_array);
MEM_freeN(editcurve);
gps->editcurve = NULL;
}
@@ -629,9 +628,8 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_new(int tot_curve_points)
{
bGPDcurve *new_gp_curve = (bGPDcurve *)MEM_callocN(sizeof(bGPDcurve), __func__);
new_gp_curve->tot_curve_points = tot_curve_points;
- new_gp_curve->curve_points = (BezTriple *)MEM_callocN(sizeof(BezTriple) * tot_curve_points,
- __func__);
- new_gp_curve->point_index_array = (int *)MEM_callocN(sizeof(int) * tot_curve_points, __func__);
+ new_gp_curve->curve_points = (bGPDcurve_point *)MEM_callocN(
+ sizeof(bGPDcurve_point) * tot_curve_points, __func__);
return new_gp_curve;
}
@@ -654,7 +652,6 @@ void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_d
bGPDcurve *BKE_gpencil_stroke_curve_duplicate(bGPDcurve *gpc_src)
{
bGPDcurve *gpc_dst = MEM_dupallocN(gpc_src);
- gpc_dst->point_index_array = MEM_dupallocN(gpc_src->point_index_array);
if (gpc_src->curve_points != NULL) {
gpc_dst->curve_points = MEM_dupallocN(gpc_src->curve_points);
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index a3cf3d03959..e1987b373ba 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -498,7 +498,8 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps)
bGPDcurve *editcurve = BKE_gpencil_stroke_editcurve_new(r_cubic_array_len);
for (int i = 0; i < r_cubic_array_len; i++) {
- BezTriple *bezt = &editcurve->curve_points[i];
+ bGPDcurve_point *cpt = &editcurve->curve_points[i];
+ BezTriple *bezt = &cpt->bezt;
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]);
@@ -506,7 +507,7 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps)
bezt->radius = orig_pt->pressure;
bezt->weight = orig_pt->strength;
- editcurve->point_index_array[i] = r_cubic_orig_index[i];
+ cpt->point_index = r_cubic_orig_index[i];
}
MEM_freeN(points);
@@ -587,27 +588,28 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps)
}
bGPDcurve *editcurve = gps->editcurve;
- BezTriple *bezt_array = editcurve->curve_points;
- int bezt_array_len = editcurve->tot_curve_points;
+ bGPDcurve_point *curve_point_array = editcurve->curve_points;
+ int curve_point_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 array_last = curve_point_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);
+ const uint points_len = BKE_curve_calc_coords_axis_len(
+ curve_point_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],
+ for (unsigned int i = 0; i < array_last; i++) {
+ bGPDcurve_point *cpt_curr = &curve_point_array[i];
+ bGPDcurve_point *cpt_next = &curve_point_array[i + 1];
+ BKE_curve_forward_diff_bezier(cpt_curr->bezt.vec[1][axis],
+ cpt_curr->bezt.vec[2][axis],
+ cpt_next->bezt.vec[0][axis],
+ cpt_next->bezt.vec[1][axis],
points_offset,
(int)resolu,
stride);
@@ -615,20 +617,20 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps)
}
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],
+ bGPDcurve_point *cpt_curr = &curve_point_array[array_last];
+ bGPDcurve_point *cpt_next = &curve_point_array[0];
+ BKE_curve_forward_diff_bezier(cpt_curr->bezt.vec[1][axis],
+ cpt_curr->bezt.vec[2][axis],
+ cpt_next->bezt.vec[0][axis],
+ cpt_next->bezt.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];
+ float *points_last = POINTER_OFFSET(&points[0][axis], array_last * resolu_stride);
+ *points_last = curve_point_array[array_last].bezt.vec[1][axis];
points_offset = POINTER_OFFSET(points_offset, stride);
}
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7a108e9025e..a8cda1aced8 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7180,8 +7180,8 @@ static void direct_link_gpencil(BlendDataReader *reader, bGPdata *gpd)
/* relink stroke edit curve. */
BLO_read_data_address(reader, &gps->editcurve);
if (gps->editcurve != NULL) {
+ /* relink curve point array */
BLO_read_data_address(reader, &gps->editcurve->curve_points);
- BLO_read_data_address(reader, &gps->editcurve->point_index_array);
}
/* relink weight data */
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d78ffb2731a..0c41f0312e8 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2875,10 +2875,10 @@ static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_addr
BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles);
if (gps->editcurve != NULL) {
BLO_write_struct(writer, bGPDcurve, gps->editcurve);
- BLO_write_struct_array(
- writer, BezTriple, gps->editcurve->tot_curve_points, gps->editcurve->curve_points);
- BLO_write_int32_array(
- writer, gps->editcurve->tot_curve_points, gps->editcurve->point_index_array);
+ BLO_write_struct_array(writer,
+ bGPDcurve_point,
+ gps->editcurve->tot_curve_points,
+ gps->editcurve->curve_points);
}
write_dverts(writer, gps->totpoints, gps->dvert);
}
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index f108272617a..8161fedc266 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -170,12 +170,46 @@ typedef enum eGPDpalette_Flag {
PL_PALETTE_ACTIVE = (1 << 0),
} eGPDpalette_Flag;
+/* ***************************************** */
+/* GP Curve Point */
+
+typedef struct bGPDcurve_point {
+ /** Bezier Triple for the handles and control points */
+ BezTriple bezt;
+ /** Pressure of input device (from 0 to 1) at this point. */
+ float pressure;
+ /** Color strength (used for alpha factor). */
+ float strength;
+ /** Index of corresponding point in gps->points */
+ int point_index;
+
+ /** Additional options. */
+ int flag;
+
+ /** Factor of uv along the stroke. */
+ float uv_fac;
+ /** Uv rotation for dot mode. */
+ float uv_rot;
+ /** Uv for fill mode */
+ float uv_fill[2];
+
+ /** Vertex Color RGBA (A=mix factor). */
+ float vert_color[4];
+ char _pad2[4];
+} bGPDcurve_point;
+
+/* bGPDcurve_point->flag */
+typedef enum eGPDcurve_point_Flag {
+ GP_CURVE_POINT_SELECT = (1 << 0),
+} eGPDcurve_point_Flag;
+
+/* ***************************************** */
+/* GP Curve */
+
/* Curve for Bezier Editing. */
typedef struct bGPDcurve {
/** Array of BezTriple. */
- BezTriple *curve_points;
- /** Array of indexes of nearest stroke points. */
- int *point_index_array;
+ bGPDcurve_point *curve_points;
/** Total number of curve points. */
int tot_curve_points;
/** Resolution for curve sampling */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 6da44fa02e2..c34901a6710 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1004,75 +1004,88 @@ static char *rna_GreasePencilGrid_path(PointerRNA *UNUSED(ptr))
return BLI_strdup("grid");
}
-static void rna_BezTriple_handle1_get(PointerRNA *ptr, float *values)
+static void rna_GpencilCurvePoint_BezTriple_handle1_get(PointerRNA *ptr, float *values)
{
- BezTriple *bezt = (BezTriple *)ptr->data;
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list