operator to reset feather weights on all shape keys
authorCampbell Barton <ideasman42@gmail.com>
Tue, 5 Jun 2012 19:39:12 +0000 (19:39 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 5 Jun 2012 19:39:12 +0000 (19:39 +0000)
release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/BKE_mask.h
source/blender/blenkernel/intern/mask.c
source/blender/editors/mask/mask_edit.c
source/blender/editors/mask/mask_intern.h
source/blender/editors/mask/mask_shapekey.c
source/blender/makesdna/DNA_mask_types.h

index 388843f8e70c6da7ad041328fa09a48f80062aa7..9f283b70f7721b9e6394d084ac794e084aecab70 100644 (file)
@@ -1224,13 +1224,10 @@ class CLIP_MT_mask(Menu):
         layout.operator("mask.parent_clear")
         layout.operator("mask.parent_set")
 
-        layout.separator()
-        layout.operator("mask.shape_key_clear")
-        layout.operator("mask.shape_key_insert")
-
         layout.separator()
         layout.menu("CLIP_MT_mask_visibility")
         layout.menu("CLIP_MT_mask_transform")
+        layout.menu("CLIP_MT_mask_animation")
 
 
 class CLIP_MT_mask_visibility(Menu):
@@ -1259,6 +1256,17 @@ class CLIP_MT_mask_transform(Menu):
         props.mode = 'MASK_SHRINKFATTEN'
 
 
+class CLIP_MT_mask_animation(Menu):
+    bl_label = "Animation"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("mask.shape_key_clear")
+        layout.operator("mask.shape_key_insert")
+        layout.operator("mask.shape_key_feather_reset")
+
+
 class CLIP_MT_camera_presets(Menu):
     """Predefined tracking camera intrinsics"""
     bl_label = "Camera Presets"
index 3ca892604c50a93341605bf9e7a39d005e8f478f..19feb4d8f2ec46f9c49347c850fe2970e83bae7f 100644 (file)
@@ -141,11 +141,13 @@ void BKE_mask_layer_shape_to_mask_interp(struct MaskLayer *masklay,
                                          struct MaskLayerShape *masklay_shape_a,
                                          struct MaskLayerShape *masklay_shape_b,
                                          const float fac);
-struct MaskLayerShape *BKE_mask_layer_shape_find_frame(struct MaskLayer *masklay, int frame);
-int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, int frame,
+struct MaskLayerShape *BKE_mask_layer_shape_find_frame(struct MaskLayer *masklay, const int frame);
+int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, const int frame,
                                           struct MaskLayerShape **r_masklay_shape_a,
                                           struct MaskLayerShape **r_masklay_shape_b);
-struct MaskLayerShape *BKE_mask_layer_shape_varify_frame(struct MaskLayer *masklay, int frame);
+struct MaskLayerShape *BKE_mask_layer_shape_alloc(struct MaskLayer *masklay, const int frame);
+void BKE_mask_layer_shape_free(struct MaskLayerShape *masklay_shape);
+struct MaskLayerShape *BKE_mask_layer_shape_varify_frame(struct MaskLayer *masklay, const int frame);
 void BKE_mask_layer_shape_unlink(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
 void BKE_mask_layer_shape_sort(struct MaskLayer *masklay);
 
index 102ec454aaacc20ad67db60c0683d1dd12f6d2c5..aaefa558c9ba9663c274cb7511c091d6088ce4f0 100644 (file)
@@ -466,10 +466,6 @@ void BKE_mask_point_direction_switch(MaskSplinePoint *point)
        }
 }
 
-typedef struct MaskLayerShapeElem {
-       float value[MASK_OBJECT_SHAPE_ELEM_SIZE];
-} MaskLayerShapeElem;
-
 void BKE_mask_spline_direction_switch(MaskLayer *masklay, MaskSpline *spline)
 {
        const int tot_point = spline->tot_point;
@@ -1008,6 +1004,20 @@ MaskSpline *BKE_mask_spline_copy(MaskSpline *spline)
        return nspline;
 }
 
