[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11273] trunk/blender/source/blender: == Constraints System ==

Joshua Leung aligorith at gmail.com
Sun Jul 15 05:35:38 CEST 2007


Revision: 11273
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11273
Author:   aligorith
Date:     2007-07-15 05:35:37 +0200 (Sun, 15 Jul 2007)

Log Message:
-----------
== Constraints System ==

After just over a week of coding, I've finished doing a major refactor/cleanup of the constraints code. In the process, quite a few old kludges and ugly hacks have been removed. Also, some new features which will greatly benefit riggers have been implemented.

=== What's New ===
* The long-awaited ``ChildOf Constraint'':
This allows you to animate parent influences, and choose which transformation channels the parent affects the child on (i.e. no translation/rotation/scaling). It should be noted that disabling some combinations may not totally work as expected. Also, the 'Set Inverse' and 'Clear Inverse' buttons at the bottom of this constraint's panel set/clear the inverse correction for the parent's effects. Use these to make the owner not stick/be glued to the parent.
* Constraint/Target Evaluation Spaces:
In some constraints, there are now 1-2 combo boxes at the bottom of their panel, which allows you to pick which `co-ordinate space' they are evaluated in. This is much more flexible than the old 'local' options for bones only were.
* Action Constraint - Loc/Rot/Size Inputs
The Action Constraint can finally use the target's location/rotation/scaling transforms as input, to control the owner of the constraint. This should work much more reliably than it used to. The target evaluation should now also be more accurate due to the new space conversion stuff.
* Transform - No longer in Crazy Space (TM)
Transforming objects/bones with constraints applied should no longer occur in Crazy Space. They are now correctly inverse-corrected. This also applies to old-style object tracking.

=== General Code Changes ===
* solve_constraints is now in constraints.c. I've removed the old `blend consecutive constraints of same type' junk, which made the code more complex than it needed to be.
* evaluate_constraint is now only passed the constraint, and two matrices. A few unused variables have been removed from here.
* A tempolary struct, bConstraintOb, is now passed to solve_constraints instead of relying on an ugly, static workobject in some cases. This works much better.
* Made the formatting of constraint code consistent
* There's a version patch for older files so that constraint settings are correctly converted to the new system. This is currently done for MajorVersion <= 244, and SubVersion < 3. I've bumped up the subversion to 3 for this purpose. However, with the imminent 2.45 release, this may need to be adjusted accordingly.
* LocEulSizeToMat4 and LocQuatSizeToMat4 now work in the order Size, Rot, Location. I've also added a few other math functions.
* Mat4BlendMat4 is now in arithb. I've modified it's method slightly, to use other arithb functions, instead of its crazy blending scheme. 
* Moved some of the RigidBodyJoint constraint's code out of blenkernel, and into src. It shouldn't be setting its target in its data initialisation function based + accessing scene stuff where it was doing so.

=== Future Work ===
* Geometry to act as targets for constraints. A space has been reserved for this already. 
* Tidy up UI buttons of constraints

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/BKE_constraint.h
    trunk/blender/source/blender/blenkernel/BKE_object.h
    trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
    trunk/blender/source/blender/blenkernel/intern/action.c
    trunk/blender/source/blender/blenkernel/intern/armature.c
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenlib/BLI_arithb.h
    trunk/blender/source/blender/blenlib/intern/arithb.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/makesdna/DNA_action_types.h
    trunk/blender/source/blender/makesdna/DNA_constraint_types.h
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/python/BPY_extern.h
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/blender/python/api2_2x/Constraint.c
    trunk/blender/source/blender/src/buttons_object.c
    trunk/blender/source/blender/src/drawobject.c
    trunk/blender/source/blender/src/editconstraint.c
    trunk/blender/source/blender/src/editobject.c
    trunk/blender/source/blender/src/transform_conversions.c

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2007-07-14 06:47:10 UTC (rev 11272)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2007-07-15 03:35:37 UTC (rev 11273)
@@ -44,7 +44,7 @@
 struct MemFile;
 
 #define BLENDER_VERSION			244
-#define BLENDER_SUBVERSION		2
+#define BLENDER_SUBVERSION		3
 
 #define BLENDER_MINVERSION		240
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_constraint.h	2007-07-14 06:47:10 UTC (rev 11272)
+++ trunk/blender/source/blender/blenkernel/BKE_constraint.h	2007-07-15 03:35:37 UTC (rev 11273)
@@ -33,43 +33,66 @@
 #ifndef BKE_CONSTRAINT_H
 #define BKE_CONSTRAINT_H
 
+
 struct bConstraint;
+struct ListBase;
 struct Object;
-struct ListBase;
 struct bConstraintChannel;
+struct bPoseChannel;
 struct bAction;
 struct bArmature;
 
