Blender V5.3
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.hh"
22#include "BLI_math_vector_c.hh"
24#include "BLI_mempool.hh"
25#include "BLI_string.hh"
26#include "BLI_string_utf8.hh"
27#include "BLI_utildefines.hh"
28
29#include "DNA_camera_types.h"
32#include "DNA_light_types.h"
33#include "DNA_mask_types.h"
34#include "DNA_material_types.h"
35#include "DNA_mesh_types.h"
36#include "DNA_object_types.h"
37#include "DNA_scene_types.h"
38#include "DNA_screen_types.h"
39#include "DNA_sequence_types.h"
40#include "DNA_space_types.h"
42#include "DNA_workspace_types.h"
43#include "DNA_world_types.h"
44
45#include "BKE_appdir.hh"
46#include "BKE_attribute.hh"
47#include "BKE_brush.hh"
48#include "BKE_colortools.hh"
49#include "BKE_curveprofile.h"
50#include "BKE_customdata.hh"
51#include "BKE_grease_pencil.hh"
52#include "BKE_idprop.hh"
53#include "BKE_layer.hh"
54#include "BKE_lib_id.hh"
55#include "BKE_main.hh"
56#include "BKE_main_namemap.hh"
57#include "BKE_material.hh"
58#include "BKE_mesh.hh"
60#include "BKE_node_runtime.hh"
62#include "BKE_paint.hh"
63#include "BKE_paint_types.hh"
64#include "BKE_screen.hh"
65#include "BKE_workspace.hh"
66
67#include "BLO_readfile.hh"
68
69#include "BLT_translation.hh"
70
71#include "versioning_common.hh"
72
73namespace blender {
74
75/* Make preferences read-only, use `versioning_userdef.cc`. */
76#define U (*((const UserDef *)&U))
77
78static bool blo_is_builtin_template(const char *app_template)
79{
80 /* For all builtin templates shipped with Blender. */
81 return (!app_template || STR_ELEM(app_template,
82 N_("2D_Animation"),
83 N_("Storyboarding"),
84 N_("Sculpting"),
85 N_("VFX"),
86 N_("Video_Editing")));
87}
88
90 const char *app_template,
91 const char *workspace_name)
92{
93 /* For all app templates. */
94 for (ScrArea &area : screen->areabase) {
95 for (ARegion &region : area.regionbase) {
96 /* Some toolbars have been saved as initialized,
97 * we don't want them to have odd zoom-level or scrolling set, see: #47047 */
99 region.v2d.flag &= ~V2D_IS_INIT;
100 }
101 }
102
103 /* Set default folder. */
104 for (SpaceLink &sl : area.spacedata) {
105 if (sl.spacetype == SPACE_FILE) {
106 SpaceFile *sfile = reinterpret_cast<SpaceFile *>(&sl);
107 if (sfile->params) {
108 const char *dir_default = BKE_appdir_folder_default();
109 if (dir_default) {
110 STRNCPY(sfile->params->dir, dir_default);
111 sfile->params->file[0] = '\0';
112 }
113 }
114 }
115 }
116 }
117
118 /* For builtin templates only. */
119 if (!blo_is_builtin_template(app_template)) {
120 return;
121 }
122
123 for (ScrArea &area : screen->areabase) {
124 for (ARegion &region : area.regionbase) {
125 /* Remove all stored panels, we want to use defaults
126 * (order, open/closed) as defined by UI code here! */
128 region.panels_category_active.free_no_destruct();
129
130 /* Reset size so it uses consistent defaults from the region types. */
131 region.sizex = 0;
132 region.sizey = 0;
133 }
134
135 if (area.spacetype == SPACE_IMAGE) {
136 if (STREQ(workspace_name, "UV Editing")) {
137 SpaceImage *sima = area.spacedata.first_as<SpaceImage>();
138 if (sima->mode == SI_MODE_VIEW) {
139 sima->mode = SI_MODE_UV;
140 }
141 sima->uv_face_opacity = 1.0f;
142 sima->uv_edge_opacity = 1.0f;
143 }
144 else if (STR_ELEM(workspace_name, "Texture Paint", "Shading")) {
145 SpaceImage *sima = area.spacedata.first_as<SpaceImage>();
146 /* Face opacity is set to 0 to not interfere with visualization while painting */
147 sima->uv_face_opacity = 0.0f;
148 sima->uv_edge_opacity = 1.0f;
149 }
150 else if (BLI_str_startswith(workspace_name, "Compositing")) {
151 SpaceImage *sima = area.spacedata.first_as<SpaceImage>();
153 }
154 }
155 else if (area.spacetype == SPACE_ACTION) {
156 /* Show markers region, hide channels and collapse summary in timelines. */
157 SpaceAction *saction = area.spacedata.first_as<SpaceAction>();
158 saction->flag |= SACTION_SHOW_MARKERS;
159 if (saction->mode == SACTCONT_TIMELINE) {
161
162 for (ARegion &region : area.regionbase) {
163 if (region.regiontype == RGN_TYPE_CHANNELS) {
164 region.flag |= RGN_FLAG_HIDDEN;
165 }
166 }
167 }
168 else {
169 /* Open properties panel by default. */
170 for (ARegion &region : area.regionbase) {
171 if (region.regiontype == RGN_TYPE_UI) {
172 region.flag &= ~RGN_FLAG_HIDDEN;
173 }
174 }
175 }
176
177 /* Reveal the footer by default. */
178 for (ARegion &region : area.regionbase) {
179 if (region.regiontype == RGN_TYPE_FOOTER) {
180 region.flag &= ~RGN_FLAG_HIDDEN;
181 }
182 }
183 }
184 else if (area.spacetype == SPACE_GRAPH) {
185 SpaceGraph *sipo = area.spacedata.first_as<SpaceGraph>();
186 sipo->flag |= SIPO_SHOW_MARKERS;
187 }
188 else if (area.spacetype == SPACE_NLA) {
189 SpaceNla *snla = area.spacedata.first_as<SpaceNla>();
190 snla->flag |= SNLA_SHOW_MARKERS;
191 }
192 else if (area.spacetype == SPACE_SEQ) {
193 SpaceSeq *seq = area.spacedata.first_as<SpaceSeq>();
195 seq->render_size = SEQ_RENDER_SIZE_PROXY_100;
202 seq->preview_overlay.flag |= SEQ_PREVIEW_SHOW_OUTLINE_SELECTED;
203 seq->cache_overlay.flag = SEQ_CACHE_SHOW | SEQ_CACHE_SHOW_FINAL_OUT;
204 seq->draw_flag |= SEQ_DRAW_EDIT_POINT_PREVIEW;
205 }
206 else if (area.spacetype == SPACE_TEXT) {
207 /* Show syntax and line numbers in Script workspace text editor. */
208 SpaceText *stext = area.spacedata.first_as<SpaceText>();
209 stext->showsyntax = true;
210 stext->showlinenrs = true;
211 stext->flags |= ST_FIND_WRAP;
212 }
213 else if (area.spacetype == SPACE_VIEW3D) {
214 View3D *v3d = area.spacedata.first_as<View3D>();
215 /* Screen space cavity by default for faster performance. */
221 /* Update default Z bias for retopology overlay. */
222 v3d->overlay.retopology_offset = 0.01f;
223 /* Clear this deprecated bit for later reuse. */
225 /* grease pencil settings */
226 v3d->vertex_opacity = 1.0f;
228 /* Remove dither pattern in wireframe mode. */
229 v3d->shading.xray_alpha_wire = 0.0f;
230 v3d->clip_start = 0.01f;
231 /* Skip startups that use the viewport color by default. */
234 }
235 /* Disable Curve Normals. */
238 /* Always enable Grease Pencil vertex color overlay by default. */
240 /* Always use theme color for wireframe by default. */
242
243 /* Level out the 3D Viewport camera rotation, see: #113751. */
244 constexpr float viewports_to_level[][4] = {
245 /* Animation, Modeling, Scripting, Texture Paint, UV Editing. */
246 {0x1.6e7cb8p-1, -0x1.c1747p-2, -0x1.2997dap-2, -0x1.d5d806p-2},
247 /* Layout. */
248 {0x1.6e7cb8p-1, -0x1.c17478p-2, -0x1.2997dcp-2, -0x1.d5d80cp-2},
249 /* Geometry Nodes. */
250 {0x1.6e7cb6p-1, -0x1.c17476p-2, -0x1.2997dep-2, -0x1.d5d80cp-2},
251 };
252
253 constexpr float viewports_to_clear_ofs[][4] = {
254 /* Geometry Nodes. */
255 {0x1.6e7cb6p-1, -0x1.c17476p-2, -0x1.2997dep-2, -0x1.d5d80cp-2},
256 /* Sculpting. */
257 {0x1.885b28p-1, -0x1.2d10cp-1, -0x1.42ae54p-3, -0x1.a486a2p-3},
258 };
259
260 constexpr float unified_viewquat[4] = {
261 0x1.6cbc88p-1, -0x1.c3a5c8p-2, -0x1.26413ep-2, -0x1.db430ap-2};
262
263 for (ARegion &region : area.regionbase) {
264 if (region.regiontype == RGN_TYPE_WINDOW) {
265 RegionView3D *rv3d = static_cast<RegionView3D *>(region.regiondata);
266
267 for (int i = 0; i < ARRAY_SIZE(viewports_to_clear_ofs); i++) {
268 if (equals_v4v4(rv3d->viewquat, viewports_to_clear_ofs[i])) {
269 zero_v3(rv3d->ofs);
270 }
271 }
272
273 for (int i = 0; i < ARRAY_SIZE(viewports_to_level); i++) {
274 if (equals_v4v4(rv3d->viewquat, viewports_to_level[i])) {
275 copy_qt_qt(rv3d->viewquat, unified_viewquat);
276 }
277 }
278 }
279 }
280 }
281 else if (area.spacetype == SPACE_CLIP) {
282 SpaceClip *sclip = area.spacedata.first_as<SpaceClip>();
284 sclip->mask_info.blend_factor = 0.7f;
286 }
287 }
288
289 /* Show tool-header by default (for most cases at least, hide for others). */
290 const bool hide_image_tool_header = STR_ELEM(workspace_name, "Rendering", "Compositing");
291 for (ScrArea &area : screen->areabase) {
292 for (SpaceLink &sl : area.spacedata) {
293 ListBaseT<ARegion> *regionbase = (&sl == area.spacedata.first()) ? &area.regionbase :
294 &sl.regionbase;
295
296 for (ARegion &region : *regionbase) {
297 if (region.regiontype == RGN_TYPE_TOOL_HEADER) {
298 if (((sl.spacetype == SPACE_IMAGE) && hide_image_tool_header) ||
299 sl.spacetype == SPACE_SEQ)
300 {
301 region.flag |= RGN_FLAG_HIDDEN;
302 }
303 else {
304 region.flag &= ~(RGN_FLAG_HIDDEN | RGN_FLAG_HIDDEN_BY_USER);
305 }
306 }
307 }
308 }
309 }
310
311 /* 2D animation template. */
312 if (app_template && STREQ(app_template, "2D_Animation")) {
313 for (ScrArea &area : screen->areabase) {
314 if (area.spacetype == SPACE_ACTION) {
315 SpaceAction *saction = area.spacedata.first_as<SpaceAction>();
316 /* Enable Sliders. */
317 saction->flag |= SACTION_SLIDERS;
318 }
319 else if (area.spacetype == SPACE_VIEW3D) {
320 View3D *v3d = area.spacedata.first_as<View3D>();
321 /* Set Material Color by default. */
323 /* Enable Annotations. */
325 }
326 }
327 }
328}
329
330void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_template)
331{
332 for (WorkSpaceLayout &layout : workspace->layouts) {
333 if (layout.screen) {
334 blo_update_defaults_screen(layout.screen, app_template, workspace->id.name + 2);
335 }
336 }
337
338 if (blo_is_builtin_template(app_template)) {
339 /* Clear all tools to use default options instead, ignore the tool saved in the file. */
340 while (!workspace->tools.is_empty()) {
341 BKE_workspace_tool_remove(workspace, workspace->tools.first());
342 }
343
344 /* For 2D animation template. */
345 if (STREQ(workspace->id.name + 2, "Drawing")) {
347 }
348
349 /* For Sculpting template. */
350 if (STREQ(workspace->id.name + 2, "Sculpting")) {
351 for (WorkSpaceLayout &layout : workspace->layouts) {
352 bScreen *screen = layout.screen;
353 if (screen) {
354 for (ScrArea &area : screen->areabase) {
355 if (area.spacetype == SPACE_VIEW3D) {
356 View3D *v3d = area.spacedata.first_as<View3D>();
358 copy_v3_fl(v3d->shading.single_color, 1.0f);
359 STRNCPY(v3d->shading.matcap, "basic_1");
360 }
361 }
362 }
363 }
364 }
365 }
366 /* For Video Editing template. */
367 if (STRPREFIX(workspace->id.name + 2, "Video Editing")) {
368 for (WorkSpaceLayout &layout : workspace->layouts) {
369 bScreen *screen = layout.screen;
370 if (screen) {
371 for (ScrArea &area : screen->areabase) {
372 for (SpaceLink &sl : area.spacedata) {
373 if (sl.spacetype == SPACE_SEQ) {
374 if ((reinterpret_cast<SpaceSeq *>(&sl))->view == SEQ_VIEW_PREVIEW) {
375 continue;
376 }
377 ListBaseT<ARegion> *regionbase = (&sl == area.spacedata.first_) ? &area.regionbase :
378 &sl.regionbase;
380 sidebar->flag |= RGN_FLAG_HIDDEN;
381 }
382 else if (sl.spacetype == SPACE_PROPERTIES) {
383 reinterpret_cast<SpaceProperties *>(&sl)->visible_tabs &= ~(1
385 }
386 else if (sl.spacetype == SPACE_FILE) {
387 SpaceFile *sfile = reinterpret_cast<SpaceFile *>(&sl);
388 if (sfile->params) {
389 sfile->params->filter |= FILE_TYPE_TEXT;
390 }
391 }
392 }
393 }
394 }
395 }
396 }
397
398 /* For General template. */
399 if (STRPREFIX(workspace->id.name + 2, "Layout")) {
400 for (WorkSpaceLayout &layout : workspace->layouts) {
401 bScreen *screen = layout.screen;
402 if (screen) {
403 for (ScrArea &area : screen->areabase) {
404 if (area.spacetype == SPACE_VIEW3D) {
405 View3D *v3d = area.spacedata.first_as<View3D>();
407 }
408 }
409 }
410 }
411 }
412}
413
415{
416 if (!paint) {
417 return;
418 }
419
420 /* Ensure input_samples has a correct default value of 1. */
421 if (paint->unified_paint_settings.input_samples == 0) {
422 paint->unified_paint_settings.input_samples = 1;
423 }
424
425 const UnifiedPaintSettings &default_ups = UnifiedPaintSettings();
426 paint->unified_paint_settings.size = default_ups.size;
427 paint->unified_paint_settings.input_samples = default_ups.input_samples;
428 paint->unified_paint_settings.unprojected_size = default_ups.unprojected_size;
429 paint->unified_paint_settings.alpha = default_ups.alpha;
430 paint->unified_paint_settings.weight = default_ups.weight;
431 paint->unified_paint_settings.flag = default_ups.flag;
432 copy_v3_v3(paint->unified_paint_settings.color, default_ups.color);
433 copy_v3_v3(paint->unified_paint_settings.secondary_color, default_ups.secondary_color);
434
435 if (paint->unified_paint_settings.curve_rand_hue == nullptr) {
436 paint->unified_paint_settings.curve_rand_hue = BKE_paint_default_curve();
437 }
438 if (paint->unified_paint_settings.curve_rand_saturation == nullptr) {
439 paint->unified_paint_settings.curve_rand_saturation = BKE_paint_default_curve();
440 }
441 if (paint->unified_paint_settings.curve_rand_value == nullptr) {
442 paint->unified_paint_settings.curve_rand_value = BKE_paint_default_curve();
443 }
444}
445
447{
448 wm->xr.session_settings.fly_speed = 3.0f;
449 wm->xr.session_settings.view_scale = 1.0f;
450}
451
452static void blo_update_defaults_scene(Main *bmain, Scene *scene)
453{
454 ToolSettings *ts = scene->toolsettings;
455
457
458 scene->r.cfra = 1.0f;
461
463
464 /* Don't enable compositing nodes. */
465 if (scene->nodetree) {
467 MEM_delete(scene->nodetree);
468 scene->nodetree = nullptr;
469 scene->use_nodes = false;
470 }
471
472 /* Rename render layers. */
473 BKE_view_layer_rename(bmain, scene, scene->view_layers.first(), "ViewLayer");
474
475 /* Disable Z pass by default. */
476 for (ViewLayer &view_layer : scene->view_layers) {
477 view_layer.passflag &= ~SCE_PASS_DEPTH;
478 view_layer.eevee.ambient_occlusion_distance = 10.0f;
479 }
480
481 if (scene->ed) {
482 /* Display missing media by default. */
484 /* Turn on frame pre-fetching per default. */
486 }
487
488 /* New EEVEE defaults. */
491 scene->eevee.clamp_volume_indirect = 0.0f; /* Default from versioning is not 0. */
492 scene->eevee.ray_tracing_options = {};
493 scene->eevee.fast_gi_thickness_near = 0.1f; /* Default from versioning is not 0.1f. */
494
496 copy_v2_fl2(scene->safe_areas.title, 0.1f, 0.05f);
497 copy_v2_fl2(scene->safe_areas.action, 0.035f, 0.035f);
498
500
501 /* Default Rotate Increment. */
502 const float default_snap_angle_increment = DEG2RADF(5.0f);
503 ts->snap_angle_increment_2d = default_snap_angle_increment;
504 ts->snap_angle_increment_3d = default_snap_angle_increment;
505 const float default_snap_angle_increment_precision = DEG2RADF(1.0f);
506 ts->snap_angle_increment_2d_precision = default_snap_angle_increment_precision;
507 ts->snap_angle_increment_3d_precision = default_snap_angle_increment_precision;
508
509 /* Be sure `curfalloff` and primitive are initialized. */
510 if (ts->gp_sculpt.cur_falloff == nullptr) {
511 ts->gp_sculpt.cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
512 CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff;
513 BKE_curvemapping_init(gp_falloff_curve);
514 BKE_curvemap_reset(gp_falloff_curve->cm,
515 &gp_falloff_curve->clipr,
518 }
519 if (ts->gp_sculpt.cur_primitive == nullptr) {
520 ts->gp_sculpt.cur_primitive = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
521 CurveMapping *gp_primitive_curve = ts->gp_sculpt.cur_primitive;
522 BKE_curvemapping_init(gp_primitive_curve);
523 BKE_curvemap_reset(gp_primitive_curve->cm,
524 &gp_primitive_curve->clipr,
527 }
528
529 if (ts->sculpt) {
530 ts->sculpt->flags = Sculpt().flags;
531 }
532
533 /* Correct default startup UVs. */
534 Mesh *mesh = static_cast<Mesh *>(BLI_findstring(&bmain->meshes, "Cube", offsetof(ID, name) + 2));
535 if (mesh && (mesh->corners_num == 24) &&
537 {
538 const float uv_values[24][2] = {
539 {0.625, 0.50}, {0.875, 0.50}, {0.875, 0.75}, {0.625, 0.75}, {0.375, 0.75}, {0.625, 0.75},
540 {0.625, 1.00}, {0.375, 1.00}, {0.375, 0.00}, {0.625, 0.00}, {0.625, 0.25}, {0.375, 0.25},
541 {0.125, 0.50}, {0.375, 0.50}, {0.375, 0.75}, {0.125, 0.75}, {0.375, 0.50}, {0.625, 0.50},
542 {0.625, 0.75}, {0.375, 0.75}, {0.375, 0.25}, {0.625, 0.25}, {0.625, 0.50}, {0.375, 0.50},
543 };
544 float (*uv_map)[2] = static_cast<float (*)[2]>(
545 CustomData_get_layer_for_write(&mesh->corner_data, CD_PROP_FLOAT2, mesh->corners_num));
546 memcpy(uv_map, uv_values, sizeof(float[2]) * mesh->corners_num);
547 }
548
549 /* Make sure that the curve profile is initialized */
550 if (ts->custom_bevel_profile_preset == nullptr) {
552 }
553
554 /* Clear ID properties so Cycles gets defaults. */
556 if (idprop) {
558 }
559
560 if (ts->sculpt) {
562 }
563
564 /* Ensure input_samples has a correct default value of 1. */
567 }
568
569 const UnifiedPaintSettings default_ups = {};
570 ts->unified_paint_settings.flag = default_ups.flag;
573
574 if (ts->unified_paint_settings.curve_rand_hue == nullptr) {
576 }
579 }
580 if (ts->unified_paint_settings.curve_rand_value == nullptr) {
582 }
583
584 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->vpaint));
585 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->wpaint));
586 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->sculpt));
587 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->gp_paint));
588 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->gp_vertexpaint));
589 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->gp_sculptpaint));
590 blo_update_defaults_paint(reinterpret_cast<Paint *>(ts->curves_sculpt));
591 blo_update_defaults_paint(reinterpret_cast<Paint *>(&ts->imapaint));
592
593 /* Weight Paint settings */
595 ts->multipaint = true;
596 ts->auto_normalize = true;
597
598 /* Cycles settings. */
600 if (cscene) {
601 /* Set the default sampling pattern to AUTOMATIC. */
602 version_cycles_property_int_set(cscene, "sampling_pattern", 5);
603 }
604}
605
606void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
607{
608 /* For all app templates. */
609 for (WorkSpace &workspace : bmain->workspaces) {
610 BLO_update_defaults_workspace(&workspace, app_template);
611 }
612
613 /* Grease pencil materials and paint modes setup. */
614 {
615 /* Rename and fix materials and enable default object lights on. */
616 if (app_template && STREQ(app_template, "2D_Animation")) {
617 Material *ma = nullptr;
618 do_versions_rename_id(bmain, ID_MA, "Black", "Solid Stroke");
619 do_versions_rename_id(bmain, ID_MA, "Red", "Squares Stroke");
620 do_versions_rename_id(bmain, ID_MA, "Grey", "Solid Fill");
621 do_versions_rename_id(bmain, ID_MA, "Black Dots", "Dots Stroke");
622
623 /* Dots Stroke. */
624 ma = static_cast<Material *>(
625 BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2));
626 if (ma == nullptr) {
627 ma = BKE_gpencil_material_add(bmain, "Dots Stroke");
628 }
629 ma->gp_style->mode = GP_MATERIAL_MODE_DOT;
630
631 /* Squares Stroke. */
632 ma = static_cast<Material *>(
633 BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2));
634 if (ma == nullptr) {
635 ma = BKE_gpencil_material_add(bmain, "Squares Stroke");
636 }
637 ma->gp_style->mode = GP_MATERIAL_MODE_SQUARE;
638
639 /* Change Solid Stroke settings. */
640 ma = static_cast<Material *>(
641 BLI_findstring(&bmain->materials, "Solid Stroke", offsetof(ID, name) + 2));
642 if (ma != nullptr) {
643 ma->gp_style->texture_offset[0] = -0.5f;
644 ma->gp_style->mix_factor = 0.5f;
645 }
646
647 /* Change Solid Fill settings. */
648 ma = static_cast<Material *>(
649 BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2));
650 if (ma != nullptr) {
651 ma->gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW;
652 ma->gp_style->texture_offset[0] = -0.5f;
653 ma->gp_style->mix_factor = 0.5f;
654 }
655
656 Object *ob = static_cast<Object *>(
657 BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2));
658 if (ob && ob->type == OB_GPENCIL_LEGACY) {
660 }
661 }
662
663 /* Add library weak references to avoid duplicating materials from essentials. */
664 const std::optional<std::string> assets_path = BKE_appdir_folder_id(BLENDER_SYSTEM_DATAFILES,
665 "assets/brushes");
666 if (assets_path.has_value()) {
667 const std::string assets_blend_path = *assets_path + "/essentials_brushes-gp_draw.blend";
668 for (Material &material : bmain->materials) {
670 &material.id, assets_blend_path.c_str(), material.id.name);
671 }
672 }
673
674 /* Reset grease pencil paint modes. */
675 for (Scene &scene : bmain->scenes) {
676 ToolSettings *ts = scene.toolsettings;
677
678 /* Ensure new Paint modes. */
682
683 /* Enable cursor. */
684 if (ts->gp_paint) {
686 }
687
688 /* Ensure Palette by default. */
689 if (ts->gp_paint) {
691 }
692 }
693
694 if (app_template && (STR_ELEM(app_template, "2D_Animation", "Storyboarding"))) {
695 /* Since !153036, the base colors for stroke & fill were getting versioned to have 0% opacity
696 * if the stroke/fill was disabled. This meant that in a new file using the following App
697 * Templates, the "Solid Stroke" material wouldn't show anything when trying to draw a fill.
698 * This sets the fill to a mid grey to make sure users don't run into this issue. */
699
700 /* Change Solid Stroke settings. */
701 Material *ma = static_cast<Material *>(
702 BLI_findstring(&bmain->materials, "Solid Stroke", offsetof(ID, name) + 2));
703 if (ma != nullptr) {
704 /* Black Stroke and Grey Fill. */
705 copy_v4_fl4(ma->gp_style->stroke_rgba, 0.0f, 0.0f, 0.0f, 1.0f);
706 copy_v4_fl4(ma->gp_style->fill_rgba, 0.5f, 0.5f, 0.5f, 1.0f);
707 }
708 }
709 }
710
711 /* For builtin templates only. */
712 if (!blo_is_builtin_template(app_template)) {
713 return;
714 }
715
716 /* Work-spaces. */
717 for (wmWindowManager &wm : bmain->wm) {
719
720 for (wmWindow &win : wm.windows) {
721 for (WorkSpace &workspace : bmain->workspaces) {
723 &workspace);
724 /* Name all screens by their workspaces (avoids 'Default.###' names). */
725 /* Default only has one window. */
726 if (layout->screen) {
727 bScreen *screen = layout->screen;
728 if (!STREQ(screen->id.name + 2, workspace.id.name + 2)) {
729 BKE_libblock_rename(*bmain, screen->id, workspace.id.name + 2);
730 }
731 }
732
733 /* For some reason we have unused screens, needed until re-saving.
734 * Clear unused layouts because they're visible in the outliner & Python API. */
735 for (WorkSpaceLayout &layout_iter : workspace.layouts.items_mutable()) {
736 if (layout != &layout_iter) {
737 BKE_workspace_layout_remove(bmain, &workspace, &layout_iter);
738 }
739 }
740 }
741 }
742 }
743
744 /* Scenes */
745 for (Scene &scene : bmain->scenes) {
746 blo_update_defaults_scene(bmain, &scene);
747
748 if (app_template && STR_ELEM(app_template, "Video_Editing", "2D_Animation")) {
749 /* Filmic is too slow, use standard until it is optimized. */
750 STRNCPY_UTF8(scene.view_settings.view_transform, "Standard");
751 STRNCPY_UTF8(scene.view_settings.look, "None");
752 }
753 else {
754 /* Default to AgX view transform. */
756 }
757
758 if (app_template && STREQ(app_template, "Video_Editing")) {
759 /* Pass: no extra tweaks needed. Keep the view settings configured above, and rely on the
760 * default state of enabled AV sync. */
761 }
762 else {
763 /* AV Sync break physics sim caching, disable until that is fixed. */
764 scene.audio.flag &= ~AUDIO_SYNC;
765 scene.flag &= ~SCE_FRAME_DROP;
766 }
767
768 /* Change default selection mode for Grease Pencil. */
769 if (app_template && STREQ(app_template, "2D_Animation")) {
770 ToolSettings *ts = scene.toolsettings;
772 }
773 }
774
775 /* Objects */
776 do_versions_rename_id(bmain, ID_OB, "Lamp", "Light");
777 do_versions_rename_id(bmain, ID_LA, "Lamp", "Light");
778
779 if (app_template && STREQ(app_template, "2D_Animation")) {
780 for (Object &object : bmain->objects) {
781 if (object.type == OB_GPENCIL_LEGACY) {
782 /* Set grease pencil object in drawing mode */
783 bGPdata *gpd = id_cast<bGPdata *>(object.data);
784 object.mode = OB_MODE_PAINT_GREASE_PENCIL;
786 break;
787 }
788 }
789 }
790
791 for (Object &object : bmain->objects) {
792 const Object dob;
793 /* Set default for shadow terminator bias. */
795 object.shadow_terminator_geometry_offset = dob.shadow_terminator_geometry_offset;
796 object.shadow_terminator_shading_offset = dob.shadow_terminator_shading_offset;
797 }
798
799 for (Mesh &mesh : bmain->meshes) {
800 /* Match default for new meshes. */
801 mesh.smoothresh_legacy = DEG2RADF(30);
802 /* Match voxel remesher options for all existing meshes in templates. */
804
806
807 /* For Sculpting template. */
808 if (app_template && STREQ(app_template, "Sculpting")) {
809 mesh.remesh_voxel_size = 0.035f;
811 }
812 else {
813 /* Remove sculpt-mask data in default mesh objects for all non-sculpt templates. */
814 CustomData_free_layers(&mesh.vert_data, CD_PAINT_MASK);
816 }
817 mesh.attributes_for_write().remove(".sculpt_face_set");
818 }
819
820 for (Camera &camera : bmain->cameras) {
821 /* Initialize to a useful value. */
822 camera.dof.focus_distance = 10.0f;
823 camera.dof.aperture_fstop = 2.8f;
824 }
825
826 for (Light &light : bmain->lights) {
827 /* Fix lights defaults. */
828 light.clipsta = 0.05f;
829 light.att_dist = 40.0f;
830 }
831
832 /* Materials */
833 for (Material &ma : bmain->materials) {
834 /* Update default material to be a bit more rough. */
835 ma.roughness = 0.5f;
836 /* Enable transparent shadows. */
837 ma.blend_flag |= MA_BL_TRANSPARENT_SHADOW;
838
839 if (ma.nodetree) {
840 for (bNode *node : ma.nodetree->all_nodes()) {
841 if (node->type_legacy == SH_NODE_BSDF_PRINCIPLED) {
842 bNodeSocket *roughness_socket = bke::node_find_socket(*node, SOCK_IN, "Roughness"_ustr);
843 *version_cycles_node_socket_float_value(roughness_socket) = 0.5f;
844 bNodeSocket *emission = bke::node_find_socket(*node, SOCK_IN, "Emission Color"_ustr);
846 bNodeSocket *emission_strength = bke::node_find_socket(
847 *node, SOCK_IN, "Emission Strength"_ustr);
848 *version_cycles_node_socket_float_value(emission_strength) = 0.0f;
849 bNodeSocket *ior = bke::node_find_socket(*node, SOCK_IN, "IOR"_ustr);
851 bNodeSocket *subsurface_scale = bke::node_find_socket(
852 *node, SOCK_IN, "Subsurface Scale"_ustr);
853 *version_cycles_node_socket_float_value(subsurface_scale) = 0.005f;
854
855 node->custom1 = SHD_GLOSSY_MULTI_GGX;
857
858 node->location[0] = -200.0f;
859 node->location[1] = 100.0f;
861 }
862 else if (node->type_legacy == SH_NODE_SUBSURFACE_SCATTERING) {
865 }
866 else if (node->type_legacy == SH_NODE_OUTPUT_MATERIAL) {
867 node->location[0] = 200.0f;
868 node->location[1] = 100.0f;
869 }
870 }
871 }
872 }
873
874 /* Brushes */
875 {
876 /* Remove default brushes replaced by assets. Also remove outliner `treestore` that may point
877 * to brushes. Normally the treestore is updated properly but it doesn't seem to update during
878 * versioning code. It's not helpful anyway. */
879 for (bScreen &screen : bmain->screens) {
880 for (ScrArea &area : screen.areabase) {
881 for (SpaceLink &space_link : area.spacedata) {
882 if (space_link.spacetype == SPACE_OUTLINER) {
883 SpaceOutliner *space_outliner = reinterpret_cast<SpaceOutliner *>(&space_link);
884 if (space_outliner->treestore) {
885 BLI_mempool_destroy(space_outliner->treestore);
886 space_outliner->treestore = nullptr;
887 }
888 }
889 }
890 }
891 }
892 for (Brush &brush : bmain->brushes.items_mutable()) {
893 BKE_id_delete(bmain, &brush);
894 }
895 }
896
897 {
898 for (Light &light : bmain->lights) {
899 light.shadow_maximum_resolution = 0.001f;
900 light.transmission_fac = 1.0f;
901 SET_FLAG_FROM_TEST(light.mode, false, LA_SHAD_RES_ABSOLUTE);
902 }
903 }
904
905 {
906 for (World &world : bmain->worlds) {
907 SET_FLAG_FROM_TEST(world.flag, true, WO_USE_SUN_SHADOW);
908 if (world.nodetree) {
909 for (bNode *node : world.nodetree->all_nodes()) {
910 if (node->type_legacy == SH_NODE_OUTPUT_WORLD) {
911 node->location[0] = 200.0f;
912 node->location[1] = 100.0f;
913 }
914 else if (node->type_legacy == SH_NODE_BACKGROUND) {
915 node->location[0] = -200.0f;
916 node->location[1] = 100.0f;
917 }
918 }
919 }
920 }
921 }
922
923 /* Grease Pencil Anti-Aliasing. */
924 {
925 for (Scene &scene : bmain->scenes) {
930 }
931 }
932}
933
934} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
#define SH_NODE_OUTPUT_WORLD
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_SUBSURFACE_SCATTERING
#define SH_NODE_OUTPUT_MATERIAL
#define SH_NODE_BACKGROUND
#define DEG2RADF(_deg)
#define M_SQRT1_3
#define STR_ELEM(...)
#define STRNCPY_UTF8(dst, src)
external readfile function prototypes.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define STRPREFIX(a, b)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define STREQ(a, b)
#define offsetof(t, d)
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
void mesh_smooth_set(Mesh &mesh, bool use_smooth, bool keep_sharp_edges=false)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
Definition node.cc:3036
void node_tree_free_embedded_tree(bNodeTree *ntree)
Definition node.cc:5231
BMesh Iterators.
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:99
@ SEQ_RENDER_SIZE_PROXY_100
char * STRNCPY(char(&dst)[N], const char *src)
@ SEQ_TIMELINE_SHOW_STRIP_DURATION
@ SEQ_TIMELINE_SHOW_STRIP_NAME
@ SEQ_TIMELINE_STRIP_END_THUMBNAILS
@ SEQ_TIMELINE_SHOW_STRIP_RETIMING
@ SEQ_TIMELINE_SHOW_STRIP_SOURCE
@ SEQ_TIMELINE_SHOW_THUMBNAILS
@ SEQ_TIMELINE_WAVEFORMS_HALF
@ SEQ_TIMELINE_SHOW_GRID
@ SEQ_TIMELINE_SHOW_STRIP_COLOR_TAG
void BKE_id_delete(Main *bmain, void *idv, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
@ ADS_FLAG_SUMMARY_COLLAPSED
MINLINE void copy_v3_v3(float r[3], const float a[3])
@ V3D_SHADING_USE_COMPOSITOR_ALWAYS
bool CustomData_free_layers(CustomData *data, eCustomDataType type)
Material * BKE_gpencil_material_add(Main *bmain, const char *name)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void BKE_main_library_weak_reference_add(ID *local_id, const char *library_filepath, const char *library_id_name)
Definition main.cc:971
void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_template)
@ V3D_AROUND_CENTER_MEDIAN
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
static void blo_update_defaults_paint(Paint *paint)
MINLINE void copy_v4_fl(float r[4], float f)
void BKE_area_region_panels_free(ListBaseT< Panel > *panels)
Definition screen.cc:724
MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
@ SI_OVERLAY_DRAW_TEXT_INFO
float * version_cycles_node_socket_float_value(bNodeSocket *socket)
@ V3D_SHADING_SPECULAR_HIGHLIGHT
const char * RE_engine_id_BLENDER_EEVEE
Definition scene.cc:1717
static void blo_update_defaults_scene(Main *bmain, Scene *scene)
@ V3D_SHADING_CAVITY_CURVATURE
@ SCE_EEVEE_VOLUME_CUSTOM_RANGE
WorkSpaceLayout * BKE_workspace_active_layout_for_workspace_get(const WorkSpaceInstanceHook *hook, const WorkSpace *workspace) GETTER_ATTRS
Definition workspace.cc:662
void BKE_curvemapping_init(CurveMapping *cumap)
MINLINE bool equals_v4v4(const float v1[4], const float v2[4]) ATTR_WARN_UNUSED_RESULT
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
float * version_cycles_node_socket_rgba_value(bNodeSocket *socket)
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:762
ID * do_versions_rename_id(Main *bmain, const short id_type, const char *name_src, const char *name_dst)
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1408
@ ME_EDIT_MIRROR_VERTEX_GROUPS
@ SEQ_DRAW_EDIT_POINT_PREVIEW
void copy_qt_qt(float q[4], const float a[4])
@ SCE_COMPOSITOR_DEVICE_GPU
@ OB_MODE_PAINT_GREASE_PENCIL
BMesh const char void * data
void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, CurveMapSlopeType slope)
@ SEQ_PREVIEW_SHOW_OUTLINE_SELECTED
IDProperty * IDP_GetProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:1000
void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, const char *newname)
void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value)
@ SEQ_CACHE_SHOW_FINAL_OUT
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
MINLINE void copy_v2_fl2(float v[2], float x, float y)
static void blo_update_defaults_windowmanager(wmWindowManager *wm)
@ MASK_DRAWFLAG_SPLINE
@ V3D_SHADING_SINGLE_COLOR
@ V3D_SHADING_MATERIAL_COLOR
MINLINE void zero_v3(float r[3])
@ ME_REMESH_REPROJECT_ATTRIBUTES
@ ME_REMESH_REPROJECT_VOLUME
static void blo_update_defaults_screen(bScreen *screen, const char *app_template, const char *workspace_name)
ARegion * BKE_region_find_in_listbase_by_type(const ListBaseT< ARegion > *regionbase, const int region_type)
Definition screen.cc:987
@ V3D_SHADING_BACKGROUND_VIEWPORT
static bool blo_is_builtin_template(const char *app_template)
IDNewNameResult BKE_libblock_rename(Main &bmain, ID &id, StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
Definition lib_id.cc:2632
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
MINLINE void copy_v3_fl(float r[3], float f)
@ SHD_SUBSURFACE_RANDOM_WALK
@ SEQ_EDIT_SHOW_MISSING_MEDIA
int bool BLI_str_startswith(const char *__restrict str, const char *__restrict start) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
struct CurveProfile * BKE_curveprofile_add(eCurveProfilePresets preset)
void BKE_workspace_layout_remove(Main *bmain, WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL()
Definition workspace.cc:472
IDProperty * version_cycles_properties_from_ID(ID *id)
@ R_IMF_EXR_FLAG_MULTIPART
CurveMapping * BKE_paint_default_curve()
Definition scene.cc:157
@ V3D_OVERLAY_EDIT_CU_NORMALS
@ V3D_OVERLAY_EDIT_EDGES_DEPRECATED
@ RGN_FLAG_HIDDEN_BY_USER
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
@ LA_SHAD_RES_ABSOLUTE
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
VecBase< float, 3 > float3
void BKE_workspace_tool_remove(WorkSpace *workspace, bToolRef *tref) ATTR_NONNULL(1
Definition workspace.cc:569
@ BLENDER_SYSTEM_DATAFILES
@ SHD_GLOSSY_MULTI_GGX
@ OB_DRAW_GROUPUSER_ACTIVE
void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
const char * BKE_appdir_folder_default() ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:139
void BKE_grease_pencil_palette_ensure(Main *bmain, Scene *scene)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< Panel > panels
eRegion_Type regiontype
ListBaseT< PanelCategoryStack > panels_category_active
ImageFormatData im_format
eEditingShowMissingMediaFlag show_missing_media_flag
eEditingCacheFlag cache_flag
struct CurveMapping * cur_falloff
struct CurveMapping * cur_primitive
char name[258]
Definition DNA_ID.h:433
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< Camera > cameras
Definition BKE_main.hh:397
ListBaseT< Light > lights
Definition BKE_main.hh:396
ListBaseT< World > worlds
Definition BKE_main.hh:399
ListBaseT< Brush > brushes
Definition BKE_main.hh:410
ListBaseT< Material > materials
Definition BKE_main.hh:392
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Mesh > meshes
Definition BKE_main.hh:389
ListBaseT< WorkSpace > workspaces
Definition BKE_main.hh:423
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
eObject_DrawExtraFlag dtx
float shadow_terminator_shading_offset
float shadow_terminator_geometry_offset
float shadow_terminator_normal_offset
ImageFormatData im_format
eCompositorDevice compositor_device
struct RaytraceEEVEE ray_tracing_options
eSceneEEVEE_Flag flag
DNA_DEPRECATED float motion_blur_shutter_deprecated
ListBaseT< ViewLayer > view_layers
struct Editing * ed
struct SceneDisplay display
ColorManagedViewSettings view_settings
DNA_DEPRECATED char use_nodes
DNA_DEPRECATED struct bNodeTree * nodetree
struct DisplaySafeAreas safe_areas
struct RenderData r
struct AudioData audio
struct SceneEEVEE eevee
struct ToolSettings * toolsettings
struct SceneGpencil grease_pencil_settings
ListBaseT< ARegion > regionbase
ListBaseT< SpaceLink > spacedata
DNA_DEPRECATED int automasking_boundary_edges_propagation_steps
eAnimEdit_Context mode
MaskSpaceInfo mask_info
eView3D_Around around
FileSelectParams * params
eGraphEdit_Flag flag
eSpaceImageOverlay_Flag flag
SpaceImageOverlay overlay
eSpaceImage_Mode mode
eSpaceNla_Flag flag
struct BLI_mempool * treestore
eSpaceText_Flags flags
CurvesSculpt * curves_sculpt
DNA_DEPRECATED struct UnifiedPaintSettings unified_paint_settings
struct CurveProfile * custom_bevel_profile_preset
struct ImagePaintSettings imapaint
GpSculptPaint * gp_sculptpaint
eGPencil_Selectmode_types gpencil_selectmode_edit
GpVertexPaint * gp_vertexpaint
struct GP_Sculpt_Settings gp_sculpt
eTool_WeightUser weightuser
eUnifiedPaintSettingsFlags flag
struct CurveMapping * curve_rand_saturation
struct CurveMapping * curve_rand_value
struct CurveMapping * curve_rand_hue
eView3DOverlay_EditFlag edit_flag
eV3DShadingColorType color_type
eView3DShading_Flag flag
View3DShadingUseCompositor use_compositor
eV3DShadingColorType wire_color_type
eV3DShadingBackgroundType background_type
eView3DShading_CavityType cavity_type
View3DOverlay overlay
eView3D_Flag2 flag2
eView3D_GPFlag gp_flag
View3DShading shading
struct ViewLayerEEVEE eevee
ListBaseT< WorkSpaceLayout > layouts
ListBaseT< bToolRef > tools
ListBaseT< struct ScrArea > areabase
struct WorkSpaceInstanceHook * workspace_hook
#define N_(msgid)