From 6fa349f85e8feff90ba00a52b3669e28ea09c223 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 25 May 2012 15:20:29 +0000 Subject: [PATCH] support for deleting splines and points while maintaining animation --- source/blender/blenkernel/BKE_mask.h | 2 ++ source/blender/blenkernel/intern/mask.c | 19 ++++++++++--------- source/blender/editors/mask/mask_ops.c | 13 +++++++++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 7745eb0b972..fb9db2fcf98 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -115,6 +115,8 @@ int BKE_mask_object_shape_spline_index(struct MaskObject *maskobj, int index, void BKE_mask_object_shape_changed_add(struct MaskObject *maskobj, int index, int do_init, int do_init_interpolate); +void BKE_mask_object_shape_changed_remove(struct MaskObject *maskobj, int index, int count); + /* rasterization */ void BKE_mask_rasterize(struct Mask *mask, int width, int height, float *buffer); diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index bc9629176cc..146b67bd15c 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -1428,33 +1428,34 @@ void BKE_mask_object_shape_changed_add(MaskObject *maskobj, int index, } } + /* move array to account for removed point */ -void BKE_mask_object_shape_changed_remove(MaskObject *maskobj, int index) +void BKE_mask_object_shape_changed_remove(MaskObject *maskobj, int index, int count) { MaskObjectShape *maskobj_shape; /* the point has already been removed in this array so add one when comparing with the shapes */ - int tot = BKE_mask_object_shape_totvert(maskobj) + 1; + int tot = BKE_mask_object_shape_totvert(maskobj); for (maskobj_shape = maskobj->splines_shapes.first; maskobj_shape; maskobj_shape = maskobj_shape->next) { - if (tot == maskobj_shape->tot_vert) { + if (tot == maskobj_shape->tot_vert - count) { float *data_resized; - maskobj_shape->tot_vert--; + maskobj_shape->tot_vert -= count; data_resized = MEM_mallocN(maskobj_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__); if (index > 0) { memcpy(data_resized, maskobj_shape->data, - (index - 1) * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); + index * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); } - if (index != maskobj_shape->tot_vert - 1) { + if (index != maskobj_shape->tot_vert) { memcpy(&data_resized[index * MASK_OBJECT_SHAPE_ELEM_SIZE], - maskobj_shape->data + (index * MASK_OBJECT_SHAPE_ELEM_SIZE), - (maskobj_shape->tot_vert - (index + 1)) * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); + maskobj_shape->data + ((index + count) * MASK_OBJECT_SHAPE_ELEM_SIZE), + (maskobj_shape->tot_vert - index) * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE); } MEM_freeN(maskobj_shape->data); @@ -1462,7 +1463,7 @@ void BKE_mask_object_shape_changed_remove(MaskObject *maskobj, int index) } else { printf("%s: vert mismatch %d != %d (frame %d)\n", - __func__, maskobj_shape->tot_vert, tot, maskobj_shape->frame); + __func__, maskobj_shape->tot_vert - count, tot, maskobj_shape->frame); } } } diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index e52d673ad9e..69befc16b87 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -1305,11 +1305,13 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) { Mask *mask = CTX_data_edit_mask(C); MaskObject *maskobj; + int mask_object_shape_ofs = 0; for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) { MaskSpline *spline = maskobj->splines.first; while (spline) { + const int tot_point_orig = spline->tot_point; int i, count = 0; MaskSpline *next_spline = spline->next; @@ -1322,6 +1324,7 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) } if (count == 0) { + /* delete the whole spline */ BLI_remlink(&maskobj->splines, spline); BKE_mask_spline_free(spline); @@ -1330,6 +1333,8 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) maskobj->act_spline = NULL; maskobj->act_point = NULL; } + + BKE_mask_object_shape_changed_remove(maskobj, mask_object_shape_ofs, tot_point_orig); } else { MaskSplinePoint *new_points; @@ -1337,7 +1342,7 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) new_points = MEM_callocN(count * sizeof(MaskSplinePoint), "deleteMaskPoints"); - for (i = 0, j = 0; i < spline->tot_point; i++) { + for (i = 0, j = 0; i < tot_point_orig; i++) { MaskSplinePoint *point = &spline->points[i]; if (!MASKPOINT_ISSEL(point)) { @@ -1354,12 +1359,16 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) maskobj->act_point = NULL; BKE_mask_point_free(point); + spline->tot_point--; + + BKE_mask_object_shape_changed_remove(maskobj, mask_object_shape_ofs + j, 1); } } + mask_object_shape_ofs += spline->tot_point; + MEM_freeN(spline->points); spline->points = new_points; - spline->tot_point = j; ED_mask_select_flush_all(mask); }