Change startup defaults
[blender.git] / source / blender / blenloader / intern / versioning_defaults.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  *
22  */
23
24 /** \file blender/blenloader/intern/versioning_defaults.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29 #include "BLI_listbase.h"
30 #include "BLI_math.h"
31 #include "BLI_string.h"
32
33 #include "DNA_camera_types.h"
34 #include "DNA_brush_types.h"
35 #include "DNA_freestyle_types.h"
36 #include "DNA_lamp_types.h"
37 #include "DNA_linestyle_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_userdef_types.h"
42 #include "DNA_mesh_types.h"
43 #include "DNA_material_types.h"
44 #include "DNA_object_types.h"
45 #include "DNA_workspace_types.h"
46
47 #include "BKE_brush.h"
48 #include "BKE_library.h"
49 #include "BKE_main.h"
50 #include "BKE_scene.h"
51 #include "BKE_workspace.h"
52
53 #include "BLO_readfile.h"
54
55
56 /**
57  * Override values in in-memory startup.blend, avoids resaving for small changes.
58  */
59 void BLO_update_defaults_userpref_blend(void)
60 {
61         /* Defaults from T37518. */
62         U.uiflag |= USER_DEPTH_CURSOR;
63         U.uiflag |= USER_QUIT_PROMPT;
64         U.uiflag |= USER_CONTINUOUS_MOUSE;
65
66         /* See T45301 */
67         U.uiflag |= USER_LOCK_CURSOR_ADJUST;
68
69         /* Default from T47064. */
70         U.audiorate = 48000;
71
72         /* Defaults from T54943 (phase 1). */
73         U.flag &= ~USER_TOOLTIPS_PYTHON;
74         U.uiflag |= USER_AUTOPERSP;
75         U.manipulator_flag |= USER_MANIPULATOR_DRAW_NAVIGATE;
76         U.uiflag2 |= USER_REGION_OVERLAP;
77
78         U.versions = 1;
79         U.savetime = 2;
80
81         /* Keep this a very small, non-zero number so zero-alpha doesn't mask out objects behind it.
82          * but take care since some hardware has driver bugs here (T46962).
83          * Further hardware workarounds should be made in gpu_extensions.c */
84         U.glalphaclip = (1.0f / 255);
85
86         /* default so DPI is detected automatically */
87         U.dpi = 0;
88         U.ui_scale = 1.0f;
89
90 #ifdef WITH_PYTHON_SECURITY
91         /* use alternative setting for security nuts
92          * otherwise we'd need to patch the binary blob - startup.blend.c */
93         U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
94 #else
95         U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
96 #endif
97 }
98
99 /**
100  * New workspace design: Remove all screens/workspaces except of "Default" one and rename the workspace to "General".
101  * For compatibility, a new workspace has been created for each screen of old files,
102  * we only want one workspace and one screen in the default startup file however.
103  */
104 static void update_defaults_startup_workspaces(Main *bmain)
105 {
106         WorkSpace *workspace_default = NULL;
107
108         for (WorkSpace *workspace = bmain->workspaces.first, *workspace_next; workspace; workspace = workspace_next) {
109                 workspace_next = workspace->id.next;
110
111                 if (STREQ(workspace->id.name + 2, "Default")) {
112                         /* don't rename within iterator, renaming causes listbase to be re-sorted */
113                         workspace_default = workspace;
114                 }
115                 else {
116                         BKE_workspace_remove(bmain, workspace);
117                 }
118         }
119
120         /* rename "Default" workspace to "General" */
121         BKE_libblock_rename(bmain, (ID *)workspace_default, "General");
122         BLI_assert(BLI_listbase_count(BKE_workspace_layouts_get(workspace_default)) == 1);
123 }
124
125 /**
126  * Update defaults in startup.blend, without having to save and embed the file.
127  * This function can be emptied each time the startup.blend is updated. */
128 void BLO_update_defaults_startup_blend(Main *bmain)
129 {
130         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
131                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
132
133                 scene->r.im_format.planes = R_IMF_PLANES_RGBA;
134                 scene->r.im_format.compress = 15;
135
136                 for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
137                         view_layer->freestyle_config.sphere_radius = 0.1f;
138                         view_layer->pass_alpha_threshold = 0.5f;
139                 }
140
141                 if (scene->toolsettings) {
142                         ToolSettings *ts = scene->toolsettings;
143
144                         if (ts->sculpt) {
145                                 Sculpt *sculpt = ts->sculpt;
146                                 sculpt->paint.symmetry_flags |= PAINT_SYMM_X;
147                                 sculpt->flags |= SCULPT_DYNTOPO_COLLAPSE;
148                                 sculpt->detail_size = 12;
149                         }
150                         
151                         if (ts->vpaint) {
152                                 VPaint *vp = ts->vpaint;
153                                 vp->radial_symm[0] = vp->radial_symm[1] = vp->radial_symm[2] = 1;
154                         }
155
156                         if (ts->wpaint) {
157                                 VPaint *wp = ts->wpaint;
158                                 wp->radial_symm[0] = wp->radial_symm[1] = wp->radial_symm[2] = 1;
159                         }
160
161                         if (ts->gp_sculpt.brush[0].size == 0) {
162                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
163                                 GP_EditBrush_Data *brush;
164                                 
165                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
166                                 brush->size = 25;
167                                 brush->strength = 0.3f;
168                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
169                                 
170                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
171                                 brush->size = 25;
172                                 brush->strength = 0.5f;
173                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
174                                 
175                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
176                                 brush->size = 25;
177                                 brush->strength = 0.5f;
178                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
179
180                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
181                                 brush->size = 50;
182                                 brush->strength = 0.3f;
183                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
184                                 
185                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
186                                 brush->size = 25;
187                                 brush->strength = 0.3f;
188                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
189                                 
190                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
191                                 brush->size = 50;
192                                 brush->strength = 0.3f; // XXX?
193                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
194                                 
195                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
196                                 brush->size = 50;
197                                 brush->strength = 0.5f; // XXX?
198                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
199                                 
200                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
201                                 brush->size = 25;
202                                 brush->strength = 0.5f;
203                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
204                         }
205                         
206                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
207                         ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
208                         ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
209                         ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
210
211                         ParticleEditSettings *pset = &ts->particle;
212                         for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) {
213                                 pset->brush[a].strength = 0.5f;
214                                 pset->brush[a].count = 10;
215                         }
216                         pset->brush[PE_BRUSH_CUT].strength = 1.0f;
217                 }
218
219                 scene->r.ffcodecdata.audio_mixrate = 48000;
220                 
221                 /* set av sync by default */
222                 printf("setting new default audio\n");
223                 scene->audio.flag |= AUDIO_SYNC;
224                 scene->flag &= ~SCE_FRAME_DROP;
225         }
226
227         for (FreestyleLineStyle *linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
228                 linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE;
229                 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
230                 linestyle->integration_type = LS_INTEGRATION_MEAN;
231                 linestyle->texstep = 1.0;
232                 linestyle->chain_count = 10;
233         }
234
235         update_defaults_startup_workspaces(bmain);
236
237         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
238                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
239                         for (SpaceLink *space_link = area->spacedata.first; space_link; space_link = space_link->next) {
240                                 if (space_link->spacetype == SPACE_CLIP) {
241                                         SpaceClip *space_clip = (SpaceClip *) space_link;
242                                         space_clip->flag &= ~SC_MANUAL_CALIBRATION;
243                                 }
244                         }
245
246                         for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
247                                 /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
248                                 BLI_freelistN(&ar->panels);
249
250                                 /* some toolbars have been saved as initialized,
251                                  * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
252                                 if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
253                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
254                                 }
255                         }
256                 }
257         }
258
259         for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
260                 me->smoothresh = DEG2RADF(180.0f);
261                 me->flag &= ~ME_TWOSIDED;
262         }
263
264         for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
265                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
266                 mat->line_col[3] = 1.0f;
267         }
268
269         {
270                 Object *ob;
271
272                 ob = (Object *)BKE_libblock_find_name_ex(bmain, ID_OB, "Camera");
273                 if (ob) {
274                         ob->rot[1] = 0.0f;
275                 }
276         }
277
278         {
279                 Brush *br;
280
281                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
282                 if (!br) {
283                         br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
284                         id_us_min(&br->id);  /* fake user only */
285                         br->imagepaint_tool = PAINT_TOOL_FILL;
286                         br->ob_mode = OB_MODE_TEXTURE_PAINT;
287                 }
288
289                 /* Vertex/Weight Paint */
290                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Average");
291                 if (!br) {
292                         br = BKE_brush_add(bmain, "Average", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
293                         id_us_min(&br->id);  /* fake user only */
294                         br->vertexpaint_tool = PAINT_BLEND_AVERAGE;
295                         br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
296                 }
297                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Smear");
298                 if (!br) {
299                         br = BKE_brush_add(bmain, "Smear", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
300                         id_us_min(&br->id);  /* fake user only */
301                         br->vertexpaint_tool = PAINT_BLEND_SMEAR;
302                         br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
303                 }
304
305                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
306                 if (br) {
307                         br->imagepaint_tool = PAINT_TOOL_MASK;
308                         br->ob_mode |= OB_MODE_TEXTURE_PAINT;
309                 }
310
311                 /* remove polish brush (flatten/contrast does the same) */
312                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
313                 if (br) {
314                         BKE_libblock_delete(bmain, br);
315                 }
316
317                 /* remove brush brush (huh?) from some modes (draw brushes do the same) */
318                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Brush");
319                 if (br) {
320                         BKE_libblock_delete(bmain, br);
321                 }
322
323                 /* remove draw brush from texpaint (draw brushes do the same) */
324                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Draw");
325                 if (br) {
326                         br->ob_mode &= ~OB_MODE_TEXTURE_PAINT;
327                 }
328
329                 /* rename twist brush to rotate brush to match rotate tool */
330                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Twist");
331                 if (br) {
332                         BKE_libblock_rename(bmain, &br->id, "Rotate");
333                 }
334
335                 /* use original normal for grab brush (otherwise flickers with normal weighting). */
336                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Grab");
337                 if (br) {
338                         br->flag |= BRUSH_ORIGINAL_NORMAL;
339                 }
340
341                 /* increase strength, better for smoothing method */
342                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Blur");
343                 if (br) {
344                         br->alpha = 1.0f;
345                 }
346
347                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Flatten/Contrast");
348                 if (br) {
349                         br->flag |= BRUSH_ACCUMULATE;
350                 }
351         }
352
353         /* Defaults from T54943. */
354         {
355                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
356                         scene->r.displaymode = R_OUTPUT_WINDOW;
357                         scene->r.size = 100;
358                         scene->unit.system = USER_UNIT_METRIC;
359                         STRNCPY(scene->view_settings.view_transform, "Filmic");
360                 }
361
362                 for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
363                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
364                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
365                                         switch (sl->spacetype) {
366                                                 case SPACE_VIEW3D:
367                                                 {
368                                                         View3D *v3d = (View3D *)sl;
369                                                         v3d->lens = 50;
370                                                         break;
371                                                 }
372                                                 case SPACE_BUTS:
373                                                 {
374                                                         SpaceButs *sbuts = (SpaceButs *)sl;
375                                                         sbuts->mainb = sbuts->mainbuser = BCONTEXT_OBJECT;
376                                                         break;
377                                                 }
378                                         }
379
380                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
381                                         for (ARegion *ar = lb->first; ar; ar = ar->next) {
382                                                 if (ar->regiontype == RGN_TYPE_HEADER) {
383                                                         if (sl->spacetype != SPACE_ACTION) {
384                                                                 ar->alignment = RGN_ALIGN_TOP;
385                                                         }
386                                                 }
387                                         }
388                                 }
389                         }
390                 }
391
392                 for (Camera *ca = bmain->camera.first; ca; ca = ca->id.next) {
393                         ca->lens = 50;
394                         ca->sensor_x = DEFAULT_SENSOR_WIDTH;
395                         ca->sensor_y = DEFAULT_SENSOR_HEIGHT;
396                 }
397
398                 for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
399                         la->energy = 10.0;
400                 }
401         }
402 }
403