diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-07-08 21:42:13 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-07-08 21:42:13 +0400 |
commit | c3d2e13a499a773f27419d910b66c1928aa9acda (patch) | |
tree | 5aa9700c532fc7090ca460387f79975ae98c8726 | |
parent | 3685eac8e185d5e2920ebdb4be0c17329cb5685a (diff) |
Camera tracking integration
===========================
- Made settings for tracking non-animatable.
- Fixed crash when enabling/disabling markers from
"Specials" menu.
- Translate all coords to make first reconstructed camera
be at position (0,0,0).
- Blender's camera now affects on reconstructed data.
Bundles are "parented" to active scene camera. So now
bundles' could could be scaled and rotated when camera
is rotating/scaling.
-rw-r--r-- | release/scripts/startup/bl_ui/space_clip.py | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_tracking.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 21 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/depsgraph.c | 19 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/tracking.c | 41 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_clip/tracking_ops.c | 46 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_tracking.c | 5 |
10 files changed, 122 insertions, 36 deletions
diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py index 6f1b0b35fd7..3d98764d1ab 100644 --- a/release/scripts/startup/bl_ui/space_clip.py +++ b/release/scripts/startup/bl_ui/space_clip.py @@ -124,6 +124,9 @@ class CLIP_PT_tools(bpy.types.Panel): col.label(text="Reconstruction:") col.operator("clip.solve_camera") col.operator("clip.clear_reconstruction") + + col = layout.column(align=True) + col.label(text="Scene Orientation:") col.operator("clip.set_origin") else: layout.operator('clip.open') diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index 78a49a767f8..0ec065e8c58 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -40,6 +40,7 @@ struct MovieTrackingMarker; struct MovieTracking; struct MovieTrackingContext; struct MovieClipUser; +struct Scene; void BKE_tracking_clamp_track(struct MovieTrackingTrack *track, int event); void BKE_tracking_track_flag(struct MovieTrackingTrack *track, int area, int flag, int clear); @@ -73,6 +74,8 @@ struct MovieTrackingTrack *BKE_find_track_by_name(struct MovieTracking *tracking struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr); +void BKE_get_tracking_mat(struct Scene *scene, float mat[4][4]); + #define TRACK_SELECTED(track) ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT) #define TRACK_AREA_SELECTED(track, area) ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT)) diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index c59ffe7930a..ce9d79fcdff 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3969,8 +3969,18 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase return; if(data->flag&FOLLOWTRACK_BUNDLE) { - if(track->flag&TRACK_HAS_BUNDLE) - translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]); + if(track->flag&TRACK_HAS_BUNDLE) { + float pos[3], mat[4][4], obmat[4][4]; + + copy_m4_m4(obmat, cob->matrix); + + BKE_get_tracking_mat(cob->scene, mat); + mul_v3_m4v3(pos, mat, track->bundle_pos); + + cob->matrix[3][0]+= pos[0]; + cob->matrix[3][1]+= pos[1]; + cob->matrix[3][2]+= pos[2]; + } } else { user.framenr= scene->r.cfra; BKE_movieclip_acquire_size(clip, &user, &width, &height); @@ -4027,9 +4037,10 @@ static void camerasolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBas camera= BKE_tracking_get_reconstructed_camera(&clip->tracking, scene->r.cfra); if(camera) { - float m[4][4]; - copy_m4_m4(m, cob->matrix); - mul_m4_m4m4(cob->matrix, m, camera->mat); + float obmat[4][4]; + + copy_m4_m4(obmat, cob->matrix); + mul_m4_m4m4(cob->matrix, camera->mat, obmat); } } } diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index a9407fcc6f3..40975738140 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -2019,6 +2019,18 @@ void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const sho flush_pointcache_reset(sce, itA->node, lasttime, 0); } } + + /* also all objects which are parented to tracking data should be re-calculated */ + for(ob=bmain->object.first; ob; ob= ob->id.next){ + bConstraint *con; + for (con = ob->constraints.first; con; con=con->next) { + bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + if(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) { + ob->recalc |= OB_RECALC_OB; + break; + } + } + } } dag_tag_renderlayers(sce, lay); @@ -2471,6 +2483,13 @@ static void dag_id_flush_update(Scene *sce, ID *id) } } + /* camera's matrix is used to orient reconstructed stuff, + so it should happen tracking-related constraints recalculation + when camera is changing */ + if(sce->camera && &sce->camera->id == id && sce->clip) { + dag_id_flush_update(sce, &sce->clip->id); + } + /* update editors */ dag_editors_update(bmain, id); } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 159ce532411..38402bb8bde 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -59,6 +59,7 @@ #include "BLI_utildefines.h" #include "BLI_ghash.h" #include "BLI_mempool.h" +#include "BLI_math.h" #include "BKE_library.h" #include "BKE_global.h" diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index e52feeb2314..b72230e056d 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -37,15 +37,18 @@ #include "DNA_movieclip_types.h" #include "DNA_object_types.h" /* SELECT */ +#include "DNA_scene_types.h" #include "BLI_utildefines.h" #include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_ghash.h" +#include "BKE_global.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" -#include "BKE_global.h" +#include "BKE_object.h" +#include "BKE_scene.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -712,11 +715,12 @@ static struct libmv_Tracks *create_libmv_tracks(MovieClip *clip) static void retrive_libmv_reconstruct(MovieClip *clip, struct libmv_Reconstruction *reconstruction) { int tracknr= 0; - int sfra= INT_MAX, efra= INT_MIN, a; + int sfra= INT_MAX, efra= INT_MIN, a, origin_set= 0; MovieTracking *tracking= &clip->tracking; MovieTrackingTrack *track; MovieTrackingCamera *camera; MovieReconstructedCamera *reconstructed; + float origin[3]= {0.0f, 0.f, 0.0f}; track= tracking->tracks.first; while(track) { @@ -757,6 +761,14 @@ static void retrive_libmv_reconstruct(MovieClip *clip, struct libmv_Reconstructi float mat[4][4]; if(libmv_reporojectionCameraForImage(reconstruction, a, mat)) { + if(!origin_set) { + copy_v3_v3(origin, mat[3]); + origin_set= 1; + } + + if(origin_set) + sub_v3_v3(mat[3], origin); + copy_m4_m4(reconstructed[camera->reconnr].mat, mat); reconstructed[camera->reconnr].framenr= a; camera->reconnr++; @@ -770,6 +782,16 @@ static void retrive_libmv_reconstruct(MovieClip *clip, struct libmv_Reconstructi memcpy(camera->reconstructed, reconstructed, camera->reconnr*sizeof(MovieReconstructedCamera)); } + if(origin_set) { + track= tracking->tracks.first; + while(track) { + if(track->flag&TRACK_HAS_BUNDLE) + sub_v3_v3(track->bundle_pos, origin); + + track= track->next; + } + } + MEM_freeN(reconstructed); } @@ -825,3 +847,18 @@ MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(MovieTracking *t return NULL; } + +void BKE_get_tracking_mat(Scene *scene, float mat[4][4]) +{ + float obmat[4][4]; + + unit_m4(obmat); + + if(!scene->camera) + scene->camera= scene_find_camera(scene); + + if(scene->camera) + object_to_mat4(scene->camera, obmat); + + copy_m4_m4(mat, obmat); +} diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index 4ec6b8803f4..d855f6c4460 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -74,6 +74,7 @@ void CLIP_OT_clear_reconstruction(struct wmOperatorType *ot); void CLIP_OT_clear_track_path(struct wmOperatorType *ot); void CLIP_OT_disable_markers(struct wmOperatorType *ot); + void CLIP_OT_set_origin(struct wmOperatorType *ot); void CLIP_OT_track_to_fcurves(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index d320e77076b..e8bd3724bb9 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -47,6 +47,7 @@ #include "BKE_global.h" #include "BKE_animsys.h" #include "BKE_depsgraph.h" +#include "BKE_scene.h" #include "WM_api.h" #include "WM_types.h" @@ -483,7 +484,7 @@ void CLIP_OT_select(wmOperatorType *ot) /* api callbacks */ ot->exec= select_exec; ot->invoke= select_invoke; - ot->poll= space_clip_frame_poll; + ot->poll= space_clip_tracking_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -554,7 +555,7 @@ void CLIP_OT_select_border(wmOperatorType *ot) ot->invoke= WM_border_select_invoke; ot->exec= border_select_exec; ot->modal= WM_border_select_modal; - ot->poll= space_clip_frame_poll; + ot->poll= space_clip_tracking_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -637,7 +638,7 @@ void CLIP_OT_select_circle(wmOperatorType *ot) ot->invoke= WM_gesture_circle_invoke; ot->modal= WM_gesture_circle_modal; ot->exec= circle_select_exec; - ot->poll= space_clip_frame_poll; + ot->poll= space_clip_tracking_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -719,7 +720,7 @@ void CLIP_OT_select_all(wmOperatorType *ot) /* api callbacks */ ot->exec= select_all_exec; - ot->poll= space_clip_frame_poll; + ot->poll= space_clip_tracking_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1018,7 +1019,7 @@ void CLIP_OT_solve_camera(wmOperatorType *ot) /* api callbacks */ ot->exec= solve_camera_exec; - ot->poll= space_clip_frame_poll; + ot->poll= space_clip_tracking_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1062,7 +1063,7 @@ void CLIP_OT_clear_reconstruction(wmOperatorType *ot) /* api callbacks */ ot->exec= clear_reconstruction_exec; - ot->poll= space_clip_frame_poll; + ot->poll= space_clip_tracking_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1145,7 +1146,7 @@ static int disable_markers_exec(bContext *C, wmOperator *op) while(track) { if(TRACK_SELECTED(track)) { - MovieTrackingMarker *marker= BKE_tracking_exact_marker(track, sc->user.framenr); + MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr); if(action==0) marker->flag|= MARKER_DISABLED; else if(action==1) marker->flag&= ~MARKER_DISABLED; @@ -1178,7 +1179,7 @@ void CLIP_OT_disable_markers(wmOperatorType *ot) /* api callbacks */ ot->exec= disable_markers_exec; - ot->poll= space_clip_frame_poll; + ot->poll= space_clip_tracking_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1193,30 +1194,23 @@ static int set_origin_exec(bContext *C, wmOperator *UNUSED(op)) { SpaceClip *sc= CTX_wm_space_clip(C); MovieClip *clip= ED_space_clip(sc); - MovieTracking *tracking= &clip->tracking; - MovieTrackingTrack *track= tracking->tracks.first; MovieTrackingTrack *sel; - MovieTrackingCamera *camera= &clip->tracking.camera; - MovieReconstructedCamera *cur= camera->reconstructed; - int a, sel_type; - float origin[3]; + Scene *scene= CTX_data_scene(C); + int sel_type; + float mat[4][4], vec[3]; BKE_movieclip_last_selection(clip, &sel_type, (void**)&sel); - copy_v3_v3(origin, sel->bundle_pos); - /* translate bundkes */ - while(track) { - sub_v3_v3(track->bundle_pos, origin); + if(scene->camera == NULL) + scene->camera= scene_find_camera(scene); - track= track->next; - } + if(!scene->camera) + return OPERATOR_CANCELLED; - /* translate cameras */ - for(a= 0; a<camera->reconnr; a++, cur++) { - cur->mat[3][0]-= origin[0]; - cur->mat[3][1]-= origin[1]; - cur->mat[3][2]-= origin[2]; - } + BKE_get_tracking_mat(scene, mat); + mul_v3_m4v3(vec, mat, sel->bundle_pos); + + sub_v3_v3(scene->camera->loc, vec); DAG_id_tag_update(&clip->id, 0); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 073bde46168..6af69dddf92 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1576,19 +1576,27 @@ static void draw_bundle_outline(void) glCallList(displist); } -static void draw_viewport_reconstruction(View3D *v3d, MovieClip *clip) +static void draw_viewport_reconstruction(Scene *scene, View3D *v3d, MovieClip *clip) { + MovieTracking *tracking= &clip->tracking; MovieTrackingTrack *track; + float mat[4][4]; if((v3d->flag2&V3D_SHOW_RECONSTRUCTION)==0) return; + BKE_get_tracking_mat(scene, mat); + glEnable(GL_LIGHTING); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); - for ( track= clip->tracking.tracks.first; track; track= track->next) { + glPushMatrix(); + glMultMatrixf(mat); + + for ( track= tracking->tracks.first; track; track= track->next) { + float pos[3]; if((track->flag&TRACK_HAS_BUNDLE)==0) continue; @@ -1628,15 +1636,19 @@ static void draw_viewport_reconstruction(View3D *v3d, MovieClip *clip) glDisable(GL_LIGHTING); UI_ThemeColor(TH_CAMERA_PATH); glLineWidth(2.0f); + glBegin(GL_LINE_STRIP); for(a= 0; a<camera->reconnr; a++, cur++) { glVertex3f(cur->mat[3][0], cur->mat[3][1], cur->mat[3][2]); } glEnd(); + glLineWidth(1.0f); glEnable(GL_LIGHTING); } + glPopMatrix(); + /* restore */ glShadeModel(GL_FLAT); glDisable(GL_COLOR_MATERIAL); @@ -2726,7 +2738,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) /* draw data for movie clip set as active for scene */ if(scene->clip) - draw_viewport_reconstruction(v3d, scene->clip); + draw_viewport_reconstruction(scene, v3d, scene->clip); // REEB_draw(); diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c index dd929ed439c..2c9f747e46a 100644 --- a/source/blender/makesrna/intern/rna_tracking.c +++ b/source/blender/makesrna/intern/rna_tracking.c @@ -135,27 +135,32 @@ static void rna_def_trackingSettings(BlenderRNA *brna) /* speed */ prop= RNA_def_property(srna, "speed", PROP_ENUM, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_enum_items(prop, speed_items); RNA_def_property_ui_text(prop, "Speed", "Speed to make tracking with"); /* use limit frames */ prop= RNA_def_property(srna, "use_frames_limit", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_FRAMES_LIMIT); RNA_def_property_ui_text(prop, "Limit Frames", "Limit number of frames be tracked during single tracking operation"); /* limit frames */ prop= RNA_def_property(srna, "frames_limit", PROP_INT, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_int_sdna(prop, NULL, "frames_limit"); RNA_def_property_range(prop, 1, INT_MAX); RNA_def_property_ui_text(prop, "Frames Limit", "Amount of frames to be tracked during single tracking operation"); /* keyframe1 */ prop= RNA_def_property(srna, "keyframe1", PROP_INT, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_int_sdna(prop, NULL, "keyframe1"); RNA_def_property_ui_text(prop, "Keyframe 1", "First keyframe used for reconstruction initialization"); /* keyframe2 */ prop= RNA_def_property(srna, "keyframe2", PROP_INT, PROP_NONE); + 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"); } |