Moved function declarations from BKE_DerivedMesh.h to BKE_mesh_runtime.h
[blender.git] / source / blender / blenloader / intern / versioning_270.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  *
22  */
23
24 /** \file blender/blenloader/intern/versioning_270.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29 #include "BLI_compiler_attrs.h"
30
31 /* for MinGW32 definition of NULL, could use BLI_blenlib.h instead too */
32 #include <stddef.h>
33
34 /* allow readfile to use deprecated functionality */
35 #define DNA_DEPRECATED_ALLOW
36
37 #include "DNA_anim_types.h"
38 #include "DNA_armature_types.h"
39 #include "DNA_brush_types.h"
40 #include "DNA_camera_types.h"
41 #include "DNA_cloth_types.h"
42 #include "DNA_constraint_types.h"
43 #include "DNA_gpencil_types.h"
44 #include "DNA_sdna_types.h"
45 #include "DNA_sequence_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_object_force_types.h"
49 #include "DNA_object_types.h"
50 #include "DNA_mask_types.h"
51 #include "DNA_mesh_types.h"
52 #include "DNA_modifier_types.h"
53 #include "DNA_particle_types.h"
54 #include "DNA_linestyle_types.h"
55 #include "DNA_view3d_types.h"
56 #include "DNA_smoke_types.h"
57 #include "DNA_rigidbody_types.h"
58
59 #include "DNA_genfile.h"
60
61 #include "BKE_animsys.h"
62 #include "BKE_brush.h"
63 #include "BKE_colortools.h"
64 #include "BKE_fcurve.h"
65 #include "BKE_gpencil.h"
66 #include "BKE_library.h"
67 #include "BKE_main.h"
68 #include "BKE_mask.h"
69 #include "BKE_modifier.h"
70 #include "BKE_node.h"
71 #include "BKE_scene.h"
72 #include "BKE_sequencer.h"
73 #include "BKE_screen.h"
74 #include "BKE_tracking.h"
75
76 #include "BLI_math.h"
77 #include "BLI_listbase.h"
78 #include "BLI_string.h"
79
80 #include "BLO_readfile.h"
81
82 #include "NOD_common.h"
83 #include "NOD_socket.h"
84 #include "NOD_composite.h"
85
86 #include "readfile.h"
87
88 #include "MEM_guardedalloc.h"
89
90 /**
91  * Setup rotation stabilization from ancient single track spec.
92  * Former Version of 2D stabilization used a single tracking marker to determine the rotation
93  * to be compensated. Now several tracks can contribute to rotation detection and this feature
94  * is enabled by the MovieTrackingTrack#flag on a per track base.
95  */
96 static void migrate_single_rot_stabilization_track_settings(MovieTrackingStabilization *stab)
97 {
98         if (stab->rot_track) {
99                 if (!(stab->rot_track->flag & TRACK_USE_2D_STAB_ROT)) {
100                         stab->tot_rot_track++;
101                         stab->rot_track->flag |= TRACK_USE_2D_STAB_ROT;
102                 }
103         }
104         stab->rot_track = NULL; /* this field is now ignored */
105 }
106
107 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
108 {
109         bConstraint *con;
110
111         for (con = lb->first; con; con = con->next) {
112                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
113                         bTransformConstraint *data = (bTransformConstraint *)con->data;
114                         const float deg_to_rad_f = DEG2RADF(1.0f);
115
116                         if (data->from == TRANS_ROTATION) {
117                                 mul_v3_fl(data->from_min, deg_to_rad_f);
118                                 mul_v3_fl(data->from_max, deg_to_rad_f);
119                         }
120
121                         if (data->to == TRANS_ROTATION) {
122                                 mul_v3_fl(data->to_min, deg_to_rad_f);
123                                 mul_v3_fl(data->to_max, deg_to_rad_f);
124                         }
125                 }
126         }
127 }
128
129 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
130 {
131         bConstraint *con;
132
133         for (con = lb->first; con; con = con->next) {
134                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
135                         bTransformConstraint *data = (bTransformConstraint *)con->data;
136
137                         if (data->from == TRANS_ROTATION) {
138                                 copy_v3_v3(data->from_min_rot, data->from_min);
139                                 copy_v3_v3(data->from_max_rot, data->from_max);
140                         }
141                         else if (data->from == TRANS_SCALE) {
142                                 copy_v3_v3(data->from_min_scale, data->from_min);
143                                 copy_v3_v3(data->from_max_scale, data->from_max);
144                         }
145
146                         if (data->to == TRANS_ROTATION) {
147                                 copy_v3_v3(data->to_min_rot, data->to_min);
148                                 copy_v3_v3(data->to_max_rot, data->to_max);
149                         }
150                         else if (data->to == TRANS_SCALE) {
151                                 copy_v3_v3(data->to_min_scale, data->to_min);
152                                 copy_v3_v3(data->to_max_scale, data->to_max);
153                         }
154                 }
155         }
156 }
157
158 static void do_version_constraints_stretch_to_limits(ListBase *lb)
159 {
160         bConstraint *con;
161
162         for (con = lb->first; con; con = con->next) {
163                 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
164                         bStretchToConstraint *data = (bStretchToConstraint *)con->data;
165                         data->bulge_min = 1.0f;
166                         data->bulge_max = 1.0f;
167                 }
168         }
169 }
170
171 static void do_version_action_editor_properties_region(ListBase *regionbase)
172 {
173         ARegion *ar;
174         
175         for (ar = regionbase->first; ar; ar = ar->next) {
176                 if (ar->regiontype == RGN_TYPE_UI) {
177                         /* already exists */
178                         return;
179                 }
180                 else if (ar->regiontype == RGN_TYPE_WINDOW) {
181                         /* add new region here */
182                         ARegion *arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
183                         
184                         BLI_insertlinkbefore(regionbase, ar, arnew);
185                         
186                         arnew->regiontype = RGN_TYPE_UI;
187                         arnew->alignment = RGN_ALIGN_RIGHT;
188                         arnew->flag = RGN_FLAG_HIDDEN;
189                         
190                         return;
191                 }
192         }
193 }
194
195 static void do_version_bones_super_bbone(ListBase *lb)
196 {
197         for (Bone *bone = lb->first; bone; bone = bone->next) {
198                 bone->scaleIn = 1.0f;
199                 bone->scaleOut = 1.0f;
200                 
201                 do_version_bones_super_bbone(&bone->childbase);
202         }
203 }
204
205 /* TODO(sergey): Consider making it somewhat more generic function in BLI_anim.h. */
206 static void anim_change_prop_name(FCurve *fcu,
207                                   const char *prefix,
208                                   const char *old_prop_name,
209                                   const char *new_prop_name)
210 {
211         const char *old_path = BLI_sprintfN("%s.%s", prefix, old_prop_name);
212         if (STREQ(fcu->rna_path, old_path)) {
213                 MEM_freeN(fcu->rna_path);
214                 fcu->rna_path = BLI_sprintfN("%s.%s", prefix, new_prop_name);
215         }
216         MEM_freeN((char *)old_path);
217 }
218
219 static void do_version_hue_sat_node(bNodeTree *ntree, bNode *node)
220 {
221         if (node->storage == NULL) {
222                 return;
223         }
224
225         /* Make sure new sockets are properly created. */
226         node_verify_socket_templates(ntree, node);
227         /* Convert value from old storage to new sockets. */
228         NodeHueSat *nhs = node->storage;
229         bNodeSocket *hue = nodeFindSocket(node, SOCK_IN, "Hue"),
230                     *saturation = nodeFindSocket(node, SOCK_IN, "Saturation"),
231                     *value = nodeFindSocket(node, SOCK_IN, "Value");
232         ((bNodeSocketValueFloat *)hue->default_value)->value = nhs->hue;
233         ((bNodeSocketValueFloat *)saturation->default_value)->value = nhs->sat;
234         ((bNodeSocketValueFloat *)value->default_value)->value = nhs->val;
235         /* Take care of possible animation. */
236         AnimData *adt = BKE_animdata_from_id(&ntree->id);
237         if (adt != NULL && adt->action != NULL) {
238                 const char *prefix = BLI_sprintfN("nodes[\"%s\"]", node->name);
239                 for (FCurve *fcu = adt->action->curves.first; fcu != NULL; fcu = fcu->next) {
240                         if (STRPREFIX(fcu->rna_path, prefix)) {
241                                 anim_change_prop_name(fcu, prefix, "color_hue", "inputs[1].default_value");
242                                 anim_change_prop_name(fcu, prefix, "color_saturation", "inputs[2].default_value");
243                                 anim_change_prop_name(fcu, prefix, "color_value", "inputs[3].default_value");
244                         }
245                 }
246                 MEM_freeN((char *)prefix);
247         }
248         /* Free storage, it is no longer used. */
249         MEM_freeN(node->storage);
250         node->storage = NULL;
251 }
252
253 static void do_versions_compositor_render_passes_storage(bNode *node)
254 {
255         int pass_index = 0;
256         const char *sockname;
257         for (bNodeSocket *sock = node->outputs.first; sock && pass_index < 31; sock = sock->next, pass_index++) {
258                 if (sock->storage == NULL) {
259                         NodeImageLayer *sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer");
260                         sock->storage = sockdata;
261                         BLI_strncpy(sockdata->pass_name, node_cmp_rlayers_sock_to_pass(pass_index), sizeof(sockdata->pass_name));
262
263                         if (pass_index == 0) sockname = "Image";
264                         else if (pass_index == 1) sockname = "Alpha";
265                         else sockname = node_cmp_rlayers_sock_to_pass(pass_index);
266                         BLI_strncpy(sock->name, sockname, sizeof(sock->name));
267                 }
268         }
269 }
270
271 static void do_versions_compositor_render_passes(bNodeTree *ntree)
272 {
273         for (bNode *node = ntree->nodes.first; node; node = node->next) {
274                 if (node->type == CMP_NODE_R_LAYERS) {
275                         /* First we make sure existing sockets have proper names.
276                          * This is important because otherwise verification will
277                          * drop links from sockets which were renamed.
278                          */
279                         do_versions_compositor_render_passes_storage(node);
280                         /* Make sure new sockets are properly created. */
281                         node_verify_socket_templates(ntree, node);
282                         /* Make sure all possibly created sockets have proper storage. */
283                         do_versions_compositor_render_passes_storage(node);
284                 }
285         }
286 }
287
288
289 static char *replace_bbone_easing_rnapath(char *old_path)
290 {
291         char *new_path = NULL;
292         
293         /* NOTE: This will break paths for any bones/custom-properties
294          * which happen be named after the bbone property id's
295          */
296         if (strstr(old_path, "bbone_in"))
297                 new_path = BLI_str_replaceN(old_path, "bbone_in", "bbone_easein");
298         else if (strstr(old_path, "bbone_out"))
299                 new_path = BLI_str_replaceN(old_path, "bbone_out", "bbone_easeout");
300         
301         if (new_path) {
302                 MEM_freeN(old_path);
303                 return new_path;
304         }
305         else {
306                 return old_path;
307         }
308 }
309
310 static void do_version_bbone_easing_fcurve_fix(ID *UNUSED(id), FCurve *fcu, void *UNUSED(user_data))
311 {
312         /* F-Curve's path (for bbone_in/out) */
313         if (fcu->rna_path) {
314                 fcu->rna_path = replace_bbone_easing_rnapath(fcu->rna_path);
315         }
316         
317         /* Driver -> Driver Vars (for bbone_in/out) */
318         if (fcu->driver) {
319                 for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) {
320                         DRIVER_TARGETS_LOOPER(dvar)
321                         {
322                                 if (dtar->rna_path) {
323                                         dtar->rna_path = replace_bbone_easing_rnapath(dtar->rna_path);
324                                 }
325                         }
326                         DRIVER_TARGETS_LOOPER_END;
327                 }
328         }
329         
330         /* FModifiers -> Stepped (for frame_start/end) */
331         if (fcu->modifiers.first) {
332                 for (FModifier *fcm = fcu->modifiers.first; fcm; fcm = fcm->next) {
333                         if (fcm->type == FMODIFIER_TYPE_STEPPED) {
334                                 FMod_Stepped *data = fcm->data;
335                                 
336                                 /* Modifier doesn't work if the modifier's copy of start/end frame are both 0
337                                  * as those were only getting written to the fcm->data copy (T52009)
338                                  */
339                                 if ((fcm->sfra == fcm->efra) && (fcm->sfra == 0)) {
340                                         fcm->sfra = data->start_frame;
341                                         fcm->efra = data->end_frame;
342                                 }
343                         }
344                 }
345         }
346 }
347
348
349 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
350 {
351         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
352
353                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
354                         Object *ob;
355
356                         for (ob = main->object.first; ob; ob = ob->id.next) {
357                                 ModifierData *md;
358                                 for (md = ob->modifiers.first; md; md = md->next) {
359                                         if (md->type == eModifierType_Bevel) {
360                                                 BevelModifierData *bmd = (BevelModifierData *)md;
361                                                 bmd->profile = 0.5f;
362                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
363                                         }
364                                 }
365                         }
366                 }
367
368                 /* nodes don't use fixed node->id any more, clean up */
369                 FOREACH_NODETREE(main, ntree, id) {
370                         if (ntree->type == NTREE_COMPOSIT) {
371                                 bNode *node;
372                                 for (node = ntree->nodes.first; node; node = node->next) {
373                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
374                                                 node->id = NULL;
375                                         }
376                                 }
377                         }
378                 } FOREACH_NODETREE_END
379
380                 {
381                         bScreen *screen;
382
383                         for (screen = main->screen.first; screen; screen = screen->id.next) {
384                                 ScrArea *area;
385                                 for (area = screen->areabase.first; area; area = area->next) {
386                                         SpaceLink *space_link;
387                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
388                                                 if (space_link->spacetype == SPACE_CLIP) {
389                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
390                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
391                                                                 space_clip->mode = SC_MODE_TRACKING;
392                                                         }
393                                                 }
394                                         }
395                                 }
396                         }
397                 }
398
399                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
400                         MovieClip *clip;
401                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
402                                 clip->tracking.settings.default_weight = 1.0f;
403                         }
404                 }
405         }
406
407         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
408                 Object *ob;
409
410                 /* Update Transform constraint (another deg -> rad stuff). */
411                 for (ob = main->object.first; ob; ob = ob->id.next) {
412                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
413
414                         if (ob->pose) {
415                                 /* Bones constraints! */
416                                 bPoseChannel *pchan;
417                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
418                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
419                                 }
420                         }
421                 }
422         }
423
424         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
425                 Mesh *me;
426
427                 /* Mesh smoothresh deg->rad. */
428                 for (me = main->mesh.first; me; me = me->id.next) {
429                         me->smoothresh = DEG2RADF(me->smoothresh);
430                 }
431         }
432
433         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
434                 FreestyleLineStyle *linestyle;
435
436                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
437                         linestyle->flag |= LS_NO_SORTING;
438                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
439                         linestyle->integration_type = LS_INTEGRATION_MEAN;
440                 }
441         }
442
443         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
444                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
445                  * This will always reset situation to a valid state.
446                  */
447                 bScreen *sc;
448
449                 for (sc = main->screen.first; sc; sc = sc->id.next) {
450                         ScrArea *sa;
451                         for (sa = sc->areabase.first; sa; sa = sa->next) {
452                                 SpaceLink *sl;
453
454                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
455                                         ARegion *ar;
456                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
457
458                                         for (ar = lb->first; ar; ar = ar->next) {
459                                                 BLI_listbase_clear(&ar->ui_previews);
460                                         }
461                                 }
462                         }
463                 }
464         }
465
466         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
467                 Object *ob;
468
469                 /* Update Transform constraint (again :|). */
470                 for (ob = main->object.first; ob; ob = ob->id.next) {
471                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
472
473                         if (ob->pose) {
474                                 /* Bones constraints! */
475                                 bPoseChannel *pchan;
476                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
477                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
478                                 }
479                         }
480                 }
481         }
482
483         if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
484                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
485                         Scene *sce;
486
487                         for (sce = main->scene.first; sce; sce = sce->id.next) {
488                                 sce->r.bake.flag = R_BAKE_CLEAR;
489                                 sce->r.bake.width = 512;
490                                 sce->r.bake.height = 512;
491                                 sce->r.bake.margin = 16;
492                                 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
493                                 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
494                                 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
495                                 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
496                                 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
497
498                                 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
499                                 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
500                                 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
501                                 sce->r.bake.im_format.quality = 90;
502                                 sce->r.bake.im_format.compress = 15;
503                         }
504                 }
505
506                 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
507                         FreestyleLineStyle *linestyle;
508
509                         for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
510                                 linestyle->flag |= LS_TEXTURE;
511                                 linestyle->texstep = 1.0;
512                         }
513                 }
514
515                 {
516                         Scene *scene;
517                         for (scene = main->scene.first; scene; scene = scene->id.next) {
518                                 int num_layers = BLI_listbase_count(&scene->r.layers);
519                                 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
520                         }
521                 }
522         }
523
524         if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
525                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
526                         Material *mat;
527
528                         for (mat = main->mat.first; mat; mat = mat->id.next) {
529                                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
530                                 mat->line_col[3] = mat->alpha;
531                         }
532                 }
533
534                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
535                         Scene *scene;
536                         for (scene = main->scene.first; scene; scene = scene->id.next) {
537                                 scene->r.preview_start_resolution = 64;
538                         }
539                 }
540         }
541
542         if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
543                 Brush *br;
544
545                 for (br = main->brush.first; br; br = br->id.next) {
546                         br->fill_threshold = 0.2f;
547                 }
548
549                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
550                         Object *ob;
551                         for (ob = main->object.first; ob; ob = ob->id.next) {
552                                 ModifierData *md;
553
554                                 for (md = ob->modifiers.first; md; md = md->next) {
555                                         if (md->type == eModifierType_Bevel) {
556                                                 BevelModifierData *bmd = (BevelModifierData *)md;
557                                                 bmd->mat = -1;
558                                         }
559                                 }
560                         }
561                 }
562         }
563
564         if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
565                 Object *ob;
566                 for (ob = main->object.first; ob; ob = ob->id.next) {
567                         ModifierData *md;
568
569                         for (md = ob->modifiers.first; md; md = md->next) {
570                                 if (md->type == eModifierType_ParticleSystem) {
571                                         ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
572                                         if (pmd->psys && pmd->psys->clmd) {
573                                                 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
574                                         }
575                                 }
576                         }
577                 }
578         }
579
580         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
581                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
582                         Scene *scene;
583                         for (scene = main->scene.first; scene; scene = scene->id.next) {
584                                 scene->r.preview_start_resolution = 64;
585                         }
586                 }
587         }
588
589         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
590                 Brush *br;
591                 for (br = main->brush.first; br; br = br->id.next) {
592                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
593                                 br->alpha = 1.0f;
594                 }
595         }
596
597         if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
598                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
599                         Image *image;
600                         for (image = main->image.first; image != NULL; image = image->id.next) {
601                                 image->gen_color[3] = 1.0f;
602                         }
603                 }
604
605                 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
606                         Object *ob;
607
608                         /* Update Transform constraint (again :|). */
609                         for (ob = main->object.first; ob; ob = ob->id.next) {
610                                 do_version_constraints_stretch_to_limits(&ob->constraints);
611
612                                 if (ob->pose) {
613                                         /* Bones constraints! */
614                                         bPoseChannel *pchan;
615                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
616                                                 do_version_constraints_stretch_to_limits(&pchan->constraints);
617                                         }
618                                 }
619                         }
620                 }
621         }
622
623         if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
624 #define BRUSH_RAKE (1 << 7)
625 #define BRUSH_RANDOM_ROTATION (1 << 25)
626
627                 Brush *br;
628
629                 for (br = main->brush.first; br; br = br->id.next) {
630                         if (br->flag & BRUSH_RAKE) {
631                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
632                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
633                         }
634                         else if (br->flag & BRUSH_RANDOM_ROTATION) {
635                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
636                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
637                         }
638                         br->mtex.random_angle = 2.0 * M_PI;
639                         br->mask_mtex.random_angle = 2.0 * M_PI;
640                 }
641         }
642
643 #undef BRUSH_RAKE
644 #undef BRUSH_RANDOM_ROTATION
645
646         /* Customizable Safe Areas */
647         if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
648                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
649                         Scene *scene;
650
651                         for (scene = main->scene.first; scene; scene = scene->id.next) {
652                                 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
653                                 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
654                                 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
655                                 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
656                         }
657                 }
658         }
659         
660         if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
661                 ParticleSettings *part;
662                 for (part = main->particle.first; part; part = part->id.next) {
663                         if (part->clumpcurve)
664                                 part->child_flag |= PART_CHILD_USE_CLUMP_CURVE;
665                         if (part->roughcurve)
666                                 part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
667                 }
668         }
669
670         if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
671                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
672                         Object *ob;
673                         ModifierData *md;
674                         for (ob = main->object.first; ob; ob = ob->id.next) {
675                                 for (md = ob->modifiers.first; md; md = md->next) {
676                                         if (md->type == eModifierType_Cloth) {
677                                                 ClothModifierData *clmd = (ClothModifierData *)md;
678                                                 clmd->sim_parms->bending_damping = 0.5f;
679                                         }
680                                         else if (md->type == eModifierType_ParticleSystem) {
681                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
682                                                 if (pmd->psys->clmd) {
683                                                         pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
684                                                 }
685                                         }
686                                 }
687                         }
688                 }
689
690                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "float", "clump_noise_size")) {
691                         ParticleSettings *part;
692                         for (part = main->particle.first; part; part = part->id.next) {
693                                 part->clump_noise_size = 1.0f;
694                         }
695                 }
696
697                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "int", "kink_extra_steps")) {
698                         ParticleSettings *part;
699                         for (part = main->particle.first; part; part = part->id.next) {
700                                 part->kink_extra_steps = 4;
701                         }
702                 }
703
704                 if (!DNA_struct_elem_find(fd->filesdna, "MTex", "float", "kinkampfac")) {
705                         ParticleSettings *part;
706                         for (part = main->particle.first; part; part = part->id.next) {
707                                 int a;
708                                 for (a = 0; a < MAX_MTEX; a++) {
709                                         MTex *mtex = part->mtex[a];
710                                         if (mtex) {
711                                                 mtex->kinkampfac = 1.0f;
712                                         }
713                                 }
714                         }
715                 }
716
717                 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
718                         Object *ob;
719
720                         for (ob = main->object.first; ob; ob = ob->id.next) {
721                                 ModifierData *md;
722                                 for (md = ob->modifiers.first; md; md = md->next) {
723                                         if (md->type == eModifierType_Hook) {
724                                                 HookModifierData *hmd = (HookModifierData *)md;
725                                                 hmd->falloff_type = eHook_Falloff_InvSquare;
726                                         }
727                                 }
728                         }
729                 }
730
731                 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
732                         FOREACH_NODETREE(main, ntree, id) {
733                                 if (ntree->type == NTREE_COMPOSIT) {
734                                         bNode *node;
735                                         for (node = ntree->nodes.first; node; node = node->next) {
736                                                 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
737                                                         NodePlaneTrackDeformData *data = node->storage;
738                                                         data->flag = 0;
739                                                         data->motion_blur_samples = 16;
740                                                         data->motion_blur_shutter = 0.5f;
741                                                 }
742                                         }
743                                 }
744                         }
745                         FOREACH_NODETREE_END
746                 }
747
748                 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
749                         Camera *ca;
750                         for (ca = main->camera.first; ca; ca = ca->id.next) {
751                                 ca->gpu_dof.fstop = 128.0f;
752                                 ca->gpu_dof.focal_length = 1.0f;
753                                 ca->gpu_dof.focus_distance = 1.0f;
754                                 ca->gpu_dof.sensor = 1.0f;
755                         }
756                 }
757         }
758
759         if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
760                 Object *ob;
761                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
762                         ModifierData *md;
763                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
764                                 if (modifier_unique_name(&ob->modifiers, md)) {
765                                         printf("Warning: Object '%s' had several modifiers with the "
766                                                "same name, renamed one of them to '%s'.\n",
767                                                ob->id.name + 2, md->name);
768                                 }
769                         }
770                 }
771         }
772
773         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
774                 bScreen *scr;
775                 ScrArea *sa;
776                 SpaceLink *sl;
777                 ARegion *ar;
778
779                 /* Make sure sequencer preview area limits zoom */
780                 for (scr = main->screen.first; scr; scr = scr->id.next) {
781                         for (sa = scr->areabase.first; sa; sa = sa->next) {
782                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
783                                         if (sl->spacetype == SPACE_SEQ) {
784                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
785                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
786                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
787                                                                 ar->v2d.minzoom = 0.001f;
788                                                                 ar->v2d.maxzoom = 1000.0f;
789                                                                 break;
790                                                         }
791                                                 }
792                                         }
793                                 }
794                         }
795                 }
796         }
797
798         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
799                 /* particle systems need to be forced to redistribute for jitter mode fix */
800                 {
801                         Object *ob;
802                         ParticleSystem *psys;
803                         for (ob = main->object.first; ob; ob = ob->id.next) {
804                                 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
805                                         if ((psys->pointcache->flag & PTCACHE_BAKED) == 0) {
806                                                 psys->recalc |= PSYS_RECALC_RESET;
807                                         }
808                                 }
809                         }
810                 }
811
812                 /* hysteresis setted to 10% but not actived */
813                 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
814                         Object *ob;
815                         for (ob = main->object.first; ob; ob = ob->id.next) {
816                                 LodLevel *level;
817                                 for (level = ob->lodlevels.first; level; level = level->next) {
818                                         level->obhysteresis = 10;
819                                 }
820                         }
821                 }
822         }
823
824         if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
825                 SceneRenderView *srv;
826                 wmWindowManager *wm;
827                 bScreen *screen;
828                 wmWindow *win;
829                 Scene *scene;
830                 Camera *cam;
831                 Image *ima;
832
833                 for (scene = main->scene.first; scene; scene = scene->id.next) {
834                         Sequence *seq;
835
836                         BKE_scene_add_render_view(scene, STEREO_LEFT_NAME);
837                         srv = scene->r.views.first;
838                         BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
839
840                         BKE_scene_add_render_view(scene, STEREO_RIGHT_NAME);
841                         srv = scene->r.views.last;
842                         BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
843
844                         SEQ_BEGIN (scene->ed, seq)
845                         {
846                                 seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
847
848 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
849 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
850                                 if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) {
851                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
852                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
853                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
854                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
855                                 }
856 #undef SEQ_USE_PROXY_CUSTOM_DIR
857 #undef SEQ_USE_PROXY_CUSTOM_FILE
858
859                         }
860                         SEQ_END
861                 }
862
863                 for (screen = main->screen.first; screen; screen = screen->id.next) {
864                         ScrArea *sa;
865                         for (sa = screen->areabase.first; sa; sa = sa->next) {
866                                 SpaceLink *sl;
867
868                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
869                                         switch (sl->spacetype) {
870                                                 case SPACE_VIEW3D:
871                                                 {
872                                                         View3D *v3d = (View3D *)sl;
873                                                         v3d->stereo3d_camera = STEREO_3D_ID;
874                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
875                                                         v3d->stereo3d_convergence_alpha = 0.15f;
876                                                         v3d->stereo3d_volume_alpha = 0.05f;
877                                                         break;
878                                                 }
879                                                 case SPACE_IMAGE:
880                                                 {
881                                                         SpaceImage *sima = (SpaceImage *) sl;
882                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
883                                                         break;
884                                                 }
885                                         }
886                                 }
887                         }
888                 }
889
890                 for (cam = main->camera.first; cam; cam = cam->id.next) {
891                         cam->stereo.interocular_distance = 0.065f;
892                         cam->stereo.convergence_distance = 30.0f * 0.065f;
893                 }
894
895                 for (ima = main->image.first; ima; ima = ima->id.next) {
896                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
897
898                         if (ima->packedfile) {
899                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
900                                 BLI_addtail(&ima->packedfiles, imapf);
901
902                                 imapf->packedfile = ima->packedfile;
903                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
904                                 ima->packedfile = NULL;
905                         }
906                 }
907
908                 for (wm = main->wm.first; wm; wm = wm->id.next) {
909                         for (win = wm->windows.first; win; win = win->next) {
910                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
911                         }
912                 }
913         }
914
915         if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
916                 bScreen *screen;
917
918                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
919                         for (screen = main->screen.first; screen; screen = screen->id.next) {
920                                 ScrArea *sa;
921
922                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
923                                         SpaceLink *sl;
924
925                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
926                                                 if (sl->spacetype == SPACE_FILE) {
927                                                         SpaceFile *sfile = (SpaceFile *)sl;
928
929                                                         if (sfile->params) {
930                                                                 sfile->params->thumbnail_size = 128;
931                                                         }
932                                                 }
933                                         }
934                                 }
935                         }
936                 }
937
938                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
939                         Scene *scene;
940                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
941                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
942                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
943                         }
944                 }
945
946                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
947                         Object *ob;
948
949                         for (ob = main->object.first; ob; ob = ob->id.next) {
950                                 ModifierData *md;
951                                 for (md = ob->modifiers.first; md; md = md->next) {
952                                         if (md->type == eModifierType_Decimate) {
953                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
954                                                 dmd->defgrp_factor = 1.0f;
955                                         }
956                                 }
957                         }
958                 }
959         }
960
961         if (!MAIN_VERSION_ATLEAST(main, 275, 3)) {
962                 Brush *br;
963 #define BRUSH_TORUS (1 << 1)
964                 for (br = main->brush.first; br; br = br->id.next) {
965                         br->flag &= ~BRUSH_TORUS;
966                 }
967 #undef BRUSH_TORUS
968         }
969
970         if (!MAIN_VERSION_ATLEAST(main, 276, 2)) {
971                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
972                         Object *ob;
973
974                         for (ob = main->object.first; ob; ob = ob->id.next) {
975                                 if (ob->pose) {
976                                         bPoseChannel *pchan;
977                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
978                                                 pchan->custom_scale = 1.0f;
979                                         }
980                                 }
981                         }
982                 }
983
984                 {
985                         bScreen *screen;
986 #define RV3D_VIEW_PERSPORTHO     7
987                         for (screen = main->screen.first; screen; screen = screen->id.next) {
988                                 ScrArea *sa;
989                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
990                                         SpaceLink *sl;
991                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
992                                                 if (sl->spacetype == SPACE_VIEW3D) {
993                                                         ARegion *ar;
994                                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
995                                                         for (ar = lb->first; ar; ar = ar->next) {
996                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
997                                                                         if (ar->regiondata) {
998                                                                                 RegionView3D *rv3d = ar->regiondata;
999                                                                                 if (rv3d->view == RV3D_VIEW_PERSPORTHO) {
1000                                                                                         rv3d->view = RV3D_VIEW_USER;
1001                                                                                 }
1002                                                                         }
1003                                                                 }
1004                                                         }
1005                                                         break;
1006                                                 }
1007                                         }
1008                                 }
1009                         }
1010 #undef RV3D_VIEW_PERSPORTHO
1011                 }
1012
1013                 {
1014                         Lamp *lamp;
1015 #define LA_YF_PHOTON    5
1016                         for (lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
1017                                 if (lamp->type == LA_YF_PHOTON) {
1018                                         lamp->type = LA_LOCAL;
1019                                 }
1020                         }
1021 #undef LA_YF_PHOTON
1022                 }
1023         }
1024
1025         if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
1026                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
1027                         Scene *scene;
1028                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1029                                 CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
1030                                 curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
1031                                 curvemapping_initialize(curve_mapping);
1032                                 curvemap_reset(curve_mapping->cm,
1033                                                &curve_mapping->clipr,
1034                                                CURVE_PRESET_MAX,
1035                                                CURVEMAP_SLOPE_POS_NEG);
1036                         }
1037                 }
1038         }
1039
1040         if (!MAIN_VERSION_ATLEAST(main, 276, 4)) {
1041                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1042                         ToolSettings *ts = scene->toolsettings;
1043                         
1044                         if (ts->gp_sculpt.brush[0].size == 0) {
1045                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
1046                                 GP_EditBrush_Data *brush;
1047                                 
1048                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
1049                                 brush->size = 25;
1050                                 brush->strength = 0.3f;
1051                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
1052                                 
1053                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
1054                                 brush->size = 25;
1055                                 brush->strength = 0.5f;
1056                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1057                                 
1058                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
1059                                 brush->size = 50;
1060                                 brush->strength = 0.3f;
1061                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1062                                 
1063                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
1064                                 brush->size = 25;
1065                                 brush->strength = 0.3f;
1066                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1067                                 
1068                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
1069                                 brush->size = 50;
1070                                 brush->strength = 0.3f; // XXX?
1071                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1072                                 
1073                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
1074                                 brush->size = 50;
1075                                 brush->strength = 0.5f; // XXX?
1076                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1077                                 
1078                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
1079                                 brush->size = 25;
1080                                 brush->strength = 0.5f;
1081                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1082                                 
1083                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_CLONE];
1084                                 brush->size = 50;
1085                                 brush->strength = 1.0f;
1086                         }
1087                         
1088                         if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
1089 #if 0 /* XXX: Cannot do this, as we get random crashes... */
1090                                 if (scene->gpd) {
1091                                         bGPdata *gpd = scene->gpd;
1092                                         
1093                                         /* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
1094                                         ts->gpencil_v3d_align = 0;
1095                                         
1096                                         if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
1097                                         if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
1098                                         if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
1099                                         
1100                                         if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
1101                                                 ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
1102                                 }
1103                                 else {
1104                                         /* Default to cursor for all standard 3D views */
1105                                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1106                                 }
1107 #endif
1108                                 
1109                                 ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1110                                 ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
1111                                 ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
1112                                 ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
1113                         }
1114                 }
1115                 
1116                 for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1117                         bool enabled = false;
1118                         
1119                         /* Ensure that the datablock's onionskinning toggle flag
1120                          * stays in sync with the status of the actual layers
1121                          */
1122                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1123                                 if (gpl->flag & GP_LAYER_ONIONSKIN) {
1124                                         enabled = true;
1125                                 }
1126                         }
1127                         
1128                         if (enabled)
1129                                 gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
1130                         else
1131                                 gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
1132                 }
1133         }
1134         if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
1135                 ListBase *lbarray[MAX_LIBARRAY];
1136                 int a;
1137
1138                 /* Important to clear all non-persistent flags from older versions here, otherwise they could collide
1139                  * with any new persistent flag we may add in the future. */
1140                 a = set_listbasepointers(main, lbarray);
1141                 while (a--) {
1142                         for (ID *id = lbarray[a]->first; id; id = id->next) {
1143                                 id->flag &= LIB_FAKEUSER;
1144                         }
1145                 }
1146         }
1147
1148         if (!MAIN_VERSION_ATLEAST(main, 276, 7)) {
1149                 Scene *scene;
1150                 for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1151                         scene->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
1152                 }
1153         }
1154
1155         if (!MAIN_VERSION_ATLEAST(main, 277, 1)) {
1156                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1157                         ParticleEditSettings *pset = &scene->toolsettings->particle;
1158                         for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) {
1159                                 if (pset->brush[a].strength > 1.0f) {
1160                                         pset->brush[a].strength *= 0.01f;
1161                                 }
1162                         }
1163                 }
1164
1165                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1166                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1167                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1168                                         ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1169                                         /* Bug: Was possible to add preview region to sequencer view by using AZones. */
1170                                         if (sl->spacetype == SPACE_SEQ) {
1171                                                 SpaceSeq *sseq = (SpaceSeq *)sl;
1172                                                 if (sseq->view == SEQ_VIEW_SEQUENCE) {
1173                                                         for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1174                                                                 /* remove preview region for sequencer-only view! */
1175                                                                 if (ar->regiontype == RGN_TYPE_PREVIEW) {
1176                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1177                                                                         ar->alignment = RGN_ALIGN_NONE;
1178                                                                         break;
1179                                                                 }
1180                                                         }
1181                                                 }
1182                                         }
1183                                         /* Remove old deprecated region from filebrowsers */
1184                                         else if (sl->spacetype == SPACE_FILE) {
1185                                                 for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1186                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
1187                                                                 /* Free old deprecated 'channel' region... */
1188                                                                 BKE_area_region_free(NULL, ar);
1189                                                                 BLI_freelinkN(regionbase, ar);
1190                                                                 break;
1191                                                         }
1192                                                 }
1193                                         }
1194                                 }
1195                         }
1196                 }
1197
1198                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1199                         CurvePaintSettings *cps = &scene->toolsettings->curve_paint_settings;
1200                         if (cps->error_threshold == 0) {
1201                                 cps->curve_type = CU_BEZIER;
1202                                 cps->flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
1203                                 cps->error_threshold = 8;
1204                                 cps->radius_max = 1.0f;
1205                                 cps->corner_angle = DEG2RADF(70.0f);
1206                         }
1207                 }
1208
1209                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1210                         Sequence *seq;
1211
1212                         SEQ_BEGIN (scene->ed, seq)
1213                         {
1214                                 if (seq->type != SEQ_TYPE_TEXT) {
1215                                         continue;
1216                                 }
1217
1218                                 if (seq->effectdata == NULL) {
1219                                         struct SeqEffectHandle effect_handle = BKE_sequence_get_effect(seq);
1220                                         effect_handle.init(seq);
1221                                 }
1222
1223                                 TextVars *data = seq->effectdata;
1224                                 if (data->color[3] == 0.0f) {
1225                                         copy_v4_fl(data->color, 1.0f);
1226                                         data->shadow_color[3] = 1.0f;
1227                                 }
1228                         }
1229                         SEQ_END
1230                 }
1231
1232                 /* Adding "Properties" region to DopeSheet */
1233                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1234                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1235                                 /* handle pushed-back space data first */
1236                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1237                                         if (sl->spacetype == SPACE_ACTION) {
1238                                                 SpaceAction *saction = (SpaceAction *)sl;
1239                                                 do_version_action_editor_properties_region(&saction->regionbase);
1240                                         }
1241                                 }
1242                                 
1243                                 /* active spacedata info must be handled too... */
1244                                 if (sa->spacetype == SPACE_ACTION) {
1245                                         do_version_action_editor_properties_region(&sa->regionbase);
1246                                 }
1247                         }
1248                 }
1249         }
1250
1251         if (!MAIN_VERSION_ATLEAST(main, 277, 2)) {
1252                 if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "scaleIn")) {
1253                         for (bArmature *arm = main->armature.first; arm; arm = arm->id.next) {
1254                                 do_version_bones_super_bbone(&arm->bonebase);
1255                         }
1256                 }
1257                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "scaleIn")) {
1258                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1259                                 if (ob->pose) {
1260                                         for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1261                                                 /* see do_version_bones_super_bbone()... */
1262                                                 pchan->scaleIn = 1.0f;
1263                                                 pchan->scaleOut = 1.0f;
1264                                                 
1265                                                 /* also make sure some legacy (unused for over a decade) flags are unset,
1266                                                  * so that we can reuse them for stuff that matters now...
1267                                                  * (i.e. POSE_IK_MAT, (unknown/unused x 4), POSE_HAS_IK)
1268                                                  *
1269                                                  * These seem to have been runtime flags used by the IK solver, but that stuff
1270                                                  * should be able to be recalculated automatically anyway, so it should be fine.
1271                                                  */
1272                                                 pchan->flag &= ~((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8));
1273                                         }
1274                                 }
1275                         }
1276                 }
1277
1278                 for (Camera *camera = main->camera.first; camera != NULL; camera = camera->id.next) {
1279                         if (camera->stereo.pole_merge_angle_from == 0.0f &&
1280                             camera->stereo.pole_merge_angle_to == 0.0f)
1281                         {
1282                                 camera->stereo.pole_merge_angle_from = DEG2RADF(60.0f);
1283                                 camera->stereo.pole_merge_angle_to = DEG2RADF(75.0f);
1284                         }
1285                 }
1286
1287                 if (!DNA_struct_elem_find(fd->filesdna, "NormalEditModifierData", "float", "mix_limit")) {
1288                         Object *ob;
1289
1290                         for (ob = main->object.first; ob; ob = ob->id.next) {
1291                                 ModifierData *md;
1292                                 for (md = ob->modifiers.first; md; md = md->next) {
1293                                         if (md->type == eModifierType_NormalEdit) {
1294                                                 NormalEditModifierData *nemd = (NormalEditModifierData *)md;
1295                                                 nemd->mix_limit = DEG2RADF(180.0f);
1296                                         }
1297                                 }
1298                         }
1299                 }
1300
1301                 if (!DNA_struct_elem_find(fd->filesdna, "BooleanModifierData", "float", "double_threshold")) {
1302                         Object *ob;
1303                         for (ob = main->object.first; ob; ob = ob->id.next) {
1304                                 ModifierData *md;
1305                                 for (md = ob->modifiers.first; md; md = md->next) {
1306                                         if (md->type == eModifierType_Boolean) {
1307                                                 BooleanModifierData *bmd = (BooleanModifierData *)md;
1308                                                 bmd->double_threshold = 1e-6f;
1309                                         }
1310                                 }
1311                         }
1312                 }
1313
1314                 for (Brush *br = main->brush.first; br; br = br->id.next) {
1315                         if (br->sculpt_tool == SCULPT_TOOL_FLATTEN) {
1316                                 br->flag |= BRUSH_ACCUMULATE;
1317                         }
1318                 }
1319
1320                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "time_scale")) {
1321                         Object *ob;
1322                         ModifierData *md;
1323                         for (ob = main->object.first; ob; ob = ob->id.next) {
1324                                 for (md = ob->modifiers.first; md; md = md->next) {
1325                                         if (md->type == eModifierType_Cloth) {
1326                                                 ClothModifierData *clmd = (ClothModifierData *)md;
1327                                                 clmd->sim_parms->time_scale = 1.0f;
1328                                         }
1329                                         else if (md->type == eModifierType_ParticleSystem) {
1330                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
1331                                                 if (pmd->psys->clmd) {
1332                                                         pmd->psys->clmd->sim_parms->time_scale = 1.0f;
1333                                                 }
1334                                         }
1335                                 }
1336                         }
1337                 }
1338         }
1339
1340         if (!MAIN_VERSION_ATLEAST(main, 277, 3)) {
1341                 /* ------- init of grease pencil initialization --------------- */
1342                 if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) {
1343                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1344                                 ToolSettings *ts = scene->toolsettings;
1345                                 /* initialize use position for sculpt brushes */
1346                                 ts->gp_sculpt.flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION;
1347                                 /* initialize  selected vertices alpha factor */
1348                                 ts->gp_sculpt.alpha = 1.0f;
1349
1350                                 /* new strength sculpt brush */
1351                                 if (ts->gp_sculpt.brush[0].size >= 11) {
1352                                         GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
1353                                         GP_EditBrush_Data *brush;
1354
1355                                         brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
1356                                         brush->size = 25;
1357                                         brush->strength = 0.5f;
1358                                         brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1359                                 }
1360                         }
1361                         /* create a default grease pencil drawing brushes set */
1362                         if (!BLI_listbase_is_empty(&main->gpencil)) {
1363                                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1364                                         ToolSettings *ts = scene->toolsettings;
1365                                         if (BLI_listbase_is_empty(&ts->gp_brushes)) {
1366                                                 BKE_gpencil_brush_init_presets(ts);
1367                                         }
1368                                 }
1369                         }
1370                         /* Convert Grease Pencil to new palettes/brushes
1371                          * Loop all strokes and create the palette and all colors
1372                          */
1373                         for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1374                                 if (BLI_listbase_is_empty(&gpd->palettes)) {
1375                                         /* create palette */
1376                                         bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette", true);
1377                                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1378                                                 /* create color using layer name */
1379                                                 bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info, true);
1380                                                 if (palcolor != NULL) {
1381                                                         /* set color attributes */
1382                                                         copy_v4_v4(palcolor->color, gpl->color);
1383                                                         copy_v4_v4(palcolor->fill, gpl->fill);
1384                                                         
1385                                                         if (gpl->flag & GP_LAYER_HIDE)       palcolor->flag |= PC_COLOR_HIDE;
1386                                                         if (gpl->flag & GP_LAYER_LOCKED)     palcolor->flag |= PC_COLOR_LOCKED;
1387                                                         if (gpl->flag & GP_LAYER_ONIONSKIN)  palcolor->flag |= PC_COLOR_ONIONSKIN;
1388                                                         if (gpl->flag & GP_LAYER_VOLUMETRIC) palcolor->flag |= PC_COLOR_VOLUMETRIC;
1389                                                         if (gpl->flag & GP_LAYER_HQ_FILL)    palcolor->flag |= PC_COLOR_HQ_FILL;
1390                                                         
1391                                                         /* set layer opacity to 1 */
1392                                                         gpl->opacity = 1.0f;
1393                                                         
1394                                                         /* set tint color */
1395                                                         ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f);
1396                                                         
1397                                                         /* flush relevant layer-settings to strokes */
1398                                                         for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
1399                                                                 for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
1400                                                                         /* set stroke to palette and force recalculation */
1401                                                                         BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname));
1402                                                                         gps->palcolor = NULL;
1403                                                                         gps->flag |= GP_STROKE_RECALC_COLOR;
1404                                                                         gps->thickness = gpl->thickness;
1405                                                                         
1406                                                                         /* set alpha strength to 1 */
1407                                                                         for (int i = 0; i < gps->totpoints; i++) {
1408                                                                                 gps->points[i].strength = 1.0f;
1409                                                                         }
1410                                                                 }
1411                                                         }
1412                                                 }
1413                                                 
1414                                                 /* set thickness to 0 (now it is a factor to override stroke thickness) */
1415                                                 gpl->thickness = 0.0f;
1416                                         }
1417                                         /* set first color as active */
1418                                         if (palette->colors.first)
1419                                                 BKE_gpencil_palettecolor_setactive(palette, palette->colors.first);
1420                                 }
1421                         }
1422                 }
1423                 /* ------- end of grease pencil initialization --------------- */
1424         }
1425
1426         if (!MAIN_VERSION_ATLEAST(main, 278, 0)) {
1427                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) {
1428                         MovieClip *clip;
1429                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
1430                                 MovieTracking *tracking = &clip->tracking;
1431                                 MovieTrackingObject *tracking_object;
1432                                 for (tracking_object = tracking->objects.first;
1433                                      tracking_object != NULL;
1434                                      tracking_object = tracking_object->next)
1435                                 {
1436                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
1437                                         MovieTrackingTrack *track;
1438                                         for (track = tracksbase->first;
1439                                              track != NULL;
1440                                              track = track->next)
1441                                         {
1442                                                 track->weight_stab = track->weight;
1443                                         }
1444                                 }
1445                         }
1446                 }
1447
1448                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) {
1449                         MovieClip *clip;
1450                         for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) {
1451                                 if (clip->tracking.stabilization.rot_track) {
1452                                         migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization);
1453                                 }
1454                                 if (clip->tracking.stabilization.scale == 0.0f) {
1455                                         /* ensure init.
1456                                          * Was previously used for autoscale only,
1457                                          * now used always (as "target scale") */
1458                                         clip->tracking.stabilization.scale = 1.0f;
1459                                 }
1460                                 /* blender prefers 1-based frame counting;
1461                                  * thus using frame 1 as reference typically works best */
1462                                 clip->tracking.stabilization.anchor_frame = 1;
1463                                 /* by default show the track lists expanded, to improve "discoverability" */
1464                                 clip->tracking.stabilization.flag |= TRACKING_SHOW_STAB_TRACKS;
1465                                 /* deprecated, not used anymore */
1466                                 clip->tracking.stabilization.ok = false;
1467                         }
1468                 }
1469         }
1470         if (!MAIN_VERSION_ATLEAST(main, 278, 2)) {
1471                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "ffmpeg_preset")) {
1472                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1473                                 /* "medium" is the preset FFmpeg uses when no presets are given. */
1474                                 scene->r.ffcodecdata.ffmpeg_preset = FFM_PRESET_MEDIUM;
1475                         }
1476                 }
1477                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "constant_rate_factor")) {
1478                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1479                                 /* fall back to behaviour from before we introduced CRF for old files */
1480                                 scene->r.ffcodecdata.constant_rate_factor = FFM_CRF_NONE;
1481                         }
1482                 }
1483
1484                 if (!DNA_struct_elem_find(fd->filesdna, "SmokeModifierData", "float", "slice_per_voxel")) {
1485                         Object *ob;
1486                         ModifierData *md;
1487
1488                         for (ob = main->object.first; ob; ob = ob->id.next) {
1489                                 for (md = ob->modifiers.first; md; md = md->next) {
1490                                         if (md->type == eModifierType_Smoke) {
1491                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1492                                                 if (smd->domain) {
1493                                                         smd->domain->slice_per_voxel = 5.0f;
1494                                                         smd->domain->slice_depth = 0.5f;
1495                                                         smd->domain->display_thickness = 1.0f;
1496                                                 }
1497                                         }
1498                                 }
1499                         }
1500                 }
1501         }
1502
1503         if (!MAIN_VERSION_ATLEAST(main, 278, 3)) {
1504                 for (Scene *scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1505                         if (scene->toolsettings != NULL) {
1506                                 ToolSettings *ts = scene->toolsettings;
1507                                 ParticleEditSettings *pset = &ts->particle;
1508                                 for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) {
1509                                         if (pset->brush[a].count == 0) {
1510                                                 pset->brush[a].count = 10;
1511                                         }
1512                                 }
1513                         }
1514                 }
1515
1516                 if (!DNA_struct_elem_find(fd->filesdna, "RigidBodyCon", "float", "spring_stiffness_ang_x")) {
1517                         Object *ob;
1518                         for (ob = main->object.first; ob; ob = ob->id.next) {
1519                                 RigidBodyCon *rbc = ob->rigidbody_constraint;
1520                                 if (rbc) {
1521                                         rbc->spring_stiffness_ang_x = 10.0;
1522                                         rbc->spring_stiffness_ang_y = 10.0;
1523                                         rbc->spring_stiffness_ang_z = 10.0;
1524                                         rbc->spring_damping_ang_x = 0.5;
1525                                         rbc->spring_damping_ang_y = 0.5;
1526                                         rbc->spring_damping_ang_z = 0.5;
1527                                 }
1528                         }
1529                 }
1530
1531                 /* constant detail for sculpting is now a resolution value instead of
1532                  * a percentage, we reuse old DNA struct member but convert it */
1533                 for (Scene *scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1534                         if (scene->toolsettings != NULL) {
1535                                 ToolSettings *ts = scene->toolsettings;
1536                                 if (ts->sculpt && ts->sculpt->constant_detail != 0.0f) {
1537                                         ts->sculpt->constant_detail = 100.0f / ts->sculpt->constant_detail;
1538                                 }
1539                         }
1540                 }
1541         }
1542
1543         if (!MAIN_VERSION_ATLEAST(main, 278, 4)) {
1544                 const float sqrt_3 = (float)M_SQRT3;
1545                 for (Brush *br = main->brush.first; br; br = br->id.next) {
1546                         br->fill_threshold /= sqrt_3;
1547                 }
1548
1549                 /* Custom motion paths */
1550                 if (!DNA_struct_elem_find(fd->filesdna, "bMotionPath", "int", "line_thickness")) {
1551                         Object *ob;
1552                         for (ob = main->object.first; ob; ob = ob->id.next) {
1553                                 bMotionPath *mpath;
1554                                 bPoseChannel *pchan;
1555                                 mpath = ob->mpath;
1556                                 if (mpath) {
1557                                         mpath->color[0] = 1.0f;
1558                                         mpath->color[1] = 0.0f;
1559                                         mpath->color[2] = 0.0f;
1560                                         mpath->line_thickness = 1;
1561                                         mpath->flag |= MOTIONPATH_FLAG_LINES;
1562                                 }
1563                                 /* bones motion path */
1564                                 if (ob->pose) {
1565                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1566                                                 mpath = pchan->mpath;
1567                                                 if (mpath) {
1568                                                         mpath->color[0] = 1.0f;
1569                                                         mpath->color[1] = 0.0f;
1570                                                         mpath->color[2] = 0.0f;
1571                                                         mpath->line_thickness = 1;
1572                                                         mpath->flag |= MOTIONPATH_FLAG_LINES;
1573                                                 }
1574                                         }
1575                                 }
1576                         }
1577                 }
1578         }
1579
1580         if (!MAIN_VERSION_ATLEAST(main, 278, 5)) {
1581                 /* Mask primitive adding code was not initializing correctly id_type of its points' parent. */
1582                 for (Mask *mask = main->mask.first; mask; mask = mask->id.next) {
1583                         for (MaskLayer *mlayer = mask->masklayers.first; mlayer; mlayer = mlayer->next) {
1584                                 for (MaskSpline *mspline = mlayer->splines.first; mspline; mspline = mspline->next) {
1585                                         int i = 0;
1586                                         for (MaskSplinePoint *mspoint = mspline->points; i < mspline->tot_point; mspoint++, i++) {
1587                                                 if (mspoint->parent.id_type == 0) {
1588                                                         BKE_mask_parent_init(&mspoint->parent);
1589                                                 }
1590                                         }
1591                                 }
1592                         }
1593                 }
1594
1595                 /* Fix for T50736, Glare comp node using same var for two different things. */
1596                 if (!DNA_struct_elem_find(fd->filesdna, "NodeGlare", "char", "star_45")) {
1597                         FOREACH_NODETREE(main, ntree, id) {
1598                                 if (ntree->type == NTREE_COMPOSIT) {
1599                                         ntreeSetTypes(NULL, ntree);
1600                                         for (bNode *node = ntree->nodes.first; node; node = node->next) {
1601                                                 if (node->type == CMP_NODE_GLARE) {
1602                                                         NodeGlare *ndg = node->storage;
1603                                                         switch (ndg->type) {
1604                                                                 case 2:  /* Grrrr! magic numbers :( */
1605                                                                         ndg->streaks = ndg->angle;
1606                                                                         break;
1607                                                                 case 0:
1608                                                                         ndg->star_45 = ndg->angle != 0;
1609                                                                         break;
1610                                                                 default:
1611                                                                         break;
1612                                                         }
1613                                                 }
1614                                         }
1615                                 }
1616                         } FOREACH_NODETREE_END
1617                 }
1618
1619                 if (!DNA_struct_elem_find(fd->filesdna, "SurfaceDeformModifierData", "float", "mat[4][4]")) {
1620                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1621                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
1622                                         if (md->type == eModifierType_SurfaceDeform) {
1623                                                 SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
1624                                                 unit_m4(smd->mat);
1625                                         }
1626                                 }
1627                         }
1628                 }
1629
1630                 FOREACH_NODETREE(main, ntree, id) {
1631                         if (ntree->type == NTREE_COMPOSIT) {
1632                                 do_versions_compositor_render_passes(ntree);
1633                         }
1634                 } FOREACH_NODETREE_END
1635         }
1636
1637         if (!MAIN_VERSION_ATLEAST(main, 279, 0)) {
1638                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1639                         if (scene->r.im_format.exr_codec == R_IMF_EXR_CODEC_DWAB) {
1640                                 scene->r.im_format.exr_codec = R_IMF_EXR_CODEC_DWAA;
1641                         }
1642                 }
1643
1644                 /* Fix related to VGroup modifiers creating named defgroup CD layers! See T51520. */
1645                 for (Mesh *me = main->mesh.first; me; me = me->id.next) {
1646                         CustomData_set_layer_name(&me->vdata, CD_MDEFORMVERT, 0, "");
1647                 }
1648         }
1649
1650         if (!MAIN_VERSION_ATLEAST(main, 279, 3)) {
1651                 if (!DNA_struct_elem_find(fd->filesdna, "SmokeDomainSettings", "float", "clipping")) {
1652                         Object *ob;
1653                         ModifierData *md;
1654
1655                         for (ob = main->object.first; ob; ob = ob->id.next) {
1656                                 for (md = ob->modifiers.first; md; md = md->next) {
1657                                         if (md->type == eModifierType_Smoke) {
1658                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1659                                                 if (smd->domain) {
1660                                                         smd->domain->clipping = 1e-3f;
1661                                                 }
1662                                         }
1663                                 }
1664                         }
1665                 }
1666         }
1667
1668         {
1669                 /* Fix for invalid state of screen due to bug in older versions. */
1670                 for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) {
1671                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
1672                                 if (sa->full && sc->state == SCREENNORMAL) {
1673                                         sa->full = NULL;
1674                                 }
1675                         }
1676                 }
1677
1678                 if (!DNA_struct_elem_find(fd->filesdna, "Brush", "float", "falloff_angle")) {
1679                         for (Brush *br = main->brush.first; br; br = br->id.next) {
1680                                 br->falloff_angle = DEG2RADF(80);
1681                                 br->flag &= ~(
1682                                         BRUSH_FLAG_DEPRECATED_1 | BRUSH_FLAG_DEPRECATED_2 |
1683                                         BRUSH_FLAG_DEPRECATED_3 | BRUSH_FLAG_DEPRECATED_4 |
1684                                         BRUSH_FRONTFACE_FALLOFF);
1685                         }
1686
1687                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1688                                 ToolSettings *ts = scene->toolsettings;
1689                                 for (int i = 0; i < 2; i++) {
1690                                         VPaint *vp = i ? ts->vpaint : ts->wpaint;
1691                                         if (vp != NULL) {
1692                                                 /* remove all other flags */
1693                                                 vp->flag &= (VP_FLAG_VGROUP_RESTRICT);
1694                                         }
1695                                 }
1696                         }
1697                 }
1698
1699                 /* Simple deform modifier no longer assumes Z axis (X for bend type).
1700                  * Must set previous defaults. */
1701                 if (!DNA_struct_elem_find(fd->filesdna, "SimpleDeformModifierData", "char", "deform_axis")) {
1702                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1703                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
1704                                         if (md->type == eModifierType_SimpleDeform) {
1705                                                 SimpleDeformModifierData *smd = (SimpleDeformModifierData *)md;
1706                                                 smd->deform_axis = 2;
1707                                         }
1708                                 }
1709                         }
1710                 }
1711
1712                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1713                         int preset = scene->r.ffcodecdata.ffmpeg_preset;
1714                         if (preset == FFM_PRESET_NONE || preset >= FFM_PRESET_GOOD) {
1715                                 continue;
1716                         }
1717                         if (preset <= FFM_PRESET_FAST) {
1718                                 preset = FFM_PRESET_REALTIME;
1719                         }
1720                         else if (preset >= FFM_PRESET_SLOW) {
1721                                 preset = FFM_PRESET_BEST;
1722                         }
1723                         else {
1724                                 preset = FFM_PRESET_GOOD;
1725                         }
1726                         scene->r.ffcodecdata.ffmpeg_preset = preset;
1727                 }
1728
1729                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleInstanceModifierData", "float", "particle_amount")) {
1730                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1731                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
1732                                         if (md->type == eModifierType_ParticleInstance) {
1733                                                 ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
1734                                                 pimd->space = eParticleInstanceSpace_World;
1735                                                 pimd->particle_amount = 1.0f;
1736                                         }
1737                                 }
1738                         }
1739                 }
1740         }
1741 }
1742
1743 void do_versions_after_linking_270(Main *main)
1744 {
1745         /* To be added to next subversion bump! */
1746         if (!MAIN_VERSION_ATLEAST(main, 279, 0)) {
1747                 FOREACH_NODETREE(main, ntree, id) {
1748                         if (ntree->type == NTREE_COMPOSIT) {
1749                                 ntreeSetTypes(NULL, ntree);
1750                                 for (bNode *node = ntree->nodes.first; node; node = node->next) {
1751                                         if (node->type == CMP_NODE_HUE_SAT) {
1752                                                 do_version_hue_sat_node(ntree, node);
1753                                         }
1754                                 }
1755                         }
1756                 } FOREACH_NODETREE_END
1757         }
1758         
1759         if (!MAIN_VERSION_ATLEAST(main, 279, 2)) {
1760                 /* B-Bones (bbone_in/out -> bbone_easein/out) + Stepped FMod Frame Start/End fix */
1761                 /* if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "bbone_easein")) */
1762                 BKE_fcurves_main_cb(main, do_version_bbone_easing_fcurve_fix, NULL);
1763         }
1764 }