Blender V5.3
versioning_404.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
9#define DNA_DEPRECATED_ALLOW
10
11#include <fmt/format.h>
12
13/* Define macros in `DNA_genfile.h`. */
14#define DNA_GENFILE_VERSIONING_MACROS
15
16#include "DNA_anim_types.h"
17#include "DNA_brush_types.h"
18#include "DNA_curves_types.h"
19#include "DNA_genfile.h"
20#include "DNA_modifier_types.h"
21#include "DNA_screen_types.h"
22#include "DNA_sequence_types.h"
23#include "DNA_workspace_types.h"
24
25#undef DNA_GENFILE_VERSIONING_MACROS
26
27#include "BLI_listbase.hh"
28#include "BLI_math_vector.hh"
29#include "BLI_math_vector_c.hh"
30#include "BLI_set.hh"
31#include "BLI_string.hh"
32#include "BLI_string_utf8.hh"
33
34#include "BKE_anim_data.hh"
35#include "BKE_fcurve.hh"
36#include "BKE_main.hh"
37#include "BKE_node.hh"
39#include "BKE_node_runtime.hh"
40#include "BKE_scene.hh"
41
42#include "SEQ_iterator.hh"
43#include "SEQ_sequencer.hh"
44
45#include "RNA_types.hh"
46
47#include "ANIM_action.hh"
49#include "ANIM_versioning.hh"
50
51#include "readfile.hh"
52
53#include "versioning_common.hh"
54
55namespace blender {
56
57/* The Threshold, Mix, and Size properties of the node were converted into node inputs, and
58 * two new outputs were added.
59 *
60 * A new Highlights output was added to expose the extracted highlights, this is not relevant for
61 * versioning.
62 *
63 * A new Glare output was added to expose just the generated glare without the input image itself.
64 * this relevant for versioning the Mix property as will be shown.
65 *
66 * The Threshold, Iterations, Fade, Color Modulation, Streaks, and Streaks Angle Offset properties
67 * were converted into node inputs, maintaining its type and range, so we just transfer its value
68 * as is.
69 *
70 * The Mix property was converted into a Strength input, but its range changed from [-1, 1] to [0,
71 * 1]. For the [-1, 0] sub-range, -1 used to mean zero strength and 0 used to mean full strength,
72 * so we can convert between the two ranges by negating the mix factor and subtracting it from 1.
73 * The [0, 1] sub-range on the other hand was useless except for the value 1, because it linearly
74 * interpolates between Image + Glare and Glare, so it essentially adds an attenuated version of
75 * the input image to the glare. When it is 1, only the glare is returned. So we split that range
76 * in half as a heuristic and for values in the range [0.5, 1], we just reconnect the output to the
77 * newly added Glare output.
78 *
79 * The Size property was converted into a float node input, and its range was changed from [1, 9]
80 * to [0, 1]. For Bloom, the [1, 9] range was related exponentially to the actual size of the
81 * glare, that is, 9 meant the glare covers the entire image, 8 meant it covers half, 7 meant it
82 * covers quarter and so on. The new range is linear and relative to the image size, that is, 1
83 * means the entire image and 0 means nothing. So we can convert from the [1, 9] range to [0, 1]
84 * range using the relation 2^(x-9).
85 * For Fog Glow, the [1, 9] range was related to the absolute size of the Fog Glow kernel in
86 * pixels, where it is 2^size pixels in size. There is no way to version this accurately, since the
87 * new size is relative to the input image size, which is runtime information. But we can assume
88 * the render size as a guess and compute the size relative to that. */
90 bNodeTree *node_tree,
91 bNode *node)
92{
93 NodeGlare *storage = static_cast<NodeGlare *>(node->storage);
94 if (!storage) {
95 return;
96 }
97
98 /* Get the newly added inputs. */
100 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_NONE, "Highlights Threshold", "Threshold");
102 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_FACTOR, "Strength", "Strength");
104 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_FACTOR, "Size", "Size");
106 node_tree, node, SOCK_IN, SOCK_INT, PROP_NONE, "Streaks", "Streaks");
108 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_ANGLE, "Streaks Angle", "Streaks Angle");
110 node_tree, node, SOCK_IN, SOCK_INT, PROP_NONE, "Iterations", "Iterations");
112 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_FACTOR, "Fade", "Fade");
114 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_FACTOR, "Color Modulation", "Color Modulation");
115
116 /* Function to remap the Mix property to the range of the new Strength input. See function
117 * description. */
118 auto mix_to_strength = [](const float mix) { return 1.0f - math::clamp(-mix, 0.0f, 1.0f); };
119
120 /* Find the render size to guess the Size value. The node tree might not belong to a scene, so we
121 * just assume an arbitrary HDTV 1080p render size. */
122 int2 render_size;
123 if (scene) {
124 BKE_render_resolution(&scene->r, true, &render_size.x, &render_size.y);
125 }
126 else {
127 render_size = int2(1920, 1080);
128 }
129
130 /* Function to remap the Size property to its new range. See function description. */
131 const int max_render_size = math::reduce_max(render_size);
132 auto size_to_linear = [&](const int size) {
133 if (storage->type == CMP_NODE_GLARE_BLOOM) {
134 return math::pow(2.0f, float(size - 9));
135 }
136 return math::min(1.0f, float((1 << size) + 1) / float(max_render_size));
137 };
138
139 /* Assign the inputs the values from the old deprecated properties. */
140 threshold->default_value_typed<bNodeSocketValueFloat>()->value = storage->threshold;
141 strength->default_value_typed<bNodeSocketValueFloat>()->value = mix_to_strength(storage->mix);
142 size->default_value_typed<bNodeSocketValueFloat>()->value = size_to_linear(storage->size);
143 streaks->default_value_typed<bNodeSocketValueInt>()->value = storage->streaks;
144 streaks_angle->default_value_typed<bNodeSocketValueFloat>()->value = storage->angle_ofs;
145 iterations->default_value_typed<bNodeSocketValueInt>()->value = storage->iter;
146 fade->default_value_typed<bNodeSocketValueFloat>()->value = storage->fade;
147 color_modulation->default_value_typed<bNodeSocketValueFloat>()->value = storage->colmod;
148
149 /* Compute the RNA path of the node. */
150 char escaped_node_name[sizeof(node->name) * 2 + 1];
151 BLI_str_escape(escaped_node_name, node->name, sizeof(escaped_node_name));
152 const std::string node_rna_path = fmt::format("nodes[\"{}\"]", escaped_node_name);
153
154 BKE_fcurves_id_cb(&node_tree->id, [&](ID * /*id*/, FCurve *fcurve) {
155 /* The FCurve does not belong to the node since its RNA path doesn't start with the node's RNA
156 * path. */
157 if (!fcurve->rna_path().startswith(node_rna_path)) {
158 return;
159 }
160
161 /* Change the RNA path of the FCurve from the old properties to the new inputs, adjusting the
162 * values of the FCurves frames when needed. */
163 if (BLI_str_endswith(fcurve->rna_path().c_str(), "threshold")) {
164 fcurve->rna_path_set_move(
165 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[1].default_value"));
166 }
167 else if (BLI_str_endswith(fcurve->rna_path().c_str(), "mix")) {
168 fcurve->rna_path_set_move(
169 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[2].default_value"));
170 adjust_fcurve_key_frame_values(
171 fcurve, PROP_FLOAT, [&](const float value) { return mix_to_strength(value); });
172 }
173 else if (BLI_str_endswith(fcurve->rna_path().c_str(), "size")) {
174 fcurve->rna_path_set_move(
175 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[3].default_value"));
176 adjust_fcurve_key_frame_values(
177 fcurve, PROP_FLOAT, [&](const float value) { return size_to_linear(value); });
178 }
179 else if (BLI_str_endswith(fcurve->rna_path().c_str(), "streaks")) {
180 fcurve->rna_path_set_move(
181 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[4].default_value"));
182 }
183 else if (BLI_str_endswith(fcurve->rna_path().c_str(), "angle_offset")) {
184 fcurve->rna_path_set_move(
185 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[5].default_value"));
186 }
187 else if (BLI_str_endswith(fcurve->rna_path().c_str(), "iterations")) {
188 fcurve->rna_path_set_move(
189 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[6].default_value"));
190 }
191 else if (BLI_str_endswith(fcurve->rna_path().c_str(), "fade")) {
192 fcurve->rna_path_set_move(
193 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[7].default_value"));
194 }
195 else if (BLI_str_endswith(fcurve->rna_path().c_str(), "color_modulation")) {
196 fcurve->rna_path_set_move(
197 BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[8].default_value"));
198 }
199 });
200
201 /* If the Mix factor is between [0.5, 1], then the user actually wants the Glare output, so
202 * reconnect the output to the newly created Glare output. */
203 if (storage->mix > 0.5f) {
204 bNodeSocket *image_output = version_node_add_socket_if_not_exist(
205 node_tree, node, SOCK_OUT, SOCK_RGBA, PROP_NONE, "Image", "Image");
206 bNodeSocket *glare_output = version_node_add_socket_if_not_exist(
207 node_tree, node, SOCK_OUT, SOCK_RGBA, PROP_NONE, "Glare", "Glare");
208
209 for (bNodeLink &link : node_tree->links.items_reversed_mutable()) {
210 if (link.fromsock != image_output) {
211 continue;
212 }
213
214 /* Relink from the Image output to the Glare output. */
215 bke::node_add_link(*node_tree, *node, *glare_output, *link.tonode, *link.tosock);
216 bke::node_remove_link(node_tree, link);
217 }
218 }
219}
220
222 const Scene *scene, bNodeTree *node_tree, Set<bNodeTree *> &node_trees_already_versioned)
223{
224 if (node_trees_already_versioned.contains(node_tree)) {
225 return;
226 }
227
228 for (bNode &node : node_tree->nodes) {
229 if (node.type_legacy == CMP_NODE_GLARE) {
231 }
232 else if (node.is_group()) {
233 bNodeTree *child_tree = reinterpret_cast<bNodeTree *>(node.id);
234 if (child_tree) {
236 scene, child_tree, node_trees_already_versioned);
237 }
238 }
239 }
240
241 node_trees_already_versioned.add_new(node_tree);
242}
243
244/* The bloom glare is now normalized by its chain length, see the compute_bloom_chain_length method
245 * in the glare code. So we need to multiply the strength by the chain length to restore its
246 * original value. Since the chain length depend on the input image size, which is runtime
247 * information, we assume the render size as a guess. */
249 bNodeTree *node_tree,
250 bNode *node)
251{
252 NodeGlare *storage = static_cast<NodeGlare *>(node->storage);
253 if (!storage) {
254 return;
255 }
256
257 if (storage->type != CMP_NODE_GLARE_BLOOM) {
258 return;
259 }
260
261 /* See the get_quality_factor method in the glare code. */
262 const int quality_factor = 1 << storage->quality;
263
264 /* Find the render size to guess the Strength value. The node tree might not belong to a scene,
265 * so we just assume an arbitrary HDTV 1080p render size. */
266 int2 render_size;
267 if (scene) {
268 BKE_render_resolution(&scene->r, true, &render_size.x, &render_size.y);
269 }
270 else {
271 render_size = int2(1920, 1080);
272 }
273
274 const int2 highlights_size = render_size / quality_factor;
275
277 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_FACTOR, "Size", "Size");
278 const float size_value = size->default_value_typed<bNodeSocketValueFloat>()->value;
279
280 /* See the compute_bloom_chain_length method in the glare code. */
281 const int smaller_dimension = math::reduce_min(highlights_size);
282 const float scaled_dimension = smaller_dimension * size_value;
283 const int chain_length = int(std::log2(math::max(1.0f, scaled_dimension)));
284
285 auto scale_strength = [chain_length](const float strength) { return strength * chain_length; };
286
288 node_tree, node, SOCK_IN, SOCK_FLOAT, PROP_FACTOR, "Strength", "Strength");
289 strength_input->default_value_typed<bNodeSocketValueFloat>()->value = scale_strength(
290 strength_input->default_value_typed<bNodeSocketValueFloat>()->value);
291
292 /* Compute the RNA path of the strength input. */
293 char escaped_node_name[sizeof(node->name) * 2 + 1];
294 BLI_str_escape(escaped_node_name, node->name, sizeof(escaped_node_name));
295 const std::string strength_rna_path = fmt::format("nodes[\"{}\"].inputs[4].default_value",
296 escaped_node_name);
297
298 /* Scale F-Curve. */
299 BKE_fcurves_id_cb(&node_tree->id, [&](ID * /*id*/, FCurve *fcurve) {
300 if (strength_rna_path == fcurve->rna_path()) {
301 adjust_fcurve_key_frame_values(
302 fcurve, PROP_FLOAT, [&](const float value) { return scale_strength(value); });
303 }
304 });
305}
306
308 const Scene *scene, bNodeTree *node_tree, Set<bNodeTree *> &node_trees_already_versioned)
309{
310 if (node_trees_already_versioned.contains(node_tree)) {
311 return;
312 }
313
314 for (bNode &node : node_tree->nodes) {
315 if (node.type_legacy == CMP_NODE_GLARE) {
316 do_version_glare_node_bloom_strength(scene, node_tree, &node);
317 }
318 else if (node.is_group()) {
319 bNodeTree *child_tree = reinterpret_cast<bNodeTree *>(node.id);
320 if (child_tree) {
322 scene, child_tree, node_trees_already_versioned);
323 }
324 }
325 }
326
327 node_trees_already_versioned.add_new(node_tree);
328}
329
330/* Previously, color to float implicit conversion happened by taking the average, while now it uses
331 * luminance coefficients. So we need to convert all implicit conversions manually by adding a
332 * dot product node that computes the average as before. */
334{
335 /* Stores a mapping between an output and the final link of the versioning node tree that was
336 * added for it, in order to share the same versioning node tree with potentially multiple
337 * outgoing links from that same output. */
338 Map<bNodeSocket *, bNodeLink *> color_to_float_links;
339 for (bNodeLink &link : node_tree->links.items_reversed_mutable()) {
340 if (!(link.fromsock->type == SOCK_RGBA && link.tosock->type == SOCK_FLOAT)) {
341 continue;
342 }
343
344 /* If that output was versioned before, just connect the existing link. */
345 bNodeLink *existing_link = color_to_float_links.lookup_default(link.fromsock, nullptr);
346 if (existing_link) {
347 version_node_add_link(*node_tree,
348 *existing_link->fromnode,
349 *existing_link->fromsock,
350 *link.tonode,
351 *link.tosock);
352 bke::node_remove_link(node_tree, link);
353 continue;
354 }
355
356 /* Add a hidden dot product node. */
357 bNode *dot_product_node = bke::node_add_static_node(nullptr, *node_tree, SH_NODE_VECTOR_MATH);
358 dot_product_node->custom1 = NODE_VECTOR_MATH_DOT_PRODUCT;
359 dot_product_node->flag |= NODE_COLLAPSED;
360 dot_product_node->location[0] = link.fromnode->location[0] + link.fromnode->width + 10.0f;
361 dot_product_node->location[1] = link.fromnode->location[1];
362
363 /* Link the source socket to the dot product input. */
364 bNodeSocket *dot_product_a_input = bke::node_find_socket(
365 *dot_product_node, SOCK_IN, "Vector"_ustr);
367 *node_tree, *link.fromnode, *link.fromsock, *dot_product_node, *dot_product_a_input);
368
369 /* Set the dot product vector to 1 / 3 to compute the average. */
370 bNodeSocket *dot_product_b_input = bke::node_find_socket(
371 *dot_product_node, SOCK_IN, "Vector_001"_ustr);
372 copy_v3_fl(dot_product_b_input->default_value_typed<bNodeSocketValueVector>()->value,
373 1.0f / 3.0f);
374
375 /* Link the dot product node output to the link target. */
376 bNodeSocket *dot_product_output = bke::node_find_socket(
377 *dot_product_node, SOCK_OUT, "Value"_ustr);
378 bNodeLink *output_link = &version_node_add_link(
379 *node_tree, *dot_product_node, *dot_product_output, *link.tonode, *link.tosock);
380
381 /* Add the new link to the cache. */
382 color_to_float_links.add_new(link.fromsock, output_link);
383
384 /* Remove the old link. */
385 bke::node_remove_link(node_tree, link);
386 }
387}
388
390{
391 for (bNode &node : node_tree->nodes.items_mutable()) {
392 if (node.type_legacy != SH_NODE_BUMP) {
393 continue;
394 }
395
396 bNodeSocket *filter_width_input = bke::node_find_socket(node, SOCK_IN, "Filter Width"_ustr);
397 if (filter_width_input) {
398 *version_cycles_node_socket_float_value(filter_width_input) = 1.0f;
399 }
400 }
401}
402
404{
405 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 2)) {
409 }
410
411 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 7)) {
412 constexpr char SCE_SNAP_TO_NODE_X = (1 << 0);
413 constexpr char SCE_SNAP_TO_NODE_Y = (1 << 1);
414 for (Scene &scene : bmain->scenes) {
415 if (scene.toolsettings->snap_node_mode & SCE_SNAP_TO_NODE_X ||
416 scene.toolsettings->snap_node_mode & SCE_SNAP_TO_NODE_Y)
417 {
419 }
420 }
421 }
422
423 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 18)) {
424 Set<bNodeTree *> node_trees_already_versioned;
425 for (Scene &scene : bmain->scenes) {
426 bNodeTree *node_tree = scene.nodetree;
427 if (!node_tree) {
428 continue;
429 }
431 &scene, node_tree, node_trees_already_versioned);
432 }
433
434 /* The above loop versioned all node trees used in a scene, but other node trees might exist
435 * that are not used in a scene. For those, assume the first scene in the file, as this is
436 * better than not doing versioning at all. */
437 Scene *scene = bmain->scenes.first();
438 for (bNodeTree &node_tree : bmain->nodetrees) {
439 if (node_trees_already_versioned.contains(&node_tree)) {
440 continue;
441 }
442
443 for (bNode &node : node_tree.nodes) {
444 if (node.type_legacy == CMP_NODE_GLARE) {
446 }
447 }
448 node_trees_already_versioned.add_new(&node_tree);
449 }
450 }
451
452 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 19)) {
453 /* Two new inputs were added, Saturation and Tint. */
455 }
456
457 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 20)) {
458 /* Two new inputs were added, Highlights Smoothness and Highlights suppression. */
460 }
461
462 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 21)) {
463 Set<bNodeTree *> node_trees_already_versioned;
464 for (Scene &scene : bmain->scenes) {
465 bNodeTree *node_tree = scene.nodetree;
466 if (!node_tree) {
467 continue;
468 }
470 &scene, node_tree, node_trees_already_versioned);
471 }
472
473 /* The above loop versioned all node trees used in a scene, but other node trees might exist
474 * that are not used in a scene. For those, assume the first scene in the file, as this is
475 * better than not doing versioning at all. */
476 Scene *scene = bmain->scenes.first();
477 for (bNodeTree &node_tree : bmain->nodetrees) {
478 if (node_trees_already_versioned.contains(&node_tree)) {
479 continue;
480 }
481
482 for (bNode &node : node_tree.nodes) {
483 if (node.type_legacy == CMP_NODE_GLARE) {
484 do_version_glare_node_bloom_strength(scene, &node_tree, &node);
485 }
486 }
487 node_trees_already_versioned.add_new(&node_tree);
488 }
489 }
490
491 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 25)) {
492 for (Scene &scene : bmain->scenes) {
493 if (!scene.adt) {
494 continue;
495 }
496 auto replace_rna_path_prefix =
497 [](FCurve &fcurve, const StringRef old_prefix, const StringRef new_prefix) {
498 const StringRef rna_path = fcurve.rna_path();
499 if (!rna_path.startswith(old_prefix)) {
500 return;
501 }
502 const StringRef tail = rna_path.drop_prefix(old_prefix.size());
503 char *new_rna_path = BLI_strdupcat(new_prefix.data(), tail.data());
504 fcurve.rna_path_set_move(new_rna_path);
505 };
506 if (scene.adt->action) {
507 animrig::foreach_fcurve_in_action(scene.adt->action->wrap(), [&](FCurve &fcurve) {
508 replace_rna_path_prefix(fcurve, "sequence_editor.sequences", "sequence_editor.strips");
509 });
510 }
511 for (FCurve &driver : scene.adt->drivers) {
512 replace_rna_path_prefix(driver, "sequence_editor.sequences", "sequence_editor.strips");
513 }
514 }
515 }
516
517 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 27)) {
518 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
519 if (ntree->type == NTREE_COMPOSIT) {
521 }
522 else if (ntree->type == NTREE_SHADER) {
524 }
525 }
527 }
528}
529
530static bool versioning_convert_seq_text_anchor(Strip *strip, void * /*user_data*/)
531{
532 if (strip->type != STRIP_TYPE_TEXT || strip->effectdata == nullptr) {
533 return true;
534 }
535
536 TextVars *data = static_cast<TextVars *>(strip->effectdata);
537 data->anchor_x = eEffectTextAnchorX(data->align);
538 data->anchor_y = eEffectTextAnchorY(data->align_y_legacy);
540
541 return true;
542}
543
545{
546 for (bNodeTree &ntree : bmain.nodetrees) {
547 if (ntree.type == NTREE_GEOMETRY) {
548 for (bNode &node : ntree.nodes) {
549 if (node.type_legacy == GEO_NODE_SUBDIVISION_SURFACE) {
551 &ntree, &node, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "Limit Surface", "Limit Surface");
552 static_cast<bNodeSocketValueBoolean *>(socket->default_value)->value = false;
553 }
554 }
555 }
556 }
557}
558
560{
561 Set<bNode *> triangulate_nodes;
562 for (bNode &node : tree->nodes) {
563 if (node.type_legacy == GEO_NODE_TRIANGULATE) {
564 triangulate_nodes.add(&node);
565 }
566 }
567
569 for (bNodeLink &link : tree->links) {
570 if (triangulate_nodes.contains(link.tonode)) {
571 input_links.add_new(link.tosock, &link);
572 }
573 }
574
575 for (bNode *triangulate : triangulate_nodes) {
576 bNodeSocket *selection = bke::node_find_socket(*triangulate, SOCK_IN, "Selection"_ustr);
577 bNodeSocket *min_verts = bke::node_find_socket(*triangulate, SOCK_IN, "Minimum Vertices"_ustr);
578 if (!min_verts) {
579 /* Make versioning idempotent. */
580 continue;
581 }
582 const int old_min_verts = static_cast<bNodeSocketValueInt *>(min_verts->default_value)->value;
583 if (!input_links.contains(min_verts) && old_min_verts <= 4) {
584 continue;
585 }
586 bNode &corners_of_face = version_node_add_empty(*tree, "GeometryNodeCornersOfFace");
588 tree, &corners_of_face, SOCK_IN, SOCK_INT, PROP_NONE, "Face Index", "Face Index");
590 tree, &corners_of_face, SOCK_IN, SOCK_FLOAT, PROP_NONE, "Weights", "Weights");
592 tree, &corners_of_face, SOCK_IN, SOCK_INT, PROP_NONE, "Sort Index", "Sort Index");
594 tree, &corners_of_face, SOCK_OUT, SOCK_INT, PROP_NONE, "Corner Index", "Corner Index");
596 tree, &corners_of_face, SOCK_OUT, SOCK_INT, PROP_NONE, "Total", "Total");
597 corners_of_face.locx_legacy = triangulate->locx_legacy - 200;
598 corners_of_face.locy_legacy = triangulate->locy_legacy - 50;
599 corners_of_face.parent = triangulate->parent;
600 for (bNodeSocket &socket : corners_of_face.inputs) {
601 socket.flag |= SOCK_HIDDEN;
602 }
603 for (bNodeSocket &socket : corners_of_face.outputs) {
604 if (!STREQ(socket.identifier, "Total")) {
605 socket.flag |= SOCK_HIDDEN;
606 }
607 }
608
609 bNode &greater_or_equal = version_node_add_empty(*tree, "FunctionNodeCompare");
610 auto *compare_storage = MEM_new<NodeFunctionCompare>(__func__);
611 compare_storage->operation = NODE_COMPARE_GREATER_EQUAL;
612 compare_storage->data_type = SOCK_INT;
613 greater_or_equal.storage = compare_storage;
615 tree, &greater_or_equal, SOCK_IN, SOCK_INT, PROP_NONE, "A_INT", "A");
617 tree, &greater_or_equal, SOCK_IN, SOCK_INT, PROP_NONE, "B_INT", "B");
619 tree, &greater_or_equal, SOCK_OUT, SOCK_BOOLEAN, PROP_NONE, "Result", "Result");
620 greater_or_equal.locx_legacy = triangulate->locx_legacy - 100;
621 greater_or_equal.locy_legacy = triangulate->locy_legacy - 50;
622 greater_or_equal.parent = triangulate->parent;
623 greater_or_equal.flag &= ~NODE_OPTIONS;
625 corners_of_face,
626 *bke::node_find_socket(*&corners_of_face, SOCK_OUT, "Total"_ustr),
627 greater_or_equal,
628 *bke::node_find_socket(*&greater_or_equal, SOCK_IN, "A_INT"_ustr));
629 if (bNodeLink **min_verts_link = input_links.lookup_ptr(min_verts)) {
630 (*min_verts_link)->tonode = &greater_or_equal;
631 (*min_verts_link)->tosock = bke::node_find_socket(*&greater_or_equal, SOCK_IN, "B_INT"_ustr);
632 }
633 else {
634 bNodeSocket *new_min_verts = bke::node_find_socket(
635 *&greater_or_equal, SOCK_IN, "B_INT"_ustr);
636 static_cast<bNodeSocketValueInt *>(new_min_verts->default_value)->value = old_min_verts;
637 }
638
639 if (bNodeLink **selection_link = input_links.lookup_ptr(selection)) {
640 bNode &boolean_and = version_node_add_empty(*tree, "FunctionNodeBooleanMath");
642 tree, &boolean_and, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "Boolean", "Boolean");
644 tree, &boolean_and, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "Boolean_001", "Boolean");
646 tree, &boolean_and, SOCK_OUT, SOCK_BOOLEAN, PROP_NONE, "Boolean", "Boolean");
647 boolean_and.locx_legacy = triangulate->locx_legacy - 75;
648 boolean_and.locy_legacy = triangulate->locy_legacy - 50;
649 boolean_and.parent = triangulate->parent;
650 boolean_and.flag &= ~NODE_OPTIONS;
651 boolean_and.custom1 = NODE_BOOLEAN_MATH_AND;
652
653 (*selection_link)->tonode = &boolean_and;
654 (*selection_link)->tosock = bke::node_find_socket(*&boolean_and, SOCK_IN, "Boolean"_ustr);
656 greater_or_equal,
657 *bke::node_find_socket(*&greater_or_equal, SOCK_OUT, "Result"_ustr),
658 boolean_and,
659 *bke::node_find_socket(*&boolean_and, SOCK_IN, "Boolean_001"_ustr));
660
662 boolean_and,
663 *bke::node_find_socket(*&boolean_and, SOCK_OUT, "Boolean"_ustr),
664 *triangulate,
665 *selection);
666 }
667 else {
669 greater_or_equal,
670 *bke::node_find_socket(*&greater_or_equal, SOCK_OUT, "Result"_ustr),
671 *triangulate,
672 *selection);
673 }
674
675 /* Make versioning idempotent. */
676 bke::node_remove_socket(*tree, *triangulate, *min_verts);
677 }
678}
679
681{
682 for (FModifier &fcurve_modifier : fcurve.modifiers) {
683 if (fcurve_modifier.type != FMODIFIER_TYPE_NOISE) {
684 continue;
685 }
686 FMod_Noise *data = static_cast<FMod_Noise *>(fcurve_modifier.data);
687 data->lacunarity = 2.0f;
688 data->roughness = 0.5f;
689 data->legacy_noise = true;
690 }
691}
692
694{
695 for (bNode &node : ntree.nodes) {
696 node.location[0] = node.locx_legacy;
697 node.location[1] = node.locy_legacy;
698 for (const bNode *parent = node.parent; parent; parent = parent->parent) {
699 node.location[0] += parent->locx_legacy;
700 node.location[1] += parent->locy_legacy;
701 }
702
703 node.location[0] += node.offsetx_legacy;
704 node.location[1] += node.offsety_legacy;
705 node.offsetx_legacy = 0.0f;
706 node.offsety_legacy = 0.0f;
707 }
708}
709
716{
717 for (bNode &node : ntree.nodes) {
718 if (!node.is_group_input()) {
719 continue;
720 }
721 for (bNodeSocket &socket : node.outputs) {
722 switch (socket.type) {
723 case SOCK_OBJECT:
724 socket.default_value_typed<bNodeSocketValueObject>()->value = nullptr;
725 break;
726 case SOCK_IMAGE:
727 socket.default_value_typed<bNodeSocketValueImage>()->value = nullptr;
728 break;
729 case SOCK_COLLECTION:
730 socket.default_value_typed<bNodeSocketValueCollection>()->value = nullptr;
731 break;
732 case SOCK_TEXTURE:
733 socket.default_value_typed<bNodeSocketValueTexture>()->value = nullptr;
734 break;
735 case SOCK_MATERIAL:
736 socket.default_value_typed<bNodeSocketValueMaterial>()->value = nullptr;
737 break;
738 default:
739 break;
740 }
741 }
742 }
743}
744
745static bool versioning_clear_strip_unused_flag(Strip *strip, void * /*user_data*/)
746{
747 strip->flag &= ~eStripFlag(1 << 6);
748 return true;
749}
750
752{
753 if (ntree.type == NTREE_GEOMETRY) {
754 for (bNode &node : ntree.nodes) {
755 if (STREQ(node.idname, "GeometryNodeInputNormal")) {
756 node.custom1 = 1;
757 }
758 }
759 }
760}
761
763{
764 for (bNode &node : node_tree->nodes.items_mutable()) {
765 if (node.type_legacy != CMP_NODE_VIEWER) {
766 continue;
767 }
768 /* custom1 was previously used for Tile Order for the Tiled Compositor. */
770 }
771}
772
773void blo_do_versions_404(FileData *fd, Library * /*lib*/, Main *bmain)
774{
775 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 1)) {
776 for (Scene &scene : bmain->scenes) {
777 Editing *ed = seq::editing_get(&scene);
778 if (ed != nullptr) {
780 }
781 }
782 }
783
784 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 4)) {
785 for (bScreen &screen : bmain->screens) {
786 for (ScrArea &area : screen.areabase) {
787 for (SpaceLink &sl : area.spacedata) {
788 if (sl.spacetype != SPACE_FILE) {
789 continue;
790 }
791 SpaceFile *sfile = reinterpret_cast<SpaceFile *>(&sl);
792 if (sfile->asset_params) {
794 }
795 }
796 }
797 }
798 }
799
800 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 6)) {
802 }
803
804 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 8)) {
805 for (bNodeTree &ntree : bmain->nodetrees) {
806 if (ntree.type == NTREE_GEOMETRY) {
808 }
809 }
810 }
811
812 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 10)) {
813 for (bAction &dna_action : bmain->actions) {
814 animrig::Action &action = dna_action.wrap();
816 action, [&](FCurve &fcurve) { version_fcurve_noise_modifier(fcurve); });
817 }
818
819 ID *id;
820 FOREACH_MAIN_ID_BEGIN (bmain, id) {
822 if (!adt) {
823 continue;
824 }
825
826 for (FCurve &fcu : adt->drivers) {
828 }
829 }
831 }
832
833 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 11)) {
834 /* #update_paint_modes_for_brush_assets() didn't handle image editor tools for some time. 4.3
835 * files saved during that period could have invalid tool references stored. */
836 for (WorkSpace &workspace : bmain->workspaces) {
837 for (bToolRef &tref : workspace.tools) {
838 if (tref.space_type == SPACE_IMAGE && tref.mode == SI_MODE_PAINT) {
839 STRNCPY_UTF8(tref.idname, "builtin.brush");
840 }
841 }
842 }
843 }
844
845 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 12)) {
846 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
848 }
850 }
851
852 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 13)) {
853 for (Object &object : bmain->objects) {
854 for (ModifierData &modifier : object.modifiers) {
855 if (modifier.type != eModifierType_Nodes) {
856 continue;
857 }
858 NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(&modifier);
859 if (!nmd->settings_legacy.properties) {
860 continue;
861 }
863 if (idprop.type != IDP_STRING) {
864 continue;
865 }
866 StringRef prop_name(idprop.name);
867 if (prop_name.endswith("_attribute_name") || prop_name.endswith("_use_attribute")) {
869 }
870 }
871 }
872 }
873 }
874
875 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 14)) {
876 for (bNodeTree &ntree : bmain->nodetrees) {
878 }
879 }
880
881 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 15)) {
882 for (Scene &scene : bmain->scenes) {
883 Editing *ed = seq::editing_get(&scene);
884 if (ed != nullptr) {
886 }
887 }
888 }
889
890 /* Fix incorrect identifier in the shader mix node. */
891 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 16)) {
892 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
893 if (ntree->type == NTREE_SHADER) {
894 for (bNode &node : ntree->nodes) {
895 if (node.type_legacy == SH_NODE_MIX_SHADER) {
896 for (bNodeSocket &socket : node.inputs) {
897 if (STREQ(socket.identifier, "Shader.001")) {
898 version_node_socket_identifier_set(socket, "Shader_001");
899 }
900 }
901 }
902 }
903 }
904 }
906 }
907
908 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 17)) {
909 if (!DNA_struct_member_exists(
910 fd->filesdna, "RenderData", "RenderSettings", "compositor_denoise_preview_quality"))
911 {
912 for (Scene &scene : bmain->scenes) {
914 }
915 }
916 if (!DNA_struct_member_exists(
917 fd->filesdna, "RenderData", "RenderSettings", "compositor_denoise_final_quality"))
918 {
919 for (Scene &scene : bmain->scenes) {
921 }
922 }
923 }
924
925 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 22)) {
926 for (Scene &scene : bmain->scenes) {
928 if (cscene) {
929 if (version_cycles_property_int(cscene, "sample_offset", 0) > 0) {
930 version_cycles_property_boolean_set(cscene, "use_sample_subset", true);
931 version_cycles_property_int_set(cscene, "sample_subset_length", (1 << 24));
932 }
933 }
934 }
935 }
936
937 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 23)) {
938 if (!DNA_struct_member_exists(fd->filesdna, "Curves", "float", "surface_collision_distance")) {
939 for (Curves &curves : bmain->hair_curves) {
940 curves.surface_collision_distance = 0.005f;
941 }
942 }
943 }
944
945 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 24)) {
946 for (bNodeTree &ntree : bmain->nodetrees) {
948 }
949 }
950
951 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 26)) {
952 const Brush default_brush;
953 for (Brush &brush : bmain->brushes) {
954 if ((brush.mask_stencil_dimension[0] == 0) && (brush.mask_stencil_dimension[1] == 0)) {
955 brush.mask_stencil_dimension[0] = default_brush.mask_stencil_dimension[0];
956 brush.mask_stencil_dimension[1] = default_brush.mask_stencil_dimension[1];
957 }
958 if ((brush.mask_stencil_pos[0] == 0) && (brush.mask_stencil_pos[1] == 0)) {
959 brush.mask_stencil_pos[0] = default_brush.mask_stencil_pos[0];
960 brush.mask_stencil_pos[1] = default_brush.mask_stencil_pos[1];
961 }
962 }
963 }
964
965 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 27)) {
966 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
967 if (ntree->type == NTREE_COMPOSIT) {
969 }
970 }
972 }
973
974 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 28)) {
975 for (Scene &scene : bmain->scenes) {
976 SequencerToolSettings *sequencer_tool_settings = seq::tool_settings_ensure(&scene);
977 sequencer_tool_settings->snap_mode |= SEQ_SNAP_TO_RETIMING;
978 }
979 }
980
981 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 29)) {
982 for (Scene &scene : bmain->scenes) {
983 ToolSettings *ts = scene.toolsettings;
984 ts->imapaint.clone_alpha = 0.5f;
985 }
986 }
987
988 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 30)) {
989 for (bScreen &screen : bmain->screens) {
990 for (ScrArea &area : screen.areabase) {
991 for (SpaceLink &sl : area.spacedata) {
993 ListBaseT<ARegion> *regionbase = (&sl == area.spacedata.first_) ? &area.regionbase :
994 &sl.regionbase;
995 for (ARegion &region : *regionbase) {
996 if (region.regiontype == RGN_TYPE_WINDOW) {
997 region.v2d.scroll |= V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
998 }
999 }
1000 }
1001 }
1002 }
1003 }
1004 }
1005}
1006
1007} // namespace blender
Functions and classes to work with Actions.
Functionality to iterate an Action in various ways.
Versioning of old animation data. Most animation versioning code lives in the versioning_xxx....
#define FOREACH_MAIN_ID_END
Definition BKE_main.hh:735
#define MAIN_VERSION_FILE_ATLEAST(main, ver, subver)
Definition BKE_main.hh:949
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition BKE_main.hh:729
#define FOREACH_NODETREE_END
Definition BKE_node.hh:936
#define FOREACH_NODETREE_BEGIN(bmain, _nodetree, _id)
Definition BKE_node.hh:926
#define GEO_NODE_TRIANGULATE
#define SH_NODE_MIX_SHADER
#define GEO_NODE_SUBDIVISION_SURFACE
#define CMP_NODE_VIEWER
#define SH_NODE_BUMP
#define SH_NODE_VECTOR_MATH
#define CMP_NODE_GLARE
#define STRNCPY_UTF8(dst, src)
blenloader genfile private function prototypes
#define ELEM(...)
#define STREQ(a, b)
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:508
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:265
bool contains(const Key &key) const
Definition BLI_map.hh:353
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
void add_new(const Key &key)
Definition BLI_set.hh:233
constexpr const char * data() const
constexpr bool endswith(StringRef suffix) const
#define storage(slot, qualifiers)
float fade(float t)
void convert_legacy_action_assignments(Main &bmain, ReportList *reports)
void convert_legacy_animato_actions(Main &bmain)
Definition versioning.cc:56
void tag_action_users_for_slotted_actions_conversion(Main &bmain)
void foreach_fcurve_in_action(Action &action, FunctionRef< void(FCurve &fcurve)> callback)
void node_remove_socket(bNodeTree &ntree, bNode &node, bNodeSocket &sock)
Definition node.cc:4015
void node_remove_link(bNodeTree *ntree, bNodeLink &link)
Definition node.cc:4676
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
Definition node.cc:4283
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
Definition node.cc:3036
T pow(const T &x, const T &power)
T clamp(const T &a, const T &min, const T &max)
T reduce_max(const VecBase< T, Size > &a)
T reduce_min(const VecBase< T, Size > &a)
T min(const T &a, const T &b)
T max(const T &a, const T &b)
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.
static void do_version_glare_node_bloom_strength_recursive(const Scene *scene, bNodeTree *node_tree, Set< bNodeTree * > &node_trees_already_versioned)
@ SCE_COMPOSITOR_DENOISE_BALANCED
@ SCE_COMPOSITOR_DENOISE_HIGH
static void add_subsurf_node_limit_surface_option(Main &bmain)
static void do_version_glare_node_options_to_inputs(const Scene *scene, bNodeTree *node_tree, bNode *node)
static void do_version_glare_node_options_to_inputs_recursive(const Scene *scene, bNodeTree *node_tree, Set< bNodeTree * > &node_trees_already_versioned)
static void version_geometry_normal_input_node(bNodeTree &ntree)
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
static void do_version_color_to_float_conversion(bNodeTree *node_tree)
void BKE_fcurves_id_cb(struct ID *id, FunctionRef< void(ID *, FCurve *)> func)
@ FILE_SORT_ASSET_CATALOG
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
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
static void version_group_input_socket_data_block_reference(bNodeTree &ntree)
float * version_cycles_node_socket_float_value(bNodeSocket *socket)
static void do_version_bump_filter_width(bNodeTree *node_tree)
bNode & version_node_add_empty(bNodeTree &ntree, const char *idname)
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:3168
@ NODE_BOOLEAN_MATH_AND
int version_cycles_property_int(IDProperty *idprop, const char *name, int default_value)
@ FMODIFIER_TYPE_NOISE
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
void version_node_socket_identifier_set(bNodeSocket &socket, const StringRefNull identifier)
void do_versions_after_linking_404(FileData *fd, Main *bmain)
VecBase< int32_t, 2 > int2
static bool versioning_convert_seq_text_anchor(Strip *strip, void *)
@ IDP_FLAG_OVERRIDABLE_LIBRARY
@ IDP_FLAG_STATIC_TYPE
BMesh const char void * data
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
static void do_version_viewer_shortcut(bNodeTree *node_tree)
void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value)
static void remove_triangulate_node_min_size_input(bNodeTree *tree)
@ NODE_COMPARE_GREATER_EQUAL
static void do_version_glare_node_bloom_strength(const Scene *scene, bNodeTree *node_tree, bNode *node)
static void version_node_locations_to_global(bNodeTree &ntree)
@ V2D_SCROLL_VERTICAL_HIDE
MINLINE void copy_v3_fl(float r[3], float f)
@ NODE_VIEWER_SHORTCUT_NONE
IDProperty * version_cycles_properties_from_ID(ID *id)
@ NODE_VECTOR_MATH_DOT_PRODUCT
void blo_do_versions_404(FileData *fd, Library *lib, Main *bmain)
@ PROP_FACTOR
Definition RNA_types.hh:308
static bool versioning_clear_strip_unused_flag(Strip *strip, void *)
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)
bNodeLink & version_node_add_link(bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b)
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)
static void version_fcurve_noise_modifier(FCurve &fcurve)
#define mix
ListBaseT< FCurve > drivers
float mask_stencil_dimension[2]
float mask_stencil_pos[2]
ListBaseT< FModifier > modifiers
eFModifier_Types type
BlendFileReadReport * reports
Definition readfile.hh:208
std::unique_ptr< SDNA > filesdna
Definition readfile.hh:111
ListBaseT< struct IDProperty > group
Definition DNA_ID.h:133
IDPropertyData data
Definition DNA_ID.h:157
ListBaseT< bNodeTree > nodetrees
Definition BKE_main.hh:409
ListBaseT< Curves > hair_curves
Definition BKE_main.hh:428
ListBaseT< Brush > brushes
Definition BKE_main.hh:410
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< WorkSpace > workspaces
Definition BKE_main.hh:423
ListBaseT< bAction > actions
Definition BKE_main.hh:408
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
struct NodesModifierSettings settings_legacy
eCompositorDenoiseQaulity compositor_denoise_preview_quality
eCompositorDenoiseQaulity compositor_denoise_final_quality
struct AnimData * adt
DNA_DEPRECATED struct bNodeTree * nodetree
struct RenderData r
struct ToolSettings * toolsettings
ListBaseT< ARegion > regionbase
ListBaseT< SpaceLink > spacedata
FileAssetSelectParams * asset_params
struct ImagePaintSettings imapaint
ListBaseT< bToolRef > tools
eNodeSocketDatatype type
ListBaseT< bNodeLink > links
eNodeTree_Type type
ListBaseT< bNode > nodes
struct bNode * parent
ListBaseT< bNodeSocket > outputs
ListBaseT< bNodeSocket > inputs
ListBaseT< struct ScrArea > areabase