[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42650] branches/soc-2011-tomato: Object tracking: object with object solver constraint is now parented to scene's camera

Sergey Sharybin sergey.vfx at gmail.com
Thu Dec 15 17:09:58 CET 2011


Revision: 42650
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42650
Author:   nazgul
Date:     2011-12-15 16:09:57 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
Object tracking: object with object solver constraint is now parented to scene's camera

Made Object Solver operator parent object to scene's camera. Behavior is pretty much
familiar to Child Of constraint -- it stores inverted transformation matrix which gives
constant offset in parent's space.
Current files would open incorrect, to make object aligned well again, just press
"Set Inverse" button in Object Solver constraint.
Fixed orientation operators so now they should work in all cases.
Also changed behavior of Set Origin operator which now sets origin to the median
point of all selected tracks/

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py
    branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
    branches/soc-2011-tomato/source/blender/blenlib/intern/math_matrix.c
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/editors/object/object_constraint.c
    branches/soc-2011-tomato/source/blender/editors/object/object_intern.h
    branches/soc-2011-tomato/source/blender/editors/object/object_ops.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
    branches/soc-2011-tomato/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_constraint_types.h

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py	2011-12-15 16:04:59 UTC (rev 42649)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py	2011-12-15 16:09:57 UTC (rev 42650)
@@ -784,6 +784,10 @@
 
         layout.prop(con, "object")
 
+        row = layout.row()
+        row.operator("constraint.objectsolver_set_inverse")
+        row.operator("constraint.objectsolver_clear_inverse")
+
         layout.operator("clip.constraint_to_fcurve")
 
     def SCRIPT(self, context, layout, con):

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c	2011-12-15 16:04:59 UTC (rev 42649)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c	2011-12-15 16:09:57 UTC (rev 42650)
@@ -825,7 +825,7 @@
 {
 	bChildOfConstraint *data= con->data;
 	bConstraintTarget *ct= targets->first;
-	
+
 	/* only evaluate if there is a target */
 	if (VALID_CONS_TARGET(ct)) {
 		float parmat[4][4];
@@ -4183,20 +4183,21 @@
 		object= BKE_tracking_named_object(tracking, data->object);
 
 		if(object) {
-			float mat[4][4], obmat[4][4], imat[4][4], cammat[4][4], camimat[4][4];
+			float mat[4][4], obmat[4][4], imat[4][4], cammat[4][4], camimat[4][4], parmat[4][4];
 
 			where_is_object_mat(scene, scene->camera, cammat);
 
 			BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat);
 
 			invert_m4_m4(camimat, cammat);
+			mul_m4_m4m4(parmat, data->invmat, cammat);
 
 			copy_m4_m4(cammat, scene->camera->obmat);
 			copy_m4_m4(obmat, cob->matrix);
 
 			invert_m4_m4(imat, mat);
 
-			mul_serie_m4(cob->matrix, cammat, imat, camimat, obmat, NULL, NULL, NULL, NULL);
+			mul_serie_m4(cob->matrix, cammat, imat, camimat, parmat, obmat, NULL, NULL, NULL);
 		}
 	}
 }

Modified: branches/soc-2011-tomato/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/intern/math_matrix.c	2011-12-15 16:04:59 UTC (rev 42649)
+++ branches/soc-2011-tomato/source/blender/blenlib/intern/math_matrix.c	2011-12-15 16:09:57 UTC (rev 42650)
@@ -195,8 +195,14 @@
 	m1[2][2]= m2[2][0]*m3[0][2] + m2[2][1]*m3[1][2] + m2[2][2]*m3[2][2]; 
 }
 
