Sequencer text strip color options
[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, 8)) {
588                 Object *ob;
589                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
590                         ModifierData *md;
591                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
592                                 if (modifier_unique_name(&ob->modifiers, md)) {
593                                         printf("Warning: Object '%s' had several modifiers with the "
594                                                "same name, renamed one of them to '%s'.\n",
595                                                ob->id.name + 2, md->name);
596                                 }
597                         }
598                 }
599         }
600
601         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
602                 bScreen *scr;
603                 ScrArea *sa;
604                 SpaceLink *sl;
605                 ARegion *ar;
606
607                 /* Make sure sequencer preview area limits zoom */
608                 for (scr = main->screen.first; scr; scr = scr->id.next) {
609                         for (sa = scr->areabase.first; sa; sa = sa->next) {
610                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
611                                         if (sl->spacetype == SPACE_SEQ) {
612                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
613                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
614                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
615                                                                 ar->v2d.minzoom = 0.001f;
616                                                                 ar->v2d.maxzoom = 1000.0f;
617                                                                 break;
618                                                         }
619                                                 }
620                                         }
621                                 }
622                         }
623                 }
624         }
625
626         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
627                 /* particle systems need to be forced to redistribute for jitter mode fix */
628                 {
629                         Object *ob;
630                         ParticleSystem *psys;
631                         for (ob = main->object.first; ob; ob = ob->id.next) {
632                                 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
633                                         if ((psys->pointcache->flag & PTCACHE_BAKED) == 0) {
634                                                 psys->recalc |= PSYS_RECALC_RESET;
635                                         }
636                                 }
637                         }
638                 }
639
640                 /* hysteresis setted to 10% but not actived */
641                 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
642                         Object *ob;
643                         for (ob = main->object.first; ob; ob = ob->id.next) {
644                                 LodLevel *level;
645                                 for (level = ob->lodlevels.first; level; level = level->next) {
646                                         level->obhysteresis = 10;
647                                 }
648                         }
649                 }
650
651                 if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
652                         Scene *scene;
653                         for (scene = main->scene.first; scene; scene = scene->id.next) {
654                                 scene->gm.scehysteresis = 10;
655                         }
656                 }
657         }
658
659         if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
660                 FOREACH_NODETREE(main, ntree, id) {
661                         bNode *node;
662                         bNodeSocket *sock;
663
664                         for (node = ntree->nodes.first; node; node = node->next) {
665                                 if (node->type == SH_NODE_MATERIAL) {
666                                         for (sock = node->inputs.first; sock; sock = sock->next) {
667                                                 if (STREQ(sock->name, "Refl")) {
668                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
669                                                 }
670                                         }
671                                 }
672                                 else if (node->type == SH_NODE_MATERIAL_EXT) {
673                                         for (sock = node->outputs.first; sock; sock = sock->next) {
674                                                 if (STREQ(sock->name, "Refl")) {
675                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
676                                                 }
677                                                 else if (STREQ(sock->name, "Ray Mirror")) {
678                                                         BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
679                                                 }
680                                         }
681                                 }
682                         }
683                 } FOREACH_NODETREE_END
684         }
685
686         if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
687                 SceneRenderView *srv;
688                 wmWindowManager *wm;
689                 bScreen *screen;
690                 wmWindow *win;
691                 Scene *scene;
692                 Camera *cam;
693                 Image *ima;
694
695                 for (scene = main->scene.first; scene; scene = scene->id.next) {
696                         Sequence *seq;
697
698                         BKE_scene_add_render_view(scene, STEREO_LEFT_NAME);
699                         srv = scene->r.views.first;
700                         BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
701
702                         BKE_scene_add_render_view(scene, STEREO_RIGHT_NAME);
703                         srv = scene->r.views.last;
704                         BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
705
706                         SEQ_BEGIN (scene->ed, seq)
707                         {
708                                 seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
709
710 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
711 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
712                                 if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) {
713                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
714                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
715                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
716                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
717                                 }
718 #undef SEQ_USE_PROXY_CUSTOM_DIR
719 #undef SEQ_USE_PROXY_CUSTOM_FILE
720
721                         }
722                         SEQ_END
723                 }
724
725                 for (screen = main->screen.first; screen; screen = screen->id.next) {
726                         ScrArea *sa;
727                         for (sa = screen->areabase.first; sa; sa = sa->next) {
728                                 SpaceLink *sl;
729
730                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
731                                         switch (sl->spacetype) {
732                                                 case SPACE_VIEW3D:
733                                                 {
734                                                         View3D *v3d = (View3D *)sl;
735                                                         v3d->stereo3d_camera = STEREO_3D_ID;
736                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
737                                                         v3d->stereo3d_convergence_alpha = 0.15f;
738                                                         v3d->stereo3d_volume_alpha = 0.05f;
739                                                         break;
740                                                 }
741                                                 case SPACE_IMAGE:
742                                                 {
743                                                         SpaceImage *sima = (SpaceImage *) sl;
744                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
745                                                         break;
746                                                 }
747                                         }
748                                 }
749                         }
750                 }
751
752                 for (cam = main->camera.first; cam; cam = cam->id.next) {
753                         cam->stereo.interocular_distance = 0.065f;
754                         cam->stereo.convergence_distance = 30.0f * 0.065f;
755                 }
756
757                 for (ima = main->image.first; ima; ima = ima->id.next) {
758                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
759
760                         if (ima->packedfile) {
761                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
762                                 BLI_addtail(&ima->packedfiles, imapf);
763
764                                 imapf->packedfile = ima->packedfile;
765                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
766                                 ima->packedfile = NULL;
767                         }
768                 }
769
770                 for (wm = main->wm.first; wm; wm = wm->id.next) {
771                         for (win = wm->windows.first; win; win = win->next) {
772                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
773                         }
774                 }
775         }
776
777         if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
778                 bScreen *screen;
779
780                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
781                         for (screen = main->screen.first; screen; screen = screen->id.next) {
782                                 ScrArea *sa;
783
784                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
785                                         SpaceLink *sl;
786
787                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
788                                                 if (sl->spacetype == SPACE_FILE) {
789                                                         SpaceFile *sfile = (SpaceFile *)sl;
790
791                                                         if (sfile->params) {
792                                                                 sfile->params->thumbnail_size = 128;
793                                                         }
794                                                 }
795                                         }
796                                 }
797                         }
798                 }
799
800                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
801                         Scene *scene;
802                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
803                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
804                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
805                         }
806                 }
807
808                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
809                         Object *ob;
810
811                         for (ob = main->object.first; ob; ob = ob->id.next) {
812                                 ModifierData *md;
813                                 for (md = ob->modifiers.first; md; md = md->next) {
814                                         if (md->type == eModifierType_Decimate) {
815                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
816                                                 dmd->defgrp_factor = 1.0f;
817                                         }
818                                 }
819                         }
820                 }
821         }
822
823         if (!MAIN_VERSION_ATLEAST(main, 275, 3)) {
824                 Brush *br;
825 #define BRUSH_TORUS (1 << 1)
826                 for (br = main->brush.first; br; br = br->id.next) {
827                         br->flag &= ~BRUSH_TORUS;
828                 }
829 #undef BRUSH_TORUS
830         }
831
832         if (!MAIN_VERSION_ATLEAST(main, 276, 2)) {
833                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
834                         Object *ob;
835
836                         for (ob = main->object.first; ob; ob = ob->id.next) {
837                                 if (ob->pose) {
838                                         bPoseChannel *pchan;
839                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
840                                                 pchan->custom_scale = 1.0f;
841                                         }
842                                 }
843                         }
844                 }
845
846                 {
847                         bScreen *screen;
848 #define RV3D_VIEW_PERSPORTHO     7
849                         for (screen = main->screen.first; screen; screen = screen->id.next) {
850                                 ScrArea *sa;
851                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
852                                         SpaceLink *sl;
853                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
854                                                 if (sl->spacetype == SPACE_VIEW3D) {
855                                                         ARegion *ar;
856                                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
857                                                         for (ar = lb->first; ar; ar = ar->next) {
858                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
859                                                                         if (ar->regiondata) {
860                                                                                 RegionView3D *rv3d = ar->regiondata;
861                                                                                 if (rv3d->view == RV3D_VIEW_PERSPORTHO) {
862                                                                                         rv3d->view = RV3D_VIEW_USER;
863                                                                                 }
864                                                                         }
865                                                                 }
866                                                         }
867                                                         break;
868                                                 }
869                                         }
870                                 }
871                         }
872 #undef RV3D_VIEW_PERSPORTHO
873                 }
874
875                 {
876                         Lamp *lamp;
877 #define LA_YF_PHOTON    5
878                         for (lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
879                                 if (lamp->type == LA_YF_PHOTON) {
880                                         lamp->type = LA_LOCAL;
881                                 }
882                         }
883 #undef LA_YF_PHOTON
884                 }
885
886                 {
887                         Object *ob;
888                         for (ob = main->object.first; ob; ob = ob->id.next) {
889                                 if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
890                                         ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
891                                 }
892                         }
893                 }
894
895         }
896
897         if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
898                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
899                         Scene *scene;
900                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
901                                 CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
902                                 curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
903                                 curvemapping_initialize(curve_mapping);
904                                 curvemap_reset(curve_mapping->cm,
905                                                &curve_mapping->clipr,
906                                                CURVE_PRESET_MAX,
907                                                CURVEMAP_SLOPE_POS_NEG);
908                         }
909                 }
910         }
911
912         if (!MAIN_VERSION_ATLEAST(main, 276, 4)) {
913                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
914                         ToolSettings *ts = scene->toolsettings;
915                         
916                         if (ts->gp_sculpt.brush[0].size == 0) {
917                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
918                                 GP_EditBrush_Data *brush;
919                                 
920                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
921                                 brush->size = 25;
922                                 brush->strength = 0.3f;
923                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
924                                 
925                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
926                                 brush->size = 25;
927                                 brush->strength = 0.5f;
928                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
929                                 
930                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
931                                 brush->size = 50;
932                                 brush->strength = 0.3f;
933                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
934                                 
935                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
936                                 brush->size = 25;
937                                 brush->strength = 0.3f;
938                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
939                                 
940                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
941                                 brush->size = 50;
942                                 brush->strength = 0.3f; // XXX?
943                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
944                                 
945                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
946                                 brush->size = 50;
947                                 brush->strength = 0.5f; // XXX?
948                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
949                                 
950                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
951                                 brush->size = 25;
952                                 brush->strength = 0.5f;
953                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
954                                 
955                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_CLONE];
956                                 brush->size = 50;
957                                 brush->strength = 1.0f;
958                         }
959                         
960                         if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
961 #if 0 /* XXX: Cannot do this, as we get random crashes... */
962                                 if (scene->gpd) {
963                                         bGPdata *gpd = scene->gpd;
964                                         
965                                         /* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
966                                         ts->gpencil_v3d_align = 0;
967                                         
968                                         if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
969                                         if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
970                                         if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
971                                         
972                                         if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
973                                                 ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
974                                 }
975                                 else {
976                                         /* Default to cursor for all standard 3D views */
977                                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
978                                 }
979 #endif
980                                 
981                                 ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
982                                 ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
983                                 ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
984                                 ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
985                         }
986                 }
987                 
988                 for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
989                         bool enabled = false;
990                         
991                         /* Ensure that the datablock's onionskinning toggle flag
992                          * stays in sync with the status of the actual layers
993                          */
994                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
995                                 if (gpl->flag & GP_LAYER_ONIONSKIN) {
996                                         enabled = true;
997                                 }
998                         }
999                         
1000                         if (enabled)
1001                                 gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
1002                         else
1003                                 gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
1004                 }
1005
1006                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) {
1007                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1008                                 ob->max_jumps = 1;
1009                         }
1010                 }
1011         }
1012         if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
1013                 ListBase *lbarray[MAX_LIBARRAY];
1014                 int a;
1015
1016                 /* Important to clear all non-persistent flags from older versions here, otherwise they could collide
1017                  * with any new persistent flag we may add in the future. */
1018                 a = set_listbasepointers(main, lbarray);
1019                 while (a--) {
1020                         for (ID *id = lbarray[a]->first; id; id = id->next) {
1021                                 id->flag &= LIB_FAKEUSER;
1022                         }
1023                 }
1024         }
1025
1026         if (!MAIN_VERSION_ATLEAST(main, 276, 7)) {
1027                 Scene *scene;
1028                 for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1029                         scene->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
1030                 }
1031         }
1032
1033         if (!MAIN_VERSION_ATLEAST(main, 277, 1)) {
1034                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1035                         ParticleEditSettings *pset = &scene->toolsettings->particle;
1036                         for (int a = 0; a < PE_TOT_BRUSH; a++) {
1037                                 if (pset->brush[a].strength > 1.0f) {
1038                                         pset->brush[a].strength *= 0.01f;
1039                                 }
1040                         }
1041                 }
1042
1043                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1044                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1045                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1046                                         ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1047                                         /* Bug: Was possible to add preview region to sequencer view by using AZones. */
1048                                         if (sl->spacetype == SPACE_SEQ) {
1049                                                 SpaceSeq *sseq = (SpaceSeq *)sl;
1050                                                 if (sseq->view == SEQ_VIEW_SEQUENCE) {
1051                                                         for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1052                                                                 /* remove preview region for sequencer-only view! */
1053                                                                 if (ar->regiontype == RGN_TYPE_PREVIEW) {
1054                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1055                                                                         ar->alignment = RGN_ALIGN_NONE;
1056                                                                         break;
1057                                                                 }
1058                                                         }
1059                                                 }
1060                                         }
1061                                         /* Remove old deprecated region from filebrowsers */
1062                                         else if (sl->spacetype == SPACE_FILE) {
1063                                                 for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1064                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
1065                                                                 /* Free old deprecated 'channel' region... */
1066                                                                 BKE_area_region_free(NULL, ar);
1067                                                                 BLI_freelinkN(regionbase, ar);
1068                                                                 break;
1069                                                         }
1070                                                 }
1071                                         }
1072                                 }
1073                         }
1074                 }
1075
1076                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1077                         CurvePaintSettings *cps = &scene->toolsettings->curve_paint_settings;
1078                         if (cps->error_threshold == 0) {
1079                                 cps->curve_type = CU_BEZIER;
1080                                 cps->flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
1081                                 cps->error_threshold = 8;
1082                                 cps->radius_max = 1.0f;
1083                                 cps->corner_angle = DEG2RADF(70.0f);
1084                         }
1085                 }
1086
1087                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1088                         Sequence *seq;
1089
1090                         SEQ_BEGIN (scene->ed, seq)
1091                         {
1092                                 if (seq->type == SEQ_TYPE_TEXT) {
1093                                         TextVars *data = seq->effectdata;
1094                                         if (data->color[3] == 0.0f) {
1095                                                 copy_v4_fl(data->color, 1.0f);
1096                                                 data->shadow_color[3] = 1.0f;
1097                                         }
1098                                 }
1099                         }
1100                         SEQ_END
1101                 }
1102
1103         }
1104 }