Fix T45709: Cached Hair system is not seen in 2.75
[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_brush_types.h"
38 #include "DNA_camera_types.h"
39 #include "DNA_cloth_types.h"
40 #include "DNA_constraint_types.h"
41 #include "DNA_sdna_types.h"
42 #include "DNA_sequence_types.h"
43 #include "DNA_space_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_object_force.h"
46 #include "DNA_object_types.h"
47 #include "DNA_mesh_types.h"
48 #include "DNA_modifier_types.h"
49 #include "DNA_particle_types.h"
50 #include "DNA_linestyle_types.h"
51 #include "DNA_actuator_types.h"
52 #include "DNA_view3d_types.h"
53
54 #include "DNA_genfile.h"
55
56 #include "BKE_main.h"
57 #include "BKE_modifier.h"
58 #include "BKE_node.h"
59 #include "BKE_scene.h"
60 #include "BKE_sequencer.h"
61 #include "BKE_screen.h"
62
63 #include "BLI_math.h"
64 #include "BLI_listbase.h"
65 #include "BLI_string.h"
66
67 #include "BLO_readfile.h"
68
69 #include "readfile.h"
70
71 #include "MEM_guardedalloc.h"
72
73 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
74 {
75         bConstraint *con;
76
77         for (con = lb->first; con; con = con->next) {
78                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
79                         bTransformConstraint *data = (bTransformConstraint *)con->data;
80                         const float deg_to_rad_f = DEG2RADF(1.0f);
81
82                         if (data->from == TRANS_ROTATION) {
83                                 mul_v3_fl(data->from_min, deg_to_rad_f);
84                                 mul_v3_fl(data->from_max, deg_to_rad_f);
85                         }
86
87                         if (data->to == TRANS_ROTATION) {
88                                 mul_v3_fl(data->to_min, deg_to_rad_f);
89                                 mul_v3_fl(data->to_max, deg_to_rad_f);
90                         }
91                 }
92         }
93 }
94
95 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
96 {
97         bConstraint *con;
98
99         for (con = lb->first; con; con = con->next) {
100                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
101                         bTransformConstraint *data = (bTransformConstraint *)con->data;
102
103                         if (data->from == TRANS_ROTATION) {
104                                 copy_v3_v3(data->from_min_rot, data->from_min);
105                                 copy_v3_v3(data->from_max_rot, data->from_max);
106                         }
107                         else if (data->from == TRANS_SCALE) {
108                                 copy_v3_v3(data->from_min_scale, data->from_min);
109                                 copy_v3_v3(data->from_max_scale, data->from_max);
110                         }
111
112                         if (data->to == TRANS_ROTATION) {
113                                 copy_v3_v3(data->to_min_rot, data->to_min);
114                                 copy_v3_v3(data->to_max_rot, data->to_max);
115                         }
116                         else if (data->to == TRANS_SCALE) {
117                                 copy_v3_v3(data->to_min_scale, data->to_min);
118                                 copy_v3_v3(data->to_max_scale, data->to_max);
119                         }
120                 }
121         }
122 }
123
124 static void do_version_constraints_stretch_to_limits(ListBase *lb)
125 {
126         bConstraint *con;
127
128         for (con = lb->first; con; con = con->next) {
129                 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
130                         bStretchToConstraint *data = (bStretchToConstraint *)con->data;
131                         data->bulge_min = 1.0f;
132                         data->bulge_max = 1.0f;
133                 }
134         }
135 }
136
137 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
138 {
139         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
140
141                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
142                         Object *ob;
143
144                         for (ob = main->object.first; ob; ob = ob->id.next) {
145                                 ModifierData *md;
146                                 for (md = ob->modifiers.first; md; md = md->next) {
147                                         if (md->type == eModifierType_Bevel) {
148                                                 BevelModifierData *bmd = (BevelModifierData *)md;
149                                                 bmd->profile = 0.5f;
150                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
151                                         }
152                                 }
153                         }
154                 }
155
156                 /* nodes don't use fixed node->id any more, clean up */
157                 FOREACH_NODETREE(main, ntree, id) {
158                         if (ntree->type == NTREE_COMPOSIT) {
159                                 bNode *node;
160                                 for (node = ntree->nodes.first; node; node = node->next) {
161                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
162                                                 node->id = NULL;
163                                         }
164                                 }
165                         }
166                 } FOREACH_NODETREE_END
167
168                 {
169                         bScreen *screen;
170
171                         for (screen = main->screen.first; screen; screen = screen->id.next) {
172                                 ScrArea *area;
173                                 for (area = screen->areabase.first; area; area = area->next) {
174                                         SpaceLink *space_link;
175                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
176                                                 if (space_link->spacetype == SPACE_CLIP) {
177                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
178                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
179                                                                 space_clip->mode = SC_MODE_TRACKING;
180                                                         }
181                                                 }
182                                         }
183                                 }
184                         }
185                 }
186
187                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
188                         MovieClip *clip;
189                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
190                                 clip->tracking.settings.default_weight = 1.0f;
191                         }
192                 }
193         }
194
195         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
196                 Scene *sce;
197                 Object *ob;
198
199                 /* Update Transform constraint (another deg -> rad stuff). */
200                 for (ob = main->object.first; ob; ob = ob->id.next) {
201                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
202
203                         if (ob->pose) {
204                                 /* Bones constraints! */
205                                 bPoseChannel *pchan;
206                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
207                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
208                                 }
209                         }
210                 }
211
212                 for (sce = main->scene.first; sce; sce = sce->id.next) {
213                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
214                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
215                         }
216                 }
217         }
218
219         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
220                 Mesh *me;
221
222                 /* Mesh smoothresh deg->rad. */
223                 for (me = main->mesh.first; me; me = me->id.next) {
224                         me->smoothresh = DEG2RADF(me->smoothresh);
225                 }
226         }
227
228         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
229                 FreestyleLineStyle *linestyle;
230
231                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
232                         linestyle->flag |= LS_NO_SORTING;
233                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
234                         linestyle->integration_type = LS_INTEGRATION_MEAN;
235                 }
236         }
237
238         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
239                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
240                  * This will always reset situation to a valid state.
241                  */
242                 bScreen *sc;
243
244                 for (sc = main->screen.first; sc; sc = sc->id.next) {
245                         ScrArea *sa;
246                         for (sa = sc->areabase.first; sa; sa = sa->next) {
247                                 SpaceLink *sl;
248
249                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
250                                         ARegion *ar;
251                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
252
253                                         for (ar = lb->first; ar; ar = ar->next) {
254                                                 BLI_listbase_clear(&ar->ui_previews);
255                                         }
256                                 }
257                         }
258                 }
259         }
260
261         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
262                 Object *ob;
263
264                 /* Update Transform constraint (again :|). */
265                 for (ob = main->object.first; ob; ob = ob->id.next) {
266                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
267
268                         if (ob->pose) {
269                                 /* Bones constraints! */
270                                 bPoseChannel *pchan;
271                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
272                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
273                                 }
274                         }
275                 }
276         }
277
278         if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
279                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
280                         Material *ma;
281
282                         for (ma = main->mat.first; ma; ma = ma->id.next)
283                                 ma->mode2 = MA_CASTSHADOW;
284                 }
285
286                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
287                         Scene *sce;
288
289                         for (sce = main->scene.first; sce; sce = sce->id.next) {
290                                 sce->r.bake.flag = R_BAKE_CLEAR;
291                                 sce->r.bake.width = 512;
292                                 sce->r.bake.height = 512;
293                                 sce->r.bake.margin = 16;
294                                 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
295                                 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
296                                 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
297                                 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
298                                 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
299
300                                 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
301                                 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
302                                 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
303                                 sce->r.bake.im_format.quality = 90;
304                                 sce->r.bake.im_format.compress = 15;
305                         }
306                 }
307
308                 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
309                         FreestyleLineStyle *linestyle;
310
311                         for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
312                                 linestyle->flag |= LS_TEXTURE;
313                                 linestyle->texstep = 1.0;
314                         }
315                 }
316
317                 {
318                         Scene *scene;
319                         for (scene = main->scene.first; scene; scene = scene->id.next) {
320                                 int num_layers = BLI_listbase_count(&scene->r.layers);
321                                 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
322                         }
323                 }
324         }
325
326         if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
327                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
328                         Material *mat;
329
330                         for (mat = main->mat.first; mat; mat = mat->id.next) {
331                                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
332                                 mat->line_col[3] = mat->alpha;
333                         }
334                 }
335
336                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
337                         Scene *scene;
338                         for (scene = main->scene.first; scene; scene = scene->id.next) {
339                                 scene->r.preview_start_resolution = 64;
340                         }
341                 }
342         }
343
344         if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
345                 /* init up & track axis property of trackto actuators */
346                 Object *ob;
347
348                 for (ob = main->object.first; ob; ob = ob->id.next) {
349                         bActuator *act;
350                         for (act = ob->actuators.first; act; act = act->next) {
351                                 if (act->type == ACT_EDIT_OBJECT) {
352                                         bEditObjectActuator *eoact = act->data;
353                                         eoact->trackflag = ob->trackflag;
354                                         /* if trackflag is pointing +-Z axis then upflag should point Y axis.
355                                          * Rest of trackflag cases, upflag should be point z axis */
356                                         if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
357                                                 eoact->upflag = 1;
358                                         }
359                                         else {
360                                                 eoact->upflag = 2;
361                                         }
362                                 }
363                         }
364                 }
365         }
366
367         if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
368                 Brush *br;
369
370                 for (br = main->brush.first; br; br = br->id.next) {
371                         br->fill_threshold = 0.2f;
372                 }
373
374                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
375                         Object *ob;
376                         for (ob = main->object.first; ob; ob = ob->id.next) {
377                                 ModifierData *md;
378
379                                 for (md = ob->modifiers.first; md; md = md->next) {
380                                         if (md->type == eModifierType_Bevel) {
381                                                 BevelModifierData *bmd = (BevelModifierData *)md;
382                                                 bmd->mat = -1;
383                                         }
384                                 }
385                         }
386                 }
387         }
388
389         if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
390                 Object *ob;
391                 for (ob = main->object.first; ob; ob = ob->id.next) {
392                         ModifierData *md;
393
394                         for (md = ob->modifiers.first; md; md = md->next) {
395                                 if (md->type == eModifierType_ParticleSystem) {
396                                         ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
397                                         if (pmd->psys && pmd->psys->clmd) {
398                                                 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
399                                         }
400                                 }
401                         }
402                 }
403         }
404
405         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
406                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
407                         Scene *scene;
408                         for (scene = main->scene.first; scene; scene = scene->id.next) {
409                                 scene->r.preview_start_resolution = 64;
410                         }
411                 }
412         }
413
414         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
415                 Brush *br;
416                 for (br = main->brush.first; br; br = br->id.next) {
417                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
418                                 br->alpha = 1.0f;
419                 }
420         }
421
422         if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
423                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
424                         Image *image;
425                         for (image = main->image.first; image != NULL; image = image->id.next) {
426                                 image->gen_color[3] = 1.0f;
427                         }
428                 }
429
430                 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
431                         Object *ob;
432
433                         /* Update Transform constraint (again :|). */
434                         for (ob = main->object.first; ob; ob = ob->id.next) {
435                                 do_version_constraints_stretch_to_limits(&ob->constraints);
436
437                                 if (ob->pose) {
438                                         /* Bones constraints! */
439                                         bPoseChannel *pchan;
440                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
441                                                 do_version_constraints_stretch_to_limits(&pchan->constraints);
442                                         }
443                                 }
444                         }
445                 }
446         }
447
448         if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
449 #define BRUSH_RAKE (1 << 7)
450 #define BRUSH_RANDOM_ROTATION (1 << 25)
451
452                 Brush *br;
453
454                 for (br = main->brush.first; br; br = br->id.next) {
455                         if (br->flag & BRUSH_RAKE) {
456                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
457                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
458                         }
459                         else if (br->flag & BRUSH_RANDOM_ROTATION) {
460                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
461                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
462                         }
463                         br->mtex.random_angle = 2.0 * M_PI;
464                         br->mask_mtex.random_angle = 2.0 * M_PI;
465                 }
466         }
467
468 #undef BRUSH_RAKE
469 #undef BRUSH_RANDOM_ROTATION
470
471         /* Customizable Safe Areas */
472         if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
473                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
474                         Scene *scene;
475
476                         for (scene = main->scene.first; scene; scene = scene->id.next) {
477                                 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
478                                 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
479                                 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
480                                 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
481                         }
482                 }
483         }
484         
485         if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
486                 ParticleSettings *part;
487                 for (part = main->particle.first; part; part = part->id.next) {
488                         if (part->clumpcurve)
489                                 part->child_flag |= PART_CHILD_USE_CLUMP_CURVE;
490                         if (part->roughcurve)
491                                 part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
492                 }
493         }
494
495         if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
496                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
497                         Object *ob;
498                         ModifierData *md;
499                         for (ob = main->object.first; ob; ob = ob->id.next) {
500                                 for (md = ob->modifiers.first; md; md = md->next) {
501                                         if (md->type == eModifierType_Cloth) {
502                                                 ClothModifierData *clmd = (ClothModifierData *)md;
503                                                 clmd->sim_parms->bending_damping = 0.5f;
504                                         }
505                                         else if (md->type == eModifierType_ParticleSystem) {
506                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
507                                                 if (pmd->psys->clmd) {
508                                                         pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
509                                                 }
510                                         }
511                                 }
512                         }
513                 }
514
515                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "float", "clump_noise_size")) {
516                         ParticleSettings *part;
517                         for (part = main->particle.first; part; part = part->id.next) {
518                                 part->clump_noise_size = 1.0f;
519                         }
520                 }
521
522                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "int", "kink_extra_steps")) {
523                         ParticleSettings *part;
524                         for (part = main->particle.first; part; part = part->id.next) {
525                                 part->kink_extra_steps = 4;
526                         }
527                 }
528
529                 if (!DNA_struct_elem_find(fd->filesdna, "MTex", "float", "kinkampfac")) {
530                         ParticleSettings *part;
531                         for (part = main->particle.first; part; part = part->id.next) {
532                                 int a;
533                                 for (a = 0; a < MAX_MTEX; a++) {
534                                         MTex *mtex = part->mtex[a];
535                                         if (mtex) {
536                                                 mtex->kinkampfac = 1.0f;
537                                         }
538                                 }
539                         }
540                 }
541
542                 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
543                         Object *ob;
544
545                         for (ob = main->object.first; ob; ob = ob->id.next) {
546                                 ModifierData *md;
547                                 for (md = ob->modifiers.first; md; md = md->next) {
548                                         if (md->type == eModifierType_Hook) {
549                                                 HookModifierData *hmd = (HookModifierData *)md;
550                                                 hmd->falloff_type = eHook_Falloff_InvSquare;
551                                         }
552                                 }
553                         }
554                 }
555
556                 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
557                         FOREACH_NODETREE(main, ntree, id) {
558                                 if (ntree->type == NTREE_COMPOSIT) {
559                                         bNode *node;
560                                         for (node = ntree->nodes.first; node; node = node->next) {
561                                                 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
562                                                         NodePlaneTrackDeformData *data = node->storage;
563                                                         data->flag = 0;
564                                                         data->motion_blur_samples = 16;
565                                                         data->motion_blur_shutter = 0.5f;
566                                                 }
567                                         }
568                                 }
569                         }
570                         FOREACH_NODETREE_END
571                 }
572
573                 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
574                         Camera *ca;
575                         for (ca = main->camera.first; ca; ca = ca->id.next) {
576                                 ca->gpu_dof.fstop = 128.0f;
577                                 ca->gpu_dof.focal_length = 1.0f;
578                                 ca->gpu_dof.focus_distance = 1.0f;
579                                 ca->gpu_dof.sensor = 1.0f;
580                         }
581                 }
582         }
583
584         if (!MAIN_VERSION_ATLEAST(main, 273, 7)) {
585                 bScreen *scr;
586                 ScrArea *sa;
587                 SpaceLink *sl;
588                 ARegion *ar;
589
590                 for (scr = main->screen.first; scr; scr = scr->id.next) {
591                         /* Remove old deprecated region from filebrowsers */
592                         for (sa = scr->areabase.first; sa; sa = sa->next) {
593                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
594                                         if (sl->spacetype == SPACE_FILE) {
595                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
596                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
597                                                                 break;
598                                                         }
599                                                 }
600
601                                                 if (ar) {
602                                                         /* Free old deprecated 'channel' region... */
603                                                         BKE_area_region_free(NULL, ar);
604                                                         BLI_freelinkN(&sl->regionbase, ar);
605                                                 }
606                                         }
607                                 }
608                         }
609                 }
610         }
611
612         if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
613                 Object *ob;
614                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
615                         ModifierData *md;
616                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
617                                 if (modifier_unique_name(&ob->modifiers, md)) {
618                                         printf("Warning: Object '%s' had several modifiers with the "
619                                                "same name, renamed one of them to '%s'.\n",
620                                                ob->id.name + 2, md->name);
621                                 }
622                         }
623                 }
624         }
625
626         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
627                 bScreen *scr;
628                 ScrArea *sa;
629                 SpaceLink *sl;
630                 ARegion *ar;
631
632                 /* Make sure sequencer preview area limits zoom */
633                 for (scr = main->screen.first; scr; scr = scr->id.next) {
634                         for (sa = scr->areabase.first; sa; sa = sa->next) {
635                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
636                                         if (sl->spacetype == SPACE_SEQ) {
637                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
638                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
639                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
640                                                                 ar->v2d.minzoom = 0.001f;
641                                                                 ar->v2d.maxzoom = 1000.0f;
642                                                                 break;
643                                                         }
644                                                 }
645                                         }
646                                 }
647                         }
648                 }
649         }
650
651         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
652                 /* particle systems need to be forced to redistribute for jitter mode fix */
653                 {
654                         Object *ob;
655                         ParticleSystem *psys;
656                         for (ob = main->object.first; ob; ob = ob->id.next) {
657                                 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
658                                         if ((psys->pointcache->flag & PTCACHE_BAKED) == 0) {
659                                                 psys->recalc |= PSYS_RECALC_RESET;
660                                         }
661                                 }
662                         }
663                 }
664
665                 /* hysteresis setted to 10% but not actived */
666                 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
667                         Object *ob;
668                         for (ob = main->object.first; ob; ob = ob->id.next) {
669                                 LodLevel *level;
670                                 for (level = ob->lodlevels.first; level; level = level->next) {
671                                         level->obhysteresis = 10;
672                                 }
673                         }
674                 }
675
676                 if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
677                         Scene *scene;
678                         for (scene = main->scene.first; scene; scene = scene->id.next) {
679                                 scene->gm.scehysteresis = 10;
680                         }
681                 }
682         }
683
684         if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
685                 FOREACH_NODETREE(main, ntree, id) {
686                         bNode *node;
687                         bNodeSocket *sock;
688
689                         for (node = ntree->nodes.first; node; node = node->next) {
690                                 if (node->type == SH_NODE_MATERIAL) {
691                                         for (sock = node->inputs.first; sock; sock = sock->next) {
692                                                 if (STREQ(sock->name, "Refl")) {
693                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
694                                                 }
695                                         }
696                                 }
697                                 else if (node->type == SH_NODE_MATERIAL_EXT) {
698                                         for (sock = node->outputs.first; sock; sock = sock->next) {
699                                                 if (STREQ(sock->name, "Refl")) {
700                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
701                                                 }
702                                                 else if (STREQ(sock->name, "Ray Mirror")) {
703                                                         BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
704                                                 }
705                                         }
706                                 }
707                         }
708                 } FOREACH_NODETREE_END
709         }
710
711         if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
712                 SceneRenderView *srv;
713                 wmWindowManager *wm;
714                 bScreen *screen;
715                 wmWindow *win;
716                 Scene *scene;
717                 Camera *cam;
718                 Image *ima;
719
720                 for (scene = main->scene.first; scene; scene = scene->id.next) {
721                         Sequence *seq;
722
723                         BKE_scene_add_render_view(scene, STEREO_LEFT_NAME);
724                         srv = scene->r.views.first;
725                         BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
726
727                         BKE_scene_add_render_view(scene, STEREO_RIGHT_NAME);
728                         srv = scene->r.views.last;
729                         BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
730
731                         SEQ_BEGIN (scene->ed, seq)
732                         {
733                                 seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
734
735 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
736 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
737                                 if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) {
738                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
739                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
740                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
741                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
742                                 }
743 #undef SEQ_USE_PROXY_CUSTOM_DIR
744 #undef SEQ_USE_PROXY_CUSTOM_FILE
745
746                         }
747                         SEQ_END
748                 }
749
750                 for (screen = main->screen.first; screen; screen = screen->id.next) {
751                         ScrArea *sa;
752                         for (sa = screen->areabase.first; sa; sa = sa->next) {
753                                 SpaceLink *sl;
754
755                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
756                                         switch (sl->spacetype) {
757                                                 case SPACE_VIEW3D:
758                                                 {
759                                                         View3D *v3d = (View3D *)sl;
760                                                         v3d->stereo3d_camera = STEREO_3D_ID;
761                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
762                                                         v3d->stereo3d_convergence_alpha = 0.15f;
763                                                         v3d->stereo3d_volume_alpha = 0.05f;
764                                                         break;
765                                                 }
766                                                 case SPACE_IMAGE:
767                                                 {
768                                                         SpaceImage *sima = (SpaceImage *) sl;
769                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
770                                                         sima->iuser.passtype = SCE_PASS_COMBINED;
771                                                         break;
772                                                 }
773                                         }
774                                 }
775                         }
776                 }
777
778                 for (cam = main->camera.first; cam; cam = cam->id.next) {
779                         cam->stereo.interocular_distance = 0.065f;
780                         cam->stereo.convergence_distance = 30.0f * 0.065f;
781                 }
782
783                 for (ima = main->image.first; ima; ima = ima->id.next) {
784                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
785
786                         if (ima->packedfile) {
787                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
788                                 BLI_addtail(&ima->packedfiles, imapf);
789
790                                 imapf->packedfile = ima->packedfile;
791                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
792                                 ima->packedfile = NULL;
793                         }
794                 }
795
796                 for (wm = main->wm.first; wm; wm = wm->id.next) {
797                         for (win = wm->windows.first; win; win = win->next) {
798                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
799                         }
800                 }
801         }
802
803         if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
804                 bScreen *screen;
805
806                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
807                         for (screen = main->screen.first; screen; screen = screen->id.next) {
808                                 ScrArea *sa;
809
810                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
811                                         SpaceLink *sl;
812
813                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
814                                                 if (sl->spacetype == SPACE_FILE) {
815                                                         SpaceFile *sfile = (SpaceFile *)sl;
816
817                                                         if (sfile->params) {
818                                                                 sfile->params->thumbnail_size = 128;
819                                                         }
820                                                 }
821                                         }
822                                 }
823                         }
824                 }
825
826                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
827                         Scene *scene;
828                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
829                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
830                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
831                         }
832                 }
833
834                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
835                         Object *ob;
836
837                         for (ob = main->object.first; ob; ob = ob->id.next) {
838                                 ModifierData *md;
839                                 for (md = ob->modifiers.first; md; md = md->next) {
840                                         if (md->type == eModifierType_Decimate) {
841                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
842                                                 dmd->defgrp_factor = 1.0f;
843                                         }
844                                 }
845                         }
846                 }
847         }
848
849         if (!MAIN_VERSION_ATLEAST(main, 275, 3)) {
850                 Brush *br;
851 #define BRUSH_TORUS (1 << 1)
852                 for (br = main->brush.first; br; br = br->id.next) {
853                         br->flag &= ~BRUSH_TORUS;
854                 }
855 #undef BRUSH_TORUS
856         }
857 }