[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43134] trunk/blender: Camera tracking: added depth object to Follow Track constraint

Sergey Sharybin sergey.vfx at gmail.com
Wed Jan 4 18:20:22 CET 2012


Revision: 43134
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43134
Author:   nazgul
Date:     2012-01-04 17:20:08 +0000 (Wed, 04 Jan 2012)
Log Message:
-----------
Camera tracking: added depth object to Follow Track constraint

If this object is defined, object with Follow Track constraint would be
projected into surface of this depth object.
If object is not set or there's no projection onto it, projection plane
calculated based on original object position would be used.

This allows to make cheap facial mocap.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_object_constraint.py
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenkernel/intern/depsgraph.c
    trunk/blender/source/blender/makesdna/DNA_constraint_types.h
    trunk/blender/source/blender/makesrna/intern/rna_constraint.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_object_constraint.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_object_constraint.py	2012-01-04 16:22:53 UTC (rev 43133)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_object_constraint.py	2012-01-04 17:20:08 UTC (rev 43134)
@@ -778,6 +778,10 @@
 
         layout.prop(con, "camera")
 
+        row = layout.row()
+        row.active = not con.use_3d_position
+        row.prop(con, "depth_object")
+
         layout.operator("clip.constraint_to_fcurve")
 
     def CAMERA_SOLVER(self, context, layout, con):

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2012-01-04 16:22:53 UTC (rev 43133)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2012-01-04 17:20:08 UTC (rev 43134)
@@ -41,6 +41,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_editVert.h"
+#include "BLI_kdopbvh.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_armature_types.h"
@@ -64,6 +65,7 @@
 #include "BKE_anim.h" /* for the curve calculation part */
 #include "BKE_armature.h"
 #include "BKE_blender.h"
+#include "BKE_bvhutils.h"
 #include "BKE_camera.h"
 #include "BKE_constraint.h"
 #include "BKE_displist.h"
@@ -3950,6 +3952,7 @@
 	
 	func(con, (ID**)&data->clip, userdata);
 	func(con, (ID**)&data->camera, userdata);
+	func(con, (ID**)&data->depth_ob, userdata);
 }
 
 static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
@@ -3985,7 +3988,6 @@
 
 	if (data->flag & FOLLOWTRACK_USE_3D_POSITION) {
 		if (track->flag & TRACK_HAS_BUNDLE) {
-			MovieTracking *tracking= &clip->tracking;
 			float obmat[4][4], mat[4][4];
 
 			copy_m4_m4(obmat, cob->matrix);
@@ -4008,9 +4010,8 @@
 				translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
 			}
 		}
-	} 
+	}
 	else {
-		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);
@@ -4035,8 +4036,7 @@
 			CameraParams params;
 			float pos[2], rmat[4][4];
 
-			user.framenr= scene->r.cfra;
-			marker= BKE_tracking_get_marker(track, user.framenr);
+			marker= BKE_tracking_get_marker(track, scene->r.cfra);
 
 			add_v2_v2v2(pos, marker->pos, track->offset);
 
@@ -4078,6 +4078,34 @@
 
 				copy_v3_v3(cob->matrix[3], disp);
 			}
+
+			if(data->depth_ob && data->depth_ob->derivedFinal) {
+				Object *depth_ob= data->depth_ob;
+				BVHTreeFromMesh treeData= NULL_BVHTreeFromMesh;
+				BVHTreeRayHit hit;
+				float ray_start[3], ray_end[3], ray_nor[3], imat[4][4];
+				int result;
+
+				invert_m4_m4(imat, depth_ob->obmat);
+
+				mul_v3_m4v3(ray_start, imat, camob->obmat[3]);
+				mul_v3_m4v3(ray_end, imat, cob->matrix[3]);
+
+				sub_v3_v3v3(ray_nor, ray_end, ray_start);
+
+				bvhtree_from_mesh_faces(&treeData, depth_ob->derivedFinal, 0.0f, 4, 6);
+
+				hit.dist= FLT_MAX;
+				hit.index= -1;
+
+				result= BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_nor, 0.0f, &hit, treeData.raycast_callback, &treeData);
+
+				if(result != -1) {
+					mul_v3_m4v3(cob->matrix[3], depth_ob->obmat, hit.co);
+				}
+
+				free_bvhtree_from_mesh(&treeData);
+			}
 		}
 	}
 }

Modified: trunk/blender/source/blender/blenkernel/intern/depsgraph.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/depsgraph.c	2012-01-04 16:22:53 UTC (rev 43133)
+++ trunk/blender/source/blender/blenkernel/intern/depsgraph.c	2012-01-04 17:20:08 UTC (rev 43134)
@@ -657,6 +657,11 @@
 
 				if((data->clip || data->flag&FOLLOWTRACK_ACTIVECLIP) && data->track[0])
 					depends_on_camera= 1;
+
+				if(data->depth_ob) {
+					node2 = dag_get_node(dag, data->depth_ob);
+					dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name);
+				}
 			}
 			else if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER)
 				depends_on_camera= 1;

Modified: trunk/blender/source/blender/makesdna/DNA_constraint_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_constraint_types.h	2012-01-04 16:22:53 UTC (rev 43133)
+++ trunk/blender/source/blender/makesdna/DNA_constraint_types.h	2012-01-04 17:20:08 UTC (rev 43134)
@@ -417,6 +417,7 @@
 	int		flag, pad;
 	char		object[24];
 	struct Object *camera;
+	struct Object *depth_ob;
 } bFollowTrackConstraint;
 
 /* Camera Solver constraints */

Modified: trunk/blender/source/blender/makesrna/intern/rna_constraint.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_constraint.c	2012-01-04 16:22:53 UTC (rev 43133)
+++ trunk/blender/source/blender/makesrna/intern/rna_constraint.c	2012-01-04 17:20:08 UTC (rev 43134)
@@ -358,6 +358,34 @@
 	}
 }
 
+static void rna_Constraint_followTrack_depthObject_set(PointerRNA *ptr, PointerRNA value)
+{
+	bConstraint *con= (bConstraint*)ptr->data;
+	bFollowTrackConstraint *data= (bFollowTrackConstraint*)con->data;
+	Object *ob= (Object*)value.data;
+
+	if (ob) {
+		if (ob->type == OB_MESH && ob != (Object*)ptr->id.data) {
+			data->depth_ob= ob;
+		}
+	} else {
+		data->depth_ob= NULL;
+	}
+}
+
+static int rna_Constraint_followTrack_depthObject_poll(PointerRNA *ptr, PointerRNA value)
+{
+	Object *ob= (Object*)value.data;
+
+	if(ob) {
+		if (ob->type == OB_MESH && ob != (Object*)ptr->id.data) {
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 static void rna_Constraint_objectSolver_camera_set(PointerRNA *ptr, PointerRNA value)
 {
 	bConstraint *con= (bConstraint*)ptr->data;
@@ -2126,6 +2154,14 @@
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update");
 	RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_followTrack_camera_set", NULL, "rna_Constraint_cameraObject_poll");
+
+	/* depth object */
+	prop= RNA_def_property(srna, "depth_object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "depth_ob");
+	RNA_def_property_ui_text(prop, "Depth Object", "Object used to define depth in camera space by projecting onto surface of this object");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update");
+	RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_followTrack_depthObject_set", NULL, "rna_Constraint_followTrack_depthObject_poll");
 }
 
 static void rna_def_constraint_camera_solver(BlenderRNA *brna)



More information about the Bf-blender-cvs mailing list