UVEdit: Add back uv angle stretch aspect correction
[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_BEGIN(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_BEGIN(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 |= ID_RECALC_PSYS_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                         } SEQ_END;
921                 }
922
923                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
924                         ScrArea *sa;
925                         for (sa = screen->areabase.first; sa; sa = sa->next) {
926                                 SpaceLink *sl;
927
928                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
929                                         switch (sl->spacetype) {
930                                                 case SPACE_VIEW3D:
931                                                 {
932                                                         View3D *v3d = (View3D *)sl;
933                                                         v3d->stereo3d_camera = STEREO_3D_ID;
934                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
935                                                         v3d->stereo3d_convergence_alpha = 0.15f;
936                                                         v3d->stereo3d_volume_alpha = 0.05f;
937                                                         break;
938                                                 }
939                                                 case SPACE_IMAGE:
940                                                 {
941                                                         SpaceImage *sima = (SpaceImage *)sl;
942                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
943                                                         break;
944                                                 }
945                                         }
946                                 }
947                         }
948                 }
949
950                 for (cam = bmain->camera.first; cam; cam = cam->id.next) {
951                         cam->stereo.interocular_distance = 0.065f;
952                         cam->stereo.convergence_distance = 30.0f * 0.065f;
953                 }
954
955                 for (ima = bmain->image.first; ima; ima = ima->id.next) {
956                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
957
958                         if (ima->packedfile) {
959                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
960                                 BLI_addtail(&ima->packedfiles, imapf);
961
962                                 imapf->packedfile = ima->packedfile;
963                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
964                                 ima->packedfile = NULL;
965                         }
966                 }
967
968                 for (wm = bmain->wm.first; wm; wm = wm->id.next) {
969                         for (win = wm->windows.first; win; win = win->next) {
970                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
971                         }
972                 }
973         }
974
975         if (!MAIN_VERSION_ATLEAST(bmain, 274, 6)) {
976                 bScreen *screen;
977
978                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
979                         for (screen = bmain->screen.first; screen; screen = screen->id.next) {
980                                 ScrArea *sa;
981
982                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
983                                         SpaceLink *sl;
984
985                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
986                                                 if (sl->spacetype == SPACE_FILE) {
987                                                         SpaceFile *sfile = (SpaceFile *)sl;
988
989                                                         if (sfile->params) {
990                                                                 sfile->params->thumbnail_size = 128;
991                                                         }
992                                                 }
993                                         }
994                                 }
995                         }
996                 }
997
998                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
999                         Scene *scene;
1000                         for (scene = bmain->scene.first; scene != NULL; scene = scene->id.next) {
1001                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
1002                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
1003                         }
1004                 }
1005
1006                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
1007                         Object *ob;
1008
1009                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1010                                 ModifierData *md;
1011                                 for (md = ob->modifiers.first; md; md = md->next) {
1012                                         if (md->type == eModifierType_Decimate) {
1013                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
1014                                                 dmd->defgrp_factor = 1.0f;
1015                                         }
1016                                 }
1017                         }
1018                 }
1019         }
1020
1021         if (!MAIN_VERSION_ATLEAST(bmain, 275, 3)) {
1022                 Brush *br;
1023 #define BRUSH_TORUS (1 << 1)
1024                 for (br = bmain->brush.first; br; br = br->id.next) {
1025                         br->flag &= ~BRUSH_TORUS;
1026                 }
1027 #undef BRUSH_TORUS
1028         }
1029
1030         if (!MAIN_VERSION_ATLEAST(bmain, 276, 2)) {
1031                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
1032                         Object *ob;
1033
1034                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1035                                 if (ob->pose) {
1036                                         bPoseChannel *pchan;
1037                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1038                                                 pchan->custom_scale = 1.0f;
1039                                         }
1040                                 }
1041                         }
1042                 }
1043
1044                 {
1045                         bScreen *screen;
1046 #define RV3D_VIEW_PERSPORTHO     7
1047                         for (screen = bmain->screen.first; screen; screen = screen->id.next) {
1048                                 ScrArea *sa;
1049                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1050                                         SpaceLink *sl;
1051                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1052                                                 if (sl->spacetype == SPACE_VIEW3D) {
1053                                                         ARegion *ar;
1054                                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1055                                                         for (ar = lb->first; ar; ar = ar->next) {
1056                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
1057                                                                         if (ar->regiondata) {
1058                                                                                 RegionView3D *rv3d = ar->regiondata;
1059                                                                                 if (rv3d->view == RV3D_VIEW_PERSPORTHO) {
1060                                                                                         rv3d->view = RV3D_VIEW_USER;
1061                                                                                 }
1062                                                                         }
1063                                                                 }
1064                                                         }
1065                                                         break;
1066                                                 }
1067                                         }
1068                                 }
1069                         }
1070 #undef RV3D_VIEW_PERSPORTHO
1071                 }
1072
1073                 {
1074                         Lamp *lamp;
1075 #define LA_YF_PHOTON    5
1076                         for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
1077                                 if (lamp->type == LA_YF_PHOTON) {
1078                                         lamp->type = LA_LOCAL;
1079                                 }
1080                         }
1081 #undef LA_YF_PHOTON
1082                 }
1083         }
1084
1085         if (!MAIN_VERSION_ATLEAST(bmain, 276, 3)) {
1086                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
1087                         Scene *scene;
1088                         for (scene = bmain->scene.first; scene != NULL; scene = scene->id.next) {
1089                                 CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
1090                                 curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
1091                                 curvemapping_initialize(curve_mapping);
1092                                 curvemap_reset(curve_mapping->cm,
1093                                                &curve_mapping->clipr,
1094                                                CURVE_PRESET_MAX,
1095                                                CURVEMAP_SLOPE_POS_NEG);
1096                         }
1097                 }
1098         }
1099
1100         if (!MAIN_VERSION_ATLEAST(bmain, 276, 4)) {
1101                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1102                         ToolSettings *ts = scene->toolsettings;
1103
1104                         if (ts->gp_sculpt.brush[0].size == 0) {
1105                                 GP_Sculpt_Settings *gset = &ts->gp_sculpt;
1106                                 GP_Sculpt_Data *brush;
1107
1108                                 brush = &gset->brush[GP_SCULPT_TYPE_SMOOTH];
1109                                 brush->size = 25;
1110                                 brush->strength = 0.3f;
1111                                 brush->flag = GP_SCULPT_FLAG_USE_FALLOFF | GP_SCULPT_FLAG_SMOOTH_PRESSURE;
1112
1113                                 brush = &gset->brush[GP_SCULPT_TYPE_THICKNESS];
1114                                 brush->size = 25;
1115                                 brush->strength = 0.5f;
1116                                 brush->flag = GP_SCULPT_FLAG_USE_FALLOFF;
1117
1118                                 brush = &gset->brush[GP_SCULPT_TYPE_GRAB];
1119                                 brush->size = 50;
1120                                 brush->strength = 0.3f;
1121                                 brush->flag = GP_SCULPT_FLAG_USE_FALLOFF;
1122
1123                                 brush = &gset->brush[GP_SCULPT_TYPE_PUSH];
1124                                 brush->size = 25;
1125                                 brush->strength = 0.3f;
1126                                 brush->flag = GP_SCULPT_FLAG_USE_FALLOFF;
1127
1128                                 brush = &gset->brush[GP_SCULPT_TYPE_TWIST];
1129                                 brush->size = 50;
1130                                 brush->strength = 0.3f; // XXX?
1131                                 brush->flag = GP_SCULPT_FLAG_USE_FALLOFF;
1132
1133                                 brush = &gset->brush[GP_SCULPT_TYPE_PINCH];
1134                                 brush->size = 50;
1135                                 brush->strength = 0.5f; // XXX?
1136                                 brush->flag = GP_SCULPT_FLAG_USE_FALLOFF;
1137
1138                                 brush = &gset->brush[GP_SCULPT_TYPE_RANDOMIZE];
1139                                 brush->size = 25;
1140                                 brush->strength = 0.5f;
1141                                 brush->flag = GP_SCULPT_FLAG_USE_FALLOFF;
1142
1143                                 brush = &gset->brush[GP_SCULPT_TYPE_CLONE];
1144                                 brush->size = 50;
1145                                 brush->strength = 1.0f;
1146                         }
1147
1148                         if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
1149 #if 0 /* XXX: Cannot do this, as we get random crashes... */
1150                                 if (scene->gpd) {
1151                                         bGPdata *gpd = scene->gpd;
1152
1153                                         /* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
1154                                         ts->gpencil_v3d_align = 0;
1155
1156                                         if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
1157                                         if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
1158                                         if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
1159
1160                                         if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
1161                                                 ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
1162                                 }
1163                                 else {
1164                                         /* Default to cursor for all standard 3D views */
1165                                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1166                                 }
1167 #endif
1168
1169                                 ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1170                                 ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
1171                                 ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
1172                                 ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
1173                         }
1174                 }
1175
1176                 for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) {
1177                         bool enabled = false;
1178
1179                         /* Ensure that the datablock's onionskinning toggle flag
1180                          * stays in sync with the status of the actual layers
1181                          */
1182                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1183                                 if (gpl->flag & GP_LAYER_ONIONSKIN) {
1184                                         enabled = true;
1185                                 }
1186                         }
1187
1188                         if (enabled)
1189                                 gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
1190                         else
1191                                 gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
1192                 }
1193         }
1194         if (!MAIN_VERSION_ATLEAST(bmain, 276, 5)) {
1195                 ListBase *lbarray[MAX_LIBARRAY];
1196                 int a;
1197
1198                 /* Important to clear all non-persistent flags from older versions here, otherwise they could collide
1199                  * with any new persistent flag we may add in the future. */
1200                 a = set_listbasepointers(bmain, lbarray);
1201                 while (a--) {
1202                         for (ID *id = lbarray[a]->first; id; id = id->next) {
1203                                 id->flag &= LIB_FAKEUSER;
1204                         }
1205                 }
1206         }
1207
1208         if (!MAIN_VERSION_ATLEAST(bmain, 276, 7)) {
1209                 Scene *scene;
1210                 for (scene = bmain->scene.first; scene != NULL; scene = scene->id.next) {
1211                         scene->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
1212                 }
1213         }
1214
1215         if (!MAIN_VERSION_ATLEAST(bmain, 277, 1)) {
1216                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1217                         ParticleEditSettings *pset = &scene->toolsettings->particle;
1218                         for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) {
1219                                 if (pset->brush[a].strength > 1.0f) {
1220                                         pset->brush[a].strength *= 0.01f;
1221                                 }
1222                         }
1223                 }
1224
1225                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1226                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1227                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1228                                         ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1229                                         /* Bug: Was possible to add preview region to sequencer view by using AZones. */
1230                                         if (sl->spacetype == SPACE_SEQ) {
1231                                                 SpaceSeq *sseq = (SpaceSeq *)sl;
1232                                                 if (sseq->view == SEQ_VIEW_SEQUENCE) {
1233                                                         for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1234                                                                 /* remove preview region for sequencer-only view! */
1235                                                                 if (ar->regiontype == RGN_TYPE_PREVIEW) {
1236                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1237                                                                         ar->alignment = RGN_ALIGN_NONE;
1238                                                                         break;
1239                                                                 }
1240                                                         }
1241                                                 }
1242                                         }
1243                                         /* Remove old deprecated region from filebrowsers */
1244                                         else if (sl->spacetype == SPACE_FILE) {
1245                                                 for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1246                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
1247                                                                 /* Free old deprecated 'channel' region... */
1248                                                                 BKE_area_region_free(NULL, ar);
1249                                                                 BLI_freelinkN(regionbase, ar);
1250                                                                 break;
1251                                                         }
1252                                                 }
1253                                         }
1254                                 }
1255                         }
1256                 }
1257
1258                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1259                         CurvePaintSettings *cps = &scene->toolsettings->curve_paint_settings;
1260                         if (cps->error_threshold == 0) {
1261                                 cps->curve_type = CU_BEZIER;
1262                                 cps->flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
1263                                 cps->error_threshold = 8;
1264                                 cps->radius_max = 1.0f;
1265                                 cps->corner_angle = DEG2RADF(70.0f);
1266                         }
1267                 }
1268
1269                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1270                         Sequence *seq;
1271
1272                         SEQ_BEGIN (scene->ed, seq)
1273                         {
1274                                 if (seq->type != SEQ_TYPE_TEXT) {
1275                                         continue;
1276                                 }
1277
1278                                 if (seq->effectdata == NULL) {
1279                                         struct SeqEffectHandle effect_handle = BKE_sequence_get_effect(seq);
1280                                         effect_handle.init(seq);
1281                                 }
1282
1283                                 TextVars *data = seq->effectdata;
1284                                 if (data->color[3] == 0.0f) {
1285                                         copy_v4_fl(data->color, 1.0f);
1286                                         data->shadow_color[3] = 1.0f;
1287                                 }
1288                         } SEQ_END;
1289                 }
1290
1291                 /* Adding "Properties" region to DopeSheet */
1292                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1293                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1294                                 /* handle pushed-back space data first */
1295                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1296                                         if (sl->spacetype == SPACE_ACTION) {
1297                                                 SpaceAction *saction = (SpaceAction *)sl;
1298                                                 do_version_action_editor_properties_region(&saction->regionbase);
1299                                         }
1300                                 }
1301
1302                                 /* active spacedata info must be handled too... */
1303                                 if (sa->spacetype == SPACE_ACTION) {
1304                                         do_version_action_editor_properties_region(&sa->regionbase);
1305                                 }
1306                         }
1307                 }
1308         }
1309
1310         if (!MAIN_VERSION_ATLEAST(bmain, 277, 2)) {
1311                 if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "scaleIn")) {
1312                         for (bArmature *arm = bmain->armature.first; arm; arm = arm->id.next) {
1313                                 do_version_bones_super_bbone(&arm->bonebase);
1314                         }
1315                 }
1316                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "scaleIn")) {
1317                         for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1318                                 if (ob->pose) {
1319                                         for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1320                                                 /* see do_version_bones_super_bbone()... */
1321                                                 pchan->scaleIn = 1.0f;
1322                                                 pchan->scaleOut = 1.0f;
1323
1324                                                 /* also make sure some legacy (unused for over a decade) flags are unset,
1325                                                  * so that we can reuse them for stuff that matters now...
1326                                                  * (i.e. POSE_IK_MAT, (unknown/unused x 4), POSE_HAS_IK)
1327                                                  *
1328                                                  * These seem to have been runtime flags used by the IK solver, but that stuff
1329                                                  * should be able to be recalculated automatically anyway, so it should be fine.
1330                                                  */
1331                                                 pchan->flag &= ~((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8));
1332                                         }
1333                                 }
1334                         }
1335                 }
1336
1337                 for (Camera *camera = bmain->camera.first; camera != NULL; camera = camera->id.next) {
1338                         if (camera->stereo.pole_merge_angle_from == 0.0f &&
1339                             camera->stereo.pole_merge_angle_to == 0.0f)
1340                         {
1341                                 camera->stereo.pole_merge_angle_from = DEG2RADF(60.0f);
1342                                 camera->stereo.pole_merge_angle_to = DEG2RADF(75.0f);
1343                         }
1344                 }
1345
1346                 if (!DNA_struct_elem_find(fd->filesdna, "NormalEditModifierData", "float", "mix_limit")) {
1347                         Object *ob;
1348
1349                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1350                                 ModifierData *md;
1351                                 for (md = ob->modifiers.first; md; md = md->next) {
1352                                         if (md->type == eModifierType_NormalEdit) {
1353                                                 NormalEditModifierData *nemd = (NormalEditModifierData *)md;
1354                                                 nemd->mix_limit = DEG2RADF(180.0f);
1355                                         }
1356                                 }
1357                         }
1358                 }
1359
1360                 if (!DNA_struct_elem_find(fd->filesdna, "BooleanModifierData", "float", "double_threshold")) {
1361                         Object *ob;
1362                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1363                                 ModifierData *md;
1364                                 for (md = ob->modifiers.first; md; md = md->next) {
1365                                         if (md->type == eModifierType_Boolean) {
1366                                                 BooleanModifierData *bmd = (BooleanModifierData *)md;
1367                                                 bmd->double_threshold = 1e-6f;
1368                                         }
1369                                 }
1370                         }
1371                 }
1372
1373                 for (Brush *br = bmain->brush.first; br; br = br->id.next) {
1374                         if (br->sculpt_tool == SCULPT_TOOL_FLATTEN) {
1375                                 br->flag |= BRUSH_ACCUMULATE;
1376                         }
1377                 }
1378
1379                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "time_scale")) {
1380                         Object *ob;
1381                         ModifierData *md;
1382                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1383                                 for (md = ob->modifiers.first; md; md = md->next) {
1384                                         if (md->type == eModifierType_Cloth) {
1385                                                 ClothModifierData *clmd = (ClothModifierData *)md;
1386                                                 clmd->sim_parms->time_scale = 1.0f;
1387                                         }
1388                                         else if (md->type == eModifierType_ParticleSystem) {
1389                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
1390                                                 if (pmd->psys->clmd) {
1391                                                         pmd->psys->clmd->sim_parms->time_scale = 1.0f;
1392                                                 }
1393                                         }
1394                                 }
1395                         }
1396                 }
1397         }
1398
1399         if (!MAIN_VERSION_ATLEAST(bmain, 277, 3)) {
1400                 /* ------- init of grease pencil initialization --------------- */
1401                 if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) {
1402                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1403                                 ToolSettings *ts = scene->toolsettings;
1404                                 /* initialize use position for sculpt brushes */
1405                                 ts->gp_sculpt.flag |= GP_SCULPT_SETT_FLAG_APPLY_POSITION;
1406
1407                                 /* new strength sculpt brush */
1408                                 if (ts->gp_sculpt.brush[0].size >= 11) {
1409                                         GP_Sculpt_Settings *gset = &ts->gp_sculpt;
1410                                         GP_Sculpt_Data *brush;
1411
1412                                         brush = &gset->brush[GP_SCULPT_TYPE_STRENGTH];
1413                                         brush->size = 25;
1414                                         brush->strength = 0.5f;
1415                                         brush->flag = GP_SCULPT_FLAG_USE_FALLOFF;
1416                                 }
1417                         }
1418                         /* Convert Grease Pencil to new palettes/brushes
1419                          * Loop all strokes and create the palette and all colors
1420                          */
1421                         for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) {
1422                                 if (BLI_listbase_is_empty(&gpd->palettes)) {
1423                                         /* create palette */
1424                                         bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette");
1425                                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1426                                                 /* create color using layer name */
1427                                                 bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info);
1428                                                 if (palcolor != NULL) {
1429                                                         /* set color attributes */
1430                                                         copy_v4_v4(palcolor->color, gpl->color);
1431                                                         copy_v4_v4(palcolor->fill, gpl->fill);
1432
1433                                                         if (gpl->flag & GP_LAYER_HIDE)       palcolor->flag |= PC_COLOR_HIDE;
1434                                                         if (gpl->flag & GP_LAYER_LOCKED)     palcolor->flag |= PC_COLOR_LOCKED;
1435                                                         if (gpl->flag & GP_LAYER_ONIONSKIN)  palcolor->flag |= PC_COLOR_ONIONSKIN;
1436                                                         if (gpl->flag & GP_LAYER_VOLUMETRIC) palcolor->flag |= PC_COLOR_VOLUMETRIC;
1437
1438                                                         /* set layer opacity to 1 */
1439                                                         gpl->opacity = 1.0f;
1440
1441                                                         /* set tint color */
1442                                                         ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f);
1443
1444                                                         /* flush relevant layer-settings to strokes */
1445                                                         for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
1446                                                                 for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
1447                                                                         /* set stroke to palette and force recalculation */
1448                                                                         BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname));
1449                                                                         gps->thickness = gpl->thickness;
1450
1451                                                                         /* set alpha strength to 1 */
1452                                                                         for (int i = 0; i < gps->totpoints; i++) {
1453                                                                                 gps->points[i].strength = 1.0f;
1454                                                                         }
1455                                                                 }
1456                                                         }
1457                                                 }
1458                                         }
1459                                 }
1460                         }
1461                 }
1462                 /* ------- end of grease pencil initialization --------------- */
1463         }
1464
1465         if (!MAIN_VERSION_ATLEAST(bmain, 278, 0)) {
1466                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) {
1467                         MovieClip *clip;
1468                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1469                                 MovieTracking *tracking = &clip->tracking;
1470                                 MovieTrackingObject *tracking_object;
1471                                 for (tracking_object = tracking->objects.first;
1472                                      tracking_object != NULL;
1473                                      tracking_object = tracking_object->next)
1474                                 {
1475                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
1476                                         MovieTrackingTrack *track;
1477                                         for (track = tracksbase->first;
1478                                              track != NULL;
1479                                              track = track->next)
1480                                         {
1481                                                 track->weight_stab = track->weight;
1482                                         }
1483                                 }
1484                         }
1485                 }
1486
1487                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) {
1488                         MovieClip *clip;
1489                         for (clip = bmain->movieclip.first; clip != NULL; clip = clip->id.next) {
1490                                 if (clip->tracking.stabilization.rot_track) {
1491                                         migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization);
1492                                 }
1493                                 if (clip->tracking.stabilization.scale == 0.0f) {
1494                                         /* ensure init.
1495                                          * Was previously used for autoscale only,
1496                                          * now used always (as "target scale") */
1497                                         clip->tracking.stabilization.scale = 1.0f;
1498                                 }
1499                                 /* blender prefers 1-based frame counting;
1500                                  * thus using frame 1 as reference typically works best */
1501                                 clip->tracking.stabilization.anchor_frame = 1;
1502                                 /* by default show the track lists expanded, to improve "discoverability" */
1503                                 clip->tracking.stabilization.flag |= TRACKING_SHOW_STAB_TRACKS;
1504                                 /* deprecated, not used anymore */
1505                                 clip->tracking.stabilization.ok = false;
1506                         }
1507                 }
1508         }
1509         if (!MAIN_VERSION_ATLEAST(bmain, 278, 2)) {
1510                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "ffmpeg_preset")) {
1511                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1512                                 /* "medium" is the preset FFmpeg uses when no presets are given. */
1513                                 scene->r.ffcodecdata.ffmpeg_preset = FFM_PRESET_MEDIUM;
1514                         }
1515                 }
1516                 if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "constant_rate_factor")) {
1517                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1518                                 /* fall back to behavior from before we introduced CRF for old files */
1519                                 scene->r.ffcodecdata.constant_rate_factor = FFM_CRF_NONE;
1520                         }
1521                 }
1522
1523                 if (!DNA_struct_elem_find(fd->filesdna, "SmokeModifierData", "float", "slice_per_voxel")) {
1524                         Object *ob;
1525                         ModifierData *md;
1526
1527                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1528                                 for (md = ob->modifiers.first; md; md = md->next) {
1529                                         if (md->type == eModifierType_Smoke) {
1530                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1531                                                 if (smd->domain) {
1532                                                         smd->domain->slice_per_voxel = 5.0f;
1533                                                         smd->domain->slice_depth = 0.5f;
1534                                                         smd->domain->display_thickness = 1.0f;
1535                                                 }
1536                                         }
1537                                 }
1538                         }
1539                 }
1540         }
1541
1542         if (!MAIN_VERSION_ATLEAST(bmain, 278, 3)) {
1543                 for (Scene *scene = bmain->scene.first; scene != NULL; scene = scene->id.next) {
1544                         if (scene->toolsettings != NULL) {
1545                                 ToolSettings *ts = scene->toolsettings;
1546                                 ParticleEditSettings *pset = &ts->particle;
1547                                 for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) {
1548                                         if (pset->brush[a].count == 0) {
1549                                                 pset->brush[a].count = 10;
1550                                         }
1551                                 }
1552                         }
1553                 }
1554
1555                 if (!DNA_struct_elem_find(fd->filesdna, "RigidBodyCon", "float", "spring_stiffness_ang_x")) {
1556                         Object *ob;
1557                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1558                                 RigidBodyCon *rbc = ob->rigidbody_constraint;
1559                                 if (rbc) {
1560                                         rbc->spring_stiffness_ang_x = 10.0;
1561                                         rbc->spring_stiffness_ang_y = 10.0;
1562                                         rbc->spring_stiffness_ang_z = 10.0;
1563                                         rbc->spring_damping_ang_x = 0.5;
1564                                         rbc->spring_damping_ang_y = 0.5;
1565                                         rbc->spring_damping_ang_z = 0.5;
1566                                 }
1567                         }
1568                 }
1569
1570                 /* constant detail for sculpting is now a resolution value instead of
1571                  * a percentage, we reuse old DNA struct member but convert it */
1572                 for (Scene *scene = bmain->scene.first; scene != NULL; scene = scene->id.next) {
1573                         if (scene->toolsettings != NULL) {
1574                                 ToolSettings *ts = scene->toolsettings;
1575                                 if (ts->sculpt && ts->sculpt->constant_detail != 0.0f) {
1576                                         ts->sculpt->constant_detail = 100.0f / ts->sculpt->constant_detail;
1577                                 }
1578                         }
1579                 }
1580         }
1581
1582         if (!MAIN_VERSION_ATLEAST(bmain, 278, 4)) {
1583                 const float sqrt_3 = (float)M_SQRT3;
1584                 for (Brush *br = bmain->brush.first; br; br = br->id.next) {
1585                         br->fill_threshold /= sqrt_3;
1586                 }
1587
1588                 /* Custom motion paths */
1589                 if (!DNA_struct_elem_find(fd->filesdna, "bMotionPath", "int", "line_thickness")) {
1590                         Object *ob;
1591                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1592                                 bMotionPath *mpath;
1593                                 bPoseChannel *pchan;
1594                                 mpath = ob->mpath;
1595                                 if (mpath) {
1596                                         mpath->color[0] = 1.0f;
1597                                         mpath->color[1] = 0.0f;
1598                                         mpath->color[2] = 0.0f;
1599                                         mpath->line_thickness = 1;
1600                                         mpath->flag |= MOTIONPATH_FLAG_LINES;
1601                                 }
1602                                 /* bones motion path */
1603                                 if (ob->pose) {
1604                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1605                                                 mpath = pchan->mpath;
1606                                                 if (mpath) {
1607                                                         mpath->color[0] = 1.0f;
1608                                                         mpath->color[1] = 0.0f;
1609                                                         mpath->color[2] = 0.0f;
1610                                                         mpath->line_thickness = 1;
1611                                                         mpath->flag |= MOTIONPATH_FLAG_LINES;
1612                                                 }
1613                                         }
1614                                 }
1615                         }
1616                 }
1617         }
1618
1619         if (!MAIN_VERSION_ATLEAST(bmain, 278, 5)) {
1620                 /* Mask primitive adding code was not initializing correctly id_type of its points' parent. */
1621                 for (Mask *mask = bmain->mask.first; mask; mask = mask->id.next) {
1622                         for (MaskLayer *mlayer = mask->masklayers.first; mlayer; mlayer = mlayer->next) {
1623                                 for (MaskSpline *mspline = mlayer->splines.first; mspline; mspline = mspline->next) {
1624                                         int i = 0;
1625                                         for (MaskSplinePoint *mspoint = mspline->points; i < mspline->tot_point; mspoint++, i++) {
1626                                                 if (mspoint->parent.id_type == 0) {
1627                                                         BKE_mask_parent_init(&mspoint->parent);
1628                                                 }
1629                                         }
1630                                 }
1631                         }
1632                 }
1633
1634                 /* Fix for T50736, Glare comp node using same var for two different things. */
1635                 if (!DNA_struct_elem_find(fd->filesdna, "NodeGlare", "char", "star_45")) {
1636                         FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1637                                 if (ntree->type == NTREE_COMPOSIT) {
1638                                         ntreeSetTypes(NULL, ntree);
1639                                         for (bNode *node = ntree->nodes.first; node; node = node->next) {
1640                                                 if (node->type == CMP_NODE_GLARE) {
1641                                                         NodeGlare *ndg = node->storage;
1642                                                         switch (ndg->type) {
1643                                                                 case 2:  /* Grrrr! magic numbers :( */
1644                                                                         ndg->streaks = ndg->angle;
1645                                                                         break;
1646                                                                 case 0:
1647                                                                         ndg->star_45 = ndg->angle != 0;
1648                                                                         break;
1649                                                                 default:
1650                                                                         break;
1651                                                         }
1652                                                 }
1653                                         }
1654                                 }
1655                         } FOREACH_NODETREE_END;
1656                 }
1657
1658                 if (!DNA_struct_elem_find(fd->filesdna, "SurfaceDeformModifierData", "float", "mat[4][4]")) {
1659                         for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1660                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
1661                                         if (md->type == eModifierType_SurfaceDeform) {
1662                                                 SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
1663                                                 unit_m4(smd->mat);
1664                                         }
1665                                 }
1666                         }
1667                 }
1668
1669                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1670                         if (ntree->type == NTREE_COMPOSIT) {
1671                                 do_versions_compositor_render_passes(ntree);
1672                         }
1673                 } FOREACH_NODETREE_END;
1674         }
1675
1676         if (!MAIN_VERSION_ATLEAST(bmain, 279, 0)) {
1677                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1678                         if (scene->r.im_format.exr_codec == R_IMF_EXR_CODEC_DWAB) {
1679                                 scene->r.im_format.exr_codec = R_IMF_EXR_CODEC_DWAA;
1680                         }
1681                 }
1682
1683                 /* Fix related to VGroup modifiers creating named defgroup CD layers! See T51520. */
1684                 for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
1685                         CustomData_set_layer_name(&me->vdata, CD_MDEFORMVERT, 0, "");
1686                 }
1687         }
1688
1689         if (!MAIN_VERSION_ATLEAST(bmain, 279, 3)) {
1690                 if (!DNA_struct_elem_find(fd->filesdna, "SmokeDomainSettings", "float", "clipping")) {
1691                         Object *ob;
1692                         ModifierData *md;
1693
1694                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1695                                 for (md = ob->modifiers.first; md; md = md->next) {
1696                                         if (md->type == eModifierType_Smoke) {
1697                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1698                                                 if (smd->domain) {
1699                                                         smd->domain->clipping = 1e-3f;
1700                                                 }
1701                                         }
1702                                 }
1703                         }
1704                 }
1705         }
1706
1707         if (!MAIN_VERSION_ATLEAST(bmain, 279, 4)) {
1708                 /* Fix for invalid state of screen due to bug in older versions. */
1709                 for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
1710                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
1711                                 if (sa->full && sc->state == SCREENNORMAL) {
1712                                         sa->full = NULL;
1713                                 }
1714                         }
1715                 }
1716
1717                 if (!DNA_struct_elem_find(fd->filesdna, "Brush", "float", "falloff_angle")) {
1718                         for (Brush *br = bmain->brush.first; br; br = br->id.next) {
1719                                 br->falloff_angle = DEG2RADF(80);
1720                                 br->flag &= ~(
1721                                         BRUSH_FLAG_DEPRECATED_1 | BRUSH_FLAG_DEPRECATED_2 |
1722                                         BRUSH_FLAG_DEPRECATED_3 | BRUSH_FLAG_DEPRECATED_4 |
1723                                         BRUSH_FRONTFACE_FALLOFF);
1724                         }
1725
1726                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1727                                 ToolSettings *ts = scene->toolsettings;
1728                                 for (int i = 0; i < 2; i++) {
1729                                         VPaint *vp = i ? ts->vpaint : ts->wpaint;
1730                                         if (vp != NULL) {
1731                                                 /* remove all other flags */
1732                                                 vp->flag &= (VP_FLAG_VGROUP_RESTRICT);
1733                                         }
1734                                 }
1735                         }
1736                 }
1737
1738                 /* Simple deform modifier no longer assumes Z axis (X for bend type).
1739                  * Must set previous defaults. */
1740                 if (!DNA_struct_elem_find(fd->filesdna, "SimpleDeformModifierData", "char", "deform_axis")) {
1741                         for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1742                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
1743                                         if (md->type == eModifierType_SimpleDeform) {
1744                                                 SimpleDeformModifierData *smd = (SimpleDeformModifierData *)md;
1745                                                 smd->deform_axis = 2;
1746                                         }
1747                                 }
1748                         }
1749                 }
1750
1751                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1752                         int preset = scene->r.ffcodecdata.ffmpeg_preset;
1753                         if (preset == FFM_PRESET_NONE || preset >= FFM_PRESET_GOOD) {
1754                                 continue;
1755                         }
1756                         if (preset <= FFM_PRESET_FAST) {
1757                                 preset = FFM_PRESET_REALTIME;
1758                         }
1759                         else if (preset >= FFM_PRESET_SLOW) {
1760                                 preset = FFM_PRESET_BEST;
1761                         }
1762                         else {
1763                                 preset = FFM_PRESET_GOOD;
1764                         }
1765                         scene->r.ffcodecdata.ffmpeg_preset = preset;
1766                 }
1767
1768                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleInstanceModifierData", "float", "particle_amount")) {
1769                         for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1770                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
1771                                         if (md->type == eModifierType_ParticleInstance) {
1772                                                 ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
1773                                                 pimd->space = eParticleInstanceSpace_World;
1774                                                 pimd->particle_amount = 1.0f;
1775                                         }
1776                                 }
1777                         }
1778                 }
1779         }
1780 }
1781
1782 void do_versions_after_linking_270(Main *bmain)
1783 {
1784         /* To be added to next subversion bump! */
1785         if (!MAIN_VERSION_ATLEAST(bmain, 279, 0)) {
1786                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1787                         if (ntree->type == NTREE_COMPOSIT) {
1788                                 ntreeSetTypes(NULL, ntree);
1789                                 for (bNode *node = ntree->nodes.first; node; node = node->next) {
1790                                         if (node->type == CMP_NODE_HUE_SAT) {
1791                                                 do_version_hue_sat_node(ntree, node);
1792                                         }
1793                                 }
1794                         }
1795                 } FOREACH_NODETREE_END;
1796         }
1797
1798         if (!MAIN_VERSION_ATLEAST(bmain, 279, 2)) {
1799                 /* B-Bones (bbone_in/out -> bbone_easein/out) + Stepped FMod Frame Start/End fix */
1800                 /* if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "bbone_easein")) */
1801                 BKE_fcurves_main_cb(bmain, do_version_bbone_easing_fcurve_fix, NULL);
1802         }
1803 }