f630dbe1aaf95ab82edd71b87519c6302023f2d5
[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                                 }
1524                                 SEQ_END
1525                         }
1526                 }
1527         }
1528
1529         /* color management pipeline changes compatibility code */
1530         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 19)) {
1531                 Scene *scene;
1532                 Image *ima;
1533                 bool colormanagement_disabled = false;
1534
1535                 /* make scenes which are not using color management have got None as display device,
1536                  * so they wouldn't perform linear-to-sRGB conversion on display
1537                  */
1538                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1539                         if ((scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) == 0) {
1540                                 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
1541
1542                                 if (display_settings->display_device[0] == 0) {
1543                                         BKE_scene_disable_color_management(scene);
1544
1545                                 }
1546
1547                                 colormanagement_disabled = true;
1548                         }
1549                 }
1550
1551                 for (ima = bmain->image.first; ima; ima = ima->id.next) {
1552                         if (ima->source == IMA_SRC_VIEWER) {
1553                                 ima->flag |= IMA_VIEW_AS_RENDER;
1554                         }
1555                         else if (colormanagement_disabled) {
1556                                 /* if colormanagement not used, set image's color space to raw, so no sRGB->linear conversion
1557                                  * would happen on display and render
1558                                  * there's no clear way to check whether color management is enabled or not in render engine
1559                                  * so set all images to raw if there's at least one scene with color management disabled
1560                                  * this would still behave incorrect in cases when color management was used for only some
1561                                  * of scenes, but such a setup is crazy anyway and think it's fair enough to break compatibility
1562                                  * in that cases
1563                                  */
1564
1565                                 BLI_strncpy(ima->colorspace_settings.name, "Raw", sizeof(ima->colorspace_settings.name));
1566                         }
1567                 }
1568         }
1569
1570         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 20)) {
1571                 Key *key;
1572                 for (key = bmain->key.first; key; key = key->id.next) {
1573                         blo_do_versions_key_uidgen(key);
1574                 }
1575         }
1576
1577         /* remove texco */
1578         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 21)) {
1579                 Material *ma;
1580                 for (ma = bmain->mat.first; ma; ma = ma->id.next) {
1581                         int a;
1582                         for (a = 0; a < MAX_MTEX; a++) {
1583                                 if (ma->mtex[a]) {
1584                                         if (ma->mtex[a]->texco == TEXCO_STICKY_) {
1585                                                 ma->mtex[a]->texco = TEXCO_UV;
1586                                         }
1587                                 }
1588                         }
1589                 }
1590
1591                 {
1592                         Mesh *me;
1593                         for (me = bmain->mesh.first; me; me = me->id.next) {
1594                                 CustomData_update_typemap(&me->vdata);
1595                                 CustomData_free_layers(&me->vdata, CD_MSTICKY, me->totvert);
1596                         }
1597                 }
1598         }
1599
1600         /* correction for files saved in blender version when BKE_pose_copy_data
1601          * didn't copy animation visualization, which lead to deadlocks on motion
1602          * path calculation for proxied armatures, see [#32742]
1603          */
1604         if (bmain->versionfile < 264) {
1605                 Object *ob;
1606
1607                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1608                         if (ob->pose) {
1609                                 if (ob->pose->avs.path_step == 0) {
1610                                         animviz_settings_init(&ob->pose->avs);
1611                                 }
1612                         }
1613                 }
1614         }
1615
1616         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 1)) {
1617                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1618                         if (ntree->type == NTREE_SHADER) {
1619                                 bNode *node;
1620                                 for (node = ntree->nodes.first; node; node = node->next)
1621                                         if (node->type == SH_NODE_TEX_COORD)
1622                                                 node->flag |= NODE_OPTIONS;
1623                         }
1624                 } FOREACH_NODETREE_END;
1625         }
1626
1627         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 2)) {
1628                 MovieClip *clip;
1629
1630                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1631                         MovieTracking *tracking = &clip->tracking;
1632                         MovieTrackingObject *tracking_object;
1633
1634                         for (tracking_object = tracking->objects.first;
1635                              tracking_object;
1636                              tracking_object = tracking_object->next)
1637                         {
1638                                 if (tracking_object->keyframe1 == 0 && tracking_object->keyframe2 == 0) {
1639                                         tracking_object->keyframe1 = tracking->settings.keyframe1;
1640                                         tracking_object->keyframe2 = tracking->settings.keyframe2;
1641                                 }
1642                         }
1643                 }
1644         }
1645
1646         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 3)) {
1647                 /* smoke branch */
1648                 {
1649                         Object *ob;
1650
1651                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1652                                 ModifierData *md;
1653                                 for (md = ob->modifiers.first; md; md = md->next) {
1654                                         if (md->type == eModifierType_Smoke) {
1655                                                 SmokeModifierData *smd = (SmokeModifierData *)md;
1656                                                 if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
1657                                                         /* keep branch saves if possible */
1658                                                         if (!smd->domain->flame_max_temp) {
1659                                                                 smd->domain->burning_rate = 0.75f;
1660                                                                 smd->domain->flame_smoke = 1.0f;
1661                                                                 smd->domain->flame_vorticity = 0.5f;
1662                                                                 smd->domain->flame_ignition = 1.25f;
1663                                                                 smd->domain->flame_max_temp = 1.75f;
1664                                                                 smd->domain->adapt_threshold = 0.02f;
1665                                                                 smd->domain->adapt_margin = 4;
1666                                                                 smd->domain->flame_smoke_color[0] = 0.7f;
1667                                                                 smd->domain->flame_smoke_color[1] = 0.7f;
1668                                                                 smd->domain->flame_smoke_color[2] = 0.7f;
1669                                                         }
1670                                                 }
1671                                                 else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
1672                                                         if (!smd->flow->texture_size) {
1673                                                                 smd->flow->fuel_amount = 1.0;
1674                                                                 smd->flow->surface_distance = 1.5;
1675                                                                 smd->flow->color[0] = 0.7f;
1676                                                                 smd->flow->color[1] = 0.7f;
1677                                                                 smd->flow->color[2] = 0.7f;
1678                                                                 smd->flow->texture_size = 1.0f;
1679                                                         }
1680                                                 }
1681                                         }
1682                                 }
1683                         }
1684                 }
1685
1686                 /* render border for viewport */
1687                 {
1688                         bScreen *sc;
1689
1690                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1691                                 ScrArea *sa;
1692                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1693                                         SpaceLink *sl;
1694                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1695                                                 if (sl->spacetype == SPACE_VIEW3D) {
1696                                                         View3D *v3d = (View3D *)sl;
1697                                                         if (v3d->render_border.xmin == 0.0f && v3d->render_border.ymin == 0.0f &&
1698                                                             v3d->render_border.xmax == 0.0f && v3d->render_border.ymax == 0.0f)
1699                                                         {
1700                                                                 v3d->render_border.xmax = 1.0f;
1701                                                                 v3d->render_border.ymax = 1.0f;
1702                                                         }
1703                                                 }
1704                                         }
1705                                 }
1706                         }
1707                 }
1708         }
1709
1710         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 5)) {
1711                 /* set a unwrapping margin and ABF by default */
1712                 Scene *scene;
1713
1714                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1715                         if (scene->toolsettings->uvcalc_margin == 0.0f) {
1716                                 scene->toolsettings->uvcalc_margin = 0.001f;
1717                                 scene->toolsettings->unwrapper = 0;
1718                         }
1719                 }
1720         }
1721
1722         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 6)) {
1723                 /* Fix for bug #32982, internal_links list could get corrupted from r51630 onward.
1724                  * Simply remove bad internal_links lists to avoid NULL pointers.
1725                  */
1726                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1727                         bNode *node;
1728                         bNodeLink *link, *nextlink;
1729
1730                         for (node = ntree->nodes.first; node; node = node->next) {
1731                                 for (link = node->internal_links.first; link; link = nextlink) {
1732                                         nextlink = link->next;
1733                                         if (!link->fromnode || !link->fromsock || !link->tonode || !link->tosock) {
1734                                                 BLI_remlink(&node->internal_links, link);
1735                                         }
1736                                 }
1737                         }
1738                 } FOREACH_NODETREE_END;
1739         }
1740
1741         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 6)) {
1742                 bScreen *sc;
1743
1744                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1745                         ScrArea *sa;
1746                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1747                                 SpaceLink *sl;
1748                                 if (sa->spacetype == SPACE_LOGIC)
1749                                         do_version_logic_264(&sa->regionbase);
1750
1751                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1752                                         if (sl->spacetype == SPACE_LOGIC)
1753                                                 do_version_logic_264(&sl->regionbase);
1754                                 }
1755                         }
1756                 }
1757         }
1758
1759         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) {
1760                 /* convert tiles size from resolution and number of tiles */
1761                 {
1762                         Scene *scene;
1763
1764                         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1765                                 if (scene->r.tilex == 0 || scene->r.tiley == 1) {
1766                                         if (scene->r.xparts && scene->r.yparts) {
1767                                                 /* scene could be set for panoramic rendering, so clamp with the
1768                                                  * lowest possible tile size value
1769                                                  */
1770                                                 scene->r.tilex = max_ii(scene->r.xsch * scene->r.size / scene->r.xparts / 100, 8);
1771                                                 scene->r.tiley = max_ii(scene->r.ysch * scene->r.size / scene->r.yparts / 100, 8);
1772                                         }
1773                                         else {
1774                                                 /* happens when mixing using current trunk and previous release */
1775                                                 scene->r.tilex = scene->r.tiley = 64;
1776                                         }
1777                                 }
1778                         }
1779                 }
1780
1781                 /* collision masks */
1782                 {
1783                         Object *ob;
1784                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
1785                                 if (ob->col_group == 0) {
1786                                         ob->col_group = 0x01;
1787                                         ob->col_mask = 0xff;
1788                                 }
1789                         }
1790                 }
1791         }
1792
1793         if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) {
1794                 MovieClip *clip;
1795
1796                 for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
1797                         MovieTrackingTrack *track;
1798                         MovieTrackingObject *object;
1799
1800                         for (track = clip->tracking.tracks.first; track; track = track->next) {
1801                                 do_versions_affine_tracker_track(track);
1802                         }
1803
1804                         for (object = clip->tracking.objects.first; object; object = object->next) {
1805                                 for (track = object->tracks.first; track; track = track->next) {
1806                                         do_versions_affine_tracker_track(track);
1807                                 }
1808                         }
1809                 }
1810         }
1811
1812         if (bmain->versionfile < 265) {
1813                 Object *ob;
1814                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
1815                         if (ob->step_height == 0.0f) {
1816                                 ob->step_height = 0.15f;
1817                                 ob->jump_speed = 10.0f;
1818                                 ob->fall_speed = 55.0f;
1819                         }
1820                 }
1821         }
1822
1823         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 3)) {
1824                 bScreen *sc;
1825                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1826                         ScrArea *sa;
1827                         for (sa = sc->areabase.first; sa; sa = sa->next) {
1828                                 SpaceLink *sl;
1829                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1830                                         switch (sl->spacetype) {
1831                                                 case SPACE_VIEW3D:
1832                                                 {
1833                                                         View3D *v3d = (View3D *)sl;
1834                                                         v3d->flag2 |= V3D_SHOW_GPENCIL;
1835                                                         break;
1836                                                 }
1837                                                 case SPACE_SEQ:
1838                                                 {
1839                                                         SpaceSeq *sseq = (SpaceSeq *)sl;
1840                                                         sseq->flag |= SEQ_SHOW_GPENCIL;
1841                                                         break;
1842                                                 }
1843                                                 case SPACE_IMAGE:
1844                                                 {
1845                                                         SpaceImage *sima = (SpaceImage *)sl;
1846                                                         sima->flag |= SI_SHOW_GPENCIL;
1847                                                         break;
1848                                                 }
1849                                                 case SPACE_NODE:
1850                                                 {
1851                                                         SpaceNode *snode = (SpaceNode *)sl;
1852                                                         snode->flag |= SNODE_SHOW_GPENCIL;
1853                                                         break;
1854                                                 }
1855                                                 case SPACE_CLIP:
1856                                                 {
1857                                                         SpaceClip *sclip = (SpaceClip *)sl;
1858                                                         sclip->flag |= SC_SHOW_GPENCIL;
1859                                                         break;
1860                                                 }
1861                                         }
1862                                 }
1863                         }
1864                 }
1865         }
1866
1867         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 5)) {
1868                 Scene *scene;
1869                 Tex *tex;
1870
1871                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
1872                         Sequence *seq;
1873                         bool set_premul = false;
1874
1875                         SEQ_BEGIN (scene->ed, seq)
1876                         {
1877                                 if (seq->flag & SEQ_MAKE_PREMUL) {
1878                                         seq->alpha_mode = SEQ_ALPHA_STRAIGHT;
1879                                 }
1880                                 else {
1881                                         BKE_sequence_alpha_mode_from_extension(seq);
1882                                 }
1883                         }
1884                         SEQ_END
1885
1886                         if (scene->r.bake_samples == 0)
1887                                 scene->r.bake_samples = 256;
1888
1889                         if (scene->world) {
1890                                 World *world = blo_do_versions_newlibadr(fd, scene->id.lib, scene->world);
1891
1892                                 if (world && is_zero_v3(&world->horr)) {
1893                                         if ((world->skytype & WO_SKYBLEND) == 0 || is_zero_v3(&world->zenr)) {
1894                                                 set_premul = true;
1895                                         }
1896                                 }
1897                         }
1898                         else
1899                                 set_premul = true;
1900
1901                         if (set_premul) {
1902                                 printf("2.66 versioning fix: replacing black sky with premultiplied alpha for scene %s\n",
1903                                        scene->id.name + 2);
1904                                 scene->r.alphamode = R_ALPHAPREMUL;
1905                         }
1906                 }
1907
1908                 for (Image *image = bmain->image.first; image; image = image->id.next) {
1909                         if (image->flag & IMA_DO_PREMUL) {
1910                                 image->alpha_mode = IMA_ALPHA_STRAIGHT;
1911                         }
1912                         else {
1913                                 BKE_image_alpha_mode_from_extension(image);
1914                         }
1915                 }
1916
1917                 for (tex = bmain->tex.first; tex; tex = tex->id.next) {
1918                         if (tex->type == TEX_IMAGE && (tex->imaflag & TEX_USEALPHA) == 0) {
1919                                 Image *image = blo_do_versions_newlibadr(fd, tex->id.lib, tex->ima);
1920
1921                                 if (image && (image->flag & IMA_DO_PREMUL) == 0)
1922                                         image->flag |= IMA_IGNORE_ALPHA;
1923                         }
1924                 }
1925
1926                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
1927                         if (ntree->type == NTREE_COMPOSIT) {
1928                                 bNode *node;
1929                                 for (node = ntree->nodes.first; node; node = node->next) {
1930                                         if (node->type == CMP_NODE_IMAGE) {
1931                                                 Image *image = blo_do_versions_newlibadr(fd, ntree->id.lib, node->id);
1932
1933                                                 if (image) {
1934                                                         if ((image->flag & IMA_DO_PREMUL) == 0 && image->alpha_mode == IMA_ALPHA_STRAIGHT)
1935                                                                 node->custom1 |= CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT;
1936                                                 }
1937                                         }
1938                                 }
1939                         }
1940                 } FOREACH_NODETREE_END;
1941         }
1942         else if (bmain->versionfile < 266 || (bmain->versionfile == 266 && bmain->subversionfile < 1)) {
1943                 /* texture use alpha was removed for 2.66 but added back again for 2.66a,
1944                  * for compatibility all textures assumed it to be enabled */
1945                 Tex *tex;
1946
1947                 for (tex = bmain->tex.first; tex; tex = tex->id.next)
1948                         if (tex->type == TEX_IMAGE)
1949                                 tex->imaflag |= TEX_USEALPHA;
1950         }
1951
1952         if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 7)) {
1953                 Curve *cu;
1954
1955                 for (cu = bmain->curve.first; cu; cu = cu->id.next) {
1956                         if (cu->flag & (CU_FRONT | CU_BACK)) {
1957                                 if (cu->ext1 != 0.0f || cu->ext2 != 0.0f) {
1958                                         Nurb *nu;
1959
1960                                         for (nu = cu->nurb.first; nu; nu = nu->next) {
1961                                                 int a;
1962
1963                                                 if (nu->bezt) {
1964                                                         BezTriple *bezt = nu->bezt;
1965                                                         a = nu->pntsu;
1966
1967                                                         while (a--) {
1968                                                                 bezt->radius = 1.0f;
1969                                                                 bezt++;
1970                                                         }
1971                                                 }
1972                                                 else if (nu->bp) {
1973                                                         BPoint *bp = nu->bp;
1974                                                         a = nu->pntsu * nu->pntsv;
1975
1976                                                         while (a--) {
1977                                                                 bp->radius = 1.0f;
1978                                                                 bp++;
1979                                                         }
1980                                                 }
1981                                         }
1982                                 }
1983                         }
1984                 }
1985         }
1986
1987         if (MAIN_VERSION_OLDER(bmain, 265, 9)) {
1988                 Mesh *me;
1989                 for (me = bmain->mesh.first; me; me = me->id.next) {
1990                         BKE_mesh_do_versions_cd_flag_init(me);
1991                 }
1992         }
1993
1994         if (MAIN_VERSION_OLDER(bmain, 265, 10)) {
1995                 Brush *br;
1996                 for (br = bmain->brush.first; br; br = br->id.next) {
1997                         if (br->ob_mode & OB_MODE_TEXTURE_PAINT) {
1998                                 br->mtex.brush_map_mode = MTEX_MAP_MODE_TILED;
1999                         }
2000                 }
2001         }
2002
2003         // add storage for compositor translate nodes when not existing
2004         if (MAIN_VERSION_OLDER(bmain, 265, 11)) {
2005                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2006                         if (ntree->type == NTREE_COMPOSIT) {
2007                                 bNode *node;
2008                                 for (node = ntree->nodes.first; node; node = node->next) {
2009                                         if (node->type == CMP_NODE_TRANSLATE && node->storage == NULL) {
2010                                                 node->storage = MEM_callocN(sizeof(NodeTranslateData), "node translate data");
2011                                         }
2012                                 }
2013                         }
2014                 } FOREACH_NODETREE_END;
2015         }
2016
2017         if (MAIN_VERSION_OLDER(bmain, 266, 2)) {
2018                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2019                         do_versions_nodetree_customnodes(ntree, ((ID *)ntree == id));
2020                 } FOREACH_NODETREE_END;
2021         }
2022
2023         if (MAIN_VERSION_OLDER(bmain, 266, 2)) {
2024                 bScreen *sc;
2025                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2026                         ScrArea *sa;
2027                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2028                                 SpaceLink *sl;
2029                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2030                                         if (sl->spacetype == SPACE_NODE) {
2031                                                 SpaceNode *snode = (SpaceNode *)sl;
2032
2033                                                 /* reset pointers to force tree path update from context */
2034                                                 snode->nodetree = NULL;
2035                                                 snode->edittree = NULL;
2036                                                 snode->id = NULL;
2037                                                 snode->from = NULL;
2038
2039                                                 /* convert deprecated treetype setting to tree_idname */
2040                                                 switch (snode->treetype) {
2041                                                         case NTREE_COMPOSIT:
2042                                                                 strcpy(snode->tree_idname, "CompositorNodeTree");
2043                                                                 break;
2044                                                         case NTREE_SHADER:
2045                                                                 strcpy(snode->tree_idname, "ShaderNodeTree");
2046                                                                 break;
2047                                                         case NTREE_TEXTURE:
2048                                                                 strcpy(snode->tree_idname, "TextureNodeTree");
2049                                                                 break;
2050                                                 }
2051                                         }
2052                                 }
2053                         }
2054                 }
2055         }
2056
2057         /* Set flag for delayed do_versions in lib_verify_nodetree. It needs valid typeinfo pointers ... */
2058         {
2059                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2060                         /* XXX This should be kept without version check for now!
2061                          * As long as USE_NODE_COMPAT_CUSTOMNODES is active, files will write links
2062                          * to tree interface sockets for forward compatibility. These links need to be removed again
2063                          * on file load in new versions.
2064                          * Once forward compatibility is not required any longer, make a subversion bump
2065                          * and only execute this for older versions.
2066                          */
2067                         ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP;
2068
2069                         /* Only add interface nodes once.
2070                          * In old Blender versions they will be removed automatically due to undefined type */
2071                         if (MAIN_VERSION_OLDER(bmain, 266, 2))
2072                                 ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP_CREATE_INTERFACE;
2073                 }
2074                 FOREACH_NODETREE_END;
2075         }
2076
2077         if (MAIN_VERSION_OLDER(bmain, 266, 3)) {
2078                 {
2079                         /* Fix for a very old issue:
2080                          * Node names were nominally made unique in r24478 (2.50.8), but the do_versions check
2081                          * to update existing node names only applied to bmain->nodetree (i.e. group nodes).
2082                          * Uniqueness is now required for proper preview mapping,
2083                          * so do this now to ensure old files don't break.
2084                          */
2085                         bNode *node;
2086                         FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2087                                 if (id == &ntree->id)
2088                                         continue;   /* already fixed for node groups */
2089
2090                                 for (node = ntree->nodes.first; node; node = node->next)
2091                                         nodeUniqueName(ntree, node);
2092                         }
2093                         FOREACH_NODETREE_END;
2094                 }
2095         }
2096
2097         if (!MAIN_VERSION_ATLEAST(bmain, 266, 4)) {
2098                 Brush *brush;
2099                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2100                         BKE_texture_mtex_default(&brush->mask_mtex);
2101
2102                         if (brush->ob_mode & OB_MODE_TEXTURE_PAINT) {
2103                                 brush->spacing /= 2;
2104                         }
2105                 }
2106         }
2107
2108         if (!MAIN_VERSION_ATLEAST(bmain, 266, 6)) {
2109                 Brush *brush;
2110 #define BRUSH_TEXTURE_OVERLAY (1 << 21)
2111
2112                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2113                         brush->overlay_flags = 0;
2114                         if (brush->flag & BRUSH_TEXTURE_OVERLAY)
2115                                 brush->overlay_flags |= (BRUSH_OVERLAY_PRIMARY | BRUSH_OVERLAY_CURSOR);
2116                 }
2117 #undef BRUSH_TEXTURE_OVERLAY
2118         }
2119
2120         if (bmain->versionfile < 267) {
2121                 //if (!DNA_struct_elem_find(fd->filesdna, "Brush", "int", "stencil_pos")) {
2122                 Brush *brush;
2123
2124                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2125                         if (brush->stencil_dimension[0] == 0) {
2126                                 brush->stencil_dimension[0] = 256;
2127                                 brush->stencil_dimension[1] = 256;
2128                                 brush->stencil_pos[0] = 256;
2129                                 brush->stencil_pos[1] = 256;
2130                         }
2131                         if (brush->mask_stencil_dimension[0] == 0) {
2132                                 brush->mask_stencil_dimension[0] = 256;
2133                                 brush->mask_stencil_dimension[1] = 256;
2134                                 brush->mask_stencil_pos[0] = 256;
2135                                 brush->mask_stencil_pos[1] = 256;
2136                         }
2137                 }
2138
2139                 /* TIP: to initialize new variables added, use the new function
2140                  * DNA_struct_elem_find(fd->filesdna, "structname", "typename", "varname")
2141                  * example:
2142                  * if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "image_gpubuffer_limit"))
2143                  *     user->image_gpubuffer_limit = 10;
2144                  */
2145
2146         }
2147
2148         /* default values in Freestyle settings */
2149         if (bmain->versionfile < 267) {
2150                 Scene *sce;
2151                 SceneRenderLayer *srl;
2152                 FreestyleLineStyle *linestyle;
2153
2154                 for (sce = bmain->scene.first; sce; sce = sce->id.next) {
2155                         if (sce->r.line_thickness_mode == 0) {
2156                                 sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE;
2157                                 sce->r.unit_line_thickness = 1.0f;
2158                         }
2159                         for (srl = sce->r.layers.first; srl; srl = srl->next) {
2160                                 if (srl->freestyleConfig.mode == 0)
2161                                         srl->freestyleConfig.mode = FREESTYLE_CONTROL_EDITOR_MODE;
2162                                 if (srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE ||
2163                                     srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL)
2164                                 {
2165                                         srl->freestyleConfig.raycasting_algorithm = 0; /* deprecated */
2166                                         srl->freestyleConfig.flags |= FREESTYLE_CULLING;
2167                                 }
2168                         }
2169
2170                         /* not freestyle */
2171                         {
2172                                 MeshStatVis *statvis = &sce->toolsettings->statvis;
2173                                 if (statvis->thickness_samples == 0) {
2174                                         statvis->overhang_axis = OB_NEGZ;
2175                                         statvis->overhang_min = 0;
2176                                         statvis->overhang_max = DEG2RADF(45.0f);
2177
2178                                         statvis->thickness_max = 0.1f;
2179                                         statvis->thickness_samples = 1;
2180
2181                                         statvis->distort_min = DEG2RADF(5.0f);
2182                                         statvis->distort_max = DEG2RADF(45.0f);
2183
2184                                         statvis->sharp_min = DEG2RADF(90.0f);
2185                                         statvis->sharp_max = DEG2RADF(180.0f);
2186                                 }
2187                         }
2188
2189                 }
2190                 for (linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
2191 #if 1
2192                         /* disable the Misc panel for now */
2193                         if (linestyle->panel == LS_PANEL_MISC) {
2194                                 linestyle->panel = LS_PANEL_STROKES;
2195                         }
2196 #endif
2197                         if (linestyle->thickness_position == 0) {
2198                                 linestyle->thickness_position = LS_THICKNESS_CENTER;
2199                                 linestyle->thickness_ratio = 0.5f;
2200                         }
2201                         if (linestyle->chaining == 0)
2202                                 linestyle->chaining = LS_CHAINING_PLAIN;
2203                         if (linestyle->rounds == 0)
2204                                 linestyle->rounds = 3;
2205                 }
2206         }
2207
2208         if (bmain->versionfile < 267) {
2209                 /* Initialize the active_viewer_key for compositing */
2210                 bScreen *screen;
2211                 Scene *scene;
2212                 bNodeInstanceKey active_viewer_key = {0};
2213                 /* simply pick the first node space and use that for the active viewer key */
2214                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
2215                         ScrArea *sa;
2216                         for (sa = screen->areabase.first; sa; sa = sa->next) {
2217                                 SpaceLink *sl;
2218                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2219                                         if (sl->spacetype == SPACE_NODE) {
2220                                                 SpaceNode *snode = (SpaceNode *)sl;
2221                                                 bNodeTreePath *path = snode->treepath.last;
2222                                                 if (!path)
2223                                                         continue;
2224
2225                                                 active_viewer_key = path->parent_key;
2226                                                 break;
2227                                         }
2228                                 }
2229                                 if (active_viewer_key.value != 0)
2230                                         break;
2231                         }
2232                         if (active_viewer_key.value != 0)
2233                                 break;
2234                 }
2235
2236                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2237                         /* NB: scene->nodetree is a local ID block, has been direct_link'ed */
2238                         if (scene->nodetree)
2239                                 scene->nodetree->active_viewer_key = active_viewer_key;
2240                 }
2241         }
2242
2243         if (MAIN_VERSION_OLDER(bmain, 267, 1)) {
2244                 Object *ob;
2245
2246                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2247                         ModifierData *md;
2248                         for (md = ob->modifiers.first; md; md = md->next) {
2249                                 if (md->type == eModifierType_Smoke) {
2250                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2251                                         if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
2252                                                 if (smd->domain->flags & MOD_SMOKE_HIGH_SMOOTH) {
2253                                                         smd->domain->highres_sampling = SM_HRES_LINEAR;
2254                                                 }
2255                                                 else {
2256                                                         smd->domain->highres_sampling = SM_HRES_NEAREST;
2257                                                 }
2258                                         }
2259                                 }
2260                         }
2261                 }
2262         }
2263
2264         if (!MAIN_VERSION_ATLEAST(bmain, 268, 1)) {
2265                 Brush *brush;
2266                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2267                         brush->spacing = MAX2(1, brush->spacing);
2268                 }
2269         }
2270
2271         if (!MAIN_VERSION_ATLEAST(bmain, 268, 2)) {
2272                 Brush *brush;
2273 #define BRUSH_FIXED (1 << 6)
2274                 for (brush = bmain->brush.first; brush; brush = brush->id.next) {
2275                         brush->flag &= ~BRUSH_FIXED;
2276
2277                         if (brush->cursor_overlay_alpha < 2)
2278                                 brush->cursor_overlay_alpha = 33;
2279                         if (brush->texture_overlay_alpha < 2)
2280                                 brush->texture_overlay_alpha = 33;
2281                         if (brush->mask_overlay_alpha < 2)
2282                                 brush->mask_overlay_alpha = 33;
2283                 }
2284 #undef BRUSH_FIXED
2285         }
2286
2287
2288         if (!MAIN_VERSION_ATLEAST(bmain, 268, 4)) {
2289                 bScreen *sc;
2290                 Object *ob;
2291
2292                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2293                         bConstraint *con;
2294                         for (con = ob->constraints.first; con; con = con->next) {
2295                                 if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
2296                                         bShrinkwrapConstraint *data = (bShrinkwrapConstraint *)con->data;
2297                                         if      (data->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) data->projAxis = OB_POSX;
2298                                         else if (data->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) data->projAxis = OB_POSY;
2299                                         else                                                          data->projAxis = OB_POSZ;
2300                                         data->projAxisSpace = CONSTRAINT_SPACE_LOCAL;
2301                                 }
2302                         }
2303                 }
2304
2305                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2306                         ModifierData *md;
2307                         for (md = ob->modifiers.first; md; md = md->next) {
2308                                 if (md->type == eModifierType_Smoke) {
2309                                         SmokeModifierData *smd = (SmokeModifierData *)md;
2310                                         if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
2311                                                 if (!smd->flow->particle_size) {
2312                                                         smd->flow->particle_size = 1.0f;
2313                                                 }
2314                                         }
2315                                 }
2316                         }
2317                 }
2318
2319                 /*
2320                  * FIX some files have a zoom level of 0, and was checked during the drawing of the node space
2321                  *
2322                  * We moved this check to the do versions to be sure the value makes any sense.
2323                  */
2324                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2325                         ScrArea *sa;
2326                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2327                                 SpaceLink *sl;
2328                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2329                                         if (sl->spacetype == SPACE_NODE) {
2330                                                 SpaceNode *snode = (SpaceNode *)sl;
2331                                                 if (snode->zoom < 0.02f) {
2332                                                         snode->zoom = 1.0;
2333                                                 }
2334                                         }
2335                                 }
2336                         }
2337                 }
2338
2339                 for (ob = bmain->object.first; ob; ob = ob->id.next) {
2340                         bSensor *sens;
2341                         bTouchSensor *ts;
2342                         bCollisionSensor *cs;
2343                         Material *ma;
2344
2345                         for (sens = ob->sensors.first; sens; sens = sens->next) {
2346                                 if (sens->type == SENS_TOUCH) {
2347                                         ts = sens->data;
2348                                         cs = MEM_callocN(sizeof(bCollisionSensor), "touch -> collision sensor do_version");
2349
2350                                         if (ts->ma) {
2351                                                 ma = blo_do_versions_newlibadr(fd, ob->id.lib, ts->ma);
2352                                                 BLI_strncpy(cs->materialName, ma->id.name + 2, sizeof(cs->materialName));
2353                                         }
2354
2355                                         cs->mode = SENS_COLLISION_MATERIAL;
2356
2357                                         MEM_freeN(ts);
2358
2359                                         sens->data = cs;
2360                                         sens->type = sens->otype = SENS_COLLISION;
2361                                 }
2362                         }
2363                 }
2364         }
2365
2366         if (!MAIN_VERSION_ATLEAST(bmain, 268, 5)) {
2367                 bScreen *sc;
2368                 ScrArea *sa;
2369
2370                 /* add missing (+) expander in node editor */
2371                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2372                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2373                                 ARegion *ar, *arnew;
2374
2375                                 if (sa->spacetype == SPACE_NODE) {
2376                                         ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
2377
2378                                         if (ar)
2379                                                 continue;
2380
2381                                         /* add subdiv level; after header */
2382                                         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
2383
2384                                         /* is error! */
2385                                         if (ar == NULL)
2386                                                 continue;
2387
2388                                         arnew = MEM_callocN(sizeof(ARegion), "node tools");
2389
2390                                         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
2391                                         arnew->regiontype = RGN_TYPE_TOOLS;
2392                                         arnew->alignment = RGN_ALIGN_LEFT;
2393
2394                                         arnew->flag = RGN_FLAG_HIDDEN;
2395                                 }
2396                         }
2397                 }
2398         }
2399
2400         if (!MAIN_VERSION_ATLEAST(bmain, 269, 1)) {
2401                 /* Removal of Cycles SSS Compatible falloff */
2402                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2403                         if (ntree->type == NTREE_SHADER) {
2404                                 bNode *node;
2405                                 for (node = ntree->nodes.first; node; node = node->next) {
2406                                         if (node->type == SH_NODE_SUBSURFACE_SCATTERING) {
2407                                                 if (node->custom1 == SHD_SUBSURFACE_COMPATIBLE) {
2408                                                         node->custom1 = SHD_SUBSURFACE_CUBIC;
2409                                                 }
2410                                         }
2411                                 }
2412                         }
2413                 } FOREACH_NODETREE_END;
2414         }
2415
2416         if (!MAIN_VERSION_ATLEAST(bmain, 269, 2)) {
2417                 /* Initialize CDL settings for Color Balance nodes */
2418                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
2419                         if (ntree->type == NTREE_COMPOSIT) {
2420                                 bNode *node;
2421                                 for (node = ntree->nodes.first; node; node = node->next) {
2422                                         if (node->type == CMP_NODE_COLORBALANCE) {
2423                                                 NodeColorBalance *n = node->storage;
2424                                                 if (node->custom1 == 0) {
2425                                                         /* LGG mode stays the same, just init CDL settings */
2426                                                         ntreeCompositColorBalanceSyncFromLGG(ntree, node);
2427                                                 }
2428                                                 else if (node->custom1 == 1) {
2429                                                         /* CDL previously used same variables as LGG, copy them over
2430                                                          * and then sync LGG for comparable results in both modes.
2431                                                          */
2432                                                         copy_v3_v3(n->offset, n->lift);
2433                                                         copy_v3_v3(n->power, n->gamma);
2434                                                         copy_v3_v3(n->slope, n->gain);
2435                                                         ntreeCompositColorBalanceSyncFromCDL(ntree, node);
2436                                                 }
2437                                         }
2438                                 }
2439                         }
2440                 } FOREACH_NODETREE_END;
2441         }
2442
2443         if (!MAIN_VERSION_ATLEAST(bmain, 269, 3)) {
2444                 bScreen *sc;
2445                 ScrArea *sa;
2446                 SpaceLink *sl;
2447                 Scene *scene;
2448
2449                 /* Update files using invalid (outdated) outlinevis Outliner values. */
2450                 for (sc = bmain->screen.first; sc; sc = sc->id.next) {
2451                         for (sa = sc->areabase.first; sa; sa = sa->next) {
2452                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2453                                         if (sl->spacetype == SPACE_OUTLINER) {
2454                                                 SpaceOops *so = (SpaceOops *)sl;
2455
2456                                                 if (!ELEM(so->outlinevis, SO_ALL_SCENES, SO_CUR_SCENE, SO_VISIBLE, SO_SELECTED, SO_ACTIVE,
2457                                                           SO_SAME_TYPE, SO_GROUPS, SO_LIBRARIES, SO_SEQUENCE, SO_DATABLOCKS,
2458                                                           SO_USERDEF))
2459                                                 {
2460                                                         so->outlinevis = SO_ALL_SCENES;
2461                                                 }
2462                                         }
2463                                 }
2464                         }
2465                 }
2466
2467                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight")) {
2468                         MovieClip *clip;
2469                         for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
2470                                 MovieTracking *tracking = &clip->tracking;
2471                                 MovieTrackingObject *tracking_object;
2472                                 for (tracking_object = tracking->objects.first;
2473                                      tracking_object;
2474                                      tracking_object = tracking_object->next)
2475                                 {
2476                                         ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
2477                                         MovieTrackingTrack *track;
2478                                         for (track = tracksbase->first;
2479                                              track;
2480                                              track = track->next)
2481                                         {
2482                                                 track->weight = 1.0f;
2483                                         }
2484                                 }
2485                         }
2486                 }
2487
2488                 if (!DNA_struct_elem_find(fd->filesdna, "TriangulateModifierData", "int", "quad_method")) {
2489                         Object *ob;
2490                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
2491                                 ModifierData *md;
2492                                 for (md = ob->modifiers.first; md; md = md->next) {
2493                                         if (md->type == eModifierType_Triangulate) {
2494                                                 TriangulateModifierData *tmd = (TriangulateModifierData *)md;
2495                                                 if ((tmd->flag & MOD_TRIANGULATE_BEAUTY)) {
2496                                                         tmd->quad_method = MOD_TRIANGULATE_QUAD_BEAUTY;
2497                                                         tmd->ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
2498                                                 }
2499                                                 else {
2500                                                         tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED;
2501                                                         tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP;
2502                                                 }
2503                                         }
2504                                 }
2505                         }
2506                 }
2507
2508                 for (scene = bmain->scene.first; scene; scene = scene->id.next) {
2509                         /* this can now be turned off */
2510                         ToolSettings *ts = scene->toolsettings;
2511                         if (ts->sculpt)
2512                                 ts->sculpt->flags |= SCULPT_DYNTOPO_SUBDIVIDE;
2513
2514                         /* single texture mode removed from game engine */
2515                         if (scene->gm.matmode == GAME_MAT_TEXFACE)
2516                                 scene->gm.matmode = GAME_MAT_MULTITEX;
2517
2518                         /* 'Increment' mode disabled for nodes, use true grid snapping instead */
2519                         if (scene->toolsettings->snap_node_mode == SCE_SNAP_MODE_INCREMENT)
2520                                 scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID;
2521
2522 #ifdef WITH_FFMPEG
2523                         /* Update for removed "sound-only" option in FFMPEG export settings. */
2524                         if (scene->r.ffcodecdata.type >= FFMPEG_INVALID) {
2525                                 scene->r.ffcodecdata.type = FFMPEG_AVI;
2526                         }
2527 #endif
2528
2529                 }
2530         }
2531
2532         if (!MAIN_VERSION_ATLEAST(bmain, 269, 4)) {
2533                 /* Internal degrees to radians conversions... */
2534                 {
2535                         Scene *scene;
2536                         Object *ob;
2537                         Lamp *lamp;
2538
2539                         for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next)
2540                                 lamp->spotsize = DEG2RADF(lamp->spotsize);
2541
2542                         for (ob = bmain->object.first; ob; ob = ob->id.next) {
2543                                 ModifierData *md;
2544                                 bSensor *bs;
2545                                 bActuator *ba;
2546
2547                                 for (md = ob->modifiers.first; md; md = md->next) {
2548                                         if (md->type == eModifierType_EdgeSplit) {
2549                                                 EdgeSplitModifierData *emd = (EdgeSplitModifierData *)md;
2550                                                 emd->split_angle = DEG2RADF(emd->split_angle);
2551                                         }
2552                                         else if (md->type == eModifierType_Bevel) {
2553                                                 BevelModifierData *bmd = (BevelModifierData *)md;
2554                                                 bmd->bevel_angle = DEG2RADF(bmd->bevel_angle);
2555                                         }
2556                                 }
2557
2558                                 for (bs = ob->sensors.first; bs; bs = bs->next) {
2559                                         if (bs->type == SENS_RADAR) {
2560                                                 bRadarSensor *brs = bs->data;
2561                                                 brs->angle = DEG2RADF(brs->angle);
2562                                         }
2563                                 }
2564
2565                                 for (ba = ob->actuators.first; ba; ba = ba->next) {
2566                                         if (ba->type == ACT_CONSTRAINT) {
2567                                                 bConstraintActuator *bca = ba->data;
2568                                                 if (bca->type == ACT_CONST_TYPE_ORI) {
2569                                                         bca->minloc[0] = DEG2RADF(bca->minloc[0]);
2570                                                         bca->maxloc[0] = DEG2RADF(bca->maxloc[0]);
2571                                                 }
2572                                         }
2573                                         else if (ba->type == ACT_SOUND) {
2574                                                 bSoundActuator *bsa = ba->data;
2575                                                 bsa->sound3D.cone_outer_angle = DEG2RADF(bsa->sound3D.cone_outer_angle);
2576                                                 bsa->sound3D.cone_inner_angle = DEG2RADF(bsa->sound3D.cone_inner_angle);
2577                                         }
2578                                 }
2579                         }
2580
2581        &