diff options
Diffstat (limited to 'source/blender/blenkernel/intern/gpencil.c')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 147 |
1 files changed, 103 insertions, 44 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 647db970d09..d1a7c95fe8d 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -186,6 +186,7 @@ static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id BLO_write_struct(writer, bGPDcurve, gpc); BLO_write_struct_array( writer, bGPDcurve_point, gpc->tot_curve_points, gpc->curve_points); + BKE_defvert_blend_write(writer, gpc->tot_curve_points, gpc->dvert); } } } @@ -259,6 +260,11 @@ void BKE_gpencil_blend_read_data(BlendDataReader *reader, bGPdata *gpd) if (gps->editcurve != NULL) { /* Relink curve point array. */ BLO_read_data_address(reader, &gps->editcurve->curve_points); + if (gps->editcurve->dvert != NULL) { + BLO_read_data_address(reader, &gps->editcurve->dvert); + BKE_defvert_blend_read( + reader, gps->editcurve->tot_curve_points, gps->editcurve->dvert); + } } /* Relink weight data. */ @@ -388,12 +394,19 @@ void BKE_gpencil_free_stroke_editcurve(bGPDstroke *gps) if (gps == NULL) { return; } - bGPDcurve *editcurve = gps->editcurve; - if (editcurve == NULL) { + bGPDcurve *gpc = gps->editcurve; + if (gpc == NULL) { return; } - MEM_freeN(editcurve->curve_points); - MEM_freeN(editcurve); + MEM_freeN(gpc->curve_points); + if (gpc->dvert != NULL) { + for (int i = 0; i < gpc->tot_curve_points; i++) { + MDeformVert *dvert = &gpc->dvert[i]; + BKE_gpencil_free_point_weights(dvert); + } + MEM_freeN(gpc->dvert); + } + MEM_freeN(gpc); gps->editcurve = NULL; } @@ -407,8 +420,9 @@ void BKE_gpencil_free_stroke(bGPDstroke *gps) if (gps->points) { MEM_freeN(gps->points); } + + BKE_gpencil_free_stroke_weights(gps); if (gps->dvert) { - BKE_gpencil_free_stroke_weights(gps); MEM_freeN(gps->dvert); } if (gps->triangles) { @@ -766,8 +780,6 @@ 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; @@ -942,6 +954,16 @@ 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); } +void BKE_gpencil_editcurve_weights_duplicate(bGPDcurve *gpc_src, bGPDcurve *gpc_dst) +{ + if (gpc_src == NULL) { + return; + } + BLI_assert(gpc_src->tot_curve_points == gpc_dst->tot_curve_points); + + BKE_defvert_array_copy(gpc_dst->dvert, gpc_src->dvert, gpc_src->tot_curve_points); +} + /* Make a copy of a given gpencil stroke editcurve */ bGPDcurve *BKE_gpencil_stroke_curve_duplicate(bGPDcurve *gpc_src) { @@ -951,6 +973,14 @@ bGPDcurve *BKE_gpencil_stroke_curve_duplicate(bGPDcurve *gpc_src) gpc_dst->curve_points = MEM_dupallocN(gpc_src->curve_points); } + if (gpc_src->dvert != NULL) { + gpc_dst->dvert = MEM_dupallocN(gpc_src->dvert); + BKE_gpencil_editcurve_weights_duplicate(gpc_src, gpc_dst); + } + else { + gpc_dst->dvert = NULL; + } + return gpc_dst; } @@ -1197,7 +1227,6 @@ void BKE_gpencil_curve_sync_selection(bGPdata *gpd, bGPDstroke *gps) return; } - gps->flag &= ~GP_STROKE_SELECT; BKE_gpencil_stroke_select_index_reset(gps); gpc->flag &= ~GP_CURVE_SELECT; @@ -1220,7 +1249,6 @@ void BKE_gpencil_curve_sync_selection(bGPdata *gpd, bGPDstroke *gps) if (is_selected) { gpc->flag |= GP_CURVE_SELECT; - gps->flag |= GP_STROKE_SELECT; BKE_gpencil_stroke_select_index_set(gpd, gps); } } @@ -1257,14 +1285,7 @@ void BKE_gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf) } /* free the stroke and its data */ - if (gps->points) { - MEM_freeN(gps->points); - } - if (gps->dvert) { - BKE_gpencil_free_stroke_weights(gps); - MEM_freeN(gps->dvert); - } - MEM_freeN(gps->triangles); + BKE_gpencil_free_stroke(gps); BLI_freelinkN(&gpf->strokes, gps); /* if frame has no strokes after this, delete it */ @@ -2078,6 +2099,26 @@ bool BKE_gpencil_stroke_select_check(const bGPDstroke *gps) /* ************************************************** */ /* GP Object - Vertex Groups */ +/* Helper to remove a dvert from a group. */ +static void gpencil_remove_dvert_ex(MDeformVert *dvert, const int def_nr, const int tot_groups) +{ + if (dvert == NULL) { + return; + } + + MDeformWeight *dw = BKE_defvert_find_index(dvert, def_nr); + if (dw != NULL) { + BKE_defvert_remove_group(dvert, dw); + } + /* Reorganize weights for other groups after deleted one. */ + for (int g = 0; g < tot_groups; g++) { + dw = BKE_defvert_find_index(dvert, g); + if ((dw != NULL) && (dw->def_nr > def_nr)) { + dw->def_nr--; + } + } +} + /** * Remove a vertex group. * \param ob: Grease pencil object @@ -2086,7 +2127,6 @@ bool BKE_gpencil_stroke_select_check(const bGPDstroke *gps) void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup) { bGPdata *gpd = ob->data; - MDeformVert *dvert = NULL; const int def_nr = BLI_findindex(&ob->defbase, defgroup); const int totgrp = BLI_listbase_count(&ob->defbase); @@ -2095,20 +2135,17 @@ void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup) LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - if (gps->dvert != NULL) { + if (GPENCIL_STROKE_TYPE_BEZIER(gps)) { + bGPDcurve *gpc = gps->editcurve; + for (int i = 0; i < gpc->tot_curve_points; i++) { + MDeformVert *dvert = &gpc->dvert[i]; + gpencil_remove_dvert_ex(dvert, def_nr, totgrp); + } + } + else if (gps->dvert != NULL) { for (int i = 0; i < gps->totpoints; i++) { - dvert = &gps->dvert[i]; - MDeformWeight *dw = BKE_defvert_find_index(dvert, def_nr); - if (dw != NULL) { - BKE_defvert_remove_group(dvert, dw); - } - /* Reorganize weights for other groups after deleted one. */ - for (int g = 0; g < totgrp; g++) { - dw = BKE_defvert_find_index(dvert, g); - if ((dw != NULL) && (dw->def_nr > def_nr)) { - dw->def_nr--; - } - } + MDeformVert *dvert = &gps->dvert[i]; + gpencil_remove_dvert_ex(dvert, def_nr, totgrp); } } } @@ -2127,8 +2164,12 @@ void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup) */ void BKE_gpencil_dvert_ensure(bGPDstroke *gps) { - if (gps->dvert == NULL) { - gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights"); + if (GPENCIL_STROKE_TYPE_BEZIER(gps) && gps->editcurve->dvert == NULL) { + bGPDcurve *gpc = gps->editcurve; + gpc->dvert = MEM_callocN(sizeof(MDeformVert) * gpc->tot_curve_points, __func__); + } + else if (gps->dvert == NULL) { + gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, __func__); } } @@ -2654,7 +2695,7 @@ bool BKE_gpencil_from_image( BKE_gpencil_stroke_select_index_set(gpd, gps); } - BKE_gpencil_stroke_geometry_update(gpd, gps); + BKE_gpencil_stroke_geometry_update(gpd, gps, GP_GEO_UPDATE_DEFAULT); } } @@ -2949,19 +2990,37 @@ void BKE_gpencil_frame_original_pointers_update(const struct bGPDframe *gpf_orig /* Assign original stroke pointer. */ if (gps_eval != NULL) { gps_eval->runtime.gps_orig = gps_orig; + if (GPENCIL_STROKE_TYPE_BEZIER(gps_orig)) { + bGPDcurve *gpc_orig = gps_orig->editcurve; + bGPDcurve *gpc_eval = gps_eval->editcurve; - /* Assign original point pointer. */ - for (int i = 0; i < gps_orig->totpoints; i++) { - if (i > gps_eval->totpoints - 1) { - break; + for (int i = 0; i < gpc_orig->tot_curve_points; i++) { + if (i > gpc_eval->tot_curve_points - 1) { + break; + } + bGPDcurve_point *gpc_pt_orig = &gpc_orig->curve_points[i]; + bGPDcurve_point *gpc_pt_eval = &gpc_eval->curve_points[i]; + gpc_pt_orig->runtime.gpc_pt_orig = NULL; + gpc_pt_orig->runtime.idx_orig = i; + gpc_pt_eval->runtime.gpc_pt_orig = gpc_pt_orig; + gpc_pt_eval->runtime.idx_orig = i; } - bGPDspoint *pt_orig = &gps_orig->points[i]; - bGPDspoint *pt_eval = &gps_eval->points[i]; - pt_orig->runtime.pt_orig = NULL; - pt_orig->runtime.idx_orig = i; - pt_eval->runtime.pt_orig = pt_orig; - pt_eval->runtime.idx_orig = i; } + else { + /* Assign original point pointer. */ + for (int i = 0; i < gps_orig->totpoints; i++) { + if (i > gps_eval->totpoints - 1) { + break; + } + bGPDspoint *pt_orig = &gps_orig->points[i]; + bGPDspoint *pt_eval = &gps_eval->points[i]; + pt_orig->runtime.pt_orig = NULL; + pt_orig->runtime.idx_orig = i; + pt_eval->runtime.pt_orig = pt_orig; + pt_eval->runtime.idx_orig = i; + } + } + /* Increase pointer. */ gps_eval = gps_eval->next; } |