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