-/* Function prototypes */
+/* ---------------------------------------------------------------------------- */
+
+/* Constraint target/owner types */
+#define TARGET_OBJECT			1	/*	string is ""				*/
+#define TARGET_BONE				2	/*	string is bone-name		*/
+#define TARGET_VERT				3	/*	string is vertex-group name 	*/
+#define TARGET_CV				4 	/* 	string is vertex-group name - is not available until curves get vgroups */
+
+/* ---------------------------------------------------------------------------- */
+
+/* special struct for use in constraint evaluation */
+typedef struct bConstraintOb {
+	struct Object *ob;			/* if pchan, then armature that it comes from, otherwise constraint owner */
+	struct bPoseChannel *pchan;	/* pose channel that owns the constraints being evaluated */
+	
+	float matrix[4][4];			/* matrix where constraints are accumulated + solved */
+	float startmat[4][4];		/* original matrix (before constraint solving) */
+	
+	short type;					/* type of owner  */
+} bConstraintOb;
+
+/* ---------------------------------------------------------------------------- */
+
+/* Constraint function prototypes */
 void unique_constraint_name (struct bConstraint *con, struct ListBase *list);
 void *new_constraint_data (short type);
-void evaluate_constraint (struct bConstraint *constraint, struct Object *ob, short ownertype, void *ownerdata, float targetmat[][4]);
 void free_constraints (struct ListBase *conlist);
 void copy_constraints (struct ListBase *dst, struct ListBase *src);
-void copy_constraint_channels (ListBase *dst, ListBase *src);
-void clone_constraint_channels (struct ListBase *dst, struct ListBase *src);
 void relink_constraints (struct ListBase *list);
 void free_constraint_data (struct bConstraint *con);
 
-/* channels */
+/* Constraint Channel function prototypes */
 struct bConstraintChannel *get_constraint_channel (ListBase *list, const char *name);
 struct bConstraintChannel *verify_constraint_channel (ListBase *list, const char *name);
+void do_constraint_channels (struct ListBase *conbase, struct ListBase *chanbase, float ctime);
+void copy_constraint_channels (ListBase *dst, ListBase *src);
+void clone_constraint_channels (struct ListBase *dst, struct ListBase *src);
 void free_constraint_channels (ListBase *chanbase);
 
-/* Gemeric functions */
-void do_constraint_channels (struct ListBase *conbase, struct ListBase *chanbase, float ctime);
-short get_constraint_target_matrix (struct bConstraint *con, short ownertype, void *ownerdata, float mat[][4], float size[3], float time);
+/* Target function prototypes  */
 char constraint_has_target (struct bConstraint *con);
 struct Object *get_constraint_target(struct bConstraint *con, char **subtarget);
 void set_constraint_target(struct bConstraint *con, struct Object *ob, char *subtarget);
 
+/* Constraint Evaluation function prototypes */
+struct bConstraintOb *constraints_make_evalob (struct Object *ob, void *subdata, short datatype);
+void constraints_clear_evalob(struct bConstraintOb *cob);
 
-/* Constraint target/owner types */
-#define TARGET_OBJECT			1	//	string is ""
-#define TARGET_BONE				2	//	string is bone-name
-#define TARGET_VERT				3	//	string is "VE:#" 
-#define TARGET_FACE				4	//	string is "FA:#" 
-#define TARGET_CV				5	//	string is "CV:#"
+short get_constraint_target_matrix (struct bConstraint *con, short ownertype, void *ownerdata, float mat[][4], float time);
+void solve_constraints (struct ListBase *conlist, struct bConstraintOb *cob, float ctime);
 
+
 #endif
 

Modified: trunk/blender/source/blender/blenkernel/BKE_object.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_object.h	2007-07-14 06:47:10 UTC (rev 11272)
+++ trunk/blender/source/blender/blenkernel/BKE_object.h	2007-07-15 03:35:37 UTC (rev 11273)
@@ -104,7 +104,6 @@
 void minmax_object(struct Object *ob, float *min, float *max);
 void minmax_object_duplis(struct Object *ob, float *min, float *max);
 void solve_tracking (struct Object *ob, float targetmat[][4]);
-void solve_constraints (struct Object *ob, short obtype, void *obdata, float ctime);
 
 void object_handle_update(struct Object *ob);
 

Modified: trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
===================================================================
--- trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2007-07-14 06:47:10 UTC (rev 11272)
+++ trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2007-07-15 03:35:37 UTC (rev 11273)
@@ -126,7 +126,7 @@
 }
 
 /* constraint.c */
