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