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