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