[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11649] trunk/blender/source/blender/ blenkernel/intern: == Constraints - Geometry Targets Improvements ==

Joshua Leung aligorith at gmail.com
Sat Aug 18 06:03:07 CEST 2007


Revision: 11649
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11649
Author:   aligorith
Date:     2007-08-18 06:03:03 +0200 (Sat, 18 Aug 2007)

Log Message:
-----------
== Constraints - Geometry Targets Improvements ==

This commit features fixes/improvements for problems I didn't manage to fix in time for the commit yesterday.

* Now for Meshes, the normals of the vertices in the VertexGroup are averaged and used to find the 'rotation' that needs to be applied. Unfortunately, this does not work with Lattices as they do not have normals.
* Depsgraph should now play nicely with geometry targets. Before, the constrained object's location wasn't being updated after the target's geometry was modified.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenkernel/intern/depsgraph.c

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2007-08-18 02:44:52 UTC (rev 11648)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2007-08-18 04:03:03 UTC (rev 11649)
@@ -1116,6 +1116,8 @@
 {
 	DerivedMesh *dm = (DerivedMesh *)ob->derivedFinal;
 	float vec[3] = {0.0f, 0.0f, 0.0f}, tvec[3];
+	float normal[3] = {0.0f, 0.0f, 0.0f}, plane[3];
+	float imat[3][3], tmat[3][3];
 	int dgroup;
 	
 	/* initialize target matrix using target matrix */
@@ -1131,15 +1133,18 @@
 		int *index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX);
 		int numVerts = dm->getNumVerts(dm);
 		int i, j, count = 0;
-		float co[3];
+		float co[3], nor[3];
 		
+		
 		/* get the average of all verts with that are in the vertex-group */
 		for (i = 0; i < numVerts; i++, index++) {	
 			for (j = 0; j < dvert[i].totweight; j++) {
 				/* does this vertex belong to nominated vertex group? */
 				if (dvert[i].dw[j].def_nr == dgroup) {
 					dm->getVertCo(dm, i, co);
+					dm->getVertNo(dm, i, nor);
 					VecAddf(vec, vec, co);
+					VecAddf(normal, normal, nor);
 					count++;
 					break;
 				}
@@ -1147,12 +1152,38 @@
 			}
 		}
 		
-		/* calculate average, and apply as new location for matrix */
-		if (count > 0)
+		
+		/* calculate averages of normal and coordinates */
+		if (count > 0) {
 			VecMulf(vec, 1.0f / count);
+			VecMulf(normal, 1.0f / count);
+		}
+		
+		
+		/* derive the rotation from the average normal: 
+		 *		- code taken from transform_manipulator.c, 
+		 *			calc_manipulator_stats, V3D_MANIP_NORMAL case
+		 */
+		/*	we need the transpose of the inverse for a normal... */
+		Mat3CpyMat4(imat, ob->obmat);
+		
+		Mat3Inv(tmat, imat);
+		Mat3Transp(tmat);
+		Mat3MulVecfl(tmat, normal);
+
+		Normalize(normal);
+		VECCOPY(plane, tmat[1]);
+		
+		VECCOPY(tmat[2], normal);
+		Crossf(tmat[0], normal, plane);
+		Crossf(tmat[1], tmat[2], tmat[0]);
+		
+		Mat4CpyMat3(mat, tmat);
+		Mat4Ortho(mat);
+		
+		
+		/* apply the average coordinate as the new location */
 		VecMat4MulVecfl(tvec, ob->obmat, vec);
-		
-		/* copy new location to matrix */
 		VECCOPY(mat[3], tvec);
 	}
 }
@@ -1224,25 +1255,19 @@
 	}
 	/* 	Case VERTEXGROUP */
 	/* Current method just takes the average location of all the points in the
-	 * VertexGroup, and uses that as the location value of the target's matrix 
-	 * instead. 
+	 * VertexGroup, and uses that as the location value of the targets. Where 
+	 * possible, the orientation will also be calculated, by calculating an
+	 * 'average' vertex normal, and deriving the rotaation from that.
 	 *
-	 * TODO: figure out a way to find 3-points to define a rotation plane based
-	 *		on the normal of the triangle formed by those three points.
-	 * NOTE: editmode is not currently taken into consideration when doing this
+	 * NOTE: EditMode is not currently supported, and will most likely remain that
+	 *		way as constraints can only really affect things on object/bone level.
 	 */
 	else if (ob->type == OB_MESH) {
-		/* devise a matrix from the vertices in the vertexgroup */
 		contarget_get_mesh_mat(ob, substring, mat);
-		
-		/* make sure it's in the right space for evaluation */
 		constraint_mat_convertspace(ob, NULL, mat, from, to);
 	}
 	else if (ob->type == OB_LATTICE) {
-		/* devise a matrix from the vertices in the vertexgroup */
 		contarget_get_lattice_mat(ob, substring, mat);
-		
-		/* make sure it's in the right space for evaluation */
 		constraint_mat_convertspace(ob, NULL, mat, from, to);
 	}
 	/*	Case BONE */

Modified: trunk/blender/source/blender/blenkernel/intern/depsgraph.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/depsgraph.c	2007-08-18 02:44:52 UTC (rev 11648)
+++ trunk/blender/source/blender/blenkernel/intern/depsgraph.c	2007-08-18 04:03:03 UTC (rev 11649)
@@ -569,7 +569,7 @@
 		}
 	}
 	
-	for (con = ob->constraints.first; con; con=con->next){
+	for (con = ob->constraints.first; con; con=con->next) {
 		if (constraint_has_target(con)) {
 			char *str;
 			Object *obt= get_constraint_target(con, &str);
@@ -578,7 +578,7 @@
 			if(ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO))
 				dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB);
 			else {
-				if(obt->type==OB_ARMATURE && str[0])
+				if(ELEM3(obt->type, OB_ARMATURE, OB_MESH, OB_LATTICE) && str[0])
 					dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB);
 				else
 					dag_add_relation(dag, node2, node, DAG_RL_OB_OB);





More information about the Bf-blender-cvs mailing list