[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36862] branches/soc-2011-pepper: = Limit Distance Constraint - 'For Transform' Option =

Joshua Leung aligorith at gmail.com
Tue May 24 14:12:13 CEST 2011


Revision: 36862
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36862
Author:   aligorith
Date:     2011-05-24 12:12:12 +0000 (Tue, 24 May 2011)
Log Message:
-----------
= Limit Distance Constraint - 'For Transform' Option =

The Limit Distance Constraint now has a "For Transform" option just
like all the other Limit constraints. This option controls whether the
constraint gets applied to interactive transforms in the 3D View too,
preventing controllers from getting large values without the animator
knowing.


Additional code changes:
* Split code to get constraint targets and grab their matrices for
solving out to a separate helper function:
get_constraint_targets_for_solving()
* Fixed a bug where "found constraint ...." prints would appear in the
console. Looks like some warning print that was forgotten

TODO:
* While coding this, I noticed potential division by zero bugs with
the Limit Distance constraint. Looking into these after this commit.

Modified Paths:
--------------
    branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_object_constraint.py
    branches/soc-2011-pepper/source/blender/blenkernel/BKE_constraint.h
    branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c
    branches/soc-2011-pepper/source/blender/editors/object/object_constraint.c
    branches/soc-2011-pepper/source/blender/editors/transform/transform.c
    branches/soc-2011-pepper/source/blender/makesdna/DNA_constraint_types.h
    branches/soc-2011-pepper/source/blender/makesrna/intern/rna_constraint.c

Modified: branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_object_constraint.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_object_constraint.py	2011-05-24 11:20:33 UTC (rev 36861)
+++ branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_object_constraint.py	2011-05-24 12:12:12 UTC (rev 36862)
@@ -476,6 +476,11 @@
         row.label(text="Clamp Region:")
         row.prop(con, "limit_mode", text="")
 
+        row = layout.row()
+        row.prop(con, "use_transform_limit")
+        row.label()
+
+
     def STRETCH_TO(self, context, layout, con):
         self.target_template(layout, con)
 

Modified: branches/soc-2011-pepper/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- branches/soc-2011-pepper/source/blender/blenkernel/BKE_constraint.h	2011-05-24 11:20:33 UTC (rev 36861)
+++ branches/soc-2011-pepper/source/blender/blenkernel/BKE_constraint.h	2011-05-24 12:12:12 UTC (rev 36862)
@@ -154,6 +154,7 @@
 void constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, float mat[][4], short from, short to);
 
 void get_constraint_target_matrix(struct Scene *scene, struct bConstraint *con, int n, short ownertype, void *ownerdata, float mat[][4], float ctime);
+void get_constraint_targets_for_solving(struct bConstraint *con, struct bConstraintOb *ob, struct ListBase *targets, float ctime);
 void solve_constraints(struct ListBase *conlist, struct bConstraintOb *cob, float ctime);
 
 #ifdef __cplusplus

Modified: branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c	2011-05-24 11:20:33 UTC (rev 36861)
+++ branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c	2011-05-24 12:12:12 UTC (rev 36862)
@@ -2642,6 +2642,8 @@
 		/* set distance (flag is only set when user demands it) */
 		if (data->dist == 0)
 			data->dist= dist;
+			
+		// FIXME: dist may be 0!
 		
 		/* check if we're which way to clamp from, and calculate interpolation factor (if needed) */
 		if (data->mode == LIMITDIST_OUTSIDE) {
@@ -4427,6 +4429,34 @@
 		unit_m4(mat);
 	}
 }
+
+/* Get the list of targets required for solving a constraint */
+void get_constraint_targets_for_solving (bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime)
+{
+	bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
+	
+	if (cti && cti->get_constraint_targets) {
+		bConstraintTarget *ct;
+		
+		/* get targets 
+		 * 	- constraints should use ct->matrix, not directly accessing values
+		 *	- ct->matrix members have not yet been calculated here! 
+		 */
+		cti->get_constraint_targets(con, targets);
+		
+		/* set matrices 
+		 * 	- calculate if possible, otherwise just initialise as identity matrix 
+		 */
+		if (cti->get_target_matrix) {
+			for (ct= targets->first; ct; ct= ct->next) 
+				cti->get_target_matrix(con, cob, ct, ctime);
+		}
+		else {
+			for (ct= targets->first; ct; ct= ct->next)
+				unit_m4(ct->matrix);
+		}
+	}
+}
  
 /* ---------- Evaluation ----------- */
 
@@ -4471,27 +4501,7 @@
 		constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace);
 		
 		/* prepare targets for constraint solving */
-		if (cti->get_constraint_targets) {
-			bConstraintTarget *ct;
-			
-			/* get targets 
-			 * 	- constraints should use ct->matrix, not directly accessing values
-			 *	- ct->matrix members have not yet been calculated here! 
-			 */
-			cti->get_constraint_targets(con, &targets);
-			
-			/* set matrices 
-			 * 	- calculate if possible, otherwise just initialise as identity matrix 
-			 */
-			if (cti->get_target_matrix) {
-				for (ct= targets.first; ct; ct= ct->next) 
-					cti->get_target_matrix(con, cob, ct, ctime);
-			}
-			else {
-				for (ct= targets.first; ct; ct= ct->next)
-					unit_m4(ct->matrix);
-			}
-		}
+		get_constraint_targets_for_solving(con, cob, &targets, ctime);
 		
 		/* Solve the constraint and put result in cob->matrix */
 		cti->evaluate_constraint(con, cob, &targets);

