[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23060] branches/blender2.5/blender: 2. 5 - FollowPath Constraint + File Loading Bugfix

Joshua Leung aligorith at gmail.com
Tue Sep 8 11:41:16 CEST 2009


Revision: 23060
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23060
Author:   aligorith
Date:     2009-09-08 11:41:15 +0200 (Tue, 08 Sep 2009)

Log Message:
-----------
2.5 - FollowPath Constraint + File Loading Bugfix

* Added a new option ('Fixed Position') for Follow Path constraint which allows you to constrain an object/bone to some fixed position along the curve. Unlike the default mode of operation, this doesn't depend on time unless you explicitly animate the offset percentage parameter associated with this.

* Made old (pre 2.5) files saved with armatures in pose mode load in pose mode again.

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_object_constraint.py
    branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_constraint_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c

Modified: branches/blender2.5/blender/release/ui/buttons_object_constraint.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_object_constraint.py	2009-09-08 08:15:56 UTC (rev 23059)
+++ branches/blender2.5/blender/release/ui/buttons_object_constraint.py	2009-09-08 09:41:15 UTC (rev 23060)
@@ -121,10 +121,18 @@
 	def FOLLOW_PATH(self, layout, con):
 		self.target_template(layout, con)
 		
-		row = layout.row()
-		row.itemR(con, "curve_follow")
-		row.itemR(con, "offset")
+		split = layout.split()
 		
+		col = split.column()
+		col.itemR(con, "curve_follow")
+		
+		col = split.column()
+		col.itemR(con, "fixed_position")
+		if con.fixed_position:
+			col.itemR(con, "offset_percentage", text="Offset")
+		else:
+			col.itemR(con, "offset")
+		
 		row = layout.row()
 		row.itemL(text="Forward:")
 		row.itemR(con, "forward", expand=True)

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-09-08 08:15:56 UTC (rev 23059)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-09-08 09:41:15 UTC (rev 23060)
@@ -1178,17 +1178,26 @@
 			makeDispListCurveTypes(cob->scene, ct->tar, 0);
 		
 		if (cu->path && cu->path->data) {
-			curvetime= bsystem_time(cob->scene, ct->tar, (float)ctime, 0.0) - data->offset;
-			
-#if 0 // XXX old animation system
-			if (calc_ipo_spec(cu->ipo, CU_SPEED, &curvetime)==0) {
-				curvetime /= cu->pathlen;
+			if ((data->followflag & FOLLOWPATH_STATIC) == 0) { 
+				/* animated position along curve depending on time */
+				curvetime= bsystem_time(cob->scene, ct->tar, ctime, 0.0) - data->offset;
+				
+				/* ctime is now a proper var setting of Curve which gets set by Animato like any other var that's animated,
+				 * but this will only work if it actually is animated... 
+				 *
+				 * we firstly calculate the modulus of cu->ctime/cu->pathlen to clamp ctime within the 0.0 to 1.0 times pathlen
+				 * range, then divide this (the modulus) by pathlen to get a value between 0.0 and 1.0
+				 */
+				curvetime= fmod(cu->ctime, cu->pathlen) / cu->pathlen;
 				CLAMP(curvetime, 0.0, 1.0);
 			}
-#endif // XXX old animation system
+			else {
+				/* fixed position along curve */
+				curvetime= data->offset; // XXX might need a more sensible value
+			}
 			
 			if ( where_on_path(ct->tar, curvetime, vec, dir) ) {
-				if (data->followflag) {
+				if (data->followflag & FOLLOWPATH_FOLLOW) {
 					vectoquat(dir, (short) data->trackflag, (short) data->upflag, quat);
 					
 					Normalize(dir);

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-09-08 08:15:56 UTC (rev 23059)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-09-08 09:41:15 UTC (rev 23060)
@@ -9596,6 +9596,7 @@
 
 	if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 2)) {
 		Scene *sce;
+		Object *ob;
 
 		for(sce = main->scene.first; sce; sce = sce->id.next) {
 			if(fd->fileflags & G_FILE_ENABLE_ALL_FRAMES)
@@ -9628,6 +9629,11 @@
 
 			sce->gm.flag |= GAME_DISPLAY_LISTS;
 		}
+		
+		for(ob = main->object.first; ob; ob = ob->id.next) {
+			if(ob->flag & 8192) // OB_POSEMODE = 8192
+				ob->mode |= OB_MODE_POSE;
+		}
 	}
 
 	/* put 2.50 compatibility code here until next subversion bump */

Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_constraint_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesdna/DNA_constraint_types.h	2009-09-08 08:15:56 UTC (rev 23059)
+++ branches/blender2.5/blender/source/blender/makesdna/DNA_constraint_types.h	2009-09-08 09:41:15 UTC (rev 23060)
@@ -64,7 +64,8 @@
 	float		enforce;	/* 	Amount of influence exherted by constraint (0.0-1.0) */
 	float		headtail;	/*	Point along subtarget bone where the actual target is. 0=head (default for all), 1=tail*/
 	int			pad;
-	struct Ipo *ipo;		/* local influence ipo or driver */
+	
+	struct Ipo *ipo;		/* local influence ipo or driver */ // XXX depreceated for 2.5... old animation system hack
 } bConstraint;
 
 
@@ -449,6 +450,10 @@
 #define TRACK_nY	0x04
 #define TRACK_nZ	0x05
 
+/* FollowPath flags */
+#define FOLLOWPATH_FOLLOW	0x01
+#define FOLLOWPATH_STATIC	0x02
+
 /* bTrackToConstraint->flags */
 #define TARGET_Z_UP 0x01
 

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c	2009-09-08 08:15:56 UTC (rev 23059)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c	2009-09-08 09:41:15 UTC (rev 23060)
@@ -871,9 +871,15 @@
 	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update");
 
 	prop= RNA_def_property(srna, "offset", PROP_INT, PROP_TIME);
-	RNA_def_property_range(prop, -300000.0, 300000.f);
+	RNA_def_property_range(prop, MINAFRAME, MAXFRAME);
 	RNA_def_property_ui_text(prop, "Offset", "Offset from the position corresponding to the time frame.");
 	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
+	
+	prop= RNA_def_property(srna, "offset_percentage", PROP_FLOAT, PROP_PERCENTAGE);
+	RNA_def_property_float_sdna(prop, NULL, "offset"); // XXX we might be better with another var or some hackery?
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_ui_text(prop, "Offset Percentage", "Percentage value defining target position along length of bone.");
+	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
 
 	prop= RNA_def_property(srna, "forward", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "trackflag");
@@ -888,9 +894,15 @@
 	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
 
 	prop= RNA_def_property(srna, "curve_follow", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "followflag", 1);
+	RNA_def_property_boolean_sdna(prop, NULL, "followflag", FOLLOWPATH_FOLLOW);
 	RNA_def_property_ui_text(prop, "Follow Curve", "Object will follow the heading and banking of the curve.");
 	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
+	
+		// TODO: do we need to do some special trickery to get offset sane for this?
+	prop= RNA_def_property(srna, "fixed_position", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "followflag", FOLLOWPATH_STATIC);
+	RNA_def_property_ui_text(prop, "Fixed Position", "Object will stay locked to a single point somewhere along the length of the curve regardless of time.");
+	RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update");
 }
 
 static void rna_def_constraint_stretch_to(BlenderRNA *brna)





More information about the Bf-blender-cvs mailing list