[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41566] branches/soc-2011-tomato: Camera tracking integration

Sergey Sharybin g.ulairi at gmail.com
Sat Nov 5 15:37:43 CET 2011


Revision: 41566
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41566
Author:   nazgul
Date:     2011-11-05 14:37:43 +0000 (Sat, 05 Nov 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Set as Background button will enable displaying background images in 3d space.
- Move options in Display panel to column. Saves some space.
- Camera solving now should deal fine with non-centered principal.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py	2011-11-05 14:34:14 UTC (rev 41565)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py	2011-11-05 14:37:43 UTC (rev 41566)
@@ -211,6 +211,8 @@
         bgpic.use_camera_clip = False
         bgpic.view_axis = 'CAMERA'
 
+        space_v3d.show_background_images = True
+
     def execute(self, context):
         sc = context.space_data
         clip = sc.clip

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-11-05 14:34:14 UTC (rev 41565)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-11-05 14:37:43 UTC (rev 41566)
@@ -363,7 +363,7 @@
 
         col = layout.column(align=True)
         col.label(text="Sensor:")
-        col.prop(clip.tracking.camera, "sensor_width", text="Size")
+        col.prop(clip.tracking.camera, "sensor_width", text="Width")
         col.prop(clip.tracking.camera, "pixel_aspect")
 
         col = layout.column()
@@ -388,36 +388,38 @@
         layout = self.layout
         sc = context.space_data
 
-        layout.prop(sc, "show_marker_pattern", text="Pattern")
-        layout.prop(sc, "show_marker_search", text="Search")
-        layout.prop(sc, "show_pyramid_levels", text="Pyramid")
+        col = layout.column(align=True)
 
-        layout.prop(sc, "show_track_path", text="Path")
-        row = layout.column()
+        col.prop(sc, "show_marker_pattern", text="Pattern")
+        col.prop(sc, "show_marker_search", text="Search")
+        col.prop(sc, "show_pyramid_levels", text="Pyramid")
+
+        col.prop(sc, "show_track_path", text="Path")
+        row = col.row()
         row.active = sc.show_track_path
         row.prop(sc, "path_length", text="Length")
 
-        layout.prop(sc, "show_disabled", text="Disabled")
-        layout.prop(sc, "show_bundles", text="Bundles")
+        col.prop(sc, "show_disabled", text="Disabled")
+        col.prop(sc, "show_bundles", text="Bundles")
 
-        layout.prop(sc, "show_names", text="Names")
-        layout.prop(sc, "show_tiny_markers", text="Tiny Markers")
+        col.prop(sc, "show_names", text="Names")
+        col.prop(sc, "show_tiny_markers", text="Tiny Markers")
 
-        layout.prop(sc, "show_grease_pencil", text="Grease Pencil")
-        layout.prop(sc, "use_mute_footage", text="Mute")
+        col.prop(sc, "show_grease_pencil", text="Grease Pencil")
+        col.prop(sc, "use_mute_footage", text="Mute")
 
         if sc.mode == 'DISTORTION':
-            layout.prop(sc, "show_grid", text="Grid")
-            layout.prop(sc, "use_manual_calibration")
+            col.prop(sc, "show_grid", text="Grid")
+            col.prop(sc, "use_manual_calibration")
         elif sc.mode == 'RECONSTRUCTION':
-            layout.prop(sc, "show_stable", text="Stable")
+            col.prop(sc, "show_stable", text="Stable")
 
-        layout.prop(sc, "lock_selection")
+        col.prop(sc, "lock_selection")
 
         clip = sc.clip
         if clip:
-            layout.label(text="Display Aspect:")
-            layout.prop(clip, "display_aspect", text="")
+            col.label(text="Display Aspect:")
+            col.prop(clip, "display_aspect", text="")
 
 
 class CLIP_PT_track_settings(Panel):

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-11-05 14:34:14 UTC (rev 41565)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-11-05 14:37:43 UTC (rev 41566)
@@ -40,8 +40,9 @@
 struct MovieTrackingContext;
 struct MovieClipUser;
 struct MovieDistortion;
+struct Camera;
+struct Object;
 struct Scene;
-struct Object;
 
 void BKE_tracking_clamp_track(struct MovieTrackingTrack *track, int event);
 void BKE_tracking_track_flag(struct MovieTrackingTrack *track, int area, int flag, int clear);
@@ -81,6 +82,9 @@
 struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr);
 void BKE_tracking_get_interpolated_camera(struct MovieTracking *tracking, int framenr, float mat[4][4]);
 
