Merge branch 'master' into blender2.8
[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.h" // NT
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 *main)
733 {
734         /* WATCH IT!!!: pointers from libdata have not been converted */
735
736         if (main->versionfile < 250) {
737                 bScreen *screen;
738                 Scene *scene;
739                 BaseLegacy *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 = main->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 = main->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 = main->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, main->name);
798                                                 seq->sound = BKE_sound_new_file(main, 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 = main->screen.first; screen; screen = screen->id.next) {
816                         do_versions_windowmanager_2_50(screen);
817                         do_versions_gpencil_2_50(main, 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 = main->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 = main->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 = main->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 = main->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 = main->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 = main->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 = main->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 (main->versionfile < 250 || (main->versionfile == 250 && main->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 = main->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_callocN(sizeof(char)*ob->totcol, "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 = main->tex.first; tex; tex = tex->id.next) {
962                         if (tex->afmax == 0)
963                                 tex->afmax = 8;
964                 }
965
966                 for (ma = main->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 = main->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 (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 2)) {
1089                 Scene *sce;
1090                 Object *ob;
1091
1092                 for (sce = main->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
1124                 for (ob = main->object.first; ob; ob = ob->id.next) {
1125                         if (ob->flag & 8192) // OB_POSEMODE = 8192
1126                                 ob->mode |= OB_MODE_POSE;
1127                 }
1128         }
1129
1130         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 4)) {
1131                 Scene *sce;
1132                 Object *ob;
1133                 Material *ma;
1134                 Lamp *la;
1135                 World *wo;
1136                 Tex *tex;
1137                 ParticleSettings *part;
1138                 bool do_gravity = false;
1139
1140                 for (sce = main->scene.first; sce; sce = sce->id.next)
1141                         if (sce->unit.scale_length == 0.0f)
1142                                 sce->unit.scale_length = 1.0f;
1143
1144                 for (ob = main->object.first; ob; ob = ob->id.next) {
1145                         /* fluid-sim stuff */
1146                         FluidsimModifierData *fluidmd = (FluidsimModifierData *) modifiers_findByType(ob, eModifierType_Fluidsim);
1147                         if (fluidmd)
1148                                 fluidmd->fss->fmd = fluidmd;
1149
1150                         /* rotation modes were added, but old objects would now default to being 'quaternion based' */
1151                         ob->rotmode = ROT_MODE_EUL;
1152                 }
1153
1154                 for (ma = main->mat.first; ma; ma = ma->id.next) {
1155                         if (ma->vol.reflection == 0.f) {
1156                                 ma->vol.reflection = 1.f;
1157                                 ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f;
1158                                 ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f;
1159                         }
1160
1161                         do_version_mtex_factor_2_50(ma->mtex, ID_MA);
1162                 }
1163
1164                 for (la = main->lamp.first; la; la = la->id.next)
1165                         do_version_mtex_factor_2_50(la->mtex, ID_LA);
1166
1167                 for (wo = main->world.first; wo; wo = wo->id.next)
1168                         do_version_mtex_factor_2_50(wo->mtex, ID_WO);
1169
1170                 for (tex = main->tex.first; tex; tex = tex->id.next)
1171                         if (tex->vd)
1172                                 if (tex->vd->extend == 0)
1173                                         tex->vd->extend = TEX_CLIP;
1174
1175                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1176                         if (sce->audio.main == 0.0f)
1177                                 sce->audio.main = 1.0f;
1178
1179                         sce->r.ffcodecdata.audio_mixrate = sce->audio.mixrate;
1180                         sce->r.ffcodecdata.audio_volume = sce->audio.main;
1181                         sce->audio.distance_model = 2;
1182                         sce->audio.doppler_factor = 1.0f;
1183                         sce->audio.speed_of_sound = 343.3f;
1184                 }
1185
1186                 /* Add default gravity to scenes */
1187                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1188                         if ((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0 &&
1189                             is_zero_v3(sce->physics_settings.gravity))
1190                         {
1191                                 sce->physics_settings.gravity[0] = sce->physics_settings.gravity[1] = 0.0f;
1192                                 sce->physics_settings.gravity[2] = -9.81f;
1193                                 sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
1194                                 do_gravity = true;
1195                         }
1196                 }
1197
1198                 /* Assign proper global gravity weights for dynamics (only z-coordinate is taken into account) */
1199                 if (do_gravity) {
1200                         for (part = main->particle.first; part; part = part->id.next)
1201                                 part->effector_weights->global_gravity = part->acc[2]/-9.81f;
1202                 }
1203
1204                 for (ob = main->object.first; ob; ob = ob->id.next) {
1205                         ModifierData *md;
1206
1207                         if (do_gravity) {
1208                                 for (md = ob->modifiers.first; md; md = md->next) {
1209                                         ClothModifierData *clmd = (ClothModifierData *) modifiers_findByType(ob, eModifierType_Cloth);
1210                                         if (clmd)
1211                                                 clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2]/-9.81f;
1212                                 }
1213
1214                                 if (ob->soft)
1215                                         ob->soft->effector_weights->global_gravity = ob->soft->grav/9.81f;
1216                         }
1217
1218                         /* Normal wind shape is plane */
1219                         if (ob->pd) {
1220                                 if (ob->pd->forcefield == PFIELD_WIND)
1221                                         ob->pd->shape = PFIELD_SHAPE_PLANE;
1222
1223                                 if (ob->pd->flag & PFIELD_PLANAR)
1224                                         ob->pd->shape = PFIELD_SHAPE_PLANE;
1225                                 else if (ob->pd->flag & PFIELD_SURFACE)
1226                                         ob->pd->shape = PFIELD_SHAPE_SURFACE;
1227
1228                                 ob->pd->flag |= PFIELD_DO_LOCATION;
1229                         }
1230                 }
1231         }
1232
1233         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 6)) {
1234                 Object *ob;
1235                 Lamp *la;
1236
1237                 /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialization */
1238                 for (ob = main->object.first; ob; ob = ob->id.next) {
1239                         /* new variables for all objects */
1240                         ob->quat[0] = 1.0f;
1241                         ob->rotAxis[1] = 1.0f;
1242
1243                         /* bones */
1244                         if (ob->pose) {
1245                                 bPoseChannel *pchan;
1246
1247                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1248                                         /* just need to initalise rotation axis properly... */
1249                                         pchan->rotAxis[1] = 1.0f;
1250                                 }
1251                         }
1252                 }
1253
1254                 for (la = main->lamp.first; la; la = la->id.next)
1255                         la->compressthresh = 0.05f;
1256         }
1257
1258         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 7)) {
1259                 Mesh *me;
1260                 Nurb *nu;
1261                 Lattice *lt;
1262                 Curve *cu;
1263                 Key *key;
1264                 const float *data;
1265                 int a, tot;
1266
1267                 /* shape keys are no longer applied to the mesh itself, but rather
1268                  * to the derivedmesh/displist, so here we ensure that the basis
1269                  * shape key is always set in the mesh coordinates. */
1270                 for (me = main->mesh.first; me; me = me->id.next) {
1271                         if ((key = blo_do_versions_newlibadr(fd, lib, me->key)) && key->refkey) {
1272                                 data = key->refkey->data;
1273                                 tot = MIN2(me->totvert, key->refkey->totelem);
1274
1275                                 for (a = 0; a < tot; a++, data += 3)
1276                                         copy_v3_v3(me->mvert[a].co, data);
1277                         }
1278                 }
1279
1280                 for (lt = main->latt.first; lt; lt = lt->id.next) {
1281                         if ((key = blo_do_versions_newlibadr(fd, lib, lt->key)) && key->refkey) {
1282                                 data = key->refkey->data;
1283                                 tot = MIN2(lt->pntsu*lt->pntsv*lt->pntsw, key->refkey->totelem);
1284
1285                                 for (a = 0; a < tot; a++, data += 3)
1286                                         copy_v3_v3(lt->def[a].vec, data);
1287                         }
1288                 }
1289
1290                 for (cu = main->curve.first; cu; cu = cu->id.next) {
1291                         if ((key = blo_do_versions_newlibadr(fd, lib, cu->key)) && key->refkey) {
1292                                 data = key->refkey->data;
1293
1294                                 for (nu = cu->nurb.first; nu; nu = nu->next) {
1295                                         if (nu->bezt) {
1296                                                 BezTriple *bezt = nu->bezt;
1297
1298                                                 for (a = 0; a < nu->pntsu; a++, bezt++) {
1299                                                         copy_v3_v3(bezt->vec[0], data); data+=3;
1300                                                         copy_v3_v3(bezt->vec[1], data); data+=3;
1301                                                         copy_v3_v3(bezt->vec[2], data); data+=3;
1302                                                         bezt->alfa = *data; data++;
1303                                                 }
1304                                         }
1305                                         else if (nu->bp) {
1306                                                 BPoint *bp = nu->bp;
1307
1308                                                 for (a = 0; a < nu->pntsu*nu->pntsv; a++, bp++) {
1309                                                         copy_v3_v3(bp->vec, data); data += 3;
1310                                                         bp->alfa = *data; data++;
1311                                                 }
1312                                         }
1313                                 }
1314                         }
1315                 }
1316         }
1317
1318         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 8)) {
1319                 {
1320                         Scene *sce = main->scene.first;
1321                         while (sce) {
1322                                 if (sce->r.frame_step == 0)
1323                                         sce->r.frame_step = 1;
1324                                 if (sce->r.mblur_samples == 0)
1325                                         sce->r.mblur_samples = sce->r.osa;
1326
1327                                 if (sce->ed && sce->ed->seqbase.first) {
1328                                         do_versions_seq_unique_name_all_strips(sce, &sce->ed->seqbase);
1329                                 }
1330
1331                                 sce = sce->id.next;
1332                         }
1333                 }
1334
1335                 {
1336                         /* ensure all nodes have unique names */
1337                         bNodeTree *ntree = main->nodetree.first;
1338                         while (ntree) {
1339                                 bNode *node = ntree->nodes.first;
1340
1341                                 while (node) {
1342                                         nodeUniqueName(ntree, node);
1343                                         node = node->next;
1344                                 }
1345
1346                                 ntree = ntree->id.next;
1347                         }
1348                 }
1349
1350                 {
1351                         Object *ob = main->object.first;
1352                         while (ob) {
1353                                 /* shaded mode disabled for now */
1354                                 if (ob->dt == OB_MATERIAL)
1355                                         ob->dt = OB_TEXTURE;
1356                                 ob = ob->id.next;
1357                         }
1358                 }
1359
1360                 {
1361                         bScreen *screen;
1362                         ScrArea *sa;
1363                         SpaceLink *sl;
1364
1365                         for (screen = main->screen.first; screen; screen = screen->id.next) {
1366                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1367                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1368                                                 if (sl->spacetype == SPACE_VIEW3D) {
1369                                                         View3D *v3d = (View3D *) sl;
1370                                                         if (v3d->drawtype == OB_MATERIAL)
1371                                                                 v3d->drawtype = OB_SOLID;
1372                                                 }
1373                                         }
1374                                 }
1375                         }
1376                 }
1377
1378                 /* only convert old 2.50 files with color management */
1379                 if (main->versionfile == 250) {
1380                         Scene *sce = main->scene.first;
1381                         Material *ma = main->mat.first;
1382                         World *wo = main->world.first;
1383                         Tex *tex = main->tex.first;
1384                         int i, convert = 0;
1385
1386                         /* convert to new color management system:
1387                          * while previously colors were stored as srgb,
1388                          * now they are stored as linear internally,
1389                          * with screen gamma correction in certain places in the UI. */
1390
1391                         /* don't know what scene is active, so we'll convert if any scene has it enabled... */
1392                         while (sce) {
1393                                 if (sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
1394                                         convert = 1;
1395                                 sce = sce->id.next;
1396                         }
1397
1398                         if (convert) {
1399                                 while (ma) {
1400                                         if (ma->ramp_col) {
1401                                                 ColorBand *band = (ColorBand *)ma->ramp_col;
1402                                                 for (i = 0; i < band->tot; i++) {
1403                                                         CBData *data = band->data + i;
1404                                                         srgb_to_linearrgb_v3_v3(&data->r, &data->r);
1405                                                 }
1406                                         }
1407
1408                                         if (ma->ramp_spec) {
1409                                                 ColorBand *band = (ColorBand *)ma->ramp_spec;
1410                                                 for (i = 0; i < band->tot; i++) {
1411                                                         CBData *data = band->data + i;
1412                                                         srgb_to_linearrgb_v3_v3(&data->r, &data->r);
1413                                                 }
1414                                         }
1415
1416                                         srgb_to_linearrgb_v3_v3(&ma->r, &ma->r);
1417                                         srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr);
1418                                         srgb_to_linearrgb_v3_v3(&ma->mirr, &ma->mirr);
1419                                         srgb_to_linearrgb_v3_v3(ma->sss_col, ma->sss_col);
1420                                         ma = ma->id.next;
1421                                 }
1422
1423                                 while (tex) {
1424                                         if (tex->coba) {
1425                                                 ColorBand *band = (ColorBand *)tex->coba;
1426                                                 for (i = 0; i < band->tot; i++) {
1427                                                         CBData *data = band->data + i;
1428                                                         srgb_to_linearrgb_v3_v3(&data->r, &data->r);
1429                                                 }
1430                                         }
1431                                         tex = tex->id.next;
1432                                 }
1433
1434                                 while (wo) {
1435                                         srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr);
1436                                         srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr);
1437                                         srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr);
1438                                         wo = wo->id.next;
1439                                 }
1440                         }
1441                 }
1442         }
1443
1444         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9)) {
1445                 Scene *sce;
1446                 Mesh *me;
1447                 Object *ob;
1448
1449                 for (sce = main->scene.first; sce; sce = sce->id.next)
1450                         if (!sce->toolsettings->particle.selectmode)
1451                                 sce->toolsettings->particle.selectmode = SCE_SELECT_PATH;
1452
1453                 if (main->versionfile == 250 && main->subversionfile > 1) {
1454                         for (me = main->mesh.first; me; me = me->id.next)
1455                                 multires_load_old_250(me);
1456
1457                         for (ob = main->object.first; ob; ob = ob->id.next) {
1458                                 MultiresModifierData *mmd = (MultiresModifierData *) modifiers_findByType(ob, eModifierType_Multires);
1459
1460                                 if (mmd) {
1461                                         mmd->totlvl--;
1462                                         mmd->lvl--;
1463                                         mmd->sculptlvl = mmd->lvl;
1464                                         mmd->renderlvl = mmd->lvl;
1465                                 }
1466                         }
1467                 }
1468         }
1469
1470         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 10)) {
1471                 Object *ob;
1472
1473                 /* properly initialize hair clothsim data on old files */
1474                 for (ob = main->object.first; ob; ob = ob->id.next) {
1475                         ModifierData *md;
1476                         for (md = ob->modifiers.first; md; md = md->next) {
1477                                 if (md->type == eModifierType_Cloth) {
1478                                         ClothModifierData *clmd = (ClothModifierData *)md;
1479                                         if (clmd->sim_parms->velocity_smooth < 0.01f)
1480                                                 clmd->sim_parms->velocity_smooth = 0.f;
1481                                 }
1482                         }
1483                 }
1484         }
1485
1486         /* fix bad area setup in subversion 10 */
1487         if (main->versionfile == 250 && main->subversionfile == 10) {
1488                 /* fix for new view type in sequencer */
1489                 bScreen *screen;
1490                 ScrArea *sa;
1491                 SpaceLink *sl;
1492
1493                 /* remove all preview window in wrong spaces */
1494                 for (screen = main->screen.first; screen; screen = screen->id.next) {
1495                         for (sa = screen->areabase.first; sa; sa = sa->next) {
1496                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1497                                         if (sl->spacetype != SPACE_SEQ) {
1498                                                 ARegion *ar;
1499                                                 ListBase *regionbase;
1500
1501                                                 if (sl == sa->spacedata.first) {
1502                                                         regionbase = &sa->regionbase;
1503                                                 }
1504                                                 else {
1505                                                         regionbase = &sl->regionbase;
1506                                                 }
1507
1508                                                 for (ar = regionbase->first; ar; ar = ar->next) {
1509                                                         if (ar->regiontype == RGN_TYPE_PREVIEW)
1510                                                                 break;
1511                                                 }
1512
1513                                                 if (ar && (ar->regiontype == RGN_TYPE_PREVIEW)) {
1514                                                         SpaceType *st = BKE_spacetype_from_id(SPACE_SEQ);
1515                                                         BKE_area_region_free(st, ar);
1516                                                         BLI_freelinkN(regionbase, ar);
1517                                                 }
1518                                         }
1519                                 }
1520                         }
1521                 }
1522         }
1523
1524         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 11)) {
1525                 {
1526                         /* fix for new view type in sequencer */
1527                         bScreen *screen;
1528                         ScrArea *sa;
1529                         SpaceLink *sl;
1530
1531                         for (screen = main->screen.first; screen; screen = screen->id.next) {
1532                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1533                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1534                                                 if (sl->spacetype == SPACE_SEQ) {
1535                                                         ARegion *ar;
1536                                                         ARegion *ar_main;
1537                                                         ListBase *regionbase;
1538                                                         SpaceSeq *sseq = (SpaceSeq *)sl;
1539
1540                                                         if (sl == sa->spacedata.first) {
1541                                                                 regionbase = &sa->regionbase;
1542                                                         }
1543                                                         else {
1544                                                                 regionbase = &sl->regionbase;
1545                                                         }
1546
1547                                                         if (sseq->view == 0)
1548                                                                 sseq->view = SEQ_VIEW_SEQUENCE;
1549                                                         if (sseq->mainb == 0)
1550                                                                 sseq->mainb = SEQ_DRAW_IMG_IMBUF;
1551
1552                                                         ar_main = (ARegion*)regionbase->first;
1553                                                         for (; ar_main; ar_main = ar_main->next) {
1554                                                                 if (ar_main->regiontype == RGN_TYPE_WINDOW)
1555                                                                         break;
1556                                                         }
1557                                                         ar = MEM_callocN(sizeof(ARegion), "preview area for sequencer");
1558                                                         BLI_insertlinkbefore(regionbase, ar_main, ar);
1559                                                         sequencer_init_preview_region(ar);
1560                                                 }
1561                                         }
1562                                 }
1563                         }
1564                 }
1565         }
1566
1567         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 12)) {
1568                 Scene *sce;
1569                 Object *ob;
1570                 Brush *brush;
1571                 Material *ma;
1572
1573                 /* game engine changes */
1574                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1575                         sce->gm.eyeseparation = 0.10f;
1576                 }
1577
1578                 /* anim viz changes */
1579                 for (ob = main->object.first; ob; ob = ob->id.next) {
1580                         /* initialize object defaults */
1581                         animviz_settings_init(&ob->avs);
1582
1583                         /* if armature, copy settings for pose from armature data
1584                          * performing initialization where appropriate
1585                          */
1586                         if (ob->pose && ob->data) {
1587                                 bArmature *arm = blo_do_versions_newlibadr(fd, lib, ob->data);
1588                                 if (arm) { /* XXX - why does this fail in some cases? */
1589                                         bAnimVizSettings *avs = &ob->pose->avs;
1590
1591                                         /* ghosting settings ---------------- */
1592                                         /* ranges */
1593                                         avs->ghost_bc = avs->ghost_ac = arm->ghostep;
1594
1595                                         avs->ghost_sf = arm->ghostsf;
1596                                         avs->ghost_ef = arm->ghostef;
1597                                         if ((avs->ghost_sf == avs->ghost_ef) && (avs->ghost_sf == 0)) {
1598                                                 avs->ghost_sf = 1;
1599                                                 avs->ghost_ef = 100;
1600                                         }
1601
1602                                         /* type */
1603                                         if (arm->ghostep == 0)
1604                                                 avs->ghost_type = GHOST_TYPE_NONE;
1605                                         else
1606                                                 avs->ghost_type = arm->ghosttype + 1;
1607
1608                                         /* stepsize */
1609                                         avs->ghost_step = arm->ghostsize;
1610                                         if (avs->ghost_step == 0)
1611                                                 avs->ghost_step = 1;
1612
1613                                         /* path settings --------------------- */
1614                                         /* ranges */
1615                                         avs->path_bc = arm->pathbc;
1616                                         avs->path_ac = arm->pathac;
1617                                         if ((avs->path_bc == avs->path_ac) && (avs->path_bc == 0))
1618                                                 avs->path_bc = avs->path_ac = 10;
1619
1620                                         avs->path_sf = arm->pathsf;
1621                                         avs->path_ef = arm->pathef;
1622                                         if ((avs->path_sf == avs->path_ef) && (avs->path_sf == 0)) {
1623                                                 avs->path_sf = 1;
1624                                                 avs->path_ef = 250;
1625                                         }
1626
1627                                         /* flags */
1628                                         if (arm->pathflag & ARM_PATH_FNUMS)
1629                                                 avs->path_viewflag |= MOTIONPATH_VIEW_FNUMS;
1630                                         if (arm->pathflag & ARM_PATH_KFRAS)
1631                                                 avs->path_viewflag |= MOTIONPATH_VIEW_KFRAS;
1632                                         if (arm->pathflag & ARM_PATH_KFNOS)
1633                                                 avs->path_viewflag |= MOTIONPATH_VIEW_KFNOS;
1634
1635                                         /* bake flags */
1636                                         if (arm->pathflag & ARM_PATH_HEADS)
1637                                                 avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS;
1638
1639                                         /* type */
1640                                         if (arm->pathflag & ARM_PATH_ACFRA)
1641                                                 avs->path_type = MOTIONPATH_TYPE_ACFRA;
1642
1643                                         /* stepsize */
1644                                         avs->path_step = arm->pathsize;
1645                                         if (avs->path_step == 0)
1646                                                 avs->path_step = 1;
1647                                 }
1648                                 else
1649                                         animviz_settings_init(&ob->pose->avs);
1650                         }
1651                 }
1652
1653                 /* brush texture changes */
1654                 for (brush = main->brush.first; brush; brush = brush->id.next) {
1655                         BKE_texture_mtex_default(&brush->mtex);
1656                         BKE_texture_mtex_default(&brush->mask_mtex);
1657                 }
1658
1659                 for (ma = main->mat.first; ma; ma = ma->id.next) {
1660                         if (ma->vol.ms_spread < 0.0001f) {
1661                                 ma->vol.ms_spread = 0.2f;
1662                                 ma->vol.ms_diff = 1.f;
1663                                 ma->vol.ms_intensity = 1.f;
1664                         }
1665                 }
1666         }
1667
1668         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 13)) {
1669                 /* NOTE: if you do more conversion, be sure to do it outside of this and
1670                  * increase subversion again, otherwise it will not be correct */
1671                 Object *ob;
1672
1673                 /* convert degrees to radians for internal use */
1674                 for (ob = main->object.first; ob; ob = ob->id.next) {
1675                         bPoseChannel *pchan;
1676
1677                         do_version_constraints_radians_degrees_250(&ob->constraints);
1678
1679                         if (ob->pose) {
1680                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1681                                         pchan->limitmin[0] *= (float)(M_PI / 180.0);
1682                                         pchan->limitmin[1] *= (float)(M_PI / 180.0);
1683                                         pchan->limitmin[2] *= (float)(M_PI / 180.0);
1684                                         pchan->limitmax[0] *= (float)(M_PI / 180.0);
1685                                         pchan->limitmax[1] *= (float)(M_PI / 180.0);
1686                                         pchan->limitmax[2] *= (float)(M_PI / 180.0);
1687
1688                                         do_version_constraints_radians_degrees_250(&pchan->constraints);
1689                                 }
1690                         }
1691                 }
1692         }
1693
1694         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 14)) {
1695                 /* fix for bad View2D extents for Animation Editors */
1696                 bScreen *screen;
1697                 ScrArea *sa;
1698                 SpaceLink *sl;
1699
1700                 for (screen = main->screen.first; screen; screen = screen->id.next) {
1701                         for (sa = screen->areabase.first; sa; sa = sa->next) {
1702                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1703                                         ListBase *regionbase;
1704                                         ARegion *ar;
1705
1706                                         if (sl == sa->spacedata.first)
1707                                                 regionbase = &sa->regionbase;
1708                                         else
1709                                                 regionbase = &sl->regionbase;
1710
1711                                         if (ELEM(sl->spacetype, SPACE_ACTION, SPACE_NLA)) {
1712                                                 for (ar = (ARegion*) regionbase->first; ar; ar = ar->next) {
1713                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
1714                                                                 ar->v2d.cur.ymax = ar->v2d.tot.ymax = 0.0f;
1715                                                                 ar->v2d.cur.ymin = ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
1716                                                         }
1717                                                 }
1718                                         }
1719                                 }
1720                         }
1721                 }
1722         }
1723
1724         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 15)) {
1725                 World *wo;
1726                 Material *ma;
1727
1728                 /* ambient default from 0.5f to 1.0f */
1729                 for (ma = main->mat.first; ma; ma = ma->id.next)
1730                         ma->amb *= 2.0f;
1731
1732                 for (wo = main->world.first; wo; wo = wo->id.next) {
1733                         /* ao splitting into ao/env/indirect */
1734                         wo->ao_env_energy = wo->aoenergy;
1735                         wo->aoenergy = 1.0f;
1736
1737                         if (wo->ao_indirect_bounces == 0)
1738                                 wo->ao_indirect_bounces = 1;
1739                         else
1740                                 wo->mode |= WO_INDIRECT_LIGHT;
1741
1742                         if (wo->aomix == WO_AOSUB)
1743                                 wo->ao_env_energy = -wo->ao_env_energy;
1744                         else if (wo->aomix == WO_AOADDSUB)
1745                                 wo->mode |= WO_AMB_OCC;
1746
1747                         wo->aomix = WO_AOMUL;
1748
1749                         /* ambient default from 0.5f to 1.0f */
1750                         mul_v3_fl(&wo->ambr, 0.5f);
1751                         wo->ao_env_energy *= 0.5f;
1752                 }
1753         }
1754
1755         if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 17)) {
1756                 Scene *sce;
1757                 Sequence *seq;
1758                 Material *ma;
1759
1760                 /* initialize to sane default so toggling on border shows something */
1761                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1762                         if (sce->r.border.xmin == 0.0f && sce->r.border.ymin == 0.0f &&
1763                             sce->r.border.xmax == 0.0f && sce->r.border.ymax == 0.0f)
1764                         {
1765                                 sce->r.border.xmin = 0.0f;
1766                                 sce->r.border.ymin = 0.0f;
1767                                 sce->r.border.xmax = 1.0f;
1768                                 sce->r.border.ymax = 1.0f;
1769                         }
1770
1771                         if ((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0)
1772                                 sce->r.ffcodecdata.audio_codec = 0x0; // CODEC_ID_NONE
1773
1774                         SEQ_BEGIN (sce->ed, seq)
1775                         {
1776                                 seq->volume = 1.0f;
1777                         }
1778                         SEQ_END
1779                 }
1780
1781                 /* particle brush strength factor was changed from int to float */
1782                 for (sce = main->scene.first; sce; sce = sce->id.next) {
1783                         ParticleEditSettings *pset = &sce->toolsettings->particle;
1784                         int a;
1785
1786                         for (a = 0; a < PE_TOT_BRUSH; a++)
1787                                 pset->brush[a].strength /= 100.0f;
1788                 }
1789
1790                 for (ma = main->mat.first; ma; ma = ma->id.next)
1791                         if (ma->mode & MA_TRACEBLE)
1792                                 ma->shade_flag |= MA_APPROX_OCCLUSION;
1793
1794                 /* sequencer changes */
1795                 {
1796                         bScreen *screen;
1797                         ScrArea *sa;
1798                         SpaceLink *sl;
1799
1800                         for (screen = main->screen.first; screen; screen = screen->id.next) {
1801                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1802                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1803                                                 if (sl->spacetype == SPACE_SEQ) {
1804                                                         ARegion *ar_preview;
1805                                                         ListBase *regionbase;
1806
1807                                                         if (sl == sa->spacedata.first) {
1808                                                                 regionbase = &sa->regionbase;
1809                                                         }
1810                                                         else {
1811                                                                 regionbase = &sl->regionbase;
1812                                                         }
1813
1814                                                         ar_preview = (ARegion*) regionbase->first;
1815                                                         for (; ar_preview; ar_preview = ar_preview->next) {
1816                                                                 if (ar_preview->regiontype == RGN_TYPE_PREVIEW)
1817                                                                         break;
1818                                                         }
1819                                                         if (ar_preview && (ar_preview->regiontype == RGN_TYPE_PREVIEW)) {
1820                                                                 sequencer_init_preview_region(ar_preview);
1821                                                         }
1822                                                 }
1823                                         }
1824                                 }
1825                         }
1826                 } /* sequencer changes */
1827         }
1828
1829         if (main->versionfile <= 251) { /* 2.5.1 had no subversions */
1830                 bScreen *sc;
1831
1832                 /* Blender 2.5.2 - subversion 0 introduced a new setting: V3D_RENDER_OVERRIDE.
1833                  * This bit was used in the past for V3D_TRANSFORM_SNAP, which is now deprecated.
1834                  * Here we clear it for old files so they don't come in with V3D_RENDER_OVERRIDE set,
1835                  * which would cause cameras, lamps, etc to become invisible */
1836                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1837                         ScrArea *sa;
1838                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1839                                 SpaceLink *sl;
1840                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1841                                         if (sl->spacetype == SPACE_VIEW3D) {
1842                                                 View3D *v3d = (View3D *)sl;
1843                                                 v3d->flag2 &= ~V3D_RENDER_OVERRIDE;
1844                                         }
1845                                 }
1846                         }
1847                 }
1848         }
1849
1850         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 1)) {
1851                 Brush *brush;
1852                 Object *ob;
1853                 Scene *scene;
1854                 bNodeTree *ntree;
1855
1856                 for (brush = main->brush.first; brush; brush = brush->id.next) {
1857                         if (brush->curve)
1858                                 brush->curve->preset = CURVE_PRESET_SMOOTH;
1859                 }
1860
1861                 /* properly initialize active flag for fluidsim modifiers */
1862                 for (ob = main->object.first; ob; ob = ob->id.next) {
1863                         ModifierData *md;
1864                         for (md = ob->modifiers.first; md; md = md->next) {
1865                                 if (md->type == eModifierType_Fluidsim) {
1866                                         FluidsimModifierData *fmd = (FluidsimModifierData *) md;
1867                                         fmd->fss->flag |= OB_FLUIDSIM_ACTIVE;
1868                                         fmd->fss->flag |= OB_FLUIDSIM_OVERRIDE_TIME;
1869                                 }
1870                         }
1871                 }
1872
1873                 /* adjustment to color balance node values */
1874                 for (scene = main->scene.first; scene; scene = scene->id.next) {
1875                         if (scene->nodetree) {
1876                                 bNode *node = scene->nodetree->nodes.first;
1877
1878                                 while (node) {
1879                                         if (node->type == CMP_NODE_COLORBALANCE) {
1880                                                 NodeColorBalance *n = (NodeColorBalance *) node->storage;
1881                                                 n->lift[0] += 1.f;
1882                                                 n->lift[1] += 1.f;
1883                                                 n->lift[2] += 1.f;
1884                                         }
1885                                         node = node->next;
1886                                 }
1887                         }
1888                 }
1889                 /* check inside node groups too */
1890                 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) {
1891                         bNode *node = ntree->nodes.first;
1892
1893                         while (node) {
1894                                 if (node->type == CMP_NODE_COLORBALANCE) {
1895                                         NodeColorBalance *n = (NodeColorBalance *) node->storage;
1896                                         n->lift[0] += 1.f;
1897                                         n->lift[1] += 1.f;
1898                                         n->lift[2] += 1.f;
1899                                 }
1900
1901                                 node = node->next;
1902                         }
1903                 }
1904         }
1905
1906         /* old-track -> constraints (this time we're really doing it!) */
1907         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 2)) {
1908                 Object *ob;
1909
1910                 for (ob = main->object.first; ob; ob = ob->id.next)
1911                         blo_do_version_old_trackto_to_constraints(ob);
1912         }
1913
1914         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 5)) {
1915                 bScreen *sc;
1916
1917                 /* Image editor scopes */
1918                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1919                         ScrArea *sa;
1920
1921                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1922                                 SpaceLink *sl;
1923
1924                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1925                                         if (sl->spacetype == SPACE_IMAGE) {
1926                                                 SpaceImage *sima = (SpaceImage *) sl;
1927                                                 scopes_new(&sima->scopes);
1928                                         }
1929                                 }
1930                         }
1931                 }
1932         }
1933
1934         if (main->versionfile < 253) {
1935                 Object *ob;
1936                 Scene *scene;
1937                 bScreen *sc;
1938                 Tex *tex;
1939                 Brush *brush;
1940
1941                 for (sc = main->screen.first; sc; sc = sc->id.next) {
1942                         ScrArea *sa;
1943                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1944                                 SpaceLink *sl;
1945
1946                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1947                                         if (sl->spacetype == SPACE_NODE) {
1948                                                 SpaceNode *snode = (SpaceNode *) sl;
1949                                                 ListBase *regionbase;
1950                                                 ARegion *ar;
1951
1952                                                 if (sl == sa->spacedata.first)
1953                                                         regionbase = &sa->regionbase;
1954                                                 else
1955                                                         regionbase = &sl->regionbase;
1956
1957                                                 if (snode->v2d.minzoom > 0.09f)
1958                                                         snode->v2d.minzoom = 0.09f;
1959                                                 if (snode->v2d.maxzoom < 2.31f)
1960                                                         snode->v2d.maxzoom = 2.31f;
1961
1962                                                 for (ar = regionbase->first; ar; ar = ar->next) {
1963                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
1964                                                                 if (ar->v2d.minzoom > 0.09f)
1965                                                                         ar->v2d.minzoom = 0.09f;
1966                                                                 if (ar->v2d.maxzoom < 2.31f)
1967                                                                         ar->v2d.maxzoom = 2.31f;
1968                                                         }
1969                                                 }
1970                                         }
1971                                         else if (sl->spacetype == SPACE_TIME) {
1972                                                 SpaceTime *stime = (SpaceTime *) sl;
1973
1974                                                 /* enable all cache display */
1975                                                 stime->cache_display |= TIME_CACHE_DISPLAY;
1976                                                 stime->cache_display |= (TIME_CACHE_SOFTBODY|TIME_CACHE_PARTICLES);
1977                                                 stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE|TIME_CACHE_DYNAMICPAINT);
1978                                         }
1979                                 }
1980                         }
1981                 }
1982
1983                 do_version_mdef_250(main);
1984
1985                 /* parent type to modifier */
1986                 for (ob = main->object.first; ob; ob = ob->id.next) {
1987                         if (ob->parent) {
1988                                 Object *parent = (Object *) blo_do_versions_newlibadr(fd, lib, ob->parent);
1989                                 if (parent) { /* parent may not be in group */
1990                                         if (parent->type == OB_ARMATURE && ob->partype == PARSKEL) {
1991                                                 ArmatureModifierData *amd;
1992                                                 bArmature *arm = (bArmature *) blo_do_versions_newlibadr(fd, lib, parent->data);
1993
1994                                                 amd = (ArmatureModifierData*) modifier_new(eModifierType_Armature);
1995                                                 amd->object = ob->parent;
1996                                                 BLI_addtail((ListBase*)&ob->modifiers, amd);
1997                                                 amd->deformflag = arm->deformflag;
1998                                                 ob->partype = PAROBJECT;
1999                                         }
2000                                         else if (parent->type == OB_LATTICE && ob->partype == PARSKEL) {
2001                                                 LatticeModifierData *lmd;
2002
2003                                                 lmd = (LatticeModifierData*) modifier_new(eModifierType_Lattice);
2004                                                 lmd->object = ob->parent;
2005                                                 BLI_addtail((ListBase*)&ob->modifiers, lmd);
2006                                                 ob->partype = PAROBJECT;
2007                                         }
2008                                         else if (parent->type == OB_CURVE && ob->partype == PARCURVE) {
2009                                                 CurveModifierData *cmd;
2010
2011                                                 cmd = (CurveModifierData*) modifier_new(eModifierType_Curve);
2012                                                 cmd->object = ob->parent;
2013                                                 BLI_addtail((ListBase*)&ob->modifiers, cmd);
2014                                                 ob->partype = PAROBJECT;
2015                                         }
2016                                 }
2017                         }
2018                 }
2019
2020                 /* initialize scene active layer */
2021                 for (scene = main->scene.first; scene; scene = scene->id.next) {
2022                         int i;
2023                         for (i = 0; i < 20; i++) {
2024                                 if (scene->lay & (1<<i)) {
2025                                         scene->layact = 1<<i;
2026                                         break;
2027                                 }
2028                         }
2029                 }
2030
2031                 for (tex = main->tex.first; tex; tex = tex->id.next) {
2032                         /* if youre picky, this isn't correct until we do a version bump
2033                          * since you could set saturation to be 0.0*/
2034                         if (tex->saturation == 0.0f)
2035                                 tex->saturation = 1.0f;
2036                 }
2037
2038                 {
2039                         Curve *cu;
2040                         for (cu = main->curve.first; cu; cu = cu->id.next) {
2041                                 cu->smallcaps_scale = 0.75f;
2042                         }
2043                 }
2044
2045                 for (scene = main->scene.first; scene; scene = scene->id.next) {
2046                         if (scene) {
2047                                 Sequence *seq;
2048                                 SEQ_BEGIN (scene->ed, seq)
2049                                 {
2050                                         if (seq->sat == 0.0f) {
2051                                                 seq->sat = 1.0f;
2052                                         }
2053                                 }
2054                                 SEQ_END
2055                         }
2056                 }
2057
2058                 /* GSOC 2010 Sculpt - New settings for Brush */
2059
2060                 for (brush = main->brush.first; brush; brush = brush->id.next) {
2061                         /* Sanity Check */
2062
2063                         /* infinite number of dabs */
2064                         if (brush->spacing == 0)
2065                                 brush->spacing = 10;
2066
2067                         /* will have no effect */
2068                         if (brush->alpha == 0)
2069                                 brush->alpha = 0.5f;
2070
2071                         /* bad radius */
2072                         if (brush->unprojected_radius == 0)
2073                                 brush->unprojected_radius = 0.125f;
2074
2075                         /* unusable size */
2076                         if (brush->size == 0)
2077                                 brush->size = 35;
2078
2079                         /* can't see overlay */
2080                         if (brush->texture_overlay_alpha == 0)
2081                                 brush->texture_overlay_alpha = 33;
2082
2083                         /* same as draw brush */
2084                         if (brush->crease_pinch_factor == 0)
2085                                 brush->crease_pinch_factor = 0.5f;
2086
2087                         /* will sculpt no vertexes */
2088                         if (brush->plane_trim == 0)
2089                                 brush->plane_trim = 0.5f;
2090
2091                         /* same as smooth stroke off */
2092                         if (brush->smooth_stroke_radius == 0)
2093                                 brush->smooth_stroke_radius = 75;
2094
2095                         /* will keep cursor in one spot */
2096                         if (brush->smooth_stroke_radius == 1)
2097                                 brush->smooth_stroke_factor = 0.9f;
2098
2099                         /* same as dots */
2100                         if (brush->rate == 0)
2101                                 brush->rate = 0.1f;
2102
2103                         /* New Settings */
2104                         if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 5)) {
2105                                 brush->flag |= BRUSH_SPACE_ATTEN; // explicitly enable adaptive space
2106
2107                                 /* spacing was originally in pixels, convert it to percentage for new version
2108                                  * size should not be zero due to sanity check above
2109                                  */
2110                                 brush->spacing = (int)(100 * ((float)brush->spacing) / ((float) brush->size));
2111
2112                                 if (brush->add_col[0] == 0 &&
2113                                         brush->add_col[1] == 0 &&
2114                                         brush->add_col[2] == 0)
2115                                 {
2116                                         brush->add_col[0] = 1.00f;
2117                                         brush->add_col[1] = 0.39f;
2118                                         brush->add_col[2] = 0.39f;
2119                                 }
2120
2121                                 if (brush->sub_col[0] == 0 &&
2122                                         brush->sub_col[1] == 0 &&
2123                                         brush->sub_col[2] == 0)
2124                                 {
2125                                         brush->sub_col[0] = 0.39f;
2126                                         brush->sub_col[1] = 0.39f;
2127                                         brush->sub_col[2] = 1.00f;
2128                                 }
2129                         }
2130                 }
2131         }
2132
2133         /* GSOC Sculpt 2010 - Sanity check on Sculpt/Paint settings */
2134         if (main->versionfile < 253) {
2135                 Scene *sce;
2136                 for (sce = main->scene.first; sce; sce = sce->id.next) {
2137                         if (sce->toolsettings->sculpt_paint_unified_alpha == 0)
2138                                 sce->toolsettings->sculpt_paint_unified_alpha = 0.5f;
2139
2140                         if (sce->toolsettings->sculpt_paint_unified_unprojected_radius == 0)
2141                                 sce->toolsettings->sculpt_paint_unified_unprojected_radius = 0.125f;
2142
2143                         if (sce->toolsettings->sculpt_paint_unified_size == 0)
2144                                 sce->toolsettings->sculpt_paint_unified_size = 35;
2145                 }
2146         }
2147
2148         if (main->versionfile < 253 || (main->versionfile == 253 && main->subversionfile < 1)) {
2149                 Object *ob;
2150
2151                 for (ob = main->object.first; ob; ob = ob->id.next) {
2152                         ModifierData *md;
2153
2154                         for (md = ob->modifiers.first; md; md = md->next) {
2155                                 if (md->type == eModifierType_Smoke) {
2156                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2157
2158                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
2159                                                 smd->domain->vorticity = 2.0f;
2160                                                 smd->domain->time_scale = 1.0f;
2161
2162                                                 if (!(smd->domain->flags & (1<<4)))
2163                                                         continue;
2164
2165                                                 /* delete old MOD_SMOKE_INITVELOCITY flag */
2166                                                 smd->domain->flags &= ~(1<<4);
2167
2168                                                 /* for now just add it to all flow objects in the scene */
2169                                                 {
2170                                                         Object *ob2;
2171                                                         for (ob2 = main->object.first; ob2; ob2 = ob2->id.next) {
2172                                                                 ModifierData *md2;
2173                                                                 for (md2 = ob2->modifiers.first; md2; md2 = md2->next) {
2174                                                                         if (md2->type == eModifierType_Smoke) {
2175                                                                                 SmokeModifierData *smd2 = (SmokeModifierData *)md2;
2176
2177                                                                                 if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) {
2178                                                                                         smd2->flow->flags |= MOD_SMOKE_FLOW_INITVELOCITY;
2179                                                                                 }
2180                                                                         }
2181                                                                 }
2182                                                         }
2183                                                 }
2184
2185                                         }
2186                                         else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
2187                                                 smd->flow->vel_multi = 1.0f;
2188                                         }
2189                                 }
2190                         }
2191                 }
2192         }
2193
2194         if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 1)) {
2195                 Brush *br;
2196                 ParticleSettings *part;
2197                 bScreen *sc;
2198                 Object *ob;
2199
2200                 for (br = main->brush.first; br; br = br->id.next) {
2201                         if (br->ob_mode == 0)
2202                                 br->ob_mode = OB_MODE_ALL_PAINT;
2203                 }
2204
2205                 for (part = main->particle.first; part; part = part->id.next) {
2206                         if (part->boids)
2207                                 part->boids->pitch = 1.0f;
2208
2209                         part->flag &= ~PART_HAIR_REGROW; /* this was a deprecated flag before */
2210                         part->kink_amp_clump = 1.f; /* keep old files looking similar */
2211                 }
2212
2213                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2214                         ScrArea *sa;
2215                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2216                                 SpaceLink *sl;
2217                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2218                                         if (sl->spacetype == SPACE_INFO) {
2219                                                 SpaceInfo *sinfo = (SpaceInfo *) sl;
2220                                                 ARegion *ar;
2221
2222                                                 sinfo->rpt_mask = INFO_RPT_OP;
2223
2224                                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
2225                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
2226                                                                 ar->v2d.scroll = (V2D_SCROLL_RIGHT);
2227                                                                 ar->v2d.align = V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y; /* align bottom left */
2228                                                                 ar->v2d.keepofs = V2D_LOCKOFS_X;
2229                                                                 ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
2230                                                                 ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
2231                                                                 ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f;
2232                                                         }
2233                                                 }
2234                                         }
2235                                 }
2236                         }
2237                 }
2238
2239                 /* fix rotation actuators for objects so they use real angles (radians)
2240                  * since before blender went opensource this strange scalar was used: (1 / 0.02) * 2 * math.pi/360 */
2241                 for (ob = main->object.first; ob; ob = ob->id.next) {
2242                         bActuator *act = ob->actuators.first;
2243                         while (act) {
2244                                 if (act->type == ACT_OBJECT) {
2245                                         /* multiply velocity with 50 in old files */
2246                                         bObjectActuator *oa = act->data;
2247                                         mul_v3_fl(oa->drot, 0.8726646259971648f);
2248                                 }
2249                                 act = act->next;
2250                         }
2251                 }
2252         }
2253
2254         /* init facing axis property of steering actuators */
2255         {
2256                 Object *ob;
2257                 for (ob = main->object.first; ob; ob = ob->id.next) {
2258                         bActuator *act;
2259                         for (act = ob->actuators.first; act; act = act->next) {
2260                                 if (act->type == ACT_STEERING) {
2261                                         bSteeringActuator *stact = act->data;
2262                                         if (stact == NULL) {//HG1
2263                                                 init_actuator(act);
2264                                         }
2265                                         else {
2266                                                 if (stact->facingaxis == 0) {
2267                                                         stact->facingaxis = 1;
2268                                                 }
2269                                         }
2270                                 }
2271                         }
2272                 }
2273         }
2274
2275         if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 3)) {
2276                 Object *ob;
2277
2278                 /* ocean res is now squared, reset old ones - will be massive */
2279                 for (ob = main->object.first; ob; ob = ob->id.next) {
2280                         ModifierData *md;
2281                         for (md = ob->modifiers.first; md; md = md->next) {
2282                                 if (md->type == eModifierType_Ocean) {
2283                                         OceanModifierData *omd = (OceanModifierData *)md;
2284                                         omd->resolution = 7;
2285                                         omd->oceancache = NULL;
2286                                 }
2287                         }
2288                 }
2289         }
2290
2291         if (main->versionfile < 256) {
2292                 bScreen *sc;
2293                 ScrArea *sa;
2294                 Key *key;
2295
2296                 /* Fix for sample line scope initializing with no height */
2297                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2298                         sa = sc->areabase.first;
2299                         while (sa) {
2300                                 SpaceLink *sl;
2301                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2302                                         if (sl->spacetype == SPACE_IMAGE) {
2303                                                 SpaceImage *sima = (SpaceImage *) sl;
2304                                                 if (sima->sample_line_hist.height == 0)
2305                                                         sima->sample_line_hist.height = 100;
2306                                         }
2307                                 }
2308                                 sa = sa->next;
2309                         }
2310                 }
2311
2312                 /* old files could have been saved with slidermin = slidermax = 0.0, but the UI in
2313                  * 2.4x would never reveal this to users as a dummy value always ended up getting used
2314                  * instead
2315                  */
2316                 for (key = main->key.first; key; key = key->id.next) {
2317                         KeyBlock *kb;
2318
2319                         for (kb = key->block.first; kb; kb = kb->next) {
2320                                 if (IS_EQF(kb->slidermin, kb->slidermax) && IS_EQF(kb->slidermax, 0.0f))
2321                                         kb->slidermax = kb->slidermin + 1.0f;
2322                         }
2323                 }
2324         }
2325
2326         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 1)) {
2327                 /* fix for bones that didn't have arm_roll before */
2328                 bArmature *arm;
2329                 Bone *bone;
2330                 Object *ob;
2331
2332                 for (arm = main->armature.first; arm; arm = arm->id.next)
2333                         for (bone = arm->bonebase.first; bone; bone = bone->next)
2334                                 do_version_bone_roll_256(bone);
2335
2336                 /* fix for objects which have zero dquat's
2337                  * since this is multiplied with the quat rather than added */
2338                 for (ob = main->object.first; ob; ob = ob->id.next) {
2339                         if (is_zero_v4(ob->dquat)) {
2340                                 unit_qt(ob->dquat);
2341                         }
2342                         if (is_zero_v3(ob->drotAxis) && ob->drotAngle == 0.0f) {
2343                                 unit_axis_angle(ob->drotAxis, &ob->drotAngle);
2344                         }
2345                 }
2346         }
2347
2348         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)) {
2349                 bNodeTree *ntree;
2350                 bNode *node;
2351                 bNodeSocket *sock, *gsock;
2352                 bNodeLink *link;
2353                 
2354                 /* node sockets are not exposed automatically any more,
2355                  * this mimics the old behavior by adding all unlinked sockets to groups.
2356                  */
2357                 for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
2358                         /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
2359                         
2360                         /* first make sure the own_index for new sockets is valid */
2361                         for (node=ntree->nodes.first; node; node=node->next) {
2362                                 for (sock = node->inputs.first; sock; sock = sock->next)
2363                                         if (sock->own_index >= ntree->cur_index)
2364                                                 ntree->cur_index = sock->own_index+1;
2365                                 for (sock = node->outputs.first; sock; sock = sock->next)
2366                                         if (sock->own_index >= ntree->cur_index)
2367                                                 ntree->cur_index = sock->own_index+1;
2368                         }
2369                         
2370                         /* add ntree->inputs/ntree->outputs sockets for all unlinked sockets in the group tree. */
2371                         for (node=ntree->nodes.first; node; node=node->next) {
2372                                 for (sock = node->inputs.first; sock; sock = sock->next) {
2373                                         if (!sock->link && !nodeSocketIsHidden(sock)) {
2374                                                 
2375                                                 gsock = do_versions_node_group_add_socket_2_56_2(ntree, sock->name, sock->type, SOCK_IN);
2376                                                 
2377                                                 /* initialize the default socket value */
2378                                                 copy_v4_v4(gsock->ns.vec, sock->ns.vec);
2379                                                 
2380                                                 /* XXX nodeAddLink does not work with incomplete (node==NULL) links any longer,
2381                                                  * have to create these directly here. These links are updated again in subsequent do_version!
2382                                                  */
2383                                                 link = MEM_callocN(sizeof(bNodeLink), "link");
2384                                                 BLI_addtail(&ntree->links, link);
2385                                                 link->fromnode = NULL;
2386                                                 link->fromsock = gsock;
2387                                                 link->tonode = node;
2388                                                 link->tosock = sock;
2389                                                 ntree->update |= NTREE_UPDATE_LINKS;
2390                                                 
2391                                                 sock->link = link;
2392                                         }
2393                                 }
2394                                 for (sock = node->outputs.first; sock; sock = sock->next) {
2395                                         if (nodeCountSocketLinks(ntree, sock)==0 && !nodeSocketIsHidden(sock)) {
2396                                                 gsock = do_versions_node_group_add_socket_2_56_2(ntree, sock->name, sock->type, SOCK_OUT);
2397                                                 
2398                                                 /* initialize the default socket value */
2399                                                 copy_v4_v4(gsock->ns.vec, sock->ns.vec);
2400                                                 
2401                                                 /* XXX nodeAddLink does not work with incomplete (node==NULL) links any longer,
2402                                                  * have to create these directly here. These links are updated again in subsequent do_version!
2403                                                  */
2404                                                 link = MEM_callocN(sizeof(bNodeLink), "link");
2405                                                 BLI_addtail(&ntree->links, link);
2406                                                 link->fromnode = node;
2407                                                 link->fromsock = sock;
2408                                                 link->tonode = NULL;
2409                                                 link->tosock = gsock;
2410                                                 ntree->update |= NTREE_UPDATE_LINKS;
2411                                                 
2412                                                 gsock->link = link;
2413                                         }
2414                                 }
2415                         }
2416                         
2417                         /* XXX The external group node sockets needs to adjust their own_index to point at
2418                          * associated ntree inputs/outputs internal sockets. However, this can only happen
2419                          * after lib-linking (needs access to internal node group tree)!
2420                          * Setting a temporary flag here, actual do_versions happens in lib_verify_nodetree.
2421                          */
2422                         ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE_2_56_2;
2423                 }
2424         }
2425
2426         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 3)) {
2427                 bScreen *sc;
2428                 Brush *brush;
2429                 Object *ob;
2430                 ParticleSettings *part;
2431                 Material *mat;
2432                 int tex_nr, transp_tex;
2433
2434                 for (mat = main->mat.first; mat; mat = mat->id.next) {
2435                         if (!(mat->mode & MA_TRANSP) && !(mat->material_type & MA_TYPE_VOLUME)) {
2436                                 transp_tex = 0;
2437
2438                                 for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) {
2439                                         if (!mat->mtex[tex_nr])
2440                                                 continue;
2441                                         if (mat->mtex[tex_nr]->mapto & MAP_ALPHA)
2442                                                 transp_tex = 1;
2443                                 }
2444
2445                                 /* weak! material alpha could be animated */
2446                                 if (mat->alpha < 1.0f || mat->fresnel_tra > 0.0f || transp_tex) {
2447                                         mat->mode |= MA_TRANSP;
2448                                         mat->mode &= ~(MA_ZTRANSP|MA_RAYTRANSP);
2449                                 }
2450                         }
2451                 }
2452
2453                 /* redraws flag in SpaceTime has been moved to Screen level */
2454                 for (sc = main->screen.first; sc; sc = sc->id.next) {
2455                         if (sc->redraws_flag == 0) {
2456                                 /* just initialize to default? */
2457                                 /* XXX: we could also have iterated through areas, and taken them from the first timeline available... */
2458                                 sc->redraws_flag = TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
2459                         }
2460                 }
2461
2462                 for (brush = main->brush.first; brush; brush = brush->id.next) {
2463                         if (brush->height == 0)
2464                                 brush->height = 0.4f;
2465                 }
2466
2467                 /* replace 'rim material' option for in offset*/
2468                 for (ob = main->object.first; ob; ob = ob->id.next) {
2469                         ModifierData *md;
2470                         for (md = ob->modifiers.first; md; md = md->next) {
2471                                 if (md->type == eModifierType_Solidify) {
2472                                         SolidifyModifierData *smd = (SolidifyModifierData *) md;
2473                                         if (smd->flag & MOD_SOLIDIFY_RIM_MATERIAL) {
2474                                                 smd->mat_ofs_rim = 1;
2475                                                 smd->flag &= ~MOD_SOLIDIFY_RIM_MATERIAL;
2476                                         }
2477                                 }
2478                         }
2479                 }
2480
2481                 /* particle draw color from material */
2482                 for (part = main->particle.first; part; part = part->id.next) {
2483                         if (part->draw & PART_DRAW_MAT_COL)
2484                                 part->draw_col = PART_DRAW_COL_MAT;
2485                 }
2486         }
2487
2488         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 6)) {
2489                 Mesh *me;
2490
2491                 for (me = main->mesh.first; me; me = me->id.next)
2492                         BKE_mesh_calc_normals_tessface(me->mvert, me->totvert, me->mface, me->totface, NULL);
2493         }
2494
2495         if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)) {
2496                 /* update blur area sizes from 0..1 range to 0..100 percentage */
2497                 Scene *scene;
2498                 bNode *node;
2499                 for (scene = main->scene.first; scene; scene = scene->id.next)
2500                         if (scene->nodetree)
2501                                 for (node = scene->nodetree->nodes.first; node; node = node->next)
2502                                         if (node->type == CMP_NODE_BLUR) {
2503                                                 NodeBlurData *nbd = node->storage;
2504                                                 nbd->percentx *= 100.0f;
2505                                                 nbd->percenty *= 100.0f;
2506                                         }
2507         }
2508
2509         if (main->versionfile < 258 || (main->versionfile == 258 && main->subversionfile < 1)) {
2510                 /* screen view2d settings were not properly initialized [#27164]
2511                  * v2d->scroll caused the bug but best reset other values too which are in old blend files only.
2512                  * need to make less ugly - possibly an iterator? */
2513                 bScreen *screen;
2514
2515                 for (screen = main->screen.first; screen; screen = screen->id.next) {
2516                         ScrArea *sa;
2517                         /* add regions */
2518                         for (sa = screen->areabase.first; sa; sa = sa->next) {
2519                                 SpaceLink *sl = sa->spacedata.first;
2520                                 if (sl->spacetype == SPACE_IMAGE) {
2521                                         ARegion *ar;
2522                                         for (ar = sa->regionbase.first; ar; ar = ar->next) {
2523                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
2524                                                         View2D *v2d = &ar->v2d;
2525                                                         v2d->minzoom = v2d->maxzoom = v2d->scroll = v2d->keeptot = v2d->keepzoom = v2d->keepofs = v2d->align = 0;
2526                                                 }
2527                                         }
2528                                 }
2529
2530                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2531                                         if (sl->spacetype == SPACE_IMAGE) {
2532                                                 ARegion *ar;
2533                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
2534                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
2535                                                                 View2D *v2d = &ar->v2d;
2536                                                                 v2d->minzoom = v2d->maxzoom = v2d->scroll = v2d->keeptot = v2d->keepzoom = v2d->keepofs = v2d->align = 0;
2537                                                         }
2538                                                 }
2539                                         }
2540                                 }
2541                         }
2542                 }
2543
2544                 {
2545                         /* Initialize texture point density curve falloff */
2546                         Tex *tex;
2547                         for (tex = main->tex.first; tex; tex = tex->id.next) {
2548                                 if (tex->pd) {
2549                                         if (tex->pd->falloff_speed_scale == 0.0f)
2550                                                 tex->pd->falloff_speed_scale = 100.0f;
2551