Fix T49738: Hair Add Brush doesn't work
[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 #include "DNA_smoke_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, 271, 6)) {
448                 Object *ob;
449                 for (ob = main->object.first; ob; ob = ob->id.next) {
450                         ModifierData *md;
451
452                         for (md = ob->modifiers.first; md; md = md->next) {
453                                 if (md->type == eModifierType_ParticleSystem) {
454                                         ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
455                                         if (pmd->psys && pmd->psys->clmd) {
456                                                 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
457                                         }
458                                 }
459                         }
460                 }
461         }
462
463         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
464                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
465                         Scene *scene;
466                         for (scene = main->scene.first; scene; scene = scene->id.next) {
467                                 scene->r.preview_start_resolution = 64;
468                         }
469                 }
470         }
471
472         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
473                 Brush *br;
474                 for (br = main->brush.first; br; br = br->id.next) {
475                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
476                                 br->alpha = 1.0f;
477                 }
478         }
479
480         if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
481                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
482                         Image *image;
483                         for (image = main->image.first; image != NULL; image = image->id.next) {
484                                 image->gen_color[3] = 1.0f;
485                         }
486                 }
487
488                 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
489                         Object *ob;
490
491                         /* Update Transform constraint (again :|). */
492                         for (ob = main->object.first; ob; ob = ob->id.next) {
493                                 do_version_constraints_stretch_to_limits(&ob->constraints);
494
495                                 if (ob->pose) {
496                                         /* Bones constraints! */
497                                         bPoseChannel *pchan;
498                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
499                                                 do_version_constraints_stretch_to_limits(&pchan->constraints);
500                                         }
501                                 }
502                         }
503                 }
504         }
505
506         if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
507 #define BRUSH_RAKE (1 << 7)
508 #define BRUSH_RANDOM_ROTATION (1 << 25)
509
510                 Brush *br;
511
512                 for (br = main->brush.first; br; br = br->id.next) {
513                         if (br->flag & BRUSH_RAKE) {
514                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
515                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
516                         }
517                         else if (br->flag & BRUSH_RANDOM_ROTATION) {
518                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
519                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
520                         }
521                         br->mtex.random_angle = 2.0 * M_PI;
522                         br->mask_mtex.random_angle = 2.0 * M_PI;
523                 }
524         }
525
526 #undef BRUSH_RAKE
527 #undef BRUSH_RANDOM_ROTATION
528
529         /* Customizable Safe Areas */
530         if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
531                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
532                         Scene *scene;
533
534                         for (scene = main->scene.first; scene; scene = scene->id.next) {
535                                 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
536                                 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
537                                 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
538                                 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
539                         }
540                 }
541         }
542         
543         if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
544                 ParticleSettings *part;
545                 for (part = main->particle.first; part; part = part->id.next) {
546                         if (part->clumpcurve)
547                                 part->child_flag |= PART_CHILD_USE_CLUMP_CURVE;
548                         if (part->roughcurve)
549                                 part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
550                 }
551         }
552
553         if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
554                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
555                         Object *ob;
556                         ModifierData *md;
557                         for (ob = main->object.first; ob; ob = ob->id.next) {
558                                 for (md = ob->modifiers.first; md; md = md->next) {
559                                         if (md->type == eModifierType_Cloth) {
560                                                 ClothModifierData *clmd = (ClothModifierData *)md;
561                                                 clmd->sim_parms->bending_damping = 0.5f;
562                                         }
563                                         else if (md->type == eModifierType_ParticleSystem) {
564                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
565                                                 if (pmd->psys->clmd) {
566                                                         pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
567                                                 }
568                                         }
569                                 }
570                         }
571                 }
572
573                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "float", "clump_noise_size")) {
574                         ParticleSettings *part;
575                         for (part = main->particle.first; part; part = part->id.next) {
576                                 part->clump_noise_size = 1.0f;
577                         }
578                 }
579
580                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "int", "kink_extra_steps")) {
581                         ParticleSettings *part;
582                         for (part = main->particle.first; part; part = part->id.next) {
583                                 part->kink_extra_steps = 4;
584                         }
585                 }
586
587                 if (!DNA_struct_elem_find(fd->filesdna, "MTex", "float", "kinkampfac")) {
588                         ParticleSettings *part;
589                         for (part = main->particle.first; part; part = part->id.next) {
590                                 int a;
591                                 for (a = 0; a < MAX_MTEX; a++) {
592                                         MTex *mtex = part->mtex[a];
593                                         if (mtex) {
594                                                 mtex->kinkampfac = 1.0f;
595                                         }
596                                 }
597                         }
598                 }
599
600                 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
601                         Object *ob;
602
603                         for (ob = main->object.first; ob; ob = ob->id.next) {
604                                 ModifierData *md;
605                                 for (md = ob->modifiers.first; md; md = md->next) {
606                                         if (md->type == eModifierType_Hook) {
607                                                 HookModifierData *hmd = (HookModifierData *)md;
608                                                 hmd->falloff_type = eHook_Falloff_InvSquare;
609                                         }
610                                 }
611                         }
612                 }
613
614                 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
615                         FOREACH_NODETREE(main, ntree, id) {
616                                 if (ntree->type == NTREE_COMPOSIT) {
617                                         bNode *node;
618                                         for (node = ntree->nodes.first; node; node = node->next) {
619                                                 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
620                                                         NodePlaneTrackDeformData *data = node->storage;
621                                                         data->flag = 0;
622                                                         data->motion_blur_samples = 16;
623                                                         data->motion_blur_shutter = 0.5f;
624                                                 }
625                                         }
626                                 }
627                         }
628                         FOREACH_NODETREE_END
629                 }
630
631                 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
632                         Camera *ca;
633                         for (ca = main->camera.first; ca; ca = ca->id.next) {
634                                 ca->gpu_dof.fstop = 128.0f;
635                                 ca->gpu_dof.focal_length = 1.0f;
636                                 ca->gpu_dof.focus_distance = 1.0f;
637                                 ca->gpu_dof.sensor = 1.0f;
638                         }
639                 }
640         }
641
642         if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
643                 Object *ob;
644                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
645                         ModifierData *md;
646                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
647                                 if (modifier_unique_name(&ob->modifiers, md)) {
648                                         printf("Warning: Object '%s' had several modifiers with the "
649                                                "same name, renamed one of them to '%s'.\n",
650                                                ob->id.name + 2, md->name);
651                                 }
652                         }
653                 }
654         }
655
656         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
657                 bScreen *scr;
658                 ScrArea *sa;
659                 SpaceLink *sl;
660                 ARegion *ar;
661
662                 /* Make sure sequencer preview area limits zoom */
663                 for (scr = main->screen.first; scr; scr = scr->id.next) {
664                         for (sa = scr->areabase.first; sa; sa = sa->next) {
665                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
666                                         if (sl->spacetype == SPACE_SEQ) {
667                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
668                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
669                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
670                                                                 ar->v2d.minzoom = 0.001f;
671                                                                 ar->v2d.maxzoom = 1000.0f;
672                                                                 break;
673                                                         }
674                                                 }
675                                         }
676                                 }
677                         }
678                 }
679         }
680
681         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
682                 /* particle systems need to be forced to redistribute for jitter mode fix */
683                 {
684                         Object *ob;
685                         ParticleSystem *psys;
686                         for (ob = main->object.first; ob; ob = ob->id.next) {
687                                 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
688                                         if ((psys->pointcache->flag & PTCACHE_BAKED) == 0) {
689                                                 psys->recalc |= PSYS_RECALC_RESET;
690                                         }
691                                 }
692                         }
693                 }
694
695                 /* hysteresis setted to 10% but not actived */
696                 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
697                         Object *ob;
698                         for (ob = main->object.first; ob; ob = ob->id.next) {
699                                 LodLevel *level;
700                                 for (level = ob->lodlevels.first; level; level = level->next) {
701                                         level->obhysteresis = 10;
702                                 }
703                         }
704                 }
705
706                 if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
707                         Scene *scene;
708                         for (scene = main->scene.first; scene; scene = scene->id.next) {
709                                 scene->gm.scehysteresis = 10;
710                         }
711                 }
712         }
713
714         if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
715                 FOREACH_NODETREE(main, ntree, id) {
716                         bNode *node;
717                         bNodeSocket *sock;
718
719                         for (node = ntree->nodes.first; node; node = node->next) {
720                                 if (node->type == SH_NODE_MATERIAL) {
721                                         for (sock = node->inputs.first; sock; sock = sock->next) {
722                                                 if (STREQ(sock->name, "Refl")) {
723                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
724                                                 }
725                                         }
726                                 }
727                                 else if (node->type == SH_NODE_MATERIAL_EXT) {
728                                         for (sock = node->outputs.first; sock; sock = sock->next) {
729                                                 if (STREQ(sock->name, "Refl")) {
730                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
731                                                 }
732                                                 else if (STREQ(sock->name, "Ray Mirror")) {
733                                                         BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
734                                                 }
735                                         }
736                                 }
737                         }
738                 } FOREACH_NODETREE_END
739         }
740
741         if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
742                 SceneRenderView *srv;
743                 wmWindowManager *wm;
744                 bScreen *screen;
745                 wmWindow *win;
746                 Scene *scene;
747                 Camera *cam;
748                 Image *ima;
749
750                 for (scene = main->scene.first; scene; scene = scene->id.next) {
751                         Sequence *seq;
752
753                         BKE_scene_add_render_view(scene, STEREO_LEFT_NAME);
754                         srv = scene->r.views.first;
755                         BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
756
757                         BKE_scene_add_render_view(scene, STEREO_RIGHT_NAME);
758                         srv = scene->r.views.last;
759                         BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
760
761                         SEQ_BEGIN (scene->ed, seq)
762                         {
763                                 seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
764
765 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
766 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
767                                 if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) {
768                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
769                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
770                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
771                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
772                                 }
773 #undef SEQ_USE_PROXY_CUSTOM_DIR
774 #undef SEQ_USE_PROXY_CUSTOM_FILE
775
776                         }
777                         SEQ_END
778                 }
779
780                 for (screen = main->screen.first; screen; screen = screen->id.next) {
781                         ScrArea *sa;
782                         for (sa = screen->areabase.first; sa; sa = sa->next) {
783                                 SpaceLink *sl;
784
785                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
786                                         switch (sl->spacetype) {
787                                                 case SPACE_VIEW3D:
788                                                 {
789                                                         View3D *v3d = (View3D *)sl;
790                                                         v3d->stereo3d_camera = STEREO_3D_ID;
791                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
792                                                         v3d->stereo3d_convergence_alpha = 0.15f;
793                                                         v3d->stereo3d_volume_alpha = 0.05f;
794                                                         break;
795                                                 }
796                                                 case SPACE_IMAGE:
797                                                 {
798                                                         SpaceImage *sima = (SpaceImage *) sl;
799                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
800                                                         break;
801                                                 }
802                                         }
803                                 }
804                         }
805                 }
806
807                 for (cam = main->camera.first; cam; cam = cam->id.next) {
808                         cam->stereo.interocular_distance = 0.065f;
809                         cam->stereo.convergence_distance = 30.0f * 0.065f;
810                 }
811
812                 for (ima = main->image.first; ima; ima = ima->id.next) {
813                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
814
815                         if (ima->packedfile) {
816                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
817                                 BLI_addtail(&ima->packedfiles, imapf);
818
819                                 imapf->packedfile = ima->packedfile;
820                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
821                                 ima->packedfile = NULL;
822                         }
823                 }
824
825                 for (wm = main->wm.first; wm; wm = wm->id.next) {
826                         for (win = wm->windows.first; win; win = win->next) {
827                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
828                         }
829                 }
830         }
831
832         if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
833                 bScreen *screen;
834
835                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
836                         for (screen = main->screen.first; screen; screen = screen->id.next) {
837                                 ScrArea *sa;
838
839                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
840                                         SpaceLink *sl;
841
842                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
843                                                 if (sl->spacetype == SPACE_FILE) {
844                                                         SpaceFile *sfile = (SpaceFile *)sl;
845
846                                                         if (sfile->params) {
847                                                                 sfile->params->thumbnail_size = 128;
848                                                         }
849                                                 }
850                                         }
851                                 }
852                         }
853                 }
854
855                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
856                         Scene *scene;
857                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
858                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
859                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
860                         }
861                 }
862
863                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
864                         Object *ob;
865
866                         for (ob = main->object.first; ob; ob = ob->id.next) {
867                                 ModifierData *md;
868                                 for (md = ob->modifiers.first; md; md = md->next) {
869                                         if (md->type == eModifierType_Decimate) {
870                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
871                                                 dmd->defgrp_factor = 1.0f;
872                                         }
873                                 }
874                         }
875                 }
876         }
877
878         if (!MAIN_VERSION_ATLEAST(main, 275, 3)) {
879                 Brush *br;
880 #define BRUSH_TORUS (1 << 1)
881                 for (br = main->brush.first; br; br = br->id.next) {
882                         br->flag &= ~BRUSH_TORUS;
883                 }
884 #undef BRUSH_TORUS
885         }
886
887         if (!MAIN_VERSION_ATLEAST(main, 276, 2)) {
888                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
889                         Object *ob;
890
891                         for (ob = main->object.first; ob; ob = ob->id.next) {
892                                 if (ob->pose) {
893                                         bPoseChannel *pchan;
894                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
895                                                 pchan->custom_scale = 1.0f;
896                                         }
897                                 }
898                         }
899                 }
900
901                 {
902                         bScreen *screen;
903 #define RV3D_VIEW_PERSPORTHO     7
904                         for (screen = main->screen.first; screen; screen = screen->id.next) {
905                                 ScrArea *sa;
906                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
907                                         SpaceLink *sl;
908                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
909                                                 if (sl->spacetype == SPACE_VIEW3D) {
910                                                         ARegion *ar;
911                                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
912                                                         for (ar = lb->first; ar; ar = ar->next) {
913                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
914                                                                         if (ar->regiondata) {
915                                                                                 RegionView3D *rv3d = ar->regiondata;
916                                                                                 if (rv3d->view == RV3D_VIEW_PERSPORTHO) {
917                                                                                         rv3d->view = RV3D_VIEW_USER;
918                                                                                 }
919                                                                         }
920                                                                 }
921                                                         }
922                                                         break;
923                                                 }
924                                         }
925                                 }
926                         }
927 #undef RV3D_VIEW_PERSPORTHO
928                 }
929
930                 {
931                         Lamp *lamp;
932 #define LA_YF_PHOTON    5
933                         for (lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
934                                 if (lamp->type == LA_YF_PHOTON) {
935                                         lamp->type = LA_LOCAL;
936                                 }
937                         }
938 #undef LA_YF_PHOTON
939                 }
940
941                 {
942                         Object *ob;
943                         for (ob = main->object.first; ob; ob = ob->id.next) {
944                                 if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
945                                         ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
946                                 }
947                         }
948                 }
949
950         }
951
952         if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
953                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
954                         Scene *scene;
955                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
956                                 CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
957                                 curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
958                                 curvemapping_initialize(curve_mapping);
959                                 curvemap_reset(curve_mapping->cm,
960                                                &curve_mapping->clipr,
961                                                CURVE_PRESET_MAX,
962                                                CURVEMAP_SLOPE_POS_NEG);
963                         }
964                 }
965         }
966
967         if (!MAIN_VERSION_ATLEAST(main, 276, 4)) {
968                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
969                         ToolSettings *ts = scene->toolsettings;
970                         
971                         if (ts->gp_sculpt.brush[0].size == 0) {
972                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
973                                 GP_EditBrush_Data *brush;
974                                 
975                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
976                                 brush->size = 25;
977                                 brush->strength = 0.3f;
978                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
979                                 
980                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
981                                 brush->size = 25;
982                                 brush->strength = 0.5f;
983                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
984                                 
985                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
986                                 brush->size = 50;
987                                 brush->strength = 0.3f;
988                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
989                                 
990                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
991                                 brush->size = 25;
992                                 brush->strength = 0.3f;
993                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
994                                 
995                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
996                                 brush->size = 50;
997                                 brush->strength = 0.3f; // XXX?
998                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
999                                 
1000                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
1001                                 brush->size = 50;
1002                                 brush->strength = 0.5f; // XXX?
1003                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1004                                 
1005                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
1006                                 brush->size = 25;
1007                                 brush->strength = 0.5f;
1008                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1009                                 
1010                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_CLONE];
1011                                 brush->size = 50;
1012                                 brush->strength = 1.0f;
1013                         }
1014                         
1015                         if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
1016 #if 0 /* XXX: Cannot do this, as we get random crashes... */
1017                                 if (scene->gpd) {
1018                                         bGPdata *gpd = scene->gpd;
1019                                         
1020                                         /* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
1021                                         ts->gpencil_v3d_align = 0;
1022                                         
1023                                         if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
1024                                         if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
1025                                         if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
1026                                         
1027                                         if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
1028                                                 ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
1029                                 }
1030                                 else {
1031                                         /* Default to cursor for all standard 3D views */
1032                                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1033                                 }
1034 #endif
1035                                 
1036                                 ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1037                                 ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
1038                                 ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
1039                                 ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
1040                         }
1041                 }
1042                 
1043                 for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1044                         bool enabled = false;
1045                         
1046                         /* Ensure that the datablock's onionskinning toggle flag
1047                          * stays in sync with the status of the actual layers
1048                          */
1049                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1050                                 if (gpl->flag & GP_LAYER_ONIONSKIN) {
1051                                         enabled = true;
1052                                 }
1053                         }
1054                         
1055                         if (enabled)
1056                                 gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
1057                         else
1058                                 gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
1059                 }
1060
1061                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) {
1062                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1063                                 ob->max_jumps = 1;
1064                         }
1065                 }
1066         }
1067         if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
1068                 ListBase *lbarray[MAX_LIBARRAY];
1069                 int a;
1070
1071                 /* Important to clear all non-persistent flags from older versions here, otherwise they could collide
1072                  * with any new persistent flag we may add in the future. */
1073                 a = set_listbasepointers(main, lbarray);
1074                 while (a--) {
1075                         for (ID *id = lbarray[a]->first; id; id = id->next) {
1076                                 id->flag &= LIB_FAKEUSER;
1077                         }
1078                 }
1079         }
1080
1081         if (!MAIN_VERSION_ATLEAST(main, 276, 7)) {
1082                 Scene *scene;
1083                 for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1084                         scene->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
1085                 }
1086         }
1087
1088         if (!MAIN_VERSION_ATLEAST(main, 277, 1)) {
1089                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1090                         ParticleEditSettings *pset = &scene->toolsettings->particle;
1091                         for (int a = 0; a < PE_TOT_BRUSH; a++) {
1092                                 if (pset->brush[a].strength > 1.0f) {
1093                                         pset->brush[a].strength *= 0.01f;
1094                                 }
1095                         }
1096                 }
1097
1098                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1099                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1100                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1101                                         ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1102                                         /* Bug: Was possible to add preview region to sequencer view by using AZones. */
1103                                         if (sl->spacetype == SPACE_SEQ) {
1104                                                 SpaceSeq *sseq = (SpaceSeq *)sl;
1105                                                 if (sseq->view == SEQ_VIEW_SEQUENCE) {
1106                                                         for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1107                                                                 /* remove preview region for sequencer-only view! */
1108                                                                 if (ar->regiontype == RGN_TYPE_PREVIEW) {
1109                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1110                                                                         ar->alignment = RGN_ALIGN_NONE;
1111                                                                         break;
1112                                                                 }
1113                                                         }
1114                                                 }
1115                                         }
1116                                         /* Remove old deprecated region from filebrowsers */
1117                                         else if (sl->spacetype == SPACE_FILE) {
1118                                                 for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1119                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
1120                                                                 /* Free old deprecated 'channel' region... */
1121                                                                 BKE_area_region_free(NULL, ar);
1122                                                                 BLI_freelinkN(regionbase, ar);
1123                                                                 break;
1124                                                         }
1125                                                 }
1126                                         }
1127                                 }
1128                         }
1129                 }
1130
1131                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1132                         CurvePaintSettings *cps = &scene->toolsettings->curve_paint_settings;
1133                         if (cps->error_threshold == 0) {
1134                                 cps->curve_type = CU_BEZIER;
1135                                 cps->flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
1136                                 cps->error_threshold = 8;
1137                                 cps->radius_max = 1.0f;
1138                                 cps->corner_angle = DEG2RADF(70.0f);
1139                         }
1140                 }
1141
1142                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1143                         Sequence *seq;
1144
1145                         SEQ_BEGIN (scene->ed, seq)
1146                         {
1147                                 if (seq->type == SEQ_TYPE_TEXT) {
1148                                         TextVars *data = seq->effectdata;
1149                                         if (data->color[3] == 0.0f) {
1150                                                 copy_v4_fl(data->color, 1.0f);
1151                                                 data->shadow_color[3] = 1.0f;
1152                                         }
1153                                 }
1154                         }
1155                         SEQ_END
1156                 }
1157
1158                 /* Adding "Properties" region to DopeSheet */
1159                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1160                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1161                                 /* handle pushed-back space data first */
1162                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1163                                         if (sl->spacetype == SPACE_ACTION) {
1164                                                 SpaceAction *saction = (SpaceAction *)sl;
1165                                                 do_version_action_editor_properties_region(&saction->regionbase);
1166                                         }
1167                                 }
1168                                 
1169                                 /* active spacedata info must be handled too... */
1170                                 if (sa->spacetype == SPACE_ACTION) {
1171                                         do_version_action_editor_properties_region(&sa->regionbase);
1172                                 }
1173                         }
1174                 }
1175         }
1176
1177         if (!MAIN_VERSION_ATLEAST(main, 277, 2)) {
1178                 if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "scaleIn")) {
1179                         for (bArmature *arm = main->armature.first; arm; arm = arm->id.next) {
1180                                 do_version_bones_super_bbone(&arm->bonebase);
1181                         }
1182                 }
1183                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "scaleIn")) {
1184                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1185                                 if (ob->pose) {
1186                                         for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1187                                                 /* see do_version_bones_super_bbone()... */
1188                                                 pchan->scaleIn = 1.0f;
1189                                                 pchan->scaleOut = 1.0f;
1190                                                 
1191                                                 /* also make sure some legacy (unused for over a decade) flags are unset,
1192                                                  * so that we can reuse them for stuff that matters now...
1193                                                  * (i.e. POSE_IK_MAT, (unknown/unused x 4), POSE_HAS_IK)
1194                                                  *
1195                                                  * These seem to have been runtime flags used by the IK solver, but that stuff
1196                                                  * should be able to be recalculated automatically anyway, so it should be fine.
1197                                                  */
1198                                                 pchan->flag &= ~((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8));
1199                                         }
1200                                 }
1201                         }
1202                 }
1203
1204                 for (Camera *camera = main->camera.first; camera != NULL; camera = camera->id.next) {
1205                         if (camera->stereo.pole_merge_angle_from == 0.0f &&
1206                                 camera->stereo.pole_merge_angle_to == 0.0f)
1207                         {
1208                                 camera->stereo.pole_merge_angle_from = DEG2RADF(60.0f);
1209                                 camera->stereo.pole_merge_angle_to = DEG2RADF(75.0f);
1210                         }
1211                 }
1212
1213                 if (!DNA_struct_elem_find(fd->filesdna, "NormalEditModifierData", "float", "mix_limit")) {
1214                         Object *ob;
1215
1216                         for (ob = main->object.first; ob; ob = ob->id.next) {
1217                                 ModifierData *md;
1218                                 for (md = ob->modifiers.first; md; md = md->next) {
1219                                         if (md->type == eModifierType_NormalEdit) {
1220                                                 NormalEditModifierData *nemd = (NormalEditModifierData *)md;
1221                                                 nemd->mix_limit = DEG2RADF(180.0f);
1222                                         }
1223                                 }
1224                         }
1225                 }
1226
1227                 if (!DNA_struct_elem_find(fd->filesdna, "BooleanModifierData", "float", "double_threshold")) {
1228                         Object *ob;
1229                         for (ob = main->object.first; ob; ob = ob->id.next) {
1230                                 ModifierData *md;
1231                                 for (md = ob->modifiers.first; md; md = md->next) {
1232                                         if (md->type == eModifierType_Boolean) {
1233                                                 BooleanModifierData *bmd = (BooleanModifierData *)md;
1234                                                 bmd->double_threshold = 1e-6f;
1235                                         }
1236                                 }
1237                         }
1238                 }
1239
1240                 for (Brush *br = main->brush.first; br; br = br->id.next) {
1241                         if (br->sculpt_tool == SCULPT_TOOL_FLATTEN) {
1242                                 br->flag |= BRUSH_ACCUMULATE;
1243                         }
1244                 }
1245
1246                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "time_scale")) {
1247                         Object *ob;
1248                         ModifierData *md;
1249                         for (ob = main->object.first; ob; ob = ob->id.next) {
1250                                 for (md = ob->modifiers.first; md; md = md->next) {
1251                                         if (md->type == eModifierType_Cloth) {
1252                                                 ClothModifierData *clmd = (ClothModifierData *)md;
1253                                                 clmd->sim_parms->time_scale = 1.0f;
1254                                         }
1255                                         else if (md->type == eModifierType_ParticleSystem) {
1256                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
1257                                                 if (pmd->psys->clmd) {
1258                                                         pmd->psys->clmd->sim_parms->time_scale = 1.0f;
1259                                                 }
1260                                         }
1261                                 }
1262                         }
1263                 }
1264         }
1265
1266         if (!MAIN_VERSION_ATLEAST(main, 277, 3)) {
1267                 /* ------- init of grease pencil initialization --------------- */
1268                 if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) {
1269                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1270                                 ToolSettings *ts = scene->toolsettings;
1271                                 /* initialize use position for sculpt brushes */
1272                                 ts->gp_sculpt.flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION;
1273                                 /* initialize  selected vertices alpha factor */
1274                                 ts->gp_sculpt.alpha = 1.0f;
1275
1276                                 /* new strength sculpt brush */
1277                                 if (ts->gp_sculpt.brush[0].size >= 11) {
1278                                         GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
1279                                         GP_EditBrush_Data *brush;
1280
1281                                         brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
1282                                         brush->size = 25;
1283                                         brush->strength = 0.5f;
1284                                         brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1285                                 }
1286                         }
1287                         /* create a default grease pencil drawing brushes set */
1288                         if (!BLI_listbase_is_empty(&main->gpencil)) {
1289                                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1290                                         ToolSettings *ts = scene->toolsettings;
1291                                         if (BLI_listbase_is_empty(&ts->gp_brushes)) {
1292                                                 BKE_gpencil_brush_init_presets(ts);
1293                                         }
1294                                 }
1295                         }
1296                         /* Convert Grease Pencil to new palettes/brushes
1297                          * Loop all strokes and create the palette and all colors
1298                          */
1299                         for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1300                                 if (BLI_listbase_is_empty(&gpd->palettes)) {
1301                                         /* create palette */
1302                                         bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette", true);
1303                                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1304                                                 /* create color using layer name */
1305                                                 bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info, true);
1306                                                 if (palcolor != NULL) {
1307                                                         /* set color attributes */
1308                                                         copy_v4_v4(palcolor->color, gpl->color);
1309                                                         copy_v4_v4(palcolor->fill, gpl->fill);
1310                                                         
1311                                                         if (gpl->flag & GP_LAYER_HIDE)       palcolor->flag |= PC_COLOR_HIDE;
1312                                                         if (gpl->flag & GP_LAYER_LOCKED)     palcolor->flag |= PC_COLOR_LOCKED;
1313                                                         if (gpl->flag & GP_LAYER_ONIONSKIN)  palcolor->flag |= PC_COLOR_ONIONSKIN;
1314                                                         if (gpl->flag & GP_LAYER_VOLUMETRIC) palcolor->flag |= PC_COLOR_VOLUMETRIC;
1315                                                         if (gpl->flag & GP_LAYER_HQ_FILL)    palcolor->flag |= PC_COLOR_HQ_FILL;
1316                                                         
1317                                                         /* set layer opacity to 1 */
1318                                                         gpl->opacity = 1.0f;
1319                                                         
1320                                                         /* set tint color */
1321                                                         ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f);
1322                                                         
1323                                                         /* flush relevant layer-settings to strokes */
1324                                                         for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
1325                                                                 for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
1326                                                                         /* set stroke to palette and force recalculation */
1327                                                                         BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname));
1328                                                                         gps->palcolor = NULL;
1329                                                                         gps->flag |= GP_STROKE_RECALC_COLOR;
1330                                                                         gps->thickness = gpl->thickness;
1331                                                                         
1332                                                                         /* set alpha strength to 1 */
1333                                                                         for (int i = 0; i < gps->totpoints; i++) {
1334                                                                                 gps->points[i].strength = 1.0f;
1335                                                                         }
1336                                                                 }
1337                                                         }
1338                                                 }
1339                                                 
1340                                                 /* set thickness to 0 (now it is a factor to override stroke thickness) */
1341                                                 gpl->thickness = 0.0f;
1342                                         }
1343                                         /* set first color as active */
1344                                         if (palette->colors.first)
1345                                                 BKE_gpencil_palettecolor_setactive(palette, palette->colors.first);
1346                                 }
1347                         }
1348                 }
1349                 /* ------- end of grease pencil initialization --------------- */
1350         }
1351
1352         if (!MAIN_VERSION_ATLEAST(main, 278, 0)) {
1353                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) {
1354                         MovieClip *clip;
1355                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
1356                                 MovieTracking *tracking = &clip->tracking;
1357                                 MovieTrackingObject *tracking_object;
1358                                 for (tracking_object = tracking->objects.first;
1359                                      tracking_object != NULL;
1360                                      tracking_object = tracking_object->next)
1361                                 {
1362                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
1363                                         MovieTrackingTrack *track;
1364                                         for (track = tracksbase->first;
1365                                              track != NULL;
1366                                              track = track->next)
1367                                         {
1368                                                 track->weight_stab = track->weight;
1369                                         }
1370                                 }
1371                         }
1372                 }
1373
1374                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) {
1375                         MovieClip *clip;
1376                         for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) {
1377                                 if (clip->tracking.stabilization.rot_track) {
1378                                         migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization);
1379                                 }
1380                                 if (clip->tracking.stabilization.scale == 0.0f) {
1381                                         /* ensure init.
1382                                          * Was previously used for autoscale only,
1383                                          * now used always (as "target scale") */
1384                                         clip->tracking.stabilization.scale = 1.0f;
1385                                 }
1386                                 /* blender prefers 1-based frame counting;
1387                                  * thus using frame 1 as reference typically works best */
1388                                 clip->tracking.stabilization.anchor_frame = 1;
1389                                 /* by default show the track lists expanded, to improve "discoverability" */
1390                                 clip->tracking.stabilization.flag |= TRACKING_SHOW_STAB_TRACKS;
1391                                 /* deprecated, not used anymore */
1392                                 clip->tracking.stabilization.ok = false;
1393                         }
1394                 }
1395         }
1396         if (!MAIN_VERSION_ATLEAST(main, 279, 0)) {
1397                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "ffmpeg_preset")) {
1398                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1399                                 /* "medium" is the preset FFmpeg uses when no presets are given. */
1400                                 scene->r.ffcodecdata.ffmpeg_preset = FFM_PRESET_MEDIUM;
1401                         }
1402                 }
1403                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "constant_rate_factor")) {
1404                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1405                                 /* fall back to behaviour from before we introduced CRF for old files */
1406                                 scene->r.ffcodecdata.constant_rate_factor = FFM_CRF_NONE;
1407                         }
1408                 }
1409
1410                 if (!DNA_struct_elem_find(fd->filesdna, "SmokeModifierData", "float", "slice_per_voxel")) {
1411                         Object *ob;
1412                         ModifierData *md;
1413
1414                         for (ob = main->object.first; ob; ob = ob->id.next) {
1415                                 for (md = ob->modifiers.first; md; md = md->next) {
1416                                         if (md->type == eModifierType_Smoke) {
1417                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1418                                                 if (smd->domain) {
1419                                                         smd->domain->slice_per_voxel = 5.0f;
1420                                                         smd->domain->slice_depth = 0.5f;
1421                                                         smd->domain->display_thickness = 1.0f;
1422                                                 }
1423                                         }
1424                                 }
1425                         }
1426                 }
1427         }
1428
1429         {
1430                 for (Scene *scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1431                         if (scene->toolsettings != NULL) {
1432                                 ToolSettings *ts = scene->toolsettings;
1433                                 ParticleEditSettings *pset = &ts->particle;
1434                                 for (int a = 0; a < PE_TOT_BRUSH; a++) {
1435                                         if (pset->brush[a].count == 0) {
1436                                                 pset->brush[a].count = 10;
1437                                         }
1438                                 }
1439                         }
1440                 }
1441         }
1442 }