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