-void mul_m4_m4m3(float (*m1)[4], float (*m3)[4], float (*m2)[3])
+void mul_m4_m4m3(float (*m1)[4], float (*m3_)[4], float (*m2_)[3])
 {
+	float m2[3][3], m3[4][4];
+
+	/* copy so it works when m1 is the same pointer as m2 or m3 */
+	copy_m3_m3(m2, m2_);
+	copy_m4_m4(m3, m3_);
+
 	m1[0][0]= m2[0][0]*m3[0][0] + m2[0][1]*m3[1][0] + m2[0][2]*m3[2][0];
 	m1[0][1]= m2[0][0]*m3[0][1] + m2[0][1]*m3[1][1] + m2[0][2]*m3[2][1];
 	m1[0][2]= m2[0][0]*m3[0][2] + m2[0][1]*m3[1][2] + m2[0][2]*m3[2][2];

Modified: branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2011-12-15 16:04:59 UTC (rev 42649)
+++ branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2011-12-15 16:09:57 UTC (rev 42650)
@@ -12689,6 +12689,7 @@
 	/* put compatibility code here until next subversion bump */
 	{
 		MovieClip *clip;
+		Object *ob;
 
 		for (clip= main->movieclip.first; clip; clip= clip->id.next) {
 			MovieTracking *tracking= &clip->tracking;
@@ -12696,6 +12697,23 @@
 			if(tracking->objects.first == NULL)
 				BKE_tracking_new_object(tracking, "Camera");
 		}
+
+		for (ob= main->object.first; ob; ob= ob->id.next) {
+			bConstraint *con;
+			for (con= ob->constraints.first; con; con=con->next) {
+				bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
+
+				if(!cti)
+					continue;
+
+				if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) {
+					bObjectSolverConstraint *data= (bObjectSolverConstraint *)con->data;
+
+					if(data->invmat[3][3]==0.0f)
+						unit_m4(data->invmat);
+				}
+			}
+		}
 	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: branches/soc-2011-tomato/source/blender/editors/object/object_constraint.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/object/object_constraint.c	2011-12-15 16:04:59 UTC (rev 42649)
+++ branches/soc-2011-tomato/source/blender/editors/object/object_constraint.c	2011-12-15 16:09:57 UTC (rev 42650)
@@ -697,25 +697,13 @@
 
 /* ------------- Child-Of Constraint ------------------ */
 
-/* ChildOf Constraint - set inverse callback */
-static int childof_set_inverse_exec (bContext *C, wmOperator *op)
+static void child_get_inverse_matrix (Scene *scene, Object *ob, bConstraint *con, float invmat[4][4])
 {
-	Scene *scene= CTX_data_scene(C);
-	Object *ob = ED_object_active_context(C);
-	bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF);
-	bChildOfConstraint *data= (con) ? (bChildOfConstraint *)con->data : NULL;
 	bConstraint *lastcon = NULL;
 	bPoseChannel *pchan= NULL;
 	
-	/* despite 3 layers of checks, we may still not be able to find a constraint */
-	if (data == NULL) {
-		printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob)? ob->id.name+2 : "<None>");
-		BKE_report(op->reports, RPT_ERROR, "Couldn't find constraint data for Child-Of Set Inverse");
-		return OPERATOR_CANCELLED;
-	}
-	
 	/* nullify inverse matrix first */
-	unit_m4(data->invmat);
+	unit_m4(invmat);
 	
 	/* try to find a pose channel - assume that this is the constraint owner */
 	// TODO: get from context instead?
@@ -761,7 +749,7 @@
 		 */
 		invert_m4_m4(imat, pchan->pose_mat);
 		mul_m4_m4m4(tmat, imat, pmat);
-		invert_m4_m4(data->invmat, tmat);
+		invert_m4_m4(invmat, tmat);
 		
 		/* 5. restore constraints */
 		pchan->constraints.last = lastcon;
@@ -783,9 +771,27 @@
 		
 		/* use what_does_parent to find inverse - just like for normal parenting */
 		what_does_parent(scene, ob, &workob);
-		invert_m4_m4(data->invmat, workob.obmat);
+		invert_m4_m4(invmat, workob.obmat);
 	}
