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