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