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