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