Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-06-05 23:39:12 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-06-05 23:39:12 +0400
commit465b11e971e126790ecd0dffa327a64189d4875e (patch)
tree788e6fc0948edec37ec35ad834ab5c322ad2f4bc /source
parent4ce2219901f247ce724bab6015138b4456483815 (diff)
operator to reset feather weights on all shape keys
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_mask.h8
-rw-r--r--source/blender/blenkernel/intern/mask.c33
-rw-r--r--source/blender/editors/mask/mask_edit.c1
-rw-r--r--source/blender/editors/mask/mask_intern.h1
-rw-r--r--source/blender/editors/mask/mask_shapekey.c94
-rw-r--r--source/blender/makesdna/DNA_mask_types.h11
6 files changed, 128 insertions, 20 deletions
diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h
index 3ca892604c5..19feb4d8f2e 100644
--- a/source/blender/blenkernel/BKE_mask.h
+++ b/source/blender/blenkernel/BKE_mask.h
@@ -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);
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index 102ec454aaa..aaefa558c9b 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -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);
}
diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c
index ffcadbd086f..9bfcd2a9886 100644
--- a/source/blender/editors/mask/mask_edit.c
+++ b/source/blender/editors/mask/mask_edit.c
@@ -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)
diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h
index 9ac55f22fd9..fc6089238a1 100644
--- a/source/blender/editors/mask/mask_intern.h
+++ b/source/blender/editors/mask/mask_intern.h
@@ -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__ */
diff --git a/source/blender/editors/mask/mask_shapekey.c b/source/blender/editors/mask/mask_shapekey.c
index 0c01487b2a9..38e8ed627f2 100644
--- a/source/blender/editors/mask/mask_shapekey.c
+++ b/source/blender/editors/mask/mask_shapekey.c
@@ -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;
+}
diff --git a/source/blender/makesdna/DNA_mask_types.h b/source/blender/makesdna/DNA_mask_types.h
index 28fc9466613..c036369c692 100644
--- a/source/blender/makesdna/DNA_mask_types.h
+++ b/source/blender/makesdna/DNA_mask_types.h
@@ -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