UVEdit: Add back uv angle stretch aspect correction
[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                                 } SEQ_END;
679                         }
680                 }
681
682                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
683                         do_versions_windowmanager_2_50(screen);
684                         do_versions_gpencil_2_50(bmain, screen);
685                 }
686
687                 /* shader, composite and texture node trees have id.name empty, put something in
688                  * to have them show in RNA viewer and accessible otherwise.
689                  */
690                 for (ma = bmain->mat.first; ma; ma = ma->id.next) {
691                         if (ma->nodetree && ma->nodetree->id.name[0] == '\0')
692                                 strcpy(ma->nodetree->id.name, "NTShader Nodetree");
693                 }
694
695                 /* and composite trees */
696                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
697                         enum { R_PANORAMA = (1 << 10) };
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                 /* particle draw and render types */
732                 for (part = bmain->particle.first; part; part = part->id.next) {
733                         if (part->draw_as) {
734                                 if (part->draw_as == PART_DRAW_DOT) {
735                                         part->ren_as = PART_DRAW_HALO;
736                                         part->draw_as = PART_DRAW_REND;
737                                 }
738                                 else if (part->draw_as <= PART_DRAW_AXIS) {
739                                         part->ren_as = PART_DRAW_HALO;
740                                 }
741                                 else {
742                                         part->ren_as = part->draw_as;
743                                         part->draw_as = PART_DRAW_REND;
744                                 }
745                         }
746                         part->path_end = 1.0f;
747                         part->clength = 1.0f;
748                 }
749
750                 /* set old pointcaches to have disk cache flag */
751                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
752
753                         //BKE_ptcache_ids_from_object(&pidlist, ob);
754
755                         //for (pid = pidlist.first; pid; pid = pid->next)
756                         //      pid->cache->flag |= PTCACHE_DISK_CACHE;
757
758                         //BLI_freelistN(&pidlist);
759                 }
760
761                 /* type was a mixed flag & enum. move the 2d flag elsewhere */
762                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
763                         Nurb *nu;
764
765                         for (nu = cu->nurb.first; nu; nu = nu->next) {
766                                 nu->flag |= (nu->type & CU_2D);
767                                 nu->type &= CU_TYPE;
768                         }
769                 }
770         }
771
772         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 1)) {
773                 Object *ob;
774                 Tex *tex;
775                 Scene *sce;
776                 ToolSettings *ts;
777                 //PTCacheID *pid;
778                 //ListBase pidlist;
779
780                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
781                         //BKE_ptcache_ids_from_object(&pidlist, ob);
782
783                         //for (pid = pidlist.first; pid; pid = pid->next) {
784                         //      if (BLI_listbase_is_empty(pid->ptcaches))
785                         //              pid->ptcaches->first = pid->ptcaches->last = pid->cache;
786                         //}
787
788                         //BLI_freelistN(&pidlist);
789
790                         if (ob->type == OB_MESH) {
791                                 Mesh *me = blo_do_versions_newlibadr(fd, lib, ob->data);
792                                 void *olddata = ob->data;
793                                 ob->data = me;
794
795                                 /* XXX - library meshes crash on loading most yoFrankie levels,
796                                  * the multires pointer gets invalid -  Campbell */
797                                 if (me && me->id.lib == NULL && me->mr && me->mr->level_count > 1) {
798                                         multires_load_old(ob, me);
799                                 }
800
801                                 ob->data = olddata;
802                         }
803
804                         if (ob->totcol && ob->matbits == NULL) {
805                                 int a;
806
807                                 ob->matbits = MEM_calloc_arrayN(ob->totcol, sizeof(char), "ob->matbits");
808                                 for (a = 0; a < ob->totcol; a++)
809                                         ob->matbits[a] = (ob->colbits & (1 << a)) != 0;
810                         }
811                 }
812
813                 /* texture filter */
814                 for (tex = bmain->tex.first; tex; tex = tex->id.next) {
815                         if (tex->afmax == 0)
816                                 tex->afmax = 8;
817                 }
818
819                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
820                         ts = sce->toolsettings;
821                         if (!ts->uv_selectmode || ts->vgroup_weight == 0.0f) {
822                                 ts->selectmode = SCE_SELECT_VERTEX;
823
824                                 /* autokeying - setting should be taken from the user-prefs
825                                  * but the userprefs version may not have correct flags set
826                                  * (i.e. will result in blank box when enabled)
827                                  */
828                                 ts->autokey_mode = U.autokey_mode;
829                                 if (ts->autokey_mode == 0)
830                                         ts->autokey_mode = 2; /* 'add/replace' but not on */
831                                 ts->uv_selectmode = UV_SELECT_VERTEX;
832                                 ts->vgroup_weight = 1.0f;
833                         }
834                 }
835         }
836
837         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 2)) {
838                 Object *ob;
839
840                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
841                         if (ob->flag & 8192) // OB_POSEMODE = 8192
842                                 ob->mode |= OB_MODE_POSE;
843                 }
844         }
845
846         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 4)) {
847                 Scene *sce;
848                 Object *ob;
849                 ParticleSettings *part;
850                 bool do_gravity = false;
851
852                 for (sce = bmain->scene.first; sce; sce = sce->id.next)
853                         if (sce->unit.scale_length == 0.0f)
854                                 sce->unit.scale_length = 1.0f;
855
856                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
857                         /* fluid-sim stuff */
858                         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
859                         if (fluidmd)
860                                 fluidmd->fss->fmd = fluidmd;
861
862                         /* rotation modes were added, but old objects would now default to being 'quaternion based' */
863                         ob->rotmode = ROT_MODE_EUL;
864                 }
865
866                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
867                         if (sce->audio.main == 0.0f)
868                                 sce->audio.main = 1.0f;
869
870                         sce->r.ffcodecdata.audio_mixrate = sce->audio.mixrate;
871                         sce->r.ffcodecdata.audio_volume = sce->audio.main;
872                         sce->audio.distance_model = 2;
873                         sce->audio.doppler_factor = 1.0f;
874                         sce->audio.speed_of_sound = 343.3f;
875                 }
876
877                 /* Add default gravity to scenes */
878                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
879                         if ((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0 &&
880                             is_zero_v3(sce->physics_settings.gravity))
881                         {
882                                 sce->physics_settings.gravity[0] = sce->physics_settings.gravity[1] = 0.0f;
883                                 sce->physics_settings.gravity[2] = -9.81f;
884                                 sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
885                                 do_gravity = true;
886                         }
887                 }
888
889                 /* Assign proper global gravity weights for dynamics (only z-coordinate is taken into account) */
890                 if (do_gravity) {
891                         for (part = bmain->particle.first; part; part = part->id.next)
892                                 part->effector_weights->global_gravity = part->acc[2] / -9.81f;
893                 }
894
895                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
896                         ModifierData *md;
897
898                         if (do_gravity) {
899                                 for (md = ob->modifiers.first; md; md = md->next) {
900                                         ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
901                                         if (clmd)
902                                                 clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2] / -9.81f;
903                                 }
904
905                                 if (ob->soft)
906                                         ob->soft->effector_weights->global_gravity = ob->soft->grav / 9.81f;
907                         }
908
909                         /* Normal wind shape is plane */
910                         if (ob->pd) {
911                                 if (ob->pd->forcefield == PFIELD_WIND)
912                                         ob->pd->shape = PFIELD_SHAPE_PLANE;
913
914                                 if (ob->pd->flag & PFIELD_PLANAR)
915                                         ob->pd->shape = PFIELD_SHAPE_PLANE;
916                                 else if (ob->pd->flag & PFIELD_SURFACE)
917                                         ob->pd->shape = PFIELD_SHAPE_SURFACE;
918
919                                 ob->pd->flag |= PFIELD_DO_LOCATION;
920                         }
921                 }
922         }
923
924         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 6)) {
925                 Object *ob;
926
927                 /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialization */
928                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
929                         /* new variables for all objects */
930                         ob->quat[0] = 1.0f;
931                         ob->rotAxis[1] = 1.0f;
932
933                         /* bones */
934                         if (ob->pose) {
935                                 bPoseChannel *pchan;
936
937                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
938                                         /* just need to initalise rotation axis properly... */
939                                         pchan->rotAxis[1] = 1.0f;
940                                 }
941                         }
942                 }
943         }
944
945         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 7)) {
946                 Mesh *me;
947                 Nurb *nu;
948                 Lattice *lt;
949                 Curve *cu;
950                 Key *key;
951                 const float *data;
952                 int a, tot;
953
954                 /* shape keys are no longer applied to the mesh itself, but rather
955                  * to the derivedmesh/displist, so here we ensure that the basis
956                  * shape key is always set in the mesh coordinates. */
957                 for (me = bmain->mesh.first; me; me = me->id.next) {
958                         if ((key = blo_do_versions_newlibadr(fd, lib, me->key)) && key->refkey) {
959                                 data = key->refkey->data;
960                                 tot = MIN2(me->totvert, key->refkey->totelem);
961
962                                 for (a = 0; a < tot; a++, data += 3)
963                                         copy_v3_v3(me->mvert[a].co, data);
964                         }
965                 }
966
967                 for (lt = bmain->latt.first; lt; lt = lt->id.next) {
968                         if ((key = blo_do_versions_newlibadr(fd, lib, lt->key)) && key->refkey) {
969                                 data = key->refkey->data;
970                                 tot = MIN2(lt->pntsu * lt->pntsv * lt->pntsw, key->refkey->totelem);
971
972                                 for (a = 0; a < tot; a++, data += 3)
973                                         copy_v3_v3(lt->def[a].vec, data);
974                         }
975                 }
976
977                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
978                         if ((key = blo_do_versions_newlibadr(fd, lib, cu->key)) && key->refkey) {
979                                 data = key->refkey->data;
980
981                                 for (nu = cu->nurb.first; nu; nu = nu->next) {
982                                         if (nu->bezt) {
983                                                 BezTriple *bezt = nu->bezt;
984
985                                                 for (a = 0; a < nu->pntsu; a++, bezt++) {
986                                                         copy_v3_v3(bezt->vec[0], data); data += 3;
987                                                         copy_v3_v3(bezt->vec[1], data); data += 3;
988                                                         copy_v3_v3(bezt->vec[2], data); data += 3;
989                                                         bezt->alfa = *data; data++;
990                                                 }
991                                         }
992                                         else if (nu->bp) {
993                                                 BPoint *bp = nu->bp;
994
995                                                 for (a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
996                                                         copy_v3_v3(bp->vec, data); data += 3;
997                                                         bp->alfa = *data; data++;
998                                                 }
999                                         }
1000                                 }
1001                         }
1002                 }
1003         }
1004
1005         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 8)) {
1006                 {
1007                         Scene *sce = bmain->scene.first;
1008                         while (sce) {
1009                                 if (sce->r.frame_step == 0)
1010                                         sce->r.frame_step = 1;
1011
1012                                 sce = sce->id.next;
1013                         }
1014                 }
1015
1016                 {
1017                         /* ensure all nodes have unique names */
1018                         bNodeTree *ntree = bmain->nodetree.first;
1019                         while (ntree) {
1020                                 bNode *node = ntree->nodes.first;
1021
1022                                 while (node) {
1023                                         nodeUniqueName(ntree, node);
1024                                         node = node->next;
1025                                 }
1026
1027                                 ntree = ntree->id.next;
1028                         }
1029                 }
1030
1031                 {
1032                         Object *ob = bmain->object.first;
1033                         while (ob) {
1034                                 /* shaded mode disabled for now */
1035                                 if (ob->dt == OB_MATERIAL)
1036                                         ob->dt = OB_TEXTURE;
1037                                 ob = ob->id.next;
1038                         }
1039                 }
1040
1041                 {
1042                         bScreen *screen;
1043                         ScrArea *sa;
1044                         SpaceLink *sl;
1045
1046                         for (screen = bmain->screen.first; screen; screen = screen->id.next) {
1047                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1048                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1049                                                 if (sl->spacetype == SPACE_VIEW3D) {
1050                                                         View3D *v3d = (View3D *)sl;
1051                                                         if (v3d->drawtype == OB_MATERIAL)
1052                                                                 v3d->drawtype = OB_SOLID;
1053                                                 }
1054                                         }
1055                                 }
1056                         }
1057                 }
1058
1059                 /* only convert old 2.50 files with color management */
1060                 if (bmain->versionfile == 250) {
1061                         Scene *sce = bmain->scene.first;
1062                         Material *ma = bmain->mat.first;
1063                         Tex *tex = bmain->tex.first;
1064                         int i, convert = 0;
1065
1066                         /* convert to new color management system:
1067                          * while previously colors were stored as srgb,
1068                          * now they are stored as linear internally,
1069                          * with screen gamma correction in certain places in the UI. */
1070
1071                         /* don't know what scene is active, so we'll convert if any scene has it enabled... */
1072                         while (sce) {
1073                                 if (sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
1074                                         convert = 1;
1075                                 sce = sce->id.next;
1076                         }
1077
1078                         if (convert) {
1079                                 while (ma) {
1080                                         srgb_to_linearrgb_v3_v3(&ma->r, &ma->r);
1081                                         srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr);
1082                                         ma = ma->id.next;
1083                                 }
1084
1085                                 while (tex) {
1086                                         if (tex->coba) {
1087                                                 ColorBand *band = (ColorBand *)tex->coba;
1088                                                 for (i = 0; i < band->tot; i++) {
1089                                                         CBData *data = band->data + i;
1090                                                         srgb_to_linearrgb_v3_v3(&data->r, &data->r);
1091                                                 }
1092                                         }
1093                                         tex = tex->id.next;
1094                                 }
1095                         }
1096                 }
1097         }
1098
1099         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 9)) {
1100                 Scene *sce;
1101                 Mesh *me;
1102                 Object *ob;
1103
1104                 for (sce = bmain->scene.first; sce; sce = sce->id.next)
1105                         if (!sce->toolsettings->particle.selectmode)
1106                                 sce->toolsettings->particle.selectmode = SCE_SELECT_PATH;
1107
1108                 if (bmain->versionfile == 250 && bmain->subversionfile > 1) {
1109                         for (me = bmain->mesh.first; me; me = me->id.next)
1110                                 multires_load_old_250(me);
1111
1112                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1113                                 MultiresModifierData *mmd = (MultiresModifierData *)modifiers_findByType(ob, eModifierType_Multires);
1114
1115                                 if (mmd) {
1116                                         mmd->totlvl--;
1117                                         mmd->lvl--;
1118                                         mmd->sculptlvl = mmd->lvl;
1119                                         mmd->renderlvl = mmd->lvl;
1120                                 }
1121                         }
1122                 }
1123         }
1124
1125         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 10)) {
1126                 Object *ob;
1127
1128                 /* properly initialize hair clothsim data on old files */
1129                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1130                         ModifierData *md;
1131                         for (md = ob->modifiers.first; md; md = md->next) {
1132                                 if (md->type == eModifierType_Cloth) {
1133                                         ClothModifierData *clmd = (ClothModifierData *)md;
1134                                         if (clmd->sim_parms->velocity_smooth < 0.01f)
1135                                                 clmd->sim_parms->velocity_smooth = 0.f;
1136                                 }
1137                         }
1138                 }
1139         }
1140
1141         /* fix bad area setup in subversion 10 */
1142         if (bmain->versionfile == 250 && bmain->subversionfile == 10) {
1143                 /* fix for new view type in sequencer */
1144                 bScreen *screen;
1145                 ScrArea *sa;
1146                 SpaceLink *sl;
1147
1148                 /* remove all preview window in wrong spaces */
1149                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
1150                         for (sa = screen->areabase.first; sa; sa = sa->next) {
1151                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1152                                         if (sl->spacetype != SPACE_SEQ) {
1153                                                 ARegion *ar;
1154                                                 ListBase *regionbase;
1155
1156                                                 if (sl == sa->spacedata.first) {
1157                                                         regionbase = &sa->regionbase;
1158                                                 }
1159                                                 else {
1160                                                         regionbase = &sl->regionbase;
1161                                                 }
1162
1163                                                 for (ar = regionbase->first; ar; ar = ar->next) {
1164                                                         if (ar->regiontype == RGN_TYPE_PREVIEW)
1165                                                                 break;
1166                                                 }
1167
1168                                                 if (ar && (ar->regiontype == RGN_TYPE_PREVIEW)) {
1169                                                         SpaceType *st = BKE_spacetype_from_id(SPACE_SEQ);
1170                                                         BKE_area_region_free(st, ar);
1171                                                         BLI_freelinkN(regionbase, ar);
1172                                                 }
1173                                         }
1174                                 }
1175                         }
1176                 }
1177         }
1178
1179         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 11)) {
1180                 {
1181                         /* fix for new view type in sequencer */
1182                         bScreen *screen;
1183                         ScrArea *sa;
1184                         SpaceLink *sl;
1185
1186                         for (screen = bmain->screen.first; screen; screen = screen->id.next) {
1187                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1188                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1189                                                 if (sl->spacetype == SPACE_SEQ) {
1190                                                         ARegion *ar;
1191                                                         ARegion *ar_main;
1192                                                         ListBase *regionbase;
1193                                                         SpaceSeq *sseq = (SpaceSeq *)sl;
1194
1195                                                         if (sl == sa->spacedata.first) {
1196                                                                 regionbase = &sa->regionbase;
1197                                                         }
1198                                                         else {
1199                                                                 regionbase = &sl->regionbase;
1200                                                         }
1201
1202                                                         if (sseq->view == 0)
1203                                                                 sseq->view = SEQ_VIEW_SEQUENCE;
1204                                                         if (sseq->mainb == 0)
1205                                                                 sseq->mainb = SEQ_DRAW_IMG_IMBUF;
1206
1207                                                         ar_main = (ARegion *)regionbase->first;
1208                                                         for (; ar_main; ar_main = ar_main->next) {
1209                                                                 if (ar_main->regiontype == RGN_TYPE_WINDOW)
1210                                                                         break;
1211                                                         }
1212                                                         ar = MEM_callocN(sizeof(ARegion), "preview area for sequencer");
1213                                                         BLI_insertlinkbefore(regionbase, ar_main, ar);
1214                                                         sequencer_init_preview_region(ar);
1215                                                 }
1216                                         }
1217                                 }
1218                         }
1219                 }
1220         }
1221
1222         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 12)) {
1223                 Object *ob;
1224                 Brush *brush;
1225
1226                 /* anim viz changes */
1227                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1228                         /* initialize object defaults */
1229                         animviz_settings_init(&ob->avs);
1230
1231                         /* if armature, copy settings for pose from armature data
1232                          * performing initialization where appropriate
1233                          */
1234                         if (ob->pose && ob->data) {
1235                                 bArmature *arm = blo_do_versions_newlibadr(fd, lib, ob->data);
1236                                 if (arm) { /* XXX - why does this fail in some cases? */
1237                                         bAnimVizSettings *avs = &ob->pose->avs;
1238
1239                                         /* ghosting settings ---------------- */
1240                                         /* ranges */
1241                                         avs->ghost_bc = avs->ghost_ac = arm->ghostep;
1242
1243                                         avs->ghost_sf = arm->ghostsf;
1244                                         avs->ghost_ef = arm->ghostef;
1245                                         if ((avs->ghost_sf == avs->ghost_ef) && (avs->ghost_sf == 0)) {
1246                                                 avs->ghost_sf = 1;
1247                                                 avs->ghost_ef = 100;
1248                                         }
1249
1250                                         /* type */
1251                                         if (arm->ghostep == 0)
1252                                                 avs->ghost_type = GHOST_TYPE_NONE;
1253                                         else
1254                                                 avs->ghost_type = arm->ghosttype + 1;
1255
1256                                         /* stepsize */
1257                                         avs->ghost_step = arm->ghostsize;
1258                                         if (avs->ghost_step == 0)
1259                                                 avs->ghost_step = 1;
1260
1261                                         /* path settings --------------------- */
1262                                         /* ranges */
1263                                         avs->path_bc = arm->pathbc;
1264                                         avs->path_ac = arm->pathac;
1265                                         if ((avs->path_bc == avs->path_ac) && (avs->path_bc == 0))
1266                                                 avs->path_bc = avs->path_ac = 10;
1267
1268                                         avs->path_sf = arm->pathsf;
1269                                         avs->path_ef = arm->pathef;
1270                                         if ((avs->path_sf == avs->path_ef) && (avs->path_sf == 0)) {
1271                                                 avs->path_sf = 1;
1272                                                 avs->path_ef = 250;
1273                                         }
1274
1275                                         /* flags */
1276                                         if (arm->pathflag & ARM_PATH_FNUMS)
1277                                                 avs->path_viewflag |= MOTIONPATH_VIEW_FNUMS;
1278                                         if (arm->pathflag & ARM_PATH_KFRAS)
1279                                                 avs->path_viewflag |= MOTIONPATH_VIEW_KFRAS;
1280                                         if (arm->pathflag & ARM_PATH_KFNOS)
1281                                                 avs->path_viewflag |= MOTIONPATH_VIEW_KFNOS;
1282
1283                                         /* bake flags */
1284                                         if (arm->pathflag & ARM_PATH_HEADS)
1285                                                 avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS;
1286
1287                                         /* type */
1288                                         if (arm->pathflag & ARM_PATH_ACFRA)
1289                                                 avs->path_type = MOTIONPATH_TYPE_ACFRA;
1290
1291                                         /* stepsize */
1292                                         avs->path_step = arm->pathsize;
1293                                         if (avs->path_step == 0)
1294                                                 avs->path_step = 1;
1295                                 }
1296                                 else
1297                                         animviz_settings_init(&ob->pose->avs);
1298                         }
1299                 }
1300
1301                 /* brush texture changes */
1302                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1303                         BKE_texture_mtex_default(&brush->mtex);
1304                         BKE_texture_mtex_default(&brush->mask_mtex);
1305                 }
1306         }
1307
1308         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 13)) {
1309                 /* NOTE: if you do more conversion, be sure to do it outside of this and
1310                  * increase subversion again, otherwise it will not be correct */
1311                 Object *ob;
1312
1313                 /* convert degrees to radians for internal use */
1314                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1315                         bPoseChannel *pchan;
1316
1317                         do_version_constraints_radians_degrees_250(&ob->constraints);
1318
1319                         if (ob->pose) {
1320                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1321                                         pchan->limitmin[0] *= (float)(M_PI / 180.0);
1322                                         pchan->limitmin[1] *= (float)(M_PI / 180.0);
1323                                         pchan->limitmin[2] *= (float)(M_PI / 180.0);
1324                                         pchan->limitmax[0] *= (float)(M_PI / 180.0);
1325                                         pchan->limitmax[1] *= (float)(M_PI / 180.0);
1326                                         pchan->limitmax[2] *= (float)(M_PI / 180.0);
1327
1328                                         do_version_constraints_radians_degrees_250(&pchan->constraints);
1329                                 }
1330                         }
1331                 }
1332         }
1333
1334         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 14)) {
1335                 /* fix for bad View2D extents for Animation Editors */
1336                 bScreen *screen;
1337                 ScrArea *sa;
1338                 SpaceLink *sl;
1339
1340                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
1341                         for (sa = screen->areabase.first; sa; sa = sa->next) {
1342                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1343                                         ListBase *regionbase;
1344                                         ARegion *ar;
1345
1346                                         if (sl == sa->spacedata.first)
1347                                                 regionbase = &sa->regionbase;
1348                                         else
1349                                                 regionbase = &sl->regionbase;
1350
1351                                         if (ELEM(sl->spacetype, SPACE_ACTION, SPACE_NLA)) {
1352                                                 for (ar = (ARegion *)regionbase->first; ar; ar = ar->next) {
1353                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
1354                                                                 ar->v2d.cur.ymax = ar->v2d.tot.ymax = 0.0f;
1355                                                                 ar->v2d.cur.ymin = ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
1356                                                         }
1357                                                 }
1358                                         }
1359                                 }
1360                         }
1361                 }
1362         }
1363
1364         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 17)) {
1365                 Scene *sce;
1366                 Sequence *seq;
1367
1368                 /* initialize to sane default so toggling on border shows something */
1369                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1370                         if (sce->r.border.xmin == 0.0f && sce->r.border.ymin == 0.0f &&
1371                             sce->r.border.xmax == 0.0f && sce->r.border.ymax == 0.0f)
1372                         {
1373                                 sce->r.border.xmin = 0.0f;
1374                                 sce->r.border.ymin = 0.0f;
1375                                 sce->r.border.xmax = 1.0f;
1376                                 sce->r.border.ymax = 1.0f;
1377                         }
1378
1379                         if ((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0)
1380                                 sce->r.ffcodecdata.audio_codec = 0x0; // CODEC_ID_NONE
1381
1382                         SEQ_BEGIN(sce->ed, seq)
1383                         {
1384                                 seq->volume = 1.0f;
1385                         } SEQ_END;
1386                 }
1387
1388                 /* particle brush strength factor was changed from int to float */
1389                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1390                         ParticleEditSettings *pset = &sce->toolsettings->particle;
1391                         int a;
1392
1393                         for (a = 0; a < ARRAY_SIZE(pset->brush); a++)
1394                                 pset->brush[a].strength /= 100.0f;
1395                 }
1396
1397                 /* sequencer changes */
1398                 {
1399                         bScreen *screen;
1400                         ScrArea *sa;
1401                         SpaceLink *sl;
1402
1403                         for (screen = bmain->screen.first; screen; screen = screen->id.next) {
1404                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
1405                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1406                                                 if (sl->spacetype == SPACE_SEQ) {
1407                                                         ARegion *ar_preview;
1408                                                         ListBase *regionbase;
1409
1410                                                         if (sl == sa->spacedata.first) {
1411                                                                 regionbase = &sa->regionbase;
1412                                                         }
1413                                                         else {
1414                                                                 regionbase = &sl->regionbase;
1415                                                         }
1416
1417                                                         ar_preview = (ARegion *)regionbase->first;
1418                                                         for (; ar_preview; ar_preview = ar_preview->next) {
1419                                                                 if (ar_preview->regiontype == RGN_TYPE_PREVIEW)
1420                                                                         break;
1421                                                         }
1422                                                         if (ar_preview && (ar_preview->regiontype == RGN_TYPE_PREVIEW)) {
1423                                                                 sequencer_init_preview_region(ar_preview);
1424                                                         }
1425                                                 }
1426                                         }
1427                                 }
1428                         }
1429                 } /* sequencer changes */
1430         }
1431
1432         if (bmain->versionfile <= 251) {    /* 2.5.1 had no subversions */
1433                 bScreen *sc;
1434
1435                 /* Blender 2.5.2 - subversion 0 introduced a new setting: V3D_RENDER_OVERRIDE.
1436                  * This bit was used in the past for V3D_TRANSFORM_SNAP, which is now deprecated.
1437                  * Here we clear it for old files so they don't come in with V3D_RENDER_OVERRIDE set,
1438                  * which would cause cameras, lamps, etc to become invisible */
1439                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1440                         ScrArea *sa;
1441                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1442                                 SpaceLink *sl;
1443                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1444                                         if (sl->spacetype == SPACE_VIEW3D) {
1445                                                 View3D *v3d = (View3D *)sl;
1446                                                 v3d->flag2 &= ~V3D_RENDER_OVERRIDE;
1447                                         }
1448                                 }
1449                         }
1450                 }
1451         }
1452
1453         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 1)) {
1454                 Brush *brush;
1455                 Object *ob;
1456                 Scene *scene;
1457                 bNodeTree *ntree;
1458
1459                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1460                         if (brush->curve)
1461                                 brush->curve->preset = CURVE_PRESET_SMOOTH;
1462                 }
1463
1464                 /* properly initialize active flag for fluidsim modifiers */
1465                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1466                         ModifierData *md;
1467                         for (md = ob->modifiers.first; md; md = md->next) {
1468                                 if (md->type == eModifierType_Fluidsim) {
1469                                         FluidsimModifierData *fmd = (FluidsimModifierData *)md;
1470                                         fmd->fss->flag |= OB_FLUIDSIM_ACTIVE;
1471                                         fmd->fss->flag |= OB_FLUIDSIM_OVERRIDE_TIME;
1472                                 }
1473                         }
1474                 }
1475
1476                 /* adjustment to color balance node values */
1477                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1478                         if (scene->nodetree) {
1479                                 bNode *node = scene->nodetree->nodes.first;
1480
1481                                 while (node) {
1482                                         if (node->type == CMP_NODE_COLORBALANCE) {
1483                                                 NodeColorBalance *n = (NodeColorBalance *)node->storage;
1484                                                 n->lift[0] += 1.f;
1485                                                 n->lift[1] += 1.f;
1486                                                 n->lift[2] += 1.f;
1487                                         }
1488                                         node = node->next;
1489                                 }
1490                         }
1491                 }
1492                 /* check inside node groups too */
1493                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) {
1494                         bNode *node = ntree->nodes.first;
1495
1496                         while (node) {
1497                                 if (node->type == CMP_NODE_COLORBALANCE) {
1498                                         NodeColorBalance *n = (NodeColorBalance *)node->storage;
1499                                         n->lift[0] += 1.f;
1500                                         n->lift[1] += 1.f;
1501                                         n->lift[2] += 1.f;
1502                                 }
1503
1504                                 node = node->next;
1505                         }
1506                 }
1507         }
1508
1509         /* old-track -> constraints (this time we're really doing it!) */
1510         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 2)) {
1511                 Object *ob;
1512
1513                 for (ob = bmain->object.first; ob; ob = ob->id.next)
1514                         blo_do_version_old_trackto_to_constraints(ob);
1515         }
1516
1517         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 5)) {
1518                 bScreen *sc;
1519
1520                 /* Image editor scopes */
1521                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1522                         ScrArea *sa;
1523
1524                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1525                                 SpaceLink *sl;
1526
1527                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1528                                         if (sl->spacetype == SPACE_IMAGE) {
1529                                                 SpaceImage *sima = (SpaceImage *)sl;
1530                                                 scopes_new(&sima->scopes);
1531                                         }
1532                                 }
1533                         }
1534                 }
1535         }
1536
1537         if (bmain->versionfile < 253) {
1538                 Object *ob;
1539                 Scene *scene;
1540                 bScreen *sc;
1541                 Tex *tex;
1542                 Brush *brush;
1543
1544                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1545                         ScrArea *sa;
1546                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1547                                 SpaceLink *sl;
1548
1549                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1550                                         if (sl->spacetype == SPACE_NODE) {
1551                                                 SpaceNode *snode = (SpaceNode *)sl;
1552                                                 ListBase *regionbase;
1553                                                 ARegion *ar;
1554
1555                                                 if (sl == sa->spacedata.first)
1556                                                         regionbase = &sa->regionbase;
1557                                                 else
1558                                                         regionbase = &sl->regionbase;
1559
1560                                                 if (snode->v2d.minzoom > 0.09f)
1561                                                         snode->v2d.minzoom = 0.09f;
1562                                                 if (snode->v2d.maxzoom < 2.31f)
1563                                                         snode->v2d.maxzoom = 2.31f;
1564
1565                                                 for (ar = regionbase->first; ar; ar = ar->next) {
1566                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
1567                                                                 if (ar->v2d.minzoom > 0.09f)
1568                                                                         ar->v2d.minzoom = 0.09f;
1569                                                                 if (ar->v2d.maxzoom < 2.31f)
1570                                                                         ar->v2d.maxzoom = 2.31f;
1571                                                         }
1572                                                 }
1573                                         }
1574                                 }
1575                         }
1576                 }
1577
1578                 do_version_mdef_250(bmain);
1579
1580                 /* parent type to modifier */
1581                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1582                         if (ob->parent) {
1583                                 Object *parent = (Object *)blo_do_versions_newlibadr(fd, lib, ob->parent);
1584                                 if (parent) { /* parent may not be in group */
1585                                         if (parent->type == OB_ARMATURE && ob->partype == PARSKEL) {
1586                                                 ArmatureModifierData *amd;
1587                                                 bArmature *arm = (bArmature *)blo_do_versions_newlibadr(fd, lib, parent->data);
1588
1589                                                 amd = (ArmatureModifierData *)modifier_new(eModifierType_Armature);
1590                                                 amd->object = ob->parent;
1591                                                 BLI_addtail((ListBase *)&ob->modifiers, amd);
1592                                                 amd->deformflag = arm->deformflag;
1593                                                 ob->partype = PAROBJECT;
1594                                         }
1595                                         else if (parent->type == OB_LATTICE && ob->partype == PARSKEL) {
1596                                                 LatticeModifierData *lmd;
1597
1598                                                 lmd = (LatticeModifierData *)modifier_new(eModifierType_Lattice);
1599                                                 lmd->object = ob->parent;
1600                                                 BLI_addtail((ListBase *)&ob->modifiers, lmd);
1601                                                 ob->partype = PAROBJECT;
1602                                         }
1603                                         else if (parent->type == OB_CURVE && ob->partype == PARCURVE) {
1604                                                 CurveModifierData *cmd;
1605
1606                                                 cmd = (CurveModifierData *)modifier_new(eModifierType_Curve);
1607                                                 cmd->object = ob->parent;
1608                                                 BLI_addtail((ListBase *)&ob->modifiers, cmd);
1609                                                 ob->partype = PAROBJECT;
1610                                         }
1611                                 }
1612                         }
1613                 }
1614
1615                 /* initialize scene active layer */
1616                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1617                         int i;
1618                         for (i = 0; i < 20; i++) {
1619                                 if (scene->lay & (1 << i)) {
1620                                         scene->layact = 1 << i;
1621                                         break;
1622                                 }
1623                         }
1624                 }
1625
1626                 for (tex = bmain->tex.first; tex; tex = tex->id.next) {
1627                         /* if youre picky, this isn't correct until we do a version bump
1628                          * since you could set saturation to be 0.0*/
1629                         if (tex->saturation == 0.0f)
1630                                 tex->saturation = 1.0f;
1631                 }
1632
1633                 {
1634                         Curve *cu;
1635                         for (cu = bmain->curve.first; cu; cu = cu->id.next) {
1636                                 cu->smallcaps_scale = 0.75f;
1637                         }
1638                 }
1639
1640                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1641                         if (scene) {
1642                                 Sequence *seq;
1643                                 SEQ_BEGIN(scene->ed, seq)
1644                                 {
1645                                         if (seq->sat == 0.0f) {
1646                                                 seq->sat = 1.0f;
1647                                         }
1648                                 } SEQ_END;
1649                         }
1650                 }
1651
1652                 /* GSOC 2010 Sculpt - New settings for Brush */
1653
1654                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1655                         /* Sanity Check */
1656
1657                         /* infinite number of dabs */
1658                         if (brush->spacing == 0)
1659                                 brush->spacing = 10;
1660
1661                         /* will have no effect */
1662                         if (brush->alpha == 0)
1663                                 brush->alpha = 0.5f;
1664
1665                         /* bad radius */
1666                         if (brush->unprojected_radius == 0)
1667                                 brush->unprojected_radius = 0.125f;
1668
1669                         /* unusable size */
1670                         if (brush->size == 0)
1671                                 brush->size = 35;
1672
1673                         /* can't see overlay */
1674                         if (brush->texture_overlay_alpha == 0)
1675                                 brush->texture_overlay_alpha = 33;
1676
1677                         /* same as draw brush */
1678                         if (brush->crease_pinch_factor == 0)
1679                                 brush->crease_pinch_factor = 0.5f;
1680
1681                         /* will sculpt no vertexes */
1682                         if (brush->plane_trim == 0)
1683                                 brush->plane_trim = 0.5f;
1684
1685                         /* same as smooth stroke off */
1686                         if (brush->smooth_stroke_radius == 0)
1687                                 brush->smooth_stroke_radius = 75;
1688
1689                         /* will keep cursor in one spot */
1690                         if (brush->smooth_stroke_radius == 1)
1691                                 brush->smooth_stroke_factor = 0.9f;
1692
1693                         /* same as dots */
1694                         if (brush->rate == 0)
1695                                 brush->rate = 0.1f;
1696
1697                         /* New Settings */
1698                         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 5)) {
1699                                 brush->flag |= BRUSH_SPACE_ATTEN; // explicitly enable adaptive space
1700
1701                                 /* spacing was originally in pixels, convert it to percentage for new version
1702                                  * size should not be zero due to sanity check above
1703                                  */
1704                                 brush->spacing = (int)(100 * ((float)brush->spacing) / ((float)brush->size));
1705
1706                                 if (brush->add_col[0] == 0 &&
1707                                     brush->add_col[1] == 0 &&
1708                                     brush->add_col[2] == 0)
1709                                 {
1710                                         brush->add_col[0] = 1.00f;
1711                                         brush->add_col[1] = 0.39f;
1712                                         brush->add_col[2] = 0.39f;
1713                                 }
1714
1715                                 if (brush->sub_col[0] == 0 &&
1716                                     brush->sub_col[1] == 0 &&
1717                                     brush->sub_col[2] == 0)
1718                                 {
1719                                         brush->sub_col[0] = 0.39f;
1720                                         brush->sub_col[1] = 0.39f;
1721                                         brush->sub_col[2] = 1.00f;
1722                                 }
1723                         }
1724                 }
1725         }
1726
1727         /* GSOC Sculpt 2010 - Sanity check on Sculpt/Paint settings */
1728         if (bmain->versionfile < 253) {
1729                 Scene *sce;
1730                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1731                         if (sce->toolsettings->sculpt_paint_unified_alpha == 0)
1732                                 sce->toolsettings->sculpt_paint_unified_alpha = 0.5f;
1733
1734                         if (sce->toolsettings->sculpt_paint_unified_unprojected_radius == 0)
1735                                 sce->toolsettings->sculpt_paint_unified_unprojected_radius = 0.125f;
1736
1737                         if (sce->toolsettings->sculpt_paint_unified_size == 0)
1738                                 sce->toolsettings->sculpt_paint_unified_size = 35;
1739                 }
1740         }
1741
1742         if (bmain->versionfile < 253 || (bmain->versionfile == 253 && bmain->subversionfile < 1)) {
1743                 Object *ob;
1744
1745                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1746                         ModifierData *md;
1747
1748                         for (md = ob->modifiers.first; md; md = md->next) {
1749                                 if (md->type == eModifierType_Smoke) {
1750                                         SmokeModifierData *smd = (SmokeModifierData *)md;
1751
1752                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
1753                                                 smd->domain->vorticity = 2.0f;
1754                                                 smd->domain->time_scale = 1.0f;
1755
1756                                                 if (!(smd->domain->flags & (1 << 4)))
1757                                                         continue;
1758
1759                                                 /* delete old MOD_SMOKE_INITVELOCITY flag */
1760                                                 smd->domain->flags &= ~(1 << 4);
1761
1762                                                 /* for now just add it to all flow objects in the scene */
1763                                                 {
1764                                                         Object *ob2;
1765                                                         for (ob2 = bmain->object.first; ob2; ob2 = ob2->id.next) {
1766                                                                 ModifierData *md2;
1767                                                                 for (md2 = ob2->modifiers.first; md2; md2 = md2->next) {
1768                                                                         if (md2->type == eModifierType_Smoke) {
1769                                                                                 SmokeModifierData *smd2 = (SmokeModifierData *)md2;
1770
1771                                                                                 if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) {
1772                                                                                         smd2->flow->flags |= MOD_SMOKE_FLOW_INITVELOCITY;
1773                                                                                 }
1774                                                                         }
1775                                                                 }
1776                                                         }
1777                                                 }
1778
1779                                         }
1780                                         else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
1781                                                 smd->flow->vel_multi = 1.0f;
1782                                         }
1783                                 }
1784                         }
1785                 }
1786         }
1787
1788         if (bmain->versionfile < 255 || (bmain->versionfile == 255 && bmain->subversionfile < 1)) {
1789                 Brush *br;
1790                 ParticleSettings *part;
1791                 bScreen *sc;
1792
1793                 for (br = bmain->brush.first; br; br = br->id.next) {
1794                         if (br->ob_mode == 0)
1795                                 br->ob_mode = OB_MODE_ALL_PAINT;
1796                 }
1797
1798                 for (part = bmain->particle.first; part; part = part->id.next) {
1799                         if (part->boids)
1800                                 part->boids->pitch = 1.0f;
1801
1802                         part->flag &= ~PART_HAIR_REGROW; /* this was a deprecated flag before */
1803                         part->kink_amp_clump = 1.f; /* keep old files looking similar */
1804                 }
1805
1806                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1807                         ScrArea *sa;
1808                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1809                                 SpaceLink *sl;
1810                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1811                                         if (sl->spacetype == SPACE_INFO) {
1812                                                 SpaceInfo *sinfo = (SpaceInfo *)sl;
1813                                                 ARegion *ar;
1814
1815                                                 sinfo->rpt_mask = INFO_RPT_OP;
1816
1817                                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
1818                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
1819                                                                 ar->v2d.scroll = (V2D_SCROLL_RIGHT);
1820                                                                 ar->v2d.align = V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
1821                                                                 ar->v2d.keepofs = V2D_LOCKOFS_X;
1822                                                                 ar->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT);
1823                                                                 ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
1824                                                                 ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f;
1825                                                         }
1826                                                 }
1827                                         }
1828                                 }
1829                         }
1830                 }
1831         }
1832
1833         if (bmain->versionfile < 255 || (bmain->versionfile == 255 && bmain->subversionfile < 3)) {
1834                 Object *ob;
1835
1836                 /* ocean res is now squared, reset old ones - will be massive */
1837                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1838                         ModifierData *md;
1839                         for (md = ob->modifiers.first; md; md = md->next) {
1840                                 if (md->type == eModifierType_Ocean) {
1841                                         OceanModifierData *omd = (OceanModifierData *)md;
1842                                         omd->resolution = 7;
1843                                         omd->oceancache = NULL;
1844                                 }
1845                         }
1846                 }
1847         }
1848
1849         if (bmain->versionfile < 256) {
1850                 bScreen *sc;
1851                 ScrArea *sa;
1852                 Key *key;
1853
1854                 /* Fix for sample line scope initializing with no height */
1855                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1856                         sa = sc->areabase.first;
1857                         while (sa) {
1858                                 SpaceLink *sl;
1859                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1860                                         if (sl->spacetype == SPACE_IMAGE) {
1861                                                 SpaceImage *sima = (SpaceImage *)sl;
1862                                                 if (sima->sample_line_hist.height == 0)
1863                                                         sima->sample_line_hist.height = 100;
1864                                         }
1865                                 }
1866                                 sa = sa->next;
1867                         }
1868                 }
1869
1870                 /* old files could have been saved with slidermin = slidermax = 0.0, but the UI in
1871                  * 2.4x would never reveal this to users as a dummy value always ended up getting used
1872                  * instead
1873                  */
1874                 for (key = bmain->key.first; key; key = key->id.next) {
1875                         KeyBlock *kb;
1876
1877                         for (kb = key->block.first; kb; kb = kb->next) {
1878                                 if (IS_EQF(kb->slidermin, kb->slidermax) && IS_EQF(kb->slidermax, 0.0f))
1879                                         kb->slidermax = kb->slidermin + 1.0f;
1880                         }
1881                 }
1882         }
1883
1884         if (bmain->versionfile < 256 || (bmain->versionfile == 256 && bmain->subversionfile < 1)) {
1885                 /* fix for bones that didn't have arm_roll before */
1886                 bArmature *arm;
1887                 Bone *bone;
1888                 Object *ob;
1889
1890                 for (arm = bmain->armature.first; arm; arm = arm->id.next)
1891                         for (bone = arm->bonebase.first; bone; bone = bone->next)
1892                                 do_version_bone_roll_256(bone);
1893
1894                 /* fix for objects which have zero dquat's
1895                  * since this is multiplied with the quat rather than added */
1896                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1897                         if (is_zero_v4(ob->dquat)) {
1898                                 unit_qt(ob->dquat);
1899                         }
1900                         if (is_zero_v3(ob->drotAxis) && ob->drotAngle == 0.0f) {
1901                                 unit_axis_angle(ob->drotAxis, &ob->drotAngle);
1902                         }
1903                 }
1904         }
1905
1906         if (bmain->versionfile < 256 || (bmain->versionfile == 256 && bmain->subversionfile < 2)) {
1907                 bNodeTree *ntree;
1908                 bNode *node;
1909                 bNodeSocket *sock, *gsock;
1910                 bNodeLink *link;
1911
1912                 /* node sockets are not exposed automatically any more,
1913                  * this mimics the old behavior by adding all unlinked sockets to groups.
1914                  */
1915                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) {
1916                         /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
1917
1918                         /* first make sure the own_index for new sockets is valid */
1919                         for (node = ntree->nodes.first; node; node = node->next) {
1920                                 for (sock = node->inputs.first; sock; sock = sock->next)
1921                                         if (sock->own_index >= ntree->cur_index)
1922                                                 ntree->cur_index = sock->own_index + 1;
1923                                 for (sock = node->outputs.first; sock; sock = sock->next)
1924                                         if (sock->own_index >= ntree->cur_index)
1925                                                 ntree->cur_index = sock->own_index + 1;
1926                         }
1927
1928                         /* add ntree->inputs/ntree->outputs sockets for all unlinked sockets in the group tree. */
1929                         for (node = ntree->nodes.first; node; node = node->next) {
1930                                 for (sock = node->inputs.first; sock; sock = sock->next) {
1931                                         if (!sock->link && !nodeSocketIsHidden(sock)) {
1932
1933                                                 gsock = do_versions_node_group_add_socket_2_56_2(ntree, sock->name, sock->type, SOCK_IN);
1934
1935                                                 /* initialize the default socket value */
1936                                                 copy_v4_v4(gsock->ns.vec, sock->ns.vec);
1937
1938                                                 /* XXX nodeAddLink does not work with incomplete (node==NULL) links any longer,
1939                                                  * have to create these directly here. These links are updated again in subsequent do_version!
1940                                                  */
1941                                                 link = MEM_callocN(sizeof(bNodeLink), "link");
1942                                                 BLI_addtail(&ntree->links, link);
1943                                                 link->fromnode = NULL;
1944                                                 link->fromsock = gsock;
1945                                                 link->tonode = node;
1946                                                 link->tosock = sock;
1947                                                 ntree->update |= NTREE_UPDATE_LINKS;
1948
1949                                                 sock->link = link;
1950                                         }
1951                                 }
1952                                 for (sock = node->outputs.first; sock; sock = sock->next) {
1953                                         if (nodeCountSocketLinks(ntree, sock) == 0 && !nodeSocketIsHidden(sock)) {
1954                                                 gsock = do_versions_node_group_add_socket_2_56_2(ntree, sock->name, sock->type, SOCK_OUT);
1955
1956                                                 /* initialize the default socket value */
1957                                                 copy_v4_v4(gsock->ns.vec, sock->ns.vec);
1958
1959                                                 /* XXX nodeAddLink does not work with incomplete (node==NULL) links any longer,
1960                                                  * have to create these directly here. These links are updated again in subsequent do_version!
1961                                                  */
1962                                                 link = MEM_callocN(sizeof(bNodeLink), "link");
1963                                                 BLI_addtail(&ntree->links, link);
1964                                                 link->fromnode = node;
1965                                                 link->fromsock = sock;
1966                                                 link->tonode = NULL;
1967                                                 link->tosock = gsock;
1968                                                 ntree->update |= NTREE_UPDATE_LINKS;
1969
1970                                                 gsock->link = link;
1971                                         }
1972                                 }
1973                         }
1974
1975                         /* XXX The external group node sockets needs to adjust their own_index to point at
1976                          * associated ntree inputs/outputs internal sockets. However, this can only happen
1977                          * after lib-linking (needs access to internal node group tree)!
1978                          * Setting a temporary flag here, actual do_versions happens in lib_verify_nodetree.
1979                          */
1980                         ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE_2_56_2;
1981                 }
1982         }
1983
1984         if (bmain->versionfile < 256 || (bmain->versionfile == 256 && bmain->subversionfile < 3)) {
1985                 bScreen *sc;
1986                 Brush *brush;
1987                 Object *ob;
1988                 ParticleSettings *part;
1989
1990                 /* redraws flag in SpaceTime has been moved to Screen level */
1991                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1992                         if (sc->redraws_flag == 0) {
1993                                 /* just initialize to default? */
1994                                 /* XXX: we could also have iterated through areas, and taken them from the first timeline available... */
1995                                 sc->redraws_flag = TIME_ALL_3D_WIN | TIME_ALL_ANIM_WIN;
1996                         }
1997                 }
1998
1999                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2000                         if (brush->height == 0)
2001                                 brush->height = 0.4f;
2002                 }
2003
2004                 /* replace 'rim material' option for in offset*/
2005                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2006                         ModifierData *md;
2007                         for (md = ob->modifiers.first; md; md = md->next) {
2008                                 if (md->type == eModifierType_Solidify) {
2009                                         SolidifyModifierData *smd = (SolidifyModifierData *)md;
2010                                         if (smd->flag & MOD_SOLIDIFY_RIM_MATERIAL) {
2011                                                 smd->mat_ofs_rim = 1;
2012                                                 smd->flag &= ~MOD_SOLIDIFY_RIM_MATERIAL;
2013                                         }
2014                                 }
2015                         }
2016                 }
2017
2018                 /* particle draw color from material */
2019                 for (part = bmain->particle.first; part; part = part->id.next) {
2020                         if (part->draw & PART_DRAW_MAT_COL)
2021                                 part->draw_col = PART_DRAW_COL_MAT;
2022                 }
2023         }
2024
2025         if (bmain->versionfile < 256 || (bmain->versionfile == 256 && bmain->subversionfile < 6)) {
2026                 Mesh *me;
2027
2028                 for (me = bmain->mesh.first; me; me = me->id.next)
2029                         BKE_mesh_calc_normals_tessface(me->mvert, me->totvert, me->mface, me->totface, NULL);
2030         }
2031
2032         if (bmain->versionfile < 256 || (bmain->versionfile == 256 && bmain->subversionfile < 2)) {
2033                 /* update blur area sizes from 0..1 range to 0..100 percentage */
2034                 Scene *scene;
2035                 bNode *node;
2036                 for (scene = bmain->scene.first; scene; scene = scene->id.next)
2037                         if (scene->nodetree)
2038                                 for (node = scene->nodetree->nodes.first; node; node = node->next)
2039                                         if (node->type == CMP_NODE_BLUR) {
2040                                                 NodeBlurData *nbd = node->storage;
2041                                                 nbd->percentx *= 100.0f;
2042                                                 nbd->percenty *= 100.0f;
2043                                         }
2044         }
2045
2046         if (bmain->versionfile < 258 || (bmain->versionfile == 258 && bmain->subversionfile < 1)) {
2047                 /* screen view2d settings were not properly initialized [#27164]
2048                  * v2d->scroll caused the bug but best reset other values too which are in old blend files only.
2049                  * need to make less ugly - possibly an iterator? */
2050                 bScreen *screen;
2051
2052                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
2053                         ScrArea *sa;
2054                         /* add regions */
2055                         for (sa = screen->areabase.first; sa; sa = sa->next) {
2056                                 SpaceLink *sl = sa->spacedata.first;
2057                                 if (sl->spacetype == SPACE_IMAGE) {
2058                                         ARegion *ar;
2059                                         for (ar = sa->regionbase.first; ar; ar = ar->next) {
2060                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
2061                                                         View2D *v2d = &ar->v2d;
2062                                                         v2d->minzoom = v2d->maxzoom = v2d->scroll = v2d->keeptot = v2d->keepzoom = v2d->keepofs = v2d->align = 0;
2063                                                 }
2064                                         }
2065                                 }
2066
2067                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2068                                         if (sl->spacetype == SPACE_IMAGE) {
2069                                                 ARegion *ar;
2070                                                 for (ar = sl->regionbase.first; ar; ar = ar->next) {
2071                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
2072                                                                 View2D *v2d = &ar->v2d;
2073                                                                 v2d->minzoom = v2d->maxzoom = v2d->scroll = v2d->keeptot = v2d->keepzoom = v2d->keepofs = v2d->align = 0;
2074                                                         }
2075                                                 }
2076                                         }
2077                                 }
2078                         }
2079                 }
2080
2081                 {
2082                         ParticleSettings *part;
2083                         for (part = bmain->particle.first; part; part = part->id.next) {
2084                                 /* Initialize particle billboard scale */
2085                                 part->bb_size[0] = part->bb_size[1] = 1.0f;
2086                         }
2087                 }
2088         }
2089
2090         if (bmain->versionfile < 259 || (bmain->versionfile == 259 && bmain->subversionfile < 1)) {
2091                 {
2092                         Scene *scene;
2093                         Sequence *seq;
2094
2095                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2096                                 scene->r.ffcodecdata.audio_channels = 2;
2097                                 scene->audio.volume = 1.0f;
2098                                 SEQ_BEGIN(scene->ed, seq)
2099                                 {
2100                                         seq->pitch = 1.0f;
2101                                 } SEQ_END;
2102                         }
2103                 }
2104
2105                 {
2106                         bScreen *screen;
2107                         for (screen = bmain->screen.first; screen; screen = screen->id.next) {
2108                                 ScrArea *sa;
2109
2110                                 /* add regions */
2111                                 for (sa = screen->areabase.first; sa; sa = sa->next) {
2112                                         SpaceLink *sl = sa->spacedata.first;
2113                                         if (sl->spacetype == SPACE_SEQ) {
2114                                                 ARegion *ar;
2115                                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
2116                                                         if (ar->regiontype == RGN_TYPE_WINDOW) {
2117                                                                 if (ar->v2d.min[1] == 4.0f)
2118                                                                         ar->v2d.min[1] = 0.5f;
2119                                                         }
2120                                                 }
2121                                         }
2122                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
2123                                                 if (sl->spacetype == SPACE_SEQ) {
2124                                                         ARegion *ar;
2125                                                         for (ar = sl->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                                         }
2133                                 }
2134                         }
2135                 }
2136
2137                 {
2138                         /* Make "auto-clamped" handles a per-keyframe setting instead of per-FCurve
2139                          *
2140                          * We're only patching F-Curves in Actions here, since it is assumed that most
2141                          * drivers out there won't be using this (and if they are, they're in the minority).
2142                          * While we should aim to fix everything ideally, in practice it's far too hard
2143                          * to get to every animdata block, not to mention the performance hit that'd have
2144                          */
2145                         bAction *act;
2146                         FCurve *fcu;
2147
2148                         for (act = bmain->action.first; act; act = act->id.next) {
2149                                 for (fcu = act->curves.first; fcu; fcu = fcu->next) {
2150                                         BezTriple *bezt;
2151                                         uint i = 0;
2152
2153                                         /* only need to touch curves that had this flag set */
2154                                         if ((fcu->flag & FCURVE_AUTO_HANDLES) == 0)
2155                                                 continue;
2156                                         if ((fcu->totvert == 0) || (fcu->bezt == NULL))
2157                                                 continue;
2158
2159                                         /* only change auto-handles to auto-clamped */
2160                                         for (bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
2161                                                 if (bezt->h1 == HD_AUTO)
2162                                                         bezt->h1 = HD_AUTO_ANIM;
2163                                                 if (bezt->h2 == HD_AUTO)
2164                                                         bezt->h2 = HD_AUTO_ANIM;
2165                                         }
2166
2167                                         fcu->flag &= ~FCURVE_AUTO_HANDLES;
2168                                 }
2169                         }
2170                 }
2171         }
2172
2173         if (bmain->versionfile < 259 || (bmain->versionfile == 259 && bmain->subversionfile < 2)) {
2174                 {
2175                         /* Convert default socket values from bNodeStack */
2176                         FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2177                                 bNode *node;
2178                                 bNodeSocket *sock;
2179
2180                                 for (node = ntree->nodes.first; node; node = node->next) {
2181                                         for (sock = node->inputs.first; sock; sock = sock->next)
2182                                                 do_versions_socket_default_value_259(sock);
2183                                         for (sock = node->outputs.first; sock; sock = sock->next)
2184                                                 do_versions_socket_default_value_259(sock);
2185                                 }
2186
2187                                 for (sock = ntree->inputs.first; sock; sock = sock->next)
2188                                         do_versions_socket_default_value_259(sock);
2189                                 for (sock = ntree->outputs.first; sock; sock = sock->next)
2190                                         do_versions_socket_default_value_259(sock);
2191
2192                                 ntree->update |= NTREE_UPDATE;
2193                         } FOREACH_NODETREE_END;
2194                 }
2195
2196                 {
2197                         /* Initialize group tree nodetypes.
2198                          * These are used to distinguish tree types and
2199                          * associate them with specific node types for polling.
2200                          */
2201                         bNodeTree *ntree;
2202                         /* all node trees in bmain->nodetree are considered groups */
2203                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
2204                                 ntree->nodetype = NODE_GROUP;
2205                 }
2206         }
2207
2208         if (bmain->versionfile < 259 || (bmain->versionfile == 259 && bmain->subversionfile < 4)) {
2209                 {
2210                         /* Adaptive time step for particle systems */
2211                         ParticleSettings *part;
2212                         for (part = bmain->particle.first; part; part = part->id.next) {
2213                                 part->courant_target = 0.2f;
2214                                 part->time_flag &= ~PART_TIME_AUTOSF;
2215                         }
2216                 }
2217         }
2218 }