Blender V5.3
versioning_501.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#define DNA_DEPRECATED_ALLOW
10
11#include "DNA_ID.h"
12
13#include "DNA_brush_enums.h"
14#include "DNA_brush_types.h"
15#include "DNA_light_types.h"
16#include "DNA_material_types.h"
17#include "DNA_mesh_types.h"
18#include "DNA_node_types.h"
19#include "DNA_screen_types.h"
20#include "DNA_sequence_types.h"
22#include "DNA_workspace_types.h"
23
24#include "BLI_listbase.hh"
25#include "BLI_math_vector_c.hh"
26#include "BLI_string.hh"
27#include "BLI_sys_types.hh"
28
29#include "BKE_asset.hh"
31#include "BKE_customdata.hh"
33#include "BKE_idprop.hh"
34#include "BKE_lib_id.hh"
35#include "BKE_main.hh"
36#include "BKE_node.hh"
38#include "BKE_node_runtime.hh"
39#include "BKE_tracking.hh"
40
41#include "SEQ_iterator.hh"
42#include "SEQ_sequencer.hh"
43
44#include "readfile.hh"
45
46#include "versioning_common.hh"
47
48// #include "CLG_log.h"
49
50namespace blender {
51
52// static CLG_LogRef LOG = {"blend.doversion"};
53
54/* The Mix mode of the Mix node previously assumed the alpha of the first input as opposed to
55 * mixing the alpha as well. So we add a separate color node to get the alpha of the first input
56 * and set it to the result using a set alpha node. */
58{
60 return;
61 }
62 const NodeShaderMix *data = reinterpret_cast<NodeShaderMix *>(node.storage);
63 if (data->data_type != SOCK_RGBA) {
64 return;
65 }
66
67 if (data->blend_type != MA_RAMP_BLEND) {
68 return;
69 }
70
71 bNodeSocket *first_input = bke::node_find_socket(node, SOCK_IN, "A_Color"_ustr);
72 bNodeSocket *output = bke::node_find_socket(node, SOCK_OUT, "Result_Color"_ustr);
73
74 /* Find the link going into the inputs of the node. */
75 bNodeLink *first_link = nullptr;
76 for (bNodeLink &link : node_tree.links) {
77 if (link.tosock == first_input) {
78 first_link = &link;
79 }
80 }
81
82 bNode &separate_node = version_node_add_empty(node_tree, "CompositorNodeSeparateColor");
83 /* Preserve the muted state on the new node so restoring all nodes later behaves the same way. */
84 SET_FLAG_FROM_TEST(separate_node.flag, node.flag & NODE_MUTED, NODE_MUTED);
85 separate_node.parent = node.parent;
86 separate_node.location[0] = node.location[0] - 10.0f;
87 separate_node.location[1] = node.location[1];
88 NodeCMPCombSepColor *storage = MEM_new<NodeCMPCombSepColor>(__func__);
90 separate_node.storage = storage;
91
92 bNodeSocket &separate_input = version_node_add_socket(
93 node_tree, separate_node, SOCK_IN, "NodeSocketColor", "Image");
94 bNodeSocket &separate_alpha_output = version_node_add_socket(
95 node_tree, separate_node, SOCK_OUT, "NodeSocketFloat", "Alpha");
96
97 copy_v4_v4(separate_input.default_value_typed<bNodeSocketValueRGBA>()->value,
98 first_input->default_value_typed<bNodeSocketValueRGBA>()->value);
99 if (first_link) {
101 node_tree, *first_link->fromnode, *first_link->fromsock, separate_node, separate_input);
102 }
103
104 bNode &set_alpha_node = version_node_add_empty(node_tree, "CompositorNodeSetAlpha");
105 SET_FLAG_FROM_TEST(set_alpha_node.flag, node.flag & NODE_MUTED, NODE_MUTED);
106 set_alpha_node.parent = node.parent;
107 set_alpha_node.location[0] = node.location[0] - 10.0f;
108 set_alpha_node.location[1] = node.location[1];
109 set_alpha_node.storage = MEM_new<NodeCMPCombSepColor>(__func__);
110
111 bNodeSocket &set_alpha_image_input = version_node_add_socket(
112 node_tree, set_alpha_node, SOCK_IN, "NodeSocketColor", "Image");
113 bNodeSocket &set_alpha_alpha_input = version_node_add_socket(
114 node_tree, set_alpha_node, SOCK_IN, "NodeSocketFloat", "Alpha");
115 bNodeSocket &set_alpha_type_input = version_node_add_socket(
116 node_tree, set_alpha_node, SOCK_IN, "NodeSocketMenu", "Type");
117 bNodeSocket &set_alpha_output = version_node_add_socket(
118 node_tree, set_alpha_node, SOCK_OUT, "NodeSocketColor", "Image");
119
120 set_alpha_type_input.default_value_typed<bNodeSocketValueMenu>()->value =
122 version_node_add_link(node_tree, node, *output, set_alpha_node, set_alpha_image_input);
124 node_tree, separate_node, separate_alpha_output, set_alpha_node, set_alpha_alpha_input);
125
126 for (bNodeLink &link : node_tree.links.items_reversed_mutable()) {
127 if (link.fromsock == output && link.tonode != &set_alpha_node) {
129 node_tree, set_alpha_node, set_alpha_output, *link.tonode, *link.tosock);
130 bke::node_remove_link(&node_tree, link);
131 }
132 }
133}
134
135/* The Mix mode of the Mix node previously assumed the alpha of the first input as opposed to
136 * mixing the alpha as well. So we add a separate color node to get the alpha of the first input
137 * and set it to the result using a pair of separate and combine color nodes. */
139{
141 return;
142 }
143 const NodeShaderMix *data = reinterpret_cast<NodeShaderMix *>(node.storage);
144 if (data->data_type != SOCK_RGBA) {
145 return;
146 }
147
148 if (data->blend_type != MA_RAMP_BLEND) {
149 return;
150 }
151
152 bNodeSocket *first_input = bke::node_find_socket(node, SOCK_IN, "A_Color"_ustr);
153 bNodeSocket *output = bke::node_find_socket(node, SOCK_OUT, "Result_Color"_ustr);
154
155 /* Find the link going into the inputs of the node. */
156 bNodeLink *first_link = nullptr;
157 for (bNodeLink &link : node_tree.links) {
158 if (link.tosock == first_input) {
159 first_link = &link;
160 }
161 }
162
163 bNode &separate_alpha_node = version_node_add_empty(node_tree, "FunctionNodeSeparateColor");
164 separate_alpha_node.parent = node.parent;
165 separate_alpha_node.location[0] = node.location[0] - 10.0f;
166 separate_alpha_node.location[1] = node.location[1];
167 NodeCombSepColor *separate_alpha_storage = MEM_new<NodeCombSepColor>(__func__);
168 separate_alpha_storage->mode = NODE_COMBSEP_COLOR_RGB;
169 separate_alpha_node.storage = separate_alpha_storage;
170
171 bNodeSocket &separate_alpha_input = version_node_add_socket(
172 node_tree, separate_alpha_node, SOCK_IN, "NodeSocketColor", "Color");
173 bNodeSocket &separate_alpha_output = version_node_add_socket(
174 node_tree, separate_alpha_node, SOCK_OUT, "NodeSocketFloat", "Alpha");
175
176 copy_v4_v4(separate_alpha_input.default_value_typed<bNodeSocketValueRGBA>()->value,
177 first_input->default_value_typed<bNodeSocketValueRGBA>()->value);
178 if (first_link) {
179 version_node_add_link(node_tree,
180 *first_link->fromnode,
181 *first_link->fromsock,
182 separate_alpha_node,
183 separate_alpha_input);
184 }
185
186 bNode &separate_color_node = version_node_add_empty(node_tree, "FunctionNodeSeparateColor");
187 separate_color_node.parent = node.parent;
188 separate_color_node.location[0] = node.location[0] - 10.0f;
189 separate_color_node.location[1] = node.location[1];
190 NodeCombSepColor *separate_color_storage = MEM_new<NodeCombSepColor>(__func__);
191 separate_color_storage->mode = NODE_COMBSEP_COLOR_RGB;
192 separate_color_node.storage = separate_color_storage;
193
194 bNodeSocket &separate_color_input = version_node_add_socket(
195 node_tree, separate_color_node, SOCK_IN, "NodeSocketColor", "Color");
196 bNodeSocket &separate_color_red_output = version_node_add_socket(
197 node_tree, separate_color_node, SOCK_OUT, "NodeSocketFloat", "Red");
198 bNodeSocket &separate_color_green_output = version_node_add_socket(
199 node_tree, separate_color_node, SOCK_OUT, "NodeSocketFloat", "Green");
200 bNodeSocket &separate_color_blue_output = version_node_add_socket(
201 node_tree, separate_color_node, SOCK_OUT, "NodeSocketFloat", "Blue");
202
203 version_node_add_link(node_tree, node, *output, separate_color_node, separate_color_input);
204
205 bNode &combine_color_node = version_node_add_empty(node_tree, "FunctionNodeCombineColor");
206 combine_color_node.parent = node.parent;
207 combine_color_node.location[0] = node.location[0] - 10.0f;
208 combine_color_node.location[1] = node.location[1];
209 NodeCombSepColor *combine_color_storage = MEM_new<NodeCombSepColor>(__func__);
210 combine_color_storage->mode = NODE_COMBSEP_COLOR_RGB;
211 combine_color_node.storage = combine_color_storage;
212
213 bNodeSocket &combine_color_red_input = version_node_add_socket(
214 node_tree, combine_color_node, SOCK_IN, "NodeSocketFloat", "Red");
215 bNodeSocket &combine_color_green_input = version_node_add_socket(
216 node_tree, combine_color_node, SOCK_IN, "NodeSocketFloat", "Green");
217 bNodeSocket &combine_color_blue_input = version_node_add_socket(
218 node_tree, combine_color_node, SOCK_IN, "NodeSocketFloat", "Blue");
219 bNodeSocket &combine_color_alpha_input = version_node_add_socket(
220 node_tree, combine_color_node, SOCK_IN, "NodeSocketFloat", "Alpha");
221 bNodeSocket &combine_color_output = version_node_add_socket(
222 node_tree, combine_color_node, SOCK_OUT, "NodeSocketColor", "Color");
223
224 version_node_add_link(node_tree,
225 separate_color_node,
226 separate_color_red_output,
227 combine_color_node,
228 combine_color_red_input);
229 version_node_add_link(node_tree,
230 separate_color_node,
231 separate_color_green_output,
232 combine_color_node,
233 combine_color_green_input);
234 version_node_add_link(node_tree,
235 separate_color_node,
236 separate_color_blue_output,
237 combine_color_node,
238 combine_color_blue_input);
239 version_node_add_link(node_tree,
240 separate_alpha_node,
241 separate_alpha_output,
242 combine_color_node,
243 combine_color_alpha_input);
244
245 for (bNodeLink &link : node_tree.links.items_reversed_mutable()) {
246 if (link.fromsock == output && link.tonode != &separate_color_node) {
248 node_tree, combine_color_node, combine_color_output, *link.tonode, *link.tosock);
249 bke::node_remove_link(&node_tree, link);
250 }
251 }
252}
253
255{
256 for (bNodeTree &group : bmain.nodetrees) {
257 if (group.type != NTREE_GEOMETRY) {
258 continue;
259 }
260 if (!group.geometry_node_asset_traits) {
261 continue;
262 }
264 continue;
265 }
266 std::string name_str = "geometry.";
267 for (char c : StringRef(BKE_id_name(group.id))) {
268 c = tolower(c);
269 if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_') {
270 name_str.push_back(c);
271 }
272 else {
273 const bool last_is_underscore = name_str[name_str.size() - 1] == '_';
274 if (!last_is_underscore) {
275 name_str.push_back('_');
276 }
277 }
278 }
280 name_str.size());
281 if (group.id.asset_data) {
282 auto property = bke::idprop::create(
283 "node_tool_idname", StringRefNull(group.geometry_node_asset_traits->node_tool_idname));
284 BKE_asset_metadata_idprop_ensure(group.id.asset_data, property.release());
285 }
286 }
287}
288
290{
291 for (bNodeTree &node_tree : bmain.nodetrees) {
292 if (node_tree.type != NTREE_GEOMETRY) {
293 continue;
294 }
295 for (bNode &node : node_tree.nodes) {
296 if (node.type_legacy != GEO_NODE_REALIZE_INSTANCES) {
297 continue;
298 }
300 }
301 }
302}
303
305{
306 for (Mesh &mesh : bmain.meshes) {
307 const CustomData *data = &mesh.corner_data;
308 if (!mesh.active_uv_map_attribute) {
309 if (const char *name = CustomData_get_active_layer_name(data, CD_PROP_FLOAT2)) {
310 mesh.active_uv_map_attribute = BLI_strdup(name);
311 }
312 }
313 if (!mesh.default_uv_map_attribute) {
314 if (const char *name = CustomData_get_render_layer_name(data, CD_PROP_FLOAT2)) {
315 mesh.default_uv_map_attribute = BLI_strdup(name);
316 }
317 }
318 }
319}
320
322{
323 for (Scene &scene : bmain.scenes) {
324 Editing *ed = seq::editing_get(&scene);
325 if (ed != nullptr) {
326 seq::foreach_strip(&ed->seqbase, [&](Strip *strip) {
327 constexpr int flag_overlap = 1 << 3;
328 constexpr int flag_ipo_frame_locked = 1 << 8;
329 constexpr int flag_effect_not_loaded = 1 << 9;
330 constexpr int flag_delete = 1 << 10;
331 constexpr int flag_ignore_channel_lock = 1 << 16;
332 constexpr int flag_show_offsets = 1 << 20;
333 strip->flag &= ~eStripFlag(flag_overlap | flag_ipo_frame_locked | flag_effect_not_loaded |
334 flag_delete | flag_ignore_channel_lock | flag_show_offsets);
335 return true;
336 });
337 }
338 }
339}
340
342{
343 if (!node.storage) {
344 return;
345 }
346 auto &storage = *reinterpret_cast<NodeGeometryStringToCurves *>(node.storage);
347 if (!blender::bke::node_find_socket(node, SOCK_IN, "Font"_ustr)) {
348 bNodeSocket &socket = version_node_add_socket(tree, node, SOCK_IN, "NodeSocketFont", "Font");
349 socket.default_value_typed<bNodeSocketValueFont>()->value = reinterpret_cast<VFont *>(node.id);
350 node.id = nullptr;
351 }
352 if (!blender::bke::node_find_socket(node, SOCK_IN, "Overflow"_ustr)) {
354 tree, node, SOCK_IN, "NodeSocketMenu", "Overflow");
355 socket.default_value_typed<bNodeSocketValueMenu>()->value = storage.overflow;
356 }
357 if (!blender::bke::node_find_socket(node, SOCK_IN, "Align X"_ustr)) {
359 tree, node, SOCK_IN, "NodeSocketMenu", "Align X");
360 socket.default_value_typed<bNodeSocketValueMenu>()->value = storage.align_x;
361 }
362 if (!blender::bke::node_find_socket(node, SOCK_IN, "Align Y"_ustr)) {
364 tree, node, SOCK_IN, "NodeSocketMenu", "Align Y");
365 socket.default_value_typed<bNodeSocketValueMenu>()->value = storage.align_y;
366 }
367 if (!blender::bke::node_find_socket(node, SOCK_IN, "Pivot Point"_ustr)) {
369 tree, node, SOCK_IN, "NodeSocketMenu", "Pivot Point");
370 socket.default_value_typed<bNodeSocketValueMenu>()->value = storage.pivot_mode;
371 }
372}
373
374static const char *legacy_pass_name_to_new_name(const char *name)
375{
376 if (STREQ(name, "DiffDir")) {
377 return "Diffuse Direct";
378 }
379 if (STREQ(name, "DiffInd")) {
380 return "Diffuse Indirect";
381 }
382 if (STREQ(name, "DiffCol")) {
383 return "Diffuse Color";
384 }
385 if (STREQ(name, "GlossDir")) {
386 return "Glossy Direct";
387 }
388 if (STREQ(name, "GlossInd")) {
389 return "Glossy Indirect";
390 }
391 if (STREQ(name, "GlossCol")) {
392 return "Glossy Color";
393 }
394 if (STREQ(name, "TransDir")) {
395 return "Transmission Direct";
396 }
397 if (STREQ(name, "TransInd")) {
398 return "Transmission Indirect";
399 }
400 if (STREQ(name, "TransCol")) {
401 return "Transmission Color";
402 }
403 if (STREQ(name, "VolumeDir")) {
404 return "Volume Direct";
405 }
406 if (STREQ(name, "VolumeInd")) {
407 return "Volume Indirect";
408 }
409 if (STREQ(name, "VolumeCol")) {
410 return "Volume Color";
411 }
412 if (STREQ(name, "AO")) {
413 return "Ambient Occlusion";
414 }
415 if (STREQ(name, "Env")) {
416 return "Environment";
417 }
418 if (STREQ(name, "IndexMA")) {
419 return "Material Index";
420 }
421 if (STREQ(name, "IndexOB")) {
422 return "Object Index";
423 }
424 if (STREQ(name, "GreasePencil")) {
425 return "Grease Pencil";
426 }
427 if (STREQ(name, "Emit")) {
428 return "Emission";
429 }
430 if (STREQ(name, "Z")) {
431 return "Depth";
432 }
433 if (STREQ(name, "Speed")) {
434 return "Vector";
435 }
436
437 return name;
438}
439
441{
442 if (light->use_nodes) {
443 return;
444 }
445
446 /* Users defined a light node tree, but deactivated it by disabling "Use Nodes". So we
447 * simulate the same effect by creating a new Light Output node and setting it to active. */
448 bNodeTree *ntree = light->nodetree;
449 if (ntree == nullptr) {
450 /* In case the light was defined through Python API it might have been missing a node tree.
451 */
453 bmain, &light->id, "Light Node Tree Versioning", "ShaderNodeTree");
454 }
455
456 bNode *old_output = nullptr;
457 for (bNode &node : ntree->nodes) {
458 if (STREQ(node.idname, "ShaderNodeOutputLight") && (node.flag & NODE_DO_OUTPUT)) {
459 old_output = &node;
460 old_output->flag &= ~NODE_DO_OUTPUT;
461 }
462 }
463
464 bNode &new_output = version_node_add_empty(*ntree, "ShaderNodeOutputLight");
465 bNodeSocket &output_surface_input = version_node_add_socket(
466 *ntree, new_output, SOCK_IN, "NodeSocketShader", "Surface");
467 new_output.flag |= NODE_DO_OUTPUT;
468
469 bNode &emission = version_node_add_empty(*ntree, "ShaderNodeEmission");
470 bNodeSocket &emission_color_input = version_node_add_socket(
471 *ntree, emission, SOCK_IN, "NodeSocketColor", "Color");
472 bNodeSocket &emission_strength_input = version_node_add_socket(
473 *ntree, emission, SOCK_IN, "NodeSocketFloat", "Strength");
474 bNodeSocket &emission_output = version_node_add_socket(
475 *ntree, emission, SOCK_OUT, "NodeSocketShader", "Emission");
476
477 version_node_add_link(*ntree, emission, emission_output, new_output, output_surface_input);
478
479 bNodeSocketValueRGBA *rgba = emission_color_input.default_value_typed<bNodeSocketValueRGBA>();
480 rgba->value[0] = 1.0f;
481 rgba->value[1] = 1.0f;
482 rgba->value[2] = 1.0f;
483 rgba->value[3] = 1.0f;
484 emission_strength_input.default_value_typed<bNodeSocketValueFloat>()->value = 1.0f;
485
486 if (old_output != nullptr) {
487 /* Position the newly created node after the old output. Assume the old output node is at
488 * the far right of the node tree. */
489 emission.location[0] = old_output->location[0] + 1.5f * old_output->width;
490 emission.location[1] = old_output->location[1];
491 }
492 else {
493 /* Use default position, see #node_tree_shader_default() */
494 emission.location[0] = -200.0f;
495 emission.location[1] = 100.0f;
496 }
497
498 new_output.location[0] = emission.location[0] + 2.0f * emission.width;
499 new_output.location[1] = emission.location[1];
500}
501
502/* For cycles, the Denoising Albedo render pass is now registered after the Denoising Normal pass
503 * to match the compositor Denoise node. So we swap the order of Denoising Albedo and Denoising
504 * Normal sockets in the Render Layers node that has been saved with the old order. */
506{
507 bNodeSocket *socket_denoise_normal = nullptr;
508 bNodeSocket *socket_denoise_albedo = nullptr;
509 for (bNodeSocket &socket : node.outputs) {
510 if (STREQ(socket.identifier, "Denoising Normal")) {
511 socket_denoise_normal = &socket;
512 }
513 if (STREQ(socket.identifier, "Denoising Albedo")) {
514 socket_denoise_albedo = &socket;
515 }
516 }
517 if (socket_denoise_albedo && socket_denoise_normal) {
518 BLI_listbase_swaplinks(&node.outputs, socket_denoise_normal, socket_denoise_albedo);
519 }
520}
521
522/* Some nodes no longer have storage but their storage is still allocated at write time for
523 * forward compatibility. This only happens during writes from 4.5, so we need to free this
524 * storage again when loading any file from 4.5. But before this versioning was done, it was
525 * possible to save a file from 4.5 in 5.0 or 5.1 and it would still have the storage, so we also
526 * need to include versions up to the current 5.1 subversion. */
528{
529 if (!node.storage) {
530 return;
531 }
532
533 switch (node.type_legacy) {
535 MEM_delete(static_cast<NodeBokehImage *>(node.storage));
536 break;
537 case CMP_NODE_MASK:
538 MEM_delete(static_cast<NodeMask *>(node.storage));
539 break;
541 MEM_delete(static_cast<NodeAntiAliasingData *>(node.storage));
542 break;
543 case CMP_NODE_VECBLUR:
544 MEM_delete(static_cast<NodeBlurData *>(node.storage));
545 break;
550 MEM_delete(static_cast<NodeChroma *>(node.storage));
551 break;
553 MEM_delete(static_cast<NodeColorCorrection *>(node.storage));
554 break;
556 MEM_delete(static_cast<NodeBoxMask *>(node.storage));
557 break;
559 MEM_delete(static_cast<NodeEllipseMask *>(node.storage));
560 break;
562 MEM_delete(static_cast<NodeSunBeams *>(node.storage));
563 break;
564 case CMP_NODE_DBLUR:
565 MEM_delete(static_cast<NodeDBlurData *>(node.storage));
566 break;
568 MEM_delete(static_cast<NodeBilateralBlurData *>(node.storage));
569 break;
570 case CMP_NODE_CROP:
571 MEM_delete(static_cast<NodeTwoXYs *>(node.storage));
572 break;
574 MEM_delete(static_cast<NodeColorBalance *>(node.storage));
575 break;
576 default:
577 return;
578 }
579
580 node.storage = nullptr;
581}
582
584{
585 /* BRUSH_AIRBRUSH was replaced with BRUSH_UNUSED_1 in 29c9353429f4b60c6e4ad234a4d6392a1f513079
586 * and subsequently re-used for BRUSH_HARDNESS_PRESSURE in 5.3 subversion 22. */
587 constexpr eBrushFlags BRUSH_AIRBRUSH = eBrushFlags(1 << 0);
588 if (brush.flag & BRUSH_AIRBRUSH) {
589 brush.flag &= ~BRUSH_AIRBRUSH;
590 brush.stroke_method = BRUSH_STROKE_AIRBRUSH;
591 }
592 else if (brush.flag & BRUSH_UNUSED_2) {
593 brush.flag &= ~BRUSH_UNUSED_2;
594 brush.stroke_method = BRUSH_STROKE_ANCHORED;
595 }
596 else if (brush.flag & BRUSH_UNUSED_3) {
597 brush.flag &= ~BRUSH_UNUSED_3;
598 brush.stroke_method = BRUSH_STROKE_SPACE;
599 }
600 else if (brush.flag & BRUSH_UNUSED_4) {
601 brush.flag &= ~BRUSH_UNUSED_4;
602 brush.stroke_method = BRUSH_STROKE_DRAG_DOT;
603 }
604 else if (brush.flag & BRUSH_UNUSED_5) {
605 brush.flag &= ~BRUSH_UNUSED_5;
606 brush.stroke_method = BRUSH_STROKE_LINE;
607 }
608 else if (brush.flag & BRUSH_UNUSED_6) {
609 brush.flag &= ~BRUSH_UNUSED_6;
610 brush.stroke_method = BRUSH_STROKE_CURVE;
611 }
612 else {
613 brush.stroke_method = BRUSH_STROKE_DOTS;
614 }
615}
616
618{
619 /* Some blend files were saved with an invalid active viewer key, possibly due to a bug that
620 * was fixed already in c8cb24121f, but blend files were never updated. So starting in 5.1, we
621 * fix those files by essentially doing what ED_node_set_active_viewer_key is supposed to do at
622 * load time during versioning. Note that the invalid active viewer will just cause a harmless
623 * assert, so this does not need to exist in previous releases. */
624 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 0)) {
625 for (bScreen &screen : bmain->screens) {
626 for (ScrArea &area : screen.areabase) {
627 for (SpaceLink &space : area.spacedata) {
628 if (space.spacetype == SPACE_NODE) {
629 SpaceNode *space_node = reinterpret_cast<SpaceNode *>(&space);
630 bNodeTreePath *path = space_node->treepath.last();
631 if (space_node->nodetree && path) {
632 space_node->nodetree->active_viewer_key = path->parent_key;
633 }
634 }
635 }
636 }
637 }
638 }
639
640 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 0)) {
642 }
643
644 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 24)) {
645 /* Note: For legacy Grease Pencil objects (#OB_GPENCIL_LEGACY) this is handled as part of
646 * bke::greasepencil::convert::legacy_main. */
648 *bmain, {}, *fd->reports);
649 /* Set the stroke mode for all brushes. */
650 for (Brush &brush : bmain->brushes) {
651 if (BrushGpencilSettings *settings = brush.gpencil_settings) {
652 if (Material *material = settings->material) {
653 BLI_assert(material->gp_style != nullptr);
654 SET_FLAG_FROM_TEST(settings->flag2,
655 (material->gp_style->flag & GP_MATERIAL_STROKE_SHOW) != 0,
657 SET_FLAG_FROM_TEST(settings->flag2,
658 (material->gp_style->flag & GP_MATERIAL_FILL_SHOW) != 0,
660 }
661 else {
662 settings->flag2 |= GP_BRUSH_USE_STROKE;
663 settings->flag2 &= ~GP_BRUSH_USE_FILL;
664 }
665 }
666 }
667 /* Set the color to transparent for when the stroke/fill is disabled. */
668 for (Material &material : bmain->materials) {
669 if (material.gp_style == nullptr) {
670 continue;
671 }
672 MaterialGPencilStyle &gp_style = *material.gp_style;
673 if ((gp_style.flag & GP_MATERIAL_STROKE_SHOW) == 0) {
674 gp_style.stroke_rgba[3] = 0.0f;
675 }
676 if ((gp_style.flag & GP_MATERIAL_FILL_SHOW) == 0) {
677 gp_style.fill_rgba[3] = 0.0f;
678 }
679 }
680 }
681
688}
689
690void blo_do_versions_501(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
691{
692 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 1)) {
693 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
694 if (node_tree->type == NTREE_COMPOSIT) {
695 for (bNode &node : node_tree->nodes) {
696 if (node.type_legacy == SH_NODE_MIX) {
698 }
699 }
700 }
701 else if (node_tree->type == NTREE_GEOMETRY) {
702 for (bNode &node : node_tree->nodes) {
703 if (node.type_legacy == SH_NODE_MIX) {
705 }
706 }
707 }
708 }
710 }
711
712 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 5)) {
714 }
715
716 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 7)) {
718 }
719
720 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 8)) {
721 for (Object &obj : bmain->objects) {
722 if (!obj.pose) {
723 continue;
724 }
725 for (bPoseChannel &pose_bone : obj.pose->chanbase) {
726 /* Those flags were previously unused, so to be safe we clear them. */
727 pose_bone.flag &= ~(POSE_SELECTED_ROOT | POSE_SELECTED_TIP);
728 }
729 }
730 }
731
732 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 9)) {
734
735 for (Scene &scene : bmain->scenes) {
737 }
738 }
739
740 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 10)) {
741 for (wmWindowManager &wm : bmain->wm) {
742 wm.xr.session_settings.view_scale = 1.0f;
743 }
744 }
745
746 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 12)) {
747 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
748 if (node_tree->type == NTREE_COMPOSIT) {
750 }
751 }
753 }
754
755 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 13)) {
756 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
757 if (node_tree->type == NTREE_COMPOSIT) {
758 for (bNode &node : node_tree->nodes) {
759 if (node.type_legacy == CMP_NODE_R_LAYERS) {
760 for (bNodeSocket &socket : node.outputs) {
761 const char *new_pass_name = legacy_pass_name_to_new_name(socket.name);
762 STRNCPY(socket.name, new_pass_name);
763 const char *new_pass_identifier = legacy_pass_name_to_new_name(socket.identifier);
764 version_node_socket_identifier_set(socket, new_pass_identifier);
765 }
766 }
767 }
768 }
769 }
771 }
772
773 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 14)) {
774 for (bScreen &screen : bmain->screens) {
775 for (ScrArea &area : screen.areabase) {
776 for (SpaceLink &sl : area.spacedata) {
777 if (sl.spacetype == SPACE_IMAGE) {
778 SpaceImage *sima = reinterpret_cast<SpaceImage *>(&sl);
779 sima->uv_edge_opacity = sima->uv_opacity;
780 }
781 }
782 }
783 }
784 }
785
786 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 16)) {
787 for (Scene &scene : bmain->scenes) {
788 if (scene.toolsettings) {
789 scene.toolsettings->anim_mirror_object = nullptr;
790 scene.toolsettings->anim_relative_object = nullptr;
791 scene.toolsettings->anim_mirror_bone[0] = '\0';
792 }
793 }
794 }
795
796 /* This has no version check and always runs for all versions because there is forward
797 * compatibility code at write time that reallocates the storage, so we need to free it
798 * regardless of the version. */
799 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
800 if (node_tree->type == NTREE_COMPOSIT) {
801 for (bNode &node : node_tree->nodes) {
802 if (ELEM(node.type_legacy, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) {
803 for (bNodeSocket &socket : node.outputs) {
804 if (socket.storage) {
805 MEM_delete_void(socket.storage);
806 socket.storage = nullptr;
807 }
808 }
809 }
810 }
811 }
812 }
814
815 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 15)) {
816 for (Light &light : bmain->lights) {
818 }
819 }
820
821 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 17)) {
822 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
823 if (node_tree->type == NTREE_COMPOSIT) {
824 for (bNode &node : node_tree->nodes) {
825 if (node.type_legacy == CMP_NODE_MOVIEDISTORTION) {
826 if (node.storage) {
827 BKE_tracking_distortion_free(static_cast<MovieDistortion *>(node.storage));
828 }
829 node.storage = nullptr;
830 }
831 }
832 }
833 }
835 }
836
837 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 18)) {
838 FOREACH_NODETREE_BEGIN (bmain, tree, id) {
839 if (tree->type == NTREE_GEOMETRY) {
840 for (bNode &node : tree->nodes) {
841 if (node.type_legacy == GEO_NODE_STRING_TO_CURVES) {
843 }
844 }
845 }
846 }
848 }
849
850 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 19)) {
851 for (Mesh &mesh : bmain->meshes) {
853 }
854 }
855
856 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 20)) {
857 for (Scene &scene : bmain->scenes) {
859 constexpr eSequencerSnapMode SEQ_SNAP_TO_FRAME_RANGE_OLD = eSequencerSnapMode(1 << 8);
860 /* Snap to frame range was bit 8, now bit 9, to make room for snap to increment in bit 8.
861 */
862 if (seq_ts->snap_mode & SEQ_SNAP_TO_FRAME_RANGE_OLD) {
863 seq_ts->snap_mode &= ~SEQ_SNAP_TO_FRAME_RANGE_OLD;
865 }
866 }
867 }
868
869 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 21)) {
870 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
871 if (node_tree->type == NTREE_COMPOSIT) {
872 for (bNode &node : node_tree->nodes) {
873 if (node.type_legacy == CMP_NODE_R_LAYERS) {
875 }
876 }
877 }
878 }
880 }
881
882 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 22)) {
883 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
884 if (node_tree->type == NTREE_COMPOSIT) {
885 for (bNode &node : node_tree->nodes) {
887 }
888 }
889 }
891 }
892
893 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 23)) {
894 for (Brush &brush : bmain->brushes) {
896 }
897 }
898
899 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 24)) {
900 FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
901 if (node_tree->type == NTREE_COMPOSIT) {
902 /* The 'Viewer Region' option was removed from the UI. */
903 node_tree->flag &= ~NTREE_VIEWER_BORDER;
904 }
905 }
907 }
908
909 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 25)) {
910 for (Scene &scene : bmain->scenes) {
911 scene.eevee.direct_light_intensity = 1.0f;
912 scene.eevee.indirect_light_intensity = 1.0f;
913 }
914 }
915
916 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 501, 27)) {
917 for (Scene &scene : bmain->scenes) {
918 if (scene.toolsettings) {
919 const short snap_geom_old = SCE_SNAP_TO_VERTEX | SCE_SNAP_TO_EDGE | SCE_SNAP_TO_FACE |
921 static_assert(snap_geom_old == 63);
922 if (scene.toolsettings->snap_mode_tools == snap_geom_old) {
924 }
925 }
926 }
927 }
928
935}
936
937} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
#define MAIN_VERSION_FILE_ATLEAST(main, ver, subver)
Definition BKE_main.hh:949
#define FOREACH_NODETREE_END
Definition BKE_node.hh:936
#define FOREACH_NODETREE_BEGIN(bmain, _nodetree, _id)
Definition BKE_node.hh:926
#define CMP_NODE_MASK
#define CMP_NODE_VECBLUR
#define CMP_NODE_LUMA_MATTE
#define CMP_NODE_MASK_ELLIPSE
#define CMP_NODE_BILATERALBLUR
#define CMP_NODE_MOVIEDISTORTION
#define CMP_NODE_COLORBALANCE
#define CMP_NODE_BOKEHIMAGE
#define CMP_NODE_DIFF_MATTE
#define CMP_NODE_CROP
#define CMP_NODE_CHROMA_MATTE
#define CMP_NODE_CRYPTOMATTE_LEGACY
#define CMP_NODE_SUNBEAMS_DEPRECATED
#define CMP_NODE_COLORCORRECTION
#define GEO_NODE_REALIZE_INSTANCES
#define SH_NODE_MIX
#define CMP_NODE_MASK_BOX
#define GEO_NODE_STRING_TO_CURVES
#define CMP_NODE_ANTIALIASING
#define CMP_NODE_R_LAYERS
#define CMP_NODE_COLOR_MATTE
#define CMP_NODE_IMAGE
#define CMP_NODE_DBLUR
ID and Library types, which are fundamental for SDNA.
#define SCE_SNAP_TO_GEOM
#define SCE_SNAP_TO_VERTEX
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define STREQ(a, b)
#define output
constexpr StringRefNull()
constexpr StringRef()
#define storage(slot, qualifiers)
void material_stroke_fill_toggles_to_attributes(Main &bmain, const std::optional< Set< GreasePencil * > > &filter, 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.
bNodeTree * node_tree_add_tree_embedded(Main *bmain, ID *owner_id, StringRefNull name, StringRefNull idname)
Definition node.cc:5005
void mesh_convert_customdata_to_storage(Mesh &mesh)
void node_remove_link(bNodeTree *ntree, bNodeLink &link)
Definition node.cc:4676
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
Definition node.cc:3036
void foreach_strip(ListBaseT< Strip > *seqbase, ForEachFunc callback, void *user_data)
Definition iterator.cc:60
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
SequencerToolSettings * tool_settings_ensure(Scene *scene)
Definition sequencer.cc:393
BMesh Iterators.
bool version_node_ensure_storage_or_invalidate(bNode &node)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop)
Definition asset.cc:172
static void do_version_mix_node_mix_mode_compositor(bNodeTree &node_tree, bNode &node)
@ BRUSH_STROKE_DRAG_DOT
@ BRUSH_STROKE_ANCHORED
@ BRUSH_STROKE_AIRBRUSH
@ CMP_NODE_COMBSEP_COLOR_RGB
static void version_clear_unused_strip_flags(Main &bmain)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void blo_do_versions_501(FileData *fd, Library *lib, Main *bmain)
@ NODE_COMBSEP_COLOR_RGB
const char * BKE_id_name(const ID &id)
static const char * legacy_pass_name_to_new_name(const char *name)
bNode & version_node_add_empty(bNodeTree &ntree, const char *idname)
void MEM_delete_void(void *vmemh)
@ CMP_NODE_SETALPHA_MODE_REPLACE_ALPHA
const char * CustomData_get_render_layer_name(const CustomData *data, eCustomDataType type)
void version_node_socket_identifier_set(bNodeSocket &socket, const StringRefNull identifier)
static void convert_brush_flags_to_type(Brush &brush)
BMesh const char void * data
@ SCE_SNAP_TO_EDGE_MIDPOINT
@ SCE_SNAP_TO_EDGE_PERPENDICULAR
void BLI_listbase_swaplinks(ListBase *listbase, void *vlinka, void *vlinkb) ATTR_NONNULL(1
Definition listbase.cc:171
static void do_version_light_remove_use_nodes(Main *bmain, Light *light)
const char * CustomData_get_active_layer_name(const CustomData *data, eCustomDataType type)
void do_versions_after_linking_501(FileData *fd, Main *bmain)
static void init_node_tool_operator_idnames(Main &bmain)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void BKE_tracking_distortion_free(MovieDistortion *distortion)
Definition tracking.cc:2414
void version_node_input_socket_name(bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
@ NTREE_VIEWER_BORDER
@ SEQ_SNAP_TO_FRAME_RANGE
@ GEO_NODE_REALIZE_TO_POINT_DOMAIN
MINLINE void copy_v4_v4(float r[4], const float a[4])
static void do_version_render_layers_node_albedo_normal_swap(bNode &node)
static void version_string_to_curves_node_inputs(bNodeTree &tree, bNode &node)
static void free_compositor_forward_compatibility_storage(bNode &node)
static void do_version_mix_node_mix_mode_geometry(bNodeTree &node_tree, bNode &node)
@ GP_BRUSH_USE_STROKE
bNodeLink & version_node_add_link(bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b)
static void version_mesh_uv_map_strings(Main &bmain)
bNodeSocket & version_node_add_socket(bNodeTree &ntree, bNode &node, const eNodeSocketInOut in_out, const char *idname, const char *identifier)
static void version_realize_instances_to_curve_domain(Main &bmain)
BlendFileReadReport * reports
Definition readfile.hh:208
struct AssetMetaData * asset_data
Definition DNA_ID.h:424
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< bNodeTree > nodetrees
Definition BKE_main.hh:409
ListBaseT< Light > lights
Definition BKE_main.hh:396
ListBaseT< Brush > brushes
Definition BKE_main.hh:410
ListBaseT< Material > materials
Definition BKE_main.hh:392
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Mesh > meshes
Definition BKE_main.hh:389
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
eMaterialGPencilStyle_Flag flag
NodeCombSepColorMode mode
struct bPose * pose
struct FFMpegCodecData ffcodecdata
struct RenderData r
struct SceneEEVEE eevee
struct ToolSettings * toolsettings
ListBaseT< SpaceLink > spacedata
struct bNodeTree * nodetree
ListBaseT< bNodeTreePath > treepath
struct Object * anim_mirror_object
struct Object * anim_relative_object
bNodeInstanceKey parent_key
ListBaseT< bNodeLink > links
struct GeometryNodeAssetTraits * geometry_node_asset_traits
eNodeTree_Type type
bNodeInstanceKey active_viewer_key
ListBaseT< bNode > nodes
struct bNode * parent
ListBaseT< bPoseChannel > chanbase
ListBaseT< struct ScrArea > areabase