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