[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29026] trunk/blender: Various constraint code cleanups:

Joshua Leung aligorith at gmail.com
Thu May 27 13:56:32 CEST 2010


Revision: 29026
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29026
Author:   aligorith
Date:     2010-05-27 13:56:31 +0200 (Thu, 27 May 2010)

Log Message:
-----------
Various constraint code cleanups:
1) Fixed some weird formatting introduced during math-lib cleanups, and some other inconsistencies
2) Optimised the Maintain Volume constraint by taking the value calculations out

Copy All Constraints Operators:
* Added one for bones too
* These are now included in the menus
* Removed some weird/extra code copying/changing/bleh the actcol/totcol stuff...

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_view3d.py
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/editors/object/object_constraint.c
    trunk/blender/source/blender/editors/object/object_intern.h
    trunk/blender/source/blender/editors/object/object_ops.c
    trunk/blender/source/blender/makesdna/DNA_constraint_types.h

Modified: trunk/blender/release/scripts/ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/ui/space_view3d.py	2010-05-27 11:25:07 UTC (rev 29025)
+++ trunk/blender/release/scripts/ui/space_view3d.py	2010-05-27 11:56:31 UTC (rev 29026)
@@ -797,6 +797,7 @@
         layout = self.layout
 
         layout.operator("object.constraint_add_with_targets")
+        layout.operator("object.constraints_copy")
         layout.operator("object.constraints_clear")
 
 
@@ -1160,6 +1161,7 @@
         layout = self.layout
 
         layout.operator("pose.constraint_add_with_targets", text="Add (With Targets)...")
+        layout.operator("pose.constraints_copy")
         layout.operator("pose.constraints_clear")
 
 

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-05-27 11:25:07 UTC (rev 29025)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-05-27 11:56:31 UTC (rev 29026)
@@ -820,12 +820,12 @@
 		
 		/* extract components of both matrices */
 		VECCOPY(loc, ct->matrix[3]);
-		mat4_to_eulO( eul, ct->rotOrder,ct->matrix);
-		mat4_to_size( size,ct->matrix);
+		mat4_to_eulO(eul, ct->rotOrder, ct->matrix);
+		mat4_to_size(size, ct->matrix);
 		
 		VECCOPY(loco, invmat[3]);
-		mat4_to_eulO( eulo, cob->rotOrder,invmat);
-		mat4_to_size( sizo,invmat);
+		mat4_to_eulO(eulo, cob->rotOrder, invmat);
+		mat4_to_size(sizo, invmat);
 		
 		/* disable channels not enabled */
 		if (!(data->flag & CHILDOF_LOCX)) loc[0]= loco[0]= 0.0f;
@@ -1017,7 +1017,7 @@
 		float tmat[4][4];
 		
 		/* Get size property, since ob->size is only the object's own relative size, not its global one */
-		mat4_to_size( size,cob->matrix);
+		mat4_to_size(size, cob->matrix);
 		
 		/* Clear the object's rotation */ 	
 		cob->matrix[0][0]=size[0];
@@ -1385,9 +1385,9 @@
 	float size[3];
 	
 	VECCOPY(loc, cob->matrix[3]);
-	mat4_to_size( size,cob->matrix);
+	mat4_to_size(size, cob->matrix);
 	
-	mat4_to_eulO( eul, cob->rotOrder,cob->matrix);
+	mat4_to_eulO(eul, cob->rotOrder, cob->matrix);
 	
 	/* constraint data uses radians internally */
 	
@@ -1638,11 +1638,11 @@
 		float	size[3];
 		
 		VECCOPY(loc, cob->matrix[3]);
-		mat4_to_size( size,cob->matrix);
+		mat4_to_size(size, cob->matrix);
 		
 		/* to allow compatible rotations, must get both rotations in the order of the owner... */
-		mat4_to_eulO( eul, cob->rotOrder,ct->matrix);
-		mat4_to_eulO( obeul, cob->rotOrder,cob->matrix);
+		mat4_to_eulO(eul, cob->rotOrder, ct->matrix);
+		mat4_to_eulO(obeul, cob->rotOrder, cob->matrix);
 		
 		if ((data->flag & ROTLIKE_X)==0)
 			eul[0] = obeul[0];
