Frame matching methods for follow track constraint
This is needed in cases when using blender camera with different resolution than original footage. Behaves in the same way as background picture framing.
This commit is contained in:
parent
9a32fd05db
commit
9f30c7147c
@ -773,16 +773,21 @@ class ConstraintButtonsPanel():
|
||||
row.prop(con, "use_active_clip")
|
||||
row.prop(con, "use_3d_position")
|
||||
|
||||
col = layout.column()
|
||||
|
||||
if not con.use_active_clip:
|
||||
layout.prop(con, "clip")
|
||||
col.prop(con, "clip")
|
||||
|
||||
row = col.row()
|
||||
row.prop(con, "frame_method", expand=True)
|
||||
|
||||
if clip:
|
||||
layout.prop_search(con, "object", clip.tracking, "objects", icon='OBJECT_DATA')
|
||||
layout.prop_search(con, "track", clip.tracking, "tracks", icon='ANIM_DATA')
|
||||
col.prop_search(con, "object", clip.tracking, "objects", icon='OBJECT_DATA')
|
||||
col.prop_search(con, "track", clip.tracking, "tracks", icon='ANIM_DATA')
|
||||
|
||||
layout.prop(con, "camera")
|
||||
col.prop(con, "camera")
|
||||
|
||||
row = layout.row()
|
||||
row = col.row()
|
||||
row.active = not con.use_3d_position
|
||||
row.prop(con, "depth_object")
|
||||
|
||||
|
@ -82,8 +82,6 @@
|
||||
#include "BKE_tessmesh.h"
|
||||
#include "BKE_tracking.h"
|
||||
#include "BKE_movieclip.h"
|
||||
#include "BKE_tracking.h"
|
||||
#include "BKE_movieclip.h"
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#include "BPY_extern.h"
|
||||
@ -3985,6 +3983,41 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
|
||||
|
||||
add_v2_v2v2(pos, marker->pos, track->offset);
|
||||
|
||||
/* aspect correction */
|
||||
if (data->frame_method != FOLLOWTRACK_FRAME_STRETCH) {
|
||||
int width, height;
|
||||
float w_src, h_src, w_dst, h_dst, asp_src, asp_dst;
|
||||
|
||||
BKE_movieclip_get_size(clip, NULL, &width, &height);
|
||||
|
||||
/* apply clip display aspect */
|
||||
w_src = width * clip->aspx;
|
||||
h_src = height * clip->aspy;
|
||||
|
||||
w_dst = scene->r.xsch * scene->r.xasp;
|
||||
h_dst = scene->r.ysch * scene->r.yasp;
|
||||
|
||||
asp_src = w_src / h_src;
|
||||
asp_dst = w_dst / h_dst;
|
||||
|
||||
if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
|
||||
if ((asp_src > asp_dst) == (data->frame_method == FOLLOWTRACK_FRAME_CROP)) {
|
||||
/* fit X */
|
||||
float div = asp_src / asp_dst;
|
||||
float cent = (float) width / 2.0f;
|
||||
|
||||
pos[0] = (((pos[0] * width - cent) * div) + cent) / width;
|
||||
}
|
||||
else {
|
||||
/* fit Y */
|
||||
float div = asp_dst / asp_src;
|
||||
float cent = (float) height / 2.0f;
|
||||
|
||||
pos[1] = (((pos[1] * height - cent) * div) + cent) / height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BKE_camera_params_init(¶ms);
|
||||
BKE_camera_params_from_object(¶ms, camob);
|
||||
|
||||
|
@ -415,7 +415,8 @@ typedef struct bShrinkwrapConstraint {
|
||||
typedef struct bFollowTrackConstraint {
|
||||
struct MovieClip *clip;
|
||||
char track[64]; /* MAX_NAME */
|
||||
int flag, pad;
|
||||
int flag;
|
||||
int frame_method;
|
||||
char object[64]; /* MAX_NAME */
|
||||
struct Object *camera;
|
||||
struct Object *depth_ob;
|
||||
@ -780,6 +781,12 @@ typedef enum eFollowTrack_Flags {
|
||||
FOLLOWTRACK_USE_3D_POSITION = (1<<1)
|
||||
} eFollowTrack_Flags;
|
||||
|
||||
typedef enum eFollowTrack_FrameMethod {
|
||||
FOLLOWTRACK_FRAME_STRETCH = 0,
|
||||
FOLLOWTRACK_FRAME_FIT = 1,
|
||||
FOLLOWTRACK_FRAME_CROP = 2
|
||||
} eFollowTrack_FrameMethod;
|
||||
|
||||
/* CameraSolver Constraint -> flag */
|
||||
typedef enum eCameraSolver_Flags {
|
||||
CAMERASOLVER_ACTIVECLIP = (1<<0)
|
||||
|
@ -2207,6 +2207,13 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna)
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
static const EnumPropertyItem frame_method_items[] = {
|
||||
{FOLLOWTRACK_FRAME_STRETCH, "STRETCH", 0, "Stretch", ""},
|
||||
{FOLLOWTRACK_FRAME_FIT, "FIT", 0, "Fit", ""},
|
||||
{FOLLOWTRACK_FRAME_CROP, "CROP", 0, "Crop", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
srna = RNA_def_struct(brna, "FollowTrackConstraint", "Constraint");
|
||||
RNA_def_struct_ui_text(srna, "Follow Track Constraint", "Lock motion to the target motion track");
|
||||
RNA_def_struct_sdna_from(srna, "bFollowTrackConstraint", "data");
|
||||
@ -2261,6 +2268,13 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna)
|
||||
RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_dependency_update");
|
||||
RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_followTrack_depthObject_set", NULL,
|
||||
"rna_Constraint_followTrack_depthObject_poll");
|
||||
|
||||
/* frame method */
|
||||
prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_bitflag_sdna(prop, NULL, "frame_method");
|
||||
RNA_def_property_enum_items(prop, frame_method_items);
|
||||
RNA_def_property_ui_text(prop, "Frame Method", "How the footage fits in the camera frame");
|
||||
RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_dependency_update");
|
||||
}
|
||||
|
||||
static void rna_def_constraint_camera_solver(BlenderRNA *brna)
|
||||
|
Loading…
Reference in New Issue
Block a user