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