Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Jul 2011 09:16:26 +0000 (09:16 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Jul 2011 09:16:26 +0000 (09:16 +0000)
===========================

- Fixed bug with bundle getting selected when clicking on camera.
- Bundles are now low-poly.
- Tweaked "Snap Cursor To Active" operator:
  If active object is camera and there's bundles wisible in viewport,
  snapping would happen to midpoint of selected bundles.

source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c

index 0f3e0464d91188ee4b4b43f2a334d7396a047992..a914fc18d01521c9cc84f709f4843eb996114fc2 100644 (file)
@@ -1391,7 +1391,7 @@ static void draw_bundle_sphere(void)
                qobj= gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_FILL);
                glShadeModel(GL_SMOOTH);
-               gluSphere(qobj, 0.05, 16, 16);
+               gluSphere(qobj, 0.05, 8, 8);
                glShadeModel(GL_FLAT);
                gluDeleteQuadric(qobj);
 
@@ -1415,13 +1415,13 @@ static void draw_bundle_outline(void)
 
                qobj= gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
-               gluDisk(qobj, 0.0,  0.05, 16, 1);
+               gluDisk(qobj, 0.0,  0.05, 8, 1);
 
                glRotatef(90, 0, 1, 0);
-               gluDisk(qobj, 0.0,  0.05, 16, 1);
+               gluDisk(qobj, 0.0,  0.05, 8, 1);
 
                glRotatef(90, 1, 0, 0);
-               gluDisk(qobj, 0.0,  0.05, 16, 1);
+               gluDisk(qobj, 0.0,  0.05, 8, 1);
 
                gluDeleteQuadric(qobj);
 
@@ -1482,8 +1482,11 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
                                glDisable(GL_LIGHTING);
                                glDepthMask(0);
 
-                               if(TRACK_SELECTED(track)) UI_ThemeColor(TH_SELECT);
-                               else UI_ThemeColor(TH_WIRE);
+                               if(TRACK_SELECTED(track)) {
+                                       if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                                       else UI_ThemeColor(TH_SELECT);
+                               } else UI_ThemeColor(TH_WIRE);
+
                                draw_bundle_outline();
 
                                glDepthMask(1);
@@ -1491,7 +1494,8 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
                        } else if(v3d->drawtype>OB_WIRE) {
                                /* selection outline */
                                if(TRACK_SELECTED(track)) {
-                                       UI_ThemeColor(TH_SELECT);
+                                       if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                                       else UI_ThemeColor(TH_SELECT);
 
                                        glDepthMask(0);
                                        glLineWidth(2.f);
@@ -1555,6 +1559,9 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
        glDisable(GL_LIGHTING);
 
        glColor4fv(curcol);
+
+       if(flag&DRAW_PICKING)
+               glLoadName(base->selcol);
 }
 
 /* flag similar to draw_object() */
index 74505b6133a2695ebd1cf4bf59721458a5316b72..2b0cd1ce9f41dc5deffc4c983228b95a918d2c6a 100644 (file)
@@ -1282,33 +1282,37 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce
                        }
                        
                        if(has_bones && basact) {
-                               int is_cam= basact->object->type==OB_CAMERA;
+                               if(basact->object->type==OB_CAMERA) {
+                                       if(BASACT==basact) {
+                                               int i, hitresult;
+                                               MovieTrackingTrack *track;
 
-                               if(is_cam) {
-                                       int i, hitresult;
-                                       MovieTrackingTrack *track;
+                                               for (i=0; i< hits; i++) {
+                                                       hitresult= buffer[3+(i*4)];
 
-                                       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))
+                                                               continue;
 
-                                               /* if there's bundles in buffer select bundles first,
-                                                  so non-camera elements should be ignored in buffer */
-                                               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) {
+                                                               track= BKE_tracking_indexed_bundle(&scene->clip->tracking, hitresult >> 16);
 
-                                               /* 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) {
-                                                       track= BKE_tracking_indexed_bundle(&scene->clip->tracking, hitresult >> 16);
-                                                       BKE_movieclip_select_track(scene->clip, track, TRACK_AREA_ALL, extend);
+                                                               if(TRACK_SELECTED(track) && extend) BKE_movieclip_deselect_track(scene->clip, track, TRACK_AREA_ALL);
+                                                               else BKE_movieclip_select_track(scene->clip, track, TRACK_AREA_ALL, extend);
 
-                                                       basact->flag|= SELECT;
-                                                       basact->object->flag= basact->flag;
+                                                               basact->flag|= SELECT;
+                                                               basact->object->flag= basact->flag;
 
-                                                       retval= 1;
-                                                       WM_event_add_notifier(C, NC_MOVIECLIP|ND_SELECT, basact->object);
+                                                               retval= 1;
 
-                                                       break;
+                                                               WM_event_add_notifier(C, NC_MOVIECLIP|ND_SELECT, track);
+                                                               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+
+                                                               break;
+                                                       }
                                                }
                                        }
                                }
@@ -1331,7 +1335,7 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce
 
                                }
                                /* prevent bone selecting to pass on to object selecting */
-                               if(!is_cam && basact==BASACT)
+                               if(basact==BASACT)
                                        basact= NULL;
                        }
                }
index b4d2fc221439ec70fe24503475eca23e19b81989..e828e85b1a37fb4acd7cb55f8a7862aefc4b7c0a 100644 (file)
@@ -57,6 +57,7 @@
 #include "BKE_lattice.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
+#include "BKE_tracking.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -852,6 +853,32 @@ void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot)
 
 /* ********************************************** */
 
+static void snap_to_bundle(Scene *scene, float *curs)
+{
+       MovieTrackingTrack *track;
+       int ok= 0;
+       float min[3], max[3], mat[4][4], pos[3];
+
+       BKE_get_tracking_mat(scene, mat);
+
+       INIT_MINMAX(min, max);
+
+       track= scene->clip->tracking.tracks.first;
+       while(track) {
+               if(track->flag&TRACK_HAS_BUNDLE && TRACK_SELECTED(track)) {
+                       ok= 1;
+                       mul_v3_m4v3(pos, mat, track->bundle_pos);
+                       DO_MINMAX(pos, min, max);
+               }
+
+               track= track->next;
+       }
+
+       if(ok) {
+               interp_v3_v3v3(curs, min, max, 0.5);
+       }
+}
+
 static int snap_curs_to_active(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
@@ -878,6 +905,14 @@ static int snap_curs_to_active(bContext *C, wmOperator *UNUSED(op))
        else {
                if (obact) {
                        VECCOPY(curs, obact->obmat[3]);
+
+                       /* special case for camera -- snap to bundles */
+                       if(obact->type==OB_CAMERA) {
+                               /* snap to bundles should happen only when bundles are visible */
+                               if(scene->clip && v3d->flag2&V3D_SHOW_RECONSTRUCTION) {
+                                       snap_to_bundle(scene, curs);
+                               }
+                       }
                }
        }