@@ -1868,29 +1868,29 @@
 {
 	bSameVolumeConstraint *data= con->data;
 
+	float volume = data->volume;
+	float fac = 1.0f;
 	float obsize[3];
-	float volume=data->volume;
 
 	mat4_to_size(obsize, cob->matrix);
-
+	
+	/* calculate normalising scale factor for non-essential values */
+	if (obsize[data->flag] != 0) 
+		fac = sqrt(volume / obsize[data->flag]) / obsize[data->flag];
+	
+	/* apply scaling factor to the channels not being kept */
 	switch (data->flag) {
 		case SAMEVOL_X:
-			if (obsize[0]!=0) {
-				mul_v3_fl(cob->matrix[1], sqrt(volume/obsize[0])/obsize[0]);
-				mul_v3_fl(cob->matrix[2], sqrt(volume/obsize[0])/obsize[0]);
-			}
+			mul_v3_fl(cob->matrix[1], fac);
+			mul_v3_fl(cob->matrix[2], fac);
 			break;
 		case SAMEVOL_Y:
-			if (obsize[1]!=0) {
-				mul_v3_fl(cob->matrix[0], sqrt(volume/obsize[1])/obsize[1]);
-				mul_v3_fl(cob->matrix[2], sqrt(volume/obsize[1])/obsize[1]);
-			}
+			mul_v3_fl(cob->matrix[0], fac);
+			mul_v3_fl(cob->matrix[2], fac);
 			break;
 		case SAMEVOL_Z:
-			if (obsize[2]!=0) {
-				mul_v3_fl(cob->matrix[0], sqrt(volume/obsize[2])/obsize[2]);
-				mul_v3_fl(cob->matrix[1], sqrt(volume/obsize[2])/obsize[2]);
-			}
+			mul_v3_fl(cob->matrix[0], fac);
+			mul_v3_fl(cob->matrix[1], fac);
 			break;
 	}
 }
@@ -2770,7 +2770,7 @@
 		float dist;
 		
 		/* store scaling before destroying obmat */
-		mat4_to_size( size,cob->matrix);
+		mat4_to_size(size, cob->matrix);
 		
 		/* store X orientation before destroying obmat */
 		xx[0] = cob->matrix[0][0];
@@ -3353,7 +3353,7 @@
 				mat4_to_size( dvec,ct->matrix);
 				break;
 			case 1: /* rotation (convert to degrees first) */
-				mat4_to_eulO( dvec, cob->rotOrder,ct->matrix);
+				mat4_to_eulO(dvec, cob->rotOrder, ct->matrix);
 				for (i=0; i<3; i++)
 					dvec[i] = (float)(dvec[i] / M_PI * 180);
 				break;
@@ -3364,8 +3364,8 @@
 		
 		/* extract components of owner's matrix */
 		VECCOPY(loc, cob->matrix[3]);
-		mat4_to_eulO( eul, cob->rotOrder,cob->matrix);
-		mat4_to_size( size,cob->matrix);	
+		mat4_to_eulO(eul, cob->rotOrder, cob->matrix);
+		mat4_to_size(size, cob->matrix);	
 		
 		/* determine where in range current transforms lie */
 		if (data->expo) {
@@ -3485,73 +3485,73 @@
 		float co[3] = {0.0f, 0.0f, 0.0f};
 		float no[3] = {0.0f, 0.0f, 0.0f};
 		float dist;
-
+		
 		SpaceTransform transform;
 		DerivedMesh *target = object_get_derived_final(cob->scene, ct->tar, CD_MASK_BAREMESH);
 		BVHTreeRayHit hit;
 		BVHTreeNearest nearest;
-
+		
 		BVHTreeFromMesh treeData;
-		memset( &treeData, 0, sizeof(treeData) );
-
+		memset(&treeData, 0, sizeof(treeData));
+		
 		nearest.index = -1;
 		nearest.dist = FLT_MAX;
-
+		
 		hit.index = -1;
 		hit.dist = 100000.0f;  //TODO should use FLT_MAX.. but normal projection doenst yet supports it
-
+		
 		unit_m4(ct->matrix);
-
+		
 		if(target != NULL)
 		{
 			space_transform_from_matrixs(&transform, cob->matrix, ct->tar->obmat);
-
+			
 			switch(scon->shrinkType)
 			{
 				case MOD_SHRINKWRAP_NEAREST_SURFACE:
 				case MOD_SHRINKWRAP_NEAREST_VERTEX:
-
+					
 					if(scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX)
 						bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6);
 					else
 						bvhtree_from_mesh_faces(&treeData, target, 0.0, 2, 6);
-
+					
 					if(treeData.tree == NULL)
 					{
 						fail = TRUE;
 						break;
 					}
-
+					
 					space_transform_apply(&transform, co);
-
+					
 					BLI_bvhtree_find_nearest(treeData.tree, co, &nearest, treeData.nearest_callback, &treeData);
 					
 					dist = len_v3v3(co, nearest.co);
 					interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist)/dist);	/* linear interpolation */
 					space_transform_invert(&transform, co);
 				break;
