d551caea425766f50df09a9286eaf9321b535706
[blender.git] / source / blender / blenloader / intern / versioning_250.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_250.c
29  *  \ingroup blenloader
30  */
31
32 #include "zlib.h"
33
34 #ifndef WIN32
35 #  include <unistd.h> // for read close
36 #else
37 #  include <io.h> // for open close read
38 #  include "winsock2.h"
39 #  include "BLI_winstuff.h"
40 #endif
41
42 /* allow readfile to use deprecated functionality */
43 #define DNA_DEPRECATED_ALLOW
44
45 #include "DNA_anim_types.h"
46 #include "DNA_armature_types.h"
47 #include "DNA_actuator_types.h"
48 #include "DNA_brush_types.h"
49 #include "DNA_camera_types.h"
50 #include "DNA_cloth_types.h"
51 #include "DNA_constraint_types.h"
52 #include "DNA_ipo_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_node_types.h"
60 #include "DNA_object_fluidsim.h" // NT
61 #include "DNA_object_types.h"
62 #include "DNA_view3d_types.h"
63 #include "DNA_screen_types.h"
64 #include "DNA_sdna_types.h"
65 #include "DNA_sequence_types.h"
66 #include "DNA_smoke_types.h"
67 #include "DNA_sound_types.h"
68 #include "DNA_space_types.h"
69 #include "DNA_world_types.h"
70
71 #include "MEM_guardedalloc.h"
72
73 #include "BLI_utildefines.h"
74 #include "BLI_blenlib.h"
75 #include "BLI_math.h"
76 #include "BLI_edgehash.h"
77
78 #include "BKE_anim.h"
79 #include "BKE_armature.h"
80 #include "BKE_colortools.h"
81 #include "BKE_global.h" // for G
82 #include "BKE_library.h" // for which_libbase
83 #include "BKE_main.h" // for Main
84 #include "BKE_mesh.h" // for ME_ defines (patching)
85 #include "BKE_modifier.h"
86 #include "BKE_multires.h"
87 #include "BKE_particle.h"
88 #include "BKE_pointcache.h"
89 #include "BKE_screen.h"
90 #include "BKE_sequencer.h"
91 #include "BKE_texture.h"
92 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
93 #include "BKE_sound.h"
94
95 #include "NOD_socket.h"
96
97 //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
98 //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
99 //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
100 #include "BLO_readfile.h"
101 #include "BLO_undofile.h"
102
103 #include "RE_engine.h"
104
105 #include "readfile.h"
106
107 #include "PIL_time.h"
108
109 #include <errno.h>
110
111 /* 2.50 patch */
112 static void area_add_header_region(ScrArea *sa, ListBase *lb)
113 {
114         ARegion *ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
115
116         BLI_addtail(lb, ar);
117         ar->regiontype = RGN_TYPE_HEADER;
118         if (sa->headertype == HEADERDOWN)
119                 ar->alignment = RGN_ALIGN_BOTTOM;
120         else
121                 ar->alignment = RGN_ALIGN_TOP;
122
123         /* initialize view2d data for header region, to allow panning */
124         /* is copy from ui_view2d.c */
125         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
126         ar->v2d.keepofs = V2D_LOCKOFS_Y;
127         ar->v2d.keeptot = V2D_KEEPTOT_STRICT;
128         ar->v2d.align = V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
129         ar->v2d.flag = (V2D_PIXELOFS_X|V2D_PIXELOFS_Y);
130 }
131
132 static void sequencer_init_preview_region(ARegion* ar)
133 {
134         // XXX a bit ugly still, copied from space_sequencer
135         /* NOTE: if you change values here, also change them in space_sequencer.c, sequencer_new */
136         ar->regiontype = RGN_TYPE_PREVIEW;
137         ar->alignment = RGN_ALIGN_TOP;
138         ar->flag |= RGN_FLAG_HIDDEN;
139         ar->v2d.keepzoom = V2D_KEEPASPECT | V2D_KEEPZOOM;
140         ar->v2d.minzoom = 0.00001f;
141         ar->v2d.maxzoom = 100000.0f;
142         ar->v2d.tot.xmin = -960.0f; /* 1920 width centered */
143         ar->v2d.tot.ymin = -540.0f; /* 1080 height centered */
144         ar->v2d.tot.xmax = 960.0f;
145         ar->v2d.tot.ymax = 540.0f;
146         ar->v2d.min[0] = 0.0f;
147         ar->v2d.min[1] = 0.0f;
148         ar->v2d.max[0] = 12000.0f;
149         ar->v2d.max[1] = 12000.0f;
150         ar->v2d.cur = ar->v2d.tot;
151         ar->v2d.align = V2D_ALIGN_FREE; // (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
152         ar->v2d.keeptot = V2D_KEEPTOT_FREE;
153 }
154
155 static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
156 {
157         ARegion *ar;
158         ARegion *ar_main;
159
160         if (sl) {
161                 /* first channels for ipo action nla... */
162                 switch (sl->spacetype) {
163                         case SPACE_IPO:
164                                 ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
165                                 BLI_addtail(lb, ar);
166                                 ar->regiontype = RGN_TYPE_CHANNELS;
167                                 ar->alignment = RGN_ALIGN_LEFT;
168                                 ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
169
170                                 /* for some reason, this doesn't seem to go auto like for NLA... */
171                                 ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
172                                 BLI_addtail(lb, ar);
173                                 ar->regiontype = RGN_TYPE_UI;
174                                 ar->alignment = RGN_ALIGN_RIGHT;
175                                 ar->v2d.scroll = V2D_SCROLL_RIGHT;
176                                 ar->v2d.flag = RGN_FLAG_HIDDEN;
177                                 break;
178
179                         case SPACE_ACTION:
180                                 ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
181                                 BLI_addtail(lb, ar);
182                                 ar->regiontype = RGN_TYPE_CHANNELS;
183                                 ar->alignment = RGN_ALIGN_LEFT;
184                                 ar->v2d.scroll = V2D_SCROLL_BOTTOM;
185                                 ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
186                                 break;
187
188                         case SPACE_NLA:
189                                 ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
190                                 BLI_addtail(lb, ar);
191                                 ar->regiontype = RGN_TYPE_CHANNELS;
192                                 ar->alignment = RGN_ALIGN_LEFT;
193                                 ar->v2d.scroll = V2D_SCROLL_BOTTOM;
194                                 ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
195
196                                 /* for some reason, some files still don't get this auto */
197                                 ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
198                                 BLI_addtail(lb, ar);
199                                 ar->regiontype = RGN_TYPE_UI;
200                                 ar->alignment = RGN_ALIGN_RIGHT;
201                                 ar->v2d.scroll = V2D_SCROLL_RIGHT;
202                                 ar->v2d.flag = RGN_FLAG_HIDDEN;
203                                 break;
204
205                         case SPACE_NODE:
206                                 ar = MEM_callocN(sizeof(ARegion), "nodetree area for node");
207                                 BLI_addtail(lb, ar);
208                                 ar->regiontype = RGN_TYPE_UI;
209                                 ar->alignment = RGN_ALIGN_LEFT;
210                                 ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
211                                 ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
212                                 /* temporarily hide it */
213                                 ar->flag = RGN_FLAG_HIDDEN;
214                                 break;
215                         case SPACE_FILE:
216                                 ar = MEM_callocN(sizeof(ARegion), "nodetree area for node");
217                                 BLI_addtail(lb, ar);
218                                 ar->regiontype = RGN_TYPE_CHANNELS;
219                                 ar->alignment = RGN_ALIGN_LEFT;
220
221                                 ar = MEM_callocN(sizeof(ARegion), "ui area for file");
222                                 BLI_addtail(lb, ar);
223                                 ar->regiontype = RGN_TYPE_UI;
224                                 ar->alignment = RGN_ALIGN_TOP;
225                                 break;
226                         case SPACE_SEQ:
227                                 ar_main = (ARegion*) lb->first;
228                                 for (; ar_main; ar_main = ar_main->next) {
229                                         if (ar_main->regiontype == RGN_TYPE_WINDOW)
230                                                 break;
231                                 }
232                                 ar = MEM_callocN(sizeof(ARegion), "preview area for sequencer");
233                                 BLI_insertlinkbefore(lb, ar_main, ar);
234                                 sequencer_init_preview_region(ar);
235                                 break;
236                         case SPACE_VIEW3D:
237                                 /* toolbar */
238                                 ar = MEM_callocN(sizeof(ARegion), "toolbar for view3d");
239
240                                 BLI_addtail(lb, ar);
241                                 ar->regiontype = RGN_TYPE_TOOLS;
242                                 ar->alignment = RGN_ALIGN_LEFT;
243                                 ar->flag = RGN_FLAG_HIDDEN;
244
245                                 /* tool properties */
246                                 ar = MEM_callocN(sizeof(ARegion), "tool properties for view3d");
247
248                                 BLI_addtail(lb, ar);
249                                 ar->regiontype = RGN_TYPE_TOOL_PROPS;
250                                 ar->alignment = RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV;
251                                 ar->flag = RGN_FLAG_HIDDEN;
252
253                                 /* buttons/list view */
254                                 ar = MEM_callocN(sizeof(ARegion), "buttons for view3d");
255
256                                 BLI_addtail(lb, ar);
257                                 ar->regiontype = RGN_TYPE_UI;
258                                 ar->alignment = RGN_ALIGN_RIGHT;
259                                 ar->flag = RGN_FLAG_HIDDEN;
260 #if 0
261                         case SPACE_BUTS:
262                                 /* context UI region */
263                                 ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
264                                 BLI_addtail(lb, ar);
265                                 ar->regiontype = RGN_TYPE_UI;
266                                 ar->alignment = RGN_ALIGN_RIGHT;
267
268                                 break;
269 #endif
270                 }
271         }
272
273         /* main region */
274         ar = MEM_callocN(sizeof(ARegion), "area region from do_versions");
275
276         BLI_addtail(lb, ar);
277         ar->winrct = sa->totrct;
278
279         ar->regiontype = RGN_TYPE_WINDOW;
280
281         if (sl) {
282                 /* if active spacetype has view2d data, copy that over to main region */
283                 /* and we split view3d */
284                 switch (sl->spacetype) {
285                         case SPACE_VIEW3D:
286                                 blo_do_versions_view3d_split_250((View3D *)sl, lb);
287                                 break;
288
289                         case SPACE_OUTLINER:
290                                 {
291                                         SpaceOops *soops = (SpaceOops *)sl;
292
293                                         memcpy(&ar->v2d, &soops->v2d, sizeof(View2D));
294
295                                         ar->v2d.scroll &= ~V2D_SCROLL_LEFT;
296                                         ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
297                                         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
298                                         ar->v2d.keepzoom |= (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPASPECT);
299                                         ar->v2d.keeptot = V2D_KEEPTOT_STRICT;
300                                         ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f;
301                                         //ar->v2d.flag |= V2D_IS_INITIALISED;
302                                 }
303                                 break;
304                         case SPACE_TIME:
305                                 {
306                                         SpaceTime *stime = (SpaceTime *)sl;
307                                         memcpy(&ar->v2d, &stime->v2d, sizeof(View2D));
308
309                                         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
310                                         ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
311                                         ar->v2d.keepofs |= V2D_LOCKOFS_Y;
312                                         ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
313                                         ar->v2d.tot.ymin = ar->v2d.cur.ymin = -10.0;
314                                         ar->v2d.min[1] = ar->v2d.max[1] = 20.0;
315                                 }
316                                 break;
317                         case SPACE_IPO:
318                                 {
319                                         SpaceIpo *sipo = (SpaceIpo *)sl;
320                                         memcpy(&ar->v2d, &sipo->v2d, sizeof(View2D));
321
322                                         /* init mainarea view2d */
323                                         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
324                                         ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
325
326                                         ar->v2d.min[0] = FLT_MIN;
327                                         ar->v2d.min[1] = FLT_MIN;
328
329                                         ar->v2d.max[0] = MAXFRAMEF;
330                                         ar->v2d.max[1] = FLT_MAX;
331
332                                         //ar->v2d.flag |= V2D_IS_INITIALISED;
333                                         break;
334                                 }
335                         case SPACE_NLA:
336                                 {
337                                         SpaceNla *snla = (SpaceNla *)sl;
338                                         memcpy(&ar->v2d, &snla->v2d, sizeof(View2D));
339
340                                         ar->v2d.tot.ymin = (float)(-sa->winy)/3.0f;
341                                         ar->v2d.tot.ymax = 0.0f;
342
343                                         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
344                                         ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
345                                         ar->v2d.align = V2D_ALIGN_NO_POS_Y;
346                                         ar->v2d.flag |= V2D_VIEWSYNC_AREA_VERTICAL;
347                                         break;
348                                 }
349                         case SPACE_ACTION:
350                                 {
351                                         SpaceAction *saction = (SpaceAction *) sl;
352
353                                         /* we totally reinit the view for the Action Editor, as some old instances had some weird cruft set */
354                                         ar->v2d.tot.xmin = -20.0f;
355                                         ar->v2d.tot.ymin = (float)(-sa->winy)/3.0f;
356                                         ar->v2d.tot.xmax = (float)((sa->winx > 120)? (sa->winx) : 120);
357                                         ar->v2d.tot.ymax = 0.0f;
358
359                                         ar->v2d.cur = ar->v2d.tot;
360
361                                         ar->v2d.min[0] = 0.0f;
362                                         ar->v2d.min[1] = 0.0f;
363
364                                         ar->v2d.max[0] = MAXFRAMEF;
365                                         ar->v2d.max[1] = FLT_MAX;
366
367                                         ar->v2d.minzoom = 0.01f;
368                                         ar->v2d.maxzoom = 50;
369                                         ar->v2d.scroll = (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
370                                         ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
371                                         ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
372                                         ar->v2d.align = V2D_ALIGN_NO_POS_Y;
373                                         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
374
375                                         /* for old files with ShapeKey editors open + an action set, clear the action as
376                                          * it doesn't make sense in the new system (i.e. violates concept that ShapeKey edit
377                                          * only shows ShapeKey-rooted actions only)
378                                          */
379                                         if (saction->mode == SACTCONT_SHAPEKEY)
380                                                 saction->action = NULL;
381                                         break;
382                                 }
383                         case SPACE_SEQ:
384                                 {
385                                         SpaceSeq *sseq = (SpaceSeq *)sl;
386                                         memcpy(&ar->v2d, &sseq->v2d, sizeof(View2D));
387
388                                         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
389                                         ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
390                                         ar->v2d.align = V2D_ALIGN_NO_NEG_Y;
391                                         ar->v2d.flag |= V2D_IS_INITIALISED;
392                                         break;
393                                 }
394                         case SPACE_NODE:
395                                 {
396                                         SpaceNode *snode = (SpaceNode *)sl;
397                                         memcpy(&ar->v2d, &snode->v2d, sizeof(View2D));
398
399                                         ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
400                                         ar->v2d.keepzoom = V2D_LIMITZOOM|V2D_KEEPASPECT;
401                                         break;
402                                 }
403                         case SPACE_BUTS:
404                                 {
405                                         SpaceButs *sbuts = (SpaceButs *)sl;
406                                         memcpy(&ar->v2d, &sbuts->v2d, sizeof(View2D));
407
408                                         ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
409                                         break;
410                                 }
411                         case SPACE_FILE:
412                                 {
413                                         // SpaceFile *sfile = (SpaceFile *)sl;
414                                         ar->v2d.tot.xmin = ar->v2d.tot.ymin = 0;
415                                         ar->v2d.tot.xmax = ar->winx;
416                                         ar->v2d.tot.ymax = ar->winy;
417                                         ar->v2d.cur = ar->v2d.tot;
418                                         ar->regiontype = RGN_TYPE_WINDOW;
419                                         ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
420                                         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
421                                         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
422                                         break;
423                                 }
424                         case SPACE_TEXT:
425                                 {
426                                         SpaceText *st = (SpaceText *)sl;
427                                         st->flags |= ST_FIND_WRAP;
428                                 }
429                                 //case SPACE_XXX: // FIXME... add other ones
430                                 //      memcpy(&ar->v2d, &((SpaceXxx *)sl)->v2d, sizeof(View2D));
431                                 //      break;
432                 }
433         }
434 }
435
436 static void do_versions_windowmanager_2_50(bScreen *screen)
437 {
438         ScrArea *sa;
439         SpaceLink *sl;
440
441         /* add regions */
442         for (sa = screen->areabase.first; sa; sa = sa->next) {
443                 /* we keep headertype variable to convert old files only */
444                 if (sa->headertype)
445                         area_add_header_region(sa, &sa->regionbase);
446
447                 area_add_window_regions(sa, sa->spacedata.first, &sa->regionbase);
448
449                 /* space imageselect is deprecated */
450                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
451                         if (sl->spacetype == SPACE_IMASEL)
452                                 sl->spacetype = SPACE_EMPTY;    /* spacedata then matches */
453                 }
454
455                 /* space sound is deprecated */
456                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
457                         if (sl->spacetype == SPACE_SOUND)
458                                 sl->spacetype = SPACE_EMPTY;    /* spacedata then matches */
459                 }
460
461                 /* it seems to be possible in 2.5 to have this saved, filewindow probably */
462                 sa->butspacetype = sa->spacetype;
463
464                 /* pushed back spaces also need regions! */
465                 if (sa->spacedata.first) {
466                         sl = sa->spacedata.first;
467                         for (sl = sl->next; sl; sl = sl->next) {
468                                 if (sa->headertype)
469                                         area_add_header_region(sa, &sl->regionbase);
470                                 area_add_window_regions(sa, sl, &sl->regionbase);
471                         }
472                 }
473         }
474 }
475
476 static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name)
477 {
478         BLI_addtail(lb, id);
479         id->us = 1;
480         id->flag = LIB_FAKEUSER;
481         *( (short *)id->name )= ID_GD;
482
483         new_id(lb, id, name);
484         /* alphabetic insterion: is in new_id */
485
486         if (G.debug & G_DEBUG)
487                 printf("Converted GPencil to ID: %s\n", id->name + 2);
488 }
489
490 static void do_versions_gpencil_2_50(Main *main, bScreen *screen)
491 {
492         ScrArea *sa;
493         SpaceLink *sl;
494
495         /* add regions */
496         for (sa = screen->areabase.first; sa; sa = sa->next) {
497                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
498                         if (sl->spacetype == SPACE_VIEW3D) {
499                                 View3D *v3d = (View3D*) sl;
500                                 if (v3d->gpd) {
501                                         versions_gpencil_add_main(&main->gpencil, (ID *)v3d->gpd, "GPencil View3D");
502                                         v3d->gpd = NULL;
503                                 }
504                         }
505                         else if (sl->spacetype == SPACE_NODE) {
506                                 SpaceNode *snode = (SpaceNode *) sl;
507                                 if (snode->gpd) {
508                                         versions_gpencil_add_main(&main->gpencil, (ID *)snode->gpd, "GPencil Node");
509                                         snode->gpd = NULL;
510                                 }
511                         }
512                         else if (sl->spacetype == SPACE_SEQ) {
513                                 SpaceSeq *sseq = (SpaceSeq *) sl;
514                                 if (sseq->gpd) {
515                                         versions_gpencil_add_main(&main->gpencil, (ID *)sseq->gpd, "GPencil Node");
516                                         sseq->gpd = NULL;
517                                 }
518                         }
519                         else if (sl->spacetype == SPACE_IMAGE) {
520                                 SpaceImage *sima = (SpaceImage *) sl;
521 #if 0                   /* see comment on r28002 */
522                                 if (sima->gpd) {
523                                         versions_gpencil_add_main(&main->gpencil, (ID *)sima->gpd, "GPencil Image");
524                                         sima->gpd = NULL;
525                                 }
526 #else
527                                 sima->gpd = NULL;
528 #endif
529                         }
530                 }
531         }
532 }
533
534 static void do_version_mtex_factor_2_50(MTex **mtex_array, short idtype)
535 {
536         MTex *mtex;
537         float varfac, colfac;
538         int a, neg;
539
540         if (!mtex_array)
541                 return;
542
543         for (a = 0; a < MAX_MTEX; a++) {
544                 if (mtex_array[a]) {
545                         mtex = mtex_array[a];
546
547                         neg = mtex->maptoneg;
548                         varfac = mtex->varfac;
549                         colfac = mtex->colfac;
550
551                         if (neg & MAP_DISP) mtex->dispfac = -mtex->dispfac;
552                         if (neg & MAP_NORM) mtex->norfac = -mtex->norfac;
553                         if (neg & MAP_WARP) mtex->warpfac = -mtex->warpfac;
554
555                         mtex->colspecfac = (neg & MAP_COLSPEC)? -colfac: colfac;
556                         mtex->mirrfac = (neg & MAP_COLMIR)? -colfac: colfac;
557                         mtex->alphafac = (neg & MAP_ALPHA)? -varfac: varfac;
558                         mtex->difffac = (neg & MAP_REF)? -varfac: varfac;
559                         mtex->specfac = (neg & MAP_SPEC)? -varfac: varfac;
560                         mtex->emitfac = (neg & MAP_EMIT)? -varfac: varfac;
561                         mtex->hardfac = (neg & MAP_HAR)? -varfac: varfac;
562                         mtex->raymirrfac = (neg & MAP_RAYMIRR)? -varfac: varfac;
563                         mtex->translfac = (neg & MAP_TRANSLU)? -varfac: varfac;
564                         mtex->ambfac = (neg & MAP_AMB)? -varfac: varfac;
565                         mtex->colemitfac = (neg & MAP_EMISSION_COL)? -colfac: colfac;
566                         mtex->colreflfac = (neg & MAP_REFLECTION_COL)? -colfac: colfac;
567                         mtex->coltransfac = (neg & MAP_TRANSMISSION_COL)? -colfac: colfac;
568                         mtex->densfac = (neg & MAP_DENSITY)? -varfac: varfac;
569                         mtex->scatterfac = (neg & MAP_SCATTERING)? -varfac: varfac;
570                         mtex->reflfac = (neg & MAP_REFLECTION)? -varfac: varfac;
571
572                         mtex->timefac = (neg & MAP_PA_TIME)? -varfac: varfac;
573                         mtex->lengthfac = (neg & MAP_PA_LENGTH)? -varfac: varfac;
574                         mtex->clumpfac = (neg & MAP_PA_CLUMP)? -varfac: varfac;
575                         mtex->kinkfac = (neg & MAP_PA_KINK)? -varfac: varfac;
576                         mtex->roughfac = (neg & MAP_PA_ROUGH)? -varfac: varfac;
577                         mtex->padensfac = (neg & MAP_PA_DENS)? -varfac: varfac;
578                         mtex->lifefac = (neg & MAP_PA_LIFE)? -varfac: varfac;
579                         mtex->sizefac = (neg & MAP_PA_SIZE)? -varfac: varfac;
580                         mtex->ivelfac = (neg & MAP_PA_IVEL)? -varfac: varfac;
581
582                         mtex->shadowfac = (neg & LAMAP_SHAD)? -colfac: colfac;
583
584                         mtex->zenupfac = (neg & WOMAP_ZENUP)? -colfac: colfac;
585                         mtex->zendownfac = (neg & WOMAP_ZENDOWN)? -colfac: colfac;
586                         mtex->blendfac = (neg & WOMAP_BLEND)? -varfac: varfac;
587
588                         if (idtype == ID_MA)
589                                 mtex->colfac = (neg & MAP_COL)? -colfac: colfac;
590                         else if (idtype == ID_LA)
591                                 mtex->colfac = (neg & LAMAP_COL)? -colfac: colfac;
592                         else if (idtype == ID_WO)
593                                 mtex->colfac = (neg & WOMAP_HORIZ)? -colfac: colfac;
594                 }
595         }
596 }
597
598 static void do_version_mdef_250(Main *main)
599 {
600         Object *ob;
601         ModifierData *md;
602         MeshDeformModifierData *mmd;
603
604         for (ob = main->object.first; ob; ob = ob->id.next) {
605                 for (md = ob->modifiers.first; md; md = md->next) {
606                         if (md->type == eModifierType_MeshDeform) {
607                                 mmd = (MeshDeformModifierData*) md;
608
609                                 if (mmd->bindcos) {
610                                         /* make bindcos NULL in order to trick older versions
611                                          * into thinking that the mesh was not bound yet */
612                                         mmd->bindcagecos = mmd->bindcos;
613                                         mmd->bindcos = NULL;
614
615                                         modifier_mdef_compact_influences(md);
616                                 }
617                         }
618                 }
619         }
620 }
621
622 static void do_version_constraints_radians_degrees_250(ListBase *lb)
623 {
624         bConstraint *con;
625
626         for (con = lb->first; con; con = con->next) {
627                 if (con->type == CONSTRAINT_TYPE_RIGIDBODYJOINT) {
628                         bRigidBodyJointConstraint *data = con->data;
629                         data->axX *= (float)(M_PI / 180.0);
630                         data->axY *= (float)(M_PI / 180.0);
631                         data->axZ *= (float)(M_PI / 180.0);
632                 }
633                 else if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
634                         bKinematicConstraint *data = con->data;
635                         data->poleangle *= (float)(M_PI / 180.0);
636                 }
637                 else if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
638                         bRotLimitConstraint *data = con->data;
639
640                         data->xmin *= (float)(M_PI / 180.0);
641                         data->xmax *= (float)(M_PI / 180.0);
642                         data->ymin *= (float)(M_PI / 180.0);
643                         data->ymax *= (float)(M_PI / 180.0);
644                         data->zmin *= (float)(M_PI / 180.0);
645                         data->zmax *= (float)(M_PI / 180.0);
646                 }
647         }
648 }
649
650 /* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already */
651 static void do_versions_seq_unique_name_all_strips(Scene * sce, ListBase *seqbasep)
652 {
653         Sequence * seq = seqbasep->first;
654
655         while (seq) {
656                 BKE_seqence_base_unique_name_recursive(&sce->ed->seqbase, seq);
657                 if (seq->seqbase.first) {
658                         do_versions_seq_unique_name_all_strips(sce, &seq->seqbase);
659                 }
660                 seq = seq->next;
661         }
662 }
663
664 static void do_version_bone_roll_256(Bone *bone)
665 {
666         Bone *child;
667         float submat[3][3];
668
669         copy_m3_m4(submat, bone->arm_mat);
670         mat3_to_vec_roll(submat, NULL, &bone->arm_roll);
671
672         for (child = bone->childbase.first; child; child = child->next)
673                 do_version_bone_roll_256(child);
674 }
675
676 static void do_versions_nodetree_dynamic_sockets(bNodeTree *ntree)
677 {
678         bNodeSocket *sock;
679         for (sock = ntree->inputs.first; sock; sock = sock->next)
680                 sock->flag |= SOCK_DYNAMIC;
681         for (sock = ntree->outputs.first; sock; sock = sock->next)
682                 sock->flag |= SOCK_DYNAMIC;
683 }
684
685 void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
686 {
687         /* WATCH IT!!!: pointers from libdata have not been converted */
688
689         if (main->versionfile < 250) {
690                 bScreen *screen;
691                 Scene *scene;
692                 Base *base;
693                 Material *ma;
694                 Camera *cam;
695                 Mesh *me;
696                 Curve *cu;
697                 Scene *sce;
698                 Tex *tx;
699                 ParticleSettings *part;
700                 Object *ob;
701                 //PTCacheID *pid;
702                 //ListBase pidlist;
703
704                 bSound *sound;
705                 Sequence *seq;
706                 bActuator *act;
707                 int a;
708
709                 for (sound = main->sound.first; sound; sound = sound->id.next) {
710                         if (sound->newpackedfile) {
711                                 sound->packedfile = sound->newpackedfile;
712                                 sound->newpackedfile = NULL;
713                         }
714                 }
715
716                 for (ob = main->object.first; ob; ob = ob->id.next) {
717                         for (act = ob->actuators.first; act; act = act->next) {
718                                 if (act->type == ACT_SOUND) {
719                                         bSoundActuator *sAct = (bSoundActuator*) act->data;
720                                         if (sAct->sound) {
721                                                 sound = blo_do_versions_newlibadr(fd, lib, sAct->sound);
722                                                 sAct->flag = sound->flags & SOUND_FLAGS_3D ? ACT_SND_3D_SOUND : 0;
723                                                 sAct->pitch = sound->pitch;
724                                                 sAct->volume = sound->volume;
725                                                 sAct->sound3D.reference_distance = sound->distance;
726                                                 sAct->sound3D.max_gain = sound->max_gain;
727                                                 sAct->sound3D.min_gain = sound->min_gain;
728                                                 sAct->sound3D.rolloff_factor = sound->attenuation;
729                                         }
730                                         else {
731                                                 sAct->sound3D.reference_distance = 1.0f;
732                                                 sAct->volume = 1.0f;
733                                                 sAct->sound3D.max_gain = 1.0f;
734                                                 sAct->sound3D.rolloff_factor = 1.0f;
735                                         }
736                                         sAct->sound3D.cone_inner_angle = 360.0f;
737                                         sAct->sound3D.cone_outer_angle = 360.0f;
738                                         sAct->sound3D.max_distance = FLT_MAX;
739                                 }
740                         }
741                 }
742
743                 for (scene = main->scene.first; scene; scene = scene->id.next) {
744                         if (scene->ed && scene->ed->seqbasep) {
745                                 SEQ_BEGIN (scene->ed, seq)
746                                 {
747                                         if (seq->type == SEQ_TYPE_SOUND_HD) {
748                                                 char str[FILE_MAX];
749                                                 BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name);
750                                                 BLI_path_abs(str, main->name);
751                                                 seq->sound = sound_new_file(main, str);
752                                         }
753                                         /* don't know, if anybody used that this way, but just in case, upgrade to new way... */
754                                         if ((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) &&
755                                            !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR))
756                                         {
757                                                 BLI_snprintf(seq->strip->proxy->dir, FILE_MAXDIR, "%s/BL_proxy", seq->strip->dir);
758                                         }
759                                 }
760                                 SEQ_END
761                         }
762                 }
763
764                 for (screen = main->screen.first; screen; screen = screen->id.next) {
765                         do_versions_windowmanager_2_50(screen);
766                         do_versions_gpencil_2_50(main, screen);
767                 }
768
769                 /* shader, composite and texture node trees have id.name empty, put something in
770                  * to have them show in RNA viewer and accessible otherwise.
771                  */
772                 for (ma = main->mat.first; ma; ma = ma->id.next) {
773                         if (ma->nodetree && ma->nodetree->id.name[0] == '\0')
774                                 strcpy(ma->nodetree->id.name, "NTShader Nodetree");
775
776                         /* which_output 0 is now "not specified" */
777                         for (a = 0; a < MAX_MTEX; a++) {
778                                 if (ma->mtex[a]) {
779                                         tx = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
780                                         if (tx && tx->use_nodes)
781                                                 ma->mtex[a]->which_output++;
782                                 }
783                         }
784                 }
785
786                 /* and composite trees */
787                 for (sce = main->scene.first; sce; sce = sce->id.next) {
788                         if (sce->nodetree && sce->nodetree->id.name[0] == '\0')
789                                 strcpy(sce->nodetree->id.name, "NTCompositing Nodetree");
790
791                         /* move to cameras */
792                         if (sce->r.mode & R_PANORAMA) {
793                                 for (base = sce->base.first; base; base = base->next) {
794                                         ob = blo_do_versions_newlibadr(fd, lib, base->object);
795
796                                         if (ob->type == OB_CAMERA && !ob->id.lib) {
797                                                 cam = blo_do_versions_newlibadr(fd, lib, ob->data);
798                                                 cam->flag |= CAM_PANORAMA;
799                                         }
800                                 }
801
802                                 sce->r.mode &= ~R_PANORAMA;
803                         }
804                 }
805
806                 /* and texture trees */
807                 for (tx = main->tex.first; tx; tx = tx->id.next) {
808                         bNode *node;
809
810                         if (tx->nodetree) {
811                                 if (tx->nodetree->id.name[0] == '\0')
812                                         strcpy(tx->nodetree->id.name, "NTTexture Nodetree");
813
814                                 /* which_output 0 is now "not specified" */
815                                 for (node = tx->nodetree->nodes.first; node; node = node->next)
816                                         if (node->type == TEX_NODE_OUTPUT)
817                                                 node->custom1++;
818                         }
819                 }
820
821                 /* copy standard draw flag to meshes(used to be global, is not available here) */
822                 for (me = main->mesh.first; me; me = me->id.next) {
823                         me->drawflag = ME_DRAWEDGES|ME_DRAWFACES|ME_DRAWCREASES;
824                 }
825
826                 /* particle draw and render types */
827                 for (part = main->particle.first; part; part = part->id.next) {
828                         if (part->draw_as) {
829                                 if (part->draw_as == PART_DRAW_DOT) {
830                                         part->ren_as = PART_DRAW_HALO;
831                                         part->draw_as = PART_DRAW_REND;
832                                 }
833                                 else if (part->draw_as <= PART_DRAW_AXIS) {
834                                         part->ren_as = PART_DRAW_HALO;
835                                 }
836                                 else {
837                                         part->ren_as = part->draw_as;
838                                         part->draw_as = PART_DRAW_REND;
839                                 }
840                         }
841                         part->path_end = 1.0f;
842                         part->clength = 1.0f;
843                 }
844
845                 /* set old pointcaches to have disk cache flag */
846                 for (ob = main->object.first; ob; ob = ob->id.next) {
847
848                         //BKE_ptcache_ids_from_object(&pidlist, ob);
849
850                         //for (pid = pidlist.first; pid; pid = pid->next)
851                         //      pid->cache->flag |= PTCACHE_DISK_CACHE;
852
853                         //BLI_freelistN(&pidlist);
854                 }
855
856                 /* type was a mixed flag & enum. move the 2d flag elsewhere */
857                 for (cu = main->curve.first; cu; cu = cu->id.next) {
858                         Nurb *nu;
859
860                         for (nu = cu->nurb.first; nu; nu = nu->next) {
861                                 nu->flag |= (nu->type & CU_2D);
862                                 nu->type &= CU_TYPE;
863                         }
864                 }
865         }
866
867         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 1)) {
868                 Object *ob;
869                 Material *ma;
870                 Tex *tex;
871                 Scene *sce;
872                 ToolSettings *ts;
873                 //PTCacheID *pid;
874                 //ListBase pidlist;
875
876                 for (ob = main->object.first; ob; ob = ob->id.next) {
877                         //BKE_ptcache_ids_from_object(&pidlist, ob);
878
879                         //for (pid = pidlist.first; pid; pid = pid->next) {
880                         //      if (pid->ptcaches->first == NULL)
881                         //              pid->ptcaches->first = pid->ptcaches->last = pid->cache;
882                         //}
883
884                         //BLI_freelistN(&pidlist);
885
886                         if (ob->type == OB_MESH) {
887                                 Mesh *me = blo_do_versions_newlibadr(fd, lib, ob->data);
888                                 void *olddata = ob->data;
889                                 ob->data = me;
890
891                                 /* XXX - library meshes crash on loading most yoFrankie levels,
892                                  * the multires pointer gets invalid -  Campbell */
893                                 if (me && me->id.lib == NULL && me->mr && me->mr->level_count > 1) {
894                                         multires_load_old(ob, me);
895                                 }
896
897                                 ob->data = olddata;
898                         }
899
900                         if (ob->totcol && ob->matbits == NULL) {
901                                 int a;
902
903                                 ob->matbits = MEM_callocN(sizeof(char)*ob->totcol, "ob->matbits");
904                                 for (a = 0; a < ob->totcol; a++)
905                                         ob->matbits[a] = ob->colbits & (1<<a);
906                         }
907                 }
908
909                 /* texture filter */
910                 for (tex = main->tex.first; tex; tex = tex->id.next) {
911                         if (tex->afmax == 0)
912                                 tex->afmax = 8;
913                 }
914
915                 for (ma = main->mat.first; ma; ma = ma->id.next) {
916                         int a;
917
918                         if (ma->mode & MA_WIRE) {
919                                 ma->material_type = MA_TYPE_WIRE;
920                                 ma->mode &= ~MA_WIRE;
921                         }
922
923                         if (ma->mode & MA_HALO) {
924                                 ma->material_type = MA_TYPE_HALO;
925                                 ma->mode &= ~MA_HALO;
926                         }
927
928                         if (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP)) {
929                                 ma->mode |= MA_TRANSP;
930                         }
931                         else {
932                                 /* ma->mode |= MA_ZTRANSP; */ /* leave ztransp as is even if its not used [#28113] */
933                                 ma->mode &= ~MA_TRANSP;
934                         }
935
936                         /* set new bump for unused slots */
937                         for (a = 0; a < MAX_MTEX; a++) {
938                                 if (ma->mtex[a]) {
939                                         tex = ma->mtex[a]->tex;
940                                         if (!tex) {
941                                                 ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
942                                                 ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
943                                         }
944                                         else {
945                                                 tex = (Tex*) blo_do_versions_newlibadr(fd, ma->id.lib, tex);
946                                                 if (tex && tex->type == 0) { /* invalid type */
947                                                         ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
948                                                         ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
949                                                 }
950                                         }
951                                 }
952                         }
953
954                         /* volume rendering settings */
955                         if (ma->vol.stepsize < 0.0001f) {
956                                 ma->vol.density = 1.0f;
957                                 ma->vol.emission = 0.0f;
958                                 ma->vol.scattering = 1.0f;
959                                 ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
960                                 ma->vol.density_scale = 1.0f;
961                                 ma->vol.depth_cutoff = 0.01f;
962                                 ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
963                                 ma->vol.stepsize = 0.2f;
964                                 ma->vol.shade_type = MA_VOL_SHADE_SHADED;
965                                 ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
966                                 ma->vol.precache_resolution = 50;
967                         }
968                 }
969
970                 for (sce = main->scene.first; sce; sce = sce->id.next) {
971                         ts = sce->toolsettings;
972                         if (ts->normalsize == 0.0f || !ts->uv_selectmode || ts->vgroup_weight == 0.0f) {
973                                 ts->normalsize = 0.1f;
974                                 ts->selectmode = SCE_SELECT_VERTEX;
975
976                                 /* autokeying - setting should be taken from the user-prefs
977                                  * but the userprefs version may not have correct flags set
978                                  * (i.e. will result in blank box when enabled)
979                                  */
980                                 ts->autokey_mode = U.autokey_mode;
981                                 if (ts->autokey_mode == 0)
982                                         ts->autokey_mode = 2; /* 'add/replace' but not on */
983                                 ts->uv_selectmode = UV_SELECT_VERTEX;
984                                 ts->vgroup_weight = 1.0f;
985                         }
986
987                         /* Game Settings */
988                         /* Dome */
989                         sce->gm.dome.angle = sce->r.domeangle;
990                         sce->gm.dome.mode = sce->r.domemode;
991                         sce->gm.dome.res = sce->r.domeres;
992                         sce->gm.dome.resbuf = sce->r.domeresbuf;
993                         sce->gm.dome.tilt = sce->r.dometilt;
994                         sce->gm.dome.warptext = sce->r.dometext;
995
996                         /* Stand Alone */
997                         sce->gm.playerflag |= (sce->r.fullscreen?GAME_PLAYER_FULLSCREEN:0);
998                         sce->gm.xplay = sce->r.xplay;
999                         sce->gm.yplay = sce->r.yplay;
1000                         sce->gm.freqplay = sce->r.freqplay;
1001                         sce->gm.depth = sce->r.depth;
1002                         sce->gm.attrib = sce->r.attrib;
1003
1004                         /* Stereo */
1005                         sce->gm.stereomode = sce->r.stereomode;
1006                         /* reassigning stereomode NO_STEREO and DOME to a separeted flag*/
1007                         if (sce->gm.stereomode == 1) { // 1 = STEREO_NOSTEREO
1008                                 sce->gm.stereoflag = STEREO_NOSTEREO;
1009                                 sce->gm.stereomode = STEREO_ANAGLYPH;
1010                         }
1011                         else if (sce->gm.stereomode == 8) { // 8 = STEREO_DOME
1012                                 sce->gm.stereoflag = STEREO_DOME;
1013                                 sce->gm.stereomode = STEREO_ANAGLYPH;
1014                         }
1015                         else
1016                                 sce->gm.stereoflag = STEREO_ENABLED;
1017
1018                         /* Framing */
1019                         sce->gm.framing = sce->framing;
1020                         sce->gm.xplay = sce->r.xplay;
1021                         sce->gm.yplay = sce->r.yplay;
1022                         sce->gm.freqplay = sce->r.freqplay;
1023                         sce->gm.depth = sce->r.depth;
1024
1025                         /* Physic (previously stored in world) */
1026                         sce->gm.gravity =9.8f;
1027                         sce->gm.physicsEngine = WOPHY_BULLET; /* Bullet by default */
1028                         sce->gm.mode = WO_DBVT_CULLING; /* DBVT culling by default */
1029                         sce->gm.occlusionRes = 128;
1030                         sce->gm.ticrate = 60;
1031                         sce->gm.maxlogicstep = 5;
1032                         sce->gm.physubstep = 1;
1033                         sce->gm.maxphystep = 5;
1034                 }
1035         }
1036
1037         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 2)) {
1038                 Scene *sce;
1039                 Object *ob;
1040
1041                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1042                         if (fd->fileflags & G_FILE_ENABLE_ALL_FRAMES)
1043                                 sce->gm.flag |= GAME_ENABLE_ALL_FRAMES;
1044                         if (fd->fileflags & G_FILE_SHOW_DEBUG_PROPS)
1045                                 sce->gm.flag |= GAME_SHOW_DEBUG_PROPS;
1046                         if (fd->fileflags & G_FILE_SHOW_FRAMERATE)
1047                                 sce->gm.flag |= GAME_SHOW_FRAMERATE;
1048                         if (fd->fileflags & G_FILE_SHOW_PHYSICS)
1049                                 sce->gm.flag |= GAME_SHOW_PHYSICS;
1050                         if (fd->fileflags & G_FILE_GLSL_NO_SHADOWS)
1051                                 sce->gm.flag |= GAME_GLSL_NO_SHADOWS;
1052                         if (fd->fileflags & G_FILE_GLSL_NO_SHADERS)
1053                                 sce->gm.flag |= GAME_GLSL_NO_SHADERS;
1054                         if (fd->fileflags & G_FILE_GLSL_NO_RAMPS)
1055                                 sce->gm.flag |= GAME_GLSL_NO_RAMPS;
1056                         if (fd->fileflags & G_FILE_GLSL_NO_NODES)
1057                                 sce->gm.flag |= GAME_GLSL_NO_NODES;
1058                         if (fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX)
1059                                 sce->gm.flag |= GAME_GLSL_NO_EXTRA_TEX;
1060                         if (fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS)
1061                                 sce->gm.flag |= GAME_IGNORE_DEPRECATION_WARNINGS;
1062
1063                         if (fd->fileflags & G_FILE_GAME_MAT_GLSL)
1064                                 sce->gm.matmode = GAME_MAT_GLSL;
1065                         else if (fd->fileflags & G_FILE_GAME_MAT)
1066                                 sce->gm.matmode = GAME_MAT_MULTITEX;
1067                         else
1068                                 sce->gm.matmode = GAME_MAT_TEXFACE;
1069
1070                         sce->gm.flag |= GAME_DISPLAY_LISTS;
1071                 }
1072
1073                 for (ob = main->object.first; ob; ob = ob->id.next) {
1074                         if (ob->flag & 8192) // OB_POSEMODE = 8192
1075                                 ob->mode |= OB_MODE_POSE;
1076                 }
1077         }
1078
1079         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 4)) {
1080                 Scene *sce;
1081                 Object *ob;
1082                 Material *ma;
1083                 Lamp *la;
1084                 World *wo;
1085                 Tex *tex;
1086                 ParticleSettings *part;
1087                 int do_gravity = FALSE;
1088
1089                 for (sce = main->scene.first; sce; sce = sce->id.next)
1090                         if (sce->unit.scale_length == 0.0f)
1091                                 sce->unit.scale_length = 1.0f;
1092
1093                 for (ob = main->object.first; ob; ob = ob->id.next) {
1094                         /* fluid-sim stuff */
1095                         FluidsimModifierData *fluidmd = (FluidsimModifierData *) modifiers_findByType(ob, eModifierType_Fluidsim);
1096                         if (fluidmd)
1097                                 fluidmd->fss->fmd = fluidmd;
1098
1099                         /* rotation modes were added, but old objects would now default to being 'quaternion based' */
1100                         ob->rotmode = ROT_MODE_EUL;
1101                 }
1102
1103                 for (ma = main->mat.first; ma; ma = ma->id.next) {
1104                         if (ma->vol.reflection == 0.f) {
1105                                 ma->vol.reflection = 1.f;
1106                                 ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f;
1107                                 ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f;
1108                         }
1109
1110                         do_version_mtex_factor_2_50(ma->mtex, ID_MA);
1111                 }
1112
1113                 for (la = main->lamp.first; la; la = la->id.next)
1114                         do_version_mtex_factor_2_50(la->mtex, ID_LA);
1115
1116                 for (wo = main->world.first; wo; wo = wo->id.next)
1117                         do_version_mtex_factor_2_50(wo->mtex, ID_WO);
1118
1119                 for (tex = main->tex.first; tex; tex = tex->id.next)
1120                         if (tex->vd)
1121                                 if (tex->vd->extend == 0)
1122                                         tex->vd->extend = TEX_CLIP;
1123
1124                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1125                         if (sce->audio.main == 0.0f)
1126                                 sce->audio.main = 1.0f;
1127
1128                         sce->r.ffcodecdata.audio_mixrate = sce->audio.mixrate;
1129                         sce->r.ffcodecdata.audio_volume = sce->audio.main;
1130                         sce->audio.distance_model = 2;
1131                         sce->audio.doppler_factor = 1.0f;
1132                         sce->audio.speed_of_sound = 343.3f;
1133                 }
1134
1135                 /* Add default gravity to scenes */
1136                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1137                         if ((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0 &&
1138                             len_v3(sce->physics_settings.gravity) == 0.0f)
1139                         {
1140                                 sce->physics_settings.gravity[0] = sce->physics_settings.gravity[1] = 0.0f;
1141                                 sce->physics_settings.gravity[2] = -9.81f;
1142                                 sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
1143                                 do_gravity = TRUE;
1144                         }
1145                 }
1146
1147                 /* Assign proper global gravity weights for dynamics (only z-coordinate is taken into account) */
1148                 if (do_gravity) {
1149                         for (part = main->particle.first; part; part = part->id.next)
1150                                 part->effector_weights->global_gravity = part->acc[2]/-9.81f;
1151                 }
1152
1153                 for (ob = main->object.first; ob; ob = ob->id.next) {
1154                         ModifierData *md;
1155
1156                         if (do_gravity) {
1157                                 for (md = ob->modifiers.first; md; md = md->next) {
1158                                         ClothModifierData *clmd = (ClothModifierData *) modifiers_findByType(ob, eModifierType_Cloth);
1159                                         if (clmd)
1160                                                 clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2]/-9.81f;
1161                                 }
1162
1163                                 if (ob->soft)
1164                                         ob->soft->effector_weights->global_gravity = ob->soft->grav/9.81f;
1165                         }
1166
1167                         /* Normal wind shape is plane */
1168                         if (ob->pd) {
1169                                 if (ob->pd->forcefield == PFIELD_WIND)
1170                                         ob->pd->shape = PFIELD_SHAPE_PLANE;
1171
1172                                 if (ob->pd->flag & PFIELD_PLANAR)
1173                                         ob->pd->shape = PFIELD_SHAPE_PLANE;
1174                                 else if (ob->pd->flag & PFIELD_SURFACE)
1175                                         ob->pd->shape = PFIELD_SHAPE_SURFACE;
1176
1177                                 ob->pd->flag |= PFIELD_DO_LOCATION;
1178                         }
1179                 }
1180         }
1181
1182         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 6)) {
1183                 Object *ob;
1184                 Lamp *la;
1185
1186                 /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialization */
1187                 for (ob = main->object.first; ob; ob = ob->id.next) {
1188                         /* new variables for all objects */
1189                         ob->quat[0] = 1.0f;
1190                         ob->rotAxis[1] = 1.0f;
1191
1192                         /* bones */
1193                         if (ob->pose) {
1194                                 bPoseChannel *pchan;
1195
1196                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1197                                         /* just need to initalise rotation axis properly... */
1198                                         pchan->rotAxis[1] = 1.0f;
1199                                 }
1200                         }
1201                 }
1202
1203                 for (la = main->lamp.first; la; la = la->id.next)
1204                         la->compressthresh = 0.05f;
1205         }
1206
1207         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 7)) {
1208                 Mesh *me;
1209                 Nurb *nu;
1210                 Lattice *lt;
1211                 Curve *cu;
1212                 Key *key;
1213                 float *data;
1214                 int a, tot;
1215
1216                 /* shape keys are no longer applied to the mesh itself, but rather
1217                  * to the derivedmesh/displist, so here we ensure that the basis
1218                  * shape key is always set in the mesh coordinates. */
1219                 for (me = main->mesh.first; me; me = me->id.next) {
1220                         if ((key = blo_do_versions_newlibadr(fd, lib, me->key)) && key->refkey) {
1221                                 data = key->refkey->data;
1222                                 tot = MIN2(me->totvert, key->refkey->totelem);
1223
1224                                 for (a = 0; a < tot; a++, data += 3)
1225                                         copy_v3_v3(me->mvert[a].co, data);
1226                         }
1227                 }
1228
1229                 for (lt = main->latt.first; lt; lt = lt->id.next) {
1230                         if ((key = blo_do_versions_newlibadr(fd, lib, lt->key)) && key->refkey) {
1231                                 data = key->refkey->data;
1232                                 tot = MIN2(lt->pntsu*lt->pntsv*lt->pntsw, key->refkey->totelem);
1233
1234                                 for (a = 0; a < tot; a++, data += 3)
1235                                         copy_v3_v3(lt->def[a].vec, data);
1236                         }
1237                 }
1238
1239                 for (cu = main->curve.first; cu; cu = cu->id.next) {
1240                         if ((key = blo_do_versions_newlibadr(fd, lib, cu->key)) && key->refkey) {
1241                                 data = key->refkey->data;
1242
1243                                 for (nu = cu->nurb.first; nu; nu = nu->next) {
1244                                         if (nu->bezt) {
1245                                                 BezTriple *bezt = nu->bezt;
1246
1247                                                 for (a = 0; a < nu->pntsu; a++, bezt++) {
1248                                                         copy_v3_v3(bezt->vec[0], data); data+=3;
1249                                                         copy_v3_v3(bezt->vec[1], data); data+=3;
1250                                                         copy_v3_v3(bezt->vec[2], data); data+=3;
1251                                                         bezt->alfa = *data; data++;
1252                                                 }
1253                                         }
1254                                         else if (nu->bp) {
1255                                                 BPoint *bp = nu->bp;
1256
1257                                                 for (a = 0; a < nu->pntsu*nu->pntsv; a++, bp++) {
1258                                                         copy_v3_v3(bp->vec, data); data += 3;
1259                                                         bp->alfa = *data; data++;
1260                                                 }
1261                                         }
1262                                 }
1263                         }
1264                 }
1265         }
1266
1267         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 8)) {
1268                 {
1269                         Scene *sce = main->scene.first;
1270                         while (sce) {
1271                                 if (sce->r.frame_step == 0)
1272                                         sce->r.frame_step = 1;
1273                                 if (sce->r.mblur_samples == 0)
1274                                         sce->r.mblur_samples = sce->r.osa;
1275
1276                                 if (sce->ed && sce->ed->seqbase.first) {
1277                                         do_versions_seq_unique_name_all_strips(sce, &sce->ed->seqbase);
1278                                 }
1279
1280                                 sce = sce->id.next;
1281                         }
1282                 }
1283
1284                 {
1285                         /* ensure all nodes have unique names */
1286                         bNodeTree *ntree = main->nodetree.first;
1287                         while (ntree) {
1288                                 bNode *node = ntree->nodes.first;
1289
1290                                 while (node) {
1291                                         nodeUniqueName(ntree, node);
1292                                         node = node->next;
1293                                 }
1294
1295                                 ntree = ntree->id.next;
1296                         }
1297                 }
1298
1299                 {
1300                         Object *ob = main->object.first;
1301                         while (ob) {
1302                                 /* shaded mode disabled for now */
1303                                 if (ob->dt == OB_MATERIAL)
1304                                         ob->dt = OB_TEXTURE;
1305                                 ob = ob->id.next;
1306                         }
1307                 }
1308
1309                 {
1310                         bScreen *screen;
1311                         ScrArea *sa;
1312                         SpaceLink *sl;
1313
1314                         for (screen = main->screen.first; screen; screen = screen->id.next) {
1315                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1316                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1317                                                 if (sl->spacetype == SPACE_VIEW3D) {
1318                                                         View3D *v3d = (View3D *) sl;
1319                                                         if (v3d->drawtype == OB_MATERIAL)
1320                                                                 v3d->drawtype = OB_SOLID;
1321                                                 }
1322                                         }
1323                                 }
1324                         }
1325                 }
1326
1327                 /* only convert old 2.50 files with color management */
1328                 if (main->versionfile == 250) {
1329                         Scene *sce = main->scene.first;
1330                         Material *ma = main->mat.first;
1331                         World *wo = main->world.first;
1332                         Tex *tex = main->tex.first;
1333                         int i, convert = 0;
1334
1335                         /* convert to new color management system:
1336                          * while previously colors were stored as srgb,
1337                          * now they are stored as linear internally,
1338                          * with screen gamma correction in certain places in the UI. */
1339
1340                         /* don't know what scene is active, so we'll convert if any scene has it enabled... */
1341                         while (sce) {
1342                                 if (sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
1343                                         convert = 1;
1344                                 sce = sce->id.next;
1345                         }
1346
1347                         if (convert) {
1348                                 while (ma) {
1349                                         if (ma->ramp_col) {
1350                                                 ColorBand *band = (ColorBand *)ma->ramp_col;
1351                                                 for (i = 0; i < band->tot; i++) {
1352                                                         CBData *data = band->data + i;
1353                                                         srgb_to_linearrgb_v3_v3(&data->r, &data->r);
1354                                                 }
1355                                         }
1356
1357                                         if (ma->ramp_spec) {
1358                                                 ColorBand *band = (ColorBand *)ma->ramp_spec;
1359                                                 for (i = 0; i < band->tot; i++) {
1360                                                         CBData *data = band->data + i;
1361                                                         srgb_to_linearrgb_v3_v3(&data->r, &data->r);
1362                                                 }
1363                                         }
1364
1365                                         srgb_to_linearrgb_v3_v3(&ma->r, &ma->r);
1366                                         srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr);
1367                                         srgb_to_linearrgb_v3_v3(&ma->mirr, &ma->mirr);
1368                                         srgb_to_linearrgb_v3_v3(ma->sss_col, ma->sss_col);
1369                                         ma = ma->id.next;
1370                                 }
1371
1372                                 while (tex) {
1373                                         if (tex->coba) {
1374                                                 ColorBand *band = (ColorBand *)tex->coba;
1375                                                 for (i = 0; i < band->tot; i++) {
1376                                                         CBData *data = band->data + i;
1377                                                         srgb_to_linearrgb_v3_v3(&data->r, &data->r);
1378                                                 }
1379                                         }
1380                                         tex = tex->id.next;
1381                                 }
1382
1383                                 while (wo) {
1384                                         srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr);
1385                                         srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr);
1386                                         srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr);
1387                                         wo = wo->id.next;
1388                                 }
1389                         }
1390                 }
1391         }
1392
1393         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9)) {
1394                 Scene *sce;
1395                 Mesh *me;
1396                 Object *ob;
1397
1398                 for (sce = main->scene.first; sce; sce = sce->id.next)
1399                         if (!sce->toolsettings->particle.selectmode)
1400                                 sce->toolsettings->particle.selectmode = SCE_SELECT_PATH;
1401
1402                 if (main->versionfile == 250 && main->subversionfile > 1) {
1403                         for (me = main->mesh.first; me; me = me->id.next)
1404                                 multires_load_old_250(me);
1405
1406                         for (ob = main->object.first; ob; ob = ob->id.next) {
1407                                 MultiresModifierData *mmd = (MultiresModifierData *) modifiers_findByType(ob, eModifierType_Multires);
1408
1409                                 if (mmd) {
1410                                         mmd->totlvl--;
1411                                         mmd->lvl--;
1412                                         mmd->sculptlvl = mmd->lvl;
1413                                         mmd->renderlvl = mmd->lvl;
1414                                 }
1415                         }
1416                 }
1417         }
1418
1419         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 10)) {
1420                 Object *ob;
1421
1422                 /* properly initialize hair clothsim data on old files */
1423                 for (ob = main->object.first; ob; ob = ob->id.next) {
1424                         ModifierData *md;
1425                         for (md = ob->modifiers.first; md; md = md->next) {
1426                                 if (md->type == eModifierType_Cloth) {
1427                                         ClothModifierData *clmd = (ClothModifierData *)md;
1428                                         if (clmd->sim_parms->velocity_smooth < 0.01f)
1429                                                 clmd->sim_parms->velocity_smooth = 0.f;
1430                                 }
1431                         }
1432                 }
1433         }
1434
1435         /* fix bad area setup in subversion 10 */
1436         if (main->versionfile == 250 && main->subversionfile == 10) {
1437                 /* fix for new view type in sequencer */
1438                 bScreen *screen;
1439                 ScrArea *sa;
1440                 SpaceLink *sl;
1441
1442                 /* remove all preview window in wrong spaces */
1443                 for (screen = main->screen.first; screen; screen = screen->id.next) {
1444                         for (sa = screen->areabase.first; sa; sa = sa->next) {
1445                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1446                                         if (sl->spacetype != SPACE_SEQ) {
1447                                                 ARegion *ar;
1448                                                 ListBase *regionbase;
1449
1450                                                 if (sl == sa->spacedata.first) {
1451                                                         regionbase = &sa->regionbase;
1452                                                 }
1453                                                 else {
1454                                                         regionbase = &sl->regionbase;
1455                                                 }
1456
1457                                                 for (ar = regionbase->first; ar; ar = ar->next) {
1458                                                         if (ar->regiontype == RGN_TYPE_PREVIEW)
1459                                                                 break;
1460                                                 }
1461
1462                                                 if (ar && (ar->regiontype == RGN_TYPE_PREVIEW)) {
1463                                                         SpaceType *st = BKE_spacetype_from_id(SPACE_SEQ);
1464                                                         BKE_area_region_free(st, ar);
1465                                                         BLI_freelinkN(regionbase, ar);
1466                                                 }
1467                                         }
1468                                 }
1469                         }
1470                 }
1471         }
1472
1473         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 11)) {
1474                 {
1475                         /* fix for new view type in sequencer */
1476                         bScreen *screen;
1477                         ScrArea *sa;
1478                         SpaceLink *sl;
1479
1480                         for (screen = main->screen.first; screen; screen = screen->id.next) {
1481                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1482                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1483                                                 if (sl->spacetype == SPACE_SEQ) {
1484                                                         ARegion *ar;
1485                                                         ARegion *ar_main;
1486                                                         ListBase *regionbase;
1487                                                         SpaceSeq *sseq = (SpaceSeq *)sl;
1488
1489                                                         if (sl == sa->spacedata.first) {
1490                                                                 regionbase = &sa->regionbase;
1491                                                         }
1492                                                         else {
1493                                                                 regionbase = &sl->regionbase;
1494                                                         }
1495
1496                                                         if (sseq->view == 0)
1497                                                                 sseq->view = SEQ_VIEW_SEQUENCE;
1498                                                         if (sseq->mainb == 0)
1499                                                                 sseq->mainb = SEQ_DRAW_IMG_IMBUF;
1500
1501                                                         ar_main = (ARegion*)regionbase->first;
1502                                                         for (; ar_main; ar_main = ar_main->next) {
1503                                                                 if (ar_main->regiontype == RGN_TYPE_WINDOW)
1504                                                                         break;
1505                                                         }
1506                                                         ar = MEM_callocN(sizeof(ARegion), "preview area for sequencer");
1507                                                         BLI_insertlinkbefore(regionbase, ar_main, ar);
1508                                                         sequencer_init_preview_region(ar);
1509                                                 }
1510                                         }
1511                                 }
1512                         }
1513                 }
1514         }
1515
1516         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 12)) {
1517                 Scene *sce;
1518                 Object *ob;
1519                 Brush *brush;
1520                 Material *ma;
1521
1522                 /* game engine changes */
1523                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1524                         sce->gm.eyeseparation = 0.10f;
1525                 }
1526
1527                 /* anim viz changes */
1528                 for (ob = main->object.first; ob; ob = ob->id.next) {
1529                         /* initialize object defaults */
1530                         animviz_settings_init(&ob->avs);
1531
1532                         /* if armature, copy settings for pose from armature data
1533                          * performing initialization where appropriate
1534                          */
1535                         if (ob->pose && ob->data) {
1536                                 bArmature *arm = blo_do_versions_newlibadr(fd, lib, ob->data);
1537                                 if (arm) { /* XXX - why does this fail in some cases? */
1538                                         bAnimVizSettings *avs = &ob->pose->avs;
1539
1540                                         /* ghosting settings ---------------- */
1541                                                 /* ranges */
1542                                         avs->ghost_bc = avs->ghost_ac = arm->ghostep;
1543
1544                                         avs->ghost_sf = arm->ghostsf;
1545                                         avs->ghost_ef = arm->ghostef;
1546                                         if ((avs->ghost_sf == avs->ghost_ef) && (avs->ghost_sf == 0)) {
1547                                                 avs->ghost_sf = 1;
1548                                                 avs->ghost_ef = 100;
1549                                         }
1550
1551                                                 /* type */
1552                                         if (arm->ghostep == 0)
1553                                                 avs->ghost_type = GHOST_TYPE_NONE;
1554                                         else
1555                                                 avs->ghost_type = arm->ghosttype + 1;
1556
1557                                                 /* stepsize */
1558                                         avs->ghost_step = arm->ghostsize;
1559                                         if (avs->ghost_step == 0)
1560                                                 avs->ghost_step = 1;
1561
1562                                         /* path settings --------------------- */
1563                                                 /* ranges */
1564                                         avs->path_bc = arm->pathbc;
1565                                         avs->path_ac = arm->pathac;
1566                                         if ((avs->path_bc == avs->path_ac) && (avs->path_bc == 0))
1567                                                 avs->path_bc = avs->path_ac = 10;
1568
1569                                         avs->path_sf = arm->pathsf;
1570                                         avs->path_ef = arm->pathef;
1571                                         if ((avs->path_sf == avs->path_ef) && (avs->path_sf == 0)) {
1572                                                 avs->path_sf = 1;
1573                                                 avs->path_ef = 250;
1574                                         }
1575
1576                                                 /* flags */
1577                                         if (arm->pathflag & ARM_PATH_FNUMS)
1578                                                 avs->path_viewflag |= MOTIONPATH_VIEW_FNUMS;
1579                                         if (arm->pathflag & ARM_PATH_KFRAS)
1580                                                 avs->path_viewflag |= MOTIONPATH_VIEW_KFRAS;
1581                                         if (arm->pathflag & ARM_PATH_KFNOS)
1582                                                 avs->path_viewflag |= MOTIONPATH_VIEW_KFNOS;
1583
1584                                                 /* bake flags */
1585                                         if (arm->pathflag & ARM_PATH_HEADS)
1586                                                 avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS;
1587
1588                                                 /* type */
1589                                         if (arm->pathflag & ARM_PATH_ACFRA)
1590                                                 avs->path_type = MOTIONPATH_TYPE_ACFRA;
1591
1592                                                 /* stepsize */
1593                                         avs->path_step = arm->pathsize;
1594                                         if (avs->path_step == 0)
1595                                                 avs->path_step = 1;
1596                                 }
1597                                 else
1598                                         animviz_settings_init(&ob->pose->avs);
1599                         }
1600                 }
1601
1602                 /* brush texture changes */
1603                 for (brush = main->brush.first; brush; brush = brush->id.next) {
1604                         default_mtex(&brush->mtex);
1605                 }
1606
1607                 for (ma = main->mat.first; ma; ma = ma->id.next) {
1608                         if (ma->vol.ms_spread < 0.0001f) {
1609                                 ma->vol.ms_spread = 0.2f;
1610                                 ma->vol.ms_diff = 1.f;
1611                                 ma->vol.ms_intensity = 1.f;
1612                         }
1613                 }
1614         }
1615
1616         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 13)) {
1617                 /* NOTE: if you do more conversion, be sure to do it outside of this and
1618                  * increase subversion again, otherwise it will not be correct */
1619                 Object *ob;
1620
1621                 /* convert degrees to radians for internal use */
1622                 for (ob = main->object.first; ob; ob = ob->id.next) {
1623                         bPoseChannel *pchan;
1624
1625                         do_version_constraints_radians_degrees_250(&ob->constraints);
1626
1627                         if (ob->pose) {
1628                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1629                                         pchan->limitmin[0] *= (float)(M_PI / 180.0);
1630                                         pchan->limitmin[1] *= (float)(M_PI / 180.0);
1631                                         pchan->limitmin[2] *= (float)(M_PI / 180.0);
1632                                         pchan->limitmax[0] *= (float)(M_PI / 180.0);
1633                                         pchan->limitmax[1] *= (float)(M_PI / 180.0);
1634                                         pchan->limitmax[2] *= (float)(M_PI / 180.0);
1635
1636                                         do_version_constraints_radians_degrees_250(&pchan->constraints);
1637                                 }
1638                         }
1639                 }
1640         }
1641
1642         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 14)) {
1643                 /* fix for bad View2D extents for Animation Editors */
1644                 bScreen *screen;
1645                 ScrArea *sa;
1646                 SpaceLink *sl;
1647
1648                 for (screen = main->screen.first; screen; screen = screen->id.next) {
1649                         for (sa = screen->areabase.first; sa; sa = sa->next) {
1650                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1651                                         ListBase *regionbase;
1652                                         ARegion *ar;
1653
1654                                         if (sl == sa->spacedata.first)
1655                                                 regionbase = &sa->regionbase;
1656                                         else
1657                                                 regionbase = &sl->regionbase;
1658
1659                                         if (ELEM(sl->spacetype, SPACE_ACTION, SPACE_NLA)) {
1660                                                 for (ar = (ARegion*) regionbase->first; ar; ar = ar->next) {
1661                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
1662                                                                 ar->v2d.cur.ymax = ar->v2d.tot.ymax = 0.0f;
1663                                                                 ar->v2d.cur.ymin = ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
1664                                                         }
1665                                                 }
1666                                         }
1667                                 }
1668                         }
1669                 }
1670         }
1671
1672         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 15)) {
1673                 World *wo;
1674                 Material *ma;
1675
1676                 /* ambient default from 0.5f to 1.0f */
1677                 for (ma = main->mat.first; ma; ma = ma->id.next)
1678                         ma->amb *= 2.0f;
1679
1680                 for (wo = main->world.first; wo; wo = wo->id.next) {
1681                         /* ao splitting into ao/env/indirect */
1682                         wo->ao_env_energy = wo->aoenergy;
1683                         wo->aoenergy = 1.0f;
1684
1685                         if (wo->ao_indirect_bounces == 0)
1686                                 wo->ao_indirect_bounces = 1;
1687                         else
1688                                 wo->mode |= WO_INDIRECT_LIGHT;
1689
1690                         if (wo->aomix == WO_AOSUB)
1691                                 wo->ao_env_energy = -wo->ao_env_energy;
1692                         else if (wo->aomix == WO_AOADDSUB)
1693                                 wo->mode |= WO_AMB_OCC;
1694
1695                         wo->aomix = WO_AOMUL;
1696
1697                         /* ambient default from 0.5f to 1.0f */
1698                         mul_v3_fl(&wo->ambr, 0.5f);
1699                         wo->ao_env_energy *= 0.5f;
1700                 }
1701         }
1702
1703         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 17)) {
1704                 Scene *sce;
1705                 Sequence *seq;
1706                 Material *ma;
1707
1708                 /* initialize to sane default so toggling on border shows something */
1709                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1710                         if (sce->r.border.xmin == 0.0f && sce->r.border.ymin == 0.0f &&
1711                             sce->r.border.xmax == 0.0f && sce->r.border.ymax == 0.0f)
1712                         {
1713                                 sce->r.border.xmin = 0.0f;
1714                                 sce->r.border.ymin = 0.0f;
1715                                 sce->r.border.xmax = 1.0f;
1716                                 sce->r.border.ymax = 1.0f;
1717                         }
1718
1719                         if ((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0)
1720                                 sce->r.ffcodecdata.audio_codec = 0x0; // CODEC_ID_NONE
1721
1722                         SEQ_BEGIN (sce->ed, seq)
1723                         {
1724                                 seq->volume = 1.0f;
1725                         }
1726                         SEQ_END
1727                 }
1728
1729                 /* particle brush strength factor was changed from int to float */
1730                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1731                         ParticleEditSettings *pset = &sce->toolsettings->particle;
1732                         int a;
1733
1734                         for (a = 0; a < PE_TOT_BRUSH; a++)
1735                                 pset->brush[a].strength /= 100.0f;
1736                 }
1737
1738                 for (ma = main->mat.first; ma; ma = ma->id.next)
1739                         if (ma->mode & MA_TRACEBLE)
1740                                 ma->shade_flag |= MA_APPROX_OCCLUSION;
1741
1742                 /* sequencer changes */
1743                 {
1744                         bScreen *screen;
1745                         ScrArea *sa;
1746                         SpaceLink *sl;
1747
1748                         for (screen = main->screen.first; screen; screen = screen->id.next) {
1749                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1750                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1751                                                 if (sl->spacetype == SPACE_SEQ) {
1752                                                         ARegion *ar_preview;
1753                                                         ListBase *regionbase;
1754
1755                                                         if (sl == sa->spacedata.first) {
1756                                                                 regionbase = &sa->regionbase;
1757                                                         }
1758                                                         else {
1759                                                                 regionbase = &sl->regionbase;
1760                                                         }
1761
1762                                                         ar_preview = (ARegion*) regionbase->first;
1763                                                         for (; ar_preview; ar_preview = ar_preview->next) {
1764                                                                 if (ar_preview->regiontype == RGN_TYPE_PREVIEW)
1765                                                                         break;
1766                                                         }
1767                                                         if (ar_preview && (ar_preview->regiontype == RGN_TYPE_PREVIEW)) {
1768                                                                 sequencer_init_preview_region(ar_preview);
1769                                                         }
1770                                                 }
1771                                         }
1772                                 }
1773                         }
1774                 } /* sequencer changes */
1775         }
1776
1777         if (main->versionfile <= 251) { /* 2.5.1 had no subversions */
1778                 bScreen *sc;
1779
1780                 /* Blender 2.5.2 - subversion 0 introduced a new setting: V3D_RENDER_OVERRIDE.
1781                  * This bit was used in the past for V3D_TRANSFORM_SNAP, which is now deprecated.
1782                  * Here we clear it for old files so they don't come in with V3D_RENDER_OVERRIDE set,
1783                  * which would cause cameras, lamps, etc to become invisible */
1784                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1785                         ScrArea *sa;
1786                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1787                                 SpaceLink *sl;
1788                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1789                                         if (sl->spacetype == SPACE_VIEW3D) {
1790                                                 View3D* v3d = (View3D *)sl;
1791                                                 v3d->flag2 &= ~V3D_RENDER_OVERRIDE;
1792                                         }
1793                                 }
1794                         }
1795                 }
1796         }
1797
1798         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 1)) {
1799                 Brush *brush;
1800                 Object *ob;
1801                 Scene *scene;
1802                 bNodeTree *ntree;
1803
1804                 for (brush = main->brush.first; brush; brush = brush->id.next) {
1805                         if (brush->curve)
1806                                 brush->curve->preset = CURVE_PRESET_SMOOTH;
1807                 }
1808
1809                 /* properly initialize active flag for fluidsim modifiers */
1810                 for (ob = main->object.first; ob; ob = ob->id.next) {
1811                         ModifierData *md;
1812                         for (md = ob->modifiers.first; md; md = md->next) {
1813                                 if (md->type == eModifierType_Fluidsim) {
1814                                         FluidsimModifierData *fmd = (FluidsimModifierData *) md;
1815                                         fmd->fss->flag |= OB_FLUIDSIM_ACTIVE;
1816                                         fmd->fss->flag |= OB_FLUIDSIM_OVERRIDE_TIME;
1817                                 }
1818                         }
1819                 }
1820
1821                 /* adjustment to color balance node values */
1822                 for (scene = main->scene.first; scene; scene = scene->id.next) {
1823                         if (scene->nodetree) {
1824                                 bNode *node = scene->nodetree->nodes.first;
1825
1826                                 while (node) {
1827                                         if (node->type == CMP_NODE_COLORBALANCE) {
1828                                                 NodeColorBalance *n = (NodeColorBalance *) node->storage;
1829                                                 n->lift[0] += 1.f;
1830                                                 n->lift[1] += 1.f;
1831                                                 n->lift[2] += 1.f;
1832                                         }
1833                                         node = node->next;
1834                                 }
1835                         }
1836                 }
1837                 /* check inside node groups too */
1838                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) {
1839                         bNode *node = ntree->nodes.first;
1840
1841                         while (node) {
1842                                 if (node->type == CMP_NODE_COLORBALANCE) {
1843                                         NodeColorBalance *n = (NodeColorBalance *) node->storage;
1844                                         n->lift[0] += 1.f;
1845                                         n->lift[1] += 1.f;
1846                                         n->lift[2] += 1.f;
1847                                 }
1848
1849                                 node = node->next;
1850                         }
1851                 }
1852         }
1853
1854         /* old-track -> constraints (this time we're really doing it!) */
1855         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 2)) {
1856                 Object *ob;
1857
1858                 for (ob = main->object.first; ob; ob = ob->id.next)
1859                         blo_do_version_old_trackto_to_constraints(ob);
1860         }
1861
1862         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 5)) {
1863                 bScreen *sc;
1864
1865                 /* Image editor scopes */
1866                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1867                         ScrArea *sa;
1868
1869                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1870                                 SpaceLink *sl;
1871
1872                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1873                                         if (sl->spacetype == SPACE_IMAGE) {
1874                                                 SpaceImage *sima = (SpaceImage *) sl;
1875                                                 scopes_new(&sima->scopes);
1876                                         }
1877                                 }
1878                         }
1879                 }
1880         }
1881
1882         if (main->versionfile < 253) {
1883                 Object *ob;
1884                 Scene *scene;
1885                 bScreen *sc;
1886                 Tex *tex;
1887                 Brush *brush;
1888
1889                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1890                         ScrArea *sa;
1891                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1892                                 SpaceLink *sl;
1893
1894                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1895                                         if (sl->spacetype == SPACE_NODE) {
1896                                                 SpaceNode *snode = (SpaceNode *) sl;
1897                                                 ListBase *regionbase;
1898                                                 ARegion *ar;
1899
1900                                                 if (sl == sa->spacedata.first)
1901                                                         regionbase = &sa->regionbase;
1902                                                 else
1903                                                         regionbase = &sl->regionbase;
1904
1905                                                 if (snode->v2d.minzoom > 0.09f)
1906                                                         snode->v2d.minzoom = 0.09f;
1907                                                 if (snode->v2d.maxzoom < 2.31f)
1908                                                         snode->v2d.maxzoom = 2.31f;
1909
1910                                                 for (ar = regionbase->first; ar; ar = ar->next) {
1911                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
1912                                                                 if (ar->v2d.minzoom > 0.09f)
1913                                                                         ar->v2d.minzoom = 0.09f;
1914                                                                 if (ar->v2d.maxzoom < 2.31f)
1915                                                                         ar->v2d.maxzoom = 2.31f;
1916                                                         }
1917                                                 }
1918                                         }
1919                                         else if (sl->spacetype == SPACE_TIME) {
1920                                                 SpaceTime *stime = (SpaceTime *) sl;
1921
1922                                                 /* enable all cache display */
1923                                                 stime->cache_display |= TIME_CACHE_DISPLAY;
1924                                                 stime->cache_display |= (TIME_CACHE_SOFTBODY|TIME_CACHE_PARTICLES);
1925                                                 stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE|TIME_CACHE_DYNAMICPAINT);
1926                                         }
1927                                 }
1928                         }
1929                 }
1930
1931                 do_version_mdef_250(main);
1932
1933                 /* parent type to modifier */
1934                 for (ob = main->object.first; ob; ob = ob->id.next) {
1935                         if (ob->parent) {
1936                                 Object *parent = (Object *) blo_do_versions_newlibadr(fd, lib, ob->parent);
1937                                 if (parent) { /* parent may not be in group */
1938                                         if (parent->type == OB_ARMATURE && ob->partype == PARSKEL) {
1939                                                 ArmatureModifierData *amd;
1940                                                 bArmature *arm = (bArmature *) blo_do_versions_newlibadr(fd, lib, parent->data);
1941
1942                                                 amd = (ArmatureModifierData*) modifier_new(eModifierType_Armature);
1943                                                 amd->object = ob->parent;
1944                                                 BLI_addtail((ListBase*)&ob->modifiers, amd);
1945                                                 amd->deformflag = arm->deformflag;
1946                                                 ob->partype = PAROBJECT;
1947                                         }
1948                                         else if (parent->type == OB_LATTICE && ob->partype == PARSKEL) {
1949                                                 LatticeModifierData *lmd;
1950
1951                                                 lmd = (LatticeModifierData*) modifier_new(eModifierType_Lattice);
1952                                                 lmd->object = ob->parent;
1953                                                 BLI_addtail((ListBase*)&ob->modifiers, lmd);
1954                                                 ob->partype = PAROBJECT;
1955                                         }
1956                                         else if (parent->type == OB_CURVE && ob->partype == PARCURVE) {
1957                                                 CurveModifierData *cmd;
1958
1959                                                 cmd = (CurveModifierData*) modifier_new(eModifierType_Curve);
1960                                                 cmd->object = ob->parent;
1961                                                 BLI_addtail((ListBase*)&ob->modifiers, cmd);
1962                                                 ob->partype = PAROBJECT;
1963                                         }
1964                                 }
1965                         }
1966                 }
1967
1968                 /* initialize scene active layer */
1969                 for (scene = main->scene.first; scene; scene = scene->id.next) {
1970                         int i;
1971                         for (i = 0; i < 20; i++) {
1972                                 if (scene->lay & (1<<i)) {
1973                                         scene->layact = 1<<i;
1974                                         break;
1975                                 }
1976                         }
1977                 }
1978
1979                 for (tex = main->tex.first; tex; tex = tex->id.next) {
1980                         /* if youre picky, this isn't correct until we do a version bump
1981                          * since you could set saturation to be 0.0*/
1982                         if (tex->saturation == 0.0f)
1983                                 tex->saturation = 1.0f;
1984                 }
1985
1986                 {
1987                         Curve *cu;
1988                         for (cu = main->curve.first; cu; cu = cu->id.next) {
1989                                 cu->smallcaps_scale = 0.75f;
1990                         }
1991                 }
1992
1993                 for (scene = main->scene.first; scene; scene = scene->id.next) {
1994                         if (scene) {
1995                                 Sequence *seq;
1996                                 SEQ_BEGIN (scene->ed, seq)
1997                                 {
1998                                         if (seq->sat == 0.0f) {
1999                                                 seq->sat = 1.0f;
2000                                         }
2001                                 }
2002                                 SEQ_END
2003                         }
2004                 }
2005
2006                 /* GSOC 2010 Sculpt - New settings for Brush */
2007
2008                 for (brush = main->brush.first; brush; brush = brush->id.next) {
2009                         /* Sanity Check */
2010
2011                         /* infinite number of dabs */
2012                         if (brush->spacing == 0)
2013                                 brush->spacing = 10;
2014
2015                         /* will have no effect */
2016                         if (brush->alpha == 0)
2017                                 brush->alpha = 0.5f;
2018
2019                         /* bad radius */
2020                         if (brush->unprojected_radius == 0)
2021                                 brush->unprojected_radius = 0.125f;
2022
2023                         /* unusable size */
2024                         if (brush->size == 0)
2025                                 brush->size = 35;
2026
2027                         /* can't see overlay */
2028                         if (brush->texture_overlay_alpha == 0)
2029                                 brush->texture_overlay_alpha = 33;
2030
2031                         /* same as draw brush */
2032                         if (brush->crease_pinch_factor == 0)
2033                                 brush->crease_pinch_factor = 0.5f;
2034
2035                         /* will sculpt no vertexes */
2036                         if (brush->plane_trim == 0)
2037                                 brush->plane_trim = 0.5f;
2038
2039                         /* same as smooth stroke off */
2040                         if (brush->smooth_stroke_radius == 0)
2041                                 brush->smooth_stroke_radius = 75;
2042
2043                         /* will keep cursor in one spot */
2044                         if (brush->smooth_stroke_radius == 1)
2045                                 brush->smooth_stroke_factor = 0.9f;
2046
2047                         /* same as dots */
2048                         if (brush->rate == 0)
2049                                 brush->rate = 0.1f;
2050
2051                         /* New Settings */
2052                         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 5)) {
2053                                 brush->flag |= BRUSH_SPACE_ATTEN; // explicitly enable adaptive space
2054
2055                                 /* spacing was originally in pixels, convert it to percentage for new version
2056                                  * size should not be zero due to sanity check above
2057                                  */
2058                                 brush->spacing = (int)(100 * ((float)brush->spacing) / ((float) brush->size));
2059
2060                                 if (brush->add_col[0] == 0 &&
2061                                         brush->add_col[1] == 0 &&
2062                                         brush->add_col[2] == 0)
2063                                 {
2064                                         brush->add_col[0] = 1.00f;
2065                                         brush->add_col[1] = 0.39f;
2066                                         brush->add_col[2] = 0.39f;
2067                                 }
2068
2069                                 if (brush->sub_col[0] == 0 &&
2070                                         brush->sub_col[1] == 0 &&
2071                                         brush->sub_col[2] == 0)
2072                                 {
2073                                         brush->sub_col[0] = 0.39f;
2074                                         brush->sub_col[1] = 0.39f;
2075                                         brush->sub_col[2] = 1.00f;
2076                                 }
2077                         }
2078                 }
2079         }
2080
2081         /* GSOC Sculpt 2010 - Sanity check on Sculpt/Paint settings */
2082         if (main->versionfile < 253) {
2083                 Scene *sce;
2084                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2085                         if (sce->toolsettings->sculpt_paint_unified_alpha == 0)
2086                                 sce->toolsettings->sculpt_paint_unified_alpha = 0.5f;
2087
2088                         if (sce->toolsettings->sculpt_paint_unified_unprojected_radius == 0)
2089                                 sce->toolsettings->sculpt_paint_unified_unprojected_radius = 0.125f;
2090
2091                         if (sce->toolsettings->sculpt_paint_unified_size == 0)
2092                                 sce->toolsettings->sculpt_paint_unified_size = 35;
2093                 }
2094         }
2095
2096         if (main->versionfile < 253 || (main->versionfile == 253 && main->subversionfile < 1)) {
2097                 Object *ob;
2098
2099                 for (ob = main->object.first; ob; ob = ob->id.next) {
2100                         ModifierData *md;
2101
2102                         for (md = ob->modifiers.first; md; md = md->next) {
2103                                 if (md->type == eModifierType_Smoke) {
2104                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2105
2106                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
2107                                                 smd->domain->vorticity = 2.0f;
2108                                                 smd->domain->time_scale = 1.0f;
2109
2110                                                 if (!(smd->domain->flags & (1<<4)))
2111                                                         continue;
2112
2113                                                 /* delete old MOD_SMOKE_INITVELOCITY flag */
2114                                                 smd->domain->flags &= ~(1<<4);
2115
2116                                                 /* for now just add it to all flow objects in the scene */
2117                                                 {
2118                                                         Object *ob2;
2119                                                         for (ob2 = main->object.first; ob2; ob2 = ob2->id.next) {
2120                                                                 ModifierData *md2;
2121                                                                 for (md2 = ob2->modifiers.first; md2; md2 = md2->next) {
2122                                                                         if (md2->type == eModifierType_Smoke) {
2123                                                                                 SmokeModifierData *smd2 = (SmokeModifierData *)md2;
2124
2125                                                                                 if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) {
2126                                                                                         smd2->flow->flags |= MOD_SMOKE_FLOW_INITVELOCITY;
2127                                                                                 }
2128                                                                         }
2129                                                                 }
2130                                                         }
2131                                                 }
2132
2133                                         }
2134                                         else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
2135                                                 smd->flow->vel_multi = 1.0f;
2136                                         }
2137                                 }
2138                         }
2139                 }
2140         }
2141
2142         if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 1)) {
2143                 Brush *br;
2144                 ParticleSettings *part;
2145                 bScreen *sc;
2146                 Object *ob;
2147
2148                 for (br = main->brush.first; br; br = br->id.next) {
2149                         if (br->ob_mode == 0)
2150                                 br->ob_mode = OB_MODE_ALL_PAINT;
2151                 }
2152
2153                 for (part = main->particle.first; part; part = part->id.next) {
2154                         if (part->boids)
2155                                 part->boids->pitch = 1.0f;
2156
2157                         part->flag &= ~PART_HAIR_REGROW; /* this was a deprecated flag before */
2158                         part->kink_amp_clump = 1.f; /* keep old files looking similar */
2159                 }
2160
2161                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2162                         ScrArea *sa;
2163                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2164                                 SpaceLink *sl;
2165                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2166                                         if (sl->spacetype == SPACE_INFO) {
2167                                                 SpaceInfo *sinfo = (SpaceInfo *) sl;
2168                                                 ARegion *ar;
2169
2170                                                 sinfo->rpt_mask = INFO_RPT_OP;
2171
2172                                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
2173                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
2174                                                                 ar->v2d.scroll = (V2D_SCROLL_RIGHT);
2175                                                                 ar->v2d.align = V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y; /* align bottom left */
2176                                                                 ar->v2d.keepofs = V2D_LOCKOFS_X;
2177                                                                 ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
2178                                                                 ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
2179                                                                 ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f;
2180                                                         }
2181                                                 }
2182                                         }
2183                                 }
2184                         }
2185                 }
2186
2187                 /* fix rotation actuators for objects so they use real angles (radians)
2188                  * since before blender went opensource this strange scalar was used: (1 / 0.02) * 2 * math.pi/360 */
2189                 for (ob = main->object.first; ob; ob = ob->id.next) {
2190                         bActuator *act = ob->actuators.first;
2191                         while (act) {
2192                                 if (act->type == ACT_OBJECT) {
2193                                         /* multiply velocity with 50 in old files */
2194                                         bObjectActuator *oa = act->data;
2195                                         mul_v3_fl(oa->drot, 0.8726646259971648f);
2196                                 }
2197                                 act = act->next;
2198                         }
2199                 }
2200         }
2201
2202         /* init facing axis property of steering actuators */
2203         {
2204                 Object *ob;
2205                 for (ob = main->object.first; ob; ob = ob->id.next) {
2206                         bActuator *act;
2207                         for (act = ob->actuators.first; act; act = act->next) {
2208                                 if (act->type == ACT_STEERING) {
2209                                         bSteeringActuator* stact = act->data;
2210                                         if (stact->facingaxis == 0) {
2211                                                 stact->facingaxis = 1;
2212                                         }
2213                                 }
2214                         }
2215                 }
2216         }
2217
2218         if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 3)) {
2219                 Object *ob;
2220
2221                 /* ocean res is now squared, reset old ones - will be massive */
2222                 for (ob = main->object.first; ob; ob = ob->id.next) {
2223                         ModifierData *md;
2224                         for (md = ob->modifiers.first; md; md = md->next) {
2225                                 if (md->type == eModifierType_Ocean) {
2226                                         OceanModifierData *omd = (OceanModifierData *)md;
2227                                         omd->resolution = 7;
2228                                         omd->oceancache = NULL;
2229                                 }
2230                         }
2231                 }
2232         }
2233
2234         if (main->versionfile < 256) {
2235                 bScreen *sc;
2236                 ScrArea *sa;
2237                 Key *key;
2238
2239                 /* Fix for sample line scope initializing with no height */
2240                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2241                         sa = sc->areabase.first;
2242                         while (sa) {
2243                                 SpaceLink *sl;
2244                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2245                                         if (sl->spacetype == SPACE_IMAGE) {
2246                                                 SpaceImage *sima = (SpaceImage *) sl;
2247                                                 if (sima->sample_line_hist.height == 0)
2248                                                         sima->sample_line_hist.height = 100;
2249                                         }
2250                                 }
2251                                 sa = sa->next;
2252                         }
2253                 }
2254
2255                 /* old files could have been saved with slidermin = slidermax = 0.0, but the UI in
2256                  * 2.4x would never reveal this to users as a dummy value always ended up getting used
2257                  * instead
2258                  */
2259                 for (key = main->key.first; key; key = key->id.next) {
2260                         KeyBlock *kb;
2261
2262                         for (kb = key->block.first; kb; kb = kb->next) {
2263                                 if (IS_EQF(kb->slidermin, kb->slidermax) && IS_EQ(kb->slidermax, 0))
2264                                         kb->slidermax = kb->slidermin + 1.0f;
2265                         }
2266                 }
2267         }
2268
2269         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 1)) {
2270                 /* fix for bones that didn't have arm_roll before */
2271                 bArmature *arm;
2272                 Bone *bone;
2273                 Object *ob;
2274
2275                 for (arm = main->armature.first; arm; arm = arm->id.next)
2276                         for (bone = arm->bonebase.first; bone; bone = bone->next)
2277                                 do_version_bone_roll_256(bone);
2278
2279                 /* fix for objects which have zero dquat's
2280                  * since this is multiplied with the quat rather than added */
2281                 for (ob = main->object.first; ob; ob = ob->id.next) {
2282                         if (is_zero_v4(ob->dquat)) {
2283                                 unit_qt(ob->dquat);
2284                         }
2285                         if (is_zero_v3(ob->drotAxis) && ob->drotAngle == 0.0f) {
2286                                 unit_axis_angle(ob->drotAxis, &ob->drotAngle);
2287                         }
2288                 }
2289         }
2290
2291         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)) {
2292                 bNodeTree *ntree;
2293
2294                 /* node sockets are not exposed automatically any more,
2295                  * this mimics the old behavior by adding all unlinked sockets to groups.
2296                  */
2297                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) {
2298                         /* XXX Only setting a flag here. Actual adding of group sockets
2299                          * is done in lib_verify_nodetree, because at this point the internal
2300                          * nodes may not be up-to-date! (missing lib-link)
2301                          */
2302                         ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE;
2303                 }
2304         }
2305
2306         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 3)) {
2307                 bScreen *sc;
2308                 Brush *brush;
2309                 Object *ob;
2310                 ParticleSettings *part;
2311                 Material *mat;
2312                 int tex_nr, transp_tex;
2313
2314                 for (mat = main->mat.first; mat; mat = mat->id.next) {
2315                         if (!(mat->mode & MA_TRANSP) && !(mat->material_type & MA_TYPE_VOLUME)) {
2316                                 transp_tex = 0;
2317
2318                                 for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) {
2319                                         if (!mat->mtex[tex_nr])
2320                                                 continue;
2321                                         if (mat->mtex[tex_nr]->mapto & MAP_ALPHA)
2322                                                 transp_tex = 1;
2323                                 }
2324
2325                                 /* weak! material alpha could be animated */
2326                                 if (mat->alpha < 1.0f || mat->fresnel_tra > 0.0f || transp_tex) {
2327                                         mat->mode |= MA_TRANSP;
2328                                         mat->mode &= ~(MA_ZTRANSP|MA_RAYTRANSP);
2329                                 }
2330                         }
2331                 }
2332
2333                 /* redraws flag in SpaceTime has been moved to Screen level */
2334                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2335                         if (sc->redraws_flag == 0) {
2336                                 /* just initialize to default? */
2337                                 // XXX: we could also have iterated through areas, and taken them from the first timeline available...
2338                                 sc->redraws_flag = TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
2339                         }
2340                 }
2341
2342                 for (brush = main->brush.first; brush; brush = brush->id.next) {
2343                         if (brush->height == 0)
2344                                 brush->height = 0.4f;
2345                 }
2346
2347                 /* replace 'rim material' option for in offset*/
2348                 for (ob = main->object.first; ob; ob = ob->id.next) {
2349                         ModifierData *md;
2350                         for (md = ob->modifiers.first; md; md = md->next) {
2351                                 if (md->type == eModifierType_Solidify) {
2352                                         SolidifyModifierData *smd = (SolidifyModifierData *) md;
2353                                         if (smd->flag & MOD_SOLIDIFY_RIM_MATERIAL) {
2354                                                 smd->mat_ofs_rim = 1;
2355                                                 smd->flag &= ~MOD_SOLIDIFY_RIM_MATERIAL;
2356                                         }
2357                                 }
2358                         }
2359                 }
2360
2361                 /* particle draw color from material */
2362                 for (part = main->particle.first; part; part = part->id.next) {
2363                         if (part->draw & PART_DRAW_MAT_COL)
2364                                 part->draw_col = PART_DRAW_COL_MAT;
2365                 }
2366         }
2367
2368         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 6)) {
2369                 Mesh *me;
2370
2371                 for (me = main->mesh.first; me; me = me->id.next)
2372                         BKE_mesh_calc_normals_tessface(me->mvert, me->totvert, me->mface, me->totface, NULL);
2373         }
2374
2375         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)) {
2376                 /* update blur area sizes from 0..1 range to 0..100 percentage */
2377                 Scene *scene;
2378                 bNode *node;
2379                 for (scene = main->scene.first; scene; scene = scene->id.next)
2380                         if (scene->nodetree)
2381                                 for (node = scene->nodetree->nodes.first; node; node = node->next)
2382                                         if (node->type == CMP_NODE_BLUR) {
2383                                                 NodeBlurData *nbd = node->storage;
2384                                                 nbd->percentx *= 100.0f;
2385                                                 nbd->percenty *= 100.0f;
2386                                         }
2387         }
2388
2389         if (main->versionfile < 258 || (main->versionfile == 258 && main->subversionfile < 1)) {
2390                 /* screen view2d settings were not properly initialized [#27164]
2391                  * v2d->scroll caused the bug but best reset other values too which are in old blend files only.
2392                  * need to make less ugly - possibly an iterator? */
2393                 bScreen *screen;
2394
2395                 for (screen = main->screen.first; screen; screen = screen->id.next) {
2396                         ScrArea *sa;
2397                         /* add regions */
2398                         for (sa = screen->areabase.first; sa; sa = sa->next) {
2399                                 SpaceLink *sl = sa->spacedata.first;
2400                                 if (sl->spacetype == SPACE_IMAGE) {
2401                                         ARegion *ar;
2402                                         for (ar = sa->regionbase.first; ar; ar = ar->next) {
2403                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
2404                                                         View2D *v2d = &ar->v2d;
2405                                                         v2d->minzoom = v2d->maxzoom = v2d->scroll = v2d->keeptot = v2d->keepzoom = v2d->keepofs = v2d->align = 0;
2406                                                 }
2407                                         }
2408                                 }
2409
2410                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2411                                         if (sl->spacetype == SPACE_IMAGE) {
2412                                                 ARegion *ar;
2413                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
2414                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
2415                                                                 View2D *v2d = &ar->v2d;
2416                                                                 v2d->minzoom = v2d->maxzoom = v2d->scroll = v2d->keeptot = v2d->keepzoom = v2d->keepofs = v2d->align = 0;
2417                                                         }
2418                                                 }
2419                                         }
2420                                 }
2421                         }
2422                 }
2423
2424                 {
2425                         /* Initialize texture point density curve falloff */
2426                         Tex *tex;
2427                         for (tex = main->tex.first; tex; tex = tex->id.next) {
2428                                 if (tex->pd) {
2429                                         if (tex->pd->falloff_speed_scale == 0.0f)
2430                                                 tex->pd->falloff_speed_scale = 100.0f;
2431
2432                                         if (!tex->pd->falloff_curve) {
2433                                                 tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
2434
2435                                                 tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
2436                                                 tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
2437                                                 curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
2438                                                 curvemapping_changed(tex->pd->falloff_curve, 0);
2439                                         }
2440                                 }
2441                         }
2442                 }
2443
2444                 {
2445                         /* add default value for behind strength of camera actuator */
2446                         Object *ob;
2447                         bActuator *act;
2448                         for (ob = main->object.first; ob; ob = ob->id.next) {
2449                                 for (act = ob->actuators.first; act; act = act->next) {
2450                                         if (act->type == ACT_CAMERA) {
2451                                                 bCameraActuator *ba = act->data;
2452
2453                                                 ba->damping = 1.0/32.0;
2454                                         }
2455                                 }
2456                         }
2457                 }
2458
2459                 {
2460                         ParticleSettings *part;
2461                         for (part = main->particle.first; part; part = part->id.next) {
2462                                 /* Initialize particle billboard scale */
2463                                 part->bb_size[0] = part->bb_size[1] = 1.0f;
2464                         }
2465                 }
2466         }
2467
2468         if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 1)) {
2469                 {
2470                         Scene *scene;
2471                         Sequence *seq;
2472
2473                         for (scene = main->scene.first; scene; scene = scene->id.next) {
2474                                 scene->r.ffcodecdata.audio_channels = 2;
2475                                 scene->audio.volume = 1.0f;
2476                                 SEQ_BEGIN (scene->ed, seq)
2477                                 {
2478                                         seq->pitch = 1.0f;
2479                                 }
2480                                 SEQ_END
2481                         }
2482                 }
2483
2484                 {
2485                         bScreen *screen;
2486                         for (screen = main->screen.first; screen; screen = screen->id.next) {
2487                                 ScrArea *sa;
2488
2489                                 /* add regions */
2490                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
2491                                         SpaceLink *sl = sa->spacedata.first;
2492                                         if (sl->spacetype == SPACE_SEQ) {
2493                                                 ARegion *ar;
2494                                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
2495                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
2496                                                                 if (ar->v2d.min[1] == 4.0f)
2497                                                                         ar->v2d.min[1] = 0.5f;
2498                                                         }
2499                                                 }
2500                                         }
2501                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
2502                                                 if (sl->spacetype == SPACE_SEQ) {
2503                                                         ARegion *ar;
2504                                                         for (ar = sl->regionbase.first; ar; ar = ar->next) {
2505                                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
2506                                                                         if (ar->v2d.min[1] == 4.0f)
2507                                                                                 ar->v2d.min[1] = 0.5f;
2508                                                                 }
2509                                                         }
2510                                                 }
2511                                         }
2512                                 }
2513                         }
2514                 }
2515
2516                 {
2517                         /* Make "auto-clamped" handles a per-keyframe setting instead of per-FCurve
2518                          *
2519                          * We're only patching F-Curves in Actions here, since it is assumed that most
2520                          * drivers out there won't be using this (and if they are, they're in the minority).
2521                          * While we should aim to fix everything ideally, in practice it's far too hard
2522                          * to get to every animdata block, not to mention the performance hit that'd have
2523                          */
2524                         bAction *act;
2525                         FCurve *fcu;
2526
2527                         for (act = main->action.first; act; act = act->id.next) {
2528                                 for (fcu = act->curves.first; fcu; fcu = fcu->next) {
2529                                         BezTriple *bezt;
2530                                         unsigned int i = 0;
2531
2532                                         /* only need to touch curves that had this flag set */
2533                                         if ((fcu->flag & FCURVE_AUTO_HANDLES) == 0)
2534                                                 continue;
2535                                         if ((fcu->totvert == 0) || (fcu->bezt == NULL))
2536                                                 continue;
2537
2538                                         /* only change auto-handles to auto-clamped */
2539                                         for (bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
2540                                                 if (bezt->h1 == HD_AUTO)
2541                                                         bezt->h1 = HD_AUTO_ANIM;
2542                                                 if (bezt->h2 == HD_AUTO)
2543                                                         bezt->h2 = HD_AUTO_ANIM;
2544                                         }
2545
2546                                         fcu->flag &= ~FCURVE_AUTO_HANDLES;
2547                                 }