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