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