[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18727] branches/blender2.5/blender/source /blender: Animato: Conversion code + drawing tweaks
Joshua Leung
aligorith at gmail.com
Thu Jan 29 04:43:29 CET 2009
Revision: 18727
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18727
Author: aligorith
Date: 2009-01-29 04:43:04 +0100 (Thu, 29 Jan 2009)
Log Message:
-----------
Animato: Conversion code + drawing tweaks
* Recoded the conversion code so that all data gets converted. Previously, some IPO's and Actions (notably the ones used for Action Constraints) were not ported across.
* Made F-Curve drawing use more saturated colours to make them more visible. I'm not sure whether this works well in practice.
* Restored some horizontal bounding-box checks to optimise drawing.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c
branches/blender2.5/blender/source/blender/editors/animation/anim_ipo_utils.c
branches/blender2.5/blender/source/blender/editors/space_ipo/ipo_draw.c
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c 2009-01-28 23:56:21 UTC (rev 18726)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c 2009-01-29 03:43:04 UTC (rev 18727)
@@ -113,8 +113,12 @@
}
/* *************************************************** */
-/* ADRCODE to RNA-Path Conversion Code */
+/* ADRCODE to RNA-Path Conversion Code - Special (Bitflags) */
+
+/* *************************************************** */
+/* ADRCODE to RNA-Path Conversion Code - Standard */
+
/* Object types */
static char *ob_adrcodes_to_paths (int adrcode, int *array_index)
{
@@ -793,7 +797,7 @@
* actname: name of Action-Channel (if applicable) that IPO-Curve's IPO-block belonged to
* constname: name of Constraint-Channel (if applicable) that IPO-Curve's IPO-block belonged to
*/
-static FCurve *icu_to_fcu (IpoCurve *icu, char *actname, char *constname)
+static void icu_to_fcurves (ListBase *list, IpoCurve *icu, char *actname, char *constname)
{
FCurve *fcu;
int i= 0;
@@ -807,6 +811,51 @@
icu->driver= NULL;
}
+ /* copy flags */
+ if (icu->flag & IPO_VISIBLE) fcu->flag |= FCURVE_VISIBLE;
+ if (icu->flag & IPO_SELECT) fcu->flag |= FCURVE_SELECTED;
+ if (icu->flag & IPO_ACTIVE) fcu->flag |= FCURVE_ACTIVE;
+ if (icu->flag & IPO_MUTE) fcu->flag |= FCURVE_MUTED;
+ if (icu->flag & IPO_PROTECT) fcu->flag |= FCURVE_PROTECTED;
+ if (icu->flag & IPO_AUTO_HORIZ) fcu->flag |= FCURVE_AUTO_HANDLES;
+
+ /* set extrapolation */
+ switch (icu->extrap) {
+ case IPO_HORIZ: /* constant extrapolation */
+ case IPO_DIR: /* linear extrapolation */
+ {
+ /* just copy, as the new defines match the old ones... */
+ fcu->extend= icu->extrap;
+ }
+ break;
+
+ case IPO_CYCL: /* cyclic extrapolation */
+ case IPO_CYCLX: /* cyclic extrapolation + offset */
+ {
+ /* Add a new FModifier (Cyclic) instead of setting extend value
+ * as that's the new equivilant of that option.
+ */
+ FModifier *fcm= fcurve_add_modifier(fcu, FMODIFIER_TYPE_CYCLES);
+ FMod_Cycles *data= (FMod_Cycles *)fcm->data;
+
+ /* if 'offset' one is in use, set appropriate settings */
+ if (icu->extrap == IPO_CYCLX)
+ data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC_OFFSET;
+ else
+ data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC;
+ }
+ break;
+ }
+
+ /* -------- */
+
+ /* get rna-path
+ * - we will need to set the 'disabled' flag if no path is able to be made (for now)
+ */
+ fcu->rna_path= get_rna_access(icu->blocktype, icu->adrcode, actname, constname, &fcu->array_index);
+ if (fcu->rna_path == NULL)
+ fcu->flag |= FCURVE_DISABLED;
+
/* convert keyframes
* - beztriples and bpoints are mutually exclusive, so we won't have both at the same time
* - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet)
@@ -850,76 +899,26 @@
//FPoint *fpt;
}
- /* get rna-path
- * - we will need to set the 'disabled' flag if no path is able to be made (for now)
- */
- fcu->rna_path= get_rna_access(icu->blocktype, icu->adrcode, actname, constname, &fcu->array_index);
- if (fcu->rna_path == NULL)
- fcu->flag |= FCURVE_DISABLED;
-
- /* copy flags */
- if (icu->flag & IPO_VISIBLE) fcu->flag |= FCURVE_VISIBLE;
- if (icu->flag & IPO_SELECT) fcu->flag |= FCURVE_SELECTED;
- if (icu->flag & IPO_ACTIVE) fcu->flag |= FCURVE_ACTIVE;
- if (icu->flag & IPO_MUTE) fcu->flag |= FCURVE_MUTED;
- if (icu->flag & IPO_PROTECT) fcu->flag |= FCURVE_PROTECTED;
- if (icu->flag & IPO_AUTO_HORIZ) fcu->flag |= FCURVE_AUTO_HANDLES;
-
- /* set extrapolation */
- switch (icu->extrap) {
- case IPO_HORIZ: /* constant extrapolation */
- case IPO_DIR: /* linear extrapolation */
- {
- /* just copy, as the new defines match the old ones... */
- fcu->extend= icu->extrap;
- }
- break;
-
- case IPO_CYCL: /* cyclic extrapolation */
- case IPO_CYCLX: /* cyclic extrapolation + offset */
- {
- /* Add a new FModifier (Cyclic) instead of setting extend value
- * as that's the new equivilant of that option.
- */
- FModifier *fcm= fcurve_add_modifier(fcu, FMODIFIER_TYPE_CYCLES);
- FMod_Cycles *data= (FMod_Cycles *)fcm->data;
-
- /* if 'offset' one is in use, set appropriate settings */
- if (icu->extrap == IPO_CYCLX)
- data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC_OFFSET;
- else
- data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC;
- }
- break;
- }
-
- /* return new F-Curve */
- return fcu;
+ /* add new F-Curve to list */
+ BLI_addtail(list, fcu);
}
-/* Convert IPO-block (i.e. all its IpoCurves) for some ID to the new system
- * This assumes that AnimData has been added already. Separation of drivers
- * from animation data is accomplished here too...
+/* ------------------------- */
+
+/* Convert IPO-block (i.e. all its IpoCurves) to the new system.
+ * This does not assume that any ID or AnimData uses it, but does assume that
+ * it is given two lists, which it will perform driver/animation-data separation.
*/
-static void ipo_to_animdata (ID *id, Ipo *ipo, char *actname, char *constname)
+static void ipo_to_animato (Ipo *ipo, char actname[], char constname[], ListBase *anim, ListBase *drivers)
{
- AnimData *adt= BKE_animdata_from_id(id);
- //bActionGroup *grp;
IpoCurve *icu, *icn;
- FCurve *fcu;
/* sanity check */
- if ELEM(NULL, id, ipo)
+ if (ELEM3(NULL, ipo, anim, drivers))
return;
- if (adt == NULL) {
- printf("ERROR ipo_to_animdata(): adt invalid \n");
- return;
- }
-
- printf("ipo to animdata - ID:%s, IPO:%s, actname:%s constname:%s curves:%d \n",
- id->name+2, ipo->id.name+2, (actname)?actname:"<None>", (constname)?constname:"<None>",
- BLI_countlist(&ipo->curve));
-
+
+ printf("ipo_to_animato \n");
+
/* validate actname and constname
* - clear actname if it was one of the generic <builtin> ones (i.e. 'Object', or 'Shapes')
* - actname can then be used to assign F-Curves in Action to Action Groups
@@ -927,10 +926,9 @@
* F-Curves for bones). This may be added later... for now let's just dump without them...
*/
if (actname) {
- printf("actname != 0 \n");
- if ((GS(id->name) == ID_OB) && (strcmp(actname, "Object") == 0))
+ if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Object") == 0))
actname= NULL;
- else if ((GS(id->name) == ID_OB) && (strcmp(actname, "Shape") == 0))
+ else if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Shape") == 0))
actname= NULL;
}
@@ -939,62 +937,38 @@
/* get link to next (for later) */
icn= icu->next;
- /* convert IPO-Curve to F-Curve
- * NOTE: this frees any of the old data stored in the IPO-Curve that isn't needed anymore...
+ /* Since an IPO-Curve may end up being made into many F-Curves (i.e. bitflag curves),
+ * we figure out the best place to put the channel, then tell the curve-converter to just dump there
*/
- // XXX we need to cope with the nasty old 'bitflag' curves... that will be a task for later
- // we will need to create a few new curves when doing so, and will need to sift through the keyframes to add relevant data
- fcu= icu_to_fcu(icu, actname, constname);
+ if (icu->driver)
+ icu_to_fcurves(drivers, icu, actname, constname);
+ else
+ icu_to_fcurves(anim, icu, actname, constname);
- /* conversion path depends on whether it's a driver or not */
- if (fcu->driver == NULL) {
- /* try to get action */
- if (adt->action == NULL) {
- adt->action= add_empty_action("ConvertedAction"); // XXX we need a better name for this...
- printf("added new action \n");
- }
- printf("\ticu to action fcurve (%p %d) -> (%p %s %d) \n", icu, icu->adrcode, fcu, fcu->rna_path, fcu->array_index);
-
- /* add F-Curve to action */
- BLI_addtail(&adt->action->curves, fcu);
- }
- else {
- printf("\ticu to driver fcurve (%p %d) -> (%p %s %d) \n", icu, icu->adrcode, fcu, fcu->rna_path, fcu->array_index);
-
- /* add F-Curve to AnimData's drivers */
- BLI_addtail(&adt->drivers, fcu);
- }
-
/* free this IpoCurve now that it's been converted */
BLI_freelinkN(&ipo->curve, icu);
}
}
-/* Convert Action-block to new system
+/* Convert Action-block to new system, separating animation and drivers
+ * New curves may not be converted directly into the given Action (i.e. for Actions linked
+ * to Objects, where ob->ipo and ob->action need to be combined).
* NOTE: we need to be careful here, as same data-structs are used for new system too!
*/
-static void action_to_animdata (ID *id, bAction *act)
+static void action_to_animato (bAction *act, ListBase *curves, ListBase *drivers)
{
- AnimData *adt= BKE_animdata_from_id(id);
bActionChannel *achan, *achann;
bConstraintChannel *conchan, *conchann;
/* only continue if there are Action Channels (indicating unconverted data) */
- if (ELEM(NULL, adt, act->chanbase.first))
+ if (act->chanbase.first == NULL)
return;
/* get rid of all Action Groups */
- // XXX this is risky if there's some old, some new data in the Action...
+ // XXX this is risky if there's some old + some new data in the Action...
if (act->groups.first)
BLI_freelistN(&act->groups);
-
- /* check if we need to set this Action as the AnimData's action */
- if (adt->action == NULL) {
- /* set this Action as AnimData's Action */
- printf("act_to_adt - set adt action to act \n");
- adt->action= act;
- }
-
+
/* loop through Action-Channels, converting data, freeing as we go */
for (achan= act->chanbase.first; achan; achan= achann) {
/* get pointer to next Action Channel */
@@ -1002,7 +976,7 @@
/* convert Action Channel's IPO data */
if (achan->ipo) {
- ipo_to_animdata(id, achan->ipo, achan->name, NULL);
+ ipo_to_animato(achan->ipo, achan->name, NULL, curves, drivers);
achan->ipo->id.us--;
achan->ipo= NULL;
}
@@ -1014,7 +988,7 @@
/* convert Constraint Channel's IPO data */
if (conchan->ipo) {
- ipo_to_animdata(id, conchan->ipo, achan->name, conchan->name);
+ ipo_to_animato(conchan->ipo, achan->name, conchan->name, curves, drivers);
conchan->ipo->id.us--;
conchan->ipo= NULL;
}
@@ -1028,6 +1002,79 @@
}
}
+
+/* ------------------------- */
+
+/* Convert IPO-block (i.e. all its IpoCurves) for some ID to the new system
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list