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

Sergey Sharybin g.ulairi at gmail.com
Mon Jul 18 20:45:05 CEST 2011


Revision: 38487
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38487
Author:   nazgul
Date:     2011-07-18 18:45:05 +0000 (Mon, 18 Jul 2011)
Log Message:
-----------
Camera tracking integration
===========================

Changed behavior of "Follow Track" constraint for tracks.

Now tracking coordinates are mapped to plane which is
parallel to camera view plane.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_camera.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_scene.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c	2011-07-18 18:44:54 UTC (rev 38486)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c	2011-07-18 18:45:05 UTC (rev 38487)
@@ -47,6 +47,7 @@
 #include "BLI_utildefines.h"
 
 #include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
@@ -54,6 +55,7 @@
 #include "DNA_curve_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_text_types.h"
@@ -3956,11 +3958,7 @@
 	Scene *scene= cob->scene;
 	bFollowTrackConstraint *data= con->data;
 	MovieClip *clip= data->clip;
-	MovieClipUser user;
 	MovieTrackingTrack *track;
-	MovieTrackingMarker *marker;
-	float tx, ty;
-	int width, height;
 
 	if(data->flag&FOLLOWTRACK_DEFAULTCLIP)
 		clip= scene->clip;
@@ -3987,15 +3985,96 @@
 			cob->matrix[3][2]+= pos[2];
 		}
 	} else {
-		user.framenr= scene->r.cfra;
-		BKE_movieclip_acquire_size(clip, &user, &width, &height);
+		Object *camob= cob->scene->camera;
 
-		marker= BKE_tracking_get_marker(track, user.framenr);
+		if(camob) {
+			MovieClipUser user;
+			MovieTrackingMarker *marker;
+			float vec[3], disp[3], axis[3], mat[4][4];
+			float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp);
+			float sensor_x, lens, len, d, ortho_scale;
 
-		tx= marker->pos[0]*width;
-		ty= marker->pos[1]*height;
+			where_is_object_mat(scene, camob, mat);
 
-		translate_m4(cob->matrix, tx, ty, 0);
+			/* camera axis */
+			vec[0]= 0.f;
+			vec[1]= 0.f;
+			vec[2]= 1.f;
+			mul_v3_m4v3(axis, mat, vec);
+
+			/* distance to projection plane */
+			copy_v3_v3(vec, cob->matrix[3]);
+			sub_v3_v3(vec, mat[3]);
+			project_v3_v3v3(disp, vec, axis);
+
+			len= len_v3(disp);
+
+			if(len>FLT_EPSILON) {
+				float rmat[4][4];
+				int is_ortho= 0;
+
+				/* calculate lens and sensor size depends on object type */
+				if(camob->type==OB_CAMERA) {
+					Camera *camera= (Camera *)camob->data;
+
+					sensor_x= camera->sensor_x;
+					lens= camera->lens;
+					is_ortho= camera->type == CAM_ORTHO;
+					ortho_scale= camera->ortho_scale;
+				} else if (camob->type==OB_LAMP) {
+					Lamp *la= camob->data;
+					float fac= cosf((float)M_PI*la->spotsize/360.0f);
+					float phi= acos(fac);
+
+					lens= 16.0f*fac/sinf(phi);
+					sensor_x= 32.f;
+					ortho_scale= 0.f;
+				} else {
+					lens= 16.f;
+					sensor_x= 32.f;
+					ortho_scale= 0.f;
+				}
+
+				user.framenr= scene->r.cfra;
+				marker= BKE_tracking_get_marker(track, user.framenr);
+
+				if(is_ortho) {
+					vec[0]= ortho_scale * (marker->pos[0]-0.5f);
+					vec[1]= ortho_scale * (marker->pos[1]-0.5f);
+					vec[2]= -len;
+
+					if(aspect>1.f) vec[1]/= aspect;
+					else vec[0]*= aspect;
+
+					mul_v3_m4v3(disp, camob->obmat, vec);
+
+					copy_m4_m4(rmat, camob->obmat);
+					zero_v3(rmat[3]);
+					mul_m4_m4m4(cob->matrix, rmat, cob->matrix);
+
+					copy_v3_v3(cob->matrix[3], disp);
+				}
+				else {
+					d= (len*sensor_x) / (2.f*lens);
+
+					vec[0]= d*(2.f*marker->pos[0]-1.f);
+					vec[1]= d*(2.f*marker->pos[1]-1.f);
+					vec[2]= -len;
+
+					if(aspect>1.f) vec[1]/= aspect;
+					else vec[0]*= aspect;
+
+					mul_v3_m4v3(disp, camob->obmat, vec);
+
+					/* apply camera rotation so Z-axis would be co-linear */
+					copy_m4_m4(rmat, camob->obmat);
+					zero_v3(rmat[3]);
+					mul_m4_m4m4(cob->matrix, rmat, cob->matrix);
+
+					copy_v3_v3(cob->matrix[3], disp);
+				}
+			}
+		}
 	}
 }
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c	2011-07-18 18:44:54 UTC (rev 38486)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c	2011-07-18 18:45:05 UTC (rev 38487)
@@ -648,8 +648,8 @@
 			if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) {
 				bFollowTrackConstraint *data= (bFollowTrackConstraint *)con->data;
 
-				if(data->reference==FOLLOWTRACK_BUNDLE) {
-					if((data->clip || data->flag&FOLLOWTRACK_DEFAULTCLIP) && data->track[0]) {
+				if((data->clip || data->flag&FOLLOWTRACK_DEFAULTCLIP) && data->track[0]) {
+					if(scene->camera) {
 						node2 = dag_get_node(dag, scene->camera);
 						dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name);
 					}

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-07-18 18:44:54 UTC (rev 38486)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-07-18 18:45:05 UTC (rev 38487)
@@ -472,7 +472,7 @@
 				if(ibuf && ibuf->rect) {
 					ImBuf *tmpibuf;
 
-					tmpibuf= BKE_tracking_acquire_pattern_imbuf(ibuf, track, marker, 1, &scopes->track_pos, NULL);
+					tmpibuf= BKE_tracking_acquire_pattern_imbuf(ibuf, track, marker, 1, scopes->track_pos, NULL);
 
 					if(tmpibuf->rect_float)
 						IMB_rect_from_float(tmpibuf);

Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_camera.c
===================================================================
--- branches/soc-2011-tomato/source/blender/makesrna/intern/rna_camera.c	2011-07-18 18:44:54 UTC (rev 38486)
+++ branches/soc-2011-tomato/source/blender/makesrna/intern/rna_camera.c	2011-07-18 18:45:05 UTC (rev 38487)
@@ -42,6 +42,7 @@
 #ifdef RNA_RUNTIME
 
 #include "BKE_object.h"
+#include "BKE_depsgraph.h"
 
 /* only for rad/deg conversion! can remove later */
 static float rna_Camera_angle_x_get(PointerRNA *ptr)
@@ -68,6 +69,13 @@
 	cam->lens= vfov_to_focallength(value, cam->sensor_y);
 }
 
+static void rna_Camera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+	Camera *camera= (Camera*)ptr->id.data;
+
+	DAG_id_tag_update(&camera->id, 0);
+}
+
 #else
 
 void RNA_def_camera(BlenderRNA *brna)
@@ -101,7 +109,7 @@
 	prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_items(prop, prop_type_items);
 	RNA_def_property_ui_text(prop, "Type", "Camera types");
-	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 
 	prop= RNA_def_property(srna, "show_guide", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "dtx");
@@ -122,14 +130,14 @@
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_ui_text(prop, "Field of View", "Camera lens horizontal field of view in degrees");
 	RNA_def_property_float_funcs(prop, "rna_Camera_angle_x_get", "rna_Camera_angle_x_set", NULL);
-	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 
 	prop= RNA_def_property(srna, "angle_y", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0));
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_ui_text(prop, "Field of View", "Camera lens vertical field of view in degrees");
 	RNA_def_property_float_funcs(prop, "rna_Camera_angle_y_get", "rna_Camera_angle_y_set", NULL);
-	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 
 	prop= RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE);
 	RNA_def_property_float_sdna(prop, NULL, "clipsta");
