Object tracking: various fixes and improvements
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 15 Dec 2011 16:10:49 +0000 (16:10 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 15 Dec 2011 16:10:49 +0000 (16:10 +0000)
- Bundles selection is now available for object's bundles
- If bundles selection wasn't changed in 3D viewport, fallback to regular
  object selection, so objects behind bundles can be selected
- Snap cursor to selection now respects object's bundle selection
- Object and rack name now can be selected from list in constraint settings
- Added preset for tracks used for object tracking

release/scripts/presets/tracking_track_color/object.py [new file with mode: 0644]
release/scripts/startup/bl_ui/properties_object_constraint.py
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/tracking.c
source/blender/editors/object/object_constraint.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c

diff --git a/release/scripts/presets/tracking_track_color/object.py b/release/scripts/presets/tracking_track_color/object.py
new file mode 100644 (file)
index 0000000..5cb663d
--- /dev/null
@@ -0,0 +1,5 @@
+import bpy
+track = bpy.context.edit_movieclip.tracking.tracks.active
+
+track.color = (1.0, 0.0, 1.0)
+track.use_custom_color = True
index 02326fb..6bec2fe 100644 (file)
@@ -755,7 +755,16 @@ class ConstraintButtonsPanel():
         col = layout.column()
         col.prop(con, "rotation_range", text="Pivot When")
 
+    @staticmethod
+    def _getConstraintClip(context, con):
+        if not con.use_active_clip:
+            return con.clip
+        else:
+            return context.scene.active_clip
+
     def FOLLOW_TRACK(self, context, layout, con):
+        clip = self._getConstraintClip(context, con)
+
         row = layout.row()
         row.prop(con, "use_active_clip")
         row.prop(con, "use_3d_position")
@@ -763,8 +772,9 @@ class ConstraintButtonsPanel():
         if not con.use_active_clip:
             layout.prop(con, "clip")
 
-        layout.prop(con, "object")
-        layout.prop(con, "track")
+        if clip:
+            layout.prop_search(con, "object", clip.tracking, "objects", icon='OBJECT_DATA')
+            layout.prop_search(con, "track", clip.tracking, "tracks", icon='ANIMATION_DATA')
 
         layout.operator("clip.constraint_to_fcurve")
 
@@ -777,12 +787,16 @@ class ConstraintButtonsPanel():
         layout.operator("clip.constraint_to_fcurve")
 
     def OBJECT_SOLVER(self, context, layout, con):
+        scene = context.scene
+        clip = self._getConstraintClip(context, con)
+
         layout.prop(con, "use_active_clip")
 
         if not con.use_active_clip:
             layout.prop(con, "clip")
 
-        layout.prop(con, "object")
+        if clip:
+            layout.prop_search(con, "object", clip.tracking, "objects", icon='OBJECT_DATA')
 
         row = layout.row()
         row.operator("constraint.objectsolver_set_inverse")
index 7723069..7b3cb3f 100644 (file)
@@ -77,7 +77,7 @@ struct ImBuf *BKE_tracking_get_search_imbuf(struct ImBuf *ibuf, struct MovieTrac
 void BKE_track_unique_name(struct ListBase *tracksbase, struct MovieTrackingTrack *track);
 
 struct MovieTrackingTrack *BKE_tracking_named_track(struct MovieTracking *tracking, struct MovieTrackingObject *object, const char *name);
-struct MovieTrackingTrack *BKE_tracking_indexed_track(struct MovieTracking *tracking, int tracknr);
+struct MovieTrackingTrack *BKE_tracking_indexed_track(struct MovieTracking *tracking, int tracknr, struct ListBase **tracksbase_r);
 
 void BKE_tracking_camera_shift(struct MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty);
 void BKE_tracking_camera_to_blender(struct MovieTracking *tracking, struct Scene *scene, struct Camera *camera, int width, int height);
index 931f3f5..262c057 100644 (file)
@@ -2257,23 +2257,34 @@ void BKE_tracking_detect_fast(MovieTracking *tracking, ListBase *tracksbase, ImB
 #endif
 }
 
-MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int tracknr)
+MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int tracknr, ListBase **tracksbase_r)
 {
-       ListBase *tracksbase= &tracking->tracks;        /* XXX: need proper tracks base */
-       MovieTrackingTrack *track= tracksbase->first;
+       MovieTrackingObject *object;
        int cur= 1;
 
-       while(track) {
-               if(track->flag&TRACK_HAS_BUNDLE) {
-                       if(cur==tracknr)
-                               return track;
+       object= tracking->objects.first;
+       while(object) {
+               ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object);
+               MovieTrackingTrack *track= tracksbase->first;
+
+               while(track) {
+                       if(track->flag&TRACK_HAS_BUNDLE) {
+                               if(cur==tracknr) {
+                                       *tracksbase_r= tracksbase;
+                                       return track;
+                               }
 
-                       cur++;
+                               cur++;
+                       }
+
+                       track= track->next;
                }
 
-               track= track->next;
+               object= object->next;
        }
 
+       *tracksbase_r= NULL;
+
        return NULL;
 }
 
index a4a33b8..fa4f50e 100644 (file)
@@ -433,6 +433,12 @@ static void test_constraints (Object *owner, bPoseChannel *pchan)
                                if((data->flag&CAMERASOLVER_ACTIVECLIP)==0 && data->clip == NULL)
                                        curcon->flag |= CONSTRAINT_DISABLE;
                        }
