Camera tracking integration
=========================== Initial implementation of Scale operator. There's no access from operator panel to operators defined for Clip Editor space, so distance can't be controlled as operator property. Added new property to MovieTrackingSettings for this.
This commit is contained in:
@@ -184,6 +184,10 @@ class CLIP_PT_tools(bpy.types.Panel):
|
||||
row = col.row()
|
||||
row.operator("clip.set_axis", text="Set X Axis").axis = 'X'
|
||||
row.operator("clip.set_axis", text="Set Y Axis").axis = 'Y'
|
||||
|
||||
col = layout.column()
|
||||
col.prop(settings, "distance")
|
||||
col.operator("clip.set_scale")
|
||||
else:
|
||||
layout.operator('clip.open')
|
||||
|
||||
|
||||
@@ -220,6 +220,7 @@ static MovieClip *movieclip_alloc(const char *name)
|
||||
clip->tracking.settings.frames_limit= 20;
|
||||
clip->tracking.settings.keyframe1= 1;
|
||||
clip->tracking.settings.keyframe2= 30;
|
||||
clip->tracking.settings.dist= 1;
|
||||
|
||||
return clip;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ void CLIP_OT_hide_tracks_clear(struct wmOperatorType *ot);
|
||||
void CLIP_OT_set_origin(struct wmOperatorType *ot);
|
||||
void CLIP_OT_set_floor(struct wmOperatorType *ot);
|
||||
void CLIP_OT_set_axis(struct wmOperatorType *ot);
|
||||
void CLIP_OT_set_scale(struct wmOperatorType *ot);
|
||||
|
||||
void CLIP_OT_slide_marker(struct wmOperatorType *ot);
|
||||
|
||||
|
||||
@@ -216,6 +216,7 @@ static void clip_operatortypes(void)
|
||||
WM_operatortype_append(CLIP_OT_set_origin);
|
||||
WM_operatortype_append(CLIP_OT_set_floor);
|
||||
WM_operatortype_append(CLIP_OT_set_axis);
|
||||
WM_operatortype_append(CLIP_OT_set_scale);
|
||||
|
||||
WM_operatortype_append(CLIP_OT_clear_track_path);
|
||||
|
||||
|
||||
@@ -1514,6 +1514,72 @@ void CLIP_OT_set_axis(wmOperatorType *ot)
|
||||
RNA_def_enum(ot->srna, "axis", axis_actions, 0, "Axis", "Axis to use to align bundle along");
|
||||
}
|
||||
|
||||
/********************** set scale operator *********************/
|
||||
|
||||
static int set_scale_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
SpaceClip *sc= CTX_wm_space_clip(C);
|
||||
MovieClip *clip= ED_space_clip(sc);
|
||||
MovieTrackingTrack *track;
|
||||
Scene *scene= CTX_data_scene(C);
|
||||
Object *parent= scene->camera;
|
||||
int tot= 0;
|
||||
float vec[2][3], mat[4][4], scale;
|
||||
|
||||
if(count_selected_bundles(C)!=2) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Two tracks with bundles should be selected to scale scene");
|
||||
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
if(scene->camera->parent)
|
||||
parent= scene->camera->parent;
|
||||
|
||||
BKE_get_tracking_mat(scene, mat);
|
||||
|
||||
track= clip->tracking.tracks.first;
|
||||
while(track) {
|
||||
if(TRACK_SELECTED(track)) {
|
||||
mul_v3_m4v3(vec[tot], mat, track->bundle_pos);
|
||||
tot++;
|
||||
}
|
||||
|
||||
track= track->next;
|
||||
}
|
||||
|
||||
sub_v3_v3(vec[0], vec[1]);
|
||||
|
||||
if(len_v3(vec[0])>1e-5) {
|
||||
scale= clip->tracking.settings.dist / len_v3(vec[0]);
|
||||
|
||||
mul_v3_fl(parent->size, scale);
|
||||
mul_v3_fl(parent->loc, scale);
|
||||
|
||||
DAG_id_tag_update(&clip->id, 0);
|
||||
DAG_id_tag_update(&parent->id, OB_RECALC_OB);
|
||||
|
||||
WM_event_add_notifier(C, NC_MOVIECLIP|NA_EVALUATED, clip);
|
||||
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL);
|
||||
}
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void CLIP_OT_set_scale(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Set Scale";
|
||||
ot->description= "Set scale of scene";
|
||||
ot->idname= "CLIP_OT_set_scale";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= set_scale_exec;
|
||||
ot->poll= space_clip_frame_camera_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
/********************** slide marker opertaotr *********************/
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -100,6 +100,8 @@ typedef struct MovieTrackingSettings {
|
||||
short speed; /* speed of tracking */
|
||||
short frames_limit; /* number of frames to be tarcked during single tracking session (if TRACKING_FRAMES_LIMIT is set) */
|
||||
int keyframe1, keyframe2; /* two keyframes for reconstrution initialization */
|
||||
float dist; /* distance between two bundles used for scene scaling */
|
||||
float pad;
|
||||
} MovieTrackingSettings;
|
||||
|
||||
typedef struct MovieTracking {
|
||||
|
||||
@@ -190,6 +190,12 @@ static void rna_def_trackingSettings(BlenderRNA *brna)
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
RNA_def_property_int_sdna(prop, NULL, "keyframe2");
|
||||
RNA_def_property_ui_text(prop, "Keyframe 2", "Second keyframe used for reconstruction initialization");
|
||||
|
||||
/* distance */
|
||||
prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "dist");
|
||||
RNA_def_property_ui_text(prop, "Distance", "Distance between two bundles used for scene scaling");
|
||||
}
|
||||
|
||||
static void rna_def_trackingCamera(BlenderRNA *brna)
|
||||
|
||||
Reference in New Issue
Block a user