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