diff options
-rw-r--r-- | source/blender/blenkernel/BKE_mask.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mask.c | 72 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 18 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 30 |
5 files changed, 83 insertions, 40 deletions
diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 14ceba42aff..862af162ec9 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -136,6 +136,7 @@ void BKE_mask_layer_calc_handles_deform(struct MaskLayer *masklay); void BKE_mask_calc_handles(struct Mask *mask); void BKE_mask_update_deform(struct Mask *mask); void BKE_mask_spline_ensure_deform(struct MaskSpline *spline); +void BKE_mask_point_parent_matrix_get(struct MaskSplinePoint *point, float ctime, float parent_matrix[3][3]); /* animation */ int BKE_mask_layer_shape_totvert(struct MaskLayer *masklay); diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index afd725f55fe..c856d8cfea4 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -1095,10 +1095,15 @@ void BKE_mask_coord_to_image(Image *image, ImageUser *iuser, float r_co[2], cons BKE_mask_coord_to_frame(r_co, co, frame_size); } -static int mask_evaluate_parent(MaskParent *parent, float ctime, float orig_co[2], float r_co[2]) +void BKE_mask_point_parent_matrix_get(MaskSplinePoint *point, float ctime, float parent_matrix[3][3]) { - if (!parent) - return FALSE; + MaskParent *parent = &point->parent; + + unit_m3(parent_matrix); + + if (!parent) { + return; + } if (parent->id_type == ID_MC) { if (parent->id) { @@ -1115,11 +1120,10 @@ static int mask_evaluate_parent(MaskParent *parent, float ctime, float orig_co[2 MovieTrackingTrack *track = BKE_tracking_track_get_named(tracking, ob, parent->sub_parent); if (track) { - float marker_pos_ofs[2]; - BKE_tracking_marker_get_subframe_position(track, clip_framenr, marker_pos_ofs); - BKE_mask_coord_from_movieclip(clip, &user, r_co, marker_pos_ofs); - - return TRUE; + float marker_position[2], parent_co[2]; + BKE_tracking_marker_get_subframe_position(track, clip_framenr, marker_position); + BKE_mask_coord_from_movieclip(clip, &user, parent_co, marker_position); + sub_v2_v2v2(parent_matrix[2], parent_co, parent->parent_orig); } } else /* if (parent->type == MASK_PARENT_PLANE_TRACK) */ { @@ -1127,47 +1131,47 @@ static int mask_evaluate_parent(MaskParent *parent, float ctime, float orig_co[2 if (plane_track) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, clip_framenr); - float H[3][3], vec[3], warped[3]; + float aspx, aspy; + float frame_size[2], H[3][3], mask_from_clip_matrix[3][3], mask_to_clip_matrix[3][3]; BKE_tracking_homography_between_two_quads(parent->parent_corners_orig, plane_marker->corners, H); - BKE_mask_coord_to_movieclip(clip, &user, vec, orig_co); - vec[2] = 1.0f; - mul_v3_m3v3(warped, H, vec); - warped[0] /= warped[2]; - warped[1] /= warped[2]; + unit_m3(mask_from_clip_matrix); + + BKE_movieclip_get_size_fl(clip, &user, frame_size); + BKE_movieclip_get_aspect(clip, &aspx, &aspy); + + frame_size[1] *= (aspy / aspx); + if (frame_size[0] == frame_size[1]) { + /* pass */ + } + else if (frame_size[0] < frame_size[1]) { + mask_from_clip_matrix[0][0] = frame_size[1] / frame_size[0]; + mask_from_clip_matrix[2][0] = -0.5f * (frame_size[1] / frame_size[0]) + 0.5f; + } + else { /* (frame_size[0] > frame_size[1]) */ + mask_from_clip_matrix[1][1] = frame_size[1] / frame_size[0]; + mask_from_clip_matrix[2][1] = -0.5f * (frame_size[1] / frame_size[0]) + 0.5f; + } - BKE_mask_coord_from_movieclip(clip, &user, r_co, warped); + invert_m3_m3(mask_to_clip_matrix, mask_from_clip_matrix); + mul_serie_m3(parent_matrix, mask_to_clip_matrix, H, mask_from_clip_matrix, NULL, NULL, NULL, NULL, NULL); } } } } } - - return FALSE; } static void mask_evaluate_apply_point_parent(MaskSplinePoint *point, float ctime) { - MaskParent *parent = &point->parent; + float parent_matrix[3][3]; - if (parent->type == MASK_PARENT_POINT_TRACK) { - float parent_co[2]; + BKE_mask_point_parent_matrix_get(point, ctime, parent_matrix); - if (mask_evaluate_parent(parent, ctime, NULL, parent_co)) { - float delta[2]; - sub_v2_v2v2(delta, parent_co, parent->parent_orig); - - add_v2_v2(point->bezt.vec[0], delta); - add_v2_v2(point->bezt.vec[1], delta); - add_v2_v2(point->bezt.vec[2], delta); - } - } - else /* if (parent->type == MASK_PARENT_PLANE_TRACK) */ { - mask_evaluate_parent(parent, ctime, point->bezt.vec[0], point->bezt.vec[0]); - mask_evaluate_parent(parent, ctime, point->bezt.vec[1], point->bezt.vec[1]); - mask_evaluate_parent(parent, ctime, point->bezt.vec[2], point->bezt.vec[2]); - } + mul_m3_v2(parent_matrix, point->bezt.vec[0]); + mul_m3_v2(parent_matrix, point->bezt.vec[1]); + mul_m3_v2(parent_matrix, point->bezt.vec[2]); } static void mask_calc_point_handle(MaskSplinePoint *point, MaskSplinePoint *point_prev, MaskSplinePoint *point_next) diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index c305cc9a030..b04af44156f 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -94,6 +94,8 @@ void mul_v4_m4v4(float r[4], float M[4][4], const float v[4]); void mul_project_m4_v3(float M[4][4], float vec[3]); void mul_v2_project_m4_v3(float r[2], float M[4][4], const float vec[3]); +void mul_m3_v2(float m[3][3], float r[2]); +void mul_v2_m3v2(float r[2], float m[3][3], float v[2]); void mul_m3_v3(float M[3][3], float r[3]); void mul_v3_m3v3(float r[3], float M[3][3], const float a[3]); void mul_v2_m3v3(float r[2], float M[3][3], const float a[3]); diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 611b3298c38..d24200fc0b7 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -322,6 +322,24 @@ void mul_serie_m4(float answ[4][4], float m1[4][4], } } +void mul_v2_m3v2(float r[2], float m[3][3], float v[2]) +{ + float temp[3], warped[3]; + + copy_v2_v2(temp, v); + temp[2] = 1.0f; + + mul_v3_m3v3(warped, m, temp); + + r[0] = warped[0] / warped[2]; + r[1] = warped[1] / warped[2]; +} + +void mul_m3_v2(float m[3][3], float r[2]) +{ + mul_v2_m3v2(r, m, r); +} + void mul_m4_v3(float mat[4][4], float vec[3]) { float x, y; diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index deda46cfe4f..ac1809e41f2 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -6556,29 +6556,40 @@ typedef struct TransDataMasking { float handle[2], orig_handle[2]; float vec[3][3]; MaskSplinePoint *point; + float parent_matrix[3][3]; + float parent_inverse_matrix[3][3]; } TransDataMasking; -static void MaskPointToTransData(MaskSplinePoint *point, +static void MaskPointToTransData(Scene *scene, MaskSplinePoint *point, TransData *td, TransData2D *td2d, TransDataMasking *tdm, const int propmode, const float asp[2]) { BezTriple *bezt = &point->bezt; short is_sel_point = MASKPOINT_ISSEL_KNOT(point); short is_sel_any = MASKPOINT_ISSEL_ANY(point); + float parent_matrix[3][3], parent_inverse_matrix[3][3]; tdm->point = point; copy_m3_m3(tdm->vec, bezt->vec); + BKE_mask_point_parent_matrix_get(point, CFRA, parent_matrix); + invert_m3_m3(parent_inverse_matrix, parent_matrix); + if (propmode || is_sel_point) { int i; for (i = 0; i < 3; i++) { + copy_m3_m3(tdm->parent_matrix, parent_matrix); + copy_m3_m3(tdm->parent_inverse_matrix, parent_inverse_matrix); + /* CV coords are scaled by aspects. this is needed for rotations and * proportional editing to be consistent with the stretched CV coords * that are displayed. this also means that for display and numinput, * and when the the CV coords are flushed, these are converted each time */ - td2d->loc[0] = bezt->vec[i][0] * asp[0]; - td2d->loc[1] = bezt->vec[i][1] * asp[1]; + mul_v2_m3v2(td2d->loc, parent_matrix, bezt->vec[i]); + td2d->loc[0] *= asp[0]; + td2d->loc[1] *= asp[1]; td2d->loc[2] = 0.0f; + td2d->loc2d = bezt->vec[i]; td->flag = 0; @@ -6610,18 +6621,23 @@ static void MaskPointToTransData(MaskSplinePoint *point, td++; td2d++; + tdm++; } } else { tdm->is_handle = TRUE; + copy_m3_m3(tdm->parent_matrix, parent_matrix); + copy_m3_m3(tdm->parent_inverse_matrix, parent_inverse_matrix); BKE_mask_point_handle(point, tdm->handle); copy_v2_v2(tdm->orig_handle, tdm->handle); - td2d->loc[0] = tdm->handle[0] * asp[0]; - td2d->loc[1] = tdm->handle[1] * asp[1]; + mul_v2_m3v2(td2d->loc, parent_matrix, tdm->handle); + td2d->loc[0] *= asp[0]; + td2d->loc[1] *= asp[1]; td2d->loc[2] = 0.0f; + td2d->loc2d = tdm->handle; td->flag = 0; @@ -6651,6 +6667,7 @@ static void MaskPointToTransData(MaskSplinePoint *point, static void createTransMaskingData(bContext *C, TransInfo *t) { + Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; TransData *td = NULL; @@ -6723,7 +6740,7 @@ static void createTransMaskingData(bContext *C, TransInfo *t) MaskSplinePoint *point = &spline->points[i]; if (propmode || MASKPOINT_ISSEL_ANY(point)) { - MaskPointToTransData(point, td, td2d, tdm, propmode, asp); + MaskPointToTransData(scene, point, td, td2d, tdm, propmode, asp); if (propmode || MASKPOINT_ISSEL_KNOT(point)) { td += 3; @@ -6756,6 +6773,7 @@ void flushTransMasking(TransInfo *t) for (a = 0, td = t->data2d, tdm = t->customData; a < t->total; a++, td++, tdm++) { td->loc2d[0] = td->loc[0] * inv[0]; td->loc2d[1] = td->loc[1] * inv[1]; + mul_m3_v2(tdm->parent_inverse_matrix, td->loc2d); if (tdm->is_handle) BKE_mask_point_set_handle(tdm->point, td->loc2d, t->flag & T_ALT_TRANSFORM, tdm->orig_handle, tdm->vec); |