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