+/* note: does NOT add to the list */
+MaskLayerShape *BKE_mask_layer_shape_alloc(MaskLayer *masklay, const int frame)
+{
+       MaskLayerShape *masklay_shape;
+       int tot_vert = BKE_mask_layer_shape_totvert(masklay);
+
+       masklay_shape = MEM_mallocN(sizeof(MaskLayerShape), __func__);
+       masklay_shape->frame = frame;
+       masklay_shape->tot_vert = tot_vert;
+       masklay_shape->data = MEM_mallocN(tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__);
+
+       return masklay_shape;
+}
+
 void BKE_mask_layer_shape_free(MaskLayerShape *masklay_shape)
 {
        MEM_freeN(masklay_shape->data);
@@ -1696,7 +1706,7 @@ void BKE_mask_layer_shape_to_mask_interp(MaskLayer *masklay,
        }
 }
 
-MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, int frame)
+MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, const int frame)
 {
        MaskLayerShape *masklay_shape;
 
@@ -1716,7 +1726,7 @@ MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, int frame)
 }
 
 /* when returning 2 - the frame isnt found but before/after frames are */
-int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, int frame,
+int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, const int frame,
                                           MaskLayerShape **r_masklay_shape_a,
                                           MaskLayerShape **r_masklay_shape_b)
 {
@@ -1751,22 +1761,15 @@ int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, int frame,
        return 0;
 }
 
-MaskLayerShape *BKE_mask_layer_shape_varify_frame(MaskLayer *masklay, int frame)
+MaskLayerShape *BKE_mask_layer_shape_varify_frame(MaskLayer *masklay, const int frame)
 {
        MaskLayerShape *masklay_shape;
 
        masklay_shape = BKE_mask_layer_shape_find_frame(masklay, frame);
 
        if (masklay_shape == NULL) {
-               int tot_vert = BKE_mask_layer_shape_totvert(masklay);
-
-               masklay_shape = MEM_mallocN(sizeof(MaskLayerShape), __func__);
-               masklay_shape->frame = frame;
-               masklay_shape->tot_vert = tot_vert;
-               masklay_shape->data = MEM_mallocN(tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__);
-
+               masklay_shape = BKE_mask_layer_shape_alloc(masklay, frame);
                BLI_addtail(&masklay->splines_shapes, masklay_shape);
-
                BKE_mask_layer_shape_sort(masklay);
        }
 
index ffcadbd086f68281382f8f80b01bafcd36229b27..9bfcd2a988679668ed95f1e08003ca0973f703ae 100644 (file)
@@ -227,6 +227,7 @@ void ED_operatortypes_mask(void)
        /* shapekeys */
        WM_operatortype_append(MASK_OT_shape_key_insert);
        WM_operatortype_append(MASK_OT_shape_key_clear);
+       WM_operatortype_append(MASK_OT_shape_key_feather_reset);
 }
 
 void ED_keymap_mask(wmKeyConfig *keyconf)
index 9ac55f22fd9557d388a00bf99a3ca68f6f7b3403..fc6089238a150b65e40db00f06b8f76bb5957e92 100644 (file)
@@ -108,5 +108,6 @@ void ED_mask_point_pos__reverse(struct bContext *C, float x, float y, float *xr,
 /* mask_shapekey.c */
 void MASK_OT_shape_key_insert(struct wmOperatorType *ot);
 void MASK_OT_shape_key_clear(struct wmOperatorType *ot);
+void MASK_OT_shape_key_feather_reset(struct wmOperatorType *ot);
 
 #endif /* __MASK_INTERN_H__ */
index 0c01487b2a9271688c18df6fb945418b82df92fb..38e8ed627f22fc7583f1973fab5be9ad9be54a34 100644 (file)
@@ -35,6 +35,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_mask.h"
 
+#include "DNA_object_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_scene_types.h"
 
@@ -155,3 +156,96 @@ int ED_mask_layer_shape_auto_key_all(Mask *mask, const int frame)
 
        return change;
 }
