Blender V5.3
versioning_common.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8/* allow readfile to use deprecated functionality */
9#define DNA_DEPRECATED_ALLOW
10
11#include <cstring>
12
13#include "DNA_layer_types.h"
14#include "DNA_modifier_types.h"
15#include "DNA_node_types.h"
16#include "DNA_screen_types.h"
17#include "DNA_sequence_types.h"
18
19#include "RNA_path.hh"
20
21#include "BLI_function_ref.hh"
22#include "BLI_listbase.hh"
23#include "BLI_map.hh"
24#include "BLI_string.hh"
25#include "BLI_string_ref.hh"
26#include "BLI_string_utf8.hh"
27
28#include "BKE_animsys.hh"
29#include "BKE_compositor.hh"
31#include "BKE_idprop.hh"
32#include "BKE_lib_id.hh"
33#include "BKE_lib_override.hh"
34#include "BKE_library.hh"
35#include "BKE_main.hh"
36#include "BKE_main_namemap.hh"
38#include "BKE_node.hh"
40#include "BKE_node_runtime.hh"
42#include "BKE_report.hh"
43#include "BKE_screen.hh"
44
45#include "ANIM_versioning.hh"
46
47#include "NOD_socket.hh"
48
49#include "BLT_translation.hh"
50
51#include "SEQ_sequencer.hh"
52
53#include "MEM_guardedalloc.h"
54
55#include "BLO_readfile.hh"
56#include "readfile.hh"
57#include "versioning_common.hh"
58
59namespace blender {
60
61short do_versions_new_to_old_idcode_get(const short id_code_new)
62{
63 switch (id_code_new) {
64 case ID_GP:
65 /* ID_GD_LEGACY (Grease Pencil v2) is now converted to ID_GP (Grease Pencil v3). */
66 return ID_GD_LEGACY;
67 default:
69 }
70}
71
72ARegion *do_versions_add_region_if_not_found(ListBaseT<ARegion> *regionbase,
73 int region_type,
74 const char * /*allocname*/,
75 int link_after_region_type)
76{
77 ARegion *link_after_region = nullptr;
78 for (ARegion &region : *regionbase) {
79 if (region.regiontype == region_type) {
80 return nullptr;
81 }
82 if (region.regiontype == link_after_region_type) {
83 link_after_region = &region;
84 }
85 }
86
87 ARegion *new_region = BKE_area_region_new();
88 new_region->regiontype = eRegion_Type(region_type);
89 BLI_insertlinkafter(regionbase, link_after_region, new_region);
90 return new_region;
91}
92
93ARegion *do_versions_ensure_region(ListBaseT<ARegion> *regionbase,
94 int region_type,
95 const char * /*allocname*/,
96 int link_after_region_type)
97{
98 ARegion *link_after_region = nullptr;
99 for (ARegion &region : *regionbase) {
100 if (region.regiontype == region_type) {
101 return &region;
102 }
103 if (region.regiontype == link_after_region_type) {
104 link_after_region = &region;
105 }
106 }
107
108 ARegion *new_region = BKE_area_region_new();
109 new_region->regiontype = eRegion_Type(region_type);
110 BLI_insertlinkafter(regionbase, link_after_region, new_region);
111 return new_region;
112}
113
115 const short id_type,
116 const char *name_src,
117 const char *name_dst)
118{
119 /* We can ignore libraries */
120 ListBaseT<ID> *lb = which_libbase(bmain, id_type);
121 ID *id = nullptr;
122 for (ID &idtest : *lb) {
123 if (!ID_IS_LINKED(&idtest)) {
124 if (STREQ(idtest.name + 2, name_src)) {
125 id = &idtest;
126 }
127 if (STREQ(idtest.name + 2, name_dst)) {
128 return nullptr;
129 }
130 }
131 }
132 if (id != nullptr) {
133 BKE_libblock_rename(*bmain, *id, name_dst);
134 }
135 return id;
136}
137
138static void change_node_socket_name(ListBaseT<bNodeSocket> *sockets,
139 const char *old_name,
140 const char *new_name)
141{
142 for (bNodeSocket &socket : *sockets) {
143 if (STREQ(socket.name, old_name)) {
144 STRNCPY_UTF8(socket.name, new_name);
145 }
146 if (STREQ(socket.identifier, old_name)) {
147 version_node_socket_identifier_set(socket, new_name);
148 }
149 }
150}
151
153{
154 BLI_assert(sock != nullptr);
155 return sock->flag & SOCK_IS_LINKED;
156}
157
159{
160 StringRef name = socket->name;
161 StringRef id = socket->identifier;
162
163 if (!id.startswith(name)) {
164 /* We only need to affect the case where the identifier starts with the name. */
165 return;
166 }
167
168 StringRef id_number = id.drop_known_prefix(name);
169 if (id_number.is_empty()) {
170 /* The name was already unique, and didn't need numbers at the end for the id. */
171 return;
172 }
173
174 if (id_number.startswith(".")) {
175 socket->identifier[name.size()] = '_';
176 socket->runtime->identifier_ustr = UString(socket->identifier);
177 }
178}
179
181{
182 STRNCPY_UTF8(socket.identifier, identifier.c_str());
183 socket.runtime->identifier_ustr = UString(socket.identifier);
184}
185
187 const int node_type,
188 const char *old_name,
189 const char *new_name)
190{
191 for (bNode *node : ntree->all_nodes()) {
192 if (node->type_legacy == node_type) {
193 change_node_socket_name(&node->inputs, old_name, new_name);
194 change_node_socket_name(&node->outputs, old_name, new_name);
195 }
196 }
197}
198
200 const int node_type,
201 const char *old_name,
202 const char *new_name)
203{
204 for (bNode *node : ntree->all_nodes()) {
205 if (node->type_legacy == node_type) {
206 change_node_socket_name(&node->inputs, old_name, new_name);
207 }
208 }
209}
210
212 const int node_type,
213 const char *old_name,
214 const char *new_name)
215{
216 for (bNode *node : ntree->all_nodes()) {
217 if (node->type_legacy == node_type) {
218 change_node_socket_name(&node->outputs, old_name, new_name);
219 }
220 }
221}
222
224{
225 using string_pair = std::pair<const char *, const char *>;
226 static const string_pair subtypes_map[] = {{"NodeSocketFloatUnsigned", "NodeSocketFloat"},
227 {"NodeSocketFloatPercentage", "NodeSocketFloat"},
228 {"NodeSocketFloatFactor", "NodeSocketFloat"},
229 {"NodeSocketFloatAngle", "NodeSocketFloat"},
230 {"NodeSocketFloatTime", "NodeSocketFloat"},
231 {"NodeSocketFloatTimeAbsolute", "NodeSocketFloat"},
232 {"NodeSocketFloatDistance", "NodeSocketFloat"},
233 {"NodeSocketIntUnsigned", "NodeSocketInt"},
234 {"NodeSocketIntPercentage", "NodeSocketInt"},
235 {"NodeSocketIntFactor", "NodeSocketInt"},
236 {"NodeSocketVectorTranslation", "NodeSocketVector"},
237 {"NodeSocketVectorDirection", "NodeSocketVector"},
238 {"NodeSocketVectorVelocity", "NodeSocketVector"},
239 {"NodeSocketVectorAcceleration", "NodeSocketVector"},
240 {"NodeSocketVectorEuler", "NodeSocketVector"},
241 {"NodeSocketVectorXYZ", "NodeSocketVector"}};
242 for (const string_pair &pair : subtypes_map) {
243 if (pair.first == idname) {
244 return pair.second;
245 }
246 }
247 /* Unchanged socket idname. */
248 return idname;
249}
250
251bNode &version_node_add_empty(bNodeTree &ntree, const char *idname)
252{
254
255 bNode *node = MEM_new<bNode>(__func__);
256 node->runtime = MEM_new<bke::bNodeRuntime>(__func__);
257 BLI_addtail(&ntree.nodes, node);
258 bke::node_unique_id(ntree, *node);
259
260 STRNCPY(node->idname, idname);
261 DATA_(ntype->ui_name).copy_utf8_truncated(node->name);
263
265 node->width = ntype->default_width;
266 node->height = ntype->height;
267 node->color[0] = node->color[1] = node->color[2] = 0.608;
268
269 node->type_legacy = ntype->type_legacy;
270
272 return *node;
273}
274
276 bke::bNodeType &ntype,
277 const char *idname,
278 const int16_t legacy_type,
279 const std::string &ui_name,
280 const std::string &ui_description,
281 const std::string &enum_name_legacy,
282 const short nclass,
283 const float width,
284 const float height,
285 const bool no_muting)
286{
287 using namespace blender::bke;
288
289 ntype.idname = UString(idname);
290 ntype.type_legacy = legacy_type;
291 ntype.height = height;
292 ntype.default_width = width;
293 ntype.minheight = 30.0f;
294 ntype.maxheight = FLT_MAX;
295
296 ntype.ui_name = ui_name;
297 ntype.ui_description = ui_description;
298 ntype.enum_name_legacy = enum_name_legacy.c_str();
299 ntype.nclass = nclass;
300 ntype.no_muting = no_muting;
301 ntype.ui_name = ui_name;
302
303 bNode *node = MEM_new<bNode>(__func__);
304 node->runtime = MEM_new<bNodeRuntime>(__func__);
305 BLI_addtail(&ntree.nodes, node);
306 node_unique_id(ntree, *node);
307 node->typeinfo = &ntype;
308
309 STRNCPY(node->idname, idname);
310 DATA_(ntype.ui_name).copy_utf8_truncated(node->name);
311 node_unique_name(ntree, *node);
312
314 node->width = ntype.default_width;
315 node->height = ntype.height;
316 node->color[0] = node->color[1] = node->color[2] = 0.608f;
317
318 node->type_legacy = ntype.type_legacy;
319
321 return *node;
322}
323
332
334 bNode &node,
335 const eNodeSocketInOut in_out,
336 const char *idname,
337 const char *identifier)
338{
340 BLI_assert(stype != nullptr);
341
342 bNodeSocket *socket = MEM_new<bNodeSocket>(__func__);
343 socket->runtime = MEM_new<bke::bNodeSocketRuntime>(__func__);
344 socket->in_out = in_out;
345 socket->limit = (in_out == SOCK_IN ? 1 : 0xFFF);
346 socket->type = stype->type;
347
348 STRNCPY_UTF8(socket->idname, idname);
349 STRNCPY_UTF8(socket->identifier, identifier);
350 socket->runtime->identifier_ustr = UString(socket->identifier);
351 STRNCPY_UTF8(socket->name, identifier);
352
353 if (in_out == SOCK_IN) {
354 BLI_addtail(&node.inputs, socket);
355 }
356 else {
357 BLI_addtail(&node.outputs, socket);
358 }
359
360 socket->default_value = bke::socket_value_new(stype->type, stype->subtype);
361
362 BKE_ntree_update_tag_socket_new(&ntree, socket);
363 return *socket;
364}
365
367 bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b)
368{
369 BLI_assert(socket_a.in_out != socket_b.in_out);
370 if (socket_a.in_out == SOCK_IN) {
371 return version_node_add_link(ntree, node_b, socket_b, node_a, socket_a);
372 }
373 bNode &node_from = node_a;
374 bNodeSocket &socket_from = socket_a;
375 bNode &node_to = node_b;
376 bNodeSocket &socket_to = socket_b;
377
378 bNodeLink *link = MEM_new<bNodeLink>(__func__);
379 link->fromnode = &node_from;
380 link->fromsock = &socket_from;
381 link->tonode = &node_to;
382 link->tosock = &socket_to;
383
384 BLI_addtail(&ntree.links, link);
385
387 return *link;
388}
389
391{
392 /* Accept node if storage is valid. */
393 if (node.storage != nullptr) {
394 return true;
395 }
396
397 /* Invalidate the type identifiers to prevent invalid access where storage data is expected
398 * (#154086). */
400 return false;
401}
402
404 bNode *node,
405 int in_out,
406 int type,
407 int subtype,
408 const char *identifier,
409 const char *name)
410{
411 bNodeSocket *sock = bke::node_find_socket(*node, eNodeSocketInOut(in_out), UString(identifier));
412 if (sock != nullptr) {
413 return sock;
414 }
416 *ntree, *node, eNodeSocketInOut(in_out), type, subtype, identifier, name);
417}
418
420{
421 ntree.tree_interface.clear_items();
422}
423
424void version_node_id(bNodeTree *ntree, const int node_type, const char *new_name)
425{
426 for (bNode *node : ntree->all_nodes()) {
427 if (node->type_legacy == node_type) {
428 if (!STREQ(node->idname, new_name)) {
429 STRNCPY(node->idname, new_name);
430 }
431 }
432 }
433}
434
439 Main *bmain,
440 const int node_tree_type,
441 const FunctionRef<bool(const bNode *)> node_match_fn,
442 const int socket_index_orig,
443 const int socket_index_offset,
444 const int total_number_of_sockets)
445{
446
447 /* The for loop for the input ids is at the top level otherwise we lose the animation
448 * keyframe data. Not sure what causes that, so I (Sybren) moved the code here from
449 * versioning_290.cc as-is (structure-wise). */
450 const DriverMap driver_map = BKE_animdata_build_driver_target_map(*bmain);
451 for (int input_index = total_number_of_sockets - 1; input_index >= socket_index_orig;
452 input_index--)
453 {
454 FOREACH_NODETREE_BEGIN (bmain, ntree, _owner_id) {
455 if (ntree->type != node_tree_type) {
456 continue;
457 }
458
459 for (bNode *node : ntree->all_nodes()) {
460 if (!node_match_fn(node)) {
461 continue;
462 }
463
464 char node_name_escaped[sizeof(node->name) * 2];
465 BLI_str_escape(node_name_escaped, node->name, sizeof(node_name_escaped));
466 char *rna_path_prefix = BLI_sprintfN("nodes[\"%s\"].inputs", node_name_escaped);
467
468 const int new_index = input_index + socket_index_offset;
469 /* Note: this should not use `owner_id`, as in the case of embedded node trees, that is set
470 * to the owning ID (like a material owning its shader node tree). It's the node tree
471 * itself that needs its animation versioned. */
472 BKE_animdata_fix_paths(ntree->id,
473 rna_path_prefix,
474 RNA_path_number_to_infix(input_index),
475 RNA_path_number_to_infix(new_index),
476 /*verify_paths=*/false,
477 driver_map);
478 MEM_delete(rna_path_prefix);
479 }
480 }
482 }
483}
484
486 const int node_tree_type,
487 const int node_type,
488 const int socket_index_orig,
489 const int socket_index_offset,
490 const int total_number_of_sockets)
491{
493 bmain,
494 node_tree_type,
495 [node_type](const bNode *node) -> bool { return node->type_legacy == node_type; },
496 socket_index_orig,
497 socket_index_offset,
498 total_number_of_sockets);
499}
500
502 const int node_tree_type,
503 const char *node_idname,
504 const int socket_index_orig,
505 const int socket_index_offset,
506 const int total_number_of_sockets)
507{
508 const StringRef node_idname_ref(node_idname);
510 bmain,
511 node_tree_type,
512 [node_idname_ref](const bNode *node) -> bool { return node_idname_ref == node->idname; },
513 socket_index_orig,
514 socket_index_offset,
515 total_number_of_sockets);
516}
517
519{
520 for (bNode *node : ntree->all_nodes()) {
521 for (bNodeSocket &socket : node->inputs) {
522 socket.flag &= ~SOCK_IS_LINKED;
523 }
524 for (bNodeSocket &socket : node->outputs) {
525 socket.flag &= ~SOCK_IS_LINKED;
526 }
527 }
528 for (bNodeLink &link : ntree->links) {
530 link.tosock->flag |= SOCK_IS_LINKED;
531 }
532}
533
534ARegion *do_versions_add_region(int regiontype, const char * /*name*/)
535{
536 ARegion *region = BKE_area_region_new();
537 region->regiontype = eRegion_Type(regiontype);
538 return region;
539}
540
542 bNode &old_node,
543 bNode &new_node,
545{
546 for (bNodeLink &link : ntree.links.items_mutable()) {
547 if (link.tonode == &old_node) {
548 bNodeSocket *old_socket = link.tosock;
549 if (old_socket->is_available()) {
550 if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) {
552 *&new_node, SOCK_IN, UString(*new_identifier));
553 link.tonode = &new_node;
554 link.tosock = new_socket;
555 old_socket->link = nullptr;
556 }
557 }
558 }
559 if (link.fromnode == &old_node) {
560 bNodeSocket *old_socket = link.fromsock;
561 if (old_socket->is_available()) {
562 if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) {
564 *&new_node, SOCK_OUT, UString(*new_identifier));
565 link.fromnode = &new_node;
566 link.fromsock = new_socket;
567 old_socket->link = nullptr;
568 }
569 }
570 }
571 }
572}
573
575{
577 for (bNodeLink &link : ntree->links) {
578 if (link.tosock == in_socket) {
579 links.append(&link);
580 }
581 }
582 return links;
583}
584
586 bNode *node,
587 bNodeSocket *geometry_socket)
588{
589 BLI_assert(geometry_socket->type == SOCK_GEOMETRY);
590 Vector<bNodeLink *> links = find_connected_links(ntree, geometry_socket);
591 for (bNodeLink *link : links) {
592 /* If the realize instances node is already before this socket, no need to continue. */
593 if (link->fromnode->type_legacy == GEO_NODE_REALIZE_INSTANCES) {
594 return;
595 }
596
597 bNode *realize_node = bke::node_add_static_node(nullptr, *ntree, GEO_NODE_REALIZE_INSTANCES);
598 realize_node->parent = node->parent;
599 realize_node->locx_legacy = node->locx_legacy - 100;
600 realize_node->locy_legacy = node->locy_legacy;
602 *ntree, *link->fromnode, *link->fromsock, *realize_node, *realize_node->inputs.first());
603 link->fromnode = realize_node;
604 link->fromsock = realize_node->outputs.first();
605 }
606}
607
609{
610 bNodeSocketValueFloat *socket_data = static_cast<bNodeSocketValueFloat *>(socket->default_value);
611 return &socket_data->value;
612}
613
615{
616 bNodeSocketValueRGBA *socket_data = static_cast<bNodeSocketValueRGBA *>(socket->default_value);
617 return socket_data->value;
618}
619
621{
622 bNodeSocketValueVector *socket_data = static_cast<bNodeSocketValueVector *>(
623 socket->default_value);
624 return socket_data->value;
625}
626
632
638
640{
641 IDProperty *idprop = render_layer->prop;
642 return (idprop) ? IDP_GetPropertyTypeFromGroup(idprop, "cycles", IDP_GROUP) : nullptr;
643}
644
645float version_cycles_property_float(IDProperty *idprop, const char *name, float default_value)
646{
648 return (prop) ? IDP_float_get(prop) : default_value;
649}
650
651int version_cycles_property_int(IDProperty *idprop, const char *name, int default_value)
652{
654 return (prop) ? IDP_int_get(prop) : default_value;
655}
656
657void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value)
658{
660 IDP_int_set(prop, value);
661 }
662 else {
663 IDP_AddToGroup(idprop, bke::idprop::create(name, value).release());
664 }
665}
666
667bool version_cycles_property_boolean(IDProperty *idprop, const char *name, bool default_value)
668{
669 return version_cycles_property_int(idprop, name, default_value);
670}
671
672void version_cycles_property_boolean_set(IDProperty *idprop, const char *name, bool value)
673{
675}
676
682
684 bNodeTree *ntree,
685 FunctionRef<bool(bNode *)> check_node,
686 const char *socket_identifier,
687 FunctionRef<void(bNode *, bNodeSocket *)> update_input,
688 FunctionRef<void(bNode *, bNodeSocket *, bNode *, bNodeSocket *)> update_input_link)
689{
690 bool need_update = false;
691
692 /* Iterate backwards from end so we don't encounter newly added links. */
693 for (bNodeLink &link : ntree->links.items_reversed_mutable()) {
694 /* Detect link to replace. */
695 bNode *fromnode = link.fromnode;
696 bNodeSocket *fromsock = link.fromsock;
697 bNode *tonode = link.tonode;
698 bNodeSocket *tosock = link.tosock;
699
700 if (!(tonode != nullptr && check_node(tonode) && STREQ(tosock->identifier, socket_identifier)))
701 {
702 continue;
703 }
704
705 /* Replace links with updated equivalent */
706 bke::node_remove_link(ntree, link);
707 update_input_link(fromnode, fromsock, tonode, tosock);
708
709 need_update = true;
710 }
711
712 /* Update sockets and/or their default values.
713 * Do this after the link update in case it changes the identifier. */
714 for (bNode &node : ntree->nodes) {
715 if (check_node(&node)) {
716 bNodeSocket *input = bke::node_find_socket(node, SOCK_IN, UString(socket_identifier));
717 if (input != nullptr) {
718 update_input(&node, input);
719 }
720 }
721 }
722
723 if (need_update) {
725 }
726}
727
729{
730 bNode *output_node = nullptr;
731 /* NOTE: duplicated from `ntreeShaderOutputNode` with small adjustments so it can be called
732 * during versioning. */
733 for (bNode &node : ntree->nodes) {
734 if (node.type_legacy != node_type) {
735 continue;
736 }
737 if (node.custom1 == SHD_OUTPUT_ALL) {
738 if (output_node == nullptr) {
739 output_node = &node;
740 }
741 else if (output_node->custom1 == SHD_OUTPUT_ALL) {
742 if ((node.flag & NODE_DO_OUTPUT) && !(output_node->flag & NODE_DO_OUTPUT)) {
743 output_node = &node;
744 }
745 }
746 }
747 else if (node.custom1 == SHD_OUTPUT_EEVEE) {
748 if (output_node == nullptr) {
749 output_node = &node;
750 }
751 else if ((node.flag & NODE_DO_OUTPUT) && !(output_node->flag & NODE_DO_OUTPUT)) {
752 output_node = &node;
753 }
754 }
755 }
756
757 return output_node;
758}
759
760bool all_scenes_use(Main *bmain, const Span<const char *> engines)
761{
762 if (!bmain->scenes.first()) {
763 return false;
764 }
765
766 for (Scene &scene : bmain->scenes) {
767 bool match = false;
768 for (const char *engine : engines) {
769 if (STREQ(scene.r.engine, engine)) {
770 match = true;
771 }
772 }
773 if (!match) {
774 return false;
775 }
776 }
777
778 return true;
779}
780
782{
783 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 500, 4)) {
784 return scene->nodetree;
785 }
786
787 return scene->compositing_node_group;
788}
789
791{
792 SceneCompositorEffect &effect = bke::compositor::new_effect(scene, "Scene Effect");
793 effect.node_group = &node_group;
794 if (!node_group.compositor_node_asset_traits) {
795 node_group.compositor_node_asset_traits = MEM_new<CompositorNodeAssetTraits>(__func__);
796 }
799}
800
802 const short versionfile,
803 const short subversionfile)
804{
805 if (!MAIN_VERSION_FILE_ATLEAST(bmain, versionfile, subversionfile)) {
806 return false;
807 }
808
809 for (Library &library : bmain->libraries) {
810 if (!LIBRARY_VERSION_FILE_ATLEAST(&library, versionfile, subversionfile)) {
811 return false;
812 }
813 }
814
815 return true;
816}
817
819 BlendfileLinkAppendContext *lapp_context,
820 BlendFileReadReport *reports)
821{
822 /* WARNING: The code below may add IDs. These IDs _will_ be (by definition) conforming to current
823 * code's version already, and _must not_ be *versioned* again.
824 *
825 * This means that when adding code here, _extreme_ care must be taken that it will not badly
826 * affect these 'modern' IDs potentially added by already existing processing.
827 *
828 * Adding code here should only be done in exceptional cases.
829 *
830 * Some further points to keep in mind:
831 * - While typically versioning order should be respected in code below (i.e. versioning
832 * affecting older versions should be done first), _this is not a hard rule_. And it should
833 * not be assumed older code must not be checked when adding newer code.
834 * - Do not rely strongly on versioning numbers here. This code may be run on data from
835 * different Blender versions (through the usage of linked data), and all existing data have
836 * already been processed through the whole do_version during blendfile reading itself. So
837 * decision to apply some versioning on some data should mostly rely on the data itself.
838 * - Unlike the regular do_version code, this one should _not_ be assumed as 'valid forever'.
839 * It is closer to the Editing or BKE code in that respect, changes to the logic or data
840 * model of an ID will require a careful update here as well.
841 *
842 * Another critical weakness of this code is that it is currently _not_ performed on data linked
843 * during an editing session, but only on data linked while reading a whole blendfile. This will
844 * have to be fixed at some point.
845 */
846
847 /* NOTE: Version number is checked against Main version (i.e. current blend file version), AND
848 * the versions of all the linked libraries. */
849
850 if (!blendfile_or_libraries_versions_atleast(new_bmain, 250, 0)) {
851 /* This happens here, because at this point in the versioning code there's
852 * 'reports' available. */
853 reports->pre_animato_file_loaded = true;
854 }
855
856 if (!blendfile_or_libraries_versions_atleast(new_bmain, 250, 0)) {
857 for (Scene &scene : new_bmain->scenes) {
858 if (scene.ed) {
860 }
861 }
862 }
863
864 if (!blendfile_or_libraries_versions_atleast(new_bmain, 302, 1)) {
866 /* Currently liboverride code can generate invalid namemap. This is a known issue, requires
867 * #107847 to be properly fixed. */
869 }
870
871 if (!blendfile_or_libraries_versions_atleast(new_bmain, 302, 3)) {
872 /* Does not add any new IDs, but needs the full Main data-base. */
874 }
875
876 if (!blendfile_or_libraries_versions_atleast(new_bmain, 402, 22)) {
877 /* Initial auto smooth versioning started at (401, 2), but a bug caused the legacy flag to not
878 * be cleared, so it is re-run in a later version when the bug is fixed and the versioning has
879 * been made idempotent. */
881 }
882
883 if (!blendfile_or_libraries_versions_atleast(new_bmain, 404, 2)) {
884 /* Version all the action assignments of just-versioned datablocks. This MUST happen before the
885 * GreasePencil conversion, as that assumes the Action Slots have already been assigned. */
887 }
888
889 if (!blendfile_or_libraries_versions_atleast(new_bmain, 403, 3)) {
890 /* Convert all the legacy grease pencil objects. This does not touch annotations. */
891 bke::greasepencil::convert::legacy_main(*new_bmain, lapp_context, *reports);
892 }
893
894 if (!blendfile_or_libraries_versions_atleast(new_bmain, 500, 4)) {
895 for (Scene &scene : new_bmain->scenes) {
896 bNodeTree *ntree = scene.nodetree;
897 if (!ntree) {
898 continue;
899 }
901 ntree->owner_id = nullptr;
902 ntree->id.tag |= ID_TAG_NO_MAIN;
903
904 scene.nodetree = nullptr;
905
906 BKE_libblock_management_main_add(new_bmain, ntree);
907
909
910 /* NOTE: The user count remains zero at this point. It will get automatically updated after
911 * blend file reading is done. */
912 }
913 }
914
915 if (!blendfile_or_libraries_versions_atleast(new_bmain, 501, 29)) {
916 /* Clear modifier node trees if the tree type is undefined.
917 * This can happen to generated auto-smooth node groups for unknown reasons (#152810). */
918 for (Object &object : new_bmain->objects) {
919 for (ModifierData &md : object.modifiers) {
920 if (md.type != eModifierType_Nodes) {
921 continue;
922 }
923 NodesModifierData &nmd = *reinterpret_cast<NodesModifierData *>(&md);
924 if (nmd.node_group && !ID_MISSING(nmd.node_group) &&
925 !STREQ(nmd.node_group->idname, "GeometryNodeTree"))
926 {
927 id_us_min(&nmd.node_group->id);
928 nmd.node_group = nullptr;
929 }
930 }
931 }
932 }
933}
934
935} // namespace blender
Versioning of old animation data. Most animation versioning code lives in the versioning_xxx....
#define IDP_float_get(prop)
#define IDP_int_get(prop)
#define IDP_int_set(prop, value)
#define MAIN_VERSION_FILE_ATLEAST(main, ver, subver)
Definition BKE_main.hh:949
#define LIBRARY_VERSION_FILE_ATLEAST(lib, ver, subver)
Definition BKE_main.hh:966
#define FOREACH_NODETREE_END
Definition BKE_node.hh:936
#define FOREACH_NODETREE_BEGIN(bmain, _nodetree, _id)
Definition BKE_node.hh:926
#define GEO_NODE_REALIZE_INSTANCES
#define STRNCPY_UTF8(dst, src)
external readfile function prototypes.
#define DATA_(msgid)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_MISSING(_id)
Definition DNA_ID.h:695
#define ID_LINK_PLACEHOLDER
Read Blender memory allocation and freeing.
#define STREQ(a, b)
const Value * lookup_ptr_as(const ForwardKey &key) const
Definition BLI_map.hh:516
constexpr const char * c_str() const
constexpr StringRef drop_known_prefix(StringRef prefix) const
UString()=default
void append(const T &value)
constexpr bool startswith(StringRef prefix) const
constexpr bool is_empty() const
constexpr int64_t size() const
#define FLT_MAX
void convert_legacy_action_assignments(Main &bmain, ReportList *reports)
SceneCompositorEffect & new_effect(Scene &scene, StringRef name)
void legacy_main(Main &bmain, BlendfileLinkAppendContext *lapp_context, BlendFileReadReport &reports)
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
void node_unlink_node(bNodeTree &ntree, bNode &node)
Definition node.cc:5026
void node_update_asset_metadata(bNodeTree &node_tree)
Definition node.cc:2462
void node_unique_id(bNodeTree &ntree, bNode &node)
Definition node.cc:4244
void * socket_value_new(eNodeSocketDatatype type, int subtype=0)
Definition node.cc:3274
void node_remove_link(bNodeTree *ntree, bNodeLink &link)
Definition node.cc:4676
bNodeType * node_type_find(UString idname)
Definition node.cc:2883
void node_unlink_attached(bNodeTree *ntree, const bNode *parent)
Definition node.cc:5053
void node_free_node(bNodeTree *tree, bNode &node)
Definition node.cc:5073
void node_set_undefined_type(bNode &node)
Definition node.cc:5667
void node_rebuild_id_vector(bNodeTree &node_tree)
Definition node.cc:5062
bNodeSocketType * node_socket_type_find(StringRef idname)
Definition node.cc:2966
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
Definition node.cc:4283
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
Definition node.cc:4638
bNodeSocket * node_add_static_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out, int type, int subtype, StringRefNull identifier, StringRefNull name)
Definition node.cc:3980
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
Definition node.cc:3036
void node_unique_name(bNodeTree &ntree, bNode &node)
Definition node.cc:4238
void doversion_250_sound_proxy_update(Main *bmain, Editing *ed)
BMesh Iterators.
bool version_node_ensure_storage_or_invalidate(bNode &node)
@ COMPOSIT_NODE_ASSET_SCENE_EFFECT
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool version_node_socket_is_used(bNodeSocket *sock)
void node_tree_relink_with_socket_id_map(bNodeTree &ntree, bNode &old_node, bNode &new_node, const Map< std::string, std::string > &map)
void version_node_socket_id_delim(bNodeSocket *socket)
char * STRNCPY(char(&dst)[N], const char *src)
StringRef legacy_socket_idname_to_socket_type(StringRef idname)
static void change_node_socket_name(ListBaseT< bNodeSocket > *sockets, const char *old_name, const char *new_name)
void BKE_ntree_update_tag_link_added(bNodeTree *ntree, bNodeLink *link)
IDProperty * IDP_GetPropertyTypeFromGroup(const IDProperty *prop, StringRef name, char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:839
void BKE_ntree_update_tag_socket_new(bNodeTree *ntree, bNodeSocket *socket)
float version_cycles_property_float(IDProperty *idprop, const char *name, float default_value)
std::string RNA_path_number_to_infix(const int number)
Definition rna_path.cc:1425
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
void version_update_node_input(bNodeTree *ntree, FunctionRef< bool(bNode *)> check_node, const char *socket_identifier, FunctionRef< void(bNode *, bNodeSocket *)> update_input, FunctionRef< void(bNode *, bNodeSocket *, bNode *, bNodeSocket *)> update_input_link)
void version_cycles_property_boolean_set(IDProperty *idprop, const char *name, bool value)
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
ARegion * do_versions_add_region(int regiontype, const char *)
float * version_cycles_node_socket_float_value(bNodeSocket *socket)
float * version_cycles_node_socket_vector_value(bNodeSocket *socket)
IDProperty * version_cycles_properties_from_render_layer(SceneRenderLayer *render_layer)
bNode & version_node_add_empty(bNodeTree &ntree, const char *idname)
IDProperty * IDP_ID_system_properties_get(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:1018
void BKE_lib_override_library_main_proxy_convert(Main *bmain, BlendFileReadReport *reports)
int version_cycles_property_int(IDProperty *idprop, const char *name, int default_value)
void version_socket_update_is_used(bNodeTree *ntree)
void BKE_animdata_fix_paths(ID &id, StringRef prefix, StringRef old_infix, StringRef new_infix, bool verify_paths, const DriverMap &driver_map)
void version_node_output_socket_name(bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
void version_node_socket_identifier_set(bNodeSocket &socket, const StringRefNull identifier)
static Vector< bNodeLink * > find_connected_links(bNodeTree *ntree, bNodeSocket *in_socket)
float * version_cycles_node_socket_rgba_value(bNodeSocket *socket)
ID * do_versions_rename_id(Main *bmain, const short id_type, const char *name_src, const char *name_dst)
void BKE_lib_override_library_main_hierarchy_root_ensure(Main *bmain, LibOverride_HierarchyRoot_ValidateOptions options={}, ReportList *reports=nullptr)
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
IDProperty * version_cycles_visibility_properties_from_ID(ID *id)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
bool BKE_main_namemap_validate_and_fix(Main &bmain)
void version_node_id(bNodeTree *ntree, const int node_type, const char *new_name)
void do_versions_after_setup(Main *new_bmain, BlendfileLinkAppendContext *lapp_context, BlendFileReadReport *reports)
void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value)
DriverMap BKE_animdata_build_driver_target_map(Main &bmain)
Definition anim_data.cc:980
bool all_scenes_use(Main *bmain, const Span< const char * > engines)
bNode * version_eevee_output_node_get(bNodeTree *ntree, int16_t node_type)
ARegion * BKE_area_region_new()
Definition screen.cc:522
void version_node_tree_clear_interface(bNodeTree &ntree)
ARegion * do_versions_ensure_region(ListBaseT< ARegion > *regionbase, int region_type, const char *, int link_after_region_type)
bool version_cycles_property_boolean(IDProperty *idprop, const char *name, bool default_value)
IDNewNameResult BKE_libblock_rename(Main &bmain, ID &id, StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
Definition lib_id.cc:2632
void BKE_main_mesh_legacy_convert_auto_smooth(Main &bmain)
static void version_node_socket_index_animdata_ex(Main *bmain, const int node_tree_type, const FunctionRef< bool(const bNode *)> node_match_fn, const int socket_index_orig, const int socket_index_offset, const int total_number_of_sockets)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void version_compositing_node_group_to_effect(Scene &scene, bNodeTree &node_group)
void version_node_input_socket_name(bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
IDProperty * version_cycles_properties_from_ID(ID *id)
@ ID_TAG_NO_MAIN
Definition DNA_ID.h:981
void BKE_libblock_management_main_add(Main *bmain, void *idv)
Definition lib_id.cc:1201
Map< ID *, Vector< DriverTarget * > > DriverMap
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
ARegion * do_versions_add_region_if_not_found(ListBaseT< ARegion > *regionbase, int region_type, const char *, int link_after_region_type)
static bool blendfile_or_libraries_versions_atleast(Main *bmain, const short versionfile, const short subversionfile)
void version_node_socket_index_animdata(Main *bmain, const int node_tree_type, const int node_type, const int socket_index_orig, const int socket_index_offset, const int total_number_of_sockets)
void add_realize_instances_before_socket(bNodeTree *ntree, bNode *node, bNodeSocket *geometry_socket)
IDProperty * version_cycles_properties_from_view_layer(ViewLayer *view_layer)
void id_us_min(ID *id)
Definition lib_id.cc:441
bNodeLink & version_node_add_link(bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b)
short do_versions_new_to_old_idcode_get(const short id_code_new)
bNodeSocket * version_node_add_socket_if_not_exist(bNodeTree *ntree, bNode *node, int in_out, int type, int subtype, const char *identifier, const char *name)
bNodeTree * version_get_scene_compositor_node_tree(Main *bmain, Scene *scene)
bNode & version_node_add_unknown(bNodeTree &ntree, bke::bNodeType &ntype, const char *idname, const int16_t legacy_type, const std::string &ui_name, const std::string &ui_description, const std::string &enum_name_legacy, const short nclass, const float width, const float height, const bool no_muting)
void version_node_socket_name(bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
signed short int16_t
Definition BKE_text.h:77
ListBaseT< ID > * which_libbase(Main *bmain, short type)
Definition main.cc:1073
void BKE_ntree_update_tag_node_new(bNodeTree *ntree, bNode *node)
bNodeSocket & version_node_add_socket(bNodeTree &ntree, bNode &node, const eNodeSocketInOut in_out, const char *idname, const char *identifier)
void version_node_remove(bNodeTree &ntree, bNode &node)
eRegion_Type regiontype
short flag
Definition DNA_ID.h:439
ListBaseT< Library > libraries
Definition BKE_main.hh:387
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
DNA_DEPRECATED IDProperty * prop
struct Editing * ed
DNA_DEPRECATED struct bNodeTree * compositing_node_group
DNA_DEPRECATED struct bNodeTree * nodetree
struct RenderData r
struct IDProperty * system_properties
eNodeSocketDatatype type
struct bNodeLink * link
bke::bNodeSocketRuntime * runtime
eNodeSocketInOut in_out
struct CompositorNodeAssetTraits * compositor_node_asset_traits
ListBaseT< bNodeLink > links
bNodeTreeInterface tree_interface
ListBaseT< bNode > nodes
struct bNode * parent
ListBaseT< bNodeSocket > outputs
ListBaseT< bNodeSocket > inputs
Defines a socket type.
Definition BKE_node.hh:163
eNodeSocketDatatype type
Definition BKE_node.hh:198
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
const char * enum_name_legacy
Definition BKE_node.hh:274