Revision: 26273
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26273
Author:   aligorith
Date:     2010-01-26 04:16:14 +0100 (Tue, 26 Jan 2010)

Log Message:
-----------
Radians vs Degrees: The Second Attempt

F-Curves now internally store radians again instead of degrees. 
- This solves problems with inconsistencies when working with drivers.
- No need to version patch old files, potentially screwing them up. As such, 
removed the version patching for F-Curves.
- Is better suited to optionally showing radians throughout the UI instead or 
degrees.

As a result, values are now converted on the fly in the Graph Editor for 
display and operators that operate on values. I've made the conversion system 
for this rather general, so that other unit type conversions can also be hooked 
up with the type conversion backend.

Also, made some tweaks to F-Curve RNA wrapping to make it represent the data 
better.

TODO:
- Transform code currently still needs to be corrected to work with these 
changes. Currently moving keyframes for rotation curves will make them change 
too rapidly vertically when using degrees.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/anim_sys.c
    trunk/blender/source/blender/blenkernel/intern/fcurve.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/animation/anim_draw.c
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/screen/screen_ops.c
    trunk/blender/source/blender/editors/space_action/action_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_draw.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_select.c
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_curve.c
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c

Modified: trunk/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim_sys.c   2010-01-26 
02:49:30 UTC (rev 26272)
+++ trunk/blender/source/blender/blenkernel/intern/anim_sys.c   2010-01-26 
03:16:14 UTC (rev 26273)
@@ -730,11 +730,6 @@
                /* set value - only for animatable numerical values */
                if (RNA_property_animateable(&new_ptr, prop)) 
                {
-                       /* convert to radians */
-                       if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == 
PROP_UNIT_ROTATION) {
-                               value *= M_PI/180.0;
-                       }
-                       
                        switch (RNA_property_type(prop)) 
                        {
                                case PROP_BOOLEAN:
@@ -1471,11 +1466,6 @@
                int array_index= nec->index;
                float value= nec->value;
                
-               /* convert to radians */
-               if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == 
PROP_UNIT_ROTATION) {
-                       value *= M_PI/180.0;
-               }
-               
                /* write values - see animsys_write_rna_setting() to sync the 
code */
                switch (RNA_property_type(prop)) 
                {

Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c     2010-01-26 
02:49:30 UTC (rev 26272)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c     2010-01-26 
03:16:14 UTC (rev 26273)
@@ -816,11 +816,6 @@
                        default:
                                break;
                }
-               
-               /* degrees to radians (since curves are stored in degrees, but 
drivers need radians) */
-               if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == 
PROP_UNIT_ROTATION) {
-                       value *= 180.0/M_PI;
-               }
        }
        else {
                if (G.f & G_DEBUG)

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c   2010-01-26 
02:49:30 UTC (rev 26272)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c   2010-01-26 
03:16:14 UTC (rev 26273)
@@ -6459,50 +6459,10 @@
        }
 }
 
