Blender V4.5
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_utildefines.h"
27
28#include "DNA_camera_types.h"
30#include "DNA_defaults.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_gpencil_legacy.h"
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_screen.hh"
64#include "BKE_workspace.hh"
65
66#include "BLO_readfile.hh"
67
68#include "BLT_translation.hh"
69
70#include "versioning_common.hh"
71
72/* Make preferences read-only, use `versioning_userdef.cc`. */
73#define U (*((const UserDef *)&U))
74
75static bool blo_is_builtin_template(const char *app_template)
76{
77 /* For all builtin templates shipped with Blender. */
78 return (
79 !app_template ||
80 STR_ELEM(app_template, N_("2D_Animation"), N_("Sculpting"), N_("VFX"), N_("Video_Editing")));
81}
82
84 const char *app_template,
85 const char *workspace_name)
86{
87 /* For all app templates. */
88 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
89 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
90 /* Some toolbars have been saved as initialized,
91 * we don't want them to have odd zoom-level or scrolling set, see: #47047 */
92 if (ELEM(region->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
93 region->v2d.flag &= ~V2D_IS_INIT;
94 }
95 }
96
97 /* Set default folder. */
98 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
99 if (sl->spacetype == SPACE_FILE) {
100 SpaceFile *sfile = (SpaceFile *)sl;
101 if (sfile->params) {
102 const char *dir_default = BKE_appdir_folder_default();
103 if (dir_default) {
104 STRNCPY(sfile->params->dir, dir_default);
105 sfile->params->file[0] = '\0';
106 }
107 }
108 }
109 }
110 }
111
112 /* For builtin templates only. */
114 return;
115 }
116
117 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
118 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
119 /* Remove all stored panels, we want to use defaults
120 * (order, open/closed) as defined by UI code here! */
121 BKE_area_region_panels_free(&region->panels);
122 BLI_freelistN(&region->panels_category_active);
123
124 /* Reset size so it uses consistent defaults from the region types. */
125 region->sizex = 0;
126 region->sizey = 0;
127 }
128
129 if (area->spacetype == SPACE_IMAGE) {
130 if (STREQ(workspace_name, "UV Editing")) {
131 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
132 if (sima->mode == SI_MODE_VIEW) {
133 sima->mode = SI_MODE_UV;
134 }
135 sima->uv_face_opacity = 1.0f;
136 }
137 else if (STR_ELEM(workspace_name, "Texture Paint", "Shading")) {
138 SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
139 sima->uv_face_opacity = 0.0f;
140 }
141 }
142 else if (area->spacetype == SPACE_ACTION) {
143 /* Show markers region, hide channels and collapse summary in timelines. */
144 SpaceAction *saction = static_cast<SpaceAction *>(area->spacedata.first);
145 saction->flag |= SACTION_SHOW_MARKERS;
146 if (saction->mode == SACTCONT_TIMELINE) {
148
149 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
150 if (region->regiontype == RGN_TYPE_CHANNELS) {
151 region->flag |= RGN_FLAG_HIDDEN;
152 }
153 }
154 }
155 else {
156 /* Open properties panel by default. */
157 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
158 if (region->regiontype == RGN_TYPE_UI) {
159 region->flag &= ~RGN_FLAG_HIDDEN;
160 }
161 }
162 }
163 }
164 else if (area->spacetype == SPACE_GRAPH) {
165 SpaceGraph *sipo = static_cast<SpaceGraph *>(area->spacedata.first);
166 sipo->flag |= SIPO_SHOW_MARKERS;
167 }
168 else if (area->spacetype == SPACE_NLA) {
169 SpaceNla *snla = static_cast<SpaceNla *>(area->spacedata.first);
170 snla->flag |= SNLA_SHOW_MARKERS;
171 }
172 else if (area->spacetype == SPACE_SEQ) {
173 SpaceSeq *seq = static_cast<SpaceSeq *>(area->spacedata.first);
184 }
185 else if (area->spacetype == SPACE_TEXT) {
186 /* Show syntax and line numbers in Script workspace text editor. */
187 SpaceText *stext = static_cast<SpaceText *>(area->spacedata.first);
188 stext->showsyntax = true;
189 stext->showlinenrs = true;
190 stext->flags |= ST_FIND_WRAP;
191 }
192 else if (area->spacetype == SPACE_VIEW3D) {
193 View3D *v3d = static_cast<View3D *>(area->spacedata.first);
194 /* Screen space cavity by default for faster performance. */
200 /* Update default Z bias for retopology overlay. */
201 v3d->overlay.retopology_offset = 0.01f;
202 /* Clear this deprecated bit for later reuse. */
204 /* grease pencil settings */
205 v3d->vertex_opacity = 1.0f;
207 /* Remove dither pattern in wireframe mode. */
208 v3d->shading.xray_alpha_wire = 0.0f;
209 v3d->clip_start = 0.01f;
210 /* Skip startups that use the viewport color by default. */
213 }
214 /* Disable Curve Normals. */
217 /* Always enable Grease Pencil vertex color overlay by default. */
219 /* Always use theme color for wireframe by default. */
221
222 /* Level out the 3D Viewport camera rotation, see: #113751. */
223 constexpr float viewports_to_level[][4] = {
224 /* Animation, Modeling, Scripting, Texture Paint, UV Editing. */
225 {0x1.6e7cb8p-1, -0x1.c1747p-2, -0x1.2997dap-2, -0x1.d5d806p-2},
226 /* Layout. */
227 {0x1.6e7cb8p-1, -0x1.c17478p-2, -0x1.2997dcp-2, -0x1.d5d80cp-2},
228 /* Geometry Nodes. */
229 {0x1.6e7cb6p-1, -0x1.c17476p-2, -0x1.2997dep-2, -0x1.d5d80cp-2},
230 };
231
232 constexpr float viewports_to_clear_ofs[][4] = {
233 /* Geometry Nodes. */
234 {0x1.6e7cb6p-1, -0x1.c17476p-2, -0x1.2997dep-2, -0x1.d5d80cp-2},
235 /* Sculpting. */
236 {0x1.885b28p-1, -0x1.2d10cp-1, -0x1.42ae54p-3, -0x1.a486a2p-3},
237 };
238
239 constexpr float unified_viewquat[4] = {
240 0x1.6cbc88p-1, -0x1.c3a5c8p-2, -0x1.26413ep-2, -0x1.db430ap-2};
241
242 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
243 if (region->regiontype == RGN_TYPE_WINDOW) {
244 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
245
246 for (int i = 0; i < ARRAY_SIZE(viewports_to_clear_ofs); i++) {
247 if (equals_v4v4(rv3d->viewquat, viewports_to_clear_ofs[i])) {
248 zero_v3(rv3d->ofs);
249 }
250 }
251
252 for (int i = 0; i < ARRAY_SIZE(viewports_to_level); i++) {
253 if (equals_v4v4(rv3d->viewquat, viewports_to_level[i])) {
254 copy_qt_qt(rv3d->viewquat, unified_viewquat);
255 }
256 }
257 }
258 }
259 }
260 else if (area->spacetype == SPACE_CLIP) {
261 SpaceClip *sclip = static_cast<SpaceClip *>(area->spacedata.first);
263 sclip->mask_info.blend_factor = 0.7f;
265 }
266 }
267
268 /* Show tool-header by default (for most cases at least, hide for others). */
269 const bool hide_image_tool_header = STREQ(workspace_name, "Rendering");
270 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
271 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
272 ListBase *regionbase = (sl == static_cast<SpaceLink *>(area->spacedata.first)) ?
273 &area->regionbase :
274 &sl->regionbase;
275
276 LISTBASE_FOREACH (ARegion *, region, regionbase) {
277 if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
278 if (((sl->spacetype == SPACE_IMAGE) && hide_image_tool_header) ||
279 sl->spacetype == SPACE_SEQ)
280 {
281 region->flag |= RGN_FLAG_HIDDEN;
282 }
283 else {
284 region->flag &= ~(RGN_FLAG_HIDDEN | RGN_FLAG_HIDDEN_BY_USER);
285 }
286 }
287 }
288 }
289 }
290
291 /* 2D animation template. */
292 if (app_template && STREQ(app_template, "2D_Animation")) {
293 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
294 if (area->spacetype == SPACE_ACTION) {
295 SpaceAction *saction = static_cast<SpaceAction *>(area->spacedata.first);
296 /* Enable Sliders. */
297 saction->flag |= SACTION_SLIDERS;
298 }
299 else if (area->spacetype == SPACE_VIEW3D) {
300 View3D *v3d = static_cast<View3D *>(area->spacedata.first);
301 /* Set Material Color by default. */
303 /* Enable Annotations. */
305 }
306 }
307 }
308}
309
311{
312 LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
313 if (layout->screen) {
314 blo_update_defaults_screen(layout->screen, app_template, workspace->id.name + 2);
315 }
316 }
317
319 /* Clear all tools to use default options instead, ignore the tool saved in the file. */
320 while (!BLI_listbase_is_empty(&workspace->tools)) {
321 BKE_workspace_tool_remove(workspace, static_cast<bToolRef *>(workspace->tools.first));
322 }
323
324 /* For 2D animation template. */
325 if (STREQ(workspace->id.name + 2, "Drawing")) {
327 }
328
329 /* For Sculpting template. */
330 if (STREQ(workspace->id.name + 2, "Sculpting")) {
331 LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
332 bScreen *screen = layout->screen;
333 if (screen) {
334 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
335 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
336 if (area->spacetype == SPACE_VIEW3D) {
337 View3D *v3d = static_cast<View3D *>(area->spacedata.first);
339 copy_v3_fl(v3d->shading.single_color, 1.0f);
340 STRNCPY(v3d->shading.matcap, "basic_1");
341 }
342 }
343 }
344 }
345 }
346 }
347 }
348}
349
350static void blo_update_defaults_scene(Main *bmain, Scene *scene)
351{
352 ToolSettings *ts = scene->toolsettings;
353
355
356 scene->r.cfra = 1.0f;
357
358 /* Don't enable compositing nodes. */
359 if (scene->nodetree) {
361 MEM_freeN(scene->nodetree);
362 scene->nodetree = nullptr;
363 scene->use_nodes = false;
364 }
365
366 /* Rename render layers. */
368 bmain, scene, static_cast<ViewLayer *>(scene->view_layers.first), "ViewLayer");
369
370 /* Disable Z pass by default. */
371 LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
372 view_layer->passflag &= ~SCE_PASS_Z;
373 }
374
375 /* Display missing media by default. */
376 if (scene->ed) {
378 }
379
380 /* New EEVEE defaults. */
381 scene->eevee.motion_blur_shutter_deprecated = 0.5f;
382
384 copy_v2_fl2(scene->safe_areas.title, 0.1f, 0.05f);
385 copy_v2_fl2(scene->safe_areas.action, 0.035f, 0.035f);
386
387 /* Default Rotate Increment. */
388 const float default_snap_angle_increment = DEG2RADF(5.0f);
389 ts->snap_angle_increment_2d = default_snap_angle_increment;
390 ts->snap_angle_increment_3d = default_snap_angle_increment;
391 const float default_snap_angle_increment_precision = DEG2RADF(1.0f);
392 ts->snap_angle_increment_2d_precision = default_snap_angle_increment_precision;
393 ts->snap_angle_increment_3d_precision = default_snap_angle_increment_precision;
394
395 /* Be sure `curfalloff` and primitive are initialized. */
396 if (ts->gp_sculpt.cur_falloff == nullptr) {
397 ts->gp_sculpt.cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
398 CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff;
399 BKE_curvemapping_init(gp_falloff_curve);
400 BKE_curvemap_reset(gp_falloff_curve->cm,
401 &gp_falloff_curve->clipr,
404 }
405 if (ts->gp_sculpt.cur_primitive == nullptr) {
406 ts->gp_sculpt.cur_primitive = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
407 CurveMapping *gp_primitive_curve = ts->gp_sculpt.cur_primitive;
408 BKE_curvemapping_init(gp_primitive_curve);
409 BKE_curvemap_reset(gp_primitive_curve->cm,
410 &gp_primitive_curve->clipr,
413 }
414
415 if (ts->sculpt) {
417 }
418
419 /* Correct default startup UVs. */
420 Mesh *mesh = static_cast<Mesh *>(BLI_findstring(&bmain->meshes, "Cube", offsetof(ID, name) + 2));
421 if (mesh && (mesh->corners_num == 24) &&
423 {
424 const float uv_values[24][2] = {
425 {0.625, 0.50}, {0.875, 0.50}, {0.875, 0.75}, {0.625, 0.75}, {0.375, 0.75}, {0.625, 0.75},
426 {0.625, 1.00}, {0.375, 1.00}, {0.375, 0.00}, {0.625, 0.00}, {0.625, 0.25}, {0.375, 0.25},
427 {0.125, 0.50}, {0.375, 0.50}, {0.375, 0.75}, {0.125, 0.75}, {0.375, 0.50}, {0.625, 0.50},
428 {0.625, 0.75}, {0.375, 0.75}, {0.375, 0.25}, {0.625, 0.25}, {0.625, 0.50}, {0.375, 0.50},
429 };
430 float(*mloopuv)[2] = static_cast<float(*)[2]>(
432 memcpy(mloopuv, uv_values, sizeof(float[2]) * mesh->corners_num);
433 }
434
435 /* Make sure that the curve profile is initialized */
436 if (ts->custom_bevel_profile_preset == nullptr) {
438 }
439
440 /* Clear ID properties so Cycles gets defaults. */
441 IDProperty *idprop = IDP_GetProperties(&scene->id);
442 if (idprop) {
443 IDP_ClearProperty(idprop);
444 }
445
446 if (ts->sculpt) {
448 }
449
450 /* Ensure input_samples has a correct default value of 1. */
453 }
454
456 ts->unified_paint_settings.flag = default_ups.flag;
457 copy_v3_v3(ts->unified_paint_settings.rgb, default_ups.rgb);
459
460 if (ts->unified_paint_settings.curve_rand_hue == nullptr) {
462 }
465 }
466 if (ts->unified_paint_settings.curve_rand_value == nullptr) {
468 }
469}
470
472{
473 /* For all app templates. */
474 LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
476 }
477
478 /* Grease pencil materials and paint modes setup. */
479 {
480 /* Rename and fix materials and enable default object lights on. */
481 if (app_template && STREQ(app_template, "2D_Animation")) {
482 Material *ma = nullptr;
483 do_versions_rename_id(bmain, ID_MA, "Black", "Solid Stroke");
484 do_versions_rename_id(bmain, ID_MA, "Red", "Squares Stroke");
485 do_versions_rename_id(bmain, ID_MA, "Grey", "Solid Fill");
486 do_versions_rename_id(bmain, ID_MA, "Black Dots", "Dots Stroke");
487
488 /* Dots Stroke. */
489 ma = static_cast<Material *>(
490 BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2));
491 if (ma == nullptr) {
492 ma = BKE_gpencil_material_add(bmain, "Dots Stroke");
493 }
495
496 /* Squares Stroke. */
497 ma = static_cast<Material *>(
498 BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2));
499 if (ma == nullptr) {
500 ma = BKE_gpencil_material_add(bmain, "Squares Stroke");
501 }
503
504 /* Change Solid Stroke settings. */
505 ma = static_cast<Material *>(
506 BLI_findstring(&bmain->materials, "Solid Stroke", offsetof(ID, name) + 2));
507 if (ma != nullptr) {
508 ma->gp_style->mix_rgba[3] = 1.0f;
509 ma->gp_style->texture_offset[0] = -0.5f;
510 ma->gp_style->mix_factor = 0.5f;
511 }
512
513 /* Change Solid Fill settings. */
514 ma = static_cast<Material *>(
515 BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2));
516 if (ma != nullptr) {
518 ma->gp_style->mix_rgba[3] = 1.0f;
519 ma->gp_style->texture_offset[0] = -0.5f;
520 ma->gp_style->mix_factor = 0.5f;
521 }
522
523 Object *ob = static_cast<Object *>(
524 BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2));
525 if (ob && ob->type == OB_GPENCIL_LEGACY) {
527 }
528 }
529
530 /* Add library weak references to avoid duplicating materials from essentials. */
531 const std::optional<std::string> assets_path = BKE_appdir_folder_id(BLENDER_SYSTEM_DATAFILES,
532 "assets/brushes");
533 if (assets_path.has_value()) {
534 const std::string assets_blend_path = *assets_path + "/essentials_brushes-gp_draw.blend";
535 LISTBASE_FOREACH (Material *, material, &bmain->materials) {
537 &material->id, assets_blend_path.c_str(), material->id.name);
538 }
539 }
540
541 /* Reset grease pencil paint modes. */
542 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
543 ToolSettings *ts = scene->toolsettings;
544
545 /* Ensure new Paint modes. */
549
550 /* Enable cursor. */
551 if (ts->gp_paint) {
553 }
554
555 /* Ensure Palette by default. */
556 if (ts->gp_paint) {
557 BKE_gpencil_palette_ensure(bmain, scene);
558 }
559 }
560 }
561
562 /* For builtin templates only. */
564 return;
565 }
566
567 /* Work-spaces. */
568 LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) {
569 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
570 LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
572 win->workspace_hook, workspace);
573 /* Name all screens by their workspaces (avoids 'Default.###' names). */
574 /* Default only has one window. */
575 if (layout->screen) {
576 bScreen *screen = layout->screen;
577 if (!STREQ(screen->id.name + 2, workspace->id.name + 2)) {
578 BKE_libblock_rename(*bmain, screen->id, workspace->id.name + 2);
579 }
580 }
581
582 /* For some reason we have unused screens, needed until re-saving.
583 * Clear unused layouts because they're visible in the outliner & Python API. */
584 LISTBASE_FOREACH_MUTABLE (WorkSpaceLayout *, layout_iter, &workspace->layouts) {
585 if (layout != layout_iter) {
586 BKE_workspace_layout_remove(bmain, workspace, layout_iter);
587 }
588 }
589 }
590 }
591 }
592
593 /* Scenes */
594 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
595 blo_update_defaults_scene(bmain, scene);
596
597 if (app_template && STR_ELEM(app_template, "Video_Editing", "2D_Animation")) {
598 /* Filmic is too slow, use standard until it is optimized. */
599 STRNCPY(scene->view_settings.view_transform, "Standard");
600 STRNCPY(scene->view_settings.look, "None");
601 }
602 else {
603 /* Default to AgX view transform. */
604 STRNCPY(scene->view_settings.view_transform, "AgX");
605 }
606
607 if (app_template && STREQ(app_template, "Video_Editing")) {
608 /* Pass: no extra tweaks needed. Keep the view settings configured above, and rely on the
609 * default state of enabled AV sync. */
610 }
611 else {
612 /* AV Sync break physics sim caching, disable until that is fixed. */
613 scene->audio.flag &= ~AUDIO_SYNC;
614 scene->flag &= ~SCE_FRAME_DROP;
615 }
616
617 /* Change default selection mode for Grease Pencil. */
618 if (app_template && STREQ(app_template, "2D_Animation")) {
619 ToolSettings *ts = scene->toolsettings;
621 }
622 }
623
624 /* Objects */
625 do_versions_rename_id(bmain, ID_OB, "Lamp", "Light");
626 do_versions_rename_id(bmain, ID_LA, "Lamp", "Light");
627
628 if (app_template && STREQ(app_template, "2D_Animation")) {
629 LISTBASE_FOREACH (Object *, object, &bmain->objects) {
630 if (object->type == OB_GPENCIL_LEGACY) {
631 /* Set grease pencil object in drawing mode */
632 bGPdata *gpd = (bGPdata *)object->data;
633 object->mode = OB_MODE_PAINT_GREASE_PENCIL;
635 break;
636 }
637 }
638 }
639
640 LISTBASE_FOREACH (Object *, object, &bmain->objects) {
642 /* Set default for shadow terminator bias. */
643 object->shadow_terminator_normal_offset = dob->shadow_terminator_normal_offset;
644 object->shadow_terminator_geometry_offset = dob->shadow_terminator_geometry_offset;
645 object->shadow_terminator_shading_offset = dob->shadow_terminator_shading_offset;
646 }
647
648 LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) {
649 /* Match default for new meshes. */
650 mesh->smoothresh_legacy = DEG2RADF(30);
651 /* Match voxel remesher options for all existing meshes in templates. */
653
654 /* For Sculpting template. */
655 if (app_template && STREQ(app_template, "Sculpting")) {
656 mesh->remesh_voxel_size = 0.035f;
657 blender::bke::mesh_smooth_set(*mesh, false);
658 }
659 else {
660 /* Remove sculpt-mask data in default mesh objects for all non-sculpt templates. */
661 CustomData_free_layers(&mesh->vert_data, CD_PAINT_MASK);
662 CustomData_free_layers(&mesh->corner_data, CD_GRID_PAINT_MASK);
663 }
664 mesh->attributes_for_write().remove(".sculpt_face_set");
665 }
666
667 LISTBASE_FOREACH (Camera *, camera, &bmain->cameras) {
668 /* Initialize to a useful value. */
669 camera->dof.focus_distance = 10.0f;
670 camera->dof.aperture_fstop = 2.8f;
671 }
672
673 LISTBASE_FOREACH (Light *, light, &bmain->lights) {
674 /* Fix lights defaults. */
675 light->clipsta = 0.05f;
676 light->att_dist = 40.0f;
677 }
678
679 /* Materials */
680 LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
681 /* Update default material to be a bit more rough. */
682 ma->roughness = 0.5f;
683 /* Enable transparent shadows. */
684 ma->blend_flag |= MA_BL_TRANSPARENT_SHADOW;
685
686 if (ma->nodetree) {
687 for (bNode *node : ma->nodetree->all_nodes()) {
688 if (node->type_legacy == SH_NODE_BSDF_PRINCIPLED) {
690 *node, SOCK_IN, "Roughness");
691 *version_cycles_node_socket_float_value(roughness_socket) = 0.5f;
692 bNodeSocket *emission = blender::bke::node_find_socket(*node, SOCK_IN, "Emission Color");
694 bNodeSocket *emission_strength = blender::bke::node_find_socket(
695 *node, SOCK_IN, "Emission Strength");
696 *version_cycles_node_socket_float_value(emission_strength) = 0.0f;
697
698 node->custom1 = SHD_GLOSSY_MULTI_GGX;
699 node->custom2 = SHD_SUBSURFACE_RANDOM_WALK;
700
701 node->location[0] = -200.0f;
702 node->location[1] = 100.0f;
703 BKE_ntree_update_tag_node_property(ma->nodetree, node);
704 }
705 else if (node->type_legacy == SH_NODE_SUBSURFACE_SCATTERING) {
706 node->custom1 = SHD_SUBSURFACE_RANDOM_WALK;
707 BKE_ntree_update_tag_node_property(ma->nodetree, node);
708 }
709 else if (node->type_legacy == SH_NODE_OUTPUT_MATERIAL) {
710 node->location[0] = 200.0f;
711 node->location[1] = 100.0f;
712 }
713 }
714 }
715 }
716
717 /* Brushes */
718 {
719 /* Remove default brushes replaced by assets. Also remove outliner `treestore` that may point
720 * to brushes. Normally the treestore is updated properly but it doesn't seem to update during
721 * versioning code. It's not helpful anyway. */
722 LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
723 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
724 LISTBASE_FOREACH (SpaceLink *, space_link, &area->spacedata) {
725 if (space_link->spacetype == SPACE_OUTLINER) {
726 SpaceOutliner *space_outliner = reinterpret_cast<SpaceOutliner *>(space_link);
727 if (space_outliner->treestore) {
728 BLI_mempool_destroy(space_outliner->treestore);
729 space_outliner->treestore = nullptr;
730 }
731 }
732 }
733 }
734 }
735 LISTBASE_FOREACH_MUTABLE (Brush *, brush, &bmain->brushes) {
736 BKE_id_delete(bmain, brush);
737 }
738 }
739
740 {
741 LISTBASE_FOREACH (Light *, light, &bmain->lights) {
742 light->shadow_maximum_resolution = 0.001f;
743 light->transmission_fac = 1.0f;
744 SET_FLAG_FROM_TEST(light->mode, false, LA_SHAD_RES_ABSOLUTE);
745 }
746 }
747
748 {
749 LISTBASE_FOREACH (World *, world, &bmain->worlds) {
750 SET_FLAG_FROM_TEST(world->flag, true, WO_USE_SUN_SHADOW);
751 if (world->nodetree) {
752 for (bNode *node : world->nodetree->all_nodes()) {
753 if (node->type_legacy == SH_NODE_OUTPUT_WORLD) {
754 node->location[0] = 200.0f;
755 node->location[1] = 100.0f;
756 }
757 else if (node->type_legacy == SH_NODE_BACKGROUND) {
758 node->location[0] = -200.0f;
759 node->location[1] = 100.0f;
760 }
761 }
762 }
763 }
764 }
765}
@ BLENDER_SYSTEM_DATAFILES
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:717
void BKE_curvemapping_init(CurveMapping *cumap)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:89
void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, int slope)
@ CURVEMAP_SLOPE_POSITIVE
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:1249
IDProperty * IDP_GetProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:887
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:2350
void BKE_main_library_weak_reference_add(ID *local_id, const char *library_filepath, const char *library_id_name)
Definition main.cc:793
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:140
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:317
void BKE_area_region_panels_free(ListBase *panels)
Definition screen.cc:579
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:397
WorkSpaceLayout * BKE_workspace_active_layout_for_workspace_get(const WorkSpaceInstanceHook *hook, const WorkSpace *workspace) GETTER_ATTRS
Definition workspace.cc:590
#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:656
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
#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
@ GP_MATERIAL_STROKE_SHOW
@ GP_MATERIAL_MODE_SQUARE
@ GP_MATERIAL_MODE_DOT
@ MA_BL_TRANSPARENT_SHADOW
@ ME_REMESH_REPROJECT_ATTRIBUTES
@ ME_REMESH_REPROJECT_VOLUME
@ SHD_SUBSURFACE_RANDOM_WALK
@ SOCK_IN
@ SHD_GLOSSY_MULTI_GGX
@ OB_MODE_PAINT_GREASE_PENCIL
Object is a sort of wrapper for general info.
@ OB_GPENCIL_LEGACY
@ OB_USE_GPENCIL_LIGHTS
@ GP_SELECTMODE_STROKE
@ SCE_FRAME_DROP
@ PAINT_SHOW_BRUSH
@ AUDIO_SYNC
@ SCE_PASS_Z
@ 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_EDIT_SHOW_MISSING_MEDIA
@ SEQ_RENDER_SIZE_PROXY_100
@ SPACE_TEXT
@ SPACE_CLIP
@ SPACE_ACTION
@ SPACE_OUTLINER
@ SPACE_FILE
@ 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
@ 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
@ V2D_IS_INIT
@ V3D_SHADING_BACKGROUND_VIEWPORT
@ V3D_SHADING_MATERIAL_COLOR
@ V3D_SHADING_SINGLE_COLOR
@ V3D_GP_SHOW_EDIT_LINES
@ V3D_SHADING_CAVITY_CURVATURE
@ V3D_SHOW_ANNOTATION
@ V3D_OVERLAY_EDIT_CU_NORMALS
@ V3D_OVERLAY_EDIT_EDGES_DEPRECATED
@ V3D_SHADING_SPECULAR_HIGHLIGHT
@ V3D_SHADING_CAVITY
@ V3D_AROUND_CENTER_MEDIAN
@ WO_USE_SUN_SHADOW
Read Guarded memory(de)allocation.
#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:2864
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:4724
VecBase< float, 3 > float3
const char * RE_engine_id_BLENDER_EEVEE_NEXT
Definition scene.cc:1626
CurveMap cm[4]
int show_missing_media_flag
struct CurveMapping * cur_primitive
struct CurveMapping * cur_falloff
Definition DNA_ID.h:404
char name[66]
Definition DNA_ID.h:415
void * first
ListBase brushes
Definition BKE_main.hh:271
ListBase scenes
Definition BKE_main.hh:245
ListBase wm
Definition BKE_main.hh:276
ListBase meshes
Definition BKE_main.hh:248
ListBase lights
Definition BKE_main.hh:255
ListBase materials
Definition BKE_main.hh:251
ListBase cameras
Definition BKE_main.hh:256
ListBase worlds
Definition BKE_main.hh:260
ListBase screens
Definition BKE_main.hh:261
ListBase workspaces
Definition BKE_main.hh:284
ListBase objects
Definition BKE_main.hh:247
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
char engine[32]
float light_direction[3]
struct bNodeTree * nodetree
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
short render_size
struct SequencerPreviewOverlay preview_overlay
struct CurveProfile * custom_bevel_profile_preset
float snap_angle_increment_3d_precision
float snap_angle_increment_2d_precision
struct UnifiedPaintSettings unified_paint_settings
float snap_angle_increment_3d
float snap_angle_increment_2d
struct GP_Sculpt_Settings gp_sculpt
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
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_screen(bScreen *screen, const char *app_template, const char *workspace_name)
static void blo_update_defaults_scene(Main *bmain, Scene *scene)
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:1183