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