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