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