From bed634c4f96cac7b1afaccc1ff646fc22f3efb29 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 21 Aug 2020 15:42:26 +0200 Subject: Refactor: move nla code from blenloader to blenkernel --- source/blender/blenkernel/intern/nla.c | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index e5527ed987a..9f5ca1d9b0e 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -54,6 +54,8 @@ #include "BKE_nla.h" #include "BKE_sound.h" +#include "BLO_read_write.h" + #include "RNA_access.h" #include "nla_private.h" @@ -2190,3 +2192,103 @@ void BKE_nla_tweakmode_exit(AnimData *adt) adt->actstrip = NULL; adt->flag &= ~ADT_NLA_EDIT_ON; } + +static void blend_write_nla_strips(BlendWriter *writer, ListBase *strips) +{ + BLO_write_struct_list(writer, NlaStrip, strips); + LISTBASE_FOREACH (NlaStrip *, strip, strips) { + /* write the strip's F-Curves and modifiers */ + BKE_fcurve_blend_write(writer, &strip->fcurves); + BKE_fmodifiers_blend_write(writer, &strip->modifiers); + + /* write the strip's children */ + blend_write_nla_strips(writer, &strip->strips); + } +} + +static void blend_data_read_nla_strips(BlendDataReader *reader, ListBase *strips) +{ + LISTBASE_FOREACH (NlaStrip *, strip, strips) { + /* strip's child strips */ + BLO_read_list(reader, &strip->strips); + blend_data_read_nla_strips(reader, &strip->strips); + + /* strip's F-Curves */ + BLO_read_list(reader, &strip->fcurves); + BKE_fcurve_blend_data_read(reader, &strip->fcurves); + + /* strip's F-Modifiers */ + BLO_read_list(reader, &strip->modifiers); + BKE_fmodifiers_blend_data_read(reader, &strip->modifiers, NULL); + } +} + +static void blend_lib_read_nla_strips(BlendLibReader *reader, ID *id, ListBase *strips) +{ + LISTBASE_FOREACH (NlaStrip *, strip, strips) { + /* check strip's children */ + blend_lib_read_nla_strips(reader, id, &strip->strips); + + /* check strip's F-Curves */ + BKE_fcurve_blend_lib_read(reader, id, &strip->fcurves); + + /* reassign the counted-reference to action */ + BLO_read_id_address(reader, id->lib, &strip->act); + } +} + +static void blend_expand_nla_strips(BlendExpander *expander, ListBase *strips) +{ + LISTBASE_FOREACH (NlaStrip *, strip, strips) { + /* check child strips */ + blend_expand_nla_strips(expander, &strip->strips); + + /* check F-Curves */ + BKE_fcurve_blend_expand(expander, &strip->fcurves); + + /* check F-Modifiers */ + BKE_fmodifiers_blend_expand(expander, &strip->modifiers); + + /* relink referenced action */ + BLO_expand(expander, strip->act); + } +} + +void BKE_nla_blend_write(BlendWriter *writer, ListBase *tracks) +{ + /* write all the tracks */ + LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { + /* write the track first */ + BLO_write_struct(writer, NlaTrack, nlt); + + /* write the track's strips */ + blend_write_nla_strips(writer, &nlt->strips); + } +} + +void BKE_nla_blend_data_read(BlendDataReader *reader, ListBase *tracks) +{ + LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { + /* relink list of strips */ + BLO_read_list(reader, &nlt->strips); + + /* relink strip data */ + blend_data_read_nla_strips(reader, &nlt->strips); + } +} + +void BKE_nla_blend_lib_read(BlendLibReader *reader, ID *id, ListBase *tracks) +{ + /* we only care about the NLA strips inside the tracks */ + LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { + blend_lib_read_nla_strips(reader, id, &nlt->strips); + } +} + +void BKE_nla_blend_expand(struct BlendExpander *expander, struct ListBase *tracks) +{ + /* nla-data - referenced actions */ + LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { + blend_expand_nla_strips(expander, &nlt->strips); + } +} -- cgit v1.2.3