2.5 - FollowPath Constraint + File Loading Bugfix
authorJoshua Leung <aligorith@gmail.com>
Tue, 8 Sep 2009 09:41:15 +0000 (09:41 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 8 Sep 2009 09:41:15 +0000 (09:41 +0000)
* 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.

release/ui/buttons_object_constraint.py
source/blender/blenkernel/intern/constraint.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_constraint_types.h
source/blender/makesrna/intern/rna_constraint.c

index cdc18e3545cd61b97dbc9197e6e73ffd20c4d5ca..ff3231a9d611aad6565be0c54168378f8624a646 100644 (file)
@@ -121,9 +121,17 @@ class ConstraintButtonsPanel(bpy.types.Panel):
        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:")
index 0f7767a1808d110058876935c0ea30716e97d1d4..dfbcc51a93cdca7f87d5f87dfc65f63b3089bea5 100644 (file)
@@ -1178,17 +1178,26 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
                        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);
index db97657a2ee68b62942b9084dff1bc7bdbd29f99..618e587d6745f97c116ab140711b7dd66c94377c 100644 (file)
@@ -9596,6 +9596,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
        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 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
                        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 */
index 6fab633b192c60e1545aaa76fb37591f765362e8..a92dc836197bebffe274671b5e871f0d4ec75146 100644 (file)
@@ -64,7 +64,8 @@ typedef struct bConstraint {
        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 @@ typedef enum B_CONSTRAINTCHANNEL_FLAG {
 #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
 
index c09a71f752a2be06c512569df86f3c7076baa6d3..83f3042d8ee6f1f25a56d70402ea6ffa2968209a 100644 (file)
@@ -871,9 +871,15 @@ static void rna_def_constraint_follow_path(BlenderRNA *brna)
        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,8 +894,14 @@ static void rna_def_constraint_follow_path(BlenderRNA *brna)
        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");
 }