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