diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 17:37:11 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 17:37:11 +0300 |
commit | 89b570570acdcf2648380fea9ab039d39f5d2693 (patch) | |
tree | aafb5f44f1b17b1d2c23546220ec4cce4a43247f /source/blender/blenkernel/intern/mball.c | |
parent | ea1094bdb0419b97174dd95a5887cd6cf2732d22 (diff) |
Refactor: move MetaBall .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender/blenkernel/intern/mball.c')
-rw-r--r-- | source/blender/blenkernel/intern/mball.c | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 2a1ac12baaa..d71c100ed87 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -35,6 +35,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_defaults.h" #include "DNA_material_types.h" #include "DNA_meta_types.h" @@ -50,6 +53,7 @@ #include "BKE_main.h" +#include "BKE_anim_data.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_idtype.h" @@ -62,6 +66,8 @@ #include "DEG_depsgraph.h" +#include "BLO_read_write.h" + static void metaball_init_data(ID *id) { MetaBall *metaball = (MetaBall *)id; @@ -110,6 +116,71 @@ static void metaball_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + MetaBall *mb = (MetaBall *)id; + if (mb->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + BLI_listbase_clear(&mb->disp); + mb->editelems = NULL; + /* Must always be cleared (meta's don't have their own edit-data). */ + mb->needs_flush_to_id = 0; + mb->lastelem = NULL; + mb->batch_cache = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, MetaBall, id_address, &mb->id); + BKE_id_blend_write(writer, &mb->id); + + /* direct data */ + BLO_write_pointer_array(writer, mb->totcol, mb->mat); + if (mb->adt) { + BKE_animdata_blend_write(writer, mb->adt); + } + + LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { + BLO_write_struct(writer, MetaElem, ml); + } + } +} + +static void metaball_blend_read_data(BlendDataReader *reader, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + BLO_read_data_address(reader, &mb->adt); + BKE_animdata_blend_read_data(reader, mb->adt); + + BLO_read_pointer_array(reader, (void **)&mb->mat); + + BLO_read_list(reader, &(mb->elems)); + + BLI_listbase_clear(&mb->disp); + mb->editelems = NULL; + /* Must always be cleared (meta's don't have their own edit-data). */ + mb->needs_flush_to_id = 0; + /* mb->edit_elems.first= mb->edit_elems.last= NULL;*/ + mb->lastelem = NULL; + mb->batch_cache = NULL; +} + +static void metaball_blend_read_lib(BlendLibReader *reader, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + for (int a = 0; a < mb->totcol; a++) { + BLO_read_id_address(reader, mb->id.lib, &mb->mat[a]); + } + + BLO_read_id_address(reader, mb->id.lib, &mb->ipo); // XXX deprecated - old animation system +} + +static void metaball_blend_read_expand(BlendExpander *expander, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + for (int a = 0; a < mb->totcol; a++) { + BLO_expand(expander, mb->mat[a]); + } +} + IDTypeInfo IDType_ID_MB = { .id_code = ID_MB, .id_filter = FILTER_ID_MB, @@ -127,10 +198,10 @@ IDTypeInfo IDType_ID_MB = { .foreach_id = metaball_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = metaball_blend_write, + .blend_read_data = metaball_blend_read_data, + .blend_read_lib = metaball_blend_read_lib, + .blend_read_expand = metaball_blend_read_expand, }; /* Functions */ |