Implement option to parent object to undistorted position of 2D track
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 24 Jul 2014 15:00:35 +0000 (21:00 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 24 Jul 2014 15:01:19 +0000 (21:01 +0600)
release/scripts/startup/bl_ui/properties_constraint.py
source/blender/blenkernel/intern/constraint.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesdna/DNA_constraint_types.h
source/blender/makesrna/intern/rna_constraint.c
source/blender/makesrna/intern/rna_tracking.c

index 50107604b3b69eed3a4c8f4c8f904ed44e4c7571..4baf31a591ba7225329cc6c997ab5a33256d4dba 100644 (file)
@@ -788,6 +788,10 @@ class ConstraintButtonsPanel():
         row.prop(con, "use_active_clip")
         row.prop(con, "use_3d_position")
 
+        sub = row.column()
+        sub.active = not con.use_3d_position
+        sub.prop(con, "use_undistorted_position")
+
         col = layout.column()
 
         if not con.use_active_clip:
index b256f84dbf77a93445eb7b9337cb4340bd2d5545..2f8690a8c4033ff71815d0928a56ffa08d679d00 100644 (file)
@@ -3943,19 +3943,31 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
 
                if (len > FLT_EPSILON) {
                        CameraParams params;
+                       int width, height;
                        float pos[2], rmat[4][4];
 
+                       BKE_movieclip_get_size(clip, NULL, &width, &height);
+
                        marker = BKE_tracking_marker_get(track, framenr);
 
                        add_v2_v2v2(pos, marker->pos, track->offset);
 
+                       if (data->flag & FOLLOWTRACK_USE_UNDISTORTION) {
+                               /* Undistortion need to happen in pixel space. */
+                               pos[0] *= width;
+                               pos[1] *= height;
+
+                               BKE_tracking_undistort_v2(tracking, pos, pos);
+
+                               /* Normalize pixel coordinates back. */
+                               pos[0] /= width;
+                               pos[1] /= height;
+                       }
+
                        /* 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;
index eb2310fa791fab221da8f889bcf14d1e830fbd61..1273b90501658d30200d3d494cc7a874e061b2f6 100644 (file)
@@ -915,7 +915,7 @@ static void view3d_main_area_listener(bScreen *sc, ScrArea *sa, ARegion *ar, wmN
                        ED_region_tag_redraw(ar);
                        break;
                case NC_MOVIECLIP:
-                       if (wmn->data == ND_DISPLAY)
+                       if (wmn->data == ND_DISPLAY || wmn->action == NA_EDITED)
                                ED_region_tag_redraw(ar);
                        break;
                case NC_SPACE:
index e35e4673684c5868e97838b7f4560955b62af8d4..0277956cac5e70be11f50a3d133779416d96ba47 100644 (file)
@@ -796,7 +796,8 @@ typedef enum ePivotConstraint_Flag {
 
 typedef enum eFollowTrack_Flags {
        FOLLOWTRACK_ACTIVECLIP  = (1<<0),
-       FOLLOWTRACK_USE_3D_POSITION     = (1<<1)
+       FOLLOWTRACK_USE_3D_POSITION     = (1<<1),
+       FOLLOWTRACK_USE_UNDISTORTION    = (1<<2)
 } eFollowTrack_Flags;
 
 typedef enum eFollowTrack_FrameMethod {
index eb38c58d8efed585d2db26b2ad29d6dabaf8680b..5519b192ca49157bfff11aceeed56311aec1bf0d 100644 (file)
@@ -2452,6 +2452,12 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna)
        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");
+
+       /* use undistortion */
+       prop = RNA_def_property(srna, "use_undistorted_position", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", FOLLOWTRACK_USE_UNDISTORTION);
+       RNA_def_property_ui_text(prop, "Undistort", "Parent to undistorted position of 2D track");
+       RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
 }
 
 static void rna_def_constraint_camera_solver(BlenderRNA *brna)
index 537ffe630a28d1edc1535d837424f0f73d094c77..899da62d9d344168496327793b078d66ce0ad0bc 100644 (file)
@@ -393,6 +393,7 @@ static void rna_tracking_flushUpdate(Main *UNUSED(bmain), Scene *scene, PointerR
        nodeUpdateID(scene->nodetree, &clip->id);
 
        WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
+       WM_main_add_notifier(NC_SCENE, NULL);
        DAG_id_tag_update(&clip->id, 0);
 }