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->vpaint) {
144                                 VPaint *vp = ts->vpaint;
145                                 vp->radial_symm[0] = vp->radial_symm[1] = vp->radial_symm[2] = 1;
146                         }
147
148                         if (ts->wpaint) {
149                                 VPaint *wp = ts->wpaint;
150                                 wp->radial_symm[0] = wp->radial_symm[1] = wp->radial_symm[2] = 1;
151                         }
152
153                         if (ts->gp_sculpt.brush[0].size == 0) {
154                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
155                                 GP_EditBrush_Data *brush;
156                                 
157                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
158                                 brush->size = 25;
159                                 brush->strength = 0.3f;
160                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
161                                 
162                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
163                                 brush->size = 25;
164                                 brush->strength = 0.5f;
165                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
166                                 
167                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
168                                 brush->size = 25;
169                                 brush->strength = 0.5f;
170                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
171
172                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
173                                 brush->size = 50;
174                                 brush->strength = 0.3f;
175                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
176                                 
177                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
178                                 brush->size = 25;
179                                 brush->strength = 0.3f;
180                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
181                                 
182                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
183                                 brush->size = 50;
184                                 brush->strength = 0.3f; // XXX?
185                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
186                                 
187                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
188                                 brush->size = 50;
189                                 brush->strength = 0.5f; // XXX?
190                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
191                                 
192                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
193                                 brush->size = 25;
194                                 brush->strength = 0.5f;
195                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
196                         }
197                         
198                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
199                         ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
200                         ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
201                         ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
202
203                         ParticleEditSettings *pset = &ts->particle;
204                         for (int a = 0; a < PE_TOT_BRUSH; a++) {
205                                 pset->brush[a].strength = 0.5f;
206                                 pset->brush[a].count = 10;
207                         }
208                         pset->brush[PE_BRUSH_CUT].strength = 1.0f;
209                 }
210
211                 scene->gm.lodflag |= SCE_LOD_USE_HYST;
212                 scene->gm.scehysteresis = 10;
213
214                 scene->r.ffcodecdata.audio_mixrate = 48000;
215         }
216
217         for (FreestyleLineStyle *linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
218                 linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE;
219                 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
220                 linestyle->integration_type = LS_INTEGRATION_MEAN;
221                 linestyle->texstep = 1.0;
222                 linestyle->chain_count = 10;
223         }
224
225         update_defaults_startup_workspaces(bmain);
226
227         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
228                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
229                         for (SpaceLink *space_link = area->spacedata.first; space_link; space_link = space_link->next) {
230                                 if (space_link->spacetype == SPACE_CLIP) {
231                                         SpaceClip *space_clip = (SpaceClip *) space_link;
232                                         space_clip->flag &= ~SC_MANUAL_CALIBRATION;
233                                 }
234                         }
235
236                         for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
237                                 /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
238                                 BLI_freelistN(&ar->panels);
239
240                                 /* some toolbars have been saved as initialized,
241                                  * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
242                                 if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
243                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
244                                 }
245                         }
246                 }
247         }
248
249         for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
250                 me->smoothresh = DEG2RADF(180.0f);
251                 me->flag &= ~ME_TWOSIDED;
252         }
253
254         for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
255                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
256                 mat->line_col[3] = 1.0f;
257         }
258
259         {
260                 Object *ob;
261
262                 ob = (Object *)BKE_libblock_find_name_ex(bmain, ID_OB, "Camera");
263                 if (ob) {
264                         ob->rot[1] = 0.0f;
265                 }
266         }
267
268         {
269                 Brush *br;
270
271                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
272                 if (!br) {
273                         br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
274                         br->imagepaint_tool = PAINT_TOOL_FILL;
275                         br->ob_mode = OB_MODE_TEXTURE_PAINT;
276                 }
277
278                 /* Vertex/Weight Paint */
279                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Average");
280                 if (!br) {
281                         br = BKE_brush_add(bmain, "Average", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
282                         br->vertexpaint_tool = PAINT_BLEND_AVERAGE;
283                         br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
284                 }
285                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Smear");
286                 if (!br) {
287                         br = BKE_brush_add(bmain, "Smear", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
288                         br->vertexpaint_tool = PAINT_BLEND_SMEAR;
289                         br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
290                 }
291
292                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
293                 if (br) {
294                         br->imagepaint_tool = PAINT_TOOL_MASK;
295                         br->ob_mode |= OB_MODE_TEXTURE_PAINT;
296                 }
297
298                 /* remove polish brush (flatten/contrast does the same) */
299                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
300                 if (br) {
301                         BKE_libblock_delete(bmain, br);
302                 }
303
304                 /* remove brush brush (huh?) from some modes (draw brushes do the same) */
305                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Brush");
306                 if (br) {
307                         BKE_libblock_delete(bmain, br);
308                 }
309
310                 /* remove draw brush from texpaint (draw brushes do the same) */
311                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Draw");
312                 if (br) {
313                         br->ob_mode &= ~OB_MODE_TEXTURE_PAINT;
314                 }
315
316                 /* rename twist brush to rotate brush to match rotate tool */
317                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Twist");
318                 if (br) {
319                         BKE_libblock_rename(bmain, &br->id, "Rotate");
320                 }
321
322                 /* use original normal for grab brush (otherwise flickers with normal weighting). */
323                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Grab");
324                 if (br) {
325                         br->flag |= BRUSH_ORIGINAL_NORMAL;
326                 }
327
328                 /* increase strength, better for smoothing method */
329                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Blur");
330                 if (br) {
331                         br->alpha = 1.0f;
332                 }
333
334                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Flatten/Contrast");
335                 if (br) {
336                         br->flag |= BRUSH_ACCUMULATE;
337                 }
338         }
339 }
340