Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-08-21 16:23:33 +0300
committerJacques Lucke <jacques@blender.org>2020-08-21 16:23:33 +0300
commit79d678e677a04c886cc7caa2b7aa30308082c462 (patch)
tree5443d015a4e661b2d7ced04cc59ceb944ae74d5d /source/blender/blenloader/intern
parent76689e85170027fa9fe2d6160b1a0921ccee6475 (diff)
Refactor: move fcurve/fmodifier code from blenloader to blenkernel
This is part of T76372.
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r--source/blender/blenloader/intern/readfile.c196
-rw-r--r--source/blender/blenloader/intern/writefile.c97
2 files changed, 16 insertions, 277 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 35e504f87b0..c9a0a7a16ab 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -121,6 +121,7 @@
#include "BKE_curve.h"
#include "BKE_curveprofile.h"
#include "BKE_effect.h"
+#include "BKE_fcurve.h"
#include "BKE_fcurve_driver.h"
#include "BKE_fluid.h"
#include "BKE_global.h" // for G
@@ -2715,142 +2716,6 @@ static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBas
/** \name Read ID: Action
* \{ */
-static void lib_link_fmodifiers(BlendLibReader *reader, ID *id, ListBase *list)
-{
- LISTBASE_FOREACH (FModifier *, fcm, list) {
- /* data for specific modifiers */
- switch (fcm->type) {
- case FMODIFIER_TYPE_PYTHON: {
- FMod_Python *data = (FMod_Python *)fcm->data;
- BLO_read_id_address(reader, id->lib, &data->script);
-
- break;
- }
- }
- }
-}
-
-static void lib_link_fcurves(BlendLibReader *reader, ID *id, ListBase *list)
-{
- if (list == NULL) {
- return;
- }
-
- /* relink ID-block references... */
- LISTBASE_FOREACH (FCurve *, fcu, list) {
- /* driver data */
- if (fcu->driver) {
- ChannelDriver *driver = fcu->driver;
- LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
- DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
- /* only relink if still used */
- if (tarIndex < dvar->num_targets) {
- BLO_read_id_address(reader, id->lib, &dtar->id);
- }
- else {
- dtar->id = NULL;
- }
- }
- DRIVER_TARGETS_LOOPER_END;
- }
- }
-
- /* modifiers */
- lib_link_fmodifiers(reader, id, &fcu->modifiers);
- }
-}
-
-/* NOTE: this assumes that link_list has already been called on the list */
-static void direct_link_fmodifiers(BlendDataReader *reader, ListBase *list, FCurve *curve)
-{
- LISTBASE_FOREACH (FModifier *, fcm, list) {
- /* relink general data */
- BLO_read_data_address(reader, &fcm->data);
- fcm->curve = curve;
-
- /* do relinking of data for specific types */
- switch (fcm->type) {
- case FMODIFIER_TYPE_GENERATOR: {
- FMod_Generator *data = (FMod_Generator *)fcm->data;
- BLO_read_float_array(reader, data->arraysize, &data->coefficients);
- break;
- }
- case FMODIFIER_TYPE_ENVELOPE: {
- FMod_Envelope *data = (FMod_Envelope *)fcm->data;
-
- BLO_read_data_address(reader, &data->data);
-
- break;
- }
- case FMODIFIER_TYPE_PYTHON: {
- FMod_Python *data = (FMod_Python *)fcm->data;
-
- BLO_read_data_address(reader, &data->prop);
- IDP_BlendDataRead(reader, &data->prop);
-
- break;
- }
- }
- }
-}
-
-/* NOTE: this assumes that link_list has already been called on the list */
-static void direct_link_fcurves(BlendDataReader *reader, ListBase *list)
-{
- /* link F-Curve data to F-Curve again (non ID-libs) */
- LISTBASE_FOREACH (FCurve *, fcu, list) {
- /* curve data */
- BLO_read_data_address(reader, &fcu->bezt);
- BLO_read_data_address(reader, &fcu->fpt);
-
- /* rna path */
- BLO_read_data_address(reader, &fcu->rna_path);
-
- /* group */
- BLO_read_data_address(reader, &fcu->grp);
-
- /* clear disabled flag - allows disabled drivers to be tried again ([#32155]),
- * but also means that another method for "reviving disabled F-Curves" exists
- */
- fcu->flag &= ~FCURVE_DISABLED;
-
- /* driver */
- BLO_read_data_address(reader, &fcu->driver);
- if (fcu->driver) {
- ChannelDriver *driver = fcu->driver;
-
- /* Compiled expression data will need to be regenerated
- * (old pointer may still be set here). */
- driver->expr_comp = NULL;
- driver->expr_simple = NULL;
-
- /* give the driver a fresh chance - the operating environment may be different now
- * (addons, etc. may be different) so the driver namespace may be sane now [#32155]
- */
- driver->flag &= ~DRIVER_FLAG_INVALID;
-
- /* relink variables, targets and their paths */
- BLO_read_list(reader, &driver->variables);
- LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
- DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
- /* only relink the targets being used */
- if (tarIndex < dvar->num_targets) {
- BLO_read_data_address(reader, &dtar->rna_path);
- }
- else {
- dtar->rna_path = NULL;
- }
- }
- DRIVER_TARGETS_LOOPER_END;
- }
- }
-
- /* modifiers */
- BLO_read_list(reader, &fcu->modifiers);
- direct_link_fmodifiers(reader, &fcu->modifiers, fcu);
- }
-}
-
static void lib_link_action(BlendLibReader *reader, bAction *act)
{
// XXX deprecated - old animation system <<<
@@ -2860,7 +2725,7 @@ static void lib_link_action(BlendLibReader *reader, bAction *act)
}
// >>> XXX deprecated - old animation system
- lib_link_fcurves(reader, &act->id, &act->curves);
+ BKE_fcurve_blend_lib_read(reader, &act->id, &act->curves);
LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
if (marker->camera) {
@@ -2884,7 +2749,7 @@ static void direct_link_action(BlendDataReader *reader, bAction *act)
}
// >>> XXX deprecated - old animation system
- direct_link_fcurves(reader, &act->curves);
+ BKE_fcurve_blend_data_read(reader, &act->curves);
LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) {
BLO_read_data_address(reader, &agrp->channels.first);
@@ -2899,7 +2764,7 @@ static void lib_link_nladata_strips(BlendLibReader *reader, ID *id, ListBase *li
lib_link_nladata_strips(reader, id, &strip->strips);
/* check strip's F-Curves */
- lib_link_fcurves(reader, id, &strip->fcurves);
+ BKE_fcurve_blend_lib_read(reader, id, &strip->fcurves);
/* reassign the counted-reference to action */
BLO_read_id_address(reader, id->lib, &strip->act);
@@ -2926,11 +2791,11 @@ static void direct_link_nladata_strips(BlendDataReader *reader, ListBase *list)
/* strip's F-Curves */
BLO_read_list(reader, &strip->fcurves);
- direct_link_fcurves(reader, &strip->fcurves);
+ BKE_fcurve_blend_data_read(reader, &strip->fcurves);
/* strip's F-Modifiers */
BLO_read_list(reader, &strip->modifiers);
- direct_link_fmodifiers(reader, &strip->modifiers, NULL);
+ BKE_fmodifiers_blend_data_read(reader, &strip->modifiers, NULL);
}
}
@@ -2986,7 +2851,7 @@ static void lib_link_animdata(BlendLibReader *reader, ID *id, AnimData *adt)
BLO_read_id_address(reader, id->lib, &adt->tmpact);
/* link drivers */
- lib_link_fcurves(reader, id, &adt->drivers);
+ BKE_fcurve_blend_lib_read(reader, id, &adt->drivers);
/* overrides don't have lib-link for now, so no need to do anything */
@@ -3003,7 +2868,7 @@ static void direct_link_animdata(BlendDataReader *reader, AnimData *adt)
/* link drivers */
BLO_read_list(reader, &adt->drivers);
- direct_link_fcurves(reader, &adt->drivers);
+ BKE_fcurve_blend_data_read(reader, &adt->drivers);
adt->driver_array = NULL;
/* link overrides */
@@ -9925,43 +9790,6 @@ static void expand_constraint_channels(BlendExpander *expander, ListBase *chanba
}
}
-static void expand_fmodifiers(BlendExpander *expander, ListBase *list)
-{
- LISTBASE_FOREACH (FModifier *, fcm, list) {
- /* library data for specific F-Modifier types */
- switch (fcm->type) {
- case FMODIFIER_TYPE_PYTHON: {
- FMod_Python *data = (FMod_Python *)fcm->data;
-
- BLO_expand(expander, data->script);
-
- break;
- }
- }
- }
-}
-
-static void expand_fcurves(BlendExpander *expander, ListBase *list)
-{
- LISTBASE_FOREACH (FCurve *, fcu, list) {
- /* Driver targets if there is a driver */
- if (fcu->driver) {
- ChannelDriver *driver = fcu->driver;
-
- LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
- DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
- // TODO: only expand those that are going to get used?
- BLO_expand(expander, dtar->id);
- }
- DRIVER_TARGETS_LOOPER_END;
- }
- }
-
- /* F-Curve Modifiers */
- expand_fmodifiers(expander, &fcu->modifiers);
- }
-}
-
static void expand_animdata_nlastrips(BlendExpander *expander, ListBase *list)
{
LISTBASE_FOREACH (NlaStrip *, strip, list) {
@@ -9969,10 +9797,10 @@ static void expand_animdata_nlastrips(BlendExpander *expander, ListBase *list)
expand_animdata_nlastrips(expander, &strip->strips);
/* check F-Curves */
- expand_fcurves(expander, &strip->fcurves);
+ BKE_fcurve_blend_expand(expander, &strip->fcurves);
/* check F-Modifiers */
- expand_fmodifiers(expander, &strip->modifiers);
+ BKE_fmodifiers_blend_expand(expander, &strip->modifiers);
/* relink referenced action */
BLO_expand(expander, strip->act);
@@ -9986,7 +9814,7 @@ static void expand_animdata(BlendExpander *expander, AnimData *adt)
BLO_expand(expander, adt->tmpact);
/* drivers - assume that these F-Curves have driver data to be in this list... */
- expand_fcurves(expander, &adt->drivers);
+ BKE_fcurve_blend_expand(expander, &adt->drivers);
/* nla-data - referenced actions */
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
@@ -10043,7 +9871,7 @@ static void expand_action(BlendExpander *expander, bAction *act)
// ---------------------------------------------------
/* F-Curves in Action */
- expand_fcurves(expander, &act->curves);
+ BKE_fcurve_blend_expand(expander, &act->curves);
LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
if (marker->camera) {
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 698eefa4979..f5cb421920a 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -708,102 +708,13 @@ static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig)
}
}
-static void write_fmodifiers(BlendWriter *writer, ListBase *fmodifiers)
-{
- /* Write all modifiers first (for faster reloading) */
- BLO_write_struct_list(writer, FModifier, fmodifiers);
-
- /* Modifiers */
- LISTBASE_FOREACH (FModifier *, fcm, fmodifiers) {
- const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
-
- /* Write the specific data */
- if (fmi && fcm->data) {
- /* firstly, just write the plain fmi->data struct */
- BLO_write_struct_by_name(writer, fmi->structName, fcm->data);
-
- /* do any modifier specific stuff */
- switch (fcm->type) {
- case FMODIFIER_TYPE_GENERATOR: {
- FMod_Generator *data = fcm->data;
-
- /* write coefficients array */
- if (data->coefficients) {
- BLO_write_float_array(writer, data->arraysize, data->coefficients);
- }
-
- break;
- }
- case FMODIFIER_TYPE_ENVELOPE: {
- FMod_Envelope *data = fcm->data;
-
- /* write envelope data */
- if (data->data) {
- BLO_write_struct_array(writer, FCM_EnvelopeData, data->totvert, data->data);
- }
-
- break;
- }
- case FMODIFIER_TYPE_PYTHON: {
- FMod_Python *data = fcm->data;
-
- /* Write ID Properties -- and copy this comment EXACTLY for easy finding
- * of library blocks that implement this.*/
- IDP_BlendWrite(writer, data->prop);
-
- break;
- }
- }
- }
- }
-}
-
-static void write_fcurves(BlendWriter *writer, ListBase *fcurves)
-{
- BLO_write_struct_list(writer, FCurve, fcurves);
- LISTBASE_FOREACH (FCurve *, fcu, fcurves) {
- /* curve data */
- if (fcu->bezt) {
- BLO_write_struct_array(writer, BezTriple, fcu->totvert, fcu->bezt);
- }
- if (fcu->fpt) {
- BLO_write_struct_array(writer, FPoint, fcu->totvert, fcu->fpt);
- }
-
- if (fcu->rna_path) {
- BLO_write_string(writer, fcu->rna_path);
- }
-
- /* driver data */
- if (fcu->driver) {
- ChannelDriver *driver = fcu->driver;
-
- BLO_write_struct(writer, ChannelDriver, driver);
-
- /* variables */
- BLO_write_struct_list(writer, DriverVar, &driver->variables);
- LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
- DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
- if (dtar->rna_path) {
- BLO_write_string(writer, dtar->rna_path);
- }
- }
- DRIVER_TARGETS_LOOPER_END;
- }
- }
-
- /* write F-Modifiers */
- write_fmodifiers(writer, &fcu->modifiers);
- }
-}
-
static void write_action(BlendWriter *writer, bAction *act, const void *id_address)
{
if (act->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, bAction, id_address, &act->id);
write_iddata(writer, &act->id);
- write_fcurves(writer, &act->curves);
+ BKE_fcurve_blend_write(writer, &act->curves);
LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
BLO_write_struct(writer, bActionGroup, grp);
@@ -838,8 +749,8 @@ static void write_nlastrips(BlendWriter *writer, ListBase *strips)
BLO_write_struct_list(writer, NlaStrip, strips);
LISTBASE_FOREACH (NlaStrip *, strip, strips) {
/* write the strip's F-Curves and modifiers */
- write_fcurves(writer, &strip->fcurves);
- write_fmodifiers(writer, &strip->modifiers);
+ BKE_fcurve_blend_write(writer, &strip->fcurves);
+ BKE_fmodifiers_blend_write(writer, &strip->modifiers);
/* write the strip's children */
write_nlastrips(writer, &strip->strips);
@@ -864,7 +775,7 @@ static void write_animdata(BlendWriter *writer, AnimData *adt)
BLO_write_struct(writer, AnimData, adt);
/* write drivers */
- write_fcurves(writer, &adt->drivers);
+ BKE_fcurve_blend_write(writer, &adt->drivers);
/* write overrides */
// FIXME: are these needed?