Blender V5.3
versioning_403.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 "DNA_brush_types.h"
12#include "DNA_camera_types.h"
14#include "DNA_curves_types.h"
15#include "DNA_modifier_types.h"
17#include "DNA_workspace_types.h"
18
19#include "BLI_listbase.hh"
20#include "BLI_math_vector_c.hh"
21#include "BLI_string_utf8.hh"
22
23#include "BKE_collection.hh"
24#include "BKE_context.hh"
25#include "BKE_customdata.hh"
26#include "BKE_file_handler.hh"
27#include "BKE_grease_pencil.hh"
28#include "BKE_image_format.hh"
29#include "BKE_main.hh"
30#include "BKE_node.hh"
32#include "BKE_node_runtime.hh"
33#include "BKE_paint.hh"
34#include "BKE_screen.hh"
35
36#include "SEQ_sequencer.hh"
37
38#include "BLT_translation.hh"
39
40#include "readfile.hh"
41
42#include "versioning_common.hh"
43
44namespace blender {
45
47{
48 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 6)) {
49 /* Shift animation data to accommodate the new Diffuse Roughness input. */
51 }
52}
53
55{
56 /* Replace paint brushes with a reference to the default brush asset for that mode. */
57 for (Scene &scene : bmain.scenes) {
59 }
60
61 /* Replace persistent tool references with the new single builtin brush tool. */
62 for (WorkSpace &workspace : bmain.workspaces) {
63 for (bToolRef &tref : workspace.tools) {
64 if (tref.space_type == SPACE_IMAGE && tref.mode == SI_MODE_PAINT) {
65 STRNCPY_UTF8(tref.idname, "builtin.brush");
66 continue;
67 }
68 if (tref.space_type != SPACE_VIEW3D) {
69 continue;
70 }
71 if (!ELEM(tref.mode,
85 {
86 continue;
87 }
88 STRNCPY_UTF8(tref.idname, "builtin.brush");
89 }
90 }
91}
92
98{
99 for (Curves &curves : bmain->hair_curves) {
100 const int curves_num = curves.geometry.curve_num;
101 if (int *resolutions = static_cast<int *>(CustomData_get_layer_named_for_write(
102 &curves.geometry.curve_data_legacy, CD_PROP_INT32, "resolution", curves_num)))
103 {
104 for (int &resolution : MutableSpan{resolutions, curves_num}) {
105 resolution = std::max(resolution, 1);
106 }
107 }
108 if (int8_t *nurb_orders = static_cast<int8_t *>(CustomData_get_layer_named_for_write(
109 &curves.geometry.curve_data_legacy, CD_PROP_INT8, "nurbs_order", curves_num)))
110 {
111 for (int8_t &nurbs_order : MutableSpan{nurb_orders, curves_num}) {
112 nurbs_order = std::max<int8_t>(nurbs_order, 1);
113 }
114 }
115 }
116}
117
119{
120 for (bNode *node : tree.all_nodes()) {
121 if (node->is_reroute()) {
122 if (node->storage != nullptr) {
123 continue;
124 }
125
126 bNodeSocket &input = *node->inputs.first();
127 bNodeSocket &output = *node->outputs.first();
128
129 /* Use uniform identifier for sockets. In old Blender versions (<=2021, up to af0b7925), the
130 * identifiers were sometimes all lower case. Fixing those wrong socket identifiers is
131 * important because otherwise they loose links now that the reroute node also uses node
132 * declarations. */
135
136 NodeReroute *data = MEM_new<NodeReroute>(__func__);
137 STRNCPY_UTF8(data->type_idname, input.idname);
138 node->storage = data;
139 }
140 }
141}
142
144{
145 for (Object &ob : bmain.objects) {
146 if (ob.type != OB_MESH) {
147 continue;
148 }
149 for (ModifierData &md : ob.modifiers) {
150 if (md.type == eModifierType_Bevel) {
151 BevelModifierData *bmd = reinterpret_cast<BevelModifierData *>(&md);
152 if (bmd->vertex_weight_name[0] == '\0') {
153 STRNCPY(bmd->vertex_weight_name, "bevel_weight_vert");
154 }
155 if (bmd->edge_weight_name[0] == '\0') {
156 STRNCPY(bmd->edge_weight_name, "bevel_weight_edge");
157 }
158 }
159 }
160 }
161}
162
164{
165 for (bNodeTree &tree : bmain.nodetrees) {
166 for (bNode &node : tree.nodes) {
167 if (node.type_legacy != GEO_NODE_SIMULATION_OUTPUT) {
168 continue;
169 }
170 bNodeSocket *skip_input = node.inputs.first();
171 if (!skip_input || !STREQ(skip_input->identifier, "Skip")) {
172 continue;
173 }
174 auto *default_value = static_cast<bNodeSocketValueBoolean *>(skip_input->default_value);
175 if (!default_value->value) {
176 continue;
177 }
178 bool is_linked = false;
179 for (bNodeLink &link : tree.links) {
180 if (link.tosock == skip_input) {
181 is_linked = true;
182 }
183 }
184 if (is_linked) {
185 continue;
186 }
187
188 bNode &input_node = version_node_add_empty(tree, "FunctionNodeInputBool");
189 input_node.parent = node.parent;
190 input_node.locx_legacy = node.locx_legacy - 25;
191 input_node.locy_legacy = node.locy_legacy;
192
193 NodeInputBool *input_node_storage = MEM_new<NodeInputBool>(__func__);
194 input_node.storage = input_node_storage;
195 input_node_storage->boolean = true;
196
197 bNodeSocket &input_node_socket = version_node_add_socket(
198 tree, input_node, SOCK_OUT, "NodeSocketBool", "Boolean");
199
200 version_node_add_link(tree, input_node, input_node_socket, node, *skip_input);
201
202 /* Change the old socket value so that the versioning code is not run again. */
203 default_value->value = false;
204 }
205 }
206}
207
208void blo_do_versions_403(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
209{
210 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 2)) {
211 for (bScreen &screen : bmain->screens) {
212 for (ScrArea &area : screen.areabase) {
213 for (SpaceLink &space_link : area.spacedata) {
214 if (space_link.spacetype == SPACE_NODE) {
215 SpaceNode *space_node = reinterpret_cast<SpaceNode *>(&space_link);
216 space_node->flag &= ~SNODE_FLAG_UNUSED_5;
217 }
218 }
219 }
220 }
221 }
222
223 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 3)) {
224 for (Brush &brush : bmain->brushes) {
225 if (BrushGpencilSettings *settings = brush.gpencil_settings) {
226 /* Copy the `draw_strength` value to the `alpha` value. */
227 brush.alpha = settings->draw_strength;
228
229 /* We approximate the simplify pixel threshold by taking the previous threshold (world
230 * space) and dividing by the legacy radius conversion factor. This should generally give
231 * reasonable "pixel" threshold values, at least for previous GPv2 defaults. */
232 settings->simplify_px = settings->simplify_f /
234 }
235 }
236 }
237
238 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 4)) {
239 for (Scene &scene : bmain->scenes) {
240 scene.view_settings.temperature = 6500.0f;
241 scene.view_settings.tint = 10.0f;
242 }
243 }
244
245 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 7)) {
246 for (Scene &scene : bmain->scenes) {
247 SequencerToolSettings *sequencer_tool_settings = seq::tool_settings_ensure(&scene);
248 sequencer_tool_settings->snap_mode |= SEQ_SNAP_TO_PREVIEW_BORDERS |
251 }
252 }
253
254 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 8)) {
256 }
257
258 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 9)) {
260 }
261
262 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 10)) {
263 /* Initialize Color Balance node white point settings. */
264 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
265 if (ntree->type != NTREE_CUSTOM) {
266 for (bNode &node : ntree->nodes) {
267 if (node.type_legacy == CMP_NODE_COLORBALANCE) {
269 NodeColorBalance *n = static_cast<NodeColorBalance *>(node.storage);
270 n->input_temperature = n->output_temperature = 6500.0f;
271 n->input_tint = n->output_tint = 10.0f;
272 }
273 }
274 }
275 }
276 }
278 }
279
280 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 11)) {
281 for (Curves &curves : bmain->hair_curves) {
282 curves.geometry.attributes_active_index = curves.attributes_active_index_legacy;
283 }
284 }
285
286 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 13)) {
287 Camera default_cam;
288 for (Camera &camera : bmain->cameras) {
289 camera.central_cylindrical_range_u_min = default_cam.central_cylindrical_range_u_min;
290 camera.central_cylindrical_range_u_max = default_cam.central_cylindrical_range_u_max;
291 camera.central_cylindrical_range_v_min = default_cam.central_cylindrical_range_v_min;
292 camera.central_cylindrical_range_v_max = default_cam.central_cylindrical_range_v_max;
293 camera.central_cylindrical_radius = default_cam.central_cylindrical_radius;
294 }
295 }
296
297 /* The File Output node now uses the linear color space setting of its stored image formats. So
298 * we need to ensure the color space value is initialized to some sane default based on the image
299 * type. Furthermore, the node now gained a new Save As Render option that is global to the node,
300 * which will be used if Use Node Format is enabled for each input, so we potentially need to
301 * disable Use Node Format in case inputs had different Save As render options. */
302 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 14)) {
303 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
304 if (ntree->type != NTREE_COMPOSIT) {
305 continue;
306 }
307
308 for (bNode &node : ntree->nodes) {
309 if (node.type_legacy != CMP_NODE_OUTPUT_FILE) {
310 continue;
311 }
313 continue;
314 }
315
316 /* Initialize node format color space if it is not set. */
318 if (storage->format.linear_colorspace_settings.name[0] == '\0') {
320 }
321
322 if (node.inputs.is_empty()) {
323 continue;
324 }
325
326 /* Initialize input formats color space if it is not set. */
327 for (const bNodeSocket &input : node.inputs) {
328 NodeImageMultiFileSocket *input_storage = static_cast<NodeImageMultiFileSocket *>(
329 input.storage);
330 if (input_storage->format.linear_colorspace_settings.name[0] == '\0') {
332 }
333 }
334
335 /* EXR images don't use Save As Render. */
337 continue;
338 }
339
340 /* Find out if all inputs have the same Save As Render option. */
341 const bNodeSocket *first_input = node.inputs.first();
342 const NodeImageMultiFileSocket *first_input_storage =
343 static_cast<NodeImageMultiFileSocket *>(first_input->storage);
344 const bool first_save_as_render = first_input_storage->save_as_render;
345 bool all_inputs_have_same_save_as_render = true;
346 for (const bNodeSocket &input : node.inputs) {
347 const NodeImageMultiFileSocket *input_storage = static_cast<NodeImageMultiFileSocket *>(
348 input.storage);
349 if (bool(input_storage->save_as_render) != first_save_as_render) {
350 all_inputs_have_same_save_as_render = false;
351 break;
352 }
353 }
354
355 /* All inputs have the same save as render option, so we set the node Save As Render option
356 * to that value, and we leave inputs as is. */
357 if (all_inputs_have_same_save_as_render) {
358 storage->save_as_render = first_save_as_render;
359 continue;
360 }
361
362 /* For inputs that have Use Node Format enabled, we need to disabled it because otherwise
363 * they will use the node's Save As Render option. It follows that we need to copy the
364 * node's format to the input format. */
365 for (const bNodeSocket &input : node.inputs) {
366 NodeImageMultiFileSocket *input_storage = static_cast<NodeImageMultiFileSocket *>(
367 input.storage);
368
369 if (!input_storage->use_node_format) {
370 continue;
371 }
372
373 input_storage->use_node_format = false;
374 input_storage->format = storage->format;
375 }
376 }
377 }
379 }
380
381 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 15)) {
382 for (Collection &collection : bmain->collections) {
383 const ListBaseT<CollectionExport> *exporters = &collection.exporters;
384 for (CollectionExport &data : *exporters) {
385 /* The name field should be empty at this point. */
386 BLI_assert(data.name[0] == '\0');
387
389 BKE_collection_exporter_name_set(exporters, &data, fh ? fh->label : DATA_("Undefined"));
390 }
391 }
392 }
393
394 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 16)) {
395 for (Scene &scene : bmain->scenes) {
397 }
398 }
399
400 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 17)) {
401 FOREACH_NODETREE_BEGIN (bmain, tree, id) {
402 if (tree->default_group_node_width == 0) {
403 tree->default_group_node_width = bke::NodeWidth::Default;
404 }
405 }
407 }
408
409 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 20)) {
410 for (bScreen &screen : bmain->screens) {
411 for (ScrArea &area : screen.areabase) {
412 for (SpaceLink &sl : area.spacedata) {
413 if (sl.spacetype == SPACE_SEQ) {
415 if (region != nullptr) {
416 region->flag &= ~RGN_FLAG_HIDDEN;
417 }
418 }
419 }
420 }
421 }
422 }
423
424 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 21)) {
425 for (bScreen &screen : bmain->screens) {
426 for (ScrArea &area : screen.areabase) {
427 for (SpaceLink &sl : area.spacedata) {
428 if (sl.spacetype == SPACE_CLIP) {
430 if (region != nullptr) {
431 View2D *v2d = &region->v2d;
433 }
434 }
435 }
436 }
437 }
438 }
439
440 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 22)) {
442 }
443
444 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 23)) {
445 for (Object &object : bmain->objects) {
446 for (ModifierData &md : object.modifiers) {
447 if (md.type != eModifierType_Nodes) {
448 continue;
449 }
450 NodesModifierData &nmd = *reinterpret_cast<NodesModifierData *>(&md);
452 /* Use disk target for existing modifiers to avoid changing behavior. */
454 }
455 }
456 }
457 }
458
459 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 24)) {
460 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
462 }
464 }
465
466 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 26)) {
468 }
469
470 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 28)) {
471 for (bScreen &screen : bmain->screens) {
472 for (ScrArea &area : screen.areabase) {
473 for (SpaceLink &sl : area.spacedata) {
474 if (sl.spacetype == SPACE_VIEW3D) {
475 View3D *v3d = reinterpret_cast<View3D *>(&sl);
480 }
481 }
482 }
483 }
484
485 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
486 if (ntree->type != NTREE_COMPOSIT) {
487 continue;
488 }
489 for (bNode &node : ntree->nodes.items_mutable()) {
491 node.flag &= ~NODE_PREVIEW;
492 }
493 }
494 }
496 }
497
498 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 29)) {
499 /* Open warnings panel by default. */
500 for (Object &object : bmain->objects) {
501 for (ModifierData &md : object.modifiers) {
502 if (md.type == eModifierType_Nodes) {
503 md.layout_panel_open_flag |= 1 << NODES_MODIFIER_PANEL_WARNINGS;
504 }
505 }
506 }
507 }
508
509 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 31)) {
510 for (WorkSpace &workspace : bmain->workspaces) {
511 for (bToolRef &tref : workspace.tools) {
512 if (tref.space_type != SPACE_SEQ) {
513 continue;
514 }
515 STRNCPY_UTF8(tref.idname, "builtin.select_box");
516 }
517 }
518 }
519}
520
521} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
Low-level operations for grease pencil.
#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_VIEWER
#define SH_NODE_BSDF_PRINCIPLED
#define CMP_NODE_COLORBALANCE
#define GEO_NODE_SIMULATION_OUTPUT
#define CMP_NODE_OUTPUT_FILE
#define CMP_NODE_COMPOSITE_DEPRECATED
#define STRNCPY_UTF8(dst, src)
#define DATA_(msgid)
Object groups, one object can be in many groups at once.
#define ELEM(...)
#define STREQ(a, b)
#define output
#define storage(slot, qualifiers)
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
constexpr float LEGACY_RADIUS_CONVERSION_FACTOR
FileHandlerType * file_handler_find(StringRef idname)
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)
@ NODES_MODIFIER_PANEL_WARNINGS
static void node_reroute_add_storage(bNodeTree &tree)
MINLINE void copy_v2_fl(float r[2], float f)
void BKE_paint_brushes_set_default_references(ToolSettings *ts)
@ V2D_VIEWSYNC_SCREEN_TIME
bNode & version_node_add_empty(bNodeTree &ntree, const char *idname)
@ CTX_MODE_VERTEX_GREASE_PENCIL
@ CTX_MODE_PAINT_VERTEX
@ CTX_MODE_VERTEX_GPENCIL_LEGACY
@ CTX_MODE_WEIGHT_GPENCIL_LEGACY
@ CTX_MODE_SCULPT_CURVES
@ CTX_MODE_SCULPT
@ CTX_MODE_PAINT_GREASE_PENCIL
@ CTX_MODE_PAINT_GPENCIL_LEGACY
@ CTX_MODE_SCULPT_GREASE_PENCIL
@ CTX_MODE_PAINT_TEXTURE
@ CTX_MODE_SCULPT_GPENCIL_LEGACY
@ CTX_MODE_WEIGHT_GREASE_PENCIL
@ CTX_MODE_PAINT_WEIGHT
@ SCE_EEVEE_FAST_GI_ENABLED
void version_node_socket_identifier_set(bNodeSocket &socket, const StringRefNull identifier)
@ R_IMF_IMTYPE_MULTILAYER
BMesh const char void * data
void blo_do_versions_403(FileData *fd, Library *lib, Main *bmain)
static void hide_simulation_node_skip_socket_value(Main &bmain)
void do_versions_after_linking_403(FileData *fd, Main *bmain)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
@ NODES_MODIFIER_BAKE_TARGET_INHERIT
@ NODES_MODIFIER_BAKE_TARGET_DISK
static void add_bevel_modifier_attribute_name_defaults(Main &bmain)
MINLINE void copy_v3_fl(float r[3], float f)
void BKE_collection_exporter_name_set(const ListBaseT< CollectionExport > *exporters, CollectionExport *data, const char *newname)
void * CustomData_get_layer_named_for_write(CustomData *data, eCustomDataType type, StringRef name, int totelem)
@ SEQ_SNAP_TO_PREVIEW_BORDERS
@ SEQ_SNAP_TO_PREVIEW_CENTER
@ SEQ_SNAP_TO_STRIPS_PREVIEW
static void fix_built_in_curve_attribute_defaults(Main *bmain)
void BKE_image_format_update_color_space_for_type(ImageFormatData *format)
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)
signed char int8_t
Definition BKE_text.h:76
bNodeSocket & version_node_add_socket(bNodeTree &ntree, bNode &node, const eNodeSocketInOut in_out, const char *idname, const char *identifier)
static void update_paint_modes_for_brush_assets(Main &bmain)
ListBaseT< CollectionExport > exporters
ColorManagedColorspaceSettings linear_colorspace_settings
ListBaseT< Collection > collections
Definition BKE_main.hh:406
ListBaseT< bNodeTree > nodetrees
Definition BKE_main.hh:409
ListBaseT< Curves > hair_curves
Definition BKE_main.hh:428
ListBaseT< Camera > cameras
Definition BKE_main.hh:397
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< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
DNA_DEPRECATED float output_tint
DNA_DEPRECATED float input_temperature
DNA_DEPRECATED float output_temperature
DNA_DEPRECATED float input_tint
DNA_DEPRECATED ImageFormatData format
NodesModifierBakeTarget bake_target
ListBaseT< ModifierData > modifiers
eSceneEEVEE_Flag flag
ColorManagedViewSettings view_settings
struct SceneEEVEE eevee
struct ToolSettings * toolsettings
ListBaseT< SpaceLink > spacedata
eSpaceNode_Flag flag
View3DOverlay overlay
ListBaseT< bToolRef > tools
ListBaseT< bNodeLink > links
ListBaseT< bNode > nodes
struct bNode * parent
ListBaseT< struct ScrArea > areabase
static constexpr int Default
Definition BKE_node.hh:253