Refactor: move nla code from blenloader to blenkernel
This commit is contained in:
@@ -38,6 +38,10 @@ struct bAction;
|
||||
|
||||
struct PointerRNA;
|
||||
struct PropertyRNA;
|
||||
struct BlendWriter;
|
||||
struct BlendDataReader;
|
||||
struct BlendLibReader;
|
||||
struct BlendExpander;
|
||||
|
||||
/* ----------------------------- */
|
||||
/* Data Management */
|
||||
@@ -146,6 +150,14 @@ enum eNlaTime_ConvertModes {
|
||||
|
||||
float BKE_nla_tweakedit_remap(struct AnimData *adt, float cframe, short mode);
|
||||
|
||||
/* ----------------------------- */
|
||||
/* .blend file API */
|
||||
|
||||
void BKE_nla_blend_write(struct BlendWriter *writer, struct ListBase *tracks);
|
||||
void BKE_nla_blend_data_read(struct BlendDataReader *reader, struct ListBase *tracks);
|
||||
void BKE_nla_blend_lib_read(struct BlendLibReader *reader, struct ID *id, struct ListBase *tracks);
|
||||
void BKE_nla_blend_expand(struct BlendExpander *expander, struct ListBase *tracks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_multires.h"
|
||||
#include "BKE_nla.h"
|
||||
#include "BKE_node.h" // for tree type defines
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_paint.h"
|
||||
@@ -2757,60 +2758,6 @@ static void direct_link_action(BlendDataReader *reader, bAction *act)
|
||||
}
|
||||
}
|
||||
|
||||
static void lib_link_nladata_strips(BlendLibReader *reader, ID *id, ListBase *list)
|
||||
{
|
||||
LISTBASE_FOREACH (NlaStrip *, strip, list) {
|
||||
/* check strip's children */
|
||||
lib_link_nladata_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 lib_link_nladata(BlendLibReader *reader, ID *id, ListBase *list)
|
||||
{
|
||||
/* we only care about the NLA strips inside the tracks */
|
||||
LISTBASE_FOREACH (NlaTrack *, nlt, list) {
|
||||
lib_link_nladata_strips(reader, id, &nlt->strips);
|
||||
}
|
||||
}
|
||||
|
||||
/* This handles Animato NLA-Strips linking
|
||||
* NOTE: this assumes that link_list has already been called on the list
|
||||
*/
|
||||
static void direct_link_nladata_strips(BlendDataReader *reader, ListBase *list)
|
||||
{
|
||||
LISTBASE_FOREACH (NlaStrip *, strip, list) {
|
||||
/* strip's child strips */
|
||||
BLO_read_list(reader, &strip->strips);
|
||||
direct_link_nladata_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);
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE: this assumes that BLO_read_list has already been called on the list */
|
||||
static void direct_link_nladata(BlendDataReader *reader, ListBase *list)
|
||||
{
|
||||
LISTBASE_FOREACH (NlaTrack *, nlt, list) {
|
||||
/* relink list of strips */
|
||||
BLO_read_list(reader, &nlt->strips);
|
||||
|
||||
/* relink strip data */
|
||||
direct_link_nladata_strips(reader, &nlt->strips);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------- */
|
||||
|
||||
static void lib_link_keyingsets(BlendLibReader *reader, ID *id, ListBase *list)
|
||||
@@ -2856,7 +2803,7 @@ static void lib_link_animdata(BlendLibReader *reader, ID *id, AnimData *adt)
|
||||
/* overrides don't have lib-link for now, so no need to do anything */
|
||||
|
||||
/* link NLA-data */
|
||||
lib_link_nladata(reader, id, &adt->nla_tracks);
|
||||
BKE_nla_blend_lib_read(reader, id, &adt->nla_tracks);
|
||||
}
|
||||
|
||||
static void direct_link_animdata(BlendDataReader *reader, AnimData *adt)
|
||||
@@ -2876,7 +2823,7 @@ static void direct_link_animdata(BlendDataReader *reader, AnimData *adt)
|
||||
|
||||
/* link NLA-data */
|
||||
BLO_read_list(reader, &adt->nla_tracks);
|
||||
direct_link_nladata(reader, &adt->nla_tracks);
|
||||
BKE_nla_blend_data_read(reader, &adt->nla_tracks);
|
||||
|
||||
/* relink active track/strip - even though strictly speaking this should only be used
|
||||
* if we're in 'tweaking mode', we need to be able to have this loaded back for
|
||||
@@ -9777,23 +9724,6 @@ static void expand_constraint_channels(BlendExpander *expander, ListBase *chanba
|
||||
}
|
||||
}
|
||||
|
||||
static void expand_animdata_nlastrips(BlendExpander *expander, ListBase *list)
|
||||
{
|
||||
LISTBASE_FOREACH (NlaStrip *, strip, list) {
|
||||
/* check child strips */
|
||||
expand_animdata_nlastrips(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);
|
||||
}
|
||||
}
|
||||
|
||||
static void expand_animdata(BlendExpander *expander, AnimData *adt)
|
||||
{
|
||||
/* own action */
|
||||
@@ -9802,11 +9732,6 @@ static void expand_animdata(BlendExpander *expander, AnimData *adt)
|
||||
|
||||
/* drivers - assume that these F-Curves have driver data to be in this list... */
|
||||
BKE_fcurve_blend_expand(expander, &adt->drivers);
|
||||
|
||||
/* nla-data - referenced actions */
|
||||
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
|
||||
expand_animdata_nlastrips(expander, &nlt->strips);
|
||||
}
|
||||
}
|
||||
|
||||
static void expand_id(BlendExpander *expander, ID *id);
|
||||
|
||||
@@ -171,6 +171,7 @@
|
||||
#include "BKE_lib_override.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_nla.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_pointcache.h"
|
||||
@@ -744,31 +745,6 @@ static void write_keyingsets(BlendWriter *writer, ListBase *list)
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
BKE_fcurve_blend_write(writer, &strip->fcurves);
|
||||
BKE_fmodifiers_blend_write(writer, &strip->modifiers);
|
||||
|
||||
/* write the strip's children */
|
||||
write_nlastrips(writer, &strip->strips);
|
||||
}
|
||||
}
|
||||
|
||||
static void write_nladata(BlendWriter *writer, ListBase *nlabase)
|
||||
{
|
||||
/* write all the tracks */
|
||||
LISTBASE_FOREACH (NlaTrack *, nlt, nlabase) {
|
||||
/* write the track first */
|
||||
BLO_write_struct(writer, NlaTrack, nlt);
|
||||
|
||||
/* write the track's strips */
|
||||
write_nlastrips(writer, &nlt->strips);
|
||||
}
|
||||
}
|
||||
|
||||
static void write_animdata(BlendWriter *writer, AnimData *adt)
|
||||
{
|
||||
/* firstly, just write the AnimData block */
|
||||
@@ -788,7 +764,7 @@ static void write_animdata(BlendWriter *writer, AnimData *adt)
|
||||
// TODO write the remaps (if they are needed)
|
||||
|
||||
/* write NLA data */
|
||||
write_nladata(writer, &adt->nla_tracks);
|
||||
BKE_nla_blend_write(writer, &adt->nla_tracks);
|
||||
}
|
||||
|
||||
static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock)
|
||||
|
||||
Reference in New Issue
Block a user