Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenloader / intern / versioning_legacy.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  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  *
26  */
27
28 /** \file blender/blenloader/intern/versioning_legacy.c
29  *  \ingroup blenloader
30  */
31
32
33 #include <limits.h>
34
35 #ifndef WIN32
36 #  include <unistd.h> // for read close
37 #else
38 #  include <zlib.h>  /* odd include order-issue */
39 #  include <io.h> // for open close read
40 #  include "winsock2.h"
41 #  include "BLI_winstuff.h"
42 #endif
43
44 /* allow readfile to use deprecated functionality */
45 #define DNA_DEPRECATED_ALLOW
46
47 #include "DNA_armature_types.h"
48 #include "DNA_camera_types.h"
49 #include "DNA_constraint_types.h"
50 #include "DNA_effect_types.h"
51 #include "DNA_group_types.h"
52 #include "DNA_key_types.h"
53 #include "DNA_lattice_types.h"
54 #include "DNA_lamp_types.h"
55 #include "DNA_material_types.h"
56 #include "DNA_mesh_types.h"
57 #include "DNA_meshdata_types.h"
58 #include "DNA_nla_types.h"
59 #include "DNA_node_types.h"
60 #include "DNA_object_fluidsim_types.h"
61 #include "DNA_object_types.h"
62 #include "DNA_view3d_types.h"
63 #include "DNA_screen_types.h"
64 #include "DNA_sdna_types.h"
65 #include "DNA_sequence_types.h"
66 #include "DNA_sound_types.h"
67 #include "DNA_space_types.h"
68 #include "DNA_vfont_types.h"
69 #include "DNA_world_types.h"
70
71 #include "MEM_guardedalloc.h"
72
73 #include "BLI_utildefines.h"
74 #include "BLI_blenlib.h"
75 #include "BLI_math.h"
76
77 #include "BKE_action.h"
78 #include "BKE_armature.h"
79 #include "BKE_colortools.h"
80 #include "BKE_constraint.h"
81 #include "BKE_deform.h"
82 #include "BKE_fcurve.h"
83 #include "BKE_image.h"
84 #include "BKE_lattice.h"
85 #include "BKE_main.h" // for Main
86 #include "BKE_mesh.h" // for ME_ defines (patching)
87 #include "BKE_modifier.h"
88 #include "BKE_particle.h"
89 #include "BKE_pointcache.h"
90 #include "BKE_scene.h"
91 #include "BKE_sequencer.h"
92
93 #include "NOD_socket.h"
94
95 #include "BLO_readfile.h"
96
97 #include "readfile.h"
98
99 #include "PIL_time.h"
100
101 #include <errno.h>
102
103 static void vcol_to_fcol(Mesh *me)
104 {
105         MFace *mface;
106         unsigned int *mcol, *mcoln, *mcolmain;
107         int a;
108
109         if (me->totface == 0 || me->mcol == NULL)
110                 return;
111
112         mcoln = mcolmain = MEM_malloc_arrayN(me->totface, 4 * sizeof(int), "mcoln");
113         mcol = (unsigned int *)me->mcol;
114         mface = me->mface;
115         for (a = me->totface; a > 0; a--, mface++) {
116                 mcoln[0] = mcol[mface->v1];
117                 mcoln[1] = mcol[mface->v2];
118                 mcoln[2] = mcol[mface->v3];
119                 mcoln[3] = mcol[mface->v4];
120                 mcoln += 4;
121         }
122
123         MEM_freeN(me->mcol);
124         me->mcol = (MCol *)mcolmain;
125 }
126
127 static void do_version_bone_head_tail_237(Bone *bone)
128 {
129         Bone *child;
130         float vec[3];
131
132         /* head */
133         copy_v3_v3(bone->arm_head, bone->arm_mat[3]);
134
135         /* tail is in current local coord system */
136         copy_v3_v3(vec, bone->arm_mat[1]);
137         mul_v3_fl(vec, bone->length);
138         add_v3_v3v3(bone->arm_tail, bone->arm_head, vec);
139
140         for (child = bone->childbase.first; child; child = child->next)
141                 do_version_bone_head_tail_237(child);
142 }
143
144 static void bone_version_238(ListBase *lb)
145 {
146         Bone *bone;
147
148         for (bone = lb->first; bone; bone = bone->next) {
149                 if (bone->rad_tail == 0.0f && bone->rad_head == 0.0f) {
150                         bone->rad_head = 0.25f*bone->length;
151                         bone->rad_tail = 0.1f*bone->length;
152
153                         bone->dist-= bone->rad_head;
154                         if (bone->dist<=0.0f)
155                                 bone->dist = 0.0f;
156                 }
157                 bone_version_238(&bone->childbase);
158         }
159 }
160
161 static void bone_version_239(ListBase *lb)
162 {
163         Bone *bone;
164
165         for (bone = lb->first; bone; bone = bone->next) {
166                 if (bone->layer == 0)
167                         bone->layer = 1;
168                 bone_version_239(&bone->childbase);
169         }
170 }
171
172 static void ntree_version_241(bNodeTree *ntree)
173 {
174         bNode *node;
175
176         if (ntree->type == NTREE_COMPOSIT) {
177                 for (node = ntree->nodes.first; node; node = node->next) {
178                         if (node->type == CMP_NODE_BLUR) {
179                                 if (node->storage == NULL) {
180                                         NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur patch");
181                                         nbd->sizex = node->custom1;
182                                         nbd->sizey = node->custom2;
183                                         nbd->filtertype = R_FILTER_QUAD;
184                                         node->storage = nbd;
185                                 }
186                         }
187                         else if (node->type == CMP_NODE_VECBLUR) {
188                                 if (node->storage == NULL) {
189                                         NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur patch");
190                                         nbd->samples = node->custom1;
191                                         nbd->maxspeed = node->custom2;
192                                         nbd->fac = 1.0f;
193                                         node->storage = nbd;
194                                 }
195                         }
196                 }
197         }
198 }
199
200 static void ntree_version_242(bNodeTree *ntree)
201 {
202         bNode *node;
203
204         if (ntree->type == NTREE_COMPOSIT) {
205                 for (node = ntree->nodes.first; node; node = node->next) {
206                         if (node->type == CMP_NODE_HUE_SAT) {
207                                 if (node->storage) {
208                                         NodeHueSat *nhs = node->storage;
209                                         if (nhs->val == 0.0f)
210                                                 nhs->val = 1.0f;
211                                 }
212                         }
213                 }
214         }
215 }
216
217 static void ntree_version_245(FileData *fd, Library *lib, bNodeTree *ntree)
218 {
219         bNode *node;
220         NodeTwoFloats *ntf;
221         ID *nodeid;
222         Image *image;
223         ImageUser *iuser;
224
225         if (ntree->type == NTREE_COMPOSIT) {
226                 for (node = ntree->nodes.first; node; node = node->next) {
227                         if (node->type == CMP_NODE_ALPHAOVER) {
228                                 if (!node->storage) {
229                                         ntf = MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats");
230                                         node->storage = ntf;
231                                         if (node->custom1)
232                                                 ntf->x = 1.0f;
233                                 }
234                         }
235
236                         /* fix for temporary flag changes during 245 cycle */
237                         nodeid = blo_do_versions_newlibadr(fd, lib, node->id);
238                         if (node->storage && nodeid && GS(nodeid->name) == ID_IM) {
239                                 image = (Image*)nodeid;
240                                 iuser = node->storage;
241                                 if (iuser->flag & IMA_OLD_PREMUL) {
242                                         iuser->flag &= ~IMA_OLD_PREMUL;
243                                 }
244                                 if (iuser->flag & IMA_DO_PREMUL) {
245                                         image->flag &= ~IMA_OLD_PREMUL;
246                                         image->alpha_mode = IMA_ALPHA_STRAIGHT;
247                                 }
248                         }
249                 }
250         }
251 }
252
253 static void idproperties_fix_groups_lengths_recurse(IDProperty *prop)
254 {
255         IDProperty *loop;
256         int i;
257
258         for (loop = prop->data.group.first, i = 0; loop; loop = loop->next, i++) {
259                 if (loop->type == IDP_GROUP)
260                         idproperties_fix_groups_lengths_recurse(loop);
261         }
262
263         if (prop->len != i) {
264                 printf("Found and fixed bad id property group length.\n");
265                 prop->len = i;
266         }
267 }
268
269 static void idproperties_fix_group_lengths(ListBase idlist)
270 {
271         ID *id;
272
273         for (id = idlist.first; id; id = id->next) {
274                 if (id->properties) {
275                         idproperties_fix_groups_lengths_recurse(id->properties);
276                 }
277         }
278 }
279
280 static void customdata_version_242(Mesh *me)
281 {
282         CustomDataLayer *layer;
283         MTFace *mtf;
284         MCol *mcol;
285         TFace *tf;
286         int a, mtfacen, mcoln;
287
288         if (!me->vdata.totlayer) {
289                 CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, me->mvert, me->totvert);
290
291                 if (me->dvert)
292                         CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_ASSIGN, me->dvert, me->totvert);
293         }
294
295         if (!me->edata.totlayer)
296                 CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, me->medge, me->totedge);
297
298         if (!me->fdata.totlayer) {
299                 CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, me->mface, me->totface);
300
301                 if (me->tface) {
302                         if (me->mcol)
303                                 MEM_freeN(me->mcol);
304
305                         me->mcol = CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, NULL, me->totface);
306                         me->mtface = CustomData_add_layer(&me->fdata, CD_MTFACE, CD_CALLOC, NULL, me->totface);
307
308                         mtf = me->mtface;
309                         mcol = me->mcol;
310                         tf = me->tface;
311
312                         for (a = 0; a < me->totface; a++, mtf++, tf++, mcol += 4) {
313                                 memcpy(mcol, tf->col, sizeof(tf->col));
314                                 memcpy(mtf->uv, tf->uv, sizeof(tf->uv));
315                         }
316
317                         MEM_freeN(me->tface);
318                         me->tface = NULL;
319                 }
320                 else if (me->mcol) {
321                         me->mcol = CustomData_add_layer(&me->fdata, CD_MCOL, CD_ASSIGN, me->mcol, me->totface);
322                 }
323         }
324
325         if (me->tface) {
326                 MEM_freeN(me->tface);
327                 me->tface = NULL;
328         }
329
330         for (a = 0, mtfacen = 0, mcoln = 0; a < me->fdata.totlayer; a++) {
331                 layer = &me->fdata.layers[a];
332
333                 if (layer->type == CD_MTFACE) {
334                         if (layer->name[0] == 0) {
335                                 if (mtfacen == 0) strcpy(layer->name, "UVMap");
336                                 else BLI_snprintf(layer->name, sizeof(layer->name), "UVMap.%.3d", mtfacen);
337                         }
338                         mtfacen++;
339                 }
340                 else if (layer->type == CD_MCOL) {
341                         if (layer->name[0] == 0) {
342                                 if (mcoln == 0)
343                                         strcpy(layer->name, "Col");
344                                 else
345                                         BLI_snprintf(layer->name, sizeof(layer->name), "Col.%.3d", mcoln);
346                         }
347                         mcoln++;
348                 }
349         }
350
351         BKE_mesh_update_customdata_pointers(me, true);
352 }
353
354 /*only copy render texface layer from active*/
355 static void customdata_version_243(Mesh *me)
356 {
357         CustomDataLayer *layer;
358         int a;
359
360         for (a = 0; a < me->fdata.totlayer; a++) {
361                 layer = &me->fdata.layers[a];
362                 layer->active_rnd = layer->active;
363         }
364 }
365
366 /* struct NodeImageAnim moved to ImageUser, and we make it default available */
367 static void do_version_ntree_242_2(bNodeTree *ntree)
368 {
369         bNode *node;
370
371         if (ntree->type == NTREE_COMPOSIT) {
372                 for (node = ntree->nodes.first; node; node = node->next) {
373                         if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
374                                 /* only image had storage */
375                                 if (node->storage) {
376                                         NodeImageAnim *nia = node->storage;
377                                         ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "ima user node");
378
379                                         iuser->frames = nia->frames;
380                                         iuser->sfra = nia->sfra;
381                                         iuser->offset = nia->nr-1;
382                                         iuser->cycl = nia->cyclic;
383                                         iuser->fie_ima = 2;
384                                         iuser->ok = 1;
385
386                                         node->storage = iuser;
387                                         MEM_freeN(nia);
388                                 }
389                                 else {
390                                         ImageUser *iuser = node->storage = MEM_callocN(sizeof(ImageUser), "node image user");
391                                         iuser->sfra = 1;
392                                         iuser->fie_ima = 2;
393                                         iuser->ok = 1;
394                                 }
395                         }
396                 }
397         }
398 }
399
400 static void do_version_free_effect_245(Effect *eff)
401 {
402         PartEff *paf;
403
404         if (eff->type == EFF_PARTICLE) {
405                 paf = (PartEff *)eff;
406                 if (paf->keys)
407                         MEM_freeN(paf->keys);
408         }
409         MEM_freeN(eff);
410 }
411
412 static void do_version_free_effects_245(ListBase *lb)
413 {
414         Effect *eff;
415
416         while ((eff = BLI_pophead(lb))) {
417                 do_version_free_effect_245(eff);
418         }
419 }
420
421 static void do_version_constraints_245(ListBase *lb)
422 {
423         bConstraint *con;
424         bConstraintTarget *ct;
425
426         for (con = lb->first; con; con = con->next) {
427                 if (con->type == CONSTRAINT_TYPE_PYTHON) {
428                         bPythonConstraint *data = (bPythonConstraint *)con->data;
429                         if (data->tar) {
430                                 /* version patching needs to be done */
431                                 ct = MEM_callocN(sizeof(bConstraintTarget), "PyConTarget");
432
433                                 ct->tar = data->tar;
434                                 BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget));
435                                 ct->space = con->tarspace;
436
437                                 BLI_addtail(&data->targets, ct);
438                                 data->tarnum++;
439
440                                 /* clear old targets to avoid problems */
441                                 data->tar = NULL;
442                                 data->subtarget[0] = '\0';
443                         }
444                 }
445                 else if (con->type == CONSTRAINT_TYPE_LOCLIKE) {
446                         bLocateLikeConstraint *data = (bLocateLikeConstraint *)con->data;
447
448                         /* new headtail functionality makes Bone-Tip function obsolete */
449                         if (data->flag & LOCLIKE_TIP)
450                                 con->headtail = 1.0f;
451                 }
452         }
453 }
454
455 PartEff *blo_do_version_give_parteff_245(Object *ob)
456 {
457         PartEff *paf;
458
459         paf = ob->effect.first;
460         while (paf) {
461                 if (paf->type == EFF_PARTICLE)
462                         return paf;
463                 paf = paf->next;
464         }
465         return NULL;
466 }
467
468 /* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already */
469 void blo_do_version_old_trackto_to_constraints(Object *ob)
470 {
471         /* create new trackto constraint from the relationship */
472         if (ob->track) {
473                 bConstraint *con = BKE_constraint_add_for_object(ob, "AutoTrack", CONSTRAINT_TYPE_TRACKTO);
474                 bTrackToConstraint *data = con->data;
475
476                 /* copy tracking settings from the object */
477                 data->tar = ob->track;
478                 data->reserved1 = ob->trackflag;
479                 data->reserved2 = ob->upflag;
480         }
481
482         /* clear old track setting */
483         ob->track = NULL;
484 }
485
486 void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
487 {
488         /* WATCH IT!!!: pointers from libdata have not been converted */
489
490         if (main->versionfile == 100) {
491                 /* tex->extend and tex->imageflag have changed: */
492                 Tex *tex = main->tex.first;
493                 while (tex) {
494                         if (tex->id.tag & LIB_TAG_NEED_LINK) {
495
496                                 if (tex->extend == 0) {
497                                         if (tex->xrepeat || tex->yrepeat) {
498                                                 tex->extend = TEX_REPEAT;
499                                         }
500                                         else {
501                                                 tex->extend = TEX_EXTEND;
502                                                 tex->xrepeat = tex->yrepeat = 1;
503                                         }
504                                 }
505
506                         }
507                         tex = tex->id.next;
508                 }
509         }
510
511         if (main->versionfile <= 101) {
512                 /* frame mapping */
513                 Scene *sce = main->scene.first;
514                 while (sce) {
515                         sce->r.framapto = 100;
516                         sce->r.images = 100;
517                         sce->r.framelen = 1.0;
518                         sce = sce->id.next;
519                 }
520         }
521
522         if (main->versionfile <= 103) {
523                 /* new variable in object: colbits */
524                 Object *ob = main->object.first;
525                 int a;
526                 while (ob) {
527                         ob->colbits = 0;
528                         if (ob->totcol) {
529                                 for (a = 0; a < ob->totcol; a++) {
530                                         if (ob->mat[a])
531                                                 ob->colbits |= (1<<a);
532                                 }
533                         }
534                         ob = ob->id.next;
535                 }
536         }
537
538         if (main->versionfile <= 104) {
539                 /* timeoffs moved */
540                 Object *ob = main->object.first;
541                 while (ob) {
542                         if (ob->transflag & 1) {
543                                 ob->transflag -= 1;
544                         }
545                         ob = ob->id.next;
546                 }
547         }
548
549         if (main->versionfile <= 105) {
550                 Object *ob = main->object.first;
551                 while (ob) {
552                         ob->dupon = 1;
553                         ob->dupoff = 0;
554                         ob->dupsta = 1;
555                         ob->dupend = 100;
556                         ob = ob->id.next;
557                 }
558         }
559
560         if (main->versionfile <= 106) {
561                 /* mcol changed */
562                 Mesh *me = main->mesh.first;
563                 while (me) {
564                         if (me->mcol)
565                                 vcol_to_fcol(me);
566                         me = me->id.next;
567                 }
568
569         }
570
571         if (main->versionfile <= 107) {
572                 Object *ob;
573                 ob = main->object.first;
574                 while (ob) {
575                         if (ob->dt == 0)
576                                 ob->dt = OB_SOLID;
577                         ob = ob->id.next;
578                 }
579
580         }
581
582         if (main->versionfile <= 109) {
583                 /* new variable: gridlines */
584                 bScreen *sc = main->screen.first;
585                 while (sc) {
586                         ScrArea *sa = sc->areabase.first;
587                         while (sa) {
588                                 SpaceLink *sl = sa->spacedata.first;
589                                 while (sl) {
590                                         if (sl->spacetype == SPACE_VIEW3D) {
591                                                 View3D *v3d = (View3D*) sl;
592
593                                                 if (v3d->gridlines == 0)
594                                                         v3d->gridlines = 20;
595                                         }
596                                         sl = sl->next;
597                                 }
598                                 sa = sa->next;
599                         }
600                         sc = sc->id.next;
601                 }
602         }
603
604         if (main->versionfile <= 134) {
605                 Tex *tex = main->tex.first;
606                 while (tex) {
607                         if ((tex->rfac == 0.0f) &&
608                                 (tex->gfac == 0.0f) &&
609                                 (tex->bfac == 0.0f))
610                         {
611                                 tex->rfac = 1.0f;
612                                 tex->gfac = 1.0f;
613                                 tex->bfac = 1.0f;
614                                 tex->filtersize = 1.0f;
615                         }
616                         tex = tex->id.next;
617                 }
618         }
619
620         if (main->versionfile <= 140) {
621                 /* r-g-b-fac in texture */
622                 Tex *tex = main->tex.first;
623                 while (tex) {
624                         if ((tex->rfac == 0.0f) &&
625                                 (tex->gfac == 0.0f) &&
626                                 (tex->bfac == 0.0f))
627                         {
628                                 tex->rfac = 1.0f;
629                                 tex->gfac = 1.0f;
630                                 tex->bfac = 1.0f;
631                                 tex->filtersize = 1.0f;
632                         }
633                         tex = tex->id.next;
634                 }
635         }
636
637         if (main->versionfile <= 153) {
638                 Scene *sce = main->scene.first;
639                 while (sce) {
640                         if (sce->r.blurfac == 0.0f)
641                                 sce->r.blurfac = 1.0f;
642                         sce = sce->id.next;
643                 }
644         }
645
646         if (main->versionfile <= 163) {
647                 Scene *sce = main->scene.first;
648                 while (sce) {
649                         if (sce->r.frs_sec == 0)
650                                 sce->r.frs_sec = 25;
651                         sce = sce->id.next;
652                 }
653         }
654
655         if (main->versionfile <= 164) {
656                 Mesh *me = main->mesh.first;
657                 while (me) {
658                         me->smoothresh = 30;
659                         me = me->id.next;
660                 }
661         }
662
663         if (main->versionfile <= 165) {
664                 Mesh *me = main->mesh.first;
665                 TFace *tface;
666                 int nr;
667                 char *cp;
668
669                 while (me) {
670                         if (me->tface) {
671                                 nr = me->totface;
672                                 tface = me->tface;
673                                 while (nr--) {
674                                         int j;
675                                         for (j = 0; j < 4; j++) {
676                                                 int k;
677                                                 cp = ((char *)&tface->col[j]) + 1;
678                                                 for (k = 0; k < 3; k++) {
679                                                         cp[k] = (cp[k] > 126) ? 255 : cp[k] * 2;
680                                                 }
681                                         }
682
683                                         tface++;
684                                 }
685                         }
686                         me = me->id.next;
687                 }
688         }
689
690         if (main->versionfile <= 169) {
691                 Mesh *me = main->mesh.first;
692                 while (me) {
693                         if (me->subdiv == 0)
694                                 me->subdiv = 1;
695                         me = me->id.next;
696                 }
697         }
698
699         if (main->versionfile <= 169) {
700                 bScreen *sc = main->screen.first;
701                 while (sc) {
702                         ScrArea *sa = sc->areabase.first;
703                         while (sa) {
704                                 SpaceLink *sl = sa->spacedata.first;
705                                 while (sl) {
706                                         if (sl->spacetype == SPACE_IPO) {
707                                                 SpaceIpo *sipo = (SpaceIpo*) sl;
708                                                 sipo->v2d.max[0] = 15000.0;
709                                         }
710                                         sl = sl->next;
711                                 }
712                                 sa = sa->next;
713                         }
714                         sc = sc->id.next;
715                 }
716         }
717
718         if (main->versionfile <= 170) {
719                 Object *ob = main->object.first;
720                 PartEff *paf;
721                 while (ob) {
722                         paf = blo_do_version_give_parteff_245(ob);
723                         if (paf) {
724                                 if (paf->staticstep == 0) {
725                                         paf->staticstep = 5;
726                                 }
727                         }
728                         ob = ob->id.next;
729                 }
730         }
731
732         if (main->versionfile <= 171) {
733                 bScreen *sc = main->screen.first;
734                 while (sc) {
735                         ScrArea *sa = sc->areabase.first;
736                         while (sa) {
737                                 SpaceLink *sl = sa->spacedata.first;
738                                 while (sl) {
739                                         if (sl->spacetype == SPACE_TEXT) {
740                                                 SpaceText *st = (SpaceText*) sl;
741                                                 st->lheight = 12;
742                                         }
743                                         sl = sl->next;
744                                 }
745                                 sa = sa->next;
746                         }
747                         sc = sc->id.next;
748                 }
749         }
750
751         if (main->versionfile <= 173) {
752                 int a, b;
753                 Mesh *me = main->mesh.first;
754                 while (me) {
755                         if (me->tface) {
756                                 TFace *tface = me->tface;
757                                 for (a = 0; a < me->totface; a++, tface++) {
758                                         for (b = 0; b < 4; b++) {
759                                                 tface->uv[b][0] /= 32767.0f;
760                                                 tface->uv[b][1] /= 32767.0f;
761                                         }
762                                 }
763                         }
764                         me = me->id.next;
765                 }
766         }
767
768         if (main->versionfile <= 204) {
769                 bSound *sound;
770
771                 sound = main->sound.first;
772                 while (sound) {
773                         if (sound->volume < 0.01f) {
774                                 sound->volume = 1.0f;
775                         }
776                         sound = sound->id.next;
777                 }
778         }
779
780         if (main->versionfile <= 212) {
781                 bSound *sound;
782                 Mesh *me;
783
784                 sound = main->sound.first;
785                 while (sound) {
786                         sound->max_gain = 1.0;
787                         sound->min_gain = 0.0;
788                         sound->distance = 1.0;
789
790                         if (sound->attenuation > 0.0f)
791                                 sound->flags |= SOUND_FLAGS_3D;
792                         else
793                                 sound->flags &= ~SOUND_FLAGS_3D;
794
795                         sound = sound->id.next;
796                 }
797
798                 /* me->subdiv changed to reflect the actual reparametization
799                  * better, and smeshes were removed - if it was a smesh make
800                  * it a subsurf, and reset the subdiv level because subsurf
801                  * takes a lot more work to calculate.
802                  */
803                 for (me = main->mesh.first; me; me = me->id.next) {
804                         if (me->flag & ME_SMESH) {
805                                 me->flag &= ~ME_SMESH;
806                                 me->flag |= ME_SUBSURF;
807
808                                 me->subdiv = 1;
809                         }
810                         else {
811                                 if (me->subdiv < 2)
812                                         me->subdiv = 1;
813                                 else
814                                         me->subdiv--;
815                         }
816                 }
817         }
818
819         if (main->versionfile <= 220) {
820                 Mesh *me;
821
822                 /* Began using alpha component of vertex colors, but
823                  * old file vertex colors are undefined, reset them
824                  * to be fully opaque. -zr
825                  */
826                 for (me = main->mesh.first; me; me = me->id.next) {
827                         if (me->mcol) {
828                                 int i;
829
830                                 for (i = 0; i < me->totface * 4; i++) {
831                                         MCol *mcol = &me->mcol[i];
832                                         mcol->a = 255;
833                                 }
834                         }
835                         if (me->tface) {
836                                 int i, j;
837
838                                 for (i = 0; i < me->totface; i++) {
839                                         TFace *tf = &((TFace*) me->tface)[i];
840
841                                         for (j = 0; j < 4; j++) {
842                                                 char *col = (char *) &tf->col[j];
843
844                                                 col[0] = 255;
845                                         }
846                                 }
847                         }
848                 }
849         }
850
851         if (main->versionfile <= 223) {
852                 VFont *vf;
853                 for (vf = main->vfont.first; vf; vf = vf->id.next) {
854                         if (STREQ(vf->name + strlen(vf->name) - 6, ".Bfont")) {
855                                 strcpy(vf->name, FO_BUILTIN_NAME);
856                         }
857                 }
858         }
859
860         if (main->versionfile <= 224) {
861                 bSound *sound;
862                 Scene *sce;
863                 Mesh *me;
864                 bScreen *sc;
865
866                 for (sound = main->sound.first; sound; sound = sound->id.next) {
867                         if (sound->packedfile) {
868                                 if (sound->newpackedfile == NULL) {
869                                         sound->newpackedfile = sound->packedfile;
870                                 }
871                                 sound->packedfile = NULL;
872                         }
873                 }
874                 /* Make sure that old subsurf meshes don't have zero subdivision level for rendering */
875                 for (me = main->mesh.first; me; me = me->id.next) {
876                         if ((me->flag & ME_SUBSURF) && (me->subdivr == 0))
877                                 me->subdivr = me->subdiv;
878                 }
879
880                 for (sce = main->scene.first; sce; sce = sce->id.next) {
881                         sce->r.stereomode = 1;  // no stereo
882                 }
883
884                 /* some oldfile patch, moved from set_func_space */
885                 for (sc = main->screen.first; sc; sc = sc->id.next) {
886                         ScrArea *sa;
887
888                         for (sa = sc->areabase.first; sa; sa = sa->next) {
889                                 SpaceLink *sl;
890
891                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
892                                         if (sl->spacetype == SPACE_IPO) {
893                                                 SpaceSeq *sseq = (SpaceSeq*) sl;
894                                                 sseq->v2d.keeptot = 0;
895                                         }
896                                 }
897                         }
898                 }
899         }
900
901         if (main->versionfile <= 227) {
902                 Scene *sce;
903                 bScreen *sc;
904                 Object *ob;
905
906                 /* As of now, this insures that the transition from the old Track system
907                  * to the new full constraint Track is painless for everyone. - theeth
908                  */
909                 ob = main->object.first;
910
911                 while (ob) {
912                         ListBase *list;
913                         list = &ob->constraints;
914
915                         /* check for already existing TrackTo constraint
916                          * set their track and up flag correctly
917                          */
918
919                         if (list) {
920                                 bConstraint *curcon;
921                                 for (curcon = list->first; curcon; curcon = curcon->next) {
922                                         if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
923                                                 bTrackToConstraint *data = curcon->data;
924                                                 data->reserved1 = ob->trackflag;
925                                                 data->reserved2 = ob->upflag;
926                                         }
927                                 }
928                         }
929
930                         if (ob->type == OB_ARMATURE) {
931                                 if (ob->pose) {
932                                         bConstraint *curcon;
933                                         bPoseChannel *pchan;
934                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
935                                                 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
936                                                         if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
937                                                                 bTrackToConstraint *data = curcon->data;
938                                                                 data->reserved1 = ob->trackflag;
939                                                                 data->reserved2 = ob->upflag;
940                                                         }
941                                                 }
942                                         }
943                                 }
944                         }
945
946                         /* Change Ob->Track in real TrackTo constraint */
947                         blo_do_version_old_trackto_to_constraints(ob);
948
949                         ob = ob->id.next;
950                 }
951
952                 for (sce = main->scene.first; sce; sce = sce->id.next) {
953                         sce->audio.mixrate = 48000;
954                         sce->audio.flag |= AUDIO_SCRUB;
955                 }
956
957                 /* patch for old wrong max view2d settings, allows zooming out more */
958                 for (sc = main->screen.first; sc; sc = sc->id.next) {
959                         ScrArea *sa;
960
961                         for (sa = sc->areabase.first; sa; sa = sa->next) {
962                                 SpaceLink *sl;
963
964                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
965                                         if (sl->spacetype == SPACE_ACTION) {
966                                                 SpaceAction *sac = (SpaceAction *) sl;
967                                                 sac->v2d.max[0] = 32000;
968                                         }
969                                         else if (sl->spacetype == SPACE_NLA) {
970                                                 SpaceNla *sla = (SpaceNla *) sl;
971                                                 sla->v2d.max[0] = 32000;
972                                         }
973                                 }
974                         }
975                 }
976         }
977
978         if (main->versionfile <= 228) {
979                 bScreen *sc;
980                 Object *ob;
981
982                 /* As of now, this insures that the transition from the old Track system
983                  * to the new full constraint Track is painless for everyone.
984                  */
985                 ob = main->object.first;
986
987                 while (ob) {
988                         ListBase *list;
989                         list = &ob->constraints;
990
991                         /* check for already existing TrackTo constraint
992                          * set their track and up flag correctly */
993
994                         if (list) {
995                                 bConstraint *curcon;
996                                 for (curcon = list->first; curcon; curcon = curcon->next) {
997                                         if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
998                                                 bTrackToConstraint *data = curcon->data;
999                                                 data->reserved1 = ob->trackflag;
1000                                                 data->reserved2 = ob->upflag;
1001                                         }
1002                                 }
1003                         }
1004
1005                         if (ob->type == OB_ARMATURE) {
1006                                 if (ob->pose) {
1007                                         bConstraint *curcon;
1008                                         bPoseChannel *pchan;
1009                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1010                                                 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
1011                                                         if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
1012                                                                 bTrackToConstraint *data = curcon->data;
1013                                                                 data->reserved1 = ob->trackflag;
1014                                                                 data->reserved2 = ob->upflag;
1015                                                         }
1016                                                 }
1017                                         }
1018                                 }
1019                         }
1020
1021                         ob = ob->id.next;
1022                 }
1023
1024                 /* convert old mainb values for new button panels */
1025                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1026                         ScrArea *sa;
1027
1028                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1029                                 SpaceLink *sl;
1030
1031                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1032                                         if (sl->spacetype == SPACE_BUTS) {
1033                                                 SpaceButs *sbuts = (SpaceButs *) sl;
1034
1035                                                 sbuts->v2d.maxzoom = 1.2f;
1036                                                 sbuts->align = 1;       /* horizontal default */
1037
1038                                                 if (sbuts->mainb == BUTS_LAMP) {
1039                                                         sbuts->mainb = CONTEXT_SHADING;
1040                                                         //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_LAMP;
1041                                                 }
1042                                                 else if (sbuts->mainb == BUTS_MAT) {
1043                                                         sbuts->mainb = CONTEXT_SHADING;
1044                                                         //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_MAT;
1045                                                 }
1046                                                 else if (sbuts->mainb == BUTS_TEX) {
1047                                                         sbuts->mainb = CONTEXT_SHADING;
1048                                                         //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_TEX;
1049                                                 }
1050                                                 else if (sbuts->mainb == BUTS_ANIM) {
1051                                                         sbuts->mainb = CONTEXT_OBJECT;
1052                                                 }
1053                                                 else if (sbuts->mainb == BUTS_WORLD) {
1054                                                         sbuts->mainb = CONTEXT_SCENE;
1055                                                         //sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_WORLD;
1056                                                 }
1057                                                 else if (sbuts->mainb == BUTS_RENDER) {
1058                                                         sbuts->mainb = CONTEXT_SCENE;
1059                                                         //sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_RENDER;
1060                                                 }
1061                                                 else if (sbuts->mainb == BUTS_FPAINT) {
1062                                                         sbuts->mainb = CONTEXT_EDITING;
1063                                                 }
1064                                                 else if (sbuts->mainb == BUTS_RADIO) {
1065                                                         sbuts->mainb = CONTEXT_SHADING;
1066                                                         //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_RAD;
1067                                                 }
1068                                                 else if (sbuts->mainb == BUTS_CONSTRAINT) {
1069                                                         sbuts->mainb = CONTEXT_OBJECT;
1070                                                 }
1071                                                 else if (sbuts->mainb == BUTS_SCRIPT) {
1072                                                         sbuts->mainb = CONTEXT_OBJECT;
1073                                                 }
1074                                                 else if (sbuts->mainb == BUTS_EDIT) {
1075                                                         sbuts->mainb = CONTEXT_EDITING;
1076                                                 }
1077                                                 else {
1078                                                         sbuts->mainb = CONTEXT_SCENE;
1079                                                 }
1080                                         }
1081                                 }
1082                         }
1083                 }
1084         }
1085
1086         /* ton: made this 230 instead of 229,
1087          * to be sure (tuho files) and this is a reliable check anyway
1088          * nevertheless, we might need to think over a fitness (initialize)
1089          * check apart from the do_versions()
1090          */
1091
1092         if (main->versionfile <= 230) {
1093                 bScreen *sc;
1094
1095                 /* new variable blockscale, for panels in any area */
1096                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1097                         ScrArea *sa;
1098
1099                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1100                                 SpaceLink *sl;
1101
1102                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1103                                         /* added: 5x better zoom in for action */
1104                                         if (sl->spacetype == SPACE_ACTION) {
1105                                                 SpaceAction *sac = (SpaceAction *)sl;
1106                                                 sac->v2d.maxzoom = 50;
1107                                         }
1108                                 }
1109                         }
1110                 }
1111         }
1112
1113         if (main->versionfile <= 231) {
1114                 /* new bit flags for showing/hiding grid floor and axes */
1115                 bScreen *sc = main->screen.first;
1116
1117                 while (sc) {
1118                         ScrArea *sa = sc->areabase.first;
1119                         while (sa) {
1120                                 SpaceLink *sl = sa->spacedata.first;
1121                                 while (sl) {
1122                                         if (sl->spacetype == SPACE_VIEW3D) {
1123                                                 View3D *v3d = (View3D*) sl;
1124
1125                                                 if (v3d->gridflag == 0) {
1126                                                         v3d->gridflag |= V3D_SHOW_X;
1127                                                         v3d->gridflag |= V3D_SHOW_Y;
1128                                                         v3d->gridflag |= V3D_SHOW_FLOOR;
1129                                                         v3d->gridflag &= ~V3D_SHOW_Z;
1130                                                 }
1131                                         }
1132                                         sl = sl->next;
1133                                 }
1134                                 sa = sa->next;
1135                         }
1136                         sc = sc->id.next;
1137                 }
1138         }
1139
1140         if (main->versionfile <= 231) {
1141                 bScreen *sc = main->screen.first;
1142
1143                 /* new bit flags for showing/hiding grid floor and axes */
1144
1145                 while (sc) {
1146                         ScrArea *sa = sc->areabase.first;
1147                         while (sa) {
1148                                 SpaceLink *sl = sa->spacedata.first;
1149                                 while (sl) {
1150                                         if (sl->spacetype == SPACE_VIEW3D) {
1151                                                 View3D *v3d = (View3D*) sl;
1152
1153                                                 if (v3d->gridflag == 0) {
1154                                                         v3d->gridflag |= V3D_SHOW_X;
1155                                                         v3d->gridflag |= V3D_SHOW_Y;
1156                                                         v3d->gridflag |= V3D_SHOW_FLOOR;
1157                                                         v3d->gridflag &= ~V3D_SHOW_Z;
1158                                                 }
1159                                         }
1160                                         sl = sl->next;
1161                                 }
1162                                 sa = sa->next;
1163                         }
1164                         sc = sc->id.next;
1165                 }
1166         }
1167
1168         if (main->versionfile <= 232) {
1169                 Tex *tex = main->tex.first;
1170                 World *wrld = main->world.first;
1171                 bScreen *sc;
1172
1173                 while (tex) {
1174                         if ((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
1175                                 tex->flag |= TEX_CHECKER_ODD;
1176                         }
1177                         /* copied from kernel texture.c */
1178                         if (tex->ns_outscale == 0.0f) {
1179                                 /* musgrave */
1180                                 tex->mg_H = 1.0f;
1181                                 tex->mg_lacunarity = 2.0f;
1182                                 tex->mg_octaves = 2.0f;
1183                                 tex->mg_offset = 1.0f;
1184                                 tex->mg_gain = 1.0f;
1185                                 tex->ns_outscale = 1.0f;
1186                                 /* distnoise */
1187                                 tex->dist_amount = 1.0f;
1188                                 /* voronoi */
1189                                 tex->vn_w1 = 1.0f;
1190                                 tex->vn_mexp = 2.5f;
1191                         }
1192                         tex = tex->id.next;
1193                 }
1194
1195                 while (wrld) {
1196                         if (wrld->aodist == 0.0f) {
1197                                 wrld->aodist = 10.0f;
1198                         }
1199                         if (wrld->aoenergy == 0.0f)
1200                                 wrld->aoenergy = 1.0f;
1201                         wrld = wrld->id.next;
1202                 }
1203
1204                 /* new variable blockscale, for panels in any area, do again because new
1205                  * areas didnt initialize it to 0.7 yet
1206                  */
1207                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1208                         ScrArea *sa;
1209                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1210                                 SpaceLink *sl;
1211                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1212                                         /* added: 5x better zoom in for nla */
1213                                         if (sl->spacetype == SPACE_NLA) {
1214                                                 SpaceNla *snla = (SpaceNla *) sl;
1215                                                 snla->v2d.maxzoom = 50;
1216                                         }
1217                                 }
1218                         }
1219                 }
1220         }
1221
1222         if (main->versionfile <= 233) {
1223                 bScreen *sc;
1224                 Material *ma = main->mat.first;
1225                 /* Object *ob = main->object.first; */
1226
1227                 while (ma) {
1228                         if (ma->pr_lamp == 0)
1229                                 ma->pr_lamp = 3;
1230                         ma = ma->id.next;
1231                 }
1232
1233                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1234                         ScrArea *sa;
1235                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1236                                 SpaceLink *sl;
1237                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1238                                         if (sl->spacetype == SPACE_VIEW3D) {
1239                                                 View3D *v3d = (View3D *) sl;
1240                                                 v3d->flag |= V3D_SELECT_OUTLINE;
1241                                         }
1242                                 }
1243                         }
1244                 }
1245         }
1246
1247         if (main->versionfile <= 234) {
1248                 bScreen *sc;
1249
1250                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1251                         ScrArea *sa;
1252                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1253                                 SpaceLink *sl;
1254                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1255                                         if (sl->spacetype == SPACE_VIEW3D) {
1256                                                 View3D *v3d = (View3D *) sl;
1257                                                 v3d->flag |= V3D_ZBUF_SELECT;
1258                                         }
1259                                         else if (sl->spacetype == SPACE_TEXT) {
1260                                                 SpaceText *st = (SpaceText *)sl;
1261                                                 if (st->tabnumber == 0)
1262                                                         st->tabnumber = 2;
1263                                         }
1264                                 }
1265                         }
1266                 }
1267         }
1268
1269         if (main->versionfile <= 235) {
1270                 Tex *tex = main->tex.first;
1271                 Scene *sce = main->scene.first;
1272                 Sequence *seq;
1273                 Editing *ed;
1274
1275                 while (tex) {
1276                         if (tex->nabla == 0.0f)
1277                                 tex->nabla = 0.025f;
1278                         tex = tex->id.next;
1279                 }
1280                 while (sce) {
1281                         ed = sce->ed;
1282                         if (ed) {
1283                                 SEQ_BEGIN (sce->ed, seq)
1284                                 {
1285                                         if (seq->type == SEQ_TYPE_IMAGE || seq->type == SEQ_TYPE_MOVIE)
1286                                                 seq->alpha_mode = SEQ_ALPHA_STRAIGHT;
1287                                 }
1288                                 SEQ_END
1289                         }
1290
1291                         sce = sce->id.next;
1292                 }
1293         }
1294
1295         if (main->versionfile <= 236) {
1296                 Object *ob;
1297                 Camera *cam = main->camera.first;
1298
1299                 while (cam) {
1300                         if (cam->ortho_scale == 0.0f) {
1301                                 cam->ortho_scale = 256.0f / cam->lens;
1302                                 if (cam->type == CAM_ORTHO)
1303                                         printf("NOTE: ortho render has changed, tweak new Camera 'scale' value.\n");
1304                         }
1305                         cam = cam->id.next;
1306                 }
1307                 /* force oops draw if depgraph was set*/
1308                 /* set time line var */
1309
1310                 /* softbody init new vars */
1311                 for (ob = main->object.first; ob; ob = ob->id.next) {
1312                         if (ob->soft) {
1313                                 if (ob->soft->defgoal == 0.0f)
1314                                         ob->soft->defgoal = 0.7f;
1315                                 if (ob->soft->physics_speed == 0.0f)
1316                                         ob->soft->physics_speed = 1.0f;
1317
1318                                 if (ob->soft->interval == 0) {
1319                                         ob->soft->interval = 2;
1320                                         ob->soft->sfra = 1;
1321                                         ob->soft->efra = 100;
1322                                 }
1323                         }
1324                         if (ob->soft && ob->soft->vertgroup == 0) {
1325                                 bDeformGroup *locGroup = defgroup_find_name(ob, "SOFTGOAL");
1326                                 if (locGroup) {
1327                                         /* retrieve index for that group */
1328                                         ob->soft->vertgroup =  1 + BLI_findindex(&ob->defbase, locGroup);
1329                                 }
1330                         }
1331                 }
1332         }
1333
1334         if (main->versionfile <= 237) {
1335                 bArmature *arm;
1336                 bConstraint *con;
1337                 Object *ob;
1338                 Bone *bone;
1339
1340                 /* armature recode checks */
1341                 for (arm = main->armature.first; arm; arm = arm->id.next) {
1342                         BKE_armature_where_is(arm);
1343
1344                         for (bone = arm->bonebase.first; bone; bone = bone->next)
1345                                 do_version_bone_head_tail_237(bone);
1346                 }
1347                 for (ob = main->object.first; ob; ob = ob->id.next) {
1348                         if (ob->parent) {
1349                                 Object *parent = blo_do_versions_newlibadr(fd, lib, ob->parent);
1350                                 if (parent && parent->type == OB_LATTICE)
1351                                         ob->partype = PARSKEL;
1352                         }
1353
1354                         /* btw. armature_rebuild_pose is further only called on leave editmode */
1355                         if (ob->type == OB_ARMATURE) {
1356                                 if (ob->pose)
1357                                         BKE_pose_tag_recalc(main, ob->pose);
1358
1359                                 /* cannot call stuff now (pointers!), done in setup_app_data */
1360                                 ob->id.recalc |= ID_RECALC_ALL;
1361
1362                                 /* new generic xray option */
1363                                 arm = blo_do_versions_newlibadr(fd, lib, ob->data);
1364                                 if (arm->flag & ARM_DRAWXRAY) {
1365                                         ob->dtx |= OB_DRAWXRAY;
1366                                 }
1367                         }
1368                         else if (ob->type == OB_MESH) {
1369                                 Mesh *me = blo_do_versions_newlibadr(fd, lib, ob->data);
1370
1371                                 if ((me->flag&ME_SUBSURF)) {
1372                                         SubsurfModifierData *smd = (SubsurfModifierData*) modifier_new(eModifierType_Subsurf);
1373
1374                                         smd->levels = MAX2(1, me->subdiv);
1375                                         smd->renderLevels = MAX2(1, me->subdivr);
1376                                         smd->subdivType = me->subsurftype;
1377
1378                                         smd->modifier.mode = 0;
1379                                         if (me->subdiv != 0)
1380                                                 smd->modifier.mode |= 1;
1381                                         if (me->subdivr != 0)
1382                                                 smd->modifier.mode |= 2;
1383                                         if (me->flag & ME_OPT_EDGES)
1384                                                 smd->flags |= eSubsurfModifierFlag_ControlEdges;
1385
1386                                         BLI_addtail(&ob->modifiers, smd);
1387
1388                                         modifier_unique_name(&ob->modifiers, (ModifierData*)smd);
1389                                 }
1390                         }
1391
1392                         /* follow path constraint needs to set the 'path' option in curves... */
1393                         for (con = ob->constraints.first; con; con = con->next) {
1394                                 if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
1395                                         bFollowPathConstraint *data = con->data;
1396                                         Object *obc = blo_do_versions_newlibadr(fd, lib, data->tar);
1397
1398                                         if (obc && obc->type == OB_CURVE) {
1399                                                 Curve *cu = blo_do_versions_newlibadr(fd, lib, obc->data);
1400                                                 if (cu)
1401                                                         cu->flag |= CU_PATH;
1402                                         }
1403                                 }
1404                         }
1405                 }
1406         }
1407
1408         if (main->versionfile <= 238) {
1409                 Lattice *lt;
1410                 Object *ob;
1411                 bArmature *arm;
1412                 Mesh *me;
1413                 Key *key;
1414                 Scene *sce = main->scene.first;
1415
1416                 while (sce) {
1417                         if (sce->toolsettings == NULL) {
1418                                 sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
1419                                 sce->toolsettings->doublimit = 0.001f;
1420                         }
1421                         sce = sce->id.next;
1422                 }
1423
1424                 for (lt = main->latt.first; lt; lt = lt->id.next) {
1425                         if (lt->fu == 0.0f && lt->fv == 0.0f && lt->fw == 0.0f) {
1426                                 calc_lat_fudu(lt->flag, lt->pntsu, &lt->fu, &lt->du);
1427                                 calc_lat_fudu(lt->flag, lt->pntsv, &lt->fv, &lt->dv);
1428                                 calc_lat_fudu(lt->flag, lt->pntsw, &lt->fw, &lt->dw);
1429                         }
1430                 }
1431
1432                 for (ob = main->object.first; ob; ob = ob->id.next) {
1433                         ModifierData *md;
1434                         PartEff *paf;
1435
1436                         for (md = ob->modifiers.first; md; md = md->next) {
1437                                 if (md->type == eModifierType_Subsurf) {
1438                                         SubsurfModifierData *smd = (SubsurfModifierData*) md;
1439
1440                                         smd->flags &= ~(eSubsurfModifierFlag_Incremental|eSubsurfModifierFlag_DebugIncr);
1441                                 }
1442                         }
1443
1444                         if ((ob->softflag & OB_SB_ENABLE) && !modifiers_findByType(ob, eModifierType_Softbody)) {
1445                                 if (ob->softflag & OB_SB_POSTDEF) {
1446                                         md = ob->modifiers.first;
1447
1448                                         while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) {
1449                                                 md = md->next;
1450                                         }
1451
1452                                         BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(eModifierType_Softbody));
1453                                 }
1454                                 else {
1455                                         BLI_addhead(&ob->modifiers, modifier_new(eModifierType_Softbody));
1456                                 }
1457
1458                                 ob->softflag &= ~OB_SB_ENABLE;
1459                         }
1460
1461                         if (ob->pose) {
1462                                 bPoseChannel *pchan;
1463                                 bConstraint *con;
1464                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1465                                         /* note, pchan->bone is also lib-link stuff */
1466                                         if (pchan->limitmin[0] == 0.0f && pchan->limitmax[0] == 0.0f) {
1467                                                 pchan->limitmin[0] = pchan->limitmin[1] = pchan->limitmin[2] = -180.0f;
1468                                                 pchan->limitmax[0] = pchan->limitmax[1] = pchan->limitmax[2] = 180.0f;
1469
1470                                                 for (con = pchan->constraints.first; con; con = con->next) {
1471                                                         if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
1472                                                                 bKinematicConstraint *data = (bKinematicConstraint*)con->data;
1473                                                                 data->weight = 1.0f;
1474                                                                 data->orientweight = 1.0f;
1475                                                                 data->flag &= ~CONSTRAINT_IK_ROT;
1476
1477                                                                 /* enforce conversion from old IK_TOPARENT to rootbone index */
1478                                                                 data->rootbone = -1;
1479
1480                                                                 /* update_pose_etc handles rootbone == -1 */
1481                                                                 BKE_pose_tag_recalc(main, ob->pose);
1482                                                         }
1483                                                 }
1484                                         }
1485                                 }
1486                         }
1487
1488                         paf = blo_do_version_give_parteff_245(ob);
1489                         if (paf) {
1490                                 if (paf->disp == 0)
1491                                         paf->disp = 100;
1492                                 if (paf->speedtex == 0)
1493                                         paf->speedtex = 8;
1494                                 if (paf->omat == 0)
1495                                         paf->omat = 1;
1496                         }
1497                 }
1498
1499                 for (arm = main->armature.first; arm; arm = arm->id.next) {
1500                         bone_version_238(&arm->bonebase);
1501                         arm->deformflag |= ARM_DEF_VGROUP;
1502                 }
1503
1504                 for (me = main->mesh.first; me; me = me->id.next) {
1505                         if (!me->medge) {
1506                                 BKE_mesh_calc_edges_legacy(me, true);  /* true = use mface->edcode */
1507                         }
1508                         else {
1509                                 BKE_mesh_strip_loose_faces(me);
1510                         }
1511                 }
1512
1513                 for (key = main->key.first; key; key = key->id.next) {
1514                         KeyBlock *kb;
1515                         int index = 1;
1516
1517                         for (kb = key->block.first; kb; kb = kb->next) {
1518                                 if (kb == key->refkey) {
1519                                         if (kb->name[0] == 0)
1520                                                 strcpy(kb->name, "Basis");
1521                                 }
1522                                 else {
1523                                         if (kb->name[0] == 0) {
1524                                                 BLI_snprintf(kb->name, sizeof(kb->name), "Key %d", index);
1525                                         }
1526                                         index++;
1527                                 }
1528                         }
1529                 }
1530         }
1531
1532         if (main->versionfile <= 239) {
1533                 bArmature *arm;
1534                 Object *ob;
1535                 Scene *sce = main->scene.first;
1536                 Camera *cam = main->camera.first;
1537                 int set_passepartout = 0;
1538
1539                 /* deformflag is local in modifier now */
1540                 for (ob = main->object.first; ob; ob = ob->id.next) {
1541                         ModifierData *md;
1542
1543                         for (md = ob->modifiers.first; md; md = md->next) {
1544                                 if (md->type == eModifierType_Armature) {
1545                                         ArmatureModifierData *amd = (ArmatureModifierData*) md;
1546                                         if (amd->object && amd->deformflag == 0) {
1547                                                 Object *oba = blo_do_versions_newlibadr(fd, lib, amd->object);
1548                                                 arm = blo_do_versions_newlibadr(fd, lib, oba->data);
1549                                                 amd->deformflag = arm->deformflag;
1550                                         }
1551                                 }
1552                         }
1553                 }
1554
1555                 /* updating stepsize for ghost drawing */
1556                 for (arm = main->armature.first; arm; arm = arm->id.next) {
1557                         if (arm->ghostsize == 0)
1558                                 arm->ghostsize = 1;
1559                         bone_version_239(&arm->bonebase);
1560                         if (arm->layer == 0)
1561                                 arm->layer = 1;
1562                 }
1563
1564                 for (; sce; sce = sce->id.next) {
1565                         if (sce->r.scemode & R_PASSEPARTOUT) {
1566                                 set_passepartout = 1;
1567                                 sce->r.scemode &= ~R_PASSEPARTOUT;
1568                         }
1569                 }
1570
1571                 for (; cam; cam = cam->id.next) {
1572                         if (set_passepartout)
1573                                 cam->flag |= CAM_SHOWPASSEPARTOUT;
1574
1575                         /* make sure old cameras have title safe on */
1576                         if (!(cam->flag & CAM_SHOW_SAFE_MARGINS))
1577                                 cam->flag |= CAM_SHOW_SAFE_MARGINS;
1578
1579                         /* set an appropriate camera passepartout alpha */
1580                         if (!(cam->passepartalpha))
1581                                 cam->passepartalpha = 0.2f;
1582                 }
1583         }
1584
1585         if (main->versionfile <= 241) {
1586                 Object *ob;
1587                 Scene *sce;
1588                 Lamp *la;
1589                 bArmature *arm;
1590                 bNodeTree *ntree;
1591
1592                 /* updating layers still */
1593                 for (arm = main->armature.first; arm; arm = arm->id.next) {
1594                         bone_version_239(&arm->bonebase);
1595                         if (arm->layer == 0)
1596                                 arm->layer = 1;
1597                 }
1598                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1599                         if (sce->audio.mixrate == 0)
1600                                 sce->audio.mixrate = 48000;
1601
1602                         /* We don't add default layer since blender2.8 because the layers
1603                          * are now in Scene->view_layers and a default layer is created in
1604                          * the doversion later on.
1605                          */
1606                         SceneRenderLayer *srl;
1607                         /* new layer flag for sky, was default for solid */
1608                         for (srl = sce->r.layers.first; srl; srl = srl->next) {
1609                                 if (srl->layflag & SCE_LAY_SOLID)
1610                                         srl->layflag |= SCE_LAY_SKY;
1611                                 srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR);
1612                         }
1613
1614                         /* node version changes */
1615                         if (sce->nodetree)
1616                                 ntree_version_241(sce->nodetree);
1617
1618                         /* uv calculation options moved to toolsettings */
1619                         if (sce->toolsettings->unwrapper == 0) {
1620                                 sce->toolsettings->uvcalc_flag = UVCALC_FILLHOLES;
1621                                 sce->toolsettings->unwrapper = 1;
1622                         }
1623                 }
1624
1625                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
1626                         ntree_version_241(ntree);
1627
1628                 for (la = main->lamp.first; la; la = la->id.next)
1629                         if (la->buffers == 0)
1630                                 la->buffers = 1;
1631
1632                 /* for empty drawsize and drawtype */
1633                 for (ob = main->object.first; ob; ob = ob->id.next) {
1634                         if (ob->empty_drawsize == 0.0f) {
1635                                 ob->empty_drawtype = OB_ARROWS;
1636                                 ob->empty_drawsize = 1.0;
1637                         }
1638                 }
1639
1640                 /* during 2.41 images with this name were used for viewer node output, lets fix that */
1641                 if (main->versionfile == 241) {
1642                         Image *ima;
1643                         for (ima = main->image.first; ima; ima = ima->id.next) {
1644                                 if (STREQ(ima->name, "Compositor")) {
1645                                         strcpy(ima->id.name + 2, "Viewer Node");
1646                                         strcpy(ima->name, "Viewer Node");
1647                                 }
1648                         }
1649                 }
1650         }
1651
1652         if (main->versionfile <= 242) {
1653                 Scene *sce;
1654                 bScreen *sc;
1655                 Object *ob;
1656                 Curve *cu;
1657                 Material *ma;
1658                 Mesh *me;
1659                 Collection *collection;
1660                 Nurb *nu;
1661                 BezTriple *bezt;
1662                 BPoint *bp;
1663                 bNodeTree *ntree;
1664                 int a;
1665
1666                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1667                         ScrArea *sa;
1668                         sa = sc->areabase.first;
1669                         while (sa) {
1670                                 SpaceLink *sl;
1671
1672                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1673                                         if (sl->spacetype == SPACE_VIEW3D) {
1674                                                 View3D *v3d = (View3D*) sl;
1675                                                 if (v3d->gridsubdiv == 0)
1676                                                         v3d->gridsubdiv = 10;
1677                                         }
1678                                 }
1679                                 sa = sa->next;
1680                         }
1681                 }
1682
1683                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1684                         if (sce->toolsettings->select_thresh == 0.0f)
1685                                 sce->toolsettings->select_thresh = 0.01f;
1686
1687                         if (sce->r.threads == 0) {
1688                                 if (sce->r.mode & R_THREADS)
1689                                         sce->r.threads = 2;
1690                                 else
1691                                         sce->r.threads = 1;
1692                         }
1693                         if (sce->nodetree)
1694                                 ntree_version_242(sce->nodetree);
1695                 }
1696
1697                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
1698                         ntree_version_242(ntree);
1699
1700                 /* add default radius values to old curve points */
1701                 for (cu = main->curve.first; cu; cu = cu->id.next) {
1702                         for (nu = cu->nurb.first; nu; nu = nu->next) {
1703                                 if (nu) {
1704                                         if (nu->bezt) {
1705                                                 for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
1706                                                         if (!bezt->radius)
1707                                                                 bezt->radius = 1.0;
1708                                                 }
1709                                         }
1710                                         else if (nu->bp) {
1711                                                 for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
1712                                                         if (!bp->radius)
1713                                                                 bp->radius = 1.0;
1714                                                 }
1715                                         }
1716                                 }
1717                         }
1718                 }
1719
1720                 for (ob = main->object.first; ob; ob = ob->id.next) {
1721                         ModifierData *md;
1722                         ListBase *list;
1723                         list = &ob->constraints;
1724
1725                         /* check for already existing MinMax (floor) constraint
1726                          * and update the sticky flagging */
1727
1728                         if (list) {
1729                                 bConstraint *curcon;
1730                                 for (curcon = list->first; curcon; curcon = curcon->next) {
1731                                         switch (curcon->type) {
1732                                                 case CONSTRAINT_TYPE_MINMAX:
1733                                                 {
1734                                                         bMinMaxConstraint *data = curcon->data;
1735                                                         if (data->sticky == 1)
1736                                                                 data->flag |= MINMAX_STICKY;
1737                                                         else
1738                                                                 data->flag &= ~MINMAX_STICKY;
1739
1740                                                         break;
1741                                                 }
1742                                                 case CONSTRAINT_TYPE_ROTLIKE:
1743                                                 {
1744                                                         bRotateLikeConstraint *data = curcon->data;
1745
1746                                                         /* version patch from buttons_object.c */
1747                                                         if (data->flag == 0)
1748                                                                 data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
1749
1750                                                         break;
1751                                                 }
1752                                         }
1753                                 }
1754                         }
1755
1756                         if (ob->type == OB_ARMATURE) {
1757                                 if (ob->pose) {
1758                                         bConstraint *curcon;
1759                                         bPoseChannel *pchan;
1760                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1761                                                 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
1762                                                         switch (curcon->type) {
1763                                                                 case CONSTRAINT_TYPE_MINMAX:
1764                                                                         {
1765                                                                                 bMinMaxConstraint *data = curcon->data;
1766                                                                                 if (data->sticky == 1)
1767                                                                                         data->flag |= MINMAX_STICKY;
1768                                                                                 else
1769                                                                                         data->flag &= ~MINMAX_STICKY;
1770                                                                         }
1771                                                                         break;
1772                                                                 case CONSTRAINT_TYPE_KINEMATIC:
1773                                                                         {
1774                                                                                 bKinematicConstraint *data = curcon->data;
1775                                                                                 if (!(data->flag & CONSTRAINT_IK_POS)) {
1776                                                                                         data->flag |= CONSTRAINT_IK_POS;
1777                                                                                         data->flag |= CONSTRAINT_IK_STRETCH;
1778                                                                                 }
1779                                                                         }
1780                                                                         break;
1781                                                                 case CONSTRAINT_TYPE_ROTLIKE:
1782                                                                         {
1783                                                                                 bRotateLikeConstraint *data = curcon->data;
1784
1785                                                                                 /* version patch from buttons_object.c */
1786                                                                                 if (data->flag == 0)
1787                                                                                         data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
1788                                                                         }
1789                                                                         break;
1790                                                         }
1791                                                 }
1792                                         }
1793                                 }
1794                         }
1795
1796                         /* copy old object level track settings to curve modifers */
1797                         for (md = ob->modifiers.first; md; md = md->next) {
1798                                 if (md->type == eModifierType_Curve) {
1799                                         CurveModifierData *cmd = (CurveModifierData*) md;
1800
1801                                         if (cmd->defaxis == 0)
1802                                                 cmd->defaxis = ob->trackflag+1;
1803                                 }
1804                         }
1805
1806                 }
1807
1808                 for (ma = main->mat.first; ma; ma = ma->id.next) {
1809                         if (ma->nodetree)
1810                                 ntree_version_242(ma->nodetree);
1811                 }
1812
1813                 for (me = main->mesh.first; me; me = me->id.next)
1814                         customdata_version_242(me);
1815
1816                 for (collection = main->collection.first; collection; collection = collection->id.next)
1817                         if (collection->layer == 0)
1818                                 collection->layer = (1 << 20) - 1;
1819
1820                 /* now, subversion control! */
1821                 if (main->subversionfile < 3) {
1822                         Image *ima;
1823                         Tex *tex;
1824
1825                         /* Image refactor initialize */
1826                         for (ima = main->image.first; ima; ima = ima->id.next) {
1827                                 ima->source = IMA_SRC_FILE;
1828                                 ima->type = IMA_TYPE_IMAGE;
1829
1830                                 ima->gen_x = 256; ima->gen_y = 256;
1831                                 ima->gen_type = 1;
1832
1833                                 if (STREQLEN(ima->id.name + 2, "Viewer Node", sizeof(ima->id.name) - 2)) {
1834                                         ima->source = IMA_SRC_VIEWER;
1835                                         ima->type = IMA_TYPE_COMPOSITE;
1836                                 }
1837                                 if (STREQLEN(ima->id.name + 2, "Render Result", sizeof(ima->id.name) - 2)) {
1838                                         ima->source = IMA_SRC_VIEWER;
1839                                         ima->type = IMA_TYPE_R_RESULT;
1840                                 }
1841
1842                         }
1843                         for (tex = main->tex.first; tex; tex = tex->id.next) {
1844                                 if (tex->type == TEX_IMAGE && tex->ima) {
1845                                         ima = blo_do_versions_newlibadr(fd, lib, tex->ima);
1846                                         if (tex->imaflag & TEX_ANIM5_)
1847                                                 ima->source = IMA_SRC_MOVIE;
1848                                         if (tex->imaflag & TEX_FIELDS_)
1849                                                 ima->flag |= IMA_FIELDS;
1850                                         if (tex->imaflag & TEX_STD_FIELD_)
1851                                                 ima->flag |= IMA_STD_FIELD;
1852                                 }
1853                                 tex->iuser.frames = tex->frames;
1854                                 tex->iuser.fie_ima = (char)tex->fie_ima;
1855                                 tex->iuser.offset = tex->offset;
1856                                 tex->iuser.sfra = tex->sfra;
1857                                 tex->iuser.cycl = (tex->imaflag & TEX_ANIMCYCLIC_)!=0;
1858                         }
1859                         for (sce = main->scene.first; sce; sce = sce->id.next) {
1860                                 if (sce->nodetree)
1861                                         do_version_ntree_242_2(sce->nodetree);
1862                         }
1863                         for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
1864                                 do_version_ntree_242_2(ntree);
1865                         for (ma = main->mat.first; ma; ma = ma->id.next)
1866                                 if (ma->nodetree)
1867                                         do_version_ntree_242_2(ma->nodetree);
1868
1869                         for (sc = main->screen.first; sc; sc = sc->id.next) {
1870                                 ScrArea *sa;
1871                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1872                                         SpaceLink *sl;
1873                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1874                                                 if (sl->spacetype == SPACE_IMAGE) {
1875                                                         ((SpaceImage *)sl)->iuser.fie_ima = 2;
1876                                                 }
1877                                         }
1878                                 }
1879                         }
1880                 }
1881
1882                 if (main->subversionfile < 4) {
1883                         for (sce = main->scene.first; sce; sce = sce->id.next) {
1884                                 sce->r.bake_mode = 1;   /* prevent to include render stuff here */
1885                                 sce->r.bake_filter = 16;
1886                                 sce->r.bake_flag = R_BAKE_CLEAR;
1887                         }
1888                 }
1889         }
1890
1891         if (main->versionfile <= 243) {
1892                 Object *ob = main->object.first;
1893
1894                 for (; ob; ob = ob->id.next) {
1895                         bDeformGroup *curdef;
1896
1897                         for (curdef = ob->defbase.first; curdef; curdef = curdef->next) {
1898                                 /* replace an empty-string name with unique name */
1899                                 if (curdef->name[0] == '\0') {
1900                                         defgroup_unique_name(curdef, ob);
1901                                 }
1902                         }
1903
1904                         if (main->versionfile < 243 || main->subversionfile < 1) {
1905                                 ModifierData *md;
1906
1907                                 /* translate old mirror modifier axis values to new flags */
1908                                 for (md = ob->modifiers.first; md; md = md->next) {
1909                                         if (md->type == eModifierType_Mirror) {
1910                                                 MirrorModifierData *mmd = (MirrorModifierData*) md;
1911
1912                                                 switch (mmd->axis) {
1913                                                         case 0:
1914                                                                 mmd->flag |= MOD_MIR_AXIS_X;
1915                                                                 break;
1916                                                         case 1:
1917                                                                 mmd->flag |= MOD_MIR_AXIS_Y;
1918                                                                 break;
1919                                                         case 2:
1920                                                                 mmd->flag |= MOD_MIR_AXIS_Z;
1921                                                                 break;
1922                                                 }
1923
1924                                                 mmd->axis = 0;
1925                                         }
1926                                 }
1927                         }
1928                 }
1929
1930                 /* render layer added, this is not the active layer */
1931                 if (main->versionfile <= 243 || main->subversionfile < 2) {
1932                         Mesh *me;
1933                         for (me = main->mesh.first; me; me = me->id.next)
1934                                 customdata_version_243(me);
1935                 }
1936
1937         }
1938
1939         if (main->versionfile <= 244) {
1940                 bScreen *sc;
1941
1942                 if (main->versionfile != 244 || main->subversionfile < 2) {
1943                         /* correct older action editors - incorrect scrolling */
1944                         for (sc = main->screen.first; sc; sc = sc->id.next) {
1945                                 ScrArea *sa;
1946                                 sa = sc->areabase.first;
1947                                 while (sa) {
1948                                         SpaceLink *sl;
1949
1950                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1951                                                 if (sl->spacetype == SPACE_ACTION) {
1952                                                         SpaceAction *saction = (SpaceAction*) sl;
1953
1954                                                         saction->v2d.tot.ymin = -1000.0;
1955                                                         saction->v2d.tot.ymax = 0.0;
1956
1957                                                         saction->v2d.cur.ymin = -75.0;
1958                                                         saction->v2d.cur.ymax = 5.0;
1959                                                 }
1960                                         }
1961                                         sa = sa->next;
1962                                 }
1963                         }
1964                 }
1965         }
1966
1967         if (main->versionfile <= 245) {
1968                 Scene *sce;
1969                 Object *ob;
1970                 Image *ima;
1971                 Lamp *la;
1972                 Material *ma;
1973                 ParticleSettings *part;
1974                 Mesh *me;
1975                 bNodeTree *ntree;
1976                 Tex *tex;
1977                 ModifierData *md;
1978                 ParticleSystem *psys;
1979
1980                 /* unless the file was created 2.44.3 but not 2.45, update the constraints */
1981                 if (!(main->versionfile == 244 && main->subversionfile == 3) &&
1982                         ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile == 0)) )
1983                 {
1984                         for (ob = main->object.first; ob; ob = ob->id.next) {
1985                                 ListBase *list;
1986                                 list = &ob->constraints;
1987
1988                                 /* fix up constraints due to constraint recode changes (originally at 2.44.3) */
1989                                 if (list) {
1990                                         bConstraint *curcon;
1991                                         for (curcon = list->first; curcon; curcon = curcon->next) {
1992                                                 /* old CONSTRAINT_LOCAL check -> convert to CONSTRAINT_SPACE_LOCAL */
1993                                                 if (curcon->flag & 0x20) {
1994                                                         curcon->ownspace = CONSTRAINT_SPACE_LOCAL;
1995                                                         curcon->tarspace = CONSTRAINT_SPACE_LOCAL;
1996                                                 }
1997
1998                                                 switch (curcon->type) {
1999                                                         case CONSTRAINT_TYPE_LOCLIMIT:
2000                                                         {
2001                                                                 bLocLimitConstraint *data = (bLocLimitConstraint *) curcon->data;
2002
2003                                                                 /* old limit without parent option for objects */
2004                                                                 if (data->flag2)
2005                                                                         curcon->ownspace = CONSTRAINT_SPACE_LOCAL;
2006                                                         }
2007                                                         break;
2008                                                 }
2009                                         }
2010                                 }
2011
2012                                 /* correctly initialize constinv matrix */
2013                                 unit_m4(ob->constinv);
2014
2015                                 if (ob->type == OB_ARMATURE) {
2016                                         if (ob->pose) {
2017                                                 bConstraint *curcon;
2018                                                 bPoseChannel *pchan;
2019
2020                                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2021                                                         /* make sure constraints are all up to date */
2022                                                         for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
2023                                                                 /* old CONSTRAINT_LOCAL check -> convert to CONSTRAINT_SPACE_LOCAL */
2024                                                                 if (curcon->flag & 0x20) {
2025                                                                         curcon->ownspace = CONSTRAINT_SPACE_LOCAL;
2026                                                                         curcon->tarspace = CONSTRAINT_SPACE_LOCAL;
2027                                                                 }
2028
2029                                                                 switch (curcon->type) {
2030                                                                         case CONSTRAINT_TYPE_ACTION:
2031                                                                         {
2032                                                                                 bActionConstraint *data = (bActionConstraint *) curcon->data;
2033
2034                                                                                 /* 'data->local' used to mean that target was in local-space */
2035                                                                                 if (data->local)
2036                                                                                         curcon->tarspace = CONSTRAINT_SPACE_LOCAL;
2037                                                                         }
2038                                                                         break;
2039                                                                 }
2040                                                         }
2041
2042                                                         /* correctly initialize constinv matrix */
2043                                                         unit_m4(pchan->constinv);
2044                                                 }
2045                                         }
2046                                 }
2047                         }
2048                 }
2049
2050                 /* fix all versions before 2.45 */
2051                 if (main->versionfile != 245) {
2052
2053                         /* repair preview from 242 - 244*/
2054                         for (ima = main->image.first; ima; ima = ima->id.next) {
2055                                 ima->preview = NULL;
2056                         }
2057                 }
2058
2059                 /* add point caches */
2060                 for (ob = main->object.first; ob; ob = ob->id.next) {
2061                         if (ob->soft && !ob->soft->pointcache)
2062                                 ob->soft->pointcache = BKE_ptcache_add(&ob->soft->ptcaches);
2063
2064                         for (psys = ob->particlesystem.first; psys; psys = psys->next) {
2065                                 if (psys->pointcache) {
2066                                         if (psys->pointcache->flag & PTCACHE_BAKED && (psys->pointcache->flag & PTCACHE_DISK_CACHE) == 0) {
2067                                                 printf("Old memory cache isn't supported for particles, so re-bake the simulation!\n");
2068                                                 psys->pointcache->flag &= ~PTCACHE_BAKED;
2069                                         }
2070                                 }
2071                                 else
2072                                         psys->pointcache = BKE_ptcache_add(&psys->ptcaches);
2073                         }
2074
2075                         for (md = ob->modifiers.first; md; md = md->next) {
2076                                 if (md->type == eModifierType_Cloth) {
2077                                         ClothModifierData *clmd = (ClothModifierData*) md;
2078                                         if (!clmd->point_cache) {
2079                                                 clmd->point_cache = BKE_ptcache_add(&clmd->ptcaches);
2080                                                 clmd->point_cache->step = 1;
2081                                         }
2082                                 }
2083                         }
2084                 }
2085
2086                 /* Copy over old per-level multires vertex data
2087                  * into a single vertex array in struct Multires */
2088                 for (me = main->mesh.first; me; me = me->id.next) {
2089                         if (me->mr && !me->mr->verts) {
2090                                 MultiresLevel *lvl = me->mr->levels.last;
2091                                 if (lvl) {
2092                                         me->mr->verts = lvl->verts;
2093                                         lvl->verts = NULL;
2094                                         /* Don't need the other vert arrays */
2095                                         for (lvl = lvl->prev; lvl; lvl = lvl->prev) {
2096                                                 MEM_freeN(lvl->verts);
2097                                                 lvl->verts = NULL;
2098                                         }
2099                                 }
2100                         }
2101                 }
2102
2103                 if (main->versionfile != 245 || main->subversionfile < 1) {
2104                         for (la = main->lamp.first; la; la = la->id.next) {
2105                                 la->falloff_type = LA_FALLOFF_INVLINEAR;
2106
2107                                 if (la->curfalloff == NULL) {
2108                                         la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
2109                                         curvemapping_initialize(la->curfalloff);
2110                                 }
2111                         }
2112                 }
2113
2114                 for (ma = main->mat.first; ma; ma = ma->id.next) {
2115                         if (ma->gloss_mir == 0.0f) {
2116                                 ma->gloss_mir = 1.0f;
2117                         }
2118                 }
2119
2120                 for (part = main->particle.first; part; part = part->id.next) {
2121                         if (part->ren_child_nbr == 0)
2122                                 part->ren_child_nbr = part->child_nbr;
2123                 }
2124
2125                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2126                         if (sce->nodetree)
2127                                 ntree_version_245(fd, lib, sce->nodetree);
2128
2129                         if (sce->r.simplify_subsurf == 0) {
2130                                 sce->r.simplify_subsurf = 6;
2131                                 sce->r.simplify_particles = 1.0f;
2132                         }
2133                 }
2134
2135                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
2136                         ntree_version_245(fd, lib, ntree);
2137
2138                 /* fix for temporary flag changes during 245 cycle */
2139                 for (ima = main->image.first; ima; ima = ima->id.next) {
2140                         if (ima->flag & IMA_OLD_PREMUL) {
2141                                 ima->flag &= ~IMA_OLD_PREMUL;
2142                                 ima->alpha_mode = IMA_ALPHA_STRAIGHT;
2143                         }
2144                 }
2145
2146                 for (tex = main->tex.first; tex; tex = tex->id.next) {
2147                         if (tex->iuser.flag & IMA_OLD_PREMUL) {
2148                                 tex->iuser.flag &= ~IMA_OLD_PREMUL;
2149                         }
2150
2151                         ima = blo_do_versions_newlibadr(fd, lib, tex->ima);
2152                         if (ima && (tex->iuser.flag & IMA_DO_PREMUL)) {
2153                                 ima->flag &= ~IMA_OLD_PREMUL;
2154                                 ima->alpha_mode = IMA_ALPHA_STRAIGHT;
2155                         }
2156                 }
2157         }
2158
2159         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 2)) {
2160                 Image *ima;
2161
2162                 /* initialize 1:1 Aspect */
2163                 for (ima = main->image.first; ima; ima = ima->id.next) {
2164                         ima->aspx = ima->aspy = 1.0f;
2165                 }
2166         }
2167
2168         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 4)) {
2169                 bArmature *arm;
2170                 ModifierData *md;
2171                 Object *ob;
2172
2173                 for (arm = main->armature.first; arm; arm = arm->id.next)
2174                         arm->deformflag |= ARM_DEF_B_BONE_REST;
2175
2176                 for (ob = main->object.first; ob; ob = ob->id.next) {
2177                         for (md = ob->modifiers.first; md; md = md->next) {
2178                                 if (md->type == eModifierType_Armature)
2179                                         ((ArmatureModifierData*) md)->deformflag |= ARM_DEF_B_BONE_REST;
2180                         }
2181                 }
2182         }
2183
2184         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 5)) {
2185                 /* foreground color needs to be something other then black */
2186                 Scene *sce;
2187                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2188                         sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f;
2189                         sce->r.fg_stamp[3] = 1.0f; /* don't use text alpha yet */
2190                         sce->r.bg_stamp[3] = 0.25f; /* make sure the background has full alpha */
2191                 }
2192         }
2193
2194
2195         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 6)) {
2196                 Scene *sce;
2197                 /* fix frs_sec_base */
2198                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2199                         if (sce->r.frs_sec_base == 0) {
2200                                 sce->r.frs_sec_base = 1;
2201                         }
2202                 }
2203         }
2204
2205         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 7)) {
2206                 Object *ob;
2207                 bPoseChannel *pchan;
2208
2209                 for (ob = main->object.first; ob; ob = ob->id.next) {
2210                         if (ob->pose) {
2211                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2212                                         do_version_constraints_245(&pchan->constraints);
2213                                 }
2214                         }
2215                         do_version_constraints_245(&ob->constraints);
2216
2217                         if (ob->soft && ob->soft->keys) {
2218                                 SoftBody *sb = ob->soft;
2219                                 int k;
2220
2221                                 for (k = 0; k < sb->totkey; k++) {
2222                                         if (sb->keys[k])
2223                                                 MEM_freeN(sb->keys[k]);
2224                                 }
2225
2226                                 MEM_freeN(sb->keys);
2227
2228                                 sb->keys = NULL;
2229                                 sb->totkey = 0;
2230                         }
2231                 }
2232         }
2233
2234         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 8)) {
2235                 Scene *sce;
2236                 Object *ob;
2237                 PartEff *paf = NULL;
2238
2239                 for (ob = main->object.first; ob; ob = ob->id.next) {
2240                         if (ob->soft && ob->soft->keys) {
2241                                 SoftBody *sb = ob->soft;
2242                                 int k;
2243
2244                                 for (k = 0; k < sb->totkey; k++) {
2245                                         if (sb->keys[k])
2246                                                 MEM_freeN(sb->keys[k]);
2247                                 }
2248
2249                                 MEM_freeN(sb->keys);
2250
2251                                 sb->keys = NULL;
2252                                 sb->totkey = 0;
2253                         }
2254
2255                         /* convert old particles to new system */
2256                         if ((paf = blo_do_version_give_parteff_245(ob))) {
2257                                 ParticleSystem *psys;
2258                                 ModifierData *md;
2259                                 ParticleSystemModifierData *psmd;
2260                                 ParticleSettings *part;
2261
2262                                 /* create new particle system */
2263                                 psys = MEM_callocN(sizeof(ParticleSystem), "particle_system");
2264                                 psys->pointcache = BKE_ptcache_add(&psys->ptcaches);
2265
2266                                 part = psys->part = BKE_particlesettings_add(main, "ParticleSettings");
2267
2268                                 /* needed for proper libdata lookup */
2269                                 blo_do_versions_oldnewmap_insert(fd->libmap, psys->part, psys->part, 0);
2270                                 part->id.lib = ob->id.lib;
2271
2272                                 part->id.us--;
2273                                 part->id.tag |= (ob->id.tag & LIB_TAG_NEED_LINK);
2274
2275                                 psys->totpart = 0;
2276                                 psys->flag = PSYS_CURRENT;
2277
2278                                 BLI_addtail(&ob->particlesystem, psys);
2279
2280                                 md = modifier_new(eModifierType_ParticleSystem);
2281                                 BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_listbase_count(&ob->particlesystem));
2282                                 psmd = (ParticleSystemModifierData*) md;
2283                                 psmd->psys = psys;
2284                                 BLI_addtail(&ob->modifiers, md);
2285
2286                                 /* convert settings from old particle system */
2287                                 /* general settings */
2288                                 part->totpart = MIN2(paf->totpart, 100000);
2289                                 part->sta = paf->sta;
2290                                 part->end = paf->end;
2291                                 part->lifetime = paf->lifetime;
2292                                 part->randlife = paf->randlife;
2293                                 psys->seed = paf->seed;
2294                                 part->disp = paf->disp;
2295                                 part->omat = paf->mat[0];
2296                                 part->hair_step = paf->totkey;
2297
2298                                 part->eff_group = paf->group;
2299
2300                                 /* old system didn't interpolate between keypoints at render time */
2301                                 part->draw_step = part->ren_step = 0;
2302
2303                                 /* physics */
2304                                 part->normfac = paf->normfac * 25.0f;
2305                                 part->obfac = paf->obfac;
2306                                 part->randfac = paf->randfac * 25.0f;
2307                                 part->dampfac = paf->damp;
2308                                 copy_v3_v3(part->acc, paf->force);
2309
2310                                 /* flags */
2311                                 if (paf->stype & PAF_VECT) {
2312                                         if (paf->flag & PAF_STATIC) {
2313                                                 /* new hair lifetime is always 100.0f */
2314                                                 float fac = paf->lifetime / 100.0f;
2315
2316                                                 part->draw_as = PART_DRAW_PATH;
2317                                                 part->type = PART_HAIR;
2318                                                 psys->recalc |= PSYS_RECALC_REDO;
2319
2320                                                 part->normfac *= fac;
2321                                                 part->randfac *= fac;
2322                                         }
2323                                         else {
2324                                                 part->draw_as = PART_DRAW_LINE;
2325                                                 part->draw |= PART_DRAW_VEL_LENGTH;
2326                                                 part->draw_line[1] = 0.04f;
2327                                         }
2328                                 }
2329
2330                                 part->rotmode = PART_ROT_VEL;
2331
2332                                 part->flag |= (paf->flag & PAF_BSPLINE) ? PART_HAIR_BSPLINE : 0;
2333                                 part->flag |= (paf->flag & PAF_TRAND) ? PART_TRAND : 0;
2334                                 part->flag |= (paf->flag & PAF_EDISTR) ? PART_EDISTR : 0;
2335                                 part->flag |= (paf->flag & PAF_UNBORN) ? PART_UNBORN : 0;
2336                                 part->flag |= (paf->flag & PAF_DIED) ? PART_DIED : 0;
2337                                 part->from |= (paf->flag & PAF_FACE) ? PART_FROM_FACE : 0;
2338                                 part->draw |= (paf->flag & PAF_SHOWE) ? PART_DRAW_EMITTER : 0;
2339
2340                                 psys->vgroup[PSYS_VG_DENSITY] = paf->vertgroup;
2341                                 psys->vgroup[PSYS_VG_VEL] = paf->vertgroup_v;
2342                                 psys->vgroup[PSYS_VG_LENGTH] = paf->vertgroup_v;
2343
2344                                 /* dupliobjects */
2345                                 if (ob->transflag & OB_DUPLIVERTS) {
2346                                         Object *dup = main->object.first;
2347
2348                                         for (; dup; dup = dup->id.next) {
2349                                                 if (ob == blo_do_versions_newlibadr(fd, lib, dup->parent)) {
2350                                                         part->dup_ob = dup;
2351                                                         ob->transflag |= OB_DUPLIPARTS;
2352                                                         ob->transflag &= ~OB_DUPLIVERTS;
2353
2354                                                         part->draw_as = PART_DRAW_OB;
2355
2356                                                         /* needed for proper libdata lookup */
2357                                                         blo_do_versions_oldnewmap_insert(fd->libmap, dup, dup, 0);
2358                                                 }
2359                                         }
2360                                 }
2361
2362                                 {
2363                                         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
2364                                         if (fluidmd && fluidmd->fss && fluidmd->fss->type == OB_FLUIDSIM_PARTICLE)
2365                                                 part->type = PART_FLUID;
2366                                 }
2367
2368                                 do_version_free_effects_245(&ob->effect);
2369
2370                                 printf("Old particle system converted to new system.\n");
2371                         }
2372                 }
2373
2374                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2375                         ParticleEditSettings *pset = &sce->toolsettings->particle;
2376                         int a;
2377
2378                         if (pset->brush[0].size == 0) {
2379                                 pset->flag = PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
2380                                 pset->emitterdist = 0.25f;
2381                                 pset->totrekey = 5;
2382                                 pset->totaddkey = 5;
2383                                 pset->brushtype = PE_BRUSH_NONE;
2384
2385                                 for (a = 0; a < ARRAY_SIZE(pset->brush); a++) {
2386                                         pset->brush[a].strength = 50;
2387                                         pset->brush[a].size = 50;
2388                                         pset->brush[a].step = 10;
2389                                 }
2390
2391                                 pset->brush[PE_BRUSH_CUT].strength = 100;
2392                         }
2393                 }
2394         }
2395
2396         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 10)) {
2397                 Object *ob;
2398
2399                 /* dupliface scale */
2400                 for (ob = main->object.first; ob; ob = ob->id.next)
2401                         ob->dupfacesca = 1.0f;
2402         }
2403
2404         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 11)) {
2405                 Object *ob;
2406                 bActionStrip *strip;
2407
2408                 /* nla-strips - scale */
2409                 for (ob = main->object.first; ob; ob = ob->id.next) {
2410                         for (strip = ob->nlastrips.first; strip; strip = strip->next) {
2411                                 float length, actlength, repeat;
2412
2413                                 if (strip->flag & ACTSTRIP_USESTRIDE)
2414                                         repeat = 1.0f;
2415                                 else
2416                                         repeat = strip->repeat;
2417
2418                                 length = strip->end-strip->start;
2419                                 if (length == 0.0f)
2420                                         length = 1.0f;
2421                                 actlength = strip->actend-strip->actstart;
2422
2423                                 strip->scale = length / (repeat * actlength);
2424                                 if (strip->scale == 0.0f)
2425                                         strip->scale = 1.0f;
2426                         }
2427                         if (ob->soft) {
2428                                 ob->soft->inpush =  ob->soft->inspring;
2429                                 ob->soft->shearstiff = 1.0f;
2430                         }
2431                 }
2432         }
2433
2434         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 14)) {
2435                 Scene *sce;
2436                 Sequence *seq;
2437
2438                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2439                         SEQ_BEGIN (sce->ed, seq)
2440                         {
2441                                 if (seq->blend_mode == 0)
2442                                         seq->blend_opacity = 100.0f;
2443                         }
2444                         SEQ_END
2445                 }
2446         }
2447
2448         /* fix broken group lengths in id properties */
2449         if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 15)) {
2450                 idproperties_fix_group_lengths(main->scene);
2451                 idproperties_fix_group_lengths(main->library);
2452                 idproperties_fix_group_lengths(main->object);
2453                 idproperties_fix_group_lengths(main->mesh);
2454                 idproperties_fix_group_lengths(main->curve);
2455                 idproperties_fix_group_lengths(main->mball);
2456                 idproperties_fix_group_lengths(main->mat);
2457                 idproperties_fix_group_lengths(main->tex);
2458                 idproperties_fix_group_lengths(main->image);
2459                 idproperties_fix_group_lengths(main->latt);
2460                 idproperties_fix_group_lengths(main->lamp);
2461                 idproperties_fix_group_lengths(main->camera);
2462                 idproperties_fix_group_lengths(main->ipo);
2463                 idproperties_fix_group_lengths(main->key);
2464                 idproperties_fix_group_lengths(main->world);
2465                 idproperties_fix_group_lengths(main->screen);
2466                 idproperties_fix_group_lengths(main->vfont);
2467                 idproperties_fix_group_lengths(main->text);
2468                 idproperties_fix_group_lengths(main->sound);
2469                 idproperties_fix_group_lengths(main->collection);
2470                 idproperties_fix_group_lengths(main->armature);
2471                 idproperties_fix_group_lengths(main->action);
2472                 idproperties_fix_group_lengths(main->nodetree);
2473                 idproperties_fix_group_lengths(main->brush);
2474                 idproperties_fix_group_lengths(main->particle);
2475         }
2476
2477         /* convert fluids to modifier */
2478         if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
2479                 Object *ob;
2480
2481                 for (ob = main->object.first; ob; ob = ob->id.next) {
2482                         if (ob->fluidsimSettings) {
2483                                 FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifier_new(eModifierType_Fluidsim);
2484                                 BLI_addhead(&ob->modifiers, (ModifierData *)fluidmd);
2485
2486                                 MEM_freeN(fluidmd->fss);
2487                                 fluidmd->fss = MEM_dupallocN(ob->fluidsimSettings);
2488                                 fluidmd->fss->ipo = blo_do_versions_newlibadr_us(fd, ob->id.lib, ob->fluidsimSettings->ipo);
2489                                 MEM_freeN(ob->fluidsimSettings);
2490
2491                                 fluidmd->fss->lastgoodframe = INT_MAX;
2492                                 fluidmd->fss->flag = 0;
2493                                 fluidmd->fss->meshVelocities = NULL;
2494                         }
2495                 }
2496         }
2497
2498         if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
2499                 Object *ob;
2500                 for (ob = main->object.first; ob; ob = ob->id.next) {
2501                         if (ob->pd && (ob->pd->forcefield == PFIELD_WIND))
2502                                 ob->pd->f_noise = 0.0f;
2503                 }
2504         }
2505
2506         /* set the curve radius interpolation to 2.47 default - easy */
2507         if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 6)) {
2508                 Curve *cu;
2509                 Nurb *nu;
2510
2511                 for (cu = main->curve.first; cu; cu = cu->id.next) {
2512                         for (nu = cu->nurb.first; nu; nu = nu->next) {
2513                                 if (nu) {
2514                                         nu->radius_interp = 3;
2515
2516                                         /* resolu and resolv are now used differently for surfaces
2517                                          * rather than using the resolution to define the entire number of divisions,
2518                                          * use it for the number of divisions per segment
2519                                          */
2520                                         if (nu->pntsv > 1) {
2521                                                 nu->resolu = MAX2( 1, (int)(((float)nu->resolu / (float)nu->pntsu)+0.5f) );
2522                                                 nu->resolv = MAX2( 1, (int)(((float)nu->resolv / (float)nu->pntsv)+0.5f) );
2523                                         }
2524                                 }
2525                         }
2526                 }
2527         }
2528
2529         if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 2)) {
2530                 Scene *sce;
2531
2532                 /* Note, these will need to be added for painting */
2533                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2534                         sce->toolsettings->imapaint.seam_bleed = 2;
2535                         sce->toolsettings->imapaint.normal_angle = 80;
2536                 }
2537         }
2538
2539         if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 3)) {
2540                 bScreen *sc;
2541
2542                 /* adjust default settings for Animation Editors */
2543                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2544                         ScrArea *sa;
2545
2546                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2547                                 SpaceLink *sl;
2548
2549                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2550                                         switch (sl->spacetype) {
2551                                                 case SPACE_ACTION:
2552                                                         {
2553                                                                 SpaceAction *sact = (SpaceAction *)sl;
2554
2555                                                                 sact->mode = SACTCONT_DOPESHEET;
2556                                                                 sact->autosnap = SACTSNAP_FRAME;
2557                                                         }
2558                                                         break;
2559                                                 case SPACE_IPO:
2560                                                         {
2561                                                                 SpaceIpo *sipo = (SpaceIpo *)sl;
2562                                                                 sipo->autosnap = SACTSNAP_FRAME;
2563                                                         }
2564                                                         break;
2565                                                 case SPACE_NLA:
2566                                                         {
2567                                                                 SpaceNla *snla = (SpaceNla *)sl;
2568                                                                 snla->autosnap = SACTSNAP_FRAME;
2569                                                         }
2570                                                         break;
2571                                         }
2572                                 }
2573                         }
2574                 }
2575         }
2576
2577         /* correct introduce of seed for wind force */
2578         if (main->versionfile < 249 && main->subversionfile < 1) {
2579                 Object *ob;
2580                 for (ob = main->object.first; ob; ob = ob->id.next) {
2581                         if (ob->pd)
2582                                 ob->pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer())) + 1) % 128;
2583                 }
2584
2585         }
2586
2587         if (main->versionfile < 249 && main->subversionfile < 2) {
2588                 Scene *sce = main->scene.first;
2589                 Sequence *seq;
2590                 Editing *ed;
2591
2592                 while (sce) {
2593                         ed = sce->ed;
2594                         if (ed) {