diff options
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 24 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.h | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile_tempload.c | 21 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_250.c | 3 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 14 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_290.c | 174 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_300.c | 263 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_legacy.c | 11 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_userdef.c | 43 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 1 |
10 files changed, 511 insertions, 45 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index b657cb8b2f9..47ed4e5c06f 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -62,6 +62,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" +#include "BLI_endian_defines.h" #include "BLI_endian_switch.h" #include "BLI_ghash.h" #include "BLI_linklist.h" @@ -111,6 +112,7 @@ #include "SEQ_iterator.h" #include "SEQ_modifier.h" #include "SEQ_sequencer.h" +#include "SEQ_utils.h" #include "readfile.h" @@ -2696,7 +2698,7 @@ static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt) static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map) { /* update IDs stored in sequencer clipboard */ - SEQ_iterator_seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); + SEQ_seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); } static int lib_link_main_data_restore_cb(LibraryIDLinkCallbackData *cb_data) @@ -2912,7 +2914,7 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, else if (sl->spacetype == SPACE_TEXT) { SpaceText *st = (SpaceText *)sl; - st->text = restore_pointer_by_name(id_map, (ID *)st->text, USER_REAL); + st->text = restore_pointer_by_name(id_map, (ID *)st->text, USER_IGNORE); if (st->text == NULL) { st->text = newmain->texts.first; } @@ -3010,8 +3012,13 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, else if (sl->spacetype == SPACE_SPREADSHEET) { SpaceSpreadsheet *sspreadsheet = (SpaceSpreadsheet *)sl; - sspreadsheet->pinned_id = restore_pointer_by_name( - id_map, sspreadsheet->pinned_id, USER_IGNORE); + LISTBASE_FOREACH (SpreadsheetContext *, context, &sspreadsheet->context_path) { + if (context->type == SPREADSHEET_CONTEXT_OBJECT) { + SpreadsheetContextObject *object_context = (SpreadsheetContextObject *)context; + object_context->object = restore_pointer_by_name( + id_map, (ID *)object_context->object, USER_IGNORE); + } + } } } } @@ -3863,6 +3870,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) blo_do_versions_270(fd, lib, main); blo_do_versions_280(fd, lib, main); blo_do_versions_290(fd, lib, main); + blo_do_versions_300(fd, lib, main); blo_do_versions_cycles(fd, lib, main); /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ @@ -3886,6 +3894,7 @@ static void do_versions_after_linking(Main *main, ReportList *reports) do_versions_after_linking_270(main); do_versions_after_linking_280(main, reports); do_versions_after_linking_290(main, reports); + do_versions_after_linking_300(main, reports); do_versions_after_linking_cycles(main); main->is_locked_for_linking = false; @@ -4444,7 +4453,9 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old) if (id == NULL) { /* ID has not been read yet, add placeholder to the main of the * library it belongs to, so that it will be read later. */ - read_libblock(fd, libmain, bhead, fd->id_tag_extra | LIB_TAG_INDIRECT, false, NULL); + read_libblock(fd, libmain, bhead, fd->id_tag_extra | LIB_TAG_INDIRECT, false, &id); + id_sort_by_name(which_libbase(libmain, GS(id->name)), id, id->prev); + /* commented because this can print way too much */ // if (G.debug & G_DEBUG) printf("expand_doit: other lib %s\n", lib->filepath); @@ -4504,7 +4515,8 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old) bhead, fd->id_tag_extra | LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT, false, - NULL); + &id); + id_sort_by_name(which_libbase(mainvar, GS(id->name)), id, id->prev); } else { /* Convert any previously read weak link to regular link diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index 9682b5456d2..d1d4e0b3256 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -210,6 +210,7 @@ void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main * void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_290(struct FileData *fd, struct Library *lib, struct Main *bmain); +void blo_do_versions_300(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_cycles(struct FileData *fd, struct Library *lib, struct Main *bmain); void do_versions_after_linking_250(struct Main *bmain); @@ -217,6 +218,7 @@ void do_versions_after_linking_260(struct Main *bmain); void do_versions_after_linking_270(struct Main *bmain); void do_versions_after_linking_280(struct Main *bmain, struct ReportList *reports); void do_versions_after_linking_290(struct Main *bmain, struct ReportList *reports); +void do_versions_after_linking_300(struct Main *bmain, struct ReportList *reports); void do_versions_after_linking_cycles(struct Main *bmain); /* This is rather unfortunate to have to expose this here, but better use that nasty hack in diff --git a/source/blender/blenloader/intern/readfile_tempload.c b/source/blender/blenloader/intern/readfile_tempload.c index 691d8f542ab..4566e1e9b4d 100644 --- a/source/blender/blenloader/intern/readfile_tempload.c +++ b/source/blender/blenloader/intern/readfile_tempload.c @@ -21,6 +21,9 @@ #include "MEM_guardedalloc.h" +#include "BLI_string.h" + +#include "BKE_main.h" #include "BKE_report.h" #include "DNA_ID.h" @@ -32,15 +35,20 @@ TempLibraryContext *BLO_library_temp_load_id(struct Main *real_main, struct ReportList *reports) { TempLibraryContext *temp_lib_ctx = MEM_callocN(sizeof(*temp_lib_ctx), __func__); + temp_lib_ctx->bmain_base = BKE_main_new(); + + /* Copy the file path so any path remapping is performed properly. */ + STRNCPY(temp_lib_ctx->bmain_base->name, real_main->name); temp_lib_ctx->blendhandle = BLO_blendhandle_from_file(blend_file_path, reports); - BLO_library_link_params_init(&temp_lib_ctx->liblink_params, real_main, 0, LIB_TAG_TEMP_MAIN); + BLO_library_link_params_init( + &temp_lib_ctx->liblink_params, temp_lib_ctx->bmain_base, 0, LIB_TAG_TEMP_MAIN); - temp_lib_ctx->temp_main = BLO_library_link_begin( + temp_lib_ctx->bmain_lib = BLO_library_link_begin( &temp_lib_ctx->blendhandle, blend_file_path, &temp_lib_ctx->liblink_params); - temp_lib_ctx->temp_id = BLO_library_link_named_part(temp_lib_ctx->temp_main, + temp_lib_ctx->temp_id = BLO_library_link_named_part(temp_lib_ctx->bmain_lib, &temp_lib_ctx->blendhandle, idcode, idname, @@ -51,8 +59,13 @@ TempLibraryContext *BLO_library_temp_load_id(struct Main *real_main, void BLO_library_temp_free(TempLibraryContext *temp_lib_ctx) { + /* This moves the temporary ID and any indirectly loaded data into `bmain_base` + * only to free `bmain_base`, while redundant this is the typical code-path for library linking, + * it's more convenient to follow this convention rather than create a new code-path for this + * one-off use case. */ BLO_library_link_end( - temp_lib_ctx->temp_main, &temp_lib_ctx->blendhandle, &temp_lib_ctx->liblink_params); + temp_lib_ctx->bmain_lib, &temp_lib_ctx->blendhandle, &temp_lib_ctx->liblink_params); BLO_blendhandle_close(temp_lib_ctx->blendhandle); + BKE_main_free(temp_lib_ctx->bmain_base); MEM_freeN(temp_lib_ctx); } diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 467fd8b0399..990fc1d65d7 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -446,7 +446,7 @@ static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name) id->flag = LIB_FAKEUSER; *((short *)id->name) = ID_GD; - BKE_id_new_name_validate(lb, id, name); + BKE_id_new_name_validate(lb, id, name, false); /* alphabetic insertion: is in BKE_id_new_name_validate */ if ((id->tag & LIB_TAG_TEMP_MAIN) == 0) { @@ -779,7 +779,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) Nurb *nu; for (nu = cu->nurb.first; nu; nu = nu->next) { - nu->flag |= (nu->type & CU_2D); nu->type &= CU_TYPE; } } diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 1ecaee10e6a..cf8f45ca227 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -1814,7 +1814,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) { - if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "bleedexp")) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) { for (Light *la = bmain->lights.first; la; la = la->id.next) { la->bleedexp = 2.5f; } @@ -1840,7 +1840,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) { - if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "cascade_max_dist")) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) { for (Light *la = bmain->lights.first; la; la = la->id.next) { la->cascade_max_dist = 1000.0f; la->cascade_count = 4; @@ -1849,7 +1849,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "contact_dist")) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) { for (Light *la = bmain->lights.first; la; la = la->id.next) { la->contact_dist = 0.2f; la->contact_bias = 0.03f; @@ -2185,7 +2185,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 280, 13)) { /* Initialize specular factor. */ - if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "spec_fac")) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) { for (Light *la = bmain->lights.first; la; la = la->id.next) { la->spec_fac = 1.0f; } @@ -3135,7 +3135,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "att_dist")) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "att_dist")) { for (Light *la = bmain->lights.first; la; la = la->id.next) { la->att_dist = la->clipend; } @@ -3172,7 +3172,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) bool is_blend = false; { - char tool = tool_init; + char tool; switch (tool_init) { case PAINT_BLEND_MIX: tool = VPAINT_TOOL_DRAW; @@ -4051,7 +4051,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } /* Initializes sun lights with the new angular diameter property */ - if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "sun_angle")) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "sun_angle")) { LISTBASE_FOREACH (Light *, light, &bmain->lights) { light->sun_angle = 2.0f * atanf(light->area_size); } diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c index 31e4b659c2f..565e62158ff 100644 --- a/source/blender/blenloader/intern/versioning_290.c +++ b/source/blender/blenloader/intern/versioning_290.c @@ -27,6 +27,7 @@ #include "BLI_utildefines.h" #include "DNA_anim_types.h" +#include "DNA_armature_types.h" #include "DNA_brush_types.h" #include "DNA_cachefile_types.h" #include "DNA_collection_types.h" @@ -47,6 +48,7 @@ #include "DNA_screen_types.h" #include "DNA_shader_fx_types.h" #include "DNA_space_types.h" +#include "DNA_text_types.h" #include "DNA_tracking_types.h" #include "DNA_workspace_types.h" @@ -56,6 +58,7 @@ #include "BKE_collection.h" #include "BKE_colortools.h" #include "BKE_cryptomatte.h" +#include "BKE_curve.h" #include "BKE_fcurve.h" #include "BKE_gpencil.h" #include "BKE_lib_id.h" @@ -377,6 +380,37 @@ static void seq_update_meta_disp_range(Editing *ed) } } +static void version_node_socket_duplicate(bNodeTree *ntree, + const int node_type, + const char *old_name, + const char *new_name) +{ + /* Duplicate a link going into the original socket. */ + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) { + if (link->tonode->type == node_type) { + bNode *node = link->tonode; + bNodeSocket *dest_socket = nodeFindSocket(node, SOCK_IN, new_name); + BLI_assert(dest_socket); + if (STREQ(link->tosock->name, old_name)) { + nodeAddLink(ntree, link->fromnode, link->fromsock, node, dest_socket); + } + } + } + + /* Duplicate the default value from the old socket and assign it to the new socket. */ + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type == node_type) { + bNodeSocket *source_socket = nodeFindSocket(node, SOCK_IN, old_name); + bNodeSocket *dest_socket = nodeFindSocket(node, SOCK_IN, new_name); + BLI_assert(source_socket && dest_socket); + if (dest_socket->default_value) { + MEM_freeN(dest_socket->default_value); + } + dest_socket->default_value = MEM_dupallocN(source_socket->default_value); + } + } +} + void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports)) { if (!MAIN_VERSION_ATLEAST(bmain, 290, 1)) { @@ -639,6 +673,29 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports)) } } + if (!MAIN_VERSION_ATLEAST(bmain, 293, 16)) { + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + seq_update_meta_disp_range(SEQ_editing_get(scene, false)); + } + + /* Add a separate socket for Grid node X and Y size. */ + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_GEOMETRY) { + version_node_socket_duplicate(ntree, GEO_NODE_MESH_PRIMITIVE_GRID, "Size X", "Size Y"); + } + FOREACH_NODETREE_END; + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 293, 20)) { + /* Set zero user text objects to have a fake user. */ + LISTBASE_FOREACH (Text *, text, &bmain->texts) { + if (text->id.us == 0) { + id_fake_user_set(&text->id); + } + } + } + /** * Versioning code until next subversion bump goes here. * @@ -651,10 +708,6 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports)) */ { /* Keep this block, even when empty. */ - - LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { - seq_update_meta_disp_range(SEQ_editing_get(scene, false)); - } } } @@ -1531,7 +1584,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) } LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { - if (scene->ed != NULL) { + if (scene->toolsettings->sequencer_tool_settings == NULL) { scene->toolsettings->sequencer_tool_settings = SEQ_tool_settings_init(); } } @@ -1907,7 +1960,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (!MAIN_VERSION_ATLEAST(bmain, 293, 14)) { - if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "diff_fac")) { + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "diff_fac")) { LISTBASE_FOREACH (Light *, light, &bmain->lights) { light->diff_fac = 1.0f; light->volume_fac = 1.0f; @@ -1925,6 +1978,115 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + if (!MAIN_VERSION_ATLEAST(bmain, 293, 15)) { + LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) { + if (ntree->type == NTREE_GEOMETRY) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (STREQ(node->idname, "GeometryNodeMeshPlane")) { + STRNCPY(node->idname, "GeometryNodeMeshGrid"); + } + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 293, 16)) { + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_GEOMETRY) { + version_node_socket_name(ntree, GEO_NODE_MESH_PRIMITIVE_GRID, "Size", "Size X"); + } + FOREACH_NODETREE_END; + } + + /* The CU_2D flag has been removed. */ + LISTBASE_FOREACH (Curve *, cu, &bmain->curves) { +#define CU_2D (1 << 3) + ListBase *nurbs = BKE_curve_nurbs_get(cu); + bool is_2d = true; + + LISTBASE_FOREACH (Nurb *, nu, nurbs) { + if (nu->flag & CU_2D) { + nu->flag &= ~CU_2D; + } + else { + is_2d = false; + } + } +#undef CU_2D + if (!is_2d && CU_IS_2D(cu)) { + cu->flag |= CU_3D; + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 293, 18)) { + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_GEOMETRY) { + version_node_socket_name(ntree, GEO_NODE_VOLUME_TO_MESH, "Grid", "Density"); + } + } + FOREACH_NODETREE_END; + + if (!DNA_struct_elem_find(fd->filesdna, "bArmature", "float", "axes_position")) { + /* Convert the axes draw position to its old default (tip of bone). */ + LISTBASE_FOREACH (struct bArmature *, arm, &bmain->armatures) { + arm->axes_position = 1.0; + } + } + + /* Initialize the spread parameter for area lights*/ + if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "area_spread")) { + LISTBASE_FOREACH (Light *, la, &bmain->lights) { + la->area_spread = DEG2RADF(180.0f); + } + } + + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { + if (sl->spacetype == SPACE_NODE) { + SpaceNode *snode = (SpaceNode *)sl; + LISTBASE_FOREACH (bNodeTreePath *, path, &snode->treepath) { + STRNCPY(path->display_name, path->node_name); + } + } + } + } + } + + /* Consolidate node and final evaluation modes. */ + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { + if (sl->spacetype == SPACE_SPREADSHEET) { + SpaceSpreadsheet *sspreadsheet = (SpaceSpreadsheet *)sl; + if (sspreadsheet->object_eval_state == 2) { + sspreadsheet->object_eval_state = SPREADSHEET_OBJECT_EVAL_STATE_EVALUATED; + } + } + } + } + } + } + + /* Set default value for the new bisect_threshold parameter in the mirror modifier. */ + if (!MAIN_VERSION_ATLEAST(bmain, 293, 19)) { + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { + if (md->type == eModifierType_Mirror) { + MirrorModifierData *mmd = (MirrorModifierData *)md; + /* This was the previous hard-coded value. */ + mmd->bisect_threshold = 0.001f; + } + } + } + + LISTBASE_FOREACH (Curve *, cu, &bmain->curves) { + /* Turn on clamping as this was implicit before. */ + cu->flag |= CU_PATH_CLAMP; + } + } + /** * Versioning code until next subversion bump goes here. * diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c new file mode 100644 index 00000000000..268598ccc51 --- /dev/null +++ b/source/blender/blenloader/intern/versioning_300.c @@ -0,0 +1,263 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup blenloader + */ +/* allow readfile to use deprecated functionality */ +#define DNA_DEPRECATED_ALLOW + +#include "BLI_listbase.h" +#include "BLI_math_vector.h" +#include "BLI_string.h" +#include "BLI_utildefines.h" + +#include "DNA_brush_types.h" +#include "DNA_genfile.h" +#include "DNA_listBase.h" +#include "DNA_modifier_types.h" +#include "DNA_text_types.h" + +#include "BKE_lib_id.h" +#include "BKE_main.h" +#include "BKE_node.h" + +#include "BLO_readfile.h" +#include "readfile.h" + +static void sort_linked_ids(Main *bmain) +{ + ListBase *lb; + FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) { + ListBase temp_list; + BLI_listbase_clear(&temp_list); + LISTBASE_FOREACH_MUTABLE (ID *, id, lb) { + if (ID_IS_LINKED(id)) { + BLI_remlink(lb, id); + BLI_addtail(&temp_list, id); + id_sort_by_name(&temp_list, id, NULL); + } + } + BLI_movelisttolist(lb, &temp_list); + } + FOREACH_MAIN_LISTBASE_END; +} + +static void assert_sorted_ids(Main *bmain) +{ +#ifndef NDEBUG + ListBase *lb; + FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) { + ID *id_prev = NULL; + LISTBASE_FOREACH (ID *, id, lb) { + if (id_prev == NULL) { + continue; + } + BLI_assert(id_prev->lib != id->lib || BLI_strcasecmp(id_prev->name, id->name) < 0); + } + } + FOREACH_MAIN_LISTBASE_END; +#else + UNUSED_VARS_NDEBUG(bmain); +#endif +} + +void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports)) +{ + if (MAIN_VERSION_ATLEAST(bmain, 300, 0) && !MAIN_VERSION_ATLEAST(bmain, 300, 1)) { + /* Set zero user text objects to have a fake user. */ + LISTBASE_FOREACH (Text *, text, &bmain->texts) { + if (text->id.us == 0) { + id_fake_user_set(&text->id); + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 300, 3)) { + /* Use new texture socket in Attribute Sample Texture node. */ + LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) { + if (ntree->type != NTREE_GEOMETRY) { + continue; + } + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type != GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE) { + continue; + } + if (node->id == NULL) { + continue; + } + LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { + if (socket->type == SOCK_TEXTURE) { + bNodeSocketValueTexture *socket_value = (bNodeSocketValueTexture *) + socket->default_value; + socket_value->value = (Tex *)node->id; + break; + } + } + node->id = NULL; + } + } + + sort_linked_ids(bmain); + assert_sorted_ids(bmain); + } + if (MAIN_VERSION_ATLEAST(bmain, 300, 3)) { + assert_sorted_ids(bmain); + } + + /** + * Versioning code until next subversion bump goes here. + * + * \note Be sure to check when bumping the version: + * - #blo_do_versions_300 in this file. + * - "versioning_userdef.c", #blo_do_versions_userdef + * - "versioning_userdef.c", #do_versions_theme + * + * \note Keep this message at the bottom of the function. + */ + { + /* Keep this block, even when empty. */ + } +} + +static void version_switch_node_input_prefix(Main *bmain) +{ + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_GEOMETRY) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type == GEO_NODE_SWITCH) { + LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { + /* Skip the "switch" socket. */ + if (socket == node->inputs.first) { + continue; + } + strcpy(socket->name, socket->name[0] == 'A' ? "False" : "True"); + + /* Replace "A" and "B", but keep the unique number suffix at the end. */ + char number_suffix[8]; + BLI_strncpy(number_suffix, socket->identifier + 1, sizeof(number_suffix)); + strcpy(socket->identifier, socket->name); + strcat(socket->identifier, number_suffix); + } + } + } + } + } + FOREACH_NODETREE_END; +} + +static void version_node_socket_name(bNodeTree *ntree, + const int node_type, + const char *old_name, + const char *new_name) +{ + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type == node_type) { + LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { + if (STREQ(socket->name, old_name)) { + strcpy(socket->name, new_name); + } + if (STREQ(socket->identifier, old_name)) { + strcpy(socket->identifier, new_name); + } + } + LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) { + if (STREQ(socket->name, old_name)) { + strcpy(socket->name, new_name); + } + if (STREQ(socket->identifier, old_name)) { + strcpy(socket->identifier, new_name); + } + } + } + } +} + +/* NOLINTNEXTLINE: readability-function-size */ +void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) +{ + if (!MAIN_VERSION_ATLEAST(bmain, 300, 1)) { + /* Set default value for the new bisect_threshold parameter in the mirror modifier. */ + if (!DNA_struct_elem_find(fd->filesdna, "MirrorModifierData", "float", "bisect_threshold")) { + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { + if (md->type == eModifierType_Mirror) { + MirrorModifierData *mmd = (MirrorModifierData *)md; + /* This was the previous hard-coded value. */ + mmd->bisect_threshold = 0.001f; + } + } + } + } + /* Grease Pencil: Set default value for dilate pixels. */ + if (!DNA_struct_elem_find(fd->filesdna, "BrushGpencilSettings", "int", "dilate_pixels")) { + LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) { + if (brush->gpencil_settings) { + brush->gpencil_settings->dilate_pixels = 1; + } + } + } + } + + if (!MAIN_VERSION_ATLEAST(bmain, 300, 2)) { + version_switch_node_input_prefix(bmain); + + if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale_xyz[3]")) { + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + if (ob->pose == NULL) { + continue; + } + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + copy_v3_fl(pchan->custom_scale_xyz, pchan->custom_scale); + } + } + } + } + + /** + * Versioning code until next subversion bump goes here. + * + * \note Be sure to check when bumping the version: + * - "versioning_userdef.c", #blo_do_versions_userdef + * - "versioning_userdef.c", #do_versions_theme + * + * \note Keep this message at the bottom of the function. + */ + { + /* Keep this block, even when empty. */ + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_GEOMETRY) { + version_node_socket_name(ntree, GEO_NODE_BOUNDING_BOX, "Mesh", "Bounding Box"); + } + } + FOREACH_NODETREE_END; + + if (!DNA_struct_elem_find(fd->filesdna, "FileAssetSelectParams", "int", "import_type")) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { + if (sl->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)sl; + if (sfile->asset_params) { + sfile->asset_params->import_type = FILE_ASSET_IMPORT_APPEND; + } + } + } + } + } + } + } +} diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index e43f8153bd1..56b2f18f8a6 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -81,6 +81,7 @@ #include "BKE_pointcache.h" #include "SEQ_iterator.h" +#include "SEQ_sequencer.h" #include "NOD_socket.h" @@ -1277,12 +1278,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (ob->soft->physics_speed == 0.0f) { ob->soft->physics_speed = 1.0f; } - - if (ob->soft->interval == 0) { - ob->soft->interval = 2; - ob->soft->sfra = 1; - ob->soft->efra = 100; - } } if (ob->soft && ob->soft->vertgroup == 0) { bDeformGroup *locGroup = BKE_object_defgroup_find_name(ob, "SOFTGOAL"); @@ -2560,18 +2555,16 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile < 249 && bmain->subversionfile < 2) { Scene *sce = bmain->scenes.first; - Sequence *seq; Editing *ed; while (sce) { ed = sce->ed; if (ed) { - SEQ_CURRENT_BEGIN (ed, seq) { + LISTBASE_FOREACH (Sequence *, seq, SEQ_active_seqbase_get(ed)) { if (seq->strip && seq->strip->proxy) { seq->strip->proxy->quality = 90; } } - SEQ_CURRENT_END; } sce = sce->id.next; diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index 8cbedb05931..be3834faa5a 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -24,6 +24,7 @@ #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #ifdef WITH_INTERNATIONAL @@ -261,17 +262,7 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme) FROM_DEFAULT_V4_UCHAR(space_node.nodeclass_shader); } - /** - * Versioning code until next subversion bump goes here. - * - * \note Be sure to check when bumping the version: - * - #blo_do_versions_userdef in this file. - * - "versioning_{BLENDER_VERSION}.c" - * - * \note Keep this message at the bottom of the function. - */ - { - /* Keep this block, even when empty. */ + if (!USER_VERSION_ATLEAST(293, 15)) { FROM_DEFAULT_V4_UCHAR(space_properties.active); FROM_DEFAULT_V4_UCHAR(space_info.info_error); @@ -286,6 +277,19 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme) btheme->space_spreadsheet = btheme->space_outliner; } + /** + * Versioning code until next subversion bump goes here. + * + * \note Be sure to check when bumping the version: + * - #blo_do_versions_userdef in this file. + * - "versioning_{BLENDER_VERSION}.c" + * + * \note Keep this message at the bottom of the function. + */ + { + /* Keep this block, even when empty. */ + } + #undef FROM_DEFAULT_V4_UCHAR #undef USER_VERSION_ATLEAST @@ -838,6 +842,23 @@ void blo_do_versions_userdef(UserDef *userdef) } } + if (!USER_VERSION_ATLEAST(293, 1)) { + /* This rename was made after 2.93.0, harmless to run when it's not needed. */ + const char *replace_table[][2] = { + {"blender", "Blender"}, + {"blender_27x", "Blender_27x"}, + {"industry_compatible", "Industry_Compatible"}, + }; + const int replace_table_len = ARRAY_SIZE(replace_table); + + BLI_str_replace_table_exact( + userdef->keyconfigstr, sizeof(userdef->keyconfigstr), replace_table, replace_table_len); + LISTBASE_FOREACH (wmKeyConfigPref *, kpt, &userdef->user_keyconfig_prefs) { + BLI_str_replace_table_exact( + kpt->idname, sizeof(kpt->idname), replace_table, replace_table_len); + } + } + if (!USER_VERSION_ATLEAST(293, 2)) { /* Enable asset browser features by default for alpha testing. * BLO_sanitize_experimental_features_userpref_blend() will disable it again for non-alpha diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 4ac49d5aebb..38c00b3f132 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -100,6 +100,7 @@ #include "BLI_bitmap.h" #include "BLI_blenlib.h" +#include "BLI_endian_defines.h" #include "BLI_mempool.h" #include "MEM_guardedalloc.h" /* MEM_freeN */ |