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