+
+
+static int mask_shape_key_feather_reset_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Scene *scene = CTX_data_scene(C);
+       const int frame = CFRA;
+       Mask *mask = CTX_data_edit_mask(C);
+       MaskLayer *masklay;
+       int change = FALSE;
+
+       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+
+               if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+                       continue;
+               }
+
+               if (masklay->splines_shapes.first) {
+                       MaskLayerShape *masklay_shape_reset;
+                       MaskLayerShape *masklay_shape;
+
+                       /* get the shapekey of the current state */
+                       masklay_shape_reset = BKE_mask_layer_shape_alloc(masklay, frame);
+                       /* initialize from mask - as if inseting a keyframe */
+                       BKE_mask_layer_shape_from_mask(masklay, masklay_shape_reset);
+
+                       for (masklay_shape = masklay->splines_shapes.first;
+                            masklay_shape;
+                            masklay_shape = masklay_shape->next)
+                       {
+
+                               if (masklay_shape_reset->tot_vert == masklay_shape->tot_vert) {
+                                       int i_abs = 0;
+                                       int i;
+                                       MaskSpline *spline;
+                                       MaskLayerShapeElem *shape_ele_src;
+                                       MaskLayerShapeElem *shape_ele_dst;
+
+                                       shape_ele_src = (MaskLayerShapeElem *)masklay_shape_reset->data;
+                                       shape_ele_dst = (MaskLayerShapeElem *)masklay_shape->data;
+
+                                       for (spline = masklay->splines.first; spline; spline = spline->next) {
+                                               for (i = 0; i < spline->tot_point; i++) {
+                                                       MaskSplinePoint *point = &spline->points[i];
+
+                                                       if (MASKPOINT_ISSEL_ANY(point)) {
+                                                               /* TODO - nicer access here */
+                                                               shape_ele_dst->value[6] = shape_ele_src->value[6];
+                                                       }
+
+                                                       shape_ele_src++;
+                                                       shape_ele_dst++;
+
+                                                       i_abs++;
+                                               }
+                                       }
+
+                               }
+                               else {
+                                       // printf("%s: skipping\n", __func__);
+                               }
+
+                               change = TRUE;
+                       }
+
+                       BKE_mask_layer_shape_free(masklay_shape_reset);
+               }
+       }
+
+       if (change) {
+               WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
+               DAG_id_tag_update(&mask->id, 0);
+
+               return OPERATOR_FINISHED;
+       }
+       else {
+               return OPERATOR_CANCELLED;
+       }
+}
+
+void MASK_OT_shape_key_feather_reset(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Feather Reset Animation";
+       ot->description = "Resets fearther weights on all selected points animation values";
+       ot->idname = "MASK_OT_shape_key_feather_reset";
+
+       /* api callbacks */
+       ot->exec = mask_shape_key_feather_reset_exec;
+       ot->poll = ED_maskedit_mask_poll;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
index 28fc9466613ab1d562a264872786ecdc8a84e6ba..c036369c692996b8c0e77a125e5e292a12136ba4 100644 (file)
@@ -97,6 +97,15 @@ typedef struct MaskLayerShape {
        char   pad[7];
 } MaskLayerShape;
 
+/* cast to this for convenience, not saved */
+#define MASK_OBJECT_SHAPE_ELEM_SIZE 8 /* 3x 2D points + weight + radius == 8 */
+
+#
+#
+typedef struct MaskLayerShapeElem {
+       float value[MASK_OBJECT_SHAPE_ELEM_SIZE];
+} MaskLayerShapeElem;
+
 typedef struct MaskLayer {
        struct MaskLayer *next, *prev;
 
@@ -129,8 +138,6 @@ typedef struct MaskLayer {
 #define MASK_SPLINE_INTERP_LINEAR   1
 #define MASK_SPLINE_INTERP_EASE     2
 
-#define MASK_OBJECT_SHAPE_ELEM_SIZE 8 /* 3x 2D points + weight + radius == 8 */
-
 /* ob->restrictflag */
 #define MASK_RESTRICT_VIEW      1
 #define MASK_RESTRICT_SELECT    2