Merge branch 'master' into blender2.8
[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_brush_types.h"
34 #include "DNA_freestyle_types.h"
35 #include "DNA_linestyle_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_space_types.h"
39 #include "DNA_userdef_types.h"
40 #include "DNA_mesh_types.h"
41 #include "DNA_material_types.h"
42 #include "DNA_object_types.h"
43 #include "DNA_workspace_types.h"
44
45 #include "BKE_brush.h"
46 #include "BKE_library.h"
47 #include "BKE_main.h"
48 #include "BKE_workspace.h"
49
50 #include "BLO_readfile.h"
51
52
53 /**
54  * Override values in in-memory startup.blend, avoids resaving for small changes.
55  */
56 void BLO_update_defaults_userpref_blend(void)
57 {
58         /* defaults from T37518 */
59
60         U.uiflag |= USER_ZBUF_CURSOR;
61         U.uiflag |= USER_QUIT_PROMPT;
62         U.uiflag |= USER_CONTINUOUS_MOUSE;
63
64         /* See T45301 */
65         U.uiflag |= USER_LOCK_CURSOR_ADJUST;
66
67         U.versions = 1;
68         U.savetime = 2;
69
70         /* default from T47064 */
71         U.audiorate = 48000;
72
73         /* Keep this a very small, non-zero number so zero-alpha doesn't mask out objects behind it.
74          * but take care since some hardware has driver bugs here (T46962).
75          * Further hardware workarounds should be made in gpu_extensions.c */
76         U.glalphaclip = (1.0f / 255);
77
78         /* default so DPI is detected automatically */
79         U.dpi = 0;
80         U.ui_scale = 1.0f;
81
82 #ifdef WITH_PYTHON_SECURITY
83         /* use alternative setting for security nuts
84          * otherwise we'd need to patch the binary blob - startup.blend.c */
85         U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
86 #else
87         U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
88 #endif
89 }
90
91 /**
92  * New workspace design: Remove all screens/workspaces except of "Default" one and rename the workspace to "General".
93  * For compatibility, a new workspace has been created for each screen of old files,
94  * we only want one workspace and one screen in the default startup file however.
95  */
96 static void update_defaults_startup_workspaces(Main *bmain)
97 {
98         WorkSpace *workspace_default = NULL;
99
100         for (WorkSpace *workspace = bmain->workspaces.first, *workspace_next; workspace; workspace = workspace_next) {
101                 workspace_next = workspace->id.next;
102
103                 if (STREQ(workspace->id.name + 2, "Default")) {
104                         /* don't rename within iterator, renaming causes listbase to be re-sorted */
105                         workspace_default = workspace;
106                 }
107                 else {
108                         BKE_workspace_remove(bmain, workspace);
109                 }
110         }
111
112         /* rename "Default" workspace to "General" */
113         BKE_libblock_rename(bmain, (ID *)workspace_default, "General");
114         BLI_assert(BLI_listbase_count(BKE_workspace_layouts_get(workspace_default)) == 1);
115 }
116
117 /**
118  * Update defaults in startup.blend, without having to save and embed the file.
119  * This function can be emptied each time the startup.blend is updated. */
120 void BLO_update_defaults_startup_blend(Main *bmain)
121 {
122         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
123                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
124
125                 scene->r.im_format.planes = R_IMF_PLANES_RGBA;
126                 scene->r.im_format.compress = 15;
127
128                 for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
129                         srl->freestyleConfig.sphere_radius = 0.1f;
130                         srl->pass_alpha_threshold = 0.5f;
131                 }
132
133                 if (scene->toolsettings) {
134                         ToolSettings *ts = scene->toolsettings;
135
136                         if (ts->sculpt) {
137                                 Sculpt *sculpt = ts->sculpt;
138                                 sculpt->paint.symmetry_flags |= PAINT_SYMM_X;
139                                 sculpt->flags |= SCULPT_DYNTOPO_COLLAPSE;
140                                 sculpt->detail_size = 12;
141                         }
142                         
143                         if (ts->gp_sculpt.brush[0].size == 0) {
144                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
145                                 GP_EditBrush_Data *brush;
146                                 
147                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
148                                 brush->size = 25;
149                                 brush->strength = 0.3f;
150                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
151                                 
152                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
153                                 brush->size = 25;
154                                 brush->strength = 0.5f;
155                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
156                                 
157                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
158                                 brush->size = 25;
159                                 brush->strength = 0.5f;
160                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
161
162                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
163                                 brush->size = 50;
164                                 brush->strength = 0.3f;
165                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
166                                 
167                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
168                                 brush->size = 25;
169                                 brush->strength = 0.3f;
170                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
171                                 
172                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
173                                 brush->size = 50;
174                                 brush->strength = 0.3f; // XXX?
175                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
176                                 
177                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
178                                 brush->size = 50;
179                                 brush->strength = 0.5f; // XXX?
180                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
181                                 
182                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
183                                 brush->size = 25;
184                                 brush->strength = 0.5f;
185                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
186                         }
187                         
188                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
189                         ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
190                         ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
191                         ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
192
193                         ParticleEditSettings *pset = &ts->particle;
194                         for (int a = 0; a < PE_TOT_BRUSH; a++) {
195                                 pset->brush[a].strength = 0.5f;
196                                 pset->brush[a].count = 10;
197                         }
198                         pset->brush[PE_BRUSH_CUT].strength = 1.0f;
199                 }
200
201                 scene->gm.lodflag |= SCE_LOD_USE_HYST;
202                 scene->gm.scehysteresis = 10;
203
204                 scene->r.ffcodecdata.audio_mixrate = 48000;
205         }
206
207         for (FreestyleLineStyle *linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
208                 linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE;
209                 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
210                 linestyle->integration_type = LS_INTEGRATION_MEAN;
211                 linestyle->texstep = 1.0;
212                 linestyle->chain_count = 10;
213         }
214
215         update_defaults_startup_workspaces(bmain);
216
217         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
218                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
219                         for (SpaceLink *space_link = area->spacedata.first; space_link; space_link = space_link->next) {
220                                 if (space_link->spacetype == SPACE_CLIP) {
221                                         SpaceClip *space_clip = (SpaceClip *) space_link;
222                                         space_clip->flag &= ~SC_MANUAL_CALIBRATION;
223                                 }
224                         }
225
226                         for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
227                                 /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
228                                 BLI_freelistN(&ar->panels);
229
230                                 /* some toolbars have been saved as initialized,
231                                  * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
232                                 if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
233                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
234                                 }
235                         }
236                 }
237         }
238
239         for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
240                 me->smoothresh = DEG2RADF(180.0f);
241                 me->flag &= ~ME_TWOSIDED;
242         }
243
244         for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
245                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
246                 mat->line_col[3] = 1.0f;
247         }
248
249         {
250                 Object *ob;
251
252                 ob = (Object *)BKE_libblock_find_name_ex(bmain, ID_OB, "Camera");
253                 if (ob) {
254                         ob->rot[1] = 0.0f;
255                 }
256         }
257
258         {
259                 Brush *br;
260
261                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
262                 if (!br) {
263                         br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
264                         br->imagepaint_tool = PAINT_TOOL_FILL;
265                         br->ob_mode = OB_MODE_TEXTURE_PAINT;
266                 }
267
268                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
269                 if (br) {
270                         br->imagepaint_tool = PAINT_TOOL_MASK;
271                         br->ob_mode |= OB_MODE_TEXTURE_PAINT;
272                 }
273
274                 /* remove polish brush (flatten/contrast does the same) */
275                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
276                 if (br) {
277                         BKE_libblock_delete(bmain, br);
278                 }
279
280                 /* remove brush brush (huh?) from some modes (draw brushes do the same) */
281                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Brush");
282                 if (br) {
283                         BKE_libblock_delete(bmain, br);
284                 }
285
286                 /* remove draw brush from texpaint (draw brushes do the same) */
287                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Draw");
288                 if (br) {
289                         br->ob_mode &= ~OB_MODE_TEXTURE_PAINT;
290                 }
291
292                 /* rename twist brush to rotate brush to match rotate tool */
293                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Twist");
294                 if (br) {
295                         BKE_libblock_rename(bmain, &br->id, "Rotate");
296                 }
297
298                 /* use original normal for grab brush (otherwise flickers with normal weighting). */
299                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Grab");
300                 if (br) {
301                         br->flag |= BRUSH_ORIGINAL_NORMAL;
302                 }
303
304                 /* increase strength, better for smoothing method */
305                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Blur");
306                 if (br) {
307                         br->alpha = 1.0f;
308                 }
309
310                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Flatten/Contrast");
311                 if (br) {
312                         br->flag |= BRUSH_ACCUMULATE;
313                 }
314         }
315 }
316