+}
+
+/* ChildOf Constraint - set inverse callback */
+static int childof_set_inverse_exec (bContext *C, wmOperator *op)
+{
+	Scene *scene= CTX_data_scene(C);
+	Object *ob = ED_object_active_context(C);
+	bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF);
+	bChildOfConstraint *data= (con) ? (bChildOfConstraint *)con->data : NULL;
+
+	/* despite 3 layers of checks, we may still not be able to find a constraint */
+	if (data == NULL) {
+		printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob)? ob->id.name+2 : "<None>");
+		BKE_report(op->reports, RPT_ERROR, "Couldn't find constraint data for Child-Of Set Inverse");
+		return OPERATOR_CANCELLED;
+	}
 	
+	child_get_inverse_matrix(scene, ob, con, data->invmat);
+
 	WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
 	
 	return OPERATOR_FINISHED;
@@ -859,6 +865,96 @@
 	edit_constraint_properties(ot);
 }
 
+/* ------------- Object Solver Constraint ------------------ */
+
+static int objectsolver_set_inverse_exec (bContext *C, wmOperator *op)
+{
+	Scene *scene= CTX_data_scene(C);
+	Object *ob = ED_object_active_context(C);
+	bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER);
+	bObjectSolverConstraint *data= (con) ? (bObjectSolverConstraint *)con->data : NULL;
+
+	/* despite 3 layers of checks, we may still not be able to find a constraint */
+	if (data == NULL) {
+		printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob)? ob->id.name+2 : "<None>");
+		BKE_report(op->reports, RPT_ERROR, "Couldn't find constraint data for Child-Of Set Inverse");
+		return OPERATOR_CANCELLED;
+	}
+
+	child_get_inverse_matrix(scene, ob, con, data->invmat);
+
+	WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
+
+	return OPERATOR_FINISHED;
+}
+
+static int objectsolver_set_inverse_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+	if (edit_constraint_invoke_properties(C, op))
+		return objectsolver_set_inverse_exec(C, op);
+	else
+		return OPERATOR_CANCELLED;
+}
+
+void CONSTRAINT_OT_objectsolver_set_inverse (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Set Inverse";
+	ot->idname= "CONSTRAINT_OT_objectsolver_set_inverse";
+	ot->description= "Set inverse correction for ObjectSolver constraint";
+
+	ot->exec= objectsolver_set_inverse_exec;
+	ot->invoke= objectsolver_set_inverse_invoke;
+	ot->poll= edit_constraint_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+	edit_constraint_properties(ot);
+}
+
+static int objectsolver_clear_inverse_exec (bContext *C, wmOperator *op)
+{
+	Object *ob = ED_object_active_context(C);
+	bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER);
+	bObjectSolverConstraint *data= (con) ? (bObjectSolverConstraint *)con->data : NULL;
+
+	if(data==NULL) {
+		BKE_report(op->reports, RPT_ERROR, "Childof constraint not found");
+		return OPERATOR_CANCELLED;
+	}
+
+	/* simply clear the matrix */
+	unit_m4(data->invmat);
+
+	WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
+
+	return OPERATOR_FINISHED;
+}
+
+static int objectsolver_clear_inverse_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+	if (edit_constraint_invoke_properties(C, op))
+		return objectsolver_clear_inverse_exec(C, op);
+	else
+		return OPERATOR_CANCELLED;
+}
+
+void CONSTRAINT_OT_objectsolver_clear_inverse (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Clear Inverse";
+	ot->idname= "CONSTRAINT_OT_objectsolver_clear_inverse";
+	ot->description= "Clear inverse correction for ObjectSolver constraint";
+
+	ot->exec= objectsolver_clear_inverse_exec;
+	ot->invoke= objectsolver_clear_inverse_invoke;
+	ot->poll= edit_constraint_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+	edit_constraint_properties(ot);
+}
+
 /***************************** BUTTONS ****************************/
 
 void ED_object_constraint_set_active(Object *ob, bConstraint *con)

Modified: branches/soc-2011-tomato/source/blender/editors/object/object_intern.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/object/object_intern.h	2011-12-15 16:04:59 UTC (rev 42649)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list