Enable vertex snapping to bundle positions
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 9 Sep 2013 11:37:37 +0000 (11:37 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 9 Sep 2013 11:37:37 +0000 (11:37 +0000)
This means it's possible now to snap stuff to
reconstructed tracks positions.

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/object.c
source/blender/editors/object/object_transform.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/transform/transform_snap.c

index 8007aba2a53e7280df7e3823cf7d45da7c1436c0..e99eb2a64f26881e2e5c6d260d8b3da71c1562de 100644 (file)
@@ -170,7 +170,7 @@ int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob);
 
 void BKE_object_relink(struct Object *ob);
 
-struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, int use_default);
+struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, bool use_default);
 
 /* this function returns a superset of the scenes selection based on relationships */
 
index f786f842be37f65e938fd104eac9844fa165d913..cc22117699497b79e470aeb2a9ea2e535de6a0fd 100644 (file)
@@ -2275,7 +2275,7 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
                 * so it should happen tracking-related constraints recalculation
                 * when camera is changing (sergey) */
                if (sce->camera && &sce->camera->id == id) {
-                       MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, 1);
+                       MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, true);
 
                        if (clip)
                                dag_id_flush_update(bmain, sce, &clip->id);
index 6ffab6786912add0f3deeb2afc0b9f5fef31926b..8ae0187e27de414b393d4527719135de4cd11afd 100644 (file)
@@ -3261,7 +3261,7 @@ void BKE_object_relink(Object *ob)
        ID_NEW(ob->proxy_group);
 }
 
-MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, int use_default)
+MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default)
 {
        MovieClip *clip = use_default ? scene->clip : NULL;
        bConstraint *con = ob->constraints.first, *scon = NULL;
index 36ce72f1cabfd9775760cb9e0fd9f5e8f676e9e5..c4878ef79d98a780d343b7e5a3e457f6a51465ea 100644 (file)
@@ -551,7 +551,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
                        }
                }
                else if (ob->type == OB_CAMERA) {
-                       MovieClip *clip = BKE_object_movieclip_get(scene, ob, FALSE);
+                       MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
 
                        /* applying scale on camera actually scales clip's reconstruction.
                         * of there's clip assigned to camera nothing to do actually.
index 8106befcab83c6b887f0cd7675c488127d71952a..f5fd0ffb3add340187b3afb2f1bcf53c5163d808 100644 (file)
@@ -1874,13 +1874,13 @@ static Object *get_camera_with_movieclip(Scene *scene, MovieClip *clip)
        Object *camera = scene->camera;
        Base *base;
 
-       if (camera && BKE_object_movieclip_get(scene, camera, 0) == clip)
+       if (camera && BKE_object_movieclip_get(scene, camera, false) == clip)
                return camera;
 
        base = scene->base.first;
        while (base) {
                if (base->object->type == OB_CAMERA) {
-                       if (BKE_object_movieclip_get(scene, base->object, 0) == clip) {
+                       if (BKE_object_movieclip_get(scene, base->object, false) == clip) {
                                camera = base->object;
                                break;
                        }
index ac216907c7fb94d78707d1e04107ea10d842c271..d1b726968b9f68994281c512c3cc48915d3c2c70 100644 (file)
@@ -1672,7 +1672,7 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
        int i;
        float drawsize;
        const bool is_view = (rv3d->persp == RV3D_CAMOB && ob == v3d->camera);
-       MovieClip *clip = BKE_object_movieclip_get(scene, base->object, 0);
+       MovieClip *clip = BKE_object_movieclip_get(scene, base->object, false);
 
        /* draw data for movie clip set as active for scene */
        if (clip) {
index ccb53468ca9563294acb26b5f6f0dd86c2fa6ff8..b737dba1a3b22d16a46ed5720b348b6f5de30fc6 100644 (file)
@@ -1662,7 +1662,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 
                                if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
                                        if (scene->camera)
-                                               clip = BKE_object_movieclip_get(scene, scene->camera, 1);
+                                               clip = BKE_object_movieclip_get(scene, scene->camera, true);
                                }
                                else {
                                        clip = bgpic->clip;
index 19426ab2dfa8c2141eeac9f5e02119e6a302ef7d..c812f1084e26a8b8e44e6170d7861d7c312b2772 100644 (file)
@@ -1462,7 +1462,7 @@ static bool mouse_select(bContext *C, const int mval[2], bool extend, bool desel
                                                        /* index of bundle is 1<<16-based. if there's no "bone" index
                                                         * in height word, this buffer value belongs to camera. not to bundle */
                                                        if (buffer[4 * i + 3] & 0xFFFF0000) {
-                                                               MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, 0);
+                                                               MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, false);
                                                                MovieTracking *tracking = &clip->tracking;
                                                                ListBase *tracksbase;
                                                                MovieTrackingTrack *track;
index 0f2f07a1053efe088d050b66caf0a63777ef44f8..5f988edb9504a8fd8f881d462544a61db3767c56 100644 (file)
@@ -882,7 +882,7 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot)
 
 static void bundle_midpoint(Scene *scene, Object *ob, float vec[3])
 {
-       MovieClip *clip = BKE_object_movieclip_get(scene, ob, 0);
+       MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
        MovieTracking *tracking;
        MovieTrackingObject *object;
        int ok = 0;
index 86bdcbdb39433297f3275edd64a7b40891ba69e9..e2b81d794c78e1c5602a0093b93fc4f49b78fd7c 100644 (file)
@@ -59,6 +59,7 @@
 #include "BKE_context.h"
 #include "BKE_editmesh.h"
 #include "BKE_mesh.h"
+#include "BKE_tracking.h"
 
 #include "RNA_access.h"
 
@@ -1557,6 +1558,90 @@ static bool snapEmpty(short snap_mode, ARegion *ar, Object *ob, float obmat[4][4
        return retval;
 }
 
+static bool snapCamera(short snap_mode, ARegion *ar, Scene *scene, Object *object, float obmat[4][4],
+                       const float ray_start[3], const float ray_normal[3], const float mval[2],
+                       float r_loc[3], float *UNUSED(r_no), float *r_dist_px, float *r_depth)
+{
+       float orig_camera_mat[4][4], orig_camera_imat[4][4], imat[4][4];
+       bool retval = false;
+       MovieClip *clip = BKE_object_movieclip_get(scene, object, false);
+       MovieTracking *tracking;
+       float ray_start_local[3], ray_normal_local[3];
+
+       if (clip == NULL) {
+               return retval;
+       }
+       if (object->transflag & OB_DUPLI) {
+               return retval;
+       }
+
+       tracking = &clip->tracking;
+
+       BKE_tracking_get_camera_object_matrix(scene, object, orig_camera_mat);
+
+       invert_m4_m4(orig_camera_imat, orig_camera_mat);
+       invert_m4_m4(imat, obmat);
+
+       switch (snap_mode) {
+               case SCE_SNAP_MODE_VERTEX:
+               {
+                       MovieTrackingObject *tracking_object;
+
+                       for (tracking_object = tracking->objects.first;
+                            tracking_object;
+                            tracking_object = tracking_object->next)
+                       {
+                               ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
+                               MovieTrackingTrack *track;
+                               float reconstructed_camera_mat[4][4],
+                                     reconstructed_camera_imat[4][4];
+                               float (*vertex_obmat)[4];
+
+                               copy_v3_v3(ray_start_local, ray_start);
+                               copy_v3_v3(ray_normal_local, ray_normal);
+
+                               if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) {
+                                       BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object,
+                                                                                         CFRA, reconstructed_camera_mat);
+
+                                       invert_m4_m4(reconstructed_camera_imat, reconstructed_camera_mat);
+                               }
+
+                               for (track = tracksbase->first; track; track = track->next) {
+                                       float bundle_pos[3];
+
+                                       if ((track->flag & TRACK_HAS_BUNDLE) == 0) {
+                                               continue;
+                                       }
+
+                                       copy_v3_v3(bundle_pos, track->bundle_pos);
+                                       if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+                                               mul_m4_v3(orig_camera_imat, ray_start_local);
+                                               mul_mat3_m4_v3(orig_camera_imat, ray_normal_local);
+                                               vertex_obmat = orig_camera_mat;
+                                       }
+                                       else {
+                                               mul_m4_v3(reconstructed_camera_imat, bundle_pos);
+                                               mul_m4_v3(imat, ray_start_local);
+                                               mul_mat3_m4_v3(imat, ray_normal_local);
+                                               vertex_obmat = obmat;
+                                       }
+
+                                       retval |= snapVertex(ar, bundle_pos, NULL, vertex_obmat, NULL,
+                                                            ray_start, ray_start_local, ray_normal_local, mval,
+                                                            r_loc, NULL, r_dist_px, r_depth);
+                               }
+                       }
+
+                       break;
+               }
+               default:
+                       break;
+       }
+
+       return retval;
+}
+
 static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, float obmat[4][4], bool use_obedit,
                        Object **r_ob, float r_obmat[4][4],
                        const float ray_start[3], const float ray_normal[3], const float mval[2],
@@ -1586,6 +1671,8 @@ static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, f
        }
        else if (ob->type == OB_EMPTY) {
                retval = snapEmpty(snap_mode, ar, ob, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_depth);
+       } else if (ob->type == OB_CAMERA) {
+               retval = snapCamera(snap_mode, ar, scene, ob, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_depth);
        }
        
        if (retval) {