diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-28 17:10:17 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-28 17:10:17 +0300 |
commit | 7b2fe4c9ec683bb7da270a54c44d301016e1470d (patch) | |
tree | 962c85e56ae3c2be6a6a8ce1ba22d14765860d80 /source/blender/blenkernel/intern/lattice.c | |
parent | 8815996418f0259b9abb9446da9bc137145de7d6 (diff) |
Refactor: move Lattice .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender/blenkernel/intern/lattice.c')
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 5782fab905f..7304dd91eea 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -35,6 +35,9 @@ #include "BLT_translation.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_curve_types.h" #include "DNA_defaults.h" #include "DNA_key_types.h" @@ -43,7 +46,9 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "BKE_anim_data.h" #include "BKE_curve.h" +#include "BKE_deform.h" #include "BKE_displist.h" #include "BKE_idtype.h" #include "BKE_lattice.h" @@ -53,10 +58,10 @@ #include "BKE_modifier.h" #include "BKE_object.h" -#include "BKE_deform.h" - #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + static void lattice_init_data(ID *id) { Lattice *lattice = (Lattice *)id; @@ -124,6 +129,59 @@ static void lattice_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS(data, lattice->key, IDWALK_CB_USER); } +static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Lattice *lt = (Lattice *)id; + if (lt->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + lt->editlatt = NULL; + lt->batch_cache = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, Lattice, id_address, <->id); + BKE_id_blend_write(writer, <->id); + + /* write animdata */ + if (lt->adt) { + BKE_animdata_blend_write(writer, lt->adt); + } + + /* direct data */ + BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def); + + BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); + } +} + +static void lattice_blend_read_data(BlendDataReader *reader, ID *id) +{ + Lattice *lt = (Lattice *)id; + BLO_read_data_address(reader, <->def); + + BLO_read_data_address(reader, <->dvert); + BKE_defvert_blend_read(reader, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); + + lt->editlatt = NULL; + lt->batch_cache = NULL; + + BLO_read_data_address(reader, <->adt); + BKE_animdata_blend_read_data(reader, lt->adt); +} + +static void lattice_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Lattice *lt = (Lattice *)id; + BLO_read_id_address(reader, lt->id.lib, <->ipo); // XXX deprecated - old animation system + BLO_read_id_address(reader, lt->id.lib, <->key); +} + +static void lattice_blend_read_expand(BlendExpander *expander, ID *id) +{ + Lattice *lt = (Lattice *)id; + BLO_expand(expander, lt->ipo); // XXX deprecated - old animation system + BLO_expand(expander, lt->key); +} + IDTypeInfo IDType_ID_LT = { .id_code = ID_LT, .id_filter = FILTER_ID_LT, @@ -141,10 +199,10 @@ IDTypeInfo IDType_ID_LT = { .foreach_id = lattice_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = lattice_blend_write, + .blend_read_data = lattice_blend_read_data, + .blend_read_lib = lattice_blend_read_lib, + .blend_read_expand = lattice_blend_read_expand, }; int BKE_lattice_index_from_uvw(Lattice *lt, const int u, const int v, const int w) |