Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenloader / intern / versioning_260.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_260.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29
30 /* allow readfile to use deprecated functionality */
31 #define DNA_DEPRECATED_ALLOW
32
33 #include "DNA_anim_types.h"
34 #include "DNA_brush_types.h"
35 #include "DNA_camera_types.h"
36 #include "DNA_cloth_types.h"
37 #include "DNA_constraint_types.h"
38 #include "DNA_genfile.h"
39 #include "DNA_key_types.h"
40 #include "DNA_linestyle_types.h"
41 #include "DNA_mesh_types.h"
42 #include "DNA_meshdata_types.h"
43 #include "DNA_object_fluidsim_types.h"
44 #include "DNA_object_types.h"
45 #include "DNA_text_types.h"
46 #include "DNA_view3d_types.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_sdna_types.h"
49 #include "DNA_smoke_types.h"
50 #include "DNA_space_types.h"
51
52 #include "MEM_guardedalloc.h"
53
54 #include "BLI_blenlib.h"
55 #include "BLI_math.h"
56 #include "BLI_string_utils.h"
57
58 #include "BLT_translation.h"
59
60 #include "BKE_anim.h"
61 #include "BKE_image.h"
62 #include "BKE_main.h" // for Main
63 #include "BKE_mesh.h" // for ME_ defines (patching)
64 #include "BKE_modifier.h"
65 #include "BKE_particle.h"
66 #include "BKE_pointcache.h"
67 #include "BKE_scene.h"
68 #include "BKE_screen.h"
69 #include "BKE_sequencer.h"
70 #include "BKE_text.h" // for txt_extended_ascii_as_utf8
71 #include "BKE_texture.h"
72 #include "BKE_tracking.h"
73 #include "BKE_writeffmpeg.h"
74
75 #include "IMB_imbuf.h"  // for proxy / timecode versioning stuff
76
77 #include "NOD_texture.h"
78
79 #include "BLO_readfile.h"
80
81 #include "readfile.h"
82
83 static void do_versions_nodetree_image_default_alpha_output(bNodeTree *ntree)
84 {
85         bNode *node;
86         bNodeSocket *sock;
87
88         for (node = ntree->nodes.first; node; node = node->next) {
89                 if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) {
90                         /* default Image output value should have 0 alpha */
91                         sock = node->outputs.first;
92                         ((bNodeSocketValueRGBA *)(sock->default_value))->value[3] = 0.0f;
93                 }
94         }
95 }
96
97 static void do_versions_nodetree_convert_angle(bNodeTree *ntree)
98 {
99         bNode *node;
100         for (node = ntree->nodes.first; node; node = node->next) {
101                 if (node->type == CMP_NODE_ROTATE) {
102                         /* Convert degrees to radians. */
103                         bNodeSocket *sock = ((bNodeSocket *)node->inputs.first)->next;
104                         ((bNodeSocketValueFloat *)sock->default_value)->value =
105                                 DEG2RADF(((bNodeSocketValueFloat *)sock->default_value)->value);
106                 }
107                 else if (node->type == CMP_NODE_DBLUR) {
108                         /* Convert degrees to radians. */
109                         NodeDBlurData *ndbd = node->storage;
110                         ndbd->angle = DEG2RADF(ndbd->angle);
111                         ndbd->spin = DEG2RADF(ndbd->spin);
112                 }
113                 else if (node->type == CMP_NODE_DEFOCUS) {
114                         /* Convert degrees to radians. */
115                         NodeDefocus *nqd = node->storage;
116                         /* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
117                         nqd->rotation = DEG2RADF(nqd->rotation * 255.0f);
118                 }
119                 else if (node->type == CMP_NODE_CHROMA_MATTE) {
120                         /* Convert degrees to radians. */
121                         NodeChroma *ndc = node->storage;
122                         ndc->t1 = DEG2RADF(ndc->t1);
123                         ndc->t2 = DEG2RADF(ndc->t2);
124                 }
125                 else if (node->type == CMP_NODE_GLARE) {
126                         /* Convert degrees to radians. */
127                         NodeGlare *ndg = node->storage;
128                         /* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
129                         ndg->angle_ofs = DEG2RADF(ndg->angle_ofs * 255.0f);
130                 }
131                 /* XXX TexMapping struct is used by other nodes too (at least node_composite_mapValue),
132                  *     but not the rot part...
133                  */
134                 else if (node->type == SH_NODE_MAPPING) {
135                         /* Convert degrees to radians. */
136                         TexMapping *tmap = node->storage;
137                         tmap->rot[0] = DEG2RADF(tmap->rot[0]);
138                         tmap->rot[1] = DEG2RADF(tmap->rot[1]);
139                         tmap->rot[2] = DEG2RADF(tmap->rot[2]);
140                 }
141         }
142 }
143
144 static void do_versions_image_settings_2_60(Scene *sce)
145 {
146         /* note: rd->subimtype is moved into individual settings now and no longer
147          * exists */
148         RenderData *rd = &sce->r;
149         ImageFormatData *imf = &sce->r.im_format;
150
151         /* we know no data loss happens here, the old values were in char range */
152         imf->imtype =   (char)rd->imtype;
153         imf->planes =   (char)rd->planes;
154         imf->compress = (char)rd->quality;
155         imf->quality =  (char)rd->quality;
156
157         /* default, was stored in multiple places, may override later */
158         imf->depth = R_IMF_CHAN_DEPTH_8;
159
160         /* openexr */
161         imf->exr_codec = rd->quality & 7; /* strange but true! 0-4 are valid values, OPENEXR_COMPRESS */
162
163         switch (imf->imtype) {
164                 case R_IMF_IMTYPE_OPENEXR:
165                         imf->depth =  (rd->subimtype & R_OPENEXR_HALF) ? R_IMF_CHAN_DEPTH_16 : R_IMF_CHAN_DEPTH_32;
166                         if (rd->subimtype & R_PREVIEW_JPG) {
167                                 imf->flag |= R_IMF_FLAG_PREVIEW_JPG;
168                         }
169                         if (rd->subimtype & R_OPENEXR_ZBUF) {
170                                 imf->flag |= R_IMF_FLAG_ZBUF;
171                         }
172                         break;
173                 case R_IMF_IMTYPE_TIFF:
174                         if (rd->subimtype & R_TIFF_16BIT) {
175                                 imf->depth = R_IMF_CHAN_DEPTH_16;
176                         }
177                         break;
178                 case R_IMF_IMTYPE_JP2:
179                         if (rd->subimtype & R_JPEG2K_16BIT) {
180                                 imf->depth = R_IMF_CHAN_DEPTH_16;
181                         }
182                         else if (rd->subimtype & R_JPEG2K_12BIT) {
183                                 imf->depth = R_IMF_CHAN_DEPTH_12;
184                         }
185
186                         if (rd->subimtype & R_JPEG2K_YCC) {
187                                 imf->jp2_flag |= R_IMF_JP2_FLAG_YCC;
188                         }
189                         if (rd->subimtype & R_JPEG2K_CINE_PRESET) {
190                                 imf->jp2_flag |= R_IMF_JP2_FLAG_CINE_PRESET;
191                         }
192                         if (rd->subimtype & R_JPEG2K_CINE_48FPS) {
193                                 imf->jp2_flag |= R_IMF_JP2_FLAG_CINE_48;
194                         }
195                         break;
196                 case R_IMF_IMTYPE_CINEON:
197                 case R_IMF_IMTYPE_DPX:
198                         if (rd->subimtype & R_CINEON_LOG) {
199                                 imf->cineon_flag |= R_IMF_CINEON_FLAG_LOG;
200                         }
201                         break;
202         }
203 }
204
205 /* socket use flags were only temporary before */
206 static void do_versions_nodetree_socket_use_flags_2_62(bNodeTree *ntree)
207 {
208         bNode *node;
209         bNodeSocket *sock;
210         bNodeLink *link;
211
212         for (node = ntree->nodes.first; node; node = node->next) {
213                 for (sock = node->inputs.first; sock; sock = sock->next)
214                         sock->flag &= ~SOCK_IN_USE;
215                 for (sock = node->outputs.first; sock; sock = sock->next)
216                         sock->flag &= ~SOCK_IN_USE;
217         }
218         for (sock = ntree->inputs.first; sock; sock = sock->next)
219                 sock->flag &= ~SOCK_IN_USE;
220         for (sock = ntree->outputs.first; sock; sock = sock->next)
221                 sock->flag &= ~SOCK_IN_USE;
222
223         for (link = ntree->links.first; link; link = link->next) {
224                 link->fromsock->flag |= SOCK_IN_USE;
225                 link->tosock->flag |= SOCK_IN_USE;
226         }
227 }
228
229 static void do_versions_nodetree_multi_file_output_format_2_62_1(Scene *sce, bNodeTree *ntree)
230 {
231         bNode *node;
232
233         for (node = ntree->nodes.first; node; node = node->next) {
234                 if (node->type == CMP_NODE_OUTPUT_FILE) {
235                         /* previous CMP_NODE_OUTPUT_FILE nodes get converted to multi-file outputs */
236                         NodeImageFile *old_data = node->storage;
237                         NodeImageMultiFile *nimf = MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file");
238                         bNodeSocket *old_image = BLI_findlink(&node->inputs, 0);
239                         bNodeSocket *old_z = BLI_findlink(&node->inputs, 1);
240                         bNodeSocket *sock;
241                         char filename[FILE_MAXFILE];
242
243                         /* ugly, need to remove the old inputs list to avoid bad pointer checks when adding new sockets.
244                          * sock->storage is expected to contain path info in ntreeCompositOutputFileAddSocket.
245                          */
246                         BLI_listbase_clear(&node->inputs);
247
248                         node->storage = nimf;
249
250                         /* looks like storage data can be messed up somehow, stupid check here */
251                         if (old_data) {
252                                 char basepath[FILE_MAXDIR];
253
254                                 /* split off filename from the old path, to be used as socket sub-path */
255                                 BLI_split_dirfile(old_data->name, basepath, filename, sizeof(basepath), sizeof(filename));
256
257                                 BLI_strncpy(nimf->base_path, basepath, sizeof(nimf->base_path));
258                                 nimf->format = old_data->im_format;
259                         }
260                         else {
261                                 BLI_strncpy(filename, old_image->name, sizeof(filename));
262                         }
263
264                         /* if z buffer is saved, change the image type to multilayer exr.
265                          * XXX this is slightly messy, Z buffer was ignored before for anything but EXR and IRIS ...
266                          * i'm just assuming here that IRIZ means IRIS with z buffer ...
267                          */
268                         if (old_data && ELEM(old_data->im_format.imtype, R_IMF_IMTYPE_IRIZ, R_IMF_IMTYPE_OPENEXR)) {
269                                 char sockpath[FILE_MAX];
270
271                                 nimf->format.imtype = R_IMF_IMTYPE_MULTILAYER;
272
273                                 BLI_snprintf(sockpath, sizeof(sockpath), "%s_Image", filename);
274                                 sock = ntreeCompositOutputFileAddSocket(ntree, node, sockpath, &nimf->format);
275                                 /* XXX later do_versions copies path from socket name, need to set this explicitly */
276                                 BLI_strncpy(sock->name, sockpath, sizeof(sock->name));
277                                 if (old_image->link) {
278                                         old_image->link->tosock = sock;
279                                         sock->link = old_image->link;
280                                 }
281
282                                 BLI_snprintf(sockpath, sizeof(sockpath), "%s_Z", filename);
283                                 sock = ntreeCompositOutputFileAddSocket(ntree, node, sockpath, &nimf->format);
284                                 /* XXX later do_versions copies path from socket name, need to set this explicitly */
285                                 BLI_strncpy(sock->name, sockpath, sizeof(sock->name));
286                                 if (old_z->link) {
287                                         old_z->link->tosock = sock;
288                                         sock->link = old_z->link;
289                                 }
290                         }
291                         else {
292                                 sock = ntreeCompositOutputFileAddSocket(ntree, node, filename, &nimf->format);
293                                 /* XXX later do_versions copies path from socket name, need to set this explicitly */
294                                 BLI_strncpy(sock->name, filename, sizeof(sock->name));
295                                 if (old_image->link) {
296                                         old_image->link->tosock = sock;
297                                         sock->link = old_image->link;
298                                 }
299                         }
300
301                         nodeRemoveSocket(ntree, node, old_image);
302                         nodeRemoveSocket(ntree, node, old_z);
303                         if (old_data)
304                                 MEM_freeN(old_data);
305                 }
306                 else if (node->type == CMP_NODE_OUTPUT_MULTI_FILE__DEPRECATED) {
307                         NodeImageMultiFile *nimf = node->storage;
308                         bNodeSocket *sock;
309
310                         /* CMP_NODE_OUTPUT_MULTI_FILE has been redeclared as CMP_NODE_OUTPUT_FILE */
311                         node->type = CMP_NODE_OUTPUT_FILE;
312
313                         /* initialize the node-wide image format from render data, if available */
314                         if (sce)
315                                 nimf->format = sce->r.im_format;
316
317                         /* transfer render format toggle to node format toggle */
318                         for (sock = node->inputs.first; sock; sock = sock->next) {
319                                 NodeImageMultiFileSocket *simf = sock->storage;
320                                 simf->use_node_format = simf->use_render_format;
321                         }
322
323                         /* we do have preview now */
324                         node->flag |= NODE_PREVIEW;
325                 }
326         }
327 }
328
329 /* blue and red are swapped pre 2.62.1, be sane (red == red) now! */
330 static void do_versions_mesh_mloopcol_swap_2_62_1(Mesh *me)
331 {
332         CustomDataLayer *layer;
333         MLoopCol *mloopcol;
334         int a;
335         int i;
336
337         for (a = 0; a < me->ldata.totlayer; a++) {
338                 layer = &me->ldata.layers[a];
339
340                 if (layer->type == CD_MLOOPCOL) {
341                         mloopcol = (MLoopCol *)layer->data;
342                         for (i = 0; i < me->totloop; i++, mloopcol++) {
343                                 SWAP(unsigned char, mloopcol->r, mloopcol->b);
344                         }
345                 }
346         }
347 }
348
349 static void do_versions_nodetree_multi_file_output_path_2_63_1(bNodeTree *ntree)
350 {
351         bNode *node;
352
353         for (node = ntree->nodes.first; node; node = node->next) {
354                 if (node->type == CMP_NODE_OUTPUT_FILE) {
355                         bNodeSocket *sock;
356                         for (sock = node->inputs.first; sock; sock = sock->next) {
357                                 NodeImageMultiFileSocket *input = sock->storage;
358                                 /* input file path is stored in dedicated struct now instead socket name */
359                                 BLI_strncpy(input->path, sock->name, sizeof(input->path));
360                         }
361                 }
362         }
363 }
364
365 static void do_versions_nodetree_file_output_layers_2_64_5(bNodeTree *ntree)
366 {
367         bNode *node;
368
369         for (node = ntree->nodes.first; node; node = node->next) {
370                 if (node->type == CMP_NODE_OUTPUT_FILE) {
371                         bNodeSocket *sock;
372                         for (sock = node->inputs.first; sock; sock = sock->next) {
373                                 NodeImageMultiFileSocket *input = sock->storage;
374
375                                 /* multilayer names are stored as separate strings now,
376                                  * used the path string before, so copy it over.
377                                  */
378                                 BLI_strncpy(input->layer, input->path, sizeof(input->layer));
379
380                                 /* paths/layer names also have to be unique now, initial check */
381                                 ntreeCompositOutputFileUniquePath(&node->inputs, sock, input->path, '_');
382                                 ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, input->layer, '_');
383                         }
384                 }
385         }
386 }
387
388 static void do_versions_nodetree_image_layer_2_64_5(bNodeTree *ntree)
389 {
390         bNode *node;
391
392         for (node = ntree->nodes.first; node; node = node->next) {
393                 if (node->type == CMP_NODE_IMAGE) {
394                         bNodeSocket *sock;
395                         for (sock = node->outputs.first; sock; sock = sock->next) {
396                                 NodeImageLayer *output = MEM_callocN(sizeof(NodeImageLayer), "node image layer");
397
398                                 /* take pass index both from current storage ptr (actually an int) */
399                                 output->pass_index = GET_INT_FROM_POINTER(sock->storage);
400
401                                 /* replace socket data pointer */
402                                 sock->storage = output;
403                         }
404                 }
405         }
406 }
407
408 static void do_versions_nodetree_frame_2_64_6(bNodeTree *ntree)
409 {
410         bNode *node;
411
412         for (node = ntree->nodes.first; node; node = node->next) {
413                 if (node->type == NODE_FRAME) {
414                         /* initialize frame node storage data */
415                         if (node->storage == NULL) {
416                                 NodeFrame *data = (NodeFrame *)MEM_callocN(sizeof(NodeFrame), "frame node storage");
417                                 node->storage = data;
418
419                                 /* copy current flags */
420                                 data->flag = node->custom1;
421
422                                 data->label_size = 20;
423                         }
424                 }
425
426                 /* initialize custom node color */
427                 node->color[0] = node->color[1] = node->color[2] = 0.608f;      /* default theme color */
428         }
429 }
430
431 static void do_versions_affine_tracker_track(MovieTrackingTrack *track)
432 {
433         int i;
434
435         for (i = 0; i < track->markersnr; i++) {
436                 MovieTrackingMarker *marker = &track->markers[i];
437
438                 if (is_zero_v2(marker->pattern_corners[0]) && is_zero_v2(marker->pattern_corners[1]) &&
439                     is_zero_v2(marker->pattern_corners[2]) && is_zero_v2(marker->pattern_corners[3]))
440                 {
441                         marker->pattern_corners[0][0] = track->pat_min[0];
442                         marker->pattern_corners[0][1] = track->pat_min[1];
443
444                         marker->pattern_corners[1][0] = track->pat_max[0];
445                         marker->pattern_corners[1][1] = track->pat_min[1];
446
447                         marker->pattern_corners[2][0] = track->pat_max[0];
448                         marker->pattern_corners[2][1] = track->pat_max[1];
449
450                         marker->pattern_corners[3][0] = track->pat_min[0];
451                         marker->pattern_corners[3][1] = track->pat_max[1];
452                 }
453
454                 if (is_zero_v2(marker->search_min) && is_zero_v2(marker->search_max)) {
455                         copy_v2_v2(marker->search_min, track->search_min);
456                         copy_v2_v2(marker->search_max, track->search_max);
457                 }
458         }
459 }
460
461 static const char *node_get_static_idname(int type, int treetype)
462 {
463         /* use static type info header to map static int type to identifier string */
464 #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
465                 case ID: return #Category #StructName;
466
467         /* XXX hack, group types share a single static integer identifier, but are registered as separate types */
468         if (type == NODE_GROUP) {
469                 switch (treetype) {
470                         case NTREE_COMPOSIT: return "CompositorNodeGroup";
471                         case NTREE_SHADER: return "ShaderNodeGroup";
472                         case NTREE_TEXTURE: return "TextureNodeGroup";
473                 }
474         }
475         else {
476                 switch (type) {
477 #include "NOD_static_types.h"
478                 }
479         }
480         return "";
481 }
482
483 static const char *node_socket_get_static_idname(bNodeSocket *sock)
484 {
485         switch (sock->type) {
486                 case SOCK_FLOAT:
487                 {
488                         bNodeSocketValueFloat *dval = sock->default_value;
489                         return nodeStaticSocketType(SOCK_FLOAT, dval->subtype);
490                 }
491                 case SOCK_INT:
492                 {
493                         bNodeSocketValueInt *dval = sock->default_value;
494                         return nodeStaticSocketType(SOCK_INT, dval->subtype);
495                 }
496                 case SOCK_BOOLEAN:
497                 {
498                         return nodeStaticSocketType(SOCK_BOOLEAN, PROP_NONE);
499                 }
500                 case SOCK_VECTOR:
501                 {
502                         bNodeSocketValueVector *dval = sock->default_value;
503                         return nodeStaticSocketType(SOCK_VECTOR, dval->subtype);
504                 }
505                 case SOCK_RGBA:
506                 {
507                         return nodeStaticSocketType(SOCK_RGBA, PROP_NONE);
508                 }
509                 case SOCK_STRING:
510                 {
511                         bNodeSocketValueString *dval = sock->default_value;
512                         return nodeStaticSocketType(SOCK_STRING, dval->subtype);
513                 }
514                 case SOCK_SHADER:
515                 {
516                         return nodeStaticSocketType(SOCK_SHADER, PROP_NONE);
517                 }
518         }
519         return "";
520 }
521
522 static void do_versions_nodetree_customnodes(bNodeTree *ntree, int UNUSED(is_group))
523 {
524         /* initialize node tree type idname */
525         {
526                 bNode *node;
527                 bNodeSocket *sock;
528
529                 ntree->typeinfo = NULL;
530
531                 /* tree type idname */
532                 switch (ntree->type) {
533                         case NTREE_COMPOSIT:
534                                 strcpy(ntree->idname, "CompositorNodeTree");
535                                 break;
536                         case NTREE_SHADER:
537                                 strcpy(ntree->idname, "ShaderNodeTree");
538                                 break;
539                         case NTREE_TEXTURE:
540                                 strcpy(ntree->idname, "TextureNodeTree");
541                                 break;
542                 }
543
544                 /* node type idname */
545                 for (node = ntree->nodes.first; node; node = node->next) {
546                         BLI_strncpy(node->idname, node_get_static_idname(node->type, ntree->type), sizeof(node->idname));
547
548                         /* existing old nodes have been initialized already */
549                         node->flag |= NODE_INIT;
550
551                         /* sockets idname */
552                         for (sock = node->inputs.first; sock; sock = sock->next)
553                                 BLI_strncpy(sock->idname, node_socket_get_static_idname(sock), sizeof(sock->idname));
554                         for (sock = node->outputs.first; sock; sock = sock->next)
555                                 BLI_strncpy(sock->idname, node_socket_get_static_idname(sock), sizeof(sock->idname));
556                 }
557                 /* tree sockets idname */
558                 for (sock = ntree->inputs.first; sock; sock = sock->next)
559                         BLI_strncpy(sock->idname, node_socket_get_static_idname(sock), sizeof(sock->idname));
560                 for (sock = ntree->outputs.first; sock; sock = sock->next)
561                         BLI_strncpy(sock->idname, node_socket_get_static_idname(sock), sizeof(sock->idname));
562         }
563
564         /* initialize socket in_out values */
565         {
566                 bNode *node;
567                 bNodeSocket *sock;
568
569                 for (node = ntree->nodes.first; node; node = node->next) {
570                         for (sock = node->inputs.first; sock; sock = sock->next)
571                                 sock->in_out = SOCK_IN;
572                         for (sock = node->outputs.first; sock; sock = sock->next)
573                                 sock->in_out = SOCK_OUT;
574                 }
575                 for (sock = ntree->inputs.first; sock; sock = sock->next)
576                         sock->in_out = SOCK_IN;
577                 for (sock = ntree->outputs.first; sock; sock = sock->next)
578                         sock->in_out = SOCK_OUT;
579         }
580
581         /* initialize socket identifier strings */
582         {
583                 bNode *node;
584                 bNodeSocket *sock;
585
586                 for (node = ntree->nodes.first; node; node = node->next) {
587                         for (sock = node->inputs.first; sock; sock = sock->next) {
588                                 BLI_strncpy(sock->identifier, sock->name, sizeof(sock->identifier));
589                                 BLI_uniquename(&node->inputs, sock, "socket", '.',
590                                                offsetof(bNodeSocket, identifier), sizeof(sock->identifier));
591                         }
592                         for (sock = node->outputs.first; sock; sock = sock->next) {
593                                 BLI_strncpy(sock->identifier, sock->name, sizeof(sock->identifier));
594                                 BLI_uniquename(&node->outputs, sock, "socket", '.',
595                                                offsetof(bNodeSocket, identifier), sizeof(sock->identifier));
596                         }
597                 }
598                 for (sock = ntree->inputs.first; sock; sock = sock->next) {
599                         BLI_strncpy(sock->identifier, sock->name, sizeof(sock->identifier));
600                         BLI_uniquename(&ntree->inputs, sock, "socket", '.',
601                                        offsetof(bNodeSocket, identifier), sizeof(sock->identifier));
602                 }
603                 for (sock = ntree->outputs.first; sock; sock = sock->next) {
604                         BLI_strncpy(sock->identifier, sock->name, sizeof(sock->identifier));
605                         BLI_uniquename(&ntree->outputs, sock, "socket", '.',
606                                        offsetof(bNodeSocket, identifier), sizeof(sock->identifier));
607                 }
608         }
609 }
610
611 void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain)
612 {
613         if (bmain->versionfile < 260) {
614                 {
615                         /* set default alpha value of Image outputs in image and render layer nodes to 0 */
616                         Scene *sce;
617                         bNodeTree *ntree;
618
619                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
620                                 /* there are files with invalid audio_channels value, the real cause
621                                  * is unknown, but we fix it here anyway to avoid crashes */
622                                 if (sce->r.ffcodecdata.audio_channels == 0)
623                                         sce->r.ffcodecdata.audio_channels = 2;
624
625                                 if (sce->nodetree)
626                                         do_versions_nodetree_image_default_alpha_output(sce->nodetree);
627                         }
628
629                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
630                                 do_versions_nodetree_image_default_alpha_output(ntree);
631                 }
632
633                 {
634                         /* support old particle dupliobject rotation settings */
635                         ParticleSettings *part;
636
637                         for (part = bmain->particle.first; part; part = part->id.next) {
638                                 if (ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
639                                         part->draw |= PART_DRAW_ROTATE_OB;
640
641                                         if (part->rotmode == 0)
642                                                 part->rotmode = PART_ROT_VEL;
643                                 }
644                         }
645                 }
646         }
647
648         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 1)) {
649                 Object *ob;
650
651                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
652                         ob->collision_boundtype = ob->boundtype;
653                 }
654
655                 {
656                         Camera *cam;
657                         for (cam = bmain->camera.first; cam; cam = cam->id.next) {
658                                 if (cam->sensor_x < 0.01f)
659                                         cam->sensor_x = DEFAULT_SENSOR_WIDTH;
660
661                                 if (cam->sensor_y < 0.01f)
662                                         cam->sensor_y = DEFAULT_SENSOR_HEIGHT;
663                         }
664                 }
665         }
666
667         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 2)) {
668                 FOREACH_NODETREE(bmain, ntree, id) {
669                         if (ntree->type == NTREE_SHADER) {
670                                 bNode *node;
671                                 for (node = ntree->nodes.first; node; node = node->next) {
672                                         if (node->type == SH_NODE_MAPPING) {
673                                                 TexMapping *tex_mapping;
674
675                                                 tex_mapping = node->storage;
676                                                 tex_mapping->projx = PROJ_X;
677                                                 tex_mapping->projy = PROJ_Y;
678                                                 tex_mapping->projz = PROJ_Z;
679                                         }
680                                 }
681                         }
682                 } FOREACH_NODETREE_END
683         }
684
685         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 4)) {
686                 {
687                         /* Convert node angles to radians! */
688                         Scene *sce;
689                         Material *mat;
690                         bNodeTree *ntree;
691
692                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
693                                 if (sce->nodetree)
694                                         do_versions_nodetree_convert_angle(sce->nodetree);
695                         }
696
697                         for (mat = bmain->mat.first; mat; mat = mat->id.next) {
698                                 if (mat->nodetree)
699                                         do_versions_nodetree_convert_angle(mat->nodetree);
700                         }
701
702                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
703                                 do_versions_nodetree_convert_angle(ntree);
704                 }
705
706                 {
707                         /* Tomato compatibility code. */
708                         bScreen *sc;
709                         MovieClip *clip;
710
711                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
712                                 ScrArea *sa;
713                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
714                                         SpaceLink *sl;
715                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
716                                                 if (sl->spacetype == SPACE_VIEW3D) {
717                                                         View3D *v3d = (View3D *)sl;
718                                                         if (v3d->bundle_size == 0.0f) {
719                                                                 v3d->bundle_size = 0.2f;
720                                                                 v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
721                                                         }
722
723                                                         if (v3d->bundle_drawtype == 0)
724                                                                 v3d->bundle_drawtype = OB_PLAINAXES;
725                                                 }
726                                                 else if (sl->spacetype == SPACE_CLIP) {
727                                                         SpaceClip *sclip = (SpaceClip *)sl;
728                                                         if (sclip->scopes.track_preview_height == 0)
729                                                                 sclip->scopes.track_preview_height = 120;
730                                                 }
731                                         }
732                                 }
733                         }
734
735                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
736                                 MovieTrackingTrack *track;
737
738                                 if (clip->aspx < 1.0f) {
739                                         clip->aspx = 1.0f;
740                                         clip->aspy = 1.0f;
741                                 }
742
743                                 clip->proxy.build_tc_flag = IMB_TC_RECORD_RUN |
744                                                             IMB_TC_FREE_RUN |
745                                                             IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN;
746
747                                 if (clip->proxy.build_size_flag == 0)
748                                         clip->proxy.build_size_flag = IMB_PROXY_25;
749
750                                 if (clip->proxy.quality == 0)
751                                         clip->proxy.quality = 90;
752
753                                 if (clip->tracking.camera.pixel_aspect < 0.01f)
754                                         clip->tracking.camera.pixel_aspect = 1.0f;
755
756                                 track = clip->tracking.tracks.first;
757                                 while (track) {
758                                         if (track->minimum_correlation == 0.0f)
759                                                 track->minimum_correlation = 0.75f;
760
761                                         track = track->next;
762                                 }
763                         }
764                 }
765         }
766
767         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 6)) {
768                 Scene *sce;
769                 MovieClip *clip;
770                 bScreen *sc;
771
772                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
773                         do_versions_image_settings_2_60(sce);
774                 }
775
776                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
777                         MovieTrackingSettings *settings = &clip->tracking.settings;
778
779                         if (settings->default_pattern_size == 0.0f) {
780                                 settings->default_motion_model = TRACK_MOTION_MODEL_TRANSLATION;
781                                 settings->default_minimum_correlation = 0.75;
782                                 settings->default_pattern_size = 11;
783                                 settings->default_search_size = 51;
784                         }
785                 }
786
787                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
788                         ScrArea *sa;
789                         for (sa = sc->areabase.first; sa; sa = sa->next) {
790                                 SpaceLink *sl;
791                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
792                                         if (sl->spacetype == SPACE_VIEW3D) {
793                                                 View3D *v3d = (View3D *)sl;
794                                                 v3d->flag2 &= ~V3D_RENDER_SHADOW;
795                                         }
796                                 }
797                         }
798                 }
799
800                 {
801                         Object *ob;
802                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
803                                 /* convert delta addition into delta scale */
804                                 int i;
805                                 for (i = 0; i < 3; i++) {
806                                         if ( (ob->dsize[i] == 0.0f) || /* simple case, user never touched dsize */
807                                              (ob->size[i]  == 0.0f))   /* cant scale the dsize to give a non zero result,
808                                                                         * so fallback to 1.0f */
809                                         {
810                                                 ob->dscale[i] = 1.0f;
811                                         }
812                                         else {
813                                                 ob->dscale[i] = (ob->size[i] + ob->dsize[i]) / ob->size[i];
814                                         }
815                                 }
816                         }
817                 }
818         }
819         /* sigh, this dscale vs dsize version patching was not done right, fix for fix,
820          * this intentionally checks an exact subversion, also note this was never in a release,
821          * at some point this could be removed. */
822         else if (bmain->versionfile == 260 && bmain->subversionfile == 6) {
823                 Object *ob;
824                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
825                         if (is_zero_v3(ob->dscale)) {
826                                 copy_vn_fl(ob->dscale, 3, 1.0f);
827                         }
828                 }
829         }
830
831         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 8)) {
832                 Brush *brush;
833
834                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
835                         if (brush->sculpt_tool == SCULPT_TOOL_ROTATE)
836                                 brush->alpha = 1.0f;
837                 }
838         }
839
840         if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 1)) {
841                 {
842                         /* update use flags for node sockets (was only temporary before) */
843                         Scene *sce;
844                         Material *mat;
845                         Tex *tex;
846                         Lamp *lamp;
847                         World *world;
848                         bNodeTree *ntree;
849
850                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
851                                 if (sce->nodetree)
852                                         do_versions_nodetree_socket_use_flags_2_62(sce->nodetree);
853                         }
854
855                         for (mat = bmain->mat.first; mat; mat = mat->id.next) {
856                                 if (mat->nodetree)
857                                         do_versions_nodetree_socket_use_flags_2_62(mat->nodetree);
858                         }
859
860                         for (tex = bmain->tex.first; tex; tex = tex->id.next) {
861                                 if (tex->nodetree)
862                                         do_versions_nodetree_socket_use_flags_2_62(tex->nodetree);
863                         }
864
865                         for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
866                                 if (lamp->nodetree)
867                                         do_versions_nodetree_socket_use_flags_2_62(lamp->nodetree);
868                         }
869
870                         for (world = bmain->world.first; world; world = world->id.next) {
871                                 if (world->nodetree)
872                                         do_versions_nodetree_socket_use_flags_2_62(world->nodetree);
873                         }
874
875                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) {
876                                 do_versions_nodetree_socket_use_flags_2_62(ntree);
877                         }
878                 }
879                 {
880                         MovieClip *clip;
881                         Object *ob;
882
883                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
884                                 MovieTracking *tracking = &clip->tracking;
885                                 MovieTrackingObject *tracking_object = tracking->objects.first;
886
887                                 clip->proxy.build_tc_flag |= IMB_TC_RECORD_RUN_NO_GAPS;
888
889                                 if (!tracking->settings.object_distance)
890                                         tracking->settings.object_distance = 1.0f;
891
892                                 if (BLI_listbase_is_empty(&tracking->objects))
893                                         BKE_tracking_object_add(tracking, "Camera");
894
895                                 while (tracking_object) {
896                                         if (!tracking_object->scale)
897                                                 tracking_object->scale = 1.0f;
898
899                                         tracking_object = tracking_object->next;
900                                 }
901                         }
902
903                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
904                                 bConstraint *con;
905                                 for (con = ob->constraints.first; con; con = con->next) {
906                                         if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
907                                                 bObjectSolverConstraint *data = (bObjectSolverConstraint *)con->data;
908
909                                                 if (data->invmat[3][3] == 0.0f)
910                                                         unit_m4(data->invmat);
911                                         }
912                                 }
913                         }
914                 }
915         }
916
917         if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 2)) {
918                 {
919                         /* convert deprecated sculpt_paint_unified_* fields to
920                          * UnifiedPaintSettings */
921                         Scene *scene;
922                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
923                                 ToolSettings *ts = scene->toolsettings;
924                                 UnifiedPaintSettings *ups = &ts->unified_paint_settings;
925                                 ups->size = ts->sculpt_paint_unified_size;
926                                 ups->unprojected_radius = ts->sculpt_paint_unified_unprojected_radius;
927                                 ups->alpha = ts->sculpt_paint_unified_alpha;
928                                 ups->flag = ts->sculpt_paint_settings;
929                         }
930                 }
931         }
932
933         if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 3)) {
934                 {
935                         /* convert extended ascii to utf-8 for text editor */
936                         Text *text;
937                         for (text = bmain->text.first; text; text = text->id.next) {
938                                 if (!(text->flags & TXT_ISEXT)) {
939                                         TextLine *tl;
940
941                                         for (tl = text->lines.first; tl; tl = tl->next) {
942                                                 int added = txt_extended_ascii_as_utf8(&tl->line);
943                                                 tl->len += added;
944
945                                                 /* reset cursor position if line was changed */
946                                                 if (added && tl == text->curl)
947                                                         text->curc = 0;
948                                         }
949                                 }
950                         }
951                 }
952                 {
953                         /* set new dynamic paint values */
954                         Object *ob;
955                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
956                                 ModifierData *md;
957                                 for (md = ob->modifiers.first; md; md = md->next) {
958                                         if (md->type == eModifierType_DynamicPaint) {
959                                                 DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
960                                                 if (pmd->canvas) {
961                                                         DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
962                                                         for (; surface; surface = surface->next) {
963                                                                 surface->color_dry_threshold = 1.0f;
964                                                                 surface->influence_scale = 1.0f;
965                                                                 surface->radius_scale = 1.0f;
966                                                                 surface->flags |= MOD_DPAINT_USE_DRYING;
967                                                         }
968                                                 }
969                                         }
970                                 }
971                         }
972                 }
973         }
974
975         if (bmain->versionfile < 262) {
976                 Object *ob;
977                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
978                         ModifierData *md;
979
980                         for (md = ob->modifiers.first; md; md = md->next) {
981                                 if (md->type == eModifierType_Cloth) {
982                                         ClothModifierData *clmd = (ClothModifierData *) md;
983                                         if (clmd->sim_parms)
984                                                 clmd->sim_parms->vel_damping = 1.0f;
985                                 }
986                         }
987                 }
988         }
989
990         if (bmain->versionfile < 263) {
991                 /* set fluidsim rate. the version patch for this in 2.62 was wrong, so
992                  * try to correct it, if rate is 0.0 that's likely not intentional */
993                 Object *ob;
994
995                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
996                         ModifierData *md;
997                         for (md = ob->modifiers.first; md; md = md->next) {
998                                 if (md->type == eModifierType_Fluidsim) {
999                                         FluidsimModifierData *fmd = (FluidsimModifierData *)md;
1000                                         if (fmd->fss->animRate == 0.0f)
1001                                                 fmd->fss->animRate = 1.0f;
1002                                 }
1003                         }
1004                 }
1005         }
1006
1007         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 1)) {
1008                 /* update use flags for node sockets (was only temporary before) */
1009                 Scene *sce;
1010                 bNodeTree *ntree;
1011
1012                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1013                         if (sce->nodetree)
1014                                 do_versions_nodetree_multi_file_output_format_2_62_1(sce, sce->nodetree);
1015                 }
1016
1017                 /* XXX can't associate with scene for group nodes, image format will stay uninitialized */
1018                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
1019                         do_versions_nodetree_multi_file_output_format_2_62_1(NULL, ntree);
1020         }
1021
1022         /* only swap for pre-release bmesh merge which had MLoopCol red/blue swap */
1023         if (bmain->versionfile == 262 && bmain->subversionfile == 1) {
1024                 {
1025                         Mesh *me;
1026                         for (me = bmain->mesh.first; me; me = me->id.next) {
1027                                 do_versions_mesh_mloopcol_swap_2_62_1(me);
1028                         }
1029                 }
1030         }
1031
1032         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 2)) {
1033                 /* Set new idname of keyingsets from their now "label-only" name. */
1034                 Scene *scene;
1035                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1036                         KeyingSet *ks;
1037                         for (ks = scene->keyingsets.first; ks; ks = ks->next) {
1038                                 if (!ks->idname[0])
1039                                         BLI_strncpy(ks->idname, ks->name, sizeof(ks->idname));
1040                         }
1041                 }
1042         }
1043
1044         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 3)) {
1045                 Object *ob;
1046                 ModifierData *md;
1047
1048                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1049                         for (md = ob->modifiers.first; md; md = md->next) {
1050                                 if (md->type == eModifierType_Lattice) {
1051                                         LatticeModifierData *lmd = (LatticeModifierData *)md;
1052                                         lmd->strength = 1.0f;
1053                                 }
1054                         }
1055                 }
1056         }
1057
1058         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 4)) {
1059                 /* Read Viscosity presets from older files */
1060                 Object *ob;
1061
1062                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1063                         ModifierData *md;
1064                         for (md = ob->modifiers.first; md; md = md->next) {
1065                                 if (md->type == eModifierType_Fluidsim) {
1066                                         FluidsimModifierData *fmd = (FluidsimModifierData *)md;
1067                                         if (fmd->fss->viscosityMode == 3) {
1068                                                 fmd->fss->viscosityValue = 5.0;
1069                                                 fmd->fss->viscosityExponent = 5;
1070                                         }
1071                                         else if (fmd->fss->viscosityMode == 4) {
1072                                                 fmd->fss->viscosityValue = 2.0;
1073                                                 fmd->fss->viscosityExponent = 3;
1074                                         }
1075                                 }
1076                         }
1077                 }
1078         }
1079
1080
1081
1082         if (bmain->versionfile < 263) {
1083                 /* Default for old files is to save particle rotations to pointcache */
1084                 ParticleSettings *part;
1085                 for (part = bmain->particle.first; part; part = part->id.next) {
1086                         part->flag |= PART_ROTATIONS;
1087                 }
1088         }
1089
1090         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 1)) {
1091                 /* file output node paths are now stored in the file info struct instead socket name */
1092                 Scene *sce;
1093                 bNodeTree *ntree;
1094
1095                 for (sce = bmain->scene.first; sce; sce = sce->id.next)
1096                         if (sce->nodetree)
1097                                 do_versions_nodetree_multi_file_output_path_2_63_1(sce->nodetree);
1098                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
1099                         do_versions_nodetree_multi_file_output_path_2_63_1(ntree);
1100         }
1101
1102         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 3)) {
1103                 Scene *scene;
1104                 Brush *brush;
1105
1106                 /* For weight paint, each brush now gets its own weight;
1107                  * unified paint settings also have weight. Update unified
1108                  * paint settings and brushes with a default weight value. */
1109
1110                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1111                         ToolSettings *ts = scene->toolsettings;
1112                         if (ts) {
1113                                 ts->unified_paint_settings.weight = ts->vgroup_weight;
1114                                 ts->unified_paint_settings.flag |= UNIFIED_PAINT_WEIGHT;
1115                         }
1116                 }
1117
1118                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1119                         brush->weight = 0.5;
1120                 }
1121         }
1122
1123         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 2)) {
1124                 bScreen *sc;
1125
1126                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1127                         ScrArea *sa;
1128                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1129                                 SpaceLink *sl;
1130
1131                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1132                                         if (sl->spacetype == SPACE_CLIP) {
1133                                                 SpaceClip *sclip = (SpaceClip *)sl;
1134                                                 ARegion *ar;
1135                                                 bool hide = false;
1136
1137                                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
1138                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
1139                                                                 if (ar->alignment != RGN_ALIGN_NONE) {
1140                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1141                                                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
1142                                                                         ar->alignment = RGN_ALIGN_NONE;
1143
1144                                                                         hide = true;
1145                                                                 }
1146                                                         }
1147                                                 }
1148
1149                                                 if (hide) {
1150                                                         sclip->view = SC_VIEW_CLIP;
1151                                                 }
1152                                         }
1153                                 }
1154                         }
1155                 }
1156         }
1157
1158         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 4)) {
1159                 Camera *cam;
1160                 Curve *cu;
1161
1162                 for (cam = bmain->camera.first; cam; cam = cam->id.next) {
1163                         if (cam->flag & CAM_PANORAMA) {
1164                                 cam->type = CAM_PANO;
1165                                 cam->flag &= ~CAM_PANORAMA;
1166                         }
1167                 }
1168
1169                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
1170                         if (cu->bevfac2 == 0.0f) {
1171                                 cu->bevfac1 = 0.0f;
1172                                 cu->bevfac2 = 1.0f;
1173                         }
1174                 }
1175         }
1176
1177         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 5)) {
1178                 {
1179                         /* file output node paths are now stored in the file info struct instead socket name */
1180                         Scene *sce;
1181                         bNodeTree *ntree;
1182
1183                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1184                                 if (sce->nodetree) {
1185                                         do_versions_nodetree_file_output_layers_2_64_5(sce->nodetree);
1186                                         do_versions_nodetree_image_layer_2_64_5(sce->nodetree);
1187                                 }
1188                         }
1189                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) {
1190                                 do_versions_nodetree_file_output_layers_2_64_5(ntree);
1191                                 do_versions_nodetree_image_layer_2_64_5(ntree);
1192                         }
1193                 }
1194         }
1195
1196         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 6)) {
1197                 /* update use flags for node sockets (was only temporary before) */
1198                 Scene *sce;
1199                 Material *mat;
1200                 Tex *tex;
1201                 Lamp *lamp;
1202                 World *world;
1203                 bNodeTree *ntree;
1204
1205                 for (sce = bmain->scene.first; sce; sce = sce->id.next)
1206                         if (sce->nodetree)
1207                                 do_versions_nodetree_frame_2_64_6(sce->nodetree);
1208
1209                 for (mat = bmain->mat.first; mat; mat = mat->id.next)
1210                         if (mat->nodetree)
1211                                 do_versions_nodetree_frame_2_64_6(mat->nodetree);
1212
1213                 for (tex = bmain->tex.first; tex; tex = tex->id.next)
1214                         if (tex->nodetree)
1215                                 do_versions_nodetree_frame_2_64_6(tex->nodetree);
1216
1217                 for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next)
1218                         if (lamp->nodetree)
1219                                 do_versions_nodetree_frame_2_64_6(lamp->nodetree);
1220
1221                 for (world = bmain->world.first; world; world = world->id.next)
1222                         if (world->nodetree)
1223                                 do_versions_nodetree_frame_2_64_6(world->nodetree);
1224
1225                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
1226                         do_versions_nodetree_frame_2_64_6(ntree);
1227         }
1228
1229         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 7)) {
1230                 Object *ob;
1231
1232                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1233                         ModifierData *md;
1234                         for (md = ob->modifiers.first; md; md = md->next) {
1235                                 if (md->type == eModifierType_Smoke) {
1236                                         SmokeModifierData *smd = (SmokeModifierData *)md;
1237                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
1238                                                 int maxres = max_iii(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2]);
1239                                                 smd->domain->scale = smd->domain->dx * maxres;
1240                                                 smd->domain->dx = 1.0f / smd->domain->scale;
1241                                         }
1242                                 }
1243                         }
1244                 }
1245         }
1246
1247         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 9)) {
1248                 FOREACH_NODETREE(bmain, ntree, id) {
1249                         if (ntree->type == NTREE_SHADER) {
1250                                 bNode *node;
1251                                 for (node = ntree->nodes.first; node; node = node->next) {
1252                                         if (ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) {
1253                                                 NodeTexImage *tex = node->storage;
1254
1255                                                 tex->iuser.frames = 1;
1256                                                 tex->iuser.sfra = 1;
1257                                                 tex->iuser.fie_ima = 2;
1258                                                 tex->iuser.ok = 1;
1259                                         }
1260                                 }
1261                         }
1262                 } FOREACH_NODETREE_END
1263         }
1264
1265         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 10)) {
1266                 {
1267                         Scene *scene;
1268                         // composite redesign
1269                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1270                                 if (scene->nodetree) {
1271                                         if (scene->nodetree->chunksize == 0) {
1272                                                 scene->nodetree->chunksize = 256;
1273                                         }
1274                                 }
1275                         }
1276
1277                         FOREACH_NODETREE(bmain, ntree, id) {
1278                                 if (ntree->type == NTREE_COMPOSIT) {
1279                                         bNode *node;
1280                                         for (node = ntree->nodes.first; node; node = node->next) {
1281                                                 if (node->type == CMP_NODE_DEFOCUS) {
1282                                                         NodeDefocus *data = node->storage;
1283                                                         if (data->maxblur == 0.0f) {
1284                                                                 data->maxblur = 16.0f;
1285                                                         }
1286                                                 }
1287                                         }
1288                                 }
1289                         } FOREACH_NODETREE_END
1290                 }
1291
1292                 {
1293                         bScreen *sc;
1294
1295                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1296                                 ScrArea *sa;
1297
1298                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1299                                         SpaceLink *sl;
1300
1301                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1302                                                 if (sl->spacetype == SPACE_CLIP) {
1303                                                         SpaceClip *sclip = (SpaceClip *)sl;
1304
1305                                                         if (sclip->around == 0) {
1306                                                                 sclip->around = V3D_AROUND_CENTER_MEAN;
1307                                                         }
1308                                                 }
1309                                         }
1310                                 }
1311                         }
1312                 }
1313
1314                 {
1315                         MovieClip *clip;
1316
1317                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1318                                 clip->start_frame = 1;
1319                         }
1320                 }
1321         }
1322
1323         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 11)) {
1324                 MovieClip *clip;
1325
1326                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1327                         MovieTrackingTrack *track;
1328
1329                         track = clip->tracking.tracks.first;
1330                         while (track) {
1331                                 do_versions_affine_tracker_track(track);
1332
1333                                 track = track->next;
1334                         }
1335                 }
1336         }
1337
1338         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 13)) {
1339                 FOREACH_NODETREE(bmain, ntree, id) {
1340                         if (ntree->type == NTREE_COMPOSIT) {
1341                                 bNode *node;
1342                                 for (node = ntree->nodes.first; node; node = node->next) {
1343                                         if (node->type == CMP_NODE_DILATEERODE) {
1344                                                 if (node->storage == NULL) {
1345                                                         NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), __func__);
1346                                                         data->falloff = PROP_SMOOTH;
1347                                                         node->storage = data;
1348                                                 }
1349                                         }
1350                                 }
1351                         }
1352                 } FOREACH_NODETREE_END
1353         }
1354
1355         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 14)) {
1356                 ParticleSettings *part;
1357
1358                 FOREACH_NODETREE(bmain, ntree, id) {
1359                         if (ntree->type == NTREE_COMPOSIT) {
1360                                 bNode *node;
1361                                 for (node = ntree->nodes.first; node; node = node->next) {
1362                                         if (node->type == CMP_NODE_KEYING) {
1363                                                 NodeKeyingData *data = node->storage;
1364
1365                                                 if (data->despill_balance == 0.0f) {
1366                                                         data->despill_balance = 0.5f;
1367                                                 }
1368                                         }
1369                                 }
1370                         }
1371                 } FOREACH_NODETREE_END
1372
1373                 /* keep compatibility for dupliobject particle size */
1374                 for (part = bmain->particle.first; part; part = part->id.next)
1375                         if (ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR))
1376                                 if ((part->draw & PART_DRAW_ROTATE_OB) == 0)
1377                                         part->draw |= PART_DRAW_NO_SCALE_OB;
1378         }
1379
1380         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 17)) {
1381                 FOREACH_NODETREE(bmain, ntree, id) {
1382                         if (ntree->type == NTREE_COMPOSIT) {
1383                                 bNode *node;
1384                                 for (node = ntree->nodes.first; node; node = node->next) {
1385                                         if (node->type == CMP_NODE_MASK) {
1386                                                 if (node->storage == NULL) {
1387                                                         NodeMask *data = MEM_callocN(sizeof(NodeMask), __func__);
1388                                                         /* move settings into own struct */
1389                                                         data->size_x = (int)node->custom3;
1390                                                         data->size_y = (int)node->custom4;
1391                                                         node->custom3 = 0.5f; /* default shutter */
1392                                                         node->storage = data;
1393                                                 }
1394                                         }
1395                                 }
1396                         }
1397                 } FOREACH_NODETREE_END
1398         }
1399
1400         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 18)) {
1401                 Scene *scene;
1402
1403                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1404                         if (scene->ed) {
1405                                 Sequence *seq;
1406
1407                                 SEQ_BEGIN (scene->ed, seq)
1408                                 {
1409                                         Strip *strip = seq->strip;
1410
1411                                         if (strip && strip->color_balance) {
1412                                                 SequenceModifierData *smd;
1413                                                 ColorBalanceModifierData *cbmd;
1414
1415                                                 smd = BKE_sequence_modifier_new(seq, NULL, seqModifierType_ColorBalance);
1416                                                 cbmd = (ColorBalanceModifierData *) smd;
1417
1418                                                 cbmd->color_balance = *strip->color_balance;
1419
1420                                                 /* multiplication with color balance used is handled differently,
1421                                                  * so we need to move multiplication to modifier so files would be
1422                                                  * compatible
1423                                                  */
1424                                                 cbmd->color_multiply = seq->mul;
1425                                                 seq->mul = 1.0f;
1426
1427                                                 MEM_freeN(strip->color_balance);
1428                                                 strip->color_balance = NULL;
1429                                         }
1430                                 }
1431                                 SEQ_END
1432                         }
1433                 }
1434         }
1435
1436         /* color management pipeline changes compatibility code */
1437         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 19)) {
1438                 Scene *scene;
1439                 Image *ima;
1440                 bool colormanagement_disabled = false;
1441
1442                 /* make scenes which are not using color management have got None as display device,
1443                  * so they wouldn't perform linear-to-sRGB conversion on display
1444                  */
1445                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1446                         if ((scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) == 0) {
1447                                 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
1448
1449                                 if (display_settings->display_device[0] == 0) {
1450                                         BKE_scene_disable_color_management(scene);
1451
1452                                 }
1453
1454                                 colormanagement_disabled = true;
1455                         }
1456                 }
1457
1458                 for (ima = bmain->image.first; ima; ima = ima->id.next) {
1459                         if (ima->source == IMA_SRC_VIEWER) {
1460                                 ima->flag |= IMA_VIEW_AS_RENDER;
1461                         }
1462                         else if (colormanagement_disabled) {
1463                                 /* if colormanagement not used, set image's color space to raw, so no sRGB->linear conversion
1464                                  * would happen on display and render
1465                                  * there's no clear way to check whether color management is enabled or not in render engine
1466                                  * so set all images to raw if there's at least one scene with color management disabled
1467                                  * this would still behave incorrect in cases when color management was used for only some
1468                                  * of scenes, but such a setup is crazy anyway and think it's fair enough to break compatibility
1469                                  * in that cases
1470                                  */
1471
1472                                 BLI_strncpy(ima->colorspace_settings.name, "Raw", sizeof(ima->colorspace_settings.name));
1473                         }
1474                 }
1475         }
1476
1477         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 20)) {
1478                 Key *key;
1479                 for (key = bmain->key.first; key; key = key->id.next) {
1480                         blo_do_versions_key_uidgen(key);
1481                 }
1482         }
1483
1484         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 21)) {
1485                 {
1486                         Mesh *me;
1487                         for (me = bmain->mesh.first; me; me = me->id.next) {
1488                                 CustomData_update_typemap(&me->vdata);
1489                                 CustomData_free_layers(&me->vdata, CD_MSTICKY, me->totvert);
1490                         }
1491                 }
1492         }
1493
1494         /* correction for files saved in blender version when BKE_pose_copy_data
1495          * didn't copy animation visualization, which lead to deadlocks on motion
1496          * path calculation for proxied armatures, see [#32742]
1497          */
1498         if (bmain->versionfile < 264) {
1499                 Object *ob;
1500
1501                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1502                         if (ob->pose) {
1503                                 if (ob->pose->avs.path_step == 0) {
1504                                         animviz_settings_init(&ob->pose->avs);
1505                                 }
1506                         }
1507                 }
1508         }
1509
1510         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 1)) {
1511                 FOREACH_NODETREE(bmain, ntree, id) {
1512                         if (ntree->type == NTREE_SHADER) {
1513                                 bNode *node;
1514                                 for (node = ntree->nodes.first; node; node = node->next)
1515                                         if (node->type == SH_NODE_TEX_COORD)
1516                                                 node->flag |= NODE_OPTIONS;
1517                         }
1518                 } FOREACH_NODETREE_END
1519         }
1520
1521         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 2)) {
1522                 MovieClip *clip;
1523
1524                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1525                         MovieTracking *tracking = &clip->tracking;
1526                         MovieTrackingObject *tracking_object;
1527
1528                         for (tracking_object = tracking->objects.first;
1529                              tracking_object;
1530                              tracking_object = tracking_object->next)
1531                         {
1532                                 if (tracking_object->keyframe1 == 0 && tracking_object->keyframe2 == 0) {
1533                                         tracking_object->keyframe1 = tracking->settings.keyframe1;
1534                                         tracking_object->keyframe2 = tracking->settings.keyframe2;
1535                                 }
1536                         }
1537                 }
1538         }
1539
1540         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 3)) {
1541                 /* smoke branch */
1542                 {
1543                         Object *ob;
1544
1545                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1546                                 ModifierData *md;
1547                                 for (md = ob->modifiers.first; md; md = md->next) {
1548                                         if (md->type == eModifierType_Smoke) {
1549                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1550                                                 if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
1551                                                         /* keep branch saves if possible */
1552                                                         if (!smd->domain->flame_max_temp) {
1553                                                                 smd->domain->burning_rate = 0.75f;
1554                                                                 smd->domain->flame_smoke = 1.0f;
1555                                                                 smd->domain->flame_vorticity = 0.5f;
1556                                                                 smd->domain->flame_ignition = 1.25f;
1557                                                                 smd->domain->flame_max_temp = 1.75f;
1558                                                                 smd->domain->adapt_threshold = 0.02f;
1559                                                                 smd->domain->adapt_margin = 4;
1560                                                                 smd->domain->flame_smoke_color[0] = 0.7f;
1561                                                                 smd->domain->flame_smoke_color[1] = 0.7f;
1562                                                                 smd->domain->flame_smoke_color[2] = 0.7f;
1563                                                         }
1564                                                 }
1565                                                 else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
1566                                                         if (!smd->flow->texture_size) {
1567                                                                 smd->flow->fuel_amount = 1.0;
1568                                                                 smd->flow->surface_distance = 1.5;
1569                                                                 smd->flow->color[0] = 0.7f;
1570                                                                 smd->flow->color[1] = 0.7f;
1571                                                                 smd->flow->color[2] = 0.7f;
1572                                                                 smd->flow->texture_size = 1.0f;
1573                                                         }
1574                                                 }
1575                                         }
1576                                 }
1577                         }
1578                 }
1579
1580                 /* render border for viewport */
1581                 {
1582                         bScreen *sc;
1583
1584                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1585                                 ScrArea *sa;
1586                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1587                                         SpaceLink *sl;
1588                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1589                                                 if (sl->spacetype == SPACE_VIEW3D) {
1590                                                         View3D *v3d = (View3D *)sl;
1591                                                         if (v3d->render_border.xmin == 0.0f && v3d->render_border.ymin == 0.0f &&
1592                                                             v3d->render_border.xmax == 0.0f && v3d->render_border.ymax == 0.0f)
1593                                                         {
1594                                                                 v3d->render_border.xmax = 1.0f;
1595                                                                 v3d->render_border.ymax = 1.0f;
1596                                                         }
1597                                                 }
1598                                         }
1599                                 }
1600                         }
1601                 }
1602         }
1603
1604         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 5)) {
1605                 /* set a unwrapping margin and ABF by default */
1606                 Scene *scene;
1607
1608                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1609                         if (scene->toolsettings->uvcalc_margin == 0.0f) {
1610                                 scene->toolsettings->uvcalc_margin = 0.001f;
1611                                 scene->toolsettings->unwrapper = 0;
1612                         }
1613                 }
1614         }
1615
1616         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 6)) {
1617                 /* Fix for bug #32982, internal_links list could get corrupted from r51630 onward.
1618                  * Simply remove bad internal_links lists to avoid NULL pointers.
1619                  */
1620                 FOREACH_NODETREE(bmain, ntree, id) {
1621                         bNode *node;
1622                         bNodeLink *link, *nextlink;
1623
1624                         for (node = ntree->nodes.first; node; node = node->next) {
1625                                 for (link = node->internal_links.first; link; link = nextlink) {
1626                                         nextlink = link->next;
1627                                         if (!link->fromnode || !link->fromsock || !link->tonode || !link->tosock) {
1628                                                 BLI_remlink(&node->internal_links, link);
1629                                         }
1630                                 }
1631                         }
1632                 } FOREACH_NODETREE_END
1633         }
1634
1635         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) {
1636                 /* convert tiles size from resolution and number of tiles */
1637                 {
1638                         Scene *scene;
1639
1640                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1641                                 if (scene->r.tilex == 0 || scene->r.tiley == 1) {
1642                                         scene->r.tilex = scene->r.tiley = 64;
1643                                 }
1644                         }
1645                 }
1646
1647                 /* collision masks */
1648                 {
1649                         Object *ob;
1650                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1651                                 if (ob->col_group == 0) {
1652                                         ob->col_group = 0x01;
1653                                         ob->col_mask = 0xff;
1654                                 }
1655                         }
1656                 }
1657         }
1658
1659         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) {
1660                 MovieClip *clip;
1661
1662                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1663                         MovieTrackingTrack *track;
1664                         MovieTrackingObject *object;
1665
1666                         for (track = clip->tracking.tracks.first; track; track = track->next) {
1667                                 do_versions_affine_tracker_track(track);
1668                         }
1669
1670                         for (object = clip->tracking.objects.first; object; object = object->next) {
1671                                 for (track = object->tracks.first; track; track = track->next) {
1672                                         do_versions_affine_tracker_track(track);
1673                                 }
1674                         }
1675                 }
1676         }
1677
1678         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 3)) {
1679                 bScreen *sc;
1680                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1681                         ScrArea *sa;
1682                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1683                                 SpaceLink *sl;
1684                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1685                                         switch (sl->spacetype) {
1686                                                 case SPACE_VIEW3D:
1687                                                 {
1688                                                         View3D *v3d = (View3D *)sl;
1689                                                         v3d->flag2 |= V3D_SHOW_GPENCIL;
1690                                                         break;
1691                                                 }
1692                                                 case SPACE_SEQ:
1693                                                 {
1694                                                         SpaceSeq *sseq = (SpaceSeq *)sl;
1695                                                         sseq->flag |= SEQ_SHOW_GPENCIL;
1696                                                         break;
1697                                                 }
1698                                                 case SPACE_IMAGE:
1699                                                 {
1700                                                         SpaceImage *sima = (SpaceImage *)sl;
1701                                                         sima->flag |= SI_SHOW_GPENCIL;
1702                                                         break;
1703                                                 }
1704                                                 case SPACE_NODE:
1705                                                 {
1706                                                         SpaceNode *snode = (SpaceNode *)sl;
1707                                                         snode->flag |= SNODE_SHOW_GPENCIL;
1708                                                         break;
1709                                                 }
1710                                                 case SPACE_CLIP:
1711                                                 {
1712                                                         SpaceClip *sclip = (SpaceClip *)sl;
1713                                                         sclip->flag |= SC_SHOW_GPENCIL;
1714                                                         break;
1715                                                 }
1716                                         }
1717                                 }
1718                         }
1719                 }
1720         }
1721
1722         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 5)) {
1723                 Scene *scene;
1724                 Tex *tex;
1725
1726                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1727                         Sequence *seq;
1728
1729                         SEQ_BEGIN (scene->ed, seq)
1730                         {
1731                                 if (seq->flag & SEQ_MAKE_PREMUL) {
1732                                         seq->alpha_mode = SEQ_ALPHA_STRAIGHT;
1733                                 }
1734                                 else {
1735                                         BKE_sequence_alpha_mode_from_extension(seq);
1736                                 }
1737                         }
1738                         SEQ_END
1739
1740                         if (scene->r.bake_samples == 0)
1741                                 scene->r.bake_samples = 256;
1742                 }
1743
1744                 for (Image *image = bmain->image.first; image; image = image->id.next) {
1745                         if (image->flag & IMA_DO_PREMUL) {
1746                                 image->alpha_mode = IMA_ALPHA_STRAIGHT;
1747                         }
1748                         else {
1749                                 BKE_image_alpha_mode_from_extension(image);
1750                         }
1751                 }
1752
1753                 for (tex = bmain->tex.first; tex; tex = tex->id.next) {
1754                         if (tex->type == TEX_IMAGE && (tex->imaflag & TEX_USEALPHA) == 0) {
1755                                 Image *image = blo_do_versions_newlibadr(fd, tex->id.lib, tex->ima);
1756
1757                                 if (image && (image->flag & IMA_DO_PREMUL) == 0)
1758                                         image->flag |= IMA_IGNORE_ALPHA;
1759                         }
1760                 }
1761
1762                 FOREACH_NODETREE(bmain, ntree, id) {
1763                         if (ntree->type == NTREE_COMPOSIT) {
1764                                 bNode *node;
1765                                 for (node = ntree->nodes.first; node; node = node->next) {
1766                                         if (node->type == CMP_NODE_IMAGE) {
1767                                                 Image *image = blo_do_versions_newlibadr(fd, ntree->id.lib, node->id);
1768
1769                                                 if (image) {
1770                                                         if ((image->flag & IMA_DO_PREMUL) == 0 && image->alpha_mode == IMA_ALPHA_STRAIGHT)
1771                                                                 node->custom1 |= CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT;
1772                                                 }
1773                                         }
1774                                 }
1775                         }
1776                 } FOREACH_NODETREE_END
1777         }
1778         else if (bmain->versionfile < 266 || (bmain->versionfile == 266 && bmain->subversionfile < 1)) {
1779                 /* texture use alpha was removed for 2.66 but added back again for 2.66a,
1780                  * for compatibility all textures assumed it to be enabled */
1781                 Tex *tex;
1782
1783                 for (tex = bmain->tex.first; tex; tex = tex->id.next)
1784                         if (tex->type == TEX_IMAGE)
1785                                 tex->imaflag |= TEX_USEALPHA;
1786         }
1787
1788         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 7)) {
1789                 Curve *cu;
1790
1791                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
1792                         if (cu->flag & (CU_FRONT | CU_BACK)) {
1793                                 if ( cu->ext1 != 0.0f || cu->ext2 != 0.0f) {
1794                                         Nurb *nu;
1795
1796                                         for (nu = cu->nurb.first; nu; nu = nu->next) {
1797                                                 int a;
1798
1799                                                 if (nu->bezt) {
1800                                                         BezTriple *bezt = nu->bezt;
1801                                                         a = nu->pntsu;
1802
1803                                                         while (a--) {
1804                                                                 bezt->radius = 1.0f;
1805                                                                 bezt++;
1806                                                         }
1807                                                 }
1808                                                 else if (nu->bp) {
1809                                                         BPoint *bp = nu->bp;
1810                                                         a = nu->pntsu * nu->pntsv;
1811
1812                                                         while (a--) {
1813                                                                 bp->radius = 1.0f;
1814                                                                 bp++;
1815                                                         }
1816                                                 }
1817                                         }
1818                                 }
1819                         }
1820                 }
1821         }
1822
1823         if (MAIN_VERSION_OLDER(bmain, 265, 9)) {
1824                 Mesh *me;
1825                 for (me = bmain->mesh.first; me; me = me->id.next) {
1826                         BKE_mesh_do_versions_cd_flag_init(me);
1827                 }
1828         }
1829
1830         if (MAIN_VERSION_OLDER(bmain, 265, 10)) {
1831                 Brush *br;
1832                 for (br = bmain->brush.first; br; br = br->id.next) {
1833                         if (br->ob_mode & OB_MODE_TEXTURE_PAINT) {
1834                                 br->mtex.brush_map_mode = MTEX_MAP_MODE_TILED;
1835                         }
1836                 }
1837         }
1838
1839         // add storage for compositor translate nodes when not existing
1840         if (MAIN_VERSION_OLDER(bmain, 265, 11)) {
1841                 FOREACH_NODETREE(bmain, ntree, id) {
1842                         if (ntree->type == NTREE_COMPOSIT) {
1843                                 bNode *node;
1844                                 for (node = ntree->nodes.first; node; node = node->next) {
1845                                         if (node->type == CMP_NODE_TRANSLATE && node->storage == NULL) {
1846                                                 node->storage = MEM_callocN(sizeof(NodeTranslateData), "node translate data");
1847                                         }
1848                                 }
1849                         }
1850                 } FOREACH_NODETREE_END
1851         }
1852
1853         if (MAIN_VERSION_OLDER(bmain, 266, 2)) {
1854                 FOREACH_NODETREE(bmain, ntree, id) {
1855                         do_versions_nodetree_customnodes(ntree, ((ID *)ntree == id));
1856                 } FOREACH_NODETREE_END
1857         }
1858
1859         if (MAIN_VERSION_OLDER(bmain, 266, 2)) {
1860                 bScreen *sc;
1861                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1862                         ScrArea *sa;
1863                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1864                                 SpaceLink *sl;
1865                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1866                                         if (sl->spacetype == SPACE_NODE) {
1867                                                 SpaceNode *snode = (SpaceNode *)sl;
1868
1869                                                 /* reset pointers to force tree path update from context */
1870                                                 snode->nodetree = NULL;
1871                                                 snode->edittree = NULL;
1872                                                 snode->id = NULL;
1873                                                 snode->from = NULL;
1874
1875                                                 /* convert deprecated treetype setting to tree_idname */
1876                                                 switch (snode->treetype) {
1877                                                         case NTREE_COMPOSIT:
1878                                                                 strcpy(snode->tree_idname, "CompositorNodeTree");
1879                                                                 break;
1880                                                         case NTREE_SHADER:
1881                                                                 strcpy(snode->tree_idname, "ShaderNodeTree");
1882                                                                 break;
1883                                                         case NTREE_TEXTURE:
1884                                                                 strcpy(snode->tree_idname, "TextureNodeTree");
1885                                                                 break;
1886                                                 }
1887                                         }
1888                                 }
1889                         }
1890                 }
1891         }
1892
1893         /* Set flag for delayed do_versions in lib_verify_nodetree. It needs valid typeinfo pointers ... */
1894         {
1895                 FOREACH_NODETREE(bmain, ntree, id) {
1896                         /* XXX This should be kept without version check for now!
1897                          * As long as USE_NODE_COMPAT_CUSTOMNODES is active, files will write links
1898                          * to tree interface sockets for forward compatibility. These links need to be removed again
1899                          * on file load in new versions.
1900                          * Once forward compatibility is not required any longer, make a subversion bump
1901                          * and only execute this for older versions.
1902                          */
1903                         ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP;
1904
1905                         /* Only add interface nodes once.
1906                          * In old Blender versions they will be removed automatically due to undefined type */
1907                         if (MAIN_VERSION_OLDER(bmain, 266, 2))
1908                                 ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP_CREATE_INTERFACE;
1909                 }
1910                 FOREACH_NODETREE_END
1911         }
1912
1913         if (MAIN_VERSION_OLDER(bmain, 266, 3)) {
1914                 {
1915                         /* Fix for a very old issue:
1916                          * Node names were nominally made unique in r24478 (2.50.8), but the do_versions check
1917                          * to update existing node names only applied to bmain->nodetree (i.e. group nodes).
1918                          * Uniqueness is now required for proper preview mapping,
1919                          * so do this now to ensure old files don't break.
1920                          */
1921                         bNode *node;
1922                         FOREACH_NODETREE(bmain, ntree, id) {
1923                                 if (id == &ntree->id)
1924                                         continue;       /* already fixed for node groups */
1925
1926                                 for (node = ntree->nodes.first; node; node = node->next)
1927                                         nodeUniqueName(ntree, node);
1928                         }
1929                         FOREACH_NODETREE_END
1930                 }
1931         }
1932
1933         if (!MAIN_VERSION_ATLEAST(bmain, 266, 4)) {
1934                 Brush *brush;
1935                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1936                         BKE_texture_mtex_default(&brush->mask_mtex);
1937
1938                         if (brush->ob_mode & OB_MODE_TEXTURE_PAINT) {
1939                                 brush->spacing /= 2;
1940                         }
1941                 }
1942         }
1943
1944         if (!MAIN_VERSION_ATLEAST(bmain, 266, 6)) {
1945                 Brush *brush;
1946 #define BRUSH_TEXTURE_OVERLAY (1 << 21)
1947
1948                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1949                         brush->overlay_flags = 0;
1950                         if (brush->flag & BRUSH_TEXTURE_OVERLAY)
1951                                 brush->overlay_flags |= (BRUSH_OVERLAY_PRIMARY | BRUSH_OVERLAY_CURSOR);
1952                 }
1953 #undef BRUSH_TEXTURE_OVERLAY
1954         }
1955
1956         if (bmain->versionfile < 267) {
1957                 //if (!DNA_struct_elem_find(fd->filesdna, "Brush", "int", "stencil_pos")) {
1958                 Brush *brush;
1959
1960                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1961                         if (brush->stencil_dimension[0] == 0) {
1962                                 brush->stencil_dimension[0] = 256;
1963                                 brush->stencil_dimension[1] = 256;
1964                                 brush->stencil_pos[0] = 256;
1965                                 brush->stencil_pos[1] = 256;
1966                         }
1967                         if (brush->mask_stencil_dimension[0] == 0) {
1968                                 brush->mask_stencil_dimension[0] = 256;
1969                                 brush->mask_stencil_dimension[1] = 256;
1970                                 brush->mask_stencil_pos[0] = 256;
1971                                 brush->mask_stencil_pos[1] = 256;
1972                         }
1973                 }
1974
1975                 /* TIP: to initialize new variables added, use the new function
1976                  * DNA_struct_elem_find(fd->filesdna, "structname", "typename", "varname")
1977                  * example:
1978                  * if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "image_gpubuffer_limit"))
1979                  *     user->image_gpubuffer_limit = 10;
1980                  */
1981
1982         }
1983
1984         /* default values in Freestyle settings */
1985         if (bmain->versionfile < 267) {
1986                 Scene *sce;
1987                 SceneRenderLayer *srl;
1988                 FreestyleLineStyle *linestyle;
1989
1990                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1991                         if (sce->r.line_thickness_mode == 0) {
1992                                 sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE;
1993                                 sce->r.unit_line_thickness = 1.0f;
1994                         }
1995                         for (srl = sce->r.layers.first; srl; srl = srl->next) {
1996                                 if (srl->freestyleConfig.mode == 0)
1997                                         srl->freestyleConfig.mode = FREESTYLE_CONTROL_EDITOR_MODE;
1998                                 if (srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE ||
1999                                     srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL)
2000                                 {
2001                                         srl->freestyleConfig.raycasting_algorithm = 0; /* deprecated */
2002                                         srl->freestyleConfig.flags |= FREESTYLE_CULLING;
2003                                 }
2004                         }
2005
2006                         /* not freestyle */
2007                         {
2008                                 MeshStatVis *statvis = &sce->toolsettings->statvis;
2009                                 if (statvis->thickness_samples == 0) {
2010                                         statvis->overhang_axis = OB_NEGZ;
2011                                         statvis->overhang_min = 0;
2012                                         statvis->overhang_max = DEG2RADF(45.0f);
2013
2014                                         statvis->thickness_max = 0.1f;
2015                                         statvis->thickness_samples = 1;
2016
2017                                         statvis->distort_min = DEG2RADF(5.0f);
2018                                         statvis->distort_max = DEG2RADF(45.0f);
2019
2020                                         statvis->sharp_min = DEG2RADF(90.0f);
2021                                         statvis->sharp_max = DEG2RADF(180.0f);
2022                                 }
2023                         }
2024
2025                 }
2026                 for (linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
2027 #if 1
2028                         /* disable the Misc panel for now */
2029                         if (linestyle->panel == LS_PANEL_MISC) {
2030                                 linestyle->panel = LS_PANEL_STROKES;
2031                         }
2032 #endif
2033                         if (linestyle->thickness_position == 0) {
2034                                 linestyle->thickness_position = LS_THICKNESS_CENTER;
2035                                 linestyle->thickness_ratio = 0.5f;
2036                         }
2037                         if (linestyle->chaining == 0)
2038                                 linestyle->chaining = LS_CHAINING_PLAIN;
2039                         if (linestyle->rounds == 0)
2040                                 linestyle->rounds = 3;
2041                 }
2042         }
2043
2044         if (bmain->versionfile < 267) {
2045                 /* Initialize the active_viewer_key for compositing */
2046                 bScreen *screen;
2047                 Scene *scene;
2048                 bNodeInstanceKey active_viewer_key = {0};
2049                 /* simply pick the first node space and use that for the active viewer key */
2050                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
2051                         ScrArea *sa;
2052                         for (sa = screen->areabase.first; sa; sa = sa->next) {
2053                                 SpaceLink *sl;
2054                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2055                                         if (sl->spacetype == SPACE_NODE) {
2056                                                 SpaceNode *snode = (SpaceNode *)sl;
2057                                                 bNodeTreePath *path = snode->treepath.last;
2058                                                 if (!path)
2059                                                         continue;
2060
2061                                                 active_viewer_key = path->parent_key;
2062                                                 break;
2063                                         }
2064                                 }
2065                                 if (active_viewer_key.value != 0)
2066                                         break;
2067                         }
2068                         if (active_viewer_key.value != 0)
2069                                 break;
2070                 }
2071
2072                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2073                         /* NB: scene->nodetree is a local ID block, has been direct_link'ed */
2074                         if (scene->nodetree)
2075                                 scene->nodetree->active_viewer_key = active_viewer_key;
2076                 }
2077         }
2078
2079         if (MAIN_VERSION_OLDER(bmain, 267, 1)) {
2080                 Object *ob;
2081
2082                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2083                         ModifierData *md;
2084                         for (md = ob->modifiers.first; md; md = md->next) {
2085                                 if (md->type == eModifierType_Smoke) {
2086                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2087                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
2088                                                 if (smd->domain->flags & MOD_SMOKE_HIGH_SMOOTH) {
2089                                                         smd->domain->highres_sampling = SM_HRES_LINEAR;
2090                                                 }
2091                                                 else {
2092                                                         smd->domain->highres_sampling = SM_HRES_NEAREST;
2093                                                 }
2094                                         }
2095                                 }
2096                         }
2097                 }
2098         }
2099
2100         if (!MAIN_VERSION_ATLEAST(bmain, 268, 1)) {
2101                 Brush *brush;
2102                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2103                         brush->spacing = MAX2(1, brush->spacing);
2104                 }
2105         }
2106
2107         if (!MAIN_VERSION_ATLEAST(bmain, 268, 2)) {
2108                 Brush *brush;
2109 #define BRUSH_FIXED (1 << 6)
2110                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2111                         brush->flag &= ~BRUSH_FIXED;
2112
2113                         if (brush->cursor_overlay_alpha < 2)
2114                                 brush->cursor_overlay_alpha = 33;
2115                         if (brush->texture_overlay_alpha < 2)
2116                                 brush->texture_overlay_alpha = 33;
2117                         if (brush->mask_overlay_alpha < 2)
2118                                 brush->mask_overlay_alpha = 33;
2119                 }
2120 #undef BRUSH_FIXED
2121         }
2122
2123
2124         if (!MAIN_VERSION_ATLEAST(bmain, 268, 4)) {
2125                 bScreen *sc;
2126                 Object *ob;
2127
2128                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2129                         bConstraint *con;
2130                         for (con = ob->constraints.first; con; con = con->next) {
2131                                 if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
2132                                         bShrinkwrapConstraint *data = (bShrinkwrapConstraint *)con->data;
2133                                         if      (data->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) data->projAxis = OB_POSX;
2134                                         else if (data->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) data->projAxis = OB_POSY;
2135                                         else                                                          data->projAxis = OB_POSZ;
2136                                         data->projAxisSpace = CONSTRAINT_SPACE_LOCAL;
2137                                 }
2138                         }
2139                 }
2140
2141                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2142                         ModifierData *md;
2143                         for (md = ob->modifiers.first; md; md = md->next) {
2144                                 if (md->type == eModifierType_Smoke) {
2145                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2146                                         if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
2147                                                 if (!smd->flow->particle_size) {
2148                                                         smd->flow->particle_size = 1.0f;
2149                                                 }
2150                                         }
2151                                 }
2152                         }
2153                 }
2154
2155                 /*
2156                  * FIX some files have a zoom level of 0, and was checked during the drawing of the node space
2157                  *
2158                  * We moved this check to the do versions to be sure the value makes any sense.
2159                  */
2160                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2161                         ScrArea *sa;
2162                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2163                                 SpaceLink *sl;
2164                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2165                                         if (sl->spacetype == SPACE_NODE) {
2166                                                 SpaceNode *snode = (SpaceNode *)sl;
2167                                                 if (snode->zoom < 0.02f) {
2168                                                         snode->zoom = 1.0;
2169                                                 }
2170                                         }
2171                                 }
2172                         }
2173                 }
2174         }
2175
2176         if (!MAIN_VERSION_ATLEAST(bmain, 268, 5)) {
2177                 bScreen *sc;
2178                 ScrArea *sa;
2179
2180                 /* add missing (+) expander in node editor */
2181                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2182                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2183                                 ARegion *ar, *arnew;
2184
2185                                 if (sa->spacetype == SPACE_NODE) {
2186                                         ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
2187
2188                                         if (ar)
2189                                                 continue;
2190
2191                                         /* add subdiv level; after header */
2192                                         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
2193
2194                                         /* is error! */
2195                                         if (ar == NULL)
2196                                                 continue;
2197
2198                                         arnew = MEM_callocN(sizeof(ARegion), "node tools");
2199
2200                                         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
2201                                         arnew->regiontype = RGN_TYPE_TOOLS;
2202                                         arnew->alignment = RGN_ALIGN_LEFT;
2203
2204                                         arnew->flag = RGN_FLAG_HIDDEN;
2205                                 }
2206                         }
2207                 }
2208         }
2209
2210         if (!MAIN_VERSION_ATLEAST(bmain, 269, 1)) {
2211                 /* Removal of Cycles SSS Compatible falloff */
2212                 FOREACH_NODETREE(bmain, ntree, id) {
2213                         if (ntree->type == NTREE_SHADER) {
2214                                 bNode *node;
2215                                 for (node = ntree->nodes.first; node; node = node->next) {
2216                                         if (node->type == SH_NODE_SUBSURFACE_SCATTERING) {
2217                                                 if (node->custom1 == SHD_SUBSURFACE_COMPATIBLE) {
2218                                                         node->custom1 = SHD_SUBSURFACE_CUBIC;
2219                                                 }
2220                                         }
2221                                 }
2222                         }
2223                 } FOREACH_NODETREE_END
2224         }
2225
2226         if (!MAIN_VERSION_ATLEAST(bmain, 269, 2)) {
2227                 /* Initialize CDL settings for Color Balance nodes */
2228                 FOREACH_NODETREE(bmain, ntree, id) {
2229                         if (ntree->type == NTREE_COMPOSIT) {
2230                                 bNode *node;
2231                                 for (node = ntree->nodes.first; node; node = node->next) {
2232                                         if (node->type == CMP_NODE_COLORBALANCE) {
2233                                                 NodeColorBalance *n = node->storage;
2234                                                 if (node->custom1 == 0) {
2235                                                         /* LGG mode stays the same, just init CDL settings */
2236                                                         ntreeCompositColorBalanceSyncFromLGG(ntree, node);
2237                                                 }
2238                                                 else if (node->custom1 == 1) {
2239                                                         /* CDL previously used same variables as LGG, copy them over
2240                                                          * and then sync LGG for comparable results in both modes.
2241                                                          */
2242                                                         copy_v3_v3(n->offset, n->lift);
2243                                                         copy_v3_v3(n->power, n->gamma);
2244                                                         copy_v3_v3(n->slope, n->gain);
2245                                                         ntreeCompositColorBalanceSyncFromCDL(ntree, node);
2246                                                 }
2247                                         }
2248                                 }
2249                         }
2250                 } FOREACH_NODETREE_END
2251         }
2252
2253         if (!MAIN_VERSION_ATLEAST(bmain, 269, 3)) {
2254                 bScreen *sc;
2255                 ScrArea *sa;
2256                 SpaceLink *sl;
2257                 Scene *scene;
2258
2259                 /* Update files using invalid (outdated) outlinevis Outliner values. */
2260                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2261                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2262                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2263                                         if (sl->spacetype == SPACE_OUTLINER) {
2264                                                 SpaceOops *so = (SpaceOops *)sl;
2265
2266                                                 if (!ELEM(so->outlinevis,
2267                                                           SO_SCENES,
2268                                                           SO_LIBRARIES,
2269                                                           SO_SEQUENCE,
2270                                                           SO_DATA_API))
2271                                                 {
2272                                                         so->outlinevis = SO_SCENES;
2273                                                 }
2274                                         }
2275                                 }
2276                         }
2277                 }
2278
2279                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight")) {
2280                         MovieClip *clip;
2281                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
2282                                 MovieTracking *tracking = &clip->tracking;
2283                                 MovieTrackingObject *tracking_object;
2284                                 for (tracking_object = tracking->objects.first;
2285                                      tracking_object;
2286                                      tracking_object = tracking_object->next)
2287                                 {
2288                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
2289                                         MovieTrackingTrack *track;
2290                                         for (track = tracksbase->first;
2291                                              track;
2292                                              track = track->next)
2293                                         {
2294                                                 track->weight = 1.0f;
2295                                         }
2296                                 }
2297                         }
2298                 }
2299
2300                 if (!DNA_struct_elem_find(fd->filesdna, "TriangulateModifierData", "int", "quad_method")) {
2301                         Object *ob;
2302                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
2303                                 ModifierData *md;
2304                                 for (md = ob->modifiers.first; md; md = md->next) {
2305                                         if (md->type == eModifierType_Triangulate) {
2306                                                 TriangulateModifierData *tmd = (TriangulateModifierData *)md;
2307                                                 if ((tmd->flag & MOD_TRIANGULATE_BEAUTY)) {
2308                                                         tmd->quad_method = MOD_TRIANGULATE_QUAD_BEAUTY;
2309                                                         tmd->ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
2310                                                 }
2311                                                 else {
2312                                                         tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED;
2313                                                         tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP;
2314                                                 }
2315                                         }
2316                                 }
2317                         }
2318                 }
2319
2320                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2321                         /* this can now be turned off */
2322                         ToolSettings *ts = scene->toolsettings;
2323                         if (ts->sculpt)
2324                                 ts->sculpt->flags |= SCULPT_DYNTOPO_SUBDIVIDE;
2325
2326                         /* 'Increment' mode disabled for nodes, use true grid snapping instead */
2327                         if (scene->toolsettings->snap_node_mode == SCE_SNAP_MODE_INCREMENT)
2328                                 scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID;
2329
2330 #ifdef WITH_FFMPEG
2331                         /* Update for removed "sound-only" option in FFMPEG export settings. */
2332                         if (scene->r.ffcodecdata.type >= FFMPEG_INVALID) {
2333                                 scene->r.ffcodecdata.type = FFMPEG_AVI;
2334                         }
2335 #endif
2336
2337                 }
2338         }
2339
2340         if (!MAIN_VERSION_ATLEAST(bmain, 269, 4)) {
2341                 /* Internal degrees to radians conversions... */
2342                 {
2343                         Scene *scene;
2344                         Object *ob;
2345                         Lamp *lamp;
2346
2347                         for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next)
2348                                 lamp->spotsize = DEG2RADF(lamp->spotsize);
2349
2350                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
2351                                 ModifierData *md;
2352
2353                                 for (md = ob->modifiers.first; md; md = md->next) {
2354                                         if (md->type == eModifierType_EdgeSplit) {
2355                                                 EdgeSplitModifierData *emd = (EdgeSplitModifierData *)md;
2356                                                 emd->split_angle = DEG2RADF(emd->split_angle);
2357                                         }
2358                                         else if (md->type == eModifierType_Bevel) {
2359                                                 BevelModifierData *bmd = (BevelModifierData *)md;
2360                                                 bmd->bevel_angle = DEG2RADF(bmd->bevel_angle);
2361                                         }
2362                                 }
2363                         }
2364
2365                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2366                                 Sequence *seq;
2367                                 SEQ_BEGIN (scene->ed, seq)
2368                                 {
2369                                         if (seq->type == SEQ_TYPE_WIPE) {
2370                                                 WipeVars *wv = seq->effectdata;
2371                                                 wv->angle = DEG2RADF(wv->angle);
2372                                         }
2373                                 }
2374                                 SEQ_END
2375                         }
2376
2377                         FOREACH_NODETREE(bmain, ntree, id) {
2378                                 if (ntree->type == NTREE_COMPOSIT) {
2379                                         bNode *node;
2380                                         for (node = ntree->nodes.first; node; node = node->next) {
2381                                                 if (node->type == CMP_NODE_BOKEHIMAGE) {
2382                                                         NodeBokehImage *n = node->storage;
2383                                                         n->angle = DEG2RADF(n->angle);
2384                                                 }
2385                                                 if (node->type == CMP_NODE_MASK_BOX) {
2386                                                         NodeBoxMask *n = node->storage;
2387                                                         n->rotation = DEG2RADF(n->rotation);
2388                                                 }
2389                                                 if (node->type == CMP_NODE_MASK_ELLIPSE) {
2390                                                         NodeEllipseMask *n = node->storage;
2391                                                         n->rotation = DEG2RADF(n->rotation);
2392                                                 }
2393                                         }
2394                                 }
2395                         } FOREACH_NODETREE_END
2396                 }
2397
2398                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingPlaneTrack", "float", "image_opacity")) {
2399                         MovieClip *clip;
2400                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
2401                                 MovieTrackingPlaneTrack *plane_track;
2402                                 for (plane_track = clip->tracking.plane_tracks.first;
2403                                      plane_track;
2404                                      plane_track = plane_track->next)
2405                                 {
2406                                         plane_track->image_opacity = 1.0f;
2407                                 }
2408                         }
2409                 }
2410         }
2411
2412         if (!MAIN_VERSION_ATLEAST(bmain, 269, 7)) {
2413                 Scene *scene;
2414                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2415                         Sculpt *sd = scene->toolsettings->sculpt;
2416
2417                         if (sd) {
2418                                 int symmetry_flags = sd->flags & 7;
2419
2420                                 if (symmetry_flags & SCULPT_SYMM_X)
2421                                         sd->paint.symmetry_flags |= PAINT_SYMM_X;
2422                                 if (symmetry_flags & SCULPT_SYMM_Y)
2423                                         sd->paint.symmetry_flags |= PAINT_SYMM_Y;
2424                                 if (symmetry_flags & SCULPT_SYMM_Z)
2425                                         sd->paint.symmetry_flags |= PAINT_SYMM_Z;
2426                                 if (symmetry_flags & SCULPT_SYMMETRY_FEATHER)
2427                                         sd->paint.symmetry_flags |= PAINT_SYMMETRY_FEATHER;
2428                         }
2429                 }
2430         }
2431
2432         if (!MAIN_VERSION_ATLEAST(bmain, 269, 8)) {
2433                 Curve *cu;
2434
2435                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
2436                         if (cu->str) {
2437                                 cu->len_wchar = BLI_strlen_utf8(cu->str);
2438                         }
2439                 }
2440         }
2441         
2442         if (!MAIN_VERSION_ATLEAST(bmain, 269, 9)) {
2443                 Object *ob;
2444                 
2445                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2446                         ModifierData *md;
2447                         for (md = ob->modifiers.first; md; md = md->next) {
2448                                 if (md->type == eModifierType_Build) {
2449                                         BuildModifierData *bmd = (BuildModifierData *)md;
2450                                         if (bmd->randomize) {
2451                                                 bmd->flag |= MOD_BUILD_FLAG_RANDOMIZE;
2452                                         }
2453                                 }
2454                         }
2455                 }
2456         }
2457
2458         if (!MAIN_VERSION_ATLEAST(bmain, 269, 11)) {
2459                 bScreen *sc;
2460
2461                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2462                         ScrArea *sa;
2463                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2464                                 SpaceLink *space_link;
2465
2466                                 for (space_link = sa->spacedata.first; space_link; space_link = space_link->next) {
2467                                         if (space_link->spacetype == SPACE_IMAGE) {
2468                                                 ARegion *ar;
2469                                                 ListBase *lb;
2470
2471                                                 if (space_link == sa->spacedata.first) {
2472                                                         lb = &sa->regionbase;
2473                                                 }
2474                                                 else {
2475                                                         lb = &space_link->regionbase;
2476                                                 }
2477
2478                                                 for (ar = lb->first; ar; ar = ar->next) {
2479                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
2480                                                                 ar->regiontype = RGN_TYPE_TOOLS;
2481                                                                 ar->alignment = RGN_ALIGN_LEFT;
2482                                                         }
2483                                                         else if (ar->regiontype == RGN_TYPE_UI) {
2484                                                                 ar->alignment = RGN_ALIGN_RIGHT;
2485                                                         }
2486                                                 }
2487                                         }
2488                                 }
2489                         }
2490                 }
2491         }
2492 }