diff options
Diffstat (limited to 'source/blender/blenkernel/intern/gpencil.c')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 138 |
1 files changed, 125 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 6c6ca996caa..98e83bfb789 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -155,6 +155,12 @@ static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points); BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles); BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert); + if (gps->editcurve != NULL) { + bGPDcurve *gpc = gps->editcurve; + BLO_write_struct(writer, bGPDcurve, gpc); + BLO_write_struct_array( + writer, bGPDcurve_point, gpc->tot_curve_points, gpc->curve_points); + } } } } @@ -222,6 +228,13 @@ void BKE_gpencil_blend_read_data(BlendDataReader *reader, bGPdata *gpd) /* Relink geometry*/ BLO_read_data_address(reader, &gps->triangles); + /* 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); + } + /* relink weight data */ if (gps->dvert) { BLO_read_data_address(reader, &gps->dvert); @@ -288,6 +301,8 @@ IDTypeInfo IDType_ID_GD = { .blend_read_data = greasepencil_blend_read_data, .blend_read_lib = greasepencil_blend_read_lib, .blend_read_expand = greasepencil_blend_read_expand, + + .blend_read_undo_preserve = NULL, }; /* ************************************************** */ @@ -339,6 +354,20 @@ void BKE_gpencil_free_stroke_weights(bGPDstroke *gps) } } +void BKE_gpencil_free_stroke_editcurve(bGPDstroke *gps) +{ + if (gps == NULL) { + return; + } + bGPDcurve *editcurve = gps->editcurve; + if (editcurve == NULL) { + return; + } + MEM_freeN(editcurve->curve_points); + MEM_freeN(editcurve); + gps->editcurve = NULL; +} + /* free stroke, doesn't unlink from any listbase */ void BKE_gpencil_free_stroke(bGPDstroke *gps) { @@ -356,6 +385,9 @@ void BKE_gpencil_free_stroke(bGPDstroke *gps) if (gps->triangles) { MEM_freeN(gps->triangles); } + if (gps->editcurve != NULL) { + BKE_gpencil_free_stroke_editcurve(gps); + } MEM_freeN(gps); } @@ -686,6 +718,13 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[]) gpd->pixfactor = GP_DEFAULT_PIX_FACTOR; + gpd->curve_edit_resolution = GP_DEFAULT_CURVE_RESOLUTION; + gpd->curve_edit_threshold = GP_DEFAULT_CURVE_ERROR; + gpd->curve_edit_corner_angle = GP_DEFAULT_CURVE_EDIT_CORNER_ANGLE; + + /* use adaptive curve resolution by default */ + gpd->flag |= GP_DATA_CURVE_ADAPTIVE_RESOLUTION; + gpd->zdepth_offset = 0.150f; /* grid settings */ @@ -774,6 +813,8 @@ bGPDstroke *BKE_gpencil_stroke_new(int mat_idx, int totpoints, short thickness) gps->mat_nr = mat_idx; + gps->editcurve = NULL; + return gps; } @@ -825,6 +866,16 @@ bGPDstroke *BKE_gpencil_stroke_add_existing_style( return gps; } +bGPDcurve *BKE_gpencil_stroke_editcurve_new(const 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 = (bGPDcurve_point *)MEM_callocN( + sizeof(bGPDcurve_point) * tot_curve_points, __func__); + + return new_gp_curve; +} + /* ************************************************** */ /* Data Duplication */ @@ -843,13 +894,28 @@ void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_d BKE_defvert_array_copy(gps_dst->dvert, gps_src->dvert, gps_src->totpoints); } +/* Make a copy of a given gpencil stroke editcurve */ +bGPDcurve *BKE_gpencil_stroke_curve_duplicate(bGPDcurve *gpc_src) +{ + bGPDcurve *gpc_dst = MEM_dupallocN(gpc_src); + + if (gpc_src->curve_points != NULL) { + gpc_dst->curve_points = MEM_dupallocN(gpc_src->curve_points); + } + + return gpc_dst; +} + /** * 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; @@ -868,6 +934,17 @@ bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src, const bool dup_poi gps_dst->dvert = NULL; } } + else { + gps_dst->points = NULL; + gps_dst->dvert = NULL; + } + + if (dup_curve && gps_src->editcurve != NULL) { + gps_dst->editcurve = BKE_gpencil_stroke_curve_duplicate(gps_src->editcurve); + } + else { + gps_dst->editcurve = NULL; + } /* return new stroke */ return gps_dst; @@ -896,7 +973,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); } @@ -921,7 +998,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); } } @@ -1035,6 +1112,39 @@ void BKE_gpencil_stroke_sync_selection(bGPDstroke *gps) } } +void BKE_gpencil_curve_sync_selection(bGPDstroke *gps) +{ + bGPDcurve *gpc = gps->editcurve; + if (gpc == NULL) { + return; + } + + gps->flag &= ~GP_STROKE_SELECT; + gpc->flag &= ~GP_CURVE_SELECT; + + bool is_selected = false; + for (int i = 0; i < gpc->tot_curve_points; i++) { + bGPDcurve_point *gpc_pt = &gpc->curve_points[i]; + BezTriple *bezt = &gpc_pt->bezt; + + if (BEZT_ISSEL_ANY(bezt)) { + gpc_pt->flag |= GP_SPOINT_SELECT; + } + else { + gpc_pt->flag &= ~GP_SPOINT_SELECT; + } + + if (gpc_pt->flag & GP_SPOINT_SELECT) { + is_selected = true; + } + } + + if (is_selected) { + gpc->flag |= GP_CURVE_SELECT; + gps->flag |= GP_STROKE_SELECT; + } +} + /* ************************************************** */ /* GP Frame API */ @@ -2009,12 +2119,12 @@ void BKE_gpencil_material_remap(struct bGPdata *gpd, /** * Load a table with material conversion index for merged materials. - * \param ob: Grease pencil object - * \param hue_threshold: Threshold for Hue - * \param sat_threshold: Threshold for Saturation - * \param val_threshold: Threshold for Value - * \param r_mat_table : return material table - * \return True if done + * \param ob: Grease pencil object. + * \param hue_threshold: Threshold for Hue. + * \param sat_threshold: Threshold for Saturation. + * \param val_threshold: Threshold for Value. + * \param r_mat_table: return material table. + * \return True if done. */ bool BKE_gpencil_merge_materials_table_get(Object *ob, const float hue_threshold, @@ -2302,12 +2412,14 @@ void BKE_gpencil_palette_ensure(Main *bmain, Scene *scene) /** * Create grease pencil strokes from image * \param sima: Image + * \param gpd: Grease pencil data-block * \param gpf: Grease pencil frame * \param size: Size * \param mask: Mask * \return True if done */ -bool BKE_gpencil_from_image(SpaceImage *sima, bGPDframe *gpf, const float size, const bool mask) +bool BKE_gpencil_from_image( + SpaceImage *sima, bGPdata *gpd, bGPDframe *gpf, const float size, const bool mask) { Image *image = sima->image; bool done = false; @@ -2355,7 +2467,7 @@ bool BKE_gpencil_from_image(SpaceImage *sima, bGPDframe *gpf, const float size, pt->flag |= GP_SPOINT_SELECT; } } - BKE_gpencil_stroke_geometry_update(gps); + BKE_gpencil_stroke_geometry_update(gpd, gps); } } @@ -2668,7 +2780,7 @@ void BKE_gpencil_parent_matrix_get(const Depsgraph *depsgraph, return; } - if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) { + if (ELEM(gpl->partype, PAROBJECT, PARSKEL)) { mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse); add_v3_v3(diff_mat[3], ob_eval->obmat[3]); return; @@ -2710,7 +2822,7 @@ void BKE_gpencil_update_layer_parent(const Depsgraph *depsgraph, Object *ob) if ((gpl->parent != NULL) && (gpl->actframe != NULL)) { Object *ob_parent = DEG_get_evaluated_object(depsgraph, gpl->parent); /* calculate new matrix */ - if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) { + if (ELEM(gpl->partype, PAROBJECT, PARSKEL)) { copy_m4_m4(cur_mat, ob_parent->obmat); } else if (gpl->partype == PARBONE) { |