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