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