From a889ffad1cee007dbdee97e736c9e03ba087a2de Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 14 Jul 2011 12:52:50 +0000 Subject: [PATCH] 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. --- release/scripts/startup/bl_ui/space_clip.py | 4 ++ source/blender/blenkernel/intern/movieclip.c | 1 + .../blender/editors/space_clip/clip_intern.h | 1 + .../blender/editors/space_clip/space_clip.c | 1 + .../blender/editors/space_clip/tracking_ops.c | 66 +++++++++++++++++++ source/blender/makesdna/DNA_tracking_types.h | 2 + source/blender/makesrna/intern/rna_tracking.c | 6 ++ 7 files changed, 81 insertions(+) diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py index 8b3efeb6bf4..6811b152eef 100644 --- a/release/scripts/startup/bl_ui/space_clip.py +++ b/release/scripts/startup/bl_ui/space_clip.py @@ -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') diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 7e2627f3c30..0e08c788be4 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -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; } diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index baf1c5fbaf1..eae34efd825 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -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); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index f9e820aad4d..29d90beb16f 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -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); diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index d32239fee1b..18a9eeb3f49 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -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 { diff --git a/source/blender/makesdna/DNA_tracking_types.h b/source/blender/makesdna/DNA_tracking_types.h index 2ad11e360c8..b45631bc276 100644 --- a/source/blender/makesdna/DNA_tracking_types.h +++ b/source/blender/makesdna/DNA_tracking_types.h @@ -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 { diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c index bb62c192790..b876c96fff8 100644 --- a/source/blender/makesrna/intern/rna_tracking.c +++ b/source/blender/makesrna/intern/rna_tracking.c @@ -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)