Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenloader / intern / versioning_270.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_270.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29 #include "BLI_compiler_attrs.h"
30
31 /* for MinGW32 definition of NULL, could use BLI_blenlib.h instead too */
32 #include <stddef.h>
33
34 /* allow readfile to use deprecated functionality */
35 #define DNA_DEPRECATED_ALLOW
36
37 #include "DNA_armature_types.h"
38 #include "DNA_brush_types.h"
39 #include "DNA_camera_types.h"
40 #include "DNA_cloth_types.h"
41 #include "DNA_constraint_types.h"
42 #include "DNA_gpencil_types.h"
43 #include "DNA_sdna_types.h"
44 #include "DNA_sequence_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_object_force.h"
48 #include "DNA_object_types.h"
49 #include "DNA_mesh_types.h"
50 #include "DNA_modifier_types.h"
51 #include "DNA_linestyle_types.h"
52 #include "DNA_actuator_types.h"
53 #include "DNA_view3d_types.h"
54 #include "DNA_smoke_types.h"
55 #include "DNA_rigidbody_types.h"
56
57 #include "DNA_genfile.h"
58
59 #include "BKE_colortools.h"
60 #include "BKE_library.h"
61 #include "BKE_main.h"
62 #include "BKE_modifier.h"
63 #include "BKE_node.h"
64 #include "BKE_scene.h"
65 #include "BKE_sequencer.h"
66 #include "BKE_screen.h"
67 #include "BKE_tracking.h"
68 #include "BKE_gpencil.h"
69
70 #include "BLI_math.h"
71 #include "BLI_listbase.h"
72 #include "BLI_string.h"
73
74 #include "BLO_readfile.h"
75
76 #include "readfile.h"
77
78 #include "MEM_guardedalloc.h"
79
80 /**
81  * Setup rotation stabilization from ancient single track spec.
82  * Former Version of 2D stabilization used a single tracking marker to determine the rotation
83  * to be compensated. Now several tracks can contribute to rotation detection and this feature
84  * is enabled by the MovieTrackingTrack#flag on a per track base.
85  */
86 static void migrate_single_rot_stabilization_track_settings(MovieTrackingStabilization *stab)
87 {
88         if (stab->rot_track) {
89                 if (!(stab->rot_track->flag & TRACK_USE_2D_STAB_ROT)) {
90                         stab->tot_rot_track++;
91                         stab->rot_track->flag |= TRACK_USE_2D_STAB_ROT;
92                 }
93         }
94         stab->rot_track = NULL; /* this field is now ignored */
95 }
96
97 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
98 {
99         bConstraint *con;
100
101         for (con = lb->first; con; con = con->next) {
102                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
103                         bTransformConstraint *data = (bTransformConstraint *)con->data;
104                         const float deg_to_rad_f = DEG2RADF(1.0f);
105
106                         if (data->from == TRANS_ROTATION) {
107                                 mul_v3_fl(data->from_min, deg_to_rad_f);
108                                 mul_v3_fl(data->from_max, deg_to_rad_f);
109                         }
110
111                         if (data->to == TRANS_ROTATION) {
112                                 mul_v3_fl(data->to_min, deg_to_rad_f);
113                                 mul_v3_fl(data->to_max, deg_to_rad_f);
114                         }
115                 }
116         }
117 }
118
119 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
120 {
121         bConstraint *con;
122
123         for (con = lb->first; con; con = con->next) {
124                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
125                         bTransformConstraint *data = (bTransformConstraint *)con->data;
126
127                         if (data->from == TRANS_ROTATION) {
128                                 copy_v3_v3(data->from_min_rot, data->from_min);
129                                 copy_v3_v3(data->from_max_rot, data->from_max);
130                         }
131                         else if (data->from == TRANS_SCALE) {
132                                 copy_v3_v3(data->from_min_scale, data->from_min);
133                                 copy_v3_v3(data->from_max_scale, data->from_max);
134                         }
135
136                         if (data->to == TRANS_ROTATION) {
137                                 copy_v3_v3(data->to_min_rot, data->to_min);
138                                 copy_v3_v3(data->to_max_rot, data->to_max);
139                         }
140                         else if (data->to == TRANS_SCALE) {
141                                 copy_v3_v3(data->to_min_scale, data->to_min);
142                                 copy_v3_v3(data->to_max_scale, data->to_max);
143                         }
144                 }
145         }
146 }
147
148 static void do_version_constraints_stretch_to_limits(ListBase *lb)
149 {
150         bConstraint *con;
151
152         for (con = lb->first; con; con = con->next) {
153                 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
154                         bStretchToConstraint *data = (bStretchToConstraint *)con->data;
155                         data->bulge_min = 1.0f;
156                         data->bulge_max = 1.0f;
157                 }
158         }
159 }
160
161 static void do_version_action_editor_properties_region(ListBase *regionbase)
162 {
163         ARegion *ar;
164         
165         for (ar = regionbase->first; ar; ar = ar->next) {
166                 if (ar->regiontype == RGN_TYPE_UI) {
167                         /* already exists */
168                         return;
169                 }
170                 else if (ar->regiontype == RGN_TYPE_WINDOW) {
171                         /* add new region here */
172                         ARegion *arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
173                         
174                         BLI_insertlinkbefore(regionbase, ar, arnew);
175                         
176                         arnew->regiontype = RGN_TYPE_UI;
177                         arnew->alignment = RGN_ALIGN_RIGHT;
178                         arnew->flag = RGN_FLAG_HIDDEN;
179                         
180                         return;
181                 }
182         }
183 }
184
185 static void do_version_bones_super_bbone(ListBase *lb)
186 {
187         for (Bone *bone = lb->first; bone; bone = bone->next) {
188                 bone->scaleIn = 1.0f;
189                 bone->scaleOut = 1.0f;
190                 
191                 do_version_bones_super_bbone(&bone->childbase);
192         }
193 }
194
195 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
196 {
197         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
198
199                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
200                         Object *ob;
201
202                         for (ob = main->object.first; ob; ob = ob->id.next) {
203                                 ModifierData *md;
204                                 for (md = ob->modifiers.first; md; md = md->next) {
205                                         if (md->type == eModifierType_Bevel) {
206                                                 BevelModifierData *bmd = (BevelModifierData *)md;
207                                                 bmd->profile = 0.5f;
208                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
209                                         }
210                                 }
211                         }
212                 }
213
214                 /* nodes don't use fixed node->id any more, clean up */
215                 FOREACH_NODETREE(main, ntree, id) {
216                         if (ntree->type == NTREE_COMPOSIT) {
217                                 bNode *node;
218                                 for (node = ntree->nodes.first; node; node = node->next) {
219                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
220                                                 node->id = NULL;
221                                         }
222                                 }
223                         }
224                 } FOREACH_NODETREE_END
225
226                 {
227                         bScreen *screen;
228
229                         for (screen = main->screen.first; screen; screen = screen->id.next) {
230                                 ScrArea *area;
231                                 for (area = screen->areabase.first; area; area = area->next) {
232                                         SpaceLink *space_link;
233                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
234                                                 if (space_link->spacetype == SPACE_CLIP) {
235                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
236                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
237                                                                 space_clip->mode = SC_MODE_TRACKING;
238                                                         }
239                                                 }
240                                         }
241                                 }
242                         }
243                 }
244
245                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
246                         MovieClip *clip;
247                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
248                                 clip->tracking.settings.default_weight = 1.0f;
249                         }
250                 }
251         }
252
253         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
254                 Scene *sce;
255                 Object *ob;
256
257                 /* Update Transform constraint (another deg -> rad stuff). */
258                 for (ob = main->object.first; ob; ob = ob->id.next) {
259                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
260
261                         if (ob->pose) {
262                                 /* Bones constraints! */
263                                 bPoseChannel *pchan;
264                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
265                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
266                                 }
267                         }
268                 }
269
270                 for (sce = main->scene.first; sce; sce = sce->id.next) {
271                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
272                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
273                         }
274                 }
275         }
276
277         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
278                 Mesh *me;
279
280                 /* Mesh smoothresh deg->rad. */
281                 for (me = main->mesh.first; me; me = me->id.next) {
282                         me->smoothresh = DEG2RADF(me->smoothresh);
283                 }
284         }
285
286         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
287                 FreestyleLineStyle *linestyle;
288
289                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
290                         linestyle->flag |= LS_NO_SORTING;
291                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
292                         linestyle->integration_type = LS_INTEGRATION_MEAN;
293                 }
294         }
295
296         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
297                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
298                  * This will always reset situation to a valid state.
299                  */
300                 bScreen *sc;
301
302                 for (sc = main->screen.first; sc; sc = sc->id.next) {
303                         ScrArea *sa;
304                         for (sa = sc->areabase.first; sa; sa = sa->next) {
305                                 SpaceLink *sl;
306
307                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
308                                         ARegion *ar;
309                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
310
311                                         for (ar = lb->first; ar; ar = ar->next) {
312                                                 BLI_listbase_clear(&ar->ui_previews);
313                                         }
314                                 }
315                         }
316                 }
317         }
318
319         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
320                 Object *ob;
321
322                 /* Update Transform constraint (again :|). */
323                 for (ob = main->object.first; ob; ob = ob->id.next) {
324                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
325
326                         if (ob->pose) {
327                                 /* Bones constraints! */
328                                 bPoseChannel *pchan;
329                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
330                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
331                                 }
332                         }
333                 }
334         }
335
336         if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
337                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
338                         Material *ma;
339
340                         for (ma = main->mat.first; ma; ma = ma->id.next)
341                                 ma->mode2 = MA_CASTSHADOW;
342                 }
343
344                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
345                         Scene *sce;
346
347                         for (sce = main->scene.first; sce; sce = sce->id.next) {
348                                 sce->r.bake.flag = R_BAKE_CLEAR;
349                                 sce->r.bake.width = 512;
350                                 sce->r.bake.height = 512;
351                                 sce->r.bake.margin = 16;
352                                 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
353                                 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
354                                 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
355                                 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
356                                 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
357
358                                 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
359                                 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
360                                 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
361                                 sce->r.bake.im_format.quality = 90;
362                                 sce->r.bake.im_format.compress = 15;
363                         }
364                 }
365
366                 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
367                         FreestyleLineStyle *linestyle;
368
369                         for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
370                                 linestyle->flag |= LS_TEXTURE;
371                                 linestyle->texstep = 1.0;
372                         }
373                 }
374
375                 {
376                         Scene *scene;
377                         for (scene = main->scene.first; scene; scene = scene->id.next) {
378                                 int num_layers = BLI_listbase_count(&scene->r.layers);
379                                 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
380                         }
381                 }
382         }
383
384         if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
385                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
386                         Material *mat;
387
388                         for (mat = main->mat.first; mat; mat = mat->id.next) {
389                                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
390                                 mat->line_col[3] = mat->alpha;
391                         }
392                 }
393
394                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
395                         Scene *scene;
396                         for (scene = main->scene.first; scene; scene = scene->id.next) {
397                                 scene->r.preview_start_resolution = 64;
398                         }
399                 }
400         }
401
402         if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
403                 /* init up & track axis property of trackto actuators */
404                 Object *ob;
405
406                 for (ob = main->object.first; ob; ob = ob->id.next) {
407                         bActuator *act;
408                         for (act = ob->actuators.first; act; act = act->next) {
409                                 if (act->type == ACT_EDIT_OBJECT) {
410                                         bEditObjectActuator *eoact = act->data;
411                                         eoact->trackflag = ob->trackflag;
412                                         /* if trackflag is pointing +-Z axis then upflag should point Y axis.
413                                          * Rest of trackflag cases, upflag should be point z axis */
414                                         if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
415                                                 eoact->upflag = 1;
416                                         }
417                                         else {
418                                                 eoact->upflag = 2;
419                                         }
420                                 }
421                         }
422                 }
423         }
424
425         if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
426                 Brush *br;
427
428                 for (br = main->brush.first; br; br = br->id.next) {
429                         br->fill_threshold = 0.2f;
430                 }
431
432                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
433                         Object *ob;
434                         for (ob = main->object.first; ob; ob = ob->id.next) {
435                                 ModifierData *md;
436
437                                 for (md = ob->modifiers.first; md; md = md->next) {
438                                         if (md->type == eModifierType_Bevel) {
439                                                 BevelModifierData *bmd = (BevelModifierData *)md;
440                                                 bmd->mat = -1;
441                                         }
442                                 }
443                         }
444                 }
445         }
446
447         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
448                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
449                         Scene *scene;
450                         for (scene = main->scene.first; scene; scene = scene->id.next) {
451                                 scene->r.preview_start_resolution = 64;
452                         }
453                 }
454         }
455
456         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
457                 Brush *br;
458                 for (br = main->brush.first; br; br = br->id.next) {
459                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
460                                 br->alpha = 1.0f;
461                 }
462         }
463
464         if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
465                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
466                         Image *image;
467                         for (image = main->image.first; image != NULL; image = image->id.next) {
468                                 image->gen_color[3] = 1.0f;
469                         }
470                 }
471
472                 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
473                         Object *ob;
474
475                         /* Update Transform constraint (again :|). */
476                         for (ob = main->object.first; ob; ob = ob->id.next) {
477                                 do_version_constraints_stretch_to_limits(&ob->constraints);
478
479                                 if (ob->pose) {
480                                         /* Bones constraints! */
481                                         bPoseChannel *pchan;
482                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
483                                                 do_version_constraints_stretch_to_limits(&pchan->constraints);
484                                         }
485                                 }
486                         }
487                 }
488         }
489
490         if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
491 #define BRUSH_RAKE (1 << 7)
492 #define BRUSH_RANDOM_ROTATION (1 << 25)
493
494                 Brush *br;
495
496                 for (br = main->brush.first; br; br = br->id.next) {
497                         if (br->flag & BRUSH_RAKE) {
498                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
499                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
500                         }
501                         else if (br->flag & BRUSH_RANDOM_ROTATION) {
502                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
503                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
504                         }
505                         br->mtex.random_angle = 2.0 * M_PI;
506                         br->mask_mtex.random_angle = 2.0 * M_PI;
507                 }
508         }
509
510 #undef BRUSH_RAKE
511 #undef BRUSH_RANDOM_ROTATION
512
513         /* Customizable Safe Areas */
514         if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
515                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
516                         Scene *scene;
517
518                         for (scene = main->scene.first; scene; scene = scene->id.next) {
519                                 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
520                                 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
521                                 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
522                                 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
523                         }
524                 }
525         }
526         
527         if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
528                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
529                         Object *ob;
530                         ModifierData *md;
531                         for (ob = main->object.first; ob; ob = ob->id.next) {
532                                 for (md = ob->modifiers.first; md; md = md->next) {
533                                         if (md->type == eModifierType_Cloth) {
534                                                 ClothModifierData *clmd = (ClothModifierData *)md;
535                                                 clmd->sim_parms->bending_damping = 0.5f;
536                                         }
537                                 }
538                         }
539                 }
540
541                 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
542                         Object *ob;
543
544                         for (ob = main->object.first; ob; ob = ob->id.next) {
545                                 ModifierData *md;
546                                 for (md = ob->modifiers.first; md; md = md->next) {
547                                         if (md->type == eModifierType_Hook) {
548                                                 HookModifierData *hmd = (HookModifierData *)md;
549                                                 hmd->falloff_type = eHook_Falloff_InvSquare;
550                                         }
551                                 }
552                         }
553                 }
554
555                 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
556                         FOREACH_NODETREE(main, ntree, id) {
557                                 if (ntree->type == NTREE_COMPOSIT) {
558                                         bNode *node;
559                                         for (node = ntree->nodes.first; node; node = node->next) {
560                                                 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
561                                                         NodePlaneTrackDeformData *data = node->storage;
562                                                         data->flag = 0;
563                                                         data->motion_blur_samples = 16;
564                                                         data->motion_blur_shutter = 0.5f;
565                                                 }
566                                         }
567                                 }
568                         }
569                         FOREACH_NODETREE_END
570                 }
571
572                 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
573                         Camera *ca;
574                         for (ca = main->camera.first; ca; ca = ca->id.next) {
575                                 ca->gpu_dof.fstop = 128.0f;
576                                 ca->gpu_dof.focal_length = 1.0f;
577                                 ca->gpu_dof.focus_distance = 1.0f;
578                                 ca->gpu_dof.sensor = 1.0f;
579                         }
580                 }
581         }
582
583         if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
584                 Object *ob;
585                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
586                         ModifierData *md;
587                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
588                                 if (modifier_unique_name(&ob->modifiers, md)) {
589                                         printf("Warning: Object '%s' had several modifiers with the "
590                                                "same name, renamed one of them to '%s'.\n",
591                                                ob->id.name + 2, md->name);
592                                 }
593                         }
594                 }
595         }
596
597         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
598                 bScreen *scr;
599                 ScrArea *sa;
600                 SpaceLink *sl;
601                 ARegion *ar;
602
603                 /* Make sure sequencer preview area limits zoom */
604                 for (scr = main->screen.first; scr; scr = scr->id.next) {
605                         for (sa = scr->areabase.first; sa; sa = sa->next) {
606                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
607                                         if (sl->spacetype == SPACE_SEQ) {
608                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
609                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
610                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
611                                                                 ar->v2d.minzoom = 0.001f;
612                                                                 ar->v2d.maxzoom = 1000.0f;
613                                                                 break;
614                                                         }
615                                                 }
616                                         }
617                                 }
618                         }
619                 }
620         }
621
622         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
623                 /* hysteresis setted to 10% but not actived */
624                 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
625                         Object *ob;
626                         for (ob = main->object.first; ob; ob = ob->id.next) {
627                                 LodLevel *level;
628                                 for (level = ob->lodlevels.first; level; level = level->next) {
629                                         level->obhysteresis = 10;
630                                 }
631                         }
632                 }
633
634                 if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
635                         Scene *scene;
636                         for (scene = main->scene.first; scene; scene = scene->id.next) {
637                                 scene->gm.scehysteresis = 10;
638                         }
639                 }
640         }
641
642         if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
643                 FOREACH_NODETREE(main, ntree, id) {
644                         bNode *node;
645                         bNodeSocket *sock;
646
647                         for (node = ntree->nodes.first; node; node = node->next) {
648                                 if (node->type == SH_NODE_MATERIAL) {
649                                         for (sock = node->inputs.first; sock; sock = sock->next) {
650                                                 if (STREQ(sock->name, "Refl")) {
651                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
652                                                 }
653                                         }
654                                 }
655                                 else if (node->type == SH_NODE_MATERIAL_EXT) {
656                                         for (sock = node->outputs.first; sock; sock = sock->next) {
657                                                 if (STREQ(sock->name, "Refl")) {
658                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
659                                                 }
660                                                 else if (STREQ(sock->name, "Ray Mirror")) {
661                                                         BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
662                                                 }
663                                         }
664                                 }
665                         }
666                 } FOREACH_NODETREE_END
667         }
668
669         if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
670                 SceneRenderView *srv;
671                 wmWindowManager *wm;
672                 bScreen *screen;
673                 wmWindow *win;
674                 Scene *scene;
675                 Camera *cam;
676                 Image *ima;
677
678                 for (scene = main->scene.first; scene; scene = scene->id.next) {
679                         Sequence *seq;
680
681                         BKE_scene_add_render_view(scene, STEREO_LEFT_NAME);
682                         srv = scene->r.views.first;
683                         BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
684
685                         BKE_scene_add_render_view(scene, STEREO_RIGHT_NAME);
686                         srv = scene->r.views.last;
687                         BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
688
689                         SEQ_BEGIN (scene->ed, seq)
690                         {
691                                 seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
692
693 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
694 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
695                                 if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) {
696                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
697                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
698                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
699                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
700                                 }
701 #undef SEQ_USE_PROXY_CUSTOM_DIR
702 #undef SEQ_USE_PROXY_CUSTOM_FILE
703
704                         }
705                         SEQ_END
706                 }
707
708                 for (screen = main->screen.first; screen; screen = screen->id.next) {
709                         ScrArea *sa;
710                         for (sa = screen->areabase.first; sa; sa = sa->next) {
711                                 SpaceLink *sl;
712
713                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
714                                         switch (sl->spacetype) {
715                                                 case SPACE_VIEW3D:
716                                                 {
717                                                         View3D *v3d = (View3D *)sl;
718                                                         v3d->stereo3d_camera = STEREO_3D_ID;
719                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
720                                                         v3d->stereo3d_convergence_alpha = 0.15f;
721                                                         v3d->stereo3d_volume_alpha = 0.05f;
722                                                         break;
723                                                 }
724                                                 case SPACE_IMAGE:
725                                                 {
726                                                         SpaceImage *sima = (SpaceImage *) sl;
727                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
728                                                         break;
729                                                 }
730                                         }
731                                 }
732                         }
733                 }
734
735                 for (cam = main->camera.first; cam; cam = cam->id.next) {
736                         cam->stereo.interocular_distance = 0.065f;
737                         cam->stereo.convergence_distance = 30.0f * 0.065f;
738                 }
739
740                 for (ima = main->image.first; ima; ima = ima->id.next) {
741                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
742
743                         if (ima->packedfile) {
744                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
745                                 BLI_addtail(&ima->packedfiles, imapf);
746
747                                 imapf->packedfile = ima->packedfile;
748                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
749                                 ima->packedfile = NULL;
750                         }
751                 }
752
753                 for (wm = main->wm.first; wm; wm = wm->id.next) {
754                         for (win = wm->windows.first; win; win = win->next) {
755                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
756                         }
757                 }
758         }
759
760         if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
761                 bScreen *screen;
762
763                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
764                         for (screen = main->screen.first; screen; screen = screen->id.next) {
765                                 ScrArea *sa;
766
767                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
768                                         SpaceLink *sl;
769
770                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
771                                                 if (sl->spacetype == SPACE_FILE) {
772                                                         SpaceFile *sfile = (SpaceFile *)sl;
773
774                                                         if (sfile->params) {
775                                                                 sfile->params->thumbnail_size = 128;
776                                                         }
777                                                 }
778                                         }
779                                 }
780                         }
781                 }
782
783                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
784                         Scene *scene;
785                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
786                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
787                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
788                         }
789                 }
790
791                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
792                         Object *ob;
793
794                         for (ob = main->object.first; ob; ob = ob->id.next) {
795                                 ModifierData *md;
796                                 for (md = ob->modifiers.first; md; md = md->next) {
797                                         if (md->type == eModifierType_Decimate) {
798                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
799                                                 dmd->defgrp_factor = 1.0f;
800                                         }
801                                 }
802                         }
803                 }
804         }
805
806         if (!MAIN_VERSION_ATLEAST(main, 275, 3)) {
807                 Brush *br;
808 #define BRUSH_TORUS (1 << 1)
809                 for (br = main->brush.first; br; br = br->id.next) {
810                         br->flag &= ~BRUSH_TORUS;
811                 }
812 #undef BRUSH_TORUS
813         }
814
815         if (!MAIN_VERSION_ATLEAST(main, 276, 2)) {
816                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
817                         Object *ob;
818
819                         for (ob = main->object.first; ob; ob = ob->id.next) {
820                                 if (ob->pose) {
821                                         bPoseChannel *pchan;
822                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
823                                                 pchan->custom_scale = 1.0f;
824                                         }
825                                 }
826                         }
827                 }
828
829                 {
830                         bScreen *screen;
831 #define RV3D_VIEW_PERSPORTHO     7
832                         for (screen = main->screen.first; screen; screen = screen->id.next) {
833                                 ScrArea *sa;
834                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
835                                         SpaceLink *sl;
836                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
837                                                 if (sl->spacetype == SPACE_VIEW3D) {
838                                                         ARegion *ar;
839                                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
840                                                         for (ar = lb->first; ar; ar = ar->next) {
841                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
842                                                                         if (ar->regiondata) {
843                                                                                 RegionView3D *rv3d = ar->regiondata;
844                                                                                 if (rv3d->view == RV3D_VIEW_PERSPORTHO) {
845                                                                                         rv3d->view = RV3D_VIEW_USER;
846                                                                                 }
847                                                                         }
848                                                                 }
849                                                         }
850                                                         break;
851                                                 }
852                                         }
853                                 }
854                         }
855 #undef RV3D_VIEW_PERSPORTHO
856                 }
857
858                 {
859                         Lamp *lamp;
860 #define LA_YF_PHOTON    5
861                         for (lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
862                                 if (lamp->type == LA_YF_PHOTON) {
863                                         lamp->type = LA_LOCAL;
864                                 }
865                         }
866 #undef LA_YF_PHOTON
867                 }
868
869                 {
870                         Object *ob;
871                         for (ob = main->object.first; ob; ob = ob->id.next) {
872                                 if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
873                                         ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
874                                 }
875                         }
876                 }
877
878         }
879
880         if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
881                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
882                         Scene *scene;
883                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
884                                 CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
885                                 curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
886                                 curvemapping_initialize(curve_mapping);
887                                 curvemap_reset(curve_mapping->cm,
888                                                &curve_mapping->clipr,
889                                                CURVE_PRESET_MAX,
890                                                CURVEMAP_SLOPE_POS_NEG);
891                         }
892                 }
893         }
894
895         if (!MAIN_VERSION_ATLEAST(main, 276, 4)) {
896                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
897                         ToolSettings *ts = scene->toolsettings;
898                         
899                         if (ts->gp_sculpt.brush[0].size == 0) {
900                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
901                                 GP_EditBrush_Data *brush;
902                                 
903                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
904                                 brush->size = 25;
905                                 brush->strength = 0.3f;
906                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
907                                 
908                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
909                                 brush->size = 25;
910                                 brush->strength = 0.5f;
911                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
912                                 
913                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
914                                 brush->size = 50;
915                                 brush->strength = 0.3f;
916                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
917                                 
918                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
919                                 brush->size = 25;
920                                 brush->strength = 0.3f;
921                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
922                                 
923                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
924                                 brush->size = 50;
925                                 brush->strength = 0.3f; // XXX?
926                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
927                                 
928                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
929                                 brush->size = 50;
930                                 brush->strength = 0.5f; // XXX?
931                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
932                                 
933                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
934                                 brush->size = 25;
935                                 brush->strength = 0.5f;
936                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
937                                 
938                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_CLONE];
939                                 brush->size = 50;
940                                 brush->strength = 1.0f;
941                         }
942                         
943                         if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
944 #if 0 /* XXX: Cannot do this, as we get random crashes... */
945                                 if (scene->gpd) {
946                                         bGPdata *gpd = scene->gpd;
947                                         
948                                         /* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
949                                         ts->gpencil_v3d_align = 0;
950                                         
951                                         if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
952                                         if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
953                                         if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
954                                         
955                                         if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
956                                                 ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
957                                 }
958                                 else {
959                                         /* Default to cursor for all standard 3D views */
960                                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
961                                 }
962 #endif
963                                 
964                                 ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
965                                 ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
966                                 ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
967                                 ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
968                         }
969                 }
970                 
971                 for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
972                         bool enabled = false;
973                         
974                         /* Ensure that the datablock's onionskinning toggle flag
975                          * stays in sync with the status of the actual layers
976                          */
977                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
978                                 if (gpl->flag & GP_LAYER_ONIONSKIN) {
979                                         enabled = true;
980                                 }
981                         }
982                         
983                         if (enabled)
984                                 gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
985                         else
986                                 gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
987                 }
988
989                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) {
990                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
991                                 ob->max_jumps = 1;
992                         }
993                 }
994         }
995         if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
996                 ListBase *lbarray[MAX_LIBARRAY];
997                 int a;
998
999                 /* Important to clear all non-persistent flags from older versions here, otherwise they could collide
1000                  * with any new persistent flag we may add in the future. */
1001                 a = set_listbasepointers(main, lbarray);
1002                 while (a--) {
1003                         for (ID *id = lbarray[a]->first; id; id = id->next) {
1004                                 id->flag &= LIB_FAKEUSER;
1005                         }
1006                 }
1007         }
1008
1009         if (!MAIN_VERSION_ATLEAST(main, 276, 7)) {
1010                 Scene *scene;
1011                 for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1012                         scene->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
1013                 }
1014         }
1015
1016         if (!MAIN_VERSION_ATLEAST(main, 277, 1)) {
1017                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1018                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1019                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1020                                         ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1021                                         /* Bug: Was possible to add preview region to sequencer view by using AZones. */
1022                                         if (sl->spacetype == SPACE_SEQ) {
1023                                                 SpaceSeq *sseq = (SpaceSeq *)sl;
1024                                                 if (sseq->view == SEQ_VIEW_SEQUENCE) {
1025                                                         for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1026                                                                 /* remove preview region for sequencer-only view! */
1027                                                                 if (ar->regiontype == RGN_TYPE_PREVIEW) {
1028                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1029                                                                         ar->alignment = RGN_ALIGN_NONE;
1030                                                                         break;
1031                                                                 }
1032                                                         }
1033                                                 }
1034                                         }
1035                                         /* Remove old deprecated region from filebrowsers */
1036                                         else if (sl->spacetype == SPACE_FILE) {
1037                                                 for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1038                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
1039                                                                 /* Free old deprecated 'channel' region... */
1040                                                                 BKE_area_region_free(NULL, ar);
1041                                                                 BLI_freelinkN(regionbase, ar);
1042                                                                 break;
1043                                                         }
1044                                                 }
1045                                         }
1046                                 }
1047                         }
1048                 }
1049
1050                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1051                         CurvePaintSettings *cps = &scene->toolsettings->curve_paint_settings;
1052                         if (cps->error_threshold == 0) {
1053                                 cps->curve_type = CU_BEZIER;
1054                                 cps->flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
1055                                 cps->error_threshold = 8;
1056                                 cps->radius_max = 1.0f;
1057                                 cps->corner_angle = DEG2RADF(70.0f);
1058                         }
1059                 }
1060
1061                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1062                         Sequence *seq;
1063
1064                         SEQ_BEGIN (scene->ed, seq)
1065                         {
1066                                 if (seq->type == SEQ_TYPE_TEXT) {
1067                                         TextVars *data = seq->effectdata;
1068                                         if (data->color[3] == 0.0f) {
1069                                                 copy_v4_fl(data->color, 1.0f);
1070                                                 data->shadow_color[3] = 1.0f;
1071                                         }
1072                                 }
1073                         }
1074                         SEQ_END
1075                 }
1076
1077                 /* Adding "Properties" region to DopeSheet */
1078                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1079                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1080                                 /* handle pushed-back space data first */
1081                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1082                                         if (sl->spacetype == SPACE_ACTION) {
1083                                                 SpaceAction *saction = (SpaceAction *)sl;
1084                                                 do_version_action_editor_properties_region(&saction->regionbase);
1085                                         }
1086                                 }
1087                                 
1088                                 /* active spacedata info must be handled too... */
1089                                 if (sa->spacetype == SPACE_ACTION) {
1090                                         do_version_action_editor_properties_region(&sa->regionbase);
1091                                 }
1092                         }
1093                 }
1094         }
1095
1096         if (!MAIN_VERSION_ATLEAST(main, 277, 2)) {
1097                 if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "scaleIn")) {
1098                         for (bArmature *arm = main->armature.first; arm; arm = arm->id.next) {
1099                                 do_version_bones_super_bbone(&arm->bonebase);
1100                         }
1101                 }
1102                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "scaleIn")) {
1103                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1104                                 if (ob->pose) {
1105                                         for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1106                                                 /* see do_version_bones_super_bbone()... */
1107                                                 pchan->scaleIn = 1.0f;
1108                                                 pchan->scaleOut = 1.0f;
1109                                                 
1110                                                 /* also make sure some legacy (unused for over a decade) flags are unset,
1111                                                  * so that we can reuse them for stuff that matters now...
1112                                                  * (i.e. POSE_IK_MAT, (unknown/unused x 4), POSE_HAS_IK)
1113                                                  *
1114                                                  * These seem to have been runtime flags used by the IK solver, but that stuff
1115                                                  * should be able to be recalculated automatically anyway, so it should be fine.
1116                                                  */
1117                                                 pchan->flag &= ~((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8));
1118                                         }
1119                                 }
1120                         }
1121                 }
1122
1123                 for (Camera *camera = main->camera.first; camera != NULL; camera = camera->id.next) {
1124                         if (camera->stereo.pole_merge_angle_from == 0.0f &&
1125                                 camera->stereo.pole_merge_angle_to == 0.0f)
1126                         {
1127                                 camera->stereo.pole_merge_angle_from = DEG2RADF(60.0f);
1128                                 camera->stereo.pole_merge_angle_to = DEG2RADF(75.0f);
1129                         }
1130                 }
1131
1132                 if (!DNA_struct_elem_find(fd->filesdna, "NormalEditModifierData", "float", "mix_limit")) {
1133                         Object *ob;
1134
1135                         for (ob = main->object.first; ob; ob = ob->id.next) {
1136                                 ModifierData *md;
1137                                 for (md = ob->modifiers.first; md; md = md->next) {
1138                                         if (md->type == eModifierType_NormalEdit) {
1139                                                 NormalEditModifierData *nemd = (NormalEditModifierData *)md;
1140                                                 nemd->mix_limit = DEG2RADF(180.0f);
1141                                         }
1142                                 }
1143                         }
1144                 }
1145
1146                 if (!DNA_struct_elem_find(fd->filesdna, "BooleanModifierData", "float", "double_threshold")) {
1147                         Object *ob;
1148                         for (ob = main->object.first; ob; ob = ob->id.next) {
1149                                 ModifierData *md;
1150                                 for (md = ob->modifiers.first; md; md = md->next) {
1151                                         if (md->type == eModifierType_Boolean) {
1152                                                 BooleanModifierData *bmd = (BooleanModifierData *)md;
1153                                                 bmd->double_threshold = 1e-6f;
1154                                         }
1155                                 }
1156                         }
1157                 }
1158
1159                 for (Brush *br = main->brush.first; br; br = br->id.next) {
1160                         if (br->sculpt_tool == SCULPT_TOOL_FLATTEN) {
1161                                 br->flag |= BRUSH_ACCUMULATE;
1162                         }
1163                 }
1164
1165                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "time_scale")) {
1166                         Object *ob;
1167                         ModifierData *md;
1168                         for (ob = main->object.first; ob; ob = ob->id.next) {
1169                                 for (md = ob->modifiers.first; md; md = md->next) {
1170                                         if (md->type == eModifierType_Cloth) {
1171                                                 ClothModifierData *clmd = (ClothModifierData *)md;
1172                                                 clmd->sim_parms->time_scale = 1.0f;
1173                                         }
1174                                 }
1175                         }
1176                 }
1177         }
1178
1179         if (!MAIN_VERSION_ATLEAST(main, 277, 3)) {
1180                 /* ------- init of grease pencil initialization --------------- */
1181                 if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) {
1182                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1183                                 ToolSettings *ts = scene->toolsettings;
1184                                 /* initialize use position for sculpt brushes */
1185                                 ts->gp_sculpt.flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION;
1186                                 /* initialize  selected vertices alpha factor */
1187                                 ts->gp_sculpt.alpha = 1.0f;
1188
1189                                 /* new strength sculpt brush */
1190                                 if (ts->gp_sculpt.brush[0].size >= 11) {
1191                                         GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
1192                                         GP_EditBrush_Data *brush;
1193
1194                                         brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
1195                                         brush->size = 25;
1196                                         brush->strength = 0.5f;
1197                                         brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1198                                 }
1199                         }
1200                         /* create a default grease pencil drawing brushes set */
1201                         if (!BLI_listbase_is_empty(&main->gpencil)) {
1202                                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1203                                         ToolSettings *ts = scene->toolsettings;
1204                                         if (BLI_listbase_is_empty(&ts->gp_brushes)) {
1205                                                 BKE_gpencil_brush_init_presets(ts);
1206                                         }
1207                                 }
1208                         }
1209                         /* Convert Grease Pencil to new palettes/brushes
1210                          * Loop all strokes and create the palette and all colors
1211                          */
1212                         for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1213                                 if (BLI_listbase_is_empty(&gpd->palettes)) {
1214                                         /* create palette */
1215                                         bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette", true);
1216                                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1217                                                 /* create color using layer name */
1218                                                 bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info, true);
1219                                                 if (palcolor != NULL) {
1220                                                         /* set color attributes */
1221                                                         copy_v4_v4(palcolor->color, gpl->color);
1222                                                         copy_v4_v4(palcolor->fill, gpl->fill);
1223                                                         
1224                                                         if (gpl->flag & GP_LAYER_HIDE)       palcolor->flag |= PC_COLOR_HIDE;
1225                                                         if (gpl->flag & GP_LAYER_LOCKED)     palcolor->flag |= PC_COLOR_LOCKED;
1226                                                         if (gpl->flag & GP_LAYER_ONIONSKIN)  palcolor->flag |= PC_COLOR_ONIONSKIN;
1227                                                         if (gpl->flag & GP_LAYER_VOLUMETRIC) palcolor->flag |= PC_COLOR_VOLUMETRIC;
1228                                                         if (gpl->flag & GP_LAYER_HQ_FILL)    palcolor->flag |= PC_COLOR_HQ_FILL;
1229                                                         
1230                                                         /* set layer opacity to 1 */
1231                                                         gpl->opacity = 1.0f;
1232                                                         
1233                                                         /* set tint color */
1234                                                         ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f);
1235                                                         
1236                                                         /* flush relevant layer-settings to strokes */
1237                                                         for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
1238                                                                 for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
1239                                                                         /* set stroke to palette and force recalculation */
1240                                                                         BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname));
1241                                                                         gps->palcolor = NULL;
1242                                                                         gps->flag |= GP_STROKE_RECALC_COLOR;
1243                                                                         gps->thickness = gpl->thickness;
1244                                                                         
1245                                                                         /* set alpha strength to 1 */
1246                                                                         for (int i = 0; i < gps->totpoints; i++) {
1247                                                                                 gps->points[i].strength = 1.0f;
1248                                                                         }
1249                                                                 }
1250                                                         }
1251                                                 }
1252                                                 
1253                                                 /* set thickness to 0 (now it is a factor to override stroke thickness) */
1254                                                 gpl->thickness = 0.0f;
1255                                         }
1256                                         /* set first color as active */
1257                                         if (palette->colors.first)
1258                                                 BKE_gpencil_palettecolor_setactive(palette, palette->colors.first);
1259                                 }
1260                         }
1261                 }
1262                 /* ------- end of grease pencil initialization --------------- */
1263         }
1264
1265         if (!MAIN_VERSION_ATLEAST(main, 278, 0)) {
1266                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) {
1267                         MovieClip *clip;
1268                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
1269                                 MovieTracking *tracking = &clip->tracking;
1270                                 MovieTrackingObject *tracking_object;
1271                                 for (tracking_object = tracking->objects.first;
1272                                      tracking_object != NULL;
1273                                      tracking_object = tracking_object->next)
1274                                 {
1275                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
1276                                         MovieTrackingTrack *track;
1277                                         for (track = tracksbase->first;
1278                                              track != NULL;
1279                                              track = track->next)
1280                                         {
1281                                                 track->weight_stab = track->weight;
1282                                         }
1283                                 }
1284                         }
1285                 }
1286
1287                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) {
1288                         MovieClip *clip;
1289                         for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) {
1290                                 if (clip->tracking.stabilization.rot_track) {
1291                                         migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization);
1292                                 }
1293                                 if (clip->tracking.stabilization.scale == 0.0f) {
1294                                         /* ensure init.
1295                                          * Was previously used for autoscale only,
1296                                          * now used always (as "target scale") */
1297                                         clip->tracking.stabilization.scale = 1.0f;
1298                                 }
1299                                 /* blender prefers 1-based frame counting;
1300                                  * thus using frame 1 as reference typically works best */
1301                                 clip->tracking.stabilization.anchor_frame = 1;
1302                                 /* by default show the track lists expanded, to improve "discoverability" */
1303                                 clip->tracking.stabilization.flag |= TRACKING_SHOW_STAB_TRACKS;
1304                                 /* deprecated, not used anymore */
1305                                 clip->tracking.stabilization.ok = false;
1306                         }
1307                 }
1308         }
1309         if (!MAIN_VERSION_ATLEAST(main, 278, 2)) {
1310                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "ffmpeg_preset")) {
1311                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1312                                 /* "medium" is the preset FFmpeg uses when no presets are given. */
1313                                 scene->r.ffcodecdata.ffmpeg_preset = FFM_PRESET_MEDIUM;
1314                         }
1315                 }
1316                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "constant_rate_factor")) {
1317                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1318                                 /* fall back to behaviour from before we introduced CRF for old files */
1319                                 scene->r.ffcodecdata.constant_rate_factor = FFM_CRF_NONE;
1320                         }
1321                 }
1322
1323                 if (!DNA_struct_elem_find(fd->filesdna, "SmokeModifierData", "float", "slice_per_voxel")) {
1324                         Object *ob;
1325                         ModifierData *md;
1326
1327                         for (ob = main->object.first; ob; ob = ob->id.next) {
1328                                 for (md = ob->modifiers.first; md; md = md->next) {
1329                                         if (md->type == eModifierType_Smoke) {
1330                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1331                                                 if (smd->domain) {
1332                                                         smd->domain->slice_per_voxel = 5.0f;
1333                                                         smd->domain->slice_depth = 0.5f;
1334                                                         smd->domain->display_thickness = 1.0f;
1335                                                 }
1336                                         }
1337                                 }
1338                         }
1339                 }
1340         }
1341
1342         if (!MAIN_VERSION_ATLEAST(main, 278, 3)) {
1343                 if (!DNA_struct_elem_find(fd->filesdna, "RigidBodyCon", "float", "spring_stiffness_ang_x")) {
1344                         Object *ob;
1345                         for (ob = main->object.first; ob; ob = ob->id.next) {
1346                                 RigidBodyCon *rbc = ob->rigidbody_constraint;
1347                                 if (rbc) {
1348                                         rbc->spring_stiffness_ang_x = 10.0;
1349                                         rbc->spring_stiffness_ang_y = 10.0;
1350                                         rbc->spring_stiffness_ang_z = 10.0;
1351                                         rbc->spring_damping_ang_x = 0.5;
1352                                         rbc->spring_damping_ang_y = 0.5;
1353                                         rbc->spring_damping_ang_z = 0.5;
1354                                 }
1355                         }
1356                 }
1357
1358                 /* constant detail for sculpting is now a resolution value instead of
1359                  * a percentage, we reuse old DNA struct member but convert it */
1360                 for (Scene *scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1361                         if (scene->toolsettings != NULL) {
1362                                 ToolSettings *ts = scene->toolsettings;
1363                                 if (ts->sculpt && ts->sculpt->constant_detail != 0.0f) {
1364                                         ts->sculpt->constant_detail = 100.0f / ts->sculpt->constant_detail;
1365                                 }
1366                         }
1367                 }
1368         }
1369
1370         if (!MAIN_VERSION_ATLEAST(main, 278, 4)) {
1371                 const float sqrt_3 = (float)M_SQRT3;
1372                 for (Brush *br = main->brush.first; br; br = br->id.next) {
1373                         br->fill_threshold /= sqrt_3;
1374                 }
1375         }
1376
1377         {
1378                 if (!DNA_struct_elem_find(fd->filesdna, "View3DDebug", "char", "background")) {
1379                         bScreen *screen;
1380
1381                         for (screen = main->screen.first; screen; screen = screen->id.next) {
1382                                 ScrArea *sa;
1383                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1384                                         SpaceLink *sl;
1385
1386                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1387                                                 switch (sl->spacetype) {
1388                                                         case SPACE_VIEW3D:
1389                                                         {
1390                                                                 View3D *v3d = (View3D *)sl;
1391                                                                 v3d->debug.background = V3D_DEBUG_BACKGROUND_NONE;
1392                                                         }
1393                                                 }
1394                                         }
1395                                 }
1396                         }
1397                 }
1398         }
1399 }