+                       else if (curcon->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
+                               bObjectSolverConstraint *data = curcon->data;
+
+                               if((data->flag&CAMERASOLVER_ACTIVECLIP)==0 && data->clip == NULL)
+                                       curcon->flag |= CONSTRAINT_DISABLE;
+                       }
                        
                        /* Check targets for constraints */
                        if (cti && cti->get_constraint_targets) {
index 27bc13a..82ee494 100644 (file)
@@ -1459,13 +1459,13 @@ static void draw_bundle_sphere(void)
 }
 
 static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D *v3d,
-                       MovieClip *clip, MovieTrackingObject *tracking_object, int flag)
+                       MovieClip *clip, MovieTrackingObject *tracking_object, int flag, int *global_track_index)
 {
        MovieTracking *tracking= &clip->tracking;
        MovieTrackingTrack *track;
        float mat[4][4], imat[4][4];
        unsigned char col[4], scol[4];
-       int bundlenr= 1;
+       int tracknr= *global_track_index;
        ListBase *tracksbase= BKE_tracking_object_tracks(tracking, tracking_object);
 
        UI_GetThemeColor4ubv(TH_TEXT, col);
@@ -1487,10 +1487,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
        else {
                float obmat[4][4];
 
-               if(flag & DRAW_PICKING) {
-                       return;
-               }
-
                BKE_tracking_get_interpolated_camera(tracking, tracking_object, scene->r.cfra, obmat);
 
                invert_m4_m4(imat, obmat);
@@ -1504,7 +1500,7 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                        continue;
 
                if(flag&DRAW_PICKING)
-                       glLoadName(base->selcol + (bundlenr<<16));
+                       glLoadName(base->selcol + (tracknr<<16));
 
                glPushMatrix();
                        glTranslatef(track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
@@ -1512,7 +1508,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
                        if(v3d->drawtype==OB_WIRE) {
                                glDisable(GL_LIGHTING);
-                               glDepthMask(0);
 
                                if(selected) {
                                        if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
@@ -1524,7 +1519,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
                                drawaxes(0.05f, v3d->bundle_drawtype);
 
-                               glDepthMask(1);
                                glEnable(GL_LIGHTING);
                        } else if(v3d->drawtype>OB_WIRE) {
                                if(v3d->bundle_drawtype==OB_EMPTY_SPHERE) {
@@ -1533,7 +1527,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                                if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
                                                else UI_ThemeColor(TH_SELECT);
 
-                                               glDepthMask(0);
                                                glLineWidth(2.f);
                                                glDisable(GL_LIGHTING);
                                                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@@ -1543,7 +1536,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
                                                glEnable(GL_LIGHTING);
                                                glLineWidth(1.f);
-                                               glDepthMask(1);
                                        }
 
                                        if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
@@ -1552,7 +1544,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                        draw_bundle_sphere();
                                } else {
                                        glDisable(GL_LIGHTING);
-                                       glDepthMask(0);
 
                                        if(selected) {
                                                if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
@@ -1564,7 +1555,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
                                        drawaxes(0.05f, v3d->bundle_drawtype);
 
-                                       glDepthMask(1);
                                        glEnable(GL_LIGHTING);
                                }
                        }
@@ -1582,7 +1572,7 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                        view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol);
                }
 
-               bundlenr++;
+               tracknr++;
        }
 
        if((flag & DRAW_PICKING)==0) {
@@ -1611,6 +1601,8 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
        }
 
        glPopMatrix();
+
+       *global_track_index= tracknr;
 }
 
 static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, MovieClip *clip, int flag)
