Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 11 Jul 2011 17:13:27 +0000 (17:13 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 11 Jul 2011 17:13:27 +0000 (17:13 +0000)
===========================

- Fixed incorrect usage of RNA structure for
  CameraSolverConstraint.
- Fixed some typos in object_constraint which were
  casting CameraSolver data to FollowTrack data.
- Tracking-related constraints now have got option
  "Use Defult Clip" which makes them use clip set as
  active for scene. Enabled by default.
- Set active blender camera focal length after reconstruction.
- Corrected offset of sequence images. Now first image from sequence
  should be at scene frame 1.

release/scripts/startup/bl_ui/properties_object_constraint.py
release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/editors/object/object_constraint.c
source/blender/editors/space_clip/clip_intern.h
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/makesdna/DNA_constraint_types.h
source/blender/makesrna/intern/rna_constraint.c

index 57711bb095d62b02bd74351a29cd307b7718a3a3..4ea473162a9ebf47894317910a5e6027f6f03975 100644 (file)
@@ -752,14 +752,21 @@ class ConstraintButtonsPanel():
         col.prop(con, "rotation_range", text="Pivot When")
 
     def FOLLOW_TRACK(self, context, layout, con):
-        layout.prop(con, "clip")
+        layout.prop(con, "use_default_clip")
+
+        if not con.use_default_clip:
+            layout.prop(con, "clip")
+
         layout.prop(con, "track")
 
         row = layout.row()
         row.prop(con, "reference", expand=True)
 
     def CAMERA_SOLVER(self, context, layout, con):
-        layout.prop(con, "clip")
+        layout.prop(con, "use_default_clip")
+
+        if not con.use_default_clip:
+            layout.prop(con, "clip")
 
     def SCRIPT(self, context, layout, con):
         layout.label("Blender 2.5 has no py-constraints")
index eb04ecae7aded8f193ddfe302780cfe2d7252523..183fbf02cae035d1b09e47569da7b64f8949c65f 100644 (file)
@@ -127,6 +127,8 @@ class CLIP_PT_tools(bpy.types.Panel):
             op = col.operator("clip.clear_track_path", text="Clear Track Path")
             op.action = 'ALL'
 
+            layout.operator("clip.apply_follow_track")
+
             col = layout.column(align=True)
             col.label(text="Reconstruction:")
             col.operator("clip.solve_camera")
@@ -257,20 +259,6 @@ class CLIP_PT_display(bpy.types.Panel):
         layout.prop(sc, "use_mute_footage")
 
 
-class CLIP_PT_test(bpy.types.Panel):
-    bl_space_type = 'CLIP_EDITOR'
-    bl_region_type = 'TOOLS'
-    bl_label = "Test"
-    bl_options = {'DEFAULT_CLOSED'}
-
-    def draw(self, context):
-        layout = self.layout
-        sc = context.space_data
-
-        layout.operator("clip.apply_follow_track")
-        layout.operator("clip.track_to_fcurves")
-
-
 class CLIP_PT_footage(bpy.types.Panel):
     bl_space_type = 'CLIP_EDITOR'
     bl_region_type = 'UI'
index ce9d79fcdff21bdbe2847eb2affde04f2e03a01a..788abbf509bf4da843436d257a14f84608286739 100644 (file)
@@ -3940,6 +3940,7 @@ static void followtrack_new_data (void *cdata)
        bFollowTrackConstraint *data= (bFollowTrackConstraint *)cdata;
 
        data->clip= NULL;
+       data->flag|= FOLLOWTRACK_DEFAULTCLIP;
 }
 
 static void followtrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
