code cleanup: favor braces when blocks have mixed brace use.
[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 {
1551                                                         sbuts->mainb = CONTEXT_SCENE;
1552                                                 }
1553                                         }
1554                                 }
1555                         }
1556                 }
1557         }
1558
1559         /* ton: made this 230 instead of 229,
1560          * to be sure (tuho files) and this is a reliable check anyway
1561          * nevertheless, we might need to think over a fitness (initialize)
1562          * check apart from the do_versions()
1563          */
1564
1565         if (main->versionfile <= 230) {
1566                 bScreen *sc;
1567
1568                 /* new variable blockscale, for panels in any area */
1569                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1570                         ScrArea *sa;
1571
1572                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1573                                 SpaceLink *sl;
1574
1575                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1576                                         if (sl->blockscale == 0.0f)
1577                                                 sl->blockscale = 0.7f;
1578                                         /* added: 5x better zoom in for action */
1579                                         if (sl->spacetype == SPACE_ACTION) {
1580                                                 SpaceAction *sac = (SpaceAction *)sl;
1581                                                 sac->v2d.maxzoom = 50;
1582                                         }
1583                                 }
1584                         }
1585                 }
1586         }
1587
1588         if (main->versionfile <= 231) {
1589                 /* new bit flags for showing/hiding grid floor and axes */
1590                 bScreen *sc = main->screen.first;
1591
1592                 while (sc) {
1593                         ScrArea *sa = sc->areabase.first;
1594                         while (sa) {
1595                                 SpaceLink *sl = sa->spacedata.first;
1596                                 while (sl) {
1597                                         if (sl->spacetype == SPACE_VIEW3D) {
1598                                                 View3D *v3d = (View3D*) sl;
1599
1600                                                 if (v3d->gridflag == 0) {
1601                                                         v3d->gridflag |= V3D_SHOW_X;
1602                                                         v3d->gridflag |= V3D_SHOW_Y;
1603                                                         v3d->gridflag |= V3D_SHOW_FLOOR;
1604                                                         v3d->gridflag &= ~V3D_SHOW_Z;
1605                                                 }
1606                                         }
1607                                         sl = sl->next;
1608                                 }
1609                                 sa = sa->next;
1610                         }
1611                         sc = sc->id.next;
1612                 }
1613         }
1614
1615         if (main->versionfile <= 231) {
1616                 Material *ma = main->mat.first;
1617                 bScreen *sc = main->screen.first;
1618                 Scene *sce;
1619                 Lamp *la;
1620                 World *wrld;
1621
1622                 /* introduction of raytrace */
1623                 while (ma) {
1624                         if (ma->fresnel_tra_i == 0.0f)
1625                                 ma->fresnel_tra_i = 1.25f;
1626                         if (ma->fresnel_mir_i == 0.0f)
1627                                 ma->fresnel_mir_i = 1.25f;
1628
1629                         ma->ang = 1.0;
1630                         ma->ray_depth = 2;
1631                         ma->ray_depth_tra = 2;
1632                         ma->fresnel_tra = 0.0;
1633                         ma->fresnel_mir = 0.0;
1634
1635                         ma = ma->id.next;
1636                 }
1637                 sce = main->scene.first;
1638                 while (sce) {
1639                         if (sce->r.gauss == 0.0f)
1640                                 sce->r.gauss = 1.0f;
1641                         sce = sce->id.next;
1642                 }
1643                 la = main->lamp.first;
1644                 while (la) {
1645                         if (la->k == 0.0f) la->k = 1.0;
1646                         if (la->ray_samp == 0)
1647                                 la->ray_samp = 1;
1648                         if (la->ray_sampy == 0)
1649                                 la->ray_sampy = 1;
1650                         if (la->ray_sampz == 0)
1651                                 la->ray_sampz = 1;
1652                         if (la->area_size == 0.0f)
1653                                 la->area_size = 1.0f;
1654                         if (la->area_sizey == 0.0f)
1655                                 la->area_sizey = 1.0f;
1656                         if (la->area_sizez == 0.0f)
1657                                 la->area_sizez = 1.0f;
1658                         la = la->id.next;
1659                 }
1660                 wrld = main->world.first;
1661                 while (wrld) {
1662                         if (wrld->range == 0.0f) {
1663                                 wrld->range = 1.0f / wrld->exposure;
1664                         }
1665                         wrld = wrld->id.next;
1666                 }
1667
1668                 /* new bit flags for showing/hiding grid floor and axes */
1669
1670                 while (sc) {
1671                         ScrArea *sa = sc->areabase.first;
1672                         while (sa) {
1673                                 SpaceLink *sl = sa->spacedata.first;
1674                                 while (sl) {
1675                                         if (sl->spacetype == SPACE_VIEW3D) {
1676                                                 View3D *v3d = (View3D*) sl;
1677
1678                                                 if (v3d->gridflag == 0) {
1679                                                         v3d->gridflag |= V3D_SHOW_X;
1680                                                         v3d->gridflag |= V3D_SHOW_Y;
1681                                                         v3d->gridflag |= V3D_SHOW_FLOOR;
1682                                                         v3d->gridflag &= ~V3D_SHOW_Z;
1683                                                 }
1684                                         }
1685                                         sl = sl->next;
1686                                 }
1687                                 sa = sa->next;
1688                         }
1689                         sc = sc->id.next;
1690                 }
1691         }
1692
1693         if (main->versionfile <= 232) {
1694                 Tex *tex = main->tex.first;
1695                 World *wrld = main->world.first;
1696                 bScreen *sc;
1697                 Scene *sce;
1698
1699                 while (tex) {
1700                         if ((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
1701                                 tex->flag |= TEX_CHECKER_ODD;
1702                         }
1703                         /* copied from kernel texture.c */
1704                         if (tex->ns_outscale == 0.0f) {
1705                                 /* musgrave */
1706                                 tex->mg_H = 1.0f;
1707                                 tex->mg_lacunarity = 2.0f;
1708                                 tex->mg_octaves = 2.0f;
1709                                 tex->mg_offset = 1.0f;
1710                                 tex->mg_gain = 1.0f;
1711                                 tex->ns_outscale = 1.0f;
1712                                 /* distnoise */
1713                                 tex->dist_amount = 1.0f;
1714                                 /* voronoi */
1715                                 tex->vn_w1 = 1.0f;
1716                                 tex->vn_mexp = 2.5f;
1717                         }
1718                         tex = tex->id.next;
1719                 }
1720
1721                 while (wrld) {
1722                         if (wrld->aodist == 0.0f) {
1723                                 wrld->aodist = 10.0f;
1724                                 wrld->aobias = 0.05f;
1725                         }
1726                         if (wrld->aosamp == 0)
1727                                 wrld->aosamp = 5;
1728                         if (wrld->aoenergy == 0.0f)
1729                                 wrld->aoenergy = 1.0f;
1730                         wrld = wrld->id.next;
1731                 }
1732
1733                 /* new variable blockscale, for panels in any area, do again because new
1734                  * areas didnt initialize it to 0.7 yet
1735                  */
1736                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1737                         ScrArea *sa;
1738                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1739                                 SpaceLink *sl;
1740                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1741                                         if (sl->blockscale == 0.0f)
1742                                                 sl->blockscale = 0.7f;
1743
1744                                         /* added: 5x better zoom in for nla */
1745                                         if (sl->spacetype == SPACE_NLA) {
1746                                                 SpaceNla *snla = (SpaceNla *) sl;
1747                                                 snla->v2d.maxzoom = 50;
1748                                         }
1749                                 }
1750                         }
1751                 }
1752                 sce = main->scene.first;
1753                 while (sce) {
1754                         if (sce->r.ocres == 0)
1755                                 sce->r.ocres = 64;
1756                         sce = sce->id.next;
1757                 }
1758
1759         }
1760
1761         if (main->versionfile <= 233) {
1762                 bScreen *sc;
1763                 Material *ma = main->mat.first;
1764                 /* Object *ob = main->object.first; */
1765
1766                 while (ma) {
1767                         if (ma->rampfac_col == 0.0f)
1768                                 ma->rampfac_col = 1.0;
1769                         if (ma->rampfac_spec == 0.0f)
1770                                 ma->rampfac_spec = 1.0;
1771                         if (ma->pr_lamp == 0)
1772                                 ma->pr_lamp = 3;
1773                         ma = ma->id.next;
1774                 }
1775
1776                 /* this should have been done loooong before! */
1777 #if 0   /* deprecated in 2.5+ */
1778                 while (ob) {
1779                         if (ob->ipowin == 0)
1780                                 ob->ipowin = ID_OB;
1781                         ob = ob->id.next;
1782                 }
1783 #endif
1784                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1785                         ScrArea *sa;
1786                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1787                                 SpaceLink *sl;
1788                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1789                                         if (sl->spacetype == SPACE_VIEW3D) {
1790                                                 View3D *v3d = (View3D *) sl;
1791                                                 v3d->flag |= V3D_SELECT_OUTLINE;
1792                                         }
1793                                 }
1794                         }
1795                 }
1796         }
1797
1798         if (main->versionfile <= 234) {
1799                 World *wo;
1800                 bScreen *sc;
1801
1802                 /* force sumo engine to be active */
1803                 for (wo = main->world.first; wo; wo = wo->id.next) {
1804                         if (wo->physicsEngine == 0)
1805                                 wo->physicsEngine = 2;
1806                 }
1807
1808                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1809                         ScrArea *sa;
1810                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1811                                 SpaceLink *sl;
1812                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1813                                         if (sl->spacetype == SPACE_VIEW3D) {
1814                                                 View3D *v3d = (View3D *) sl;
1815                                                 v3d->flag |= V3D_ZBUF_SELECT;
1816                                         }
1817                                         else if (sl->spacetype == SPACE_TEXT) {
1818                                                 SpaceText *st = (SpaceText *)sl;
1819                                                 if (st->tabnumber == 0)
1820                                                         st->tabnumber = 2;
1821                                         }
1822                                 }
1823                         }
1824                 }
1825         }
1826
1827         if (main->versionfile <= 235) {
1828                 Tex *tex = main->tex.first;
1829                 Scene *sce = main->scene.first;
1830                 Sequence *seq;
1831                 Editing *ed;
1832
1833                 while (tex) {
1834                         if (tex->nabla == 0.0f)
1835                                 tex->nabla = 0.025f;
1836                         tex = tex->id.next;
1837                 }
1838                 while (sce) {
1839                         ed = sce->ed;
1840                         if (ed) {
1841                                 SEQ_BEGIN (sce->ed, seq)
1842                                 {
1843                                         if (seq->type == SEQ_TYPE_IMAGE || seq->type == SEQ_TYPE_MOVIE)
1844                                                 seq->alpha_mode = SEQ_ALPHA_STRAIGHT;
1845                                 }
1846                                 SEQ_END
1847                         }
1848
1849                         sce = sce->id.next;
1850                 }
1851         }
1852
1853         if (main->versionfile <= 236) {
1854                 Object *ob;
1855                 Camera *cam = main->camera.first;
1856                 Material *ma;
1857                 bScreen *sc;
1858
1859                 while (cam) {
1860                         if (cam->ortho_scale == 0.0f) {
1861                                 cam->ortho_scale = 256.0f / cam->lens;
1862                                 if (cam->type == CAM_ORTHO)
1863                                         printf("NOTE: ortho render has changed, tweak new Camera 'scale' value.\n");
1864                         }
1865                         cam = cam->id.next;
1866                 }
1867                 /* set manipulator type */
1868                 /* force oops draw if depgraph was set*/
1869                 /* set time line var */
1870                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1871                         ScrArea *sa;
1872                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1873                                 SpaceLink *sl;
1874                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1875                                         if (sl->spacetype == SPACE_VIEW3D) {
1876                                                 View3D *v3d = (View3D *) sl;
1877                                                 if (v3d->twtype == 0)
1878                                                         v3d->twtype = V3D_MANIP_TRANSLATE;
1879                                         }
1880                                 }
1881                         }
1882                 }
1883                 /* init new shader vars */
1884                 for (ma = main->mat.first; ma; ma = ma->id.next) {
1885                         if (ma->darkness == 0.0f) {
1886                                 ma->rms = 0.1f;
1887                                 ma->darkness = 1.0f;
1888                         }
1889                 }
1890
1891                 /* softbody init new vars */
1892                 for (ob = main->object.first; ob; ob = ob->id.next) {
1893                         if (ob->soft) {
1894                                 if (ob->soft->defgoal == 0.0f)
1895                                         ob->soft->defgoal = 0.7f;
1896                                 if (ob->soft->physics_speed == 0.0f)
1897                                         ob->soft->physics_speed = 1.0f;
1898
1899                                 if (ob->soft->interval == 0) {
1900                                         ob->soft->interval = 2;
1901                                         ob->soft->sfra = 1;
1902                                         ob->soft->efra = 100;
1903                                 }
1904                         }
1905                         if (ob->soft && ob->soft->vertgroup == 0) {
1906                                 bDeformGroup *locGroup = defgroup_find_name(ob, "SOFTGOAL");
1907                                 if (locGroup) {
1908                                         /* retrieve index for that group */
1909                                         ob->soft->vertgroup =  1 + BLI_findindex(&ob->defbase, locGroup);
1910                                 }
1911                         }
1912                 }
1913         }
1914
1915         if (main->versionfile <= 237) {
1916                 bArmature *arm;
1917                 bConstraint *con;
1918                 Object *ob;
1919                 Bone *bone;
1920
1921                 /* armature recode checks */
1922                 for (arm = main->armature.first; arm; arm = arm->id.next) {
1923                         BKE_armature_where_is(arm);
1924
1925                         for (bone = arm->bonebase.first; bone; bone = bone->next)
1926                                 do_version_bone_head_tail_237(bone);
1927                 }
1928                 for (ob = main->object.first; ob; ob = ob->id.next) {
1929                         if (ob->parent) {
1930                                 Object *parent = blo_do_versions_newlibadr(fd, lib, ob->parent);
1931                                 if (parent && parent->type == OB_LATTICE)
1932                                         ob->partype = PARSKEL;
1933                         }
1934
1935                         /* btw. armature_rebuild_pose is further only called on leave editmode */
1936                         if (ob->type == OB_ARMATURE) {
1937                                 if (ob->pose)
1938                                         ob->pose->flag |= POSE_RECALC;
1939
1940                                 /* cannot call stuff now (pointers!), done in setup_app_data */
1941                                 ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
1942
1943                                 /* new generic xray option */
1944                                 arm = blo_do_versions_newlibadr(fd, lib, ob->data);
1945                                 if (arm->flag & ARM_DRAWXRAY) {
1946                                         ob->dtx |= OB_DRAWXRAY;
1947                                 }
1948                         }
1949                         else if (ob->type == OB_MESH) {
1950                                 Mesh *me = blo_do_versions_newlibadr(fd, lib, ob->data);
1951
1952                                 if ((me->flag&ME_SUBSURF)) {
1953                                         SubsurfModifierData *smd = (SubsurfModifierData*) modifier_new(eModifierType_Subsurf);
1954
1955                                         smd->levels = MAX2(1, me->subdiv);
1956                                         smd->renderLevels = MAX2(1, me->subdivr);
1957                                         smd->subdivType = me->subsurftype;
1958
1959                                         smd->modifier.mode = 0;
1960                                         if (me->subdiv != 0)
1961                                                 smd->modifier.mode |= 1;
1962                                         if (me->subdivr != 0)
1963                                                 smd->modifier.mode |= 2;
1964                                         if (me->flag & ME_OPT_EDGES)
1965                                                 smd->flags |= eSubsurfModifierFlag_ControlEdges;
1966
1967                                         BLI_addtail(&ob->modifiers, smd);
1968
1969                                         modifier_unique_name(&ob->modifiers, (ModifierData*)smd);
1970                                 }
1971                         }
1972
1973                         /* follow path constraint needs to set the 'path' option in curves... */
1974                         for (con = ob->constraints.first; con; con = con->next) {
1975                                 if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
1976                                         bFollowPathConstraint *data = con->data;
1977                                         Object *obc = blo_do_versions_newlibadr(fd, lib, data->tar);
1978
1979                                         if (obc && obc->type == OB_CURVE) {
1980                                                 Curve *cu = blo_do_versions_newlibadr(fd, lib, obc->data);
1981                                                 if (cu)
1982                                                         cu->flag |= CU_PATH;
1983                                         }
1984                                 }
1985                         }
1986                 }
1987         }
1988
1989         if (main->versionfile <= 238) {
1990                 Lattice *lt;
1991                 Object *ob;
1992                 bArmature *arm;
1993                 Mesh *me;
1994                 Key *key;
1995                 Scene *sce = main->scene.first;
1996
1997                 while (sce) {
1998                         if (sce->toolsettings == NULL) {
1999                                 sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
2000                                 sce->toolsettings->cornertype =0;
2001                                 sce->toolsettings->degr = 90;
2002                                 sce->toolsettings->step = 9;
2003                                 sce->toolsettings->turn = 1;
2004                                 sce->toolsettings->extr_offs = 1;
2005                                 sce->toolsettings->doublimit = 0.001f;
2006                                 sce->toolsettings->segments = 32;
2007                                 sce->toolsettings->rings = 32;
2008                                 sce->toolsettings->vertices = 32;
2009                         }
2010                         sce = sce->id.next;
2011                 }
2012
2013                 for (lt = main->latt.first; lt; lt = lt->id.next) {
2014                         if (lt->fu == 0.0f && lt->fv == 0.0f && lt->fw == 0.0f) {
2015                                 calc_lat_fudu(lt->flag, lt->pntsu, &lt->fu, &lt->du);
2016                                 calc_lat_fudu(lt->flag, lt->pntsv, &lt->fv, &lt->dv);
2017                                 calc_lat_fudu(lt->flag, lt->pntsw, &lt->fw, &lt->dw);
2018                         }
2019                 }
2020
2021                 for (ob = main->object.first; ob; ob = ob->id.next) {
2022                         ModifierData *md;
2023                         PartEff *paf;
2024
2025                         for (md = ob->modifiers.first; md; md = md->next) {
2026                                 if (md->type == eModifierType_Subsurf) {
2027                                         SubsurfModifierData *smd = (SubsurfModifierData*) md;
2028
2029                                         smd->flags &= ~(eSubsurfModifierFlag_Incremental|eSubsurfModifierFlag_DebugIncr);
2030                                 }
2031                         }
2032
2033                         if ((ob->softflag & OB_SB_ENABLE) && !modifiers_findByType(ob, eModifierType_Softbody)) {
2034                                 if (ob->softflag & OB_SB_POSTDEF) {
2035                                         md = ob->modifiers.first;
2036
2037                                         while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) {
2038                                                 md = md->next;
2039                                         }
2040
2041                                         BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(eModifierType_Softbody));
2042                                 }
2043                                 else {
2044                                         BLI_addhead(&ob->modifiers, modifier_new(eModifierType_Softbody));
2045                                 }
2046
2047                                 ob->softflag &= ~OB_SB_ENABLE;
2048                         }
2049
2050                         if (ob->pose) {
2051                                 bPoseChannel *pchan;
2052                                 bConstraint *con;
2053                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2054                                         /* note, pchan->bone is also lib-link stuff */
2055                                         if (pchan->limitmin[0] == 0.0f && pchan->limitmax[0] == 0.0f) {
2056                                                 pchan->limitmin[0] = pchan->limitmin[1] = pchan->limitmin[2] = -180.0f;
2057                                                 pchan->limitmax[0] = pchan->limitmax[1] = pchan->limitmax[2] = 180.0f;
2058
2059                                                 for (con = pchan->constraints.first; con; con = con->next) {
2060                                                         if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2061                                                                 bKinematicConstraint *data = (bKinematicConstraint*)con->data;
2062                                                                 data->weight = 1.0f;
2063                                                                 data->orientweight = 1.0f;
2064                                                                 data->flag &= ~CONSTRAINT_IK_ROT;
2065
2066                                                                 /* enforce conversion from old IK_TOPARENT to rootbone index */
2067                                                                 data->rootbone = -1;
2068
2069                                                                 /* update_pose_etc handles rootbone == -1 */
2070                                                                 ob->pose->flag |= POSE_RECALC;
2071                                                         }
2072                                                 }
2073                                         }
2074                                 }
2075                         }
2076
2077                         paf = blo_do_version_give_parteff_245(ob);
2078                         if (paf) {
2079                                 if (paf->disp == 0)
2080                                         paf->disp = 100;
2081                                 if (paf->speedtex == 0)
2082                                         paf->speedtex = 8;
2083                                 if (paf->omat == 0)
2084                                         paf->omat = 1;
2085                         }
2086                 }
2087
2088                 for (arm = main->armature.first; arm; arm = arm->id.next) {
2089                         bone_version_238(&arm->bonebase);
2090                         arm->deformflag |= ARM_DEF_VGROUP;
2091                 }
2092
2093                 for (me = main->mesh.first; me; me = me->id.next) {
2094                         if (!me->medge) {
2095                                 BKE_mesh_make_edges(me, 1);     /* 1 = use mface->edcode */
2096                         }
2097                         else {
2098                                 BKE_mesh_strip_loose_faces(me);
2099                         }
2100                 }
2101
2102                 for (key = main->key.first; key; key = key->id.next) {
2103                         KeyBlock *kb;
2104                         int index = 1;
2105
2106                         for (kb = key->block.first; kb; kb = kb->next) {
2107                                 if (kb == key->refkey) {
2108                                         if (kb->name[0] == 0)
2109                                                 strcpy(kb->name, "Basis");
2110                                 }
2111                                 else {
2112                                         if (kb->name[0] == 0) {
2113                                                 BLI_snprintf(kb->name, sizeof(kb->name), "Key %d", index);
2114                                         }
2115                                         index++;
2116                                 }
2117                         }
2118                 }
2119         }
2120
2121         if (main->versionfile <= 239) {
2122                 bArmature *arm;
2123                 Object *ob;
2124                 Scene *sce = main->scene.first;
2125                 Camera *cam = main->camera.first;
2126                 Material *ma = main->mat.first;
2127                 int set_passepartout = 0;
2128
2129                 /* deformflag is local in modifier now */
2130                 for (ob = main->object.first; ob; ob = ob->id.next) {
2131                         ModifierData *md;
2132
2133                         for (md = ob->modifiers.first; md; md = md->next) {
2134                                 if (md->type == eModifierType_Armature) {
2135                                         ArmatureModifierData *amd = (ArmatureModifierData*) md;
2136                                         if (amd->object && amd->deformflag == 0) {
2137                                                 Object *oba = blo_do_versions_newlibadr(fd, lib, amd->object);
2138                                                 arm = blo_do_versions_newlibadr(fd, lib, oba->data);
2139                                                 amd->deformflag = arm->deformflag;
2140                                         }
2141                                 }
2142                         }
2143                 }
2144
2145                 /* updating stepsize for ghost drawing */
2146                 for (arm = main->armature.first; arm; arm = arm->id.next) {
2147                         if (arm->ghostsize == 0)
2148                                 arm->ghostsize = 1;
2149                         bone_version_239(&arm->bonebase);
2150                         if (arm->layer == 0)
2151                                 arm->layer = 1;
2152                 }
2153
2154                 for (; sce; sce = sce->id.next) {
2155                         /* make 'innervert' the default subdivide type, for backwards compat */
2156                         sce->toolsettings->cornertype = 1;
2157
2158                         if (sce->r.scemode & R_PASSEPARTOUT) {
2159                                 set_passepartout = 1;
2160                                 sce->r.scemode &= ~R_PASSEPARTOUT;
2161                         }
2162                         /* gauss is filter variable now */
2163                         if (sce->r.mode & R_GAUSS) {
2164                                 sce->r.filtertype = R_FILTER_GAUSS;
2165                                 sce->r.mode &= ~R_GAUSS;
2166                         }
2167                 }
2168
2169                 for (; cam; cam = cam->id.next) {
2170                         if (set_passepartout)
2171                                 cam->flag |= CAM_SHOWPASSEPARTOUT;
2172
2173                         /* make sure old cameras have title safe on */
2174                         if (!(cam->flag & CAM_SHOWTITLESAFE))
2175                                 cam->flag |= CAM_SHOWTITLESAFE;
2176
2177                         /* set an appropriate camera passepartout alpha */
2178                         if (!(cam->passepartalpha))
2179                                 cam->passepartalpha = 0.2f;
2180                 }
2181
2182                 for (; ma; ma = ma->id.next) {
2183                         if (ma->strand_sta == 0.0f) {
2184                                 ma->strand_sta = ma->strand_end = 1.0f;
2185                                 ma->mode |= MA_TANGENT_STR;
2186                         }
2187                         if (ma->mode & MA_TRACEBLE)
2188                                 ma->mode |= MA_SHADBUF;
2189                 }
2190         }
2191
2192         if (main->versionfile <= 241) {
2193                 Object *ob;
2194                 Tex *tex;
2195                 Scene *sce;
2196                 World *wo;
2197                 Lamp *la;
2198                 Material *ma;
2199                 bArmature *arm;
2200                 bNodeTree *ntree;
2201
2202                 for (wo = main->world.first; wo; wo = wo->id.next) {
2203                         /* Migrate to Bullet for games, except for the NaN versions */
2204                         /* People can still explicitly choose for Sumo (after 2.42 is out) */
2205                         if (main->versionfile > 225)
2206                                 wo->physicsEngine = WOPHY_BULLET;
2207                         if (WO_AODIST == wo->aomode)
2208                                 wo->aocolor = WO_AOPLAIN;
2209                 }
2210
2211                 /* updating layers still */
2212                 for (arm = main->armature.first; arm; arm = arm->id.next) {
2213                         bone_version_239(&arm->bonebase);
2214                         if (arm->layer == 0)
2215                                 arm->layer = 1;
2216                 }
2217                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2218                         if (sce->audio.mixrate == 0)
2219                                 sce->audio.mixrate = 44100;
2220
2221                         if (sce->r.xparts <2 )
2222                                 sce->r.xparts = 4;
2223                         if (sce->r.yparts < 2)
2224                                 sce->r.yparts = 4;
2225
2226                         /* adds default layer */
2227                         if (sce->r.layers.first == NULL)
2228                                 BKE_scene_add_render_layer(sce, NULL);
2229                         else {
2230                                 SceneRenderLayer *srl;
2231                                 /* new layer flag for sky, was default for solid */
2232                                 for (srl = sce->r.layers.first; srl; srl = srl->next) {
2233                                         if (srl->layflag & SCE_LAY_SOLID)
2234                                                 srl->layflag |= SCE_LAY_SKY;
2235                                         srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR);
2236                                 }
2237                         }
2238
2239                         /* node version changes */
2240                         if (sce->nodetree)
2241                                 ntree_version_241(sce->nodetree);
2242
2243                         /* uv calculation options moved to toolsettings */
2244                         if (sce->toolsettings->uvcalc_radius == 0.0f) {
2245                                 sce->toolsettings->uvcalc_radius = 1.0f;
2246                                 sce->toolsettings->uvcalc_cubesize = 1.0f;
2247                                 sce->toolsettings->uvcalc_mapdir = 1;
2248                                 sce->toolsettings->uvcalc_mapalign = 1;
2249                                 sce->toolsettings->uvcalc_flag = UVCALC_FILLHOLES;
2250                                 sce->toolsettings->unwrapper = 1;
2251                         }
2252
2253                         if (sce->r.mode & R_PANORAMA) {
2254                                 /* all these checks to ensure saved files with svn version keep working... */
2255                                 if (sce->r.xsch < sce->r.ysch) {
2256                                         Object *obc = blo_do_versions_newlibadr(fd, lib, sce->camera);
2257                                         if (obc && obc->type == OB_CAMERA) {
2258                                                 Camera *cam = blo_do_versions_newlibadr(fd, lib, obc->data);
2259                                                 if (cam->lens >= 10.0f) {
2260                                                         sce->r.xsch *= sce->r.xparts;
2261                                                         cam->lens *= (float)sce->r.ysch / (float)sce->r.xsch;
2262                                                 }
2263                                         }
2264                                 }
2265                         }
2266                 }
2267
2268                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
2269                         ntree_version_241(ntree);
2270
2271                 for (la = main->lamp.first; la; la = la->id.next)
2272                         if (la->buffers == 0)
2273                                 la->buffers = 1;
2274
2275                 for (tex = main->tex.first; tex; tex = tex->id.next) {
2276                         if (tex->env && tex->env->viewscale == 0.0f)
2277                                 tex->env->viewscale = 1.0f;
2278                         //tex->imaflag |= TEX_GAUSS_MIP;
2279                 }
2280
2281                 /* for empty drawsize and drawtype */
2282                 for (ob = main->object.first; ob; ob = ob->id.next) {
2283                         if (ob->empty_drawsize == 0.0f) {
2284                                 ob->empty_drawtype = OB_ARROWS;
2285                                 ob->empty_drawsize = 1.0;
2286                         }
2287                 }
2288
2289                 for (ma = main->mat.first; ma; ma = ma->id.next) {
2290                         /* stucci returns intensity from now on */
2291                         int a;
2292                         for (a = 0; a < MAX_MTEX; a++) {
2293                                 if (ma->mtex[a] && ma->mtex[a]->tex) {
2294                                         tex = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
2295                                         if (tex && tex->type == TEX_STUCCI)
2296                                                 ma->mtex[a]->mapto &= ~(MAP_COL|MAP_SPEC|MAP_REF);
2297                                 }
2298                         }
2299                         /* transmissivity defaults */
2300                         if (ma->tx_falloff == 0.0f)
2301                                 ma->tx_falloff = 1.0f;
2302                 }
2303
2304                 /* during 2.41 images with this name were used for viewer node output, lets fix that */
2305                 if (main->versionfile == 241) {
2306                         Image *ima;
2307                         for (ima = main->image.first; ima; ima = ima->id.next)
2308                                 if (strcmp(ima->name, "Compositor") == 0) {
2309                                         strcpy(ima->id.name+2, "Viewer Node");
2310                                         strcpy(ima->name, "Viewer Node");
2311                                 }
2312                 }
2313         }
2314
2315         if (main->versionfile <= 242) {
2316                 Scene *sce;
2317                 bScreen *sc;
2318                 Object *ob;
2319                 Curve *cu;
2320                 Material *ma;
2321                 Mesh *me;
2322                 Group *group;
2323                 Nurb *nu;
2324                 BezTriple *bezt;
2325                 BPoint *bp;
2326                 bNodeTree *ntree;
2327                 int a;
2328
2329                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2330                         ScrArea *sa;
2331                         sa = sc->areabase.first;
2332                         while (sa) {
2333                                 SpaceLink *sl;
2334
2335                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2336                                         if (sl->spacetype == SPACE_VIEW3D) {
2337                                                 View3D *v3d = (View3D*) sl;
2338                                                 if (v3d->gridsubdiv == 0)
2339                                                         v3d->gridsubdiv = 10;
2340                                         }
2341                                 }
2342                                 sa = sa->next;
2343                         }
2344                 }
2345
2346                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2347                         if (sce->toolsettings->select_thresh == 0.0f)
2348                                 sce->toolsettings->select_thresh = 0.01f;
2349                         if (sce->toolsettings->clean_thresh == 0.0f)
2350                                 sce->toolsettings->clean_thresh = 0.1f;
2351
2352                         if (sce->r.threads == 0) {
2353                                 if (sce->r.mode & R_THREADS)
2354                                         sce->r.threads = 2;
2355                                 else
2356                                         sce->r.threads = 1;
2357                         }
2358                         if (sce->nodetree)
2359                                 ntree_version_242(sce->nodetree);
2360                 }
2361
2362                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
2363                         ntree_version_242(ntree);
2364
2365                 /* add default radius values to old curve points */
2366                 for (cu = main->curve.first; cu; cu = cu->id.next) {
2367                         for (nu = cu->nurb.first; nu; nu = nu->next) {
2368                                 if (nu) {
2369                                         if (nu->bezt) {
2370                                                 for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
2371                                                         if (!bezt->radius)
2372                                                                 bezt->radius = 1.0;
2373                                                 }
2374                                         }
2375                                         else if (nu->bp) {
2376                                                 for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
2377                                                         if (!bp->radius)
2378                                                                 bp->radius = 1.0;
2379                                                 }
2380                                         }
2381                                 }
2382                         }
2383                 }
2384
2385                 for (ob = main->object.first; ob; ob = ob->id.next) {
2386                         ModifierData *md;
2387                         ListBase *list;
2388                         list = &ob->constraints;
2389
2390                         /* check for already existing MinMax (floor) constraint
2391                          * and update the sticky flagging */
2392
2393                         if (list) {
2394                                 bConstraint *curcon;
2395                                 for (curcon = list->first; curcon; curcon = curcon->next) {
2396                                         switch (curcon->type) {
2397                                                 case CONSTRAINT_TYPE_MINMAX:
2398                                                 {
2399                                                         bMinMaxConstraint *data = curcon->data;
2400                                                         if (data->sticky == 1)
2401                                                                 data->flag |= MINMAX_STICKY;
2402                                                         else
2403                                                                 data->flag &= ~MINMAX_STICKY;
2404                                                 }
2405                                                         break;
2406                                                 case CONSTRAINT_TYPE_ROTLIKE:
2407                                                 {
2408                                                         bRotateLikeConstraint *data = curcon->data;
2409
2410                                                         /* version patch from buttons_object.c */
2411                                                         if (data->flag == 0)
2412                                                                 data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
2413                                                 }
2414                                                         break;
2415                                         }
2416                                 }
2417                         }
2418
2419                         if (ob->type == OB_ARMATURE) {
2420                                 if (ob->pose) {
2421                                         bConstraint *curcon;
2422                                         bPoseChannel *pchan;
2423                                         for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2424                                                 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
2425                                                         switch (curcon->type) {
2426                                                                 case CONSTRAINT_TYPE_MINMAX:
2427                                                                         {
2428                                                                                 bMinMaxConstraint *data = curcon->data;
2429                                                                                 if (data->sticky == 1)
2430                                                                                         data->flag |= MINMAX_STICKY;
2431                                                                                 else
2432                                                                                         data->flag &= ~MINMAX_STICKY;
2433                                                                         }
2434                                                                         break;
2435                                                                 case CONSTRAINT_TYPE_KINEMATIC:
2436                                                                         {
2437                                                                                 bKinematicConstraint *data = curcon->data;
2438                                                                                 if (!(data->flag & CONSTRAINT_IK_POS)) {
2439                                                                                         data->flag |= CONSTRAINT_IK_POS;
2440                                                                                         data->flag |= CONSTRAINT_IK_STRETCH;
2441                                                                                 }
2442                                                                         }
2443                                                                         break;
2444                                                                 case CONSTRAINT_TYPE_ROTLIKE:
2445                                                                         {
2446                                                                                 bRotateLikeConstraint *data = curcon->data;
2447
2448                                                                                 /* version patch from buttons_object.c */
2449                                                                                 if (data->flag == 0)
2450                                                                                         data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
2451                                                                         }
2452                                                                         break;
2453                                                         }
2454                                                 }
2455                                         }
2456                                 }
2457                         }
2458
2459                         /* copy old object level track settings to curve modifers */
2460                         for (md = ob->modifiers.first; md; md = md->next) {
2461                                 if (md->type == eModifierType_Curve) {
2462                                         CurveModifierData *cmd = (CurveModifierData*) md;
2463
2464                                         if (cmd->defaxis == 0)
2465                                                 cmd->defaxis = ob->trackflag+1;
2466                                 }
2467                         }
2468
2469                 }
2470
2471                 for (ma = main->mat.first; ma; ma = ma->id.next) {
2472                         if (ma->shad_alpha == 0.0f)
2473                                 ma->shad_alpha = 1.0f;
2474                         if (ma->nodetree)
2475                                 ntree_version_242(ma->nodetree);
2476                 }
2477
2478                 for (me = main->mesh.first; me; me = me->id.next)
2479                         customdata_version_242(me);
2480
2481                 for (group = main->group.first; group; group = group->id.next)
2482                         if (group->layer == 0)
2483                                 group->layer = (1<<20)-1;
2484
2485                 /* now, subversion control! */
2486                 if (main->subversionfile < 3) {
2487                         Image *ima;
2488                         Tex *tex;
2489
2490                         /* Image refactor initialize */
2491                         for (ima = main->image.first; ima; ima = ima->id.next) {
2492                                 ima->source = IMA_SRC_FILE;
2493                                 ima->type = IMA_TYPE_IMAGE;
2494
2495                                 ima->gen_x = 256; ima->gen_y = 256;
2496                                 ima->gen_type = 1;
2497
2498                                 if (0 == strncmp(ima->id.name+2, "Viewer Node", sizeof(ima->id.name) - 2)) {
2499                                         ima->source = IMA_SRC_VIEWER;
2500                                         ima->type = IMA_TYPE_COMPOSITE;
2501                                 }
2502                                 if (0 == strncmp(ima->id.name+2, "Render Result", sizeof(ima->id.name) - 2)) {
2503                                         ima->source = IMA_SRC_VIEWER;
2504                                         ima->type = IMA_TYPE_R_RESULT;
2505                                 }
2506
2507                         }
2508                         for (tex = main->tex.first; tex; tex = tex->id.next) {
2509                                 if (tex->type == TEX_IMAGE && tex->ima) {
2510                                         ima = blo_do_versions_newlibadr(fd, lib, tex->ima);
2511                                         if (tex->imaflag & TEX_ANIM5_)
2512                                                 ima->source = IMA_SRC_MOVIE;
2513                                         if (tex->imaflag & TEX_FIELDS_)
2514                                                 ima->flag |= IMA_FIELDS;
2515                                         if (tex->imaflag & TEX_STD_FIELD_)
2516                                                 ima->flag |= IMA_STD_FIELD;
2517                                 }
2518                                 tex->iuser.frames = tex->frames;
2519                                 tex->iuser.fie_ima = (char)tex->fie_ima;
2520                                 tex->iuser.offset = tex->offset;
2521                                 tex->iuser.sfra = tex->sfra;
2522                                 tex->iuser.cycl = (tex->imaflag & TEX_ANIMCYCLIC_)!=0;
2523                         }
2524                         for (sce = main->scene.first; sce; sce = sce->id.next) {
2525                                 if (sce->nodetree)
2526                                         do_version_ntree_242_2(sce->nodetree);
2527                         }
2528                         for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
2529                                 do_version_ntree_242_2(ntree);
2530                         for (ma = main->mat.first; ma; ma = ma->id.next)
2531                                 if (ma->nodetree)
2532                                         do_version_ntree_242_2(ma->nodetree);
2533
2534                         for (sc = main->screen.first; sc; sc = sc->id.next) {
2535                                 ScrArea *sa;
2536                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
2537                                         SpaceLink *sl;
2538                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
2539                                                 if (sl->spacetype == SPACE_IMAGE)
2540                                                         ((SpaceImage *)sl)->iuser.fie_ima = 2;
2541                                                 else if (sl->spacetype == SPACE_VIEW3D) {
2542                                                         View3D *v3d = (View3D *)sl;
2543                                                         BGpic *bgpic;
2544                                                         for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next)
2545                                                                 bgpic->iuser.fie_ima = 2;
2546                                                 }
2547                                         }
2548                                 }
2549                         }
2550                 }
2551
2552                 if (main->subversionfile < 4) {
2553                         for (sce = main->scene.first; sce; sce = sce->id.next) {
2554                                 sce->r.bake_mode = 1;   /* prevent to include render stuff here */
2555                                 sce->r.bake_filter = 16;
2556                                 sce->r.bake_osa = 5;
2557                                 sce->r.bake_flag = R_BAKE_CLEAR;
2558                         }
2559                 }
2560
2561                 if (main->subversionfile < 5) {
2562                         for (sce = main->scene.first; sce; sce = sce->id.next) {
2563                                 /* improved triangle to quad conversion settings */
2564                                 if (sce->toolsettings->jointrilimit == 0.0f)
2565                                         sce->toolsettings->jointrilimit = 0.8f;
2566                         }
2567                 }
2568         }
2569
2570         if (main->versionfile <= 243) {
2571                 Object *ob = main->object.first;
2572                 Material *ma;
2573
2574                 for (ma = main->mat.first; ma; ma = ma->id.next) {
2575                         if (ma->sss_scale == 0.0f) {
2576                                 ma->sss_radius[0] = 1.0f;
2577                                 ma->sss_radius[1] = 1.0f;
2578                                 ma->sss_radius[2] = 1.0f;
2579                                 ma->sss_col[0] = 0.8f;
2580                                 ma->sss_col[1] = 0.8f;
2581                                 ma->sss_col[2] = 0.8f;
2582                                 ma->sss_error = 0.05f;
2583                                 ma->sss_scale = 0.1f;
2584                                 ma->sss_ior = 1.3f;
2585                                 ma->sss_colfac = 1.0f;
2586                                 ma->sss_texfac = 0.0f;
2587                         }
2588                         if (ma->sss_front == 0 && ma->sss_back == 0) {
2589                                 ma->sss_front = 1.0f;
2590                                 ma->sss_back = 1.0f;
2591                         }
2592                         if (ma->sss_col[0] == 0 && ma->sss_col[1] == 0 && ma->sss_col[2] == 0) {
2593                                 ma->sss_col[0] = ma->r;
2594                                 ma->sss_col[1] = ma->g;
2595                                 ma->sss_col[2] = ma->b;
2596                         }
2597                 }
2598
2599                 for (; ob; ob = ob->id.next) {
2600                         bDeformGroup *curdef;
2601
2602                         for (curdef = ob->defbase.first; curdef; curdef = curdef->next) {
2603                                 /* replace an empty-string name with unique name */
2604                                 if (curdef->name[0] == '\0') {
2605                                         defgroup_unique_name(curdef, ob);
2606                                 }
2607                         }
2608
2609                         if (main->versionfile < 243 || main->subversionfile < 1) {
2610                                 ModifierData *md;
2611
2612                                 /* translate old mirror modifier axis values to new flags */
2613                                 for (md = ob->modifiers.first; md; md = md->next) {
2614                                         if (md->type == eModifierType_Mirror) {
2615                                                 MirrorModifierData *mmd = (MirrorModifierData*) md;
2616
2617                                                 switch (mmd->axis) {
2618                                                         case 0:
2619                                                                 mmd->flag |= MOD_MIR_AXIS_X;
2620                                                                 break;
2621                                                         case 1:
2622                                                                 mmd->flag |= MOD_MIR_AXIS_Y;
2623                                                                 break;
2624                                                         case 2:
2625                                 &nbs