@@ -1618,6 +1610,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
        MovieTracking *tracking= &clip->tracking;
        MovieTrackingObject *tracking_object;
        float curcol[4];
+       int global_track_index= 1;
 
        if((v3d->flag2&V3D_SHOW_RECONSTRUCTION)==0)
                return;
@@ -1634,7 +1627,8 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
 
        tracking_object= tracking->objects.first;
        while(tracking_object) {
-               draw_viewport_object_reconstruction(scene, base, v3d, clip, tracking_object, flag);
+               draw_viewport_object_reconstruction(scene, base, v3d, clip, tracking_object,
+                                       flag, &global_track_index);
 
                tracking_object= tracking_object->next;
        }
index d8ff01a..7da0714 100644 (file)
@@ -1320,6 +1320,25 @@ Base *ED_view3d_give_base_under_cursor(bContext *C, const int mval[2])
        return basact;
 }
 
+static void deselect_all_tracks(MovieTracking *tracking)
+{
+       MovieTrackingObject *object;
+
+       object= tracking->objects.first;
+       while(object) {
+               ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object);
+               MovieTrackingTrack *track= tracksbase->first;
+
+               while(track) {
+                       BKE_tracking_deselect_track(track, TRACK_AREA_ALL);
+
+                       track= track->next;
+               }
+
+               object= object->next;
+       }
+}
+
 /* mval is region coords */
 static int mouse_select(bContext *C, const int mval[2], short extend, short obcenter, short enumerate)
 {
@@ -1391,31 +1410,41 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce
                                if(basact->object->type==OB_CAMERA) {
                                        if(BASACT==basact) {
                                                int i, hitresult;
-                                               MovieTrackingTrack *track;
+                                               int changed= 0;
 
                                                for (i=0; i< hits; i++) {
                                                        hitresult= buffer[3+(i*4)];
 
                                                        /* if there's bundles in buffer select bundles first,
                                                           so non-camera elements should be ignored in buffer */
-                                                       if(basact->selcol != (hitresult & 0xFFFF))
+                                                       if(basact->selcol != (hitresult & 0xFFFF)) {
                                                                continue;
+                                                       }
 
                                                        /* index of bundle is 1<<16-based. if there's no "bone" index
                                                           in hight word, this buffer value belongs to camera,. not to bundle */
                                                        if(buffer[4*i+3] & 0xFFFF0000) {
                                                                MovieClip *clip= object_get_movieclip(scene, basact->object, 0);
                                                                MovieTracking *tracking= &clip->tracking;
-                                                               int selected;
-
-                                                               track= BKE_tracking_indexed_track(&clip->tracking, hitresult >> 16);
+                                                               ListBase *tracksbase;
+                                                               MovieTrackingTrack *track;
 
-                                                               selected= (track->flag&SELECT) || (track->pat_flag&SELECT) || (track->search_flag&SELECT);
+                                                               track= BKE_tracking_indexed_track(&clip->tracking, hitresult >> 16, &tracksbase);
 
-                                                               if(selected && extend)
+                                                               if(TRACK_SELECTED(track) && extend) {
+                                                                       changed= 0;
                                                                        BKE_tracking_deselect_track(track, TRACK_AREA_ALL);
-                                                               else
-                                                                       BKE_tracking_select_track(&tracking->tracks, track, TRACK_AREA_ALL, extend);
+                                                               }
+                                                               else {
+                                                                       int oldsel= TRACK_SELECTED(track) ? 1 : 0;
+                                                                       if(!extend)
+                                                                               deselect_all_tracks(tracking);
+
+                                                                       BKE_tracking_select_track(tracksbase, track, TRACK_AREA_ALL, extend);
+
+                                                                       if(oldsel!=(TRACK_SELECTED(track) ? 1 : 0))
+                                                                               changed= 1;
+                                                               }
 
                                                                basact->flag|= SELECT;
                                                                basact->object->flag= basact->flag;
@@ -1428,6 +1457,12 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce
                                                                break;
                                                        }
                                                }
+
+                                               if(!changed) {
+                                                       /* fallback to regular object selection if no new bundles were selected,
+                                                          allows to select object parented to reconstruction object */
+                                                       basact= mouse_select_eval_buffer(&vc, buffer, hits, mval, startbase, 0);
+                                               }
                                        }
                                }
                                else if(ED_do_pose_selectbuffer(scene, basact, buffer, hits, extend) ) {        /* then bone is found */
index ecb54c7..db33426 100644 (file)
@@ -55,6 +55,7 @@
 #include "BKE_lattice.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
+#include "BKE_scene.h"
 #include "BKE_tracking.h"
 
 #include "WM_api.h"
@@ -756,28 +757,55 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot)
 
 static void bundle_midpoint(Scene *scene, Object *ob, float vec[3])
 {
-       MovieTrackingTrack *track;
        MovieClip *clip= object_get_movieclip(scene, ob, 0);
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingObject *object= tracking->objects.first;
        int ok= 0;
-       float min[3], max[3], mat[4][4], pos[3];
+       float min[3], max[3], mat[4][4], pos[3], cammat[4][4];
 
        if(!clip)
                return;
 
+       unit_m4(cammat);
+
+       if(!scene->camera)
+               scene->camera= scene_find_camera(scene);
+
+       if(scene->camera)
+               copy_m4_m4(cammat, scene->camera->obmat);
+
        BKE_get_tracking_mat(scene, ob, mat);
 
        INIT_MINMAX(min, max);
 
-       track= clip->tracking.tracks.first;
-       while(track) {
-               int selected= (track->flag&SELECT) || (track->pat_flag&SELECT) || (track->search_flag&SELECT);
-               if((track->flag&TRACK_HAS_BUNDLE) && selected) {
-                       ok= 1;
-                       mul_v3_m4v3(pos, mat, track->bundle_pos);
-                       DO_MINMAX(pos, min, max);
+       while(object) {
+               ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object);
+               MovieTrackingTrack *track= tracksbase->first;
+               float obmat[4][4];
+
+               if(object->flag & TRACKING_OBJECT_CAMERA) {
+                       copy_m4_m4(obmat, mat);
+               }
+               else {
+                       float imat[4][4];
+
+                       BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, imat);
+                       invert_m4(imat);
+
+                       mul_m4_m4m4(obmat, imat, cammat);
+               }
+
+               while(track) {
+                       if((track->flag&TRACK_HAS_BUNDLE) && TRACK_SELECTED(track)) {
+                               ok= 1;
+                               mul_v3_m4v3(pos, obmat, track->bundle_pos);
+                               DO_MINMAX(pos, min, max);
+                       }
+
+                       track= track->next;
                }
 
-               track= track->next;
+               object= object->next;
        }
 
        if(ok) {