[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26256] trunk/blender/source/blender/ blenloader/intern/readfile.c: Fix for radians-degrees version patch, more testing should have gone

Brecht Van Lommel brecht at blender.org
Mon Jan 25 18:51:21 CET 2010


Revision: 26256
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26256
Author:   blendix
Date:     2010-01-25 18:51:21 +0100 (Mon, 25 Jan 2010)

Log Message:
-----------
Fix for radians-degrees version patch, more testing should have gone
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.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2010-01-25 17:48:02 UTC (rev 26255)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2010-01-25 17:51:21 UTC (rev 26256)
@@ -6459,28 +6459,43 @@
 	}
 }
 
-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;
+	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;
+				}
+			}
 			
-			bt->vec[0][1] *= 180.0/M_PI;
-			bt->vec[1][1] *= 180.0/M_PI;
-			bt->vec[2][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;
 		}
 	}
-	else if (fcu->fpt) {
-		for (i=0; i<fcu->totvert; i++) {
-			FPoint *fpt = fcu->fpt+i;
-			
-			fpt->vec[1] *= 180.0/M_PI;
-		}
-	}
-	
-	fcu->flag |= FCURVE_ROTATION_DEGREES;
 }
 
 static void do_versions(FileData *fd, Library *lib, Main *main)
@@ -10536,69 +10551,68 @@
 	
 	
 	/* 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;
+	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");
+			}
 			
-			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) {
 				
-				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;
+				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");
 					}
-					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;
+					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) {
-				FCurve *fcu;
-				
-				/* 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);
-				}
-			}
 		}
+		
+		/* 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! */





More information about the Bf-blender-cvs mailing list