[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47022] branches/soc-2011-tomato/source/ blender: support for deleting splines and points while maintaining animation

Campbell Barton ideasman42 at gmail.com
Fri May 25 17:20:29 CEST 2012


Revision: 47022
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47022
Author:   campbellbarton
Date:     2012-05-25 15:20:29 +0000 (Fri, 25 May 2012)
Log Message:
-----------
support for deleting splines and points while maintaining animation

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
    branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-05-25 14:57:17 UTC (rev 47021)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-05-25 15:20:29 UTC (rev 47022)
@@ -115,6 +115,8 @@
 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);
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-05-25 14:57:17 UTC (rev 47021)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-05-25 15:20:29 UTC (rev 47022)
@@ -1428,33 +1428,34 @@
 	}
 }
 
+
 /* 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 @@
 		}
 		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);
 		}
 	}
 }

Modified: branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c	2012-05-25 14:57:17 UTC (rev 47021)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c	2012-05-25 15:20:29 UTC (rev 47022)
@@ -1305,11 +1305,13 @@
 {
 	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 @@
 			}
 
 			if (count == 0) {
+
 				/* delete the whole spline */
 				BLI_remlink(&maskobj->splines, spline);
 				BKE_mask_spline_free(spline);
@@ -1330,6 +1333,8 @@
 					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 @@
 
 				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 @@
 							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);
 			}




More information about the Bf-blender-cvs mailing list