diff options
author | Hans Goudey <h.goudey@me.com> | 2020-09-13 01:42:27 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-09-13 01:42:27 +0300 |
commit | 3eaca737531a917e60350bd74d52849b612831da (patch) | |
tree | 8950b659cbafcaa55e4ebfee64999a2fc382a606 /source/blender/blenkernel | |
parent | 5545d833154e017f3948db9970b8d770ea8e8f9b (diff) | |
parent | 8f6740b2754ff1f5c936ee95e2cd7ed837627608 (diff) |
Merge branch 'property-search-single-tab' into property-search-start-end-operators
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_customdata.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_gpencil.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 16 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cachefile.c | 38 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 164 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/gpencil_geom.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/hair.c | 77 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image_gpu.c | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pointcloud.c | 72 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/simulation.cc | 98 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 71 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/texture.c | 70 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/volume.cc | 65 |
16 files changed, 656 insertions, 58 deletions
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index d21fe5afa7e..fea9bbe9bb5 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -570,9 +570,9 @@ void CustomData_data_transfer(const struct MeshPairRemap *me_remap, /* .blend file I/O */ void CustomData_blend_write_prepare(struct CustomData *data, - struct CustomDataLayer **r_write_layers, - struct CustomDataLayer *write_layers_buff, - size_t write_layers_size); + struct CustomDataLayer **r_write_layers, + struct CustomDataLayer *write_layers_buff, + size_t write_layers_size); void CustomData_blend_write(struct BlendWriter *writer, struct CustomData *data, diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 88eef40ebd2..f1912b14e8c 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -48,6 +48,7 @@ struct bGPDlayer_Mask; struct bGPDspoint; struct bGPDstroke; struct bGPdata; +struct BlendDataReader; #define GPENCIL_SIMPLIFY(scene) ((scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_ENABLE)) #define GPENCIL_SIMPLIFY_ONPLAY(playing) \ @@ -281,6 +282,8 @@ void BKE_gpencil_parent_matrix_get(const struct Depsgraph *depsgraph, void BKE_gpencil_update_layer_parent(const struct Depsgraph *depsgraph, struct Object *ob); +void BKE_gpencil_blend_read_data(struct BlendDataReader *reader, struct bGPdata *gpd); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5e8b371e604..3421aa9e900 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -254,23 +254,23 @@ typedef struct bNodeType { * \note Used as a fallback when #bNode.label isn't set. */ void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); - /// Optional custom resize handle polling. + /** Optional custom resize handle polling. */ int (*resize_area_func)(struct bNode *node, int x, int y); - /// Optional selection area polling. + /** Optional selection area polling. */ int (*select_area_func)(struct bNode *node, int x, int y); - /// Optional tweak area polling (for grabbing). + /** Optional tweak area polling (for grabbing). */ int (*tweak_area_func)(struct bNode *node, int x, int y); - /// Called when the node is updated in the editor. + /** Called when the node is updated in the editor. */ void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node); - /// Check and update if internal ID data has changed. + /** Check and update if internal ID data has changed. */ void (*group_update_func)(struct bNodeTree *ntree, struct bNode *node); - /// Initialize a new node instance of this type after creation. + /** Initialize a new node instance of this type after creation. */ void (*initfunc)(struct bNodeTree *ntree, struct bNode *node); - /// Free the node instance. + /** Free the node instance. */ void (*freefunc)(struct bNode *node); - /// Make a copy of the node instance. + /** Make a copy of the node instance. */ void (*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index cf43d0fe845..cc5226a1ab7 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -57,7 +57,6 @@ set(INC ) set(INC_SYS - ${GLEW_INCLUDE_PATH} ${ZLIB_INCLUDE_DIRS} ) @@ -457,7 +456,6 @@ if(WITH_BINRELOC) add_definitions(-DWITH_BINRELOC) endif() -add_definitions(${GL_DEFINITIONS}) if(WIN32) list(APPEND INC diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index f3386df03c8..9475ba7efcf 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -39,6 +39,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_cachefile.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" @@ -48,6 +49,8 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + #ifdef WITH_ALEMBIC # include "ABC_alembic.h" #endif @@ -85,6 +88,37 @@ static void cache_file_free_data(ID *id) BLI_freelistN(&cache_file->object_paths); } +static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + CacheFile *cache_file = (CacheFile *)id; + if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + BLI_listbase_clear(&cache_file->object_paths); + cache_file->handle = NULL; + memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath)); + cache_file->handle_readers = NULL; + + BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id); + + if (cache_file->adt) { + BKE_animdata_blend_write(writer, cache_file->adt); + } + } +} + +static void cache_file_blend_read_data(BlendDataReader *reader, ID *id) +{ + CacheFile *cache_file = (CacheFile *)id; + BLI_listbase_clear(&cache_file->object_paths); + cache_file->handle = NULL; + cache_file->handle_filepath[0] = '\0'; + cache_file->handle_readers = NULL; + + /* relink animdata */ + BLO_read_data_address(reader, &cache_file->adt); + BKE_animdata_blend_read_data(reader, cache_file->adt); +} + IDTypeInfo IDType_ID_CF = { .id_code = ID_CF, .id_filter = FILTER_ID_CF, @@ -102,8 +136,8 @@ IDTypeInfo IDType_ID_CF = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = cache_file_blend_write, + .blend_read_data = cache_file_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index e7fe10cf19c..fc1b4d82c20 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -845,7 +845,8 @@ static void childof_new_data(void *cdata) bChildOfConstraint *data = (bChildOfConstraint *)cdata; data->flag = (CHILDOF_LOCX | CHILDOF_LOCY | CHILDOF_LOCZ | CHILDOF_ROTX | CHILDOF_ROTY | - CHILDOF_ROTZ | CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ); + CHILDOF_ROTZ | CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ | + CHILDOF_SET_INVERSE); unit_m4(data->invmat); } diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 1e37ae3892b..03ac7e622e1 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -40,12 +40,16 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_gpencil_types.h" #include "DNA_material_types.h" #include "DNA_meshdata_types.h" #include "DNA_space_types.h" #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_collection.h" #include "BKE_colortools.h" #include "BKE_deform.h" @@ -64,6 +68,10 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + +#include "BKE_gpencil.h" + static CLG_LogRef LOG = {"bke.gpencil"}; static void greasepencil_copy_data(Main *UNUSED(bmain), @@ -111,6 +119,154 @@ static void greasepencil_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bGPdata *gpd = (bGPdata *)id; + if (gpd->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed data-blocks. */ + /* XXX not sure why the whole run-time data is not cleared in reading code, + * for now mimicking it here. */ + gpd->runtime.sbuffer = NULL; + gpd->runtime.sbuffer_used = 0; + gpd->runtime.sbuffer_size = 0; + gpd->runtime.tot_cp_points = 0; + + /* write gpd data block to file */ + BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id); + BKE_id_blend_write(writer, &gpd->id); + + if (gpd->adt) { + BKE_animdata_blend_write(writer, gpd->adt); + } + + BLO_write_pointer_array(writer, gpd->totcol, gpd->mat); + + /* write grease-pencil layers to file */ + BLO_write_struct_list(writer, bGPDlayer, &gpd->layers); + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + /* Write mask list. */ + BLO_write_struct_list(writer, bGPDlayer_Mask, &gpl->mask_layers); + /* write this layer's frames to file */ + BLO_write_struct_list(writer, bGPDframe, &gpl->frames); + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + /* write strokes */ + BLO_write_struct_list(writer, bGPDstroke, &gpf->strokes); + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points); + BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles); + BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert); + } + } + } + } +} + +void BKE_gpencil_blend_read_data(BlendDataReader *reader, bGPdata *gpd) +{ + /* we must firstly have some grease-pencil data to link! */ + if (gpd == NULL) { + return; + } + + /* relink animdata */ + BLO_read_data_address(reader, &gpd->adt); + BKE_animdata_blend_read_data(reader, gpd->adt); + + /* Ensure full objectmode for linked grease pencil. */ + if (gpd->id.lib != NULL) { + gpd->flag &= ~GP_DATA_STROKE_PAINTMODE; + gpd->flag &= ~GP_DATA_STROKE_EDITMODE; + gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE; + gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE; + gpd->flag &= ~GP_DATA_STROKE_VERTEXMODE; + } + + /* init stroke buffer */ + gpd->runtime.sbuffer = NULL; + gpd->runtime.sbuffer_used = 0; + gpd->runtime.sbuffer_size = 0; + gpd->runtime.tot_cp_points = 0; + + /* relink palettes (old palettes deprecated, only to convert old files) */ + BLO_read_list(reader, &gpd->palettes); + if (gpd->palettes.first != NULL) { + LISTBASE_FOREACH (Palette *, palette, &gpd->palettes) { + BLO_read_list(reader, &palette->colors); + } + } + + /* materials */ + BLO_read_pointer_array(reader, (void **)&gpd->mat); + + /* relink layers */ + BLO_read_list(reader, &gpd->layers); + + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + /* relink frames */ + BLO_read_list(reader, &gpl->frames); + + BLO_read_data_address(reader, &gpl->actframe); + + gpl->runtime.icon_id = 0; + + /* Relink masks. */ + BLO_read_list(reader, &gpl->mask_layers); + + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + /* relink strokes (and their points) */ + BLO_read_list(reader, &gpf->strokes); + + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + /* relink stroke points array */ + BLO_read_data_address(reader, &gps->points); + /* Relink geometry*/ + BLO_read_data_address(reader, &gps->triangles); + + /* relink weight data */ + if (gps->dvert) { + BLO_read_data_address(reader, &gps->dvert); + BKE_defvert_blend_read(reader, gps->totpoints, gps->dvert); + } + } + } + } +} + +static void greasepencil_blend_read_data(BlendDataReader *reader, ID *id) +{ + bGPdata *gpd = (bGPdata *)id; + BKE_gpencil_blend_read_data(reader, gpd); +} + +static void greasepencil_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bGPdata *gpd = (bGPdata *)id; + + /* Relink all data-lock linked by GP data-lock */ + /* Layers */ + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + /* Layer -> Parent References */ + BLO_read_id_address(reader, gpd->id.lib, &gpl->parent); + } + + /* materials */ + for (int a = 0; a < gpd->totcol; a++) { + BLO_read_id_address(reader, gpd->id.lib, &gpd->mat[a]); + } +} + +static void greasepencil_blend_read_expand(BlendExpander *expander, ID *id) +{ + bGPdata *gpd = (bGPdata *)id; + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + BLO_expand(expander, gpl->parent); + } + + for (int a = 0; a < gpd->totcol; a++) { + BLO_expand(expander, gpd->mat[a]); + } +} + IDTypeInfo IDType_ID_GD = { .id_code = ID_GD, .id_filter = FILTER_ID_GD, @@ -128,10 +284,10 @@ IDTypeInfo IDType_ID_GD = { .foreach_id = greasepencil_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = greasepencil_blend_write, + .blend_read_data = greasepencil_blend_read_data, + .blend_read_lib = greasepencil_blend_read_lib, + .blend_read_expand = greasepencil_blend_read_expand, }; /* ************************************************** */ diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c index 83e3a3098e9..a9b0eede055 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.c +++ b/source/blender/blenkernel/intern/gpencil_geom.c @@ -2264,17 +2264,16 @@ static int gpencil_material_find_index_by_name(Object *ob, const char *name) return -1; } -/* Create the name with the object name and a subfix. */ -static void make_element_name(char *obname, char *name, const int maxlen, char *r_name) +/** + * Create the name with the object name and a suffix. + */ +static void make_element_name(const char *obname, const char *name, const int maxlen, char *r_name) { char str[256]; - sprintf(str, "%s_%s", obname, name); + SNPRINTF(str, "%s_%s", obname, name); + /* Replace any point by underscore. */ - char *current_pos = strchr(str, '.'); - while (current_pos) { - *current_pos = '_'; - current_pos = strchr(current_pos, '.'); - } + BLI_str_replace_char(str, '.', '_'); BLI_strncpy_utf8(r_name, str, maxlen); } diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c index 314b7228373..57997eaf3a1 100644 --- a/source/blender/blenkernel/intern/hair.c +++ b/source/blender/blenkernel/intern/hair.c @@ -47,8 +47,10 @@ #include "DEG_depsgraph_query.h" -const char *HAIR_ATTR_POSITION = "Position"; -const char *HAIR_ATTR_RADIUS = "Radius"; +#include "BLO_read_write.h" + +static const char *HAIR_ATTR_POSITION = "Position"; +static const char *HAIR_ATTR_RADIUS = "Radius"; /* Hair datablock */ @@ -109,6 +111,69 @@ static void hair_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Hair *hair = (Hair *)id; + if (hair->id.us > 0 || BLO_write_is_undo(writer)) { + CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; + CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); + CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff)); + + /* Write LibData */ + BLO_write_id_struct(writer, Hair, id_address, &hair->id); + BKE_id_blend_write(writer, &hair->id); + + /* Direct data */ + CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id); + CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id); + + BLO_write_pointer_array(writer, hair->totcol, hair->mat); + if (hair->adt) { + BKE_animdata_blend_write(writer, hair->adt); + } + + /* Remove temporary data. */ + if (players && players != players_buff) { + MEM_freeN(players); + } + if (clayers && clayers != clayers_buff) { + MEM_freeN(clayers); + } + } +} + +static void hair_blend_read_data(BlendDataReader *reader, ID *id) +{ + Hair *hair = (Hair *)id; + BLO_read_data_address(reader, &hair->adt); + BKE_animdata_blend_read_data(reader, hair->adt); + + /* Geometry */ + CustomData_blend_read(reader, &hair->pdata, hair->totpoint); + CustomData_blend_read(reader, &hair->cdata, hair->totcurve); + BKE_hair_update_customdata_pointers(hair); + + /* Materials */ + BLO_read_pointer_array(reader, (void **)&hair->mat); +} + +static void hair_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Hair *hair = (Hair *)id; + for (int a = 0; a < hair->totcol; a++) { + BLO_read_id_address(reader, hair->id.lib, &hair->mat[a]); + } +} + +static void hair_blend_read_expand(BlendExpander *expander, ID *id) +{ + Hair *hair = (Hair *)id; + for (int a = 0; a < hair->totcol; a++) { + BLO_expand(expander, hair->mat[a]); + } +} + IDTypeInfo IDType_ID_HA = { .id_code = ID_HA, .id_filter = FILTER_ID_HA, @@ -126,10 +191,10 @@ IDTypeInfo IDType_ID_HA = { .foreach_id = hair_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = hair_blend_write, + .blend_read_data = hair_blend_read_data, + .blend_read_lib = hair_blend_read_lib, + .blend_read_expand = hair_blend_read_expand, }; static void hair_random(Hair *hair) diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c index d4a1c1e2c46..f37e038e69e 100644 --- a/source/blender/blenkernel/intern/image_gpu.c +++ b/source/blender/blenkernel/intern/image_gpu.c @@ -272,6 +272,13 @@ static GPUTexture *image_get_gpu_texture(Image *ima, * context and might as well ensure we have as much space free as possible. */ gpu_free_unused_buffers(); + /* Free GPU textures when requesting a different render pass/layer. */ + if (ima->gpu_pass != iuser->pass || ima->gpu_layer != iuser->layer) { + ima->gpu_pass = iuser->pass; + ima->gpu_layer = iuser->layer; + ima->gpuflag |= IMA_GPU_REFRESH; + } + /* currently, gpu refresh tagging is used by ima sequences */ if (ima->gpuflag & IMA_GPU_REFRESH) { image_free_gpu(ima, true); @@ -282,7 +289,10 @@ static GPUTexture *image_get_gpu_texture(Image *ima, BKE_image_tag_time(ima); /* Test if we already have a texture. */ - GPUTexture **tex = get_image_gpu_texture_ptr(ima, textarget, iuser ? iuser->multiview_eye : 0); + const int current_view = iuser ? ((iuser->flag & IMA_SHOW_STEREO) != 0 ? iuser->multiview_eye : + iuser->view) : + 0; + GPUTexture **tex = get_image_gpu_texture_ptr(ima, textarget, current_view); if (*tex) { return *tex; } diff --git a/source/blender/blenkernel/intern/pointcloud.c b/source/blender/blenkernel/intern/pointcloud.c index 087bf123575..6ec305a971c 100644 --- a/source/blender/blenkernel/intern/pointcloud.c +++ b/source/blender/blenkernel/intern/pointcloud.c @@ -47,12 +47,14 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + /* PointCloud datablock */ static void pointcloud_random(PointCloud *pointcloud); -const char *POINTCLOUD_ATTR_POSITION = "Position"; -const char *POINTCLOUD_ATTR_RADIUS = "Radius"; +static const char *POINTCLOUD_ATTR_POSITION = "Position"; +static const char *POINTCLOUD_ATTR_RADIUS = "Radius"; static void pointcloud_init_data(ID *id) { @@ -111,6 +113,64 @@ static void pointcloud_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + PointCloud *pointcloud = (PointCloud *)id; + if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) { + CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_blend_write_prepare( + &pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); + + /* Write LibData */ + BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id); + BKE_id_blend_write(writer, &pointcloud->id); + + /* Direct data */ + CustomData_blend_write( + writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id); + + BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat); + if (pointcloud->adt) { + BKE_animdata_blend_write(writer, pointcloud->adt); + } + + /* Remove temporary data. */ + if (players && players != players_buff) { + MEM_freeN(players); + } + } +} + +static void pointcloud_blend_read_data(BlendDataReader *reader, ID *id) +{ + PointCloud *pointcloud = (PointCloud *)id; + BLO_read_data_address(reader, &pointcloud->adt); + BKE_animdata_blend_read_data(reader, pointcloud->adt); + + /* Geometry */ + CustomData_blend_read(reader, &pointcloud->pdata, pointcloud->totpoint); + BKE_pointcloud_update_customdata_pointers(pointcloud); + + /* Materials */ + BLO_read_pointer_array(reader, (void **)&pointcloud->mat); +} + +static void pointcloud_blend_read_lib(BlendLibReader *reader, ID *id) +{ + PointCloud *pointcloud = (PointCloud *)id; + for (int a = 0; a < pointcloud->totcol; a++) { + BLO_read_id_address(reader, pointcloud->id.lib, &pointcloud->mat[a]); + } +} + +static void pointcloud_blend_read_expand(BlendExpander *expander, ID *id) +{ + PointCloud *pointcloud = (PointCloud *)id; + for (int a = 0; a < pointcloud->totcol; a++) { + BLO_expand(expander, pointcloud->mat[a]); + } +} + IDTypeInfo IDType_ID_PT = { .id_code = ID_PT, .id_filter = FILTER_ID_PT, @@ -128,10 +188,10 @@ IDTypeInfo IDType_ID_PT = { .foreach_id = pointcloud_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = pointcloud_blend_write, + .blend_read_data = pointcloud_blend_read_data, + .blend_read_lib = pointcloud_blend_read_lib, + .blend_read_expand = pointcloud_blend_read_expand, }; static void pointcloud_random(PointCloud *pointcloud) diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index 9dc1f073e2a..f08051510db 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -63,6 +63,8 @@ #include "SIM_simulation_update.hh" +#include "BLO_read_write.h" + using StateInitFunction = void (*)(SimulationState *state); using StateResetFunction = void (*)(SimulationState *state); using StateRemoveFunction = void (*)(SimulationState *state); @@ -145,6 +147,94 @@ static void simulation_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void simulation_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Simulation *simulation = (Simulation *)id; + if (simulation->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, Simulation, id_address, &simulation->id); + BKE_id_blend_write(writer, &simulation->id); + + if (simulation->adt) { + BKE_animdata_blend_write(writer, simulation->adt); + } + + /* nodetree is integral part of simulation, no libdata */ + if (simulation->nodetree) { + BLO_write_struct(writer, bNodeTree, simulation->nodetree); + ntreeBlendWrite(writer, simulation->nodetree); + } + + LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { + BLO_write_string(writer, state->name); + BLO_write_string(writer, state->type); + /* TODO: Decentralize this part. */ + if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { + ParticleSimulationState *particle_state = (ParticleSimulationState *)state; + + CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_blend_write_prepare( + &particle_state->attributes, &players, players_buff, ARRAY_SIZE(players_buff)); + + BLO_write_struct(writer, ParticleSimulationState, particle_state); + + CustomData_blend_write(writer, + &particle_state->attributes, + players, + particle_state->tot_particles, + CD_MASK_ALL, + &simulation->id); + + /* Remove temporary data. */ + if (players && players != players_buff) { + MEM_freeN(players); + } + } + else if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER)) { + ParticleMeshEmitterSimulationState *emitter_state = (ParticleMeshEmitterSimulationState *) + state; + BLO_write_struct(writer, ParticleMeshEmitterSimulationState, emitter_state); + } + } + + BLO_write_struct_list(writer, SimulationDependency, &simulation->dependencies); + } +} + +static void simulation_blend_read_data(BlendDataReader *reader, ID *id) +{ + Simulation *simulation = (Simulation *)id; + BLO_read_data_address(reader, &simulation->adt); + BKE_animdata_blend_read_data(reader, simulation->adt); + + BLO_read_list(reader, &simulation->states); + LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { + BLO_read_data_address(reader, &state->name); + BLO_read_data_address(reader, &state->type); + if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { + ParticleSimulationState *particle_state = (ParticleSimulationState *)state; + CustomData_blend_read(reader, &particle_state->attributes, particle_state->tot_particles); + } + } + + BLO_read_list(reader, &simulation->dependencies); +} + +static void simulation_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Simulation *simulation = (Simulation *)id; + LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { + BLO_read_id_address(reader, simulation->id.lib, &dependency->id); + } +} + +static void simulation_blend_read_expand(BlendExpander *expander, ID *id) +{ + Simulation *simulation = (Simulation *)id; + LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { + BLO_expand(expander, dependency->id); + } +} + IDTypeInfo IDType_ID_SIM = { /* id_code */ ID_SIM, /* id_filter */ FILTER_ID_SIM, @@ -162,10 +252,10 @@ IDTypeInfo IDType_ID_SIM = { /* foreach_id */ simulation_foreach_id, /* foreach_cache */ NULL, - /* blend_write */ NULL, - /* blend_read_data */ NULL, - /* blend_read_lib */ NULL, - /* blend_read_expand */ NULL, + /* blend_write */ simulation_blend_write, + /* blend_read_data */ simulation_blend_read_data, + /* blend_read_lib */ simulation_blend_read_lib, + /* blend_read_expand */ simulation_blend_read_expand, }; void *BKE_simulation_add(Main *bmain, const char *name) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 88b32e194cf..9cf5ef85850 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3014,7 +3014,7 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob) * * a: never ever make tangent handles (sub) and or (ob)ject to collision. * b: rather calculate them using some C2 - * (C2= continuous in second derivate -> no jump in bending ) condition. + * (C2= continuous in second derivative -> no jump in bending ) condition. * * Not too hard to do, but needs some more code to care for; * some one may want look at it (JOW 2010/06/12). */ diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 8ee6a3627dc..c8a31b51500 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -33,6 +33,9 @@ #include "BLT_translation.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_anim_types.h" #include "DNA_object_types.h" #include "DNA_packedFile_types.h" @@ -63,6 +66,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + static void sound_free_audio(bSound *sound); static void sound_copy_data(Main *UNUSED(bmain), @@ -126,6 +131,64 @@ static void sound_foreach_cache(ID *id, function_callback(id, &key, &sound->waveform, 0, user_data); } +static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bSound *sound = (bSound *)id; + if (sound->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + sound->tags = 0; + sound->handle = NULL; + sound->playback_handle = NULL; + sound->spinlock = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, bSound, id_address, &sound->id); + BKE_id_blend_write(writer, &sound->id); + + BKE_packedfile_blend_write(writer, sound->packedfile); + } +} + +static void sound_blend_read_data(BlendDataReader *reader, ID *id) +{ + bSound *sound = (bSound *)id; + sound->tags = 0; + sound->handle = NULL; + sound->playback_handle = NULL; + + /* versioning stuff, if there was a cache, then we enable caching: */ + if (sound->cache) { + sound->flags |= SOUND_FLAGS_CACHING; + sound->cache = NULL; + } + + if (BLO_read_data_is_undo(reader)) { + sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD; + } + + sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock"); + BLI_spin_init(sound->spinlock); + + /* clear waveform loading flag */ + sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING; + + BKE_packedfile_blend_read(reader, &sound->packedfile); + BKE_packedfile_blend_read(reader, &sound->newpackedfile); +} + +static void sound_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bSound *sound = (bSound *)id; + BLO_read_id_address( + reader, sound->id.lib, &sound->ipo); // XXX deprecated - old animation system +} + +static void sound_blend_read_expand(BlendExpander *expander, ID *id) +{ + bSound *snd = (bSound *)id; + BLO_expand(expander, snd->ipo); // XXX deprecated - old animation system +} + IDTypeInfo IDType_ID_SO = { .id_code = ID_SO, .id_filter = FILTER_ID_SO, @@ -144,10 +207,10 @@ IDTypeInfo IDType_ID_SO = { .foreach_id = NULL, .foreach_cache = sound_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = sound_blend_write, + .blend_read_data = sound_blend_read_data, + .blend_read_lib = sound_blend_read_lib, + .blend_read_expand = sound_blend_read_expand, }; #ifdef WITH_AUDASPACE diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 9e176f355d3..698f6b8cffd 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -36,6 +36,9 @@ #include "BLT_translation.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_brush_types.h" #include "DNA_color_types.h" #include "DNA_defaults.h" @@ -50,6 +53,7 @@ #include "BKE_main.h" +#include "BKE_anim_data.h" #include "BKE_colorband.h" #include "BKE_colortools.h" #include "BKE_icons.h" @@ -65,6 +69,8 @@ #include "RE_shader_ext.h" +#include "BLO_read_write.h" + static void texture_init_data(ID *id) { Tex *texture = (Tex *)id; @@ -134,6 +140,62 @@ static void texture_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS(data, texture->ima, IDWALK_CB_USER); } +static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Tex *tex = (Tex *)id; + if (tex->id.us > 0 || BLO_write_is_undo(writer)) { + /* write LibData */ + BLO_write_id_struct(writer, Tex, id_address, &tex->id); + BKE_id_blend_write(writer, &tex->id); + + if (tex->adt) { + BKE_animdata_blend_write(writer, tex->adt); + } + + /* direct data */ + if (tex->coba) { + BLO_write_struct(writer, ColorBand, tex->coba); + } + + /* nodetree is integral part of texture, no libdata */ + if (tex->nodetree) { + BLO_write_struct(writer, bNodeTree, tex->nodetree); + ntreeBlendWrite(writer, tex->nodetree); + } + + BKE_previewimg_blend_write(writer, tex->preview); + } +} + +static void texture_blend_read_data(BlendDataReader *reader, ID *id) +{ + Tex *tex = (Tex *)id; + BLO_read_data_address(reader, &tex->adt); + BKE_animdata_blend_read_data(reader, tex->adt); + + BLO_read_data_address(reader, &tex->coba); + + BLO_read_data_address(reader, &tex->preview); + BKE_previewimg_blend_read(reader, tex->preview); + + tex->iuser.ok = 1; + tex->iuser.scene = NULL; +} + +static void texture_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Tex *tex = (Tex *)id; + BLO_read_id_address(reader, tex->id.lib, &tex->ima); + BLO_read_id_address(reader, tex->id.lib, &tex->ipo); // XXX deprecated - old animation system +} + +static void texture_blend_read_expand(BlendExpander *expander, ID *id) +{ + Tex *tex = (Tex *)id; + BLO_expand(expander, tex->ima); + BLO_expand(expander, tex->ipo); // XXX deprecated - old animation system +} + IDTypeInfo IDType_ID_TE = { .id_code = ID_TE, .id_filter = FILTER_ID_TE, @@ -151,10 +213,10 @@ IDTypeInfo IDType_ID_TE = { .foreach_id = texture_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = texture_blend_write, + .blend_read_data = texture_blend_read_data, + .blend_read_lib = texture_blend_read_lib, + .blend_read_expand = texture_blend_read_expand, }; /* Utils for all IDs using those texture slots. */ 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) |