-
+				
 				case MOD_SHRINKWRAP_PROJECT:
 					if(scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) no[0] = 1.0f;
 					if(scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) no[1] = 1.0f;
 					if(scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS) no[2] = 1.0f;
-
+					
 					if(INPR(no,no) < FLT_EPSILON)
 					{
 						fail = TRUE;
 						break;
 					}
-
+					
 					normalize_v3(no);
-
-
+					
+					
 					bvhtree_from_mesh_faces(&treeData, target, scon->dist, 4, 6);
 					if(treeData.tree == NULL)
 					{
 						fail = TRUE;
 						break;
 					}
-
+					
 					if(normal_projection_project_vertex(0, co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) == FALSE)
 					{
 						fail = TRUE;
@@ -3560,17 +3560,17 @@
 					VECCOPY(co, hit.co);
 				break;
 			}
-
+			
 			free_bvhtree_from_mesh(&treeData);
-
+			
 			target->release(target);
-
+			
 			if(fail == TRUE)
 			{
 				/* Don't move the point */
 				co[0] = co[1] = co[2] = 0.0f;
 			}
-
+			
 			/* co is in local object coordinates, change it to global and update target position */
 			mul_m4_v3(cob->matrix, co);
 			VECCOPY(ct->matrix[3], co);
@@ -3704,7 +3704,7 @@
 		/* construct rotation matrix from the axis-angle rotation found above 
 		 *	- this call takes care to make sure that the axis provided is a unit vector first
 		 */
-		axis_angle_to_mat3( rmat,raxis, rangle);
+		axis_angle_to_mat3(rmat, raxis, rangle);
 		
 		/* rotate the owner in the way defined by this rotation matrix, then reapply the location since
 		 * we may have destroyed that in the process of multiplying the matrix
@@ -4262,9 +4262,9 @@
 			/* perform custom copying operations if needed */
 			if (cti->copy_data)
 				cti->copy_data(con, srccon);
-
+			
 			/* for proxies we dont want to make extern */
-			if(do_extern) {
+			if (do_extern) {
 				/* go over used ID-links for this constraint to ensure that they are valid for proxies */
 				if (cti->id_looper)
 					cti->id_looper(con, con_extern_cb, NULL);

Modified: trunk/blender/source/blender/editors/object/object_constraint.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_constraint.c	2010-05-27 11:25:07 UTC (rev 29025)
+++ trunk/blender/source/blender/editors/object/object_constraint.c	2010-05-27 11:56:31 UTC (rev 29026)
@@ -133,6 +133,7 @@
 {
 	return constraints_get_active(get_active_constraints(ob));
 }
+
 /* -------------- Constraint Management (Add New, Remove, Rename) -------------------- */
 /* ------------- PyConstraints ------------------ */
 
@@ -435,15 +436,16 @@
 
 void object_test_constraints (Object *owner)
 {
-	if(owner->constraints.first)
+	if (owner->constraints.first)
 		test_constraints(owner, NULL);
-
+	
 	if (owner->type==OB_ARMATURE && owner->pose) {
 		bPoseChannel *pchan;
-
-		for (pchan= owner->pose->chanbase.first; pchan; pchan= pchan->next)
-			if(pchan->constraints.first)
+		
+		for (pchan= owner->pose->chanbase.first; pchan; pchan= pchan->next) {
+			if (pchan->constraints.first)
 				test_constraints(owner, pchan);
+		}
 	}
 }
 
@@ -454,9 +456,9 @@
 #define EDIT_CONSTRAINT_OWNER_BONE		1
 
 static EnumPropertyItem constraint_owner_items[] = {
-{EDIT_CONSTRAINT_OWNER_OBJECT, "OBJECT", 0, "Object", "Edit a constraint on the active object"},
-{EDIT_CONSTRAINT_OWNER_BONE, "BONE", 0, "Bone", "Edit a constraint on the active bone"},
-{0, NULL, 0, NULL, NULL}};
+	{EDIT_CONSTRAINT_OWNER_OBJECT, "OBJECT", 0, "Object", "Edit a constraint on the active object"},
+	{EDIT_CONSTRAINT_OWNER_BONE, "BONE", 0, "Bone", "Edit a constraint on the active bone"},
+	{0, NULL, 0, NULL, NULL}};
 
 
 static int edit_constraint_poll_generic(bContext *C, StructRNA *rna_type)
@@ -519,7 +521,8 @@
 	
 	if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) {
 		list = &ob->constraints;
-	} else if (owner == EDIT_CONSTRAINT_OWNER_BONE) {
+	} 
+	else if (owner == EDIT_CONSTRAINT_OWNER_BONE) {
 		bPoseChannel *pchan= get_active_posechannel(ob);
 		if (pchan)
 			list = &pchan->constraints;
@@ -529,7 +532,7 @@
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list