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