UVEdit: Add back uv angle stretch aspect correction
[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(uchar, 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 = POINTER_AS_INT(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_BEGIN(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
771                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
772                         do_versions_image_settings_2_60(sce);
773                 }
774
775                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
776                         MovieTrackingSettings *settings = &clip->tracking.settings;
777
778                         if (settings->default_pattern_size == 0.0f) {
779                                 settings->default_motion_model = TRACK_MOTION_MODEL_TRANSLATION;
780                                 settings->default_minimum_correlation = 0.75;
781                                 settings->default_pattern_size = 11;
782                                 settings->default_search_size = 51;
783                         }
784                 }
785
786                 {
787                         Object *ob;
788                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
789                                 /* convert delta addition into delta scale */
790                                 int i;
791                                 for (i = 0; i < 3; i++) {
792                                         if ( (ob->dsize[i] == 0.0f) || /* simple case, user never touched dsize */
793                                              (ob->size[i]  == 0.0f))   /* cant scale the dsize to give a non zero result,
794                                                                         * so fallback to 1.0f */
795                                         {
796                                                 ob->dscale[i] = 1.0f;
797                                         }
798                                         else {
799                                                 ob->dscale[i] = (ob->size[i] + ob->dsize[i]) / ob->size[i];
800                                         }
801                                 }
802                         }
803                 }
804         }
805         /* sigh, this dscale vs dsize version patching was not done right, fix for fix,
806          * this intentionally checks an exact subversion, also note this was never in a release,
807          * at some point this could be removed. */
808         else if (bmain->versionfile == 260 && bmain->subversionfile == 6) {
809                 Object *ob;
810                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
811                         if (is_zero_v3(ob->dscale)) {
812                                 copy_vn_fl(ob->dscale, 3, 1.0f);
813                         }
814                 }
815         }
816
817         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 8)) {
818                 Brush *brush;
819
820                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
821                         if (brush->sculpt_tool == SCULPT_TOOL_ROTATE)
822                                 brush->alpha = 1.0f;
823                 }
824         }
825
826         if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 1)) {
827                 {
828                         /* update use flags for node sockets (was only temporary before) */
829                         Scene *sce;
830                         Material *mat;
831                         Tex *tex;
832                         Lamp *lamp;
833                         World *world;
834                         bNodeTree *ntree;
835
836                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
837                                 if (sce->nodetree)
838                                         do_versions_nodetree_socket_use_flags_2_62(sce->nodetree);
839                         }
840
841                         for (mat = bmain->mat.first; mat; mat = mat->id.next) {
842                                 if (mat->nodetree)
843                                         do_versions_nodetree_socket_use_flags_2_62(mat->nodetree);
844                         }
845
846                         for (tex = bmain->tex.first; tex; tex = tex->id.next) {
847                                 if (tex->nodetree)
848                                         do_versions_nodetree_socket_use_flags_2_62(tex->nodetree);
849                         }
850
851                         for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
852                                 if (lamp->nodetree)
853                                         do_versions_nodetree_socket_use_flags_2_62(lamp->nodetree);
854                         }
855
856                         for (world = bmain->world.first; world; world = world->id.next) {
857                                 if (world->nodetree)
858                                         do_versions_nodetree_socket_use_flags_2_62(world->nodetree);
859                         }
860
861                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) {
862                                 do_versions_nodetree_socket_use_flags_2_62(ntree);
863                         }
864                 }
865                 {
866                         MovieClip *clip;
867                         Object *ob;
868
869                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
870                                 MovieTracking *tracking = &clip->tracking;
871                                 MovieTrackingObject *tracking_object = tracking->objects.first;
872
873                                 clip->proxy.build_tc_flag |= IMB_TC_RECORD_RUN_NO_GAPS;
874
875                                 if (!tracking->settings.object_distance)
876                                         tracking->settings.object_distance = 1.0f;
877
878                                 if (BLI_listbase_is_empty(&tracking->objects))
879                                         BKE_tracking_object_add(tracking, "Camera");
880
881                                 while (tracking_object) {
882                                         if (!tracking_object->scale)
883                                                 tracking_object->scale = 1.0f;
884
885                                         tracking_object = tracking_object->next;
886                                 }
887                         }
888
889                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
890                                 bConstraint *con;
891                                 for (con = ob->constraints.first; con; con = con->next) {
892                                         if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
893                                                 bObjectSolverConstraint *data = (bObjectSolverConstraint *)con->data;
894
895                                                 if (data->invmat[3][3] == 0.0f)
896                                                         unit_m4(data->invmat);
897                                         }
898                                 }
899                         }
900                 }
901         }
902
903         if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 2)) {
904                 {
905                         /* convert deprecated sculpt_paint_unified_* fields to
906                          * UnifiedPaintSettings */
907                         Scene *scene;
908                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
909                                 ToolSettings *ts = scene->toolsettings;
910                                 UnifiedPaintSettings *ups = &ts->unified_paint_settings;
911                                 ups->size = ts->sculpt_paint_unified_size;
912                                 ups->unprojected_radius = ts->sculpt_paint_unified_unprojected_radius;
913                                 ups->alpha = ts->sculpt_paint_unified_alpha;
914                                 ups->flag = ts->sculpt_paint_settings;
915                         }
916                 }
917         }
918
919         if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 3)) {
920                 {
921                         /* convert extended ascii to utf-8 for text editor */
922                         Text *text;
923                         for (text = bmain->text.first; text; text = text->id.next) {
924                                 if (!(text->flags & TXT_ISEXT)) {
925                                         TextLine *tl;
926
927                                         for (tl = text->lines.first; tl; tl = tl->next) {
928                                                 int added = txt_extended_ascii_as_utf8(&tl->line);
929                                                 tl->len += added;
930
931                                                 /* reset cursor position if line was changed */
932                                                 if (added && tl == text->curl)
933                                                         text->curc = 0;
934                                         }
935                                 }
936                         }
937                 }
938                 {
939                         /* set new dynamic paint values */
940                         Object *ob;
941                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
942                                 ModifierData *md;
943                                 for (md = ob->modifiers.first; md; md = md->next) {
944                                         if (md->type == eModifierType_DynamicPaint) {
945                                                 DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
946                                                 if (pmd->canvas) {
947                                                         DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
948                                                         for (; surface; surface = surface->next) {
949                                                                 surface->color_dry_threshold = 1.0f;
950                                                                 surface->influence_scale = 1.0f;
951                                                                 surface->radius_scale = 1.0f;
952                                                                 surface->flags |= MOD_DPAINT_USE_DRYING;
953                                                         }
954                                                 }
955                                         }
956                                 }
957                         }
958                 }
959         }
960
961         if (bmain->versionfile < 262) {
962                 Object *ob;
963                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
964                         ModifierData *md;
965
966                         for (md = ob->modifiers.first; md; md = md->next) {
967                                 if (md->type == eModifierType_Cloth) {
968                                         ClothModifierData *clmd = (ClothModifierData *)md;
969                                         if (clmd->sim_parms)
970                                                 clmd->sim_parms->vel_damping = 1.0f;
971                                 }
972                         }
973                 }
974         }
975
976         if (bmain->versionfile < 263) {
977                 /* set fluidsim rate. the version patch for this in 2.62 was wrong, so
978                  * try to correct it, if rate is 0.0 that's likely not intentional */
979                 Object *ob;
980
981                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
982                         ModifierData *md;
983                         for (md = ob->modifiers.first; md; md = md->next) {
984                                 if (md->type == eModifierType_Fluidsim) {
985                                         FluidsimModifierData *fmd = (FluidsimModifierData *)md;
986                                         if (fmd->fss->animRate == 0.0f)
987                                                 fmd->fss->animRate = 1.0f;
988                                 }
989                         }
990                 }
991         }
992
993         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 1)) {
994                 /* update use flags for node sockets (was only temporary before) */
995                 Scene *sce;
996                 bNodeTree *ntree;
997
998                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
999                         if (sce->nodetree)
1000                                 do_versions_nodetree_multi_file_output_format_2_62_1(sce, sce->nodetree);
1001                 }
1002
1003                 /* XXX can't associate with scene for group nodes, image format will stay uninitialized */
1004                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
1005                         do_versions_nodetree_multi_file_output_format_2_62_1(NULL, ntree);
1006         }
1007
1008         /* only swap for pre-release bmesh merge which had MLoopCol red/blue swap */
1009         if (bmain->versionfile == 262 && bmain->subversionfile == 1) {
1010                 {
1011                         Mesh *me;
1012                         for (me = bmain->mesh.first; me; me = me->id.next) {
1013                                 do_versions_mesh_mloopcol_swap_2_62_1(me);
1014                         }
1015                 }
1016         }
1017
1018         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 2)) {
1019                 /* Set new idname of keyingsets from their now "label-only" name. */
1020                 Scene *scene;
1021                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1022                         KeyingSet *ks;
1023                         for (ks = scene->keyingsets.first; ks; ks = ks->next) {
1024                                 if (!ks->idname[0])
1025                                         BLI_strncpy(ks->idname, ks->name, sizeof(ks->idname));
1026                         }
1027                 }
1028         }
1029
1030         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 3)) {
1031                 Object *ob;
1032                 ModifierData *md;
1033
1034                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1035                         for (md = ob->modifiers.first; md; md = md->next) {
1036                                 if (md->type == eModifierType_Lattice) {
1037                                         LatticeModifierData *lmd = (LatticeModifierData *)md;
1038                                         lmd->strength = 1.0f;
1039                                 }
1040                         }
1041                 }
1042         }
1043
1044         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 4)) {
1045                 /* Read Viscosity presets from older files */
1046                 Object *ob;
1047
1048                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1049                         ModifierData *md;
1050                         for (md = ob->modifiers.first; md; md = md->next) {
1051                                 if (md->type == eModifierType_Fluidsim) {
1052                                         FluidsimModifierData *fmd = (FluidsimModifierData *)md;
1053                                         if (fmd->fss->viscosityMode == 3) {
1054                                                 fmd->fss->viscosityValue = 5.0;
1055                                                 fmd->fss->viscosityExponent = 5;
1056                                         }
1057                                         else if (fmd->fss->viscosityMode == 4) {
1058                                                 fmd->fss->viscosityValue = 2.0;
1059                                                 fmd->fss->viscosityExponent = 3;
1060                                         }
1061                                 }
1062                         }
1063                 }
1064         }
1065
1066
1067
1068         if (bmain->versionfile < 263) {
1069                 /* Default for old files is to save particle rotations to pointcache */
1070                 ParticleSettings *part;
1071                 for (part = bmain->particle.first; part; part = part->id.next) {
1072                         part->flag |= PART_ROTATIONS;
1073                 }
1074         }
1075
1076         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 1)) {
1077                 /* file output node paths are now stored in the file info struct instead socket name */
1078                 Scene *sce;
1079                 bNodeTree *ntree;
1080
1081                 for (sce = bmain->scene.first; sce; sce = sce->id.next)
1082                         if (sce->nodetree)
1083                                 do_versions_nodetree_multi_file_output_path_2_63_1(sce->nodetree);
1084                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
1085                         do_versions_nodetree_multi_file_output_path_2_63_1(ntree);
1086         }
1087
1088         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 3)) {
1089                 Scene *scene;
1090                 Brush *brush;
1091
1092                 /* For weight paint, each brush now gets its own weight;
1093                  * unified paint settings also have weight. Update unified
1094                  * paint settings and brushes with a default weight value. */
1095
1096                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1097                         ToolSettings *ts = scene->toolsettings;
1098                         if (ts) {
1099                                 ts->unified_paint_settings.weight = ts->vgroup_weight;
1100                                 ts->unified_paint_settings.flag |= UNIFIED_PAINT_WEIGHT;
1101                         }
1102                 }
1103
1104                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1105                         brush->weight = 0.5;
1106                 }
1107         }
1108
1109         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 2)) {
1110                 bScreen *sc;
1111
1112                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1113                         ScrArea *sa;
1114                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1115                                 SpaceLink *sl;
1116
1117                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1118                                         if (sl->spacetype == SPACE_CLIP) {
1119                                                 SpaceClip *sclip = (SpaceClip *)sl;
1120                                                 ARegion *ar;
1121                                                 bool hide = false;
1122
1123                                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
1124                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
1125                                                                 if (ar->alignment != RGN_ALIGN_NONE) {
1126                                                                         ar->flag |= RGN_FLAG_HIDDEN;
1127                                                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
1128                                                                         ar->alignment = RGN_ALIGN_NONE;
1129
1130                                                                         hide = true;
1131                                                                 }
1132                                                         }
1133                                                 }
1134
1135                                                 if (hide) {
1136                                                         sclip->view = SC_VIEW_CLIP;
1137                                                 }
1138                                         }
1139                                 }
1140                         }
1141                 }
1142         }
1143
1144         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 4)) {
1145                 Camera *cam;
1146                 Curve *cu;
1147
1148                 for (cam = bmain->camera.first; cam; cam = cam->id.next) {
1149                         if (cam->flag & CAM_PANORAMA) {
1150                                 cam->type = CAM_PANO;
1151                                 cam->flag &= ~CAM_PANORAMA;
1152                         }
1153                 }
1154
1155                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
1156                         if (cu->bevfac2 == 0.0f) {
1157                                 cu->bevfac1 = 0.0f;
1158                                 cu->bevfac2 = 1.0f;
1159                         }
1160                 }
1161         }
1162
1163         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 5)) {
1164                 {
1165                         /* file output node paths are now stored in the file info struct instead socket name */
1166                         Scene *sce;
1167                         bNodeTree *ntree;
1168
1169                         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1170                                 if (sce->nodetree) {
1171                                         do_versions_nodetree_file_output_layers_2_64_5(sce->nodetree);
1172                                         do_versions_nodetree_image_layer_2_64_5(sce->nodetree);
1173                                 }
1174                         }
1175                         for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) {
1176                                 do_versions_nodetree_file_output_layers_2_64_5(ntree);
1177                                 do_versions_nodetree_image_layer_2_64_5(ntree);
1178                         }
1179                 }
1180         }
1181
1182         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 6)) {
1183                 /* update use flags for node sockets (was only temporary before) */
1184                 Scene *sce;
1185                 Material *mat;
1186                 Tex *tex;
1187                 Lamp *lamp;
1188                 World *world;
1189                 bNodeTree *ntree;
1190
1191                 for (sce = bmain->scene.first; sce; sce = sce->id.next)
1192                         if (sce->nodetree)
1193                                 do_versions_nodetree_frame_2_64_6(sce->nodetree);
1194
1195                 for (mat = bmain->mat.first; mat; mat = mat->id.next)
1196                         if (mat->nodetree)
1197                                 do_versions_nodetree_frame_2_64_6(mat->nodetree);
1198
1199                 for (tex = bmain->tex.first; tex; tex = tex->id.next)
1200                         if (tex->nodetree)
1201                                 do_versions_nodetree_frame_2_64_6(tex->nodetree);
1202
1203                 for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next)
1204                         if (lamp->nodetree)
1205                                 do_versions_nodetree_frame_2_64_6(lamp->nodetree);
1206
1207                 for (world = bmain->world.first; world; world = world->id.next)
1208                         if (world->nodetree)
1209                                 do_versions_nodetree_frame_2_64_6(world->nodetree);
1210
1211                 for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
1212                         do_versions_nodetree_frame_2_64_6(ntree);
1213         }
1214
1215         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 7)) {
1216                 Object *ob;
1217
1218                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1219                         ModifierData *md;
1220                         for (md = ob->modifiers.first; md; md = md->next) {
1221                                 if (md->type == eModifierType_Smoke) {
1222                                         SmokeModifierData *smd = (SmokeModifierData *)md;
1223                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
1224                                                 int maxres = max_iii(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2]);
1225                                                 smd->domain->scale = smd->domain->dx * maxres;
1226                                                 smd->domain->dx = 1.0f / smd->domain->scale;
1227                                         }
1228                                 }
1229                         }
1230                 }
1231         }
1232
1233         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 9)) {
1234                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1235                         if (ntree->type == NTREE_SHADER) {
1236                                 bNode *node;
1237                                 for (node = ntree->nodes.first; node; node = node->next) {
1238                                         if (ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) {
1239                                                 NodeTexImage *tex = node->storage;
1240
1241                                                 tex->iuser.frames = 1;
1242                                                 tex->iuser.sfra = 1;
1243                                                 tex->iuser.ok = 1;
1244                                         }
1245                                 }
1246                         }
1247                 } FOREACH_NODETREE_END;
1248         }
1249
1250         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 10)) {
1251                 {
1252                         Scene *scene;
1253                         // composite redesign
1254                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1255                                 if (scene->nodetree) {
1256                                         if (scene->nodetree->chunksize == 0) {
1257                                                 scene->nodetree->chunksize = 256;
1258                                         }
1259                                 }
1260                         }
1261
1262                         FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1263                                 if (ntree->type == NTREE_COMPOSIT) {
1264                                         bNode *node;
1265                                         for (node = ntree->nodes.first; node; node = node->next) {
1266                                                 if (node->type == CMP_NODE_DEFOCUS) {
1267                                                         NodeDefocus *data = node->storage;
1268                                                         if (data->maxblur == 0.0f) {
1269                                                                 data->maxblur = 16.0f;
1270                                                         }
1271                                                 }
1272                                         }
1273                                 }
1274                         } FOREACH_NODETREE_END;
1275                 }
1276
1277                 {
1278                         bScreen *sc;
1279
1280                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1281                                 ScrArea *sa;
1282
1283                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1284                                         SpaceLink *sl;
1285
1286                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1287                                                 if (sl->spacetype == SPACE_CLIP) {
1288                                                         SpaceClip *sclip = (SpaceClip *)sl;
1289
1290                                                         if (sclip->around == 0) {
1291                                                                 sclip->around = V3D_AROUND_CENTER_MEDIAN;
1292                                                         }
1293                                                 }
1294                                         }
1295                                 }
1296                         }
1297                 }
1298
1299                 {
1300                         MovieClip *clip;
1301
1302                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1303                                 clip->start_frame = 1;
1304                         }
1305                 }
1306         }
1307
1308         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 11)) {
1309                 MovieClip *clip;
1310
1311                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1312                         MovieTrackingTrack *track;
1313
1314                         track = clip->tracking.tracks.first;
1315                         while (track) {
1316                                 do_versions_affine_tracker_track(track);
1317
1318                                 track = track->next;
1319                         }
1320                 }
1321         }
1322
1323         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 13)) {
1324                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1325                         if (ntree->type == NTREE_COMPOSIT) {
1326                                 bNode *node;
1327                                 for (node = ntree->nodes.first; node; node = node->next) {
1328                                         if (node->type == CMP_NODE_DILATEERODE) {
1329                                                 if (node->storage == NULL) {
1330                                                         NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), __func__);
1331                                                         data->falloff = PROP_SMOOTH;
1332                                                         node->storage = data;
1333                                                 }
1334                                         }
1335                                 }
1336                         }
1337                 } FOREACH_NODETREE_END;
1338         }
1339
1340         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 14)) {
1341                 ParticleSettings *part;
1342
1343                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1344                         if (ntree->type == NTREE_COMPOSIT) {
1345                                 bNode *node;
1346                                 for (node = ntree->nodes.first; node; node = node->next) {
1347                                         if (node->type == CMP_NODE_KEYING) {
1348                                                 NodeKeyingData *data = node->storage;
1349
1350                                                 if (data->despill_balance == 0.0f) {
1351                                                         data->despill_balance = 0.5f;
1352                                                 }
1353                                         }
1354                                 }
1355                         }
1356                 } FOREACH_NODETREE_END;
1357
1358                 /* keep compatibility for dupliobject particle size */
1359                 for (part = bmain->particle.first; part; part = part->id.next)
1360                         if (ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR))
1361                                 if ((part->draw & PART_DRAW_ROTATE_OB) == 0)
1362                                         part->draw |= PART_DRAW_NO_SCALE_OB;
1363         }
1364
1365         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 17)) {
1366                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1367                         if (ntree->type == NTREE_COMPOSIT) {
1368                                 bNode *node;
1369                                 for (node = ntree->nodes.first; node; node = node->next) {
1370                                         if (node->type == CMP_NODE_MASK) {
1371                                                 if (node->storage == NULL) {
1372                                                         NodeMask *data = MEM_callocN(sizeof(NodeMask), __func__);
1373                                                         /* move settings into own struct */
1374                                                         data->size_x = (int)node->custom3;
1375                                                         data->size_y = (int)node->custom4;
1376                                                         node->custom3 = 0.5f; /* default shutter */
1377                                                         node->storage = data;
1378                                                 }
1379                                         }
1380                                 }
1381                         }
1382                 } FOREACH_NODETREE_END;
1383         }
1384
1385         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 18)) {
1386                 Scene *scene;
1387
1388                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1389                         if (scene->ed) {
1390                                 Sequence *seq;
1391
1392                                 SEQ_BEGIN (scene->ed, seq)
1393                                 {
1394                                         Strip *strip = seq->strip;
1395
1396                                         if (strip && strip->color_balance) {
1397                                                 SequenceModifierData *smd;
1398                                                 ColorBalanceModifierData *cbmd;
1399
1400                                                 smd = BKE_sequence_modifier_new(seq, NULL, seqModifierType_ColorBalance);
1401                                                 cbmd = (ColorBalanceModifierData *)smd;
1402
1403                                                 cbmd->color_balance = *strip->color_balance;
1404
1405                                                 /* multiplication with color balance used is handled differently,
1406                                                  * so we need to move multiplication to modifier so files would be
1407                                                  * compatible
1408                                                  */
1409                                                 cbmd->color_multiply = seq->mul;
1410                                                 seq->mul = 1.0f;
1411
1412                                                 MEM_freeN(strip->color_balance);
1413                                                 strip->color_balance = NULL;
1414                                         }
1415                                 } SEQ_END;
1416                         }
1417                 }
1418         }
1419
1420         /* color management pipeline changes compatibility code */
1421         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 19)) {
1422                 Scene *scene;
1423                 Image *ima;
1424                 bool colormanagement_disabled = false;
1425
1426                 /* make scenes which are not using color management have got None as display device,
1427                  * so they wouldn't perform linear-to-sRGB conversion on display
1428                  */
1429                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1430                         if ((scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) == 0) {
1431                                 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
1432
1433                                 if (display_settings->display_device[0] == 0) {
1434                                         BKE_scene_disable_color_management(scene);
1435
1436                                 }
1437
1438                                 colormanagement_disabled = true;
1439                         }
1440                 }
1441
1442                 for (ima = bmain->image.first; ima; ima = ima->id.next) {
1443                         if (ima->source == IMA_SRC_VIEWER) {
1444                                 ima->flag |= IMA_VIEW_AS_RENDER;
1445                         }
1446                         else if (colormanagement_disabled) {
1447                                 /* if colormanagement not used, set image's color space to raw, so no sRGB->linear conversion
1448                                  * would happen on display and render
1449                                  * there's no clear way to check whether color management is enabled or not in render engine
1450                                  * so set all images to raw if there's at least one scene with color management disabled
1451                                  * this would still behave incorrect in cases when color management was used for only some
1452                                  * of scenes, but such a setup is crazy anyway and think it's fair enough to break compatibility
1453                                  * in that cases
1454                                  */
1455
1456                                 BLI_strncpy(ima->colorspace_settings.name, "Raw", sizeof(ima->colorspace_settings.name));
1457                         }
1458                 }
1459         }
1460
1461         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 20)) {
1462                 Key *key;
1463                 for (key = bmain->key.first; key; key = key->id.next) {
1464                         blo_do_versions_key_uidgen(key);
1465                 }
1466         }
1467
1468         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 21)) {
1469                 {
1470                         Mesh *me;
1471                         for (me = bmain->mesh.first; me; me = me->id.next) {
1472                                 CustomData_update_typemap(&me->vdata);
1473                                 CustomData_free_layers(&me->vdata, CD_MSTICKY, me->totvert);
1474                         }
1475                 }
1476         }
1477
1478         /* correction for files saved in blender version when BKE_pose_copy_data
1479          * didn't copy animation visualization, which lead to deadlocks on motion
1480          * path calculation for proxied armatures, see [#32742]
1481          */
1482         if (bmain->versionfile < 264) {
1483                 Object *ob;
1484
1485                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1486                         if (ob->pose) {
1487                                 if (ob->pose->avs.path_step == 0) {
1488                                         animviz_settings_init(&ob->pose->avs);
1489                                 }
1490                         }
1491                 }
1492         }
1493
1494         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 1)) {
1495                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1496                         if (ntree->type == NTREE_SHADER) {
1497                                 bNode *node;
1498                                 for (node = ntree->nodes.first; node; node = node->next)
1499                                         if (node->type == SH_NODE_TEX_COORD)
1500                                                 node->flag |= NODE_OPTIONS;
1501                         }
1502                 } FOREACH_NODETREE_END;
1503         }
1504
1505         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 2)) {
1506                 MovieClip *clip;
1507
1508                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1509                         MovieTracking *tracking = &clip->tracking;
1510                         MovieTrackingObject *tracking_object;
1511
1512                         for (tracking_object = tracking->objects.first;
1513                              tracking_object;
1514                              tracking_object = tracking_object->next)
1515                         {
1516                                 if (tracking_object->keyframe1 == 0 && tracking_object->keyframe2 == 0) {
1517                                         tracking_object->keyframe1 = tracking->settings.keyframe1;
1518                                         tracking_object->keyframe2 = tracking->settings.keyframe2;
1519                                 }
1520                         }
1521                 }
1522         }
1523
1524         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 3)) {
1525                 /* smoke branch */
1526                 {
1527                         Object *ob;
1528
1529                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1530                                 ModifierData *md;
1531                                 for (md = ob->modifiers.first; md; md = md->next) {
1532                                         if (md->type == eModifierType_Smoke) {
1533                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1534                                                 if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
1535                                                         /* keep branch saves if possible */
1536                                                         if (!smd->domain->flame_max_temp) {
1537                                                                 smd->domain->burning_rate = 0.75f;
1538                                                                 smd->domain->flame_smoke = 1.0f;
1539                                                                 smd->domain->flame_vorticity = 0.5f;
1540                                                                 smd->domain->flame_ignition = 1.25f;
1541                                                                 smd->domain->flame_max_temp = 1.75f;
1542                                                                 smd->domain->adapt_threshold = 0.02f;
1543                                                                 smd->domain->adapt_margin = 4;
1544                                                                 smd->domain->flame_smoke_color[0] = 0.7f;
1545                                                                 smd->domain->flame_smoke_color[1] = 0.7f;
1546                                                                 smd->domain->flame_smoke_color[2] = 0.7f;
1547                                                         }
1548                                                 }
1549                                                 else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
1550                                                         if (!smd->flow->texture_size) {
1551                                                                 smd->flow->fuel_amount = 1.0;
1552                                                                 smd->flow->surface_distance = 1.5;
1553                                                                 smd->flow->color[0] = 0.7f;
1554                                                                 smd->flow->color[1] = 0.7f;
1555                                                                 smd->flow->color[2] = 0.7f;
1556                                                                 smd->flow->texture_size = 1.0f;
1557                                                         }
1558                                                 }
1559                                         }
1560                                 }
1561                         }
1562                 }
1563
1564                 /* render border for viewport */
1565                 {
1566                         bScreen *sc;
1567
1568                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1569                                 ScrArea *sa;
1570                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1571                                         SpaceLink *sl;
1572                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1573                                                 if (sl->spacetype == SPACE_VIEW3D) {
1574                                                         View3D *v3d = (View3D *)sl;
1575                                                         if (v3d->render_border.xmin == 0.0f && v3d->render_border.ymin == 0.0f &&
1576                                                             v3d->render_border.xmax == 0.0f && v3d->render_border.ymax == 0.0f)
1577                                                         {
1578                                                                 v3d->render_border.xmax = 1.0f;
1579                                                                 v3d->render_border.ymax = 1.0f;
1580                                                         }
1581                                                 }
1582                                         }
1583                                 }
1584                         }
1585                 }
1586         }
1587
1588         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 5)) {
1589                 /* set a unwrapping margin and ABF by default */
1590                 Scene *scene;
1591
1592                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1593                         if (scene->toolsettings->uvcalc_margin == 0.0f) {
1594                                 scene->toolsettings->uvcalc_margin = 0.001f;
1595                                 scene->toolsettings->unwrapper = 0;
1596                         }
1597                 }
1598         }
1599
1600         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 6)) {
1601                 /* Fix for bug #32982, internal_links list could get corrupted from r51630 onward.
1602                  * Simply remove bad internal_links lists to avoid NULL pointers.
1603                  */
1604                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1605                         bNode *node;
1606                         bNodeLink *link, *nextlink;
1607
1608                         for (node = ntree->nodes.first; node; node = node->next) {
1609                                 for (link = node->internal_links.first; link; link = nextlink) {
1610                                         nextlink = link->next;
1611                                         if (!link->fromnode || !link->fromsock || !link->tonode || !link->tosock) {
1612                                                 BLI_remlink(&node->internal_links, link);
1613                                         }
1614                                 }
1615                         }
1616                 } FOREACH_NODETREE_END;
1617         }
1618
1619         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) {
1620                 /* convert tiles size from resolution and number of tiles */
1621                 {
1622                         Scene *scene;
1623
1624                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1625                                 if (scene->r.tilex == 0 || scene->r.tiley == 1) {
1626                                         scene->r.tilex = scene->r.tiley = 64;
1627                                 }
1628                         }
1629                 }
1630
1631                 /* collision masks */
1632                 {
1633                         Object *ob;
1634                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1635                                 if (ob->col_group == 0) {
1636                                         ob->col_group = 0x01;
1637                                         ob->col_mask = 0xff;
1638                                 }
1639                         }
1640                 }
1641         }
1642
1643         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) {
1644                 MovieClip *clip;
1645
1646                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1647                         MovieTrackingTrack *track;
1648                         MovieTrackingObject *object;
1649
1650                         for (track = clip->tracking.tracks.first; track; track = track->next) {
1651                                 do_versions_affine_tracker_track(track);
1652                         }
1653
1654                         for (object = clip->tracking.objects.first; object; object = object->next) {
1655                                 for (track = object->tracks.first; track; track = track->next) {
1656                                         do_versions_affine_tracker_track(track);
1657                                 }
1658                         }
1659                 }
1660         }
1661
1662         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 3)) {
1663                 bScreen *sc;
1664                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1665                         ScrArea *sa;
1666                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1667                                 SpaceLink *sl;
1668                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1669                                         switch (sl->spacetype) {
1670                                                 case SPACE_VIEW3D:
1671                                                 {
1672                                                         View3D *v3d = (View3D *)sl;
1673                                                         v3d->flag2 |= V3D_SHOW_ANNOTATION;
1674                                                         break;
1675                                                 }
1676                                                 case SPACE_SEQ:
1677                                                 {
1678                                                         SpaceSeq *sseq = (SpaceSeq *)sl;
1679                                                         sseq->flag |= SEQ_SHOW_GPENCIL;
1680                                                         break;
1681                                                 }
1682                                                 case SPACE_IMAGE:
1683                                                 {
1684                                                         SpaceImage *sima = (SpaceImage *)sl;
1685                                                         sima->flag |= SI_SHOW_GPENCIL;
1686                                                         break;
1687                                                 }
1688                                                 case SPACE_NODE:
1689                                                 {
1690                                                         SpaceNode *snode = (SpaceNode *)sl;
1691                                                         snode->flag |= SNODE_SHOW_GPENCIL;
1692                                                         break;
1693                                                 }
1694                                                 case SPACE_CLIP:
1695                                                 {
1696                                                         SpaceClip *sclip = (SpaceClip *)sl;
1697                                                         sclip->flag |= SC_SHOW_ANNOTATION;
1698                                                         break;
1699                                                 }
1700                                         }
1701                                 }
1702                         }
1703                 }
1704         }
1705
1706         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 5)) {
1707                 Scene *scene;
1708                 Tex *tex;
1709
1710                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1711                         Sequence *seq;
1712
1713                         SEQ_BEGIN (scene->ed, seq)
1714                         {
1715                                 enum { SEQ_MAKE_PREMUL = (1 << 6) };
1716                                 if (seq->flag & SEQ_MAKE_PREMUL) {
1717                                         seq->alpha_mode = SEQ_ALPHA_STRAIGHT;
1718                                 }
1719                                 else {
1720                                         BKE_sequence_alpha_mode_from_extension(seq);
1721                                 }
1722                         } SEQ_END;
1723
1724                         if (scene->r.bake_samples == 0)
1725                                 scene->r.bake_samples = 256;
1726                 }
1727
1728                 for (Image *image = bmain->image.first; image; image = image->id.next) {
1729                         if (image->flag & IMA_DO_PREMUL) {
1730                                 image->alpha_mode = IMA_ALPHA_STRAIGHT;
1731                         }
1732                         else {
1733                                 BKE_image_alpha_mode_from_extension(image);
1734                         }
1735                 }
1736
1737                 for (tex = bmain->tex.first; tex; tex = tex->id.next) {
1738                         if (tex->type == TEX_IMAGE && (tex->imaflag & TEX_USEALPHA) == 0) {
1739                                 Image *image = blo_do_versions_newlibadr(fd, tex->id.lib, tex->ima);
1740
1741                                 if (image && (image->flag & IMA_DO_PREMUL) == 0)
1742                                         image->flag |= IMA_IGNORE_ALPHA;
1743                         }
1744                 }
1745
1746                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1747                         if (ntree->type == NTREE_COMPOSIT) {
1748                                 bNode *node;
1749                                 for (node = ntree->nodes.first; node; node = node->next) {
1750                                         if (node->type == CMP_NODE_IMAGE) {
1751                                                 Image *image = blo_do_versions_newlibadr(fd, ntree->id.lib, node->id);
1752
1753                                                 if (image) {
1754                                                         if ((image->flag & IMA_DO_PREMUL) == 0 && image->alpha_mode == IMA_ALPHA_STRAIGHT)
1755                                                                 node->custom1 |= CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT;
1756                                                 }
1757                                         }
1758                                 }
1759                         }
1760                 } FOREACH_NODETREE_END;
1761         }
1762         else if (bmain->versionfile < 266 || (bmain->versionfile == 266 && bmain->subversionfile < 1)) {
1763                 /* texture use alpha was removed for 2.66 but added back again for 2.66a,
1764                  * for compatibility all textures assumed it to be enabled */
1765                 Tex *tex;
1766
1767                 for (tex = bmain->tex.first; tex; tex = tex->id.next)
1768                         if (tex->type == TEX_IMAGE)
1769                                 tex->imaflag |= TEX_USEALPHA;
1770         }
1771
1772         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 7)) {
1773                 Curve *cu;
1774
1775                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
1776                         if (cu->flag & (CU_FRONT | CU_BACK)) {
1777                                 if (cu->ext1 != 0.0f || cu->ext2 != 0.0f) {
1778                                         Nurb *nu;
1779
1780                                         for (nu = cu->nurb.first; nu; nu = nu->next) {
1781                                                 int a;
1782
1783                                                 if (nu->bezt) {
1784                                                         BezTriple *bezt = nu->bezt;
1785                                                         a = nu->pntsu;
1786
1787                                                         while (a--) {
1788                                                                 bezt->radius = 1.0f;
1789                                                                 bezt++;
1790                                                         }
1791                                                 }
1792                                                 else if (nu->bp) {
1793                                                         BPoint *bp = nu->bp;
1794                                                         a = nu->pntsu * nu->pntsv;
1795
1796                                                         while (a--) {
1797                                                                 bp->radius = 1.0f;
1798                                                                 bp++;
1799                                                         }
1800                                                 }
1801                                         }
1802                                 }
1803                         }
1804                 }
1805         }
1806
1807         if (MAIN_VERSION_OLDER(bmain, 265, 9)) {
1808                 Mesh *me;
1809                 for (me = bmain->mesh.first; me; me = me->id.next) {
1810                         BKE_mesh_do_versions_cd_flag_init(me);
1811                 }
1812         }
1813
1814         if (MAIN_VERSION_OLDER(bmain, 265, 10)) {
1815                 Brush *br;
1816                 for (br = bmain->brush.first; br; br = br->id.next) {
1817                         if (br->ob_mode & OB_MODE_TEXTURE_PAINT) {
1818                                 br->mtex.brush_map_mode = MTEX_MAP_MODE_TILED;
1819                         }
1820                 }
1821         }
1822
1823         // add storage for compositor translate nodes when not existing
1824         if (MAIN_VERSION_OLDER(bmain, 265, 11)) {
1825                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1826                         if (ntree->type == NTREE_COMPOSIT) {
1827                                 bNode *node;
1828                                 for (node = ntree->nodes.first; node; node = node->next) {
1829                                         if (node->type == CMP_NODE_TRANSLATE && node->storage == NULL) {
1830                                                 node->storage = MEM_callocN(sizeof(NodeTranslateData), "node translate data");
1831                                         }
1832                                 }
1833                         }
1834                 } FOREACH_NODETREE_END;
1835         }
1836
1837         if (MAIN_VERSION_OLDER(bmain, 266, 2)) {
1838                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1839                         do_versions_nodetree_customnodes(ntree, ((ID *)ntree == id));
1840                 } FOREACH_NODETREE_END;
1841         }
1842
1843         if (MAIN_VERSION_OLDER(bmain, 266, 2)) {
1844                 bScreen *sc;
1845                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1846                         ScrArea *sa;
1847                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1848                                 SpaceLink *sl;
1849                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1850                                         if (sl->spacetype == SPACE_NODE) {
1851                                                 SpaceNode *snode = (SpaceNode *)sl;
1852
1853                                                 /* reset pointers to force tree path update from context */
1854                                                 snode->nodetree = NULL;
1855                                                 snode->edittree = NULL;
1856                                                 snode->id = NULL;
1857                                                 snode->from = NULL;
1858
1859                                                 /* convert deprecated treetype setting to tree_idname */
1860                                                 switch (snode->treetype) {
1861                                                         case NTREE_COMPOSIT:
1862                                                                 strcpy(snode->tree_idname, "CompositorNodeTree");
1863                                                                 break;
1864                                                         case NTREE_SHADER:
1865                                                                 strcpy(snode->tree_idname, "ShaderNodeTree");
1866                                                                 break;
1867                                                         case NTREE_TEXTURE:
1868                                                                 strcpy(snode->tree_idname, "TextureNodeTree");
1869                                                                 break;
1870                                                 }
1871                                         }
1872                                 }
1873                         }
1874                 }
1875         }
1876
1877         /* Set flag for delayed do_versions in lib_verify_nodetree. It needs valid typeinfo pointers ... */
1878         {
1879                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1880                         /* XXX This should be kept without version check for now!
1881                          * As long as USE_NODE_COMPAT_CUSTOMNODES is active, files will write links
1882                          * to tree interface sockets for forward compatibility. These links need to be removed again
1883                          * on file load in new versions.
1884                          * Once forward compatibility is not required any longer, make a subversion bump
1885                          * and only execute this for older versions.
1886                          */
1887                         ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP;
1888
1889                         /* Only add interface nodes once.
1890                          * In old Blender versions they will be removed automatically due to undefined type */
1891                         if (MAIN_VERSION_OLDER(bmain, 266, 2))
1892                                 ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP_CREATE_INTERFACE;
1893                 }
1894                 FOREACH_NODETREE_END;
1895         }
1896
1897         if (MAIN_VERSION_OLDER(bmain, 266, 3)) {
1898                 {
1899                         /* Fix for a very old issue:
1900                          * Node names were nominally made unique in r24478 (2.50.8), but the do_versions check
1901                          * to update existing node names only applied to bmain->nodetree (i.e. group nodes).
1902                          * Uniqueness is now required for proper preview mapping,
1903                          * so do this now to ensure old files don't break.
1904                          */
1905                         bNode *node;
1906                         FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1907                                 if (id == &ntree->id)
1908                                         continue;   /* already fixed for node groups */
1909
1910                                 for (node = ntree->nodes.first; node; node = node->next)
1911                                         nodeUniqueName(ntree, node);
1912                         }
1913                         FOREACH_NODETREE_END;
1914                 }
1915         }
1916
1917         if (!MAIN_VERSION_ATLEAST(bmain, 266, 4)) {
1918                 Brush *brush;
1919                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1920                         BKE_texture_mtex_default(&brush->mask_mtex);
1921
1922                         if (brush->ob_mode & OB_MODE_TEXTURE_PAINT) {
1923                                 brush->spacing /= 2;
1924                         }
1925                 }
1926         }
1927
1928         if (!MAIN_VERSION_ATLEAST(bmain, 266, 6)) {
1929                 Brush *brush;
1930 #define BRUSH_TEXTURE_OVERLAY (1 << 21)
1931
1932                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1933                         brush->overlay_flags = 0;
1934                         if (brush->flag & BRUSH_TEXTURE_OVERLAY)
1935                                 brush->overlay_flags |= (BRUSH_OVERLAY_PRIMARY | BRUSH_OVERLAY_CURSOR);
1936                 }
1937 #undef BRUSH_TEXTURE_OVERLAY
1938         }
1939
1940         if (bmain->versionfile < 267) {
1941                 //if (!DNA_struct_elem_find(fd->filesdna, "Brush", "int", "stencil_pos")) {
1942                 Brush *brush;
1943
1944                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
1945                         if (brush->stencil_dimension[0] == 0) {
1946                                 brush->stencil_dimension[0] = 256;
1947                                 brush->stencil_dimension[1] = 256;
1948                                 brush->stencil_pos[0] = 256;
1949                                 brush->stencil_pos[1] = 256;
1950                         }
1951                         if (brush->mask_stencil_dimension[0] == 0) {
1952                                 brush->mask_stencil_dimension[0] = 256;
1953                                 brush->mask_stencil_dimension[1] = 256;
1954                                 brush->mask_stencil_pos[0] = 256;
1955                                 brush->mask_stencil_pos[1] = 256;
1956                         }
1957                 }
1958
1959                 /* TIP: to initialize new variables added, use the new function
1960                  * DNA_struct_elem_find(fd->filesdna, "structname", "typename", "varname")
1961                  * example:
1962                  * if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "image_gpubuffer_limit"))
1963                  *     user->image_gpubuffer_limit = 10;
1964                  */
1965
1966         }
1967
1968         /* default values in Freestyle settings */
1969         if (bmain->versionfile < 267) {
1970                 Scene *sce;
1971                 SceneRenderLayer *srl;
1972                 FreestyleLineStyle *linestyle;
1973
1974                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1975                         if (sce->r.line_thickness_mode == 0) {
1976                                 sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE;
1977                                 sce->r.unit_line_thickness = 1.0f;
1978                         }
1979                         for (srl = sce->r.layers.first; srl; srl = srl->next) {
1980                                 if (srl->freestyleConfig.mode == 0)
1981                                         srl->freestyleConfig.mode = FREESTYLE_CONTROL_EDITOR_MODE;
1982                                 if (srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE ||
1983                                     srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL)
1984                                 {
1985                                         srl->freestyleConfig.raycasting_algorithm = 0; /* deprecated */
1986                                         srl->freestyleConfig.flags |= FREESTYLE_CULLING;
1987                                 }
1988                         }
1989
1990                         /* not freestyle */
1991                         {
1992                                 MeshStatVis *statvis = &sce->toolsettings->statvis;
1993                                 if (statvis->thickness_samples == 0) {
1994                                         statvis->overhang_axis = OB_NEGZ;
1995                                         statvis->overhang_min = 0;
1996                                         statvis->overhang_max = DEG2RADF(45.0f);
1997
1998                                         statvis->thickness_max = 0.1f;
1999                                         statvis->thickness_samples = 1;
2000
2001                                         statvis->distort_min = DEG2RADF(5.0f);
2002                                         statvis->distort_max = DEG2RADF(45.0f);
2003
2004                                         statvis->sharp_min = DEG2RADF(90.0f);
2005                                         statvis->sharp_max = DEG2RADF(180.0f);
2006                                 }
2007                         }
2008
2009                 }
2010                 for (linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
2011 #if 1
2012                         /* disable the Misc panel for now */
2013                         if (linestyle->panel == LS_PANEL_MISC) {
2014                                 linestyle->panel = LS_PANEL_STROKES;
2015                         }
2016 #endif
2017                         if (linestyle->thickness_position == 0) {
2018                                 linestyle->thickness_position = LS_THICKNESS_CENTER;
2019                                 linestyle->thickness_ratio = 0.5f;
2020                         }
2021                         if (linestyle->chaining == 0)
2022                                 linestyle->chaining = LS_CHAINING_PLAIN;
2023                         if (linestyle->rounds == 0)
2024                                 linestyle->rounds = 3;
2025                 }
2026         }
2027
2028         if (bmain->versionfile < 267) {
2029                 /* Initialize the active_viewer_key for compositing */
2030                 bScreen *screen;
2031                 Scene *scene;
2032                 bNodeInstanceKey active_viewer_key = {0};
2033                 /* simply pick the first node space and use that for the active viewer key */
2034                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
2035                         ScrArea *sa;
2036                         for (sa = screen->areabase.first; sa; sa = sa->next) {
2037                                 SpaceLink *sl;
2038                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2039                                         if (sl->spacetype == SPACE_NODE) {
2040                                                 SpaceNode *snode = (SpaceNode *)sl;
2041                                                 bNodeTreePath *path = snode->treepath.last;
2042                                                 if (!path)
2043                                                         continue;
2044
2045                                                 active_viewer_key = path->parent_key;
2046                                                 break;
2047                                         }
2048                                 }
2049                                 if (active_viewer_key.value != 0)
2050                                         break;
2051                         }
2052                         if (active_viewer_key.value != 0)
2053                                 break;
2054                 }
2055
2056                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2057                         /* NB: scene->nodetree is a local ID block, has been direct_link'ed */
2058                         if (scene->nodetree)
2059                                 scene->nodetree->active_viewer_key = active_viewer_key;
2060                 }
2061         }
2062
2063         if (MAIN_VERSION_OLDER(bmain, 267, 1)) {
2064                 Object *ob;
2065
2066                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2067                         ModifierData *md;
2068                         for (md = ob->modifiers.first; md; md = md->next) {
2069                                 if (md->type == eModifierType_Smoke) {
2070                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2071                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
2072                                                 if (smd->domain->flags & MOD_SMOKE_HIGH_SMOOTH) {
2073                                                         smd->domain->highres_sampling = SM_HRES_LINEAR;
2074                                                 }
2075                                                 else {
2076                                                         smd->domain->highres_sampling = SM_HRES_NEAREST;
2077                                                 }
2078                                         }
2079                                 }
2080                         }
2081                 }
2082         }
2083
2084         if (!MAIN_VERSION_ATLEAST(bmain, 268, 1)) {
2085                 Brush *brush;
2086                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2087                         brush->spacing = MAX2(1, brush->spacing);
2088                 }
2089         }
2090
2091         if (!MAIN_VERSION_ATLEAST(bmain, 268, 2)) {
2092                 Brush *brush;
2093 #define BRUSH_FIXED (1 << 6)
2094                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2095                         brush->flag &= ~BRUSH_FIXED;
2096
2097                         if (brush->cursor_overlay_alpha < 2)
2098                                 brush->cursor_overlay_alpha = 33;
2099                         if (brush->texture_overlay_alpha < 2)
2100                                 brush->texture_overlay_alpha = 33;
2101                         if (brush->mask_overlay_alpha < 2)
2102                                 brush->mask_overlay_alpha = 33;
2103                 }
2104 #undef BRUSH_FIXED
2105         }
2106
2107
2108         if (!MAIN_VERSION_ATLEAST(bmain, 268, 4)) {
2109                 bScreen *sc;
2110                 Object *ob;
2111
2112                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2113                         bConstraint *con;
2114                         for (con = ob->constraints.first; con; con = con->next) {
2115                                 if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
2116                                         bShrinkwrapConstraint *data = (bShrinkwrapConstraint *)con->data;
2117                                         if      (data->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) data->projAxis = OB_POSX;
2118                                         else if (data->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) data->projAxis = OB_POSY;
2119                                         else                                                          data->projAxis = OB_POSZ;
2120                                         data->projAxisSpace = CONSTRAINT_SPACE_LOCAL;
2121                                 }
2122                         }
2123                 }
2124
2125                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2126                         ModifierData *md;
2127                         for (md = ob->modifiers.first; md; md = md->next) {
2128                                 if (md->type == eModifierType_Smoke) {
2129                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2130                                         if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
2131                                                 if (!smd->flow->particle_size) {
2132                                                         smd->flow->particle_size = 1.0f;
2133                                                 }
2134                                         }
2135                                 }
2136                         }
2137                 }
2138
2139                 /*
2140                  * FIX some files have a zoom level of 0, and was checked during the drawing of the node space
2141                  *
2142                  * We moved this check to the do versions to be sure the value makes any sense.
2143                  */
2144                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2145                         ScrArea *sa;
2146                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2147                                 SpaceLink *sl;
2148                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2149                                         if (sl->spacetype == SPACE_NODE) {
2150                                                 SpaceNode *snode = (SpaceNode *)sl;
2151                                                 if (snode->zoom < 0.02f) {
2152                                                         snode->zoom = 1.0;
2153                                                 }
2154                                         }
2155                                 }
2156                         }
2157                 }
2158         }
2159
2160         if (!MAIN_VERSION_ATLEAST(bmain, 268, 5)) {
2161                 bScreen *sc;
2162                 ScrArea *sa;
2163
2164                 /* add missing (+) expander in node editor */
2165                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2166                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2167                                 ARegion *ar, *arnew;
2168
2169                                 if (sa->spacetype == SPACE_NODE) {
2170                                         ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
2171
2172                                         if (ar)
2173                                                 continue;
2174
2175                                         /* add subdiv level; after header */
2176                                         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
2177
2178                                         /* is error! */
2179                                         if (ar == NULL)
2180                                                 continue;
2181
2182                                         arnew = MEM_callocN(sizeof(ARegion), "node tools");
2183
2184                                         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
2185                                         arnew->regiontype = RGN_TYPE_TOOLS;
2186                                         arnew->alignment = RGN_ALIGN_LEFT;
2187
2188                                         arnew->flag = RGN_FLAG_HIDDEN;
2189                                 }
2190                         }
2191                 }
2192         }
2193
2194         if (!MAIN_VERSION_ATLEAST(bmain, 269, 1)) {
2195                 /* Removal of Cycles SSS Compatible falloff */
2196                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2197                         if (ntree->type == NTREE_SHADER) {
2198                                 bNode *node;
2199                                 for (node = ntree->nodes.first; node; node = node->next) {
2200                                         if (node->type == SH_NODE_SUBSURFACE_SCATTERING) {
2201                                                 if (node->custom1 == SHD_SUBSURFACE_COMPATIBLE) {
2202                                                         node->custom1 = SHD_SUBSURFACE_CUBIC;
2203                                                 }
2204                                         }
2205                                 }
2206                         }
2207                 } FOREACH_NODETREE_END;
2208         }
2209
2210         if (!MAIN_VERSION_ATLEAST(bmain, 269, 2)) {
2211                 /* Initialize CDL settings for Color Balance nodes */
2212                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2213                         if (ntree->type == NTREE_COMPOSIT) {
2214                                 bNode *node;
2215                                 for (node = ntree->nodes.first; node; node = node->next) {
2216                                         if (node->type == CMP_NODE_COLORBALANCE) {
2217                                                 NodeColorBalance *n = node->storage;
2218                                                 if (node->custom1 == 0) {
2219                                                         /* LGG mode stays the same, just init CDL settings */
2220                                                         ntreeCompositColorBalanceSyncFromLGG(ntree, node);
2221                                                 }
2222                                                 else if (node->custom1 == 1) {
2223                                                         /* CDL previously used same variables as LGG, copy them over
2224                                                          * and then sync LGG for comparable results in both modes.
2225                                                          */
2226                                                         copy_v3_v3(n->offset, n->lift);
2227                                                         copy_v3_v3(n->power, n->gamma);
2228                                                         copy_v3_v3(n->slope, n->gain);
2229                                                         ntreeCompositColorBalanceSyncFromCDL(ntree, node);
2230                                                 }
2231                                         }
2232                                 }
2233                         }
2234                 } FOREACH_NODETREE_END;
2235         }
2236
2237         if (!MAIN_VERSION_ATLEAST(bmain, 269, 3)) {
2238                 bScreen *sc;
2239                 ScrArea *sa;
2240                 SpaceLink *sl;
2241                 Scene *scene;
2242
2243                 /* Update files using invalid (outdated) outlinevis Outliner values. */
2244                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2245                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2246                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2247                                         if (sl->spacetype == SPACE_OUTLINER) {
2248                                                 SpaceOops *so = (SpaceOops *)sl;
2249
2250                                                 if (!ELEM(so->outlinevis,
2251                                                           SO_SCENES,
2252                                                           SO_LIBRARIES,
2253                                                           SO_SEQUENCE,
2254                                                           SO_DATA_API))
2255                                                 {
2256                                                         so->outlinevis = SO_SCENES;
2257                                                 }
2258                                         }
2259                                 }
2260                         }
2261                 }
2262
2263                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight")) {
2264                         MovieClip *clip;
2265                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
2266                                 MovieTracking *tracking = &clip->tracking;
2267                                 MovieTrackingObject *tracking_object;
2268                                 for (tracking_object = tracking->objects.first;
2269                                      tracking_object;
2270                                      tracking_object = tracking_object->next)
2271                                 {
2272                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
2273                                         MovieTrackingTrack *track;
2274                                         for (track = tracksbase->first;
2275                                              track;
2276                                              track = track->next)
2277                                         {
2278                                                 track->weight = 1.0f;
2279                                         }
2280                                 }
2281                         }
2282                 }
2283
2284                 if (!DNA_struct_elem_find(fd->filesdna, "TriangulateModifierData", "int", "quad_method")) {
2285                         Object *ob;
2286                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
2287                                 ModifierData *md;
2288                                 for (md = ob->modifiers.first; md; md = md->next) {
2289                                         if (md->type == eModifierType_Triangulate) {
2290                                                 TriangulateModifierData *tmd = (TriangulateModifierData *)md;
2291                                                 if ((tmd->flag & MOD_TRIANGULATE_BEAUTY)) {
2292                                                         tmd->quad_method = MOD_TRIANGULATE_QUAD_BEAUTY;
2293                                                         tmd->ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
2294                                                 }
2295                                                 else {
2296                                                         tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED;
2297                                                         tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP;
2298                                                 }
2299                                         }
2300                                 }
2301                         }
2302                 }
2303
2304                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2305                         /* this can now be turned off */
2306                         ToolSettings *ts = scene->toolsettings;
2307                         if (ts->sculpt)
2308                                 ts->sculpt->flags |= SCULPT_DYNTOPO_SUBDIVIDE;
2309
2310                         /* 'Increment' mode disabled for nodes, use true grid snapping instead */
2311                         if (scene->toolsettings->snap_node_mode == SCE_SNAP_MODE_INCREMENT)
2312                                 scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID;
2313
2314 #ifdef WITH_FFMPEG
2315                         /* Update for removed "sound-only" option in FFMPEG export settings. */
2316                         if (scene->r.ffcodecdata.type >= FFMPEG_INVALID) {
2317                                 scene->r.ffcodecdata.type = FFMPEG_AVI;
2318                         }
2319 #endif
2320
2321                 }
2322         }
2323
2324         if (!MAIN_VERSION_ATLEAST(bmain, 269, 4)) {
2325                 /* Internal degrees to radians conversions... */
2326                 {
2327                         Scene *scene;
2328                         Object *ob;
2329                         Lamp *lamp;
2330
2331                         for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next)
2332                                 lamp->spotsize = DEG2RADF(lamp->spotsize);
2333
2334                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
2335                                 ModifierData *md;
2336
2337                                 for (md = ob->modifiers.first; md; md = md->next) {
2338                                         if (md->type == eModifierType_EdgeSplit) {
2339                                                 EdgeSplitModifierData *emd = (EdgeSplitModifierData *)md;
2340                                                 emd->split_angle = DEG2RADF(emd->split_angle);
2341                                         }
2342                                         else if (md->type == eModifierType_Bevel) {
2343                                                 BevelModifierData *bmd = (BevelModifierData *)md;
2344                                                 bmd->bevel_angle = DEG2RADF(bmd->bevel_angle);
2345                                         }
2346                                 }
2347                         }
2348
2349                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2350                                 Sequence *seq;
2351                                 SEQ_BEGIN (scene->ed, seq)
2352                                 {
2353                                         if (seq->type == SEQ_TYPE_WIPE) {
2354                                                 WipeVars *wv = seq->effectdata;
2355                                                 wv->angle = DEG2RADF(wv->angle);
2356                                         }
2357                                 } SEQ_END;
2358                         }
2359
2360                         FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2361                                 if (ntree->type == NTREE_COMPOSIT) {
2362                                         bNode *node;
2363                                         for (node = ntree->nodes.first; node; node = node->next) {
2364                                                 if (node->type == CMP_NODE_BOKEHIMAGE) {
2365                                                         NodeBokehImage *n = node->storage;
2366                                                         n->angle = DEG2RADF(n->angle);
2367                                                 }
2368                                                 if (node->type == CMP_NODE_MASK_BOX) {
2369                                                         NodeBoxMask *n = node->storage;
2370                                                         n->rotation = DEG2RADF(n->rotation);
2371                                                 }
2372                                                 if (node->type == CMP_NODE_MASK_ELLIPSE) {
2373                                                         NodeEllipseMask *n = node->storage;
2374                                                         n->rotation = DEG2RADF(n->rotation);
2375                                                 }
2376                                         }
2377                                 }
2378                         } FOREACH_NODETREE_END;
2379                 }
2380
2381                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingPlaneTrack", "float", "image_opacity")) {
2382                         MovieClip *clip;
2383                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
2384                                 MovieTrackingPlaneTrack *plane_track;
2385                                 for (plane_track = clip->tracking.plane_tracks.first;
2386                                      plane_track;
2387                                      plane_track = plane_track->next)
2388                                 {
2389                                         plane_track->image_opacity = 1.0f;
2390                                 }
2391                         }
2392                 }
2393         }
2394
2395         if (!MAIN_VERSION_ATLEAST(bmain, 269, 7)) {
2396                 Scene *scene;
2397                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2398                         Sculpt *sd = scene->toolsettings->sculpt;
2399
2400                         if (sd) {
2401                                 enum {
2402                                         SCULPT_SYMM_X = (1 << 0),
2403                                         SCULPT_SYMM_Y = (1 << 1),
2404                                         SCULPT_SYMM_Z = (1 << 2),
2405                                 };
2406                                 int symmetry_flags = sd->flags & 7;
2407
2408                                 if (symmetry_flags & SCULPT_SYMM_X)
2409                                         sd->paint.symmetry_flags |= PAINT_SYMM_X;
2410                                 if (symmetry_flags & SCULPT_SYMM_Y)
2411                                         sd->paint.symmetry_flags |= PAINT_SYMM_Y;
2412                                 if (symmetry_flags & SCULPT_SYMM_Z)
2413                                         sd->paint.symmetry_flags |= PAINT_SYMM_Z;
2414                                 if (symmetry_flags & SCULPT_SYMMETRY_FEATHER)
2415                                         sd->paint.symmetry_flags |= PAINT_SYMMETRY_FEATHER;
2416                         }
2417                 }
2418         }
2419
2420         if (!MAIN_VERSION_ATLEAST(bmain, 269, 8)) {
2421                 Curve *cu;
2422
2423                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
2424                         if (cu->str) {
2425                                 cu->len_wchar = BLI_strlen_utf8(cu->str);
2426                         }
2427                 }
2428         }
2429
2430         if (!MAIN_VERSION_ATLEAST(bmain, 269, 9)) {
2431                 Object *ob;
2432
2433                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2434                         ModifierData *md;
2435                         for (md = ob->modifiers.first; md; md = md->next) {
2436                                 if (md->type == eModifierType_Build) {
2437                                         BuildModifierData *bmd = (BuildModifierData *)md;
2438                                         if (bmd->randomize) {
2439                                                 bmd->flag |= MOD_BUILD_FLAG_RANDOMIZE;
2440                                         }
2441                                 }
2442                         }
2443                 }
2444         }
2445
2446         if (!MAIN_VERSION_ATLEAST(bmain, 269, 11)) {
2447                 bScreen *sc;
2448
2449                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2450                         ScrArea *sa;
2451                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2452                                 SpaceLink *space_link;
2453
2454                                 for (space_link = sa->spacedata.first; space_link; space_link = space_link->next) {
2455                                         if (space_link->spacetype == SPACE_IMAGE) {
2456                                                 ARegion *ar;
2457                                                 ListBase *lb;
2458
2459                                                 if (space_link == sa->spacedata.first) {
2460                                                         lb = &sa->regionbase;
2461                                                 }
2462                                                 else {
2463                                                         lb = &space_link->regionbase;
2464                                                 }
2465
2466                                                 for (ar = lb->first; ar; ar = ar->next) {
2467                                                         if (ar->regiontype == RGN_TYPE_PREVIEW) {
2468                                                                 ar->regiontype = RGN_TYPE_TOOLS;
2469                                                                 ar->alignment = RGN_ALIGN_LEFT;
2470                                                         }
2471                                                         else if (ar->regiontype == RGN_TYPE_UI) {
2472                                                                 ar->alignment = RGN_ALIGN_RIGHT;
2473                                                         }
2474                                                 }
2475                                         }
2476                                 }
2477                         }
2478                 }
2479         }
2480 }