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