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