-void BPY_pyconstraint_eval(struct bPythonConstraint *con, float obmat[][4], short ownertype, void *ownerdata, float targetmat[][4])
+void BPY_pyconstraint_eval(struct bPythonConstraint *con, float ownermat[][4], float targetmat[][4])
 {
 }
 int BPY_pyconstraint_targets(struct bPythonConstraint *con, float targetmat[][4])

Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c	2007-07-14 06:47:10 UTC (rev 11272)
+++ trunk/blender/source/blender/blenkernel/intern/action.c	2007-07-15 03:35:37 UTC (rev 11273)
@@ -225,12 +225,12 @@
 {
 	bPoseChannel *chan;
 	
-	if (!pose){
+	if (!pose) {
 		return NULL;
 	}
 	
 	/*      See if this channel exists */
-	for (chan=pose->chanbase.first; chan; chan=chan->next){
+	for (chan=pose->chanbase.first; chan; chan=chan->next) {
 		if (!strcmp (name, chan->name))
 			return chan;
 	}
@@ -239,7 +239,7 @@
 	chan = MEM_callocN(sizeof(bPoseChannel), "verifyPoseChannel");
 	
 	strncpy (chan->name, name, 31);
-	/* init vars to prevent mat errors */
+	/* init vars to prevent math errors */
 	chan->quat[0] = 1.0F;
 	chan->size[0] = chan->size[1] = chan->size[2] = 1.0F;
 	
@@ -247,6 +247,8 @@
 	chan->limitmax[0]= chan->limitmax[1]= chan->limitmax[2]= 180.0f;
 	chan->stiffness[0]= chan->stiffness[1]= chan->stiffness[2]= 0.0f;
 	
+	Mat4One(chan->constinv);
+	
 	BLI_addtail (&pose->chanbase, chan);
 	
 	return chan;

Modified: trunk/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/armature.c	2007-07-14 06:47:10 UTC (rev 11272)
+++ trunk/blender/source/blender/blenkernel/intern/armature.c	2007-07-15 03:35:37 UTC (rev 11273)
@@ -1321,7 +1321,7 @@
 	float goalrot[3][3], goalpos[3];
 	float rootmat[4][4], imat[4][4];
 	float goal[4][4], goalinv[4][4];
-	float size[3], irest_basis[3][3], full_basis[3][3];
+	float irest_basis[3][3], full_basis[3][3];
 	float end_pose[4][4], world_pose[4][4];
 	float length, basis[3][3], rest_basis[3][3], start[3], *ikstretch=NULL;
 	int a, flag, hasstretch=0;
@@ -1444,7 +1444,7 @@
 		data= (bKinematicConstraint*)target->con->data;
 
 		/* 1.0=ctime, we pass on object for auto-ik */
-		get_constraint_target_matrix(target->con, TARGET_BONE, ob, rootmat, size, 1.0);
+		get_constraint_target_matrix(target->con, TARGET_BONE, ob, rootmat, 1.0);
 
 		/* and set and transform goal */
 		Mat4MulMat4(goal, rootmat, goalinv);
@@ -1603,211 +1603,7 @@
 	pchan->flag |= POSE_DONE;
 }
 
-static void do_local_constraint(bPoseChannel *pchan, bConstraint *con)
-{
-	switch(con->type) {
-		case CONSTRAINT_TYPE_LOCLIKE:
-		{
-			bLocateLikeConstraint *data= con->data;
-			float fac= con->enforce;
-			
-			if(data->tar && data->subtarget[0]) {
-				bPoseChannel *pchant= get_pose_channel(data->tar->pose, data->subtarget);
-				if(pchant) {
-					float loc[3];
-					
-					/* copy location of tip of bone? */
-					if (data->flag & LOCLIKE_TIP) {
-						float mat[4][4], tmat[4][4];
-						
-						Mat4One(tmat);
-						VECCOPY(tmat[3], pchant->pose_tail);
-						
-						armature_mat_pose_to_delta(mat, tmat, pchant->bone->arm_mat);
-						VECCOPY(loc, mat[3]);
-					}
-					else
-						VECCOPY(loc, pchant->loc);
-					
-					/* do offsets? */
-					if (data->flag & LOCLIKE_OFFSET)
-						VecAddf(loc, loc, pchan->loc);
-					
-					if (data->flag & LOCLIKE_X)
-						pchan->loc[0]= FloatLerpf(loc[0], pchan->loc[0], fac);
-					if (data->flag & LOCLIKE_Y)
-						pchan->loc[1]= FloatLerpf(loc[1], pchan->loc[1], fac);
-					if (data->flag & LOCLIKE_Z)
-						pchan->loc[2]= FloatLerpf(loc[2], pchan->loc[2], fac);
-					if (data->flag & LOCLIKE_X_INVERT)
-						pchan->loc[0]= FloatLerpf(pchant->loc[0], pchan->loc[0], -fac);
-					if (data->flag & LOCLIKE_Y_INVERT)
-						pchan->loc[1]= FloatLerpf(pchant->loc[1], pchan->loc[1], -fac);
-					if (data->flag & LOCLIKE_Z_INVERT)
-						pchan->loc[2]= FloatLerpf(pchant->loc[2], pchan->loc[2], -fac);
-				}
-			}
-		}
-			break;
-		case CONSTRAINT_TYPE_ROTLIKE:
-		{
-			bRotateLikeConstraint *data= con->data;
-			if(data->tar && data->subtarget[0]) {
-				bPoseChannel *pchant= get_pose_channel(data->tar->pose, data->subtarget);
-				if(pchant) {
-					if(data->flag != (ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z)) {
-						float eul[3], eult[3], euln[3];
-						float fac= con->enforce;
-						
-						QuatToEul(pchan->quat, eul);
-						QuatToEul(pchant->quat, eult);
-						VECCOPY(euln, eul);
-						
-						if(data->flag & ROTLIKE_X) euln[0]= FloatLerpf(eult[0], eul[0], fac); 
-						if(data->flag & ROTLIKE_Y) euln[1]= FloatLerpf(eult[1], eul[1], fac);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list