forked from bartvdbraak/blender
operator to reset feather weights on all shape keys
This commit is contained in:
parent
4ce2219901
commit
465b11e971
@ -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"
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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__ */
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user