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