@@ -147,26 +155,26 @@
 	RNA_def_property_float_sdna(prop, NULL, "lens");
 	RNA_def_property_range(prop, 1.0f, 5000.0f);
 	RNA_def_property_ui_text(prop, "Focal Length", "Perspective Camera lens value in millimeters");
-	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 	
 	prop= RNA_def_property(srna, "sensor_x", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "sensor_x");
 	RNA_def_property_range(prop, 1.0f, FLT_MAX);
 	RNA_def_property_ui_range(prop, 1.0f, 100.f, 1, 2);
 	RNA_def_property_ui_text(prop, "Sensor X", "Horizontal size of the image sensor area in millimeters");
-	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 
 	prop= RNA_def_property(srna, "sensor_y", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_range(prop, 1.0f, FLT_MAX);
 	RNA_def_property_ui_range(prop, 1.0f, 100.f, 1, 2);
 	RNA_def_property_ui_text(prop, "Sensor Y", "Vertical size of the image sensor area in millimeters");
-	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 
 	prop= RNA_def_property(srna, "ortho_scale", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "ortho_scale");
 	RNA_def_property_range(prop, 0.01f, 4000.0f);
 	RNA_def_property_ui_text(prop, "Orthographic Scale", "Orthographic Camera scale (similar to zoom)");
-	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 
 	prop= RNA_def_property(srna, "draw_size", PROP_FLOAT, PROP_DISTANCE);
 	RNA_def_property_float_sdna(prop, NULL, "drawsize");

Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2011-tomato/source/blender/makesrna/intern/rna_scene.c	2011-07-18 18:44:54 UTC (rev 38486)
+++ branches/soc-2011-tomato/source/blender/makesrna/intern/rna_scene.c	2011-07-18 18:45:05 UTC (rev 38487)
@@ -1016,6 +1016,15 @@
 	}
 }
 
+static void rna_SceneCamera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+	Scene *scene= (Scene*)ptr->id.data;
+	Object *camera= scene->camera;
+
+	if(camera)
+		DAG_id_tag_update(&camera->id, 0);
+}
+
 #else
 
 static void rna_def_transform_orientation(BlenderRNA *brna)
@@ -2200,13 +2209,13 @@
 	RNA_def_property_int_sdna(prop, NULL, "xsch");
 	RNA_def_property_range(prop, 4, 10000);
 	RNA_def_property_ui_text(prop, "Resolution X", "Number of horizontal pixels in the rendered image");
-	RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list