BMesh decimate, improve behavior with weights
[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 #include "BLI_string.h"
31
32 /* for MinGW32 definition of NULL, could use BLI_blenlib.h instead too */
33 #include <stddef.h>
34
35 /* allow readfile to use deprecated functionality */
36 #define DNA_DEPRECATED_ALLOW
37
38 #include "DNA_brush_types.h"
39 #include "DNA_camera_types.h"
40 #include "DNA_cloth_types.h"
41 #include "DNA_constraint_types.h"
42 #include "DNA_sdna_types.h"
43 #include "DNA_sequence_types.h"
44 #include "DNA_space_types.h"
45 #include "DNA_screen_types.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_camera_types.h"
53 #include "DNA_view3d_types.h"
54
55 #include "DNA_genfile.h"
56
57 #include "BKE_main.h"
58 #include "BKE_modifier.h"
59 #include "BKE_node.h"
60 #include "BKE_scene.h"
61 #include "BKE_sequencer.h"
62 #include "BKE_screen.h"
63 #include "BKE_sequencer.h"
64
65 #include "BLI_math.h"
66 #include "BLI_listbase.h"
67 #include "BLI_string.h"
68
69 #include "BLO_readfile.h"
70
71 #include "readfile.h"
72
73 #include "MEM_guardedalloc.h"
74
75 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
76 {
77         bConstraint *con;
78
79         for (con = lb->first; con; con = con->next) {
80                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
81                         bTransformConstraint *data = (bTransformConstraint *)con->data;
82                         const float deg_to_rad_f = DEG2RADF(1.0f);
83
84                         if (data->from == TRANS_ROTATION) {
85                                 mul_v3_fl(data->from_min, deg_to_rad_f);
86                                 mul_v3_fl(data->from_max, deg_to_rad_f);
87                         }
88
89                         if (data->to == TRANS_ROTATION) {
90                                 mul_v3_fl(data->to_min, deg_to_rad_f);
91                                 mul_v3_fl(data->to_max, deg_to_rad_f);
92                         }
93                 }
94         }
95 }
96
97 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
98 {
99         bConstraint *con;
100
101         for (con = lb->first; con; con = con->next) {
102                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
103                         bTransformConstraint *data = (bTransformConstraint *)con->data;
104
105                         if (data->from == TRANS_ROTATION) {
106                                 copy_v3_v3(data->from_min_rot, data->from_min);
107                                 copy_v3_v3(data->from_max_rot, data->from_max);
108                         }
109                         else if (data->from == TRANS_SCALE) {
110                                 copy_v3_v3(data->from_min_scale, data->from_min);
111                                 copy_v3_v3(data->from_max_scale, data->from_max);
112                         }
113
114                         if (data->to == TRANS_ROTATION) {
115                                 copy_v3_v3(data->to_min_rot, data->to_min);
116                                 copy_v3_v3(data->to_max_rot, data->to_max);
117                         }
118                         else if (data->to == TRANS_SCALE) {
119                                 copy_v3_v3(data->to_min_scale, data->to_min);
120                                 copy_v3_v3(data->to_max_scale, data->to_max);
121                         }
122                 }
123         }
124 }
125
126 static void do_version_constraints_stretch_to_limits(ListBase *lb)
127 {
128         bConstraint *con;
129
130         for (con = lb->first; con; con = con->next) {
131                 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
132                         bStretchToConstraint *data = (bStretchToConstraint *)con->data;
133                         data->bulge_min = 1.0f;
134                         data->bulge_max = 1.0f;
135                 }
136         }
137 }
138
139 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
140 {
141         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
142
143                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
144                         Object *ob;
145
146                         for (ob = main->object.first; ob; ob = ob->id.next) {
147                                 ModifierData *md;
148                                 for (md = ob->modifiers.first; md; md = md->next) {
149                                         if (md->type == eModifierType_Bevel) {
150                                                 BevelModifierData *bmd = (BevelModifierData *)md;
151                                                 bmd->profile = 0.5f;
152                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
153                                         }
154                                 }
155                         }
156                 }
157
158                 /* nodes don't use fixed node->id any more, clean up */
159                 FOREACH_NODETREE(main, ntree, id) {
160                         if (ntree->type == NTREE_COMPOSIT) {
161                                 bNode *node;
162                                 for (node = ntree->nodes.first; node; node = node->next) {
163                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
164                                                 node->id = NULL;
165                                         }
166                                 }
167                         }
168                 } FOREACH_NODETREE_END
169
170                 {
171                         bScreen *screen;
172
173                         for (screen = main->screen.first; screen; screen = screen->id.next) {
174                                 ScrArea *area;
175                                 for (area = screen->areabase.first; area; area = area->next) {
176                                         SpaceLink *space_link;
177                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
178                                                 if (space_link->spacetype == SPACE_CLIP) {
179                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
180                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
181                                                                 space_clip->mode = SC_MODE_TRACKING;
182                                                         }
183                                                 }
184                                         }
185                                 }
186                         }
187                 }
188
189                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
190                         MovieClip *clip;
191                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
192                                 clip->tracking.settings.default_weight = 1.0f;
193                         }
194                 }
195         }
196
197         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
198                 Scene *sce;
199                 Object *ob;
200
201                 /* Update Transform constraint (another deg -> rad stuff). */
202                 for (ob = main->object.first; ob; ob = ob->id.next) {
203                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
204
205                         if (ob->pose) {
206                                 /* Bones constraints! */
207                                 bPoseChannel *pchan;
208                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
209                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
210                                 }
211                         }
212                 }
213
214                 for (sce = main->scene.first; sce; sce = sce->id.next) {
215                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
216                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
217                         }
218                 }
219         }
220
221         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
222                 Mesh *me;
223
224                 /* Mesh smoothresh deg->rad. */
225                 for (me = main->mesh.first; me; me = me->id.next) {
226                         me->smoothresh = DEG2RADF(me->smoothresh);
227                 }
228         }
229
230         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
231                 FreestyleLineStyle *linestyle;
232
233                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
234                         linestyle->flag |= LS_NO_SORTING;
235                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
236                         linestyle->integration_type = LS_INTEGRATION_MEAN;
237                 }
238         }
239
240         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
241                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
242                  * This will always reset situation to a valid state.
243                  */
244                 bScreen *sc;
245
246                 for (sc = main->screen.first; sc; sc = sc->id.next) {
247                         ScrArea *sa;
248                         for (sa = sc->areabase.first; sa; sa = sa->next) {
249                                 SpaceLink *sl;
250
251                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
252                                         ARegion *ar;
253                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
254
255                                         for (ar = lb->first; ar; ar = ar->next) {
256                                                 BLI_listbase_clear(&ar->ui_previews);
257                                         }
258                                 }
259                         }
260                 }
261         }
262
263         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
264                 Object *ob;
265
266                 /* Update Transform constraint (again :|). */
267                 for (ob = main->object.first; ob; ob = ob->id.next) {
268                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
269
270                         if (ob->pose) {
271                                 /* Bones constraints! */
272                                 bPoseChannel *pchan;
273                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
274                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
275                                 }
276                         }
277                 }
278         }
279
280         if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
281                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
282                         Material *ma;
283
284                         for (ma = main->mat.first; ma; ma = ma->id.next)
285                                 ma->mode2 = MA_CASTSHADOW;
286                 }
287
288                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
289                         Scene *sce;
290
291                         for (sce = main->scene.first; sce; sce = sce->id.next) {
292                                 sce->r.bake.flag = R_BAKE_CLEAR;
293                                 sce->r.bake.width = 512;
294                                 sce->r.bake.height = 512;
295                                 sce->r.bake.margin = 16;
296                                 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
297                                 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
298                                 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
299                                 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
300                                 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
301
302                                 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
303                                 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
304                                 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
305                                 sce->r.bake.im_format.quality = 90;
306                                 sce->r.bake.im_format.compress = 15;
307                         }
308                 }
309
310                 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
311                         FreestyleLineStyle *linestyle;
312
313                         for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
314                                 linestyle->flag |= LS_TEXTURE;
315                                 linestyle->texstep = 1.0;
316                         }
317                 }
318
319                 {
320                         Scene *scene;
321                         for (scene = main->scene.first; scene; scene = scene->id.next) {
322                                 int num_layers = BLI_listbase_count(&scene->r.layers);
323                                 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
324                         }
325                 }
326         }
327
328         if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
329                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
330                         Material *mat;
331
332                         for (mat = main->mat.first; mat; mat = mat->id.next) {
333                                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
334                                 mat->line_col[3] = mat->alpha;
335                         }
336                 }
337
338                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
339                         Scene *scene;
340                         for (scene = main->scene.first; scene; scene = scene->id.next) {
341                                 scene->r.preview_start_resolution = 64;
342                         }
343                 }
344         }
345
346         if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
347                 /* init up & track axis property of trackto actuators */
348                 Object *ob;
349
350                 for (ob = main->object.first; ob; ob = ob->id.next) {
351                         bActuator *act;
352                         for (act = ob->actuators.first; act; act = act->next) {
353                                 if (act->type == ACT_EDIT_OBJECT) {
354                                         bEditObjectActuator *eoact = act->data;
355                                         eoact->trackflag = ob->trackflag;
356                                         /* if trackflag is pointing +-Z axis then upflag should point Y axis.
357                                          * Rest of trackflag cases, upflag should be point z axis */
358                                         if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
359                                                 eoact->upflag = 1;
360                                         }
361                                         else {
362                                                 eoact->upflag = 2;
363                                         }
364                                 }
365                         }
366                 }
367         }
368
369         if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
370                 Brush *br;
371
372                 for (br = main->brush.first; br; br = br->id.next) {
373                         br->fill_threshold = 0.2f;
374                 }
375
376                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
377                         Object *ob;
378                         for (ob = main->object.first; ob; ob = ob->id.next) {
379                                 ModifierData *md;
380
381                                 for (md = ob->modifiers.first; md; md = md->next) {
382                                         if (md->type == eModifierType_Bevel) {
383                                                 BevelModifierData *bmd = (BevelModifierData *)md;
384                                                 bmd->mat = -1;
385                                         }
386                                 }
387                         }
388                 }
389         }
390
391         if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
392                 Object *ob;
393                 for (ob = main->object.first; ob; ob = ob->id.next) {
394                         ModifierData *md;
395
396                         for (md = ob->modifiers.first; md; md = md->next) {
397                                 if (md->type == eModifierType_ParticleSystem) {
398                                         ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
399                                         if (pmd->psys && pmd->psys->clmd) {
400                                                 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
401                                         }
402                                 }
403                         }
404                 }
405         }
406
407         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
408                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
409                         Scene *scene;
410                         for (scene = main->scene.first; scene; scene = scene->id.next) {
411                                 scene->r.preview_start_resolution = 64;
412                         }
413                 }
414         }
415
416         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
417                 Brush *br;
418                 for (br = main->brush.first; br; br = br->id.next) {
419                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
420                                 br->alpha = 1.0f;
421                 }
422         }
423
424         if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
425                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
426                         Image *image;
427                         for (image = main->image.first; image != NULL; image = image->id.next) {
428                                 image->gen_color[3] = 1.0f;
429                         }
430                 }
431
432                 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
433                         Object *ob;
434
435                         /* Update Transform constraint (again :|). */
436                         for (ob = main->object.first; ob; ob = ob->id.next) {
437                                 do_version_constraints_stretch_to_limits(&ob->constraints);
438
439                                 if (ob->pose) {
440                                         /* Bones constraints! */
441                                         bPoseChannel *pchan;
442                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
443                                                 do_version_constraints_stretch_to_limits(&pchan->constraints);
444                                         }
445                                 }
446                         }
447                 }
448         }
449
450         if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
451 #define BRUSH_RAKE (1 << 7)
452 #define BRUSH_RANDOM_ROTATION (1 << 25)
453
454                 Brush *br;
455
456                 for (br = main->brush.first; br; br = br->id.next) {
457                         if (br->flag & BRUSH_RAKE) {
458                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
459                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
460                         }
461                         else if (br->flag & BRUSH_RANDOM_ROTATION) {
462                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
463                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
464                         }
465                         br->mtex.random_angle = 2.0 * M_PI;
466                         br->mask_mtex.random_angle = 2.0 * M_PI;
467                 }
468         }
469
470 #undef BRUSH_RAKE
471 #undef BRUSH_RANDOM_ROTATION
472
473         /* Customizable Safe Areas */
474         if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
475                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
476                         Scene *scene;
477
478                         for (scene = main->scene.first; scene; scene = scene->id.next) {
479                                 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
480                                 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
481                                 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
482                                 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
483                         }
484                 }
485         }
486         
487         if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
488                 ParticleSettings *part;
489                 for (part = main->particle.first; part; part = part->id.next) {
490                         if (part->clumpcurve)
491                                 part->child_flag |= PART_CHILD_USE_CLUMP_CURVE;
492                         if (part->roughcurve)
493                                 part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
494                 }
495         }
496
497         if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
498                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
499                         Object *ob;
500                         ModifierData *md;
501                         for (ob = main->object.first; ob; ob = ob->id.next) {
502                                 for (md = ob->modifiers.first; md; md = md->next) {
503                                         if (md->type == eModifierType_Cloth) {
504                                                 ClothModifierData *clmd = (ClothModifierData *)md;
505                                                 clmd->sim_parms->bending_damping = 0.5f;
506                                         }
507                                         else if (md->type == eModifierType_ParticleSystem) {
508                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
509                                                 if (pmd->psys->clmd) {
510                                                         pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
511                                                 }
512                                         }
513                                 }
514                         }
515                 }
516
517                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "float", "clump_noise_size")) {
518                         ParticleSettings *part;
519                         for (part = main->particle.first; part; part = part->id.next) {
520                                 part->clump_noise_size = 1.0f;
521                         }
522                 }
523
524                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "int", "kink_extra_steps")) {
525                         ParticleSettings *part;
526                         for (part = main->particle.first; part; part = part->id.next) {
527                                 part->kink_extra_steps = 4;
528                         }
529                 }
530
531                 if (!DNA_struct_elem_find(fd->filesdna, "MTex", "float", "kinkampfac")) {
532                         ParticleSettings *part;
533                         for (part = main->particle.first; part; part = part->id.next) {
534                                 int a;
535                                 for (a = 0; a < MAX_MTEX; a++) {
536                                         MTex *mtex = part->mtex[a];
537                                         if (mtex) {
538                                                 mtex->kinkampfac = 1.0f;
539                                         }
540                                 }
541                         }
542                 }
543
544                 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
545                         Object *ob;
546
547                         for (ob = main->object.first; ob; ob = ob->id.next) {
548                                 ModifierData *md;
549                                 for (md = ob->modifiers.first; md; md = md->next) {
550                                         if (md->type == eModifierType_Hook) {
551                                                 HookModifierData *hmd = (HookModifierData *)md;
552                                                 hmd->falloff_type = eHook_Falloff_InvSquare;
553                                         }
554                                 }
555                         }
556                 }
557
558                 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
559                         FOREACH_NODETREE(main, ntree, id) {
560                                 if (ntree->type == NTREE_COMPOSIT) {
561                                         bNode *node;
562                                         for (node = ntree->nodes.first; node; node = node->next) {
563                                                 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
564                                                         NodePlaneTrackDeformData *data = node->storage;
565                                                         data->flag = 0;
566                                                         data->motion_blur_samples = 16;
567                                                         data->motion_blur_shutter = 0.5f;
568                                                 }
569                                         }
570                                 }
571                         }
572                         FOREACH_NODETREE_END
573                 }
574
575                 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
576                         Camera *ca;
577                         for (ca = main->camera.first; ca; ca = ca->id.next) {
578                                 ca->gpu_dof.fstop = 128.0f;
579                                 ca->gpu_dof.focal_length = 1.0f;
580                                 ca->gpu_dof.focus_distance = 1.0f;
581                                 ca->gpu_dof.sensor = 1.0f;
582                         }
583                 }
584         }
585
586         if (!MAIN_VERSION_ATLEAST(main, 273, 7)) {
587                 bScreen *scr;
588                 ScrArea *sa;
589                 SpaceLink *sl;
590                 ARegion *ar;
591
592                 for (scr = main->screen.first; scr; scr = scr->id.next) {
593                         /* Remove old deprecated region from filebrowsers */
594                         for (sa = scr->areabase.first; sa; sa = sa->next) {
595                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
596                                         if (sl->spacetype == SPACE_FILE) {
597                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
598                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
599                                                                 break;
600                                                         }
601                                                 }
602
603                                                 if (ar) {
604                                                         /* Free old deprecated 'channel' region... */
605                                                         BKE_area_region_free(NULL, ar);
606                                                         BLI_freelinkN(&sl->regionbase, ar);
607                                                 }
608                                         }
609                                 }
610                         }
611                 }
612         }
613
614         if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
615                 Object *ob;
616                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
617                         ModifierData *md;
618                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
619                                 if (modifier_unique_name(&ob->modifiers, md)) {
620                                         printf("Warning: Object '%s' had several modifiers with the "
621                                                "same name, renamed one of them to '%s'.\n",
622                                                ob->id.name + 2, md->name);
623                                 }
624                         }
625                 }
626         }
627
628         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
629                 bScreen *scr;
630                 ScrArea *sa;
631                 SpaceLink *sl;
632                 ARegion *ar;
633
634                 /* Make sure sequencer preview area limits zoom */
635                 for (scr = main->screen.first; scr; scr = scr->id.next) {
636                         for (sa = scr->areabase.first; sa; sa = sa->next) {
637                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
638                                         if (sl->spacetype == SPACE_SEQ) {
639                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
640                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
641                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
642                                                                 ar->v2d.minzoom = 0.001f;
643                                                                 ar->v2d.maxzoom = 1000.0f;
644                                                                 break;
645                                                         }
646                                                 }
647                                         }
648                                 }
649                         }
650                 }
651         }
652
653         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
654                 /* particle systems need to be forced to redistribute for jitter mode fix */
655                 {
656                         Object *ob;
657                         ParticleSystem *psys;
658                         for (ob = main->object.first; ob; ob = ob->id.next) {
659                                 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
660                                         psys->recalc |= PSYS_RECALC_RESET;
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 }