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