2D stabilizer: Revert majority of UI change
[blender.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_armature_types.h"
38 #include "DNA_brush_types.h"
39 #include "DNA_camera_types.h"
40 #include "DNA_cloth_types.h"
41 #include "DNA_constraint_types.h"
42 #include "DNA_gpencil_types.h"
43 #include "DNA_sdna_types.h"
44 #include "DNA_sequence_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_object_force.h"
48 #include "DNA_object_types.h"
49 #include "DNA_mesh_types.h"
50 #include "DNA_modifier_types.h"
51 #include "DNA_particle_types.h"
52 #include "DNA_linestyle_types.h"
53 #include "DNA_actuator_types.h"
54 #include "DNA_view3d_types.h"
55
56 #include "DNA_genfile.h"
57
58 #include "BKE_colortools.h"
59 #include "BKE_library.h"
60 #include "BKE_main.h"
61 #include "BKE_modifier.h"
62 #include "BKE_node.h"
63 #include "BKE_scene.h"
64 #include "BKE_sequencer.h"
65 #include "BKE_screen.h"
66 #include "BKE_tracking.h"
67 #include "BKE_gpencil.h"
68
69 #include "BLI_math.h"
70 #include "BLI_listbase.h"
71 #include "BLI_string.h"
72
73 #include "BLO_readfile.h"
74
75 #include "readfile.h"
76
77 #include "MEM_guardedalloc.h"
78
79 /**
80  * Setup rotation stabilization from ancient single track spec.
81  * Former Version of 2D stabilization used a single tracking marker to determine the rotation
82  * to be compensated. Now several tracks can contribute to rotation detection and this feature
83  * is enabled by the MovieTrackingTrack#flag on a per track base.
84  */
85 static void migrate_single_rot_stabilization_track_settings(MovieTrackingStabilization *stab)
86 {
87         if (stab->rot_track) {
88                 if (!(stab->rot_track->flag & TRACK_USE_2D_STAB_ROT)) {
89                         stab->tot_rot_track++;
90                         stab->rot_track->flag |= TRACK_USE_2D_STAB_ROT;
91                 }
92         }
93         stab->rot_track = NULL; /* this field is now ignored */
94
95         /* by default show the track lists expanded, to improve "discoverability" */
96         stab->flag |= TRACKING_SHOW_STAB_TRACKS;
97 }
98
99 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
100 {
101         bConstraint *con;
102
103         for (con = lb->first; con; con = con->next) {
104                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
105                         bTransformConstraint *data = (bTransformConstraint *)con->data;
106                         const float deg_to_rad_f = DEG2RADF(1.0f);
107
108                         if (data->from == TRANS_ROTATION) {
109                                 mul_v3_fl(data->from_min, deg_to_rad_f);
110                                 mul_v3_fl(data->from_max, deg_to_rad_f);
111                         }
112
113                         if (data->to == TRANS_ROTATION) {
114                                 mul_v3_fl(data->to_min, deg_to_rad_f);
115                                 mul_v3_fl(data->to_max, deg_to_rad_f);
116                         }
117                 }
118         }
119 }
120
121 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
122 {
123         bConstraint *con;
124
125         for (con = lb->first; con; con = con->next) {
126                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
127                         bTransformConstraint *data = (bTransformConstraint *)con->data;
128
129                         if (data->from == TRANS_ROTATION) {
130                                 copy_v3_v3(data->from_min_rot, data->from_min);
131                                 copy_v3_v3(data->from_max_rot, data->from_max);
132                         }
133                         else if (data->from == TRANS_SCALE) {
134                                 copy_v3_v3(data->from_min_scale, data->from_min);
135                                 copy_v3_v3(data->from_max_scale, data->from_max);
136                         }
137
138                         if (data->to == TRANS_ROTATION) {
139                                 copy_v3_v3(data->to_min_rot, data->to_min);
140                                 copy_v3_v3(data->to_max_rot, data->to_max);
141                         }
142                         else if (data->to == TRANS_SCALE) {
143                                 copy_v3_v3(data->to_min_scale, data->to_min);
144                                 copy_v3_v3(data->to_max_scale, data->to_max);
145                         }
146                 }
147         }
148 }
149
150 static void do_version_constraints_stretch_to_limits(ListBase *lb)
151 {
152         bConstraint *con;
153
154         for (con = lb->first; con; con = con->next) {
155                 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
156                         bStretchToConstraint *data = (bStretchToConstraint *)con->data;
157                         data->bulge_min = 1.0f;
158                         data->bulge_max = 1.0f;
159                 }
160         }
161 }
162
163 static void do_version_action_editor_properties_region(ListBase *regionbase)
164 {
165         ARegion *ar;
166         
167         for (ar = regionbase->first; ar; ar = ar->next) {
168                 if (ar->regiontype == RGN_TYPE_UI) {
169                         /* already exists */
170                         return;
171                 }
172                 else if (ar->regiontype == RGN_TYPE_WINDOW) {
173                         /* add new region here */
174                         ARegion *arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
175                         
176                         BLI_insertlinkbefore(regionbase, ar, arnew);
177                         
178                         arnew->regiontype = RGN_TYPE_UI;
179                         arnew->alignment = RGN_ALIGN_RIGHT;
180                         arnew->flag = RGN_FLAG_HIDDEN;
181                         
182                         return;
183                 }
184         }
185 }
186
187 static void do_version_bones_super_bbone(ListBase *lb)
188 {
189         for (Bone *bone = lb->first; bone; bone = bone->next) {
190                 bone->scaleIn = 1.0f;
191                 bone->scaleOut = 1.0f;
192                 
193                 do_version_bones_super_bbone(&bone->childbase);
194         }
195 }
196
197 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
198 {
199         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
200
201                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
202                         Object *ob;
203
204                         for (ob = main->object.first; ob; ob = ob->id.next) {
205                                 ModifierData *md;
206                                 for (md = ob->modifiers.first; md; md = md->next) {
207                                         if (md->type == eModifierType_Bevel) {
208                                                 BevelModifierData *bmd = (BevelModifierData *)md;
209                                                 bmd->profile = 0.5f;
210                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
211                                         }
212                                 }
213                         }
214                 }
215
216                 /* nodes don't use fixed node->id any more, clean up */
217                 FOREACH_NODETREE(main, ntree, id) {
218                         if (ntree->type == NTREE_COMPOSIT) {
219                                 bNode *node;
220                                 for (node = ntree->nodes.first; node; node = node->next) {
221                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
222                                                 node->id = NULL;
223                                         }
224                                 }
225                         }
226                 } FOREACH_NODETREE_END
227
228                 {
229                         bScreen *screen;
230
231                         for (screen = main->screen.first; screen; screen = screen->id.next) {
232                                 ScrArea *area;
233                                 for (area = screen->areabase.first; area; area = area->next) {
234                                         SpaceLink *space_link;
235                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
236                                                 if (space_link->spacetype == SPACE_CLIP) {
237                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
238                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
239                                                                 space_clip->mode = SC_MODE_TRACKING;
240                                                         }
241                                                 }
242                                         }
243                                 }
244                         }
245                 }
246
247                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
248                         MovieClip *clip;
249                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
250                                 clip->tracking.settings.default_weight = 1.0f;
251                         }
252                 }
253         }
254
255         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
256                 Scene *sce;
257                 Object *ob;
258
259                 /* Update Transform constraint (another deg -> rad stuff). */
260                 for (ob = main->object.first; ob; ob = ob->id.next) {
261                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
262
263                         if (ob->pose) {
264                                 /* Bones constraints! */
265                                 bPoseChannel *pchan;
266                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
267                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
268                                 }
269                         }
270                 }
271
272                 for (sce = main->scene.first; sce; sce = sce->id.next) {
273                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
274                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
275                         }
276                 }
277         }
278
279         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
280                 Mesh *me;
281
282                 /* Mesh smoothresh deg->rad. */
283                 for (me = main->mesh.first; me; me = me->id.next) {
284                         me->smoothresh = DEG2RADF(me->smoothresh);
285                 }
286         }
287
288         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
289                 FreestyleLineStyle *linestyle;
290
291                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
292                         linestyle->flag |= LS_NO_SORTING;
293                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
294                         linestyle->integration_type = LS_INTEGRATION_MEAN;
295                 }
296         }
297
298         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
299                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
300                  * This will always reset situation to a valid state.
301                  */
302                 bScreen *sc;
303
304                 for (sc = main->screen.first; sc; sc = sc->id.next) {
305                         ScrArea *sa;
306                         for (sa = sc->areabase.first; sa; sa = sa->next) {
307                                 SpaceLink *sl;
308
309                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
310                                         ARegion *ar;
311                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
312
313                                         for (ar = lb->first; ar; ar = ar->next) {
314                                                 BLI_listbase_clear(&ar->ui_previews);
315                                         }
316                                 }
317                         }
318                 }
319         }
320
321         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
322                 Object *ob;
323
324                 /* Update Transform constraint (again :|). */
325                 for (ob = main->object.first; ob; ob = ob->id.next) {
326                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
327
328                         if (ob->pose) {
329                                 /* Bones constraints! */
330                                 bPoseChannel *pchan;
331                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
332                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
333                                 }
334                         }
335                 }
336         }
337
338         if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
339                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
340                         Material *ma;
341
342                         for (ma = main->mat.first; ma; ma = ma->id.next)
343                                 ma->mode2 = MA_CASTSHADOW;
344                 }
345
346                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
347                         Scene *sce;
348
349                         for (sce = main->scene.first; sce; sce = sce->id.next) {
350                                 sce->r.bake.flag = R_BAKE_CLEAR;
351                                 sce->r.bake.width = 512;
352                                 sce->r.bake.height = 512;
353                                 sce->r.bake.margin = 16;
354                                 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
355                                 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
356                                 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
357                                 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
358                                 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
359
360                                 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
361                                 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
362                                 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
363                                 sce->r.bake.im_format.quality = 90;
364                                 sce->r.bake.im_format.compress = 15;
365                         }
366                 }
367
368                 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
369                         FreestyleLineStyle *linestyle;
370
371                         for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
372                                 linestyle->flag |= LS_TEXTURE;
373                                 linestyle->texstep = 1.0;
374                         }
375                 }
376
377                 {
378                         Scene *scene;
379                         for (scene = main->scene.first; scene; scene = scene->id.next) {
380                                 int num_layers = BLI_listbase_count(&scene->r.layers);
381                                 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
382                         }
383                 }
384         }
385
386         if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
387                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
388                         Material *mat;
389
390                         for (mat = main->mat.first; mat; mat = mat->id.next) {
391                                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
392                                 mat->line_col[3] = mat->alpha;
393                         }
394                 }
395
396                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
397                         Scene *scene;
398                         for (scene = main->scene.first; scene; scene = scene->id.next) {
399                                 scene->r.preview_start_resolution = 64;
400                         }
401                 }
402         }
403
404         if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
405                 /* init up & track axis property of trackto actuators */
406                 Object *ob;
407
408                 for (ob = main->object.first; ob; ob = ob->id.next) {
409                         bActuator *act;
410                         for (act = ob->actuators.first; act; act = act->next) {
411                                 if (act->type == ACT_EDIT_OBJECT) {
412                                         bEditObjectActuator *eoact = act->data;
413                                         eoact->trackflag = ob->trackflag;
414                                         /* if trackflag is pointing +-Z axis then upflag should point Y axis.
415                                          * Rest of trackflag cases, upflag should be point z axis */
416                                         if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
417                                                 eoact->upflag = 1;
418                                         }
419                                         else {
420                                                 eoact->upflag = 2;
421                                         }
422                                 }
423                         }
424                 }
425         }
426
427         if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
428                 Brush *br;
429
430                 for (br = main->brush.first; br; br = br->id.next) {
431                         br->fill_threshold = 0.2f;
432                 }
433
434                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
435                         Object *ob;
436                         for (ob = main->object.first; ob; ob = ob->id.next) {
437                                 ModifierData *md;
438
439                                 for (md = ob->modifiers.first; md; md = md->next) {
440                                         if (md->type == eModifierType_Bevel) {
441                                                 BevelModifierData *bmd = (BevelModifierData *)md;
442                                                 bmd->mat = -1;
443                                         }
444                                 }
445                         }
446                 }
447         }
448
449         if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
450                 Object *ob;
451                 for (ob = main->object.first; ob; ob = ob->id.next) {
452                         ModifierData *md;
453
454                         for (md = ob->modifiers.first; md; md = md->next) {
455                                 if (md->type == eModifierType_ParticleSystem) {
456                                         ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
457                                         if (pmd->psys && pmd->psys->clmd) {
458                                                 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
459                                         }
460                                 }
461                         }
462                 }
463         }
464
465         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
466                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
467                         Scene *scene;
468                         for (scene = main->scene.first; scene; scene = scene->id.next) {
469                                 scene->r.preview_start_resolution = 64;
470                         }
471                 }
472         }
473
474         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
475                 Brush *br;
476                 for (br = main->brush.first; br; br = br->id.next) {
477                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
478                                 br->alpha = 1.0f;
479                 }
480         }
481
482         if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
483                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
484                         Image *image;
485                         for (image = main->image.first; image != NULL; image = image->id.next) {
486                                 image->gen_color[3] = 1.0f;
487                         }
488                 }
489
490                 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
491                         Object *ob;
492
493                         /* Update Transform constraint (again :|). */
494                         for (ob = main->object.first; ob; ob = ob->id.next) {
495                                 do_version_constraints_stretch_to_limits(&ob->constraints);
496
497                                 if (ob->pose) {
498                                         /* Bones constraints! */
499                                         bPoseChannel *pchan;
500                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
501                                                 do_version_constraints_stretch_to_limits(&pchan->constraints);
502                                         }
503                                 }
504                         }
505                 }
506         }
507
508         if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
509 #define BRUSH_RAKE (1 << 7)
510 #define BRUSH_RANDOM_ROTATION (1 << 25)
511
512                 Brush *br;
513
514                 for (br = main->brush.first; br; br = br->id.next) {
515                         if (br->flag & BRUSH_RAKE) {
516                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
517                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
518                         }
519                         else if (br->flag & BRUSH_RANDOM_ROTATION) {
520                                 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
521                                 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
522                         }
523                         br->mtex.random_angle = 2.0 * M_PI;
524                         br->mask_mtex.random_angle = 2.0 * M_PI;
525                 }
526         }
527
528 #undef BRUSH_RAKE
529 #undef BRUSH_RANDOM_ROTATION
530
531         /* Customizable Safe Areas */
532         if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
533                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
534                         Scene *scene;
535
536                         for (scene = main->scene.first; scene; scene = scene->id.next) {
537                                 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
538                                 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
539                                 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
540                                 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
541                         }
542                 }
543         }
544         
545         if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
546                 ParticleSettings *part;
547                 for (part = main->particle.first; part; part = part->id.next) {
548                         if (part->clumpcurve)
549                                 part->child_flag |= PART_CHILD_USE_CLUMP_CURVE;
550                         if (part->roughcurve)
551                                 part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
552                 }
553         }
554
555         if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
556                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
557                         Object *ob;
558                         ModifierData *md;
559                         for (ob = main->object.first; ob; ob = ob->id.next) {
560                                 for (md = ob->modifiers.first; md; md = md->next) {
561                                         if (md->type == eModifierType_Cloth) {
562                                                 ClothModifierData *clmd = (ClothModifierData *)md;
563                                                 clmd->sim_parms->bending_damping = 0.5f;
564                                         }
565                                         else if (md->type == eModifierType_ParticleSystem) {
566                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
567                                                 if (pmd->psys->clmd) {
568                                                         pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
569                                                 }
570                                         }
571                                 }
572                         }
573                 }
574
575                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "float", "clump_noise_size")) {
576                         ParticleSettings *part;
577                         for (part = main->particle.first; part; part = part->id.next) {
578                                 part->clump_noise_size = 1.0f;
579                         }
580                 }
581
582                 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "int", "kink_extra_steps")) {
583                         ParticleSettings *part;
584                         for (part = main->particle.first; part; part = part->id.next) {
585                                 part->kink_extra_steps = 4;
586                         }
587                 }
588
589                 if (!DNA_struct_elem_find(fd->filesdna, "MTex", "float", "kinkampfac")) {
590                         ParticleSettings *part;
591                         for (part = main->particle.first; part; part = part->id.next) {
592                                 int a;
593                                 for (a = 0; a < MAX_MTEX; a++) {
594                                         MTex *mtex = part->mtex[a];
595                                         if (mtex) {
596                                                 mtex->kinkampfac = 1.0f;
597                                         }
598                                 }
599                         }
600                 }
601
602                 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
603                         Object *ob;
604
605                         for (ob = main->object.first; ob; ob = ob->id.next) {
606                                 ModifierData *md;
607                                 for (md = ob->modifiers.first; md; md = md->next) {
608                                         if (md->type == eModifierType_Hook) {
609                                                 HookModifierData *hmd = (HookModifierData *)md;
610                                                 hmd->falloff_type = eHook_Falloff_InvSquare;
611                                         }
612                                 }
613                         }
614                 }
615
616                 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
617                         FOREACH_NODETREE(main, ntree, id) {
618                                 if (ntree->type == NTREE_COMPOSIT) {
619                                         bNode *node;
620                                         for (node = ntree->nodes.first; node; node = node->next) {
621                                                 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
622                                                         NodePlaneTrackDeformData *data = node->storage;
623                                                         data->flag = 0;
624                                                         data->motion_blur_samples = 16;
625                                                         data->motion_blur_shutter = 0.5f;
626                                                 }
627                                         }
628                                 }
629                         }
630                         FOREACH_NODETREE_END
631                 }
632
633                 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
634                         Camera *ca;
635                         for (ca = main->camera.first; ca; ca = ca->id.next) {
636                                 ca->gpu_dof.fstop = 128.0f;
637                                 ca->gpu_dof.focal_length = 1.0f;
638                                 ca->gpu_dof.focus_distance = 1.0f;
639                                 ca->gpu_dof.sensor = 1.0f;
640                         }
641                 }
642         }
643
644         if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
645                 Object *ob;
646                 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
647                         ModifierData *md;
648                         for (md = ob->modifiers.last; md != NULL; md = md->prev) {
649                                 if (modifier_unique_name(&ob->modifiers, md)) {
650                                         printf("Warning: Object '%s' had several modifiers with the "
651                                                "same name, renamed one of them to '%s'.\n",
652                                                ob->id.name + 2, md->name);
653                                 }
654                         }
655                 }
656         }
657
658         if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
659                 bScreen *scr;
660                 ScrArea *sa;
661                 SpaceLink *sl;
662                 ARegion *ar;
663
664                 /* Make sure sequencer preview area limits zoom */
665                 for (scr = main->screen.first; scr; scr = scr->id.next) {
666                         for (sa = scr->areabase.first; sa; sa = sa->next) {
667                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
668                                         if (sl->spacetype == SPACE_SEQ) {
669                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
670                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
671                                                                 ar->v2d.keepzoom |= V2D_LIMITZOOM;
672                                                                 ar->v2d.minzoom = 0.001f;
673                                                                 ar->v2d.maxzoom = 1000.0f;
674                                                                 break;
675                                                         }
676                                                 }
677                                         }
678                                 }
679                         }
680                 }
681         }
682
683         if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
684                 /* particle systems need to be forced to redistribute for jitter mode fix */
685                 {
686                         Object *ob;
687                         ParticleSystem *psys;
688                         for (ob = main->object.first; ob; ob = ob->id.next) {
689                                 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
690                                         if ((psys->pointcache->flag & PTCACHE_BAKED) == 0) {
691                                                 psys->recalc |= PSYS_RECALC_RESET;
692                                         }
693                                 }
694                         }
695                 }
696
697                 /* hysteresis setted to 10% but not actived */
698                 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
699                         Object *ob;
700                         for (ob = main->object.first; ob; ob = ob->id.next) {
701                                 LodLevel *level;
702                                 for (level = ob->lodlevels.first; level; level = level->next) {
703                                         level->obhysteresis = 10;
704                                 }
705                         }
706                 }
707
708                 if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
709                         Scene *scene;
710                         for (scene = main->scene.first; scene; scene = scene->id.next) {
711                                 scene->gm.scehysteresis = 10;
712                         }
713                 }
714         }
715
716         if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
717                 FOREACH_NODETREE(main, ntree, id) {
718                         bNode *node;
719                         bNodeSocket *sock;
720
721                         for (node = ntree->nodes.first; node; node = node->next) {
722                                 if (node->type == SH_NODE_MATERIAL) {
723                                         for (sock = node->inputs.first; sock; sock = sock->next) {
724                                                 if (STREQ(sock->name, "Refl")) {
725                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
726                                                 }
727                                         }
728                                 }
729                                 else if (node->type == SH_NODE_MATERIAL_EXT) {
730                                         for (sock = node->outputs.first; sock; sock = sock->next) {
731                                                 if (STREQ(sock->name, "Refl")) {
732                                                         BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
733                                                 }
734                                                 else if (STREQ(sock->name, "Ray Mirror")) {
735                                                         BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
736                                                 }
737                                         }
738                                 }
739                         }
740                 } FOREACH_NODETREE_END
741         }
742
743         if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
744                 SceneRenderView *srv;
745                 wmWindowManager *wm;
746                 bScreen *screen;
747                 wmWindow *win;
748                 Scene *scene;
749                 Camera *cam;
750                 Image *ima;
751
752                 for (scene = main->scene.first; scene; scene = scene->id.next) {
753                         Sequence *seq;
754
755                         BKE_scene_add_render_view(scene, STEREO_LEFT_NAME);
756                         srv = scene->r.views.first;
757                         BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
758
759                         BKE_scene_add_render_view(scene, STEREO_RIGHT_NAME);
760                         srv = scene->r.views.last;
761                         BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
762
763                         SEQ_BEGIN (scene->ed, seq)
764                         {
765                                 seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
766
767 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
768 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
769                                 if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) {
770                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
771                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
772                                         if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
773                                                 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
774                                 }
775 #undef SEQ_USE_PROXY_CUSTOM_DIR
776 #undef SEQ_USE_PROXY_CUSTOM_FILE
777
778                         }
779                         SEQ_END
780                 }
781
782                 for (screen = main->screen.first; screen; screen = screen->id.next) {
783                         ScrArea *sa;
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                                         switch (sl->spacetype) {
789                                                 case SPACE_VIEW3D:
790                                                 {
791                                                         View3D *v3d = (View3D *)sl;
792                                                         v3d->stereo3d_camera = STEREO_3D_ID;
793                                                         v3d->stereo3d_flag |= V3D_S3D_DISPPLANE;
794                                                         v3d->stereo3d_convergence_alpha = 0.15f;
795                                                         v3d->stereo3d_volume_alpha = 0.05f;
796                                                         break;
797                                                 }
798                                                 case SPACE_IMAGE:
799                                                 {
800                                                         SpaceImage *sima = (SpaceImage *) sl;
801                                                         sima->iuser.flag |= IMA_SHOW_STEREO;
802                                                         break;
803                                                 }
804                                         }
805                                 }
806                         }
807                 }
808
809                 for (cam = main->camera.first; cam; cam = cam->id.next) {
810                         cam->stereo.interocular_distance = 0.065f;
811                         cam->stereo.convergence_distance = 30.0f * 0.065f;
812                 }
813
814                 for (ima = main->image.first; ima; ima = ima->id.next) {
815                         ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo 3d Format");
816
817                         if (ima->packedfile) {
818                                 ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed File");
819                                 BLI_addtail(&ima->packedfiles, imapf);
820
821                                 imapf->packedfile = ima->packedfile;
822                                 BLI_strncpy(imapf->filepath, ima->name, FILE_MAX);
823                                 ima->packedfile = NULL;
824                         }
825                 }
826
827                 for (wm = main->wm.first; wm; wm = wm->id.next) {
828                         for (win = wm->windows.first; win; win = win->next) {
829                                 win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format");
830                         }
831                 }
832         }
833
834         if (!MAIN_VERSION_ATLEAST(main, 274, 6)) {
835                 bScreen *screen;
836
837                 if (!DNA_struct_elem_find(fd->filesdna, "FileSelectParams", "int", "thumbnail_size")) {
838                         for (screen = main->screen.first; screen; screen = screen->id.next) {
839                                 ScrArea *sa;
840
841                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
842                                         SpaceLink *sl;
843
844                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
845                                                 if (sl->spacetype == SPACE_FILE) {
846                                                         SpaceFile *sfile = (SpaceFile *)sl;
847
848                                                         if (sfile->params) {
849                                                                 sfile->params->thumbnail_size = 128;
850                                                         }
851                                                 }
852                                         }
853                                 }
854                         }
855                 }
856
857                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "short", "simplify_subsurf_render")) {
858                         Scene *scene;
859                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
860                                 scene->r.simplify_subsurf_render = scene->r.simplify_subsurf;
861                                 scene->r.simplify_particles_render = scene->r.simplify_particles;
862                         }
863                 }
864
865                 if (!DNA_struct_elem_find(fd->filesdna, "DecimateModifierData", "float", "defgrp_factor")) {
866                         Object *ob;
867
868                         for (ob = main->object.first; ob; ob = ob->id.next) {
869                                 ModifierData *md;
870                                 for (md = ob->modifiers.first; md; md = md->next) {
871                                         if (md->type == eModifierType_Decimate) {
872                                                 DecimateModifierData *dmd = (DecimateModifierData *)md;
873                                                 dmd->defgrp_factor = 1.0f;
874                                         }
875                                 }
876                         }
877                 }
878         }
879
880         if (!MAIN_VERSION_ATLEAST(main, 275, 3)) {
881                 Brush *br;
882 #define BRUSH_TORUS (1 << 1)
883                 for (br = main->brush.first; br; br = br->id.next) {
884                         br->flag &= ~BRUSH_TORUS;
885                 }
886 #undef BRUSH_TORUS
887         }
888
889         if (!MAIN_VERSION_ATLEAST(main, 276, 2)) {
890                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
891                         Object *ob;
892
893                         for (ob = main->object.first; ob; ob = ob->id.next) {
894                                 if (ob->pose) {
895                                         bPoseChannel *pchan;
896                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
897                                                 pchan->custom_scale = 1.0f;
898                                         }
899                                 }
900                         }
901                 }
902
903                 {
904                         bScreen *screen;
905 #define RV3D_VIEW_PERSPORTHO     7
906                         for (screen = main->screen.first; screen; screen = screen->id.next) {
907                                 ScrArea *sa;
908                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
909                                         SpaceLink *sl;
910                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
911                                                 if (sl->spacetype == SPACE_VIEW3D) {
912                                                         ARegion *ar;
913                                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
914                                                         for (ar = lb->first; ar; ar = ar->next) {
915                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
916                                                                         if (ar->regiondata) {
917                                                                                 RegionView3D *rv3d = ar->regiondata;
918                                                                                 if (rv3d->view == RV3D_VIEW_PERSPORTHO) {
919                                                                                         rv3d->view = RV3D_VIEW_USER;
920                                                                                 }
921                                                                         }
922                                                                 }
923                                                         }
924                                                         break;
925                                                 }
926                                         }
927                                 }
928                         }
929 #undef RV3D_VIEW_PERSPORTHO
930                 }
931
932                 {
933                         Lamp *lamp;
934 #define LA_YF_PHOTON    5
935                         for (lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
936                                 if (lamp->type == LA_YF_PHOTON) {
937                                         lamp->type = LA_LOCAL;
938                                 }
939                         }
940 #undef LA_YF_PHOTON
941                 }
942
943                 {
944                         Object *ob;
945                         for (ob = main->object.first; ob; ob = ob->id.next) {
946                                 if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
947                                         ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
948                                 }
949                         }
950                 }
951
952         }
953
954         if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
955                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
956                         Scene *scene;
957                         for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
958                                 CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
959                                 curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
960                                 curvemapping_initialize(curve_mapping);
961                                 curvemap_reset(curve_mapping->cm,
962                                                &curve_mapping->clipr,
963                                                CURVE_PRESET_MAX,
964                                                CURVEMAP_SLOPE_POS_NEG);
965                         }
966                 }
967         }
968
969         if (!MAIN_VERSION_ATLEAST(main, 276, 4)) {
970                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
971                         ToolSettings *ts = scene->toolsettings;
972                         
973                         if (ts->gp_sculpt.brush[0].size == 0) {
974                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
975                                 GP_EditBrush_Data *brush;
976                                 
977                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
978                                 brush->size = 25;
979                                 brush->strength = 0.3f;
980                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
981                                 
982                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
983                                 brush->size = 25;
984                                 brush->strength = 0.5f;
985                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
986                                 
987                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
988                                 brush->size = 50;
989                                 brush->strength = 0.3f;
990                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
991                                 
992                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
993                                 brush->size = 25;
994                                 brush->strength = 0.3f;
995                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
996                                 
997                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
998                                 brush->size = 50;
999                                 brush->strength = 0.3f; // XXX?
1000                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1001                                 
1002                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
1003                                 brush->size = 50;
1004                                 brush->strength = 0.5f; // XXX?
1005                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1006                                 
1007                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
1008                                 brush->size = 25;
1009                                 brush->strength = 0.5f;
1010                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1011                                 
1012                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_CLONE];
1013                                 brush->size = 50;
1014                                 brush->strength = 1.0f;
1015                         }
1016                         
1017                         if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
1018 #if 0 /* XXX: Cannot do this, as we get random crashes... */
1019                                 if (scene->gpd) {
1020                                         bGPdata *gpd = scene->gpd;
1021                                         
1022                                         /* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
1023                                         ts->gpencil_v3d_align = 0;
1024                                         
1025                                         if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
1026                                         if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
1027                                         if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
1028                                         
1029                                         if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
1030                                                 ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
1031                                 }
1032                                 else {
1033                                         /* Default to cursor for all standard 3D views */
1034                                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1035                                 }
1036 #endif
1037                                 
1038                                 ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
1039                                 ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
1040                                 ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
1041                                 ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
1042                         }
1043                 }
1044                 
1045                 for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1046                         bool enabled = false;
1047                         
1048                         /* Ensure that the datablock's onionskinning toggle flag
1049                          * stays in sync with the status of the actual layers
1050                          */
1051                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1052                                 if (gpl->flag & GP_LAYER_ONIONSKIN) {
1053                                         enabled = true;
1054                                 }
1055                         }
1056                         
1057                         if (enabled)
1058                                 gpd->flag |= GP_DATA_SHOW_ONIONSKINS;
1059                         else
1060                                 gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
1061                 }
1062
1063                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) {
1064                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1065                                 ob->max_jumps = 1;
1066                         }
1067                 }
1068         }
1069         if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
1070                 ListBase *lbarray[MAX_LIBARRAY];
1071                 int a;
1072
1073                 /* Important to clear all non-persistent flags from older versions here, otherwise they could collide
1074                  * with any new persistent flag we may add in the future. */
1075                 a = set_listbasepointers(main, lbarray);
1076                 while (a--) {
1077                         for (ID *id = lbarray[a]->first; id; id = id->next) {
1078                                 id->flag &= LIB_FAKEUSER;
1079                         }
1080                 }
1081         }
1082
1083         if (!MAIN_VERSION_ATLEAST(main, 276, 7)) {
1084                 Scene *scene;
1085                 for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
1086                         scene->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
1087                 }
1088         }
1089
1090         if (!MAIN_VERSION_ATLEAST(main, 277, 1)) {
1091                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1092                         ParticleEditSettings *pset = &scene->toolsettings->particle;
1093                         for (int a = 0; a < PE_TOT_BRUSH; a++) {
1094                                 if (pset->brush[a].strength > 1.0f) {
1095                                         pset->brush[a].strength *= 0.01f;
1096                                 }
1097                         }
1098                 }
1099
1100                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1101                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1102                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1103                                         ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1104                                         /* Bug: Was possible to add preview region to sequencer view by using AZones. */
1105                                         if (sl->spacetype == SPACE_SEQ) {
1106                                                 SpaceSeq *sseq = (SpaceSeq *)sl;
1107                                                 if (sseq->view == SEQ_VIEW_SEQUENCE) {
1108                                                         for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1109                                                                 /* remove preview region for sequencer-only view! */
1110                                                                 if (ar->regiontype == RGN_TYPE_PREVIEW) {
1111                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1112                                                                         ar->alignment = RGN_ALIGN_NONE;
1113                                                                         break;
1114                                                                 }
1115                                                         }
1116                                                 }
1117                                         }
1118                                         /* Remove old deprecated region from filebrowsers */
1119                                         else if (sl->spacetype == SPACE_FILE) {
1120                                                 for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
1121                                                         if (ar->regiontype == RGN_TYPE_CHANNELS) {
1122                                                                 /* Free old deprecated 'channel' region... */
1123                                                                 BKE_area_region_free(NULL, ar);
1124                                                                 BLI_freelinkN(regionbase, ar);
1125                                                                 break;
1126                                                         }
1127                                                 }
1128                                         }
1129                                 }
1130                         }
1131                 }
1132
1133                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1134                         CurvePaintSettings *cps = &scene->toolsettings->curve_paint_settings;
1135                         if (cps->error_threshold == 0) {
1136                                 cps->curve_type = CU_BEZIER;
1137                                 cps->flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
1138                                 cps->error_threshold = 8;
1139                                 cps->radius_max = 1.0f;
1140                                 cps->corner_angle = DEG2RADF(70.0f);
1141                         }
1142                 }
1143
1144                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1145                         Sequence *seq;
1146
1147                         SEQ_BEGIN (scene->ed, seq)
1148                         {
1149                                 if (seq->type == SEQ_TYPE_TEXT) {
1150                                         TextVars *data = seq->effectdata;
1151                                         if (data->color[3] == 0.0f) {
1152                                                 copy_v4_fl(data->color, 1.0f);
1153                                                 data->shadow_color[3] = 1.0f;
1154                                         }
1155                                 }
1156                         }
1157                         SEQ_END
1158                 }
1159
1160                 /* Adding "Properties" region to DopeSheet */
1161                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1162                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1163                                 /* handle pushed-back space data first */
1164                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1165                                         if (sl->spacetype == SPACE_ACTION) {
1166                                                 SpaceAction *saction = (SpaceAction *)sl;
1167                                                 do_version_action_editor_properties_region(&saction->regionbase);
1168                                         }
1169                                 }
1170                                 
1171                                 /* active spacedata info must be handled too... */
1172                                 if (sa->spacetype == SPACE_ACTION) {
1173                                         do_version_action_editor_properties_region(&sa->regionbase);
1174                                 }
1175                         }
1176                 }
1177         }
1178
1179         if (!MAIN_VERSION_ATLEAST(main, 277, 2)) {
1180                 if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "scaleIn")) {
1181                         for (bArmature *arm = main->armature.first; arm; arm = arm->id.next) {
1182                                 do_version_bones_super_bbone(&arm->bonebase);
1183                         }
1184                 }
1185                 if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "scaleIn")) {
1186                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1187                                 if (ob->pose) {
1188                                         for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1189                                                 /* see do_version_bones_super_bbone()... */
1190                                                 pchan->scaleIn = 1.0f;
1191                                                 pchan->scaleOut = 1.0f;
1192                                                 
1193                                                 /* also make sure some legacy (unused for over a decade) flags are unset,
1194                                                  * so that we can reuse them for stuff that matters now...
1195                                                  * (i.e. POSE_IK_MAT, (unknown/unused x 4), POSE_HAS_IK)
1196                                                  *
1197                                                  * These seem to have been runtime flags used by the IK solver, but that stuff
1198                                                  * should be able to be recalculated automatically anyway, so it should be fine.
1199                                                  */
1200                                                 pchan->flag &= ~((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8));
1201                                         }
1202                                 }
1203                         }
1204                 }
1205
1206                 for (Camera *camera = main->camera.first; camera != NULL; camera = camera->id.next) {
1207                         if (camera->stereo.pole_merge_angle_from == 0.0f &&
1208                                 camera->stereo.pole_merge_angle_to == 0.0f)
1209                         {
1210                                 camera->stereo.pole_merge_angle_from = DEG2RADF(60.0f);
1211                                 camera->stereo.pole_merge_angle_to = DEG2RADF(75.0f);
1212                         }
1213                 }
1214
1215                 if (!DNA_struct_elem_find(fd->filesdna, "NormalEditModifierData", "float", "mix_limit")) {
1216                         Object *ob;
1217
1218                         for (ob = main->object.first; ob; ob = ob->id.next) {
1219                                 ModifierData *md;
1220                                 for (md = ob->modifiers.first; md; md = md->next) {
1221                                         if (md->type == eModifierType_NormalEdit) {
1222                                                 NormalEditModifierData *nemd = (NormalEditModifierData *)md;
1223                                                 nemd->mix_limit = DEG2RADF(180.0f);
1224                                         }
1225                                 }
1226                         }
1227                 }
1228
1229                 if (!DNA_struct_elem_find(fd->filesdna, "BooleanModifierData", "float", "double_threshold")) {
1230                         Object *ob;
1231                         for (ob = main->object.first; ob; ob = ob->id.next) {
1232                                 ModifierData *md;
1233                                 for (md = ob->modifiers.first; md; md = md->next) {
1234                                         if (md->type == eModifierType_Boolean) {
1235                                                 BooleanModifierData *bmd = (BooleanModifierData *)md;
1236                                                 bmd->double_threshold = 1e-6f;
1237                                         }
1238                                 }
1239                         }
1240                 }
1241
1242                 for (Brush *br = main->brush.first; br; br = br->id.next) {
1243                         if (br->sculpt_tool == SCULPT_TOOL_FLATTEN) {
1244                                 br->flag |= BRUSH_ACCUMULATE;
1245                         }
1246                 }
1247
1248                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "time_scale")) {
1249                         Object *ob;
1250                         ModifierData *md;
1251                         for (ob = main->object.first; ob; ob = ob->id.next) {
1252                                 for (md = ob->modifiers.first; md; md = md->next) {
1253                                         if (md->type == eModifierType_Cloth) {
1254                                                 ClothModifierData *clmd = (ClothModifierData *)md;
1255                                                 clmd->sim_parms->time_scale = 1.0f;
1256                                         }
1257                                         else if (md->type == eModifierType_ParticleSystem) {
1258                                                 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
1259                                                 if (pmd->psys->clmd) {
1260                                                         pmd->psys->clmd->sim_parms->time_scale = 1.0f;
1261                                                 }
1262                                         }
1263                                 }
1264                         }
1265                 }
1266         }
1267
1268         if (!MAIN_VERSION_ATLEAST(main, 277, 3)) {
1269                 /* ------- init of grease pencil initialization --------------- */
1270                 if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) {
1271                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1272                                 ToolSettings *ts = scene->toolsettings;
1273                                 /* initialize use position for sculpt brushes */
1274                                 ts->gp_sculpt.flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION;
1275                                 /* initialize  selected vertices alpha factor */
1276                                 ts->gp_sculpt.alpha = 1.0f;
1277
1278                                 /* new strength sculpt brush */
1279                                 if (ts->gp_sculpt.brush[0].size >= 11) {
1280                                         GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
1281                                         GP_EditBrush_Data *brush;
1282
1283                                         brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
1284                                         brush->size = 25;
1285                                         brush->strength = 0.5f;
1286                                         brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
1287                                 }
1288                         }
1289                         /* create a default grease pencil drawing brushes set */
1290                         if (!BLI_listbase_is_empty(&main->gpencil)) {
1291                                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1292                                         ToolSettings *ts = scene->toolsettings;
1293                                         if (BLI_listbase_is_empty(&ts->gp_brushes)) {
1294                                                 BKE_gpencil_brush_init_presets(ts);
1295                                         }
1296                                 }
1297                         }
1298                         /* Convert Grease Pencil to new palettes/brushes
1299                          * Loop all strokes and create the palette and all colors
1300                          */
1301                         for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
1302                                 if (BLI_listbase_is_empty(&gpd->palettes)) {
1303                                         /* create palette */
1304                                         bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette", true);
1305                                         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1306                                                 /* create color using layer name */
1307                                                 bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info, true);
1308                                                 if (palcolor != NULL) {
1309                                                         /* set color attributes */
1310                                                         copy_v4_v4(palcolor->color, gpl->color);
1311                                                         copy_v4_v4(palcolor->fill, gpl->fill);
1312                                                         palcolor->flag = gpl->flag;
1313                                                         /* set layer opacity to 1 */
1314                                                         gpl->opacity = 1.0f;
1315                                                         /* set tint color */
1316                                                         ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f);
1317
1318                                                         for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
1319                                                                 for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
1320                                                                         /* set stroke to palette and force recalculation */
1321                                                                         strcpy(gps->colorname, gpl->info);
1322                                                                         gps->palcolor = NULL;
1323                                                                         gps->flag |= GP_STROKE_RECALC_COLOR;
1324                                                                         gps->thickness = gpl->thickness;
1325                                                                         /* set alpha strength to 1 */
1326                                                                         for (int i = 0; i < gps->totpoints; i++) {
1327                                                                                 gps->points[i].strength = 1.0f;
1328                                                                         }
1329
1330                                                                 }
1331                                                         }
1332                                                 }
1333                                                 /* set thickness to 0 (now it is a factor to override stroke thickness) */
1334                                                 gpl->thickness = 0.0f;
1335                                         }
1336                                         /* set first color as active */
1337                                         if (palette->colors.first)
1338                                                 BKE_gpencil_palettecolor_setactive(palette, palette->colors.first);
1339                                 }
1340                         }
1341                 }
1342                 /* ------- end of grease pencil initialization --------------- */
1343         }
1344
1345         {
1346                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) {
1347                         MovieClip *clip;
1348                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
1349                                 MovieTracking *tracking = &clip->tracking;
1350                                 MovieTrackingObject *tracking_object;
1351                                 for (tracking_object = tracking->objects.first;
1352                                      tracking_object != NULL;
1353                                      tracking_object = tracking_object->next)
1354                                 {
1355                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
1356                                         MovieTrackingTrack *track;
1357                                         for (track = tracksbase->first;
1358                                              track != NULL;
1359                                              track = track->next)
1360                                         {
1361                                                 track->weight_stab = track->weight;
1362                                         }
1363                                 }
1364                         }
1365                 }
1366
1367                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) {
1368                         MovieClip *clip;
1369                         for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) {
1370                                 if (clip->tracking.stabilization.rot_track) {
1371                                         migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization);
1372                                         if (!clip->tracking.stabilization.scale) {
1373                                                 /* ensure init.
1374                                                  * Was previously used for autoscale only,
1375                                                  * now used always (as "target scale") */
1376                                                 clip->tracking.stabilization.scale = 1.0f;
1377                                         }
1378                                 }
1379                         }
1380                 }
1381         }
1382 }