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