Cleanup: ensure '_END' macros end with a semicolon
[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                                 } SEQ_END;
1820                         }
1821
1822                         sce = sce->id.next;
1823                 }
1824         }
1825
1826         if (bmain->versionfile <= 236) {
1827                 Object *ob;
1828                 Camera *cam = bmain->camera.first;
1829                 Material *ma;
1830                 bScreen *sc;
1831
1832                 while (cam) {
1833                         if (cam->ortho_scale == 0.0f) {
1834                                 cam->ortho_scale = 256.0f / cam->lens;
1835                                 if (cam->type == CAM_ORTHO)
1836                                         printf("NOTE: ortho render has changed, tweak new Camera 'scale' value.\n");
1837                         }
1838                         cam = cam->id.next;
1839                 }
1840                 /* set manipulator type */
1841                 /* force oops draw if depgraph was set*/
1842                 /* set time line var */
1843                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1844                         ScrArea *sa;
1845                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1846                                 SpaceLink *sl;
1847                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1848                                         if (sl->spacetype == SPACE_VIEW3D) {
1849                                                 View3D *v3d = (View3D *)sl;
1850                                                 if (v3d->twtype == 0)
1851                                                         v3d->twtype = V3D_MANIP_TRANSLATE;
1852                                         }
1853                                 }
1854                         }
1855                 }
1856                 /* init new shader vars */
1857                 for (ma = bmain->mat.first; ma; ma = ma->id.next) {
1858                         if (ma->darkness == 0.0f) {
1859                                 ma->rms = 0.1f;
1860                                 ma->darkness = 1.0f;
1861                         }
1862                 }
1863
1864                 /* softbody init new vars */
1865                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1866                         if (ob->soft) {
1867                                 if (ob->soft->defgoal == 0.0f)
1868                                         ob->soft->defgoal = 0.7f;
1869                                 if (ob->soft->physics_speed == 0.0f)
1870                                         ob->soft->physics_speed = 1.0f;
1871
1872                                 if (ob->soft->interval == 0) {
1873                                         ob->soft->interval = 2;
1874                                         ob->soft->sfra = 1;
1875                                         ob->soft->efra = 100;
1876                                 }
1877                         }
1878                         if (ob->soft && ob->soft->vertgroup == 0) {
1879                                 bDeformGroup *locGroup = defgroup_find_name(ob, "SOFTGOAL");
1880                                 if (locGroup) {
1881                                         /* retrieve index for that group */
1882                                         ob->soft->vertgroup =  1 + BLI_findindex(&ob->defbase, locGroup);
1883                                 }
1884                         }
1885                 }
1886         }
1887
1888         if (bmain->versionfile <= 237) {
1889                 bArmature *arm;
1890                 bConstraint *con;
1891                 Object *ob;
1892                 Bone *bone;
1893
1894                 /* armature recode checks */
1895                 for (arm = bmain->armature.first; arm; arm = arm->id.next) {
1896                         BKE_armature_where_is(arm);
1897
1898                         for (bone = arm->bonebase.first; bone; bone = bone->next)
1899                                 do_version_bone_head_tail_237(bone);
1900                 }
1901                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1902                         if (ob->parent) {
1903                                 Object *parent = blo_do_versions_newlibadr(fd, lib, ob->parent);
1904                                 if (parent && parent->type == OB_LATTICE)
1905                                         ob->partype = PARSKEL;
1906                         }
1907
1908                         /* btw. armature_rebuild_pose is further only called on leave editmode */
1909                         if (ob->type == OB_ARMATURE) {
1910                                 if (ob->pose)
1911                                         BKE_pose_tag_recalc(bmain, ob->pose);
1912
1913                                 /* cannot call stuff now (pointers!), done in setup_app_data */
1914                                 ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
1915
1916                                 /* new generic xray option */
1917                                 arm = blo_do_versions_newlibadr(fd, lib, ob->data);
1918                                 if (arm->flag & ARM_DRAWXRAY) {
1919                                         ob->dtx |= OB_DRAWXRAY;
1920                                 }
1921                         }
1922                         else if (ob->type == OB_MESH) {
1923                                 Mesh *me = blo_do_versions_newlibadr(fd, lib, ob->data);
1924
1925                                 if ((me->flag & ME_SUBSURF)) {
1926                                         SubsurfModifierData *smd = (SubsurfModifierData *)modifier_new(eModifierType_Subsurf);
1927
1928                                         smd->levels = MAX2(1, me->subdiv);
1929                                         smd->renderLevels = MAX2(1, me->subdivr);
1930                                         smd->subdivType = me->subsurftype;
1931
1932                                         smd->modifier.mode = 0;
1933                                         if (me->subdiv != 0)
1934                                                 smd->modifier.mode |= 1;
1935                                         if (me->subdivr != 0)
1936                                                 smd->modifier.mode |= 2;
1937                                         if (me->flag & ME_OPT_EDGES)
1938                                                 smd->flags |= eSubsurfModifierFlag_ControlEdges;
1939
1940                                         BLI_addtail(&ob->modifiers, smd);
1941
1942                                         modifier_unique_name(&ob->modifiers, (ModifierData *)smd);
1943                                 }
1944                         }
1945
1946                         /* follow path constraint needs to set the 'path' option in curves... */
1947                         for (con = ob->constraints.first; con; con = con->next) {
1948                                 if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
1949                                         bFollowPathConstraint *data = con->data;
1950                                         Object *obc = blo_do_versions_newlibadr(fd, lib, data->tar);
1951
1952                                         if (obc && obc->type == OB_CURVE) {
1953                                                 Curve *cu = blo_do_versions_newlibadr(fd, lib, obc->data);
1954                                                 if (cu)
1955                                                         cu->flag |= CU_PATH;
1956                                         }
1957                                 }
1958                         }
1959                 }
1960         }
1961
1962         if (bmain->versionfile <= 238) {
1963                 Lattice *lt;
1964                 Object *ob;
1965                 bArmature *arm;
1966                 Mesh *me;
1967                 Key *key;
1968                 Scene *sce = bmain->scene.first;
1969
1970                 while (sce) {
1971                         if (sce->toolsettings == NULL) {
1972                                 sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
1973                                 sce->toolsettings->doublimit = 0.001f;
1974                         }
1975                         sce = sce->id.next;
1976                 }
1977
1978                 for (lt = bmain->latt.first; lt; lt = lt->id.next) {
1979                         if (lt->fu == 0.0f && lt->fv == 0.0f && lt->fw == 0.0f) {
1980                                 calc_lat_fudu(lt->flag, lt->pntsu, &lt->fu, &lt->du);
1981                                 calc_lat_fudu(lt->flag, lt->pntsv, &lt->fv, &lt->dv);
1982                                 calc_lat_fudu(lt->flag, lt->pntsw, &lt->fw, &lt->dw);
1983                         }
1984                 }
1985
1986                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1987                         ModifierData *md;
1988                         PartEff *paf;
1989
1990                         for (md = ob->modifiers.first; md; md = md->next) {
1991                                 if (md->type == eModifierType_Subsurf) {
1992                                         SubsurfModifierData *smd = (SubsurfModifierData *)md;
1993
1994                                         smd->flags &= ~(eSubsurfModifierFlag_Incremental | eSubsurfModifierFlag_DebugIncr);
1995                                 }
1996                         }
1997
1998                         if ((ob->softflag & OB_SB_ENABLE) && !modifiers_findByType(ob, eModifierType_Softbody)) {
1999                                 if (ob->softflag & OB_SB_POSTDEF) {
2000                                         md = ob->modifiers.first;
2001
2002                                         while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) {
2003                                                 md = md->next;
2004                                         }
2005
2006                                         BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(eModifierType_Softbody));
2007                                 }
2008                                 else {
2009                                         BLI_addhead(&ob->modifiers, modifier_new(eModifierType_Softbody));
2010                                 }
2011
2012                                 ob->softflag &= ~OB_SB_ENABLE;
2013                         }
2014
2015                         if (ob->pose) {
2016                                 bPoseChannel *pchan;
2017                                 bConstraint *con;
2018                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2019                                         /* note, pchan->bone is also lib-link stuff */
2020                                         if (pchan->limitmin[0] == 0.0f && pchan->limitmax[0] == 0.0f) {
2021                                                 pchan->limitmin[0] = pchan->limitmin[1] = pchan->limitmin[2] = -180.0f;
2022                                                 pchan->limitmax[0] = pchan->limitmax[1] = pchan->limitmax[2] = 180.0f;
2023
2024                                                 for (con = pchan->constraints.first; con; con = con->next) {
2025                                                         if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2026                                                                 bKinematicConstraint *data = (bKinematicConstraint *)con->data;
2027                                                                 data->weight = 1.0f;
2028                                                                 data->orientweight = 1.0f;
2029                                                                 data->flag &= ~CONSTRAINT_IK_ROT;
2030
2031                                                                 /* enforce conversion from old IK_TOPARENT to rootbone index */
2032                                                                 data->rootbone = -1;
2033
2034                                                                 /* update_pose_etc handles rootbone == -1 */
2035                                                                 BKE_pose_tag_recalc(bmain, ob->pose);
2036                                                         }
2037                                                 }
2038                                         }
2039                                 }
2040                         }
2041
2042                         paf = blo_do_version_give_parteff_245(ob);
2043                         if (paf) {
2044                                 if (paf->disp == 0)
2045                                         paf->disp = 100;
2046                                 if (paf->speedtex == 0)
2047                                         paf->speedtex = 8;
2048                                 if (paf->omat == 0)
2049                                         paf->omat = 1;
2050                         }
2051                 }
2052
2053                 for (arm = bmain->armature.first; arm; arm = arm->id.next) {
2054                         bone_version_238(&arm->bonebase);
2055                         arm->deformflag |= ARM_DEF_VGROUP;
2056                 }
2057
2058                 for (me = bmain->mesh.first; me; me = me->id.next) {
2059                         if (!me->medge) {
2060                                 BKE_mesh_calc_edges_legacy(me, true);  /* true = use mface->edcode */
2061                         }
2062                         else {
2063                                 BKE_mesh_strip_loose_faces(me);
2064                         }
2065                 }
2066
2067                 for (key = bmain->key.first; key; key = key->id.next) {
2068                         KeyBlock *kb;
2069                         int index = 1;
2070
2071                         for (kb = key->block.first; kb; kb = kb->next) {
2072                                 if (kb == key->refkey) {
2073                                         if (kb->name[0] == 0)
2074                                                 strcpy(kb->name, "Basis");
2075                                 }
2076                                 else {
2077                                         if (kb->name[0] == 0) {
2078                                                 BLI_snprintf(kb->name, sizeof(kb->name), "Key %d", index);
2079                                         }
2080                                         index++;
2081                                 }
2082                         }
2083                 }
2084         }
2085
2086         if (bmain->versionfile <= 239) {
2087                 bArmature *arm;
2088                 Object *ob;
2089                 Scene *sce = bmain->scene.first;
2090                 Camera *cam = bmain->camera.first;
2091                 Material *ma = bmain->mat.first;
2092                 int set_passepartout = 0;
2093
2094                 /* deformflag is local in modifier now */
2095                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2096                         ModifierData *md;
2097
2098                         for (md = ob->modifiers.first; md; md = md->next) {
2099                                 if (md->type == eModifierType_Armature) {
2100                                         ArmatureModifierData *amd = (ArmatureModifierData *)md;
2101                                         if (amd->object && amd->deformflag == 0) {
2102                                                 Object *oba = blo_do_versions_newlibadr(fd, lib, amd->object);
2103                                                 arm = blo_do_versions_newlibadr(fd, lib, oba->data);
2104                                                 amd->deformflag = arm->deformflag;
2105                                         }
2106                                 }
2107                         }
2108                 }
2109
2110                 /* updating stepsize for ghost drawing */
2111                 for (arm = bmain->armature.first; arm; arm = arm->id.next) {
2112                         if (arm->ghostsize == 0)
2113                                 arm->ghostsize = 1;
2114                         bone_version_239(&arm->bonebase);
2115                         if (arm->layer == 0)
2116                                 arm->layer = 1;
2117                 }
2118
2119                 for (; sce; sce = sce->id.next) {
2120                         if (sce->r.scemode & R_PASSEPARTOUT) {
2121                                 set_passepartout = 1;
2122                                 sce->r.scemode &= ~R_PASSEPARTOUT;
2123                         }
2124                         /* gauss is filter variable now */
2125                         if (sce->r.mode & R_GAUSS) {
2126                                 sce->r.filtertype = R_FILTER_GAUSS;
2127                                 sce->r.mode &= ~R_GAUSS;
2128                         }
2129                 }
2130
2131                 for (; cam; cam = cam->id.next) {
2132                         if (set_passepartout)
2133                                 cam->flag |= CAM_SHOWPASSEPARTOUT;
2134
2135                         /* make sure old cameras have title safe on */
2136                         if (!(cam->flag & CAM_SHOW_SAFE_MARGINS))
2137                                 cam->flag |= CAM_SHOW_SAFE_MARGINS;
2138
2139                         /* set an appropriate camera passepartout alpha */
2140                         if (!(cam->passepartalpha))
2141                                 cam->passepartalpha = 0.2f;
2142                 }
2143
2144                 for (; ma; ma = ma->id.next) {
2145                         if (ma->strand_sta == 0.0f) {
2146                                 ma->strand_sta = ma->strand_end = 1.0f;
2147                                 ma->mode |= MA_TANGENT_STR;
2148                         }
2149                         if (ma->mode & MA_TRACEBLE)
2150                                 ma->mode |= MA_SHADBUF;
2151                 }
2152         }
2153
2154         if (bmain->versionfile <= 241) {
2155                 Object *ob;
2156                 Tex *tex;
2157                 Scene *sce;
2158                 World *wo;
2159                 Lamp *la;
2160                 Material *ma;
2161                 bArmature *arm;
2162                 bNodeTree *ntree;
2163
2164                 for (wo = bmain->world.first; wo; wo = wo->id.next) {
2165                         /* Migrate to Bullet for games, except for the NaN versions */
2166                         /* People can still explicitly choose for Sumo (after 2.42 is out) */
2167                         if (bmain->versionfile > 225)
2168                                 wo->physicsEngine = WOPHY_BULLET;
2169                         if (WO_AODIST == wo->aomode)
2170                                 wo->aocolor = WO_AOPLAIN;
2171                 }
2172
2173                 /* updating layers still */
2174                 for (arm = bmain->armature.first; arm; arm = arm->id.next) {
2175                         bone_version_239(&arm->bonebase);
2176                         if (arm->layer == 0)
2177                                 arm->layer = 1;
2178                 }
2179                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
2180                         if (sce->audio.mixrate == 0)
2181                                 sce->audio.mixrate = 48000;
2182
2183                         if (sce->r.xparts < 2)
2184                                 sce->r.xparts = 4;
2185                         if (sce->r.yparts < 2)
2186                                 sce->r.yparts = 4;
2187
2188                         /* adds default layer */
2189                         if (BLI_listbase_is_empty(&sce->r.layers)) {
2190                                 BKE_scene_add_render_layer(sce, NULL);
2191                         }
2192                         else {
2193                                 SceneRenderLayer *srl;
2194                                 /* new layer flag for sky, was default for solid */
2195                                 for (srl = sce->r.layers.first; srl; srl = srl->next) {
2196                                         if (srl->layflag & SCE_LAY_SOLID)
2197                                                 srl->layflag |= SCE_LAY_SKY;
2198                                         srl->passflag &= (SCE_PASS_COMBINED | SCE_PASS_Z | SCE_PASS_NORMAL | SCE_PASS_VECTOR);
2199                                 }
2200                         }
2201
2202                         /* node version changes */
2203                         if (sce->nodetree)
2204                                 ntree_version_241(sce->nodetree);
2205
2206                         /* uv calculation options moved to toolsettings */
2207                         if (sce->toolsettings->unwrapper == 0) {
2208                                 sce->toolsettings->uvcalc_flag = UVCALC_FILLHOLES;
2209                                 sce->toolsettings->unwrapper = 1;
2210                         }
2211
2212                         if (sce->r.mode & R_PANORAMA) {
2213                                 /* all these checks to ensure saved files between released versions keep working... */
2214                                 if (sce->r.xsch < sce->r.ysch) {
2215                                         Object *obc = blo_do_versions_newlibadr(fd, lib, sce->camera);
2216                                         if (obc && obc->type == OB_CAMERA) {
2217                                                 Camera *cam = blo_do_versions_newlibadr(fd, lib, obc->data);
2218                                                 if (cam->lens >= 10.0f) {
2219                                                         sce->r.xsch *= sce->r.xparts;
2220                                                         cam->lens *= (float)sce->r.ysch / (float)sce->r.xsch;
2221                                                 }
2222                                         }
2223                                 }
2224                         }
2225                 }
2226
2227                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
2228                         ntree_version_241(ntree);
2229
2230                 for (la = bmain->lamp.first; la; la = la->id.next)
2231                         if (la->buffers == 0)
2232                                 la->buffers = 1;
2233
2234                 for (tex = bmain->tex.first; tex; tex = tex->id.next) {
2235                         if (tex->env && tex->env->viewscale == 0.0f)
2236                                 tex->env->viewscale = 1.0f;
2237                         //tex->imaflag |= TEX_GAUSS_MIP;
2238                 }
2239
2240                 /* for empty drawsize and drawtype */
2241                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2242                         if (ob->empty_drawsize == 0.0f) {
2243                                 ob->empty_drawtype = OB_ARROWS;
2244                                 ob->empty_drawsize = 1.0;
2245                         }
2246                 }
2247
2248                 for (ma = bmain->mat.first; ma; ma = ma->id.next) {
2249                         /* stucci returns intensity from now on */
2250                         int a;
2251                         for (a = 0; a < MAX_MTEX; a++) {
2252                                 if (ma->mtex[a] && ma->mtex[a]->tex) {
2253                                         tex = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
2254                                         if (tex && tex->type == TEX_STUCCI)
2255                                                 ma->mtex[a]->mapto &= ~(MAP_COL | MAP_SPEC | MAP_REF);
2256                                 }
2257                         }
2258                         /* transmissivity defaults */
2259                         if (ma->tx_falloff == 0.0f)
2260                                 ma->tx_falloff = 1.0f;
2261                 }
2262
2263                 /* during 2.41 images with this name were used for viewer node output, lets fix that */
2264                 if (bmain->versionfile == 241) {
2265                         Image *ima;
2266                         for (ima = bmain->image.first; ima; ima = ima->id.next) {
2267                                 if (STREQ(ima->name, "Compositor")) {
2268                                         strcpy(ima->id.name + 2, "Viewer Node");
2269                                         strcpy(ima->name, "Viewer Node");
2270                                 }
2271                         }
2272                 }
2273         }
2274
2275         if (bmain->versionfile <= 242) {
2276                 Scene *sce;
2277                 bScreen *sc;
2278                 Object *ob;
2279                 Curve *cu;
2280                 Material *ma;
2281                 Mesh *me;
2282                 Group *group;
2283                 Nurb *nu;
2284                 BezTriple *bezt;
2285                 BPoint *bp;
2286                 bNodeTree *ntree;
2287                 int a;
2288
2289                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2290                         ScrArea *sa;
2291                         sa = sc->areabase.first;
2292                         while (sa) {
2293                                 SpaceLink *sl;
2294
2295                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2296                                         if (sl->spacetype == SPACE_VIEW3D) {
2297                                                 View3D *v3d = (View3D *)sl;
2298                                                 if (v3d->gridsubdiv == 0)
2299                                                         v3d->gridsubdiv = 10;
2300                                         }
2301                                 }
2302                                 sa = sa->next;
2303                         }
2304                 }
2305
2306                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
2307                         if (sce->toolsettings->select_thresh == 0.0f)
2308                                 sce->toolsettings->select_thresh = 0.01f;
2309
2310                         if (sce->r.threads == 0) {
2311                                 if (sce->r.mode & R_THREADS)
2312                                         sce->r.threads = 2;
2313                                 else
2314                                         sce->r.threads = 1;
2315                         }
2316                         if (sce->nodetree)
2317                                 ntree_version_242(sce->nodetree);
2318                 }
2319
2320                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
2321                         ntree_version_242(ntree);
2322
2323                 /* add default radius values to old curve points */
2324                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
2325                         for (nu = cu->nurb.first; nu; nu = nu->next) {
2326                                 if (nu) {
2327                                         if (nu->bezt) {
2328                                                 for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
2329                                                         if (!bezt->radius)
2330                                                                 bezt->radius = 1.0;
2331                                                 }
2332                                         }
2333                                         else if (nu->bp) {
2334                                                 for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
2335                                                         if (!bp->radius)
2336                                                                 bp->radius = 1.0;
2337                                                 }
2338                                         }
2339                                 }
2340                         }
2341                 }
2342
2343                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2344                         ModifierData *md;
2345                         ListBase *list;
2346                         list = &ob->constraints;
2347
2348                         /* check for already existing MinMax (floor) constraint
2349                          * and update the sticky flagging */
2350
2351                         if (list) {
2352                                 bConstraint *curcon;
2353                                 for (curcon = list->first; curcon; curcon = curcon->next) {
2354                                         switch (curcon->type) {
2355                                                 case CONSTRAINT_TYPE_MINMAX:
2356                                                 {
2357                                                         bMinMaxConstraint *data = curcon->data;
2358                                                         if (data->sticky == 1)
2359                                                                 data->flag |= MINMAX_STICKY;
2360                                                         else
2361                                                                 data->flag &= ~MINMAX_STICKY;
2362
2363                                                         break;
2364                                                 }
2365                                                 case CONSTRAINT_TYPE_ROTLIKE:
2366                                                 {
2367                                                         bRotateLikeConstraint *data = curcon->data;
2368
2369                                                         /* version patch from buttons_object.c */
2370                                                         if (data->flag == 0)
2371                                                                 data->flag = ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z;
2372
2373                                                         break;
2374                                                 }
2375                                         }
2376                                 }
2377                         }
2378
2379                         if (ob->type == OB_ARMATURE) {
2380                                 if (ob->pose) {
2381                                         bConstraint *curcon;
2382                                         bPoseChannel *pchan;
2383                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2384                                                 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
2385                                                         switch (curcon->type) {
2386                                                                 case CONSTRAINT_TYPE_MINMAX:
2387                                                                 {
2388                                                                         bMinMaxConstraint *data = curcon->data;
2389                                                                         if (data->sticky == 1)
2390                                                                                 data->flag |= MINMAX_STICKY;
2391                                                                         else
2392                                                                                 data->flag &= ~MINMAX_STICKY;
2393                                                                         break;
2394                                                                 }
2395                                                                 case CONSTRAINT_TYPE_KINEMATIC:
2396                                                                 {
2397                                                                         bKinematicConstraint *data = curcon->data;
2398                                                                         if (!(data->flag & CONSTRAINT_IK_POS)) {
2399                                                                                 data->flag |= CONSTRAINT_IK_POS;
2400                                                                                 data->flag |= CONSTRAINT_IK_STRETCH;
2401                                                                         }
2402                                                                         break;
2403                                                                 }
2404                                                                 case CONSTRAINT_TYPE_ROTLIKE:
2405                                                                 {
2406                                                                         bRotateLikeConstraint *data = curcon->data;
2407
2408                                                                         /* version patch from buttons_object.c */
2409                                                                         if (data->flag == 0)
2410                                                                                 data->flag = ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z;
2411                                                                         break;
2412                                                                 }
2413                                                         }
2414                                                 }
2415                                         }
2416                                 }
2417                         }
2418
2419                         /* copy old object level track settings to curve modifers */
2420                         for (md = ob->modifiers.first; md; md = md->next) {
2421                                 if (md->type == eModifierType_Curve) {
2422                                         CurveModifierData *cmd = (CurveModifierData *)md;
2423
2424                                         if (cmd->defaxis == 0)
2425                                                 cmd->defaxis = ob->trackflag + 1;
2426                                 }
2427                         }
2428
2429                 }
2430
2431                 for (ma = bmain->mat.first; ma; ma = ma->id.next) {
2432                         if (ma->shad_alpha == 0.0f)
2433                                 ma->shad_alpha = 1.0f;
2434                         if (ma->nodetree)
2435                                 ntree_version_242(ma->nodetree);
2436                 }
2437
2438                 for (me = bmain->mesh.first; me; me = me->id.next)
2439                         customdata_version_242(me);
2440
2441                 for (group = bmain->group.first; group; group = group->id.next)
2442                         if (group->layer == 0)
2443                                 group->layer = (1 << 20) - 1;
2444
2445                 /* now, subversion control! */
2446                 if (bmain->subversionfile < 3) {
2447                         Image *ima;
2448                         Tex *tex;
2449
2450                         /* Image refactor initialize */
2451                         for (ima = bmain->image.first; ima; ima = ima->id.next) {
2452                                 ima->source = IMA_SRC_FILE;
2453                                 ima->type = IMA_TYPE_IMAGE;
2454
2455                                 ima->gen_x = 256; ima->gen_y = 256;
2456                                 ima->gen_type = 1;
2457
2458                                 if (STREQLEN(ima->id.name + 2, "Viewer Node", sizeof(ima->id.name) - 2)) {
2459                                         ima->source = IMA_SRC_VIEWER;
2460                                         ima->type = IMA_TYPE_COMPOSITE;
2461                                 }
2462                                 if (STREQLEN(ima->id.name + 2, "Render Result", sizeof(ima->id.name) - 2)) {
2463                                         ima->source = IMA_SRC_VIEWER;
2464                                         ima->type = IMA_TYPE_R_RESULT;
2465                                 }
2466
2467                         }
2468                         for (tex = bmain->tex.first; tex; tex = tex->id.next) {
2469                                 if (tex->type == TEX_IMAGE && tex->ima) {
2470                                         ima = blo_do_versions_newlibadr(fd, lib, tex->ima);
2471                                         if (tex->imaflag & TEX_ANIM5_)
2472                                                 ima->source = IMA_SRC_MOVIE;
2473                                         if (tex->imaflag & TEX_FIELDS_)
2474                                                 ima->flag |= IMA_FIELDS;
2475                                         if (tex->imaflag & TEX_STD_FIELD_)
2476                                                 ima->flag |= IMA_STD_FIELD;
2477                                 }
2478                                 tex->iuser.frames = tex->frames;
2479                                 tex->iuser.fie_ima = (char)tex->fie_ima;
2480                                 tex->iuser.offset = tex->offset;
2481                                 tex->iuser.sfra = tex->sfra;
2482                                 tex->iuser.cycl = (tex->imaflag & TEX_ANIMCYCLIC_) != 0;
2483                         }
2484                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
2485                                 if (sce->nodetree)
2486                                         do_version_ntree_242_2(sce->nodetree);
2487                         }
2488                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
2489                                 do_version_ntree_242_2(ntree);
2490                         for (ma = bmain->mat.first; ma; ma = ma->id.next)
2491                                 if (ma->nodetree)
2492                                         do_version_ntree_242_2(ma->nodetree);
2493
2494                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2495                                 ScrArea *sa;
2496                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
2497                                         SpaceLink *sl;
2498                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
2499                                                 if (sl->spacetype == SPACE_IMAGE)
2500                                                         ((SpaceImage *)sl)->iuser.fie_ima = 2;
2501                                                 else if (sl->spacetype == SPACE_VIEW3D) {
2502                                                         View3D *v3d = (View3D *)sl;
2503                                                         BGpic *bgpic;
2504                                                         for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next)
2505                                                                 bgpic->iuser.fie_ima = 2;
2506                                                 }
2507                                         }
2508                                 }
2509                         }
2510                 }
2511
2512                 if (bmain->subversionfile < 4) {
2513                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
2514                                 sce->r.bake_mode = 1;   /* prevent to include render stuff here */
2515                                 sce->r.bake_filter = 16;
2516                                 sce->r.bake_osa = 5;
2517                                 sce->r.bake_flag = R_BAKE_CLEAR;
2518                         }
2519                 }
2520         }
2521
2522         if (bmain->versionfile <= 243) {
2523                 Object *ob = bmain->object.first;
2524                 Material *ma;
2525
2526                 for (ma = bmain->mat.first; ma; ma = ma->id.next) {
2527                         if (ma->sss_scale == 0.0f) {
2528                                 ma->sss_radius[0] = 1.0f;
2529                                 ma->sss_radius[1] = 1.0f;
2530                                 ma->sss_radius[2] = 1.0f;
2531                                 ma->sss_col[0] = 0.8f;
2532                                 ma->sss_col[1] = 0.8f;
2533                                 ma->sss_col[2] = 0.8f;
2534                                 ma->sss_error = 0.05f;
2535                                 ma->sss_scale = 0.1f;
2536                                 ma->sss_ior = 1.3f;
2537                                 ma->sss_colfac = 1.0f;
2538                                 ma->sss_texfac = 0.0f;
2539                         }
2540                         if (ma->sss_front == 0 && ma->sss_back == 0) {
2541                                 ma->sss_front = 1.0f;
2542                                 ma->sss_back = 1.0f;
2543                         }
2544                         if (ma->sss_col[0] == 0 && ma->sss_col[1] == 0 && ma->sss_col[2] == 0) {
2545                                 ma->sss_col[0] = ma->r;
2546                                 ma->sss_col[1] = ma->g;
2547                                 ma->sss_col[2] = ma->b;
2548                         }
2549                 }
2550
2551                 for (; ob; ob = ob->id.next) {
2552                         bDeformGroup *curdef;
2553
2554                         for (curdef = ob->defbase.first; curdef; curdef = curdef->next) {
2555                                 /* replace an empty-string name with unique name */
2556                                 if (curdef->name[0] == '\0') {
2557                                         defgroup_unique_name(curdef, ob);
2558                                 }
2559                         }
2560
2561                         if (bmain->versionfile < 243 || bmain->subversionfile < 1) {
2562                                 ModifierData *md;
2563
2564                                 /* translate old mirror modifier axis values to new flags */
2565                                 for (md = ob->modifiers.first; md; md = md->next) {
2566                                         if (md->type == eModifierType_Mirror) {
2567                                                 MirrorModifierData *mmd = (MirrorModifierData *)md;
2568
2569                                                 switch (mmd->axis) {
2570                                                         case 0:
2571                                                                 mmd->flag |= MOD_MIR_AXIS_X;
2572                                                                 break;
2573                                                         case 1:
2574                                                                 mmd->flag |= MOD_MIR_AXIS_Y;
2575                                                                 break;
2576                                                         case 2:
2577                                                                 mmd->flag |= MOD_MIR_AXIS_Z;
2578                                                                 break;
2579                                                 }
2580
2581                                                 mmd->axis = 0;
2582                                         }
2583                                 }
2584                         }
2585                 }
2586
2587                 /* render layer added, this is not the active layer */
2588                 if (bmain->versionfile <= 243 || bmain->subversionfile < 2) {
2589                         Mesh *me;
2590                         for (me = bmain->mesh.first; me; me = me->id.next)
2591                                 customdata_version_243(me);
2592                 }
2593
2594         }
2595
2596         if (bmain->versionfile <= 244) {
2597                 Scene *sce;
2598                 bScreen *sc;
2599                 Lamp *la;
2600                 World *wrld;
2601
2602                 if (bmain->versionfile != 244 || bmain->subversionfile < 2) {
2603                         for (sce = bmain->scene.first; sce; sce = sce->id.next)
2604                                 sce->r.mode |= R_SSS;
2605
2606                         /* correct older action editors - incorrect scrolling */
2607                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2608                                 ScrArea *sa;
2609                                 sa = sc->areabase.first;
2610                                 while (sa) {
2611                                         SpaceLink *sl;
2612
2613                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
2614                                                 if (sl->spacetype == SPACE_ACTION) {
2615                                                         SpaceAction *saction = (SpaceAction *)sl;
2616
2617                                                         saction->v2d.tot.ymin = -1000.0;
2618                                                         saction->v2d.tot.ymax = 0.0;
2619
2620                                                         saction->v2d.cur.ymin = -75.0;
2621                                                         saction->v2d.cur.ymax = 5.0;
2622                                                 }
2623                                         }
2624                                         sa = sa->next;
2625                                 }
2626                         }
2627                 }
2628
2629                 if (bmain->versionfile != 244 || bmain->subversionfile < 3) {
2630                         /* constraints recode version patch used to be here. Moved to 245 now... */
2631
2632                         for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) {
2633                                 if (wrld->mode & WO_AMB_OCC)