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