-static void do_version_fcurves_radians_degrees_250(ListBase *lb, char 
*propname)
-{
-       FCurve *fcu;
-       FModifier *fcm;
-       int 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;
-                               }
-                       }
-                       
-                       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;
-               }
-       }
-}
-                       
 static void do_version_constraints_radians_degrees_250(ListBase *lb)
 {
        bConstraint *con;
 
-       /* fcurves for this are not converted, assumption is these were 
unlikely to be used */
        for     (con=lb->first; con; con=con->next) {
                if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
                        bRigidBodyJointConstraint *data = con->data;
@@ -10578,25 +10538,15 @@
                
        }
        
-       
-       /* put 2.50 compatibility code here until next subversion bump */
        if (main->versionfile < 250 || (main->versionfile == 250 && 
main->subversionfile < 13)) {
                /* NOTE: if you do more conversion, be sure to do it outside of 
this and
                   increase subversion again, otherwise it will not be correct 
*/
                Object *ob;
-               bAction *act;
                
                /* 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);
                        bPoseChannel *pchan;
 
-                       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");
-                       }
-
                        
do_version_constraints_radians_degrees_250(&ob->constraints);
 
                        if (ob->pose) {
@@ -10612,18 +10562,15 @@
                                }
                        }
                }
-               
-               /* 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");
-               }
        }
+       
+       /* put 2.50 compatibility code here until next subversion bump */
+       if (1) {
+       
+       }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! 
*/
-       /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
+       /* WATCH IT 2!: Userdef struct init has to be in 
editors/interface/resources.c! */
 
        /* don't forget to set version number in blender.c! */
 }

Modified: trunk/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_draw.c  2010-01-26 
02:49:30 UTC (rev 26272)
+++ trunk/blender/source/blender/editors/animation/anim_draw.c  2010-01-26 
03:16:14 UTC (rev 26273)
@@ -62,6 +62,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "RNA_access.h"
+
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
@@ -237,6 +239,7 @@
 /* NLA-MAPPING UTILITIES (required for drawing and also editing keyframes)  */
 
 /* Obtain the AnimData block providing NLA-mapping for the given channel (if 
applicable) */
+// TODO: do not supply return this if the animdata tells us that there is no 
mapping to perform
 AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale)
 {
        /* sanity checks */
@@ -252,11 +255,6 @@
 
 /* ------------------- */
 
-typedef struct NlaMappingApplyBackup {
-       struct NlaMappingBackup *next, *prev;
-       BezTriple bezt;
-} NlaMappingApplyBackup;
-
 /* helper function for ANIM_nla_mapping_apply_fcurve() -> "restore", i.e. 
mapping points back to action-time */
 static short bezt_nlamapping_restore(BeztEditData *bed, BezTriple *bezt)
 {
@@ -322,3 +320,93 @@
 }
 
 /* *************************************************** */
+/* UNITS CONVERSION MAPPING (required for drawing and editing keyframes) */
+
+/* Get unit conversion factor for given ID + F-Curve */
+float ANIM_unit_mapping_get_factor (Scene *scene, ID *id, FCurve *fcu, short 
restore)
+{
+       /* sanity checks */
+       if (id && fcu && fcu->rna_path) 
+       {
+               PointerRNA ptr, id_ptr;
+               PropertyRNA *prop;
+               
+               /* get RNA property that F-Curve affects */
+               RNA_id_pointer_create(id, &id_ptr);
+               if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) 
+               {
+                       /* rotations: radians <-> degrees? */
+                       if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == 
PROP_UNIT_ROTATION)
+                       {
+                               /* if the radians flag is not set, default to 
using degrees which need conversions */
+                               if ((scene) && (scene->unit.flag & 
USER_UNIT_ROT_RADIANS) == 0) {
+                                       if (restore)
+                                               return M_PI / 180.0f;   /* 
degrees to radians */
+                                       else
+                                               return 180.0f / M_PI;   /* 
radians to degrees */
+                               }
+                       }
+                       
+                       // TODO: other rotation types here as necessary
+               }
+       }
+       
+       /* no mapping needs to occur... */
+       return 1.0f;
+}
+
+/* ----------------------- */
+
+/* helper function for ANIM_unit_mapping_apply_fcurve -> mapping callback for 
unit mapping */
+static short bezt_unit_mapping_apply (BeztEditData *bed, BezTriple *bezt)
+{
+       /* mapping factor is stored in f1, only_keys option is stored in i1 */
+       short only_keys= (short)bed->i1;
+       float fac= bed->f1;
+       
+       /* adjust BezTriple handles only if allowed to */
+       if (only_keys == 0) {
+               bezt->vec[0][1] *= fac;
+               bezt->vec[2][1] *= fac;
+       }
+       
+       bezt->vec[1][1] *= fac;
+       
+       return 0;
+}
+
+/* Apply/Unapply units conversions to keyframes */
+void ANIM_unit_mapping_apply_fcurve (Scene *scene, ID *id, FCurve *fcu, short 
restore, short only_keys)
+{
+       BeztEditData bed;
+       float fac;
+       
+       /* calculate mapping factor, and abort if nothing to change */
+       fac= ANIM_unit_mapping_get_factor(scene, id, fcu, restore);
+       if (fac == 1.0f)
+               return;
+       
+       /* init edit data 
+        *      - mapping factor is stored in f1
+        *      - only_keys is stored in 'i1'
+        */
+       memset(&bed, 0, sizeof(BeztEditData));
+       bed.f1= (float)fac;
+       bed.i1= (int)only_keys;
+       
+       /* apply to F-Curve */
+       ANIM_fcurve_keys_bezier_loop(&bed, fcu, NULL, bezt_unit_mapping_apply, 
NULL);
+       
+       // FIXME: loop here for samples should be generalised
+       if (fcu->fpt) {
+               FPoint *fpt;
+               int i;
+               
+               for (i=0, fpt=fcu->fpt; i < fcu->totvert; i++, fpt++) {
+                       /* apply unit mapping */
+                       fpt->vec[1] *= fac;
+               }
+       }
+}
+
+/* *************************************************** */

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c 2010-01-26 
02:49:30 UTC (rev 26272)
+++ trunk/blender/source/blender/editors/animation/keyframing.c 2010-01-26 
03:16:14 UTC (rev 26273)
@@ -783,11 +783,6 @@
                curval= setting_get_rna_value(&ptr, prop, fcu->array_index);
        }
        
-       /* convert to degrees */
-       if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) 
{
-               curval *= 180.0/M_PI;
-       }
-       
        /* only insert keyframes where they are needed */
        if (flag & INSERTKEY_NEEDED) {
                short insert_mode;
@@ -900,10 +895,6 @@
                        }
                }
                
-               /* mark the curve if it's a new rotation curve */
-               if ((fcu->totvert == 0) && 
(RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION))
-                       fcu->flag |= FCURVE_ROTATION_DEGREES;
-               
                /* insert keyframe */
                ret += insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
        }
@@ -926,6 +917,12 @@
        AnimData *adt= BKE_animdata_from_id(id);
        FCurve *fcu = NULL;
        
+       /* sanity checks */
+       if ELEM(NULL, id, adt) {
+               printf("ERROR: no ID-block and/or AnimData to delete keyframe 
from \n");
+               break;
+       }       
+       
        /* get F-Curve
         * Note: here is one of the places where we don't want new Action + 
F-Curve added!
         *              so 'add' var must be 0

Modified: trunk/blender/source/blender/editors/include/ED_anim_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_anim_api.h  2010-01-26 
02:49:30 UTC (rev 26272)
+++ trunk/blender/source/blender/editors/include/ED_anim_api.h  2010-01-26 
03:16:14 UTC (rev 26273)

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to