Fix for radians-degrees version patch, more testing should have gone
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 25 Jan 2010 17:51:21 +0000 (17:51 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 25 Jan 2010 17:51:21 +0000 (17:51 +0000)
into this before committing:

* Subversion was not increased, meaning that conversion would be applied
  even on files saved with the new version.
* Drivers were not converted.
* FCurve generator modifiers were not converted.

This seems to cover all cases we found for Durian, if another conversion
is needed for this, be sure to increase the subversion number and do it
in a separate if() test, otherwise files will break.

source/blender/blenloader/intern/readfile.c

index 492321d9ed9334f9a144989fb31f15dee640b0d8..30a5b647fe16837b5b3010ec55c87d5dff2ec347 100644 (file)
@@ -6459,28 +6459,43 @@ static void do_version_mtex_factor_2_50(MTex **mtex_array, short idtype)
        }
 }
 
-static void do_version_fcurve_radians_degrees_250(FCurve *fcu)
+static void do_version_fcurves_radians_degrees_250(ListBase *lb, char *propname)
 {
+       FCurve *fcu;
+       FModifier *fcm;
        int i;
        
-       if (fcu->bezt) {
-               for (i=0; i<fcu->totvert; i++) {
-                       BezTriple *bt = fcu->bezt+i;
-                       
-                       bt->vec[0][1] *= 180.0/M_PI;
-                       bt->vec[1][1] *= 180.0/M_PI;
-                       bt->vec[2][1] *= 180.0/M_PI;
-               }
-       }
-       else if (fcu->fpt) {
-               for (i=0; i<fcu->totvert; i++) {
-                       FPoint *fpt = fcu->fpt+i;
+       for (fcu=lb->first; fcu; fcu=fcu->next) {
+               if (strstr(fcu->rna_path, propname)) {
+                       if (fcu->bezt) {
+                               for (i=0; i<fcu->totvert; i++) {
+                                       BezTriple *bt = fcu->bezt+i;
+                                       
+                                       bt->vec[0][1] *= 180.0/M_PI;
+                                       bt->vec[1][1] *= 180.0/M_PI;
+                                       bt->vec[2][1] *= 180.0/M_PI;
+                               }
+                       }
+                       else if (fcu->fpt) {
+                               for (i=0; i<fcu->totvert; i++) {
+                                       FPoint *fpt = fcu->fpt+i;
+                                       
+                                       fpt->vec[1] *= 180.0/M_PI;
+                               }
+                       }
                        
-                       fpt->vec[1] *= 180.0/M_PI;
+                       for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
+                               if (fcm->type == FMODIFIER_TYPE_GENERATOR) {
+                                       FMod_Generator *data= (FMod_Generator *)fcm->data;
+
+                                       for (i=0; i<data->arraysize; i++)
+                                               data->coefficients[i] *= 180/M_PI;
+                               }
+                       }
+
+                       fcu->flag |= FCURVE_ROTATION_DEGREES;
                }
        }
-       
-       fcu->flag |= FCURVE_ROTATION_DEGREES;
 }
 
 static void do_versions(FileData *fd, Library *lib, Main *main)
@@ -10536,69 +10551,68 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        
        
        /* put 2.50 compatibility code here until next subversion bump */
-       if (1) {
-               {
-                       /* still missing:
-                          - Pose channel IK (min x/y/z, max x/y/z)
-                        */
-                       bAction *act;
-                       Object *ob;
-                       
-                       float rads_per_deg = M_PI / 180.0;
-                       
-                       /* convert degrees to radians for internal use */
-                       for (ob=main->object.first; ob; ob=ob->id.next) {
-                               AnimData *adt = BKE_animdata_from_id((ID *)ob);
-                               bConstraint *con;
-                               
-                               for     (con=ob->constraints.first; con; con=con->next) {
-                                       
-                                       if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
-                                               bRigidBodyJointConstraint *data = con->data;
-                                               data->axX *= rads_per_deg;
-                                               data->axY *= rads_per_deg;
-                                               data->axZ *= rads_per_deg;
-                                       }
-                                       else if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
-                                               bKinematicConstraint *data = con->data;
-                                               data->poleangle *= rads_per_deg;
-                                       }
-                                       else if(con->type==CONSTRAINT_TYPE_ROTLIMIT) {
-                                               bRotLimitConstraint *data = con->data;
-                                               FCurve *fcu;
-
-                                               /* do it here, slightly less chance of getting a false positive */
-                                               for (fcu=adt->action->curves.first; fcu; fcu=fcu->next) {
-                                                       if (strstr(fcu->rna_path, "minimum_x"))
-                                                               do_version_fcurve_radians_degrees_250(fcu);
-                                               }
-                                               
-                                               data->xmin *= rads_per_deg;
-                                               data->xmax *= rads_per_deg;
-                                               data->ymin *= rads_per_deg;
-                                               data->ymax *= rads_per_deg;
-                                               data->zmin *= rads_per_deg;
-                                               data->zmax *= rads_per_deg;
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 13)) {
+               /* still missing: - Pose channel IK (min x/y/z, max x/y/z)
+                  NOTE: if you do more conversion, be sure to do it outside of this and
+                  increase subversion again, otherwise it will not be correct */
+               bAction *act;
+               Object *ob;
+               
+               float rads_per_deg = M_PI / 180.0;
+               
+               /* convert degrees to radians for internal use */
+               for (ob=main->object.first; ob; ob=ob->id.next) {
+                       AnimData *adt = BKE_animdata_from_id((ID *)ob);
+                       bConstraint *con;
 
-                                       }
-                               }
+                       if(adt) {
+                               do_version_fcurves_radians_degrees_250(&adt->drivers, "rotation_euler");
+                               do_version_fcurves_radians_degrees_250(&adt->drivers, "delta_rotation_euler");
+                               do_version_fcurves_radians_degrees_250(&adt->drivers, "pole_angle");
                        }
                        
-                       /* convert fcurve values to be stored in degrees */
-                       for (act = main->action.first; act; act=act->id.next) {
-                               FCurve *fcu;
+                       for     (con=ob->constraints.first; con; con=con->next) {
                                
-                               /* convert over named properties with PROP_UNIT_ROTATION time of this change */
-                               for (fcu=act->curves.first; fcu; fcu=fcu->next) {
-                                       if (strstr(fcu->rna_path, "rotation_euler"))
-                                               do_version_fcurve_radians_degrees_250(fcu);
-                                       else if (strstr(fcu->rna_path, "delta_rotation_euler"))
-                                               do_version_fcurve_radians_degrees_250(fcu);
-                                       else if (strstr(fcu->rna_path, "pole_angle"))
-                                               do_version_fcurve_radians_degrees_250(fcu);
+                               if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
+                                       bRigidBodyJointConstraint *data = con->data;
+                                       data->axX *= rads_per_deg;
+                                       data->axY *= rads_per_deg;
+                                       data->axZ *= rads_per_deg;
+                               }
+                               else if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
+                                       bKinematicConstraint *data = con->data;
+                                       data->poleangle *= rads_per_deg;
+                               }
+                               else if(con->type==CONSTRAINT_TYPE_ROTLIMIT) {
+                                       bRotLimitConstraint *data = con->data;
+
+                                       if(adt) {
+                                               do_version_fcurves_radians_degrees_250(&adt->action->curves, "minimum_x");
+                                               do_version_fcurves_radians_degrees_250(&adt->action->curves, "minimum_y");
+                                               do_version_fcurves_radians_degrees_250(&adt->action->curves, "minimum_z");
+                                               do_version_fcurves_radians_degrees_250(&adt->action->curves, "maximum_x");
+                                               do_version_fcurves_radians_degrees_250(&adt->action->curves, "maximum_y");
+                                               do_version_fcurves_radians_degrees_250(&adt->action->curves, "maximum_z");
+                                       }
+
+                                       data->xmin *= rads_per_deg;
+                                       data->xmax *= rads_per_deg;
+                                       data->ymin *= rads_per_deg;
+                                       data->ymax *= rads_per_deg;
+                                       data->zmin *= rads_per_deg;
+                                       data->zmax *= rads_per_deg;
+
                                }
                        }
                }
+               
+               /* convert fcurve values to be stored in degrees */
+               for (act = main->action.first; act; act=act->id.next) {
+                       /* convert over named properties with PROP_UNIT_ROTATION time of this change */
+                       do_version_fcurves_radians_degrees_250(&act->curves, "rotation_euler");
+                       do_version_fcurves_radians_degrees_250(&act->curves, "delta_rotation_euler");
+                       do_version_fcurves_radians_degrees_250(&act->curves, "pole_angle");
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */