Cycles-Bake: Custom Baking passes
[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_gpencil_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_force.h"
47 #include "DNA_object_types.h"
48 #include "DNA_mesh_types.h"
49 #include "DNA_modifier_types.h"
50 #include "DNA_particle_types.h"
51 #include "DNA_linestyle_types.h"
52 #include "DNA_actuator_types.h"
53 #include "DNA_view3d_types.h"
54
55 #include "DNA_genfile.h"
56
57 #include "BKE_colortools.h"
58 #include "BKE_library.h"
59 #include "BKE_main.h"
60 #include "BKE_modifier.h"
61 #include "BKE_node.h"
62 #include "BKE_scene.h"
63 #include "BKE_sequencer.h"
64 #include "BKE_screen.h"
65
66 #include "BLI_math.h"
67 #include "BLI_listbase.h"
68 #include "BLI_string.h"
69
70 #include "BLO_readfile.h"
71
72 #include "readfile.h"
73
74 #include "MEM_guardedalloc.h"
75
76 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
77 {
78         bConstraint *con;
79
80         for (con = lb->first; con; con = con->next) {
81                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
82                         bTransformConstraint *data = (bTransformConstraint *)con->data;
83                         const float deg_to_rad_f = DEG2RADF(1.0f);
84
85                         if (data->from == TRANS_ROTATION) {
86                                 mul_v3_fl(data->from_min, deg_to_rad_f);
87                                 mul_v3_fl(data->from_max, deg_to_rad_f);
88                         }
89
90                         if (data->to == TRANS_ROTATION) {
91                                 mul_v3_fl(data->to_min, deg_to_rad_f);
92                                 mul_v3_fl(data->to_max, deg_to_rad_f);
93                         }
94                 }
95         }
96 }
97
98 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
99 {
100         bConstraint *con;
101
102         for (con = lb->first; con; con = con->next) {
103                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
104                         bTransformConstraint *data = (bTransformConstraint *)con->data;
105
106                         if (data->from == TRANS_ROTATION) {
107                                 copy_v3_v3(data->from_min_rot, data->from_min);
108                                 copy_v3_v3(data->from_max_rot, data->from_max);
109                         }
110                         else if (data->from == TRANS_SCALE) {
111                                 copy_v3_v3(data->from_min_scale, data->from_min);
112                                 copy_v3_v3(data->from_max_scale, data->from_max);
113                         }
114
115                         if (data->to == TRANS_ROTATION) {
116                                 copy_v3_v3(data->to_min_rot, data->to_min);
117                                 copy_v3_v3(data->to_max_rot, data->to_max);
118                         }
119                         else if (data->to == TRANS_SCALE) {
120                                 copy_v3_v3(data->to_min_scale, data->to_min);
121                                 copy_v3_v3(data->to_max_scale, data->to_max);
122                         }
123                 }
124         }
125 }
126
127 static void do_version_constraints_stretch_to_limits(ListBase *lb)
128 {
129         bConstraint *con;
130
131         for (con = lb->first; con; con = con->next) {
132                 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
133                         bStretchToConstraint *data = (bStretchToConstraint *)con->data;
134                         data->bulge_min = 1.0f;
135                         data->bulge_max = 1.0f;
136                 }
137         }
138 }
139
140 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
141 {
142         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
143
144                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
145                         Object *ob;
146
147                         for (ob = main->object.first; ob; ob = ob->id.next) {
148                                 ModifierData *md;
149                                 for (md = ob->modifiers.first; md; md = md->next) {
150                                         if (md->type == eModifierType_Bevel) {
151                                                 BevelModifierData *bmd = (BevelModifierData *)md;
152                                                 bmd->profile = 0.5f;
153                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
154                                         }
155                                 }
156                         }
157                 }
158
159                 /* nodes don't use fixed node->id any more, clean up */
160                 FOREACH_NODETREE(main, ntree, id) {
161                         if (ntree->type == NTREE_COMPOSIT) {
162                                 bNode *node;
163                                 for (node = ntree->nodes.first; node; node = node->next) {
164                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
165                                                 node->id = NULL;
166                                         }
167                                 }
168                         }
169                 } FOREACH_NODETREE_END
170
171                 {
172                         bScreen *screen;
173
174                         for (screen = main->screen.first; screen; screen = screen->id.next) {
175                                 ScrArea *area;
176                                 for (area = screen->areabase.first; area; area = area->next) {
177                                         SpaceLink *space_link;
178                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
179                                                 if (space_link->spacetype == SPACE_CLIP) {
180                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
181                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
182                                                                 space_clip->mode = SC_MODE_TRACKING;
183                                                         }
184                                                 }
185                                         }
186                                 }
187                         }
188                 }
189
190                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
191                         MovieClip *clip;
192                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
193                                 clip->tracking.settings.default_weight = 1.0f;
194                         }
195                 }
196         }
197
198         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
199                 Scene *sce;
200                 Object *ob;
201
202                 /* Update Transform constraint (another deg -> rad stuff). */
203                 for (ob = main->object.first; ob; ob = ob->id.next) {
204                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
205
206                         if (ob->pose) {
207                                 /* Bones constraints! */
208                                 bPoseChannel *pchan;
209                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
210                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
211                                 }
212                         }
213                 }
214
215                 for (sce = main->scene.first; sce; sce = sce->id.next) {
216                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
217                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
218                         }
219                 }
220         }
221
222         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
223                 Mesh *me;
224
225                 /* Mesh smoothresh deg->rad. */
226                 for (me = main->mesh.first; me; me = me->id.next) {
227                         me->smoothresh = DEG2RADF(me->smoothresh);
228                 }
229         }
230
231         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
232                 FreestyleLineStyle *linestyle;
233
234                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
235                         linestyle->flag |= LS_NO_SORTING;
236                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
237                         linestyle->integration_type = LS_INTEGRATION_MEAN;
238                 }
239         }
240
241         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
242                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
243                  * This will always reset situation to a valid state.
244                  */
245                 bScreen *sc;
246
247                 for (sc = main->screen.first; sc; sc = sc->id.next) {
248                         ScrArea *sa;
249                         for (sa = sc->areabase.first; sa; sa = sa->next) {
250                                 SpaceLink *sl;
251
252                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
253                                         ARegion *ar;
254                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
255
256                                         for (ar = lb->first; ar; ar = ar->next) {
257                                                 BLI_listbase_clear(&ar->ui_previews);
258                                         }
259                                 }
260                         }
261                 }
262         }
263
264         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
265                 Object *ob;
266
267                 /* Update Transform constraint (again :|). */
268                 for (ob = main->object.first; ob; ob = ob->id.next) {
269                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
270
271                         if (ob->pose) {
272                                 /* Bones constraints! */
273                                 bPoseChannel *pchan;
274                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
275                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
276                                 }
277                         }
278                 }
279         }
280
281         if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
282                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
283                         Material *ma;
284
285                         for (ma = main->mat.first; ma; ma = ma->id.next)
286                                 ma->mode2 = MA_CASTSHADOW;
287                 }
288
289                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
290                         Scene *sce;
291
292                         for (sce = main->scene.first; sce; sce = sce->id.next) {
293                                 sce->r.bake.flag = R_BAKE_CLEAR;
294                                 sce->r.bake.width = 512;
295                                 sce->r.bake.height = 512;
296                                 sce->r.bake.margin = 16;
297                                 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
298                                 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
299                                 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
300                                 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
301                                 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
302
303                                 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
304                                 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
305                                 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
306                                 sce->r.bake.im_format.quality = 90;
307                                 sce->r.bake.im_format.compress = 15;
308                         }
309                 }
310
311                 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
312                         FreestyleLineStyle *linestyle;
313
314                         for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
315                                 linestyle->flag |= LS_TEXTURE;
316                                 linestyle->texstep = 1.0;
317                         }
318                 }
319
320                 {
321                         Scene *scene;
322                         for (scene = main->scene.first; scene; scene = scene->id.next) {
323                                 int num_layers = BLI_listbase_count(&scene->r.layers);
324                                 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
325                         }
326                 }
327         }
328
329         if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
330                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
331                         Material *mat;
332
333                         for (mat = main->mat.first; mat; mat = mat->id.next) {
334                                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
335                                 mat->line_col[3] = mat->alpha;
336                         }
337                 }
338
339                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
340                         Scene *scene;
341                         for (scene = main->scene.first; scene; scene = scene->id.next) {
342                                 scene->r.preview_start_resolution = 64;
343                         }
344                 }
345         }
346
347         if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
348                 /* init up & track axis property of trackto actuators */
349                 Object *ob;
350
351                 for (ob = main->object.first; ob; ob = ob->id.next) {
352                         bActuator *act;
353                         for (act = ob->actuators.first; act; act = act->next) {
354                                 if (act->type == ACT_EDIT_OBJECT) {
355                                         bEditObjectActuator *eoact = act->data;
356                                         eoact->trackflag = ob->trackflag;
357                                         /* if trackflag is pointing +-Z axis then upflag should point Y axis.
358                                          * Rest of trackflag cases, upflag should be point z axis */
359                                         if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
360                                                 eoact->upflag = 1;
361                                         }
362                                         else {
363                                                 eoact->upflag = 2;
364                                         }
365                                 }
366                         }
367                 }
368         }
369
370         if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
371                 Brush *br;
372
373                 for (br = main->brush.first; br; br = br->id.next) {
374                         br->fill_threshold = 0.2f;
375                 }
376
377                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
378                         Object *ob;
379                         for (ob = main->object.first; ob; ob = ob->id.next) {
380                                 ModifierData *md;
381
382                                 for (md = ob->modifiers.first; md; md = md->next) {
383                                         if (md->type == eModifierType_Bevel) {
384                                                 BevelModifierData *bmd = (BevelModifierData *)md;
385                                                 bmd->mat = -1;
386                                         }
387                                 }
388                         }
389                 }
390         }
391
392         if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
393                 Object *ob;
394                 for (ob = main->object.first; ob; ob = ob->id.next) {
395                         ModifierData *md;
396
397                         for (md = ob->modifiers.first; md; md = md->next) {
398                                 if (md->type == eModifierType_ParticleSystem) {
399                                         ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
400                                         if (pmd->psys && pmd->psys->clmd) {
401                                                 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
402                                         }
403                                 }
404                         }
405                 }
406         }
407
408         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
409                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
410                         Scene *scene;
411                         for (scene = main->scene.first; scene; scene = scene->id.next) {
412                                 scene->r.preview_start_resolution = 64;
413                         }
414                 }
415         }
416
417         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
418                 Brush *br;
419                 for (br = main->brush.first; br; br = br->id.next) {
420                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
421                                 br->alpha = 1.0f;
422                 }
423         }
424
425         if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
426                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
427                         Image *image;
428                         for (image = main->image.first; image != NULL; image = image->id.next) {
429                                 image->gen_color[3] = 1.0f;
430                         }
431                 }
432
433                 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
434                         Object *ob;
435
436                         /* Update Transform constraint (again :|). */
437                         for (ob = main->object.first; ob; ob = ob->id.next) {
438                                 do_version_constraints_stretch_to_limits(&ob->constraints);
439
440                                 if (ob->pose) {
441                                         /* Bones constraints! */
442                                         bPoseChannel *pchan;
443                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
444                                                 do_version_constraints_stretch_to_limits(&pchan->constraints);
445                                         }
446                                 }
447                         }
448                 }
449         }
450
451         if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
452 #define BRUSH_RAKE (1 << 7)
453 #define BRUSH_RANDOM_ROTATION (1 << 25)
454
455                 Brush *br;
456
457                 for (br = main->brush.first; br; br = br->id.next) {
458                         if (br->flag & BRUSH_RAKE) {
459                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
460                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
461                         }
462                         else if (br->flag & BRUSH_RANDOM_ROTATION) {
463                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
464                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
465                         }
466                         br->mtex.random_angle = 2.0 * M_PI;
467                         br->mask_mtex.random_angle = 2.0 * M_PI;
468                 }
469         }
470
471 #undef BRUSH_RAKE
472 #undef BRUSH_RANDOM_ROTATION
473
474         /* Customizable Safe Areas */
475         if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
476                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
477                         Scene *scene;
478
479                         for (scene = main->scene.first; scene; scene = scene->id.next) {
480                                 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
481                                 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
482                                 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
483                                 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
484                         }
485                 }
486         }
487         
488         if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
489                 ParticleSettings *part;
490                 for (part = main->particle.first; part; part = part->id.next) {
491                         if (part->clumpcurve)
492                                 part->child_flag |= PART_CHILD_USE_CLUMP_CURVE;
493                         if (part->roughcurve)
494                                 part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
495                 }
496         }
497
498         if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
499                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
500                         Object *ob;
501                         ModifierData *md;
502                         for (ob = main->object.first; ob; ob = ob->id.next) {
503                                 for (md = ob->modifiers.first; md; md = md->next) {
504                                         if (md->type == eModifierType_Cloth) {
505                                                 ClothModifierData *clmd = (ClothModifierData *)md;
506                                                 clmd->sim_parms->bending_damping = 0.5f;
507                                         }
508                                         else if (md->type == eModifierType_ParticleSystem) {
509                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
510                                                 if (pmd->psys->clmd) {
511                                                         pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
512                                                 }
513                                         }
514                                 }
515                         }
516                 }
517
518                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "float", "clump_noise_size")) {
519                         ParticleSettings *part;
520                         for (part = main->particle.first; part; part = part->id.next) {
521                                 part->clump_noise_size = 1.0f;
522                         }
523                 }
524
525                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "int", "kink_extra_steps")) {
526                         ParticleSettings *part;
527                         for (part = main->particle.first; part; part = part->id.next) {
528                                 part->kink_extra_steps = 4;
529                         }
530                 }
531
532                 if (!DNA_struct_elem_find(fd->filesdna, "MTex", "float", "kinkampfac")) {
533                         ParticleSettings *part;
534                         for (part = main->particle.first; part; part = part->id.next) {
535                                 int a;
536                                 for (a = 0; a < MAX_MTEX; a++) {
537                                         MTex *mtex = part->mtex[a];
538                                         if (mtex) {
539                                                 mtex->kinkampfac = 1.0f;
540                                         }
541                                 }
542                         }
543                 }
544
545                 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
546                         Object *ob;
547
548                         for (ob = main->object.first; ob; ob = ob->id.next) {
549                                 ModifierData *md;
550                                 for (md = ob->modifiers.first; md; md = md->next) {
551                                         if (md->type == eModifierType_Hook) {
552                                                 HookModifierData *hmd = (HookModifierData *)md;
553                                                 hmd->falloff_type = eHook_Falloff_InvSquare;
554                                         }
555                                 }
556                         }
557                 }
558
559                 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
560                         FOREACH_NODETREE(main, ntree, id) {
561                                 if (ntree->type == NTREE_COMPOSIT) {
562                                         bNode *node;
563                                         for (node = ntree->nodes.first; node; node = node->next) {
564                                                 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
565                                                         NodePlaneTrackDeformData *data = node->storage;
566                                                         data->flag = 0;
567                                                         data->motion_blur_samples = 16;
568                                                         data->motion_blur_shutter = 0.5f;
569                                                 }
570                                         }
571                                 }
572                         }
573                         FOREACH_NODETREE_END
574                 }
575
576                 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
577                         Camera *ca;
578                         for (ca = main->camera.first; ca; ca = ca->id.next) {
579                                 ca->gpu_dof.fstop = 128.0f;
580                                 ca->gpu_dof.focal_length = 1.0f;
581                                 ca->gpu_dof.focus_distance = 1.0f;
582                                 ca->gpu_dof.sensor = 1.0f;
583                         }
584                 }
585         }
586
587         if (!MAIN_VERSION_ATLEAST(main, 273, 7)) {
588                 bScreen *scr;
589                 ScrArea *sa;
590                 SpaceLink *sl;
591                 ARegion *ar;
592
593                 for (scr = main->screen.first; scr; scr = scr->id.next) {
594                         /* Remove old deprecated region from filebrowsers */
595                         for (sa = scr->areabase.first; sa; sa = sa->next) {
596                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
597                                         if (sl->spacetype == SPACE_FILE) {
598                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
599                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
600                                                                 break;
601                                                         }
602                                                 }
603
604                                                 if (ar) {
605                                                         /* Free old deprecated 'channel' region... */
606                                                         BKE_area_region_free(NULL, ar);
607                                                         BLI_freelinkN(&sl->regionbase, ar);
608                                                 }
609                                         }
610                                 }
611                         }
612                 }
613         }
614
615         if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
616                 Object *ob;
617                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
618                         ModifierData *md;
619                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
620                                 if (modifier_unique_name(&ob->modifiers, md)) {
621                                         printf("Warning: Object '%s' had several modifiers with the "
622                                                "same name, renamed one of them to '%s'.\n",
623                                                ob->id.name + 2, md->name);
624                                 }
625                         }
626                 }
627         }
628
629         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
630                 bScreen *scr;
631                 ScrArea *sa;
632                 SpaceLink *sl;
633                 ARegion *ar;
634
635                 /* Make sure sequencer preview area limits zoom */
636                 for (scr = main->screen.first; scr; scr = scr->id.next) {
637                         for (sa = scr->areabase.first; sa; sa = sa->next) {
638                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
639                                         if (sl->spacetype == SPACE_SEQ) {
640                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
641                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
642                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
643                                                                 ar->v2d.minzoom = 0.001f;
644                                                                 ar->v2d.maxzoom = 1000.0f;
645                                                                 break;
646                                                         }
647                                                 }
648                                         }
649                                 }
650                         }
651                 }
652         }
653
654         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
655                 /* particle systems need to be forced to redistribute for jitter mode fix */
656                 {
657                         Object *ob;
658                         ParticleSystem *psys;
659                         for (ob = main->object.first; ob; ob = ob->id.next) {
660                                 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
661                                         if ((psys->pointcache->flag & PTCACHE_BAKED) == 0) {
662                                                 psys->recalc |= PSYS_RECALC_RESET;
663                                         }
664                                 }
665                         }
666                 }
667
668                 /* hysteresis setted to 10% but not actived */
669                 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
670                         Object *ob;
671                         for (ob = main->object.first; ob; ob = ob->id.next) {
672                                 LodLevel *level;
673                                 for (level = ob->lodlevels.first; level; level = level->next) {
674                                         level->obhysteresis = 10;
675                                 }
676                         }
677                 }
678
679                 if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
680                         Scene *scene;
681                         for (scene = main->scene.first; scene; scene = scene->id.next) {
682                                 scene->gm.scehysteresis = 10;
683                         }
684                 }
685         }
686
687         if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
688                 FOREACH_NODETREE(main, ntree, id) {
689                         bNode *node;
690                         bNodeSocket *sock;
691
692                         for (node = ntree->nodes.first; node; node = node->next) {
693                                 if (node->type == SH_NODE_MATERIAL) {
694                                         for (sock = node->inputs.first; sock; sock = sock->next) {
695                                                 if (STREQ(sock->name, "Refl")) {
696                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
697                                                 }
698                                         }
699                                 }
700                                 else if (node->type == SH_NODE_MATERIAL_EXT) {
701                                         for (sock = node->outputs.first; sock; sock = sock->next) {
702                                                 if (STREQ(sock->name, "Refl")) {
703                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
704                                                 }
705                                                 else if (STREQ(sock->name, "Ray Mirror")) {
706                                                         BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
707                                                 }
708                                         }
709                                 }
710                         }
711                 } FOREACH_NODETREE_END
712         }
713
714         if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
715                 SceneRenderView *srv;
716                 wmWindowManager *wm;
717                 bScreen *screen;
718                 wmWindow *win;
719                 Scene *scene;
720                 Camera *cam;
721                 Image *ima;
722
723                 for (scene = main->scene.first; scene; scene = scene->id.next) {
724                         Sequence *seq;
725
726                         BKE_scene_add_render_view(scene, STEREO_LEFT_NAME);
727                         srv = scene->r.views.first;
728                         BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
729
730                         BKE_scene_add_render_view(scene, STEREO_RIGHT_NAME);
731                         srv = scene->r.views.last;
732                         BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
733
734                         SEQ_BEGIN (scene->ed, seq)
735                         {
736                                 seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
737
738 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
739 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
740                                 if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) {
741                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
742                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
743                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
744                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
745                                 }
746 #undef SEQ_USE_PROXY_CUSTOM_DIR
747 #undef SEQ_USE_PROXY_CUSTOM_FILE
748
749                         }
750                         SEQ_END
751                 }
752
753                 for (screen = main->screen.first; screen; screen = screen->id.next) {
754                         ScrArea *sa;
755                         for (sa = screen->areabase.first; sa; sa = sa->next) {
756                                 SpaceLink *sl;
757
758                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
759                                         switch (sl->spacetype) {
760                                                 case SPACE_VIEW3D:
761                                                 {
762                                                         View3D *v3d = (View3D *)sl;
763                                                         v3d->stereo3d_camera = STEREO_3D_ID;
764                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
765                                                         v3d->stereo3d_convergence_alpha = 0.15f;
766                                                         v3d->stereo3d_volume_alpha = 0.05f;
767                                                         break;
768                                                 }
769                                                 case SPACE_IMAGE:
770                                                 {
771                                                         SpaceImage *sima = (SpaceImage *) sl;
772                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
773                                                         break;
774                                                 }
775                                         }
776                                 }
777                         }
778                 }
779
780                 for (cam = main->camera.first; cam; cam = cam->id.next) {
781                         cam->stereo.interocular_distance = 0.065f;
782                         cam->stereo.convergence_distance = 30.0f * 0.065f;
783                 }
784
785                 for (ima = main->image.first; ima; ima = ima->id.next) {
786                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
787
788                         if (ima->packedfile) {
789                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
790                                 BLI_addtail(&ima->packedfiles, imapf);
791
792                                 imapf->packedfile = ima->packedfile;
793                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
794                                 ima->packedfile = NULL;
795                         }
796                 }
797
798                 for (wm = main->wm.first; wm; wm = wm->id.next) {
799                         for (win = wm->windows.first; win; win = win->next) {
800                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
801                         }
802                 }
803         }
804
805         if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
806                 bScreen *screen;
807
808                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
809                         for (screen = main->screen.first; screen; screen = screen->id.next) {
810                                 ScrArea *sa;
811
812                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
813                                         SpaceLink *sl;
814
815                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
816                                                 if (sl->spacetype == SPACE_FILE) {
817                                                         SpaceFile *sfile = (SpaceFile *)sl;
818
819                                                         if (sfile->params) {
820                                                                 sfile->params->thumbnail_size = 128;
821                                                         }
822                                                 }
823                                         }
824                                 }
825                         }
826                 }
827
828                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
829                         Scene *scene;
830                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
831                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
832                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
833                         }
834                 }
835
836                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
837                         Object *ob;
838
839                         for (ob = main->object.first; ob; ob = ob->id.next) {
840                                 ModifierData *md;
841                                 for (md = ob->modifiers.first; md; md = md->next) {
842                                         if (md->type == eModifierType_Decimate) {
843                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
844                                                 dmd->defgrp_factor = 1.0f;
845                                         }
846                                 }
847                         }
848                 }
849         }
850
851         if (!MAIN_VERSION_ATLEAST(main, 275, 3)) {
852                 Brush *br;
853 #define BRUSH_TORUS (1 << 1)
854                 for (br = main->brush.first; br; br = br->id.next) {
855                         br->flag &= ~BRUSH_TORUS;
856                 }
857 #undef BRUSH_TORUS
858         }
859
860         if (!MAIN_VERSION_ATLEAST(main, 276, 2)) {
861                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
862                         Object *ob;
863
864                         for (ob = main->object.first; ob; ob = ob->id.next) {
865                                 if (ob->pose) {
866                                         bPoseChannel *pchan;
867                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
868                                                 pchan->custom_scale = 1.0f;
869                                         }
870                                 }
871                         }
872                 }
873
874                 {
875                         bScreen *screen;
876 #define RV3D_VIEW_PERSPORTHO     7
877                         for (screen = main->screen.first; screen; screen = screen->id.next) {
878                                 ScrArea *sa;
879                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
880                                         SpaceLink *sl;
881                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
882                                                 if (sl->spacetype == SPACE_VIEW3D) {
883                                                         ARegion *ar;
884                                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
885                                                         for (ar = lb->first; ar; ar = ar->next) {
886                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
887                                                                         if (ar->regiondata) {
888                                                                                 RegionView3D *rv3d = ar->regiondata;
889                                                                                 if (rv3d->view == RV3D_VIEW_PERSPORTHO) {
890                                                                                         rv3d->view = RV3D_VIEW_USER;
891                                                                                 }
892                                                                         }
893                                                                 }
894                                                         }
895                                                         break;
896                                                 }
897                                         }
898                                 }
899                         }
900 #undef RV3D_VIEW_PERSPORTHO
901                 }
902
903                 {
904                         Lamp *lamp;
905 #define LA_YF_PHOTON    5
906                         for (lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
907                                 if (lamp->type == LA_YF_PHOTON) {
908                                         lamp->type = LA_LOCAL;
909                                 }
910                         }
911 #undef LA_YF_PHOTON
912                 }
913
914                 {
915                         Object *ob;
916                         for (ob = main->object.first; ob; ob = ob->id.next) {
917                                 if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
918                                         ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
919                                 }
920                         }
921                 }
922
923         }
924
925         if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
926                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
927                         Scene *scene;
928                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
929                                 CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
930                                 curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
931                                 curvemapping_initialize(curve_mapping);
932                                 curvemap_reset(curve_mapping->cm,
933                                                &curve_mapping->clipr,
934                                                CURVE_PRESET_MAX,
935                                                CURVEMAP_SLOPE_POS_NEG);
936                         }
937                 }
938         }
939
940         if (!MAIN_VERSION_ATLEAST(main, 276, 4)) {
941                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
942                         ToolSettings *ts = scene->toolsettings;
943                         
944                         if (ts->gp_sculpt.brush[0].size == 0) {
945                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
946                                 GP_EditBrush_Data *brush;
947                                 
948                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
949                                 brush->size = 25;
950                                 brush->strength = 0.3f;
951                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
952                                 
953                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
954                                 brush->size = 25;
955                                 brush->strength = 0.5f;
956                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
957                                 
958                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
959                                 brush->size = 50;
960                                 brush->strength = 0.3f;
961                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
962                                 
963                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
964                                 brush->size = 25;
965                                 brush->strength = 0.3f;
966                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
967                                 
968                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
969                                 brush->size = 50;
970                                 brush->strength = 0.3f; // XXX?
971                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
972                                 
973                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
974                                 brush->size = 50;
975                                 brush->strength = 0.5f; // XXX?
976                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
977                                 
978                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
979                                 brush->size = 25;
980                                 brush->strength = 0.5f;
981                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
982                                 
983                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_CLONE];
984                                 brush->size = 50;
985                                 brush->strength = 1.0f;
986                         }
987                         
988                         if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
989 #if 0 /* XXX: Cannot do this, as we get random crashes... */
990                                 if (scene->gpd) {
991                                         bGPdata *gpd = scene->gpd;
992                                         
993                                         /* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
994                                         ts->gpencil_v3d_align = 0;
995                                         
996                                         if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
997                                         if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
998                                         if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
999                                         
1000                                         if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
1001                                                 ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
1002                                 }
1003                                 else {
1004                                         /* Default to cursor for all standard 3D views */
1005                                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1006                                 }
1007 #endif
1008                                 
1009                                 ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1010                                 ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
1011                                 ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
1012                                 ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
1013                         }
1014                 }
1015                 
1016                 for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1017                         bool enabled = false;
1018                         
1019                         /* Ensure that the datablock's onionskinning toggle flag
1020                          * stays in sync with the status of the actual layers
1021                          */
1022                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1023                                 if (gpl->flag & GP_LAYER_ONIONSKIN) {
1024                                         enabled = true;
1025                                 }
1026                         }
1027                         
1028                         if (enabled)
1029                                 gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
1030                         else
1031                                 gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
1032                 }
1033
1034                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) {
1035                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1036                                 ob->max_jumps = 1;
1037                         }
1038                 }
1039         }
1040         if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
1041                 ListBase *lbarray[MAX_LIBARRAY];
1042                 int a;
1043
1044                 /* Important to clear all non-persistent flags from older versions here, otherwise they could collide
1045                  * with any new persistent flag we may add in the future. */
1046                 a = set_listbasepointers(main, lbarray);
1047                 while (a--) {
1048                         for (ID *id = lbarray[a]->first; id; id = id->next) {
1049                                 id->flag &= LIB_FAKEUSER;
1050                         }
1051                 }
1052         }
1053
1054         if (!MAIN_VERSION_ATLEAST(main, 276, 7)) {
1055                 Scene *scene;
1056                 for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1057                         scene->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
1058                 }
1059         }
1060 }