From 12693b807ec0f3daf16f05ae621c7aec98ce2c61 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 11 Sep 2020 11:39:06 +0200 Subject: Refactor: move Volume .blend I/O to IDTypeInfo callbacks --- source/blender/blenkernel/intern/volume.cc | 65 ++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern/volume.cc') diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index f99be2f6aee..eb871e41f8e 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -51,6 +51,8 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + #include "CLG_log.h" #ifdef WITH_OPENVDB @@ -509,6 +511,61 @@ static void volume_foreach_cache(ID *id, function_callback(id, &key, (void **)&volume->runtime.grids, 0, user_data); } +static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Volume *volume = (Volume *)id; + if (volume->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + volume->runtime.grids = 0; + + /* write LibData */ + BLO_write_id_struct(writer, Volume, id_address, &volume->id); + BKE_id_blend_write(writer, &volume->id); + + /* direct data */ + BLO_write_pointer_array(writer, volume->totcol, volume->mat); + if (volume->adt) { + BKE_animdata_blend_write(writer, volume->adt); + } + + BKE_packedfile_blend_write(writer, volume->packedfile); + } +} + +static void volume_blend_read_data(BlendDataReader *reader, ID *id) +{ + Volume *volume = (Volume *)id; + BLO_read_data_address(reader, &volume->adt); + BKE_animdata_blend_read_data(reader, volume->adt); + + BKE_packedfile_blend_read(reader, &volume->packedfile); + volume->runtime.frame = 0; + + /* materials */ + BLO_read_pointer_array(reader, (void **)&volume->mat); +} + +static void volume_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Volume *volume = (Volume *)id; + /* Needs to be done *after* cache pointers are restored (call to + * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in + * lib_link... */ + BKE_volume_init_grids(volume); + + for (int a = 0; a < volume->totcol; a++) { + BLO_read_id_address(reader, volume->id.lib, &volume->mat[a]); + } +} + +static void volume_blend_read_expand(BlendExpander *expander, ID *id) +{ + Volume *volume = (Volume *)id; + for (int a = 0; a < volume->totcol; a++) { + BLO_expand(expander, volume->mat[a]); + } +} + IDTypeInfo IDType_ID_VO = { /* id_code */ ID_VO, /* id_filter */ FILTER_ID_VO, @@ -526,10 +583,10 @@ IDTypeInfo IDType_ID_VO = { /* foreach_id */ volume_foreach_id, /* foreach_cache */ volume_foreach_cache, - /* blend_write */ NULL, - /* blend_read_data */ NULL, - /* blend_read_lib */ NULL, - /* blend_read_expand */ NULL, + /* blend_write */ volume_blend_write, + /* blend_read_data */ volume_blend_read_data, + /* blend_read_lib */ volume_blend_read_lib, + /* blend_read_expand */ volume_blend_read_expand, }; void BKE_volume_init_grids(Volume *volume) -- cgit v1.2.3