Apply scale on scene reconstruction when applying scale on camera
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 13 May 2013 13:37:05 +0000 (13:37 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 13 May 2013 13:37:05 +0000 (13:37 +0000)
This means when you've got reconstructed scene assigned to a
3d camera (via camera solver constraint) and applies scale on
this camera from Ctrl-A menu, scale will be applied on the
reconstructed scene and reset camera size to identity.

This is very useful feature for scene orientation, when you'll
just scale camera by S in the viewport to match bundles
some points in the space, and then you'll easiy make camera
have identity scale (which is needed for nice working moblur
and other things mentioning by Sebastian :) without loosing
scale of bundles themselves.

Behavior of apply scale for cameras without clip assigned
to them does not change at all.

source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/tracking.c
source/blender/editors/object/object_transform.c

index 56b5240883cb6165ecbe30d2d8be6deeeaedd956..d8c761cd1b4e16539fdd9fe4d666e044160ce1c4 100644 (file)
@@ -195,6 +195,8 @@ void BKE_tracking_reconstruction_solve(struct MovieReconstructContext *context,
                                        float *progress, char *stats_message, int message_size);
 int BKE_tracking_reconstruction_finish(struct MovieReconstructContext *context, struct MovieTracking *tracking);
 
+void BKE_tracking_reconstruction_scale(struct MovieTracking *tracking, float scale[3]);
+
 /* **** Feature detection **** */
 void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ListBase *tracksbase, struct ImBuf *imbuf,
                               int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer,
index 7ad74085f856d8f25de787c3942f68b3c7274b88..74507b6d5431b2ea14562cd6063e4b3754d9ba9f 100644 (file)
@@ -3353,6 +3353,49 @@ int BKE_tracking_reconstruction_finish(MovieReconstructContext *context, MovieTr
        return TRUE;
 }
 
+static void tracking_scale_reconstruction(ListBase *tracksbase, MovieTrackingReconstruction *reconstruction,
+                                          float scale[3])
+{
+       MovieTrackingTrack *track;
+       int i;
+       float first_camera_delta[3] = {0.0f, 0.0f, 0.0f};
+
+       if (reconstruction->camnr > 0) {
+               mul_v3_v3v3(first_camera_delta, reconstruction->cameras[0].mat[3], scale);
+       }
+
+       for (i = 0; i < reconstruction->camnr; i++) {
+               MovieReconstructedCamera *camera = &reconstruction->cameras[i];
+               mul_v3_v3(camera->mat[3], scale);
+               sub_v3_v3(camera->mat[3], first_camera_delta);
+       }
+
+       for (track = tracksbase->first; track; track = track->next) {
+               if (track->flag & TRACK_HAS_BUNDLE) {
+                       mul_v3_v3(track->bundle_pos, scale);
+                       sub_v3_v3(track->bundle_pos, first_camera_delta);
+               }
+       }
+}
+
+/* Apply scale on all reconstructed cameras and bundles,
+ * used by camera scale apply operator.
+ */
+void BKE_tracking_reconstruction_scale(MovieTracking *tracking, float scale[3])
+{
+       MovieTrackingObject *object;
+
+       for (object = tracking->objects.first; object; object = object->next) {
+               ListBase *tracksbase;
+               MovieTrackingReconstruction *reconstruction;
+
+               tracksbase = BKE_tracking_object_get_tracks(tracking, object);
+               reconstruction = BKE_tracking_object_get_reconstruction(tracking, object);
+
+               tracking_scale_reconstruction(tracksbase, reconstruction, scale);
+       }
+}
+
 /*********************** Feature detection *************************/
 
 /* Check whether point is inside grease pencil stroke. */
index f62561743919b27c8679cd438b9625ac04eb83ca..7eb5c36a3fc6776354b46a780960a92da883c47d 100644 (file)
@@ -58,6 +58,7 @@
 #include "BKE_multires.h"
 #include "BKE_armature.h"
 #include "BKE_lattice.h"
+#include "BKE_tracking.h"
 
 #include "RNA_define.h"
 #include "RNA_access.h"
@@ -549,8 +550,21 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
                                }
                        }
                }
-               else
+               else if (ob->type == OB_CAMERA) {
+                       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.
+                        */
+                       if (!clip)
+                               continue;
+
+                       if (apply_scale)
+                               BKE_tracking_reconstruction_scale(&clip->tracking, ob->size);
+               }
+               else {
                        continue;
+               }
 
                if (apply_loc)
                        zero_v3(ob->loc);