@@ -3953,13 +3954,16 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
 {
        Scene *scene= cob->scene;
        bFollowTrackConstraint *data= con->data;
-       MovieClip *clip= data->clip ? data->clip : scene->clip;
+       MovieClip *clip= data->clip;
        MovieClipUser user;
        MovieTrackingTrack *track;
        MovieTrackingMarker *marker;
        float tx, ty;
        int width, height;
 
+       if(data->flag&FOLLOWTRACK_DEFAULTCLIP)
+               clip= scene->clip;
+
        if(!clip || !data->track[0])
                return;
 
@@ -3968,7 +3972,7 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
        if(!track)
                return;
 
-       if(data->flag&FOLLOWTRACK_BUNDLE) {
+       if(data->reference==FOLLOWTRACK_BUNDLE) {
                if(track->flag&TRACK_HAS_BUNDLE) {
                        float pos[3], mat[4][4], obmat[4][4];
 
@@ -4017,6 +4021,7 @@ static void camerasolver_new_data (void *cdata)
        bCameraSolverConstraint *data= (bCameraSolverConstraint *)cdata;
 
        data->clip= NULL;
+       data->flag|= CAMERASOLVER_DEFAULTCLIP;
 }
 
 static void camerasolver_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
@@ -4030,9 +4035,12 @@ static void camerasolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBas
 {
        Scene *scene= cob->scene;
        bCameraSolverConstraint *data= con->data;
-       MovieClip *clip= data->clip ? data->clip : scene->clip;
+       MovieClip *clip= data->clip;
        MovieReconstructedCamera *camera;
 
+       if(data->flag&CAMERASOLVER_DEFAULTCLIP)
+               clip= scene->clip;
+
        if(clip) {
                camera= BKE_tracking_get_reconstructed_camera(&clip->tracking, scene->r.cfra);
 
index 034d0f11f4706924d692e37b5698c3aec85e22e0..256c4f752b6368e4da871bb56af686dc15440785 100644 (file)
@@ -99,7 +99,7 @@ static ImBuf *movieclip_load_sequence_file(MovieClip *clip, int framenr)
           autoguess offset for now. could be something smarter in the future */
        offset= sequence_guess_offset(clip->name, strlen(head), numlen);
 
-       if(numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr);
+       if(numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr-1);
        else strncpy(name, clip->name, sizeof(name));
 
        if(clip->id.lib)
index 7b37cf187127b2385fa9b3d1ad30c1c87828a929..53ab06a507179db5576872a84bc91548af6784d4 100644 (file)
@@ -377,7 +377,7 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u
        MovieTrackingTrack *track;
 
 #ifdef WITH_LIBMV
-       context->region_tracker= libmv_regionTrackerNew(100, 4, 0.2);
+       context->region_tracker= libmv_regionTrackerNew(100, 7, 0.2);
 #endif
 
        context->settings= *settings;
index 9e20875e725d6cf7fb08b2e5f14aa49a42f47b19..c34aec6b6733c6daa9c23286e584a089d0d75311 100644 (file)
@@ -408,16 +408,18 @@ static void test_constraints (Object *owner, bPoseChannel *pchan)
                        else if (curcon->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
                                bFollowTrackConstraint *data = curcon->data;
 
-                               if(data->clip != NULL && data->track[0]) {
-                                       if (!BKE_find_track_by_name(&data->clip->tracking, data->track))
-                                               curcon->flag |= CONSTRAINT_DISABLE;
+                               if((data->flag&CAMERASOLVER_DEFAULTCLIP)==0) {
+                                       if(data->clip != NULL && data->track[0]) {
+                                               if (!BKE_find_track_by_name(&data->clip->tracking, data->track))
+                                                       curcon->flag |= CONSTRAINT_DISABLE;
+                                       }
+                                       else curcon->flag |= CONSTRAINT_DISABLE;
                                }
-                               else curcon->flag |= CONSTRAINT_DISABLE;
                        }
                        else if (curcon->type == CONSTRAINT_TYPE_CAMERASOLVER) {
-                               bFollowTrackConstraint *data = curcon->data;
+                               bCameraSolverConstraint *data = curcon->data;
 
-                               if(data->clip == NULL)
+                               if((data->flag&CAMERASOLVER_DEFAULTCLIP)==0 && data->clip == NULL)
                                        curcon->flag |= CONSTRAINT_DISABLE;
                        }
                        
@@ -1382,26 +1384,6 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase
                        break;
                }
 
-               case CONSTRAINT_TYPE_FOLLOWTRACK:
-               {
-                       bFollowTrackConstraint *data= con->data;
-
-                       if(data->clip == NULL)
-                               data->clip= scene->clip;
-
-                       break;
-               }
-
-               case CONSTRAINT_TYPE_CAMERASOLVER:
-               {
-                       bCameraSolverConstraint *data= con->data;
-
-                       if(data->clip == NULL)
-                               data->clip= scene->clip;
-
-                       break;
-               }
-
                default:
                        break;
        }
index 3e544697660a24432afbf774d2e2e384b2ee5008..1b007feb8ed44bdadef158aaf50bba89b326db90 100644 (file)
@@ -81,8 +81,6 @@ void CLIP_OT_set_origin(struct wmOperatorType *ot);
 
 void CLIP_OT_slide_marker(struct wmOperatorType *ot);
 
-void CLIP_OT_track_to_fcurves(struct wmOperatorType *ot);
-
 /* clip_draw.c */
 void draw_clip_main(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene);
 void draw_clip_track_widget(const struct bContext *C, void *trackp, void *userp, void *clipp, rcti *rect);
index 650b504919ec7f2b7d3ed2200620b39635ce732e..f2825939d0e9e08275b8f672556991b8df6a397a 100644 (file)
@@ -219,8 +219,6 @@ static void clip_operatortypes(void)
        WM_operatortype_append(CLIP_OT_clear_track_path);
 
        WM_operatortype_append(CLIP_OT_slide_marker);
-
-       WM_operatortype_append(CLIP_OT_track_to_fcurves);
 }
 
 static void clip_keymap(struct wmKeyConfig *keyconf)
index d52618264cc1e8a50a2a1e8e552d059383cf233d..40ddd301db1ca68136c7be09b1c5560d71ba8d99 100644 (file)
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_camera_types.h"
 #include "DNA_movieclip_types.h"
 #include "DNA_object_types.h"  /* SELECT */
 #include "DNA_scene_types.h"
-#include "DNA_anim_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
@@ -45,8 +45,8 @@
 #include "BKE_movieclip.h"
 #include "BKE_tracking.h"
 #include "BKE_global.h"
-#include "BKE_animsys.h"
 #include "BKE_depsgraph.h"
+#include "BKE_report.h"
 #include "BKE_scene.h"
 
 #include "WM_api.h"
@@ -997,16 +997,40 @@ void CLIP_OT_track_markers(wmOperatorType *ot)
 
 /********************** solve camera operator *********************/
 
-static int solve_camera_exec(bContext *C, wmOperator *UNUSED(op))
+static int solve_camera_exec(bContext *C, wmOperator *op)
 {
        SpaceClip *sc= CTX_wm_space_clip(C);
        MovieClip *clip= ED_space_clip(sc);
        Scene *scene= CTX_data_scene(C);
 
+       if(BLI_countlist(&clip->tracking.tracks)<10) {
+               BKE_report(op->reports, RPT_ERROR, "At least 10 tracks are needed for reconstruction");
+       }
+
        BKE_tracking_solve_reconstruction(clip);
 
        scene->clip= clip;
 
+       if(!scene->camera)
+               scene->camera= scene_find_camera(scene);
+
+       if(scene->camera) {
+               float focal= clip->tracking.camera.focal;
+
+               /* set blender camera focal length so result would look fine there */
+               if(focal) {
+                       int width, height;
+                       Camera *camera= (Camera*)scene->camera->data;
+
+                       BKE_movieclip_approx_size(clip, &width, &height);
+
+                       if(width)
+                               camera->lens= focal*32.0f/(float)width;
+
+                       WM_event_add_notifier(C, NC_OBJECT, camera);
+               }
+       }
+
        DAG_id_tag_update(&clip->id, 0);
 
        WM_event_add_notifier(C, NC_MOVIECLIP|NA_EVALUATED, clip);
@@ -1550,85 +1574,3 @@ void CLIP_OT_hide_tracks_clear(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
-
-/********************** track to fcurves opertaotr *********************/
-
-static int track_to_fcurves_poll(bContext *C)
-{
-       Object *ob= CTX_data_active_object(C);
-       SpaceClip *sc= CTX_wm_space_clip(C);
-
-       if(ob && sc) {
-               MovieClip *clip= ED_space_clip(sc);
-               int type;
-               void *sel;
-
-               if(clip) {
-                       BKE_movieclip_last_selection(clip, &type, &sel);
-                       if(type==MCLIP_SEL_TRACK)
-                               return 1;
-               }
-       }
-
-       return 0;
-}
-
-static int track_to_fcurves_exec(bContext *C, wmOperator *op)
-{
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       MovieClip *clip= ED_space_clip(sc);
-       Object *ob= CTX_data_active_object(C);
-       Scene *scene= CTX_data_scene(C);
-       KeyingSet *ks;
-       int kflag, fra= SFRA, type;
-       MovieTrackingTrack *track;
-       bAction *act= verify_adt_action(&ob->id, 1);
-       MovieClipUser user= {0};
-       int width, height;
-       float scale= RNA_float_get(op->ptr, "scale");
-
-       BKE_movieclip_last_selection(clip, &type, (void**)&track);
-
-       ks= ANIM_builtin_keyingset_get_named(NULL, "Location");
-       kflag= ks->flag;
-       kflag |= ANIM_get_keyframing_flags(scene, 1);
-
-       BKE_movieclip_acquire_size(clip, &user, &width, &height);
-
-       while(fra<EFRA) {
-               MovieTrackingMarker *marker= BKE_tracking_get_marker(track, fra);
-
-               if((marker->framenr&MARKER_DISABLED)==0) {
-                       FCurve *fcu;
-
-                       fcu= verify_fcurve(act, ks->name, "location", 0, 1);
-                       insert_vert_fcurve(fcu, fra, marker->pos[0]*width*scale, kflag);
-
-                       fcu= verify_fcurve(act, ks->name, "location", 1, 1);
-                       insert_vert_fcurve(fcu, fra, marker->pos[1]*height*scale, kflag);
-               }
-
-               fra++;
-       }
-
-       WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void CLIP_OT_track_to_fcurves(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Convert Track To FCurves";
-       ot->description= "Convert active track to f-curves for active object in the scene";
-       ot->idname= "CLIP_OT_track_to_fcurves";
-
-       /* api callbacks */
-       ot->exec= track_to_fcurves_exec;
-       ot->poll= track_to_fcurves_poll;
-
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
-       RNA_def_float(ot->srna, "scale", 1.f, -FLT_MAX, FLT_MAX, "Scale", "Scale factor for generated coordinates", -100.f, 100.f);
-}
index c9789eb1c6bedd9449c9e0bfa2330d4670892ef2..ce48981d2953dbf892944a901a064c7d96451274 100644 (file)
@@ -412,12 +412,13 @@ typedef struct bShrinkwrapConstraint {
 typedef struct bFollowTrackConstraint {
        struct MovieClip        *clip;
        char    track[24];
-       int             flag, pad;
+       int             flag, reference;
 } bFollowTrackConstraint;
 
 /* Camera Solver constraints */
 typedef struct bCameraSolverConstraint {
        struct MovieClip        *clip;
+       int             flag, pad;
 } bCameraSolverConstraint;
 
 /* ------------------------------------------ */
@@ -750,10 +751,20 @@ typedef enum ePivotConstraint_Flag {
 } ePivotConstraint_Flag;
 
 /* FollowTrack Constraint -> flag */
+typedef enum eFollowTrack_Reference {
+       FOLLOWTRACK_TRACK               = (1<<0),
+       FOLLOWTRACK_BUNDLE              = (1<<1)
+} FollowTrack_Reference;
+
 typedef enum eFollowTrack_Flags {
-       FOLLOWTRACK_BUNDLE      = (1<<0),
+       FOLLOWTRACK_DEFAULTCLIP = (1<<0)
 } eFollowTrack_Flags;
 
+/* CameraSolver Constraint -> flag */
+typedef enum eCameraSolver_Flags {
+       CAMERASOLVER_DEFAULTCLIP        = (1<<0)
+} eCameraSolver_Flags;
+
 /* Rigid-Body Constraint */
 #define CONSTRAINT_DRAW_PIVOT 0x40
 #define        CONSTRAINT_DISABLE_LINKED_COLLISION 0x80
index 2061120dbca536725fa4ef848761aa5dc056abfd..cdcfbe6e04d830978efae5fb2f5cd398cb3888ad 100644 (file)
@@ -163,7 +163,7 @@ static StructRNA *rna_ConstraintType_refine(struct PointerRNA *ptr)
                case CONSTRAINT_TYPE_FOLLOWTRACK:
                        return &RNA_FollowTrackConstraint;
                case CONSTRAINT_TYPE_CAMERASOLVER:
-                       return &RNA_FollowTrackConstraint;
+                       return &RNA_CameraSolverConstraint;
                default:
                        return &RNA_UnknownType;
        }
@@ -2009,7 +2009,7 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna)
        PropertyRNA *prop;
 
        static EnumPropertyItem reference_items[] = {
-               {0, "TRACK", 0, "Track", "Use 2D track position as reference"},
+               {FOLLOWTRACK_TRACK, "TRACK", 0, "Track", "Use 2D track position as reference"},
                {FOLLOWTRACK_BUNDLE, "BUNDLE", 0, "Bundle", "Use 3D reconstructed bundle position as reference"},
                {0, NULL, 0, NULL, NULL}};
 
@@ -2032,10 +2032,16 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna)
 
        /* reference */
        prop= RNA_def_property(srna, "reference", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_sdna(prop, NULL, "flag");
+       RNA_def_property_enum_sdna(prop, NULL, "reference");
        RNA_def_property_enum_items(prop, reference_items);
        RNA_def_property_ui_text(prop, "Reference", "Reference source to follow");
        RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
+
+       /* use default clip */
+       prop= RNA_def_property(srna, "use_default_clip", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", FOLLOWTRACK_DEFAULTCLIP);
+       RNA_def_property_ui_text(prop, "Default Clip", "Use default clip defined in scene");
+       RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
 }
 
 static void rna_def_constraint_camera_solver(BlenderRNA *brna)
@@ -2044,7 +2050,7 @@ static void rna_def_constraint_camera_solver(BlenderRNA *brna)
        PropertyRNA *prop;
 
        srna= RNA_def_struct(brna, "CameraSolverConstraint", "Constraint");
-       RNA_def_struct_ui_text(srna, "Follow Track Constraint", "Locks motion to the target motion track");
+       RNA_def_struct_ui_text(srna, "Follow Track Constraint", "Locks motion to the reconstructed camera movenment");
        RNA_def_struct_sdna_from(srna, "bCameraSolverConstraint", "data");
 
        /* movie clip */
@@ -2053,6 +2059,12 @@ static void rna_def_constraint_camera_solver(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Movie Clip", "Movie Clip to get tracking data from");
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update");
+
+       /* use default clip */
+       prop= RNA_def_property(srna, "use_default_clip", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", CAMERASOLVER_DEFAULTCLIP);
+       RNA_def_property_ui_text(prop, "Default Clip", "Use default clip defined in scene");
+       RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
 }
 
 /* base struct for constraints */