Modified: branches/soc-2011-pepper/source/blender/editors/object/object_constraint.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/object/object_constraint.c	2011-05-24 11:20:33 UTC (rev 36861)
+++ branches/soc-2011-pepper/source/blender/editors/object/object_constraint.c	2011-05-24 12:12:12 UTC (rev 36862)
@@ -567,7 +567,8 @@
 	}
 	
 	con = constraints_findByName(list, constraint_name);
-	printf("constraint found = %p, %s\n", (void *)con, (con)?con->name:"<Not found>");
+	//if (G.f & G_DEBUG)
+	//printf("constraint found = %p, %s\n", (void *)con, (con)?con->name:"<Not found>");
 
 	if (con && (type != 0) && (con->type != type))
 		con = NULL;

Modified: branches/soc-2011-pepper/source/blender/editors/transform/transform.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/transform/transform.c	2011-05-24 11:20:33 UTC (rev 36861)
+++ branches/soc-2011-pepper/source/blender/editors/transform/transform.c	2011-05-24 12:12:12 UTC (rev 36862)
@@ -1982,12 +1982,15 @@
 
 /* ******************* TRANSFORM LIMITS ********************** */
 
-static void constraintTransLim(TransInfo *UNUSED(t), TransData *td)
+static void constraintTransLim(TransInfo *t, TransData *td)
 {
 	if (td->con) {
-		bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
+		bConstraintTypeInfo *ctiLoc= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
+		bConstraintTypeInfo *ctiDist= get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT);
+		
 		bConstraintOb cob= {NULL};
 		bConstraint *con;
+		float ctime = (float)(t->scene->r.cfra);
 		
 		/* Make a temporary bConstraintOb for using these limit constraints
 		 * 	- they only care that cob->matrix is correctly set ;-)
@@ -1998,6 +2001,8 @@
 		
 		/* Evaluate valid constraints */
 		for (con= td->con; con; con= con->next) {
+			bConstraintTypeInfo *cti = NULL;
+			ListBase targets = {NULL, NULL};
 			float tmat[4][4];
 			
 			/* only consider constraint if enabled */
@@ -2010,7 +2015,17 @@
 				
 				if ((data->flag2 & LIMIT_TRANSFORM)==0)
 					continue;
+				cti = ctiLoc;
+			}
+			else if (con->type == CONSTRAINT_TYPE_DISTLIMIT) {
+				bDistLimitConstraint *data= con->data;
 				
+				if ((data->flag & LIMITDIST_TRANSFORM)==0)
+					continue;
+				cti = ctiDist;
+			}
+			
+			if (cti) {
 				/* do space conversions */
 				if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
 					/* just multiply by td->mtx (this should be ok) */
@@ -2022,8 +2037,11 @@
 					continue;
 				}
 				
+				/* get constraint targets if needed */
+				get_constraint_targets_for_solving(con, &cob, &targets, ctime);
+				
 				/* do constraint */
-				cti->evaluate_constraint(con, &cob, NULL);
+				cti->evaluate_constraint(con, &cob, &targets);
 				
 				/* convert spaces again */
 				if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
@@ -2031,6 +2049,9 @@
 					copy_m4_m4(tmat, cob.matrix);
 					mul_m4_m3m4(cob.matrix, td->smtx, tmat);
 				}
+				
+				/* free targets list */
+				BLI_freelistN(&targets);
 			}
 		}
 		

Modified: branches/soc-2011-pepper/source/blender/makesdna/DNA_constraint_types.h
===================================================================
--- branches/soc-2011-pepper/source/blender/makesdna/DNA_constraint_types.h	2011-05-24 11:20:33 UTC (rev 36861)
+++ branches/soc-2011-pepper/source/blender/makesdna/DNA_constraint_types.h	2011-05-24 12:12:12 UTC (rev 36862)
@@ -677,7 +677,10 @@
 /* distance limit constraint */
 	/* bDistLimitConstraint->flag */
 typedef enum eDistLimit_Flag {
-	LIMITDIST_USESOFT	= (1<<0)
+	/* "soft" cushion effect when reaching the limit sphere */ // NOT IMPLEMENTED!
+	LIMITDIST_USESOFT	= (1<<0),
+	/* as for all Limit constraints - allow to be used during transform? */
+	LIMITDIST_TRANSFORM = (1<<1)
 } eDistLimit_Flag;
 
 	/* bDistLimitConstraint->mode */

Modified: branches/soc-2011-pepper/source/blender/makesrna/intern/rna_constraint.c
===================================================================
--- branches/soc-2011-pepper/source/blender/makesrna/intern/rna_constraint.c	2011-05-24 11:20:33 UTC (rev 36861)
+++ branches/soc-2011-pepper/source/blender/makesrna/intern/rna_constraint.c	2011-05-24 12:12:12 UTC (rev 36862)
@@ -1787,6 +1787,11 @@
 	RNA_def_property_enum_items(prop, constraint_distance_items);
 	RNA_def_property_ui_text(prop, "Limit Mode", "Distances in relation to sphere of influence to allow");
 	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
+	
+	prop= RNA_def_property(srna, "use_transform_limit", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", LIMITDIST_TRANSFORM);
+	RNA_def_property_ui_text(prop, "For Transform", "Transforms are affected by this constraint as well");
+	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
 }
 
 static void rna_def_constraint_shrinkwrap(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list