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