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