support for deleting splines and points while maintaining animation

This commit is contained in:
Campbell Barton
2012-05-25 15:20:29 +00:00
parent b230ebf726
commit 6fa349f85e
3 changed files with 23 additions and 11 deletions

View File

@@ -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);

View File

@@ -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);
}
}
}

View File

@@ -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);
}