+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);
+
 void BKE_get_tracking_mat(struct Scene *scene, struct Object *ob, float mat[4][4]);
 void BKE_tracking_projection_matrix(struct MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4]);
 void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c	2011-11-05 14:34:14 UTC (rev 41565)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c	2011-11-05 14:37:43 UTC (rev 41566)
@@ -64,6 +64,7 @@
 #include "BKE_anim.h" /* for the curve calculation part */
 #include "BKE_armature.h"
 #include "BKE_blender.h"
+#include "BKE_camera.h"
 #include "BKE_constraint.h"
 #include "BKE_displist.h"
 #include "BKE_deform.h"

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-11-05 14:34:14 UTC (rev 41565)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-11-05 14:37:43 UTC (rev 41566)
@@ -36,6 +36,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_gpencil_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_movieclip_types.h"
 #include "DNA_object_types.h"	/* SELECT */
 #include "DNA_scene_types.h"
@@ -1497,6 +1498,29 @@
 		unit_m4(mat);
 }
 
+void BKE_tracking_camera_shift(MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty)
+{
+	*shiftx= (0.5f*winx-tracking->camera.principal[0]) / winx;
+	*shifty= (0.5f*winy-tracking->camera.principal[1]) / winx;
+}
+
+void BKE_tracking_camera_to_blender(MovieTracking *tracking, Scene *scene, Camera *camera, int width, int height)
+{
+	float focal= tracking->camera.focal;
+
+	camera->sensor_x= tracking->camera.sensor_width;
+	camera->sensor_fit= CAMERA_SENSOR_FIT_AUTO;
+	camera->lens= focal*camera->sensor_x/width;
+
+	scene->r.xsch= width*tracking->camera.pixel_aspect;
+	scene->r.ysch= height;
+
+	scene->r.xasp= 1.0f;
+	scene->r.yasp= 1.0f;
+
+	BKE_tracking_camera_shift(tracking, width, height, &camera->shiftx, &camera->shifty);
+}
+
 void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4])
 {
 	MovieReconstructedCamera *camera;
@@ -1504,7 +1528,10 @@
 	float viewfac, pixsize, left, right, bottom, top, clipsta, clipend;
 	float winmat[4][4];
 	float ycor= 1.0f/tracking->camera.pixel_aspect;
+	float shiftx, shifty, winside= MAX2(winx, winy);
 
+	BKE_tracking_camera_shift(tracking, winx, winy, &shiftx, &shifty);
+
 	clipsta= 0.1f;
 	clipend= 1000.0f;
 
@@ -1515,11 +1542,16 @@
 
 	pixsize= clipsta/viewfac;
 
-	left= -0.5f*(float)winx*pixsize;
-	bottom= -0.5f*ycor*(float)winy*pixsize;
-	right=  0.5f*(float)winx*pixsize;
-	top=  0.5f*ycor*(float)winy*pixsize;
+	left= -0.5f*(float)winx + shiftx*winside;
+	bottom= -0.5f*(ycor)*(float)winy + shifty*winside;
+	right=  0.5f*(float)winx + shiftx*winside;
+	top=  0.5f*(ycor)*(float)winy + shifty*winside;
 
+	left *= pixsize;
+	right *= pixsize;
+	bottom *= pixsize;
+	top *= pixsize;
+
 	perspective_m4(winmat, left, right, bottom, top, clipsta, clipend);
 
 	camera= BKE_tracking_get_reconstructed_camera(tracking, framenr);

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-11-05 14:34:14 UTC (rev 41565)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-11-05 14:37:43 UTC (rev 41566)
@@ -1551,28 +1551,12 @@
 		scene->camera= scene_find_camera(scene);
 
 	if(scene->camera) {
-		float focal= tracking->camera.focal;
-
 		/* set blender camera focal length so result would look fine there */
-		if(focal) {
-			Camera *camera= (Camera*)scene->camera->data;
+		Camera *camera= (Camera*)scene->camera->data;
 
-			camera->sensor_x= tracking->camera.sensor_width;
-			camera->lens= focal*camera->sensor_x/width;
+		BKE_tracking_camera_to_blender(tracking, scene, camera, width, height);
 
-			scene->r.xsch= width;
-			scene->r.ysch= height;
-
-			if(tracking->camera.pixel_aspect > 1.0f) {
-				scene->r.xasp= tracking->camera.pixel_aspect;
-				scene->r.yasp= 1.0f;
-			} else {
-				scene->r.xasp= 1.0f;
-				scene->r.yasp= 1.0f / tracking->camera.pixel_aspect;
-			}
-
-			WM_event_add_notifier(C, NC_OBJECT, camera);
-		}
+		WM_event_add_notifier(C, NC_OBJECT, camera);
 	}
 
 	DAG_id_tag_update(&clip->id, 0);




More information about the Bf-blender-cvs mailing list