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