Blender V5.0
versioning_defaults.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
15
16#define DNA_DEPRECATED_ALLOW
17
18#include "MEM_guardedalloc.h"
19
20#include "BLI_listbase.h"
21#include "BLI_math_rotation.h"
22#include "BLI_math_vector.h"
24#include "BLI_mempool.h"
25#include "BLI_string.h"
26#include "BLI_string_utf8.h"
27#include "BLI_utildefines.h"
28
29#include "DNA_camera_types.h"
31#include "DNA_defaults.h"
33#include "DNA_light_types.h"
34#include "DNA_mask_types.h"
35#include "DNA_material_types.h"
36#include "DNA_mesh_types.h"
37#include "DNA_object_types.h"
38#include "DNA_scene_types.h"
39#include "DNA_screen_types.h"
40#include "DNA_sequence_types.h"
41#include "DNA_space_types.h"
43#include "DNA_workspace_types.h"
44#include "DNA_world_types.h"
45
46#include "BKE_appdir.hh"
47#include "BKE_attribute.hh"
48#include "BKE_brush.hh"
49#include "BKE_colortools.hh"
50#include "BKE_curveprofile.h"
51#include "BKE_customdata.hh"
52#include "BKE_gpencil_legacy.h"
53#include "BKE_idprop.hh"
54#include "BKE_layer.hh"
55#include "BKE_lib_id.hh"
56#include "BKE_main.hh"
57#include "BKE_main_namemap.hh"
58#include "BKE_material.hh"
59#include "BKE_mesh.hh"
61#include "BKE_node_runtime.hh"
63#include "BKE_paint.hh"
64#include "BKE_paint_types.hh"
65#include "BKE_screen.hh"
66#include "BKE_workspace.hh"
67
68#include "BLO_readfile.hh"
69
70#include "BLT_translation.hh"
71
72#include "versioning_common.hh"
73
74/* Make preferences read-only, use `versioning_userdef.cc`. */
75#define U (*((const UserDef *)&U))
76
77static bool blo_is_builtin_template(const char *app_template)
78{
79 /* For all builtin templates shipped with Blender. */
81 N_("2D_Animation"),
82 N_("Storyboarding"),
83 N_("Sculpting"),
84 N_("VFX"),
85 N_("Video_Editing")));
86}
87
89 const char *app_template,
90 const char *workspace_name)
91{
92 /* For all app templates. */
93 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
94 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
95 /* Some toolbars have been saved as initialized,
96 * we don't want them to have odd zoom-level or scrolling set, see: #47047 */
97 if (ELEM(region->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
98 region->v2d.flag &= ~V2D_IS_INIT;
99 }
100 }
101
102 /* Set default folder. */
103 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
104 if (sl->spacetype == SPACE_FILE) {
105 SpaceFile *sfile = (SpaceFile *)sl;
106 if (sfile->params) {
107 const char *dir_default = BKE_appdir_folder_default();
108 if (dir_default) {
109 STRNCPY(sfile->params->dir, dir_default);
110 sfile->params->file[0] = '\0';
111 }
112 }
113 }
114 }
115 }
116
117 /* For builtin templates only. */
119 return;
120 }
121
122 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
123 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
124 /* Remove all stored panels, we want to use defaults
125 * (order, open/closed) as defined by UI code here! */
126 BKE_area_region_panels_free(&region->panels);
127 BLI_freelistN(&region->panels_category_active);
128
129 /* Reset size so it uses consistent defaults from the region types. */
130 region->sizex = 0;
131 region->sizey = 0;
132 }
133
134 if (area->spacetype == SPACE_IMAGE) {
135 if (STREQ(workspace_name, "UV Editing")) {
136 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
137 if (sima->mode == SI_MODE_VIEW) {
138 sima->mode = SI_MODE_UV;
139 }
140 sima->uv_face_opacity = 1.0f;
141 }
142 else if (STR_ELEM(workspace_name, "Texture Paint", "Shading")) {
143 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
144 sima->uv_face_opacity = 0.0f;
145 }
146 }
147 else if (area->spacetype == SPACE_ACTION) {
148 /* Show markers region, hide channels and collapse summary in timelines. */
149 SpaceAction *saction = static_cast<SpaceAction *>(area->spacedata.first);
150 saction->flag |= SACTION_SHOW_MARKERS;
151 if (saction->mode == SACTCONT_TIMELINE) {
153
154 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
155 if (region->regiontype == RGN_TYPE_CHANNELS) {
156 region->flag |= RGN_FLAG_HIDDEN;
157 }
158 }
159 }
160 else {
161 /* Open properties panel by default. */
162 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
163 if (region->regiontype == RGN_TYPE_UI) {
164 region->flag &= ~RGN_FLAG_HIDDEN;
165 }
166 }
167 }
168 }
169 else if (area->spacetype == SPACE_GRAPH) {
170 SpaceGraph *sipo = static_cast<SpaceGraph *>(area->spacedata.first);
171 sipo->flag |= SIPO_SHOW_MARKERS;
172 }
173 else if (area->spacetype == SPACE_NLA) {
174 SpaceNla *snla = static_cast<SpaceNla *>(area->spacedata.first);
175 snla->flag |= SNLA_SHOW_MARKERS;
176 }
177 else if (area->spacetype == SPACE_SEQ) {
178 SpaceSeq *seq = static_cast<SpaceSeq *>(area->spacedata.first);
189 }
190 else if (area->spacetype == SPACE_TEXT) {
191 /* Show syntax and line numbers in Script workspace text editor. */
192 SpaceText *stext = static_cast<SpaceText *>(area->spacedata.first);
193 stext->showsyntax = true;
194 stext->showlinenrs = true;
195 stext->flags |= ST_FIND_WRAP;
196 }
197 else if (area->spacetype == SPACE_VIEW3D) {
198 View3D *v3d = static_cast<View3D *>(area->spacedata.first);
199 /* Screen space cavity by default for faster performance. */
205 /* Update default Z bias for retopology overlay. */
206 v3d->overlay.retopology_offset = 0.01f;
207 /* Clear this deprecated bit for later reuse. */
209 /* grease pencil settings */
210 v3d->vertex_opacity = 1.0f;
212 /* Remove dither pattern in wireframe mode. */
213 v3d->shading.xray_alpha_wire = 0.0f;
214 v3d->clip_start = 0.01f;
215 /* Skip startups that use the viewport color by default. */
218 }
219 /* Disable Curve Normals. */
222 /* Always enable Grease Pencil vertex color overlay by default. */
224 /* Always use theme color for wireframe by default. */
226
227 /* Level out the 3D Viewport camera rotation, see: #113751. */
228 constexpr float viewports_to_level[][4] = {
229 /* Animation, Modeling, Scripting, Texture Paint, UV Editing. */
230 {0x1.6e7cb8p-1, -0x1.c1747p-2, -0x1.2997dap-2, -0x1.d5d806p-2},
231 /* Layout. */
232 {0x1.6e7cb8p-1, -0x1.c17478p-2, -0x1.2997dcp-2, -0x1.d5d80cp-2},
233 /* Geometry Nodes. */
234 {0x1.6e7cb6p-1, -0x1.c17476p-2, -0x1.2997dep-2, -0x1.d5d80cp-2},
235 };
236
237 constexpr float viewports_to_clear_ofs[][4] = {
238 /* Geometry Nodes. */
239 {0x1.6e7cb6p-1, -0x1.c17476p-2, -0x1.2997dep-2, -0x1.d5d80cp-2},
240 /* Sculpting. */
241 {0x1.885b28p-1, -0x1.2d10cp-1, -0x1.42ae54p-3, -0x1.a486a2p-3},
242 };
243
244 constexpr float unified_viewquat[4] = {
245 0x1.6cbc88p-1, -0x1.c3a5c8p-2, -0x1.26413ep-2, -0x1.db430ap-2};
246
247 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
248 if (region->regiontype == RGN_TYPE_WINDOW) {
249 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
250
251 for (int i = 0; i < ARRAY_SIZE(viewports_to_clear_ofs); i++) {
252 if (equals_v4v4(rv3d->viewquat, viewports_to_clear_ofs[i])) {
253 zero_v3(rv3d->ofs);
254 }
255 }
256
257 for (int i = 0; i < ARRAY_SIZE(viewports_to_level); i++) {
258 if (equals_v4v4(rv3d->viewquat, viewports_to_level[i])) {
259 copy_qt_qt(rv3d->viewquat, unified_viewquat);
260 }
261 }
262 }
263 }
264 }
265 else if (area->spacetype == SPACE_CLIP) {
266 SpaceClip *sclip = static_cast<SpaceClip *>(area->spacedata.first);
268 sclip->mask_info.blend_factor = 0.7f;
270 }
271 }
272
273 /* Show tool-header by default (for most cases at least, hide for others). */
274 const bool hide_image_tool_header = STREQ(workspace_name, "Rendering");
275 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
276 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
277 ListBase *regionbase = (sl == static_cast<SpaceLink *>(area->spacedata.first)) ?
278 &area->regionbase :
279 &sl->regionbase;
280
281 LISTBASE_FOREACH (ARegion *, region, regionbase) {
282 if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
283 if (((sl->spacetype == SPACE_IMAGE) && hide_image_tool_header) ||
284 sl->spacetype == SPACE_SEQ)
285 {
286 region->flag |= RGN_FLAG_HIDDEN;
287 }
288 else {
289 region->flag &= ~(RGN_FLAG_HIDDEN | RGN_FLAG_HIDDEN_BY_USER);
290 }
291 }
292 }
293 }
294 }
295
296 /* 2D animation template. */
297 if (app_template && STREQ(app_template, "2D_Animation")) {
298 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
299 if (area->spacetype == SPACE_ACTION) {
300 SpaceAction *saction = static_cast<SpaceAction *>(area->spacedata.first);
301 /* Enable Sliders. */
302 saction->flag |= SACTION_SLIDERS;
303 }
304 else if (area->spacetype == SPACE_VIEW3D) {
305 View3D *v3d = static_cast<View3D *>(area->spacedata.first);
306 /* Set Material Color by default. */
308 /* Enable Annotations. */
310 }
311 }
312 }
313}
314
316{
317 LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
318 if (layout->screen) {
319 blo_update_defaults_screen(layout->screen, app_template, workspace->id.name + 2);
320 }
321 }
322
324 /* Clear all tools to use default options instead, ignore the tool saved in the file. */
325 while (!BLI_listbase_is_empty(&workspace->tools)) {
326 BKE_workspace_tool_remove(workspace, static_cast<bToolRef *>(workspace->tools.first));
327 }
328
329 /* For 2D animation template. */
330 if (STREQ(workspace->id.name + 2, "Drawing")) {
332 }
333
334 /* For Sculpting template. */
335 if (STREQ(workspace->id.name + 2, "Sculpting")) {
336 LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
337 bScreen *screen = layout->screen;
338 if (screen) {
339 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
340 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
341 if (area->spacetype == SPACE_VIEW3D) {
342 View3D *v3d = static_cast<View3D *>(area->spacedata.first);
344 copy_v3_fl(v3d->shading.single_color, 1.0f);
345 STRNCPY(v3d->shading.matcap, "basic_1");
346 }
347 }
348 }
349 }
350 }
351 }
352 }
353 /* For Video Editing template. */
354 if (STRPREFIX(workspace->id.name + 2, "Video Editing")) {
355 LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
356 bScreen *screen = layout->screen;
357 if (screen) {
358 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
359 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
360 if (sl->spacetype == SPACE_SEQ) {
361 if (((SpaceSeq *)sl)->view == SEQ_VIEW_PREVIEW) {
362 continue;
363 }
364 ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
365 &sl->regionbase;
367 sidebar->flag |= RGN_FLAG_HIDDEN;
368 }
369 if (sl->spacetype == SPACE_PROPERTIES) {
370 SpaceProperties *properties = reinterpret_cast<SpaceProperties *>(sl);
371 properties->mainb = properties->mainbo = properties->mainbuser = BCONTEXT_STRIP;
372 }
373 }
374 }
375 }
376 }
377 }
378}
379
381{
382 if (!paint) {
383 return;
384 }
385
386 /* Ensure input_samples has a correct default value of 1. */
387 if (paint->unified_paint_settings.input_samples == 0) {
389 }
390
392 paint->unified_paint_settings.size = default_ups.size;
395 paint->unified_paint_settings.alpha = default_ups.alpha;
396 paint->unified_paint_settings.weight = default_ups.weight;
397 paint->unified_paint_settings.flag = default_ups.flag;
398 copy_v3_v3(paint->unified_paint_settings.color, default_ups.color);
400
401 if (paint->unified_paint_settings.curve_rand_hue == nullptr) {
403 }
404 if (paint->unified_paint_settings.curve_rand_saturation == nullptr) {
406 }
407 if (paint->unified_paint_settings.curve_rand_value == nullptr) {
409 }
410}
411
416
417static void blo_update_defaults_scene(Main *bmain, Scene *scene)
418{
419 ToolSettings *ts = scene->toolsettings;
420
422
423 scene->r.cfra = 1.0f;
426
427 /* Don't enable compositing nodes. */
428 if (scene->nodetree) {
430 MEM_freeN(scene->nodetree);
431 scene->nodetree = nullptr;
432 scene->use_nodes = false;
433 }
434
435 /* Rename render layers. */
437 bmain, scene, static_cast<ViewLayer *>(scene->view_layers.first), "ViewLayer");
438
439 /* Disable Z pass by default. */
440 LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
441 view_layer->passflag &= ~SCE_PASS_DEPTH;
442 view_layer->eevee.ambient_occlusion_distance = 10.0f;
443 }
444
445 if (scene->ed) {
446 /* Display missing media by default. */
448 /* Turn on frame pre-fetching per default. */
450 }
451
452 /* New EEVEE defaults. */
453 scene->eevee.motion_blur_shutter_deprecated = 0.5f;
455
457 copy_v2_fl2(scene->safe_areas.title, 0.1f, 0.05f);
458 copy_v2_fl2(scene->safe_areas.action, 0.035f, 0.035f);
459
461
462 /* Default Rotate Increment. */
463 const float default_snap_angle_increment = DEG2RADF(5.0f);
464 ts->snap_angle_increment_2d = default_snap_angle_increment;
465 ts->snap_angle_increment_3d = default_snap_angle_increment;
466 const float default_snap_angle_increment_precision = DEG2RADF(1.0f);
467 ts->snap_angle_increment_2d_precision = default_snap_angle_increment_precision;
468 ts->snap_angle_increment_3d_precision = default_snap_angle_increment_precision;
469
470 /* Be sure `curfalloff` and primitive are initialized. */
471 if (ts->gp_sculpt.cur_falloff == nullptr) {
472 ts->gp_sculpt.cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
473 CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff;
474 BKE_curvemapping_init(gp_falloff_curve);
475 BKE_curvemap_reset(gp_falloff_curve->cm,
476 &gp_falloff_curve->clipr,
479 }
480 if (ts->gp_sculpt.cur_primitive == nullptr) {
481 ts->gp_sculpt.cur_primitive = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
482 CurveMapping *gp_primitive_curve = ts->gp_sculpt.cur_primitive;
483 BKE_curvemapping_init(gp_primitive_curve);
484 BKE_curvemap_reset(gp_primitive_curve->cm,
485 &gp_primitive_curve->clipr,
488 }
489
490 if (ts->sculpt) {
492 }
493
494 /* Correct default startup UVs. */
495 Mesh *mesh = static_cast<Mesh *>(BLI_findstring(&bmain->meshes, "Cube", offsetof(ID, name) + 2));
496 if (mesh && (mesh->corners_num == 24) &&
498 {
499 const float uv_values[24][2] = {
500 {0.625, 0.50}, {0.875, 0.50}, {0.875, 0.75}, {0.625, 0.75}, {0.375, 0.75}, {0.625, 0.75},
501 {0.625, 1.00}, {0.375, 1.00}, {0.375, 0.00}, {0.625, 0.00}, {0.625, 0.25}, {0.375, 0.25},
502 {0.125, 0.50}, {0.375, 0.50}, {0.375, 0.75}, {0.125, 0.75}, {0.375, 0.50}, {0.625, 0.50},
503 {0.625, 0.75}, {0.375, 0.75}, {0.375, 0.25}, {0.625, 0.25}, {0.625, 0.50}, {0.375, 0.50},
504 };
505 float (*uv_map)[2] = static_cast<float (*)[2]>(
507 memcpy(uv_map, uv_values, sizeof(float[2]) * mesh->corners_num);
508 }
509
510 /* Make sure that the curve profile is initialized */
511 if (ts->custom_bevel_profile_preset == nullptr) {
513 }
514
515 /* Clear ID properties so Cycles gets defaults. */
516 IDProperty *idprop = IDP_GetProperties(&scene->id);
517 if (idprop) {
518 IDP_ClearProperty(idprop);
519 }
520
521 if (ts->sculpt) {
523 }
524
525 /* Ensure input_samples has a correct default value of 1. */
526 if (ts->unified_paint_settings.input_samples == 0) {
527 ts->unified_paint_settings.input_samples = 1;
528 }
529
531 ts->unified_paint_settings.flag = default_ups.flag;
532 copy_v3_v3(ts->unified_paint_settings.color, default_ups.color);
533 copy_v3_v3(ts->unified_paint_settings.secondary_color, default_ups.secondary_color);
534
535 if (ts->unified_paint_settings.curve_rand_hue == nullptr) {
536 ts->unified_paint_settings.curve_rand_hue = BKE_paint_default_curve();
537 }
538 if (ts->unified_paint_settings.curve_rand_saturation == nullptr) {
539 ts->unified_paint_settings.curve_rand_saturation = BKE_paint_default_curve();
540 }
541 if (ts->unified_paint_settings.curve_rand_value == nullptr) {
542 ts->unified_paint_settings.curve_rand_value = BKE_paint_default_curve();
543 }
544
545 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->vpaint));
546 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->wpaint));
547 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->sculpt));
548 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->gp_paint));
549 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->gp_vertexpaint));
550 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->gp_sculptpaint));
551 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->curves_sculpt));
552 blo_update_defaults_paint(reinterpret_cast<Paint *>(&ts->imapaint));
553
554 /* Weight Paint settings */
556}
557
559{
560 /* For all app templates. */
561 LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
563 }
564
565 /* Grease pencil materials and paint modes setup. */
566 {
567 /* Rename and fix materials and enable default object lights on. */
568 if (app_template && STREQ(app_template, "2D_Animation")) {
569 Material *ma = nullptr;
570 do_versions_rename_id(bmain, ID_MA, "Black", "Solid Stroke");
571 do_versions_rename_id(bmain, ID_MA, "Red", "Squares Stroke");
572 do_versions_rename_id(bmain, ID_MA, "Grey", "Solid Fill");
573 do_versions_rename_id(bmain, ID_MA, "Black Dots", "Dots Stroke");
574
575 /* Dots Stroke. */
576 ma = static_cast<Material *>(
577 BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2));
578 if (ma == nullptr) {
579 ma = BKE_gpencil_material_add(bmain, "Dots Stroke");
580 }
582
583 /* Squares Stroke. */
584 ma = static_cast<Material *>(
585 BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2));
586 if (ma == nullptr) {
587 ma = BKE_gpencil_material_add(bmain, "Squares Stroke");
588 }
590
591 /* Change Solid Stroke settings. */
592 ma = static_cast<Material *>(
593 BLI_findstring(&bmain->materials, "Solid Stroke", offsetof(ID, name) + 2));
594 if (ma != nullptr) {
595 ma->gp_style->mix_rgba[3] = 1.0f;
596 ma->gp_style->texture_offset[0] = -0.5f;
597 ma->gp_style->mix_factor = 0.5f;
598 }
599
600 /* Change Solid Fill settings. */
601 ma = static_cast<Material *>(
602 BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2));
603 if (ma != nullptr) {
605 ma->gp_style->mix_rgba[3] = 1.0f;
606 ma->gp_style->texture_offset[0] = -0.5f;
607 ma->gp_style->mix_factor = 0.5f;
608 }
609
610 Object *ob = static_cast<Object *>(
611 BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2));
612 if (ob && ob->type == OB_GPENCIL_LEGACY) {
614 }
615 }
616
617 /* Add library weak references to avoid duplicating materials from essentials. */
618 const std::optional<std::string> assets_path = BKE_appdir_folder_id(BLENDER_SYSTEM_DATAFILES,
619 "assets/brushes");
620 if (assets_path.has_value()) {
621 const std::string assets_blend_path = *assets_path + "/essentials_brushes-gp_draw.blend";
622 LISTBASE_FOREACH (Material *, material, &bmain->materials) {
624 &material->id, assets_blend_path.c_str(), material->id.name);
625 }
626 }
627
628 /* Reset grease pencil paint modes. */
629 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
630 ToolSettings *ts = scene->toolsettings;
631
632 /* Ensure new Paint modes. */
636
637 /* Enable cursor. */
638 if (ts->gp_paint) {
640 }
641
642 /* Ensure Palette by default. */
643 if (ts->gp_paint) {
644 BKE_gpencil_palette_ensure(bmain, scene);
645 }
646 }
647 }
648
649 /* For builtin templates only. */
651 return;
652 }
653
654 /* Work-spaces. */
655 LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) {
657
658 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
659 LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
661 win->workspace_hook, workspace);
662 /* Name all screens by their workspaces (avoids 'Default.###' names). */
663 /* Default only has one window. */
664 if (layout->screen) {
665 bScreen *screen = layout->screen;
666 if (!STREQ(screen->id.name + 2, workspace->id.name + 2)) {
667 BKE_libblock_rename(*bmain, screen->id, workspace->id.name + 2);
668 }
669 }
670
671 /* For some reason we have unused screens, needed until re-saving.
672 * Clear unused layouts because they're visible in the outliner & Python API. */
673 LISTBASE_FOREACH_MUTABLE (WorkSpaceLayout *, layout_iter, &workspace->layouts) {
674 if (layout != layout_iter) {
675 BKE_workspace_layout_remove(bmain, workspace, layout_iter);
676 }
677 }
678 }
679 }
680 }
681
682 /* Scenes */
683 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
684 blo_update_defaults_scene(bmain, scene);
685
686 if (app_template && STR_ELEM(app_template, "Video_Editing", "2D_Animation")) {
687 /* Filmic is too slow, use standard until it is optimized. */
688 STRNCPY_UTF8(scene->view_settings.view_transform, "Standard");
689 STRNCPY_UTF8(scene->view_settings.look, "None");
690 }
691 else {
692 /* Default to AgX view transform. */
693 STRNCPY_UTF8(scene->view_settings.view_transform, "AgX");
694 }
695
696 if (app_template && STREQ(app_template, "Video_Editing")) {
697 /* Pass: no extra tweaks needed. Keep the view settings configured above, and rely on the
698 * default state of enabled AV sync. */
699 }
700 else {
701 /* AV Sync break physics sim caching, disable until that is fixed. */
702 scene->audio.flag &= ~AUDIO_SYNC;
703 scene->flag &= ~SCE_FRAME_DROP;
704 }
705
706 /* Change default selection mode for Grease Pencil. */
707 if (app_template && STREQ(app_template, "2D_Animation")) {
708 ToolSettings *ts = scene->toolsettings;
710 }
711 }
712
713 /* Objects */
714 do_versions_rename_id(bmain, ID_OB, "Lamp", "Light");
715 do_versions_rename_id(bmain, ID_LA, "Lamp", "Light");
716
717 if (app_template && STREQ(app_template, "2D_Animation")) {
718 LISTBASE_FOREACH (Object *, object, &bmain->objects) {
719 if (object->type == OB_GPENCIL_LEGACY) {
720 /* Set grease pencil object in drawing mode */
721 bGPdata *gpd = (bGPdata *)object->data;
722 object->mode = OB_MODE_PAINT_GREASE_PENCIL;
724 break;
725 }
726 }
727 }
728
729 LISTBASE_FOREACH (Object *, object, &bmain->objects) {
731 /* Set default for shadow terminator bias. */
732 object->shadow_terminator_normal_offset = dob->shadow_terminator_normal_offset;
733 object->shadow_terminator_geometry_offset = dob->shadow_terminator_geometry_offset;
734 object->shadow_terminator_shading_offset = dob->shadow_terminator_shading_offset;
735 }
736
737 LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) {
738 /* Match default for new meshes. */
739 mesh->smoothresh_legacy = DEG2RADF(30);
740 /* Match voxel remesher options for all existing meshes in templates. */
742
743 /* For Sculpting template. */
744 if (app_template && STREQ(app_template, "Sculpting")) {
745 mesh->remesh_voxel_size = 0.035f;
746 blender::bke::mesh_smooth_set(*mesh, false);
747 }
748 else {
749 /* Remove sculpt-mask data in default mesh objects for all non-sculpt templates. */
750 CustomData_free_layers(&mesh->vert_data, CD_PAINT_MASK);
751 CustomData_free_layers(&mesh->corner_data, CD_GRID_PAINT_MASK);
752 }
753 mesh->attributes_for_write().remove(".sculpt_face_set");
754 }
755
756 LISTBASE_FOREACH (Camera *, camera, &bmain->cameras) {
757 /* Initialize to a useful value. */
758 camera->dof.focus_distance = 10.0f;
759 camera->dof.aperture_fstop = 2.8f;
760 }
761
762 LISTBASE_FOREACH (Light *, light, &bmain->lights) {
763 /* Fix lights defaults. */
764 light->clipsta = 0.05f;
765 light->att_dist = 40.0f;
766 }
767
768 /* Materials */
769 LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
770 /* Update default material to be a bit more rough. */
771 ma->roughness = 0.5f;
772 /* Enable transparent shadows. */
773 ma->blend_flag |= MA_BL_TRANSPARENT_SHADOW;
774
775 if (ma->nodetree) {
776 for (bNode *node : ma->nodetree->all_nodes()) {
777 if (node->type_legacy == SH_NODE_BSDF_PRINCIPLED) {
779 *node, SOCK_IN, "Roughness");
780 *version_cycles_node_socket_float_value(roughness_socket) = 0.5f;
781 bNodeSocket *emission = blender::bke::node_find_socket(*node, SOCK_IN, "Emission Color");
783 bNodeSocket *emission_strength = blender::bke::node_find_socket(
784 *node, SOCK_IN, "Emission Strength");
785 *version_cycles_node_socket_float_value(emission_strength) = 0.0f;
788
789 node->custom1 = SHD_GLOSSY_MULTI_GGX;
790 node->custom2 = SHD_SUBSURFACE_RANDOM_WALK;
791
792 node->location[0] = -200.0f;
793 node->location[1] = 100.0f;
794 BKE_ntree_update_tag_node_property(ma->nodetree, node);
795 }
796 else if (node->type_legacy == SH_NODE_SUBSURFACE_SCATTERING) {
797 node->custom1 = SHD_SUBSURFACE_RANDOM_WALK;
798 BKE_ntree_update_tag_node_property(ma->nodetree, node);
799 }
800 else if (node->type_legacy == SH_NODE_OUTPUT_MATERIAL) {
801 node->location[0] = 200.0f;
802 node->location[1] = 100.0f;
803 }
804 }
805 }
806 }
807
808 /* Brushes */
809 {
810 /* Remove default brushes replaced by assets. Also remove outliner `treestore` that may point
811 * to brushes. Normally the treestore is updated properly but it doesn't seem to update during
812 * versioning code. It's not helpful anyway. */
813 LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
814 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
815 LISTBASE_FOREACH (SpaceLink *, space_link, &area->spacedata) {
816 if (space_link->spacetype == SPACE_OUTLINER) {
817 SpaceOutliner *space_outliner = reinterpret_cast<SpaceOutliner *>(space_link);
818 if (space_outliner->treestore) {
819 BLI_mempool_destroy(space_outliner->treestore);
820 space_outliner->treestore = nullptr;
821 }
822 }
823 }
824 }
825 }
826 LISTBASE_FOREACH_MUTABLE (Brush *, brush, &bmain->brushes) {
827 BKE_id_delete(bmain, brush);
828 }
829 }
830
831 {
832 LISTBASE_FOREACH (Light *, light, &bmain->lights) {
833 light->shadow_maximum_resolution = 0.001f;
834 light->transmission_fac = 1.0f;
835 SET_FLAG_FROM_TEST(light->mode, false, LA_SHAD_RES_ABSOLUTE);
836 }
837 }
838
839 {
840 LISTBASE_FOREACH (World *, world, &bmain->worlds) {
841 SET_FLAG_FROM_TEST(world->flag, true, WO_USE_SUN_SHADOW);
842 if (world->nodetree) {
843 for (bNode *node : world->nodetree->all_nodes()) {
844 if (node->type_legacy == SH_NODE_OUTPUT_WORLD) {
845 node->location[0] = 200.0f;
846 node->location[1] = 100.0f;
847 }
848 else if (node->type_legacy == SH_NODE_BACKGROUND) {
849 node->location[0] = -200.0f;
850 node->location[1] = 100.0f;
851 }
852 }
853 }
854 }
855 }
856
857 /* Grease Pencil Anti-Aliasing. */
858 {
859 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
860 scene->grease_pencil_settings.smaa_threshold = 1.0f;
861 scene->grease_pencil_settings.smaa_threshold_render = 0.25f;
862 scene->grease_pencil_settings.aa_samples = 8;
863 scene->grease_pencil_settings.motion_blur_steps = 8;
864 }
865 }
866}
const char * BKE_appdir_folder_default() ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:137
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:721
@ BLENDER_SYSTEM_DATAFILES
void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, CurveMapSlopeType slope)
void BKE_curvemapping_init(CurveMapping *cumap)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:89
struct CurveProfile * BKE_curveprofile_add(eCurveProfilePresets preset)
CustomData interface, see also DNA_customdata_types.h.
void CustomData_free_layers(CustomData *data, eCustomDataType type)
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void BKE_gpencil_palette_ensure(struct Main *bmain, struct Scene *scene)
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1257
IDProperty * IDP_GetProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:877
void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, const char *newname)
void BKE_id_delete(Main *bmain, void *idv) ATTR_NONNULL()
IDNewNameResult BKE_libblock_rename(Main &bmain, ID &id, blender::StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
Definition lib_id.cc:2370
void BKE_main_library_weak_reference_add(ID *local_id, const char *library_filepath, const char *library_id_name)
Definition main.cc:803
General operations, lookup, etc. for materials.
Material * BKE_gpencil_material_add(Main *bmain, const char *name)
#define SH_NODE_OUTPUT_WORLD
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_SUBSURFACE_SCATTERING
#define SH_NODE_OUTPUT_MATERIAL
#define SH_NODE_BACKGROUND
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
CurveMapping * BKE_paint_default_curve()
Definition scene.cc:146
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:326
ARegion * BKE_region_find_in_listbase_by_type(const ListBase *regionbase, const int region_type)
Definition screen.cc:835
void BKE_area_region_panels_free(ListBase *panels)
Definition screen.cc:585
void BKE_workspace_tool_remove(WorkSpace *workspace, bToolRef *tref) ATTR_NONNULL(1
void BKE_workspace_layout_remove(Main *bmain, WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL()
Definition workspace.cc:399
WorkSpaceLayout * BKE_workspace_active_layout_for_workspace_get(const WorkSpaceInstanceHook *hook, const WorkSpace *workspace) GETTER_ATTRS
Definition workspace.cc:592
#define LISTBASE_FOREACH(type, var, list)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:608
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
#define DEG2RADF(_deg)
#define M_SQRT1_3
void copy_qt_qt(float q[4], const float a[4])
MINLINE void copy_v2_fl2(float v[2], float x, float y)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE bool equals_v4v4(const float v1[4], const float v2[4]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void zero_v3(float r[3])
MINLINE void copy_v4_fl(float r[4], float f)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
#define STR_ELEM(...)
Definition BLI_string.h:661
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
#define STRNCPY_UTF8(dst, src)
#define STRPREFIX(a, b)
#define ARRAY_SIZE(arr)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define STREQ(a, b)
external readfile function prototypes.
@ ID_LA
@ ID_MA
@ ID_OB
@ ADS_FLAG_SUMMARY_COLLAPSED
@ SACTCONT_TIMELINE
@ SACTION_SHOW_MARKERS
@ SACTION_SLIDERS
@ CURVE_PRESET_GAUSS
@ CURVE_PRESET_BELL
@ PROF_PRESET_LINE
@ CD_PROP_FLOAT2
@ CD_GRID_PAINT_MASK
#define DNA_struct_default_get(struct_name)
@ GP_DATA_STROKE_PAINTMODE
@ LA_SHAD_RES_ABSOLUTE
@ MASK_DRAWFLAG_SPLINE
@ MA_BL_TRANSPARENT_SHADOW
@ GP_MATERIAL_STROKE_SHOW
@ GP_MATERIAL_MODE_SQUARE
@ GP_MATERIAL_MODE_DOT
@ ME_REMESH_REPROJECT_ATTRIBUTES
@ ME_REMESH_REPROJECT_VOLUME
@ SHD_SUBSURFACE_RANDOM_WALK
@ SHD_GLOSSY_MULTI_GGX
@ SOCK_IN
@ OB_MODE_PAINT_GREASE_PENCIL
Object is a sort of wrapper for general info.
@ OB_USE_GPENCIL_LIGHTS
@ OB_GPENCIL_LEGACY
@ GP_SELECTMODE_STROKE
@ OB_DRAW_GROUPUSER_ACTIVE
@ PAINT_SHOW_BRUSH
@ AUDIO_SYNC
@ UV_FLAG_SELECT_SYNC
@ SCE_FRAME_DROP
@ SCE_EEVEE_VOLUME_CUSTOM_RANGE
@ R_IMF_EXR_FLAG_MULTIPART
@ SCE_PASS_DEPTH
@ RGN_TYPE_CHANNELS
@ RGN_TYPE_TOOL_HEADER
@ RGN_TYPE_UI
@ RGN_TYPE_WINDOW
@ RGN_TYPE_TOOLS
@ RGN_TYPE_TOOL_PROPS
@ RGN_FLAG_HIDDEN
@ RGN_FLAG_HIDDEN_BY_USER
@ SEQ_CACHE_PREFETCH_ENABLE
@ SEQ_EDIT_SHOW_MISSING_MEDIA
@ SEQ_RENDER_SIZE_PROXY_100
@ SPACE_TEXT
@ SPACE_CLIP
@ SPACE_ACTION
@ SPACE_OUTLINER
@ SPACE_FILE
@ SPACE_PROPERTIES
@ SPACE_NLA
@ SPACE_SEQ
@ SPACE_IMAGE
@ SPACE_GRAPH
@ SPACE_VIEW3D
@ SEQ_TIMELINE_SHOW_STRIP_DURATION
@ SEQ_TIMELINE_SHOW_THUMBNAILS
@ SEQ_TIMELINE_SHOW_STRIP_RETIMING
@ SEQ_TIMELINE_WAVEFORMS_HALF
@ SEQ_TIMELINE_SHOW_STRIP_SOURCE
@ SEQ_TIMELINE_SHOW_STRIP_NAME
@ SEQ_TIMELINE_SHOW_GRID
@ SEQ_TIMELINE_SHOW_STRIP_COLOR_TAG
@ SEQ_VIEW_PREVIEW
@ SIPO_SHOW_MARKERS
@ SEQ_PREVIEW_SHOW_OUTLINE_SELECTED
@ SNLA_SHOW_MARKERS
@ SEQ_DRAW_TRANSFORM_PREVIEW
@ ST_FIND_WRAP
@ SEQ_CACHE_SHOW
@ SEQ_CACHE_SHOW_FINAL_OUT
@ SEQ_SHOW_MARKERS
@ SEQ_USE_PROXIES
@ SEQ_ZOOM_TO_FIT
@ SEQ_SHOW_OVERLAY
@ SI_MODE_VIEW
@ SI_MODE_UV
@ BCONTEXT_STRIP
@ V2D_IS_INIT
@ V3D_SHADING_BACKGROUND_VIEWPORT
@ V3D_SHADING_MATERIAL_COLOR
@ V3D_SHADING_SINGLE_COLOR
@ V3D_SHOW_ANNOTATION
@ V3D_SHADING_SPECULAR_HIGHLIGHT
@ V3D_SHADING_CAVITY
@ V3D_GP_SHOW_EDIT_LINES
@ V3D_SHADING_CAVITY_CURVATURE
@ V3D_AROUND_CENTER_MEDIAN
@ V3D_OVERLAY_EDIT_CU_NORMALS
@ V3D_OVERLAY_EDIT_EDGES_DEPRECATED
@ WO_USE_SUN_SHADOW
static AppView * view
Read Guarded memory(de)allocation.
nullptr float
#define offsetof(t, d)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
Definition node.cc:2532
void mesh_smooth_set(Mesh &mesh, bool use_smooth, bool keep_sharp_edges=false)
void node_tree_free_embedded_tree(bNodeTree *ntree)
Definition node.cc:4462
VecBase< float, 3 > float3
const char * name
const char * RE_engine_id_BLENDER_EEVEE
Definition scene.cc:1580
struct ImageFormatData im_format
CurveMap cm[4]
int show_missing_media_flag
struct CurveMapping * cur_primitive
struct CurveMapping * cur_falloff
Definition DNA_ID.h:414
char name[258]
Definition DNA_ID.h:432
void * first
ListBase brushes
Definition BKE_main.hh:302
ListBase scenes
Definition BKE_main.hh:278
ListBase wm
Definition BKE_main.hh:307
ListBase meshes
Definition BKE_main.hh:281
ListBase lights
Definition BKE_main.hh:288
ListBase materials
Definition BKE_main.hh:284
ListBase cameras
Definition BKE_main.hh:289
ListBase worlds
Definition BKE_main.hh:291
ListBase screens
Definition BKE_main.hh:292
ListBase workspaces
Definition BKE_main.hh:315
ListBase objects
Definition BKE_main.hh:280
struct MaterialGPencilStyle * gp_style
int corners_num
CustomData corner_data
float shadow_terminator_shading_offset
float shadow_terminator_geometry_offset
float shadow_terminator_normal_offset
struct UnifiedPaintSettings unified_paint_settings
struct BakeData bake
char engine[32]
struct ImageFormatData im_format
float light_direction[3]
struct SceneDisplay display
struct ToolSettings * toolsettings
struct Editing * ed
struct RenderData r
ListBase view_layers
struct DisplaySafeAreas safe_areas
struct SceneEEVEE eevee
int automasking_boundary_edges_propagation_steps
MaskSpaceInfo mask_info
FileSelectParams * params
float uv_face_opacity
struct BLI_mempool * treestore
struct SequencerCacheOverlay cache_overlay
struct SequencerTimelineOverlay timeline_overlay
ListBase regionbase
short render_size
struct SequencerPreviewOverlay preview_overlay
struct ImagePaintSettings imapaint
struct CurveProfile * custom_bevel_profile_preset
float snap_angle_increment_3d_precision
float snap_angle_increment_2d_precision
GpSculptPaint * gp_sculptpaint
float snap_angle_increment_3d
float snap_angle_increment_2d
CurvesSculpt * curves_sculpt
struct GP_Sculpt_Settings gp_sculpt
GpVertexPaint * gp_vertexpaint
struct CurveMapping * curve_rand_value
struct CurveMapping * curve_rand_saturation
struct CurveMapping * curve_rand_hue
float normals_constant_screen_size
float texture_paint_mode_opacity
float vertex_paint_mode_opacity
float gpencil_vertex_paint_opacity
float weight_paint_mode_opacity
float background_color[3]
float vertex_opacity
View3DOverlay overlay
View3DShading shading
float clip_start
Wrapper for bScreen.
struct bScreen * screen
ListBase areabase
XrSessionSettings session_settings
i
Definition text_draw.cc:230
ID * do_versions_rename_id(Main *bmain, const short id_type, const char *name_src, const char *name_dst)
float * version_cycles_node_socket_float_value(bNodeSocket *socket)
float * version_cycles_node_socket_rgba_value(bNodeSocket *socket)
void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_template)
static void blo_update_defaults_paint(Paint *paint)
static void blo_update_defaults_screen(bScreen *screen, const char *app_template, const char *workspace_name)
static void blo_update_defaults_scene(Main *bmain, Scene *scene)
static void blo_update_defaults_windowmanager(wmWindowManager *wm)
void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
static bool blo_is_builtin_template(const char *app_template)
#define N_(msgid)
char app_template[64]
Definition wm_files.cc:1191