mask slide now auto-keys
authorCampbell Barton <ideasman42@gmail.com>
Fri, 25 May 2012 12:48:24 +0000 (12:48 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 25 May 2012 12:48:24 +0000 (12:48 +0000)
source/blender/blenkernel/intern/mask.c
source/blender/editors/include/ED_mask.h
source/blender/editors/mask/mask_ops.c
source/blender/editors/mask/mask_shapekey.c
source/blender/editors/transform/transform_conversions.c

index 55ea417349112e255cb32e34df3bfa5210e638e4..bc9629176cce2cec0ab4e00504bbc5ced664e999 100644 (file)
@@ -1351,6 +1351,7 @@ void BKE_mask_object_shape_changed_add(MaskObject *maskobj, int index,
                                               &spline, &spline_point_index))
        {
                /* sanity check */
+               /* the point has already been removed in this array so subtract one when comparing with the shapes */
                int tot = BKE_mask_object_shape_totvert(maskobj) - 1;
 
                /* for interpolation */
@@ -1376,8 +1377,8 @@ void BKE_mask_object_shape_changed_add(MaskObject *maskobj, int index,
                }
 
                for (maskobj_shape = maskobj->splines_shapes.first;
-                        maskobj_shape;
-                        maskobj_shape = maskobj_shape->next)
+                    maskobj_shape;
+                    maskobj_shape = maskobj_shape->next)
                {
                        if (tot == maskobj_shape->tot_vert) {
                                float *data_resized;
@@ -1386,14 +1387,14 @@ void BKE_mask_object_shape_changed_add(MaskObject *maskobj, int index,
                                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 * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE);
+                                              maskobj_shape->data,
+                                              index * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE);
                                }
 
                                if (index != maskobj_shape->tot_vert - 1) {
                                        memcpy(&data_resized[(index + 1) * 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 * MASK_OBJECT_SHAPE_ELEM_SIZE),
+                                              (maskobj_shape->tot_vert - (index + 1)) * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE);
                                }
 
                                if (do_init) {
@@ -1404,16 +1405,16 @@ void BKE_mask_object_shape_changed_add(MaskObject *maskobj, int index,
                                        if (do_init_interpolate) {
                                                for (i = 0; i < 3; i++) {
                                                        interp_weights_uv_v2_apply(uv[i],
-                                                                                                          &fp[i * 2],
-                                                                                                          &data_resized[(pi_prev_abs * MASK_OBJECT_SHAPE_ELEM_SIZE) + (i * 2)],
-                                                                                                          &data_resized[(pi_next_abs * MASK_OBJECT_SHAPE_ELEM_SIZE) + (i * 2)]);
+                                                                                  &fp[i * 2],
+                                                                                  &data_resized[(pi_prev_abs * MASK_OBJECT_SHAPE_ELEM_SIZE) + (i * 2)],
+                                                                                  &data_resized[(pi_next_abs * MASK_OBJECT_SHAPE_ELEM_SIZE) + (i * 2)]);
                                                }
                                        }
                                }
                                else {
                                        memset(&data_resized[index * MASK_OBJECT_SHAPE_ELEM_SIZE],
-                                                  0,
-                                                  sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE);
+                                              0,
+                                              sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE);
                                }
 
                                MEM_freeN(maskobj_shape->data);
@@ -1428,24 +1429,43 @@ void BKE_mask_object_shape_changed_add(MaskObject *maskobj, int index,
 }
 
 /* move array to account for removed point */
-#if 0
 void BKE_mask_object_shape_changed_remove(MaskObject *maskobj, int index)
 {
        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;
+
        for (maskobj_shape = maskobj->splines_shapes.first;
             maskobj_shape;
             maskobj_shape = maskobj_shape->next)
        {
-               if (frame == maskobj_shape->frame) {
-                       return maskobj_shape;
+               if (tot == maskobj_shape->tot_vert) {
+                       float *data_resized;
+
+                       maskobj_shape->tot_vert--;
+                       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);
+                       }
+
+                       if (index != maskobj_shape->tot_vert - 1) {
+                               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);
+                       }
+
+                       MEM_freeN(maskobj_shape->data);
+                       maskobj_shape->data = data_resized;
                }
-               else if (frame < maskobj_shape->frame) {
-                       break;
+               else {
+                       printf("%s: vert mismatch %d != %d (frame %d)\n",
+                              __func__, maskobj_shape->tot_vert, tot, maskobj_shape->frame);
                }
        }
 }
-#endif
 
 /* rasterization */
 void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer)
index 01495561912f9d814f504a6ac133bc7deb936efd..ed1d2ba688ed7de903dc9b3504e0c89fee265735 100644 (file)
@@ -41,4 +41,7 @@ void ED_operatormacros_mask(void);
 /* mask_draw.c */
 void ED_mask_draw(const bContext *C);
 
+/* mask_shapekey.c */
+int ED_mask_object_shape_auto_key_all(struct Mask *mask, const int frame);
+
 #endif /* ED_TEXT_H */
index 8f8be8fefc17cf6c7ad7bc0c1c097eee533e36f1..e52d673ad9e688f6ca794e3725132d2e4c267679 100644 (file)
@@ -40,6 +40,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_mask.h"
 
+#include "DNA_scene_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_object_types.h"  /* SELECT */
 
@@ -49,6 +50,7 @@
 #include "ED_screen.h"
 #include "ED_mask.h"
 #include "ED_clip.h"
+#include "ED_keyframing.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -770,8 +772,14 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
 
                case LEFTMOUSE:
                        if (event->val == KM_RELEASE) {
+                               Scene *scene = CTX_data_scene(C);
+
                                free_slide_point_data(op->customdata);
 
+                               if (IS_AUTOKEY_ON(scene)) {
+                                       ED_mask_object_shape_auto_key_all(data->mask, CFRA);
+                               }
+
                                WM_event_add_notifier(C, NC_MASK | NA_EDITED, data->mask);
                                DAG_id_tag_update(&data->mask->id, 0);
 
index c80ca97907701c15512e8be2bc86748a14d1554d..7a91fbeed13760a51a0b3d6eb73ddf610d0937ed 100755 (executable)
@@ -142,3 +142,19 @@ void MASK_OT_shape_key_clear(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
+
+int ED_mask_object_shape_auto_key_all(Mask *mask, const int frame)
+{
+       MaskObject *maskobj;
+       int change = FALSE;
+
+       for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
+               MaskObjectShape *maskobj_shape;
+
+               maskobj_shape = BKE_mask_object_shape_varify_frame(maskobj, frame);
+               BKE_mask_object_shape_from_mask(maskobj, maskobj_shape);
+               change = TRUE;
+       }
+
+       return change;
+}
index 7cc8b47951787a88f4ca6526101a97e2e6526292..875e9e4a63f0f6c2cabb21da0cfa3919847500b0 100644 (file)
@@ -4913,16 +4913,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
 
                        /* TODO - dont key all masks... */
                        if (IS_AUTOKEY_ON(t->scene)) {
-                               MaskObject *maskobj;
                                Scene *scene = t->scene;
-                               int frame = CFRA;
 
-                               for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
-                                       MaskObjectShape *maskobj_shape;
-
-                                       maskobj_shape = BKE_mask_object_shape_varify_frame(maskobj, frame);
-                                       BKE_mask_object_shape_from_mask(maskobj, maskobj_shape);
-                               }
+                               ED_mask_object_shape_auto_key_all(mask, CFRA);
                        }
                }
        }