~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenloader/intern/readfile.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: readfile.c 30571 2010-07-21 09:25:00Z blendix $
3
 
 *
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
27
25
 *
28
26
 */
29
27
 
 
28
/** \file blender/blenloader/intern/readfile.c
 
29
 *  \ingroup blenloader
 
30
 */
 
31
 
 
32
 
30
33
#include "zlib.h"
31
34
 
32
35
#include <limits.h>
36
39
#include <fcntl.h> // for open
37
40
#include <string.h> // for strrchr strncmp strstr
38
41
#include <math.h> // for fabs
 
42
#include <stdarg.h> /* for va_start/end */
39
43
 
40
44
#ifndef WIN32
41
 
        #include <unistd.h> // for read close
42
 
        #include <sys/param.h> // for MAXPATHLEN
 
45
#  include <unistd.h> // for read close
43
46
#else
44
 
        #include <io.h> // for open close read
45
 
#include "winsock2.h"
46
 
#include "BLI_winstuff.h"
 
47
#  include <io.h> // for open close read
 
48
#  include "winsock2.h"
 
49
#  include "BLI_winstuff.h"
47
50
#endif
48
51
 
 
52
/* allow readfile to use deprecated functionality */
 
53
#define DNA_DEPRECATED_ALLOW
 
54
 
49
55
#include "DNA_anim_types.h"
50
 
#include "DNA_action_types.h"
51
56
#include "DNA_armature_types.h"
52
 
#include "DNA_ID.h"
53
57
#include "DNA_actuator_types.h"
54
 
#include "DNA_boid_types.h"
55
58
#include "DNA_brush_types.h"
56
59
#include "DNA_camera_types.h"
57
60
#include "DNA_cloth_types.h"
58
 
#include "DNA_color_types.h"
59
61
#include "DNA_controller_types.h"
60
62
#include "DNA_constraint_types.h"
61
 
#include "DNA_curve_types.h"
62
 
#include "DNA_customdata_types.h"
 
63
#include "DNA_dynamicpaint_types.h"
63
64
#include "DNA_effect_types.h"
64
65
#include "DNA_fileglobal_types.h"
65
66
#include "DNA_genfile.h"
66
67
#include "DNA_group_types.h"
67
68
#include "DNA_gpencil_types.h"
68
69
#include "DNA_ipo_types.h"
69
 
#include "DNA_image_types.h"
70
70
#include "DNA_key_types.h"
71
71
#include "DNA_lattice_types.h"
72
72
#include "DNA_lamp_types.h"
74
74
#include "DNA_material_types.h"
75
75
#include "DNA_mesh_types.h"
76
76
#include "DNA_meshdata_types.h"
77
 
#include "DNA_modifier_types.h"
78
77
#include "DNA_nla_types.h"
79
78
#include "DNA_node_types.h"
80
 
#include "DNA_object_types.h"
81
 
#include "DNA_object_force.h"
82
79
#include "DNA_object_fluidsim.h" // NT
83
 
#include "DNA_outliner_types.h"
84
 
#include "DNA_object_force.h"
85
80
#include "DNA_packedFile_types.h"
86
81
#include "DNA_particle_types.h"
87
82
#include "DNA_property_types.h"
93
88
#include "DNA_scene_types.h"
94
89
#include "DNA_sequence_types.h"
95
90
#include "DNA_smoke_types.h"
 
91
#include "DNA_speaker_types.h"
96
92
#include "DNA_sound_types.h"
97
93
#include "DNA_space_types.h"
98
 
#include "DNA_texture_types.h"
99
 
#include "DNA_userdef_types.h"
100
94
#include "DNA_vfont_types.h"
101
95
#include "DNA_world_types.h"
102
 
#include "DNA_windowmanager_types.h"
 
96
#include "DNA_movieclip_types.h"
103
97
 
104
98
#include "MEM_guardedalloc.h"
 
99
 
 
100
#include "BLI_utildefines.h"
105
101
#include "BLI_blenlib.h"
106
102
#include "BLI_math.h"
 
103
#include "BLI_edgehash.h"
107
104
 
108
105
#include "BKE_anim.h"
109
106
#include "BKE_action.h"
114
111
#include "BKE_context.h"
115
112
#include "BKE_curve.h"
116
113
#include "BKE_deform.h"
117
 
#include "BKE_effect.h" /* give_parteff */
 
114
#include "BKE_effect.h"
118
115
#include "BKE_fcurve.h"
119
116
#include "BKE_global.h" // for G
120
117
#include "BKE_group.h"
121
118
#include "BKE_image.h"
122
119
#include "BKE_lattice.h"
123
120
#include "BKE_library.h" // for which_libbase
 
121
#include "BKE_idcode.h"
 
122
#include "BKE_material.h"
124
123
#include "BKE_main.h" // for Main
125
124
#include "BKE_mesh.h" // for ME_ defines (patching)
126
125
#include "BKE_modifier.h"
127
126
#include "BKE_multires.h"
128
127
#include "BKE_node.h" // for tree type defines
 
128
#include "BKE_ocean.h"
129
129
#include "BKE_object.h"
130
130
#include "BKE_paint.h"
131
131
#include "BKE_particle.h"
136
136
#include "BKE_scene.h"
137
137
#include "BKE_screen.h"
138
138
#include "BKE_sequencer.h"
 
139
#include "BKE_text.h" // for txt_extended_ascii_as_utf8
139
140
#include "BKE_texture.h" // for open_plugin_tex
 
141
#include "BKE_tracking.h"
140
142
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
141
 
#include "BKE_ipo.h"
142
143
#include "BKE_sound.h"
143
144
 
 
145
#include "IMB_imbuf.h"  // for proxy / timecode versioning stuff
 
146
 
 
147
#include "NOD_socket.h"
 
148
 
144
149
//XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
145
150
//XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
146
151
//XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
147
152
#include "BLO_readfile.h"
148
153
#include "BLO_undofile.h"
149
 
#include "BLO_readblenfile.h" // streaming read pipe, for BLO_readblenfile BLO_readblenfilememory
 
154
 
 
155
#include "RE_engine.h"
150
156
 
151
157
#include "readfile.h"
152
158
 
242
248
 
243
249
 
244
250
/* local prototypes */
245
 
static void *read_struct(FileData *fd, BHead *bh, char *blockname);
246
 
 
 
251
static void *read_struct(FileData *fd, BHead *bh, const char *blockname);
 
252
static void direct_link_modifiers(FileData *fd, ListBase *lb);
 
253
static void convert_tface_mt(FileData *fd, Main *main);
 
254
 
 
255
/* this function ensures that reports are printed,
 
256
 * in the case of libraray linking errors this is important!
 
257
 *
 
258
 * bit kludge but better then doubling up on prints,
 
259
 * we could alternatively have a versions of a report function which foces printing - campbell
 
260
 */
 
261
static void BKE_reportf_wrap(ReportList *reports, ReportType type, const char *format, ...)
 
262
{
 
263
        char fixed_buf[1024]; /* should be long enough */
 
264
 
 
265
        va_list args;
 
266
 
 
267
        va_start(args, format);
 
268
        vsnprintf(fixed_buf, sizeof(fixed_buf), format, args);
 
269
        va_end(args);
 
270
 
 
271
        fixed_buf[sizeof(fixed_buf) - 1] = '\0';
 
272
 
 
273
        BKE_report(reports, type, fixed_buf);
 
274
 
 
275
        if (G.background==0) {
 
276
                printf("%s\n", fixed_buf);
 
277
        }
 
278
}
247
279
 
248
280
static OldNewMap *oldnewmap_new(void) 
249
281
{
259
291
{
260
292
        const struct OldNew *x1=v1, *x2=v2;
261
293
        
262
 
        if( x1->old > x2->old) return 1;
263
 
        else if( x1->old < x2->old) return -1;
 
294
        if ( x1->old > x2->old) return 1;
 
295
        else if ( x1->old < x2->old) return -1;
264
296
        return 0;
265
297
}
266
298
 
276
308
{
277
309
        OldNew *entry;
278
310
 
279
 
        if(oldaddr==NULL || newaddr==NULL) return;
 
311
        if (oldaddr==NULL || newaddr==NULL) return;
280
312
        
281
313
        if (onm->nentries==onm->entriessize) {
282
314
                int osize= onm->entriessize;
299
331
{
300
332
        int i;
301
333
 
 
334
        if (addr==NULL) return NULL;
 
335
 
302
336
        if (onm->lasthit<onm->nentries-1) {
303
337
                OldNew *entry= &onm->entries[++onm->lasthit];
304
338
 
327
361
{
328
362
        int i;
329
363
        
330
 
        if(addr==NULL) return NULL;
 
364
        if (addr==NULL) return NULL;
331
365
        
332
366
        /* lasthit works fine for non-libdata, linking there is done in same sequence as writing */
333
 
        if(onm->sorted) {
 
367
        if (onm->sorted) {
334
368
                OldNew entry_s, *entry;
335
369
                
336
370
                entry_s.old= addr;
337
371
                
338
372
                entry= bsearch(&entry_s, onm->entries, onm->nentries, sizeof(OldNew), verg_oldnewmap);
339
 
                if(entry) {
 
373
                if (entry) {
340
374
                        ID *id= entry->newp;
341
375
                        
342
376
                        if (id && (!lib || id->lib)) {
396
430
        ListBase *lbarray[MAX_LIBARRAY], *fromarray[MAX_LIBARRAY];
397
431
        int a;
398
432
 
399
 
        a= set_listbasepointers(mainvar, lbarray);
 
433
        set_listbasepointers(mainvar, lbarray);
400
434
        a= set_listbasepointers(from, fromarray);
401
 
        while(a--) {
402
 
                addlisttolist(lbarray[a], fromarray[a]);
 
435
        while (a--) {
 
436
                BLI_movelisttolist(lbarray[a], fromarray[a]);
403
437
        }
404
438
}
405
439
 
423
457
        Main *mainvar;
424
458
 
425
459
        id= lb->first;
426
 
        while(id) {
 
460
        while (id) {
427
461
                idnext= id->next;
428
 
                if(id->lib) {
 
462
                if (id->lib) {
429
463
                        mainvar= first;
430
 
                        while(mainvar) {
431
 
                                if(mainvar->curlib==id->lib) {
 
464
                        while (mainvar) {
 
465
                                if (mainvar->curlib==id->lib) {
432
466
                                        lbn= which_libbase(mainvar, GS(id->name));
433
467
                                        BLI_remlink(lb, id);
434
468
                                        BLI_addtail(lbn, id);
436
470
                                }
437
471
                                mainvar= mainvar->next;
438
472
                        }
439
 
                        if(mainvar==0) printf("error split_libdata\n");
 
473
                        if (mainvar==NULL) printf("error split_libdata\n");
440
474
                }
441
475
                id= idnext;
442
476
        }
451
485
        mainlist->first= mainlist->last= main;
452
486
        main->next= NULL;
453
487
 
454
 
        if(main->library.first==NULL)
 
488
        if (main->library.first==NULL)
455
489
                return;
456
490
        
457
491
        for (lib= main->library.first; lib; lib= lib->id.next) {
461
495
        }
462
496
 
463
497
        i= set_listbasepointers(main, lbarray);
464
 
        while(i--)
 
498
        while (i--)
465
499
                split_libdata(lbarray[i], main->next);
466
500
}
467
501
 
482
516
        for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
483
517
                if (bhead->code==GLOB) {
484
518
                        FileGlobal *fg= read_struct(fd, bhead, "Global");
485
 
                        if(fg) {
 
519
                        if (fg) {
486
520
                                main->subversionfile= fg->subversion;
487
521
                                main->minversionfile= fg->minversion;
488
522
                                main->minsubversionfile= fg->minsubversion;
495
529
}
496
530
 
497
531
 
498
 
static Main *blo_find_main(FileData *fd, ListBase *mainlist, const char *name, const char *relabase)
 
532
static Main *blo_find_main(FileData *fd, ListBase *mainlist, const char *filepath, const char *relabase)
499
533
{
500
534
        Main *m;
501
535
        Library *lib;
502
 
        char name1[FILE_MAXDIR+FILE_MAXFILE];
 
536
        char name1[FILE_MAX];
503
537
        
504
 
        strncpy(name1, name, sizeof(name1)-1);
 
538
        BLI_strncpy(name1, filepath, sizeof(name1));
505
539
        cleanup_path(relabase, name1);
506
540
//      printf("blo_find_main: original in  %s\n", name);
507
541
//      printf("blo_find_main: converted to %s\n", name1);
509
543
        for (m= mainlist->first; m; m= m->next) {
510
544
                char *libname= (m->curlib)?m->curlib->filepath:m->name;
511
545
                
512
 
                if (BLI_streq(name1, libname)) {
513
 
                        if(G.f & G_DEBUG) printf("blo_find_main: found library %s\n", libname);
 
546
                if (BLI_path_cmp(name1, libname) == 0) {
 
547
                        if (G.debug & G_DEBUG) printf("blo_find_main: found library %s\n", libname);
514
548
                        return m;
515
549
                }
516
550
        }
519
553
        BLI_addtail(mainlist, m);
520
554
 
521
555
        lib= alloc_libblock(&m->library, ID_LI, "lib");
522
 
        strncpy(lib->name, name, sizeof(lib->name)-1);
 
556
        BLI_strncpy(lib->name, filepath, sizeof(lib->name));
523
557
        BLI_strncpy(lib->filepath, name1, sizeof(lib->filepath));
524
558
        
525
559
        m->curlib= lib;
526
560
        
527
561
        read_file_version(fd, m);
528
562
        
529
 
        if(G.f & G_DEBUG) printf("blo_find_main: added new lib %s\n", name);
 
563
        if (G.debug & G_DEBUG) printf("blo_find_main: added new lib %s\n", filepath);
530
564
        return m;
531
565
}
532
566
 
536
570
static void switch_endian_bh4(BHead4 *bhead)
537
571
{
538
572
        /* the ID_.. codes */
539
 
        if((bhead->code & 0xFFFF)==0) bhead->code >>=16;
 
573
        if ((bhead->code & 0xFFFF)==0) bhead->code >>=16;
540
574
 
541
575
        if (bhead->code != ENDB) {
542
576
                SWITCH_INT(bhead->len);
548
582
static void switch_endian_bh8(BHead8 *bhead)
549
583
{
550
584
        /* the ID_.. codes */
551
 
        if((bhead->code & 0xFFFF)==0) bhead->code >>=16;
 
585
        if ((bhead->code & 0xFFFF)==0) bhead->code >>=16;
552
586
 
553
587
        if (bhead->code != ENDB) {
554
588
                SWITCH_INT(bhead->len);
578
612
                }
579
613
 
580
614
                /* this patch is to avoid a long long being read from not-eight aligned positions
581
 
                   is necessary on any modern 64bit architecture) */
 
615
                 * is necessary on any modern 64bit architecture) */
582
616
                memcpy(&old, &bhead8->old, 8);
583
617
                bhead4->old = (int) (old >> 3);
584
618
 
603
637
 
604
638
static BHeadN *get_bhead(FileData *fd)
605
639
{
606
 
        BHead8 bhead8;
607
 
        BHead4 bhead4;
608
 
        BHead  bhead;
609
 
        BHeadN *new_bhead = 0;
 
640
        BHeadN *new_bhead = NULL;
610
641
        int readsize;
611
642
        
612
643
        if (fd) {
613
644
                if ( ! fd->eof) {
614
 
 
615
 
                        /* not strictly needed but shuts valgrind up
 
645
                        /* initializing to zero isn't strictly needed but shuts valgrind up
616
646
                         * since uninitialized memory gets compared */
617
 
                        memset(&bhead8, 0, sizeof(BHead8));
618
 
                        memset(&bhead4, 0, sizeof(BHead4));
619
 
                        memset(&bhead,  0, sizeof(BHead));
 
647
                        BHead8 bhead8= {0};
 
648
                        BHead4 bhead4= {0};
 
649
                        BHead  bhead= {0};
620
650
                        
621
651
                        // First read the bhead structure.
622
652
                        // Depending on the platform the file was written on this can
636
666
 
637
667
                                        if (fd->flags & FD_FLAGS_POINTSIZE_DIFFERS) {
638
668
                                                bh8_from_bh4(&bhead, &bhead4);
639
 
                                        } else {
 
669
                                        }
 
670
                                        else {
640
671
                                                memcpy(&bhead, &bhead4, sizeof(bhead));
641
672
                                        }
642
 
                                } else {
 
673
                                }
 
674
                                else {
643
675
                                        fd->eof = 1;
644
676
                                        bhead.len= 0;
645
677
                                }
646
 
                        } else {
 
678
                        }
 
679
                        else {
647
680
                                bhead8.code = DATA;
648
681
                                readsize = fd->read(fd, &bhead8, sizeof(bhead8));
649
682
 
654
687
 
655
688
                                        if (fd->flags & FD_FLAGS_POINTSIZE_DIFFERS) {
656
689
                                                bh4_from_bh8(&bhead, &bhead8, (fd->flags & FD_FLAGS_SWITCH_ENDIAN));
657
 
                                        } else {
 
690
                                        }
 
691
                                        else {
658
692
                                                memcpy(&bhead, &bhead8, sizeof(bhead));
659
693
                                        }
660
 
                                } else {
 
694
                                }
 
695
                                else {
661
696
                                        fd->eof = 1;
662
697
                                        bhead.len= 0;
663
698
                                }
672
707
                        if ( ! fd->eof) {
673
708
                                new_bhead = MEM_mallocN(sizeof(BHeadN) + bhead.len, "new_bhead");
674
709
                                if (new_bhead) {
675
 
                                        new_bhead->next = new_bhead->prev = 0;
 
710
                                        new_bhead->next = new_bhead->prev = NULL;
676
711
                                        new_bhead->bhead = bhead;
677
712
 
678
713
                                        readsize = fd->read(fd, new_bhead + 1, bhead.len);
680
715
                                        if (readsize != bhead.len) {
681
716
                                                fd->eof = 1;
682
717
                                                MEM_freeN(new_bhead);
683
 
                                                new_bhead = 0;
 
718
                                                new_bhead = NULL;
684
719
                                        }
685
 
                                } else {
 
720
                                }
 
721
                                else {
686
722
                                        fd->eof = 1;
687
723
                                }
688
724
                        }
702
738
BHead *blo_firstbhead(FileData *fd)
703
739
{
704
740
        BHeadN *new_bhead;
705
 
        BHead *bhead = 0;
 
741
        BHead *bhead = NULL;
706
742
 
707
743
        // Rewind the file
708
744
        // Read in a new block if necessary
709
745
 
710
746
        new_bhead = fd->listbase.first;
711
 
        if (new_bhead == 0) {
 
747
        if (new_bhead == NULL) {
712
748
                new_bhead = get_bhead(fd);
713
749
        }
714
750
 
719
755
        return(bhead);
720
756
}
721
757
 
722
 
BHead *blo_prevbhead(FileData *fd, BHead *thisblock)
 
758
BHead *blo_prevbhead(FileData *UNUSED(fd), BHead *thisblock)
723
759
{
724
760
        BHeadN *bheadn= (BHeadN *) (((char *) thisblock) - GET_INT_FROM_POINTER( &((BHeadN*)0)->bhead) );
725
761
        BHeadN *prev= bheadn->prev;
739
775
 
740
776
                // get the next BHeadN. If it doesn't exist we read in the next one
741
777
                new_bhead = new_bhead->next;
742
 
                if (new_bhead == 0) {
 
778
                if (new_bhead == NULL) {
743
779
                        new_bhead = get_bhead(fd);
744
780
                }
745
781
        }
762
798
        readsize = fd->read(fd, header, sizeof(header));
763
799
 
764
800
        if (readsize == sizeof(header)) {
765
 
                if(strncmp(header, "BLENDER", 7) == 0) {
 
801
                if (strncmp(header, "BLENDER", 7) == 0) {
766
802
                        int remove_this_endian_test= 1;
767
803
 
768
804
                        fd->flags |= FD_FLAGS_FILE_OK;
769
805
 
770
806
                        // what size are pointers in the file ?
771
 
                        if(header[7]=='_') {
 
807
                        if (header[7]=='_') {
772
808
                                fd->flags |= FD_FLAGS_FILE_POINTSIZE_IS_4;
773
809
                                if (sizeof(void *) != 4) {
774
810
                                        fd->flags |= FD_FLAGS_POINTSIZE_DIFFERS;
775
811
                                }
776
 
                        } else {
 
812
                        }
 
813
                        else {
777
814
                                if (sizeof(void *) != 8) {
778
815
                                        fd->flags |= FD_FLAGS_POINTSIZE_DIFFERS;
779
816
                                }
811
848
                        }
812
849
 
813
850
                        return 1;
814
 
                } else if (bhead->code==ENDB)
 
851
                }
 
852
                else if (bhead->code==ENDB)
815
853
                        break;
816
854
        }
817
855
 
824
862
 
825
863
        if (readsize < 0) {
826
864
                readsize = EOF;
827
 
        } else {
 
865
        }
 
866
        else {
828
867
                filedata->seek += readsize;
829
868
        }
830
869
 
837
876
 
838
877
        if (readsize < 0) {
839
878
                readsize = EOF;
840
 
        } else {
 
879
        }
 
880
        else {
841
881
                filedata->seek += readsize;
842
882
        }
843
883
 
846
886
 
847
887
static int fd_read_from_memory(FileData *filedata, void *buffer, unsigned int size)
848
888
{
849
 
                // don't read more bytes then there are available in the buffer
850
 
        int readsize = MIN2(size, filedata->buffersize - filedata->seek);
 
889
        // don't read more bytes then there are available in the buffer
 
890
        int readsize = (int)MIN2(size, (unsigned int)(filedata->buffersize - filedata->seek));
851
891
 
852
892
        memcpy(buffer, filedata->buffer + filedata->seek, readsize);
853
893
        filedata->seek += readsize;
862
902
        static MemFileChunk *chunk=NULL;
863
903
        unsigned int chunkoffset, readsize, totread;
864
904
        
865
 
        if(size==0) return 0;
 
905
        if (size==0) return 0;
866
906
        
867
 
        if(seek != (unsigned int)filedata->seek) {
 
907
        if (seek != (unsigned int)filedata->seek) {
868
908
                chunk= filedata->memfile->chunks.first;
869
909
                seek= 0;
870
910
                
871
 
                while(chunk) {
872
 
                        if(seek + chunk->size > (unsigned) filedata->seek) break;
 
911
                while (chunk) {
 
912
                        if (seek + chunk->size > (unsigned) filedata->seek) break;
873
913
                        seek+= chunk->size;
874
914
                        chunk= chunk->next;
875
915
                }
877
917
                seek= filedata->seek;
878
918
        }
879
919
        
880
 
        if(chunk) {
 
920
        if (chunk) {
881
921
                totread= 0;
882
922
 
883
923
                do {
884
924
                        /* first check if it's on the end if current chunk */
885
 
                        if(seek-offset == chunk->size) {
 
925
                        if (seek-offset == chunk->size) {
886
926
                                offset+= chunk->size;
887
927
                                chunk= chunk->next;
888
928
                        }
889
929
 
890
930
                        /* debug, should never happen */
891
 
                        if(chunk==NULL) {
 
931
                        if (chunk==NULL) {
892
932
                                printf("illegal read, chunk zero\n");
893
933
                                return 0;
894
934
                        }
899
939
                        /* data can be spread over multiple chunks, so clamp size
900
940
                         * to within this chunk, and then it will read further in
901
941
                         * the next chunk */
902
 
                        if(chunkoffset+readsize > chunk->size)
 
942
                        if (chunkoffset+readsize > chunk->size)
903
943
                                readsize= chunk->size-chunkoffset;
904
944
 
905
945
                        memcpy((char*)buffer+totread, chunk->buf+chunkoffset, readsize);
906
946
                        totread += readsize;
907
947
                        filedata->seek += readsize;
908
948
                        seek += readsize;
909
 
                } while(totread < size);
 
949
                } while (totread < size);
910
950
                
911
951
                return totread;
912
952
        }
922
962
        fd->gzfiledes = NULL;
923
963
 
924
964
                /* XXX, this doesn't need to be done all the time,
925
 
                 * but it keeps us reentrant,  remove once we have
 
965
                 * but it keeps us re-entrant,  remove once we have
926
966
                 * a lib that provides a nice lock. - zr
927
967
                 */
928
968
        fd->memsdna = DNA_sdna_from_data(DNAstr,  DNAlen,  0);
940
980
 
941
981
        if (fd->flags & FD_FLAGS_FILE_OK) {
942
982
                if (!read_file_dna(fd)) {
943
 
                        BKE_report(reports, RPT_ERROR, "File incomplete");
 
983
                        BKE_reportf(reports, RPT_ERROR, "Failed to read blend file: \"%s\", incomplete", fd->relabase);
944
984
                        blo_freefiledata(fd);
945
985
                        fd= NULL;
946
986
                }
947
987
        } 
948
988
        else {
949
 
                BKE_report(reports, RPT_ERROR, "File is not a Blender file");
 
989
                BKE_reportf(reports, RPT_ERROR, "Failed to read blend file: \"%s\", not a blend file", fd->relabase);
950
990
                blo_freefiledata(fd);
951
991
                fd= NULL;
952
992
        }
956
996
 
957
997
/* cannot be called with relative paths anymore! */
958
998
/* on each new library added, it now checks for the current FileData and expands relativeness */
959
 
FileData *blo_openblenderfile(char *name, ReportList *reports)
 
999
FileData *blo_openblenderfile(const char *filepath, ReportList *reports)
960
1000
{
961
1001
        gzFile gzfile;
962
1002
        errno= 0;
963
 
        gzfile= gzopen(name, "rb");
 
1003
        gzfile= BLI_gzopen(filepath, "rb");
964
1004
 
965
 
        if (gzfile == Z_NULL) {
966
 
                BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", name, errno ? strerror(errno) : "Unknown erro reading file");
 
1005
        if (gzfile == (gzFile)Z_NULL) {
 
1006
                BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", filepath, errno ? strerror(errno) : "Unknown error reading file");
967
1007
                return NULL;
968
 
        } else {
 
1008
        }
 
1009
        else {
969
1010
                FileData *fd = filedata_new();
970
1011
                fd->gzfiledes = gzfile;
971
1012
                fd->read = fd_read_gzip_from_file;
972
1013
 
973
1014
                /* needed for library_append and read_libraries */
974
 
                BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
 
1015
                BLI_strncpy(fd->relabase, filepath, sizeof(fd->relabase));
975
1016
 
976
1017
                return blo_decode_and_check(fd, reports);
977
1018
        }
982
1023
        if (!mem || memsize<SIZEOFBLENDERHEADER) {
983
1024
                BKE_report(reports, RPT_ERROR, (mem)? "Unable to read": "Unable to open");
984
1025
                return NULL;
985
 
        } else {
 
1026
        }
 
1027
        else {
986
1028
                FileData *fd= filedata_new();
987
1029
                fd->buffer= mem;
988
1030
                fd->buffersize= memsize;
998
1040
        if (!memfile) {
999
1041
                BKE_report(reports, RPT_ERROR, "Unable to open blend <memory>");
1000
1042
                return NULL;
1001
 
        } else {
 
1043
        }
 
1044
        else {
1002
1045
                FileData *fd= filedata_new();
1003
1046
                fd->memfile= memfile;
1004
1047
 
1025
1068
 
1026
1069
                if (fd->buffer && !(fd->flags & FD_FLAGS_NOT_MY_BUFFER)) {
1027
1070
                        MEM_freeN(fd->buffer);
1028
 
                        fd->buffer = 0;
 
1071
                        fd->buffer = NULL;
1029
1072
                }
1030
1073
 
1031
1074
                // Free all BHeadN data blocks
1044
1087
                        oldnewmap_free(fd->globmap);
1045
1088
                if (fd->imamap)
1046
1089
                        oldnewmap_free(fd->imamap);
 
1090
                if (fd->movieclipmap)
 
1091
                        oldnewmap_free(fd->movieclipmap);
1047
1092
                if (fd->libmap && !(fd->flags & FD_FLAGS_NOT_MY_LIBMAP))
1048
1093
                        oldnewmap_free(fd->libmap);
1049
1094
                if (fd->bheadmap)
1055
1100
 
1056
1101
/* ************ DIV ****************** */
1057
1102
 
1058
 
int BLO_has_bfile_extension(char *str)
 
1103
int BLO_has_bfile_extension(const char *str)
1059
1104
{
1060
 
        return (BLI_testextensie(str, ".ble") || BLI_testextensie(str, ".blend")||BLI_testextensie(str, ".blend.gz"));
 
1105
        return (BLI_testextensie(str, ".ble") || BLI_testextensie(str, ".blend") || BLI_testextensie(str, ".blend.gz"));
1061
1106
}
1062
1107
 
1063
1108
int BLO_is_a_library(const char *path, char *dir, char *group)
1070
1115
        
1071
1116
        strcpy(dir, path);
1072
1117
        len= strlen(dir);
1073
 
        if(len<7) return 0;
1074
 
        if( dir[len-1] != '/' && dir[len-1] != '\\') return 0;
 
1118
        if (len<7) return 0;
 
1119
        if ( dir[len-1] != '/' && dir[len-1] != '\\') return 0;
1075
1120
        
1076
1121
        group[0]= 0;
1077
1122
        dir[len-1]= 0;
1079
1124
        /* Find the last slash */
1080
1125
        fd= BLI_last_slash(dir);
1081
1126
 
1082
 
        if(fd==0) return 0;
 
1127
        if (fd==NULL) return 0;
1083
1128
        *fd= 0;
1084
 
        if(BLO_has_bfile_extension(fd+1)) {
 
1129
        if (BLO_has_bfile_extension(fd+1)) {
1085
1130
                /* the last part of the dir is a .blend file, no group follows */
1086
1131
                *fd= '/'; /* put back the removed slash separating the dir and the .blend file name */
1087
1132
        }
1093
1138
                if (!fd || !BLO_has_bfile_extension(fd+1)) return 0;
1094
1139
 
1095
1140
                /* now we know that we are in a blend file and it is safe to 
1096
 
                   assume that gp actually points to a group */
1097
 
                if (BLI_streq("Screen", gp)==0)
 
1141
                 * assume that gp actually points to a group */
 
1142
                if (strcmp("Screen", gp)!=0)
1098
1143
                        BLI_strncpy(group, gp, GROUP_MAX);
1099
1144
        }
1100
1145
        return 1;
1114
1159
 
1115
1160
static void *newimaadr(FileData *fd, void *adr)         /* used to restore image data after undo */
1116
1161
{
1117
 
        if(fd->imamap && adr)
 
1162
        if (fd->imamap && adr)
1118
1163
                return oldnewmap_lookup_and_inc(fd->imamap, adr);
1119
1164
        return NULL;
1120
1165
}
1121
1166
 
 
1167
static void *newmclipadr(FileData *fd, void *adr)              /* used to restore movie clip data after undo */
 
1168
{
 
1169
        if (fd->movieclipmap && adr)
 
1170
                return oldnewmap_lookup_and_inc(fd->movieclipmap, adr);
 
1171
        return NULL;
 
1172
}
 
1173
 
1122
1174
 
1123
1175
static void *newlibadr(FileData *fd, void *lib, void *adr)              /* only lib data */
1124
1176
{
1129
1181
{
1130
1182
        ID *id= newlibadr(fd, lib, adr);
1131
1183
 
1132
 
        if(id)
 
1184
        if (id)
1133
1185
                id->us++;
1134
1186
 
1135
1187
        return id;
1144
1196
                
1145
1197
                if (old==entry->newp && entry->nr==ID_ID) {
1146
1198
                        entry->newp= new;
1147
 
                        if(new) entry->nr= GS( ((ID *)new)->name );
 
1199
                        if (new) entry->nr= GS( ((ID *)new)->name );
1148
1200
                        break;
1149
1201
                }
1150
1202
        }
1154
1206
{
1155
1207
        Main *mainptr;
1156
1208
        
1157
 
        for(mainptr= mainlist->first; mainptr; mainptr= mainptr->next) {
 
1209
        for (mainptr= mainlist->first; mainptr; mainptr= mainptr->next) {
1158
1210
                FileData *fd;
1159
1211
                
1160
 
                if(mainptr->curlib) fd= mainptr->curlib->filedata;
 
1212
                if (mainptr->curlib) fd= mainptr->curlib->filedata;
1161
1213
                else fd= basefd;
1162
1214
                
1163
 
                if(fd) {
 
1215
                if (fd) {
1164
1216
                        change_idid_adr_fd(fd, old, new);
1165
1217
                }
1166
1218
        }
1170
1222
 * to clear that pointer before reading the undo memfile since
1171
1223
 * the object might be removed, it is set again in reading
1172
1224
 * if the local object still exists */
1173
 
void blo_clear_proxy_pointers_from_lib(FileData *fd, Main *oldmain)
 
1225
void blo_clear_proxy_pointers_from_lib(Main *oldmain)
1174
1226
{
1175
1227
        Object *ob= oldmain->object.first;
1176
1228
        
1177
 
        for(;ob; ob= ob->id.next)
1178
 
                if(ob->id.lib)
 
1229
        for (;ob; ob= ob->id.next)
 
1230
                if (ob->id.lib)
1179
1231
                        ob->proxy_from= NULL;
1180
1232
}
1181
1233
 
1187
1239
        
1188
1240
        fd->imamap= oldnewmap_new();
1189
1241
        
1190
 
        for(;ima; ima= ima->id.next) {
 
1242
        for (;ima; ima= ima->id.next) {
1191
1243
                Link *ibuf= ima->ibufs.first;
1192
 
                for(; ibuf; ibuf= ibuf->next) 
 
1244
                for (; ibuf; ibuf= ibuf->next)
1193
1245
                        oldnewmap_insert(fd->imamap, ibuf, ibuf, 0);
1194
 
                if(ima->gputexture)
 
1246
                if (ima->gputexture)
1195
1247
                        oldnewmap_insert(fd->imamap, ima->gputexture, ima->gputexture, 0);
1196
 
                for(a=0; a<IMA_MAX_RENDER_SLOT; a++)
1197
 
                        if(ima->renders[a])
 
1248
                for (a=0; a<IMA_MAX_RENDER_SLOT; a++)
 
1249
                        if (ima->renders[a])
1198
1250
                                oldnewmap_insert(fd->imamap, ima->renders[a], ima->renders[a], 0);
1199
1251
        }
1200
 
        for(; sce; sce= sce->id.next) {
1201
 
                if(sce->nodetree) {
 
1252
        for (; sce; sce= sce->id.next) {
 
1253
                if (sce->nodetree) {
1202
1254
                        bNode *node;
1203
 
                        for(node= sce->nodetree->nodes.first; node; node= node->next)
 
1255
                        for (node= sce->nodetree->nodes.first; node; node= node->next)
1204
1256
                                oldnewmap_insert(fd->imamap, node->preview, node->preview, 0);
1205
1257
                }
1206
1258
        }
1213
1265
        OldNew *entry= fd->imamap->entries;
1214
1266
        Image *ima= oldmain->image.first;
1215
1267
        Scene *sce= oldmain->scene.first;
1216
 
        int i, a;
 
1268
        int i;
1217
1269
        
1218
1270
        /* used entries were restored, so we put them to zero */
1219
1271
        for (i=0; i<fd->imamap->nentries; i++, entry++) {
1220
 
                 if (entry->nr>0)
 
1272
                if (entry->nr>0)
1221
1273
                        entry->newp= NULL;
1222
1274
        }
1223
1275
        
1224
 
        for(;ima; ima= ima->id.next) {
 
1276
        for (;ima; ima= ima->id.next) {
1225
1277
                Link *ibuf, *next;
1226
1278
                
1227
1279
                /* this mirrors direct_link_image */
1228
 
                for(ibuf= ima->ibufs.first; ibuf; ibuf= next) {
 
1280
                for (ibuf= ima->ibufs.first; ibuf; ibuf= next) {
1229
1281
                        next= ibuf->next;
1230
 
                        if(NULL==newimaadr(fd, ibuf)) { /* so was restored */
 
1282
                        if (NULL==newimaadr(fd, ibuf)) {        /* so was restored */
1231
1283
                                BLI_remlink(&ima->ibufs, ibuf);
1232
1284
                                ima->bindcode= 0;
1233
1285
                                ima->gputexture= NULL;
1234
1286
                        }
1235
1287
                }
 
1288
                for (i=0; i<IMA_MAX_RENDER_SLOT; i++)
 
1289
                        ima->renders[i]= newimaadr(fd, ima->renders[i]);
1236
1290
 
1237
1291
                ima->gputexture= newimaadr(fd, ima->gputexture);
1238
 
                for(a=0; a<IMA_MAX_RENDER_SLOT; a++)
1239
 
                        ima->renders[a]= newimaadr(fd, ima->renders[a]);
1240
1292
        }
1241
 
        for(; sce; sce= sce->id.next) {
1242
 
                if(sce->nodetree) {
 
1293
        for (; sce; sce= sce->id.next) {
 
1294
                if (sce->nodetree) {
1243
1295
                        bNode *node;
1244
 
                        for(node= sce->nodetree->nodes.first; node; node= node->next)
 
1296
                        for (node= sce->nodetree->nodes.first; node; node= node->next)
1245
1297
                                node->preview= newimaadr(fd, node->preview);
1246
1298
                }
1247
1299
        }
1248
1300
}
1249
1301
 
 
1302
void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain)
 
1303
{
 
1304
        MovieClip *clip= oldmain->movieclip.first;
 
1305
        Scene *sce= oldmain->scene.first;
 
1306
 
 
1307
        fd->movieclipmap= oldnewmap_new();
 
1308
 
 
1309
        for (;clip; clip= clip->id.next) {
 
1310
                if (clip->cache)
 
1311
                        oldnewmap_insert(fd->movieclipmap, clip->cache, clip->cache, 0);
 
1312
 
 
1313
                if (clip->tracking.camera.intrinsics)
 
1314
                        oldnewmap_insert(fd->movieclipmap, clip->tracking.camera.intrinsics, clip->tracking.camera.intrinsics, 0);
 
1315
        }
 
1316
 
 
1317
        for (; sce; sce= sce->id.next) {
 
1318
                if (sce->nodetree) {
 
1319
                        bNode *node;
 
1320
                        for (node= sce->nodetree->nodes.first; node; node= node->next)
 
1321
                                if (node->type==CMP_NODE_MOVIEDISTORTION)
 
1322
                                        oldnewmap_insert(fd->movieclipmap, node->storage, node->storage, 0);
 
1323
                }
 
1324
        }
 
1325
}
 
1326
 
 
1327
/* set old main movie clips caches to zero if it has been restored */
 
1328
/* this works because freeing old main only happens after this call */
 
1329
void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain)
 
1330
{
 
1331
        OldNew *entry= fd->movieclipmap->entries;
 
1332
        MovieClip *clip= oldmain->movieclip.first;
 
1333
        Scene *sce= oldmain->scene.first;
 
1334
        int i;
 
1335
 
 
1336
        /* used entries were restored, so we put them to zero */
 
1337
        for (i=0; i<fd->movieclipmap->nentries; i++, entry++) {
 
1338
                if (entry->nr>0)
 
1339
                                entry->newp= NULL;
 
1340
        }
 
1341
 
 
1342
        for (;clip; clip= clip->id.next) {
 
1343
                clip->cache= newmclipadr(fd, clip->cache);
 
1344
                clip->tracking.camera.intrinsics= newmclipadr(fd, clip->tracking.camera.intrinsics);
 
1345
        }
 
1346
 
 
1347
        for (; sce; sce= sce->id.next) {
 
1348
                if (sce->nodetree) {
 
1349
                        bNode *node;
 
1350
                        for (node= sce->nodetree->nodes.first; node; node= node->next)
 
1351
                                if (node->type==CMP_NODE_MOVIEDISTORTION)
 
1352
                                        node->storage= newmclipadr(fd, node->storage);
 
1353
                }
 
1354
        }
 
1355
}
 
1356
 
 
1357
 
1250
1358
/* undo file support: add all library pointers in lookup */
1251
1359
void blo_add_library_pointer_map(ListBase *mainlist, FileData *fd)
1252
1360
{
1253
1361
        Main *ptr= mainlist->first;
1254
1362
        ListBase *lbarray[MAX_LIBARRAY];
1255
1363
        
1256
 
        for(ptr= ptr->next; ptr; ptr= ptr->next) {
 
1364
        for (ptr= ptr->next; ptr; ptr= ptr->next) {
1257
1365
                int i= set_listbasepointers(ptr, lbarray);
1258
 
                while(i--) {
 
1366
                while (i--) {
1259
1367
                        ID *id;
1260
 
                        for(id= lbarray[i]->first; id; id= id->next)
 
1368
                        for (id= lbarray[i]->first; id; id= id->next)
1261
1369
                                oldnewmap_insert(fd->libmap, id, id, GS(id->name));
1262
1370
                }
1263
1371
        }
1276
1384
        blocksize= filesdna->typelens[ filesdna->structs[bhead->SDNAnr][0] ];
1277
1385
 
1278
1386
        nblocks= bhead->nr;
1279
 
        while(nblocks--) {
 
1387
        while (nblocks--) {
1280
1388
                DNA_struct_switch_endian(filesdna, bhead->SDNAnr, data);
1281
1389
 
1282
1390
                data+= blocksize;
1283
1391
        }
1284
1392
}
1285
1393
 
1286
 
static void *read_struct(FileData *fd, BHead *bh, char *blockname)
 
1394
static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
1287
1395
{
1288
1396
        void *temp= NULL;
1289
1397
 
1293
1401
                        switch_endian_structs(fd->filesdna, bh);
1294
1402
 
1295
1403
                if (fd->compflags[bh->SDNAnr]) {        /* flag==0: doesn't exist anymore */
1296
 
                        if(fd->compflags[bh->SDNAnr]==2) {
 
1404
                        if (fd->compflags[bh->SDNAnr]==2) {
1297
1405
                                temp= DNA_struct_reconstruct(fd->memsdna, fd->filesdna, fd->compflags, bh->SDNAnr, bh->nr, (bh+1));
1298
 
                        } else {
 
1406
                        }
 
1407
                        else {
1299
1408
                                temp= MEM_mallocN(bh->len, blockname);
1300
1409
                                memcpy(temp, (bh+1), bh->len);
1301
1410
                        }
1309
1418
{
1310
1419
        Link *ln, *prev;
1311
1420
 
1312
 
        if(lb->first==NULL) return;
 
1421
        if (lb->first==NULL) return;
1313
1422
 
1314
1423
        lb->first= newdataadr(fd, lb->first);
1315
1424
        ln= lb->first;
1316
1425
        prev= NULL;
1317
 
        while(ln) {
 
1426
        while (ln) {
1318
1427
                ln->next= newdataadr(fd, ln->next);
1319
1428
                ln->prev= prev;
1320
1429
                prev= ln;
1328
1437
        Link *ln, *prev;
1329
1438
        void *poin;
1330
1439
 
1331
 
        if(lb->first==0) return;
 
1440
        if (lb->first==NULL) return;
1332
1441
        poin= newdataadr(fd, lb->first);
1333
 
        if(lb->first) {
 
1442
        if (lb->first) {
1334
1443
                oldnewmap_insert(fd->globmap, lb->first, poin, 0);
1335
1444
        }
1336
1445
        lb->first= poin;
1337
1446
 
1338
1447
        ln= lb->first;
1339
 
        prev= 0;
1340
 
        while(ln) {
 
1448
        prev= NULL;
 
1449
        while (ln) {
1341
1450
                poin= newdataadr(fd, ln->next);
1342
 
                if(ln->next) {
 
1451
                if (ln->next) {
1343
1452
                        oldnewmap_insert(fd->globmap, ln->next, poin, 0);
1344
1453
                }
1345
1454
                ln->next= poin;
1364
1473
                 * the old dna format to a pointer array in
1365
1474
                 * the new dna format.
1366
1475
                 */
1367
 
        if(*mat) {
 
1476
        if (*mat) {
1368
1477
                len= MEM_allocN_len(*mat)/fd->filesdna->pointerlen;
1369
1478
 
1370
 
                if(fd->filesdna->pointerlen==8 && fd->memsdna->pointerlen==4) {
 
1479
                if (fd->filesdna->pointerlen==8 && fd->memsdna->pointerlen==4) {
1371
1480
                        ipoin=imat= MEM_mallocN( len*4, "newmatar");
1372
1481
                        lpoin= *mat;
1373
1482
 
1374
 
                        while(len-- > 0) {
1375
 
                                if((fd->flags & FD_FLAGS_SWITCH_ENDIAN))
 
1483
                        while (len-- > 0) {
 
1484
                                if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN))
1376
1485
                                        SWITCH_LONGINT(*lpoin);
1377
1486
                                *ipoin= (int) ((*lpoin) >> 3);
1378
1487
                                ipoin++;
1382
1491
                        *mat= imat;
1383
1492
                }
1384
1493
 
1385
 
                if(fd->filesdna->pointerlen==4 && fd->memsdna->pointerlen==8) {
 
1494
                if (fd->filesdna->pointerlen==4 && fd->memsdna->pointerlen==8) {
1386
1495
                        lpoin=lmat= MEM_mallocN( len*8, "newmatar");
1387
1496
                        ipoin= *mat;
1388
1497
 
1389
 
                        while(len-- > 0) {
 
1498
                        while (len-- > 0) {
1390
1499
                                *lpoin= *ipoin;
1391
1500
                                ipoin++;
1392
1501
                                lpoin++;
1399
1508
 
1400
1509
/* ************ READ ID Properties *************** */
1401
1510
 
1402
 
void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
1403
 
void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
 
1511
static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
 
1512
static void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
1404
1513
 
1405
1514
static void IDP_DirectLinkIDPArray(IDProperty *prop, int switch_endian, FileData *fd)
1406
1515
{
1412
1521
        prop->data.pointer = newdataadr(fd, prop->data.pointer);
1413
1522
 
1414
1523
        array= (IDProperty*) prop->data.pointer;
 
1524
        
 
1525
        /* note!, idp-arrays didn't exist in 2.4x, so the pointer will be cleared
 
1526
         * theres not really anything we can do to correct this, at least don't crash */
 
1527
        if (array==NULL) {
 
1528
                prop->len= 0;
 
1529
                prop->totallen= 0;
 
1530
        }
 
1531
        
1415
1532
 
1416
 
        for(i=0; i<prop->len; i++)
 
1533
        for (i=0; i<prop->len; i++)
1417
1534
                IDP_DirectLinkProperty(&array[i], switch_endian, fd);
1418
1535
}
1419
1536
 
1426
1543
        prop->totallen = prop->len;
1427
1544
        prop->data.pointer = newdataadr(fd, prop->data.pointer);
1428
1545
 
1429
 
        if(prop->subtype == IDP_GROUP) {
 
1546
        if (prop->subtype == IDP_GROUP) {
1430
1547
                test_pointer_array(fd, prop->data.pointer);
1431
1548
                array= prop->data.pointer;
1432
1549
 
1433
 
                for(i=0; i<prop->len; i++)
 
1550
                for (i=0; i<prop->len; i++)
1434
1551
                        IDP_DirectLinkProperty(array[i], switch_endian, fd);
1435
1552
        }
1436
 
        else if(prop->subtype == IDP_DOUBLE) {
 
1553
        else if (prop->subtype == IDP_DOUBLE) {
1437
1554
                if (switch_endian) {
1438
1555
                        for (i=0; i<prop->len; i++) {
1439
1556
                                SWITCH_LONGINT(((double*)prop->data.pointer)[i]);
1449
1566
        }
1450
1567
}
1451
1568
 
1452
 
static void IDP_DirectLinkString(IDProperty *prop, int switch_endian, FileData *fd)
 
1569
static void IDP_DirectLinkString(IDProperty *prop, FileData *fd)
1453
1570
{
1454
1571
        /*since we didn't save the extra string buffer, set totallen to len.*/
1455
1572
        prop->totallen = prop->len;
1469
1586
        }
1470
1587
}
1471
1588
 
1472
 
void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd)
 
1589
static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd)
1473
1590
{
1474
1591
        switch (prop->type) {
1475
1592
                case IDP_GROUP:
1476
1593
                        IDP_DirectLinkGroup(prop, switch_endian, fd);
1477
1594
                        break;
1478
1595
                case IDP_STRING:
1479
 
                        IDP_DirectLinkString(prop, switch_endian, fd);
 
1596
                        IDP_DirectLinkString(prop, fd);
1480
1597
                        break;
1481
1598
                case IDP_ARRAY:
1482
1599
                        IDP_DirectLinkArray(prop, switch_endian, fd);
1485
1602
                        IDP_DirectLinkIDPArray(prop, switch_endian, fd);
1486
1603
                        break;
1487
1604
                case IDP_DOUBLE:
1488
 
                        /*erg, stupid doubles.  since I'm storing them
1489
 
                         in the same field as int val; val2 in the
1490
 
                         IDPropertyData struct, they have to deal with
1491
 
                         endianness specifically
1492
 
                         
1493
 
                         in theory, val and val2 would've already been swapped
1494
 
                         if switch_endian is true, so we have to first unswap
1495
 
                         them then reswap them as a single 64-bit entity.
 
1605
                        /* erg, stupid doubles.  since I'm storing them
 
1606
                         * in the same field as int val; val2 in the
 
1607
                         * IDPropertyData struct, they have to deal with
 
1608
                         * endianness specifically
 
1609
                         *
 
1610
                         * in theory, val and val2 would've already been swapped
 
1611
                         * if switch_endian is true, so we have to first unswap
 
1612
                         * them then reswap them as a single 64-bit entity.
1496
1613
                         */
1497
1614
                        
1498
1615
                        if (switch_endian) {
1506
1623
}
1507
1624
 
1508
1625
/*stub function*/
1509
 
void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd)
 
1626
static void IDP_LibLinkProperty(IDProperty *UNUSED(prop), int UNUSED(switch_endian), FileData *UNUSED(fd))
1510
1627
{
1511
1628
}
1512
1629
 
1520
1637
        /* flag seems to be able to hang? Maybe old files... not bad to clear anyway */
1521
1638
        cumap->flag &= ~CUMA_PREMULLED;
1522
1639
        
1523
 
        for(a=0; a<CM_TOT; a++) {
 
1640
        for (a=0; a<CM_TOT; a++) {
1524
1641
                cumap->cm[a].curve= newdataadr(fd, cumap->cm[a].curve);
1525
1642
                cumap->cm[a].table= NULL;
1526
1643
                cumap->cm[a].premultable= NULL;
1534
1651
        Brush *brush;
1535
1652
        
1536
1653
        /* only link ID pointers */
1537
 
        for(brush= main->brush.first; brush; brush= brush->id.next) {
1538
 
                if(brush->id.flag & LIB_NEEDLINK) {
 
1654
        for (brush= main->brush.first; brush; brush= brush->id.next) {
 
1655
                if (brush->id.flag & LIB_NEEDLINK) {
1539
1656
                        brush->id.flag -= LIB_NEEDLINK;
1540
1657
 
1541
1658
                        brush->mtex.tex= newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
1550
1667
 
1551
1668
        /* fallof curve */
1552
1669
        brush->curve= newdataadr(fd, brush->curve);
1553
 
        if(brush->curve)
 
1670
        if (brush->curve)
1554
1671
                direct_link_curvemapping(fd, brush->curve);
1555
1672
        else
1556
1673
                brush_curve_preset(brush, CURVE_PRESET_SHARP);
1559
1676
        brush->icon_imbuf= NULL;
1560
1677
}
1561
1678
 
1562
 
static void direct_link_script(FileData *fd, Script *script)
 
1679
static void direct_link_script(FileData *UNUSED(fd), Script *script)
1563
1680
{
1564
1681
        script->id.us = 1;
1565
 
        SCRIPT_SET_NULL(script)
 
1682
        SCRIPT_SET_NULL(script);
1566
1683
}
1567
1684
 
1568
1685
 
1587
1704
 
1588
1705
        if (prv) {
1589
1706
                int i;
1590
 
                for (i=0; i < PREVIEW_MIPMAPS; ++i) {
 
1707
                for (i=0; i < NUM_ICON_SIZES; ++i) {
1591
1708
                        if (prv->rect[i]) {
1592
1709
                                prv->rect[i] = newdataadr(fd, prv->rect[i]);
1593
1710
                        }
1607
1724
        Ipo *ipo;
1608
1725
 
1609
1726
        ipo= main->ipo.first;
1610
 
        while(ipo) {
1611
 
                if(ipo->id.flag & LIB_NEEDLINK) {
 
1727
        while (ipo) {
 
1728
                if (ipo->id.flag & LIB_NEEDLINK) {
1612
1729
                        IpoCurve *icu;
1613
 
                        for(icu= ipo->curve.first; icu; icu= icu->next) {
1614
 
                                if(icu->driver)
 
1730
                        for (icu= ipo->curve.first; icu; icu= icu->next) {
 
1731
                                if (icu->driver)
1615
1732
                                        icu->driver->ob= newlibadr(fd, ipo->id.lib, icu->driver->ob);
1616
1733
                        }
1617
1734
                        ipo->id.flag -= LIB_NEEDLINK;
1627
1744
 
1628
1745
        link_list(fd, &(ipo->curve));
1629
1746
        icu= ipo->curve.first;
1630
 
        while(icu) {
 
1747
        while (icu) {
1631
1748
                icu->bezt= newdataadr(fd, icu->bezt);
1632
1749
                icu->bp= newdataadr(fd, icu->bp);
1633
1750
                icu->driver= newdataadr(fd, icu->driver);
1641
1758
        bActionStrip *strip;
1642
1759
        bActionModifier *amod;
1643
1760
        
1644
 
        for (strip=striplist->first; strip; strip=strip->next){
 
1761
        for (strip=striplist->first; strip; strip=strip->next) {
1645
1762
                strip->object = newlibadr(fd, id->lib, strip->object);
1646
1763
                strip->act = newlibadr_us(fd, id->lib, strip->act);
1647
1764
                strip->ipo = newlibadr(fd, id->lib, strip->ipo);
1648
 
                for(amod= strip->modifiers.first; amod; amod= amod->next)
 
1765
                for (amod= strip->modifiers.first; amod; amod= amod->next)
1649
1766
                        amod->ob= newlibadr(fd, id->lib, amod->ob);
1650
1767
        }
1651
1768
}
1657
1774
        
1658
1775
        link_list(fd, strips);
1659
1776
        
1660
 
        for(strip= strips->first; strip; strip= strip->next)
 
1777
        for (strip= strips->first; strip; strip= strip->next)
1661
1778
                link_list(fd, &strip->modifiers);
1662
1779
}
1663
1780
 
1666
1783
{
1667
1784
        bConstraintChannel *chan;
1668
1785
 
1669
 
        for (chan=chanbase->first; chan; chan=chan->next){
 
1786
        for (chan=chanbase->first; chan; chan=chan->next) {
1670
1787
                chan->ipo = newlibadr_us(fd, id->lib, chan->ipo);
1671
1788
        }
1672
1789
}
1740
1857
                                FMod_Generator *data= (FMod_Generator *)fcm->data;
1741
1858
                                
1742
1859
                                data->coefficients= newdataadr(fd, data->coefficients);
 
1860
 
 
1861
                                if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
 
1862
                                        unsigned int a;
 
1863
                                        for (a = 0; a < data->arraysize; a++)
 
1864
                                                SWITCH_INT(data->coefficients[a]);
 
1865
                                }
1743
1866
                        }
1744
1867
                                break;
1745
1868
                        case FMODIFIER_TYPE_ENVELOPE:
1868
1991
                
1869
1992
                /* reassign the counted-reference to action */
1870
1993
                strip->act = newlibadr_us(fd, id->lib, strip->act);
 
1994
                
 
1995
                /* fix action id-root (i.e. if it comes from a pre 2.57 .blend file) */
 
1996
                if ((strip->act) && (strip->act->idroot == 0))
 
1997
                        strip->act->idroot = GS(id->name);
1871
1998
        }
1872
1999
}
1873
2000
 
1899
2026
                
1900
2027
                /* strip's F-Modifiers */
1901
2028
                link_list(fd, &strip->modifiers);
1902
 
                direct_link_fcurves(fd, &strip->modifiers);
 
2029
                direct_link_fmodifiers(fd, &strip->modifiers);
1903
2030
        }
1904
2031
}
1905
2032
 
1961
2088
        adt->action= newlibadr_us(fd, id->lib, adt->action);
1962
2089
        adt->tmpact= newlibadr_us(fd, id->lib, adt->tmpact);
1963
2090
        
 
2091
        /* fix action id-roots (i.e. if they come from a pre 2.57 .blend file) */
 
2092
        if ((adt->action) && (adt->action->idroot == 0))
 
2093
                adt->action->idroot = GS(id->name);
 
2094
        if ((adt->tmpact) && (adt->tmpact->idroot == 0))
 
2095
                adt->tmpact->idroot = GS(id->name);
 
2096
        
1964
2097
        /* link drivers */
1965
2098
        lib_link_fcurves(fd, id, &adt->drivers);
1966
2099
        
1987
2120
        link_list(fd, &adt->nla_tracks);
1988
2121
        direct_link_nladata(fd, &adt->nla_tracks);
1989
2122
        
1990
 
        /* clear temp pointers that may have been set... */
1991
 
        // TODO: it's probably only a small cost to reload this anyway...
1992
 
        adt->actstrip= NULL;
 
2123
        /* relink active strip - even though strictly speaking this should only be used
 
2124
         * if we're in 'tweaking mode', we need to be able to have this loaded back for
 
2125
         * undo, but also since users may not exit tweakmode before saving (#24535)
 
2126
         */
 
2127
        // TODO: it's not really nice that anyone should be able to save the file in this
 
2128
        //              state, but it's going to be too hard to enforce this single case...
 
2129
        adt->actstrip= newdataadr(fd, adt->actstrip);
1993
2130
}       
1994
2131
 
1995
2132
/* ************ READ MOTION PATHS *************** */
2012
2149
{
2013
2150
        bNode *node;
2014
2151
        
2015
 
        if(ntree->adt) lib_link_animdata(fd, &ntree->id, ntree->adt);
 
2152
        if (ntree->adt) lib_link_animdata(fd, &ntree->id, ntree->adt);
2016
2153
        
2017
2154
        ntree->gpd= newlibadr_us(fd, id->lib, ntree->gpd);
2018
2155
        
2019
 
        for(node= ntree->nodes.first; node; node= node->next)
 
2156
        for (node= ntree->nodes.first; node; node= node->next)
2020
2157
                node->id= newlibadr_us(fd, id->lib, node->id);
2021
2158
}
2022
2159
 
2026
2163
        bNodeTree *ntree;
2027
2164
        
2028
2165
        /* only link ID pointers */
2029
 
        for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
2030
 
                if(ntree->id.flag & LIB_NEEDLINK) {
 
2166
        for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
 
2167
                if (ntree->id.flag & LIB_NEEDLINK) {
2031
2168
                        ntree->id.flag -= LIB_NEEDLINK;
2032
2169
                        lib_link_ntree(fd, &ntree->id, ntree);
2033
2170
                }
2034
2171
        }
2035
2172
}
2036
2173
 
 
2174
static void do_versions_socket_default_value(bNodeSocket *sock)
 
2175
{
 
2176
        bNodeSocketValueFloat *valfloat;
 
2177
        bNodeSocketValueVector *valvector;
 
2178
        bNodeSocketValueRGBA *valrgba;
 
2179
        
 
2180
        if (sock->default_value)
 
2181
                return;
 
2182
        
 
2183
        switch (sock->type) {
 
2184
        case SOCK_FLOAT:
 
2185
                valfloat = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueFloat), "default socket value");
 
2186
                valfloat->value = sock->ns.vec[0];
 
2187
                valfloat->min = sock->ns.min;
 
2188
                valfloat->max = sock->ns.max;
 
2189
                valfloat->subtype = PROP_NONE;
 
2190
                break;
 
2191
        case SOCK_VECTOR:
 
2192
                valvector = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueVector), "default socket value");
 
2193
                copy_v3_v3(valvector->value, sock->ns.vec);
 
2194
                valvector->min = sock->ns.min;
 
2195
                valvector->max = sock->ns.max;
 
2196
                valvector->subtype = PROP_NONE;
 
2197
                break;
 
2198
        case SOCK_RGBA:
 
2199
                valrgba = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueRGBA), "default socket value");
 
2200
                copy_v4_v4(valrgba->value, sock->ns.vec);
 
2201
                break;
 
2202
        }
 
2203
}
 
2204
 
 
2205
static void do_versions_nodetree_default_value(bNodeTree *ntree)
 
2206
{
 
2207
        bNode *node;
 
2208
        bNodeSocket *sock;
 
2209
        for (node=ntree->nodes.first; node; node=node->next) {
 
2210
                for (sock=node->inputs.first; sock; sock=sock->next)
 
2211
                        do_versions_socket_default_value(sock);
 
2212
                for (sock=node->outputs.first; sock; sock=sock->next)
 
2213
                        do_versions_socket_default_value(sock);
 
2214
        }
 
2215
        for (sock=ntree->inputs.first; sock; sock=sock->next)
 
2216
                do_versions_socket_default_value(sock);
 
2217
        for (sock=ntree->outputs.first; sock; sock=sock->next)
 
2218
                do_versions_socket_default_value(sock);
 
2219
}
 
2220
 
 
2221
static void lib_nodetree_init_types_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
 
2222
{
 
2223
        bNode *node;
 
2224
        
 
2225
        ntreeInitTypes(ntree);
 
2226
 
 
2227
        /* need to do this here instead of in do_versions, otherwise next function can crash */
 
2228
        do_versions_nodetree_default_value(ntree);
 
2229
        
 
2230
        /* XXX could be replaced by do_versions for new nodes */
 
2231
        for (node=ntree->nodes.first; node; node=node->next)
 
2232
                node_verify_socket_templates(ntree, node);
 
2233
}
 
2234
 
 
2235
/* updates group node socket own_index so that
 
2236
 * external links to/from the group node are preserved.
 
2237
 */
 
2238
static void lib_node_do_versions_group_indices(bNode *gnode)
 
2239
{
 
2240
        bNodeTree *ngroup= (bNodeTree*)gnode->id;
 
2241
        bNode *intnode;
 
2242
        bNodeSocket *sock, *gsock, *intsock;
 
2243
        int found;
 
2244
        
 
2245
        for (sock=gnode->outputs.first; sock; sock=sock->next) {
 
2246
                int old_index = sock->to_index;
 
2247
                for (gsock=ngroup->outputs.first; gsock; gsock=gsock->next) {
 
2248
                        if (gsock->link && gsock->link->fromsock->own_index == old_index) {
 
2249
                                sock->own_index = gsock->own_index;
 
2250
                                break;
 
2251
                        }
 
2252
                }
 
2253
        }
 
2254
        for (sock=gnode->inputs.first; sock; sock=sock->next) {
 
2255
                int old_index = sock->to_index;
 
2256
                /* can't use break in double loop */
 
2257
                found = 0;
 
2258
                for (intnode=ngroup->nodes.first; intnode && !found; intnode=intnode->next) {
 
2259
                        for (intsock=intnode->inputs.first; intsock; intsock=intsock->next) {
 
2260
                                if (intsock->own_index == old_index && intsock->link) {
 
2261
                                        sock->own_index = intsock->link->fromsock->own_index;
 
2262
                                        found = 1;
 
2263
                                        break;
 
2264
                                }
 
2265
                        }
 
2266
                }
 
2267
        }
 
2268
}
 
2269
 
 
2270
/* updates external links for all group nodes in a tree */
 
2271
static void lib_nodetree_do_versions_group_indices_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
 
2272
{
 
2273
        bNode *node;
 
2274
        
 
2275
        for (node=ntree->nodes.first; node; node=node->next) {
 
2276
                if (node->type==NODE_GROUP) {
 
2277
                        bNodeTree *ngroup= (bNodeTree*)node->id;
 
2278
                        if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE))
 
2279
                                lib_node_do_versions_group_indices(node);
 
2280
                }
 
2281
        }
 
2282
}
 
2283
 
 
2284
/* make an update call for the tree */
 
2285
static void lib_nodetree_do_versions_update_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
 
2286
{
 
2287
        if (ntree->update)
 
2288
                ntreeUpdateTree(ntree);
 
2289
}
 
2290
 
2037
2291
/* verify types for nodes and groups, all data has to be read */
2038
2292
/* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic
2039
 
* typedefs*/
2040
 
static void lib_verify_nodetree(Main *main, int open)
 
2293
 * typedefs */
 
2294
static void lib_verify_nodetree(Main *main, int UNUSED(open))
2041
2295
{
2042
 
        Scene *sce;
2043
 
        Material *ma;
2044
 
        Tex *tx;
2045
2296
        bNodeTree *ntree;
2046
 
        
2047
 
        /* this crashes blender on undo/redo
2048
 
                if(open==1) {
 
2297
        int i;
 
2298
        bNodeTreeType *ntreetype;
 
2299
 
 
2300
        /* this crashes blender on undo/redo */
 
2301
#if 0
 
2302
                if (open==1) {
2049
2303
                        reinit_nodesystem();
2050
 
                }*/
2051
 
        
2052
 
        /* now create the own typeinfo structs an verify nodes */
2053
 
        /* here we still assume no groups in groups */
2054
 
        for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
2055
 
                ntreeVerifyTypes(ntree);        /* internal nodes, no groups! */
2056
 
                ntreeMakeOwnType(ntree);        /* for group usage */
2057
 
        }
2058
 
        
2059
 
        /* now verify all types in material trees, groups are set OK now */
2060
 
        for(ma= main->mat.first; ma; ma= ma->id.next) {
2061
 
                if(ma->nodetree)
2062
 
                        ntreeVerifyTypes(ma->nodetree);
2063
 
        }
2064
 
        /* and scene trees */
2065
 
        for(sce= main->scene.first; sce; sce= sce->id.next) {
2066
 
                if(sce->nodetree)
2067
 
                        ntreeVerifyTypes(sce->nodetree);
2068
 
        }
2069
 
        /* and texture trees */
2070
 
        for(tx= main->tex.first; tx; tx= tx->id.next) {
2071
 
                if(tx->nodetree)
2072
 
                        ntreeVerifyTypes(tx->nodetree);
2073
 
        }
2074
 
}
2075
 
 
2076
 
 
 
2304
                }
 
2305
#endif
 
2306
        
 
2307
        /* set node->typeinfo pointers */
 
2308
        for (i=0; i < NUM_NTREE_TYPES; ++i) {
 
2309
                ntreetype= ntreeGetType(i);
 
2310
                if (ntreetype && ntreetype->foreach_nodetree)
 
2311
                        ntreetype->foreach_nodetree(main, NULL, lib_nodetree_init_types_cb);
 
2312
        }
 
2313
        for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
 
2314
                lib_nodetree_init_types_cb(NULL, NULL, ntree);
 
2315
        
 
2316
        {
 
2317
                int has_old_groups=0;
 
2318
                /* XXX this should actually be part of do_versions, but since we need
 
2319
                 * finished library linking, it is not possible there. Instead in do_versions
 
2320
                 * we have set the NTREE_DO_VERSIONS flag, so at this point we can do the
 
2321
                 * actual group node updates.
 
2322
                 */
 
2323
                for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
 
2324
                        if (ntree->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE) {
 
2325
                                /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
 
2326
                                node_group_expose_all_sockets(ntree);
 
2327
                                has_old_groups = 1;
 
2328
                        }
 
2329
                }
 
2330
                
 
2331
                if (has_old_groups) {
 
2332
                        for (i=0; i < NUM_NTREE_TYPES; ++i) {
 
2333
                                ntreetype= ntreeGetType(i);
 
2334
                                if (ntreetype && ntreetype->foreach_nodetree)
 
2335
                                        ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_group_indices_cb);
 
2336
                        }
 
2337
                }
 
2338
                
 
2339
                for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
 
2340
                        ntree->flag &= ~NTREE_DO_VERSIONS_GROUP_EXPOSE;
 
2341
        }
 
2342
        
 
2343
        /* verify all group user nodes */
 
2344
        for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
 
2345
                ntreeVerifyNodes(main, &ntree->id);
 
2346
        }
 
2347
        
 
2348
        /* make update calls where necessary */
 
2349
        {
 
2350
                for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
 
2351
                        if (ntree->update)
 
2352
                                ntreeUpdateTree(ntree);
 
2353
 
 
2354
                for (i=0; i < NUM_NTREE_TYPES; ++i) {
 
2355
                        ntreetype= ntreeGetType(i);
 
2356
                        if (ntreetype && ntreetype->foreach_nodetree)
 
2357
                                ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_update_cb);
 
2358
                }
 
2359
        }
 
2360
}
 
2361
 
 
2362
static void direct_link_node_socket(FileData *fd, bNodeSocket *sock)
 
2363
{
 
2364
        sock->link= newdataadr(fd, sock->link);
 
2365
        sock->storage= newdataadr(fd, sock->storage);
 
2366
        sock->default_value= newdataadr(fd, sock->default_value);
 
2367
        sock->cache= NULL;
 
2368
}
2077
2369
 
2078
2370
/* ntree itself has been read! */
2079
2371
static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
2084
2376
        bNodeLink *link;
2085
2377
        
2086
2378
        ntree->init= 0;         /* to set callbacks and force setting types */
2087
 
        ntree->owntype= NULL;
2088
2379
        ntree->progress= NULL;
 
2380
        ntree->execdata= NULL;
2089
2381
        
2090
2382
        ntree->adt= newdataadr(fd, ntree->adt);
2091
2383
        direct_link_animdata(fd, ntree->adt);
2092
2384
        
2093
2385
        link_list(fd, &ntree->nodes);
2094
 
        for(node= ntree->nodes.first; node; node= node->next) {
2095
 
                if(node->type == NODE_DYNAMIC) {
 
2386
        for (node= ntree->nodes.first; node; node= node->next) {
 
2387
                if (node->type == NODE_DYNAMIC) {
2096
2388
                        node->custom1= 0;
2097
2389
                        node->custom1= BSET(node->custom1, NODE_DYNAMIC_LOADED);
2098
 
                        node->typeinfo= NULL;
2099
2390
                }
 
2391
 
 
2392
                node->typeinfo= NULL;
2100
2393
                
2101
 
                node->storage= newdataadr(fd, node->storage);
2102
 
                if(node->storage) {
2103
 
                        
2104
 
                        /* could be handlerized at some point */
2105
 
                        if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
2106
 
                                direct_link_curvemapping(fd, node->storage);
2107
 
                        else if(ntree->type==NTREE_COMPOSIT) {
2108
 
                                if( ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT))
2109
 
                                        direct_link_curvemapping(fd, node->storage);
2110
 
                                else if(ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
2111
 
                                        ((ImageUser *)node->storage)->ok= 1;
2112
 
                        }
2113
 
                        else if( ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) ) {
2114
 
                                direct_link_curvemapping(fd, node->storage);
2115
 
                        }
2116
 
                }
2117
2394
                link_list(fd, &node->inputs);
2118
2395
                link_list(fd, &node->outputs);
 
2396
                
 
2397
                if (node->type == CMP_NODE_MOVIEDISTORTION) {
 
2398
                        node->storage= newmclipadr(fd, node->storage);
 
2399
                }
 
2400
                else
 
2401
                        node->storage= newdataadr(fd, node->storage);
 
2402
 
 
2403
                if (node->storage) {
 
2404
                        /* could be handlerized at some point */
 
2405
                        if (ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
 
2406
                                direct_link_curvemapping(fd, node->storage);
 
2407
                        else if (ntree->type==NTREE_COMPOSIT) {
 
2408
                                if ( ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT))
 
2409
                                        direct_link_curvemapping(fd, node->storage);
 
2410
                                else if (ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
 
2411
                                        ((ImageUser *)node->storage)->ok= 1;
 
2412
                        }
 
2413
                        else if ( ntree->type==NTREE_TEXTURE) {
 
2414
                                if (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME)
 
2415
                                        direct_link_curvemapping(fd, node->storage);
 
2416
                                else if (node->type==TEX_NODE_IMAGE)
 
2417
                                        ((ImageUser *)node->storage)->ok= 1;
 
2418
                        }
 
2419
                }
2119
2420
        }
2120
2421
        link_list(fd, &ntree->links);
2121
2422
        
 
2423
        /* external sockets */
 
2424
        link_list(fd, &ntree->inputs);
 
2425
        link_list(fd, &ntree->outputs);
 
2426
        
2122
2427
        /* and we connect the rest */
2123
 
        for(node= ntree->nodes.first; node; node= node->next) {
 
2428
        for (node= ntree->nodes.first; node; node= node->next) {
 
2429
                node->parent = newdataadr(fd, node->parent);
2124
2430
                node->preview= newimaadr(fd, node->preview);
2125
2431
                node->lasty= 0;
2126
 
                for(sock= node->inputs.first; sock; sock= sock->next)
2127
 
                        sock->link= newdataadr(fd, sock->link);
2128
 
                for(sock= node->outputs.first; sock; sock= sock->next)
2129
 
                        sock->ns.data= NULL;
 
2432
                
 
2433
                for (sock= node->inputs.first; sock; sock= sock->next)
 
2434
                        direct_link_node_socket(fd, sock);
 
2435
                for (sock= node->outputs.first; sock; sock= sock->next)
 
2436
                        direct_link_node_socket(fd, sock);
2130
2437
        }
2131
 
        for(link= ntree->links.first; link; link= link->next) {
 
2438
        for (sock= ntree->inputs.first; sock; sock= sock->next)
 
2439
                direct_link_node_socket(fd, sock);
 
2440
        for (sock= ntree->outputs.first; sock; sock= sock->next)
 
2441
                direct_link_node_socket(fd, sock);
 
2442
        
 
2443
        for (link= ntree->links.first; link; link= link->next) {
2132
2444
                link->fromnode= newdataadr(fd, link->fromnode);
2133
2445
                link->tonode= newdataadr(fd, link->tonode);
2134
2446
                link->fromsock= newdataadr(fd, link->fromsock);
2135
2447
                link->tosock= newdataadr(fd, link->tosock);
2136
2448
        }
2137
 
                
 
2449
        
2138
2450
        /* type verification is in lib-link */
2139
2451
}
2140
2452
 
2146
2458
        ID *id;
2147
2459
} tConstraintLinkData;
2148
2460
/* callback function used to relink constraint ID-links */
2149
 
static void lib_link_constraint_cb(bConstraint *con, ID **idpoin, void *userdata)
 
2461
static void lib_link_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, short isReference, void *userdata)
2150
2462
{
2151
2463
        tConstraintLinkData *cld= (tConstraintLinkData *)userdata;
2152
 
        *idpoin = newlibadr(cld->fd, cld->id->lib, *idpoin);
 
2464
        
 
2465
        /* for reference types, we need to increment the usercounts on load... */
 
2466
        if (isReference) {
 
2467
                /* reference type - with usercount */
 
2468
                *idpoin = newlibadr_us(cld->fd, cld->id->lib, *idpoin);
 
2469
        }
 
2470
        else {
 
2471
                /* target type - no usercount needed */
 
2472
                *idpoin = newlibadr(cld->fd, cld->id->lib, *idpoin);
 
2473
        }
2153
2474
}
2154
2475
 
2155
2476
static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist)
2161
2482
        for (con = conlist->first; con; con=con->next) {
2162
2483
                /* patch for error introduced by changing constraints (dunno how) */
2163
2484
                /* if con->data type changes, dna cannot resolve the pointer! (ton) */
2164
 
                if(con->data==NULL) {
 
2485
                if (con->data==NULL) {
2165
2486
                        con->type= CONSTRAINT_TYPE_NULL;
2166
2487
                }
2167
2488
                /* own ipo, all constraints have it */
2207
2528
                                con->lin_error = 0.f;
2208
2529
                                con->rot_error = 0.f;
2209
2530
                        }
 
2531
                        case CONSTRAINT_TYPE_CHILDOF:
 
2532
                        {
 
2533
                                /* XXX version patch, in older code this flag wasn't always set, and is inherent to type */
 
2534
                                if (con->ownspace == CONSTRAINT_SPACE_POSE)
 
2535
                                        con->flag |= CONSTRAINT_SPACEONCE;
 
2536
                        }
2210
2537
                                break;
2211
2538
                }
2212
2539
        }
2221
2548
        if (!pose || !arm)
2222
2549
                return;
2223
2550
        
 
2551
 
2224
2552
        /* always rebuild to match proxy or lib changes */
2225
2553
        rebuild= ob->proxy || (ob->id.lib==NULL && arm->id.lib);
2226
2554
 
2227
 
        if (ob->proxy && pose->proxy_act_bone[0]) {
2228
 
                Bone *bone = get_named_bone(arm, pose->proxy_act_bone);
2229
 
                if (bone)
2230
 
                        arm->act_bone = bone;
 
2555
        if (ob->proxy) {
 
2556
                /* sync proxy layer */
 
2557
                if (pose->proxy_layer)
 
2558
                        arm->layer = pose->proxy_layer;
 
2559
                
 
2560
                /* sync proxy active bone */
 
2561
                if (pose->proxy_act_bone[0]) {
 
2562
                        Bone *bone = get_named_bone(arm, pose->proxy_act_bone);
 
2563
                        if (bone)
 
2564
                                arm->act_bone = bone;
 
2565
                }
2231
2566
        }
2232
2567
 
2233
2568
        for (pchan = pose->chanbase.first; pchan; pchan=pchan->next) {
2236
2571
                /* hurms... loop in a loop, but yah... later... (ton) */
2237
2572
                pchan->bone= get_named_bone(arm, pchan->name);
2238
2573
                
2239
 
                pchan->custom= newlibadr(fd, arm->id.lib, pchan->custom);
2240
 
                if(pchan->bone==NULL)
 
2574
                pchan->custom= newlibadr_us(fd, arm->id.lib, pchan->custom);
 
2575
                if (pchan->bone==NULL)
2241
2576
                        rebuild= 1;
2242
 
                else if(ob->id.lib==NULL && arm->id.lib) {
 
2577
                else if (ob->id.lib==NULL && arm->id.lib) {
2243
2578
                        /* local pose selection copied to armature, bit hackish */
2244
2579
                        pchan->bone->flag &= ~BONE_SELECTED;
2245
2580
                        pchan->bone->flag |= pchan->selectflag;
2246
2581
                }
2247
2582
        }
2248
2583
        
2249
 
        if(rebuild) {
2250
 
                ob->recalc= OB_RECALC_ALL;
 
2584
        if (rebuild) {
 
2585
                ob->recalc= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
2251
2586
                pose->flag |= POSE_RECALC;
2252
2587
        }
2253
2588
}
2258
2593
 
2259
2594
        arm= main->armature.first;
2260
2595
 
2261
 
        while(arm) {
2262
 
                if(arm->id.flag & LIB_NEEDLINK) {
 
2596
        while (arm) {
 
2597
                if (arm->id.flag & LIB_NEEDLINK) {
2263
2598
                        if (arm->adt) lib_link_animdata(fd, &arm->id, arm->adt);
2264
2599
                        arm->id.flag -= LIB_NEEDLINK;
2265
2600
                }
2273
2608
 
2274
2609
        bone->parent= newdataadr(fd, bone->parent);
2275
2610
        bone->prop= newdataadr(fd, bone->prop);
2276
 
        if(bone->prop)
 
2611
        if (bone->prop)
2277
2612
                IDP_DirectLinkProperty(bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
2278
2613
                
2279
2614
        bone->flag &= ~BONE_DRAW_ACTIVE;
2280
2615
 
2281
2616
        link_list(fd, &bone->childbase);
2282
2617
 
2283
 
        for(child=bone->childbase.first; child; child=child->next)
 
2618
        for (child=bone->childbase.first; child; child=child->next)
2284
2619
                direct_link_bones(fd, child);
2285
2620
}
2286
2621
 
2312
2647
        Camera *ca;
2313
2648
 
2314
2649
        ca= main->camera.first;
2315
 
        while(ca) {
2316
 
                if(ca->id.flag & LIB_NEEDLINK) {
 
2650
        while (ca) {
 
2651
                if (ca->id.flag & LIB_NEEDLINK) {
2317
2652
                        if (ca->adt) lib_link_animdata(fd, &ca->id, ca->adt);
2318
2653
                        
2319
2654
                        ca->ipo= newlibadr_us(fd, ca->id.lib, ca->ipo); // XXX depreceated - old animation system
2342
2677
        int a;
2343
2678
 
2344
2679
        la= main->lamp.first;
2345
 
        while(la) {
2346
 
                if(la->id.flag & LIB_NEEDLINK) {
 
2680
        while (la) {
 
2681
                if (la->id.flag & LIB_NEEDLINK) {
2347
2682
                        if (la->adt) lib_link_animdata(fd, &la->id, la->adt);
2348
2683
                        
2349
 
                        for(a=0; a<MAX_MTEX; a++) {
 
2684
                        for (a=0; a<MAX_MTEX; a++) {
2350
2685
                                mtex= la->mtex[a];
2351
 
                                if(mtex) {
 
2686
                                if (mtex) {
2352
2687
                                        mtex->tex= newlibadr_us(fd, la->id.lib, mtex->tex);
2353
2688
                                        mtex->object= newlibadr(fd, la->id.lib, mtex->object);
2354
2689
                                }
2355
2690
                        }
2356
2691
                        
2357
2692
                        la->ipo= newlibadr_us(fd, la->id.lib, la->ipo); // XXX depreceated - old animation system
 
2693
 
 
2694
                        if (la->nodetree)
 
2695
                                lib_link_ntree(fd, &la->id, la->nodetree);
2358
2696
                        
2359
2697
                        la->id.flag -= LIB_NEEDLINK;
2360
2698
                }
2369
2707
        la->adt= newdataadr(fd, la->adt);
2370
2708
        direct_link_animdata(fd, la->adt);
2371
2709
 
2372
 
        for(a=0; a<MAX_MTEX; a++) {
 
2710
        for (a=0; a<MAX_MTEX; a++) {
2373
2711
                la->mtex[a]= newdataadr(fd, la->mtex[a]);
2374
2712
        }
2375
2713
        
2376
2714
        la->curfalloff= newdataadr(fd, la->curfalloff);
2377
 
        if(la->curfalloff)
 
2715
        if (la->curfalloff)
2378
2716
                direct_link_curvemapping(fd, la->curfalloff);
 
2717
 
 
2718
        la->nodetree= newdataadr(fd, la->nodetree);
 
2719
        if (la->nodetree)
 
2720
                direct_link_nodetree(fd, la->nodetree);
2379
2721
        
2380
2722
        la->preview = direct_link_preview_image(fd, la->preview);
2381
2723
}
2387
2729
        Key *key;
2388
2730
 
2389
2731
        key= main->key.first;
2390
 
        while(key) {
2391
 
                if(key->id.flag & LIB_NEEDLINK) {
2392
 
                        if(key->adt) lib_link_animdata(fd, &key->id, key->adt);
 
2732
        while (key) {
 
2733
                /*check if we need to generate unique ids for the shapekeys*/
 
2734
                if (!key->uidgen) {
 
2735
                        KeyBlock *block;
 
2736
 
 
2737
                        key->uidgen = 1;
 
2738
                        for (block=key->block.first; block; block=block->next) {
 
2739
                                block->uid = key->uidgen++;
 
2740
                        }
 
2741
                }
 
2742
 
 
2743
                if (key->id.flag & LIB_NEEDLINK) {
 
2744
                        if (key->adt) lib_link_animdata(fd, &key->id, key->adt);
2393
2745
                        
2394
2746
                        key->ipo= newlibadr_us(fd, key->id.lib, key->ipo); // XXX depreceated - old animation system
2395
2747
                        key->from= newlibadr(fd, key->id.lib, key->from);
2408
2760
        elemsize= key->elemsize;
2409
2761
        data= kb->data;
2410
2762
 
2411
 
        for(a=0; a<kb->totelem; a++) {
 
2763
        for (a=0; a<kb->totelem; a++) {
2412
2764
 
2413
2765
                cp= key->elemstr;
2414
2766
                poin= data;
2415
2767
 
2416
 
                while( cp[0] ) {        /* cp[0]==amount */
 
2768
                while ( cp[0] ) {       /* cp[0]==amount */
2417
2769
 
2418
2770
                        switch(cp[1]) {         /* cp[1]= type */
2419
2771
                        case IPO_FLOAT:
2420
2772
                        case IPO_BPOINT:
2421
2773
                        case IPO_BEZTRIPLE:
2422
2774
                                b= cp[0];
2423
 
                                while(b--) {
 
2775
                                while (b--) {
2424
2776
                                        SWITCH_INT((*poin));
2425
2777
                                        poin+= 4;
2426
2778
                                }
2446
2798
        key->refkey= newdataadr(fd, key->refkey);
2447
2799
 
2448
2800
        kb= key->block.first;
2449
 
        while(kb) {
 
2801
        while (kb) {
2450
2802
 
2451
2803
                kb->data= newdataadr(fd, kb->data);
2452
 
 
2453
 
                if(fd->flags & FD_FLAGS_SWITCH_ENDIAN)
 
2804
                
 
2805
                if (fd->flags & FD_FLAGS_SWITCH_ENDIAN)
2454
2806
                        switch_endian_keyblock(key, kb);
2455
2807
 
2456
2808
                kb= kb->next;
2465
2817
        int a;
2466
2818
 
2467
2819
        mb= main->mball.first;
2468
 
        while(mb) {
2469
 
                if(mb->id.flag & LIB_NEEDLINK) {
 
2820
        while (mb) {
 
2821
                if (mb->id.flag & LIB_NEEDLINK) {
2470
2822
                        if (mb->adt) lib_link_animdata(fd, &mb->id, mb->adt);
2471
2823
                        
2472
 
                        for(a=0; a<mb->totcol; a++) mb->mat[a]= newlibadr_us(fd, mb->id.lib, mb->mat[a]);
 
2824
                        for (a=0; a<mb->totcol; a++) mb->mat[a]= newlibadr_us(fd, mb->id.lib, mb->mat[a]);
2473
2825
 
2474
2826
                        mb->ipo= newlibadr_us(fd, mb->id.lib, mb->ipo); // XXX depreceated - old animation system
2475
2827
 
2505
2857
        int a;
2506
2858
 
2507
2859
        wrld= main->world.first;
2508
 
        while(wrld) {
2509
 
                if(wrld->id.flag & LIB_NEEDLINK) {
 
2860
        while (wrld) {
 
2861
                if (wrld->id.flag & LIB_NEEDLINK) {
2510
2862
                        if (wrld->adt) lib_link_animdata(fd, &wrld->id, wrld->adt);
2511
2863
                        
2512
2864
                        wrld->ipo= newlibadr_us(fd, wrld->id.lib, wrld->ipo); // XXX depreceated - old animation system
2513
2865
                        
2514
 
                        for(a=0; a<MAX_MTEX; a++) {
 
2866
                        for (a=0; a<MAX_MTEX; a++) {
2515
2867
                                mtex= wrld->mtex[a];
2516
 
                                if(mtex) {
 
2868
                                if (mtex) {
2517
2869
                                        mtex->tex= newlibadr_us(fd, wrld->id.lib, mtex->tex);
2518
2870
                                        mtex->object= newlibadr(fd, wrld->id.lib, mtex->object);
2519
2871
                                }
2520
2872
                        }
 
2873
 
 
2874
                        if (wrld->nodetree)
 
2875
                                lib_link_ntree(fd, &wrld->id, wrld->nodetree);
2521
2876
                        
2522
2877
                        wrld->id.flag -= LIB_NEEDLINK;
2523
2878
                }
2532
2887
        wrld->adt= newdataadr(fd, wrld->adt);
2533
2888
        direct_link_animdata(fd, wrld->adt);
2534
2889
 
2535
 
        for(a=0; a<MAX_MTEX; a++) {
 
2890
        for (a=0; a<MAX_MTEX; a++) {
2536
2891
                wrld->mtex[a]= newdataadr(fd, wrld->mtex[a]);
2537
2892
        }
 
2893
 
 
2894
        wrld->nodetree= newdataadr(fd, wrld->nodetree);
 
2895
        if (wrld->nodetree)
 
2896
                direct_link_nodetree(fd, wrld->nodetree);
 
2897
 
2538
2898
        wrld->preview = direct_link_preview_image(fd, wrld->preview);
2539
2899
}
2540
2900
 
2541
2901
 
2542
2902
/* ************ READ VFONT ***************** */
2543
2903
 
2544
 
static void lib_link_vfont(FileData *fd, Main *main)
 
2904
static void lib_link_vfont(FileData *UNUSED(fd), Main *main)
2545
2905
{
2546
2906
        VFont *vf;
2547
2907
 
2548
2908
        vf= main->vfont.first;
2549
 
        while(vf) {
2550
 
                if(vf->id.flag & LIB_NEEDLINK) {
 
2909
        while (vf) {
 
2910
                if (vf->id.flag & LIB_NEEDLINK) {
2551
2911
                        vf->id.flag -= LIB_NEEDLINK;
2552
2912
                }
2553
2913
                vf= vf->id.next;
2562
2922
 
2563
2923
/* ************ READ TEXT ****************** */
2564
2924
 
2565
 
static void lib_link_text(FileData *fd, Main *main)
 
2925
static void lib_link_text(FileData *UNUSED(fd), Main *main)
2566
2926
{
2567
2927
        Text *text;
2568
2928
 
2569
2929
        text= main->text.first;
2570
 
        while(text) {
2571
 
                if(text->id.flag & LIB_NEEDLINK) {
 
2930
        while (text) {
 
2931
                if (text->id.flag & LIB_NEEDLINK) {
2572
2932
                        text->id.flag -= LIB_NEEDLINK;
2573
2933
                }
2574
2934
                text= text->id.next;
2587
2947
 
2588
2948
        text->compiled= NULL;
2589
2949
 
2590
 
/*
2591
 
        if(text->flags & TXT_ISEXT) {
 
2950
#if 0
 
2951
        if (text->flags & TXT_ISEXT) {
2592
2952
                reopen_text(text);
2593
 
        } else {
2594
 
*/
 
2953
                }
 
2954
                else {
 
2955
#endif
2595
2956
 
2596
2957
        link_list(fd, &text->lines);
2597
2958
        link_list(fd, &text->markers);
2600
2961
        text->sell= newdataadr(fd, text->sell);
2601
2962
 
2602
2963
        ln= text->lines.first;
2603
 
        while(ln) {
 
2964
        while (ln) {
2604
2965
                ln->line= newdataadr(fd, ln->line);
2605
2966
                ln->format= NULL;
2606
2967
                
2625
2986
 
2626
2987
        ima= main->image.first;
2627
2988
        while (ima) {
2628
 
                if(ima->id.flag & LIB_NEEDLINK) {
 
2989
                if (ima->id.flag & LIB_NEEDLINK) {
2629
2990
                        if (ima->id.properties) IDP_LibLinkProperty(ima->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
2630
2991
 
2631
2992
                        ima->id.flag -= LIB_NEEDLINK;
2638
2999
{
2639
3000
        Link *ln, *prev;
2640
3001
        
2641
 
        if(lb->first==NULL) return;
 
3002
        if (lb->first==NULL) return;
2642
3003
        
2643
3004
        lb->first= newimaadr(fd, lb->first);
2644
3005
        ln= lb->first;
2645
3006
        prev= NULL;
2646
 
        while(ln) {
 
3007
        while (ln) {
2647
3008
                ln->next= newimaadr(fd, ln->next);
2648
3009
                ln->prev= prev;
2649
3010
                prev= ln;
2655
3016
static void direct_link_image(FileData *fd, Image *ima)
2656
3017
{
2657
3018
        /* for undo system, pointers could be restored */
2658
 
        if(fd->imamap)
 
3019
        if (fd->imamap)
2659
3020
                link_ibuf_list(fd, &ima->ibufs);
2660
3021
        else
2661
3022
                ima->ibufs.first= ima->ibufs.last= NULL;
2662
3023
        
2663
3024
        /* if not restored, we keep the binded opengl index */
2664
 
        if(ima->ibufs.first==NULL) {
 
3025
        if (ima->ibufs.first==NULL) {
2665
3026
                ima->bindcode= 0;
2666
3027
                ima->gputexture= NULL;
2667
3028
        }
2669
3030
        ima->anim= NULL;
2670
3031
        ima->rr= NULL;
2671
3032
        ima->repbind= NULL;
2672
 
        memset(ima->renders, 0, sizeof(ima->renders));
2673
 
        ima->last_render_slot= ima->render_slot;
 
3033
        
 
3034
        /* undo system, try to restore render buffers */
 
3035
        if (fd->imamap) {
 
3036
                int a;
 
3037
                
 
3038
                for (a=0; a<IMA_MAX_RENDER_SLOT; a++)
 
3039
                        ima->renders[a]= newimaadr(fd, ima->renders[a]);
 
3040
        }
 
3041
        else {
 
3042
                memset(ima->renders, 0, sizeof(ima->renders));
 
3043
                ima->last_render_slot= ima->render_slot;
 
3044
        }
2674
3045
        
2675
3046
        ima->packedfile = direct_link_packedfile(fd, ima->packedfile);
2676
3047
        ima->preview = direct_link_preview_image(fd, ima->preview);
2686
3057
        int a;
2687
3058
 
2688
3059
        cu= main->curve.first;
2689
 
        while(cu) {
2690
 
                if(cu->id.flag & LIB_NEEDLINK) {
2691
 
                        if(cu->adt) lib_link_animdata(fd, &cu->id, cu->adt);
 
3060
        while (cu) {
 
3061
                if (cu->id.flag & LIB_NEEDLINK) {
 
3062
                        if (cu->adt) lib_link_animdata(fd, &cu->id, cu->adt);
2692
3063
 
2693
 
                        for(a=0; a<cu->totcol; a++) cu->mat[a]= newlibadr_us(fd, cu->id.lib, cu->mat[a]);
 
3064
                        for (a=0; a<cu->totcol; a++) cu->mat[a]= newlibadr_us(fd, cu->id.lib, cu->mat[a]);
2694
3065
 
2695
3066
                        cu->bevobj= newlibadr(fd, cu->id.lib, cu->bevobj);
2696
3067
                        cu->taperobj= newlibadr(fd, cu->id.lib, cu->taperobj);
2714
3085
{
2715
3086
        int len;
2716
3087
 
2717
 
        if(nu->knotsu) {
 
3088
        if (nu->knotsu) {
2718
3089
                len= KNOTSU(nu);
2719
 
                while(len--) {
 
3090
                while (len--) {
2720
3091
                        SWITCH_INT(nu->knotsu[len]);
2721
3092
                }
2722
3093
        }
2723
 
        if(nu->knotsv) {
 
3094
        if (nu->knotsv) {
2724
3095
                len= KNOTSV(nu);
2725
 
                while(len--) {
 
3096
                while (len--) {
2726
3097
                        SWITCH_INT(nu->knotsv[len]);
2727
3098
                }
2728
3099
        }
2742
3113
        cu->strinfo= newdataadr(fd, cu->strinfo);       
2743
3114
        cu->tb= newdataadr(fd, cu->tb);
2744
3115
 
2745
 
        if(cu->vfont==0) link_list(fd, &(cu->nurb));
 
3116
        if (cu->vfont == NULL) link_list(fd, &(cu->nurb));
2746
3117
        else {
2747
 
                cu->nurb.first=cu->nurb.last= 0;
 
3118
                cu->nurb.first=cu->nurb.last= NULL;
2748
3119
 
2749
3120
                tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "TextBoxread");
2750
3121
                if (cu->tb) {
2751
3122
                        memcpy(tb, cu->tb, cu->totbox*sizeof(TextBox));
2752
3123
                        MEM_freeN(cu->tb);
2753
3124
                        cu->tb= tb;                     
2754
 
                } else {
 
3125
                }
 
3126
                else {
2755
3127
                        cu->totbox = 1;
2756
3128
                        cu->actbox = 1;
2757
3129
                        cu->tb = tb;
2758
3130
                        cu->tb[0].w = cu->linewidth;
2759
3131
                }               
2760
 
                if (cu->wordspace == 0.0) cu->wordspace = 1.0;
 
3132
                if (cu->wordspace == 0.0f) cu->wordspace = 1.0f;
2761
3133
        }
2762
3134
 
2763
3135
        cu->bev.first=cu->bev.last= NULL;
2768
3140
        cu->editfont= NULL;
2769
3141
        
2770
3142
        nu= cu->nurb.first;
2771
 
        while(nu) {
 
3143
        while (nu) {
2772
3144
                nu->bezt= newdataadr(fd, nu->bezt);
2773
3145
                nu->bp= newdataadr(fd, nu->bp);
2774
3146
                nu->knotsu= newdataadr(fd, nu->knotsu);
2775
3147
                nu->knotsv= newdataadr(fd, nu->knotsv);
2776
 
                if (cu->vfont==0) nu->charidx= nu->mat_nr;
 
3148
                if (cu->vfont == NULL) nu->charidx= nu->mat_nr;
2777
3149
 
2778
 
                if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
 
3150
                if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
2779
3151
                        switch_endian_knots(nu);
2780
3152
                }
2781
3153
 
2791
3163
        Tex *tex;
2792
3164
 
2793
3165
        tex= main->tex.first;
2794
 
        while(tex) {
2795
 
                if(tex->id.flag & LIB_NEEDLINK) {
2796
 
                        if(tex->adt) lib_link_animdata(fd, &tex->id, tex->adt);
 
3166
        while (tex) {
 
3167
                if (tex->id.flag & LIB_NEEDLINK) {
 
3168
                        if (tex->adt) lib_link_animdata(fd, &tex->id, tex->adt);
2797
3169
 
2798
3170
                        tex->ima= newlibadr_us(fd, tex->id.lib, tex->ima);
2799
3171
                        tex->ipo= newlibadr_us(fd, tex->id.lib, tex->ipo);
2800
 
                        if(tex->env) tex->env->object= newlibadr(fd, tex->id.lib, tex->env->object);
2801
 
                        if(tex->pd)
 
3172
                        if (tex->env) tex->env->object= newlibadr(fd, tex->id.lib, tex->env->object);
 
3173
                        if (tex->pd)
2802
3174
                                tex->pd->object= newlibadr(fd, tex->id.lib, tex->pd->object);
2803
 
                        if(tex->vd) tex->vd->object= newlibadr(fd, tex->id.lib, tex->vd->object);
 
3175
                        if (tex->vd) tex->vd->object= newlibadr(fd, tex->id.lib, tex->vd->object);
 
3176
                        if (tex->ot) tex->ot->object= newlibadr(fd, tex->id.lib, tex->ot->object);
 
3177
                                
2804
3178
 
2805
 
                        if(tex->nodetree)
 
3179
                        if (tex->nodetree)
2806
3180
                                lib_link_ntree(fd, &tex->id, tex->nodetree);
2807
3181
                        
2808
3182
                        tex->id.flag -= LIB_NEEDLINK;
2817
3191
        direct_link_animdata(fd, tex->adt);
2818
3192
        
2819
3193
        tex->plugin= newdataadr(fd, tex->plugin);
2820
 
        if(tex->plugin) {
2821
 
                tex->plugin->handle= 0;
 
3194
        if (tex->plugin) {
 
3195
                tex->plugin->handle= NULL;
2822
3196
                open_plugin_tex(tex->plugin);
2823
3197
                /* initialize data for this instance, if an initialization
2824
3198
                 * function exists.
2828
3202
        }
2829
3203
        tex->coba= newdataadr(fd, tex->coba);
2830
3204
        tex->env= newdataadr(fd, tex->env);
2831
 
        if(tex->env) {
 
3205
        if (tex->env) {
2832
3206
                tex->env->ima= NULL;
2833
3207
                memset(tex->env->cube, 0, 6*sizeof(void *));
2834
3208
                tex->env->ok= 0;
2835
3209
        }
2836
3210
        tex->pd= newdataadr(fd, tex->pd);
2837
 
        if(tex->pd) {
 
3211
        if (tex->pd) {
2838
3212
                tex->pd->point_tree = NULL;
2839
3213
                tex->pd->coba= newdataadr(fd, tex->pd->coba);
 
3214
                tex->pd->falloff_curve= newdataadr(fd, tex->pd->falloff_curve);
 
3215
                if (tex->pd->falloff_curve) {
 
3216
                        direct_link_curvemapping(fd, tex->pd->falloff_curve);
 
3217
                }
2840
3218
        }
2841
3219
        
2842
3220
        tex->vd= newdataadr(fd, tex->vd);
2843
 
        if(tex->vd) {
 
3221
        if (tex->vd) {
2844
3222
                tex->vd->dataset = NULL;
2845
3223
                tex->vd->ok = 0;
2846
3224
        }
 
3225
        else {
 
3226
                if (tex->type == TEX_VOXELDATA)
 
3227
                        tex->vd= MEM_callocN(sizeof(VoxelData), "direct_link_texture VoxelData");
 
3228
        }
 
3229
        
 
3230
        tex->ot= newdataadr(fd, tex->ot);
2847
3231
        
2848
3232
        tex->nodetree= newdataadr(fd, tex->nodetree);
2849
 
        if(tex->nodetree)
 
3233
        if (tex->nodetree)
2850
3234
                direct_link_nodetree(fd, tex->nodetree);
2851
3235
        
2852
3236
        tex->preview = direct_link_preview_image(fd, tex->preview);
2865
3249
        int a;
2866
3250
 
2867
3251
        ma= main->mat.first;
2868
 
        while(ma) {
2869
 
                if(ma->id.flag & LIB_NEEDLINK) {
2870
 
                        if(ma->adt) lib_link_animdata(fd, &ma->id, ma->adt);
 
3252
        while (ma) {
 
3253
                if (ma->id.flag & LIB_NEEDLINK) {
 
3254
                        if (ma->adt) lib_link_animdata(fd, &ma->id, ma->adt);
2871
3255
 
2872
 
                        /*Link ID Properties -- and copy this comment EXACTLY for easy finding
2873
 
                        of library blocks that implement this.*/
 
3256
                        /* Link ID Properties -- and copy this comment EXACTLY for easy finding
 
3257
                         * of library blocks that implement this.*/
2874
3258
                        if (ma->id.properties) IDP_LibLinkProperty(ma->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
2875
3259
 
2876
3260
                        ma->ipo= newlibadr_us(fd, ma->id.lib, ma->ipo);
2877
3261
                        ma->group= newlibadr_us(fd, ma->id.lib, ma->group);
2878
3262
                        
2879
 
                        for(a=0; a<MAX_MTEX; a++) {
 
3263
                        for (a=0; a<MAX_MTEX; a++) {
2880
3264
                                mtex= ma->mtex[a];
2881
 
                                if(mtex) {
 
3265
                                if (mtex) {
2882
3266
                                        mtex->tex= newlibadr_us(fd, ma->id.lib, mtex->tex);
2883
3267
                                        mtex->object= newlibadr(fd, ma->id.lib, mtex->object);
2884
3268
                                }
2885
3269
                        }
2886
3270
                        
2887
 
                        if(ma->nodetree)
 
3271
                        if (ma->nodetree)
2888
3272
                                lib_link_ntree(fd, &ma->id, ma->nodetree);
2889
3273
                        
2890
3274
                        ma->id.flag -= LIB_NEEDLINK;
2900
3284
        ma->adt= newdataadr(fd, ma->adt);
2901
3285
        direct_link_animdata(fd, ma->adt);
2902
3286
        
2903
 
        for(a=0; a<MAX_MTEX; a++) {
 
3287
        for (a=0; a<MAX_MTEX; a++) {
2904
3288
                ma->mtex[a]= newdataadr(fd, ma->mtex[a]);
2905
3289
        }
2906
3290
 
2908
3292
        ma->ramp_spec= newdataadr(fd, ma->ramp_spec);
2909
3293
        
2910
3294
        ma->nodetree= newdataadr(fd, ma->nodetree);
2911
 
        if(ma->nodetree)
 
3295
        if (ma->nodetree)
2912
3296
                direct_link_nodetree(fd, ma->nodetree);
2913
3297
 
2914
3298
        ma->preview = direct_link_preview_image(fd, ma->preview);
2916
3300
}
2917
3301
 
2918
3302
/* ************ READ PARTICLE SETTINGS ***************** */
2919
 
 
 
3303
/* update this also to writefile.c */
 
3304
static const char *ptcache_data_struct[] = {
 
3305
        "", // BPHYS_DATA_INDEX
 
3306
        "", // BPHYS_DATA_LOCATION
 
3307
        "", // BPHYS_DATA_VELOCITY
 
3308
        "", // BPHYS_DATA_ROTATION
 
3309
        "", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */
 
3310
        "", // BPHYS_DATA_SIZE:
 
3311
        "", // BPHYS_DATA_TIMES:        
 
3312
        "BoidData" // case BPHYS_DATA_BOIDS:
 
3313
};
2920
3314
static void direct_link_pointcache(FileData *fd, PointCache *cache)
2921
3315
{
2922
 
        if((cache->flag & PTCACHE_DISK_CACHE)==0) {
 
3316
        if ((cache->flag & PTCACHE_DISK_CACHE)==0) {
2923
3317
                PTCacheMem *pm;
 
3318
                PTCacheExtra *extra;
2924
3319
                int i;
2925
3320
 
2926
3321
                link_list(fd, &cache->mem_cache);
2927
3322
 
2928
3323
                pm = cache->mem_cache.first;
2929
3324
 
2930
 
                for(; pm; pm=pm->next) {
2931
 
                        if(pm->index_array)
2932
 
                                pm->index_array = newdataadr(fd, pm->index_array);
 
3325
                for (; pm; pm=pm->next) {
 
3326
                        for (i=0; i<BPHYS_TOT_DATA; i++) {
 
3327
                                pm->data[i] = newdataadr(fd, pm->data[i]);
 
3328
                                
 
3329
                                /* the cache saves non-struct data without DNA */
 
3330
                                if (pm->data[i] && ptcache_data_struct[i][0]=='\0' && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) {
 
3331
                                        int j, tot= (BKE_ptcache_data_size (i) * pm->totpoint)/4; /* data_size returns bytes */
 
3332
                                        int *poin= pm->data[i];
 
3333
                                        
 
3334
                                        for (j= 0; j<tot; j++)
 
3335
                                                SWITCH_INT(poin[j]);
 
3336
                                }
 
3337
                        }
2933
3338
                        
2934
 
                        for(i=0; i<BPHYS_TOT_DATA; i++) {
2935
 
                                if(pm->data[i] && pm->data_types & (1<<i))
2936
 
                                        pm->data[i] = newdataadr(fd, pm->data[i]);
2937
 
                        }
 
3339
                        link_list(fd, &pm->extradata);
 
3340
 
 
3341
                        for (extra=pm->extradata.first; extra; extra=extra->next)
 
3342
                                extra->data = newdataadr(fd, extra->data);
2938
3343
                }
2939
3344
        }
2940
3345
        else
2944
3349
        cache->simframe= 0;
2945
3350
        cache->edit= NULL;
2946
3351
        cache->free_edit= NULL;
 
3352
        cache->cached_frames= NULL;
2947
3353
}
2948
3354
 
2949
 
static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointCache **ocache)
 
3355
static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointCache **ocache, int force_disk)
2950
3356
{
2951
 
        PointCache *cache;
2952
 
 
2953
 
        if(ptcaches->first) {
 
3357
        if (ptcaches->first) {
 
3358
                PointCache *cache= NULL;
2954
3359
                link_list(fd, ptcaches);
2955
 
                for(cache=ptcaches->first; cache; cache=cache->next)
 
3360
                for (cache=ptcaches->first; cache; cache=cache->next) {
2956
3361
                        direct_link_pointcache(fd, cache);
 
3362
                        if (force_disk) {
 
3363
                                cache->flag |= PTCACHE_DISK_CACHE;
 
3364
                                cache->step = 1;
 
3365
                        }
 
3366
                }
2957
3367
 
2958
3368
                *ocache = newdataadr(fd, *ocache);
2959
3369
        }
2960
 
        else if(*ocache) {
 
3370
        else if (*ocache) {
2961
3371
                /* old "single" caches need to be linked too */
2962
3372
                *ocache = newdataadr(fd, *ocache);
2963
3373
                direct_link_pointcache(fd, *ocache);
 
3374
                if (force_disk) {
 
3375
                        (*ocache)->flag |= PTCACHE_DISK_CACHE;
 
3376
                        (*ocache)->step = 1;
 
3377
                }
2964
3378
 
2965
3379
                ptcaches->first = ptcaches->last = *ocache;
2966
3380
        }
2967
3381
}
2968
3382
 
2969
 
void lib_link_partdeflect(FileData *fd, ID *id, PartDeflect *pd)
 
3383
static void lib_link_partdeflect(FileData *fd, ID *id, PartDeflect *pd)
2970
3384
{
2971
 
        if(pd && pd->tex)
 
3385
        if (pd && pd->tex)
2972
3386
                pd->tex=newlibadr_us(fd, id->lib, pd->tex);
2973
3387
}
2974
3388
 
2976
3390
{
2977
3391
        ParticleSettings *part;
2978
3392
        ParticleDupliWeight *dw;
 
3393
        MTex *mtex;
 
3394
        int a;
2979
3395
 
2980
3396
        part= main->particle.first;
2981
 
        while(part) {
2982
 
                if(part->id.flag & LIB_NEEDLINK) {
 
3397
        while (part) {
 
3398
                if (part->id.flag & LIB_NEEDLINK) {
2983
3399
                        if (part->adt) lib_link_animdata(fd, &part->id, part->adt);
2984
3400
                        part->ipo= newlibadr_us(fd, part->id.lib, part->ipo); // XXX depreceated - old animation system
2985
3401
                        
2991
3407
                        lib_link_partdeflect(fd, &part->id, part->pd);
2992
3408
                        lib_link_partdeflect(fd, &part->id, part->pd2);
2993
3409
 
2994
 
                        if(part->effector_weights)
 
3410
                        if (part->effector_weights)
2995
3411
                                part->effector_weights->group = newlibadr(fd, part->id.lib, part->effector_weights->group);
2996
3412
 
2997
 
                        dw = part->dupliweights.first;
2998
 
                        for(; dw; dw=dw->next)
2999
 
                                dw->ob = newlibadr(fd, part->id.lib, dw->ob);
3000
 
 
3001
 
                        if(part->boids) {
 
3413
                        if (part->dupliweights.first && part->dup_group) {
 
3414
                                int index_ok = 0;
 
3415
                                /* check for old files without indices (all indexes 0) */
 
3416
                                dw = part->dupliweights.first;
 
3417
                                if (part->dupliweights.first == part->dupliweights.last) {
 
3418
                                        /* special case for only one object in the group */
 
3419
                                        index_ok = 1;
 
3420
                                }
 
3421
                                else { 
 
3422
                                        for (; dw; dw=dw->next) {
 
3423
                                                if (dw->index > 0) {
 
3424
                                                        index_ok = 1;
 
3425
                                                        break;
 
3426
                                                }
 
3427
                                        }
 
3428
                                }
 
3429
 
 
3430
                                if (index_ok) {
 
3431
                                        /* if we have indexes, let's use them */
 
3432
                                        dw = part->dupliweights.first;
 
3433
                                        for (; dw; dw=dw->next) {
 
3434
                                                GroupObject *go = (GroupObject *)BLI_findlink(&part->dup_group->gobject, dw->index);
 
3435
                                                dw->ob = go ? go->ob : NULL;
 
3436
                                        }
 
3437
                                }
 
3438
                                else {
 
3439
                                        /* otherwise try to get objects from own library (won't work on library linked groups) */
 
3440
                                        for (; dw; dw=dw->next)
 
3441
                                                dw->ob = newlibadr(fd, part->id.lib, dw->ob);
 
3442
                                }
 
3443
                        }
 
3444
                        else {
 
3445
                                part->dupliweights.first = part->dupliweights.last = NULL;
 
3446
                        }
 
3447
 
 
3448
                        if (part->boids) {
3002
3449
                                BoidState *state = part->boids->states.first;
3003
3450
                                BoidRule *rule;
3004
 
                                for(; state; state=state->next) {
 
3451
                                for (; state; state=state->next) {
3005
3452
                                        rule = state->rules.first;
3006
 
                                for(; rule; rule=rule->next)
 
3453
                                for (; rule; rule=rule->next)
3007
3454
                                        switch(rule->type) {
3008
3455
                                                case eBoidRuleType_Goal:
3009
3456
                                                case eBoidRuleType_Avoid:
3021
3468
                                        }
3022
3469
                                }
3023
3470
                        }
 
3471
                        
 
3472
                        for (a=0; a<MAX_MTEX; a++) {
 
3473
                                mtex= part->mtex[a];
 
3474
                                if (mtex) {
 
3475
                                        mtex->tex = newlibadr_us(fd, part->id.lib, mtex->tex);
 
3476
                                        mtex->object = newlibadr(fd, part->id.lib, mtex->object);
 
3477
                                }
 
3478
                        }
 
3479
 
3024
3480
                        part->id.flag -= LIB_NEEDLINK;
3025
3481
                }
3026
3482
                part= part->id.next;
3029
3485
 
3030
3486
static void direct_link_partdeflect(PartDeflect *pd)
3031
3487
{
3032
 
        if(pd) pd->rng=NULL;
 
3488
        if (pd) pd->rng=NULL;
3033
3489
}
3034
3490
 
3035
3491
static void direct_link_particlesettings(FileData *fd, ParticleSettings *part)
3036
3492
{
 
3493
        int a;
3037
3494
        part->adt= newdataadr(fd, part->adt);
3038
3495
        part->pd= newdataadr(fd, part->pd);
3039
3496
        part->pd2= newdataadr(fd, part->pd2);
3043
3500
        direct_link_partdeflect(part->pd2);
3044
3501
 
3045
3502
        part->effector_weights = newdataadr(fd, part->effector_weights);
3046
 
        if(!part->effector_weights)
 
3503
        if (!part->effector_weights)
3047
3504
                part->effector_weights = BKE_add_effector_weights(part->eff_group);
3048
3505
 
3049
3506
        link_list(fd, &part->dupliweights);
3051
3508
        part->boids= newdataadr(fd, part->boids);
3052
3509
        part->fluid= newdataadr(fd, part->fluid);
3053
3510
 
3054
 
        if(part->boids) {
 
3511
        if (part->boids) {
3055
3512
                BoidState *state;
3056
3513
                link_list(fd, &part->boids->states);
3057
3514
                
3058
 
                for(state=part->boids->states.first; state; state=state->next) {
 
3515
                for (state=part->boids->states.first; state; state=state->next) {
3059
3516
                        link_list(fd, &state->rules);
3060
3517
                        link_list(fd, &state->conditions);
3061
3518
                        link_list(fd, &state->actions);
3062
3519
                }
3063
3520
        }
 
3521
        for (a=0; a<MAX_MTEX; a++) {
 
3522
                part->mtex[a]= newdataadr(fd, part->mtex[a]);
 
3523
        }
3064
3524
}
3065
3525
 
3066
3526
static void lib_link_particlesystems(FileData *fd, Object *ob, ID *id, ListBase *particles)
3067
3527
{
3068
3528
        ParticleSystem *psys, *psysnext;
3069
3529
 
3070
 
        for(psys=particles->first; psys; psys=psysnext){
 
3530
        for (psys=particles->first; psys; psys=psysnext) {
3071
3531
                psysnext= psys->next;
3072
3532
                
3073
3533
                psys->part = newlibadr_us(fd, id->lib, psys->part);
3074
 
                if(psys->part) {
 
3534
                if (psys->part) {
3075
3535
                        ParticleTarget *pt = psys->targets.first;
3076
3536
 
3077
 
                        for(; pt; pt=pt->next)
 
3537
                        for (; pt; pt=pt->next)
3078
3538
                                pt->ob=newlibadr(fd, id->lib, pt->ob);
3079
3539
 
3080
3540
                        psys->parent= newlibadr_us(fd, id->lib, psys->parent);
3081
3541
                        psys->target_ob = newlibadr(fd, id->lib, psys->target_ob);
3082
3542
 
3083
 
                        if(psys->clmd) {
 
3543
                        if (psys->clmd) {
3084
3544
                                /* XXX - from reading existing code this seems correct but intended usage of
3085
3545
                                 * pointcache should /w cloth should be added in 'ParticleSystem' - campbell */
3086
3546
                                psys->clmd->point_cache= psys->pointcache;
3105
3565
        ParticleData *pa;
3106
3566
        int a;
3107
3567
 
3108
 
        for(psys=particles->first; psys; psys=psys->next) {
 
3568
        for (psys=particles->first; psys; psys=psys->next) {
3109
3569
                psys->particles=newdataadr(fd,psys->particles);
3110
3570
                
3111
 
                if(psys->particles && psys->particles->hair){
3112
 
                        for(a=0,pa=psys->particles; a<psys->totpart; a++, pa++)
 
3571
                if (psys->particles && psys->particles->hair) {
 
3572
                        for (a=0,pa=psys->particles; a<psys->totpart; a++, pa++)
3113
3573
                                pa->hair=newdataadr(fd,pa->hair);
3114
3574
                }
3115
3575
                
3116
 
                if(psys->particles && psys->particles->keys){
3117
 
                        for(a=0,pa=psys->particles; a<psys->totpart; a++, pa++) {
 
3576
                if (psys->particles && psys->particles->keys) {
 
3577
                        for (a=0,pa=psys->particles; a<psys->totpart; a++, pa++) {
3118
3578
                                pa->keys= NULL;
3119
3579
                                pa->totkey= 0;
3120
3580
                        }
3122
3582
                        psys->flag &= ~PSYS_KEYED;
3123
3583
                }
3124
3584
 
3125
 
                if(psys->particles && psys->particles->boid) {
 
3585
                if (psys->particles && psys->particles->boid) {
3126
3586
                        pa = psys->particles;
3127
3587
                        pa->boid = newdataadr(fd, pa->boid);
3128
 
                        for(a=1,pa++; a<psys->totpart; a++, pa++)
 
3588
                        for (a=1,pa++; a<psys->totpart; a++, pa++)
3129
3589
                                pa->boid = (pa-1)->boid + 1;
3130
3590
                }
3131
 
                else {
3132
 
                        for(a=0,pa=psys->particles; a<psys->totpart; a++, pa++)
 
3591
                else if (psys->particles) {
 
3592
                        for (a=0,pa=psys->particles; a<psys->totpart; a++, pa++)
3133
3593
                                pa->boid = NULL;
3134
3594
                }
3135
3595
 
 
3596
                psys->fluid_springs = newdataadr(fd, psys->fluid_springs);
3136
3597
 
3137
3598
                psys->child = newdataadr(fd,psys->child);
3138
3599
                psys->effectors = NULL;
3147
3608
                psys->childcachebufs.first = psys->childcachebufs.last = NULL;
3148
3609
                psys->frand = NULL;
3149
3610
                psys->pdd = NULL;
 
3611
                psys->renderdata = NULL;
3150
3612
                
3151
 
                direct_link_pointcache_list(fd, &psys->ptcaches, &psys->pointcache);
 
3613
                direct_link_pointcache_list(fd, &psys->ptcaches, &psys->pointcache, 0);
3152
3614
 
3153
 
                if(psys->clmd) {
 
3615
                if (psys->clmd) {
3154
3616
                        psys->clmd = newdataadr(fd, psys->clmd);
3155
3617
                        psys->clmd->clothObject = NULL;
3156
3618
                        
3157
3619
                        psys->clmd->sim_parms= newdataadr(fd, psys->clmd->sim_parms);
 
3620
                        psys->clmd->sim_parms->effector_weights = NULL;
3158
3621
                        psys->clmd->coll_parms= newdataadr(fd, psys->clmd->coll_parms);
3159
3622
                        
3160
 
                        if(psys->clmd->sim_parms) {
3161
 
                                if(psys->clmd->sim_parms->presets > 10)
 
3623
                        if (psys->clmd->sim_parms) {
 
3624
                                if (psys->clmd->sim_parms->presets > 10)
3162
3625
                                        psys->clmd->sim_parms->presets = 0;
3163
3626
                        }
3164
3627
 
3168
3631
                }
3169
3632
 
3170
3633
                psys->tree = NULL;
 
3634
                psys->bvhtree = NULL;
3171
3635
        }
3172
3636
        return;
3173
3637
}
3179
3643
        MTFace *tf= mtface;
3180
3644
        int i;
3181
3645
 
 
3646
        /* Add pseudo-references (not fake users!) to images used by texface. A
 
3647
         * little bogus; it would be better if each mesh consistently added one ref
 
3648
         * to each image it used. - z0r */
3182
3649
        for (i=0; i<totface; i++, tf++) {
3183
3650
                tf->tpage= newlibadr(fd, me->id.lib, tf->tpage);
3184
 
                if(tf->tpage && tf->tpage->id.us==0)
 
3651
                if (tf->tpage && tf->tpage->id.us==0)
3185
3652
                        tf->tpage->id.us= 1;
3186
3653
        }
3187
3654
}
3189
3656
static void lib_link_customdata_mtface(FileData *fd, Mesh *me, CustomData *fdata, int totface)
3190
3657
{
3191
3658
        int i;  
3192
 
        for(i=0; i<fdata->totlayer; i++) {
 
3659
        for (i=0; i<fdata->totlayer; i++) {
3193
3660
                CustomDataLayer *layer = &fdata->layers[i];
3194
3661
                
3195
 
                if(layer->type == CD_MTFACE)
 
3662
                if (layer->type == CD_MTFACE)
3196
3663
                        lib_link_mtface(fd, me, layer->data, totface);
3197
3664
        }
3198
3665
 
3199
3666
}
3200
3667
 
 
3668
static void lib_link_customdata_mtpoly(FileData *fd, Mesh *me, CustomData *pdata, int totface)
 
3669
{
 
3670
        int i;
 
3671
 
 
3672
        for (i=0; i<pdata->totlayer; i++) {
 
3673
                CustomDataLayer *layer = &pdata->layers[i];
 
3674
                
 
3675
                if (layer->type == CD_MTEXPOLY) {
 
3676
                        MTexPoly *tf= layer->data;
 
3677
                        int i;
 
3678
 
 
3679
                        for (i=0; i<totface; i++, tf++) {
 
3680
                                tf->tpage= newlibadr(fd, me->id.lib, tf->tpage);
 
3681
                                if (tf->tpage && tf->tpage->id.us==0)
 
3682
                                        tf->tpage->id.us= 1;
 
3683
                        }
 
3684
                }
 
3685
        }
 
3686
}
 
3687
 
3201
3688
static void lib_link_mesh(FileData *fd, Main *main)
3202
3689
{
3203
3690
        Mesh *me;
3204
3691
 
3205
3692
        me= main->mesh.first;
3206
 
        while(me) {
3207
 
                if(me->id.flag & LIB_NEEDLINK) {
 
3693
        while (me) {
 
3694
                if (me->id.flag & LIB_NEEDLINK) {
3208
3695
                        int i;
3209
3696
 
3210
 
                        /*Link ID Properties -- and copy this comment EXACTLY for easy finding
3211
 
                        of library blocks that implement this.*/
 
3697
                        /* Link ID Properties -- and copy this comment EXACTLY for easy finding
 
3698
                         * of library blocks that implement this.*/
3212
3699
                        if (me->id.properties) IDP_LibLinkProperty(me->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
3213
3700
                        if (me->adt) lib_link_animdata(fd, &me->id, me->adt);
3214
3701
 
3215
3702
                        /* this check added for python created meshes */
3216
 
                        if(me->mat) {
3217
 
                                for(i=0; i<me->totcol; i++) {
 
3703
                        if (me->mat) {
 
3704
                                for (i=0; i<me->totcol; i++) {
3218
3705
                                        me->mat[i]= newlibadr_us(fd, me->id.lib, me->mat[i]);
3219
3706
                                }
3220
3707
                        }
3225
3712
                        me->texcomesh= newlibadr_us(fd, me->id.lib, me->texcomesh);
3226
3713
 
3227
3714
                        lib_link_customdata_mtface(fd, me, &me->fdata, me->totface);
3228
 
                        if(me->mr && me->mr->levels.first)
 
3715
                        lib_link_customdata_mtpoly(fd, me, &me->pdata, me->totpoly);
 
3716
                        if (me->mr && me->mr->levels.first)
3229
3717
                                lib_link_customdata_mtface(fd, me, &me->mr->fdata,
3230
3718
                                                           ((MultiresLevel*)me->mr->levels.first)->totface);
3231
3719
 
 
3720
                        /*check if we need to convert mfaces to mpolys*/
 
3721
                        if (me->totface && !me->totpoly) {
 
3722
                                /* temporarily switch main so that reading from
 
3723
                                 * external CustomData works */
 
3724
                                Main *gmain = G.main;
 
3725
                                G.main = main;
 
3726
                                
 
3727
                                BKE_mesh_convert_mfaces_to_mpolys(me);
 
3728
 
 
3729
                                G.main = gmain;
 
3730
                        }
 
3731
                        
 
3732
                        /*
 
3733
                         * Re-tessellate, even if the polys were just created from tessfaces, this
 
3734
                         * is important because it:
 
3735
                         *  - fill the CD_POLYINDEX layer
 
3736
                         *  - gives consistency of tessface between loading from a file and
 
3737
                         *    converting an edited BMesh back into a mesh (i.e. it replaces
 
3738
                         *    quad tessfaces in a loaded mesh immediately, instead of lazily
 
3739
                         *    waiting until edit mode has been entered/exited, making it easier
 
3740
                         *    to recognize problems that would otherwise only show up after edits).
 
3741
                         */
 
3742
#ifdef USE_TESSFACE_DEFAULT
 
3743
                        BKE_mesh_tessface_calc(me);
 
3744
#else
 
3745
                        BKE_mesh_tessface_clear(me);
 
3746
#endif
 
3747
 
3232
3748
                        me->id.flag -= LIB_NEEDLINK;
3233
3749
                }
3234
3750
                me= me->id.next;
3235
3751
        }
 
3752
 
 
3753
        /* convert texface options to material */
 
3754
        convert_tface_mt(fd, main);
3236
3755
}
3237
3756
 
3238
3757
static void direct_link_dverts(FileData *fd, int count, MDeformVert *mdverts)
3239
3758
{
3240
 
        int     i;
 
3759
        int i;
3241
3760
 
3242
 
        if (!mdverts)
 
3761
        if (mdverts == NULL) {
3243
3762
                return;
 
3763
        }
3244
3764
 
3245
 
        for (i=0; i<count; i++) {
3246
 
                mdverts[i].dw=newdataadr(fd, mdverts[i].dw);
3247
 
                if (!mdverts[i].dw)
3248
 
                        mdverts[i].totweight=0;
 
3765
        for (i= count; i > 0; i--, mdverts++) {
 
3766
                /*convert to vgroup allocation system*/
 
3767
                MDeformWeight *dw;
 
3768
                if (mdverts->dw && (dw= newdataadr(fd, mdverts->dw))) {
 
3769
                        const ssize_t dw_len= mdverts->totweight * sizeof(MDeformWeight);
 
3770
                        void *dw_tmp= MEM_mallocN(dw_len, "direct_link_dverts");
 
3771
                        memcpy(dw_tmp, dw, dw_len);
 
3772
                        mdverts->dw= dw_tmp;
 
3773
                        MEM_freeN(dw);
 
3774
                }
 
3775
                else {
 
3776
                        mdverts->dw= NULL;
 
3777
                        mdverts->totweight= 0;
 
3778
                }
3249
3779
        }
3250
3780
}
3251
3781
 
3252
3782
static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int external)
3253
3783
{
3254
 
        if(mdisps) {
 
3784
        if (mdisps) {
3255
3785
                int i;
3256
3786
 
3257
 
                for(i = 0; i < count; ++i) {
 
3787
                for (i = 0; i < count; ++i) {
3258
3788
                        mdisps[i].disps = newdataadr(fd, mdisps[i].disps);
3259
 
                        if(!external && !mdisps[i].disps)
 
3789
                        mdisps[i].hidden = newdataadr(fd, mdisps[i].hidden);
 
3790
 
 
3791
                        if (mdisps[i].totdisp && !mdisps[i].level) {
 
3792
                                /* this calculation is only correct for loop mdisps;
 
3793
                                 * if loading pre-BMesh face mdisps this will be
 
3794
                                 * overwritten with the correct value in
 
3795
                                 * bm_corners_to_loops() */
 
3796
                                float gridsize = sqrtf(mdisps[i].totdisp);
 
3797
                                mdisps[i].level = (int)(logf(gridsize - 1.0f) / M_LN2) + 1;
 
3798
                        }
 
3799
 
 
3800
                        if ( (fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps) ) {
 
3801
                                /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */
 
3802
                                /* this does swap for data written at write_mdisps() - readfile.c */
 
3803
                                int x;
 
3804
                                float *tmpdisps= *mdisps[i].disps;
 
3805
                                for (x=0;x<mdisps[i].totdisp*3;x++) {
 
3806
                                        SWITCH_INT(*tmpdisps);
 
3807
                                        tmpdisps++;
 
3808
                                }
 
3809
                        }
 
3810
                        if (!external && !mdisps[i].disps)
3260
3811
                                mdisps[i].totdisp = 0;
3261
3812
                }
3262
 
        }       
 
3813
        }
3263
3814
}
3264
3815
 
 
3816
/*this isn't really a public api function, so prototyped here*/
3265
3817
static void direct_link_customdata(FileData *fd, CustomData *data, int count)
3266
3818
{
3267
3819
        int i = 0;
3268
3820
 
3269
3821
        data->layers= newdataadr(fd, data->layers);
 
3822
 
 
3823
        /* annoying workaround for bug [#31079] loading legacy files with
 
3824
         * no polygons _but_ have stale customdata */
 
3825
        if (UNLIKELY(count == 0 && data->layers == NULL && data->totlayer != 0)) {
 
3826
                memset(data, 0, sizeof(*data));
 
3827
                return;
 
3828
        }
 
3829
 
3270
3830
        data->external= newdataadr(fd, data->external);
3271
3831
 
3272
3832
        while (i < data->totlayer) {
3273
3833
                CustomDataLayer *layer = &data->layers[i];
3274
3834
 
3275
 
                if(layer->flag & CD_FLAG_EXTERNAL)
 
3835
                if (layer->flag & CD_FLAG_EXTERNAL)
3276
3836
                        layer->flag &= ~CD_FLAG_IN_MEMORY;
3277
3837
 
3278
3838
                if (CustomData_verify_versions(data, i)) {
3279
3839
                        layer->data = newdataadr(fd, layer->data);
3280
 
                        if(layer->type == CD_MDISPS)
 
3840
                        if (layer->type == CD_MDISPS)
3281
3841
                                direct_link_mdisps(fd, count, layer->data, layer->flag & CD_FLAG_EXTERNAL);
3282
3842
                        i++;
3283
3843
                }
3284
3844
        }
 
3845
 
 
3846
        CustomData_update_typemap(data);
3285
3847
}
3286
3848
 
3287
3849
static void direct_link_mesh(FileData *fd, Mesh *mesh)
3292
3854
        mesh->mvert= newdataadr(fd, mesh->mvert);
3293
3855
        mesh->medge= newdataadr(fd, mesh->medge);
3294
3856
        mesh->mface= newdataadr(fd, mesh->mface);
 
3857
        mesh->mloop= newdataadr(fd, mesh->mloop);
 
3858
        mesh->mpoly= newdataadr(fd, mesh->mpoly);
3295
3859
        mesh->tface= newdataadr(fd, mesh->tface);
3296
3860
        mesh->mtface= newdataadr(fd, mesh->mtface);
3297
3861
        mesh->mcol= newdataadr(fd, mesh->mcol);
3298
3862
        mesh->msticky= newdataadr(fd, mesh->msticky);
3299
3863
        mesh->dvert= newdataadr(fd, mesh->dvert);
3300
 
        
 
3864
        mesh->mloopcol= newdataadr(fd, mesh->mloopcol);
 
3865
        mesh->mloopuv= newdataadr(fd, mesh->mloopuv);
 
3866
        mesh->mtpoly= newdataadr(fd, mesh->mtpoly);
 
3867
        mesh->mselect = newdataadr(fd, mesh->mselect);
 
3868
 
 
3869
        /* animdata */
3301
3870
        mesh->adt= newdataadr(fd, mesh->adt);
3302
3871
        direct_link_animdata(fd, mesh->adt);
3303
3872
 
3304
 
        /* Partial-mesh visibility (do this before using totvert, totface, or totedge!) */
3305
 
        mesh->pv= newdataadr(fd, mesh->pv);
3306
 
        if(mesh->pv) {
3307
 
                mesh->pv->vert_map= newdataadr(fd, mesh->pv->vert_map);
3308
 
                mesh->pv->edge_map= newdataadr(fd, mesh->pv->edge_map);
3309
 
                mesh->pv->old_faces= newdataadr(fd, mesh->pv->old_faces);
3310
 
                mesh->pv->old_edges= newdataadr(fd, mesh->pv->old_edges);
3311
 
        }
3312
 
 
3313
3873
        /* normally direct_link_dverts should be called in direct_link_customdata,
3314
 
           but for backwards compat in do_versions to work we do it here */
3315
 
        direct_link_dverts(fd, mesh->pv ? mesh->pv->totvert : mesh->totvert, mesh->dvert);
3316
 
 
3317
 
        direct_link_customdata(fd, &mesh->vdata, mesh->pv ? mesh->pv->totvert : mesh->totvert);
3318
 
        direct_link_customdata(fd, &mesh->edata, mesh->pv ? mesh->pv->totedge : mesh->totedge);
3319
 
        direct_link_customdata(fd, &mesh->fdata, mesh->pv ? mesh->pv->totface : mesh->totface);
 
3874
         * but for backwards compat in do_versions to work we do it here */
 
3875
        direct_link_dverts(fd, mesh->totvert, mesh->dvert);
 
3876
 
 
3877
        direct_link_customdata(fd, &mesh->vdata, mesh->totvert);
 
3878
        direct_link_customdata(fd, &mesh->edata, mesh->totedge);
 
3879
        direct_link_customdata(fd, &mesh->fdata, mesh->totface);
 
3880
        direct_link_customdata(fd, &mesh->ldata, mesh->totloop);
 
3881
        direct_link_customdata(fd, &mesh->pdata, mesh->totpoly);
 
3882
        
 
3883
 
 
3884
#ifdef USE_BMESH_FORWARD_COMPAT
 
3885
        /* NEVER ENABLE THIS CODE INTO BMESH!
 
3886
         * THIS IS FOR LOADING BMESH INTO OLDER FILES ONLY */
 
3887
        mesh->mpoly= newdataadr(fd, mesh->mpoly);
 
3888
        mesh->mloop= newdataadr(fd, mesh->mloop);
 
3889
 
 
3890
        direct_link_customdata(fd, &mesh->pdata, mesh->totpoly);
 
3891
        direct_link_customdata(fd, &mesh->ldata, mesh->totloop);
 
3892
 
 
3893
        if (mesh->mpoly) {
 
3894
                /* be clever and load polygons as mfaces */
 
3895
 
 
3896
                mesh->totface= mesh_mpoly_to_mface(&mesh->fdata, &mesh->ldata, &mesh->pdata,
 
3897
                                                   mesh->totface, mesh->totloop, mesh->totpoly);
 
3898
 
 
3899
                CustomData_free(&mesh->pdata, mesh->totpoly);
 
3900
                memset(&mesh->pdata, 0, sizeof(CustomData));
 
3901
                mesh->totpoly = 0;
 
3902
 
 
3903
                CustomData_free(&mesh->ldata, mesh->totloop);
 
3904
                memset(&mesh->ldata, 0, sizeof(CustomData));
 
3905
                mesh->totloop = 0;
 
3906
 
 
3907
                mesh_update_customdata_pointers(mesh);
 
3908
        }
 
3909
 
 
3910
#endif
 
3911
 
3320
3912
 
3321
3913
        mesh->bb= NULL;
3322
 
        mesh->mselect = NULL;
3323
 
        mesh->edit_mesh= NULL;
 
3914
        mesh->edit_btmesh= NULL;
3324
3915
        
3325
3916
        /* Multires data */
3326
3917
        mesh->mr= newdataadr(fd, mesh->mr);
3327
 
        if(mesh->mr) {
 
3918
        if (mesh->mr) {
3328
3919
                MultiresLevel *lvl;
3329
3920
                
3330
3921
                link_list(fd, &mesh->mr->levels);
3338
3929
                mesh->mr->edge_creases= newdataadr(fd, mesh->mr->edge_creases);
3339
3930
 
3340
3931
                mesh->mr->verts = newdataadr(fd, mesh->mr->verts);
 
3932
                
 
3933
                /* If mesh has the same number of vertices as the
 
3934
                 * highest multires level, load the current mesh verts
 
3935
                 * into multires and discard the old data. Needed
 
3936
                 * because some saved files either do not have a verts
 
3937
                 * array, or the verts array contains out-of-date
 
3938
                 * data. */
 
3939
                if (mesh->totvert == ((MultiresLevel*)mesh->mr->levels.last)->totvert) {
 
3940
                        if (mesh->mr->verts)
 
3941
                                MEM_freeN(mesh->mr->verts);
 
3942
                        mesh->mr->verts = MEM_dupallocN(mesh->mvert);
 
3943
                }
3341
3944
                        
3342
 
                for(; lvl; lvl= lvl->next) {
 
3945
                for (; lvl; lvl= lvl->next) {
3343
3946
                        lvl->verts= newdataadr(fd, lvl->verts);
3344
3947
                        lvl->faces= newdataadr(fd, lvl->faces);
3345
3948
                        lvl->edges= newdataadr(fd, lvl->edges);
3347
3950
                }
3348
3951
        }
3349
3952
 
3350
 
        /* Gracefully handle corrupted mesh */
3351
 
        if(mesh->mr && !mesh->mr->verts) {
3352
 
                /* If totals match, simply load the current mesh verts into multires */
3353
 
                if(mesh->totvert == ((MultiresLevel*)mesh->mr->levels.last)->totvert)
3354
 
                        mesh->mr->verts = MEM_dupallocN(mesh->mvert);
3355
 
                else {
3356
 
                        /* Otherwise, we can't recover the data, silently remove multires */
3357
 
                        multires_free(mesh->mr);
3358
 
                        mesh->mr = NULL;
3359
 
                }
 
3953
        /* if multires is present but has no valid vertex data,
 
3954
         * there's no way to recover it; silently remove multires */
 
3955
        if (mesh->mr && !mesh->mr->verts) {
 
3956
                multires_free(mesh->mr);
 
3957
                mesh->mr = NULL;
3360
3958
        }
3361
3959
        
3362
 
        if((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && mesh->tface) {
 
3960
        if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && mesh->tface) {
3363
3961
                TFace *tf= mesh->tface;
3364
 
                unsigned int i;
 
3962
                int i;
3365
3963
 
3366
 
                for (i=0; i< (mesh->pv ? mesh->pv->totface : mesh->totface); i++, tf++) {
 
3964
                for (i=0; i< (mesh->totface); i++, tf++) {
3367
3965
                        SWITCH_INT(tf->col[0]);
3368
3966
                        SWITCH_INT(tf->col[1]);
3369
3967
                        SWITCH_INT(tf->col[2]);
3379
3977
        Lattice *lt;
3380
3978
        
3381
3979
        lt= main->latt.first;
3382
 
        while(lt) {
3383
 
                if(lt->id.flag & LIB_NEEDLINK) {
 
3980
        while (lt) {
 
3981
                if (lt->id.flag & LIB_NEEDLINK) {
 
3982
                        if (lt->adt) lib_link_animdata(fd, &lt->id, lt->adt);
3384
3983
                        
3385
3984
                        lt->ipo= newlibadr_us(fd, lt->id.lib, lt->ipo); // XXX depreceated - old animation system
3386
3985
                        lt->key= newlibadr_us(fd, lt->id.lib, lt->key);
3399
3998
        direct_link_dverts(fd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert);
3400
3999
        
3401
4000
        lt->editlatt= NULL;
 
4001
        
 
4002
        lt->adt = newdataadr(fd, lt->adt);
 
4003
        direct_link_animdata(fd, lt->adt);
3402
4004
}
3403
4005
 
3404
4006
 
3411
4013
 
3412
4014
        *idpoin = newlibadr(fd, ob->id.lib, *idpoin);
3413
4015
        /* hardcoded bad exception; non-object modifier data gets user count (texture, displace) */
3414
 
        if(*idpoin && GS((*idpoin)->name)!=ID_OB)
 
4016
        if (*idpoin && GS((*idpoin)->name)!=ID_OB)
3415
4017
                (*idpoin)->us++;
3416
4018
}
3417
4019
static void lib_link_modifiers(FileData *fd, Object *ob)
3430
4032
        int warn=0, a;
3431
4033
 
3432
4034
        ob= main->object.first;
3433
 
        while(ob) {
3434
 
                if(ob->id.flag & LIB_NEEDLINK) {
 
4035
        while (ob) {
 
4036
                if (ob->id.flag & LIB_NEEDLINK) {
3435
4037
                        if (ob->id.properties) IDP_LibLinkProperty(ob->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
3436
4038
                        if (ob->adt) lib_link_animdata(fd, &ob->id, ob->adt);
3437
4039
                        
3446
4048
                        ob->dup_group= newlibadr_us(fd, ob->id.lib, ob->dup_group);
3447
4049
                        
3448
4050
                        ob->proxy= newlibadr_us(fd, ob->id.lib, ob->proxy);
3449
 
                        if(ob->proxy) {
 
4051
                        if (ob->proxy) {
3450
4052
                                /* paranoia check, actually a proxy_from pointer should never be written... */
3451
 
                                if(ob->proxy->id.lib==NULL) {
 
4053
                                if (ob->proxy->id.lib==NULL) {
3452
4054
                                        ob->proxy->proxy_from= NULL;
3453
4055
                                        ob->proxy= NULL;
3454
4056
                                        
3461
4063
                                        /* this triggers object_update to always use a copy */
3462
4064
                                        ob->proxy->proxy_from= ob;
3463
4065
                                        /* force proxy updates after load/undo, a bit weak */
3464
 
                                        ob->recalc= ob->proxy->recalc= OB_RECALC_ALL;
 
4066
                                        ob->recalc= ob->proxy->recalc= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
3465
4067
                                }
3466
4068
                        }
3467
4069
                        ob->proxy_group= newlibadr(fd, ob->id.lib, ob->proxy_group);
3468
4070
                        
3469
4071
                        poin= ob->data;
3470
4072
                        ob->data= newlibadr_us(fd, ob->id.lib, ob->data);
3471
 
                           
3472
 
                        if(ob->data==NULL && poin!=NULL) {
3473
 
                                if(ob->id.lib)
 
4073
 
 
4074
                        if (ob->data==NULL && poin!=NULL) {
 
4075
                                if (ob->id.lib)
3474
4076
                                        printf("Can't find obdata of %s lib %s\n", ob->id.name+2, ob->id.lib->name);
3475
4077
                                else
3476
4078
                                        printf("Object %s lost data.\n", ob->id.name+2);
3478
4080
                                ob->type= OB_EMPTY;
3479
4081
                                warn= 1;
3480
4082
 
3481
 
                                if(ob->pose) {
 
4083
                                if (ob->pose) {
3482
4084
                                        free_pose(ob->pose);
3483
4085
                                        ob->pose= NULL;
3484
4086
                                        ob->mode &= ~OB_MODE_POSE;
3485
4087
                                }
3486
4088
                        }
3487
 
                        for(a=0; a<ob->totcol; a++) ob->mat[a]= newlibadr_us(fd, ob->id.lib, ob->mat[a]);
 
4089
                        for (a=0; a<ob->totcol; a++) ob->mat[a]= newlibadr_us(fd, ob->id.lib, ob->mat[a]);
3488
4090
                        
 
4091
                        /* When the object is local and the data is library its possible
 
4092
                         * the material list size gets out of sync. [#22663] */
 
4093
                        if (ob->data && ob->id.lib != ((ID *)ob->data)->lib) {
 
4094
                                short *totcol_data= give_totcolp(ob);
 
4095
                                /* Only expand so as not to loose any object materials that might be set. */
 
4096
                                if (totcol_data && *totcol_data > ob->totcol) {
 
4097
                                        /* printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data); */
 
4098
                                        resize_object_material(ob, *totcol_data);
 
4099
                                }
 
4100
                        }
 
4101
 
3489
4102
                        ob->gpd= newlibadr_us(fd, ob->id.lib, ob->gpd);
3490
4103
                        ob->duplilist= NULL;
3491
 
            
 
4104
 
3492
4105
                        ob->id.flag -= LIB_NEEDLINK;
3493
4106
                        /* if id.us==0 a new base will be created later on */
3494
4107
                        
3501
4114
                        lib_link_nlastrips(fd, &ob->id, &ob->nlastrips);
3502
4115
// >>> XXX depreceated - old animation system
3503
4116
 
3504
 
                        for(paf= ob->effect.first; paf; paf= paf->next) {
3505
 
                                if(paf->type==EFF_PARTICLE) {
 
4117
                        for (paf= ob->effect.first; paf; paf= paf->next) {
 
4118
                                if (paf->type==EFF_PARTICLE) {
3506
4119
                                        paf->group= newlibadr_us(fd, ob->id.lib, paf->group);
3507
4120
                                }
3508
4121
                        }                               
3509
4122
 
3510
4123
                        sens= ob->sensors.first;
3511
 
                        while(sens) {
3512
 
                                for(a=0; a<sens->totlinks; a++)
 
4124
                        while (sens) {
 
4125
                                for (a=0; a<sens->totlinks; a++)
3513
4126
                                        sens->links[a]= newglobadr(fd, sens->links[a]);
3514
4127
 
3515
 
                                if(sens->type==SENS_TOUCH) {
 
4128
                                if (sens->type==SENS_TOUCH) {
3516
4129
                                        bTouchSensor *ts= sens->data;
3517
4130
                                        ts->ma= newlibadr(fd, ob->id.lib, ts->ma);
3518
4131
                                }
3519
 
                                else if(sens->type==SENS_MESSAGE) {
 
4132
                                else if (sens->type==SENS_MESSAGE) {
3520
4133
                                        bMessageSensor *ms= sens->data;
3521
4134
                                        ms->fromObject=
3522
4135
                                                newlibadr(fd, ob->id.lib, ms->fromObject);
3525
4138
                        }
3526
4139
 
3527
4140
                        cont= ob->controllers.first;
3528
 
                        while(cont) {
3529
 
                                for(a=0; a<cont->totlinks; a++)
 
4141
                        while (cont) {
 
4142
                                for (a=0; a<cont->totlinks; a++)
3530
4143
                                        cont->links[a]= newglobadr(fd, cont->links[a]);
3531
4144
 
3532
 
                                if(cont->type==CONT_PYTHON) {
 
4145
                                if (cont->type==CONT_PYTHON) {
3533
4146
                                        bPythonCont *pc= cont->data;
3534
4147
                                        pc->text= newlibadr(fd, ob->id.lib, pc->text);
3535
4148
                                }
3540
4153
                        }
3541
4154
 
3542
4155
                        act= ob->actuators.first;
3543
 
                        while(act) {
3544
 
                                if(act->type==ACT_SOUND) {
 
4156
                        while (act) {
 
4157
                                if (act->type==ACT_SOUND) {
3545
4158
                                        bSoundActuator *sa= act->data;
3546
4159
                                        sa->sound= newlibadr_us(fd, ob->id.lib, sa->sound);
3547
4160
                                }
3548
 
                                else if(act->type==ACT_GAME) {
 
4161
                                else if (act->type==ACT_GAME) {
3549
4162
                                        /* bGameActuator *ga= act->data; */
3550
4163
                                }
3551
 
                                else if(act->type==ACT_CAMERA) {
 
4164
                                else if (act->type==ACT_CAMERA) {
3552
4165
                                        bCameraActuator *ca= act->data;
3553
4166
                                        ca->ob= newlibadr(fd, ob->id.lib, ca->ob);
3554
4167
                                }
3555
4168
                                        /* leave this one, it's obsolete but necessary to read for conversion */
3556
 
                                else if(act->type==ACT_ADD_OBJECT) {
 
4169
                                else if (act->type==ACT_ADD_OBJECT) {
3557
4170
                                        bAddObjectActuator *eoa= act->data;
3558
 
                                        if(eoa) eoa->ob= newlibadr(fd, ob->id.lib, eoa->ob);
 
4171
                                        if (eoa) eoa->ob= newlibadr(fd, ob->id.lib, eoa->ob);
3559
4172
                                }
3560
 
                                else if(act->type==ACT_OBJECT) {
 
4173
                                else if (act->type==ACT_OBJECT) {
3561
4174
                                        bObjectActuator *oa= act->data;
3562
 
                                        oa->reference= newlibadr(fd, ob->id.lib, oa->reference);
 
4175
                                        if (oa==NULL) {
 
4176
                                                init_actuator(act);
 
4177
                                        }
 
4178
                                        else {
 
4179
                                                oa->reference= newlibadr(fd, ob->id.lib, oa->reference);
 
4180
                                        }
3563
4181
                                }
3564
 
                                else if(act->type==ACT_EDIT_OBJECT) {
 
4182
                                else if (act->type==ACT_EDIT_OBJECT) {
3565
4183
                                        bEditObjectActuator *eoa= act->data;
3566
 
                                        if(eoa==NULL) {
 
4184
                                        if (eoa==NULL) {
3567
4185
                                                init_actuator(act);
3568
4186
                                        }
3569
4187
                                        else {
3571
4189
                                                eoa->me= newlibadr(fd, ob->id.lib, eoa->me);
3572
4190
                                        }
3573
4191
                                }
3574
 
                                else if(act->type==ACT_OBJECT) {
3575
 
                                        bObjectActuator *oa= act->data;
3576
 
                                        if(oa==NULL) {
3577
 
                                                init_actuator(act);
3578
 
                                        }
3579
 
                                        else {
3580
 
                                                oa->reference= newlibadr(fd, ob->id.lib, oa->reference);
3581
 
                                        }
3582
 
                                }
3583
 
                                else if(act->type==ACT_SCENE) {
 
4192
                                else if (act->type==ACT_SCENE) {
3584
4193
                                        bSceneActuator *sa= act->data;
3585
4194
                                        sa->camera= newlibadr(fd, ob->id.lib, sa->camera);
3586
4195
                                        sa->scene= newlibadr(fd, ob->id.lib, sa->scene);
3587
4196
                                }
3588
 
                                else if(act->type==ACT_ACTION) {
3589
 
                                        bActionActuator *aa= act->data;
3590
 
                                        aa->act= newlibadr(fd, ob->id.lib, aa->act);
3591
 
                                }
3592
 
                                else if(act->type==ACT_SHAPEACTION) {
3593
 
                                        bActionActuator *aa= act->data;
3594
 
                                        aa->act= newlibadr(fd, ob->id.lib, aa->act);
3595
 
                                }
3596
 
                                else if(act->type==ACT_PROPERTY) {
 
4197
                                else if (act->type==ACT_ACTION) {
 
4198
                                        bActionActuator *aa= act->data;
 
4199
                                        aa->act= newlibadr(fd, ob->id.lib, aa->act);
 
4200
                                }
 
4201
                                else if (act->type==ACT_SHAPEACTION) {
 
4202
                                        bActionActuator *aa= act->data;
 
4203
                                        aa->act= newlibadr(fd, ob->id.lib, aa->act);
 
4204
                                }
 
4205
                                else if (act->type==ACT_PROPERTY) {
3597
4206
                                        bPropertyActuator *pa= act->data;
3598
4207
                                        pa->ob= newlibadr(fd, ob->id.lib, pa->ob);
3599
4208
                                }
3600
 
                                else if(act->type==ACT_MESSAGE) {
 
4209
                                else if (act->type==ACT_MESSAGE) {
3601
4210
                                        bMessageActuator *ma= act->data;
3602
4211
                                        ma->toObject= newlibadr(fd, ob->id.lib, ma->toObject);
3603
4212
                                }
3604
 
                                else if(act->type==ACT_2DFILTER){
 
4213
                                else if (act->type==ACT_2DFILTER) {
3605
4214
                                        bTwoDFilterActuator *_2dfa = act->data; 
3606
4215
                                        _2dfa->text= newlibadr(fd, ob->id.lib, _2dfa->text);
3607
4216
                                }
3608
 
                                else if(act->type==ACT_PARENT) {
 
4217
                                else if (act->type==ACT_PARENT) {
3609
4218
                                        bParentActuator *parenta = act->data; 
3610
4219
                                        parenta->ob = newlibadr(fd, ob->id.lib, parenta->ob);
3611
4220
                                }
3612
 
                                else if(act->type==ACT_STATE) {
 
4221
                                else if (act->type==ACT_STATE) {
3613
4222
                                        /* bStateActuator *statea = act->data; */
3614
4223
                                }
3615
 
                                else if(act->type==ACT_ARMATURE) {
 
4224
                                else if (act->type==ACT_ARMATURE) {
3616
4225
                                        bArmatureActuator *arma= act->data;
3617
4226
                                        arma->target= newlibadr(fd, ob->id.lib, arma->target);
3618
4227
                                        arma->subtarget= newlibadr(fd, ob->id.lib, arma->subtarget);
3619
4228
                                }
 
4229
                                else if (act->type==ACT_STEERING) {
 
4230
                                        bSteeringActuator *steeringa = act->data; 
 
4231
                                        steeringa->target = newlibadr(fd, ob->id.lib, steeringa->target);
 
4232
                                        steeringa->navmesh = newlibadr(fd, ob->id.lib, steeringa->navmesh);
 
4233
                                }
3620
4234
                                act= act->next;
3621
4235
                        }
3622
4236
                        
3623
4237
                        {
3624
4238
                                FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
3625
4239
                                
3626
 
                                if(fluidmd && fluidmd->fss) 
 
4240
                                if (fluidmd && fluidmd->fss)
3627
4241
                                        fluidmd->fss->ipo = newlibadr_us(fd, ob->id.lib, fluidmd->fss->ipo);
3628
4242
                        }
3629
4243
 
3630
4244
                        {
3631
4245
                                SmokeModifierData *smd = (SmokeModifierData *)modifiers_findByType(ob, eModifierType_Smoke);
3632
4246
                                
3633
 
                                if(smd && smd->type == MOD_SMOKE_TYPE_DOMAIN && smd->domain) 
3634
 
                                {
3635
 
                                        smd->domain->coll_group = newlibadr_us(fd, ob->id.lib, smd->domain->coll_group);
3636
 
                                        smd->domain->eff_group = newlibadr_us(fd, ob->id.lib, smd->domain->eff_group);
3637
 
                                        smd->domain->fluid_group = newlibadr_us(fd, ob->id.lib, smd->domain->fluid_group);
3638
 
 
3639
 
                                        smd->domain->effector_weights->group = newlibadr(fd, ob->id.lib, smd->domain->effector_weights->group);
3640
 
                                }
3641
 
                        }
3642
 
 
3643
 
                        {
3644
 
                                ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
3645
 
                                
3646
 
                                if(clmd) 
3647
 
                                {
3648
 
                                        clmd->sim_parms->effector_weights->group = newlibadr(fd, ob->id.lib, clmd->sim_parms->effector_weights->group);
3649
 
                                        clmd->coll_parms->group= newlibadr(fd, ob->id.lib, clmd->coll_parms->group);
3650
 
                                }
3651
 
                        }
3652
 
                        
 
4247
                                if (smd && smd->type == MOD_SMOKE_TYPE_DOMAIN && smd->domain)
 
4248
                                {
 
4249
                                        smd->domain->flags |= MOD_SMOKE_FILE_LOAD; /* flag for refreshing the simulation after loading */
 
4250
                                }
 
4251
                        }
 
4252
 
3653
4253
                        /* texture field */
3654
 
                        if(ob->pd)
 
4254
                        if (ob->pd)
3655
4255
                                lib_link_partdeflect(fd, &ob->id, ob->pd);
3656
4256
 
3657
 
                        if(ob->soft)
 
4257
                        if (ob->soft)
3658
4258
                                ob->soft->effector_weights->group = newlibadr(fd, ob->id.lib, ob->soft->effector_weights->group);
3659
4259
 
3660
4260
                        lib_link_particlesystems(fd, ob, &ob->id, &ob->particlesystem);
3663
4263
                ob= ob->id.next;
3664
4264
        }
3665
4265
 
3666
 
        if(warn)
 
4266
        if (warn) {
3667
4267
                BKE_report(fd->reports, RPT_WARNING, "Warning in console");
 
4268
        }
3668
4269
}
3669
4270
 
3670
4271
 
3697
4298
                        direct_link_motionpath(fd, pchan->mpath);
3698
4299
                
3699
4300
                pchan->iktree.first= pchan->iktree.last= NULL;
3700
 
                pchan->path= NULL;
 
4301
                pchan->siktree.first= pchan->siktree.last= NULL;
 
4302
                
 
4303
                /* in case this value changes in future, clamp else we get undefined behavior */
 
4304
                CLAMP(pchan->rotmode, ROT_MODE_MIN, ROT_MODE_MAX);
3701
4305
        }
3702
4306
        pose->ikdata = NULL;
3703
4307
        if (pose->ikparam != NULL) {
3716
4320
                md->scene = NULL;
3717
4321
                
3718
4322
                /* if modifiers disappear, or for upward compatibility */
3719
 
                if(NULL==modifierType_getInfo(md->type))
 
4323
                if (NULL==modifierType_getInfo(md->type))
3720
4324
                        md->type= eModifierType_None;
3721
4325
                        
3722
4326
                if (md->type==eModifierType_Subsurf) {
3723
4327
                        SubsurfModifierData *smd = (SubsurfModifierData*) md;
3724
4328
 
3725
 
                        smd->emCache = smd->mCache = 0;
 
4329
                        smd->emCache = smd->mCache = NULL;
3726
4330
                }
3727
4331
                else if (md->type==eModifierType_Armature) {
3728
4332
                        ArmatureModifierData *amd = (ArmatureModifierData*) md;
3737
4341
                        clmd->sim_parms= newdataadr(fd, clmd->sim_parms);
3738
4342
                        clmd->coll_parms= newdataadr(fd, clmd->coll_parms);
3739
4343
 
3740
 
                        direct_link_pointcache_list(fd, &clmd->ptcaches, &clmd->point_cache);
 
4344
                        direct_link_pointcache_list(fd, &clmd->ptcaches, &clmd->point_cache, 0);
3741
4345
                        
3742
 
                        if(clmd->sim_parms) {
3743
 
                                if(clmd->sim_parms->presets > 10)
 
4346
                        if (clmd->sim_parms) {
 
4347
                                if (clmd->sim_parms->presets > 10)
3744
4348
                                        clmd->sim_parms->presets = 0;
3745
4349
 
3746
4350
                                clmd->sim_parms->reset = 0;
 
4351
 
 
4352
                                clmd->sim_parms->effector_weights = newdataadr(fd, clmd->sim_parms->effector_weights);
 
4353
 
 
4354
                                if (!clmd->sim_parms->effector_weights) {
 
4355
                                        clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL);
 
4356
                                }
3747
4357
                        }
3748
 
 
3749
 
                        clmd->sim_parms->effector_weights = newdataadr(fd, clmd->sim_parms->effector_weights);
3750
 
                        if(!clmd->sim_parms->effector_weights)
3751
 
                                clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL);
3752
 
                        
3753
4358
                }
3754
4359
                else if (md->type==eModifierType_Fluidsim) {
3755
4360
                        FluidsimModifierData *fluidmd = (FluidsimModifierData*) md;
3756
4361
                        
3757
4362
                        fluidmd->fss= newdataadr(fd, fluidmd->fss);
3758
 
                        fluidmd->fss->fmd= fluidmd;
3759
 
                        fluidmd->fss->meshSurfNormals = 0;
 
4363
                        if (fluidmd->fss) {
 
4364
                                fluidmd->fss->fmd= fluidmd;
 
4365
                                fluidmd->fss->meshVelocities = NULL;
 
4366
                        }
3760
4367
                }
3761
4368
                else if (md->type==eModifierType_Smoke) {
3762
4369
                        SmokeModifierData *smd = (SmokeModifierData*) md;
3763
4370
 
3764
 
                        if(smd->type==MOD_SMOKE_TYPE_DOMAIN)
 
4371
                        if (smd->type==MOD_SMOKE_TYPE_DOMAIN)
3765
4372
                        {
3766
4373
                                smd->flow = NULL;
3767
4374
                                smd->coll = NULL;
3776
4383
                                smd->domain->tex_wt = NULL;
3777
4384
 
3778
4385
                                smd->domain->effector_weights = newdataadr(fd, smd->domain->effector_weights);
3779
 
                                if(!smd->domain->effector_weights)
 
4386
                                if (!smd->domain->effector_weights)
3780
4387
                                        smd->domain->effector_weights = BKE_add_effector_weights(NULL);
3781
4388
 
3782
 
                                direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0]));
3783
 
                                direct_link_pointcache_list(fd, &(smd->domain->ptcaches[1]), &(smd->domain->point_cache[1]));
 
4389
                                direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0]), 1);
 
4390
 
 
4391
                                /* Smoke uses only one cache from now on, so store pointer convert */
 
4392
                                if (smd->domain->ptcaches[1].first || smd->domain->point_cache[1]) {
 
4393
                                        if (smd->domain->point_cache[1]) {
 
4394
                                                PointCache *cache = newdataadr(fd, smd->domain->point_cache[1]);
 
4395
                                                if (cache->flag & PTCACHE_FAKE_SMOKE)
 
4396
                                                        ; /* Smoke was already saved in "new format" and this cache is a fake one. */
 
4397
                                                else
 
4398
                                                        printf("High resolution smoke cache not available due to pointcache update. Please reset the simulation.\n");
 
4399
                                                BKE_ptcache_free(cache);
 
4400
                                        }
 
4401
                                        smd->domain->ptcaches[1].first = NULL;
 
4402
                                        smd->domain->ptcaches[1].last = NULL;
 
4403
                                        smd->domain->point_cache[1] = NULL;
 
4404
                                }
3784
4405
                        }
3785
 
                        else if(smd->type==MOD_SMOKE_TYPE_FLOW)
3786
 
                        {
 
4406
                        else if (smd->type==MOD_SMOKE_TYPE_FLOW) {
3787
4407
                                smd->domain = NULL;
3788
4408
                                smd->coll = NULL;
3789
4409
                                smd->flow = newdataadr(fd, smd->flow);
3790
4410
                                smd->flow->smd = smd;
3791
4411
                                smd->flow->psys = newdataadr(fd, smd->flow->psys);
3792
4412
                        }
3793
 
                        else if(smd->type==MOD_SMOKE_TYPE_COLL)
3794
 
                        {
 
4413
                        else if (smd->type==MOD_SMOKE_TYPE_COLL) {
3795
4414
                                smd->flow = NULL;
3796
4415
                                smd->domain = NULL;
3797
4416
                                smd->coll = newdataadr(fd, smd->coll);
3798
 
                                if(smd->coll)
 
4417
                                if (smd->coll)
3799
4418
                                {
3800
4419
                                        smd->coll->points = NULL;
3801
4420
                                        smd->coll->numpoints = 0;
3805
4424
 
3806
4425
                        }
3807
4426
                }
 
4427
                else if (md->type==eModifierType_DynamicPaint) {
 
4428
                        DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
 
4429
 
 
4430
                        if (pmd->canvas)
 
4431
                        {
 
4432
                                pmd->canvas = newdataadr(fd, pmd->canvas);
 
4433
                                pmd->canvas->pmd = pmd;
 
4434
                                pmd->canvas->dm = NULL;
 
4435
                                pmd->canvas->flags &= ~MOD_DPAINT_BAKING; /* just in case */
 
4436
 
 
4437
                                if (pmd->canvas->surfaces.first) {
 
4438
                                        DynamicPaintSurface *surface;
 
4439
                                        link_list(fd, &pmd->canvas->surfaces);
 
4440
 
 
4441
                                        for (surface=pmd->canvas->surfaces.first; surface; surface=surface->next) {
 
4442
                                                surface->canvas = pmd->canvas;
 
4443
                                                surface->data = NULL;
 
4444
                                                direct_link_pointcache_list(fd, &(surface->ptcaches), &(surface->pointcache), 1);
 
4445
 
 
4446
                                                if (!(surface->effector_weights = newdataadr(fd, surface->effector_weights)))
 
4447
                                                        surface->effector_weights = BKE_add_effector_weights(NULL);
 
4448
                                        }
 
4449
                                }
 
4450
                        }
 
4451
                        if (pmd->brush)
 
4452
                        {
 
4453
                                pmd->brush = newdataadr(fd, pmd->brush);
 
4454
                                pmd->brush->pmd = pmd;
 
4455
                                pmd->brush->psys = newdataadr(fd, pmd->brush->psys);
 
4456
                                pmd->brush->paint_ramp = newdataadr(fd, pmd->brush->paint_ramp);
 
4457
                                pmd->brush->vel_ramp = newdataadr(fd, pmd->brush->vel_ramp);
 
4458
                                pmd->brush->dm = NULL;
 
4459
                        }
 
4460
                }
3808
4461
                else if (md->type==eModifierType_Collision) {
3809
4462
                        
3810
4463
                        CollisionModifierData *collmd = (CollisionModifierData*) md;
3825
4478
                        collmd->current_x = NULL;
3826
4479
                        collmd->current_xnew = NULL;
3827
4480
                        collmd->current_v = NULL;
3828
 
                        collmd->time = -1000;
 
4481
                        collmd->time_x = collmd->time_xnew = -1000;
3829
4482
                        collmd->numverts = 0;
3830
4483
                        collmd->bvhtree = NULL;
3831
4484
                        collmd->mfaces = NULL;
3844
4497
                        HookModifierData *hmd = (HookModifierData*) md;
3845
4498
 
3846
4499
                        hmd->indexar= newdataadr(fd, hmd->indexar);
3847
 
                        if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
 
4500
                        if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
3848
4501
                                int a;
3849
 
                                for(a=0; a<hmd->totindex; a++) {
 
4502
                                for (a=0; a<hmd->totindex; a++) {
3850
4503
                                        SWITCH_INT(hmd->indexar[a]);
3851
4504
                                }
3852
4505
                        }
3853
 
                } else if (md->type==eModifierType_ParticleSystem) {
 
4506
                }
 
4507
                else if (md->type==eModifierType_ParticleSystem) {
3854
4508
                        ParticleSystemModifierData *psmd = (ParticleSystemModifierData*) md;
3855
4509
 
3856
 
                        psmd->dm=0;
3857
 
                        psmd->psys=newdataadr(fd, psmd->psys);
 
4510
                        psmd->dm= NULL;
 
4511
                        psmd->psys= newdataadr(fd, psmd->psys);
3858
4512
                        psmd->flag &= ~eParticleSystemFlag_psys_updated;
3859
 
                } else if (md->type==eModifierType_Explode) {
 
4513
                        psmd->flag |= eParticleSystemFlag_file_loaded;
 
4514
                }
 
4515
                else if (md->type==eModifierType_Explode) {
3860
4516
                        ExplodeModifierData *psmd = (ExplodeModifierData*) md;
3861
4517
 
3862
 
                        psmd->facepa=0;
 
4518
                        psmd->facepa=NULL;
3863
4519
                }
3864
4520
                else if (md->type==eModifierType_MeshDeform) {
3865
4521
                        MeshDeformModifierData *mmd = (MeshDeformModifierData*) md;
3874
4530
                        mmd->bindweights= newdataadr(fd, mmd->bindweights);
3875
4531
                        mmd->bindcos= newdataadr(fd, mmd->bindcos);
3876
4532
 
3877
 
                        if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
 
4533
                        if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
3878
4534
                                int a;
3879
4535
 
3880
 
                                if(mmd->bindoffsets)
3881
 
                                        for(a=0; a<mmd->totvert+1; a++)
3882
 
                                                SWITCH_INT(mmd->bindoffsets[a])
3883
 
                                if(mmd->bindcagecos)
3884
 
                                        for(a=0; a<mmd->totcagevert*3; a++)
3885
 
                                                SWITCH_INT(mmd->bindcagecos[a])
3886
 
                                if(mmd->dynverts)
3887
 
                                        for(a=0; a<mmd->totvert; a++)
3888
 
                                                SWITCH_INT(mmd->dynverts[a])
 
4536
                                if (mmd->bindoffsets)
 
4537
                                        for (a=0; a<mmd->totvert+1; a++)
 
4538
                                                SWITCH_INT(mmd->bindoffsets[a]);
 
4539
                                if (mmd->bindcagecos)
 
4540
                                        for (a=0; a<mmd->totcagevert*3; a++)
 
4541
                                                SWITCH_INT(mmd->bindcagecos[a]);
 
4542
                                if (mmd->dynverts)
 
4543
                                        for (a=0; a<mmd->totvert; a++)
 
4544
                                                SWITCH_INT(mmd->dynverts[a]);
3889
4545
 
3890
 
                                if(mmd->bindweights)
3891
 
                                        for(a=0; a<mmd->totcagevert*mmd->totvert; a++)
3892
 
                                                SWITCH_INT(mmd->bindweights[a])
3893
 
                                if(mmd->bindcos)
3894
 
                                        for(a=0; a<mmd->totcagevert*3; a++)
3895
 
                                                SWITCH_INT(mmd->bindcos[a])
 
4546
                                if (mmd->bindweights)
 
4547
                                        for (a=0; a<mmd->totcagevert*mmd->totvert; a++)
 
4548
                                                SWITCH_INT(mmd->bindweights[a]);
 
4549
                                if (mmd->bindcos)
 
4550
                                        for (a=0; a<mmd->totcagevert*3; a++)
 
4551
                                                SWITCH_INT(mmd->bindcos[a]);
3896
4552
                        }
3897
4553
                }
 
4554
                else if (md->type==eModifierType_Ocean) {
 
4555
                        OceanModifierData *omd = (OceanModifierData*) md;
 
4556
                        omd->oceancache = NULL;
 
4557
                        omd->ocean = NULL;
 
4558
                        omd->refresh = (MOD_OCEAN_REFRESH_ADD|MOD_OCEAN_REFRESH_RESET|MOD_OCEAN_REFRESH_SIM);
 
4559
                }
 
4560
                else if (md->type==eModifierType_Warp) {
 
4561
                        WarpModifierData *tmd = (WarpModifierData *) md;
 
4562
 
 
4563
                        tmd->curfalloff= newdataadr(fd, tmd->curfalloff);
 
4564
                        if (tmd->curfalloff)
 
4565
                                direct_link_curvemapping(fd, tmd->curfalloff);
 
4566
                }
 
4567
                else if (md->type==eModifierType_WeightVGEdit) {
 
4568
                        WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md;
 
4569
 
 
4570
                        wmd->cmap_curve = newdataadr(fd, wmd->cmap_curve);
 
4571
                        if (wmd->cmap_curve)
 
4572
                                direct_link_curvemapping(fd, wmd->cmap_curve);
 
4573
                }
3898
4574
        }
3899
4575
}
3900
4576
 
3905
4581
        bSensor *sens;
3906
4582
        bController *cont;
3907
4583
        bActuator *act;
3908
 
        int a;
3909
4584
        
3910
 
        /* weak weak... this was only meant as draw flag, now is used in give_base too */
 
4585
        /* weak weak... this was only meant as draw flag, now is used in give_base_to_objects too */
3911
4586
        ob->flag &= ~OB_FROMGROUP;
3912
4587
 
3913
4588
        /* loading saved files with editmode enabled works, but for undo we like
3914
 
           to stay in object mode during undo presses so keep editmode disabled */
3915
 
        if(fd->memfile)
 
4589
         * to stay in object mode during undo presses so keep editmode disabled */
 
4590
        if (fd->memfile)
3916
4591
                ob->mode &= ~(OB_MODE_EDIT|OB_MODE_PARTICLE_EDIT);
3917
4592
        
3918
4593
        ob->disp.first=ob->disp.last= NULL;
3942
4617
        
3943
4618
        link_list(fd, &ob->effect);
3944
4619
        paf= ob->effect.first;
3945
 
        while(paf) {
3946
 
                if(paf->type==EFF_PARTICLE) {
 
4620
        while (paf) {
 
4621
                if (paf->type==EFF_PARTICLE) {
3947
4622
                        paf->keys= NULL;
3948
4623
                }
3949
 
                if(paf->type==EFF_WAVE) {
 
4624
                if (paf->type==EFF_WAVE) {
3950
4625
                        WaveEff *wav = (WaveEff*) paf;
3951
4626
                        PartEff *next = paf->next;
3952
4627
                        WaveModifierData *wmd = (WaveModifierData*) modifier_new(eModifierType_Wave);
3970
4645
                        paf = next;
3971
4646
                        continue;
3972
4647
                }
3973
 
                if(paf->type==EFF_BUILD) {
 
4648
                if (paf->type==EFF_BUILD) {
3974
4649
                        BuildEff *baf = (BuildEff*) paf;
3975
4650
                        PartEff *next = paf->next;
3976
4651
                        BuildModifierData *bmd = (BuildModifierData*) modifier_new(eModifierType_Build);
3994
4669
        ob->pd= newdataadr(fd, ob->pd);
3995
4670
        direct_link_partdeflect(ob->pd);
3996
4671
        ob->soft= newdataadr(fd, ob->soft);
3997
 
        if(ob->soft) {
 
4672
        if (ob->soft) {
3998
4673
                SoftBody *sb= ob->soft;         
3999
4674
                
4000
4675
                sb->bpoint= NULL;       // init pointers so it gets rebuilt nicely
4004
4679
                /* still have to be loaded to be compatible with old files */
4005
4680
                sb->keys= newdataadr(fd, sb->keys);
4006
4681
                test_pointer_array(fd, (void **)&sb->keys);
4007
 
                if(sb->keys) {
4008
 
                        for(a=0; a<sb->totkey; a++) {
 
4682
                if (sb->keys) {
 
4683
                        int a;
 
4684
                        for (a=0; a<sb->totkey; a++) {
4009
4685
                                sb->keys[a]= newdataadr(fd, sb->keys[a]);
4010
4686
                        }
4011
4687
                }
4012
4688
 
4013
4689
                sb->effector_weights = newdataadr(fd, sb->effector_weights);
4014
 
                if(!sb->effector_weights)
 
4690
                if (!sb->effector_weights)
4015
4691
                        sb->effector_weights = BKE_add_effector_weights(NULL);
4016
4692
 
4017
 
                direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache);
 
4693
                direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache, 0);
4018
4694
        }
4019
4695
        ob->bsoft= newdataadr(fd, ob->bsoft);
4020
4696
        ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */
4024
4700
        
4025
4701
        link_list(fd, &ob->prop);
4026
4702
        prop= ob->prop.first;
4027
 
        while(prop) {
 
4703
        while (prop) {
4028
4704
                prop->poin= newdataadr(fd, prop->poin);
4029
 
                if(prop->poin==0) prop->poin= &prop->data;
 
4705
                if (prop->poin==NULL) prop->poin= &prop->data;
4030
4706
                prop= prop->next;
4031
4707
        }
4032
4708
 
4033
4709
        link_list(fd, &ob->sensors);
4034
4710
        sens= ob->sensors.first;
4035
 
        while(sens) {
 
4711
        while (sens) {
4036
4712
                sens->data= newdataadr(fd, sens->data);
4037
4713
                sens->links= newdataadr(fd, sens->links);
4038
4714
                test_pointer_array(fd, (void **)&sens->links);
4045
4721
        if (ob->init_state) {
4046
4722
                /* if a known first state is specified, set it so that the game will start ok */
4047
4723
                ob->state = ob->init_state;
4048
 
        } else if (!ob->state) {
 
4724
        }
 
4725
        else if (!ob->state) {
4049
4726
                ob->state = 1;
4050
4727
        }
4051
4728
        cont= ob->controllers.first;
4052
 
        while(cont) {
 
4729
        while (cont) {
4053
4730
                cont->data= newdataadr(fd, cont->data);
4054
4731
                cont->links= newdataadr(fd, cont->links);
4055
4732
                test_pointer_array(fd, (void **)&cont->links);
4060
4737
 
4061
4738
        link_glob_list(fd, &ob->actuators);
4062
4739
        act= ob->actuators.first;
4063
 
        while(act) {
 
4740
        while (act) {
4064
4741
                act->data= newdataadr(fd, act->data);
4065
4742
                act= act->next;
4066
4743
        }
4071
4748
                HookModifierData *hmd = (HookModifierData*) modifier_new(eModifierType_Hook);
4072
4749
 
4073
4750
                hook->indexar= newdataadr(fd, hook->indexar);
4074
 
                if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
 
4751
                if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
4075
4752
                        int a;
4076
 
                        for(a=0; a<hook->totindex; a++) {
 
4753
                        for (a=0; a<hook->totindex; a++) {
4077
4754
                                SWITCH_INT(hook->indexar[a]);
4078
4755
                        }
4079
4756
                }
4080
4757
 
4081
4758
                        /* Do conversion here because if we have loaded
4082
4759
                         * a hook we need to make sure it gets converted
4083
 
                         * and free'd, regardless of version.
 
4760
                         * and freed, regardless of version.
4084
4761
                         */
4085
 
                VECCOPY(hmd->cent, hook->cent);
 
4762
                copy_v3_v3(hmd->cent, hook->cent);
4086
4763
                hmd->falloff = hook->falloff;
4087
4764
                hmd->force = hook->force;
4088
4765
                hmd->indexar = hook->indexar;
4098
4775
                MEM_freeN(hook);
4099
4776
        }
4100
4777
        
 
4778
        ob->customdata_mask= 0;
4101
4779
        ob->bb= NULL;
4102
4780
        ob->derivedDeform= NULL;
4103
4781
        ob->derivedFinal= NULL;
4104
4782
        ob->gpulamp.first= ob->gpulamp.last= NULL;
4105
4783
        link_list(fd, &ob->pc_ids);
4106
4784
 
4107
 
        if(ob->sculpt)
 
4785
        /* in case this value changes in future, clamp else we get undefined behavior */
 
4786
        CLAMP(ob->rotmode, ROT_MODE_MIN, ROT_MODE_MAX);
 
4787
 
 
4788
        if (ob->sculpt) {
4108
4789
                ob->sculpt= MEM_callocN(sizeof(SculptSession), "reload sculpt session");
 
4790
        }
4109
4791
}
4110
4792
 
4111
4793
/* ************ READ SCENE ***************** */
4115
4797
{
4116
4798
        bNode *node;
4117
4799
        
4118
 
        for(node= ntree->nodes.first; node; node= node->next)
4119
 
                if(node->id==NULL && ELEM4(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS, CMP_NODE_OUTPUT_FILE))
 
4800
        for (node= ntree->nodes.first; node; node= node->next)
 
4801
                if (node->id==NULL && ELEM4(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS, CMP_NODE_OUTPUT_FILE))
4120
4802
                        node->id= &scene->id;
4121
4803
}
4122
4804
 
4123
4805
static void link_paint(FileData *fd, Scene *sce, Paint *p)
4124
4806
{
4125
 
        if(p && p->brushes) {
4126
 
                int i;
4127
 
                for(i = 0; i < p->brush_count; ++i)
4128
 
                        p->brushes[i]= newlibadr_us(fd, sce->id.lib, p->brushes[i]);
 
4807
        if (p) {
 
4808
                p->brush= newlibadr_us(fd, sce->id.lib, p->brush);
 
4809
                p->paint_cursor= NULL;
4129
4810
        }
4130
4811
}
4131
4812
 
4138
4819
        TimeMarker *marker;
4139
4820
        
4140
4821
        sce= main->scene.first;
4141
 
        while(sce) {
4142
 
                if(sce->id.flag & LIB_NEEDLINK) {
4143
 
                        /*Link ID Properties -- and copy this comment EXACTLY for easy finding
4144
 
                        of library blocks that implement this.*/
 
4822
        while (sce) {
 
4823
                if (sce->id.flag & LIB_NEEDLINK) {
 
4824
                        /* Link ID Properties -- and copy this comment EXACTLY for easy finding
 
4825
                         * of library blocks that implement this.*/
4145
4826
                        if (sce->id.properties) IDP_LibLinkProperty(sce->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
4146
4827
                        if (sce->adt) lib_link_animdata(fd, &sce->id, sce->adt);
4147
4828
                        
4150
4831
                        sce->camera= newlibadr(fd, sce->id.lib, sce->camera);
4151
4832
                        sce->world= newlibadr_us(fd, sce->id.lib, sce->world);
4152
4833
                        sce->set= newlibadr(fd, sce->id.lib, sce->set);
4153
 
                        sce->ima= newlibadr_us(fd, sce->id.lib, sce->ima);
4154
4834
                        sce->gpd= newlibadr_us(fd, sce->id.lib, sce->gpd);
4155
4835
                        
4156
4836
                        link_paint(fd, sce, &sce->toolsettings->sculpt->paint);
4157
4837
                        link_paint(fd, sce, &sce->toolsettings->vpaint->paint);
4158
4838
                        link_paint(fd, sce, &sce->toolsettings->wpaint->paint);
4159
4839
                        link_paint(fd, sce, &sce->toolsettings->imapaint.paint);
4160
 
 
 
4840
                        link_paint(fd, sce, &sce->toolsettings->uvsculpt->paint);
4161
4841
                        sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
4162
4842
 
4163
 
                        for(base= sce->base.first; base; base= next) {
 
4843
                        for (base= sce->base.first; base; base= next) {
4164
4844
                                next= base->next;
4165
4845
 
4166
4846
                                /* base->object= newlibadr_us(fd, sce->id.lib, base->object); */
4167
4847
                                base->object= newlibadr_us(fd, sce->id.lib, base->object);
4168
4848
                                
4169
 
                                if(base->object==NULL) {
4170
 
                                        BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: Object lost from scene:'%s\'\n", sce->id.name+2);
4171
 
                                        if(G.background==0) printf("LIB ERROR: base removed from scene:'%s\'\n", sce->id.name+2);
 
4849
                                if (base->object==NULL) {
 
4850
                                        BKE_reportf_wrap(fd->reports, RPT_ERROR,
 
4851
                                                         "LIB ERROR: Object lost from scene:'%s\'\n",
 
4852
                                                         sce->id.name+2);
4172
4853
                                        BLI_remlink(&sce->base, base);
4173
 
                                        if(base==sce->basact) sce->basact= 0;
 
4854
                                        if (base==sce->basact) sce->basact= NULL;
4174
4855
                                        MEM_freeN(base);
4175
4856
                                }
4176
4857
                        }
4177
4858
 
4178
4859
                        SEQ_BEGIN(sce->ed, seq) {
4179
 
                                if(seq->ipo) seq->ipo= newlibadr_us(fd, sce->id.lib, seq->ipo);
4180
 
                                if(seq->scene) {
 
4860
                                if (seq->ipo) seq->ipo= newlibadr_us(fd, sce->id.lib, seq->ipo);
 
4861
                                seq->scene_sound = NULL;
 
4862
                                if (seq->scene) {
4181
4863
                                        seq->scene= newlibadr(fd, sce->id.lib, seq->scene);
4182
 
                                        seq->scene_sound = sound_scene_add_scene_sound(sce, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
4183
 
                                }
4184
 
                                if(seq->scene_camera) seq->scene_camera= newlibadr(fd, sce->id.lib, seq->scene_camera);
4185
 
                                if(seq->sound) {
 
4864
                                        if (seq->scene) {
 
4865
                                                seq->scene_sound = sound_scene_add_scene_sound_defaults(sce, seq);
 
4866
                                        }
 
4867
                                }
 
4868
                                if (seq->clip) {
 
4869
                                        seq->clip = newlibadr(fd, sce->id.lib, seq->clip);
 
4870
                                        seq->clip->id.us++;
 
4871
                                }
 
4872
                                if (seq->scene_camera) seq->scene_camera= newlibadr(fd, sce->id.lib, seq->scene_camera);
 
4873
                                if (seq->sound) {
4186
4874
                                        seq->scene_sound = NULL;
4187
 
                                        if(seq->type == SEQ_HD_SOUND)
 
4875
                                        if (seq->type == SEQ_HD_SOUND)
4188
4876
                                                seq->type = SEQ_SOUND;
4189
4877
                                        else
4190
4878
                                                seq->sound= newlibadr(fd, sce->id.lib, seq->sound);
4191
4879
                                        if (seq->sound) {
4192
4880
                                                seq->sound->id.us++;
4193
 
                                                seq->scene_sound = sound_add_scene_sound(sce, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
 
4881
                                                seq->scene_sound = sound_add_scene_sound_defaults(sce, seq);
4194
4882
                                        }
4195
4883
                                }
4196
 
                                seq->anim= 0;
 
4884
                                seq->anim= NULL;
4197
4885
                        }
4198
4886
                        SEQ_END
4199
4887
 
4200
4888
#ifdef DURIAN_CAMERA_SWITCH
4201
 
                        for(marker= sce->markers.first; marker; marker= marker->next) {
4202
 
                                if(marker->camera) {
 
4889
                        for (marker= sce->markers.first; marker; marker= marker->next) {
 
4890
                                if (marker->camera) {
4203
4891
                                        marker->camera= newlibadr(fd, sce->id.lib, marker->camera);
4204
4892
                                }
4205
4893
                        }
 
4894
#else
 
4895
                        (void)marker;
4206
4896
#endif
4207
4897
 
4208
 
                        if(sce->ed)
4209
 
                                seq_update_muting(sce, sce->ed);
 
4898
                        seq_update_muting(sce->ed);
 
4899
                        seq_update_sound_bounds_all(sce);
4210
4900
                        
4211
 
                        if(sce->nodetree) {
 
4901
                        if (sce->nodetree) {
4212
4902
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
4213
4903
                                composite_patch(sce->nodetree, sce);
4214
4904
                        }
4215
4905
                        
4216
 
                        for(srl= sce->r.layers.first; srl; srl= srl->next) {
 
4906
                        for (srl= sce->r.layers.first; srl; srl= srl->next) {
4217
4907
                                srl->mat_override= newlibadr_us(fd, sce->id.lib, srl->mat_override);
4218
4908
                                srl->light_override= newlibadr_us(fd, sce->id.lib, srl->light_override);
4219
4909
                        }
4220
4910
                        /*Game Settings: Dome Warp Text*/
4221
4911
                        sce->gm.dome.warptext= newlibadr(fd, sce->id.lib, sce->gm.dome.warptext);
4222
4912
 
 
4913
                        /* Motion Tracking */
 
4914
                        sce->clip= newlibadr_us(fd, sce->id.lib, sce->clip);
 
4915
 
4223
4916
                        sce->id.flag -= LIB_NEEDLINK;
4224
4917
                }
4225
4918
 
4233
4926
 
4234
4927
        link_list(fd, lb);
4235
4928
 
4236
 
        for(seq=lb->first; seq; seq=seq->next)
4237
 
                if(seq->seqbase.first)
 
4929
        for (seq=lb->first; seq; seq=seq->next)
 
4930
                if (seq->seqbase.first)
4238
4931
                        link_recurs_seq(fd, &seq->seqbase);
4239
4932
}
4240
4933
 
4241
4934
static void direct_link_paint(FileData *fd, Paint **paint)
4242
4935
{
4243
 
        Paint *p;
4244
 
 
4245
 
        p= (*paint)= newdataadr(fd, (*paint));
4246
 
        if(p) {
4247
 
                p->paint_cursor= NULL;
4248
 
                p->brushes= newdataadr(fd, p->brushes);
4249
 
                test_pointer_array(fd, (void**)&p->brushes);
4250
 
        }
 
4936
/* TODO. is this needed */
 
4937
        (*paint)= newdataadr(fd, (*paint));
4251
4938
}
4252
4939
 
4253
4940
static void direct_link_scene(FileData *fd, Scene *sce)
4259
4946
        sce->theDag = NULL;
4260
4947
        sce->dagisvalid = 0;
4261
4948
        sce->obedit= NULL;
4262
 
        sce->stats= 0;
 
4949
        sce->stats= NULL;
4263
4950
        sce->fps_info= NULL;
 
4951
        sce->customdata_mask_modal= 0;
 
4952
        sce->lay_updated = 0;
4264
4953
 
4265
4954
        sound_create_scene(sce);
4266
4955
 
4278
4967
        sce->basact= newdataadr(fd, sce->basact);
4279
4968
        
4280
4969
        sce->toolsettings= newdataadr(fd, sce->toolsettings);
4281
 
        if(sce->toolsettings) {
 
4970
        if (sce->toolsettings) {
4282
4971
                direct_link_paint(fd, (Paint**)&sce->toolsettings->sculpt);
4283
4972
                direct_link_paint(fd, (Paint**)&sce->toolsettings->vpaint);
4284
4973
                direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
4285
 
 
4286
 
                sce->toolsettings->imapaint.paint.brushes= newdataadr(fd, sce->toolsettings->imapaint.paint.brushes);
4287
 
                test_pointer_array(fd, (void**)&sce->toolsettings->imapaint.paint.brushes);
 
4974
                direct_link_paint(fd, (Paint**)&sce->toolsettings->uvsculpt);
4288
4975
 
4289
4976
                sce->toolsettings->imapaint.paintcursor= NULL;
4290
4977
                sce->toolsettings->particle.paintcursor= NULL;
4291
4978
        }
4292
4979
 
4293
 
        if(sce->ed) {
 
4980
        if (sce->ed) {
4294
4981
                ListBase *old_seqbasep= &((Editing *)sce->ed)->seqbase;
4295
4982
                
4296
4983
                ed= sce->ed= newdataadr(fd, sce->ed);
4305
4992
                        seq->seq2= newdataadr(fd, seq->seq2);
4306
4993
                        seq->seq3= newdataadr(fd, seq->seq3);
4307
4994
                        /* a patch: after introduction of effects with 3 input strips */
4308
 
                        if(seq->seq3==0) seq->seq3= seq->seq2;
 
4995
                        if (seq->seq3==NULL) seq->seq3= seq->seq2;
4309
4996
 
4310
4997
                        seq->plugin= newdataadr(fd, seq->plugin);
4311
4998
                        seq->effectdata= newdataadr(fd, seq->effectdata);
4312
4999
                        
4313
 
                        if(seq->type & SEQ_EFFECT)
 
5000
                        if (seq->type & SEQ_EFFECT)
4314
5001
                                seq->flag |= SEQ_EFFECT_NOT_LOADED;
4315
5002
 
4316
 
                        if(seq->type == SEQ_SPEED) {
 
5003
                        if (seq->type == SEQ_SPEED) {
4317
5004
                                SpeedControlVars *s= seq->effectdata;
4318
5005
                                s->frameMap= NULL;
4319
5006
                        }
4320
5007
 
4321
5008
                        seq->strip= newdataadr(fd, seq->strip);
4322
 
                        if(seq->strip && seq->strip->done==0) {
 
5009
                        if (seq->strip && seq->strip->done==0) {
4323
5010
                                seq->strip->done= 1;
4324
 
                                seq->strip->tstripdata = 0;
4325
 
                                seq->strip->tstripdata_startstill = 0;
4326
 
                                seq->strip->tstripdata_endstill = 0;
4327
 
                                seq->strip->ibuf_startstill = 0;
4328
 
                                seq->strip->ibuf_endstill = 0;
4329
5011
 
4330
 
                                if(seq->type == SEQ_IMAGE ||
 
5012
                                if (seq->type == SEQ_IMAGE ||
4331
5013
                                   seq->type == SEQ_MOVIE ||
4332
5014
                                   seq->type == SEQ_RAM_SOUND ||
4333
5015
                                   seq->type == SEQ_HD_SOUND) {
4334
5016
                                        seq->strip->stripdata = newdataadr(
4335
5017
                                                fd, seq->strip->stripdata);
4336
 
                                } else {
4337
 
                                        seq->strip->stripdata = 0;
 
5018
                                }
 
5019
                                else {
 
5020
                                        seq->strip->stripdata = NULL;
4338
5021
                                }
4339
5022
                                if (seq->flag & SEQ_USE_CROP) {
4340
5023
                                        seq->strip->crop = newdataadr(
4341
5024
                                                fd, seq->strip->crop);
4342
 
                                } else {
4343
 
                                        seq->strip->crop = 0;
 
5025
                                }
 
5026
                                else {
 
5027
                                        seq->strip->crop = NULL;
4344
5028
                                }
4345
5029
                                if (seq->flag & SEQ_USE_TRANSFORM) {
4346
5030
                                        seq->strip->transform = newdataadr(
4347
5031
                                                fd, seq->strip->transform);
4348
 
                                } else {
4349
 
                                        seq->strip->transform = 0;
 
5032
                                }
 
5033
                                else {
 
5034
                                        seq->strip->transform = NULL;
4350
5035
                                }
4351
5036
                                if (seq->flag & SEQ_USE_PROXY) {
4352
5037
                                        seq->strip->proxy = newdataadr(
4353
5038
                                                fd, seq->strip->proxy);
4354
 
                                        seq->strip->proxy->anim = 0;
4355
 
                                } else {
4356
 
                                        seq->strip->proxy = 0;
 
5039
                                        seq->strip->proxy->anim = NULL;
 
5040
                                }
 
5041
                                else {
 
5042
                                        seq->strip->proxy = NULL;
4357
5043
                                }
4358
5044
                                if (seq->flag & SEQ_USE_COLOR_BALANCE) {
4359
5045
                                        seq->strip->color_balance = newdataadr(
4360
5046
                                                fd, seq->strip->color_balance);
4361
 
                                } else {
4362
 
                                        seq->strip->color_balance = 0;
 
5047
                                }
 
5048
                                else {
 
5049
                                        seq->strip->color_balance = NULL;
4363
5050
                                }
4364
5051
                                if (seq->strip->color_balance) {
4365
5052
                                        // seq->strip->color_balance->gui = 0; // XXX - peter, is this relevant in 2.5?
4377
5064
                        offset= ((intptr_t)&(temp.seqbase)) - ((intptr_t)&temp);
4378
5065
                        
4379
5066
                        /* root pointer */
4380
 
                        if(ed->seqbasep == old_seqbasep) {
 
5067
                        if (ed->seqbasep == old_seqbasep) {
4381
5068
                                ed->seqbasep= &ed->seqbase;
4382
5069
                        }
4383
5070
                        else {
4386
5073
                                poin -= offset;
4387
5074
                                
4388
5075
                                poin= newdataadr(fd, poin);
4389
 
                                if(poin) ed->seqbasep= (ListBase *)(poin+offset);
 
5076
                                if (poin) ed->seqbasep= (ListBase *)(poin+offset);
4390
5077
                                else ed->seqbasep= &ed->seqbase;
4391
5078
                        }                       
4392
5079
                        /* stack */
4393
5080
                        link_list(fd, &(ed->metastack));
4394
5081
                        
4395
 
                        for(ms= ed->metastack.first; ms; ms= ms->next) {
 
5082
                        for (ms= ed->metastack.first; ms; ms= ms->next) {
4396
5083
                                ms->parseq= newdataadr(fd, ms->parseq);
4397
5084
                                
4398
 
                                if(ms->oldbasep == old_seqbasep)
 
5085
                                if (ms->oldbasep == old_seqbasep)
4399
5086
                                        ms->oldbasep= &ed->seqbase;
4400
5087
                                else {
4401
5088
                                        poin= (char *)ms->oldbasep;
4402
5089
                                        poin -= offset;
4403
5090
                                        poin= newdataadr(fd, poin);
4404
 
                                        if(poin) ms->oldbasep= (ListBase *)(poin+offset);
 
5091
                                        if (poin) ms->oldbasep= (ListBase *)(poin+offset);
4405
5092
                                        else ms->oldbasep= &ed->seqbase;
4406
5093
                                }
4407
5094
                        }
4433
5120
        link_list(fd, &(sce->r.layers));
4434
5121
 
4435
5122
        sce->nodetree= newdataadr(fd, sce->nodetree);
4436
 
        if(sce->nodetree)
 
5123
        if (sce->nodetree)
4437
5124
                direct_link_nodetree(fd, sce->nodetree);
4438
 
        
4439
5125
}
4440
5126
 
4441
5127
/* ************ READ WM ***************** */
4447
5133
        wm->id.us= 1;
4448
5134
        link_list(fd, &(wm->windows));
4449
5135
        
4450
 
        for(win= wm->windows.first; win; win= win->next) {
 
5136
        for (win= wm->windows.first; win; win= win->next) {
4451
5137
                win->ghostwin= NULL;
4452
5138
                win->eventstate= NULL;
4453
5139
                win->curswin= NULL;
4472
5158
 
4473
5159
        wm->keyconfigs.first= wm->keyconfigs.last= NULL;
4474
5160
        wm->defaultconf= NULL;
 
5161
        wm->addonconf= NULL;
 
5162
        wm->userconf= NULL;
4475
5163
 
4476
5164
        wm->jobs.first= wm->jobs.last= NULL;
4477
5165
        wm->drags.first= wm->drags.last= NULL;
4478
5166
        
4479
5167
        wm->windrawable= NULL;
 
5168
        wm->winactive= NULL;
4480
5169
        wm->initialized= 0;
4481
5170
        wm->op_undo_depth= 0;
4482
5171
}
4486
5175
        wmWindowManager *wm;
4487
5176
        wmWindow *win;
4488
5177
        
4489
 
        for(wm= main->wm.first; wm; wm= wm->id.next) {
4490
 
                if(wm->id.flag & LIB_NEEDLINK) {
4491
 
                        for(win= wm->windows.first; win; win= win->next)
 
5178
        for (wm= main->wm.first; wm; wm= wm->id.next) {
 
5179
                if (wm->id.flag & LIB_NEEDLINK) {
 
5180
                        for (win= wm->windows.first; win; win= win->next)
4492
5181
                                win->screen= newlibadr(fd, NULL, win->screen);
4493
5182
 
4494
5183
                        wm->id.flag -= LIB_NEEDLINK;
4532
5221
 
4533
5222
static void butspace_version_132(SpaceButs *buts)
4534
5223
{
4535
 
        buts->v2d.tot.xmin= 0.0f;
4536
 
        buts->v2d.tot.ymin= 0.0f;
4537
 
        buts->v2d.tot.xmax= 1279.0f;
4538
 
        buts->v2d.tot.ymax= 228.0f;
 
5224
        buts->v2d.tot.xmin = 0.0f;
 
5225
        buts->v2d.tot.ymin = 0.0f;
 
5226
        buts->v2d.tot.xmax = 1279.0f;
 
5227
        buts->v2d.tot.ymax = 228.0f;
4539
5228
 
4540
5229
        buts->v2d.min[0]= 256.0f;
4541
5230
        buts->v2d.min[1]= 42.0f;
4552
5241
}
4553
5242
 
4554
5243
/* note: file read without screens option G_FILE_NO_UI; 
4555
 
   check lib pointers in call below */
 
5244
 * check lib pointers in call below */
4556
5245
static void lib_link_screen(FileData *fd, Main *main)
4557
5246
{
4558
5247
        bScreen *sc;
4559
5248
        ScrArea *sa;
4560
5249
 
4561
 
        for(sc= main->screen.first; sc; sc= sc->id.next) {
4562
 
                if(sc->id.flag & LIB_NEEDLINK) {
 
5250
        for (sc= main->screen.first; sc; sc= sc->id.next) {
 
5251
                if (sc->id.flag & LIB_NEEDLINK) {
4563
5252
                        sc->id.us= 1;
4564
5253
                        sc->scene= newlibadr(fd, sc->id.lib, sc->scene);
4565
5254
                        sc->animtimer= NULL; /* saved in rare cases */
4566
5255
                        
4567
5256
                        sa= sc->areabase.first;
4568
 
                        while(sa) {
 
5257
                        while (sa) {
4569
5258
                                SpaceLink *sl;
4570
5259
                                
4571
5260
                                sa->full= newlibadr(fd, sc->id.lib, sa->full);
4572
5261
                                
4573
5262
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
4574
 
                                        if(sl->spacetype==SPACE_VIEW3D) {
 
5263
                                        if (sl->spacetype==SPACE_VIEW3D) {
4575
5264
                                                View3D *v3d= (View3D*) sl;
4576
5265
                                                BGpic *bgpic = NULL;
4577
5266
                                                
4579
5268
                                                v3d->ob_centre= newlibadr(fd, sc->id.lib, v3d->ob_centre);
4580
5269
                                                
4581
5270
                                                /* should be do_versions but not easy adding into the listbase */
4582
 
                                                if(v3d->bgpic) {
 
5271
                                                if (v3d->bgpic) {
4583
5272
                                                        v3d->bgpic= newlibadr(fd, sc->id.lib, v3d->bgpic);
4584
5273
                                                        BLI_addtail(&v3d->bgpicbase, bgpic);
4585
5274
                                                        v3d->bgpic= NULL;
4586
5275
                                                }
4587
5276
 
4588
 
                                                for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
 
5277
                                                for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
4589
5278
                                                        bgpic->ima= newlibadr_us(fd, sc->id.lib, bgpic->ima);
 
5279
                                                        bgpic->clip= newlibadr_us(fd, sc->id.lib, bgpic->clip);
4590
5280
                                                }
4591
 
                                                if(v3d->localvd) {
 
5281
                                                if (v3d->localvd) {
4592
5282
                                                        v3d->localvd->camera= newlibadr(fd, sc->id.lib, v3d->localvd->camera);
4593
5283
                                                }
4594
5284
                                        }
4595
 
                                        else if(sl->spacetype==SPACE_IPO) {
 
5285
                                        else if (sl->spacetype==SPACE_IPO) {
4596
5286
                                                SpaceIpo *sipo= (SpaceIpo *)sl;
4597
5287
                                                bDopeSheet *ads= sipo->ads;
4598
5288
                                                
4601
5291
                                                        ads->filter_grp= newlibadr(fd, sc->id.lib, ads->filter_grp);
4602
5292
                                                }
4603
5293
                                        }
4604
 
                                        else if(sl->spacetype==SPACE_BUTS) {
 
5294
                                        else if (sl->spacetype==SPACE_BUTS) {
4605
5295
                                                SpaceButs *sbuts= (SpaceButs *)sl;
4606
 
                                                sbuts->ri= NULL;
4607
5296
                                                sbuts->pinid= newlibadr(fd, sc->id.lib, sbuts->pinid);
4608
5297
                                                sbuts->mainbo= sbuts->mainb;
4609
5298
                                                sbuts->mainbuser= sbuts->mainb;
4610
 
                                                if(main->versionfile<132)
 
5299
                                                if (main->versionfile<132)
4611
5300
                                                        butspace_version_132(sbuts);
4612
5301
                                        }
4613
 
                                        else if(sl->spacetype==SPACE_FILE) {
 
5302
                                        else if (sl->spacetype==SPACE_FILE) {
4614
5303
                                                SpaceFile *sfile= (SpaceFile *)sl;
4615
5304
                                                sfile->files= NULL;
4616
 
                                                sfile->params= NULL;
4617
5305
                                                sfile->op= NULL;
4618
5306
                                                sfile->layout= NULL;
4619
5307
                                                sfile->folders_prev= NULL;
4620
5308
                                                sfile->folders_next= NULL;
4621
5309
                                        }
4622
 
                                        else if(sl->spacetype==SPACE_IMASEL) {
4623
 
                                                SpaceImaSel *simasel= (SpaceImaSel *)sl;
4624
 
 
4625
 
                                                simasel->files = NULL;                                          
4626
 
                                                simasel->returnfunc= NULL;
4627
 
                                                simasel->menup= NULL;
4628
 
                                                simasel->pupmenu= NULL;
4629
 
                                                simasel->img= NULL;
4630
 
                                        }
4631
 
                                        else if(sl->spacetype==SPACE_ACTION) {
 
5310
                                        else if (sl->spacetype==SPACE_ACTION) {
4632
5311
                                                SpaceAction *saction= (SpaceAction *)sl;
4633
5312
                                                bDopeSheet *ads= &saction->ads;
4634
5313
                                                
4639
5318
                                                
4640
5319
                                                saction->action = newlibadr(fd, sc->id.lib, saction->action);
4641
5320
                                        }
4642
 
                                        else if(sl->spacetype==SPACE_IMAGE) {
 
5321
                                        else if (sl->spacetype==SPACE_IMAGE) {
4643
5322
                                                SpaceImage *sima= (SpaceImage *)sl;
4644
5323
 
4645
5324
                                                sima->image= newlibadr_us(fd, sc->id.lib, sima->image);
4649
5328
                                                 */
4650
5329
                                                sima->gpd= newlibadr_us(fd, sc->id.lib, sima->gpd);
4651
5330
                                        }
4652
 
                                        else if(sl->spacetype==SPACE_NLA){
 
5331
                                        else if (sl->spacetype==SPACE_NLA) {
4653
5332
                                                SpaceNla *snla= (SpaceNla *)sl;
4654
5333
                                                bDopeSheet *ads= snla->ads;
4655
5334
                                                
4658
5337
                                                        ads->filter_grp= newlibadr(fd, sc->id.lib, ads->filter_grp);
4659
5338
                                                }
4660
5339
                                        }
4661
 
                                        else if(sl->spacetype==SPACE_TEXT) {
 
5340
                                        else if (sl->spacetype==SPACE_TEXT) {
4662
5341
                                                SpaceText *st= (SpaceText *)sl;
4663
5342
 
4664
5343
                                                st->text= newlibadr(fd, sc->id.lib, st->text);
 
5344
                                                st->drawcache= NULL;
4665
5345
 
4666
5346
                                        }
4667
 
                                        else if(sl->spacetype==SPACE_SCRIPT) {
 
5347
                                        else if (sl->spacetype==SPACE_SCRIPT) {
4668
5348
 
4669
5349
                                                SpaceScript *scpt= (SpaceScript *)sl;
4670
5350
                                                /*scpt->script = NULL; - 2.45 set to null, better re-run the script */
4671
5351
                                                if (scpt->script) {
4672
5352
                                                        scpt->script= newlibadr(fd, sc->id.lib, scpt->script);
4673
5353
                                                        if (scpt->script) {
4674
 
                                                                SCRIPT_SET_NULL(scpt->script)
 
5354
                                                                SCRIPT_SET_NULL(scpt->script);
4675
5355
                                                        }
4676
5356
                                                }
4677
5357
                                        }
4678
 
                                        else if(sl->spacetype==SPACE_OUTLINER) {
 
5358
                                        else if (sl->spacetype==SPACE_OUTLINER) {
4679
5359
                                                SpaceOops *so= (SpaceOops *)sl;
4680
5360
                                                TreeStoreElem *tselem;
4681
5361
                                                int a;
4683
5363
                                                so->tree.first= so->tree.last= NULL;
4684
5364
                                                so->search_tse.id= newlibadr(fd, NULL, so->search_tse.id);
4685
5365
                                                
4686
 
                                                if(so->treestore) {
 
5366
                                                if (so->treestore) {
4687
5367
                                                        tselem= so->treestore->data;
4688
 
                                                        for(a=0; a<so->treestore->usedelem; a++, tselem++) {
 
5368
                                                        for (a=0; a<so->treestore->usedelem; a++, tselem++) {
4689
5369
                                                                tselem->id= newlibadr(fd, NULL, tselem->id);
4690
5370
                                                        }
4691
5371
                                                }
4692
5372
                                        }
4693
 
                                        else if(sl->spacetype==SPACE_SOUND) {
4694
 
                                                SpaceSound *ssound= (SpaceSound *)sl;
4695
 
 
4696
 
                                                ssound->sound= newlibadr_us(fd, sc->id.lib, ssound->sound);
4697
 
                                        }
4698
 
                                        else if(sl->spacetype==SPACE_NODE) {
 
5373
                                        else if (sl->spacetype==SPACE_NODE) {
4699
5374
                                                SpaceNode *snode= (SpaceNode *)sl;
4700
5375
                                                
4701
5376
                                                snode->id= newlibadr(fd, sc->id.lib, snode->id);
4702
 
                                                
4703
 
                                                /* internal data, a bit patchy */
4704
 
                                                if(snode->id) {
4705
 
                                                        if(GS(snode->id->name)==ID_MA)
4706
 
                                                                snode->nodetree= ((Material *)snode->id)->nodetree;
4707
 
                                                        else if(GS(snode->id->name)==ID_SCE)
4708
 
                                                                snode->nodetree= ((Scene *)snode->id)->nodetree;
4709
 
                                                        else if(GS(snode->id->name)==ID_TE)
4710
 
                                                                snode->nodetree= ((Tex *)snode->id)->nodetree;
4711
 
                                                }
 
5377
                                                snode->edittree= NULL;
 
5378
                                                
 
5379
                                                if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
 
5380
                                                        /* internal data, a bit patchy */
 
5381
                                                        snode->nodetree= NULL;
 
5382
                                                        if (snode->id) {
 
5383
                                                                if (GS(snode->id->name)==ID_MA)
 
5384
                                                                        snode->nodetree= ((Material *)snode->id)->nodetree;
 
5385
                                                                else if (GS(snode->id->name)==ID_WO)
 
5386
                                                                        snode->nodetree= ((World *)snode->id)->nodetree;
 
5387
                                                                else if (GS(snode->id->name)==ID_LA)
 
5388
                                                                        snode->nodetree= ((Lamp *)snode->id)->nodetree;
 
5389
                                                                else if (GS(snode->id->name)==ID_SCE)
 
5390
                                                                        snode->nodetree= ((Scene *)snode->id)->nodetree;
 
5391
                                                                else if (GS(snode->id->name)==ID_TE)
 
5392
                                                                        snode->nodetree= ((Tex *)snode->id)->nodetree;
 
5393
                                                        }
 
5394
                                                }
 
5395
                                                else {
 
5396
                                                        snode->nodetree= newlibadr_us(fd, sc->id.lib, snode->nodetree);
 
5397
                                                }
 
5398
                                                
 
5399
                                                snode->linkdrag.first = snode->linkdrag.last = NULL;
 
5400
                                        }
 
5401
                                        else if (sl->spacetype==SPACE_CLIP) {
 
5402
                                                SpaceClip *sclip= (SpaceClip *)sl;
 
5403
 
 
5404
                                                sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
 
5405
 
 
5406
                                                sclip->scopes.track_preview = NULL;
 
5407
                                                sclip->scopes.ok = 0;
4712
5408
                                        }
4713
5409
                                }
4714
5410
                                sa= sa->next;
4722
5418
static void *restore_pointer_by_name(Main *mainp, ID *id, int user)
4723
5419
{
4724
5420
                
4725
 
        if(id) {
 
5421
        if (id) {
4726
5422
                ListBase *lb= which_libbase(mainp, GS(id->name));
4727
5423
                
4728
 
                if(lb) {        // there's still risk of checking corrupt mem (freed Ids in oops)
 
5424
                if (lb) {       // there's still risk of checking corrupt mem (freed Ids in oops)
4729
5425
                        ID *idn= lb->first;
4730
5426
                        char *name= id->name+2;
4731
5427
                        
4732
 
                        while(idn) {
4733
 
                                if(idn->name[2]==name[0] && strcmp(idn->name+2, name)==0) {
4734
 
                                        if(idn->lib==id->lib) {
4735
 
                                                if(user && idn->us==0) idn->us++;
 
5428
                        while (idn) {
 
5429
                                if (idn->name[2]==name[0] && strcmp(idn->name+2, name)==0) {
 
5430
                                        if (idn->lib==id->lib) {
 
5431
                                                if (user && idn->us==0) idn->us++;
4736
5432
                                                break;
4737
5433
                                        }
4738
5434
                                }
4744
5440
        return NULL;
4745
5441
}
4746
5442
 
 
5443
static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
 
5444
{
 
5445
        Main *newmain = (Main *)arg_pt;
 
5446
 
 
5447
        if (seq->sound) {
 
5448
                seq->sound = restore_pointer_by_name(newmain, (ID *)seq->sound, 0);
 
5449
                seq->sound->id.us++;
 
5450
        }
 
5451
 
 
5452
        if (seq->scene)
 
5453
                seq->scene = restore_pointer_by_name(newmain, (ID *)seq->scene, 1);
 
5454
 
 
5455
        if (seq->scene_camera)
 
5456
                seq->scene_camera = restore_pointer_by_name(newmain, (ID *)seq->scene_camera, 1);
 
5457
 
 
5458
        return 1;
 
5459
}
 
5460
 
 
5461
static void lib_link_clipboard_restore(Main *newmain)
 
5462
{
 
5463
        /* update IDs stored in sequencer clipboard */
 
5464
        seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, newmain);
 
5465
}
 
5466
 
4747
5467
/* called from kernel/blender.c */
4748
5468
/* used to link a file (without UI) to the current UI */
4749
5469
/* note that it assumes the old pointers in UI are still valid, so old Main is not freed */
4755
5475
        ScrArea *sa;
4756
5476
 
4757
5477
        /* first windowmanager */
4758
 
        for(wm= newmain->wm.first; wm; wm= wm->id.next) {
4759
 
                for(win= wm->windows.first; win; win= win->next) {
 
5478
        for (wm= newmain->wm.first; wm; wm= wm->id.next) {
 
5479
                for (win= wm->windows.first; win; win= win->next) {
4760
5480
                        win->screen= restore_pointer_by_name(newmain, (ID *)win->screen, 1);
4761
5481
                        
4762
 
                        if(win->screen==NULL)
 
5482
                        if (win->screen==NULL)
4763
5483
                                win->screen= curscreen;
4764
5484
 
4765
5485
                        win->screen->winid= win->winid;
4767
5487
        }
4768
5488
        
4769
5489
        
4770
 
        for(sc= newmain->screen.first; sc; sc= sc->id.next) {
 
5490
        for (sc= newmain->screen.first; sc; sc= sc->id.next) {
4771
5491
                Scene *oldscene= sc->scene;
4772
5492
 
4773
5493
                sc->scene= restore_pointer_by_name(newmain, (ID *)sc->scene, 1);
4774
 
                if(sc->scene==NULL)
 
5494
                if (sc->scene==NULL)
4775
5495
                        sc->scene= curscene;
4776
5496
 
4777
5497
                /* keep cursor location through undo */
4778
5498
                copy_v3_v3(sc->scene->cursor, oldscene->cursor);
4779
5499
 
4780
5500
                sa= sc->areabase.first;
4781
 
                while(sa) {
 
5501
                while (sa) {
4782
5502
                        SpaceLink *sl;
4783
5503
 
4784
5504
                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
4785
 
                                if(sl->spacetype==SPACE_VIEW3D) {
 
5505
                                if (sl->spacetype==SPACE_VIEW3D) {
4786
5506
                                        View3D *v3d= (View3D*) sl;
4787
5507
                                        BGpic *bgpic;
 
5508
                                        ARegion *ar;
4788
5509
                                        
4789
 
                                        if(v3d->scenelock)
 
5510
                                        if (v3d->scenelock)
4790
5511
                                                v3d->camera= NULL; /* always get from scene */
4791
5512
                                        else
4792
5513
                                                v3d->camera= restore_pointer_by_name(newmain, (ID *)v3d->camera, 1);
4793
 
                                        if(v3d->camera==NULL)
 
5514
                                        if (v3d->camera==NULL)
4794
5515
                                                v3d->camera= sc->scene->camera;
4795
5516
                                        v3d->ob_centre= restore_pointer_by_name(newmain, (ID *)v3d->ob_centre, 1);
4796
5517
                                        
4797
 
                                        for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
 
5518
                                        for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
4798
5519
                                                bgpic->ima= restore_pointer_by_name(newmain, (ID *)bgpic->ima, 1);
 
5520
                                                bgpic->clip= restore_pointer_by_name(newmain, (ID *)bgpic->clip, 1);
4799
5521
                                        }
4800
 
                                        if(v3d->localvd) {
 
5522
                                        if (v3d->localvd) {
4801
5523
                                                /*Base *base;*/
4802
5524
 
4803
5525
                                                v3d->localvd->camera= sc->scene->camera;
4804
5526
                                                
4805
5527
                                                /* localview can become invalid during undo/redo steps, so we exit it when no could be found */
4806
5528
                                                /* XXX  regionlocalview ?
4807
 
                                                for(base= sc->scene->base.first; base; base= base->next) {
4808
 
                                                        if(base->lay & v3d->lay) break;
 
5529
                                                for (base= sc->scene->base.first; base; base= base->next) {
 
5530
                                                        if (base->lay & v3d->lay) break;
4809
5531
                                                }
4810
 
                                                if(base==NULL) {
 
5532
                                                if (base==NULL) {
4811
5533
                                                        v3d->lay= v3d->localvd->lay;
4812
5534
                                                        v3d->layact= v3d->localvd->layact;
4813
5535
                                                        MEM_freeN(v3d->localvd); 
4815
5537
                                                }
4816
5538
                                                */
4817
5539
                                        }
4818
 
                                        else if(v3d->scenelock) v3d->lay= sc->scene->lay;
 
5540
                                        else if (v3d->scenelock) v3d->lay= sc->scene->lay;
4819
5541
 
4820
5542
                                        /* not very nice, but could help */
4821
 
                                        if((v3d->layact & v3d->lay)==0) v3d->layact= v3d->lay;
 
5543
                                        if ((v3d->layact & v3d->lay)==0) v3d->layact= v3d->lay;
4822
5544
                                        
 
5545
                                        /* free render engines for now */
 
5546
                                        for (ar= sa->regionbase.first; ar; ar= ar->next) {
 
5547
                                                RegionView3D *rv3d= ar->regiondata;
 
5548
 
 
5549
                                                if (rv3d && rv3d->render_engine) {
 
5550
                                                        RE_engine_free(rv3d->render_engine);
 
5551
                                                        rv3d->render_engine= NULL;
 
5552
                                                }
 
5553
                                        }
4823
5554
                                }
4824
 
                                else if(sl->spacetype==SPACE_IPO) {
 
5555
                                else if (sl->spacetype==SPACE_IPO) {
4825
5556
                                        SpaceIpo *sipo= (SpaceIpo *)sl;
4826
5557
                                        bDopeSheet *ads= sipo->ads;
4827
5558
                                        
4832
5563
                                                        ads->filter_grp= restore_pointer_by_name(newmain, (ID *)ads->filter_grp, 0);
4833
5564
                                        }
4834
5565
                                }
4835
 
                                else if(sl->spacetype==SPACE_BUTS) {
 
5566
                                else if (sl->spacetype==SPACE_BUTS) {
4836
5567
                                        SpaceButs *sbuts= (SpaceButs *)sl;
4837
5568
                                        sbuts->pinid = restore_pointer_by_name(newmain, sbuts->pinid, 0);
4838
5569
                                        //XXX if (sbuts->ri) sbuts->ri->curtile = 0;
4839
5570
                                }
4840
 
                                else if(sl->spacetype==SPACE_FILE) {
 
5571
                                else if (sl->spacetype==SPACE_FILE) {
4841
5572
                                        
4842
5573
                                        SpaceFile *sfile= (SpaceFile *)sl;
4843
 
                                        sfile->files= NULL;
4844
 
                                        sfile->folders_prev= NULL;
4845
 
                                        sfile->folders_next= NULL;
4846
 
                                        sfile->params= NULL;
4847
5574
                                        sfile->op= NULL;
4848
5575
                                }
4849
 
                                else if(sl->spacetype==SPACE_IMASEL) {
4850
 
                                        SpaceImaSel *simasel= (SpaceImaSel *)sl;
4851
 
                                        if (simasel->files) {
4852
 
                                                //XXX BIF_filelist_freelib(simasel->files);
4853
 
                                        }
4854
 
                                }
4855
 
                                else if(sl->spacetype==SPACE_ACTION) {
 
5576
                                else if (sl->spacetype==SPACE_ACTION) {
4856
5577
                                        SpaceAction *saction= (SpaceAction *)sl;
4857
5578
                                        
4858
5579
                                        saction->action = restore_pointer_by_name(newmain, (ID *)saction->action, 1);
4861
5582
                                        if (saction->ads.filter_grp)
4862
5583
                                                saction->ads.filter_grp= restore_pointer_by_name(newmain, (ID *)saction->ads.filter_grp, 0);
4863
5584
                                }
4864
 
                                else if(sl->spacetype==SPACE_IMAGE) {
 
5585
                                else if (sl->spacetype==SPACE_IMAGE) {
4865
5586
                                        SpaceImage *sima= (SpaceImage *)sl;
4866
5587
 
4867
5588
                                        sima->image= restore_pointer_by_name(newmain, (ID *)sima->image, 1);
4868
5589
 
 
5590
                                        /* this will be freed, not worth attempting to find same scene,
 
5591
                                         * since it gets initialized later */
 
5592
                                        sima->iuser.scene = NULL;
 
5593
 
4869
5594
                                        sima->scopes.waveform_1 = NULL;
4870
5595
                                        sima->scopes.waveform_2 = NULL;
4871
5596
                                        sima->scopes.waveform_3 = NULL;
4877
5602
                                         */
4878
5603
                                        sima->gpd= restore_pointer_by_name(newmain, (ID *)sima->gpd, 1);
4879
5604
                                }
4880
 
                                else if(sl->spacetype==SPACE_NLA){
 
5605
                                else if (sl->spacetype==SPACE_NLA) {
4881
5606
                                        SpaceNla *snla= (SpaceNla *)sl;
4882
5607
                                        bDopeSheet *ads= snla->ads;
4883
5608
                                        
4888
5613
                                                        ads->filter_grp= restore_pointer_by_name(newmain, (ID *)ads->filter_grp, 0);
4889
5614
                                        }
4890
5615
                                }
4891
 
                                else if(sl->spacetype==SPACE_TEXT) {
 
5616
                                else if (sl->spacetype==SPACE_TEXT) {
4892
5617
                                        SpaceText *st= (SpaceText *)sl;
4893
5618
 
4894
5619
                                        st->text= restore_pointer_by_name(newmain, (ID *)st->text, 1);
4895
 
                                        if(st->text==NULL) st->text= newmain->text.first;
 
5620
                                        if (st->text==NULL) st->text= newmain->text.first;
4896
5621
                                }
4897
 
                                else if(sl->spacetype==SPACE_SCRIPT) {
 
5622
                                else if (sl->spacetype==SPACE_SCRIPT) {
4898
5623
                                        SpaceScript *scpt= (SpaceScript *)sl;
4899
5624
                                        
4900
5625
                                        scpt->script= restore_pointer_by_name(newmain, (ID *)scpt->script, 1);
4901
5626
                                        
4902
5627
                                        /*sc->script = NULL; - 2.45 set to null, better re-run the script */
4903
5628
                                        if (scpt->script) {
4904
 
                                                SCRIPT_SET_NULL(scpt->script)
 
5629
                                                SCRIPT_SET_NULL(scpt->script);
4905
5630
                                        }
4906
5631
                                }
4907
 
                                else if(sl->spacetype==SPACE_OUTLINER) {
 
5632
                                else if (sl->spacetype==SPACE_OUTLINER) {
4908
5633
                                        SpaceOops *so= (SpaceOops *)sl;
4909
5634
                                        int a;
4910
5635
                                        
4911
5636
                                        so->search_tse.id= restore_pointer_by_name(newmain, so->search_tse.id, 0);
4912
5637
                                        
4913
 
                                        if(so->treestore) {
 
5638
                                        if (so->treestore) {
4914
5639
                                                TreeStore *ts= so->treestore;
4915
5640
                                                TreeStoreElem *tselem=ts->data;
4916
 
                                                for(a=0; a<ts->usedelem; a++, tselem++) {
 
5641
                                                for (a=0; a<ts->usedelem; a++, tselem++) {
4917
5642
                                                        tselem->id= restore_pointer_by_name(newmain, tselem->id, 0);
4918
5643
                                                }
4919
5644
                                        }
4920
5645
                                }
4921
 
                                else if(sl->spacetype==SPACE_SOUND) {
4922
 
                                        SpaceSound *ssound= (SpaceSound *)sl;
4923
 
 
4924
 
                                        ssound->sound= restore_pointer_by_name(newmain, (ID *)ssound->sound, 1);
4925
 
                                }
4926
 
                                else if(sl->spacetype==SPACE_NODE) {
 
5646
                                else if (sl->spacetype==SPACE_NODE) {
4927
5647
                                        SpaceNode *snode= (SpaceNode *)sl;
4928
5648
                                        
4929
5649
                                        snode->id= restore_pointer_by_name(newmain, snode->id, 1);
4930
5650
                                        snode->edittree= NULL;
4931
5651
                                        
4932
 
                                        if(snode->id==NULL)
 
5652
                                        if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
4933
5653
                                                snode->nodetree= NULL;
 
5654
                                                if (snode->id) {
 
5655
                                                        if (GS(snode->id->name)==ID_MA)
 
5656
                                                                snode->nodetree= ((Material *)snode->id)->nodetree;
 
5657
                                                        else if (GS(snode->id->name)==ID_SCE)
 
5658
                                                                snode->nodetree= ((Scene *)snode->id)->nodetree;
 
5659
                                                        else if (GS(snode->id->name)==ID_TE)
 
5660
                                                                snode->nodetree= ((Tex *)snode->id)->nodetree;
 
5661
                                                }
 
5662
                                        }
4934
5663
                                        else {
4935
 
                                                if(GS(snode->id->name)==ID_MA)
4936
 
                                                        snode->nodetree= ((Material *)snode->id)->nodetree;
4937
 
                                                else if(GS(snode->id->name)==ID_SCE)
4938
 
                                                        snode->nodetree= ((Scene *)snode->id)->nodetree;
4939
 
                                                else if(GS(snode->id->name)==ID_TE)
4940
 
                                                        snode->nodetree= ((Tex *)snode->id)->nodetree;
 
5664
                                                snode->nodetree= restore_pointer_by_name(newmain, &snode->nodetree->id, 1);
4941
5665
                                        }
4942
5666
                                }
 
5667
                                else if (sl->spacetype==SPACE_CLIP) {
 
5668
                                        SpaceClip *sclip= (SpaceClip *)sl;
 
5669
 
 
5670
                                        sclip->clip= restore_pointer_by_name(newmain, (ID *)sclip->clip, 1);
 
5671
 
 
5672
                                        sclip->scopes.ok = 0;
 
5673
                                }
4943
5674
                        }
4944
5675
                        sa= sa->next;
4945
5676
                }
4946
5677
        }
 
5678
 
 
5679
        /* update IDs stored in all possible clipboards */
 
5680
        lib_link_clipboard_restore(newmain);
4947
5681
}
4948
5682
 
4949
5683
static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
4952
5686
 
4953
5687
        link_list(fd, &(ar->panels));
4954
5688
 
4955
 
        for(pa= ar->panels.first; pa; pa=pa->next) {
 
5689
        for (pa= ar->panels.first; pa; pa=pa->next) {
4956
5690
                pa->paneltab= newdataadr(fd, pa->paneltab);
4957
5691
                pa->runtime_flag= 0;
4958
5692
                pa->activedata= NULL;
4960
5694
        }
4961
5695
        
4962
5696
        ar->regiondata= newdataadr(fd, ar->regiondata);
4963
 
        if(ar->regiondata) {
4964
 
                if(spacetype==SPACE_VIEW3D) {
 
5697
        if (ar->regiondata) {
 
5698
                if (spacetype==SPACE_VIEW3D) {
4965
5699
                        RegionView3D *rv3d= ar->regiondata;
4966
5700
                        
4967
5701
                        rv3d->localvd= newdataadr(fd, rv3d->localvd);
4968
5702
                        rv3d->clipbb= newdataadr(fd, rv3d->clipbb);
4969
5703
                        
4970
5704
                        rv3d->depths= NULL;
4971
 
                        rv3d->retopo_view_data= NULL;
4972
5705
                        rv3d->ri= NULL;
 
5706
                        rv3d->render_engine= NULL;
4973
5707
                        rv3d->sms= NULL;
4974
5708
                        rv3d->smooth_timer= NULL;
4975
5709
                }
4994
5728
{
4995
5729
        ARegion *ar;
4996
5730
        
4997
 
        for(ar= regions->first; ar; ar= ar->next) {
4998
 
                if(ar->regiontype==RGN_TYPE_WINDOW && ar->regiondata==NULL) {
 
5731
        for (ar= regions->first; ar; ar= ar->next) {
 
5732
                if (ar->regiontype==RGN_TYPE_WINDOW && ar->regiondata==NULL) {
4999
5733
                        RegionView3D *rv3d;
5000
5734
                        
5001
5735
                        rv3d= ar->regiondata= MEM_callocN(sizeof(RegionView3D), "region v3d patch");
5002
 
                        rv3d->persp= v3d->persp;
5003
 
                        rv3d->view= v3d->view;
 
5736
                        rv3d->persp= (char)v3d->persp;
 
5737
                        rv3d->view= (char)v3d->view;
5004
5738
                        rv3d->dist= v3d->dist;
5005
 
                        VECCOPY(rv3d->ofs, v3d->ofs);
5006
 
                        QUATCOPY(rv3d->viewquat, v3d->viewquat);
 
5739
                        copy_v3_v3(rv3d->ofs, v3d->ofs);
 
5740
                        copy_qt_qt(rv3d->viewquat, v3d->viewquat);
5007
5741
                }
5008
5742
        }
5009
5743
 
5010
5744
        /* this was not initialized correct always */
5011
 
        if(v3d->twtype == 0)
 
5745
        if (v3d->twtype == 0)
5012
5746
                v3d->twtype= V3D_MANIP_TRANSLATE;
5013
5747
}
5014
5748
 
5029
5763
        sc->swap= 0;
5030
5764
        
5031
5765
        /* hacky patch... but people have been saving files with the verse-blender,
5032
 
           causing the handler to keep running for ever, with no means to disable it */
5033
 
        for(a=0; a<SCREEN_MAXHANDLER; a+=2) {
5034
 
                if( sc->handler[a]==SCREEN_HANDLER_VERSE) {
 
5766
         * causing the handler to keep running for ever, with no means to disable it */
 
5767
        for (a=0; a<SCREEN_MAXHANDLER; a+=2) {
 
5768
                if ( sc->handler[a]==SCREEN_HANDLER_VERSE) {
5035
5769
                        sc->handler[a]= 0;
5036
5770
                        break;
5037
5771
                }
5038
5772
        }
5039
5773
        
5040
5774
        /* edges */
5041
 
        for(se= sc->edgebase.first; se; se= se->next) {
 
5775
        for (se= sc->edgebase.first; se; se= se->next) {
5042
5776
                se->v1= newdataadr(fd, se->v1);
5043
5777
                se->v2= newdataadr(fd, se->v2);
5044
 
                if( (intptr_t)se->v1 > (intptr_t)se->v2) {
 
5778
                if ( (intptr_t)se->v1 > (intptr_t)se->v2) {
5045
5779
                        sv= se->v1;
5046
5780
                        se->v1= se->v2;
5047
5781
                        se->v2= sv;
5048
5782
                }
5049
5783
 
5050
 
                if(se->v1==NULL) {
 
5784
                if (se->v1==NULL) {
5051
5785
                        printf("error reading screen... file corrupt\n");
5052
5786
                        se->v1= se->v2;
5053
5787
                }
5054
5788
        }
5055
5789
 
5056
5790
        /* areas */
5057
 
        for(sa= sc->areabase.first; sa; sa= sa->next) {
 
5791
        for (sa= sc->areabase.first; sa; sa= sa->next) {
5058
5792
                SpaceLink *sl;
5059
5793
                ARegion *ar;
5060
5794
 
5064
5798
                sa->handlers.first= sa->handlers.last= NULL;
5065
5799
                sa->type= NULL; /* spacetype callbacks */
5066
5800
                
5067
 
                for(ar= sa->regionbase.first; ar; ar= ar->next)
 
5801
                for (ar= sa->regionbase.first; ar; ar= ar->next)
5068
5802
                        direct_link_region(fd, ar, sa->spacetype);
5069
5803
                
5070
5804
                /* accident can happen when read/save new file with older version */
5071
5805
                /* 2.50: we now always add spacedata for info */
5072
 
                if(sa->spacedata.first==NULL) {
 
5806
                if (sa->spacedata.first==NULL) {
5073
5807
                        SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo");
5074
5808
                        sa->spacetype= sinfo->spacetype= SPACE_INFO;
5075
5809
                        BLI_addtail(&sa->spacedata, sinfo);
5076
5810
                }
5077
5811
                /* add local view3d too */
5078
 
                else if(sa->spacetype==SPACE_VIEW3D)
 
5812
                else if (sa->spacetype==SPACE_VIEW3D)
5079
5813
                        view3d_split_250(sa->spacedata.first, &sa->regionbase);
5080
5814
                
5081
5815
                for (sl= sa->spacedata.first; sl; sl= sl->next) {
5082
5816
                        link_list(fd, &(sl->regionbase));
5083
5817
 
5084
 
                        for(ar= sl->regionbase.first; ar; ar= ar->next)
 
5818
                        for (ar= sl->regionbase.first; ar; ar= ar->next)
5085
5819
                                direct_link_region(fd, ar, sl->spacetype);
5086
5820
 
5087
5821
                        if (sl->spacetype==SPACE_VIEW3D) {
5093
5827
                                link_list(fd, &(v3d->bgpicbase));
5094
5828
 
5095
5829
                                /* should be do_versions except this doesnt fit well there */
5096
 
                                if(v3d->bgpic) {
 
5830
                                if (v3d->bgpic) {
5097
5831
                                        bgpic= newdataadr(fd, v3d->bgpic);
5098
5832
                                        BLI_addtail(&v3d->bgpicbase, bgpic);
5099
5833
                                        v3d->bgpic= NULL;
5100
5834
                                }
5101
5835
 
5102
 
                                for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next)
 
5836
                                for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next)
5103
5837
                                        bgpic->iuser.ok= 1;
5104
5838
 
5105
 
                                if(v3d->gpd) {
 
5839
                                if (v3d->gpd) {
5106
5840
                                        v3d->gpd= newdataadr(fd, v3d->gpd);
5107
5841
                                        direct_link_gpencil(fd, v3d->gpd);
5108
5842
                                }
5109
5843
                                v3d->localvd= newdataadr(fd, v3d->localvd);
5110
 
                                v3d->afterdraw.first= v3d->afterdraw.last= NULL;
 
5844
                                v3d->afterdraw_transp.first= v3d->afterdraw_transp.last= NULL;
 
5845
                                v3d->afterdraw_xray.first= v3d->afterdraw_xray.last= NULL;
 
5846
                                v3d->afterdraw_xraytransp.first= v3d->afterdraw_xraytransp.last= NULL;
5111
5847
                                v3d->properties_storage= NULL;
 
5848
 
 
5849
                                /* render can be quite heavy, set to wire on load */
 
5850
                                if (v3d->drawtype == OB_RENDER)
 
5851
                                        v3d->drawtype = OB_WIRE;
5112
5852
                                
5113
5853
                                view3d_split_250(v3d, &sl->regionbase);
5114
5854
                        }
5127
5867
                                SpaceOops *soops= (SpaceOops*) sl;
5128
5868
                                
5129
5869
                                soops->treestore= newdataadr(fd, soops->treestore);
5130
 
                                if(soops->treestore) {
 
5870
                                if (soops->treestore) {
5131
5871
                                        soops->treestore->data= newdataadr(fd, soops->treestore->data);
5132
5872
                                        /* we only saved what was used */
5133
5873
                                        soops->treestore->totelem= soops->treestore->usedelem;
5134
5874
                                        soops->storeflag |= SO_TREESTORE_CLEANUP;       // at first draw
5135
5875
                                }
5136
5876
                        }
5137
 
                        else if(sl->spacetype==SPACE_IMAGE) {
 
5877
                        else if (sl->spacetype==SPACE_IMAGE) {
5138
5878
                                SpaceImage *sima= (SpaceImage *)sl;
5139
5879
                                
5140
5880
                                sima->cumap= newdataadr(fd, sima->cumap);
5141
 
                                if(sima->cumap)
 
5881
                                if (sima->cumap)
5142
5882
                                        direct_link_curvemapping(fd, sima->cumap);
5143
5883
                                
5144
5884
                                sima->iuser.scene= NULL;
5151
5891
                                
5152
5892
                                /* WARNING: gpencil data is no longer stored directly in sima after 2.5 
5153
5893
                                 * so sacrifice a few old files for now to avoid crashes with new files!
5154
 
                                 */
5155
 
                                //sima->gpd= newdataadr(fd, sima->gpd);
5156
 
                                //if (sima->gpd)
5157
 
                                //      direct_link_gpencil(fd, sima->gpd);
 
5894
                                 * committed: r28002 */
 
5895
#if 0
 
5896
                                sima->gpd= newdataadr(fd, sima->gpd);
 
5897
                                if (sima->gpd)
 
5898
                                        direct_link_gpencil(fd, sima->gpd);
 
5899
#endif
5158
5900
                        }
5159
 
                        else if(sl->spacetype==SPACE_NODE) {
 
5901
                        else if (sl->spacetype==SPACE_NODE) {
5160
5902
                                SpaceNode *snode= (SpaceNode *)sl;
5161
5903
                                
5162
 
                                if(snode->gpd) {
 
5904
                                if (snode->gpd) {
5163
5905
                                        snode->gpd= newdataadr(fd, snode->gpd);
5164
5906
                                        direct_link_gpencil(fd, snode->gpd);
5165
5907
                                }
5166
 
                                snode->nodetree= snode->edittree= NULL;
5167
5908
                        }
5168
 
                        else if(sl->spacetype==SPACE_TIME) {
 
5909
                        else if (sl->spacetype==SPACE_TIME) {
5169
5910
                                SpaceTime *stime= (SpaceTime *)sl;
5170
5911
                                stime->caches.first= stime->caches.last= NULL;
5171
5912
                        }
5172
 
                        else if(sl->spacetype==SPACE_LOGIC) {
 
5913
                        else if (sl->spacetype==SPACE_LOGIC) {
5173
5914
                                SpaceLogic *slogic= (SpaceLogic *)sl;
5174
5915
                                        
5175
 
                                if(slogic->gpd) {
 
5916
                                if (slogic->gpd) {
5176
5917
                                        slogic->gpd= newdataadr(fd, slogic->gpd);
5177
5918
                                        direct_link_gpencil(fd, slogic->gpd);
5178
5919
                                }
5179
5920
                        }
5180
 
                        else if(sl->spacetype==SPACE_SEQ) {
 
5921
                        else if (sl->spacetype==SPACE_SEQ) {
5181
5922
                                SpaceSeq *sseq= (SpaceSeq *)sl;
5182
 
                                if(sseq->gpd) {
 
5923
                                if (sseq->gpd) {
5183
5924
                                        sseq->gpd= newdataadr(fd, sseq->gpd);
5184
5925
                                        direct_link_gpencil(fd, sseq->gpd);
5185
5926
                                }
5186
5927
                        }
5187
 
                        else if(sl->spacetype==SPACE_BUTS) {
 
5928
                        else if (sl->spacetype==SPACE_BUTS) {
5188
5929
                                SpaceButs *sbuts= (SpaceButs *)sl;
5189
5930
                                sbuts->path= NULL;
 
5931
                                sbuts->texuser= NULL;
5190
5932
                        }
5191
 
                        else if(sl->spacetype==SPACE_CONSOLE) {
 
5933
                        else if (sl->spacetype==SPACE_CONSOLE) {
5192
5934
                                SpaceConsole *sconsole= (SpaceConsole *)sl;
5193
5935
                                ConsoleLine *cl, *cl_next;
5194
5936
                                
5195
5937
                                link_list(fd, &sconsole->scrollback);
5196
5938
                                link_list(fd, &sconsole->history);
5197
5939
                                
5198
 
                                //for(cl= sconsole->scrollback.first; cl; cl= cl->next)
 
5940
                                //for (cl= sconsole->scrollback.first; cl; cl= cl->next)
5199
5941
                                //      cl->line= newdataadr(fd, cl->line);
5200
5942
                                
5201
 
                                /*comma expressions, (e.g. expr1, expr2, expr3) evalutate each expression,
5202
 
                                  from left to right.  the right-most expression sets the result of the comma
5203
 
                                  expression as a whole*/
5204
 
                                for(cl= sconsole->history.first; cl; cl= cl_next) {
 
5943
                                /* comma expressions, (e.g. expr1, expr2, expr3) evalutate each expression,
 
5944
                                 * from left to right.  the right-most expression sets the result of the comma
 
5945
                                 * expression as a whole*/
 
5946
                                for (cl= sconsole->history.first; cl; cl= cl_next) {
5205
5947
                                        cl_next= cl->next;
5206
5948
                                        cl->line= newdataadr(fd, cl->line);
5207
 
                                        if (cl->line == NULL) {
 
5949
                                        if (cl->line) {
 
5950
                                                /* the allocted length is not written, so reset here */
 
5951
                                                cl->len_alloc= cl->len + 1;
 
5952
                                        }
 
5953
                                        else {
5208
5954
                                                BLI_remlink(&sconsole->history, cl);
5209
5955
                                                MEM_freeN(cl);
5210
5956
                                        }
5211
5957
                                }
5212
5958
                        }
5213
 
                        else if(sl->spacetype==SPACE_FILE) {
 
5959
                        else if (sl->spacetype==SPACE_FILE) {
5214
5960
                                SpaceFile *sfile= (SpaceFile *)sl;
5215
5961
                                
5216
5962
                                /* this sort of info is probably irrelevant for reloading...
5220
5966
                                sfile->files= NULL;
5221
5967
                                sfile->layout= NULL;
5222
5968
                                sfile->op= NULL;
5223
 
                                sfile->params= NULL;
 
5969
                                sfile->params= newdataadr(fd, sfile->params);
5224
5970
                        }
5225
5971
                }
5226
5972
                
5240
5986
{
5241
5987
        Main *newmain;
5242
5988
        
5243
 
        for(newmain= fd->mainlist.first; newmain; newmain= newmain->next) {
5244
 
                if(newmain->curlib) {
5245
 
                        if(strcmp(newmain->curlib->filepath, lib->filepath)==0) {
5246
 
                                printf("Fixed error in file; multiple instances of lib:\n %s\n", lib->filepath);
5247
 
                                
 
5989
        for (newmain= fd->mainlist.first; newmain; newmain= newmain->next) {
 
5990
                if (newmain->curlib) {
 
5991
                        if (BLI_path_cmp(newmain->curlib->filepath, lib->filepath) == 0) {
 
5992
                                BKE_reportf_wrap(fd->reports, RPT_WARNING,
 
5993
                                                 "Library '%s', '%s' had multiple instances, save and reload!",
 
5994
                                                 lib->name, lib->filepath);
 
5995
 
5248
5996
                                change_idid_adr(&fd->mainlist, fd, lib, newmain->curlib);
5249
5997
//                              change_idid_adr_fd(fd, lib, newmain->curlib);
5250
5998
                                
5251
5999
                                BLI_remlink(&main->library, lib);
5252
6000
                                MEM_freeN(lib);
5253
 
                                
5254
 
                                BKE_report(fd->reports, RPT_WARNING, "Library had multiple instances, save and reload!");
 
6001
 
5255
6002
 
5256
6003
                                return;
5257
6004
                        }
5272
6019
        lib->parent= NULL;
5273
6020
}
5274
6021
 
5275
 
static void lib_link_library(FileData *fd, Main *main)
 
6022
static void lib_link_library(FileData *UNUSED(fd), Main *main)
5276
6023
{
5277
6024
        Library *lib;
5278
 
        for(lib= main->library.first; lib; lib= lib->id.next) {
 
6025
        for (lib= main->library.first; lib; lib= lib->id.next) {
5279
6026
                lib->id.us= 1;
5280
6027
        }
5281
6028
}
5282
6029
 
5283
 
/* Always call this once you havbe loaded new library data to set the relative paths correctly in relation to the blend file */
 
6030
/* Always call this once you have loaded new library data to set the relative paths correctly in relation to the blend file */
5284
6031
static void fix_relpaths_library(const char *basepath, Main *main)
5285
6032
{
5286
6033
        Library *lib;
5287
6034
        /* BLO_read_from_memory uses a blank filename */
5288
 
        if (basepath==NULL || basepath[0] == '\0')
5289
 
                return;
5290
 
                
5291
 
        for(lib= main->library.first; lib; lib= lib->id.next) {
5292
 
                /* Libraries store both relative and abs paths, recreate relative paths,
5293
 
                 * relative to the blend file since indirectly linked libs will be relative to their direct linked library */
5294
 
                if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
5295
 
                        strncpy(lib->name, lib->filepath, sizeof(lib->name));
5296
 
                        BLI_path_rel(lib->name, basepath);
5297
 
                }
5298
 
        }
 
6035
        if (basepath==NULL || basepath[0] == '\0') {
 
6036
                for (lib= main->library.first; lib; lib= lib->id.next) {
 
6037
                        /* when loading a linked lib into a file which has not been saved,
 
6038
                         * there is nothing we can be relative to, so instead we need to make
 
6039
                         * it absolute. This can happen when appending an object with a relative
 
6040
                         * link into an unsaved blend file. See [#27405].
 
6041
                         * The remap relative option will make it relative again on save - campbell */
 
6042
                        if (strncmp(lib->name, "//", 2)==0) {
 
6043
                                BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name));
 
6044
                        }
 
6045
                }
 
6046
        }
 
6047
        else {
 
6048
                for (lib= main->library.first; lib; lib= lib->id.next) {
 
6049
                        /* Libraries store both relative and abs paths, recreate relative paths,
 
6050
                         * relative to the blend file since indirectly linked libs will be relative to their direct linked library */
 
6051
                        if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
 
6052
                                BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name));
 
6053
                                BLI_path_rel(lib->name, basepath);
 
6054
                        }
 
6055
                }
 
6056
        }
 
6057
}
 
6058
 
 
6059
/* ************ READ SPEAKER ***************** */
 
6060
 
 
6061
static void lib_link_speaker(FileData *fd, Main *main)
 
6062
{
 
6063
        Speaker *spk;
 
6064
 
 
6065
        spk= main->speaker.first;
 
6066
        while (spk) {
 
6067
                if (spk->id.flag & LIB_NEEDLINK) {
 
6068
                        if (spk->adt) lib_link_animdata(fd, &spk->id, spk->adt);
 
6069
 
 
6070
                        spk->sound= newlibadr(fd, spk->id.lib, spk->sound);
 
6071
                        if (spk->sound) {
 
6072
                                spk->sound->id.us++;
 
6073
                        }
 
6074
 
 
6075
                        spk->id.flag -= LIB_NEEDLINK;
 
6076
                }
 
6077
                spk= spk->id.next;
 
6078
        }
 
6079
}
 
6080
 
 
6081
static void direct_link_speaker(FileData *fd, Speaker *spk)
 
6082
{
 
6083
        spk->adt= newdataadr(fd, spk->adt);
 
6084
        direct_link_animdata(fd, spk->adt);
 
6085
 
 
6086
#if 0
 
6087
        spk->sound= newdataadr(fd, spk->sound);
 
6088
        direct_link_sound(fd, spk->sound);
 
6089
#endif
5299
6090
}
5300
6091
 
5301
6092
/* ************** READ SOUND ******************* */
5304
6095
{
5305
6096
        sound->handle = NULL;
5306
6097
        sound->playback_handle = NULL;
 
6098
        sound->waveform = NULL;
 
6099
 
 
6100
        // versioning stuff, if there was a cache, then we enable caching:
 
6101
        if (sound->cache)
 
6102
        {
 
6103
                sound->flags |= SOUND_FLAGS_CACHING;
 
6104
                sound->cache = NULL;
 
6105
        }
5307
6106
 
5308
6107
        sound->packedfile = direct_link_packedfile(fd, sound->packedfile);
5309
6108
        sound->newpackedfile = direct_link_packedfile(fd, sound->newpackedfile);
5314
6113
        bSound *sound;
5315
6114
 
5316
6115
        sound= main->sound.first;
5317
 
        while(sound) {
5318
 
                if(sound->id.flag & LIB_NEEDLINK) {
 
6116
        while (sound) {
 
6117
                if (sound->id.flag & LIB_NEEDLINK) {
5319
6118
                        sound->id.flag -= LIB_NEEDLINK;
5320
6119
                        sound->ipo= newlibadr_us(fd, sound->id.lib, sound->ipo); // XXX depreceated - old animation system
5321
6120
                        
5322
6121
                        sound_load(main, sound);
5323
 
 
5324
 
                        if(sound->cache)
5325
 
                                sound_cache(sound, 1);
5326
6122
                }
5327
6123
                sound= sound->id.next;
5328
6124
        }
5340
6136
        GroupObject *go;
5341
6137
        int add_us;
5342
6138
        
5343
 
        while(group) {
5344
 
                if(group->id.flag & LIB_NEEDLINK) {
 
6139
        while (group) {
 
6140
                if (group->id.flag & LIB_NEEDLINK) {
5345
6141
                        group->id.flag -= LIB_NEEDLINK;
5346
6142
                        
5347
6143
                        add_us= 0;
5348
6144
                        
5349
6145
                        go= group->gobject.first;
5350
 
                        while(go) {
 
6146
                        while (go) {
5351
6147
                                go->ob= newlibadr(fd, group->id.lib, go->ob);
5352
 
                                if(go->ob) {
 
6148
                                if (go->ob) {
5353
6149
                                        go->ob->flag |= OB_FROMGROUP;
5354
6150
                                        /* if group has an object, it increments user... */
5355
6151
                                        add_us= 1;
5356
 
                                        if(go->ob->id.us==0) 
 
6152
                                        if (go->ob->id.us==0)
5357
6153
                                                go->ob->id.us= 1;
5358
6154
                                }
5359
6155
                                go= go->next;
5360
6156
                        }
5361
 
                        if(add_us) group->id.us++;
 
6157
                        if (add_us) group->id.us++;
5362
6158
                        rem_from_group(group, NULL, NULL, NULL);        /* removes NULL entries */
5363
6159
                }
5364
6160
                group= group->id.next;
5365
6161
        }
5366
6162
}
5367
6163
 
 
6164
/* ***************** READ MOVIECLIP *************** */
 
6165
 
 
6166
static void direct_link_movieReconstruction(FileData *fd, MovieTrackingReconstruction *reconstruction)
 
6167
{
 
6168
        reconstruction->cameras= newdataadr(fd, reconstruction->cameras);
 
6169
}
 
6170
 
 
6171
static void direct_link_movieTracks(FileData *fd, ListBase *tracksbase)
 
6172
{
 
6173
        MovieTrackingTrack *track;
 
6174
 
 
6175
        link_list(fd, tracksbase);
 
6176
 
 
6177
        track= tracksbase->first;
 
6178
        while (track) {
 
6179
                track->markers= newdataadr(fd, track->markers);
 
6180
 
 
6181
                track= track->next;
 
6182
        }
 
6183
}
 
6184
 
 
6185
static void direct_link_movieclip(FileData *fd, MovieClip *clip)
 
6186
{
 
6187
        MovieTracking *tracking= &clip->tracking;
 
6188
        MovieTrackingObject *object;
 
6189
 
 
6190
        clip->adt= newdataadr(fd, clip->adt);
 
6191
 
 
6192
        if (fd->movieclipmap) clip->cache= newmclipadr(fd, clip->cache);
 
6193
        else clip->cache= NULL;
 
6194
 
 
6195
        if (fd->movieclipmap) clip->tracking.camera.intrinsics= newmclipadr(fd, clip->tracking.camera.intrinsics);
 
6196
        else clip->tracking.camera.intrinsics= NULL;
 
6197
 
 
6198
        direct_link_movieTracks(fd, &tracking->tracks);
 
6199
        direct_link_movieReconstruction(fd, &tracking->reconstruction);
 
6200
 
 
6201
        clip->tracking.act_track= newdataadr(fd, clip->tracking.act_track);
 
6202
 
 
6203
        clip->anim= NULL;
 
6204
        clip->tracking_context= NULL;
 
6205
        clip->tracking.stats= NULL;
 
6206
 
 
6207
        clip->tracking.stabilization.ok= 0;
 
6208
        clip->tracking.stabilization.scaleibuf= NULL;
 
6209
        clip->tracking.stabilization.rot_track= newdataadr(fd, clip->tracking.stabilization.rot_track);
 
6210
 
 
6211
        link_list(fd, &tracking->objects);
 
6212
 
 
6213
        object= tracking->objects.first;
 
6214
        while (object) {
 
6215
                direct_link_movieTracks(fd, &object->tracks);
 
6216
                direct_link_movieReconstruction(fd, &object->reconstruction);
 
6217
 
 
6218
                object= object->next;
 
6219
        }
 
6220
}
 
6221
 
 
6222
static void lib_link_movieclip(FileData *fd, Main *main)
 
6223
{
 
6224
        MovieClip *clip;
 
6225
 
 
6226
        clip= main->movieclip.first;
 
6227
        while (clip) {
 
6228
                if (clip->id.flag & LIB_NEEDLINK) {
 
6229
                        if (clip->adt)
 
6230
                                lib_link_animdata(fd, &clip->id, clip->adt);
 
6231
 
 
6232
                        clip->gpd= newlibadr_us(fd, clip->id.lib, clip->gpd);
 
6233
 
 
6234
                        clip->id.flag -= LIB_NEEDLINK;
 
6235
                }
 
6236
                clip= clip->id.next;
 
6237
        }
 
6238
}
 
6239
 
5368
6240
/* ************** GENERAL & MAIN ******************** */
5369
6241
 
5370
6242
 
5371
 
static char *dataname(short id_code)
 
6243
static const char *dataname(short id_code)
5372
6244
{
5373
6245
        
5374
6246
        switch( id_code ) {
5393
6265
                case ID_SCR: return "Data from SCR";
5394
6266
                case ID_VF: return "Data from VF";
5395
6267
                case ID_TXT     : return "Data from TXT";
 
6268
                case ID_SPK: return "Data from SPK";
5396
6269
                case ID_SO: return "Data from SO";
5397
6270
                case ID_NT: return "Data from NT";
5398
6271
                case ID_BR: return "Data from BR";
5399
6272
                case ID_PA: return "Data from PA";
5400
6273
                case ID_GD: return "Data from GD";
 
6274
                case ID_MC: return "Data from MC";
5401
6275
        }
5402
6276
        return "Data from Lib Block";
5403
6277
        
5404
6278
}
5405
6279
 
5406
 
static BHead *read_data_into_oldnewmap(FileData *fd, BHead *bhead, char *allocname)
 
6280
static BHead *read_data_into_oldnewmap(FileData *fd, BHead *bhead, const char *allocname)
5407
6281
{
5408
6282
        bhead = blo_nextbhead(fd, bhead);
5409
6283
 
5410
 
        while(bhead && bhead->code==DATA) {
 
6284
        while (bhead && bhead->code==DATA) {
5411
6285
                void *data;
5412
6286
#if 0
5413
 
                /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */         
 
6287
                /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */
5414
6288
                short *sp= fd->filesdna->structs[bhead->SDNAnr];
5415
 
                char *allocname = fd->filesdna->types[ sp[0] ];
5416
6289
                char *tmp= malloc(100);
5417
 
                
 
6290
                allocname = fd->filesdna->types[ sp[0] ];
5418
6291
                strcpy(tmp, allocname);
5419
6292
                data= read_struct(fd, bhead, tmp);
5420
6293
#else
5439
6312
 
5440
6313
        ID *id;
5441
6314
        ListBase *lb;
5442
 
        char *allocname;
 
6315
        const char *allocname;
5443
6316
        
5444
6317
        /* read libblock */
5445
6318
        id = read_struct(fd, bhead, "lib block");
5451
6324
        oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);      /* for ID_ID check */
5452
6325
        
5453
6326
        /* do after read_struct, for dna reconstruct */
5454
 
        if(bhead->code==ID_ID) {
 
6327
        if (bhead->code==ID_ID) {
5455
6328
                lb= which_libbase(main, GS(id->name));
5456
6329
        }
5457
6330
        else {
5463
6336
        /* clear first 8 bits */
5464
6337
        id->flag= (id->flag & 0xFF00) | flag | LIB_NEEDLINK;
5465
6338
        id->lib= main->curlib;
5466
 
        if(id->flag & LIB_FAKEUSER) id->us= 1;
 
6339
        if (id->flag & LIB_FAKEUSER) id->us= 1;
5467
6340
        else id->us= 0;
5468
6341
        id->icon_id = 0;
 
6342
        id->flag &= ~(LIB_ID_RECALC|LIB_ID_RECALC_DATA);
5469
6343
 
5470
6344
        /* this case cannot be direct_linked: it's just the ID part */
5471
 
        if(bhead->code==ID_ID) {
 
6345
        if (bhead->code==ID_ID) {
5472
6346
                return blo_nextbhead(fd, bhead);
5473
6347
        }
5474
6348
 
5537
6411
                case ID_CA:
5538
6412
                        direct_link_camera(fd, (Camera *)id);
5539
6413
                        break;
 
6414
                case ID_SPK:
 
6415
                        direct_link_speaker(fd, (Speaker *)id);
 
6416
                        break;
5540
6417
                case ID_SO:
5541
6418
                        direct_link_sound(fd, (bSound *)id);
5542
6419
                        break;
5564
6441
                case ID_GD:
5565
6442
                        direct_link_gpencil(fd, (bGPdata *)id);
5566
6443
                        break;
 
6444
                case ID_MC:
 
6445
                        direct_link_movieclip(fd, (MovieClip *)id);
 
6446
                        break;
5567
6447
        }
5568
6448
        
5569
6449
        /*link direct data of ID properties*/
5590
6470
        bfd->main->subversionfile= fg->subversion;
5591
6471
        bfd->main->minversionfile= fg->minversion;
5592
6472
        bfd->main->minsubversionfile= fg->minsubversion;
 
6473
        bfd->main->revision= fg->revision;
5593
6474
        
5594
6475
        bfd->winpos= fg->winpos;
5595
6476
        bfd->fileflags= fg->fileflags;
5596
6477
        bfd->displaymode= fg->displaymode;
5597
6478
        bfd->globalf= fg->globalf;
5598
6479
        BLI_strncpy(bfd->filename, fg->filename, sizeof(bfd->filename));
5599
 
        if(G.fileflags & G_FILE_RECOVER)
 
6480
        
 
6481
        if (G.fileflags & G_FILE_RECOVER)
5600
6482
                BLI_strncpy(fd->relabase, fg->filename, sizeof(fd->relabase));
5601
6483
        
5602
6484
        bfd->curscreen= fg->curscreen;
5614
6496
static void link_global(FileData *fd, BlendFileData *bfd)
5615
6497
{
5616
6498
        
5617
 
        bfd->curscreen= newlibadr(fd, 0, bfd->curscreen);
5618
 
        bfd->curscene= newlibadr(fd, 0, bfd->curscene);
 
6499
        bfd->curscreen= newlibadr(fd, NULL, bfd->curscreen);
 
6500
        bfd->curscene= newlibadr(fd, NULL, bfd->curscene);
5619
6501
        // this happens in files older than 2.35
5620
 
        if(bfd->curscene==NULL) {
5621
 
                if(bfd->curscreen) bfd->curscene= bfd->curscreen->scene;
 
6502
        if (bfd->curscene==NULL) {
 
6503
                if (bfd->curscreen) bfd->curscene= bfd->curscreen->scene;
5622
6504
        }
5623
6505
}
5624
6506
 
5628
6510
        unsigned int *mcol, *mcoln, *mcolmain;
5629
6511
        int a;
5630
6512
 
5631
 
        if(me->totface==0 || me->mcol==0) return;
 
6513
        if (me->totface==0 || me->mcol==NULL) return;
5632
6514
 
5633
6515
        mcoln= mcolmain= MEM_mallocN(4*sizeof(int)*me->totface, "mcoln");
5634
6516
        mcol = (unsigned int *)me->mcol;
5635
6517
        mface= me->mface;
5636
 
        for(a=me->totface; a>0; a--, mface++) {
 
6518
        for (a=me->totface; a>0; a--, mface++) {
5637
6519
                mcoln[0]= mcol[mface->v1];
5638
6520
                mcoln[1]= mcol[mface->v2];
5639
6521
                mcoln[2]= mcol[mface->v3];
5664
6546
        }
5665
6547
}
5666
6548
 
 
6549
static void do_version_bone_head_tail_237(Bone *bone)
 
6550
{
 
6551
        Bone *child;
 
6552
        float vec[3];
 
6553
 
 
6554
        /* head */
 
6555
        copy_v3_v3(bone->arm_head, bone->arm_mat[3]);
 
6556
 
 
6557
        /* tail is in current local coord system */
 
6558
        copy_v3_v3(vec, bone->arm_mat[1]);
 
6559
        mul_v3_fl(vec, bone->length);
 
6560
        add_v3_v3v3(bone->arm_tail, bone->arm_head, vec);
 
6561
 
 
6562
        for (child= bone->childbase.first; child; child= child->next)
 
6563
                do_version_bone_head_tail_237(child);
 
6564
}
 
6565
 
5667
6566
static void bone_version_238(ListBase *lb)
5668
6567
{
5669
6568
        Bone *bone;
5670
6569
        
5671
 
        for(bone= lb->first; bone; bone= bone->next) {
5672
 
                if(bone->rad_tail==0.0f && bone->rad_head==0.0f) {
 
6570
        for (bone= lb->first; bone; bone= bone->next) {
 
6571
                if (bone->rad_tail==0.0f && bone->rad_head==0.0f) {
5673
6572
                        bone->rad_head= 0.25f*bone->length;
5674
6573
                        bone->rad_tail= 0.1f*bone->length;
5675
6574
                        
5676
6575
                        bone->dist-= bone->rad_head;
5677
 
                        if(bone->dist<=0.0f) bone->dist= 0.0f;
 
6576
                        if (bone->dist<=0.0f) bone->dist= 0.0f;
5678
6577
                }
5679
6578
                bone_version_238(&bone->childbase);
5680
6579
        }
5684
6583
{
5685
6584
        Bone *bone;
5686
6585
        
5687
 
        for(bone= lb->first; bone; bone= bone->next) {
5688
 
                if(bone->layer==0) 
 
6586
        for (bone= lb->first; bone; bone= bone->next) {
 
6587
                if (bone->layer==0)
5689
6588
                        bone->layer= 1;
5690
6589
                bone_version_239(&bone->childbase);
5691
6590
        }
5695
6594
{
5696
6595
        bNode *node;
5697
6596
        
5698
 
        if(ntree->type==NTREE_COMPOSIT) {
5699
 
                for(node= ntree->nodes.first; node; node= node->next) {
5700
 
                        if(node->type==CMP_NODE_BLUR) {
5701
 
                                if(node->storage==NULL) {
 
6597
        if (ntree->type==NTREE_COMPOSIT) {
 
6598
                for (node= ntree->nodes.first; node; node= node->next) {
 
6599
                        if (node->type==CMP_NODE_BLUR) {
 
6600
                                if (node->storage==NULL) {
5702
6601
                                        NodeBlurData *nbd= MEM_callocN(sizeof(NodeBlurData), "node blur patch");
5703
6602
                                        nbd->sizex= node->custom1;
5704
6603
                                        nbd->sizey= node->custom2;
5706
6605
                                        node->storage= nbd;
5707
6606
                                }
5708
6607
                        }
5709
 
                        else if(node->type==CMP_NODE_VECBLUR) {
5710
 
                                if(node->storage==NULL) {
 
6608
                        else if (node->type==CMP_NODE_VECBLUR) {
 
6609
                                if (node->storage==NULL) {
5711
6610
                                        NodeBlurData *nbd= MEM_callocN(sizeof(NodeBlurData), "node blur patch");
5712
6611
                                        nbd->samples= node->custom1;
5713
6612
                                        nbd->maxspeed= node->custom2;
5723
6622
{
5724
6623
        bNode *node;
5725
6624
        
5726
 
        if(ntree->type==NTREE_COMPOSIT) {
5727
 
                for(node= ntree->nodes.first; node; node= node->next) {
5728
 
                        if(node->type==CMP_NODE_HUE_SAT) {
5729
 
                                if(node->storage) {
 
6625
        if (ntree->type==NTREE_COMPOSIT) {
 
6626
                for (node= ntree->nodes.first; node; node= node->next) {
 
6627
                        if (node->type==CMP_NODE_HUE_SAT) {
 
6628
                                if (node->storage) {
5730
6629
                                        NodeHueSat *nhs= node->storage;
5731
 
                                        if(nhs->val==0.0f) nhs->val= 1.0f;
 
6630
                                        if (nhs->val==0.0f) nhs->val= 1.0f;
5732
6631
                                }
5733
6632
                        }
5734
6633
                }
5735
6634
        }
5736
 
        else if(ntree->type==NTREE_SHADER) {
5737
 
                for(node= ntree->nodes.first; node; node= node->next)
5738
 
                        if(node->type == SH_NODE_GEOMETRY && node->storage == NULL)
 
6635
        else if (ntree->type==NTREE_SHADER) {
 
6636
                for (node= ntree->nodes.first; node; node= node->next)
 
6637
                        if (node->type == SH_NODE_GEOMETRY && node->storage == NULL)
5739
6638
                                node->storage= MEM_callocN(sizeof(NodeGeometry), "NodeGeometry");
5740
6639
        }
5741
6640
        
5742
6641
}
5743
6642
 
5744
 
 
5745
 
/* somehow, probably importing via python, keyblock adrcodes are not in order */
5746
 
static void sort_shape_fix(Main *main)
5747
 
{
5748
 
        Key *key;
5749
 
        KeyBlock *kb;
5750
 
        int sorted= 0;
5751
 
        
5752
 
        while(sorted==0) {
5753
 
                sorted= 1;
5754
 
                for(key= main->key.first; key; key= key->id.next) {
5755
 
                        for(kb= key->block.first; kb; kb= kb->next) {
5756
 
                                if(kb->next && kb->adrcode>kb->next->adrcode) {
5757
 
                                        KeyBlock *next= kb->next;
5758
 
                                        BLI_remlink(&key->block, kb);
5759
 
                                        BLI_insertlink(&key->block, next, kb);
5760
 
                                        kb= next;
5761
 
                                        sorted= 0;
5762
 
                                }
5763
 
                        }
5764
 
                }
5765
 
                if(sorted==0) printf("warning, shape keys were sorted incorrect, fixed it!\n");
5766
 
        }
5767
 
}
5768
 
 
5769
6643
static void customdata_version_242(Mesh *me)
5770
6644
{
5771
6645
        CustomDataLayer *layer;
5830
6704
 
5831
6705
                if (layer->type == CD_MTFACE) {
5832
6706
                        if (layer->name[0] == 0) {
5833
 
                                if (mtfacen == 0) strcpy(layer->name, "UVTex");
5834
 
                                else sprintf(layer->name, "UVTex.%.3d", mtfacen);
 
6707
                                if (mtfacen == 0) strcpy(layer->name, "UVMap");
 
6708
                                else BLI_snprintf(layer->name, sizeof(layer->name), "UVMap.%.3d", mtfacen);
5835
6709
                        }
5836
6710
                        mtfacen++;
5837
6711
                }
5838
6712
                else if (layer->type == CD_MCOL) {
5839
6713
                        if (layer->name[0] == 0) {
5840
6714
                                if (mcoln == 0) strcpy(layer->name, "Col");
5841
 
                                else sprintf(layer->name, "Col.%.3d", mcoln);
 
6715
                                else BLI_snprintf(layer->name, sizeof(layer->name), "Col.%.3d", mcoln);
5842
6716
                        }
5843
6717
                        mcoln++;
5844
6718
                }
5845
6719
        }
5846
6720
 
5847
 
        mesh_update_customdata_pointers(me);
 
6721
        mesh_update_customdata_pointers(me, TRUE);
5848
6722
}
5849
6723
 
5850
6724
/*only copy render texface layer from active*/
5864
6738
{
5865
6739
        bNode *node;
5866
6740
        
5867
 
        if(ntree->type==NTREE_COMPOSIT) {
5868
 
                for(node= ntree->nodes.first; node; node= node->next) {
5869
 
                        if(ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
 
6741
        if (ntree->type==NTREE_COMPOSIT) {
 
6742
                for (node= ntree->nodes.first; node; node= node->next) {
 
6743
                        if (ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
5870
6744
                                /* only image had storage */
5871
 
                                if(node->storage) {
 
6745
                                if (node->storage) {
5872
6746
                                        NodeImageAnim *nia= node->storage;
5873
6747
                                        ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "ima user node");
5874
6748
 
5901
6775
        Image *image;
5902
6776
        ImageUser *iuser;
5903
6777
 
5904
 
        if(ntree->type==NTREE_COMPOSIT) {
5905
 
                for(node= ntree->nodes.first; node; node= node->next) {
5906
 
                        if(node->type == CMP_NODE_ALPHAOVER) {
5907
 
                                if(!node->storage) {
 
6778
        if (ntree->type==NTREE_COMPOSIT) {
 
6779
                for (node= ntree->nodes.first; node; node= node->next) {
 
6780
                        if (node->type == CMP_NODE_ALPHAOVER) {
 
6781
                                if (!node->storage) {
5908
6782
                                        ntf= MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats");
5909
6783
                                        node->storage= ntf;
5910
 
                                        if(node->custom1)
 
6784
                                        if (node->custom1)
5911
6785
                                                ntf->x= 1.0f;
5912
6786
                                }
5913
6787
                        }
5914
6788
                        
5915
6789
                        /* fix for temporary flag changes during 245 cycle */
5916
6790
                        nodeid= newlibadr(fd, lib, node->id);
5917
 
                        if(node->storage && nodeid && GS(nodeid->name) == ID_IM) {
 
6791
                        if (node->storage && nodeid && GS(nodeid->name) == ID_IM) {
5918
6792
                                image= (Image*)nodeid;
5919
6793
                                iuser= node->storage;
5920
 
                                if(iuser->flag & IMA_OLD_PREMUL) {
 
6794
                                if (iuser->flag & IMA_OLD_PREMUL) {
5921
6795
                                        iuser->flag &= ~IMA_OLD_PREMUL;
5922
6796
                                        iuser->flag |= IMA_DO_PREMUL;
5923
6797
                                }
5924
 
                                if(iuser->flag & IMA_DO_PREMUL) {
 
6798
                                if (iuser->flag & IMA_DO_PREMUL) {
5925
6799
                                        image->flag &= ~IMA_OLD_PREMUL;
5926
6800
                                        image->flag |= IMA_DO_PREMUL;
5927
6801
                                }
5964
6838
        int a, b, texalpha;
5965
6839
 
5966
6840
        /* verify we have a tface layer */
5967
 
        for(b=0; b<me->fdata.totlayer; b++)
5968
 
                if(me->fdata.layers[b].type == CD_MTFACE)
 
6841
        for (b=0; b<me->fdata.totlayer; b++)
 
6842
                if (me->fdata.layers[b].type == CD_MTFACE)
5969
6843
                        break;
5970
6844
        
5971
 
        if(b == me->fdata.totlayer)
 
6845
        if (b == me->fdata.totlayer)
5972
6846
                return;
5973
6847
 
5974
6848
        /* if we do, set alpha sort if the game engine did it before */
5975
 
        for(a=0, mf=me->mface; a<me->totface; a++, mf++) {
5976
 
                if(mf->mat_nr < me->totcol) {
5977
 
                        ma= newlibadr(fd, lib, me->mat[(int)mf->mat_nr]);
 
6849
        for (a=0, mf=me->mface; a<me->totface; a++, mf++) {
 
6850
                if (mf->mat_nr < me->totcol) {
 
6851
                        ma= newlibadr(fd, lib, me->mat[mf->mat_nr]);
5978
6852
                        texalpha = 0;
5979
6853
 
5980
6854
                        /* we can't read from this if it comes from a library,
5981
6855
                         * because direct_link might not have happened on it,
5982
6856
                         * so ma->mtex is not pointing to valid memory yet */
5983
 
                        if(ma && ma->id.lib)
 
6857
                        if (ma && ma->id.lib)
5984
6858
                                ma= NULL;
5985
6859
 
5986
 
                        for(b=0; ma && b<MAX_MTEX; b++)
5987
 
                                if(ma->mtex && ma->mtex[b] && ma->mtex[b]->mapto & MAP_ALPHA)
 
6860
                        for (b=0; ma && b<MAX_MTEX; b++)
 
6861
                                if (ma->mtex && ma->mtex[b] && ma->mtex[b]->mapto & MAP_ALPHA)
5988
6862
                                        texalpha = 1;
5989
6863
                }
5990
6864
                else {
5992
6866
                        texalpha = 0;
5993
6867
                }
5994
6868
 
5995
 
                for(b=0; b<me->fdata.totlayer; b++) {
5996
 
                        if(me->fdata.layers[b].type == CD_MTFACE) {
 
6869
                for (b=0; b<me->fdata.totlayer; b++) {
 
6870
                        if (me->fdata.layers[b].type == CD_MTFACE) {
5997
6871
                                tf = ((MTFace*)me->fdata.layers[b].data) + a;
5998
6872
 
5999
6873
                                tf->mode &= ~TF_ALPHASORT;
6000
 
                                if(ma && (ma->mode & MA_ZTRANSP))
6001
 
                                        if(ELEM(tf->transp, TF_ALPHA, TF_ADD) || (texalpha && (tf->transp != TF_CLIP)))
 
6874
                                if (ma && (ma->mode & MA_ZTRANSP))
 
6875
                                        if (ELEM(tf->transp, TF_ALPHA, TF_ADD) || (texalpha && (tf->transp != TF_CLIP)))
6002
6876
                                                tf->mode |= TF_ALPHASORT;
6003
6877
                        }
6004
6878
                }
6012
6886
        
6013
6887
        BLI_addtail(lb, ar);
6014
6888
        ar->regiontype= RGN_TYPE_HEADER;
6015
 
        if(sa->headertype==1)
 
6889
        if (sa->headertype==HEADERDOWN)
6016
6890
                ar->alignment= RGN_ALIGN_BOTTOM;
6017
6891
        else
6018
6892
                ar->alignment= RGN_ALIGN_TOP;
6019
6893
        
6020
 
        /* initialise view2d data for header region, to allow panning */
 
6894
        /* initialize view2d data for header region, to allow panning */
6021
6895
        /* is copy from ui_view2d.c */
6022
6896
        ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
6023
6897
        ar->v2d.keepofs = V2D_LOCKOFS_Y;
6036
6910
        ar->v2d.keepzoom= V2D_KEEPASPECT | V2D_KEEPZOOM;
6037
6911
        ar->v2d.minzoom= 0.00001f;
6038
6912
        ar->v2d.maxzoom= 100000.0f;
6039
 
        ar->v2d.tot.xmin= -960.0f; /* 1920 width centered */
6040
 
        ar->v2d.tot.ymin= -540.0f; /* 1080 height centered */
6041
 
        ar->v2d.tot.xmax= 960.0f;
6042
 
        ar->v2d.tot.ymax= 540.0f;
 
6913
        ar->v2d.tot.xmin = -960.0f; /* 1920 width centered */
 
6914
        ar->v2d.tot.ymin = -540.0f; /* 1080 height centered */
 
6915
        ar->v2d.tot.xmax = 960.0f;
 
6916
        ar->v2d.tot.ymax = 540.0f;
6043
6917
        ar->v2d.min[0]= 0.0f;
6044
6918
        ar->v2d.min[1]= 0.0f;
6045
6919
        ar->v2d.max[0]= 12000.0f;
6055
6929
        ARegion *ar;
6056
6930
        ARegion *ar_main;
6057
6931
 
6058
 
        if(sl) {
 
6932
        if (sl) {
6059
6933
                /* first channels for ipo action nla... */
6060
6934
                switch(sl->spacetype) {
6061
6935
                        case SPACE_IPO:
6103
6977
                        case SPACE_NODE:
6104
6978
                                ar= MEM_callocN(sizeof(ARegion), "nodetree area for node");
6105
6979
                                BLI_addtail(lb, ar);
6106
 
                                ar->regiontype= RGN_TYPE_CHANNELS;
 
6980
                                ar->regiontype= RGN_TYPE_UI;
6107
6981
                                ar->alignment= RGN_ALIGN_LEFT;
6108
6982
                                ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
6109
6983
                                ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
6176
7050
        
6177
7051
        ar->regiontype= RGN_TYPE_WINDOW;
6178
7052
        
6179
 
        if(sl) {
 
7053
        if (sl) {
6180
7054
                /* if active spacetype has view2d data, copy that over to main region */
6181
7055
                /* and we split view3d */
6182
7056
                switch(sl->spacetype) {
6208
7082
                                ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
6209
7083
                                ar->v2d.keepofs |= V2D_LOCKOFS_Y;
6210
7084
                                ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
6211
 
                                ar->v2d.tot.ymin= ar->v2d.cur.ymin= -10.0;
 
7085
                                ar->v2d.tot.ymin = ar->v2d.cur.ymin = -10.0;
6212
7086
                                ar->v2d.min[1]= ar->v2d.max[1]= 20.0;
6213
7087
                        }
6214
7088
                                break;
6230
7104
                                //ar->v2d.flag |= V2D_IS_INITIALISED;
6231
7105
                                break;
6232
7106
                        }
6233
 
                        case SPACE_SOUND:
6234
 
                        {
6235
 
                                SpaceSound *ssound= (SpaceSound *)sl;
6236
 
                                memcpy(&ar->v2d, &ssound->v2d, sizeof(View2D));
6237
 
                                
6238
 
                                ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
6239
 
                                ar->v2d.scroll |= (V2D_SCROLL_LEFT);
6240
 
                                //ar->v2d.flag |= V2D_IS_INITIALISED;
6241
 
                                break;
6242
 
                        }
6243
7107
                        case SPACE_NLA:
6244
7108
                        {
6245
7109
                                SpaceNla *snla= (SpaceNla *)sl;
6246
7110
                                memcpy(&ar->v2d, &snla->v2d, sizeof(View2D));
6247
7111
                                
6248
 
                                ar->v2d.tot.ymin= (float)(-sa->winy)/3.0f;
6249
 
                                ar->v2d.tot.ymax= 0.0f;
 
7112
                                ar->v2d.tot.ymin = (float)(-sa->winy)/3.0f;
 
7113
                                ar->v2d.tot.ymax = 0.0f;
6250
7114
                                
6251
7115
                                ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
6252
7116
                                ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
6256
7120
                        }
6257
7121
                        case SPACE_ACTION:
6258
7122
                        {
 
7123
                                SpaceAction *saction= (SpaceAction *)sl;
 
7124
                                
6259
7125
                                /* we totally reinit the view for the Action Editor, as some old instances had some weird cruft set */
6260
 
                                ar->v2d.tot.xmin= -20.0f;
6261
 
                                ar->v2d.tot.ymin= (float)(-sa->winy)/3.0f;
6262
 
                                ar->v2d.tot.xmax= (float)((sa->winx > 120)? (sa->winx) : 120);
6263
 
                                ar->v2d.tot.ymax= 0.0f;
 
7126
                                ar->v2d.tot.xmin = -20.0f;
 
7127
                                ar->v2d.tot.ymin = (float)(-sa->winy)/3.0f;
 
7128
                                ar->v2d.tot.xmax = (float)((sa->winx > 120)? (sa->winx) : 120);
 
7129
                                ar->v2d.tot.ymax = 0.0f;
6264
7130
                                
6265
7131
                                ar->v2d.cur= ar->v2d.tot;
6266
7132
                                
6267
7133
                                ar->v2d.min[0]= 0.0f;
6268
 
                                 ar->v2d.min[1]= 0.0f;
 
7134
                                ar->v2d.min[1]= 0.0f;
6269
7135
                                
6270
7136
                                ar->v2d.max[0]= MAXFRAMEF;
6271
 
                                 ar->v2d.max[1]= FLT_MAX;
6272
 
                                
 
7137
                                ar->v2d.max[1]= FLT_MAX;
 
7138
 
6273
7139
                                ar->v2d.minzoom= 0.01f;
6274
7140
                                ar->v2d.maxzoom= 50;
6275
7141
                                ar->v2d.scroll = (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
6277
7143
                                ar->v2d.keepzoom= V2D_LOCKZOOM_Y;
6278
7144
                                ar->v2d.align= V2D_ALIGN_NO_POS_Y;
6279
7145
                                ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
 
7146
                                
 
7147
                                /* for old files with ShapeKey editors open + an action set, clear the action as 
 
7148
                                 * it doesn't make sense in the new system (i.e. violates concept that ShapeKey edit
 
7149
                                 * only shows ShapeKey-rooted actions only)
 
7150
                                 */
 
7151
                                if (saction->mode == SACTCONT_SHAPEKEY)
 
7152
                                        saction->action = NULL;
6280
7153
                                break;
6281
7154
                        }
6282
7155
                        case SPACE_SEQ:
6338
7211
        SpaceLink *sl;
6339
7212
        
6340
7213
        /* add regions */
6341
 
        for(sa= screen->areabase.first; sa; sa= sa->next) {
 
7214
        for (sa= screen->areabase.first; sa; sa= sa->next) {
6342
7215
                
6343
7216
                /* we keep headertype variable to convert old files only */
6344
 
                if(sa->headertype)
 
7217
                if (sa->headertype)
6345
7218
                        area_add_header_region(sa, &sa->regionbase);
6346
7219
                
6347
7220
                area_add_window_regions(sa, sa->spacedata.first, &sa->regionbase);
6348
7221
                
6349
 
                /* space imageselect is depricated */
6350
 
                for(sl= sa->spacedata.first; sl; sl= sl->next) {
6351
 
                        if(sl->spacetype==SPACE_IMASEL)
6352
 
                                sl->spacetype= SPACE_INFO;      /* spacedata then matches */
6353
 
                }               
 
7222
                /* space imageselect is deprecated */
 
7223
                for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
7224
                        if (sl->spacetype==SPACE_IMASEL)
 
7225
                                sl->spacetype= SPACE_EMPTY;     /* spacedata then matches */
 
7226
                }
 
7227
                
 
7228
                /* space sound is deprecated */
 
7229
                for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
7230
                        if (sl->spacetype==SPACE_SOUND)
 
7231
                                sl->spacetype= SPACE_EMPTY;     /* spacedata then matches */
 
7232
                }
 
7233
                
 
7234
                /* it seems to be possible in 2.5 to have this saved, filewindow probably */
 
7235
                sa->butspacetype= sa->spacetype;
6354
7236
                
6355
7237
                /* pushed back spaces also need regions! */
6356
 
                if(sa->spacedata.first) {
 
7238
                if (sa->spacedata.first) {
6357
7239
                        sl= sa->spacedata.first;
6358
 
                        for(sl= sl->next; sl; sl= sl->next) {
6359
 
                                if(sa->headertype)
 
7240
                        for (sl= sl->next; sl; sl= sl->next) {
 
7241
                                if (sa->headertype)
6360
7242
                                        area_add_header_region(sa, &sl->regionbase);
6361
7243
                                area_add_window_regions(sa, sl, &sl->regionbase);
6362
7244
                        }
6364
7246
        }
6365
7247
}
6366
7248
 
6367
 
static void versions_gpencil_add_main(ListBase *lb, ID *id, char *name)
 
7249
static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name)
6368
7250
{
6369
7251
        
6370
7252
        BLI_addtail(lb, id);
6375
7257
        new_id(lb, id, name);
6376
7258
        /* alphabetic insterion: is in new_id */
6377
7259
        
6378
 
        if(G.f & G_DEBUG)
 
7260
        if (G.debug & G_DEBUG)
6379
7261
                printf("Converted GPencil to ID: %s\n", id->name+2);
6380
7262
}
6381
7263
 
6385
7267
        SpaceLink *sl;
6386
7268
        
6387
7269
        /* add regions */
6388
 
        for(sa= screen->areabase.first; sa; sa= sa->next) {
6389
 
                for(sl= sa->spacedata.first; sl; sl= sl->next) {
 
7270
        for (sa= screen->areabase.first; sa; sa= sa->next) {
 
7271
                for (sl= sa->spacedata.first; sl; sl= sl->next) {
6390
7272
                        if (sl->spacetype==SPACE_VIEW3D) {
6391
7273
                                View3D *v3d= (View3D*) sl;
6392
 
                                if(v3d->gpd) {
 
7274
                                if (v3d->gpd) {
6393
7275
                                        versions_gpencil_add_main(&main->gpencil, (ID *)v3d->gpd, "GPencil View3D");
6394
7276
                                        v3d->gpd= NULL;
6395
7277
                                }
6396
7278
                        }
6397
7279
                        else if (sl->spacetype==SPACE_NODE) {
6398
7280
                                SpaceNode *snode= (SpaceNode *)sl;
6399
 
                                if(snode->gpd) {
 
7281
                                if (snode->gpd) {
6400
7282
                                        versions_gpencil_add_main(&main->gpencil, (ID *)snode->gpd, "GPencil Node");
6401
7283
                                        snode->gpd= NULL;
6402
7284
                                }
6403
7285
                        }
6404
7286
                        else if (sl->spacetype==SPACE_SEQ) {
6405
7287
                                SpaceSeq *sseq= (SpaceSeq *)sl;
6406
 
                                if(sseq->gpd) {
 
7288
                                if (sseq->gpd) {
6407
7289
                                        versions_gpencil_add_main(&main->gpencil, (ID *)sseq->gpd, "GPencil Node");
6408
7290
                                        sseq->gpd= NULL;
6409
7291
                                }
6410
7292
                        }
6411
7293
                        else if (sl->spacetype==SPACE_IMAGE) {
6412
7294
                                SpaceImage *sima= (SpaceImage *)sl;
6413
 
                                if(sima->gpd) {
 
7295
#if 0                   /* see comment on r28002 */
 
7296
                                if (sima->gpd) {
6414
7297
                                        versions_gpencil_add_main(&main->gpencil, (ID *)sima->gpd, "GPencil Image");
6415
7298
                                        sima->gpd= NULL;
6416
7299
                                }
 
7300
#else
 
7301
                                sima->gpd= NULL;
 
7302
#endif
6417
7303
                        }
6418
7304
                }
6419
7305
        }               
6420
7306
}
6421
7307
 
 
7308
/* deprecated, only keep this for readfile.c */
 
7309
static PartEff *do_version_give_parteff_245(Object *ob)
 
7310
{
 
7311
        PartEff *paf;
 
7312
 
 
7313
        paf= ob->effect.first;
 
7314
        while (paf) {
 
7315
                if (paf->type==EFF_PARTICLE) return paf;
 
7316
                paf= paf->next;
 
7317
        }
 
7318
        return NULL;
 
7319
}
 
7320
static void do_version_free_effect_245(Effect *eff)
 
7321
{
 
7322
        PartEff *paf;
 
7323
 
 
7324
        if (eff->type==EFF_PARTICLE) {
 
7325
                paf= (PartEff *)eff;
 
7326
                if (paf->keys) MEM_freeN(paf->keys);
 
7327
        }
 
7328
        MEM_freeN(eff);
 
7329
}
 
7330
static void do_version_free_effects_245(ListBase *lb)
 
7331
{
 
7332
        Effect *eff;
 
7333
 
 
7334
        eff= lb->first;
 
7335
        while (eff) {
 
7336
                BLI_remlink(lb, eff);
 
7337
                do_version_free_effect_245(eff);
 
7338
                eff= lb->first;
 
7339
        }
 
7340
}
 
7341
 
6422
7342
static void do_version_mtex_factor_2_50(MTex **mtex_array, short idtype)
6423
7343
{
6424
7344
        MTex *mtex;
6425
7345
        float varfac, colfac;
6426
7346
        int a, neg;
6427
7347
 
6428
 
        if(!mtex_array)
 
7348
        if (!mtex_array)
6429
7349
                return;
6430
7350
 
6431
 
        for(a=0; a<MAX_MTEX; a++) {
6432
 
                if(mtex_array[a]) {
 
7351
        for (a=0; a<MAX_MTEX; a++) {
 
7352
                if (mtex_array[a]) {
6433
7353
                        mtex= mtex_array[a];
6434
7354
 
6435
7355
                        neg= mtex->maptoneg;
6436
7356
                        varfac= mtex->varfac;
6437
7357
                        colfac= mtex->colfac;
6438
7358
 
6439
 
                        if(neg & MAP_DISP) mtex->dispfac= -mtex->dispfac;
6440
 
                        if(neg & MAP_NORM) mtex->norfac= -mtex->norfac;
6441
 
                        if(neg & MAP_WARP) mtex->warpfac= -mtex->warpfac;
 
7359
                        if (neg & MAP_DISP) mtex->dispfac= -mtex->dispfac;
 
7360
                        if (neg & MAP_NORM) mtex->norfac= -mtex->norfac;
 
7361
                        if (neg & MAP_WARP) mtex->warpfac= -mtex->warpfac;
6442
7362
 
6443
7363
                        mtex->colspecfac= (neg & MAP_COLSPEC)? -colfac: colfac;
6444
7364
                        mtex->mirrfac= (neg & MAP_COLMIR)? -colfac: colfac;
6466
7386
                        mtex->lifefac= (neg & MAP_PA_LIFE)? -varfac: varfac;
6467
7387
                        mtex->sizefac= (neg & MAP_PA_SIZE)? -varfac: varfac;
6468
7388
                        mtex->ivelfac= (neg & MAP_PA_IVEL)? -varfac: varfac;
6469
 
                        mtex->pvelfac= (neg & MAP_PA_PVEL)? -varfac: varfac;
6470
7389
 
6471
7390
                        mtex->shadowfac= (neg & LAMAP_SHAD)? -colfac: colfac;
6472
7391
 
6474
7393
                        mtex->zendownfac= (neg & WOMAP_ZENDOWN)? -colfac: colfac;
6475
7394
                        mtex->blendfac= (neg & WOMAP_BLEND)? -varfac: varfac;
6476
7395
 
6477
 
                        if(idtype == ID_MA)
 
7396
                        if (idtype == ID_MA)
6478
7397
                                mtex->colfac= (neg & MAP_COL)? -colfac: colfac;
6479
 
                        else if(idtype == ID_LA)
 
7398
                        else if (idtype == ID_LA)
6480
7399
                                mtex->colfac= (neg & LAMAP_COL)? -colfac: colfac;
6481
 
                        else if(idtype == ID_WO)
 
7400
                        else if (idtype == ID_WO)
6482
7401
                                mtex->colfac= (neg & WOMAP_HORIZ)? -colfac: colfac;
6483
7402
                }
6484
7403
        }
6485
7404
}
6486
7405
 
6487
 
static void do_version_mdef_250(FileData *fd, Library *lib, Main *main)
 
7406
static void do_version_mdef_250(Main *main)
6488
7407
{
6489
7408
        Object *ob;
6490
7409
        ModifierData *md;
6491
7410
        MeshDeformModifierData *mmd;
6492
7411
 
6493
 
        for(ob= main->object.first; ob; ob=ob->id.next) {
6494
 
                for(md=ob->modifiers.first; md; md=md->next) {
6495
 
                        if(md->type == eModifierType_MeshDeform) {
 
7412
        for (ob= main->object.first; ob; ob=ob->id.next) {
 
7413
                for (md=ob->modifiers.first; md; md=md->next) {
 
7414
                        if (md->type == eModifierType_MeshDeform) {
6496
7415
                                mmd= (MeshDeformModifierData*)md;
6497
7416
 
6498
 
                                if(mmd->bindcos) {
 
7417
                                if (mmd->bindcos) {
6499
7418
                                        /* make bindcos NULL in order to trick older versions
6500
 
                                           into thinking that the mesh was not bound yet */
 
7419
                                         * into thinking that the mesh was not bound yet */
6501
7420
                                        mmd->bindcagecos= mmd->bindcos;
6502
7421
                                        mmd->bindcos= NULL;
6503
7422
 
6513
7432
        bConstraint *con;
6514
7433
 
6515
7434
        for     (con=lb->first; con; con=con->next) {
6516
 
                if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
 
7435
                if (con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
6517
7436
                        bRigidBodyJointConstraint *data = con->data;
6518
 
                        data->axX *= M_PI/180.0;
6519
 
                        data->axY *= M_PI/180.0;
6520
 
                        data->axZ *= M_PI/180.0;
 
7437
                        data->axX *= (float)(M_PI/180.0);
 
7438
                        data->axY *= (float)(M_PI/180.0);
 
7439
                        data->axZ *= (float)(M_PI/180.0);
6521
7440
                }
6522
 
                else if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
 
7441
                else if (con->type==CONSTRAINT_TYPE_KINEMATIC) {
6523
7442
                        bKinematicConstraint *data = con->data;
6524
 
                        data->poleangle *= M_PI/180.0;
 
7443
                        data->poleangle *= (float)(M_PI/180.0);
6525
7444
                }
6526
 
                else if(con->type==CONSTRAINT_TYPE_ROTLIMIT) {
 
7445
                else if (con->type==CONSTRAINT_TYPE_ROTLIMIT) {
6527
7446
                        bRotLimitConstraint *data = con->data;
6528
7447
 
6529
 
                        data->xmin *= M_PI/180.0;
6530
 
                        data->xmax *= M_PI/180.0;
6531
 
                        data->ymin *= M_PI/180.0;
6532
 
                        data->ymax *= M_PI/180.0;
6533
 
                        data->zmin *= M_PI/180.0;
6534
 
                        data->zmax *= M_PI/180.0;
 
7448
                        data->xmin *= (float)(M_PI/180.0);
 
7449
                        data->xmax *= (float)(M_PI/180.0);
 
7450
                        data->ymin *= (float)(M_PI/180.0);
 
7451
                        data->ymax *= (float)(M_PI/180.0);
 
7452
                        data->zmin *= (float)(M_PI/180.0);
 
7453
                        data->zmax *= (float)(M_PI/180.0);
6535
7454
                }
6536
7455
        }
6537
7456
}
6560
7479
{
6561
7480
        Sequence * seq = seqbasep->first;
6562
7481
 
6563
 
        while(seq) {
 
7482
        while (seq) {
6564
7483
                seqbase_unique_name_recursive(&sce->ed->seqbase, seq);
6565
7484
                if (seq->seqbase.first) {
6566
7485
                        do_versions_seq_unique_name_all_strips(
6570
7489
        }
6571
7490
}
6572
7491
 
 
7492
 
 
7493
static void do_version_bone_roll_256(Bone *bone)
 
7494
{
 
7495
        Bone *child;
 
7496
        float submat[3][3];
 
7497
        
 
7498
        copy_m3_m4(submat, bone->arm_mat);
 
7499
        mat3_to_vec_roll(submat, NULL, &bone->arm_roll);
 
7500
        
 
7501
        for (child = bone->childbase.first; child; child = child->next)
 
7502
                do_version_bone_roll_256(child);
 
7503
}
 
7504
 
 
7505
static void do_versions_nodetree_dynamic_sockets(bNodeTree *ntree)
 
7506
{
 
7507
        bNodeSocket *sock;
 
7508
        for (sock=ntree->inputs.first; sock; sock=sock->next)
 
7509
                sock->flag |= SOCK_DYNAMIC;
 
7510
        for (sock=ntree->outputs.first; sock; sock=sock->next)
 
7511
                sock->flag |= SOCK_DYNAMIC;
 
7512
}
 
7513
 
 
7514
void convert_tface_mt(FileData *fd, Main *main)
 
7515
{
 
7516
        Main *gmain;
 
7517
 
 
7518
        /* this is a delayed do_version (so it can create new materials) */
 
7519
        if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 3)) {
 
7520
 
 
7521
                //XXX hack, material.c uses G.main all over the place, instead of main
 
7522
                // temporarily set G.main to the current main
 
7523
                gmain = G.main;
 
7524
                G.main = main;
 
7525
 
 
7526
                if (!(do_version_tface(main, 1))) {
 
7527
                        BKE_report(fd->reports, RPT_WARNING, "Texface conversion problem. Error in console");
 
7528
                }
 
7529
 
 
7530
                //XXX hack, material.c uses G.main allover the place, instead of main
 
7531
                G.main = gmain;
 
7532
        }
 
7533
}
 
7534
 
 
7535
static void do_versions_nodetree_image_default_alpha_output(bNodeTree *ntree)
 
7536
{
 
7537
        bNode *node;
 
7538
        bNodeSocket *sock;
 
7539
        for (node=ntree->nodes.first; node; node=node->next) {
 
7540
                if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) {
 
7541
                        /* default Image output value should have 0 alpha */
 
7542
                        sock = node->outputs.first;
 
7543
                        ((bNodeSocketValueRGBA*)sock->default_value)->value[3] = 0.0f;
 
7544
                }
 
7545
        }
 
7546
}
 
7547
 
 
7548
static void do_version_ntree_tex_mapping_260(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
 
7549
{
 
7550
        bNode *node;
 
7551
 
 
7552
        for (node=ntree->nodes.first; node; node=node->next) {
 
7553
                if (node->type == SH_NODE_MAPPING) {
 
7554
                        TexMapping *tex_mapping;
 
7555
 
 
7556
                        tex_mapping= node->storage;
 
7557
                        tex_mapping->projx= PROJ_X;
 
7558
                        tex_mapping->projy= PROJ_Y;
 
7559
                        tex_mapping->projz= PROJ_Z;
 
7560
                }
 
7561
        }
 
7562
}
 
7563
 
 
7564
static void do_versions_nodetree_convert_angle(bNodeTree *ntree)
 
7565
{
 
7566
        bNode *node;
 
7567
        for (node=ntree->nodes.first; node; node=node->next) {
 
7568
                if (node->type == CMP_NODE_ROTATE) {
 
7569
                        /* Convert degrees to radians. */
 
7570
                        bNodeSocket *sock = ((bNodeSocket*)node->inputs.first)->next;
 
7571
                        ((bNodeSocketValueFloat*)sock->default_value)->value = DEG2RADF(((bNodeSocketValueFloat*)sock->default_value)->value);
 
7572
                }
 
7573
                else if (node->type == CMP_NODE_DBLUR) {
 
7574
                        /* Convert degrees to radians. */
 
7575
                        NodeDBlurData *ndbd= node->storage;
 
7576
                        ndbd->angle = DEG2RADF(ndbd->angle);
 
7577
                        ndbd->spin = DEG2RADF(ndbd->spin);
 
7578
                }
 
7579
                else if (node->type == CMP_NODE_DEFOCUS) {
 
7580
                        /* Convert degrees to radians. */
 
7581
                        NodeDefocus *nqd = node->storage;
 
7582
                        /* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
 
7583
                        nqd->rotation = DEG2RADF(nqd->rotation*255.0f);
 
7584
                }
 
7585
                else if (node->type == CMP_NODE_CHROMA_MATTE) {
 
7586
                        /* Convert degrees to radians. */
 
7587
                        NodeChroma *ndc = node->storage;
 
7588
                        ndc->t1 = DEG2RADF(ndc->t1);
 
7589
                        ndc->t2 = DEG2RADF(ndc->t2);
 
7590
                }
 
7591
                else if (node->type == CMP_NODE_GLARE) {
 
7592
                        /* Convert degrees to radians. */
 
7593
                        NodeGlare* ndg = node->storage;
 
7594
                        /* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
 
7595
                        ndg->angle_ofs = DEG2RADF(ndg->angle_ofs*255.0f);
 
7596
                }
 
7597
                /* XXX TexMapping struct is used by other nodes too (at least node_composite_mapValue),
 
7598
                 *     but not the rot part...
 
7599
                 */
 
7600
                else if (node->type == SH_NODE_MAPPING) {
 
7601
                        /* Convert degrees to radians. */
 
7602
                        TexMapping* tmap = node->storage;
 
7603
                        tmap->rot[0] = DEG2RADF(tmap->rot[0]);
 
7604
                        tmap->rot[1] = DEG2RADF(tmap->rot[1]);
 
7605
                        tmap->rot[2] = DEG2RADF(tmap->rot[2]);
 
7606
                }
 
7607
        }
 
7608
}
 
7609
 
 
7610
void do_versions_image_settings_2_60(Scene *sce)
 
7611
{
 
7612
        /* note: rd->subimtype is moved into individual settings now and no longer
 
7613
         * exists */
 
7614
        RenderData *rd= &sce->r;
 
7615
        ImageFormatData *imf= &sce->r.im_format;
 
7616
 
 
7617
        /* we know no data loss happens here, the old values were in char range */
 
7618
        imf->imtype=   (char)rd->imtype;
 
7619
        imf->planes=   (char)rd->planes;
 
7620
        imf->compress= (char)rd->quality;
 
7621
        imf->quality=  (char)rd->quality;
 
7622
 
 
7623
        /* default, was stored in multiple places, may override later */
 
7624
        imf->depth= R_IMF_CHAN_DEPTH_8;
 
7625
 
 
7626
        /* openexr */
 
7627
        imf->exr_codec = rd->quality & 7; /* strange but true! 0-4 are valid values, OPENEXR_COMPRESS */
 
7628
 
 
7629
        switch (imf->imtype) {
 
7630
        case R_IMF_IMTYPE_OPENEXR:
 
7631
                imf->depth=  (rd->subimtype & R_OPENEXR_HALF) ? R_IMF_CHAN_DEPTH_16 : R_IMF_CHAN_DEPTH_32;
 
7632
                if (rd->subimtype & R_PREVIEW_JPG) {
 
7633
                        imf->flag |= R_IMF_FLAG_PREVIEW_JPG;
 
7634
                }
 
7635
                if (rd->subimtype & R_OPENEXR_ZBUF) {
 
7636
                        imf->flag |= R_IMF_FLAG_ZBUF;
 
7637
                }
 
7638
                break;
 
7639
        case R_IMF_IMTYPE_TIFF:
 
7640
                if (rd->subimtype & R_TIFF_16BIT) {
 
7641
                        imf->depth= R_IMF_CHAN_DEPTH_16;
 
7642
                }
 
7643
                break;
 
7644
        case R_IMF_IMTYPE_JP2:
 
7645
                if (rd->subimtype & R_JPEG2K_16BIT) {
 
7646
                        imf->depth= R_IMF_CHAN_DEPTH_16;
 
7647
                }
 
7648
                else if (rd->subimtype & R_JPEG2K_12BIT) {
 
7649
                        imf->depth= R_IMF_CHAN_DEPTH_12;
 
7650
                }
 
7651
 
 
7652
                if (rd->subimtype & R_JPEG2K_YCC) {
 
7653
                        imf->jp2_flag |= R_IMF_JP2_FLAG_YCC;
 
7654
                }
 
7655
                if (rd->subimtype & R_JPEG2K_CINE_PRESET) {
 
7656
                        imf->jp2_flag |= R_IMF_JP2_FLAG_CINE_PRESET;
 
7657
                }
 
7658
                if (rd->subimtype & R_JPEG2K_CINE_48FPS) {
 
7659
                        imf->jp2_flag |= R_IMF_JP2_FLAG_CINE_48;
 
7660
                }
 
7661
                break;
 
7662
        case R_IMF_IMTYPE_CINEON:
 
7663
        case R_IMF_IMTYPE_DPX:
 
7664
                if (rd->subimtype & R_CINEON_LOG) {
 
7665
                        imf->cineon_flag |= R_IMF_CINEON_FLAG_LOG;
 
7666
                }
 
7667
                break;
 
7668
        }
 
7669
 
 
7670
}
 
7671
 
 
7672
/* socket use flags were only temporary before */
 
7673
static void do_versions_nodetree_socket_use_flags_2_62(bNodeTree *ntree)
 
7674
{
 
7675
        bNode *node;
 
7676
        bNodeSocket *sock;
 
7677
        bNodeLink *link;
 
7678
        
 
7679
        for (node=ntree->nodes.first; node; node=node->next) {
 
7680
                for (sock=node->inputs.first; sock; sock=sock->next)
 
7681
                        sock->flag &= ~SOCK_IN_USE;
 
7682
                for (sock=node->outputs.first; sock; sock=sock->next)
 
7683
                        sock->flag &= ~SOCK_IN_USE;
 
7684
        }
 
7685
        for (sock=ntree->inputs.first; sock; sock=sock->next)
 
7686
                sock->flag &= ~SOCK_IN_USE;
 
7687
        for (sock=ntree->outputs.first; sock; sock=sock->next)
 
7688
                sock->flag &= ~SOCK_IN_USE;
 
7689
        
 
7690
        for (link=ntree->links.first; link; link=link->next) {
 
7691
                link->fromsock->flag |= SOCK_IN_USE;
 
7692
                link->tosock->flag |= SOCK_IN_USE;
 
7693
        }
 
7694
}
 
7695
 
 
7696
static void do_versions_nodetree_multi_file_output_format_2_62_1(Scene *sce, bNodeTree *ntree)
 
7697
{
 
7698
        bNode *node;
 
7699
        bNodeSocket *sock;
 
7700
        
 
7701
        for (node=ntree->nodes.first; node; node=node->next) {
 
7702
                if (node->type==CMP_NODE_OUTPUT_FILE) {
 
7703
                        /* previous CMP_NODE_OUTPUT_FILE nodes get converted to multi-file outputs */
 
7704
                        NodeImageFile *old_data = node->storage;
 
7705
                        NodeImageMultiFile *nimf= MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file");
 
7706
                        bNodeSocket *old_image = BLI_findlink(&node->inputs, 0);
 
7707
                        bNodeSocket *old_z = BLI_findlink(&node->inputs, 1);
 
7708
                        bNodeSocket *sock;
 
7709
                        char basepath[FILE_MAXDIR];
 
7710
                        char filename[FILE_MAXFILE];
 
7711
                        
 
7712
                        node->storage= nimf;
 
7713
                        
 
7714
                        /* split off filename from the old path, to be used as socket sub-path */
 
7715
                        BLI_split_dirfile(old_data->name, basepath, filename, sizeof(basepath), sizeof(filename));
 
7716
                        
 
7717
                        BLI_strncpy(nimf->base_path, basepath, sizeof(nimf->base_path));
 
7718
                        nimf->format = old_data->im_format;
 
7719
                        
 
7720
                        /* if z buffer is saved, change the image type to multilayer exr.
 
7721
                         * XXX this is slightly messy, Z buffer was ignored before for anything but EXR and IRIS ...
 
7722
                         * i'm just assuming here that IRIZ means IRIS with z buffer ...
 
7723
                         */
 
7724
                        if (ELEM(old_data->im_format.imtype, R_IMF_IMTYPE_IRIZ, R_IMF_IMTYPE_OPENEXR)) {
 
7725
                                char sockpath[FILE_MAX];
 
7726
                                
 
7727
                                nimf->format.imtype = R_IMF_IMTYPE_MULTILAYER;
 
7728
                                
 
7729
                                BLI_snprintf(sockpath, sizeof(sockpath), "%s_Image", filename);
 
7730
                                sock = ntreeCompositOutputFileAddSocket(ntree, node, sockpath, &nimf->format);
 
7731
                                /* XXX later do_versions copies path from socket name, need to set this explicitely */
 
7732
                                BLI_strncpy(sock->name, sockpath, sizeof(sock->name));
 
7733
                                if (old_image->link) {
 
7734
                                        old_image->link->tosock = sock;
 
7735
                                        sock->link = old_image->link;
 
7736
                                }
 
7737
                                
 
7738
                                BLI_snprintf(sockpath, sizeof(sockpath), "%s_Z", filename);
 
7739
                                sock = ntreeCompositOutputFileAddSocket(ntree, node, sockpath, &nimf->format);
 
7740
                                /* XXX later do_versions copies path from socket name, need to set this explicitely */
 
7741
                                BLI_strncpy(sock->name, sockpath, sizeof(sock->name));
 
7742
                                if (old_z->link) {
 
7743
                                        old_z->link->tosock = sock;
 
7744
                                        sock->link = old_z->link;
 
7745
                                }
 
7746
                        }
 
7747
                        else {
 
7748
                                sock = ntreeCompositOutputFileAddSocket(ntree, node, filename, &nimf->format);
 
7749
                                /* XXX later do_versions copies path from socket name, need to set this explicitely */
 
7750
                                BLI_strncpy(sock->name, filename, sizeof(sock->name));
 
7751
                                if (old_image->link) {
 
7752
                                        old_image->link->tosock = sock;
 
7753
                                        sock->link = old_image->link;
 
7754
                                }
 
7755
                        }
 
7756
                        
 
7757
                        nodeRemoveSocket(ntree, node, old_image);
 
7758
                        nodeRemoveSocket(ntree, node, old_z);
 
7759
                        MEM_freeN(old_data);
 
7760
                }
 
7761
                else if (node->type==CMP_NODE_OUTPUT_MULTI_FILE__DEPRECATED) {
 
7762
                        NodeImageMultiFile *nimf = node->storage;
 
7763
                        
 
7764
                        /* CMP_NODE_OUTPUT_MULTI_FILE has been redeclared as CMP_NODE_OUTPUT_FILE */
 
7765
                        node->type = CMP_NODE_OUTPUT_FILE;
 
7766
                        
 
7767
                        /* initialize the node-wide image format from render data, if available */
 
7768
                        if (sce)
 
7769
                                nimf->format = sce->r.im_format;
 
7770
                        
 
7771
                        /* transfer render format toggle to node format toggle */
 
7772
                        for (sock=node->inputs.first; sock; sock=sock->next) {
 
7773
                                NodeImageMultiFileSocket *simf = sock->storage;
 
7774
                                simf->use_node_format = simf->use_render_format;
 
7775
                        }
 
7776
                        
 
7777
                        /* we do have preview now */
 
7778
                        node->flag |= NODE_PREVIEW;
 
7779
                }
 
7780
        }
 
7781
}
 
7782
 
 
7783
/* blue and red are swapped pre 2.62.1, be sane (red == red) now! */
 
7784
static void do_versions_mesh_mloopcol_swap_2_62_1(Mesh *me)
 
7785
{
 
7786
        CustomDataLayer *layer;
 
7787
        MLoopCol *mloopcol;
 
7788
        int a;
 
7789
        int i;
 
7790
 
 
7791
        for (a = 0; a < me->ldata.totlayer; a++) {
 
7792
                layer = &me->ldata.layers[a];
 
7793
 
 
7794
                if (layer->type == CD_MLOOPCOL) {
 
7795
                        mloopcol = (MLoopCol *)layer->data;
 
7796
                        for (i = 0; i < me->totloop; i++, mloopcol++) {
 
7797
                                SWAP(char, mloopcol->r, mloopcol->b);
 
7798
                        }
 
7799
                }
 
7800
        }
 
7801
}
 
7802
 
6573
7803
static void do_versions(FileData *fd, Library *lib, Main *main)
6574
7804
{
6575
7805
        /* WATCH IT!!!: pointers from libdata have not been converted */
6576
7806
 
6577
 
        if(G.f & G_DEBUG)
6578
 
                printf("read file %s\n  Version %d sub %d\n", fd->relabase, main->versionfile, main->subversionfile);
 
7807
        if (G.debug & G_DEBUG)
 
7808
                printf("read file %s\n  Version %d sub %d svn r%d\n", fd->relabase, main->versionfile, main->subversionfile, main->revision);
6579
7809
        
6580
 
        if(main->versionfile == 100) {
 
7810
        if (main->versionfile == 100) {
6581
7811
                /* tex->extend and tex->imageflag have changed: */
6582
7812
                Tex *tex = main->tex.first;
6583
 
                while(tex) {
6584
 
                        if(tex->id.flag & LIB_NEEDLINK) {
 
7813
                while (tex) {
 
7814
                        if (tex->id.flag & LIB_NEEDLINK) {
6585
7815
 
6586
 
                                if(tex->extend==0) {
6587
 
                                        if(tex->xrepeat || tex->yrepeat) tex->extend= TEX_REPEAT;
 
7816
                                if (tex->extend==0) {
 
7817
                                        if (tex->xrepeat || tex->yrepeat) tex->extend= TEX_REPEAT;
6588
7818
                                        else {
6589
7819
                                                tex->extend= TEX_EXTEND;
6590
7820
                                                tex->xrepeat= tex->yrepeat= 1;
6595
7825
                        tex= tex->id.next;
6596
7826
                }
6597
7827
        }
6598
 
        if(main->versionfile <= 101) {
 
7828
        if (main->versionfile <= 101) {
6599
7829
                /* frame mapping */
6600
7830
                Scene *sce = main->scene.first;
6601
 
                while(sce) {
 
7831
                while (sce) {
6602
7832
                        sce->r.framapto= 100;
6603
7833
                        sce->r.images= 100;
6604
7834
                        sce->r.framelen= 1.0;
6605
7835
                        sce= sce->id.next;
6606
7836
                }
6607
7837
        }
6608
 
        if(main->versionfile <= 102) {
 
7838
        if (main->versionfile <= 102) {
6609
7839
                /* init halo's at 1.0 */
6610
7840
                Material *ma = main->mat.first;
6611
 
                while(ma) {
 
7841
                while (ma) {
6612
7842
                        ma->add= 1.0;
6613
7843
                        ma= ma->id.next;
6614
7844
                }
6615
7845
        }
6616
 
        if(main->versionfile <= 103) {
 
7846
        if (main->versionfile <= 103) {
6617
7847
                /* new variable in object: colbits */
6618
7848
                Object *ob = main->object.first;
6619
7849
                int a;
6620
 
                while(ob) {
 
7850
                while (ob) {
6621
7851
                        ob->colbits= 0;
6622
 
                        if(ob->totcol) {
6623
 
                                for(a=0; a<ob->totcol; a++) {
6624
 
                                        if(ob->mat[a]) ob->colbits |= (1<<a);
 
7852
                        if (ob->totcol) {
 
7853
                                for (a=0; a<ob->totcol; a++) {
 
7854
                                        if (ob->mat[a]) ob->colbits |= (1<<a);
6625
7855
                                }
6626
7856
                        }
6627
7857
                        ob= ob->id.next;
6628
7858
                }
6629
7859
        }
6630
 
        if(main->versionfile <= 104) {
 
7860
        if (main->versionfile <= 104) {
6631
7861
                /* timeoffs moved */
6632
7862
                Object *ob = main->object.first;
6633
 
                while(ob) {
6634
 
                        if(ob->transflag & 1) {
 
7863
                while (ob) {
 
7864
                        if (ob->transflag & 1) {
6635
7865
                                ob->transflag -= 1;
6636
 
                                ob->ipoflag |= OB_OFFS_OB;
 
7866
                                //ob->ipoflag |= OB_OFFS_OB;
6637
7867
                        }
6638
7868
                        ob= ob->id.next;
6639
7869
                }
6640
7870
        }
6641
 
        if(main->versionfile <= 105) {
 
7871
        if (main->versionfile <= 105) {
6642
7872
                Object *ob = main->object.first;
6643
 
                while(ob) {
 
7873
                while (ob) {
6644
7874
                        ob->dupon= 1; ob->dupoff= 0;
6645
7875
                        ob->dupsta= 1; ob->dupend= 100;
6646
7876
                        ob= ob->id.next;
6647
7877
                }
6648
7878
        }
6649
 
        if(main->versionfile <= 106) {
 
7879
        if (main->versionfile <= 106) {
6650
7880
                /* mcol changed */
6651
7881
                Mesh *me = main->mesh.first;
6652
 
                while(me) {
6653
 
                        if(me->mcol) vcol_to_fcol(me);
 
7882
                while (me) {
 
7883
                        if (me->mcol) vcol_to_fcol(me);
6654
7884
                        me= me->id.next;
6655
7885
                }
6656
7886
 
6657
7887
        }
6658
 
        if(main->versionfile <= 107) {
 
7888
        if (main->versionfile <= 107) {
6659
7889
                Object *ob;
6660
7890
                Scene *sce = main->scene.first;
6661
 
                while(sce) {
 
7891
                while (sce) {
6662
7892
                        sce->r.mode |= R_GAMMA;
6663
7893
                        sce= sce->id.next;
6664
7894
                }
6665
7895
                ob= main->object.first;
6666
 
                while(ob) {
6667
 
                        ob->ipoflag |= OB_OFFS_PARENT;
6668
 
                        if(ob->dt==0) ob->dt= OB_SOLID;
 
7896
                while (ob) {
 
7897
                        //ob->ipoflag |= OB_OFFS_PARENT;
 
7898
                        if (ob->dt==0) ob->dt= OB_SOLID;
6669
7899
                        ob= ob->id.next;
6670
7900
                }
6671
7901
 
6672
7902
        }
6673
 
        if(main->versionfile <= 109) {
 
7903
        if (main->versionfile <= 109) {
6674
7904
                /* new variable: gridlines */
6675
7905
                bScreen *sc = main->screen.first;
6676
 
                while(sc) {
 
7906
                while (sc) {
6677
7907
                        ScrArea *sa= sc->areabase.first;
6678
 
                        while(sa) {
 
7908
                        while (sa) {
6679
7909
                                SpaceLink *sl= sa->spacedata.first;
6680
7910
                                while (sl) {
6681
7911
                                        if (sl->spacetype==SPACE_VIEW3D) {
6690
7920
                        sc= sc->id.next;
6691
7921
                }
6692
7922
        }
6693
 
        if(main->versionfile <= 112) {
6694
 
                Mesh *me = main->mesh.first;
6695
 
                while(me) {
6696
 
                        me->cubemapsize= 1.0;
6697
 
                        me= me->id.next;
6698
 
                }
6699
 
        }
6700
 
        if(main->versionfile <= 113) {
 
7923
        if (main->versionfile <= 113) {
6701
7924
                Material *ma = main->mat.first;
6702
 
                while(ma) {
6703
 
                        if(ma->flaresize==0.0) ma->flaresize= 1.0;
6704
 
                        ma->subsize= 1.0;
6705
 
                        ma->flareboost= 1.0;
 
7925
                while (ma) {
 
7926
                        if (ma->flaresize==0.0f) ma->flaresize= 1.0f;
 
7927
                        ma->subsize= 1.0f;
 
7928
                        ma->flareboost= 1.0f;
6706
7929
                        ma= ma->id.next;
6707
7930
                }
6708
7931
        }
6709
7932
 
6710
 
        if(main->versionfile <= 134) {
 
7933
        if (main->versionfile <= 134) {
6711
7934
                Tex *tex = main->tex.first;
6712
7935
                while (tex) {
6713
 
                        if ((tex->rfac == 0.0) &&
6714
 
                                (tex->gfac == 0.0) &&
6715
 
                                (tex->bfac == 0.0)) {
6716
 
                                tex->rfac = 1.0;
6717
 
                                tex->gfac = 1.0;
6718
 
                                tex->bfac = 1.0;
6719
 
                                tex->filtersize = 1.0;
 
7936
                        if ((tex->rfac == 0.0f) &&
 
7937
                                (tex->gfac == 0.0f) &&
 
7938
                                (tex->bfac == 0.0f)) {
 
7939
                                tex->rfac = 1.0f;
 
7940
                                tex->gfac = 1.0f;
 
7941
                                tex->bfac = 1.0f;
 
7942
                                tex->filtersize = 1.0f;
6720
7943
                        }
6721
7944
                        tex = tex->id.next;
6722
7945
                }
6723
7946
        }
6724
 
        if(main->versionfile <= 140) {
 
7947
        if (main->versionfile <= 140) {
6725
7948
                /* r-g-b-fac in texture */
6726
7949
                Tex *tex = main->tex.first;
6727
7950
                while (tex) {
6728
 
                        if ((tex->rfac == 0.0) &&
6729
 
                                (tex->gfac == 0.0) &&
6730
 
                                (tex->bfac == 0.0)) {
6731
 
                                tex->rfac = 1.0;
6732
 
                                tex->gfac = 1.0;
6733
 
                                tex->bfac = 1.0;
6734
 
                                tex->filtersize = 1.0;
 
7951
                        if ((tex->rfac == 0.0f) &&
 
7952
                                (tex->gfac == 0.0f) &&
 
7953
                                (tex->bfac == 0.0f)) {
 
7954
                                tex->rfac = 1.0f;
 
7955
                                tex->gfac = 1.0f;
 
7956
                                tex->bfac = 1.0f;
 
7957
                                tex->filtersize = 1.0f;
6735
7958
                        }
6736
7959
                        tex = tex->id.next;
6737
7960
                }
6738
7961
        }
6739
 
        if(main->versionfile <= 153) {
6740
 
                Scene *sce = main->scene.first;
6741
 
                while(sce) {
6742
 
                        if(sce->r.blurfac==0.0) sce->r.blurfac= 1.0;
6743
 
                        sce= sce->id.next;
6744
 
                }
6745
 
        }
6746
 
        if(main->versionfile <= 163) {
6747
 
                Scene *sce = main->scene.first;
6748
 
                while(sce) {
6749
 
                        if(sce->r.frs_sec==0) sce->r.frs_sec= 25;
6750
 
                        sce= sce->id.next;
6751
 
                }
6752
 
        }
6753
 
        if(main->versionfile <= 164) {
 
7962
        if (main->versionfile <= 153) {
 
7963
                Scene *sce = main->scene.first;
 
7964
                while (sce) {
 
7965
                        if (sce->r.blurfac==0.0f) sce->r.blurfac= 1.0f;
 
7966
                        sce= sce->id.next;
 
7967
                }
 
7968
        }
 
7969
        if (main->versionfile <= 163) {
 
7970
                Scene *sce = main->scene.first;
 
7971
                while (sce) {
 
7972
                        if (sce->r.frs_sec==0) sce->r.frs_sec= 25;
 
7973
                        sce= sce->id.next;
 
7974
                }
 
7975
        }
 
7976
        if (main->versionfile <= 164) {
6754
7977
                Mesh *me= main->mesh.first;
6755
 
                while(me) {
 
7978
                while (me) {
6756
7979
                        me->smoothresh= 30;
6757
7980
                        me= me->id.next;
6758
7981
                }
6759
7982
        }
6760
 
        if(main->versionfile <= 165) {
 
7983
        if (main->versionfile <= 165) {
6761
7984
                Mesh *me= main->mesh.first;
6762
7985
                TFace *tface;
6763
7986
                int nr;
6764
7987
                char *cp;
6765
7988
 
6766
 
                while(me) {
6767
 
                        if(me->tface) {
 
7989
                while (me) {
 
7990
                        if (me->tface) {
6768
7991
                                nr= me->totface;
6769
7992
                                tface= me->tface;
6770
 
                                while(nr--) {
 
7993
                                while (nr--) {
6771
7994
                                        cp= (char *)&tface->col[0];
6772
 
                                        if(cp[1]>126) cp[1]= 255; else cp[1]*=2;
6773
 
                                        if(cp[2]>126) cp[2]= 255; else cp[2]*=2;
6774
 
                                        if(cp[3]>126) cp[3]= 255; else cp[3]*=2;
 
7995
                                        if (cp[1]>126) cp[1]= 255; else cp[1]*=2;
 
7996
                                        if (cp[2]>126) cp[2]= 255; else cp[2]*=2;
 
7997
                                        if (cp[3]>126) cp[3]= 255; else cp[3]*=2;
6775
7998
                                        cp= (char *)&tface->col[1];
6776
 
                                        if(cp[1]>126) cp[1]= 255; else cp[1]*=2;
6777
 
                                        if(cp[2]>126) cp[2]= 255; else cp[2]*=2;
6778
 
                                        if(cp[3]>126) cp[3]= 255; else cp[3]*=2;
 
7999
                                        if (cp[1]>126) cp[1]= 255; else cp[1]*=2;
 
8000
                                        if (cp[2]>126) cp[2]= 255; else cp[2]*=2;
 
8001
                                        if (cp[3]>126) cp[3]= 255; else cp[3]*=2;
6779
8002
                                        cp= (char *)&tface->col[2];
6780
 
                                        if(cp[1]>126) cp[1]= 255; else cp[1]*=2;
6781
 
                                        if(cp[2]>126) cp[2]= 255; else cp[2]*=2;
6782
 
                                        if(cp[3]>126) cp[3]= 255; else cp[3]*=2;
 
8003
                                        if (cp[1]>126) cp[1]= 255; else cp[1]*=2;
 
8004
                                        if (cp[2]>126) cp[2]= 255; else cp[2]*=2;
 
8005
                                        if (cp[3]>126) cp[3]= 255; else cp[3]*=2;
6783
8006
                                        cp= (char *)&tface->col[3];
6784
 
                                        if(cp[1]>126) cp[1]= 255; else cp[1]*=2;
6785
 
                                        if(cp[2]>126) cp[2]= 255; else cp[2]*=2;
6786
 
                                        if(cp[3]>126) cp[3]= 255; else cp[3]*=2;
 
8007
                                        if (cp[1]>126) cp[1]= 255; else cp[1]*=2;
 
8008
                                        if (cp[2]>126) cp[2]= 255; else cp[2]*=2;
 
8009
                                        if (cp[3]>126) cp[3]= 255; else cp[3]*=2;
6787
8010
 
6788
8011
                                        tface++;
6789
8012
                                }
6792
8015
                }
6793
8016
        }
6794
8017
 
6795
 
        if(main->versionfile <= 169) {
 
8018
        if (main->versionfile <= 169) {
6796
8019
                Mesh *me= main->mesh.first;
6797
 
                while(me) {
6798
 
                        if(me->subdiv==0) me->subdiv= 1;
 
8020
                while (me) {
 
8021
                        if (me->subdiv==0) me->subdiv= 1;
6799
8022
                        me= me->id.next;
6800
8023
                }
6801
8024
        }
6802
8025
 
6803
 
        if(main->versionfile <= 169) {
 
8026
        if (main->versionfile <= 169) {
6804
8027
                bScreen *sc= main->screen.first;
6805
 
                while(sc) {
 
8028
                while (sc) {
6806
8029
                        ScrArea *sa= sc->areabase.first;
6807
 
                        while(sa) {
 
8030
                        while (sa) {
6808
8031
                                SpaceLink *sl= sa->spacedata.first;
6809
 
                                while(sl) {
6810
 
                                        if(sl->spacetype==SPACE_IPO) {
 
8032
                                while (sl) {
 
8033
                                        if (sl->spacetype==SPACE_IPO) {
6811
8034
                                                SpaceIpo *sipo= (SpaceIpo*) sl;
6812
8035
                                                sipo->v2d.max[0]= 15000.0;
6813
8036
                                        }
6819
8042
                }
6820
8043
        }
6821
8044
 
6822
 
        if(main->versionfile <= 170) {
 
8045
        if (main->versionfile <= 170) {
6823
8046
                Object *ob = main->object.first;
6824
8047
                PartEff *paf;
6825
8048
                while (ob) {
6826
 
                        paf = give_parteff(ob);
 
8049
                        paf = do_version_give_parteff_245(ob);
6827
8050
                        if (paf) {
6828
8051
                                if (paf->staticstep == 0) {
6829
8052
                                        paf->staticstep= 5;
6833
8056
                }
6834
8057
        }
6835
8058
 
6836
 
        if(main->versionfile <= 171) {
 
8059
        if (main->versionfile <= 171) {
6837
8060
                bScreen *sc= main->screen.first;
6838
 
                while(sc) {
 
8061
                while (sc) {
6839
8062
                        ScrArea *sa= sc->areabase.first;
6840
 
                        while(sa) {
 
8063
                        while (sa) {
6841
8064
                                SpaceLink *sl= sa->spacedata.first;
6842
 
                                while(sl) {
6843
 
                                        if(sl->spacetype==SPACE_TEXT) {
 
8065
                                while (sl) {
 
8066
                                        if (sl->spacetype==SPACE_TEXT) {
6844
8067
                                                SpaceText *st= (SpaceText*) sl;
6845
8068
                                                st->lheight= 12;
6846
8069
                                        }
6852
8075
                }
6853
8076
        }
6854
8077
 
6855
 
        if(main->versionfile <= 173) {
 
8078
        if (main->versionfile <= 173) {
6856
8079
                int a, b;
6857
8080
                Mesh *me= main->mesh.first;
6858
 
                while(me) {
6859
 
                        if(me->tface) {
 
8081
                while (me) {
 
8082
                        if (me->tface) {
6860
8083
                                TFace *tface= me->tface;
6861
 
                                for(a=0; a<me->totface; a++, tface++) {
6862
 
                                        for(b=0; b<4; b++) {
6863
 
                                                tface->uv[b][0]/= 32767.0;
6864
 
                                                tface->uv[b][1]/= 32767.0;
 
8084
                                for (a=0; a<me->totface; a++, tface++) {
 
8085
                                        for (b=0; b<4; b++) {
 
8086
                                                tface->uv[b][0]/= 32767.0f;
 
8087
                                                tface->uv[b][1]/= 32767.0f;
6865
8088
                                        }
6866
8089
                                }
6867
8090
                        }
6869
8092
                }
6870
8093
        }
6871
8094
 
6872
 
        if(main->versionfile <= 191) {
 
8095
        if (main->versionfile <= 191) {
6873
8096
                Object *ob= main->object.first;
6874
8097
                Material *ma = main->mat.first;
6875
8098
 
6876
8099
                /* let faces have default add factor of 0.0 */
6877
 
                while(ma) {
 
8100
                while (ma) {
6878
8101
                  if (!(ma->mode & MA_HALO)) ma->add = 0.0;
6879
8102
                  ma = ma->id.next;
6880
8103
                }
6881
8104
 
6882
 
                while(ob) {
 
8105
                while (ob) {
6883
8106
                        ob->mass= 1.0f;
6884
8107
                        ob->damping= 0.1f;
6885
8108
                        /*ob->quat[1]= 1.0f;*/ /* quats arnt used yet */
6887
8110
                }
6888
8111
        }
6889
8112
 
6890
 
        if(main->versionfile <= 193) {
 
8113
        if (main->versionfile <= 193) {
6891
8114
                Object *ob= main->object.first;
6892
 
                while(ob) {
 
8115
                while (ob) {
6893
8116
                        ob->inertia= 1.0f;
6894
8117
                        ob->rdamping= 0.1f;
6895
8118
                        ob= ob->id.next;
6896
8119
                }
6897
8120
        }
6898
8121
 
6899
 
        if(main->versionfile <= 196) {
 
8122
        if (main->versionfile <= 196) {
6900
8123
                Mesh *me= main->mesh.first;
6901
8124
                int a, b;
6902
 
                while(me) {
6903
 
                        if(me->tface) {
 
8125
                while (me) {
 
8126
                        if (me->tface) {
6904
8127
                                TFace *tface= me->tface;
6905
 
                                for(a=0; a<me->totface; a++, tface++) {
6906
 
                                        for(b=0; b<4; b++) {
 
8128
                                for (a=0; a<me->totface; a++, tface++) {
 
8129
                                        for (b=0; b<4; b++) {
6907
8130
                                                tface->mode |= TF_DYNAMIC;
6908
8131
                                                tface->mode &= ~TF_INVISIBLE;
6909
8132
                                        }
6913
8136
                }
6914
8137
        }
6915
8138
 
6916
 
        if(main->versionfile <= 200) {
 
8139
        if (main->versionfile <= 200) {
6917
8140
                Object *ob= main->object.first;
6918
 
                while(ob) {
6919
 
                        ob->scaflag = ob->gameflag & (64+128+256+512+1024+2048);
 
8141
                while (ob) {
 
8142
                        ob->scaflag = ob->gameflag & (OB_DO_FH|OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
6920
8143
                                /* 64 is do_fh */
6921
 
                        ob->gameflag &= ~(128+256+512+1024+2048);
 
8144
                        ob->gameflag &= ~(OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
6922
8145
                        ob = ob->id.next;
6923
8146
                }
6924
8147
        }
6925
8148
 
6926
 
        if(main->versionfile <= 201) {
 
8149
        if (main->versionfile <= 201) {
6927
8150
                /* add-object + end-object are joined to edit-object actuator */
6928
8151
                Object *ob = main->object.first;
6929
8152
                bProperty *prop;
6934
8157
                while (ob) {
6935
8158
                        act = ob->actuators.first;
6936
8159
                        while (act) {
6937
 
                                if(act->type==ACT_IPO) {
 
8160
                                if (act->type==ACT_IPO) {
6938
8161
                                        ia= act->data;
6939
8162
                                        prop= get_ob_property(ob, ia->name);
6940
 
                                        if(prop) {
 
8163
                                        if (prop) {
6941
8164
                                                ia->type= ACT_IPO_FROM_PROP;
6942
8165
                                        }
6943
8166
                                }
6944
 
                                else if(act->type==ACT_ADD_OBJECT) {
 
8167
                                else if (act->type==ACT_ADD_OBJECT) {
6945
8168
                                        aoa= act->data;
6946
8169
                                        eoa= MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
6947
8170
                                        eoa->type= ACT_EDOB_ADD_OBJECT;
6951
8174
                                        act->data= eoa;
6952
8175
                                        act->type= act->otype= ACT_EDIT_OBJECT;
6953
8176
                                }
6954
 
                                else if(act->type==ACT_END_OBJECT) {
 
8177
                                else if (act->type==ACT_END_OBJECT) {
6955
8178
                                        eoa= MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
6956
8179
                                        eoa->type= ACT_EDOB_END_OBJECT;
6957
8180
                                        act->data= eoa;
6963
8186
                }
6964
8187
        }
6965
8188
 
6966
 
        if(main->versionfile <= 202) {
 
8189
        if (main->versionfile <= 202) {
6967
8190
                /* add-object and end-object are joined to edit-object
6968
8191
                 * actuator */
6969
8192
                Object *ob= main->object.first;
6970
8193
                bActuator *act;
6971
8194
                bObjectActuator *oa;
6972
 
                while(ob) {
 
8195
                while (ob) {
6973
8196
                        act= ob->actuators.first;
6974
 
                        while(act) {
6975
 
                                if(act->type==ACT_OBJECT) {
 
8197
                        while (act) {
 
8198
                                if (act->type==ACT_OBJECT) {
6976
8199
                                        oa= act->data;
6977
8200
                                        oa->flag &= ~(ACT_TORQUE_LOCAL|ACT_DROT_LOCAL);         /* this actuator didn't do local/glob rot before */
6978
8201
                                }
6982
8205
                }
6983
8206
        }
6984
8207
 
6985
 
        if(main->versionfile <= 204) {
 
8208
        if (main->versionfile <= 204) {
6986
8209
                /* patches for new physics */
6987
8210
                Object *ob= main->object.first;
6988
8211
                bActuator *act;
6989
8212
                bObjectActuator *oa;
6990
8213
                bSound *sound;
6991
 
                while(ob) {
 
8214
                while (ob) {
6992
8215
 
6993
8216
                        /* please check this for demo20 files like
6994
8217
                         * original Egypt levels etc.  converted
6995
8218
                         * rotation factor of 50 is not workable */
6996
8219
                        act= ob->actuators.first;
6997
 
                        while(act) {
6998
 
                                if(act->type==ACT_OBJECT) {
 
8220
                        while (act) {
 
8221
                                if (act->type==ACT_OBJECT) {
6999
8222
                                        oa= act->data;
7000
8223
 
7001
 
                                        oa->forceloc[0]*= 25.0;
7002
 
                                        oa->forceloc[1]*= 25.0;
7003
 
                                        oa->forceloc[2]*= 25.0;
 
8224
                                        oa->forceloc[0]*= 25.0f;
 
8225
                                        oa->forceloc[1]*= 25.0f;
 
8226
                                        oa->forceloc[2]*= 25.0f;
7004
8227
 
7005
 
                                        oa->forcerot[0]*= 10.0;
7006
 
                                        oa->forcerot[1]*= 10.0;
7007
 
                                        oa->forcerot[2]*= 10.0;
 
8228
                                        oa->forcerot[0]*= 10.0f;
 
8229
                                        oa->forcerot[1]*= 10.0f;
 
8230
                                        oa->forcerot[2]*= 10.0f;
7008
8231
                                }
7009
8232
                                act= act->next;
7010
8233
                        }
7013
8236
 
7014
8237
                sound = main->sound.first;
7015
8238
                while (sound) {
7016
 
                        if (sound->volume < 0.01) {
7017
 
                                sound->volume = 1.0;
 
8239
                        if (sound->volume < 0.01f) {
 
8240
                                sound->volume = 1.0f;
7018
8241
                        }
7019
8242
                        sound = sound->id.next;
7020
8243
                }
7021
8244
        }
7022
8245
 
7023
 
        if(main->versionfile <= 205) {
 
8246
        if (main->versionfile <= 205) {
7024
8247
                /* patches for new physics */
7025
8248
                Object *ob= main->object.first;
7026
8249
                bActuator *act;
7028
8251
                bEditObjectActuator *oa;
7029
8252
                bRaySensor *rs;
7030
8253
                bCollisionSensor *cs;
7031
 
                while(ob) {
 
8254
                while (ob) {
7032
8255
                        /* Set anisotropic friction off for old objects,
7033
8256
                         * values to 1.0.  */
7034
8257
                        ob->gameflag &= ~OB_ANISOTROPIC_FRICTION;
7037
8260
                        ob->anisotropicFriction[2] = 1.0;
7038
8261
 
7039
8262
                        act= ob->actuators.first;
7040
 
                        while(act) {
7041
 
                                if(act->type==ACT_EDIT_OBJECT) {
 
8263
                        while (act) {
 
8264
                                if (act->type==ACT_EDIT_OBJECT) {
7042
8265
                                        /* Zero initial velocity for newly
7043
8266
                                         * added objects */
7044
8267
                                        oa= act->data;
7053
8276
                        sens= ob->sensors.first;
7054
8277
                        while (sens) {
7055
8278
                                /* Extra fields for radar sensors. */
7056
 
                                if(sens->type == SENS_RADAR) {
 
8279
                                if (sens->type == SENS_RADAR) {
7057
8280
                                        bRadarSensor *s = sens->data;
7058
8281
                                        s->range = 10000.0;
7059
8282
                                }
7060
8283
 
7061
8284
                                /* Pulsing: defaults for new sensors. */
7062
 
                                if(sens->type != SENS_ALWAYS) {
 
8285
                                if (sens->type != SENS_ALWAYS) {
7063
8286
                                        sens->pulse = 0;
7064
8287
                                        sens->freq = 0;
7065
 
                                } else {
 
8288
                                }
 
8289
                                else {
7066
8290
                                        sens->pulse = 1;
7067
8291
                                }
7068
8292
 
7072
8296
                                /* Collision and ray: default = trigger
7073
8297
                                 * on property. The material field can
7074
8298
                                 * remain empty. */
7075
 
                                if(sens->type == SENS_COLLISION) {
 
8299
                                if (sens->type == SENS_COLLISION) {
7076
8300
                                        cs = (bCollisionSensor*) sens->data;
7077
8301
                                        cs->mode = 0;
7078
8302
                                }
7079
 
                                if(sens->type == SENS_RAY) {
 
8303
                                if (sens->type == SENS_RAY) {
7080
8304
                                        rs = (bRaySensor*) sens->data;
7081
8305
                                        rs->mode = 0;
7082
8306
                                }
7087
8311
                /* have to check the exact multiplier */
7088
8312
        }
7089
8313
 
7090
 
        if(main->versionfile <= 211) {
 
8314
        if (main->versionfile <= 211) {
7091
8315
                /* Render setting: per scene, the applicable gamma value
7092
8316
                 * can be set. Default is 1.0, which means no
7093
8317
                 * correction.  */
7097
8321
 
7098
8322
                /* added alpha in obcolor */
7099
8323
                ob= main->object.first;
7100
 
                while(ob) {
 
8324
                while (ob) {
7101
8325
                        ob->col[3]= 1.0;
7102
8326
                        ob= ob->id.next;
7103
8327
                }
7104
8328
 
7105
8329
                /* added alpha in obcolor */
7106
8330
                ob= main->object.first;
7107
 
                while(ob) {
 
8331
                while (ob) {
7108
8332
                        act= ob->actuators.first;
7109
 
                        while(act) {
 
8333
                        while (act) {
7110
8334
                                if (act->type==ACT_OBJECT) {
7111
8335
                                        /* multiply velocity with 50 in old files */
7112
8336
                                        oa= act->data;
7113
 
                                        if (fabs(oa->linearvelocity[0]) >= 0.01f)
7114
 
                                                oa->linearvelocity[0] *= 50.0;
7115
 
                                        if (fabs(oa->linearvelocity[1]) >= 0.01f)
7116
 
                                                oa->linearvelocity[1] *= 50.0;
7117
 
                                        if (fabs(oa->linearvelocity[2]) >= 0.01f)
7118
 
                                                oa->linearvelocity[2] *= 50.0;
7119
 
                                        if (fabs(oa->angularvelocity[0])>=0.01f)
7120
 
                                                oa->angularvelocity[0] *= 50.0;
7121
 
                                        if (fabs(oa->angularvelocity[1])>=0.01f)
7122
 
                                                oa->angularvelocity[1] *= 50.0;
7123
 
                                        if (fabs(oa->angularvelocity[2])>=0.01f)
7124
 
                                                oa->angularvelocity[2] *= 50.0;
 
8337
                                        if (fabsf(oa->linearvelocity[0]) >= 0.01f)
 
8338
                                                oa->linearvelocity[0] *= 50.0f;
 
8339
                                        if (fabsf(oa->linearvelocity[1]) >= 0.01f)
 
8340
                                                oa->linearvelocity[1] *= 50.0f;
 
8341
                                        if (fabsf(oa->linearvelocity[2]) >= 0.01f)
 
8342
                                                oa->linearvelocity[2] *= 50.0f;
 
8343
                                        if (fabsf(oa->angularvelocity[0])>=0.01f)
 
8344
                                                oa->angularvelocity[0] *= 50.0f;
 
8345
                                        if (fabsf(oa->angularvelocity[1])>=0.01f)
 
8346
                                                oa->angularvelocity[1] *= 50.0f;
 
8347
                                        if (fabsf(oa->angularvelocity[2])>=0.01f)
 
8348
                                                oa->angularvelocity[2] *= 50.0f;
7125
8349
                                }
7126
8350
                                act= act->next;
7127
8351
                        }
7129
8353
                }
7130
8354
        }
7131
8355
 
7132
 
        if(main->versionfile <= 212) {
 
8356
        if (main->versionfile <= 212) {
7133
8357
 
7134
8358
                bSound* sound;
7135
8359
                bProperty *prop;
7143
8367
                        sound->min_gain = 0.0;
7144
8368
                        sound->distance = 1.0;
7145
8369
 
7146
 
                        if (sound->attenuation > 0.0)
 
8370
                        if (sound->attenuation > 0.0f)
7147
8371
                                sound->flags |= SOUND_FLAGS_3D;
7148
8372
                        else
7149
8373
                                sound->flags &= ~SOUND_FLAGS_3D;
7155
8379
 
7156
8380
                while (ob) {
7157
8381
                        prop= ob->prop.first;
7158
 
                        while(prop) {
 
8382
                        while (prop) {
7159
8383
                                if (prop->type == GPROP_TIME) {
7160
8384
                                        // convert old GPROP_TIME values from int to float
7161
8385
                                        *((float *)&prop->data) = (float) prop->data;
7177
8401
                                me->flag|= ME_SUBSURF;
7178
8402
 
7179
8403
                                me->subdiv= 1;
7180
 
                        } else {
 
8404
                        }
 
8405
                        else {
7181
8406
                                if (me->subdiv<2)
7182
8407
                                        me->subdiv= 1;
7183
8408
                                else
7186
8411
                }
7187
8412
        }
7188
8413
 
7189
 
        if(main->versionfile <= 220) {
 
8414
        if (main->versionfile <= 220) {
7190
8415
                Object *ob;
7191
8416
                Mesh *me;
7192
8417
 
7193
8418
                ob = main->object.first;
7194
8419
 
7195
8420
                /* adapt form factor in order to get the 'old' physics
7196
 
                 * behaviour back...*/
 
8421
                 * behavior back...*/
7197
8422
 
7198
8423
                while (ob) {
7199
8424
                        /* in future, distinguish between different
7201
8426
                        ob->formfactor = 0.4f;
7202
8427
                        /* patch form factor , note that inertia equiv radius
7203
8428
                         * of a rotation symmetrical obj */
7204
 
                        if (ob->inertia != 1.0) {
 
8429
                        if (ob->inertia != 1.0f) {
7205
8430
                                ob->formfactor /= ob->inertia * ob->inertia;
7206
8431
                        }
7207
8432
                        ob = ob->id.next;
7235
8460
                        }
7236
8461
                }
7237
8462
        }
7238
 
        if(main->versionfile <= 221) {
 
8463
        if (main->versionfile <= 221) {
7239
8464
                Scene *sce= main->scene.first;
7240
8465
 
7241
8466
                // new variables for std-alone player and runtime
7242
 
                while(sce) {
 
8467
                while (sce) {
7243
8468
 
7244
8469
                        sce->r.xplay= 640;
7245
8470
                        sce->r.yplay= 480;
7249
8474
                }
7250
8475
 
7251
8476
        }
7252
 
        if(main->versionfile <= 222) {
 
8477
        if (main->versionfile <= 222) {
7253
8478
                Scene *sce= main->scene.first;
7254
8479
 
7255
8480
                // new variables for std-alone player and runtime
7256
 
                while(sce) {
 
8481
                while (sce) {
7257
8482
 
7258
8483
                        sce->r.depth= 32;
7259
8484
 
7262
8487
        }
7263
8488
 
7264
8489
 
7265
 
        if(main->versionfile <= 223) {
 
8490
        if (main->versionfile <= 223) {
7266
8491
                VFont *vf;
7267
8492
                Image *ima;
7268
8493
                Object *ob;
7269
8494
 
7270
8495
                for (vf= main->vfont.first; vf; vf= vf->id.next) {
7271
 
                        if (BLI_streq(vf->name+strlen(vf->name)-6, ".Bfont")) {
7272
 
                                strcpy(vf->name, "<builtin>");
 
8496
                        if (strcmp(vf->name+strlen(vf->name)-6, ".Bfont")==0) {
 
8497
                                strcpy(vf->name, FO_BUILTIN_NAME);
7273
8498
                        }
7274
8499
                }
7275
8500
 
7276
8501
                /* Old textures animate at 25 FPS */
7277
 
                for (ima = main->image.first; ima; ima=ima->id.next){
 
8502
                for (ima = main->image.first; ima; ima=ima->id.next) {
7278
8503
                        ima->animspeed = 25;
7279
8504
                }
7280
8505
 
7293
8518
                        }
7294
8519
                }
7295
8520
        }
7296
 
        if(main->versionfile <= 224) {
 
8521
        if (main->versionfile <= 224) {
7297
8522
                bSound* sound;
7298
8523
                Scene *sce;
7299
8524
                Mesh *me;
7308
8533
                        }
7309
8534
                }
7310
8535
                /* Make sure that old subsurf meshes don't have zero subdivision level for rendering */
7311
 
                for (me=main->mesh.first; me; me=me->id.next){
 
8536
                for (me=main->mesh.first; me; me=me->id.next) {
7312
8537
                        if ((me->flag & ME_SUBSURF) && (me->subdivr==0))
7313
8538
                                me->subdivr=me->subdiv;
7314
8539
                }
7336
8561
        }
7337
8562
 
7338
8563
 
7339
 
        if(main->versionfile <= 225) {
 
8564
        if (main->versionfile <= 225) {
7340
8565
                World *wo;
7341
8566
                /* Use Sumo for old games */
7342
8567
                for (wo = main->world.first; wo; wo= wo->id.next) {
7344
8569
                }
7345
8570
        }
7346
8571
 
7347
 
        if(main->versionfile <= 227) {
 
8572
        if (main->versionfile <= 227) {
7348
8573
                Scene *sce;
7349
8574
                Material *ma;
7350
8575
                bScreen *sc;
7351
8576
                Object *ob;
7352
8577
 
7353
 
                /*  As of now, this insures that the transition from the old Track system
7354
 
                        to the new full constraint Track is painless for everyone. - theeth
7355
 
                */
 
8578
                /* As of now, this insures that the transition from the old Track system
 
8579
                 * to the new full constraint Track is painless for everyone. - theeth
 
8580
                 */
7356
8581
                ob = main->object.first;
7357
8582
 
7358
8583
                while (ob) {
7360
8585
                        list = &ob->constraints;
7361
8586
 
7362
8587
                        /* check for already existing TrackTo constraint
7363
 
                           set their track and up flag correctly */
 
8588
                         * set their track and up flag correctly */
7364
8589
 
7365
 
                        if (list){
 
8590
                        if (list) {
7366
8591
                                bConstraint *curcon;
7367
 
                                for (curcon = list->first; curcon; curcon=curcon->next){
7368
 
                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO){
 
8592
                                for (curcon = list->first; curcon; curcon=curcon->next) {
 
8593
                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
7369
8594
                                                bTrackToConstraint *data = curcon->data;
7370
8595
                                                data->reserved1 = ob->trackflag;
7371
8596
                                                data->reserved2 = ob->upflag;
7374
8599
                        }
7375
8600
 
7376
8601
                        if (ob->type == OB_ARMATURE) {
7377
 
                                if (ob->pose){
 
8602
                                if (ob->pose) {
7378
8603
                                        bConstraint *curcon;
7379
8604
                                        bPoseChannel *pchan;
7380
8605
                                        for (pchan = ob->pose->chanbase.first;
7381
 
                                                 pchan; pchan=pchan->next){
 
8606
                                                 pchan; pchan=pchan->next) {
7382
8607
                                                for (curcon = pchan->constraints.first;
7383
 
                                                         curcon; curcon=curcon->next){
7384
 
                                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO){
 
8608
                                                         curcon; curcon=curcon->next) {
 
8609
                                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
7385
8610
                                                                bTrackToConstraint *data = curcon->data;
7386
8611
                                                                data->reserved1 = ob->trackflag;
7387
8612
                                                                data->reserved2 = ob->upflag;
7432
8657
                        }
7433
8658
                }
7434
8659
        }
7435
 
        if(main->versionfile <= 228) {
 
8660
        if (main->versionfile <= 228) {
7436
8661
                Scene *sce;
7437
8662
                bScreen *sc;
7438
8663
                Object *ob;
7439
8664
 
7440
8665
 
7441
 
                /*  As of now, this insures that the transition from the old Track system
7442
 
                        to the new full constraint Track is painless for everyone.*/
 
8666
                /* As of now, this insures that the transition from the old Track system
 
8667
                 * to the new full constraint Track is painless for everyone.*/
7443
8668
                ob = main->object.first;
7444
8669
 
7445
8670
                while (ob) {
7447
8672
                        list = &ob->constraints;
7448
8673
 
7449
8674
                        /* check for already existing TrackTo constraint
7450
 
                           set their track and up flag correctly */
 
8675
                         * set their track and up flag correctly */
7451
8676
 
7452
 
                        if (list){
 
8677
                        if (list) {
7453
8678
                                bConstraint *curcon;
7454
 
                                for (curcon = list->first; curcon; curcon=curcon->next){
7455
 
                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO){
 
8679
                                for (curcon = list->first; curcon; curcon=curcon->next) {
 
8680
                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
7456
8681
                                                bTrackToConstraint *data = curcon->data;
7457
8682
                                                data->reserved1 = ob->trackflag;
7458
8683
                                                data->reserved2 = ob->upflag;
7461
8686
                        }
7462
8687
 
7463
8688
                        if (ob->type == OB_ARMATURE) {
7464
 
                                if (ob->pose){
 
8689
                                if (ob->pose) {
7465
8690
                                        bConstraint *curcon;
7466
8691
                                        bPoseChannel *pchan;
7467
8692
                                        for (pchan = ob->pose->chanbase.first;
7468
 
                                                 pchan; pchan=pchan->next){
 
8693
                                                 pchan; pchan=pchan->next) {
7469
8694
                                                for (curcon = pchan->constraints.first;
7470
 
                                                         curcon; curcon=curcon->next){
7471
 
                                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO){
 
8695
                                                         curcon; curcon=curcon->next) {
 
8696
                                                        if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
7472
8697
                                                                bTrackToConstraint *data = curcon->data;
7473
8698
                                                                data->reserved1 = ob->trackflag;
7474
8699
                                                                data->reserved2 = ob->upflag;
7499
8724
                                                sbuts->v2d.maxzoom= 1.2f;
7500
8725
                                                sbuts->align= 1;        /* horizontal default */
7501
8726
                                        
7502
 
                                                if(sbuts->mainb==BUTS_LAMP) {
 
8727
                                                if (sbuts->mainb==BUTS_LAMP) {
7503
8728
                                                        sbuts->mainb= CONTEXT_SHADING;
7504
8729
                                                        //sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
7505
8730
                                                }
7506
 
                                                else if(sbuts->mainb==BUTS_MAT) {
 
8731
                                                else if (sbuts->mainb==BUTS_MAT) {
7507
8732
                                                        sbuts->mainb= CONTEXT_SHADING;
7508
8733
                                                        //sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
7509
8734
                                                }
7510
 
                                                else if(sbuts->mainb==BUTS_TEX) {
 
8735
                                                else if (sbuts->mainb==BUTS_TEX) {
7511
8736
                                                        sbuts->mainb= CONTEXT_SHADING;
7512
8737
                                                        //sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
7513
8738
                                                }
7514
 
                                                else if(sbuts->mainb==BUTS_ANIM) {
 
8739
                                                else if (sbuts->mainb==BUTS_ANIM) {
7515
8740
                                                        sbuts->mainb= CONTEXT_OBJECT;
7516
8741
                                                }
7517
 
                                                else if(sbuts->mainb==BUTS_WORLD) {
 
8742
                                                else if (sbuts->mainb==BUTS_WORLD) {
7518
8743
                                                        sbuts->mainb= CONTEXT_SCENE;
7519
8744
                                                        //sbuts->tab[CONTEXT_SCENE]= TAB_SCENE_WORLD;
7520
8745
                                                }
7521
 
                                                else if(sbuts->mainb==BUTS_RENDER) {
 
8746
                                                else if (sbuts->mainb==BUTS_RENDER) {
7522
8747
                                                        sbuts->mainb= CONTEXT_SCENE;
7523
8748
                                                        //sbuts->tab[CONTEXT_SCENE]= TAB_SCENE_RENDER;
7524
8749
                                                }
7525
 
                                                else if(sbuts->mainb==BUTS_GAME) {
 
8750
                                                else if (sbuts->mainb==BUTS_GAME) {
7526
8751
                                                        sbuts->mainb= CONTEXT_LOGIC;
7527
8752
                                                }
7528
 
                                                else if(sbuts->mainb==BUTS_FPAINT) {
 
8753
                                                else if (sbuts->mainb==BUTS_FPAINT) {
7529
8754
                                                        sbuts->mainb= CONTEXT_EDITING;
7530
8755
                                                }
7531
 
                                                else if(sbuts->mainb==BUTS_RADIO) {
 
8756
                                                else if (sbuts->mainb==BUTS_RADIO) {
7532
8757
                                                        sbuts->mainb= CONTEXT_SHADING;
7533
8758
                                                        //sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_RAD;
7534
8759
                                                }
7535
 
                                                else if(sbuts->mainb==BUTS_CONSTRAINT) {
7536
 
                                                        sbuts->mainb= CONTEXT_OBJECT;
7537
 
                                                }
7538
 
                                                else if(sbuts->mainb==BUTS_SCRIPT) {
7539
 
                                                        sbuts->mainb= CONTEXT_OBJECT;
7540
 
                                                }
7541
 
                                                else if(sbuts->mainb==BUTS_EDIT) {
 
8760
                                                else if (sbuts->mainb==BUTS_CONSTRAINT) {
 
8761
                                                        sbuts->mainb= CONTEXT_OBJECT;
 
8762
                                                }
 
8763
                                                else if (sbuts->mainb==BUTS_SCRIPT) {
 
8764
                                                        sbuts->mainb= CONTEXT_OBJECT;
 
8765
                                                }
 
8766
                                                else if (sbuts->mainb==BUTS_EDIT) {
7542
8767
                                                        sbuts->mainb= CONTEXT_EDITING;
7543
8768
                                                }
7544
8769
                                                else sbuts->mainb= CONTEXT_SCENE;
7548
8773
                }
7549
8774
        }
7550
8775
        /* ton: made this 230 instead of 229,
7551
 
           to be sure (tuho files) and this is a reliable check anyway
7552
 
           nevertheless, we might need to think over a fitness (initialize)
7553
 
           check apart from the do_versions() */
 
8776
         * to be sure (tuho files) and this is a reliable check anyway
 
8777
         * nevertheless, we might need to think over a fitness (initialize)
 
8778
         * check apart from the do_versions() */
7554
8779
 
7555
 
        if(main->versionfile <= 230) {
 
8780
        if (main->versionfile <= 230) {
7556
8781
                bScreen *sc;
7557
8782
 
7558
8783
                // new variable blockscale, for panels in any area
7563
8788
                                SpaceLink *sl;
7564
8789
 
7565
8790
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
7566
 
                                        if(sl->blockscale==0.0) sl->blockscale= 0.7f;
 
8791
                                        if (sl->blockscale==0.0f) sl->blockscale= 0.7f;
7567
8792
                                        /* added: 5x better zoom in for action */
7568
 
                                        if(sl->spacetype==SPACE_ACTION) {
 
8793
                                        if (sl->spacetype==SPACE_ACTION) {
7569
8794
                                                SpaceAction *sac= (SpaceAction *)sl;
7570
8795
                                                sac->v2d.maxzoom= 50;
7571
8796
                                        }
7573
8798
                        }
7574
8799
                }
7575
8800
        }
7576
 
        if(main->versionfile <= 231) {
 
8801
        if (main->versionfile <= 231) {
7577
8802
                /* new bit flags for showing/hiding grid floor and axes */
7578
8803
                bScreen *sc = main->screen.first;
7579
 
                while(sc) {
 
8804
                while (sc) {
7580
8805
                        ScrArea *sa= sc->areabase.first;
7581
 
                        while(sa) {
 
8806
                        while (sa) {
7582
8807
                                SpaceLink *sl= sa->spacedata.first;
7583
8808
                                while (sl) {
7584
8809
                                        if (sl->spacetype==SPACE_VIEW3D) {
7598
8823
                        sc= sc->id.next;
7599
8824
                }
7600
8825
        }
7601
 
        if(main->versionfile <= 231) {
 
8826
        if (main->versionfile <= 231) {
7602
8827
                Material *ma= main->mat.first;
7603
8828
                bScreen *sc = main->screen.first;
7604
8829
                Scene *sce;
7606
8831
                World *wrld;
7607
8832
 
7608
8833
                /* introduction of raytrace */
7609
 
                while(ma) {
7610
 
                        if(ma->fresnel_tra_i==0.0) ma->fresnel_tra_i= 1.25;
7611
 
                        if(ma->fresnel_mir_i==0.0) ma->fresnel_mir_i= 1.25;
 
8834
                while (ma) {
 
8835
                        if (ma->fresnel_tra_i==0.0f) ma->fresnel_tra_i= 1.25f;
 
8836
                        if (ma->fresnel_mir_i==0.0f) ma->fresnel_mir_i= 1.25f;
7612
8837
 
7613
8838
                        ma->ang= 1.0;
7614
8839
                        ma->ray_depth= 2;
7619
8844
                        ma= ma->id.next;
7620
8845
                }
7621
8846
                sce= main->scene.first;
7622
 
                while(sce) {
7623
 
                        if(sce->r.gauss==0.0) sce->r.gauss= 1.0;
 
8847
                while (sce) {
 
8848
                        if (sce->r.gauss==0.0f) sce->r.gauss= 1.0f;
7624
8849
                        sce= sce->id.next;
7625
8850
                }
7626
8851
                la= main->lamp.first;
7627
 
                while(la) {
7628
 
                        if(la->k==0.0) la->k= 1.0;
7629
 
                        if(la->ray_samp==0) la->ray_samp= 1;
7630
 
                        if(la->ray_sampy==0) la->ray_sampy= 1;
7631
 
                        if(la->ray_sampz==0) la->ray_sampz= 1;
7632
 
                        if(la->area_size==0.0) la->area_size= 1.0;
7633
 
                        if(la->area_sizey==0.0) la->area_sizey= 1.0;
7634
 
                        if(la->area_sizez==0.0) la->area_sizez= 1.0;
 
8852
                while (la) {
 
8853
                        if (la->k==0.0f) la->k= 1.0;
 
8854
                        if (la->ray_samp==0) la->ray_samp= 1;
 
8855
                        if (la->ray_sampy==0) la->ray_sampy= 1;
 
8856
                        if (la->ray_sampz==0) la->ray_sampz= 1;
 
8857
                        if (la->area_size==0.0f) la->area_size= 1.0f;
 
8858
                        if (la->area_sizey==0.0f) la->area_sizey= 1.0f;
 
8859
                        if (la->area_sizez==0.0f) la->area_sizez= 1.0f;
7635
8860
                        la= la->id.next;
7636
8861
                }
7637
8862
                wrld= main->world.first;
7638
 
                while(wrld) {
7639
 
                        if(wrld->range==0.0) {
 
8863
                while (wrld) {
 
8864
                        if (wrld->range==0.0f) {
7640
8865
                                wrld->range= 1.0f/wrld->exposure;
7641
8866
                        }
7642
8867
                        wrld= wrld->id.next;
7644
8869
 
7645
8870
                /* new bit flags for showing/hiding grid floor and axes */
7646
8871
 
7647
 
                while(sc) {
 
8872
                while (sc) {
7648
8873
                        ScrArea *sa= sc->areabase.first;
7649
 
                        while(sa) {
 
8874
                        while (sa) {
7650
8875
                                SpaceLink *sl= sa->spacedata.first;
7651
8876
                                while (sl) {
7652
8877
                                        if (sl->spacetype==SPACE_VIEW3D) {
7666
8891
                        sc= sc->id.next;
7667
8892
                }
7668
8893
        }
7669
 
        if(main->versionfile <= 232) {
 
8894
        if (main->versionfile <= 232) {
7670
8895
                Tex *tex= main->tex.first;
7671
8896
                World *wrld= main->world.first;
7672
8897
                bScreen *sc;
7673
8898
                Scene *sce;
7674
8899
 
7675
 
                while(tex) {
7676
 
                        if((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
 
8900
                while (tex) {
 
8901
                        if ((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
7677
8902
                                tex->flag |= TEX_CHECKER_ODD;
7678
8903
                        }
7679
8904
                        /* copied from kernel texture.c */
7680
 
                        if(tex->ns_outscale==0.0) {
 
8905
                        if (tex->ns_outscale==0.0f) {
7681
8906
                                /* musgrave */
7682
8907
                                tex->mg_H = 1.0f;
7683
8908
                                tex->mg_lacunarity = 2.0f;
7694
8919
                        tex= tex->id.next;
7695
8920
                }
7696
8921
 
7697
 
                while(wrld) {
7698
 
                        if(wrld->aodist==0.0) {
 
8922
                while (wrld) {
 
8923
                        if (wrld->aodist==0.0f) {
7699
8924
                                wrld->aodist= 10.0f;
7700
8925
                                wrld->aobias= 0.05f;
7701
8926
                        }
7702
 
                        if(wrld->aosamp==0.0) wrld->aosamp= 5;
7703
 
                        if(wrld->aoenergy==0.0) wrld->aoenergy= 1.0;
 
8927
                        if (wrld->aosamp==0) wrld->aosamp= 5;
 
8928
                        if (wrld->aoenergy==0.0f) wrld->aoenergy= 1.0f;
7704
8929
                        wrld= wrld->id.next;
7705
8930
                }
7706
8931
 
7712
8937
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
7713
8938
                                SpaceLink *sl;
7714
8939
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
7715
 
                                        if(sl->blockscale==0.0) sl->blockscale= 0.7f;
 
8940
                                        if (sl->blockscale==0.0f) sl->blockscale= 0.7f;
7716
8941
 
7717
8942
                                        /* added: 5x better zoom in for nla */
7718
 
                                        if(sl->spacetype==SPACE_NLA) {
 
8943
                                        if (sl->spacetype==SPACE_NLA) {
7719
8944
                                                SpaceNla *snla= (SpaceNla *)sl;
7720
8945
                                                snla->v2d.maxzoom= 50;
7721
8946
                                        }
7723
8948
                        }
7724
8949
                }
7725
8950
                sce= main->scene.first;
7726
 
                while(sce) {
7727
 
                        if(sce->r.ocres==0) sce->r.ocres= 64;
 
8951
                while (sce) {
 
8952
                        if (sce->r.ocres==0) sce->r.ocres= 64;
7728
8953
                        sce= sce->id.next;
7729
8954
                }
7730
8955
 
7731
8956
        }
7732
 
        if(main->versionfile <= 233) {
 
8957
        if (main->versionfile <= 233) {
7733
8958
                bScreen *sc;
7734
8959
                Material *ma= main->mat.first;
7735
 
                Object *ob= main->object.first;
 
8960
                /* Object *ob= main->object.first; */
7736
8961
                
7737
 
                while(ma) {
7738
 
                        if(ma->rampfac_col==0.0) ma->rampfac_col= 1.0;
7739
 
                        if(ma->rampfac_spec==0.0) ma->rampfac_spec= 1.0;
7740
 
                        if(ma->pr_lamp==0) ma->pr_lamp= 3;
 
8962
                while (ma) {
 
8963
                        if (ma->rampfac_col==0.0f) ma->rampfac_col= 1.0;
 
8964
                        if (ma->rampfac_spec==0.0f) ma->rampfac_spec= 1.0;
 
8965
                        if (ma->pr_lamp==0) ma->pr_lamp= 3;
7741
8966
                        ma= ma->id.next;
7742
8967
                }
7743
8968
                
7744
8969
                /* this should have been done loooong before! */
7745
 
                while(ob) {
7746
 
                        if(ob->ipowin==0) ob->ipowin= ID_OB;
 
8970
#if 0   /* deprecated in 2.5+ */
 
8971
                while (ob) {
 
8972
                        if (ob->ipowin==0) ob->ipowin= ID_OB;
7747
8973
                        ob= ob->id.next;
7748
8974
                }
7749
 
                
 
8975
#endif
7750
8976
                for (sc= main->screen.first; sc; sc= sc->id.next) {
7751
8977
                        ScrArea *sa;
7752
8978
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
7753
8979
                                SpaceLink *sl;
7754
8980
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
7755
 
                                        if(sl->spacetype==SPACE_VIEW3D) {
 
8981
                                        if (sl->spacetype==SPACE_VIEW3D) {
7756
8982
                                                View3D *v3d= (View3D *)sl;
7757
8983
                                                v3d->flag |= V3D_SELECT_OUTLINE;
7758
8984
                                        }
7764
8990
 
7765
8991
        
7766
8992
 
7767
 
        if(main->versionfile <= 234) {
 
8993
        if (main->versionfile <= 234) {
7768
8994
                World *wo;
7769
8995
                bScreen *sc;
7770
8996
                
7771
8997
                // force sumo engine to be active
7772
8998
                for (wo = main->world.first; wo; wo= wo->id.next) {
7773
 
                        if(wo->physicsEngine==0) wo->physicsEngine = 2;
 
8999
                        if (wo->physicsEngine==0) wo->physicsEngine = 2;
7774
9000
                }
7775
9001
                
7776
9002
                for (sc= main->screen.first; sc; sc= sc->id.next) {
7778
9004
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
7779
9005
                                SpaceLink *sl;
7780
9006
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
7781
 
                                        if(sl->spacetype==SPACE_VIEW3D) {
 
9007
                                        if (sl->spacetype==SPACE_VIEW3D) {
7782
9008
                                                View3D *v3d= (View3D *)sl;
7783
9009
                                                v3d->flag |= V3D_ZBUF_SELECT;
7784
9010
                                        }
7785
 
                                        else if(sl->spacetype==SPACE_TEXT) {
 
9011
                                        else if (sl->spacetype==SPACE_TEXT) {
7786
9012
                                                SpaceText *st= (SpaceText *)sl;
7787
 
                                                if(st->tabnumber==0) st->tabnumber= 2;
 
9013
                                                if (st->tabnumber==0) st->tabnumber= 2;
7788
9014
                                        }
7789
9015
                                }
7790
9016
                        }
7791
9017
                }
7792
9018
        }
7793
 
        if(main->versionfile <= 235) {
 
9019
        if (main->versionfile <= 235) {
7794
9020
                Tex *tex= main->tex.first;
7795
9021
                Scene *sce= main->scene.first;
7796
9022
                Sequence *seq;
7797
9023
                Editing *ed;
7798
9024
                
7799
 
                while(tex) {
7800
 
                        if(tex->nabla==0.0) tex->nabla= 0.025f;
 
9025
                while (tex) {
 
9026
                        if (tex->nabla==0.0f) tex->nabla= 0.025f;
7801
9027
                        tex= tex->id.next;
7802
9028
                }
7803
 
                while(sce) {
 
9029
                while (sce) {
7804
9030
                        ed= sce->ed;
7805
 
                        if(ed) {
 
9031
                        if (ed) {
7806
9032
                                SEQ_BEGIN(sce->ed, seq) {
7807
 
                                        if(seq->type==SEQ_IMAGE || seq->type==SEQ_MOVIE)
 
9033
                                        if (seq->type==SEQ_IMAGE || seq->type==SEQ_MOVIE)
7808
9034
                                                seq->flag |= SEQ_MAKE_PREMUL;
7809
9035
                                }
7810
9036
                                SEQ_END
7813
9039
                        sce= sce->id.next;
7814
9040
                }
7815
9041
        }
7816
 
        if(main->versionfile <= 236) {
 
9042
        if (main->versionfile <= 236) {
7817
9043
                Object *ob;
7818
9044
                Camera *cam= main->camera.first;
7819
9045
                Material *ma;
7820
9046
                bScreen *sc;
7821
9047
 
7822
 
                while(cam) {
7823
 
                        if(cam->ortho_scale==0.0) {
 
9048
                while (cam) {
 
9049
                        if (cam->ortho_scale==0.0f) {
7824
9050
                                cam->ortho_scale= 256.0f/cam->lens;
7825
 
                                if(cam->type==CAM_ORTHO) printf("NOTE: ortho render has changed, tweak new Camera 'scale' value.\n");
 
9051
                                if (cam->type==CAM_ORTHO) printf("NOTE: ortho render has changed, tweak new Camera 'scale' value.\n");
7826
9052
                        }
7827
9053
                        cam= cam->id.next;
7828
9054
                }
7834
9060
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
7835
9061
                                SpaceLink *sl;
7836
9062
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
7837
 
                                        if(sl->spacetype==SPACE_VIEW3D) {
 
9063
                                        if (sl->spacetype==SPACE_VIEW3D) {
7838
9064
                                                View3D *v3d= (View3D *)sl;
7839
 
                                                if(v3d->twtype==0) v3d->twtype= V3D_MANIP_TRANSLATE;
7840
 
                                        }
7841
 
                                        else if(sl->spacetype==SPACE_TIME) {
7842
 
                                                SpaceTime *stime= (SpaceTime *)sl;
7843
 
                                                if(stime->redraws==0)
7844
 
                                                        stime->redraws= TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
 
9065
                                                if (v3d->twtype==0) v3d->twtype= V3D_MANIP_TRANSLATE;
7845
9066
                                        }
7846
9067
                                }
7847
9068
                        }
7848
9069
                }
7849
9070
                // init new shader vars
7850
9071
                for (ma= main->mat.first; ma; ma= ma->id.next) {
7851
 
                        if(ma->darkness==0.0) {
 
9072
                        if (ma->darkness==0.0f) {
7852
9073
                                ma->rms=0.1f;
7853
9074
                                ma->darkness=1.0f;
7854
9075
                        }
7855
9076
                }
7856
9077
                
7857
9078
                /* softbody init new vars */
7858
 
                for(ob= main->object.first; ob; ob= ob->id.next) {
7859
 
                        if(ob->soft) {
7860
 
                                if(ob->soft->defgoal==0.0) ob->soft->defgoal= 0.7f;
7861
 
                                if(ob->soft->physics_speed==0.0) ob->soft->physics_speed= 1.0f;
 
9079
                for (ob= main->object.first; ob; ob= ob->id.next) {
 
9080
                        if (ob->soft) {
 
9081
                                if (ob->soft->defgoal==0.0f) ob->soft->defgoal= 0.7f;
 
9082
                                if (ob->soft->physics_speed==0.0f) ob->soft->physics_speed= 1.0f;
7862
9083
                                
7863
 
                                if(ob->soft->interval==0) {
 
9084
                                if (ob->soft->interval==0) {
7864
9085
                                        ob->soft->interval= 2;
7865
9086
                                        ob->soft->sfra= 1;
7866
9087
                                        ob->soft->efra= 100;
7867
9088
                                }
7868
9089
                        }
7869
 
                        if(ob->soft && ob->soft->vertgroup==0) {
 
9090
                        if (ob->soft && ob->soft->vertgroup==0) {
7870
9091
                                bDeformGroup *locGroup = defgroup_find_name(ob, "SOFTGOAL");
7871
 
                                if(locGroup){
 
9092
                                if (locGroup) {
7872
9093
                                        /* retrieve index for that group */
7873
 
                                        ob->soft->vertgroup =  1 + defgroup_find_index(ob, locGroup); 
 
9094
                                        ob->soft->vertgroup =  1 + BLI_findindex(&ob->defbase, locGroup);
7874
9095
                                }
7875
9096
                        }
7876
9097
                }
7877
9098
        }
7878
 
        if(main->versionfile <= 237) {
 
9099
        if (main->versionfile <= 237) {
7879
9100
                bArmature *arm;
7880
9101
                bConstraint *con;
7881
9102
                Object *ob;
 
9103
                Bone *bone;
7882
9104
                
7883
9105
                // armature recode checks 
7884
 
                for(arm= main->armature.first; arm; arm= arm->id.next) {
 
9106
                for (arm= main->armature.first; arm; arm= arm->id.next) {
7885
9107
                        where_is_armature(arm);
 
9108
 
 
9109
                        for (bone= arm->bonebase.first; bone; bone= bone->next)
 
9110
                                do_version_bone_head_tail_237(bone);
7886
9111
                }
7887
 
                for(ob= main->object.first; ob; ob= ob->id.next) {
7888
 
                        if(ob->parent) {
 
9112
                for (ob= main->object.first; ob; ob= ob->id.next) {
 
9113
                        if (ob->parent) {
7889
9114
                                Object *parent= newlibadr(fd, lib, ob->parent);
7890
9115
                                if (parent && parent->type==OB_LATTICE)
7891
9116
                                        ob->partype = PARSKEL;
7892
9117
                        }
7893
9118
 
7894
9119
                        // btw. armature_rebuild_pose is further only called on leave editmode
7895
 
                        if(ob->type==OB_ARMATURE) {
7896
 
                                if(ob->pose)
 
9120
                        if (ob->type==OB_ARMATURE) {
 
9121
                                if (ob->pose)
7897
9122
                                        ob->pose->flag |= POSE_RECALC;
7898
 
                                ob->recalc |= OB_RECALC_ALL;    // cannot call stuff now (pointers!), done in setup_app_data
 
9123
                                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;       // cannot call stuff now (pointers!), done in setup_app_data
7899
9124
 
7900
9125
                                /* new generic xray option */
7901
9126
                                arm= newlibadr(fd, lib, ob->data);
7902
 
                                if(arm->flag & ARM_DRAWXRAY) {
 
9127
                                if (arm->flag & ARM_DRAWXRAY) {
7903
9128
                                        ob->dtx |= OB_DRAWXRAY;
7904
9129
                                }
7905
 
                        } else if (ob->type==OB_MESH) {
 
9130
                        }
 
9131
                        else if (ob->type==OB_MESH) {
7906
9132
                                Mesh *me = newlibadr(fd, lib, ob->data);
7907
9133
                                
7908
9134
                                if ((me->flag&ME_SUBSURF)) {
7927
9153
                        }
7928
9154
                        
7929
9155
                        // follow path constraint needs to set the 'path' option in curves...
7930
 
                        for(con=ob->constraints.first; con; con= con->next) {
7931
 
                                if(con->type==CONSTRAINT_TYPE_FOLLOWPATH) {
 
9156
                        for (con=ob->constraints.first; con; con= con->next) {
 
9157
                                if (con->type==CONSTRAINT_TYPE_FOLLOWPATH) {
7932
9158
                                        bFollowPathConstraint *data = con->data;
7933
9159
                                        Object *obc= newlibadr(fd, lib, data->tar);
7934
9160
                                        
7935
 
                                        if(obc && obc->type==OB_CURVE) {
 
9161
                                        if (obc && obc->type==OB_CURVE) {
7936
9162
                                                Curve *cu= newlibadr(fd, lib, obc->data);
7937
 
                                                if(cu) cu->flag |= CU_PATH;
 
9163
                                                if (cu) cu->flag |= CU_PATH;
7938
9164
                                        }
7939
9165
                                }
7940
9166
                        }
7941
9167
                }
7942
9168
        }
7943
 
        if(main->versionfile <= 238) {
 
9169
        if (main->versionfile <= 238) {
7944
9170
                Lattice *lt;
7945
9171
                Object *ob;
7946
9172
                bArmature *arm;
7948
9174
                Key *key;
7949
9175
                Scene *sce= main->scene.first;
7950
9176
 
7951
 
                while(sce){
7952
 
                        if(sce->toolsettings == NULL){
 
9177
                while (sce) {
 
9178
                        if (sce->toolsettings == NULL) {
7953
9179
                                sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings),"Tool Settings Struct");    
7954
9180
                                sce->toolsettings->cornertype=0;
7955
9181
                                sce->toolsettings->degr = 90; 
7960
9186
                                sce->toolsettings->segments = 32;
7961
9187
                                sce->toolsettings->rings = 32;
7962
9188
                                sce->toolsettings->vertices = 32;
7963
 
                                sce->toolsettings->editbutflag =1;
7964
9189
                        }
7965
9190
                        sce= sce->id.next;      
7966
9191
                }
7967
9192
 
7968
9193
                for (lt=main->latt.first; lt; lt=lt->id.next) {
7969
 
                        if (lt->fu==0.0 && lt->fv==0.0 && lt->fw==0.0) {
 
9194
                        if (lt->fu==0.0f && lt->fv==0.0f && lt->fw==0.0f) {
7970
9195
                                calc_lat_fudu(lt->flag, lt->pntsu, &lt->fu, &lt->du);
7971
9196
                                calc_lat_fudu(lt->flag, lt->pntsv, &lt->fv, &lt->dv);
7972
9197
                                calc_lat_fudu(lt->flag, lt->pntsw, &lt->fw, &lt->dw);
7973
9198
                        }
7974
9199
                }
7975
9200
 
7976
 
                for(ob=main->object.first; ob; ob= ob->id.next) {
 
9201
                for (ob=main->object.first; ob; ob= ob->id.next) {
7977
9202
                        ModifierData *md;
7978
9203
                        PartEff *paf;
7979
9204
 
7994
9219
                                        }
7995
9220
 
7996
9221
                                        BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(eModifierType_Softbody));
7997
 
                                } else {
 
9222
                                }
 
9223
                                else {
7998
9224
                                        BLI_addhead(&ob->modifiers, modifier_new(eModifierType_Softbody));
7999
9225
                                }
8000
9226
 
8001
9227
                                ob->softflag &= ~OB_SB_ENABLE;
8002
9228
                        }
8003
 
                        if(ob->pose) {
 
9229
                        if (ob->pose) {
8004
9230
                                bPoseChannel *pchan;
8005
9231
                                bConstraint *con;
8006
 
                                for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 
9232
                                for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
8007
9233
                                        // note, pchan->bone is also lib-link stuff
8008
9234
                                        if (pchan->limitmin[0] == 0.0f && pchan->limitmax[0] == 0.0f) {
8009
9235
                                                pchan->limitmin[0]= pchan->limitmin[1]= pchan->limitmin[2]= -180.0f;
8010
9236
                                                pchan->limitmax[0]= pchan->limitmax[1]= pchan->limitmax[2]= 180.0f;
8011
9237
                                                
8012
 
                                                for(con= pchan->constraints.first; con; con= con->next) {
8013
 
                                                        if(con->type == CONSTRAINT_TYPE_KINEMATIC) {
 
9238
                                                for (con= pchan->constraints.first; con; con= con->next) {
 
9239
                                                        if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
8014
9240
                                                                bKinematicConstraint *data = (bKinematicConstraint*)con->data;
8015
9241
                                                                data->weight = 1.0f;
8016
9242
                                                                data->orientweight = 1.0f;
8027
9253
                                }
8028
9254
                        }
8029
9255
 
8030
 
                        paf = give_parteff(ob);
 
9256
                        paf = do_version_give_parteff_245(ob);
8031
9257
                        if (paf) {
8032
 
                                if(paf->disp == 0)
 
9258
                                if (paf->disp == 0)
8033
9259
                                        paf->disp = 100;
8034
 
                                if(paf->speedtex == 0)
 
9260
                                if (paf->speedtex == 0)
8035
9261
                                        paf->speedtex = 8;
8036
 
                                if(paf->omat == 0)
 
9262
                                if (paf->omat == 0)
8037
9263
                                        paf->omat = 1;
8038
9264
                        }
8039
9265
                }
8040
9266
                
8041
 
                for(arm=main->armature.first; arm; arm= arm->id.next) {
 
9267
                for (arm=main->armature.first; arm; arm= arm->id.next) {
8042
9268
                        bone_version_238(&arm->bonebase);
8043
9269
                        arm->deformflag |= ARM_DEF_VGROUP;
8044
9270
                }
8045
9271
 
8046
 
                for(me=main->mesh.first; me; me= me->id.next) {
 
9272
                for (me=main->mesh.first; me; me= me->id.next) {
8047
9273
                        if (!me->medge) {
8048
9274
                                make_edges(me, 1);      /* 1 = use mface->edcode */
8049
 
                        } else {
 
9275
                        }
 
9276
                        else {
8050
9277
                                mesh_strip_loose_faces(me);
8051
9278
                        }
8052
9279
                }
8053
9280
                
8054
 
                for(key= main->key.first; key; key= key->id.next) {
 
9281
                for (key= main->key.first; key; key= key->id.next) {
8055
9282
                        KeyBlock *kb;
8056
 
                        int index= 1;
8057
 
                        
8058
 
                        /* trick to find out if we already introduced adrcode */
8059
 
                        for(kb= key->block.first; kb; kb= kb->next)
8060
 
                                if(kb->adrcode) break;
8061
 
                        
8062
 
                        if(kb==NULL) {
8063
 
                                for(kb= key->block.first; kb; kb= kb->next) {
8064
 
                                        if(kb==key->refkey) {
8065
 
                                                if(kb->name[0]==0)
8066
 
                                                        strcpy(kb->name, "Basis");
8067
 
                                        }
8068
 
                                        else {
8069
 
                                                if(kb->name[0]==0)
8070
 
                                                        sprintf(kb->name, "Key %d", index);
8071
 
                                                kb->adrcode= index++;
8072
 
                                        }
 
9283
                        int index = 1;
 
9284
 
 
9285
                        for (kb= key->block.first; kb; kb= kb->next) {
 
9286
                                if (kb==key->refkey) {
 
9287
                                        if (kb->name[0]==0)
 
9288
                                                strcpy(kb->name, "Basis");
 
9289
                                }
 
9290
                                else {
 
9291
                                        if (kb->name[0]==0) {
 
9292
                                                BLI_snprintf(kb->name, sizeof(kb->name), "Key %d", index);
 
9293
                                        }
 
9294
                                        index++;
8073
9295
                                }
8074
9296
                        }
8075
9297
                }
8076
9298
        }
8077
 
        if(main->versionfile <= 239) {
 
9299
        if (main->versionfile <= 239) {
8078
9300
                bArmature *arm;
8079
9301
                Object *ob;
8080
9302
                Scene *sce= main->scene.first;
8083
9305
                int set_passepartout= 0;
8084
9306
                
8085
9307
                /* deformflag is local in modifier now */
8086
 
                for(ob=main->object.first; ob; ob= ob->id.next) {
 
9308
                for (ob=main->object.first; ob; ob= ob->id.next) {
8087
9309
                        ModifierData *md;
8088
9310
                        
8089
9311
                        for (md=ob->modifiers.first; md; md=md->next) {
8090
9312
                                if (md->type==eModifierType_Armature) {
8091
9313
                                        ArmatureModifierData *amd = (ArmatureModifierData*) md;
8092
 
                                        if(amd->object && amd->deformflag==0) {
 
9314
                                        if (amd->object && amd->deformflag==0) {
8093
9315
                                                Object *oba= newlibadr(fd, lib, amd->object);
8094
 
                                                bArmature *arm= newlibadr(fd, lib, oba->data);
 
9316
                                                arm= newlibadr(fd, lib, oba->data);
8095
9317
                                                amd->deformflag= arm->deformflag;
8096
9318
                                        }
8097
9319
                                }
8099
9321
                }
8100
9322
                
8101
9323
                /* updating stepsize for ghost drawing */
8102
 
                for(arm= main->armature.first; arm; arm= arm->id.next) {
 
9324
                for (arm= main->armature.first; arm; arm= arm->id.next) {
8103
9325
                        if (arm->ghostsize==0) arm->ghostsize=1;
8104
9326
                        bone_version_239(&arm->bonebase);
8105
 
                        if(arm->layer==0) arm->layer= 1;
 
9327
                        if (arm->layer==0) arm->layer= 1;
8106
9328
                }
8107
9329
                
8108
 
                for(;sce;sce= sce->id.next) {
 
9330
                for (;sce;sce= sce->id.next) {
8109
9331
                        /* make 'innervert' the default subdivide type, for backwards compat */
8110
9332
                        sce->toolsettings->cornertype=1;
8111
9333
                
8112
 
                        if(sce->r.scemode & R_PASSEPARTOUT) {
 
9334
                        if (sce->r.scemode & R_PASSEPARTOUT) {
8113
9335
                                set_passepartout= 1;
8114
9336
                                sce->r.scemode &= ~R_PASSEPARTOUT;
8115
9337
                        }
8116
9338
                        /* gauss is filter variable now */
8117
 
                        if(sce->r.mode & R_GAUSS) {
 
9339
                        if (sce->r.mode & R_GAUSS) {
8118
9340
                                sce->r.filtertype= R_FILTER_GAUSS;
8119
9341
                                sce->r.mode &= ~R_GAUSS;
8120
9342
                        }
8121
9343
                }
8122
9344
                
8123
 
                for(;cam; cam= cam->id.next) {
8124
 
                        if(set_passepartout)
 
9345
                for (;cam; cam= cam->id.next) {
 
9346
                        if (set_passepartout)
8125
9347
                                cam->flag |= CAM_SHOWPASSEPARTOUT;
8126
9348
                        
8127
9349
                        /* make sure old cameras have title safe on */
8128
9350
                        if (!(cam->flag & CAM_SHOWTITLESAFE))
8129
 
                         cam->flag |= CAM_SHOWTITLESAFE;
 
9351
                                cam->flag |= CAM_SHOWTITLESAFE;
8130
9352
                        
8131
9353
                        /* set an appropriate camera passepartout alpha */
8132
9354
                        if (!(cam->passepartalpha)) cam->passepartalpha = 0.2f;
8133
9355
                }
8134
9356
                
8135
 
                for(; ma; ma= ma->id.next) {
8136
 
                        if(ma->strand_sta==0.0f) {
 
9357
                for (; ma; ma= ma->id.next) {
 
9358
                        if (ma->strand_sta==0.0f) {
8137
9359
                                ma->strand_sta= ma->strand_end= 1.0f;
8138
9360
                                ma->mode |= MA_TANGENT_STR;
8139
9361
                        }
8140
 
                        if(ma->mode & MA_TRACEBLE) ma->mode |= MA_SHADBUF;
 
9362
                        if (ma->mode & MA_TRACEBLE) ma->mode |= MA_SHADBUF;
8141
9363
                }
8142
9364
        }
8143
9365
        
8144
 
        if(main->versionfile <= 241) {
 
9366
        if (main->versionfile <= 241) {
8145
9367
                Object *ob;
8146
9368
                Tex *tex;
8147
9369
                Scene *sce;
8153
9375
                
8154
9376
                for (wo = main->world.first; wo; wo= wo->id.next) {
8155
9377
                        /* Migrate to Bullet for games, except for the NaN versions */
8156
 
                        /* People can still explicitely choose for Sumo (after 2.42 is out) */
8157
 
                        if(main->versionfile > 225)
 
9378
                        /* People can still explicitly choose for Sumo (after 2.42 is out) */
 
9379
                        if (main->versionfile > 225)
8158
9380
                                wo->physicsEngine = WOPHY_BULLET;
8159
 
                        if(WO_AODIST == wo->aomode)
 
9381
                        if (WO_AODIST == wo->aomode)
8160
9382
                                wo->aocolor= WO_AOPLAIN;
8161
9383
                }
8162
9384
                
8163
9385
                /* updating layers still */
8164
 
                for(arm= main->armature.first; arm; arm= arm->id.next) {
 
9386
                for (arm= main->armature.first; arm; arm= arm->id.next) {
8165
9387
                        bone_version_239(&arm->bonebase);
8166
 
                        if(arm->layer==0) arm->layer= 1;
 
9388
                        if (arm->layer==0) arm->layer= 1;
8167
9389
                }
8168
 
                for(sce= main->scene.first; sce; sce= sce->id.next) {
8169
 
                        if(sce->jumpframe==0) sce->jumpframe= 10;
8170
 
                        if(sce->audio.mixrate==0) sce->audio.mixrate= 44100;
 
9390
                for (sce= main->scene.first; sce; sce= sce->id.next) {
 
9391
                        if (sce->audio.mixrate==0) sce->audio.mixrate= 44100;
8171
9392
 
8172
 
                        if(sce->r.xparts<2) sce->r.xparts= 4;
8173
 
                        if(sce->r.yparts<2) sce->r.yparts= 4;
 
9393
                        if (sce->r.xparts<2) sce->r.xparts= 4;
 
9394
                        if (sce->r.yparts<2) sce->r.yparts= 4;
8174
9395
                        /* adds default layer */
8175
 
                        if(sce->r.layers.first==NULL)
8176
 
                                scene_add_render_layer(sce);
 
9396
                        if (sce->r.layers.first==NULL)
 
9397
                                scene_add_render_layer(sce, NULL);
8177
9398
                        else {
8178
9399
                                SceneRenderLayer *srl;
8179
9400
                                /* new layer flag for sky, was default for solid */
8180
 
                                for(srl= sce->r.layers.first; srl; srl= srl->next) {
8181
 
                                        if(srl->layflag & SCE_LAY_SOLID)
 
9401
                                for (srl= sce->r.layers.first; srl; srl= srl->next) {
 
9402
                                        if (srl->layflag & SCE_LAY_SOLID)
8182
9403
                                                srl->layflag |= SCE_LAY_SKY;
8183
9404
                                        srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR);
8184
9405
                                }
8185
9406
                        }
8186
9407
                        
8187
9408
                        /* node version changes */
8188
 
                        if(sce->nodetree)
 
9409
                        if (sce->nodetree)
8189
9410
                                ntree_version_241(sce->nodetree);
8190
9411
 
8191
9412
                        /* uv calculation options moved to toolsettings */
8192
 
                        if (sce->toolsettings->uvcalc_radius == 0.0) {
 
9413
                        if (sce->toolsettings->uvcalc_radius == 0.0f) {
8193
9414
                                sce->toolsettings->uvcalc_radius = 1.0f;
8194
9415
                                sce->toolsettings->uvcalc_cubesize = 1.0f;
8195
9416
                                sce->toolsettings->uvcalc_mapdir = 1;
8198
9419
                                sce->toolsettings->unwrapper = 1;
8199
9420
                        }
8200
9421
 
8201
 
                        if(sce->r.mode & R_PANORAMA) {
8202
 
                                /* all these checks to ensure saved files with cvs version keep working... */
8203
 
                                if(sce->r.xsch < sce->r.ysch) {
 
9422
                        if (sce->r.mode & R_PANORAMA) {
 
9423
                                /* all these checks to ensure saved files with svn version keep working... */
 
9424
                                if (sce->r.xsch < sce->r.ysch) {
8204
9425
                                        Object *obc= newlibadr(fd, lib, sce->camera);
8205
 
                                        if(obc && obc->type==OB_CAMERA) {
 
9426
                                        if (obc && obc->type==OB_CAMERA) {
8206
9427
                                                Camera *cam= newlibadr(fd, lib, obc->data);
8207
 
                                                if(cam->lens>=10.0f) {
 
9428
                                                if (cam->lens>=10.0f) {
8208
9429
                                                        sce->r.xsch*= sce->r.xparts;
8209
9430
                                                        cam->lens*= (float)sce->r.ysch/(float)sce->r.xsch;
8210
9431
                                                }
8213
9434
                        }
8214
9435
                }
8215
9436
                
8216
 
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
 
9437
                for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
8217
9438
                        ntree_version_241(ntree);
8218
9439
                
8219
 
                for(la= main->lamp.first; la; la= la->id.next)
8220
 
                        if(la->buffers==0)
 
9440
                for (la= main->lamp.first; la; la= la->id.next)
 
9441
                        if (la->buffers==0)
8221
9442
                                la->buffers= 1;
8222
9443
                
8223
 
                for(tex= main->tex.first; tex; tex= tex->id.next) {
8224
 
                        if(tex->env && tex->env->viewscale==0.0f)
 
9444
                for (tex= main->tex.first; tex; tex= tex->id.next) {
 
9445
                        if (tex->env && tex->env->viewscale==0.0f)
8225
9446
                                tex->env->viewscale= 1.0f;
8226
9447
//                      tex->imaflag |= TEX_GAUSS_MIP;
8227
9448
                }
8228
9449
                
8229
9450
                /* for empty drawsize and drawtype */
8230
 
                for(ob=main->object.first; ob; ob= ob->id.next) {
8231
 
                        if(ob->empty_drawsize==0.0f) {
 
9451
                for (ob=main->object.first; ob; ob= ob->id.next) {
 
9452
                        if (ob->empty_drawsize==0.0f) {
8232
9453
                                ob->empty_drawtype = OB_ARROWS;
8233
9454
                                ob->empty_drawsize = 1.0;
8234
9455
                        }
8235
9456
                }
8236
9457
                
8237
 
                for(ma= main->mat.first; ma; ma= ma->id.next) {
 
9458
                for (ma= main->mat.first; ma; ma= ma->id.next) {
8238
9459
                        /* stucci returns intensity from now on */
8239
9460
                        int a;
8240
 
                        for(a=0; a<MAX_MTEX; a++) {
8241
 
                                if(ma->mtex[a] && ma->mtex[a]->tex) {
8242
 
                                        Tex *tex= newlibadr(fd, lib, ma->mtex[a]->tex);
8243
 
                                        if(tex && tex->type==TEX_STUCCI)
 
9461
                        for (a=0; a<MAX_MTEX; a++) {
 
9462
                                if (ma->mtex[a] && ma->mtex[a]->tex) {
 
9463
                                        tex= newlibadr(fd, lib, ma->mtex[a]->tex);
 
9464
                                        if (tex && tex->type==TEX_STUCCI)
8244
9465
                                                ma->mtex[a]->mapto &= ~(MAP_COL|MAP_SPEC|MAP_REF);
8245
9466
                                }
8246
9467
                        }
8247
9468
                        /* transmissivity defaults */
8248
 
                        if(ma->tx_falloff==0.0) ma->tx_falloff= 1.0;
 
9469
                        if (ma->tx_falloff==0.0f) ma->tx_falloff= 1.0f;
8249
9470
                }
8250
9471
                
8251
9472
                /* during 2.41 images with this name were used for viewer node output, lets fix that */
8252
 
                if(main->versionfile == 241) {
 
9473
                if (main->versionfile == 241) {
8253
9474
                        Image *ima;
8254
 
                        for(ima= main->image.first; ima; ima= ima->id.next)
8255
 
                                if(strcmp(ima->name, "Compositor")==0) {
 
9475
                        for (ima= main->image.first; ima; ima= ima->id.next)
 
9476
                                if (strcmp(ima->name, "Compositor")==0) {
8256
9477
                                        strcpy(ima->id.name+2, "Viewer Node");
8257
9478
                                        strcpy(ima->name, "Viewer Node");
8258
9479
                                }
8259
9480
                }
8260
9481
        }
8261
9482
                
8262
 
        if(main->versionfile <= 242) {
 
9483
        if (main->versionfile <= 242) {
8263
9484
                Scene *sce;
8264
9485
                bScreen *sc;
8265
9486
                Object *ob;
8273
9494
                bNodeTree *ntree;
8274
9495
                int a;
8275
9496
                
8276
 
                for(sc= main->screen.first; sc; sc= sc->id.next) {
 
9497
                for (sc= main->screen.first; sc; sc= sc->id.next) {
8277
9498
                        ScrArea *sa;
8278
9499
                        sa= sc->areabase.first;
8279
 
                        while(sa) {
 
9500
                        while (sa) {
8280
9501
                                SpaceLink *sl;
8281
9502
 
8282
9503
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
8283
 
                                        if(sl->spacetype==SPACE_VIEW3D) {
 
9504
                                        if (sl->spacetype==SPACE_VIEW3D) {
8284
9505
                                                View3D *v3d= (View3D*) sl;
8285
9506
                                                if (v3d->gridsubdiv == 0)
8286
9507
                                                        v3d->gridsubdiv = 10;
8290
9511
                        }
8291
9512
                }
8292
9513
                
8293
 
                for(sce= main->scene.first; sce; sce= sce->id.next) {
 
9514
                for (sce= main->scene.first; sce; sce= sce->id.next) {
8294
9515
                        if (sce->toolsettings->select_thresh == 0.0f)
8295
9516
                                sce->toolsettings->select_thresh= 0.01f;
8296
9517
                        if (sce->toolsettings->clean_thresh == 0.0f) 
8302
9523
                                else
8303
9524
                                        sce->r.threads= 1;
8304
9525
                        }
8305
 
                        if(sce->nodetree)
 
9526
                        if (sce->nodetree)
8306
9527
                                ntree_version_242(sce->nodetree);
8307
9528
                }
8308
9529
                
8309
 
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
 
9530
                for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
8310
9531
                        ntree_version_242(ntree);
8311
9532
                
8312
9533
                /* add default radius values to old curve points */
8313
 
                for(cu= main->curve.first; cu; cu= cu->id.next) {
8314
 
                        for(nu= cu->nurb.first; nu; nu= nu->next) {
 
9534
                for (cu= main->curve.first; cu; cu= cu->id.next) {
 
9535
                        for (nu= cu->nurb.first; nu; nu= nu->next) {
8315
9536
                                if (nu) {
8316
 
                                        if(nu->bezt) {
8317
 
                                                for(bezt=nu->bezt, a=0; a<nu->pntsu; a++, bezt++) {
 
9537
                                        if (nu->bezt) {
 
9538
                                                for (bezt=nu->bezt, a=0; a<nu->pntsu; a++, bezt++) {
8318
9539
                                                        if (!bezt->radius) bezt->radius= 1.0;
8319
9540
                                                }
8320
9541
                                        }
8321
 
                                        else if(nu->bp) {
8322
 
                                                for(bp=nu->bp, a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
8323
 
                                                        if(!bp->radius) bp->radius= 1.0;
 
9542
                                        else if (nu->bp) {
 
9543
                                                for (bp=nu->bp, a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
 
9544
                                                        if (!bp->radius) bp->radius= 1.0;
8324
9545
                                                }
8325
9546
                                        }
8326
9547
                                }
8327
9548
                        }
8328
9549
                }
8329
9550
                
8330
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
 
9551
                for (ob = main->object.first; ob; ob= ob->id.next) {
8331
9552
                        ModifierData *md;
8332
9553
                        ListBase *list;
8333
9554
                        list = &ob->constraints;
8334
9555
 
8335
9556
                        /* check for already existing MinMax (floor) constraint
8336
 
                           and update the sticky flagging */
 
9557
                         * and update the sticky flagging */
8337
9558
 
8338
 
                        if (list){
 
9559
                        if (list) {
8339
9560
                                bConstraint *curcon;
8340
 
                                for (curcon = list->first; curcon; curcon=curcon->next){
 
9561
                                for (curcon = list->first; curcon; curcon=curcon->next) {
8341
9562
                                        switch (curcon->type) {
8342
9563
                                                case CONSTRAINT_TYPE_MINMAX:
8343
9564
                                                {
8353
9574
                                                        bRotateLikeConstraint *data = curcon->data;
8354
9575
                                                        
8355
9576
                                                        /* version patch from buttons_object.c */
8356
 
                                                        if(data->flag==0) 
 
9577
                                                        if (data->flag==0)
8357
9578
                                                                data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
8358
9579
                                                }
8359
9580
                                                        break;
8362
9583
                        }
8363
9584
 
8364
9585
                        if (ob->type == OB_ARMATURE) {
8365
 
                                if (ob->pose){
 
9586
                                if (ob->pose) {
8366
9587
                                        bConstraint *curcon;
8367
9588
                                        bPoseChannel *pchan;
8368
 
                                        for (pchan = ob->pose->chanbase.first; pchan; pchan=pchan->next){
8369
 
                                                for (curcon = pchan->constraints.first; curcon; curcon=curcon->next){
 
9589
                                        for (pchan = ob->pose->chanbase.first; pchan; pchan=pchan->next) {
 
9590
                                                for (curcon = pchan->constraints.first; curcon; curcon=curcon->next) {
8370
9591
                                                        switch (curcon->type) {
8371
9592
                                                                case CONSTRAINT_TYPE_MINMAX:
8372
9593
                                                                {
8391
9612
                                                                        bRotateLikeConstraint *data = curcon->data;
8392
9613
                                                                        
8393
9614
                                                                        /* version patch from buttons_object.c */
8394
 
                                                                        if(data->flag==0) 
 
9615
                                                                        if (data->flag==0)
8395
9616
                                                                                data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
8396
9617
                                                                }
8397
9618
                                                                        break;
8412
9633
                        
8413
9634
                }
8414
9635
                
8415
 
                for(ma = main->mat.first; ma; ma= ma->id.next) {
8416
 
                        if(ma->shad_alpha==0.0f)
 
9636
                for (ma = main->mat.first; ma; ma= ma->id.next) {
 
9637
                        if (ma->shad_alpha==0.0f)
8417
9638
                                ma->shad_alpha= 1.0f;
8418
 
                        if(ma->nodetree)
 
9639
                        if (ma->nodetree)
8419
9640
                                ntree_version_242(ma->nodetree);
8420
9641
                }
8421
9642
 
8422
 
                for(me=main->mesh.first; me; me=me->id.next)
 
9643
                for (me=main->mesh.first; me; me=me->id.next)
8423
9644
                        customdata_version_242(me);
8424
9645
                
8425
 
                for(group= main->group.first; group; group= group->id.next)
8426
 
                        if(group->layer==0)
8427
 
                           group->layer= (1<<20)-1;
8428
 
                
8429
 
                /* History fix (python?), shape key adrcode numbers have to be sorted */
8430
 
                sort_shape_fix(main);
8431
 
                                
 
9646
                for (group= main->group.first; group; group= group->id.next)
 
9647
                        if (group->layer==0)
 
9648
                                group->layer= (1<<20)-1;
 
9649
 
8432
9650
                /* now, subversion control! */
8433
 
                if(main->subversionfile < 3) {
8434
 
                        bScreen *sc;
 
9651
                if (main->subversionfile < 3) {
8435
9652
                        Image *ima;
8436
9653
                        Tex *tex;
8437
9654
                        
8438
9655
                        /* Image refactor initialize */
8439
 
                        for(ima= main->image.first; ima; ima= ima->id.next) {
 
9656
                        for (ima= main->image.first; ima; ima= ima->id.next) {
8440
9657
                                ima->source= IMA_SRC_FILE;
8441
9658
                                ima->type= IMA_TYPE_IMAGE;
8442
9659
                                
8443
9660
                                ima->gen_x= 256; ima->gen_y= 256;
8444
9661
                                ima->gen_type= 1;
8445
9662
                                
8446
 
                                if(0==strncmp(ima->id.name+2, "Viewer Node", sizeof(ima->id.name+2))) {
 
9663
                                if (0==strncmp(ima->id.name+2, "Viewer Node", sizeof(ima->id.name)-2)) {
8447
9664
                                        ima->source= IMA_SRC_VIEWER;
8448
9665
                                        ima->type= IMA_TYPE_COMPOSITE;
8449
9666
                                }
8450
 
                                if(0==strncmp(ima->id.name+2, "Render Result", sizeof(ima->id.name+2))) {
 
9667
                                if (0==strncmp(ima->id.name+2, "Render Result", sizeof(ima->id.name)-2)) {
8451
9668
                                        ima->source= IMA_SRC_VIEWER;
8452
9669
                                        ima->type= IMA_TYPE_R_RESULT;
8453
9670
                                }
8454
9671
                                
8455
9672
                        }
8456
 
                        for(tex= main->tex.first; tex; tex= tex->id.next) {
8457
 
                                if(tex->type==TEX_IMAGE && tex->ima) {
 
9673
                        for (tex= main->tex.first; tex; tex= tex->id.next) {
 
9674
                                if (tex->type==TEX_IMAGE && tex->ima) {
8458
9675
                                        ima= newlibadr(fd, lib, tex->ima);
8459
 
                                        if(tex->imaflag & TEX_ANIM5_)
 
9676
                                        if (tex->imaflag & TEX_ANIM5_)
8460
9677
                                                ima->source= IMA_SRC_MOVIE;
8461
 
                                        if(tex->imaflag & TEX_FIELDS_)
 
9678
                                        if (tex->imaflag & TEX_FIELDS_)
8462
9679
                                                ima->flag |= IMA_FIELDS;
8463
 
                                        if(tex->imaflag & TEX_STD_FIELD_)
 
9680
                                        if (tex->imaflag & TEX_STD_FIELD_)
8464
9681
                                                ima->flag |= IMA_STD_FIELD;
8465
9682
                                }
8466
9683
                                tex->iuser.frames= tex->frames;
8467
 
                                tex->iuser.fie_ima= tex->fie_ima;
 
9684
                                tex->iuser.fie_ima= (char)tex->fie_ima;
8468
9685
                                tex->iuser.offset= tex->offset;
8469
9686
                                tex->iuser.sfra= tex->sfra;
8470
9687
                                tex->iuser.cycl= (tex->imaflag & TEX_ANIMCYCLIC_)!=0;
8471
9688
                        }
8472
 
                        for(sce= main->scene.first; sce; sce= sce->id.next) {
8473
 
                                if(sce->nodetree)
 
9689
                        for (sce= main->scene.first; sce; sce= sce->id.next) {
 
9690
                                if (sce->nodetree)
8474
9691
                                        do_version_ntree_242_2(sce->nodetree);
8475
9692
                        }
8476
 
                        for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
 
9693
                        for (ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
8477
9694
                                do_version_ntree_242_2(ntree);
8478
 
                        for(ma = main->mat.first; ma; ma= ma->id.next)
8479
 
                                if(ma->nodetree)
 
9695
                        for (ma = main->mat.first; ma; ma= ma->id.next)
 
9696
                                if (ma->nodetree)
8480
9697
                                        do_version_ntree_242_2(ma->nodetree);
8481
9698
                        
8482
 
                        for(sc= main->screen.first; sc; sc= sc->id.next) {
 
9699
                        for (sc= main->screen.first; sc; sc= sc->id.next) {
8483
9700
                                ScrArea *sa;
8484
 
                                for(sa= sc->areabase.first; sa; sa= sa->next) {
 
9701
                                for (sa= sc->areabase.first; sa; sa= sa->next) {
8485
9702
                                        SpaceLink *sl;
8486
9703
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
8487
 
                                                if(sl->spacetype==SPACE_IMAGE)
 
9704
                                                if (sl->spacetype==SPACE_IMAGE)
8488
9705
                                                        ((SpaceImage *)sl)->iuser.fie_ima= 2;
8489
 
                                                else if(sl->spacetype==SPACE_VIEW3D) {
 
9706
                                                else if (sl->spacetype==SPACE_VIEW3D) {
8490
9707
                                                        View3D *v3d= (View3D *)sl;
8491
9708
                                                        BGpic *bgpic;
8492
 
                                                        for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next)
 
9709
                                                        for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next)
8493
9710
                                                                bgpic->iuser.fie_ima= 2;
8494
9711
                                                }
8495
9712
                                        }
8497
9714
                        }
8498
9715
                }
8499
9716
                
8500
 
                if(main->subversionfile < 4) {
8501
 
                        for(sce= main->scene.first; sce; sce= sce->id.next) {
 
9717
                if (main->subversionfile < 4) {
 
9718
                        for (sce= main->scene.first; sce; sce= sce->id.next) {
8502
9719
                                sce->r.bake_mode= 1;    /* prevent to include render stuff here */
8503
9720
                                sce->r.bake_filter= 2;
8504
9721
                                sce->r.bake_osa= 5;
8506
9723
                        }
8507
9724
                }
8508
9725
 
8509
 
                if(main->subversionfile < 5) {
8510
 
                        for(sce= main->scene.first; sce; sce= sce->id.next) {
 
9726
                if (main->subversionfile < 5) {
 
9727
                        for (sce= main->scene.first; sce; sce= sce->id.next) {
8511
9728
                                /* improved triangle to quad conversion settings */
8512
 
                                if(sce->toolsettings->jointrilimit==0.0f)
 
9729
                                if (sce->toolsettings->jointrilimit==0.0f)
8513
9730
                                        sce->toolsettings->jointrilimit= 0.8f;
8514
9731
                        }
8515
9732
                }
8516
9733
        }
8517
 
        if(main->versionfile <= 243) {
 
9734
        if (main->versionfile <= 243) {
8518
9735
                Object *ob= main->object.first;
8519
9736
                Material *ma;
8520
9737
 
8521
 
                for(ma=main->mat.first; ma; ma= ma->id.next) {
8522
 
                        if(ma->sss_scale==0.0f) {
 
9738
                for (ma=main->mat.first; ma; ma= ma->id.next) {
 
9739
                        if (ma->sss_scale==0.0f) {
8523
9740
                                ma->sss_radius[0]= 1.0f;
8524
9741
                                ma->sss_radius[1]= 1.0f;
8525
9742
                                ma->sss_radius[2]= 1.0f;
8532
9749
                                ma->sss_colfac= 1.0f;
8533
9750
                                ma->sss_texfac= 0.0f;
8534
9751
                        }
8535
 
                        if(ma->sss_front==0 && ma->sss_back==0) {
 
9752
                        if (ma->sss_front==0 && ma->sss_back==0) {
8536
9753
                                ma->sss_front= 1.0f;
8537
9754
                                ma->sss_back= 1.0f;
8538
9755
                        }
8539
 
                        if(ma->sss_col[0]==0 && ma->sss_col[1]==0 && ma->sss_col[2]==0) {
 
9756
                        if (ma->sss_col[0]==0 && ma->sss_col[1]==0 && ma->sss_col[2]==0) {
8540
9757
                                ma->sss_col[0]= ma->r;
8541
9758
                                ma->sss_col[1]= ma->g;
8542
9759
                                ma->sss_col[2]= ma->b;
8543
9760
                        }
8544
9761
                }
8545
9762
                
8546
 
                for(; ob; ob= ob->id.next) {
 
9763
                for (; ob; ob= ob->id.next) {
8547
9764
                        bDeformGroup *curdef;
8548
9765
                        
8549
 
                        for(curdef= ob->defbase.first; curdef; curdef=curdef->next) {
 
9766
                        for (curdef= ob->defbase.first; curdef; curdef=curdef->next) {
8550
9767
                                /* replace an empty-string name with unique name */
8551
9768
                                if (curdef->name[0] == '\0') {
8552
9769
                                        defgroup_unique_name(curdef, ob);
8553
9770
                                }
8554
9771
                        }
8555
9772
 
8556
 
                        if(main->versionfile < 243 || main->subversionfile < 1) {
 
9773
                        if (main->versionfile < 243 || main->subversionfile < 1) {
8557
9774
                                ModifierData *md;
8558
9775
 
8559
9776
                                /* translate old mirror modifier axis values to new flags */
8581
9798
                }
8582
9799
                
8583
9800
                /* render layer added, this is not the active layer */
8584
 
                if(main->versionfile <= 243 || main->subversionfile < 2) {
 
9801
                if (main->versionfile <= 243 || main->subversionfile < 2) {
8585
9802
                        Mesh *me;
8586
 
                        for(me=main->mesh.first; me; me=me->id.next)
 
9803
                        for (me=main->mesh.first; me; me=me->id.next)
8587
9804
                                customdata_version_243(me);
8588
9805
                }               
8589
9806
 
8590
9807
        }
8591
9808
        
8592
 
        if(main->versionfile <= 244) {
 
9809
        if (main->versionfile <= 244) {
8593
9810
                Scene *sce;
8594
9811
                bScreen *sc;
8595
9812
                Lamp *la;
8596
9813
                World *wrld;
8597
9814
                
8598
 
                if(main->versionfile != 244 || main->subversionfile < 2) {
8599
 
                        for(sce= main->scene.first; sce; sce= sce->id.next)
 
9815
                if (main->versionfile != 244 || main->subversionfile < 2) {
 
9816
                        for (sce= main->scene.first; sce; sce= sce->id.next)
8600
9817
                                sce->r.mode |= R_SSS;
8601
9818
 
8602
9819
                        /* correct older action editors - incorrect scrolling */
8603
 
                        for(sc= main->screen.first; sc; sc= sc->id.next) {
 
9820
                        for (sc= main->screen.first; sc; sc= sc->id.next) {
8604
9821
                                ScrArea *sa;
8605
9822
                                sa= sc->areabase.first;
8606
 
                                while(sa) {
 
9823
                                while (sa) {
8607
9824
                                        SpaceLink *sl;
8608
9825
 
8609
9826
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
8610
 
                                                if(sl->spacetype==SPACE_ACTION) {
 
9827
                                                if (sl->spacetype==SPACE_ACTION) {
8611
9828
                                                        SpaceAction *saction= (SpaceAction*) sl;
8612
9829
                                                        
8613
 
                                                        saction->v2d.tot.ymin= -1000.0;
8614
 
                                                        saction->v2d.tot.ymax= 0.0;
 
9830
                                                        saction->v2d.tot.ymin = -1000.0;
 
9831
                                                        saction->v2d.tot.ymax = 0.0;
8615
9832
                                                        
8616
 
                                                        saction->v2d.cur.ymin= -75.0;
8617
 
                                                        saction->v2d.cur.ymax= 5.0;
 
9833
                                                        saction->v2d.cur.ymin = -75.0;
 
9834
                                                        saction->v2d.cur.ymax = 5.0;
8618
9835
                                                }
8619
9836
                                        }
8620
9837
                                        sa = sa->next;
8625
9842
                        /* constraints recode version patch used to be here. Moved to 245 now... */
8626
9843
                        
8627
9844
                        
8628
 
                        for(wrld=main->world.first; wrld; wrld= wrld->id.next) {
 
9845
                        for (wrld=main->world.first; wrld; wrld= wrld->id.next) {
8629
9846
                                if (wrld->mode & WO_AMB_OCC)
8630
9847
                                        wrld->ao_samp_method = WO_AOSAMP_CONSTANT;
8631
9848
                                else
8634
9851
                                wrld->ao_adapt_thresh = 0.005f;
8635
9852
                        }
8636
9853
                        
8637
 
                        for(la=main->lamp.first; la; la= la->id.next) {
 
9854
                        for (la=main->lamp.first; la; la= la->id.next) {
8638
9855
                                if (la->type == LA_AREA)
8639
9856
                                        la->ray_samp_method = LA_SAMP_CONSTANT;
8640
9857
                                else
8644
9861
                        }
8645
9862
                }
8646
9863
        }
8647
 
        if(main->versionfile <= 245) {
 
9864
        if (main->versionfile <= 245) {
8648
9865
                Scene *sce;
8649
 
                bScreen *sc;
8650
9866
                Object *ob;
8651
9867
                Image *ima;
8652
9868
                Lamp *la;
8691
9907
                                        }
8692
9908
                                }
8693
9909
                                
8694
 
                                /* correctly initialise constinv matrix */
 
9910
                                /* correctly initialize constinv matrix */
8695
9911
                                unit_m4(ob->constinv);
8696
9912
                                
8697
9913
                                if (ob->type == OB_ARMATURE) {
8721
9937
                                                                }
8722
9938
                                                        }
8723
9939
                                                        
8724
 
                                                        /* correctly initialise constinv matrix */
 
9940
                                                        /* correctly initialize constinv matrix */
8725
9941
                                                        unit_m4(pchan->constinv);
8726
9942
                                                }
8727
9943
                                        }
8733
9949
                if (main->versionfile != 245) {
8734
9950
 
8735
9951
                        /* repair preview from 242 - 244*/
8736
 
                        for(ima= main->image.first; ima; ima= ima->id.next) {
 
9952
                        for (ima= main->image.first; ima; ima= ima->id.next) {
8737
9953
                                ima->preview = NULL;
8738
9954
                        }
8739
 
                        
8740
 
                        /* repair imasel space - completely reworked */
8741
 
                        for(sc= main->screen.first; sc; sc= sc->id.next) {
8742
 
                                ScrArea *sa;
8743
 
                                sa= sc->areabase.first;
8744
 
                                while(sa) {
8745
 
                                        SpaceLink *sl;
8746
 
                                        
8747
 
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
8748
 
                                                if(sl->spacetype==SPACE_IMASEL) {
8749
 
                                                        SpaceImaSel *simasel= (SpaceImaSel*) sl;
8750
 
                                                        simasel->blockscale= 0.7f;
8751
 
                                                        /* view 2D */
8752
 
                                                        simasel->v2d.tot.xmin=  -10.0f;
8753
 
                                                        simasel->v2d.tot.ymin=  -10.0f;
8754
 
                                                        simasel->v2d.tot.xmax= (float)sa->winx + 10.0f;
8755
 
                                                        simasel->v2d.tot.ymax= (float)sa->winy + 10.0f;                                         
8756
 
                                                        simasel->v2d.cur.xmin=  0.0f;
8757
 
                                                        simasel->v2d.cur.ymin=  0.0f;
8758
 
                                                        simasel->v2d.cur.xmax= (float)sa->winx;
8759
 
                                                        simasel->v2d.cur.ymax= (float)sa->winy;                                         
8760
 
                                                        simasel->v2d.min[0]= 1.0;
8761
 
                                                        simasel->v2d.min[1]= 1.0;                                               
8762
 
                                                        simasel->v2d.max[0]= 32000.0f;
8763
 
                                                        simasel->v2d.max[1]= 32000.0f;                                          
8764
 
                                                        simasel->v2d.minzoom= 0.5f;
8765
 
                                                        simasel->v2d.maxzoom= 1.21f;                                            
8766
 
                                                        simasel->v2d.scroll= 0;
8767
 
                                                        simasel->v2d.keepzoom= V2D_LIMITZOOM|V2D_KEEPASPECT;
8768
 
                                                        simasel->v2d.keeptot= 0;
8769
 
                                                        simasel->prv_h = 96;
8770
 
                                                        simasel->prv_w = 96;
8771
 
                                                        simasel->flag = 7; /* ??? elubie */
8772
 
                                                        strcpy (simasel->dir,  U.textudir);     /* TON */
8773
 
                                                        strcpy (simasel->file, "");
8774
 
                                                        
8775
 
                                                        simasel->returnfunc     =  0;   
8776
 
                                                        simasel->title[0]       =  0;
8777
 
                                                }
8778
 
                                        }
8779
 
                                        sa = sa->next;
8780
 
                                }
8781
 
                        }
8782
9955
                }
8783
9956
 
8784
9957
                /* add point caches */
8785
 
                for(ob=main->object.first; ob; ob=ob->id.next) {
8786
 
                        if(ob->soft && !ob->soft->pointcache)
 
9958
                for (ob=main->object.first; ob; ob=ob->id.next) {
 
9959
                        if (ob->soft && !ob->soft->pointcache)
8787
9960
                                ob->soft->pointcache= BKE_ptcache_add(&ob->soft->ptcaches);
8788
9961
 
8789
 
                        for(psys=ob->particlesystem.first; psys; psys=psys->next) {
8790
 
                                //if(psys->soft && !psys->soft->pointcache)
8791
 
                                //      psys->soft->pointcache= BKE_ptcache_add(&psys->soft->ptcaches);
8792
 
                                if(!psys->pointcache)
 
9962
                        for (psys=ob->particlesystem.first; psys; psys=psys->next) {
 
9963
                                if (psys->pointcache) {
 
9964
                                        if (psys->pointcache->flag & PTCACHE_BAKED && (psys->pointcache->flag & PTCACHE_DISK_CACHE)==0) {
 
9965
                                                printf("Old memory cache isn't supported for particles, so re-bake the simulation!\n");
 
9966
                                                psys->pointcache->flag &= ~PTCACHE_BAKED;
 
9967
                                        }
 
9968
                                }
 
9969
                                else
8793
9970
                                        psys->pointcache= BKE_ptcache_add(&psys->ptcaches);
8794
9971
                        }
8795
9972
 
8796
 
                        for(md=ob->modifiers.first; md; md=md->next) {
8797
 
                                if(md->type==eModifierType_Cloth) {
 
9973
                        for (md=ob->modifiers.first; md; md=md->next) {
 
9974
                                if (md->type==eModifierType_Cloth) {
8798
9975
                                        ClothModifierData *clmd = (ClothModifierData*) md;
8799
 
                                        if(!clmd->point_cache)
 
9976
                                        if (!clmd->point_cache)
8800
9977
                                                clmd->point_cache= BKE_ptcache_add(&clmd->ptcaches);
8801
9978
                                }
8802
9979
                        }
8803
9980
                }
8804
9981
 
8805
9982
                /* Copy over old per-level multires vertex data
8806
 
                   into a single vertex array in struct Multires */
8807
 
                for(me = main->mesh.first; me; me=me->id.next) {
8808
 
                        if(me->mr && !me->mr->verts) {
 
9983
                 * into a single vertex array in struct Multires */
 
9984
                for (me = main->mesh.first; me; me=me->id.next) {
 
9985
                        if (me->mr && !me->mr->verts) {
8809
9986
                                MultiresLevel *lvl = me->mr->levels.last;
8810
 
                                if(lvl) {
 
9987
                                if (lvl) {
8811
9988
                                        me->mr->verts = lvl->verts;
8812
9989
                                        lvl->verts = NULL;
8813
9990
                                        /* Don't need the other vert arrays */
8814
 
                                        for(lvl = lvl->prev; lvl; lvl = lvl->prev) {
 
9991
                                        for (lvl = lvl->prev; lvl; lvl = lvl->prev) {
8815
9992
                                                MEM_freeN(lvl->verts);
8816
9993
                                                lvl->verts = NULL;
8817
9994
                                        }
8820
9997
                }
8821
9998
                
8822
9999
                if (main->versionfile != 245 || main->subversionfile < 1) {
8823
 
                        for(la=main->lamp.first; la; la= la->id.next) {
 
10000
                        for (la=main->lamp.first; la; la= la->id.next) {
8824
10001
                                if (la->mode & LA_QUAD) la->falloff_type = LA_FALLOFF_SLIDERS;
8825
10002
                                else la->falloff_type = LA_FALLOFF_INVLINEAR;
8826
10003
                                
8831
10008
                        }
8832
10009
                }               
8833
10010
                
8834
 
                for(ma=main->mat.first; ma; ma= ma->id.next) {
8835
 
                        if(ma->samp_gloss_mir == 0) {
 
10011
                for (ma=main->mat.first; ma; ma= ma->id.next) {
 
10012
                        if (ma->samp_gloss_mir == 0) {
8836
10013
                                ma->gloss_mir = ma->gloss_tra= 1.0f;
8837
10014
                                ma->aniso_gloss_mir = 1.0f;
8838
10015
                                ma->samp_gloss_mir = ma->samp_gloss_tra= 18;
8841
10018
                                ma->fadeto_mir = MA_RAYMIR_FADETOSKY;
8842
10019
                        }
8843
10020
 
8844
 
                        if(ma->strand_min == 0.0f)
 
10021
                        if (ma->strand_min == 0.0f)
8845
10022
                                ma->strand_min= 1.0f;
8846
10023
                }
8847
10024
 
8848
 
                for(part=main->particle.first; part; part=part->id.next) {
8849
 
                        if(part->ren_child_nbr==0)
 
10025
                for (part=main->particle.first; part; part=part->id.next) {
 
10026
                        if (part->ren_child_nbr==0)
8850
10027
                                part->ren_child_nbr= part->child_nbr;
8851
10028
 
8852
 
                        if(part->simplify_refsize==0) {
 
10029
                        if (part->simplify_refsize==0) {
8853
10030
                                part->simplify_refsize= 1920;
8854
10031
                                part->simplify_rate= 1.0f;
8855
10032
                                part->simplify_transition= 0.1f;
8857
10034
                        }
8858
10035
                }
8859
10036
 
8860
 
                for(wrld=main->world.first; wrld; wrld= wrld->id.next) {
8861
 
                        if(wrld->ao_approx_error == 0.0f)
 
10037
                for (wrld=main->world.first; wrld; wrld= wrld->id.next) {
 
10038
                        if (wrld->ao_approx_error == 0.0f)
8862
10039
                                wrld->ao_approx_error= 0.25f;
8863
10040
                }
8864
10041
 
8865
 
                for(sce= main->scene.first; sce; sce= sce->id.next) {
8866
 
                        if(sce->nodetree)
 
10042
                for (sce= main->scene.first; sce; sce= sce->id.next) {
 
10043
                        if (sce->nodetree)
8867
10044
                                ntree_version_245(fd, lib, sce->nodetree);
8868
10045
 
8869
 
                        if(sce->r.simplify_shadowsamples == 0) {
 
10046
                        if (sce->r.simplify_shadowsamples == 0) {
8870
10047
                                sce->r.simplify_subsurf= 6;
8871
10048
                                sce->r.simplify_particles= 1.0f;
8872
10049
                                sce->r.simplify_shadowsamples= 16;
8873
10050
                                sce->r.simplify_aosss= 1.0f;
8874
10051
                        }
8875
10052
 
8876
 
                        if(sce->r.cineongamma == 0) {
 
10053
                        if (sce->r.cineongamma == 0) {
8877
10054
                                sce->r.cineonblack= 95;
8878
10055
                                sce->r.cineonwhite= 685;
8879
10056
                                sce->r.cineongamma= 1.7f;
8880
10057
                        }
8881
10058
                }
8882
10059
 
8883
 
                for(ntree=main->nodetree.first; ntree; ntree= ntree->id.next)
 
10060
                for (ntree=main->nodetree.first; ntree; ntree= ntree->id.next)
8884
10061
                        ntree_version_245(fd, lib, ntree);
8885
10062
 
8886
10063
                /* fix for temporary flag changes during 245 cycle */
8887
 
                for(ima= main->image.first; ima; ima= ima->id.next) {
8888
 
                        if(ima->flag & IMA_OLD_PREMUL) {
 
10064
                for (ima= main->image.first; ima; ima= ima->id.next) {
 
10065
                        if (ima->flag & IMA_OLD_PREMUL) {
8889
10066
                                ima->flag &= ~IMA_OLD_PREMUL;
8890
10067
                                ima->flag |= IMA_DO_PREMUL;
8891
10068
                        }
8892
10069
                }
8893
10070
 
8894
 
                for(tex=main->tex.first; tex; tex=tex->id.next) {
8895
 
                        if(tex->iuser.flag & IMA_OLD_PREMUL) {
 
10071
                for (tex=main->tex.first; tex; tex=tex->id.next) {
 
10072
                        if (tex->iuser.flag & IMA_OLD_PREMUL) {
8896
10073
                                tex->iuser.flag &= ~IMA_OLD_PREMUL;
8897
10074
                                tex->iuser.flag |= IMA_DO_PREMUL;
8898
10075
 
8899
10076
                        }
8900
10077
 
8901
10078
                        ima= newlibadr(fd, lib, tex->ima);
8902
 
                        if(ima && (tex->iuser.flag & IMA_DO_PREMUL)) { 
 
10079
                        if (ima && (tex->iuser.flag & IMA_DO_PREMUL)) {
8903
10080
                                ima->flag &= ~IMA_OLD_PREMUL;
8904
10081
                                ima->flag |= IMA_DO_PREMUL;
8905
10082
                        }
8910
10087
         * */
8911
10088
        {
8912
10089
                Scene *sce;
8913
 
                for(sce=main->scene.first; sce; sce = sce->id.next)
 
10090
                for (sce=main->scene.first; sce; sce = sce->id.next)
8914
10091
                {
8915
10092
                        if (sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[1] ||
8916
10093
                                sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[2] ||
8928
10105
                Image *ima;
8929
10106
 
8930
10107
                /* initialize 1:1 Aspect */
8931
 
                for(ima= main->image.first; ima; ima= ima->id.next) {
 
10108
                for (ima= main->image.first; ima; ima= ima->id.next) {
8932
10109
                        ima->aspx = ima->aspy = 1.0f;                           
8933
10110
                }
8934
10111
 
8939
10116
                ModifierData *md;
8940
10117
                Object *ob;
8941
10118
                
8942
 
                for(arm= main->armature.first; arm; arm= arm->id.next)
 
10119
                for (arm= main->armature.first; arm; arm= arm->id.next)
8943
10120
                        arm->deformflag |= ARM_DEF_B_BONE_REST;
8944
10121
                
8945
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
8946
 
                        for(md=ob->modifiers.first; md; md=md->next) {
8947
 
                                if(md->type==eModifierType_Armature)
 
10122
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10123
                        for (md=ob->modifiers.first; md; md=md->next) {
 
10124
                                if (md->type==eModifierType_Armature)
8948
10125
                                        ((ArmatureModifierData*)md)->deformflag |= ARM_DEF_B_BONE_REST;
8949
10126
                        }
8950
10127
                }
8951
10128
        }
8952
10129
 
8953
10130
        if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 5)) {
8954
 
                /* foreground color needs to be somthing other then black */
 
10131
                /* foreground color needs to be something other then black */
8955
10132
                Scene *sce;
8956
 
                for(sce= main->scene.first; sce; sce=sce->id.next) {
 
10133
                for (sce= main->scene.first; sce; sce=sce->id.next) {
8957
10134
                        sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f;
8958
 
                        sce->r.fg_stamp[3] = 1.0f; /* dont use text alpha yet */
 
10135
                        sce->r.fg_stamp[3] = 1.0f; /* don't use text alpha yet */
8959
10136
                        sce->r.bg_stamp[3] = 0.25f; /* make sure the background has full alpha */
8960
10137
                }
8961
10138
        }
8964
10141
        if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 6)) {
8965
10142
                Scene *sce;
8966
10143
                /* fix frs_sec_base */
8967
 
                for(sce= main->scene.first; sce; sce= sce->id.next) {
 
10144
                for (sce= main->scene.first; sce; sce= sce->id.next) {
8968
10145
                        if (sce->r.frs_sec_base == 0) {
8969
10146
                                sce->r.frs_sec_base = 1;
8970
10147
                        }
8988
10165
                                                                ct= MEM_callocN(sizeof(bConstraintTarget), "PyConTarget");
8989
10166
                                                                
8990
10167
                                                                ct->tar = data->tar;
8991
 
                                                                strcpy(ct->subtarget, data->subtarget);
 
10168
                                                                BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget));
8992
10169
                                                                ct->space = con->tarspace;
8993
10170
                                                                
8994
10171
                                                                BLI_addtail(&data->targets, ct);
8996
10173
                                                                
8997
10174
                                                                /* clear old targets to avoid problems */
8998
10175
                                                                data->tar = NULL;
8999
 
                                                                strcpy(data->subtarget, "");
 
10176
                                                                data->subtarget[0]= '\0';
9000
10177
                                                        }
9001
10178
                                                }
9002
10179
                                                else if (con->type == CONSTRAINT_TYPE_LOCLIKE) {
9018
10195
                                                ct= MEM_callocN(sizeof(bConstraintTarget), "PyConTarget");
9019
10196
                                                
9020
10197
                                                ct->tar = data->tar;
9021
 
                                                strcpy(ct->subtarget, data->subtarget);
 
10198
                                                BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget));
9022
10199
                                                ct->space = con->tarspace;
9023
10200
                                                
9024
10201
                                                BLI_addtail(&data->targets, ct);
9026
10203
                                                
9027
10204
                                                /* clear old targets to avoid problems */
9028
10205
                                                data->tar = NULL;
9029
 
                                                strcpy(data->subtarget, "");
 
10206
                                                data->subtarget[0]= '\0';
9030
10207
                                        }
9031
10208
                                }
9032
10209
                                else if (con->type == CONSTRAINT_TYPE_LOCLIKE) {
9038
10215
                                }
9039
10216
                        }
9040
10217
 
9041
 
                        if(ob->soft && ob->soft->keys) {
 
10218
                        if (ob->soft && ob->soft->keys) {
9042
10219
                                SoftBody *sb = ob->soft;
9043
10220
                                int k;
9044
10221
 
9045
 
                                for(k=0; k<sb->totkey; k++) {
9046
 
                                        if(sb->keys[k])
 
10222
                                for (k=0; k<sb->totkey; k++) {
 
10223
                                        if (sb->keys[k])
9047
10224
                                                MEM_freeN(sb->keys[k]);
9048
10225
                                }
9049
10226
 
9058
10235
        if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 8)) {
9059
10236
                Scene *sce;
9060
10237
                Object *ob;
9061
 
                PartEff *paf=0;
 
10238
                PartEff *paf=NULL;
9062
10239
 
9063
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9064
 
                        if(ob->soft && ob->soft->keys) {
 
10240
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10241
                        if (ob->soft && ob->soft->keys) {
9065
10242
                                SoftBody *sb = ob->soft;
9066
10243
                                int k;
9067
10244
 
9068
 
                                for(k=0; k<sb->totkey; k++) {
9069
 
                                        if(sb->keys[k])
 
10245
                                for (k=0; k<sb->totkey; k++) {
 
10246
                                        if (sb->keys[k])
9070
10247
                                                MEM_freeN(sb->keys[k]);
9071
10248
                                }
9072
10249
 
9077
10254
                        }
9078
10255
 
9079
10256
                        /* convert old particles to new system */
9080
 
                        if((paf = give_parteff(ob))) {
 
10257
                        if ((paf = do_version_give_parteff_245(ob))) {
9081
10258
                                ParticleSystem *psys;
9082
10259
                                ModifierData *md;
9083
10260
                                ParticleSystemModifierData *psmd;
9102
10279
                                BLI_addtail(&ob->particlesystem, psys);
9103
10280
 
9104
10281
                                md= modifier_new(eModifierType_ParticleSystem);
9105
 
                                sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
 
10282
                                BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
9106
10283
                                psmd= (ParticleSystemModifierData*) md;
9107
10284
                                psmd->psys=psys;
9108
10285
                                BLI_addtail(&ob->modifiers, md);
9129
10306
                                part->obfac = paf->obfac;
9130
10307
                                part->randfac = paf->randfac * 25.0f;
9131
10308
                                part->dampfac = paf->damp;
9132
 
                                VECCOPY(part->acc, paf->force);
 
10309
                                copy_v3_v3(part->acc, paf->force);
9133
10310
 
9134
10311
                                /* flags */
9135
 
                                if(paf->stype & PAF_VECT) {
9136
 
                                        if(paf->flag & PAF_STATIC) {
 
10312
                                if (paf->stype & PAF_VECT) {
 
10313
                                        if (paf->flag & PAF_STATIC) {
9137
10314
                                                /* new hair lifetime is always 100.0f */
9138
10315
                                                float fac = paf->lifetime / 100.0f;
9139
10316
 
9166
10343
                                psys->vgroup[PSYS_VG_LENGTH] = paf->vertgroup_v;
9167
10344
 
9168
10345
                                /* dupliobjects */
9169
 
                                if(ob->transflag & OB_DUPLIVERTS) {
 
10346
                                if (ob->transflag & OB_DUPLIVERTS) {
9170
10347
                                        Object *dup = main->object.first;
9171
10348
 
9172
 
                                        for(; dup; dup= dup->id.next) {
9173
 
                                                if(ob == newlibadr(fd, lib, dup->parent)) {
 
10349
                                        for (; dup; dup= dup->id.next) {
 
10350
                                                if (ob == newlibadr(fd, lib, dup->parent)) {
9174
10351
                                                        part->dup_ob = dup;
9175
10352
                                                        ob->transflag |= OB_DUPLIPARTS;
9176
10353
                                                        ob->transflag &= ~OB_DUPLIVERTS;
9186
10363
                                
9187
10364
                                {
9188
10365
                                        FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
9189
 
                                        if(fluidmd && fluidmd->fss && fluidmd->fss->type == OB_FLUIDSIM_PARTICLE)
 
10366
                                        if (fluidmd && fluidmd->fss && fluidmd->fss->type == OB_FLUIDSIM_PARTICLE)
9190
10367
                                                part->type = PART_FLUID;
9191
10368
                                }
9192
10369
 
9193
 
                                free_effects(&ob->effect);
 
10370
                                do_version_free_effects_245(&ob->effect);
9194
10371
 
9195
10372
                                printf("Old particle system converted to new system.\n");
9196
10373
                        }
9197
10374
                }
9198
10375
 
9199
 
                for(sce= main->scene.first; sce; sce=sce->id.next) {
 
10376
                for (sce= main->scene.first; sce; sce=sce->id.next) {
9200
10377
                        ParticleEditSettings *pset= &sce->toolsettings->particle;
9201
10378
                        int a;
9202
10379
 
9203
 
                        if(pset->brush[0].size == 0) {
 
10380
                        if (pset->brush[0].size == 0) {
9204
10381
                                pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
9205
10382
                                pset->emitterdist= 0.25f;
9206
10383
                                pset->totrekey= 5;
9207
10384
                                pset->totaddkey= 5;
9208
10385
                                pset->brushtype= PE_BRUSH_NONE;
9209
10386
 
9210
 
                                for(a=0; a<PE_TOT_BRUSH; a++) {
 
10387
                                for (a=0; a<PE_TOT_BRUSH; a++) {
9211
10388
                                        pset->brush[a].strength= 50;
9212
10389
                                        pset->brush[a].size= 50;
9213
10390
                                        pset->brush[a].step= 10;
9221
10398
                Material *ma;
9222
10399
                int a;
9223
10400
 
9224
 
                for(ma=main->mat.first; ma; ma= ma->id.next)
9225
 
                        if(ma->mode & MA_NORMAP_TANG)
9226
 
                                for(a=0; a<MAX_MTEX; a++)
9227
 
                                        if(ma->mtex[a] && ma->mtex[a]->tex)
 
10401
                for (ma=main->mat.first; ma; ma= ma->id.next)
 
10402
                        if (ma->mode & MA_NORMAP_TANG)
 
10403
                                for (a=0; a<MAX_MTEX; a++)
 
10404
                                        if (ma->mtex[a] && ma->mtex[a]->tex)
9228
10405
                                                ma->mtex[a]->normapspace = MTEX_NSPACE_TANGENT;
9229
10406
        }
9230
10407
        
9232
10409
                Object *ob;
9233
10410
                
9234
10411
                /* dupliface scale */
9235
 
                for(ob= main->object.first; ob; ob= ob->id.next)
 
10412
                for (ob= main->object.first; ob; ob= ob->id.next)
9236
10413
                        ob->dupfacesca = 1.0f;
9237
10414
        }
9238
10415
        
9257
10434
                                strip->scale = length / (repeat * actlength);
9258
10435
                                if (strip->scale == 0.0f) strip->scale= 1.0f;
9259
10436
                        }       
9260
 
                        if(ob->soft){
 
10437
                        if (ob->soft) {
9261
10438
                                ob->soft->inpush =  ob->soft->inspring;
9262
10439
                                ob->soft->shearstiff = 1.0f; 
9263
10440
                        }
9268
10445
                Scene *sce;
9269
10446
                Sequence *seq;
9270
10447
                
9271
 
                for(sce=main->scene.first; sce; sce=sce->id.next) {
 
10448
                for (sce=main->scene.first; sce; sce=sce->id.next) {
9272
10449
                        SEQ_BEGIN(sce->ed, seq) {
9273
10450
                                if (seq->blend_mode == 0)
9274
10451
                                        seq->blend_opacity = 100.0f;
9288
10465
                idproperties_fix_group_lengths(main->mat);
9289
10466
                idproperties_fix_group_lengths(main->tex);
9290
10467
                idproperties_fix_group_lengths(main->image);
9291
 
                idproperties_fix_group_lengths(main->wave);
9292
10468
                idproperties_fix_group_lengths(main->latt);
9293
10469
                idproperties_fix_group_lengths(main->lamp);
9294
10470
                idproperties_fix_group_lengths(main->camera);
9309
10485
        }
9310
10486
 
9311
10487
        /* sun/sky */
9312
 
        if(main->versionfile < 246) {
 
10488
        if (main->versionfile < 246) {
9313
10489
                Object *ob;
9314
10490
                bActuator *act;
9315
10491
 
9316
10492
                /* dRot actuator change direction in 2.46 */
9317
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9318
 
                        for(act= ob->actuators.first; act; act= act->next) {
 
10493
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10494
                        for (act= ob->actuators.first; act; act= act->next) {
9319
10495
                                if (act->type == ACT_OBJECT) {
9320
10496
                                        bObjectActuator *ba= act->data;
9321
10497
 
9328
10504
        }
9329
10505
        
9330
10506
        // convert fluids to modifier
9331
 
        if(main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1))
 
10507
        if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1))
9332
10508
        {
9333
10509
                Object *ob;
9334
10510
                
9335
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9336
 
                        if(ob->fluidsimSettings)
 
10511
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10512
                        if (ob->fluidsimSettings)
9337
10513
                        {
9338
10514
                                FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifier_new(eModifierType_Fluidsim);
9339
10515
                                BLI_addhead(&ob->modifiers, (ModifierData *)fluidmd);
9345
10521
                                
9346
10522
                                fluidmd->fss->lastgoodframe = INT_MAX;
9347
10523
                                fluidmd->fss->flag = 0;
9348
 
                                fluidmd->fss->meshSurfNormals = 0;
 
10524
                                fluidmd->fss->meshVelocities = NULL;
9349
10525
                        }
9350
10526
                }
9351
10527
        }
9352
10528
        
9353
10529
 
9354
 
        if(main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
 
10530
        if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
9355
10531
                Mesh *me;
9356
10532
 
9357
 
                for(me=main->mesh.first; me; me= me->id.next)
 
10533
                for (me=main->mesh.first; me; me= me->id.next)
9358
10534
                        alphasort_version_246(fd, lib, me);
9359
10535
        }
9360
10536
        
9361
 
        if(main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)){
 
10537
        if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
9362
10538
                Object *ob;
9363
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9364
 
                        if(ob->pd && (ob->pd->forcefield == PFIELD_WIND))
 
10539
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10540
                        if (ob->pd && (ob->pd->forcefield == PFIELD_WIND))
9365
10541
                                ob->pd->f_noise = 0.0f;
9366
10542
                }
9367
10543
        }
9368
10544
 
9369
 
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 2)){
 
10545
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 2)) {
9370
10546
                Object *ob;
9371
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
 
10547
                for (ob = main->object.first; ob; ob= ob->id.next) {
9372
10548
                        ob->gameflag |= OB_COLLISION;
9373
10549
                        ob->margin = 0.06f;
9374
10550
                }
9375
10551
        }
9376
10552
 
9377
 
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 3)){
 
10553
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 3)) {
9378
10554
                Object *ob;
9379
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
 
10555
                for (ob = main->object.first; ob; ob= ob->id.next) {
9380
10556
                        // Starting from subversion 3, ACTOR is a separate feature.
9381
10557
                        // Before it was conditioning all the other dynamic flags
9382
10558
                        if (!(ob->gameflag & OB_ACTOR))
9387
10563
 
9388
10564
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 5)) {
9389
10565
                Lamp *la= main->lamp.first;
9390
 
                for(; la; la= la->id.next) {
 
10566
                for (; la; la= la->id.next) {
9391
10567
                        la->skyblendtype= MA_RAMP_ADD;
9392
10568
                        la->skyblendfac= 1.0f;
9393
10569
                }
9398
10574
                Curve *cu;
9399
10575
                Nurb *nu;
9400
10576
                
9401
 
                for(cu= main->curve.first; cu; cu= cu->id.next) {
9402
 
                        for(nu= cu->nurb.first; nu; nu= nu->next) {
 
10577
                for (cu= main->curve.first; cu; cu= cu->id.next) {
 
10578
                        for (nu= cu->nurb.first; nu; nu= nu->next) {
9403
10579
                                if (nu) {
9404
10580
                                        nu->radius_interp = 3;
9405
10581
                                        
9406
10582
                                        /* resolu and resolv are now used differently for surfaces
9407
 
                                         * rather then using the resolution to define the entire number of divisions,
 
10583
                                         * rather than using the resolution to define the entire number of divisions,
9408
10584
                                         * use it for the number of divisions per segment
9409
10585
                                         */
9410
10586
                                        if (nu->pntsv > 1) {
9420
10596
                bActuator *act;
9421
10597
                Object *ob;
9422
10598
                
9423
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9424
 
                        for(act= ob->actuators.first; act; act= act->next) {
 
10599
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10600
                        for (act= ob->actuators.first; act; act= act->next) {
9425
10601
                                if (act->type == ACT_CONSTRAINT) {
9426
10602
                                        bConstraintActuator *coa = act->data;
9427
10603
                                        if (coa->type == ACT_CONST_TYPE_DIST) {
9434
10610
 
9435
10611
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 9)) {
9436
10612
                Lamp *la= main->lamp.first;
9437
 
                for(; la; la= la->id.next) {
 
10613
                for (; la; la= la->id.next) {
9438
10614
                        la->sky_exposure= 1.0f;
9439
10615
                }
9440
10616
        }
9444
10620
                bActuator *act;
9445
10621
                Object *ob;
9446
10622
                
9447
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9448
 
                        for(act= ob->actuators.first; act; act= act->next) {
 
10623
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10624
                        for (act= ob->actuators.first; act; act= act->next) {
9449
10625
                                if (act->type == ACT_MESSAGE) {
9450
10626
                                        bMessageActuator *msgAct = (bMessageActuator *) act->data;
9451
 
                                        if (strlen(msgAct->toPropName) > 2) {
 
10627
                                        if (BLI_strnlen(msgAct->toPropName, 3) > 2) {
9452
10628
                                                /* strip first 2 chars, would have only worked if these were OB anyway */
9453
 
                                                memmove( msgAct->toPropName, msgAct->toPropName+2, sizeof(msgAct->toPropName)-2 );
9454
 
                                        } else {
 
10629
                                                memmove(msgAct->toPropName, msgAct->toPropName + 2, sizeof(msgAct->toPropName) - 2);
 
10630
                                        }
 
10631
                                        else {
9455
10632
                                                msgAct->toPropName[0] = '\0';
9456
10633
                                        }
9457
10634
                                }
9462
10639
        if (main->versionfile < 248) {
9463
10640
                Lamp *la;
9464
10641
 
9465
 
                for(la=main->lamp.first; la; la= la->id.next) {
9466
 
                        if(la->atm_turbidity == 0.0) {
 
10642
                for (la=main->lamp.first; la; la= la->id.next) {
 
10643
                        if (la->atm_turbidity == 0.0f) {
9467
10644
                                la->sun_effect_type = 0;
9468
10645
                                la->horizon_brightness = 1.0f;
9469
10646
                                la->spread = 1.0f;
9491
10668
                        sce->toolsettings->skgen_resolution = 250;
9492
10669
                        sce->toolsettings->skgen_threshold_internal     = 0.1f;
9493
10670
                        sce->toolsettings->skgen_threshold_external     = 0.1f;
9494
 
                        sce->toolsettings->skgen_angle_limit                    = 30.0f;
 
10671
                        sce->toolsettings->skgen_angle_limit                    = 30.0f;
9495
10672
                        sce->toolsettings->skgen_length_ratio                   = 1.3f;
9496
10673
                        sce->toolsettings->skgen_length_limit                   = 1.5f;
9497
10674
                        sce->toolsettings->skgen_correlation_limit              = 0.98f;
9555
10732
                Object *ob;
9556
10733
 
9557
10734
                /* Adjustments needed after Bullets update */
9558
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
 
10735
                for (ob = main->object.first; ob; ob= ob->id.next) {
9559
10736
                        ob->damping *= 0.635f;
9560
 
                        ob->rdamping = 0.1 + (0.8f * ob->rdamping);
 
10737
                        ob->rdamping = 0.1f + (0.8f * ob->rdamping);
9561
10738
                }
9562
10739
        }
9563
10740
        
9574
10751
                        sce->r.dometilt = 0;
9575
10752
                }
9576
10753
                /* DBVT culling by default */
9577
 
                for(wrld=main->world.first; wrld; wrld= wrld->id.next) {
 
10754
                for (wrld=main->world.first; wrld; wrld= wrld->id.next) {
9578
10755
                        wrld->mode |= WO_DBVT_CULLING;
9579
10756
                        wrld->occlusionRes = 128;
9580
10757
                }
9583
10760
        if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 5)) {
9584
10761
                Object *ob;
9585
10762
                World *wrld;
9586
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9587
 
                        ob->m_contactProcessingThreshold = 1.; //pad3 is used for m_contactProcessingThreshold
9588
 
                        if(ob->parent) {
 
10763
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10764
                        ob->m_contactProcessingThreshold = 1.0f; //pad3 is used for m_contactProcessingThreshold
 
10765
                        if (ob->parent) {
9589
10766
                                /* check if top parent has compound shape set and if yes, set this object
9590
 
                                   to compound shaper as well (was the behaviour before, now it's optional) */
 
10767
                                 * to compound shaper as well (was the behavior before, now it's optional) */
9591
10768
                                Object *parent= newlibadr(fd, lib, ob->parent);
9592
10769
                                while (parent && parent != ob &&  parent->parent != NULL) {
9593
10770
                                        parent = newlibadr(fd, lib, parent->parent);
9594
10771
                                }
9595
 
                                if(parent) {
 
10772
                                if (parent) {
9596
10773
                                        if (parent->gameflag & OB_CHILD)
9597
10774
                                                ob->gameflag |= OB_CHILD;
9598
10775
                                }
9599
10776
                        }
9600
10777
                }
9601
 
                for(wrld=main->world.first; wrld; wrld= wrld->id.next) {
 
10778
                for (wrld=main->world.first; wrld; wrld= wrld->id.next) {
9602
10779
                        wrld->ticrate = 60;
9603
10780
                        wrld->maxlogicstep = 5;
9604
10781
                        wrld->physubstep = 1;
9605
10782
                        wrld->maxphystep = 5;
9606
10783
                }
9607
10784
        }
9608
 
 
9609
 
        if (main->versionfile < 249) {
9610
 
                Scene *sce;
9611
 
                for (sce= main->scene.first; sce; sce= sce->id.next)
9612
 
                        sce->r.renderer= 0;
9613
 
                
9614
 
        }
9615
10785
        
9616
10786
        // correct introduce of seed for wind force
9617
10787
        if (main->versionfile < 249 && main->subversionfile < 1) {
9618
10788
                Object *ob;
9619
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9620
 
                        if(ob->pd)
 
10789
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10790
                        if (ob->pd)
9621
10791
                                ob->pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
9622
10792
                }
9623
10793
        
9628
10798
                Sequence *seq;
9629
10799
                Editing *ed;
9630
10800
                
9631
 
                while(sce) {
 
10801
                while (sce) {
9632
10802
                        ed= sce->ed;
9633
 
                        if(ed) {
 
10803
                        if (ed) {
9634
10804
                                SEQP_BEGIN(ed, seq) {
9635
 
                                        if (seq->strip && seq->strip->proxy){
9636
 
                                                if (sce->r.size != 100.0) {
9637
 
                                                        seq->strip->proxy->size
9638
 
                                                                = sce->r.size;
9639
 
                                                } else {
9640
 
                                                        seq->strip->proxy->size
9641
 
                                                                = 25.0;
9642
 
                                                }
 
10805
                                        if (seq->strip && seq->strip->proxy) {
9643
10806
                                                seq->strip->proxy->quality =90;
9644
10807
                                        }
9645
10808
                                }
9671
10834
                bActuator *act;
9672
10835
                int a;
9673
10836
 
9674
 
                for(sound = main->sound.first; sound; sound = sound->id.next)
 
10837
                for (sound = main->sound.first; sound; sound = sound->id.next)
9675
10838
                {
9676
 
                        if(sound->newpackedfile)
 
10839
                        if (sound->newpackedfile)
9677
10840
                        {
9678
10841
                                sound->packedfile = sound->newpackedfile;
9679
10842
                                sound->newpackedfile = NULL;
9680
10843
                        }
9681
10844
                }
9682
10845
 
9683
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
9684
 
                        for(act= ob->actuators.first; act; act= act->next) {
 
10846
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
10847
                        for (act= ob->actuators.first; act; act= act->next) {
9685
10848
                                if (act->type == ACT_SOUND) {
9686
10849
                                        bSoundActuator *sAct = (bSoundActuator*) act->data;
9687
 
                                        if(sAct->sound)
 
10850
                                        if (sAct->sound)
9688
10851
                                        {
9689
10852
                                                sound = newlibadr(fd, lib, sAct->sound);
9690
10853
                                                sAct->flag = sound->flags & SOUND_FLAGS_3D ? ACT_SND_3D_SOUND : 0;
9695
10858
                                                sAct->sound3D.min_gain = sound->min_gain;
9696
10859
                                                sAct->sound3D.rolloff_factor = sound->attenuation;
9697
10860
                                        }
9698
 
                                        else
9699
 
                                        {
 
10861
                                        else {
9700
10862
                                                sAct->sound3D.reference_distance = 1.0f;
9701
10863
                                                sAct->volume = 1.0f;
9702
10864
                                                sAct->sound3D.max_gain = 1.0f;
9709
10871
                        }
9710
10872
                }
9711
10873
 
9712
 
                for(scene = main->scene.first; scene; scene = scene->id.next)
 
10874
                for (scene = main->scene.first; scene; scene = scene->id.next)
9713
10875
                {
9714
 
                        if(scene->ed && scene->ed->seqbasep)
 
10876
                        if (scene->ed && scene->ed->seqbasep)
9715
10877
                        {
9716
 
                                for(seq = scene->ed->seqbasep->first; seq; seq = seq->next)
9717
 
                                {
9718
 
                                        if(seq->type == SEQ_HD_SOUND)
 
10878
                                SEQ_BEGIN(scene->ed, seq) {
 
10879
                                        if (seq->type == SEQ_HD_SOUND)
9719
10880
                                        {
9720
10881
                                                char str[FILE_MAX];
9721
 
                                                BLI_join_dirfile(str, seq->strip->dir, seq->strip->stripdata->name);
9722
 
                                                BLI_path_abs(str, G.sce);
 
10882
                                                BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name);
 
10883
                                                BLI_path_abs(str, main->name);
9723
10884
                                                seq->sound = sound_new_file(main, str);
9724
10885
                                        }
9725
10886
                                        /* don't know, if anybody used that
9726
 
                                           this way, but just in case, upgrade
9727
 
                                           to new way... */
9728
 
                                        if((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) &&
 
10887
                                         * this way, but just in case, upgrade
 
10888
                                         * to new way... */
 
10889
                                        if ((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) &&
9729
10890
                                           !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR))
9730
10891
                                        {
9731
10892
                                                
9732
 
                                                snprintf(seq->strip->proxy->dir, 
 
10893
                                                BLI_snprintf(seq->strip->proxy->dir, 
9733
10894
                                                         FILE_MAXDIR, "%s/BL_proxy", 
9734
10895
                                                         seq->strip->dir);
9735
10896
                                        }
9736
10897
                                }
 
10898
                                SEQ_END
9737
10899
                        }
9738
10900
                }
9739
10901
 
9740
 
                for(screen= main->screen.first; screen; screen= screen->id.next) {
 
10902
                for (screen= main->screen.first; screen; screen= screen->id.next) {
9741
10903
                        do_versions_windowmanager_2_50(screen);
9742
10904
                        do_versions_gpencil_2_50(main, screen);
9743
10905
                }
9744
10906
                
9745
 
                /* shader, composit and texture node trees have id.name empty, put something in
 
10907
                /* shader, composite and texture node trees have id.name empty, put something in
9746
10908
                 * to have them show in RNA viewer and accessible otherwise.
9747
10909
                 */
9748
 
                for(ma= main->mat.first; ma; ma= ma->id.next) {
9749
 
                        if(ma->nodetree && strlen(ma->nodetree->id.name)==0)
 
10910
                for (ma= main->mat.first; ma; ma= ma->id.next) {
 
10911
                        if (ma->nodetree && ma->nodetree->id.name[0] == '\0')
9750
10912
                                strcpy(ma->nodetree->id.name, "NTShader Nodetree");
9751
10913
                        
9752
10914
                        /* which_output 0 is now "not specified" */
9753
 
                        for(a=0; a<MAX_MTEX; a++) {
9754
 
                                if(ma->mtex[a]) {
 
10915
                        for (a=0; a<MAX_MTEX; a++) {
 
10916
                                if (ma->mtex[a]) {
9755
10917
                                        tx= newlibadr(fd, lib, ma->mtex[a]->tex);
9756
 
                                        if(tx && tx->use_nodes)
 
10918
                                        if (tx && tx->use_nodes)
9757
10919
                                                ma->mtex[a]->which_output++;
9758
10920
                                }
9759
10921
                        }
9760
10922
                }
9761
 
                /* and composit trees */
9762
 
                for(sce= main->scene.first; sce; sce= sce->id.next) {
9763
 
                        if(sce->nodetree && strlen(sce->nodetree->id.name)==0)
 
10923
                /* and composite trees */
 
10924
                for (sce= main->scene.first; sce; sce= sce->id.next) {
 
10925
                        if (sce->nodetree && sce->nodetree->id.name[0] == '\0')
9764
10926
                                strcpy(sce->nodetree->id.name, "NTCompositing Nodetree");
9765
10927
 
9766
10928
                        /* move to cameras */
9767
 
                        if(sce->r.mode & R_PANORAMA) {
9768
 
                                for(base=sce->base.first; base; base=base->next) {
 
10929
                        if (sce->r.mode & R_PANORAMA) {
 
10930
                                for (base=sce->base.first; base; base=base->next) {
9769
10931
                                        ob= newlibadr(fd, lib, base->object);
9770
10932
 
9771
 
                                        if(ob->type == OB_CAMERA && !ob->id.lib) {
 
10933
                                        if (ob->type == OB_CAMERA && !ob->id.lib) {
9772
10934
                                                cam= newlibadr(fd, lib, ob->data);
9773
10935
                                                cam->flag |= CAM_PANORAMA;
9774
10936
                                        }
9778
10940
                        }
9779
10941
                }
9780
10942
                /* and texture trees */
9781
 
                for(tx= main->tex.first; tx; tx= tx->id.next) {
 
10943
                for (tx= main->tex.first; tx; tx= tx->id.next) {
9782
10944
                        bNode *node;
9783
10945
 
9784
 
                        if(tx->nodetree) {
9785
 
                                if(strlen(tx->nodetree->id.name)==0)
 
10946
                        if (tx->nodetree) {
 
10947
                                if (tx->nodetree->id.name[0] == '\0')
9786
10948
                                        strcpy(tx->nodetree->id.name, "NTTexture Nodetree");
9787
10949
 
9788
10950
                                /* which_output 0 is now "not specified" */
9789
 
                                for(node=tx->nodetree->nodes.first; node; node=node->next)
9790
 
                                        if(node->type == TEX_NODE_OUTPUT)
 
10951
                                for (node=tx->nodetree->nodes.first; node; node=node->next)
 
10952
                                        if (node->type == TEX_NODE_OUTPUT)
9791
10953
                                                node->custom1++;
9792
10954
                        }
9793
10955
                }
9794
10956
                
9795
10957
                /* copy standard draw flag to meshes(used to be global, is not available here) */
9796
 
                for(me= main->mesh.first; me; me= me->id.next) {
 
10958
                for (me= main->mesh.first; me; me= me->id.next) {
9797
10959
                        me->drawflag= ME_DRAWEDGES|ME_DRAWFACES|ME_DRAWCREASES;
9798
10960
                }
9799
10961
 
9800
10962
                /* particle draw and render types */
9801
 
                for(part= main->particle.first; part; part= part->id.next) {
9802
 
                        if(part->draw_as) {
9803
 
                                if(part->draw_as == PART_DRAW_DOT) {
 
10963
                for (part= main->particle.first; part; part= part->id.next) {
 
10964
                        if (part->draw_as) {
 
10965
                                if (part->draw_as == PART_DRAW_DOT) {
9804
10966
                                        part->ren_as = PART_DRAW_HALO;
9805
10967
                                        part->draw_as = PART_DRAW_REND;
9806
10968
                                }
9807
 
                                else if(part->draw_as <= PART_DRAW_AXIS) {
 
10969
                                else if (part->draw_as <= PART_DRAW_AXIS) {
9808
10970
                                        part->ren_as = PART_DRAW_HALO;
9809
10971
                                }
9810
10972
                                else {
9816
10978
                        part->clength = 1.0f;
9817
10979
                }
9818
10980
                /* set old pointcaches to have disk cache flag */
9819
 
                for(ob = main->object.first; ob; ob= ob->id.next) {
 
10981
                for (ob = main->object.first; ob; ob= ob->id.next) {
9820
10982
 
9821
10983
                        //BKE_ptcache_ids_from_object(&pidlist, ob);
9822
10984
 
9823
 
                        //for(pid=pidlist.first; pid; pid=pid->next)
 
10985
                        //for (pid=pidlist.first; pid; pid=pid->next)
9824
10986
                        //      pid->cache->flag |= PTCACHE_DISK_CACHE;
9825
10987
 
9826
10988
                        //BLI_freelistN(&pidlist);
9827
10989
                }
9828
10990
 
9829
10991
                /* type was a mixed flag & enum. move the 2d flag elsewhere */
9830
 
                for(cu = main->curve.first; cu; cu= cu->id.next) {
 
10992
                for (cu = main->curve.first; cu; cu= cu->id.next) {
9831
10993
                        Nurb *nu;
9832
10994
 
9833
 
                        for(nu= cu->nurb.first; nu; nu= nu->next) {
 
10995
                        for (nu= cu->nurb.first; nu; nu= nu->next) {
9834
10996
                                nu->flag |= (nu->type & CU_2D);
9835
10997
                                nu->type &= CU_TYPE;
9836
10998
                        }
9845
11007
                ToolSettings *ts;
9846
11008
                //PTCacheID *pid;
9847
11009
                //ListBase pidlist;
9848
 
                int a;
9849
11010
 
9850
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
 
11011
                for (ob = main->object.first; ob; ob = ob->id.next) {
9851
11012
                        //BKE_ptcache_ids_from_object(&pidlist, ob);
9852
11013
 
9853
 
                        //for(pid=pidlist.first; pid; pid=pid->next) {
9854
 
                        //      if(pid->ptcaches->first == NULL)
 
11014
                        //for (pid=pidlist.first; pid; pid=pid->next) {
 
11015
                        //      if (pid->ptcaches->first == NULL)
9855
11016
                        //              pid->ptcaches->first = pid->ptcaches->last = pid->cache;
9856
11017
                        //}
9857
11018
 
9858
11019
                        //BLI_freelistN(&pidlist);
9859
11020
 
9860
 
                        if(ob->type == OB_MESH) {
 
11021
                        if (ob->type == OB_MESH) {
9861
11022
                                Mesh *me = newlibadr(fd, lib, ob->data);
9862
11023
                                void *olddata = ob->data;
9863
11024
                                ob->data = me;
9864
11025
 
9865
 
                                if(me && me->id.lib==NULL && me->mr && me->mr->level_count > 1) /* XXX - library meshes crash on loading most yoFrankie levels, the multires pointer gets invalid -  Campbell */
 
11026
                                /* XXX - library meshes crash on loading most yoFrankie levels,
 
11027
                                 * the multires pointer gets invalid -  Campbell */
 
11028
                                if (me && me->id.lib==NULL && me->mr && me->mr->level_count > 1) {
9866
11029
                                        multires_load_old(ob, me);
 
11030
                                }
9867
11031
 
9868
11032
                                ob->data = olddata;
9869
11033
                        }
9870
11034
 
9871
 
                        if(ob->totcol && ob->matbits == NULL) {
 
11035
                        if (ob->totcol && ob->matbits == NULL) {
9872
11036
                                int a;
9873
11037
 
9874
11038
                                ob->matbits= MEM_callocN(sizeof(char)*ob->totcol, "ob->matbits");
9875
 
                                for(a=0; a<ob->totcol; a++)
 
11039
                                for (a=0; a<ob->totcol; a++)
9876
11040
                                        ob->matbits[a]= ob->colbits & (1<<a);
9877
11041
                        }
9878
11042
                }
9879
11043
 
9880
11044
                /* texture filter */
9881
 
                for(tex = main->tex.first; tex; tex = tex->id.next) {
9882
 
                        if(tex->afmax == 0)
 
11045
                for (tex = main->tex.first; tex; tex = tex->id.next) {
 
11046
                        if (tex->afmax == 0)
9883
11047
                                tex->afmax= 8;
9884
11048
                }
9885
11049
 
9886
 
                for(ma = main->mat.first; ma; ma = ma->id.next) {
9887
 
                        if(ma->mode & MA_WIRE) {
 
11050
                for (ma = main->mat.first; ma; ma = ma->id.next) {
 
11051
                        int a;
 
11052
                        if (ma->mode & MA_WIRE) {
9888
11053
                                ma->material_type= MA_TYPE_WIRE;
9889
11054
                                ma->mode &= ~MA_WIRE;
9890
11055
                        }
9891
 
                        if(ma->mode & MA_HALO) {
 
11056
                        if (ma->mode & MA_HALO) {
9892
11057
                                ma->material_type= MA_TYPE_HALO;
9893
11058
                                ma->mode &= ~MA_HALO;
9894
11059
                        }
9895
11060
 
9896
 
                        if(ma->mode & (MA_ZTRANSP|MA_RAYTRANSP)) {
 
11061
                        if (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP)) {
9897
11062
                                ma->mode |= MA_TRANSP;
9898
11063
                        }
9899
11064
                        else {
9900
 
                                ma->mode |= MA_ZTRANSP;
 
11065
                                /* ma->mode |= MA_ZTRANSP; */ /* leave ztransp as is even if its not used [#28113] */
9901
11066
                                ma->mode &= ~MA_TRANSP;
9902
11067
                        }
9903
11068
 
9904
11069
                        /* set new bump for unused slots */
9905
 
                        for(a=0; a<MAX_MTEX; a++) {
9906
 
                                if(ma->mtex[a]) {
 
11070
                        for (a=0; a<MAX_MTEX; a++) {
 
11071
                                if (ma->mtex[a]) {
9907
11072
                                        tex= ma->mtex[a]->tex;
9908
 
                                        if(!tex)
9909
 
                                                ma->mtex[a]->texflag |= MTEX_NEW_BUMP;
 
11073
                                        if (!tex) {
 
11074
                                                ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
 
11075
                                                ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
 
11076
                                        }
9910
11077
                                        else {
9911
11078
                                                tex= (Tex*)newlibadr(fd, ma->id.lib, tex);
9912
 
                                                if(tex && tex->type == 0) /* invalid type */
9913
 
                                                        ma->mtex[a]->texflag |= MTEX_NEW_BUMP;
 
11079
                                                if (tex && tex->type == 0) { /* invalid type */
 
11080
                                                        ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
 
11081
                                                        ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
 
11082
                                                }
9914
11083
                                        }
9915
11084
                                }
9916
11085
                        }
9931
11100
                        }
9932
11101
                }
9933
11102
 
9934
 
                for(sce = main->scene.first; sce; sce = sce->id.next) {
 
11103
                for (sce = main->scene.first; sce; sce = sce->id.next) {
9935
11104
                        ts= sce->toolsettings;
9936
 
                        if(ts->normalsize == 0.0 || !ts->uv_selectmode || ts->vgroup_weight == 0.0) {
 
11105
                        if (ts->normalsize == 0.0f || !ts->uv_selectmode || ts->vgroup_weight == 0.0f) {
9937
11106
                                ts->normalsize= 0.1f;
9938
11107
                                ts->selectmode= SCE_SELECT_VERTEX;
9939
11108
                                
9958
11127
                        sce->gm.dome.warptext = sce->r.dometext;
9959
11128
 
9960
11129
                        //Stand Alone
9961
 
                        sce->gm.fullscreen = sce->r.fullscreen;
 
11130
                        sce->gm.playerflag |= (sce->r.fullscreen?GAME_PLAYER_FULLSCREEN:0);
9962
11131
                        sce->gm.xplay = sce->r.xplay;
9963
11132
                        sce->gm.yplay = sce->r.yplay;
9964
11133
                        sce->gm.freqplay = sce->r.freqplay;
9966
11135
                        sce->gm.attrib = sce->r.attrib;
9967
11136
 
9968
11137
                        //Stereo
9969
 
                        sce->gm.xsch = sce->r.xsch;
9970
 
                        sce->gm.ysch = sce->r.ysch;
9971
11138
                        sce->gm.stereomode = sce->r.stereomode;
9972
11139
                        /* reassigning stereomode NO_STEREO and DOME to a separeted flag*/
9973
 
                        if (sce->gm.stereomode == 1){ //1 = STEREO_NOSTEREO
 
11140
                        if (sce->gm.stereomode == 1) { //1 = STEREO_NOSTEREO
9974
11141
                                sce->gm.stereoflag = STEREO_NOSTEREO;
9975
11142
                                sce->gm.stereomode = STEREO_ANAGLYPH;
9976
11143
                        }
9977
 
                        else if(sce->gm.stereomode == 8){ //8 = STEREO_DOME
 
11144
                        else if (sce->gm.stereomode == 8) { //8 = STEREO_DOME
9978
11145
                                sce->gm.stereoflag = STEREO_DOME;
9979
11146
                                sce->gm.stereomode = STEREO_ANAGLYPH;
9980
11147
                        }
10004
11171
                Scene *sce;
10005
11172
                Object *ob;
10006
11173
 
10007
 
                for(sce = main->scene.first; sce; sce = sce->id.next) {
10008
 
                        if(fd->fileflags & G_FILE_ENABLE_ALL_FRAMES)
 
11174
                for (sce = main->scene.first; sce; sce = sce->id.next) {
 
11175
                        if (fd->fileflags & G_FILE_ENABLE_ALL_FRAMES)
10009
11176
                                sce->gm.flag |= GAME_ENABLE_ALL_FRAMES;
10010
 
                        if(fd->fileflags & G_FILE_SHOW_DEBUG_PROPS)
 
11177
                        if (fd->fileflags & G_FILE_SHOW_DEBUG_PROPS)
10011
11178
                                sce->gm.flag |= GAME_SHOW_DEBUG_PROPS;
10012
 
                        if(fd->fileflags & G_FILE_SHOW_FRAMERATE)
 
11179
                        if (fd->fileflags & G_FILE_SHOW_FRAMERATE)
10013
11180
                                sce->gm.flag |= GAME_SHOW_FRAMERATE;
10014
 
                        if(fd->fileflags & G_FILE_SHOW_PHYSICS)
 
11181
                        if (fd->fileflags & G_FILE_SHOW_PHYSICS)
10015
11182
                                sce->gm.flag |= GAME_SHOW_PHYSICS;
10016
 
                        if(fd->fileflags & G_FILE_GLSL_NO_SHADOWS)
 
11183
                        if (fd->fileflags & G_FILE_GLSL_NO_SHADOWS)
10017
11184
                                sce->gm.flag |= GAME_GLSL_NO_SHADOWS;
10018
 
                        if(fd->fileflags & G_FILE_GLSL_NO_SHADERS)
 
11185
                        if (fd->fileflags & G_FILE_GLSL_NO_SHADERS)
10019
11186
                                sce->gm.flag |= GAME_GLSL_NO_SHADERS;
10020
 
                        if(fd->fileflags & G_FILE_GLSL_NO_RAMPS)
 
11187
                        if (fd->fileflags & G_FILE_GLSL_NO_RAMPS)
10021
11188
                                sce->gm.flag |= GAME_GLSL_NO_RAMPS;
10022
 
                        if(fd->fileflags & G_FILE_GLSL_NO_NODES)
 
11189
                        if (fd->fileflags & G_FILE_GLSL_NO_NODES)
10023
11190
                                sce->gm.flag |= GAME_GLSL_NO_NODES;
10024
 
                        if(fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX)
 
11191
                        if (fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX)
10025
11192
                                sce->gm.flag |= GAME_GLSL_NO_EXTRA_TEX;
10026
 
                        if(fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS)
 
11193
                        if (fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS)
10027
11194
                                sce->gm.flag |= GAME_IGNORE_DEPRECATION_WARNINGS;
10028
11195
 
10029
 
                        if(fd->fileflags & G_FILE_GAME_MAT_GLSL)
 
11196
                        if (fd->fileflags & G_FILE_GAME_MAT_GLSL)
10030
11197
                                sce->gm.matmode= GAME_MAT_GLSL;
10031
 
                        else if(fd->fileflags & G_FILE_GAME_MAT)
 
11198
                        else if (fd->fileflags & G_FILE_GAME_MAT)
10032
11199
                                sce->gm.matmode= GAME_MAT_MULTITEX;
10033
11200
                        else
10034
11201
                                sce->gm.matmode= GAME_MAT_TEXFACE;
10036
11203
                        sce->gm.flag |= GAME_DISPLAY_LISTS;
10037
11204
                }
10038
11205
                
10039
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
10040
 
                        if(ob->flag & 8192) // OB_POSEMODE = 8192
 
11206
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
11207
                        if (ob->flag & 8192) // OB_POSEMODE = 8192
10041
11208
                                ob->mode |= OB_MODE_POSE;
10042
11209
                }
10043
11210
        }
10052
11219
                ParticleSettings *part;
10053
11220
                int do_gravity = 0;
10054
11221
 
10055
 
                for(sce = main->scene.first; sce; sce = sce->id.next)
10056
 
                        if(sce->unit.scale_length == 0.0f)
 
11222
                for (sce = main->scene.first; sce; sce = sce->id.next)
 
11223
                        if (sce->unit.scale_length == 0.0f)
10057
11224
                                sce->unit.scale_length= 1.0f;
10058
11225
                
10059
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
 
11226
                for (ob = main->object.first; ob; ob = ob->id.next) {
10060
11227
                        /* fluid-sim stuff */
10061
11228
                        FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
10062
11229
                        if (fluidmd) fluidmd->fss->fmd = fluidmd;
10065
11232
                        ob->rotmode= ROT_MODE_EUL;
10066
11233
                }
10067
11234
                
10068
 
                for(ma = main->mat.first; ma; ma=ma->id.next) {
10069
 
                        if(ma->vol.reflection == 0.f) {
 
11235
                for (ma = main->mat.first; ma; ma=ma->id.next) {
 
11236
                        if (ma->vol.reflection == 0.f) {
10070
11237
                                ma->vol.reflection = 1.f;
10071
11238
                                ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f;
10072
11239
                                ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f;
10075
11242
                        do_version_mtex_factor_2_50(ma->mtex, ID_MA);
10076
11243
                }
10077
11244
 
10078
 
                for(la = main->lamp.first; la; la=la->id.next)
 
11245
                for (la = main->lamp.first; la; la=la->id.next)
10079
11246
                        do_version_mtex_factor_2_50(la->mtex, ID_LA);
10080
11247
 
10081
 
                for(wo = main->world.first; wo; wo=wo->id.next)
 
11248
                for (wo = main->world.first; wo; wo=wo->id.next)
10082
11249
                        do_version_mtex_factor_2_50(wo->mtex, ID_WO);
10083
11250
 
10084
 
                for(tex = main->tex.first; tex; tex=tex->id.next)
10085
 
                        if(tex->vd)
10086
 
                                if(tex->vd->extend == 0)
 
11251
                for (tex = main->tex.first; tex; tex=tex->id.next)
 
11252
                        if (tex->vd)
 
11253
                                if (tex->vd->extend == 0)
10087
11254
                                        tex->vd->extend = TEX_CLIP;
10088
11255
                
10089
 
                for(sce= main->scene.first; sce; sce= sce->id.next)
 
11256
                for (sce= main->scene.first; sce; sce= sce->id.next)
10090
11257
                {
10091
 
                        if(sce->audio.main == 0.0)
10092
 
                                sce->audio.main = 1.0;
 
11258
                        if (sce->audio.main == 0.0f)
 
11259
                                sce->audio.main = 1.0f;
10093
11260
 
10094
11261
                        sce->r.ffcodecdata.audio_mixrate = sce->audio.mixrate;
10095
11262
                        sce->r.ffcodecdata.audio_volume = sce->audio.main;
10096
 
                        sce->audio.distance_model = 2.0;
10097
 
                        sce->audio.doppler_factor = 1.0;
10098
 
                        sce->audio.speed_of_sound = 343.3;
 
11263
                        sce->audio.distance_model = 2;
 
11264
                        sce->audio.doppler_factor = 1.0f;
 
11265
                        sce->audio.speed_of_sound = 343.3f;
10099
11266
                }
10100
11267
 
10101
11268
                /* Add default gravity to scenes */
10102
 
                for(sce= main->scene.first; sce; sce= sce->id.next) {
10103
 
                        if((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0
10104
 
                                && len_v3(sce->physics_settings.gravity) == 0.0f) {
10105
 
 
 
11269
                for (sce= main->scene.first; sce; sce= sce->id.next) {
 
11270
                        if ((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0 &&
 
11271
                            len_v3(sce->physics_settings.gravity) == 0.0f)
 
11272
                        {
10106
11273
                                sce->physics_settings.gravity[0] = sce->physics_settings.gravity[1] = 0.0f;
10107
11274
                                sce->physics_settings.gravity[2] = -9.81f;
10108
11275
                                sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
10111
11278
                }
10112
11279
 
10113
11280
                /* Assign proper global gravity weights for dynamics (only z-coordinate is taken into account) */
10114
 
                if(do_gravity) for(part= main->particle.first; part; part= part->id.next)
 
11281
                if (do_gravity) for (part= main->particle.first; part; part= part->id.next)
10115
11282
                        part->effector_weights->global_gravity = part->acc[2]/-9.81f;
10116
11283
 
10117
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
 
11284
                for (ob = main->object.first; ob; ob = ob->id.next) {
10118
11285
                        ModifierData *md;
10119
11286
 
10120
 
                        if(do_gravity) {
10121
 
                                for(md= ob->modifiers.first; md; md= md->next) {
 
11287
                        if (do_gravity) {
 
11288
                                for (md= ob->modifiers.first; md; md= md->next) {
10122
11289
                                        ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
10123
 
                                        if(clmd)
10124
 
                                                clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2]/-9.81;
 
11290
                                        if (clmd)
 
11291
                                                clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2]/-9.81f;
10125
11292
                                }
10126
11293
 
10127
 
                                if(ob->soft)
10128
 
                                        ob->soft->effector_weights->global_gravity = ob->soft->grav/9.81;
 
11294
                                if (ob->soft)
 
11295
                                        ob->soft->effector_weights->global_gravity = ob->soft->grav/9.81f;
10129
11296
                        }
10130
11297
 
10131
11298
                        /* Normal wind shape is plane */
10132
 
                        if(ob->pd) {
10133
 
                                if(ob->pd->forcefield == PFIELD_WIND)
 
11299
                        if (ob->pd) {
 
11300
                                if (ob->pd->forcefield == PFIELD_WIND)
10134
11301
                                        ob->pd->shape = PFIELD_SHAPE_PLANE;
10135
11302
                                
10136
 
                                if(ob->pd->flag & PFIELD_PLANAR)
 
11303
                                if (ob->pd->flag & PFIELD_PLANAR)
10137
11304
                                        ob->pd->shape = PFIELD_SHAPE_PLANE;
10138
 
                                else if(ob->pd->flag & PFIELD_SURFACE)
 
11305
                                else if (ob->pd->flag & PFIELD_SURFACE)
10139
11306
                                        ob->pd->shape = PFIELD_SHAPE_SURFACE;
 
11307
 
 
11308
                                ob->pd->flag |= PFIELD_DO_LOCATION;
10140
11309
                        }
10141
11310
                }
10142
11311
        }
10145
11314
                Object *ob;
10146
11315
                Lamp *la;
10147
11316
                
10148
 
                /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialisation */
 
11317
                /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialization */
10149
11318
                for (ob= main->object.first; ob; ob= ob->id.next) {
10150
11319
                        /* new variables for all objects */
10151
11320
                        ob->quat[0]= 1.0f;
10162
11331
                        }
10163
11332
                }
10164
11333
 
10165
 
                for(la = main->lamp.first; la; la=la->id.next)
 
11334
                for (la = main->lamp.first; la; la=la->id.next)
10166
11335
                        la->compressthresh= 0.05f;
10167
11336
        }
10168
11337
 
10176
11345
                int a, tot;
10177
11346
 
10178
11347
                /* shape keys are no longer applied to the mesh itself, but rather
10179
 
                   to the derivedmesh/displist, so here we ensure that the basis
10180
 
                   shape key is always set in the mesh coordinates. */
 
11348
                 * to the derivedmesh/displist, so here we ensure that the basis
 
11349
                 * shape key is always set in the mesh coordinates. */
10181
11350
 
10182
 
                for(me= main->mesh.first; me; me= me->id.next) {
10183
 
                        if((key = newlibadr(fd, lib, me->key)) && key->refkey) {
 
11351
                for (me= main->mesh.first; me; me= me->id.next) {
 
11352
                        if ((key = newlibadr(fd, lib, me->key)) && key->refkey) {
10184
11353
                                data= key->refkey->data;
10185
11354
                                tot= MIN2(me->totvert, key->refkey->totelem);
10186
11355
 
10187
 
                                for(a=0; a<tot; a++, data+=3)
10188
 
                                        VECCOPY(me->mvert[a].co, data)
 
11356
                                for (a=0; a<tot; a++, data+=3)
 
11357
                                        copy_v3_v3(me->mvert[a].co, data);
10189
11358
                        }
10190
11359
                }
10191
11360
 
10192
 
                for(lt= main->latt.first; lt; lt= lt->id.next) {
10193
 
                        if((key = newlibadr(fd, lib, lt->key)) && key->refkey) {
 
11361
                for (lt= main->latt.first; lt; lt= lt->id.next) {
 
11362
                        if ((key = newlibadr(fd, lib, lt->key)) && key->refkey) {
10194
11363
                                data= key->refkey->data;
10195
11364
                                tot= MIN2(lt->pntsu*lt->pntsv*lt->pntsw, key->refkey->totelem);
10196
11365
 
10197
 
                                for(a=0; a<tot; a++, data+=3)
10198
 
                                        VECCOPY(lt->def[a].vec, data)
 
11366
                                for (a=0; a<tot; a++, data+=3)
 
11367
                                        copy_v3_v3(lt->def[a].vec, data);
10199
11368
                        }
10200
11369
                }
10201
11370
 
10202
 
                for(cu= main->curve.first; cu; cu= cu->id.next) {
10203
 
                        if((key = newlibadr(fd, lib, cu->key)) && key->refkey) {
 
11371
                for (cu= main->curve.first; cu; cu= cu->id.next) {
 
11372
                        if ((key = newlibadr(fd, lib, cu->key)) && key->refkey) {
10204
11373
                                data= key->refkey->data;
10205
11374
 
10206
 
                                for(nu=cu->nurb.first; nu; nu=nu->next) {
10207
 
                                        if(nu->bezt) {
 
11375
                                for (nu=cu->nurb.first; nu; nu=nu->next) {
 
11376
                                        if (nu->bezt) {
10208
11377
                                                BezTriple *bezt = nu->bezt;
10209
11378
 
10210
 
                                                for(a=0; a<nu->pntsu; a++, bezt++) {
10211
 
                                                        VECCOPY(bezt->vec[0], data); data+=3;
10212
 
                                                        VECCOPY(bezt->vec[1], data); data+=3;
10213
 
                                                        VECCOPY(bezt->vec[2], data); data+=3;
 
11379
                                                for (a=0; a<nu->pntsu; a++, bezt++) {
 
11380
                                                        copy_v3_v3(bezt->vec[0], data); data+=3;
 
11381
                                                        copy_v3_v3(bezt->vec[1], data); data+=3;
 
11382
                                                        copy_v3_v3(bezt->vec[2], data); data+=3;
10214
11383
                                                        bezt->alfa= *data; data++;
10215
11384
                                                }
10216
11385
                                        }
10217
 
                                        else if(nu->bp) {
 
11386
                                        else if (nu->bp) {
10218
11387
                                                BPoint *bp = nu->bp;
10219
11388
 
10220
 
                                                for(a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
10221
 
                                                        VECCOPY(bp->vec, data); data+=3;
 
11389
                                                for (a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
 
11390
                                                        copy_v3_v3(bp->vec, data); data+=3;
10222
11391
                                                        bp->alfa= *data; data++;
10223
11392
                                                }
10224
11393
                                        }
10231
11400
        {
10232
11401
                {
10233
11402
                        Scene *sce= main->scene.first;
10234
 
                        while(sce) {
10235
 
                                if(sce->r.frame_step==0)
 
11403
                        while (sce) {
 
11404
                                if (sce->r.frame_step==0)
10236
11405
                                        sce->r.frame_step= 1;
10237
11406
                                if (sce->r.mblur_samples==0)
10238
11407
                                        sce->r.mblur_samples = sce->r.osa;
10248
11417
                {
10249
11418
                        /* ensure all nodes have unique names */
10250
11419
                        bNodeTree *ntree= main->nodetree.first;
10251
 
                        while(ntree) {
 
11420
                        while (ntree) {
10252
11421
                                bNode *node=ntree->nodes.first;
10253
11422
                                
10254
 
                                while(node) {
 
11423
                                while (node) {
10255
11424
                                        nodeUniqueName(ntree, node);
10256
11425
                                        node= node->next;
10257
11426
                                }
10263
11432
                        Object *ob=main->object.first;
10264
11433
                        while (ob) {
10265
11434
                                /* shaded mode disabled for now */
10266
 
                                if (ob->dt == OB_SHADED) ob->dt = OB_TEXTURE;
 
11435
                                if (ob->dt == OB_MATERIAL) ob->dt = OB_TEXTURE;
10267
11436
                                ob=ob->id.next;
10268
11437
                        }
10269
11438
                }
10273
11442
                        ScrArea *sa;
10274
11443
                        SpaceLink *sl;
10275
11444
                        
10276
 
                        for(screen= main->screen.first; screen; screen= screen->id.next) {
10277
 
                                for(sa= screen->areabase.first; sa; sa= sa->next) {
10278
 
                                        for(sl= sa->spacedata.first; sl; sl= sl->next) {
10279
 
                                                if(sl->spacetype==SPACE_VIEW3D) {
 
11445
                        for (screen= main->screen.first; screen; screen= screen->id.next) {
 
11446
                                for (sa= screen->areabase.first; sa; sa= sa->next) {
 
11447
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
11448
                                                if (sl->spacetype==SPACE_VIEW3D) {
10280
11449
                                                        View3D *v3d = (View3D *)sl;
10281
 
                                                        if (v3d->drawtype == OB_SHADED) v3d->drawtype = OB_SOLID;
 
11450
                                                        if (v3d->drawtype == OB_MATERIAL) v3d->drawtype = OB_SOLID;
10282
11451
                                                }
10283
11452
                                        }
10284
11453
                                }
10294
11463
                        int i, convert=0;
10295
11464
                        
10296
11465
                        /* convert to new color management system:
10297
 
                         while previously colors were stored as srgb, 
10298
 
                         now they are stored as linear internally, 
10299
 
                         with screen gamma correction in certain places in the UI. */
 
11466
                         * while previously colors were stored as srgb,
 
11467
                         * now they are stored as linear internally,
 
11468
                         * with screen gamma correction in certain places in the UI. */
10300
11469
 
10301
11470
                        /* don't know what scene is active, so we'll convert if any scene has it enabled... */
10302
11471
                        while (sce) {
10303
 
                                if(sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
 
11472
                                if (sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
10304
11473
                                        convert=1;
10305
11474
                                sce=sce->id.next;
10306
11475
                        }
10307
11476
                        
10308
11477
                        if (convert) {
10309
 
                                while(ma) {
 
11478
                                while (ma) {
10310
11479
                                        if (ma->ramp_col) {
10311
11480
                                                ColorBand *band = (ColorBand *)ma->ramp_col;
10312
11481
                                                for (i=0; i<band->tot; i++) {
10329
11498
                                        ma=ma->id.next;
10330
11499
                                }
10331
11500
                                
10332
 
                                while(tex) {
 
11501
                                while (tex) {
10333
11502
                                        if (tex->coba) {
10334
11503
                                                ColorBand *band = (ColorBand *)tex->coba;
10335
11504
                                                for (i=0; i<band->tot; i++) {
10340
11509
                                        tex=tex->id.next;
10341
11510
                                }
10342
11511
                                
10343
 
                                while(wo) {
 
11512
                                while (wo) {
10344
11513
                                        srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr);
10345
11514
                                        srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr);
10346
11515
                                        srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr);
10348
11517
                                }
10349
11518
                        }
10350
11519
                }
10351
 
                /* clear hanging 'temp' screens from older 2.5 files*/
10352
 
                if (main->versionfile == 250) {
10353
 
                        bScreen *screen, *nextscreen;
10354
 
                        wmWindowManager *wm;
10355
 
                        wmWindow *win, *nextwin;
10356
 
 
10357
 
                        for(screen= main->screen.first; screen; screen= nextscreen) {
10358
 
                                nextscreen= screen->id.next;
10359
 
 
10360
 
                                if (screen->full == SCREENTEMP) {
10361
 
                                        /* remove corresponding windows */
10362
 
                                        for(wm= main->wm.first; wm; wm=wm->id.next) {
10363
 
                                                for(win= wm->windows.first; win; win=nextwin) {
10364
 
                                                        nextwin= win->next;
10365
 
 
10366
 
                                                        if(newlibadr(fd, wm->id.lib, win->screen) == screen)
10367
 
                                                                BLI_freelinkN(&wm->windows, win);
10368
 
                                                }
10369
 
                                        }
10370
 
 
10371
 
                                        /* remove screen itself */
10372
 
                                        free_libblock(&main->screen, screen);
10373
 
                                }
10374
 
                        }
10375
 
                }
10376
11520
        }
10377
11521
        
10378
11522
        if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9))
10381
11525
                Mesh *me;
10382
11526
                Object *ob;
10383
11527
 
10384
 
                for(sce=main->scene.first; sce; sce=sce->id.next)
10385
 
                        if(!sce->toolsettings->particle.selectmode)
 
11528
                for (sce=main->scene.first; sce; sce=sce->id.next)
 
11529
                        if (!sce->toolsettings->particle.selectmode)
10386
11530
                                sce->toolsettings->particle.selectmode= SCE_SELECT_PATH;
10387
11531
 
10388
11532
                if (main->versionfile == 250 && main->subversionfile > 1) {
10389
 
                        for(me=main->mesh.first; me; me=me->id.next)
 
11533
                        for (me=main->mesh.first; me; me=me->id.next)
10390
11534
                                multires_load_old_250(me);
10391
11535
 
10392
 
                        for(ob=main->object.first; ob; ob=ob->id.next) {
 
11536
                        for (ob=main->object.first; ob; ob=ob->id.next) {
10393
11537
                                MultiresModifierData *mmd = (MultiresModifierData *)modifiers_findByType(ob, eModifierType_Multires);
10394
11538
 
10395
 
                                if(mmd) {
 
11539
                                if (mmd) {
10396
11540
                                        mmd->totlvl--;
10397
11541
                                        mmd->lvl--;
10398
11542
                                        mmd->sculptlvl= mmd->lvl;
10406
11550
        {
10407
11551
                Object *ob;
10408
11552
 
10409
 
                /* properly initialise hair clothsim data on old files */
10410
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
 
11553
                /* properly initialize hair clothsim data on old files */
 
11554
                for (ob = main->object.first; ob; ob = ob->id.next) {
10411
11555
                        ModifierData *md;
10412
 
                        for(md= ob->modifiers.first; md; md= md->next) {
 
11556
                        for (md= ob->modifiers.first; md; md= md->next) {
10413
11557
                                if (md->type == eModifierType_Cloth) {
10414
11558
                                        ClothModifierData *clmd = (ClothModifierData *)md;
10415
11559
                                        if (clmd->sim_parms->velocity_smooth < 0.01f)
10429
11573
 
10430
11574
 
10431
11575
                /* remove all preview window in wrong spaces */
10432
 
                for(screen= main->screen.first; screen; screen= screen->id.next) {
10433
 
                        for(sa= screen->areabase.first; sa; sa= sa->next) {
10434
 
                                for(sl= sa->spacedata.first; sl; sl= sl->next) {
10435
 
                                        if(sl->spacetype!=SPACE_SEQ) {
 
11576
                for (screen= main->screen.first; screen; screen= screen->id.next) {
 
11577
                        for (sa= screen->areabase.first; sa; sa= sa->next) {
 
11578
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
11579
                                        if (sl->spacetype!=SPACE_SEQ) {
10436
11580
                                                ARegion *ar;
10437
11581
                                                ListBase *regionbase;
10438
11582
 
10439
11583
                                                if (sl == sa->spacedata.first) {
10440
11584
                                                        regionbase = &sa->regionbase;
10441
 
                                                } else {
 
11585
                                                }
 
11586
                                                else {
10442
11587
                                                        regionbase = &sl->regionbase;
10443
11588
                                                }
10444
11589
 
10445
11590
 
10446
 
                                                for( ar = regionbase->first; ar; ar = ar->next) {
 
11591
                                                for ( ar = regionbase->first; ar; ar = ar->next) {
10447
11592
                                                        if (ar->regiontype == RGN_TYPE_PREVIEW)
10448
11593
                                                                break;
10449
11594
                                                }
10468
11613
                        SpaceLink *sl;
10469
11614
 
10470
11615
 
10471
 
                        for(screen= main->screen.first; screen; screen= screen->id.next) {
10472
 
                                for(sa= screen->areabase.first; sa; sa= sa->next) {
10473
 
                                        for(sl= sa->spacedata.first; sl; sl= sl->next) {
10474
 
                                                if(sl->spacetype==SPACE_SEQ) {
 
11616
                        for (screen= main->screen.first; screen; screen= screen->id.next) {
 
11617
                                for (sa= screen->areabase.first; sa; sa= sa->next) {
 
11618
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
11619
                                                if (sl->spacetype==SPACE_SEQ) {
10475
11620
                                                        ARegion *ar;
10476
11621
                                                        ARegion *ar_main;
10477
11622
                                                        ListBase *regionbase;
10479
11624
 
10480
11625
                                                        if (sl == sa->spacedata.first) {
10481
11626
                                                                regionbase = &sa->regionbase;
10482
 
                                                        } else {
 
11627
                                                        }
 
11628
                                                        else {
10483
11629
                                                                regionbase = &sl->regionbase;
10484
11630
                                                        }
10485
11631
 
10509
11655
                Material *ma;
10510
11656
                
10511
11657
                /* game engine changes */
10512
 
                for(sce = main->scene.first; sce; sce = sce->id.next) {
10513
 
                        sce->gm.eyeseparation = 0.10;
 
11658
                for (sce = main->scene.first; sce; sce = sce->id.next) {
 
11659
                        sce->gm.eyeseparation = 0.10f;
10514
11660
                }
10515
11661
                
10516
11662
                /* anim viz changes */
10517
11663
                for (ob= main->object.first; ob; ob= ob->id.next) {
10518
 
                        /* initialise object defaults */
 
11664
                        /* initialize object defaults */
10519
11665
                        animviz_settings_init(&ob->avs);
10520
11666
                        
10521
11667
                        /* if armature, copy settings for pose from armature data 
10522
 
                         * performing initialisation where appropriate 
 
11668
                         * performing initialization where appropriate
10523
11669
                         */
10524
11670
                        if (ob->pose && ob->data) {
10525
11671
                                bArmature *arm= newlibadr(fd, lib, ob->data);
10526
 
                                if(arm) { /* XXX - why does this fail in some cases? */
 
11672
                                if (arm) { /* XXX - why does this fail in some cases? */
10527
11673
                                        bAnimVizSettings *avs= &ob->pose->avs;
10528
11674
                                        
10529
11675
                                        /* ghosting settings ---------------- */
10604
11750
        
10605
11751
        if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 13)) {
10606
11752
                /* NOTE: if you do more conversion, be sure to do it outside of this and
10607
 
                   increase subversion again, otherwise it will not be correct */
 
11753
                 * increase subversion again, otherwise it will not be correct */
10608
11754
                Object *ob;
10609
11755
                
10610
11756
                /* convert degrees to radians for internal use */
10615
11761
 
10616
11762
                        if (ob->pose) {
10617
11763
                                for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
10618
 
                                        pchan->limitmin[0] *= M_PI/180.0;
10619
 
                                        pchan->limitmin[1] *= M_PI/180.0;
10620
 
                                        pchan->limitmin[2] *= M_PI/180.0;
10621
 
                                        pchan->limitmax[0] *= M_PI/180.0;
10622
 
                                        pchan->limitmax[1] *= M_PI/180.0;
10623
 
                                        pchan->limitmax[2] *= M_PI/180.0;
 
11764
                                        pchan->limitmin[0] *= (float)(M_PI/180.0);
 
11765
                                        pchan->limitmin[1] *= (float)(M_PI/180.0);
 
11766
                                        pchan->limitmin[2] *= (float)(M_PI/180.0);
 
11767
                                        pchan->limitmax[0] *= (float)(M_PI/180.0);
 
11768
                                        pchan->limitmax[1] *= (float)(M_PI/180.0);
 
11769
                                        pchan->limitmax[2] *= (float)(M_PI/180.0);
10624
11770
 
10625
11771
                                        do_version_constraints_radians_degrees_250(&pchan->constraints);
10626
11772
                                }
10648
11794
                                        if (ELEM(sl->spacetype, SPACE_ACTION, SPACE_NLA)) {
10649
11795
                                                for (ar = (ARegion*)regionbase->first; ar; ar = ar->next) {
10650
11796
                                                        if (ar->regiontype == RGN_TYPE_WINDOW) {
10651
 
                                                                ar->v2d.cur.ymax= ar->v2d.tot.ymax= 0.0f;
10652
 
                                                                ar->v2d.cur.ymin= ar->v2d.tot.ymin= (float)(-sa->winy) / 3.0f;
 
11797
                                                                ar->v2d.cur.ymax = ar->v2d.tot.ymax = 0.0f;
 
11798
                                                                ar->v2d.cur.ymin = ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
10653
11799
                                                        }
10654
11800
                                                }
10655
11801
                                        }
10663
11809
                Material *ma;
10664
11810
 
10665
11811
                /* ambient default from 0.5f to 1.0f */
10666
 
                for(ma= main->mat.first; ma; ma=ma->id.next)
 
11812
                for (ma= main->mat.first; ma; ma=ma->id.next)
10667
11813
                        ma->amb *= 2.0f;
10668
11814
 
10669
 
                for(wo= main->world.first; wo; wo=wo->id.next) {
 
11815
                for (wo= main->world.first; wo; wo=wo->id.next) {
10670
11816
                        /* ao splitting into ao/env/indirect */
10671
11817
                        wo->ao_env_energy= wo->aoenergy;
10672
11818
                        wo->aoenergy= 1.0f;
10673
11819
 
10674
 
                        if(wo->ao_indirect_bounces == 0)
 
11820
                        if (wo->ao_indirect_bounces == 0)
10675
11821
                                wo->ao_indirect_bounces= 1;
10676
11822
                        else
10677
11823
                                wo->mode |= WO_INDIRECT_LIGHT;
10678
11824
 
10679
 
                        if(wo->aomix == WO_AOSUB)
 
11825
                        if (wo->aomix == WO_AOSUB)
10680
11826
                                wo->ao_env_energy= -wo->ao_env_energy;
10681
 
                        else if(wo->aomix == WO_AOADDSUB)
 
11827
                        else if (wo->aomix == WO_AOADDSUB)
10682
11828
                                wo->mode |= WO_AMB_OCC;
10683
11829
 
10684
11830
                        wo->aomix= WO_AOMUL;
10695
11841
                Material *ma;
10696
11842
 
10697
11843
                /* initialize to sane default so toggling on border shows something */
10698
 
                for(sce = main->scene.first; sce; sce = sce->id.next) {
10699
 
                        if(sce->r.border.xmin == 0.0f && sce->r.border.ymin == 0.0f &&
 
11844
                for (sce = main->scene.first; sce; sce = sce->id.next) {
 
11845
                        if (sce->r.border.xmin == 0.0f && sce->r.border.ymin == 0.0f &&
10700
11846
                           sce->r.border.xmax == 0.0f && sce->r.border.ymax == 0.0f) {
10701
 
                                sce->r.border.xmin= 0.0f;
10702
 
                                sce->r.border.ymin= 0.0f;
10703
 
                                sce->r.border.xmax= 1.0f;
10704
 
                                sce->r.border.ymax= 1.0f;
 
11847
                                sce->r.border.xmin = 0.0f;
 
11848
                                sce->r.border.ymin = 0.0f;
 
11849
                                sce->r.border.xmax = 1.0f;
 
11850
                                sce->r.border.ymax = 1.0f;
10705
11851
                        }
10706
11852
 
10707
 
                        if((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0)
 
11853
                        if ((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0)
10708
11854
                                sce->r.ffcodecdata.audio_codec = 0x0; // CODEC_ID_NONE
10709
11855
 
10710
11856
                        SEQ_BEGIN(sce->ed, seq) {
10713
11859
                        SEQ_END
10714
11860
                }
10715
11861
 
10716
 
                for(ma = main->mat.first; ma; ma=ma->id.next)
10717
 
                        if(ma->mode & MA_TRACEBLE)
 
11862
                /* particle brush strength factor was changed from int to float */
 
11863
                for (sce= main->scene.first; sce; sce=sce->id.next) {
 
11864
                        ParticleEditSettings *pset= &sce->toolsettings->particle;
 
11865
                        int a;
 
11866
 
 
11867
                        for (a=0; a<PE_TOT_BRUSH; a++)
 
11868
                                pset->brush[a].strength /= 100.0f;
 
11869
                }
 
11870
 
 
11871
                for (ma = main->mat.first; ma; ma=ma->id.next)
 
11872
                        if (ma->mode & MA_TRACEBLE)
10718
11873
                                ma->shade_flag |= MA_APPROX_OCCLUSION;
10719
11874
 
10720
11875
                /* sequencer changes */
10723
11878
                        ScrArea *sa;
10724
11879
                        SpaceLink *sl;
10725
11880
 
10726
 
                        for(screen= main->screen.first; screen; screen= screen->id.next) {
10727
 
                                for(sa= screen->areabase.first; sa; sa= sa->next) {
10728
 
                                        for(sl= sa->spacedata.first; sl; sl= sl->next) {
10729
 
                                                if(sl->spacetype==SPACE_SEQ) {
 
11881
                        for (screen= main->screen.first; screen; screen= screen->id.next) {
 
11882
                                for (sa= screen->areabase.first; sa; sa= sa->next) {
 
11883
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
11884
                                                if (sl->spacetype==SPACE_SEQ) {
10730
11885
                                                        ARegion *ar_preview;
10731
11886
                                                        ListBase *regionbase;
10732
11887
 
10733
11888
                                                        if (sl == sa->spacedata.first) {
10734
11889
                                                                regionbase = &sa->regionbase;
10735
 
                                                        } else {
 
11890
                                                        }
 
11891
                                                        else {
10736
11892
                                                                regionbase = &sl->regionbase;
10737
11893
                                                        }
10738
11894
 
10758
11914
                 * This bit was used in the past for V3D_TRANSFORM_SNAP, which is now deprecated. 
10759
11915
                 * Here we clear it for old files so they don't come in with V3D_RENDER_OVERRIDE set,
10760
11916
                 * which would cause cameras, lamps, etc to become invisible */
10761
 
                for(sc= main->screen.first; sc; sc= sc->id.next) {
 
11917
                for (sc= main->screen.first; sc; sc= sc->id.next) {
10762
11918
                        ScrArea *sa;
10763
 
                        for(sa= sc->areabase.first; sa; sa= sa->next) {
 
11919
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
10764
11920
                                SpaceLink *sl;
10765
11921
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
10766
 
                                        if(sl->spacetype==SPACE_VIEW3D) {
 
11922
                                        if (sl->spacetype==SPACE_VIEW3D) {
10767
11923
                                                View3D* v3d = (View3D *)sl;
10768
11924
                                                v3d->flag2 &= ~V3D_RENDER_OVERRIDE;
10769
11925
                                        }
10782
11938
                        if (brush->curve) brush->curve->preset = CURVE_PRESET_SMOOTH;
10783
11939
                }
10784
11940
                
10785
 
                /* properly initialise active flag for fluidsim modifiers */
10786
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
 
11941
                /* properly initialize active flag for fluidsim modifiers */
 
11942
                for (ob = main->object.first; ob; ob = ob->id.next) {
10787
11943
                        ModifierData *md;
10788
 
                        for(md= ob->modifiers.first; md; md= md->next) {
 
11944
                        for (md= ob->modifiers.first; md; md= md->next) {
10789
11945
                                if (md->type == eModifierType_Fluidsim) {
10790
11946
                                        FluidsimModifierData *fmd = (FluidsimModifierData *)md;
10791
11947
                                        fmd->fss->flag |= OB_FLUIDSIM_ACTIVE; 
10795
11951
                }
10796
11952
                
10797
11953
                /* adjustment to color balance node values */
10798
 
                for(scene= main->scene.first; scene; scene= scene->id.next) {
10799
 
                        if(scene->nodetree) {
 
11954
                for (scene= main->scene.first; scene; scene= scene->id.next) {
 
11955
                        if (scene->nodetree) {
10800
11956
                                bNode *node=scene->nodetree->nodes.first;
10801
11957
                                
10802
 
                                while(node) {
 
11958
                                while (node) {
10803
11959
                                        if (node->type == CMP_NODE_COLORBALANCE) {
10804
11960
                                                NodeColorBalance *n= (NodeColorBalance *)node->storage;
10805
11961
                                                n->lift[0] += 1.f;
10814
11970
                for (ntree= main->nodetree.first; ntree; ntree=ntree->id.next) {
10815
11971
                        bNode *node=ntree->nodes.first;
10816
11972
                        
10817
 
                        while(node) {
 
11973
                        while (node) {
10818
11974
                                if (node->type == CMP_NODE_COLORBALANCE) {
10819
11975
                                        NodeColorBalance *n= (NodeColorBalance *)node->storage;
10820
11976
                                        n->lift[0] += 1.f;
10838
11994
                bScreen *sc;
10839
11995
                
10840
11996
                /* Image editor scopes */
10841
 
                for(sc= main->screen.first; sc; sc= sc->id.next) {
 
11997
                for (sc= main->screen.first; sc; sc= sc->id.next) {
10842
11998
                        ScrArea *sa;
10843
 
                        for(sa= sc->areabase.first; sa; sa= sa->next) {
 
11999
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
10844
12000
                                SpaceLink *sl;
10845
12001
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
10846
 
                                        if(sl->spacetype==SPACE_IMAGE) {
 
12002
                                        if (sl->spacetype==SPACE_IMAGE) {
10847
12003
                                                SpaceImage *sima = (SpaceImage *)sl;
10848
12004
                                                scopes_new(&sima->scopes);
10849
12005
                                        }
10896
12052
                                                /* enable all cache display */
10897
12053
                                                stime->cache_display |= TIME_CACHE_DISPLAY;
10898
12054
                                                stime->cache_display |= (TIME_CACHE_SOFTBODY|TIME_CACHE_PARTICLES);
10899
 
                                                stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE);
 
12055
                                                stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE|TIME_CACHE_DYNAMICPAINT);
10900
12056
                                        }
10901
12057
                                }
10902
12058
                        }
10903
12059
                }
10904
12060
 
10905
 
                do_version_mdef_250(fd, lib, main);
 
12061
                do_version_mdef_250(main);
10906
12062
 
10907
12063
                /* parent type to modifier */
10908
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
10909
 
                        if(ob->parent) {
 
12064
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
12065
                        if (ob->parent) {
10910
12066
                                Object *parent= (Object *)newlibadr(fd, lib, ob->parent);
10911
 
                                if(parent) { /* parent may not be in group */
10912
 
                                        if(parent->type==OB_ARMATURE && ob->partype==PARSKEL) {
 
12067
                                if (parent) { /* parent may not be in group */
 
12068
                                        if (parent->type==OB_ARMATURE && ob->partype==PARSKEL) {
10913
12069
                                                ArmatureModifierData *amd;
10914
12070
                                                bArmature *arm= (bArmature *)newlibadr(fd, lib, parent->data);
10915
12071
 
10919
12075
                                                amd->deformflag= arm->deformflag;
10920
12076
                                                ob->partype = PAROBJECT;
10921
12077
                                        }
10922
 
                                        else if(parent->type==OB_LATTICE && ob->partype==PARSKEL) {
 
12078
                                        else if (parent->type==OB_LATTICE && ob->partype==PARSKEL) {
10923
12079
                                                LatticeModifierData *lmd;
10924
12080
 
10925
12081
                                                lmd = (LatticeModifierData*) modifier_new(eModifierType_Lattice);
10927
12083
                                                BLI_addtail((ListBase*)&ob->modifiers, lmd);
10928
12084
                                                ob->partype = PAROBJECT;
10929
12085
                                        }
10930
 
                                        else if(parent->type==OB_CURVE && ob->partype==PARCURVE) {
 
12086
                                        else if (parent->type==OB_CURVE && ob->partype==PARCURVE) {
10931
12087
                                                CurveModifierData *cmd;
10932
12088
 
10933
12089
                                                cmd = (CurveModifierData*) modifier_new(eModifierType_Curve);
10939
12095
                        }
10940
12096
                }
10941
12097
                
10942
 
                /* initialise scene active layer */
 
12098
                /* initialize scene active layer */
10943
12099
                for (scene= main->scene.first; scene; scene=scene->id.next) {
10944
12100
                        int i;
10945
 
                        for(i=0; i<20; i++) {
10946
 
                                if(scene->lay & (1<<i)) {
 
12101
                        for (i=0; i<20; i++) {
 
12102
                                if (scene->lay & (1<<i)) {
10947
12103
                                        scene->layact= 1<<i;
10948
12104
                                        break;
10949
12105
                                }
10950
12106
                        }
10951
12107
                }
10952
12108
 
10953
 
                for(tex= main->tex.first; tex; tex= tex->id.next) {
 
12109
                for (tex= main->tex.first; tex; tex= tex->id.next) {
10954
12110
                        /* if youre picky, this isn't correct until we do a version bump
10955
12111
                         * since you could set saturation to be 0.0*/
10956
 
                        if(tex->saturation==0.0f)
 
12112
                        if (tex->saturation==0.0f)
10957
12113
                                tex->saturation= 1.0f;
10958
12114
                }
10959
12115
 
10960
12116
                {
10961
12117
                        Curve *cu;
10962
 
                        for(cu= main->curve.first; cu; cu= cu->id.next) {
 
12118
                        for (cu= main->curve.first; cu; cu= cu->id.next) {
10963
12119
                                cu->smallcaps_scale= 0.75f;
10964
12120
                        }
10965
12121
                }
10966
12122
 
10967
12123
                for (scene= main->scene.first; scene; scene=scene->id.next) {
10968
 
                        if(scene) {
 
12124
                        if (scene) {
10969
12125
                                Sequence *seq;
10970
12126
                                SEQ_BEGIN(scene->ed, seq) {
10971
 
                                        if(seq->sat==0.0f) {
 
12127
                                        if (seq->sat==0.0f) {
10972
12128
                                                seq->sat= 1.0f;
10973
12129
                                        }
10974
12130
                                }
10991
12147
 
10992
12148
                        // bad radius
10993
12149
                        if (brush->unprojected_radius == 0)
10994
 
                                brush->unprojected_radius = 0.125;
 
12150
                                brush->unprojected_radius = 0.125f;
10995
12151
 
10996
12152
                        // unusable size
10997
12153
                        if (brush->size == 0)
11033
12189
                                        brush->add_col[1] == 0 &&
11034
12190
                                        brush->add_col[2] == 0)
11035
12191
                                {
11036
 
                                        brush->add_col[0] = 1.00;
11037
 
                                        brush->add_col[1] = 0.39;
11038
 
                                        brush->add_col[2] = 0.39;
 
12192
                                        brush->add_col[0] = 1.00f;
 
12193
                                        brush->add_col[1] = 0.39f;
 
12194
                                        brush->add_col[2] = 0.39f;
11039
12195
                                }
11040
12196
 
11041
12197
                                if (brush->sub_col[0] == 0 &&
11042
12198
                                        brush->sub_col[1] == 0 &&
11043
12199
                                        brush->sub_col[2] == 0)
11044
12200
                                {
11045
 
                                        brush->sub_col[0] = 0.39;
11046
 
                                        brush->sub_col[1] = 0.39;
11047
 
                                        brush->sub_col[2] = 1.00;
11048
 
                                }
11049
 
                        }
11050
 
                }
11051
 
        }
11052
 
 
11053
 
        /* put compatibility code here until next subversion bump */
11054
 
        {
 
12201
                                        brush->sub_col[0] = 0.39f;
 
12202
                                        brush->sub_col[1] = 0.39f;
 
12203
                                        brush->sub_col[2] = 1.00f;
 
12204
                                }
 
12205
                        }
 
12206
                }
 
12207
        }
 
12208
 
 
12209
        /* GSOC Sculpt 2010 - Sanity check on Sculpt/Paint settings */
 
12210
        if (main->versionfile < 253) {
 
12211
                Scene *sce;
 
12212
                for (sce= main->scene.first; sce; sce= sce->id.next) {
 
12213
                        if (sce->toolsettings->sculpt_paint_unified_alpha == 0)
 
12214
                                sce->toolsettings->sculpt_paint_unified_alpha = 0.5f;
 
12215
 
 
12216
                        if (sce->toolsettings->sculpt_paint_unified_unprojected_radius == 0) 
 
12217
                                sce->toolsettings->sculpt_paint_unified_unprojected_radius = 0.125f;
 
12218
 
 
12219
                        if (sce->toolsettings->sculpt_paint_unified_size == 0)
 
12220
                                sce->toolsettings->sculpt_paint_unified_size = 35;
 
12221
                }
 
12222
        }
 
12223
 
 
12224
        if (main->versionfile < 253 || (main->versionfile == 253 && main->subversionfile < 1))
 
12225
                {
 
12226
                        Object *ob;
 
12227
 
 
12228
                        for (ob = main->object.first; ob; ob = ob->id.next) {
 
12229
                                ModifierData *md;
 
12230
                                for (md= ob->modifiers.first; md; md= md->next) {
 
12231
                                        if (md->type == eModifierType_Smoke) {
 
12232
                                                SmokeModifierData *smd = (SmokeModifierData *)md;
 
12233
 
 
12234
                                                if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
 
12235
                                                {
 
12236
                                                        smd->domain->vorticity = 2.0f;
 
12237
                                                        smd->domain->time_scale = 1.0f;
 
12238
 
 
12239
                                                        if (!(smd->domain->flags & (1<<4)))
 
12240
                                                                continue;
 
12241
 
 
12242
                                                        /* delete old MOD_SMOKE_INITVELOCITY flag */
 
12243
                                                        smd->domain->flags &= ~(1<<4);
 
12244
 
 
12245
                                                        /* for now just add it to all flow objects in the scene */
 
12246
                                                        {
 
12247
                                                                Object *ob2;
 
12248
                                                                for (ob2 = main->object.first; ob2; ob2 = ob2->id.next) {
 
12249
                                                                        ModifierData *md2;
 
12250
                                                                        for (md2= ob2->modifiers.first; md2; md2= md2->next) {
 
12251
                                                                                if (md2->type == eModifierType_Smoke) {
 
12252
                                                                                        SmokeModifierData *smd2 = (SmokeModifierData *)md2;
 
12253
 
 
12254
                                                                                        if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow)
 
12255
                                                                                        {
 
12256
                                                                                                smd2->flow->flags |= MOD_SMOKE_FLOW_INITVELOCITY;
 
12257
                                                                                        }
 
12258
                                                                                }
 
12259
                                                                        }
 
12260
                                                                }
 
12261
                                                        }
 
12262
 
 
12263
                                                }
 
12264
                                                else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
 
12265
                                                        smd->flow->vel_multi = 1.0f;
 
12266
                                                }
 
12267
 
 
12268
                                        }
 
12269
                                }
 
12270
                        }
 
12271
                }
 
12272
 
 
12273
        if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 1)) {
 
12274
                Brush *br;
 
12275
                ParticleSettings *part;
 
12276
                bScreen *sc;
 
12277
                Object *ob;
 
12278
 
 
12279
                for (br= main->brush.first; br; br= br->id.next) {
 
12280
                        if (br->ob_mode==0)
 
12281
                                br->ob_mode= OB_MODE_ALL_PAINT;
 
12282
                }
 
12283
 
 
12284
                for (part = main->particle.first; part; part = part->id.next) {
 
12285
                        if (part->boids)
 
12286
                                part->boids->pitch = 1.0f;
 
12287
 
 
12288
                        part->flag &= ~PART_HAIR_REGROW; /* this was a deprecated flag before */
 
12289
                        part->kink_amp_clump = 1.f; /* keep old files looking similar */
 
12290
                }
 
12291
 
 
12292
                for (sc= main->screen.first; sc; sc= sc->id.next) {
 
12293
                        ScrArea *sa;
 
12294
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
 
12295
                                SpaceLink *sl;
 
12296
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
12297
                                        if (sl->spacetype == SPACE_INFO) {
 
12298
                                                SpaceInfo *sinfo= (SpaceInfo *)sl;
 
12299
                                                ARegion *ar;
 
12300
 
 
12301
                                                sinfo->rpt_mask= INFO_RPT_OP;
 
12302
 
 
12303
                                                for (ar= sa->regionbase.first; ar; ar= ar->next) {
 
12304
                                                        if (ar->regiontype == RGN_TYPE_WINDOW) {
 
12305
                                                                ar->v2d.scroll = (V2D_SCROLL_RIGHT);
 
12306
                                                                ar->v2d.align = V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y; /* align bottom left */
 
12307
                                                                ar->v2d.keepofs = V2D_LOCKOFS_X;
 
12308
                                                                ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
 
12309
                                                                ar->v2d.keeptot= V2D_KEEPTOT_BOUNDS;
 
12310
                                                                ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
 
12311
                                                        }
 
12312
                                                }
 
12313
                                        }
 
12314
                                }
 
12315
                        }
 
12316
                }
 
12317
 
 
12318
                /* fix rotation actuators for objects so they use real angles (radians)
 
12319
                 * since before blender went opensource this strange scalar was used: (1 / 0.02) * 2 * math.pi/360 */
 
12320
                for (ob= main->object.first; ob; ob= ob->id.next) {
 
12321
                        bActuator *act= ob->actuators.first;
 
12322
                        while (act) {
 
12323
                                if (act->type==ACT_OBJECT) {
 
12324
                                        /* multiply velocity with 50 in old files */
 
12325
                                        bObjectActuator *oa= act->data;
 
12326
                                        mul_v3_fl(oa->drot, 0.8726646259971648f);
 
12327
                                }
 
12328
                                act= act->next;
 
12329
                        }
 
12330
                }
 
12331
        }
 
12332
        
 
12333
        // init facing axis property of steering actuators
 
12334
        {                                       
 
12335
                Object *ob;
 
12336
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
12337
                        bActuator *act;
 
12338
                        for (act= ob->actuators.first; act; act= act->next) {
 
12339
                                if (act->type==ACT_STEERING) {
 
12340
                                        bSteeringActuator* stact = act->data;
 
12341
                                        if (stact->facingaxis==0)
 
12342
                                        {
 
12343
                                                stact->facingaxis=1;
 
12344
                                        }                                               
 
12345
                                }
 
12346
                        }
 
12347
                }
 
12348
        }
 
12349
 
 
12350
        if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 3)) {
 
12351
                Object *ob;
 
12352
 
 
12353
                /* ocean res is now squared, reset old ones - will be massive */
 
12354
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
12355
                        ModifierData *md;
 
12356
                        for (md= ob->modifiers.first; md; md= md->next) {
 
12357
                                if (md->type == eModifierType_Ocean) {
 
12358
                                        OceanModifierData *omd = (OceanModifierData *)md;
 
12359
                                        omd->resolution = 7;
 
12360
                                        omd->oceancache = NULL;
 
12361
                                }
 
12362
                        }
 
12363
                }               
 
12364
        }
 
12365
 
 
12366
        if (main->versionfile < 256) {
 
12367
                bScreen *sc;
 
12368
                ScrArea *sa;
 
12369
                Key *key;
 
12370
                
 
12371
                /* Fix for sample line scope initializing with no height */
 
12372
                for (sc= main->screen.first; sc; sc= sc->id.next) {
 
12373
                        sa= sc->areabase.first;
 
12374
                        while (sa) {
 
12375
                                SpaceLink *sl;
 
12376
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
12377
                                        if (sl->spacetype==SPACE_IMAGE) {
 
12378
                                                SpaceImage *sima= (SpaceImage *)sl;
 
12379
                                                if (sima->sample_line_hist.height == 0 )
 
12380
                                                        sima->sample_line_hist.height = 100;
 
12381
                                        }
 
12382
                                }
 
12383
                                sa= sa->next;
 
12384
                        }
 
12385
                }
 
12386
                
 
12387
                /* old files could have been saved with slidermin = slidermax = 0.0, but the UI in
 
12388
                 * 2.4x would never reveal this to users as a dummy value always ended up getting used
 
12389
                 * instead
 
12390
                 */
 
12391
                for (key = main->key.first; key; key = key->id.next) {
 
12392
                        KeyBlock *kb;
 
12393
                        
 
12394
                        for (kb = key->block.first; kb; kb = kb->next) {
 
12395
                                if (IS_EQF(kb->slidermin, kb->slidermax) && IS_EQ(kb->slidermax, 0))
 
12396
                                        kb->slidermax = kb->slidermin + 1.0f;
 
12397
                        }
 
12398
                }
 
12399
        }
 
12400
        
 
12401
        if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 1)) {
 
12402
                /* fix for bones that didn't have arm_roll before */
 
12403
                bArmature* arm;
 
12404
                Bone* bone;
 
12405
                Object *ob;
 
12406
 
 
12407
                for (arm = main->armature.first; arm; arm = arm->id.next)
 
12408
                        for (bone = arm->bonebase.first; bone; bone = bone->next)
 
12409
                                do_version_bone_roll_256(bone);
 
12410
 
 
12411
                /* fix for objects which have zero dquat's
 
12412
                 * since this is multiplied with the quat rather than added */
 
12413
                for (ob= main->object.first; ob; ob= ob->id.next) {
 
12414
                        if (is_zero_v4(ob->dquat)) {
 
12415
                                unit_qt(ob->dquat);
 
12416
                        }
 
12417
                        if (is_zero_v3(ob->drotAxis) && ob->drotAngle == 0.0f) {
 
12418
                                unit_axis_angle(ob->drotAxis, &ob->drotAngle);
 
12419
                        }
 
12420
                }
 
12421
        }
 
12422
 
 
12423
        if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)) {
 
12424
                bNodeTree *ntree;
 
12425
                
 
12426
                /* node sockets are not exposed automatically any more,
 
12427
                 * this mimics the old behavior by adding all unlinked sockets to groups.
 
12428
                 */
 
12429
                for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
 
12430
                        /* XXX Only setting a flag here. Actual adding of group sockets
 
12431
                         * is done in lib_verify_nodetree, because at this point the internal
 
12432
                         * nodes may not be up-to-date! (missing lib-link)
 
12433
                         */
 
12434
                        ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE;
 
12435
                }
 
12436
        }
 
12437
 
 
12438
        if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile <3)) {
 
12439
                bScreen *sc;
 
12440
                Brush *brush;
 
12441
                Object *ob;
 
12442
                ParticleSettings *part;
 
12443
                Material *mat;
 
12444
                int tex_nr, transp_tex;
 
12445
                
 
12446
                for (mat = main->mat.first; mat; mat = mat->id.next) {
 
12447
                        if (!(mat->mode & MA_TRANSP) && !(mat->material_type & MA_TYPE_VOLUME)) {
 
12448
                                
 
12449
                                transp_tex= 0;
 
12450
                                
 
12451
                                for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
 
12452
                                        if (!mat->mtex[tex_nr]) continue;
 
12453
                                        if (mat->mtex[tex_nr]->mapto & MAP_ALPHA) transp_tex= 1;
 
12454
                                }
 
12455
 
 
12456
                                /* weak! material alpha could be animated */
 
12457
                                if (mat->alpha < 1.0f || mat->fresnel_tra > 0.0f || transp_tex) {
 
12458
                                        mat->mode |= MA_TRANSP;
 
12459
                                        mat->mode &= ~(MA_ZTRANSP|MA_RAYTRANSP);
 
12460
                                }
 
12461
                        }
 
12462
                }
 
12463
 
 
12464
                /* redraws flag in SpaceTime has been moved to Screen level */
 
12465
                for (sc = main->screen.first; sc; sc= sc->id.next) {
 
12466
                        if (sc->redraws_flag == 0) {
 
12467
                                /* just initialize to default? */
 
12468
                                // XXX: we could also have iterated through areas, and taken them from the first timeline available...
 
12469
                                sc->redraws_flag = TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
 
12470
                        }
 
12471
                }
 
12472
 
 
12473
                for (brush= main->brush.first; brush; brush= brush->id.next) {
 
12474
                        if (brush->height == 0)
 
12475
                                brush->height= 0.4f;
 
12476
                }
 
12477
 
 
12478
                /* replace 'rim material' option for in offset*/
 
12479
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
12480
                        ModifierData *md;
 
12481
                        for (md= ob->modifiers.first; md; md= md->next) {
 
12482
                                if (md->type == eModifierType_Solidify) {
 
12483
                                        SolidifyModifierData *smd = (SolidifyModifierData *)md;
 
12484
                                        if (smd->flag & MOD_SOLIDIFY_RIM_MATERIAL) {
 
12485
                                                smd->mat_ofs_rim= 1;
 
12486
                                                smd->flag &= ~MOD_SOLIDIFY_RIM_MATERIAL;
 
12487
                                        }
 
12488
                                }
 
12489
                        }
 
12490
                }
 
12491
 
 
12492
                /* particle draw color from material */
 
12493
                for (part = main->particle.first; part; part = part->id.next) {
 
12494
                        if (part->draw & PART_DRAW_MAT_COL)
 
12495
                                part->draw_col = PART_DRAW_COL_MAT;
 
12496
                }
 
12497
        }
 
12498
 
 
12499
        if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 6)) {
 
12500
                Mesh *me;
 
12501
 
 
12502
                for (me= main->mesh.first; me; me= me->id.next)
 
12503
                        mesh_calc_normals_tessface(me->mvert, me->totvert, me->mface, me->totface, NULL);
 
12504
        }
 
12505
 
 
12506
        if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)) {
 
12507
                /* update blur area sizes from 0..1 range to 0..100 percentage */
 
12508
                Scene *scene;
 
12509
                bNode *node;
 
12510
                for (scene=main->scene.first; scene; scene=scene->id.next)
 
12511
                        if (scene->nodetree)
 
12512
                                for (node=scene->nodetree->nodes.first; node; node=node->next)
 
12513
                                        if (node->type==CMP_NODE_BLUR) {
 
12514
                                                NodeBlurData *nbd= node->storage;
 
12515
                                                nbd->percentx *= 100.0f;
 
12516
                                                nbd->percenty *= 100.0f;
 
12517
                                        }
 
12518
        }
 
12519
 
 
12520
        if (main->versionfile < 258 || (main->versionfile == 258 && main->subversionfile < 1)) {
 
12521
                /* screen view2d settings were not properly initialized [#27164]
 
12522
                 * v2d->scroll caused the bug but best reset other values too which are in old blend files only.
 
12523
                 * need to make less ugly - possibly an iterator? */
 
12524
                bScreen *screen;
 
12525
                for (screen= main->screen.first; screen; screen= screen->id.next) {
 
12526
                        ScrArea *sa;
 
12527
                        /* add regions */
 
12528
                        for (sa= screen->areabase.first; sa; sa= sa->next) {
 
12529
                                SpaceLink *sl= sa->spacedata.first;
 
12530
                                if (sl->spacetype==SPACE_IMAGE) {
 
12531
                                        ARegion *ar;
 
12532
                                        for (ar=sa->regionbase.first; ar; ar= ar->next) {
 
12533
                                                if (ar->regiontype == RGN_TYPE_WINDOW) {
 
12534
                                                        View2D *v2d= &ar->v2d;
 
12535
                                                        v2d->minzoom= v2d->maxzoom= v2d->scroll= v2d->keeptot= v2d->keepzoom= v2d->keepofs= v2d->align= 0;
 
12536
                                                }
 
12537
                                        }
 
12538
                                }
 
12539
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
12540
                                        if (sl->spacetype==SPACE_IMAGE) {
 
12541
                                                ARegion *ar;
 
12542
                                                for (ar=sl->regionbase.first; ar; ar= ar->next) {
 
12543
                                                        if (ar->regiontype == RGN_TYPE_WINDOW) {
 
12544
                                                                View2D *v2d= &ar->v2d;
 
12545
                                                                v2d->minzoom= v2d->maxzoom= v2d->scroll= v2d->keeptot= v2d->keepzoom= v2d->keepofs= v2d->align= 0;
 
12546
                                                        }
 
12547
                                                }
 
12548
                                        }
 
12549
                                }
 
12550
                        }
 
12551
                }
 
12552
 
 
12553
                {
 
12554
                        /* Initialize texture point density curve falloff */
 
12555
                        Tex *tex;
 
12556
                        for (tex= main->tex.first; tex; tex= tex->id.next) {
 
12557
                                if (tex->pd) {
 
12558
                                        if (tex->pd->falloff_speed_scale == 0.0f)
 
12559
                                                tex->pd->falloff_speed_scale = 100.0f;
 
12560
                                        
 
12561
                                        if (!tex->pd->falloff_curve) {
 
12562
                                                tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
 
12563
                                                
 
12564
                                                tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
 
12565
                                                tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
 
12566
                                                curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
 
12567
                                                curvemapping_changed(tex->pd->falloff_curve, 0);
 
12568
                                        }
 
12569
                                }
 
12570
                        }
 
12571
                }
 
12572
 
 
12573
                {
 
12574
                        /* add default value for behind strength of camera actuator */
 
12575
                        Object *ob;
 
12576
                        bActuator *act;
 
12577
                        for (ob = main->object.first; ob; ob= ob->id.next) {
 
12578
                                for (act= ob->actuators.first; act; act= act->next) {
 
12579
                                        if (act->type == ACT_CAMERA) {
 
12580
                                                bCameraActuator *ba= act->data;
 
12581
 
 
12582
                                                ba->damping = 1.0/32.0;
 
12583
                                        }
 
12584
                                }
 
12585
                        }
 
12586
                }
 
12587
 
 
12588
                {
 
12589
                        ParticleSettings *part;
 
12590
                        for (part = main->particle.first; part; part = part->id.next) {
 
12591
                                /* Initialize particle billboard scale */
 
12592
                                part->bb_size[0] = part->bb_size[1] = 1.0f;
 
12593
                        }
 
12594
                }
 
12595
        }
 
12596
 
 
12597
        if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 1)) {
 
12598
                {
 
12599
                        Scene *scene;
 
12600
                        Sequence *seq;
 
12601
 
 
12602
                        for (scene=main->scene.first; scene; scene=scene->id.next)
 
12603
                        {
 
12604
                                scene->r.ffcodecdata.audio_channels = 2;
 
12605
                                scene->audio.volume = 1.0f;
 
12606
                                SEQ_BEGIN(scene->ed, seq) {
 
12607
                                        seq->pitch = 1.0f;
 
12608
                                }
 
12609
                                SEQ_END
 
12610
                        }
 
12611
                }
 
12612
                {
 
12613
                        bScreen *screen;
 
12614
                        for (screen= main->screen.first; screen; screen= screen->id.next) {
 
12615
                                ScrArea *sa;
 
12616
                                /* add regions */
 
12617
                                for (sa= screen->areabase.first; sa; sa= sa->next) {
 
12618
                                        SpaceLink *sl= sa->spacedata.first;
 
12619
                                        if (sl->spacetype==SPACE_SEQ) {
 
12620
                                                ARegion *ar;
 
12621
                                                for (ar=sa->regionbase.first; ar; ar= ar->next) {
 
12622
                                                        if (ar->regiontype == RGN_TYPE_WINDOW) {
 
12623
                                                                if (ar->v2d.min[1] == 4.0f)
 
12624
                                                                        ar->v2d.min[1]= 0.5f;
 
12625
                                                        }
 
12626
                                                }
 
12627
                                        }
 
12628
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
12629
                                                if (sl->spacetype==SPACE_SEQ) {
 
12630
                                                        ARegion *ar;
 
12631
                                                        for (ar=sl->regionbase.first; ar; ar= ar->next) {
 
12632
                                                                if (ar->regiontype == RGN_TYPE_WINDOW) {
 
12633
                                                                        if (ar->v2d.min[1] == 4.0f)
 
12634
                                                                                ar->v2d.min[1]= 0.5f;
 
12635
                                                                }
 
12636
                                                        }
 
12637
                                                }
 
12638
                                        }
 
12639
                                }
 
12640
                        }
 
12641
                }
 
12642
                {
 
12643
                        /* Make "auto-clamped" handles a per-keyframe setting instead of per-FCurve 
 
12644
                         *
 
12645
                         * We're only patching F-Curves in Actions here, since it is assumed that most
 
12646
                         * drivers out there won't be using this (and if they are, they're in the minority).
 
12647
                         * While we should aim to fix everything ideally, in practice it's far too hard
 
12648
                         * to get to every animdata block, not to mention the performance hit that'd have
 
12649
                         */
 
12650
                        bAction *act;
 
12651
                        FCurve *fcu;
 
12652
                        
 
12653
                        for (act = main->action.first; act; act = act->id.next) {
 
12654
                                for (fcu = act->curves.first; fcu; fcu = fcu->next) {
 
12655
                                        BezTriple *bezt;
 
12656
                                        unsigned int i = 0;
 
12657
                                        
 
12658
                                        /* only need to touch curves that had this flag set */
 
12659
                                        if ((fcu->flag & FCURVE_AUTO_HANDLES) == 0)
 
12660
                                                continue;
 
12661
                                        if ((fcu->totvert == 0) || (fcu->bezt == NULL))
 
12662
                                                continue;
 
12663
                                                
 
12664
                                        /* only change auto-handles to auto-clamped */
 
12665
                                        for (bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
 
12666
                                                if (bezt->h1 == HD_AUTO) bezt->h1 = HD_AUTO_ANIM;
 
12667
                                                if (bezt->h2 == HD_AUTO) bezt->h2 = HD_AUTO_ANIM;
 
12668
                                        }
 
12669
                                        
 
12670
                                        fcu->flag &= ~FCURVE_AUTO_HANDLES;
 
12671
                                }
 
12672
                        }
 
12673
                }
 
12674
                {
 
12675
                        /* convert fcurve and shape action actuators to action actuators */
 
12676
                        Object *ob;
 
12677
                        bActuator *act;
 
12678
                        bIpoActuator *ia;
 
12679
                        bActionActuator *aa;
 
12680
 
 
12681
                        for (ob= main->object.first; ob; ob= ob->id.next) {
 
12682
                                for (act= ob->actuators.first; act; act= act->next) {
 
12683
                                        if (act->type == ACT_IPO) {
 
12684
                                                // Create the new actuator
 
12685
                                                ia= act->data;
 
12686
                                                aa= MEM_callocN(sizeof(bActionActuator), "fcurve -> action actuator do_version");
 
12687
 
 
12688
                                                // Copy values
 
12689
                                                aa->type = ia->type;
 
12690
                                                aa->flag = ia->flag;
 
12691
                                                aa->sta = ia->sta;
 
12692
                                                aa->end = ia->end;
 
12693
                                                BLI_strncpy(aa->name, ia->name, sizeof(aa->name));
 
12694
                                                BLI_strncpy(aa->frameProp, ia->frameProp, sizeof(aa->frameProp));
 
12695
                                                if (ob->adt)
 
12696
                                                        aa->act = ob->adt->action;
 
12697
 
 
12698
                                                // Get rid of the old actuator
 
12699
                                                MEM_freeN(ia);
 
12700
 
 
12701
                                                // Assign the new actuator
 
12702
                                                act->data = aa;
 
12703
                                                act->type= act->otype= ACT_ACTION;
 
12704
                                                
 
12705
                                        }
 
12706
                                        else if (act->type == ACT_SHAPEACTION) {
 
12707
                                                act->type = act->otype = ACT_ACTION;
 
12708
                                        }
 
12709
                                }
 
12710
                        }
 
12711
                }
 
12712
        }
 
12713
 
 
12714
        if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)) {
 
12715
                {
 
12716
                        /* Convert default socket values from bNodeStack */
 
12717
                        Scene *sce;
 
12718
                        Material *mat;
 
12719
                        Tex *tex;
 
12720
                        bNodeTree *ntree;
 
12721
                        for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
 
12722
                                do_versions_nodetree_default_value(ntree);
 
12723
                                ntree->update |= NTREE_UPDATE;
 
12724
                        }
 
12725
                        for (sce=main->scene.first; sce; sce=sce->id.next)
 
12726
                                if (sce->nodetree) {
 
12727
                                do_versions_nodetree_default_value(sce->nodetree);
 
12728
                                sce->nodetree->update |= NTREE_UPDATE;
 
12729
                        }
 
12730
                        for (mat=main->mat.first; mat; mat=mat->id.next)
 
12731
                                if (mat->nodetree) {
 
12732
                                do_versions_nodetree_default_value(mat->nodetree);
 
12733
                                mat->nodetree->update |= NTREE_UPDATE;
 
12734
                        }
 
12735
                        for (tex=main->tex.first; tex; tex=tex->id.next)
 
12736
                                if (tex->nodetree) {
 
12737
                                do_versions_nodetree_default_value(tex->nodetree);
 
12738
                                tex->nodetree->update |= NTREE_UPDATE;
 
12739
                        }
 
12740
                }
 
12741
 
 
12742
                /* add SOCK_DYNAMIC flag to existing group sockets */
 
12743
                {
 
12744
                        bNodeTree *ntree;
 
12745
                        /* only need to do this for trees in main, local trees are not used as groups */
 
12746
                        for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
 
12747
                                do_versions_nodetree_dynamic_sockets(ntree);
 
12748
                                ntree->update |= NTREE_UPDATE;
 
12749
                        }
 
12750
                }
 
12751
 
 
12752
                {
 
12753
                        /* Initialize group tree nodetypes.
 
12754
                         * These are used to distinguish tree types and
 
12755
                         * associate them with specific node types for polling.
 
12756
                         */
 
12757
                        bNodeTree *ntree;
 
12758
                        /* all node trees in main->nodetree are considered groups */
 
12759
                        for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
 
12760
                                ntree->nodetype = NODE_GROUP;
 
12761
                }
 
12762
        }
 
12763
 
 
12764
        if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 4)) {
 
12765
                {
 
12766
                        /* Adaptive time step for particle systems */
 
12767
                        ParticleSettings *part;
 
12768
                        for (part = main->particle.first; part; part = part->id.next) {
 
12769
                                part->courant_target = 0.2f;
 
12770
                                part->time_flag &= ~PART_TIME_AUTOSF;
 
12771
                        }
 
12772
                }
 
12773
 
 
12774
                {
 
12775
                        /* set defaults for obstacle avoidance, recast data */
 
12776
                        Scene *sce;
 
12777
                        for (sce = main->scene.first; sce; sce = sce->id.next)
 
12778
                        {
 
12779
                                if (sce->gm.levelHeight == 0.f)
 
12780
                                        sce->gm.levelHeight = 2.f;
 
12781
 
 
12782
                                if (sce->gm.recastData.cellsize == 0.0f)
 
12783
                                        sce->gm.recastData.cellsize = 0.3f;
 
12784
                                if (sce->gm.recastData.cellheight == 0.0f)
 
12785
                                        sce->gm.recastData.cellheight = 0.2f;
 
12786
                                if (sce->gm.recastData.agentmaxslope == 0.0f)
 
12787
                                        sce->gm.recastData.agentmaxslope = (float)M_PI/4;
 
12788
                                if (sce->gm.recastData.agentmaxclimb == 0.0f)
 
12789
                                        sce->gm.recastData.agentmaxclimb = 0.9f;
 
12790
                                if (sce->gm.recastData.agentheight == 0.0f)
 
12791
                                        sce->gm.recastData.agentheight = 2.0f;
 
12792
                                if (sce->gm.recastData.agentradius == 0.0f)
 
12793
                                        sce->gm.recastData.agentradius = 0.6f;
 
12794
                                if (sce->gm.recastData.edgemaxlen == 0.0f)
 
12795
                                        sce->gm.recastData.edgemaxlen = 12.0f;
 
12796
                                if (sce->gm.recastData.edgemaxerror == 0.0f)
 
12797
                                        sce->gm.recastData.edgemaxerror = 1.3f;
 
12798
                                if (sce->gm.recastData.regionminsize == 0.0f)
 
12799
                                        sce->gm.recastData.regionminsize = 8.f;
 
12800
                                if (sce->gm.recastData.regionmergesize == 0.0f)
 
12801
                                        sce->gm.recastData.regionmergesize = 20.f;
 
12802
                                if (sce->gm.recastData.vertsperpoly<3)
 
12803
                                        sce->gm.recastData.vertsperpoly = 6;
 
12804
                                if (sce->gm.recastData.detailsampledist == 0.0f)
 
12805
                                        sce->gm.recastData.detailsampledist = 6.0f;
 
12806
                                if (sce->gm.recastData.detailsamplemaxerror == 0.0f)
 
12807
                                        sce->gm.recastData.detailsamplemaxerror = 1.0f;
 
12808
                        }
 
12809
                }
 
12810
        }
 
12811
 
 
12812
        if (main->versionfile < 260) {
 
12813
                {
 
12814
                        /* set default alpha value of Image outputs in image and render layer nodes to 0 */
 
12815
                        Scene *sce;
 
12816
                        bNodeTree *ntree;
 
12817
                        
 
12818
                        for (sce=main->scene.first; sce; sce=sce->id.next) {
 
12819
                                /* there are files with invalid audio_channels value, the real cause
 
12820
                                 * is unknown, but we fix it here anyway to avoid crashes */
 
12821
                                if (sce->r.ffcodecdata.audio_channels == 0)
 
12822
                                        sce->r.ffcodecdata.audio_channels = 2;
 
12823
 
 
12824
                                if (sce->nodetree)
 
12825
                                        do_versions_nodetree_image_default_alpha_output(sce->nodetree);
 
12826
                        }
 
12827
 
 
12828
                        for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
 
12829
                                do_versions_nodetree_image_default_alpha_output(ntree);
 
12830
                }
 
12831
 
 
12832
                {
 
12833
                        /* support old particle dupliobject rotation settings */
 
12834
                        ParticleSettings *part;
 
12835
 
 
12836
                        for (part=main->particle.first; part; part=part->id.next) {
 
12837
                                if (ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
 
12838
                                        part->draw |= PART_DRAW_ROTATE_OB;
 
12839
 
 
12840
                                        if (part->rotmode == 0)
 
12841
                                                part->rotmode = PART_ROT_VEL;
 
12842
                                }
 
12843
                        }
 
12844
                }
 
12845
        }
 
12846
 
 
12847
        if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 1)) {
 
12848
                Object *ob;
 
12849
 
 
12850
                for (ob= main->object.first; ob; ob= ob->id.next) {
 
12851
                        ob->collision_boundtype= ob->boundtype;
 
12852
                }
 
12853
 
 
12854
                {
 
12855
                        Camera *cam;
 
12856
                        for (cam= main->camera.first; cam; cam= cam->id.next) {
 
12857
                                if (cam->sensor_x < 0.01f)
 
12858
                                        cam->sensor_x = DEFAULT_SENSOR_WIDTH;
 
12859
 
 
12860
                                if (cam->sensor_y < 0.01f)
 
12861
                                        cam->sensor_y = DEFAULT_SENSOR_HEIGHT;
 
12862
                        }
 
12863
                }
 
12864
        }
 
12865
 
 
12866
        if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 2)) {
 
12867
                bNodeTreeType *ntreetype= ntreeGetType(NTREE_SHADER);
 
12868
 
 
12869
                if (ntreetype && ntreetype->foreach_nodetree)
 
12870
                        ntreetype->foreach_nodetree(main, NULL, do_version_ntree_tex_mapping_260);
 
12871
        }
 
12872
 
 
12873
        if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 4)) {
 
12874
                {
 
12875
                        /* Convert node angles to radians! */
 
12876
                        Scene *sce;
 
12877
                        Material *mat;
 
12878
                        bNodeTree *ntree;
 
12879
 
 
12880
                        for (sce=main->scene.first; sce; sce=sce->id.next) {
 
12881
                                if (sce->nodetree)
 
12882
                                        do_versions_nodetree_convert_angle(sce->nodetree);
 
12883
                        }
 
12884
 
 
12885
                        for (mat=main->mat.first; mat; mat=mat->id.next) {
 
12886
                                if (mat->nodetree)
 
12887
                                        do_versions_nodetree_convert_angle(mat->nodetree);
 
12888
                        }
 
12889
 
 
12890
                        for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
 
12891
                                do_versions_nodetree_convert_angle(ntree);
 
12892
                }
 
12893
 
 
12894
                {
 
12895
                        /* Tomato compatibility code. */
 
12896
                        bScreen *sc;
 
12897
                        MovieClip *clip;
 
12898
 
 
12899
                        for (sc= main->screen.first; sc; sc= sc->id.next) {
 
12900
                                ScrArea *sa;
 
12901
                                for (sa= sc->areabase.first; sa; sa= sa->next) {
 
12902
                                        SpaceLink *sl;
 
12903
                                        for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
12904
                                                if (sl->spacetype==SPACE_VIEW3D) {
 
12905
                                                        View3D *v3d= (View3D *)sl;
 
12906
                                                        if (v3d->bundle_size==0.0f) {
 
12907
                                                                v3d->bundle_size= 0.2f;
 
12908
                                                                v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
 
12909
                                                        }
 
12910
                                                        else if (sl->spacetype==SPACE_CLIP) {
 
12911
                                                                SpaceClip *sc= (SpaceClip *)sl;
 
12912
                                                                if (sc->scopes.track_preview_height==0)
 
12913
                                                                        sc->scopes.track_preview_height= 120;
 
12914
                                                        }
 
12915
 
 
12916
                                                        if (v3d->bundle_drawtype==0)
 
12917
                                                                v3d->bundle_drawtype= OB_PLAINAXES;
 
12918
                                                }
 
12919
                                        }
 
12920
                                }
 
12921
                        }
 
12922
 
 
12923
                        for (clip= main->movieclip.first; clip; clip= clip->id.next) {
 
12924
                                MovieTrackingTrack *track;
 
12925
 
 
12926
                                if (clip->aspx<1.0f) {
 
12927
                                        clip->aspx= 1.0f;
 
12928
                                        clip->aspy= 1.0f;
 
12929
                                }
 
12930
 
 
12931
                                clip->proxy.build_tc_flag= IMB_TC_RECORD_RUN |
 
12932
                                                           IMB_TC_FREE_RUN |
 
12933
                                                           IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN;
 
12934
 
 
12935
                                if (clip->proxy.build_size_flag==0)
 
12936
                                        clip->proxy.build_size_flag= IMB_PROXY_25;
 
12937
 
 
12938
                                if (clip->proxy.quality==0)
 
12939
                                        clip->proxy.quality= 90;
 
12940
 
 
12941
                                if (clip->tracking.camera.pixel_aspect<0.01f)
 
12942
                                        clip->tracking.camera.pixel_aspect= 1.f;
 
12943
 
 
12944
                                track= clip->tracking.tracks.first;
 
12945
                                while (track) {
 
12946
                                        if (track->pyramid_levels==0)
 
12947
                                                track->pyramid_levels= 2;
 
12948
 
 
12949
                                        if (track->minimum_correlation==0.0f)
 
12950
                                                track->minimum_correlation= 0.75f;
 
12951
 
 
12952
                                        track= track->next;
 
12953
                                }
 
12954
                        }
 
12955
                }
 
12956
        }
 
12957
 
 
12958
        if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 6))
 
12959
        {
 
12960
                Scene *sce;
 
12961
                MovieClip *clip;
 
12962
                bScreen *sc;
 
12963
 
 
12964
                for (sce = main->scene.first; sce; sce = sce->id.next) {
 
12965
                        do_versions_image_settings_2_60(sce);
 
12966
                }
 
12967
 
 
12968
                for (clip= main->movieclip.first; clip; clip= clip->id.next) {
 
12969
                        MovieTrackingSettings *settings= &clip->tracking.settings;
 
12970
 
 
12971
                        if (settings->default_pyramid_levels==0) {
 
12972
                                settings->default_tracker= TRACKER_KLT;
 
12973
                                settings->default_pyramid_levels= 2;
 
12974
                                settings->default_minimum_correlation= 0.75;
 
12975
                                settings->default_pattern_size= 11;
 
12976
                                settings->default_search_size= 51;
 
12977
                        }
 
12978
                }
 
12979
 
 
12980
                for (sc= main->screen.first; sc; sc= sc->id.next) {
 
12981
                        ScrArea *sa;
 
12982
                        for (sa= sc->areabase.first; sa; sa= sa->next) {
 
12983
                                SpaceLink *sl;
 
12984
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
 
12985
                                        if (sl->spacetype==SPACE_VIEW3D) {
 
12986
                                                View3D *v3d= (View3D *)sl;
 
12987
                                                v3d->flag2&= ~V3D_RENDER_SHADOW;
 
12988
                                        }
 
12989
                                }
 
12990
                        }
 
12991
                }
 
12992
 
 
12993
                {
 
12994
                        Object *ob;
 
12995
                        for (ob= main->object.first; ob; ob= ob->id.next) {
 
12996
                                /* convert delta addition into delta scale */
 
12997
                                int i;
 
12998
                                for (i= 0; i < 3; i++) {
 
12999
                                        if ( (ob->dsize[i] == 0.0f) || /* simple case, user never touched dsize */
 
13000
                                             (ob->size[i]  == 0.0f))   /* cant scale the dsize to give a non zero result, so fallback to 1.0f */
 
13001
                                        {
 
13002
                                                ob->dscale[i]= 1.0f;
 
13003
                                        }
 
13004
                                        else {
 
13005
                                                ob->dscale[i]= (ob->size[i] + ob->dsize[i]) / ob->size[i];
 
13006
                                        }
 
13007
                                }
 
13008
                        }
 
13009
                }
 
13010
        }
 
13011
        /* sigh, this dscale vs dsize version patching was not done right, fix for fix,
 
13012
         * this intentionally checks an exact subversion, also note this was never in a release,
 
13013
         * at some point this could be removed. */
 
13014
        else if (main->versionfile == 260 && main->subversionfile == 6) {
 
13015
                Object *ob;
 
13016
                for (ob = main->object.first; ob; ob= ob->id.next) {
 
13017
                        if (is_zero_v3(ob->dscale)) {
 
13018
                                fill_vn_fl(ob->dscale, 3, 1.0f);
 
13019
                        }
 
13020
                }
 
13021
        }
 
13022
 
 
13023
        if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 8))
 
13024
        {
 
13025
                Brush *brush;
 
13026
 
 
13027
                for (brush= main->brush.first; brush; brush= brush->id.next) {
 
13028
                        if (brush->sculpt_tool == SCULPT_TOOL_ROTATE)
 
13029
                                brush->alpha= 1.0f;
 
13030
                }
 
13031
        }
 
13032
 
 
13033
        if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 1))
 
13034
        {
 
13035
                {
 
13036
                        /* update use flags for node sockets (was only temporary before) */
 
13037
                        Scene *sce;
 
13038
                        Material *mat;
 
13039
                        Tex *tex;
 
13040
                        Lamp *lamp;
 
13041
                        World *world;
 
13042
                        bNodeTree *ntree;
 
13043
 
 
13044
                        for (sce=main->scene.first; sce; sce=sce->id.next)
 
13045
                                if (sce->nodetree)
 
13046
                                        do_versions_nodetree_socket_use_flags_2_62(sce->nodetree);
 
13047
 
 
13048
                        for (mat=main->mat.first; mat; mat=mat->id.next)
 
13049
                                if (mat->nodetree)
 
13050
                                        do_versions_nodetree_socket_use_flags_2_62(mat->nodetree);
 
13051
 
 
13052
                        for (tex=main->tex.first; tex; tex=tex->id.next)
 
13053
                                if (tex->nodetree)
 
13054
                                        do_versions_nodetree_socket_use_flags_2_62(tex->nodetree);
 
13055
 
 
13056
                        for (lamp=main->lamp.first; lamp; lamp=lamp->id.next)
 
13057
                                if (lamp->nodetree)
 
13058
                                        do_versions_nodetree_socket_use_flags_2_62(lamp->nodetree);
 
13059
 
 
13060
                        for (world=main->world.first; world; world=world->id.next)
 
13061
                                if (world->nodetree)
 
13062
                                        do_versions_nodetree_socket_use_flags_2_62(world->nodetree);
 
13063
 
 
13064
                        for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
 
13065
                                do_versions_nodetree_socket_use_flags_2_62(ntree);
 
13066
                }
 
13067
                {
 
13068
                        /* Initialize BGE exit key to esc key */
 
13069
                        Scene *scene;
 
13070
                        for (scene= main->scene.first; scene; scene= scene->id.next) {
 
13071
                                if (!scene->gm.exitkey)
 
13072
                                        scene->gm.exitkey = 218; // Blender key code for ESC
 
13073
                        }
 
13074
                }
 
13075
                {
 
13076
                        MovieClip *clip;
 
13077
                        Object *ob;
 
13078
 
 
13079
                        for (clip= main->movieclip.first; clip; clip= clip->id.next) {
 
13080
                                MovieTracking *tracking= &clip->tracking;
 
13081
                                MovieTrackingObject *tracking_object= tracking->objects.first;
 
13082
 
 
13083
                                clip->proxy.build_tc_flag|= IMB_TC_RECORD_RUN_NO_GAPS;
 
13084
 
 
13085
                                if (!tracking->settings.object_distance)
 
13086
                                        tracking->settings.object_distance= 1.0f;
 
13087
 
 
13088
                                if (tracking->objects.first == NULL)
 
13089
                                        BKE_tracking_new_object(tracking, "Camera");
 
13090
 
 
13091
                                while (tracking_object) {
 
13092
                                        if (!tracking_object->scale)
 
13093
                                                tracking_object->scale= 1.0f;
 
13094
 
 
13095
                                        tracking_object= tracking_object->next;
 
13096
                                }
 
13097
                        }
 
13098
 
 
13099
                        for (ob= main->object.first; ob; ob= ob->id.next) {
 
13100
                                bConstraint *con;
 
13101
                                for (con= ob->constraints.first; con; con=con->next) {
 
13102
                                        bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 
13103
 
 
13104
                                        if (!cti)
 
13105
                                                continue;
 
13106
 
 
13107
                                        if (cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) {
 
13108
                                                bObjectSolverConstraint *data= (bObjectSolverConstraint *)con->data;
 
13109
 
 
13110
                                                if (data->invmat[3][3]==0.0f)
 
13111
                                                        unit_m4(data->invmat);
 
13112
                                        }
 
13113
                                }
 
13114
                        }
 
13115
                }
 
13116
                {
 
13117
                /* Warn the user if he is using ["Text"] properties for Font objects */
 
13118
                        Object *ob;
 
13119
                        bProperty *prop;
 
13120
 
 
13121
                        for (ob= main->object.first; ob; ob= ob->id.next) {
 
13122
                                if (ob->type == OB_FONT) {
 
13123
                                        prop = get_ob_property(ob, "Text");
 
13124
                                        if (prop) {
 
13125
                                                BKE_reportf_wrap(fd->reports, RPT_WARNING,
 
13126
                                                                 "Game property name conflict in object: \"%s\".\nText objects reserve the "
 
13127
                                                                 "[\"Text\"] game property to change their content through Logic Bricks.\n",
 
13128
                                                                 ob->id.name+2);
 
13129
                                        }
 
13130
                                }
 
13131
                        }
 
13132
                }
 
13133
        }
 
13134
 
 
13135
        if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 2))
 
13136
        {
 
13137
                {
 
13138
                        /* convert Camera Actuator values to defines */
 
13139
                        Object *ob;
 
13140
                        bActuator *act;
 
13141
                        for (ob = main->object.first; ob; ob= ob->id.next) {
 
13142
                                for (act= ob->actuators.first; act; act= act->next) {
 
13143
                                        if (act->type == ACT_CAMERA) {
 
13144
                                                bCameraActuator *ba= act->data;
 
13145
 
 
13146
                                                if (ba->axis==(float) 'x') ba->axis=OB_POSX;
 
13147
                                                else if (ba->axis==(float)'y') ba->axis=OB_POSY;
 
13148
                                                /* don't do an if/else to avoid imediate subversion bump*/
 
13149
//                                      ba->axis=((ba->axis == (float) 'x')?OB_POSX_X:OB_POSY);
 
13150
                                        }
 
13151
                                }
 
13152
                        }
 
13153
                }
 
13154
 
 
13155
                {
 
13156
                        /* convert deprecated sculpt_paint_unified_* fields to
 
13157
                         * UnifiedPaintSettings */
 
13158
                        Scene *scene;
 
13159
                        for (scene= main->scene.first; scene; scene= scene->id.next) {
 
13160
                                ToolSettings *ts= scene->toolsettings;
 
13161
                                UnifiedPaintSettings *ups= &ts->unified_paint_settings;
 
13162
                                ups->size= ts->sculpt_paint_unified_size;
 
13163
                                ups->unprojected_radius= ts->sculpt_paint_unified_unprojected_radius;
 
13164
                                ups->alpha= ts->sculpt_paint_unified_alpha;
 
13165
                                ups->flag= ts->sculpt_paint_settings;
 
13166
                        }
 
13167
                }
 
13168
        }
 
13169
 
 
13170
        if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 3))
 
13171
        {
 
13172
                {
 
13173
                        /* convert extended ascii to utf-8 for text editor */
 
13174
                        Text *text;
 
13175
                        for (text= main->text.first; text; text= text->id.next)
 
13176
                                if (!(text->flags & TXT_ISEXT)) {
 
13177
                                        TextLine *tl;
 
13178
                                        
 
13179
                                        for (tl= text->lines.first; tl; tl= tl->next) {
 
13180
                                                int added= txt_extended_ascii_as_utf8(&tl->line);
 
13181
                                                tl->len+= added;
 
13182
                                                
 
13183
                                                /* reset cursor position if line was changed */
 
13184
                                                if (added && tl == text->curl)
 
13185
                                                        text->curc = 0;
 
13186
                                        }
 
13187
                                }
 
13188
                }
 
13189
                {
 
13190
                        /* set new dynamic paint values */
 
13191
                        Object *ob;
 
13192
                        for (ob = main->object.first; ob; ob = ob->id.next) {
 
13193
                                ModifierData *md;
 
13194
                                for (md= ob->modifiers.first; md; md= md->next) {
 
13195
                                        if (md->type == eModifierType_DynamicPaint) {
 
13196
                                                DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
 
13197
                                                if (pmd->canvas)
 
13198
                                                {
 
13199
                                                        DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
 
13200
                                                        for (; surface; surface=surface->next) {
 
13201
                                                                surface->color_dry_threshold = 1.0f;
 
13202
                                                                surface->influence_scale = 1.0f;
 
13203
                                                                surface->radius_scale = 1.0f;
 
13204
                                                                surface->flags |= MOD_DPAINT_USE_DRYING;
 
13205
                                                        }
 
13206
                                                }
 
13207
                                        }
 
13208
                                }
 
13209
                        }
 
13210
                }
 
13211
        }
 
13212
        
 
13213
        if (main->versionfile < 262)
 
13214
        {
 
13215
                Object *ob;
 
13216
                for (ob=main->object.first; ob; ob= ob->id.next) {
 
13217
                        ModifierData *md;
 
13218
 
 
13219
                        for (md=ob->modifiers.first; md; md=md->next) {
 
13220
                                if (md->type==eModifierType_Cloth) {
 
13221
                                        ClothModifierData *clmd = (ClothModifierData*) md;
 
13222
                                        if (clmd->sim_parms)
 
13223
                                                clmd->sim_parms->vel_damping = 1.0f;
 
13224
                                }
 
13225
                        }
 
13226
                }
 
13227
        }
 
13228
 
 
13229
        if (main->versionfile < 263)
 
13230
        {
 
13231
                /* set fluidsim rate. the version patch for this in 2.62 was wrong, so
 
13232
                 * try to correct it, if rate is 0.0 that's likely not intentional */
 
13233
                Object *ob;
 
13234
 
 
13235
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
13236
                        ModifierData *md;
 
13237
                        for (md = ob->modifiers.first; md; md = md->next) {
 
13238
                                if (md->type == eModifierType_Fluidsim) {
 
13239
                                        FluidsimModifierData *fmd = (FluidsimModifierData *)md;
 
13240
                                        if (fmd->fss->animRate == 0.0f)
 
13241
                                                fmd->fss->animRate = 1.0f;
 
13242
                                }
 
13243
                        }
 
13244
                }
 
13245
        }
 
13246
 
 
13247
        if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 1))
 
13248
        {
 
13249
                /* update use flags for node sockets (was only temporary before) */
 
13250
                Scene *sce;
 
13251
                bNodeTree *ntree;
 
13252
                
 
13253
                for (sce=main->scene.first; sce; sce=sce->id.next)
 
13254
                        if (sce->nodetree)
 
13255
                                do_versions_nodetree_multi_file_output_format_2_62_1(sce, sce->nodetree);
 
13256
                
 
13257
                /* XXX can't associate with scene for group nodes, image format will stay uninitialized */
 
13258
                for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
 
13259
                        do_versions_nodetree_multi_file_output_format_2_62_1(NULL, ntree);
 
13260
        }
 
13261
 
 
13262
        /* only swap for pre-release bmesh merge which had MLoopCol red/blue swap */
 
13263
        if (main->versionfile == 262 && main->subversionfile == 1)
 
13264
        {
 
13265
                {
 
13266
                        Mesh *me;
 
13267
                        for (me = main->mesh.first; me; me = me->id.next) {
 
13268
                                do_versions_mesh_mloopcol_swap_2_62_1(me);
 
13269
                        }
 
13270
                }
 
13271
 
 
13272
        }
 
13273
 
 
13274
        if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 2))
 
13275
        {
 
13276
                {
 
13277
                        /* Set new idname of keyingsets from their now "label-only" name. */
 
13278
                        Scene *scene;
 
13279
                        for (scene = main->scene.first; scene; scene = scene->id.next) {
 
13280
                                KeyingSet *ks;
 
13281
                                for (ks = scene->keyingsets.first; ks; ks = ks->next) {
 
13282
                                        if (!ks->idname[0])
 
13283
                                                BLI_strncpy(ks->idname, ks->name, sizeof(ks->idname));
 
13284
                                }
 
13285
                        }
 
13286
                }
 
13287
        }
 
13288
        
 
13289
        if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 3))
 
13290
        {
 
13291
                Object *ob;
 
13292
                ModifierData *md;
 
13293
        
 
13294
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
13295
                        for (md=ob->modifiers.first; md; md=md->next) {
 
13296
                                if (md->type == eModifierType_Lattice) {
 
13297
                                        LatticeModifierData *lmd = (LatticeModifierData *)md;
 
13298
                                        lmd->strength = 1.0f;
 
13299
                                }
 
13300
                        }
 
13301
                }
 
13302
        }
 
13303
 
 
13304
        if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 4))
 
13305
        {
 
13306
                /* Read Viscosity presets from older files */
 
13307
                Object *ob;
 
13308
 
 
13309
                for (ob = main->object.first; ob; ob = ob->id.next) {
 
13310
                        ModifierData *md;
 
13311
                        for (md = ob->modifiers.first; md; md = md->next) {
 
13312
                                if (md->type == eModifierType_Fluidsim) {
 
13313
                                        FluidsimModifierData *fmd = (FluidsimModifierData *)md;
 
13314
                                        if (fmd->fss->viscosityMode == 3) {
 
13315
                                                fmd->fss->viscosityValue = 5.0;
 
13316
                                                fmd->fss->viscosityExponent = 5;
 
13317
                                        }
 
13318
                                        else if (fmd->fss->viscosityMode == 4) {
 
13319
                                                fmd->fss->viscosityValue = 2.0;
 
13320
                                                fmd->fss->viscosityExponent = 3;
 
13321
                                        }
 
13322
                                }
 
13323
                        }
 
13324
                }
 
13325
        }
 
13326
 
 
13327
 
 
13328
 
 
13329
        if (main->versionfile < 263)
 
13330
        {
 
13331
                /* Default for old files is to save particle rotations to pointcache */
 
13332
                ParticleSettings *part;
 
13333
                for (part = main->particle.first; part; part = part->id.next)
 
13334
                        part->flag |= PART_ROTATIONS;
11055
13335
        }
11056
13336
 
11057
13337
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
11064
13344
static void do_versions_after_linking(FileData *fd, Library *lib, Main *main)
11065
13345
{
11066
13346
        /* old Animation System (using IPO's) needs to be converted to the new Animato system */
11067
 
        if(main->versionfile < 250)
 
13347
        if (main->versionfile < 250)
11068
13348
                do_versions_ipos_to_animato(main);
11069
13349
}
11070
13350
#endif
11089
13369
        lib_link_latt(fd, main);
11090
13370
        lib_link_text(fd, main);
11091
13371
        lib_link_camera(fd, main);
 
13372
        lib_link_speaker(fd, main);
11092
13373
        lib_link_sound(fd, main);
11093
13374
        lib_link_group(fd, main);
11094
13375
        lib_link_armature(fd, main);
11097
13378
        lib_link_nodetree(fd, main);    /* has to be done after scene/materials, this will verify group nodes */
11098
13379
        lib_link_brush(fd, main);
11099
13380
        lib_link_particlesettings(fd, main);
 
13381
        lib_link_movieclip(fd, main);
11100
13382
 
11101
13383
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
11102
13384
 
11103
13385
        lib_link_library(fd, main);             /* only init users */
11104
13386
}
11105
13387
 
 
13388
static void direct_link_keymapitem(FileData *fd, wmKeyMapItem *kmi)
 
13389
{
 
13390
        kmi->properties= newdataadr(fd, kmi->properties);
 
13391
        if (kmi->properties)
 
13392
                IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 
13393
        kmi->ptr= NULL;
 
13394
        kmi->flag &= ~KMI_UPDATE;
 
13395
}
11106
13396
 
11107
13397
static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
11108
13398
{
11109
13399
        UserDef *user;
11110
13400
        wmKeyMap *keymap;
11111
13401
        wmKeyMapItem *kmi;
 
13402
        wmKeyMapDiffItem *kmdi;
11112
13403
 
11113
13404
        bfd->user= user= read_struct(fd, bhead, "user def");
11114
13405
 
11115
13406
        /* read all data into fd->datamap */
11116
13407
        bhead= read_data_into_oldnewmap(fd, bhead, "user def");
11117
13408
 
 
13409
        if (user->keymaps.first) {
 
13410
                /* backwards compatibility */
 
13411
                user->user_keymaps= user->keymaps;
 
13412
                user->keymaps.first= user->keymaps.last= NULL;
 
13413
        }
 
13414
 
11118
13415
        link_list(fd, &user->themes);
11119
 
        link_list(fd, &user->keymaps);
 
13416
        link_list(fd, &user->user_keymaps);
11120
13417
        link_list(fd, &user->addons);
11121
13418
 
11122
 
        for(keymap=user->keymaps.first; keymap; keymap=keymap->next) {
 
13419
        for (keymap=user->user_keymaps.first; keymap; keymap=keymap->next) {
11123
13420
                keymap->modal_items= NULL;
11124
 
                keymap->poll= NULL;
 
13421
                keymap->poll = NULL;
 
13422
                keymap->flag &= ~KEYMAP_UPDATE;
11125
13423
 
 
13424
                link_list(fd, &keymap->diff_items);
11126
13425
                link_list(fd, &keymap->items);
11127
 
                for(kmi=keymap->items.first; kmi; kmi=kmi->next) {
11128
 
                        kmi->properties= newdataadr(fd, kmi->properties);
11129
 
                        if(kmi->properties)
11130
 
                                IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
11131
 
                        kmi->ptr= NULL;
 
13426
                
 
13427
                for (kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) {
 
13428
                        kmdi->remove_item= newdataadr(fd, kmdi->remove_item);
 
13429
                        kmdi->add_item= newdataadr(fd, kmdi->add_item);
 
13430
 
 
13431
                        if (kmdi->remove_item)
 
13432
                                direct_link_keymapitem(fd, kmdi->remove_item);
 
13433
                        if (kmdi->add_item)
 
13434
                                direct_link_keymapitem(fd, kmdi->add_item);
11132
13435
                }
 
13436
 
 
13437
                for (kmi=keymap->items.first; kmi; kmi=kmi->next)
 
13438
                        direct_link_keymapitem(fd, kmi);
11133
13439
        }
11134
13440
 
11135
13441
        // XXX
11136
13442
        user->uifonts.first= user->uifonts.last= NULL;
11137
 
        user->uistyles.first= user->uistyles.last= NULL;
 
13443
        
 
13444
        link_list(fd, &user->uistyles);
11138
13445
 
11139
13446
        /* free fd->datamap again */
11140
13447
        oldnewmap_free_unused(fd->datamap);
11143
13450
        return bhead;
11144
13451
}
11145
13452
 
11146
 
BlendFileData *blo_read_file_internal(FileData *fd, const char *filename)
 
13453
BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
11147
13454
{
11148
13455
        BHead *bhead= blo_firstbhead(fd);
11149
13456
        BlendFileData *bfd;
11150
13457
 
11151
13458
        bfd= MEM_callocN(sizeof(BlendFileData), "blendfiledata");
11152
 
        bfd->main= MEM_callocN(sizeof(Main), "main");
 
13459
        bfd->main= MEM_callocN(sizeof(Main), "readfile_Main");
11153
13460
        BLI_addtail(&fd->mainlist, bfd->main);
11154
13461
 
11155
13462
        bfd->main->versionfile= fd->fileversion;
11156
13463
        
11157
13464
        bfd->type= BLENFILETYPE_BLEND;
11158
 
        strncpy(bfd->main->name, filename, sizeof(bfd->main->name)-1);
 
13465
        BLI_strncpy(bfd->main->name, filepath, sizeof(bfd->main->name));
11159
13466
 
11160
 
        while(bhead) {
 
13467
        while (bhead) {
11161
13468
                switch(bhead->code) {
11162
13469
                case DATA:
11163
13470
                case DNA1:
11177
13484
 
11178
13485
                case ID_LI:
11179
13486
                        /* skip library datablocks in undo, this works together with
11180
 
                           BLO_read_from_memfile, where the old main->library is restored
11181
 
                           overwriting  the libraries from the memory file. previously
11182
 
                           it did not save ID_LI/ID_ID blocks in this case, but they are
11183
 
                           needed to make quit.blend recover them correctly. */
11184
 
                        if(fd->memfile)
 
13487
                         * BLO_read_from_memfile, where the old main->library is restored
 
13488
                         * overwriting  the libraries from the memory file. previously
 
13489
                         * it did not save ID_LI/ID_ID blocks in this case, but they are
 
13490
                         * needed to make quit.blend recover them correctly. */
 
13491
                        if (fd->memfile)
11185
13492
                                bhead= blo_nextbhead(fd, bhead);
11186
13493
                        else
11187
13494
                                bhead= read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
11188
13495
                        break;
11189
13496
                case ID_ID:
11190
13497
                        /* same as above */
11191
 
                        if(fd->memfile)
 
13498
                        if (fd->memfile)
11192
13499
                                bhead= blo_nextbhead(fd, bhead);
11193
13500
                        else
11194
13501
                                /* always adds to the most recently loaded
11207
13514
        }
11208
13515
 
11209
13516
        /* do before read_libraries, but skip undo case */
11210
 
//      if(fd->memfile==NULL) (the mesh shuffle hacks don't work yet? ton)
 
13517
//      if (fd->memfile==NULL) (the mesh shuffle hacks don't work yet? ton)
11211
13518
                do_versions(fd, NULL, bfd->main);
11212
13519
 
11213
13520
        read_libraries(fd, &fd->mainlist);
11216
13523
 
11217
13524
        lib_link_all(fd, bfd->main);
11218
13525
        //do_versions_after_linking(fd, NULL, bfd->main); // XXX: not here (or even in this function at all)! this causes crashes on many files - Aligorith (July 04, 2010)
11219
 
        lib_verify_nodetree(bfd->main, 1);
 
13526
        lib_verify_nodetree(bfd->main, TRUE);
11220
13527
        fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */
11221
13528
        
11222
13529
        link_global(fd, bfd);   /* as last */
11235
13542
{
11236
13543
        const struct bheadsort *x1=v1, *x2=v2;
11237
13544
        
11238
 
        if( x1->old > x2->old) return 1;
11239
 
        else if( x1->old < x2->old) return -1;
 
13545
        if ( x1->old > x2->old) return 1;
 
13546
        else if ( x1->old < x2->old) return -1;
11240
13547
        return 0;
11241
13548
}
11242
13549
 
11250
13557
                tot++;
11251
13558
        
11252
13559
        fd->tot_bheadmap= tot;
11253
 
        if(tot==0) return;
 
13560
        if (tot==0) return;
11254
13561
        
11255
13562
        bhs= fd->bheadmap= MEM_mallocN(tot*sizeof(struct bheadsort), "bheadsort");
11256
13563
        
11266
13573
static BHead *find_previous_lib(FileData *fd, BHead *bhead)
11267
13574
{
11268
13575
        /* skip library datablocks in undo, see comment in read_libblock */
11269
 
        if(fd->memfile)
 
13576
        if (fd->memfile)
11270
13577
                return NULL;
11271
13578
 
11272
13579
        for (; bhead; bhead= blo_prevbhead(fd, bhead))
11292
13599
        bhs_s.old= old;
11293
13600
        bhs= bsearch(&bhs_s, fd->bheadmap, fd->tot_bheadmap, sizeof(struct bheadsort), verg_bheadsort);
11294
13601
 
11295
 
        if(bhs)
 
13602
        if (bhs)
11296
13603
                return bhs->bhead;
11297
13604
        
11298
13605
#if 0
11322
13629
        ID *id;
11323
13630
 
11324
13631
        bhead= find_bhead(fd, old);
11325
 
        if(bhead) {
 
13632
        if (bhead) {
11326
13633
                        /* from another library? */
11327
 
                if(bhead->code==ID_ID) {
 
13634
                if (bhead->code==ID_ID) {
11328
13635
                        BHead *bheadlib= find_previous_lib(fd, bhead);
11329
13636
 
11330
 
                        if(bheadlib) {
 
13637
                        if (bheadlib) {
11331
13638
                                Library *lib= read_struct(fd, bheadlib, "Library");
11332
13639
                                Main *ptr= blo_find_main(fd, &fd->mainlist, lib->name, fd->relabase);
11333
13640
 
11334
13641
                                id= is_yet_read(fd, ptr, bhead);
11335
13642
 
11336
 
                                if(id==NULL) {
 
13643
                                if (id==NULL) {
11337
13644
                                        read_libblock(fd, ptr, bhead, LIB_READ+LIB_INDIRECT, NULL);
11338
13645
                                        // commented because this can print way too much
11339
 
                                        // if(G.f & G_DEBUG) printf("expand_doit: other lib %s\n", lib->name);
 
13646
                                        // if (G.debug & G_DEBUG) printf("expand_doit: other lib %s\n", lib->name);
11340
13647
                                        
11341
13648
                                        /* for outliner dependency only */
11342
13649
                                        ptr->curlib->parent= mainvar->curlib;
11348
13655
                                         * lib_indirect.blend but lib.blend does too, linking in a Scene or Group from lib.blend can result in an
11349
13656
                                         * empty without the dupli group referenced. Once you save and reload the group would appier. - Campbell */
11350
13657
                                        /* This crashes files, must look further into it */
11351
 
                                        /*oldnewmap_insert(fd->libmap, bhead->old, id, 1);*/
 
13658
                                        
 
13659
                                        /* Update: the issue is that in file reading, the oldnewmap is OK, but for existing data, it has to be
 
13660
                                         * inserted in the map to be found! */
 
13661
                                        if (id->flag & LIB_PRE_EXISTING)
 
13662
                                                oldnewmap_insert(fd->libmap, bhead->old, id, 1);
11352
13663
                                        
11353
13664
                                        change_idid_adr_fd(fd, bhead->old, id);
11354
13665
                                        // commented because this can print way too much
11355
 
                                        // if(G.f & G_DEBUG) printf("expand_doit: already linked: %s lib: %s\n", id->name, lib->name);
 
13666
                                        // if (G.debug & G_DEBUG) printf("expand_doit: already linked: %s lib: %s\n", id->name, lib->name);
11356
13667
                                }
11357
13668
                                
11358
13669
                                MEM_freeN(lib);
11360
13671
                }
11361
13672
                else {
11362
13673
                        id= is_yet_read(fd, mainvar, bhead);
11363
 
                        if(id==NULL) {
 
13674
                        if (id==NULL) {
11364
13675
                                read_libblock(fd, mainvar, bhead, LIB_TESTIND, NULL);
11365
13676
                        }
11366
13677
                        else {
11367
13678
                                /* this is actually only needed on UI call? when ID was already read before, and another append
11368
 
                                   happens which invokes same ID... in that case the lookup table needs this entry */
 
13679
                                 * happens which invokes same ID... in that case the lookup table needs this entry */
11369
13680
                                oldnewmap_insert(fd->libmap, bhead->old, id, 1);
11370
13681
                                // commented because this can print way too much
11371
 
                                // if(G.f & G_DEBUG) printf("expand: already read %s\n", id->name);
 
13682
                                // if (G.debug & G_DEBUG) printf("expand: already read %s\n", id->name);
11372
13683
                        }
11373
13684
                }
11374
13685
        }
11380
13691
static void expand_ipo(FileData *fd, Main *mainvar, Ipo *ipo)
11381
13692
{
11382
13693
        IpoCurve *icu;
11383
 
        for(icu= ipo->curve.first; icu; icu= icu->next) {
11384
 
                if(icu->driver)
 
13694
        for (icu= ipo->curve.first; icu; icu= icu->next) {
 
13695
                if (icu->driver)
11385
13696
                        expand_doit(fd, mainvar, icu->driver->ob);
11386
13697
        }
11387
13698
}
11503
13814
 
11504
13815
static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSettings *part)
11505
13816
{
 
13817
        int a;
 
13818
 
11506
13819
        expand_doit(fd, mainvar, part->dup_ob);
11507
13820
        expand_doit(fd, mainvar, part->dup_group);
11508
13821
        expand_doit(fd, mainvar, part->eff_group);
11509
13822
        expand_doit(fd, mainvar, part->bb_ob);
11510
13823
        
11511
 
        if(part->adt)
 
13824
        if (part->adt)
11512
13825
                expand_animdata(fd, mainvar, part->adt);
 
13826
 
 
13827
        for (a=0; a<MAX_MTEX; a++) {
 
13828
                if (part->mtex[a]) {
 
13829
                        expand_doit(fd, mainvar, part->mtex[a]->tex);
 
13830
                        expand_doit(fd, mainvar, part->mtex[a]->object);
 
13831
                }
 
13832
        }
11513
13833
}
11514
13834
 
11515
13835
static void expand_group(FileData *fd, Main *mainvar, Group *group)
11516
13836
{
11517
13837
        GroupObject *go;
11518
13838
        
11519
 
        for(go= group->gobject.first; go; go= go->next) {
 
13839
        for (go= group->gobject.first; go; go= go->next) {
11520
13840
                expand_doit(fd, mainvar, go->ob);
11521
13841
        }
11522
13842
}
11525
13845
{
11526
13846
        expand_doit(fd, mainvar, key->ipo); // XXX depreceated - old animation system
11527
13847
        
11528
 
        if(key->adt)
 
13848
        if (key->adt)
11529
13849
                expand_animdata(fd, mainvar, key->adt);
11530
13850
}
11531
13851
 
11533
13853
{
11534
13854
        bNode *node;
11535
13855
        
11536
 
        if(ntree->adt)
 
13856
        if (ntree->adt)
11537
13857
                expand_animdata(fd, mainvar, ntree->adt);
11538
13858
                
11539
 
        if(ntree->gpd)
 
13859
        if (ntree->gpd)
11540
13860
                expand_doit(fd, mainvar, ntree->gpd);
11541
13861
        
11542
 
        for(node= ntree->nodes.first; node; node= node->next)
11543
 
                if(node->id && node->type!=CMP_NODE_R_LAYERS)
 
13862
        for (node= ntree->nodes.first; node; node= node->next)
 
13863
                if (node->id && node->type!=CMP_NODE_R_LAYERS)
11544
13864
                        expand_doit(fd, mainvar, node->id);
11545
13865
 
11546
13866
}
11550
13870
        expand_doit(fd, mainvar, tex->ima);
11551
13871
        expand_doit(fd, mainvar, tex->ipo); // XXX depreceated - old animation system
11552
13872
        
11553
 
        if(tex->adt)
 
13873
        if (tex->adt)
11554
13874
                expand_animdata(fd, mainvar, tex->adt);
11555
13875
        
11556
 
        if(tex->nodetree)
 
13876
        if (tex->nodetree)
11557
13877
                expand_nodetree(fd, mainvar, tex->nodetree);
11558
13878
}
11559
13879
 
11567
13887
{
11568
13888
        int a;
11569
13889
 
11570
 
        for(a=0; a<MAX_MTEX; a++) {
11571
 
                if(ma->mtex[a]) {
 
13890
        for (a=0; a<MAX_MTEX; a++) {
 
13891
                if (ma->mtex[a]) {
11572
13892
                        expand_doit(fd, mainvar, ma->mtex[a]->tex);
11573
13893
                        expand_doit(fd, mainvar, ma->mtex[a]->object);
11574
13894
                }
11576
13896
        
11577
13897
        expand_doit(fd, mainvar, ma->ipo); // XXX depreceated - old animation system
11578
13898
        
11579
 
        if(ma->adt)
 
13899
        if (ma->adt)
11580
13900
                expand_animdata(fd, mainvar, ma->adt);
11581
13901
        
11582
 
        if(ma->nodetree)
 
13902
        if (ma->nodetree)
11583
13903
                expand_nodetree(fd, mainvar, ma->nodetree);
 
13904
        
 
13905
        if (ma->group)
 
13906
                expand_doit(fd, mainvar, ma->group);
11584
13907
}
11585
13908
 
11586
13909
static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la)
11587
13910
{
11588
13911
        int a;
11589
13912
 
11590
 
        for(a=0; a<MAX_MTEX; a++) {
11591
 
                if(la->mtex[a]) {
 
13913
        for (a=0; a<MAX_MTEX; a++) {
 
13914
                if (la->mtex[a]) {
11592
13915
                        expand_doit(fd, mainvar, la->mtex[a]->tex);
11593
13916
                        expand_doit(fd, mainvar, la->mtex[a]->object);
11594
13917
                }
11598
13921
        
11599
13922
        if (la->adt)
11600
13923
                expand_animdata(fd, mainvar, la->adt);
 
13924
 
 
13925
        if (la->nodetree)
 
13926
                expand_nodetree(fd, mainvar, la->nodetree);
11601
13927
}
11602
13928
 
11603
13929
static void expand_lattice(FileData *fd, Main *mainvar, Lattice *lt)
11604
13930
{
11605
13931
        expand_doit(fd, mainvar, lt->ipo); // XXX depreceated - old animation system
11606
13932
        expand_doit(fd, mainvar, lt->key);
 
13933
        
 
13934
        if (lt->adt)
 
13935
                expand_animdata(fd, mainvar, lt->adt);
11607
13936
}
11608
13937
 
11609
13938
 
11611
13940
{
11612
13941
        int a;
11613
13942
 
11614
 
        for(a=0; a<MAX_MTEX; a++) {
11615
 
                if(wrld->mtex[a]) {
 
13943
        for (a=0; a<MAX_MTEX; a++) {
 
13944
                if (wrld->mtex[a]) {
11616
13945
                        expand_doit(fd, mainvar, wrld->mtex[a]->tex);
11617
13946
                        expand_doit(fd, mainvar, wrld->mtex[a]->object);
11618
13947
                }
11622
13951
        
11623
13952
        if (wrld->adt)
11624
13953
                expand_animdata(fd, mainvar, wrld->adt);
 
13954
 
 
13955
        if (wrld->nodetree)
 
13956
                expand_nodetree(fd, mainvar, wrld->nodetree);
11625
13957
}
11626
13958
 
11627
13959
 
11629
13961
{
11630
13962
        int a;
11631
13963
 
11632
 
        for(a=0; a<mb->totcol; a++) {
 
13964
        for (a=0; a<mb->totcol; a++) {
11633
13965
                expand_doit(fd, mainvar, mb->mat[a]);
11634
13966
        }
11635
13967
        
11636
 
        if(mb->adt)
 
13968
        if (mb->adt)
11637
13969
                expand_animdata(fd, mainvar, mb->adt);
11638
13970
}
11639
13971
 
11641
13973
{
11642
13974
        int a;
11643
13975
 
11644
 
        for(a=0; a<cu->totcol; a++) {
 
13976
        for (a=0; a<cu->totcol; a++) {
11645
13977
                expand_doit(fd, mainvar, cu->mat[a]);
11646
13978
        }
11647
13979
        
11655
13987
        expand_doit(fd, mainvar, cu->taperobj);
11656
13988
        expand_doit(fd, mainvar, cu->textoncurve);
11657
13989
        
11658
 
        if(cu->adt)
 
13990
        if (cu->adt)
11659
13991
                expand_animdata(fd, mainvar, cu->adt);
11660
13992
}
11661
13993
 
11666
13998
        TFace *tf;
11667
13999
        int a, i;
11668
14000
        
11669
 
        for(a=0; a<me->totcol; a++) {
 
14001
        if (me->adt)
 
14002
                expand_animdata(fd, mainvar, me->adt);
 
14003
                
 
14004
        for (a=0; a<me->totcol; a++) {
11670
14005
                expand_doit(fd, mainvar, me->mat[a]);
11671
14006
        }
11672
14007
 
11673
14008
        expand_doit(fd, mainvar, me->key);
11674
14009
        expand_doit(fd, mainvar, me->texcomesh);
11675
14010
 
11676
 
        if(me->tface) {
 
14011
        if (me->tface) {
11677
14012
                tf= me->tface;
11678
 
                for(i=0; i<me->totface; i++, tf++)
11679
 
                        if(tf->tpage)
 
14013
                for (i=0; i<me->totface; i++, tf++)
 
14014
                        if (tf->tpage)
11680
14015
                                expand_doit(fd, mainvar, tf->tpage);
11681
14016
        }
11682
14017
 
11683
 
        for(a=0; a<me->fdata.totlayer; a++) {
 
14018
        for (a=0; a<me->fdata.totlayer; a++) {
11684
14019
                layer= &me->fdata.layers[a];
11685
14020
 
11686
 
                if(layer->type == CD_MTFACE) {
 
14021
                if (layer->type == CD_MTFACE) {
11687
14022
                        mtf= (MTFace*)layer->data;
11688
 
                        for(i=0; i<me->totface; i++, mtf++)
11689
 
                                if(mtf->tpage)
 
14023
                        for (i=0; i<me->totface; i++, mtf++)
 
14024
                                if (mtf->tpage)
11690
14025
                                        expand_doit(fd, mainvar, mtf->tpage);
11691
14026
                }
11692
14027
        }
11698
14033
        Main *mainvar;
11699
14034
} tConstraintExpandData;
11700
14035
/* callback function used to expand constraint ID-links */
11701
 
static void expand_constraint_cb(bConstraint *con, ID **idpoin, void *userdata)
 
14036
static void expand_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED(isReference), void *userdata)
11702
14037
{
11703
14038
        tConstraintExpandData *ced= (tConstraintExpandData *)userdata;
11704
14039
        expand_doit(ced->fd, ced->mainvar, *idpoin);
11749
14084
{
11750
14085
        Bone *curBone;
11751
14086
 
11752
 
        if(arm->adt)
 
14087
        if (arm->adt)
11753
14088
                expand_animdata(fd, mainvar, arm->adt);
11754
14089
 
11755
14090
        for (curBone = arm->bonebase.first; curBone; curBone=curBone->next) {
11757
14092
        }
11758
14093
}
11759
14094
 
11760
 
static void expand_modifier(FileData *fd, Main *mainvar, ModifierData *md)
 
14095
static void expand_object_expandModifiers(void *userData, Object *UNUSED(ob),
 
14096
                                                                                          ID **idpoin)
11761
14097
{
11762
 
        if (md->type==eModifierType_Lattice) {
11763
 
                LatticeModifierData *lmd = (LatticeModifierData*) md;
11764
 
                        
11765
 
                expand_doit(fd, mainvar, lmd->object);
11766
 
        } 
11767
 
        else if (md->type==eModifierType_Curve) {
11768
 
                CurveModifierData *cmd = (CurveModifierData*) md;
11769
 
                        
11770
 
                expand_doit(fd, mainvar, cmd->object);
11771
 
        }
11772
 
        else if (md->type==eModifierType_Array) {
11773
 
                ArrayModifierData *amd = (ArrayModifierData*) md;
11774
 
                        
11775
 
                expand_doit(fd, mainvar, amd->curve_ob);
11776
 
                expand_doit(fd, mainvar, amd->offset_ob);
11777
 
        }
11778
 
        else if (md->type==eModifierType_Mirror) {
11779
 
                MirrorModifierData *mmd = (MirrorModifierData*) md;
11780
 
                        
11781
 
                expand_doit(fd, mainvar, mmd->mirror_ob);
11782
 
        }
11783
 
        else if (md->type==eModifierType_Displace) {
11784
 
                DisplaceModifierData *dmd = (DisplaceModifierData*) md;
11785
 
                
11786
 
                expand_doit(fd, mainvar, dmd->map_object);
11787
 
                expand_doit(fd, mainvar, dmd->texture);
11788
 
        }
11789
 
        else if (md->type==eModifierType_Smoke) {
11790
 
                SmokeModifierData *smd = (SmokeModifierData*) md;
11791
 
                        
11792
 
                if(smd->type==MOD_SMOKE_TYPE_DOMAIN && smd->domain)
11793
 
                {       
11794
 
                        expand_doit(fd, mainvar, smd->domain->coll_group);
11795
 
                        expand_doit(fd, mainvar, smd->domain->fluid_group);
11796
 
                        expand_doit(fd, mainvar, smd->domain->eff_group);
11797
 
                }
11798
 
        }
 
14098
        struct { FileData *fd; Main *mainvar; } *data= userData;
 
14099
 
 
14100
        FileData *fd= data->fd;
 
14101
        Main *mainvar= data->mainvar;
 
14102
 
 
14103
        expand_doit(fd, mainvar, *idpoin);
11799
14104
}
11800
14105
 
11801
14106
static void expand_object(FileData *fd, Main *mainvar, Object *ob)
11802
14107
{
11803
 
        ModifierData *md;
11804
14108
        ParticleSystem *psys;
11805
14109
        bSensor *sens;
11806
14110
        bController *cont;
11810
14114
        int a;
11811
14115
 
11812
14116
        expand_doit(fd, mainvar, ob->data);
11813
 
        
11814
 
        for (md=ob->modifiers.first; md; md=md->next) {
11815
 
                expand_modifier(fd, mainvar, md);
 
14117
 
 
14118
        /* expand_object_expandModifier() */
 
14119
        if (ob->modifiers.first) {
 
14120
                struct { FileData *fd; Main *mainvar; } data;
 
14121
                data.fd= fd;
 
14122
                data.mainvar= mainvar;
 
14123
 
 
14124
                modifiers_foreachIDLink(ob, expand_object_expandModifiers, (void *)&data);
11816
14125
        }
11817
14126
 
11818
14127
        expand_pose(fd, mainvar, ob->pose);
11827
14136
        
11828
14137
        expand_constraint_channels(fd, mainvar, &ob->constraintChannels);
11829
14138
 
11830
 
        for (strip=ob->nlastrips.first; strip; strip=strip->next){
 
14139
        for (strip=ob->nlastrips.first; strip; strip=strip->next) {
11831
14140
                expand_doit(fd, mainvar, strip->object);
11832
14141
                expand_doit(fd, mainvar, strip->act);
11833
14142
                expand_doit(fd, mainvar, strip->ipo);
11834
14143
        }
11835
14144
// XXX depreceated - old animation system (for version patching only)
11836
14145
        
11837
 
        if(ob->adt)
 
14146
        if (ob->adt)
11838
14147
                expand_animdata(fd, mainvar, ob->adt);
11839
14148
        
11840
 
        for(a=0; a<ob->totcol; a++) {
 
14149
        for (a=0; a<ob->totcol; a++) {
11841
14150
                expand_doit(fd, mainvar, ob->mat[a]);
11842
14151
        }
11843
14152
        
11844
 
        paf = give_parteff(ob);
 
14153
        paf = do_version_give_parteff_245(ob);
11845
14154
        if (paf && paf->group) 
11846
14155
                expand_doit(fd, mainvar, paf->group);
11847
14156
 
11848
 
        if(ob->dup_group)
 
14157
        if (ob->dup_group)
11849
14158
                expand_doit(fd, mainvar, ob->dup_group);
11850
14159
        
11851
 
        if(ob->proxy)
 
14160
        if (ob->proxy)
11852
14161
                expand_doit(fd, mainvar, ob->proxy);
11853
 
        if(ob->proxy_group)
 
14162
        if (ob->proxy_group)
11854
14163
                expand_doit(fd, mainvar, ob->proxy_group);
11855
14164
 
11856
 
        for(psys=ob->particlesystem.first; psys; psys=psys->next)
 
14165
        for (psys=ob->particlesystem.first; psys; psys=psys->next)
11857
14166
                expand_doit(fd, mainvar, psys->part);
11858
14167
 
11859
14168
        sens= ob->sensors.first;
11860
 
        while(sens) {
11861
 
                if(sens->type==SENS_TOUCH) {
 
14169
        while (sens) {
 
14170
                if (sens->type==SENS_TOUCH) {
11862
14171
                        bTouchSensor *ts= sens->data;
11863
14172
                        expand_doit(fd, mainvar, ts->ma);
11864
14173
                }
11865
 
                else if(sens->type==SENS_MESSAGE) {
 
14174
                else if (sens->type==SENS_MESSAGE) {
11866
14175
                        bMessageSensor *ms= sens->data;
11867
14176
                        expand_doit(fd, mainvar, ms->fromObject);
11868
14177
                }
11870
14179
        }
11871
14180
 
11872
14181
        cont= ob->controllers.first;
11873
 
        while(cont) {
11874
 
                if(cont->type==CONT_PYTHON) {
 
14182
        while (cont) {
 
14183
                if (cont->type==CONT_PYTHON) {
11875
14184
                        bPythonCont *pc= cont->data;
11876
14185
                        expand_doit(fd, mainvar, pc->text);
11877
14186
                }
11879
14188
        }
11880
14189
 
11881
14190
        act= ob->actuators.first;
11882
 
        while(act) {
11883
 
                if(act->type==ACT_SOUND) {
 
14191
        while (act) {
 
14192
                if (act->type==ACT_SOUND) {
11884
14193
                        bSoundActuator *sa= act->data;
11885
14194
                        expand_doit(fd, mainvar, sa->sound);
11886
14195
                }
11887
 
                else if(act->type==ACT_CAMERA) {
 
14196
                else if (act->type==ACT_CAMERA) {
11888
14197
                        bCameraActuator *ca= act->data;
11889
14198
                        expand_doit(fd, mainvar, ca->ob);
11890
14199
                }
11891
 
                else if(act->type==ACT_EDIT_OBJECT) {
 
14200
                else if (act->type==ACT_EDIT_OBJECT) {
11892
14201
                        bEditObjectActuator *eoa= act->data;
11893
 
                        if(eoa) {
 
14202
                        if (eoa) {
11894
14203
                                expand_doit(fd, mainvar, eoa->ob);
11895
14204
                                expand_doit(fd, mainvar, eoa->me);
11896
14205
                        }
11897
14206
                }
11898
 
                else if(act->type==ACT_OBJECT) {
 
14207
                else if (act->type==ACT_OBJECT) {
11899
14208
                        bObjectActuator *oa= act->data;
11900
14209
                        expand_doit(fd, mainvar, oa->reference);
11901
14210
                }
11902
 
                else if(act->type==ACT_ADD_OBJECT) {
 
14211
                else if (act->type==ACT_ADD_OBJECT) {
11903
14212
                        bAddObjectActuator *aoa= act->data;
11904
14213
                        expand_doit(fd, mainvar, aoa->ob);
11905
14214
                }
11906
 
                else if(act->type==ACT_SCENE) {
 
14215
                else if (act->type==ACT_SCENE) {
11907
14216
                        bSceneActuator *sa= act->data;
11908
14217
                        expand_doit(fd, mainvar, sa->camera);
11909
14218
                        expand_doit(fd, mainvar, sa->scene);
11910
14219
                }
11911
 
                else if(act->type==ACT_2DFILTER) {
 
14220
                else if (act->type==ACT_2DFILTER) {
11912
14221
                        bTwoDFilterActuator *tdfa= act->data;
11913
14222
                        expand_doit(fd, mainvar, tdfa->text);
11914
14223
                }
11915
 
                else if(act->type==ACT_ACTION) {
11916
 
                        bActionActuator *aa= act->data;
11917
 
                        expand_doit(fd, mainvar, aa->act);
11918
 
                }
11919
 
                else if(act->type==ACT_SHAPEACTION) {
11920
 
                        bActionActuator *aa= act->data;
11921
 
                        expand_doit(fd, mainvar, aa->act);
11922
 
                }
11923
 
                else if(act->type==ACT_PROPERTY) {
 
14224
                else if (act->type==ACT_ACTION) {
 
14225
                        bActionActuator *aa= act->data;
 
14226
                        expand_doit(fd, mainvar, aa->act);
 
14227
                }
 
14228
                else if (act->type==ACT_SHAPEACTION) {
 
14229
                        bActionActuator *aa= act->data;
 
14230
                        expand_doit(fd, mainvar, aa->act);
 
14231
                }
 
14232
                else if (act->type==ACT_PROPERTY) {
11924
14233
                        bPropertyActuator *pa= act->data;
11925
14234
                        expand_doit(fd, mainvar, pa->ob);
11926
14235
                }
11927
 
                else if(act->type==ACT_MESSAGE) {
 
14236
                else if (act->type==ACT_MESSAGE) {
11928
14237
                        bMessageActuator *ma= act->data;
11929
14238
                        expand_doit(fd, mainvar, ma->toObject);
11930
14239
                }
11931
 
                else if(act->type==ACT_PARENT) {
 
14240
                else if (act->type==ACT_PARENT) {
11932
14241
                        bParentActuator *pa= act->data;
11933
14242
                        expand_doit(fd, mainvar, pa->ob);
11934
14243
                }
11935
 
                else if(act->type==ACT_ARMATURE) {
 
14244
                else if (act->type==ACT_ARMATURE) {
11936
14245
                        bArmatureActuator *arma= act->data;
11937
14246
                        expand_doit(fd, mainvar, arma->target);
11938
14247
                }
 
14248
                else if (act->type==ACT_STEERING) {
 
14249
                        bSteeringActuator *sta= act->data;
 
14250
                        expand_doit(fd, mainvar, sta->target);
 
14251
                        expand_doit(fd, mainvar, sta->navmesh);
 
14252
                }
11939
14253
                act= act->next;
11940
14254
        }
11941
14255
 
11942
 
        if(ob->pd && ob->pd->tex)
 
14256
        if (ob->pd && ob->pd->tex)
11943
14257
                expand_doit(fd, mainvar, ob->pd->tex);
11944
14258
        
11945
14259
}
11949
14263
        Base *base;
11950
14264
        SceneRenderLayer *srl;
11951
14265
 
11952
 
        for(base= sce->base.first; base; base= base->next) {
 
14266
        for (base= sce->base.first; base; base= base->next) {
11953
14267
                expand_doit(fd, mainvar, base->object);
11954
14268
        }
11955
14269
        expand_doit(fd, mainvar, sce->camera);
11956
14270
        expand_doit(fd, mainvar, sce->world);
11957
14271
        
11958
 
        if(sce->adt)
 
14272
        if (sce->adt)
11959
14273
                expand_animdata(fd, mainvar, sce->adt);
11960
14274
        expand_keyingsets(fd, mainvar, &sce->keyingsets);
11961
14275
        
11962
 
        if(sce->set)
 
14276
        if (sce->set)
11963
14277
                expand_doit(fd, mainvar, sce->set);
11964
14278
        
11965
 
        if(sce->nodetree)
 
14279
        if (sce->nodetree)
11966
14280
                expand_nodetree(fd, mainvar, sce->nodetree);
11967
14281
        
11968
 
        for(srl= sce->r.layers.first; srl; srl= srl->next) {
 
14282
        for (srl= sce->r.layers.first; srl; srl= srl->next) {
11969
14283
                expand_doit(fd, mainvar, srl->mat_override);
11970
14284
                expand_doit(fd, mainvar, srl->light_override);
11971
14285
        }
11972
14286
 
11973
 
        if(sce->r.dometext)
 
14287
        if (sce->r.dometext)
11974
14288
                expand_doit(fd, mainvar, sce->gm.dome.warptext);
11975
14289
                
11976
 
        if(sce->gpd)
 
14290
        if (sce->gpd)
11977
14291
                expand_doit(fd, mainvar, sce->gpd);
11978
14292
 
11979
 
        if(sce->ed) {
 
14293
        if (sce->ed) {
11980
14294
                Sequence *seq;
11981
14295
 
11982
14296
                SEQ_BEGIN(sce->ed, seq) {
11983
 
                        if(seq->scene) expand_doit(fd, mainvar, seq->scene);
11984
 
                        if(seq->scene_camera) expand_doit(fd, mainvar, seq->scene_camera);
11985
 
                        if(seq->sound) expand_doit(fd, mainvar, seq->sound);
 
14297
                        if (seq->scene) expand_doit(fd, mainvar, seq->scene);
 
14298
                        if (seq->scene_camera) expand_doit(fd, mainvar, seq->scene_camera);
 
14299
                        if (seq->sound) expand_doit(fd, mainvar, seq->sound);
11986
14300
                }
11987
14301
                SEQ_END
11988
14302
        }
11991
14305
        {
11992
14306
                TimeMarker *marker;
11993
14307
 
11994
 
                for(marker= sce->markers.first; marker; marker= marker->next) {
11995
 
                        if(marker->camera) {
 
14308
                for (marker= sce->markers.first; marker; marker= marker->next) {
 
14309
                        if (marker->camera) {
11996
14310
                                expand_doit(fd, mainvar, marker->camera);
11997
14311
                        }
11998
14312
                }
11999
14313
        }
12000
14314
#endif
 
14315
 
 
14316
        expand_doit(fd, mainvar, sce->clip);
12001
14317
}
12002
14318
 
12003
14319
static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
12004
14320
{
12005
14321
        expand_doit(fd, mainvar, ca->ipo); // XXX depreceated - old animation system
12006
14322
        
12007
 
        if(ca->adt)
 
14323
        if (ca->adt)
12008
14324
                expand_animdata(fd, mainvar, ca->adt);
12009
14325
}
12010
14326
 
 
14327
static void expand_speaker(FileData *fd, Main *mainvar, Speaker *spk)
 
14328
{
 
14329
        expand_doit(fd, mainvar, spk->sound);
 
14330
 
 
14331
        if (spk->adt)
 
14332
                expand_animdata(fd, mainvar, spk->adt);
 
14333
}
 
14334
 
12011
14335
static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
12012
14336
{
12013
14337
        expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
12014
14338
}
12015
14339
 
 
14340
static void expand_movieclip(FileData *fd, Main *mainvar, MovieClip *clip)
 
14341
{
 
14342
        if (clip->adt)
 
14343
                expand_animdata(fd, mainvar, clip->adt);
 
14344
}
12016
14345
 
12017
14346
static void expand_main(FileData *fd, Main *mainvar)
12018
14347
{
12020
14349
        ID *id;
12021
14350
        int a, doit= 1;
12022
14351
 
12023
 
        if(fd==0) return;
 
14352
        if (fd==NULL) return;
12024
14353
 
12025
 
        while(doit) {
 
14354
        while (doit) {
12026
14355
                doit= 0;
12027
14356
 
12028
14357
                a= set_listbasepointers(mainvar, lbarray);
12029
 
                while(a--) {
 
14358
                while (a--) {
12030
14359
                        id= lbarray[a]->first;
12031
14360
 
12032
 
                        while(id) {
12033
 
                                if(id->flag & LIB_TEST) {
 
14361
                        while (id) {
 
14362
                                if (id->flag & LIB_TEST) {
12034
14363
 
12035
14364
                                        switch(GS(id->name)) {
12036
14365
 
12070
14399
                                        case ID_CA:
12071
14400
                                                expand_camera(fd, mainvar, (Camera *)id);
12072
14401
                                                break;
 
14402
                                        case ID_SPK:
 
14403
                                                expand_speaker(fd, mainvar,(Speaker *)id);
 
14404
                                                break;
12073
14405
                                        case ID_SO:
12074
14406
                                                expand_sound(fd, mainvar, (bSound *)id);
12075
14407
                                                break;
12093
14425
                                                break;
12094
14426
                                        case ID_PA:
12095
14427
                                                expand_particlesettings(fd, mainvar, (ParticleSettings *)id);
 
14428
                                                break;
 
14429
                                        case ID_MC:
 
14430
                                                expand_movieclip(fd, mainvar, (MovieClip *)id);
 
14431
                                                break;
12096
14432
                                        }
12097
14433
 
12098
14434
                                        doit= 1;
12109
14445
{
12110
14446
        Scene *sce;
12111
14447
        
12112
 
        for(sce= mainvar->scene.first; sce; sce= sce->id.next)
12113
 
                if(object_in_scene(ob, sce))
 
14448
        for (sce= mainvar->scene.first; sce; sce= sce->id.next)
 
14449
                if (object_in_scene(ob, sce))
12114
14450
                        return 1;
12115
14451
        return 0;
12116
14452
}
12117
14453
 
12118
 
/* when *lib set, it also does objects that were in the appended group */
12119
 
static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, int is_group_append)
 
14454
static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, const short idcode, const short is_link)
12120
14455
{
12121
14456
        Object *ob;
12122
14457
        Base *base;
 
14458
        const short is_group_append= (is_link==FALSE && idcode==ID_GR);
12123
14459
 
12124
14460
        /* give all objects which are LIB_INDIRECT a base, or for a group when *lib has been set */
12125
 
        for(ob= mainvar->object.first; ob; ob= ob->id.next) {
 
14461
        for (ob= mainvar->object.first; ob; ob= ob->id.next) {
12126
14462
                
12127
 
                if( ob->id.flag & LIB_INDIRECT ) {
 
14463
                if ( ob->id.flag & LIB_INDIRECT ) {
12128
14464
                        
12129
 
                                /* IF below is quite confusing!
12130
 
                                if we are appending, but this object wasnt just added allong with a group,
12131
 
                                then this is already used indirectly in the scene somewhere else and we didnt just append it.
12132
 
                                
12133
 
                                (ob->id.flag & LIB_PRE_EXISTING)==0 means that this is a newly appended object - Campbell */
 
14465
                        /* IF below is quite confusing!
 
14466
                         * if we are appending, but this object wasnt just added along with a group,
 
14467
                         * then this is already used indirectly in the scene somewhere else and we didnt just append it.
 
14468
                         *
 
14469
                         * (ob->id.flag & LIB_PRE_EXISTING)==0 means that this is a newly appended object - Campbell */
12134
14470
                        if (is_group_append==0 || (ob->id.flag & LIB_PRE_EXISTING)==0) {
12135
14471
                                
12136
14472
                                int do_it= 0;
12137
14473
                                
12138
 
                                if(ob->id.us==0)
 
14474
                                if (ob->id.us==0) {
12139
14475
                                        do_it= 1;
12140
 
                                else if(ob->id.us==1 && lib)
12141
 
                                        if(ob->id.lib==lib && (ob->flag & OB_FROMGROUP) && object_in_any_scene(mainvar, ob)==0)
12142
 
                                                do_it= 1;
12143
 
                                                
12144
 
                                if(do_it) {
 
14476
                                }
 
14477
                                else if (idcode==ID_GR) {
 
14478
                                        if (ob->id.us==1 && is_link==FALSE && ob->id.lib==lib) {
 
14479
                                                if ((ob->flag & OB_FROMGROUP) && object_in_any_scene(mainvar, ob)==0) {
 
14480
                                                        do_it= 1;
 
14481
                                                }
 
14482
                                        }
 
14483
                                }
 
14484
                                else {
 
14485
                                        /* when appending, make sure any indirectly loaded objects
 
14486
                                         * get a base else they cant be accessed at all [#27437] */
 
14487
                                        if (ob->id.us==1 && is_link==FALSE && ob->id.lib==lib) {
 
14488
 
 
14489
                                                /* we may be appending from a scene where we already
 
14490
                                                 *  have a linked object which is not in any scene [#27616] */
 
14491
                                                if ((ob->id.flag & LIB_PRE_EXISTING)==0) {
 
14492
 
 
14493
                                                        if (object_in_any_scene(mainvar, ob)==0) {
 
14494
                                                                do_it= 1;
 
14495
                                                        }
 
14496
                                                }
 
14497
                                        }
 
14498
                                }
 
14499
 
 
14500
                                if (do_it) {
12145
14501
                                        base= MEM_callocN( sizeof(Base), "add_ext_base");
12146
14502
                                        BLI_addtail(&(sce->base), base);
12147
14503
                                        base->lay= ob->lay;
12157
14513
        }
12158
14514
}
12159
14515
 
12160
 
/* when *lib set, it also does objects that were in the appended group */
12161
14516
static void give_base_to_groups(Main *mainvar, Scene *scene)
12162
14517
{
12163
14518
        Group *group;
12164
14519
 
12165
14520
        /* give all objects which are LIB_INDIRECT a base, or for a group when *lib has been set */
12166
 
        for(group= mainvar->group.first; group; group= group->id.next) {
12167
 
                if(((group->id.flag & LIB_INDIRECT)==0 && (group->id.flag & LIB_PRE_EXISTING)==0)) {
 
14521
        for (group= mainvar->group.first; group; group= group->id.next) {
 
14522
                if (((group->id.flag & LIB_INDIRECT)==0 && (group->id.flag & LIB_PRE_EXISTING)==0)) {
12168
14523
                        Base *base;
12169
14524
 
12170
14525
                        /* add_object(...) messes with the selection */
12176
14531
                        base= scene_add_base(scene, ob);
12177
14532
                        base->flag |= SELECT;
12178
14533
                        base->object->flag= base->flag;
12179
 
                        ob->recalc |= OB_RECALC_ALL;
 
14534
                        ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
12180
14535
                        scene->basact= base;
12181
14536
 
12182
14537
                        /* assign the group */
12183
14538
                        ob->dup_group= group;
12184
14539
                        ob->transflag |= OB_DUPLIGROUP;
12185
14540
                        rename_id(&ob->id, group->id.name+2);
12186
 
                        VECCOPY(ob->loc, scene->cursor);
 
14541
                        copy_v3_v3(ob->loc, scene->cursor);
12187
14542
                }
12188
14543
        }
12189
14544
}
12190
14545
 
12191
 
static void append_named_part(const bContext *C, Main *mainl, FileData *fd, char *name, int idcode, short flag)
 
14546
/* returns true if the item was found
 
14547
 * but it may already have already been appended/linked */
 
14548
static ID *append_named_part(Main *mainl, FileData *fd, const char *idname, const short idcode)
12192
14549
{
12193
 
        Scene *scene= CTX_data_scene(C);
12194
 
        Object *ob;
12195
 
        Base *base;
12196
14550
        BHead *bhead;
12197
 
        ID *id;
12198
 
        int endloop=0;
12199
 
 
12200
 
        bhead = blo_firstbhead(fd);
12201
 
        while(bhead && endloop==0) {
12202
 
 
12203
 
                if(bhead->code==ENDB) endloop= 1;
12204
 
                else if(bhead->code==idcode) {
12205
 
                        char *idname= bhead_id_name(fd, bhead);
12206
 
                                
12207
 
                        if(strcmp(idname+2, name)==0) {
12208
 
 
 
14551
        ID *id= NULL;
 
14552
        int found=0;
 
14553
 
 
14554
        for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
 
14555
                if (bhead->code==idcode) {
 
14556
                        const char *idname_test= bhead_id_name(fd, bhead);
 
14557
 
 
14558
                        if (strcmp(idname_test + 2, idname)==0) {
 
14559
                                found= 1;
12209
14560
                                id= is_yet_read(fd, mainl, bhead);
12210
 
                                if(id==NULL) {
12211
 
                                        read_libblock(fd, mainl, bhead, LIB_TESTEXT, NULL);
 
14561
                                if (id==NULL) {
 
14562
                                        /* not read yet */
 
14563
                                        read_libblock(fd, mainl, bhead, LIB_TESTEXT, &id);
 
14564
 
 
14565
                                        if (id) {
 
14566
                                                /* sort by name in list */
 
14567
                                                ListBase *lb= which_libbase(mainl, idcode);
 
14568
                                                id_sort_by_name(lb, id);
 
14569
                                        }
12212
14570
                                }
12213
14571
                                else {
 
14572
                                        /* already linked */
12214
14573
                                        printf("append: already linked\n");
12215
14574
                                        oldnewmap_insert(fd->libmap, bhead->old, id, 1);
12216
 
                                        if(id->flag & LIB_INDIRECT) {
 
14575
                                        if (id->flag & LIB_INDIRECT) {
12217
14576
                                                id->flag -= LIB_INDIRECT;
12218
14577
                                                id->flag |= LIB_EXTERN;
12219
14578
                                        }
12220
14579
                                }
12221
14580
 
12222
 
                                if(idcode==ID_OB && scene) {    /* loose object: give a base */
12223
 
                                        base= MEM_callocN( sizeof(Base), "app_nam_part");
12224
 
                                        BLI_addtail(&scene->base, base);
12225
 
 
12226
 
                                        if(id==NULL) ob= mainl->object.last;
12227
 
                                        else ob= (Object *)id;
12228
 
                                        
12229
 
                                        /* link at active layer (view3d->lay if in context, else scene->lay */
12230
 
                                        if((flag & FILE_ACTIVELAY)) {
12231
 
                                                View3D *v3d = CTX_wm_view3d(C);
12232
 
                                                if (v3d) {
12233
 
                                                        ob->lay = v3d->layact;
12234
 
                                                } else {
12235
 
                                                        ob->lay = scene->lay;
12236
 
                                                }
12237
 
                                        }
12238
 
                                        ob->mode= 0;
12239
 
                                        base->lay= ob->lay;
12240
 
                                        base->object= ob;
12241
 
                                        ob->id.us++;
12242
 
                                        
12243
 
                                        if(flag & FILE_AUTOSELECT) { 
12244
 
                                                base->flag |= SELECT;
12245
 
                                                base->object->flag = base->flag;
12246
 
                                                /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
12247
 
                                        }
12248
 
                                }
12249
 
                                endloop= 1;
12250
 
                        }
12251
 
                }
12252
 
 
12253
 
                bhead = blo_nextbhead(fd, bhead);
12254
 
        }
12255
 
}
12256
 
 
12257
 
void BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, char *name, int idcode, short flag)
12258
 
{
12259
 
        FileData *fd= (FileData*)(*bh);
12260
 
        append_named_part(C, mainl, fd, name, idcode, flag);
 
14581
                                break;
 
14582
                        }
 
14583
                }
 
14584
                else if (bhead->code==ENDB) {
 
14585
                        break;
 
14586
                }
 
14587
        }
 
14588
 
 
14589
        /* if we found the id but the id is NULL, this is really bad */
 
14590
        BLI_assert((found != 0) == (id != NULL));
 
14591
 
 
14592
        return found ? id : NULL;
 
14593
}
 
14594
 
 
14595
static ID *append_named_part_ex(const bContext *C, Main *mainl, FileData *fd, const char *idname, const int idcode, const int flag)
 
14596
{
 
14597
        ID *id= append_named_part(mainl, fd, idname, idcode);
 
14598
 
 
14599
        if (id && (GS(id->name) == ID_OB)) {    /* loose object: give a base */
 
14600
                Scene *scene= CTX_data_scene(C); /* can be NULL */
 
14601
                if (scene) {
 
14602
                        Base *base;
 
14603
                        Object *ob;
 
14604
 
 
14605
                        base= MEM_callocN( sizeof(Base), "app_nam_part");
 
14606
                        BLI_addtail(&scene->base, base);
 
14607
 
 
14608
                        ob= (Object *)id;
 
14609
 
 
14610
                        /* link at active layer (view3d->lay if in context, else scene->lay */
 
14611
                        if ((flag & FILE_ACTIVELAY)) {
 
14612
                                View3D *v3d = CTX_wm_view3d(C);
 
14613
                                ob->lay = v3d ? v3d->layact : scene->lay;
 
14614
                        }
 
14615
 
 
14616
                        ob->mode= 0;
 
14617
                        base->lay= ob->lay;
 
14618
                        base->object= ob;
 
14619
                        ob->id.us++;
 
14620
 
 
14621
                        if (flag & FILE_AUTOSELECT) {
 
14622
                                base->flag |= SELECT;
 
14623
                                base->object->flag = base->flag;
 
14624
                                /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
 
14625
                        }
 
14626
                }
 
14627
        }
 
14628
 
 
14629
        return id;
 
14630
}
 
14631
 
 
14632
ID *BLO_library_append_named_part(Main *mainl, BlendHandle** bh, const char *idname, const int idcode)
 
14633
{
 
14634
        FileData *fd= (FileData*)(*bh);
 
14635
        return append_named_part(mainl, fd, idname, idcode);
 
14636
}
 
14637
 
 
14638
ID *BLO_library_append_named_part_ex(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, const int idcode, const short flag)
 
14639
{
 
14640
        FileData *fd= (FileData*)(*bh);
 
14641
        return append_named_part_ex(C, mainl, fd, idname, idcode, flag);
12261
14642
}
12262
14643
 
12263
14644
static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r)
12266
14647
 
12267
14648
        for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
12268
14649
                if (bhead->code == GS(id->name)) {
12269
 
                        
12270
 
                        if (BLI_streq(id->name, bhead_id_name(fd, bhead))) {
 
14650
 
 
14651
                        if (strcmp(id->name, bhead_id_name(fd, bhead))==0) {
12271
14652
                                id->flag &= ~LIB_READ;
12272
14653
                                id->flag |= LIB_TEST;
12273
14654
//                              printf("read lib block %s\n", id->name);
12275
14656
 
12276
14657
                                break;
12277
14658
                        }
12278
 
                } else if (bhead->code==ENDB)
 
14659
                }
 
14660
                else if (bhead->code==ENDB)
12279
14661
                        break;
12280
14662
        }
12281
14663
}
12282
14664
 
12283
14665
/* common routine to append/link something from a library */
12284
14666
 
12285
 
static Main* library_append_begin(const bContext *C, FileData **fd, char *dir)
 
14667
static Main* library_append_begin(Main *mainvar, FileData **fd, const char *filepath)
12286
14668
{
12287
 
        Main *mainvar= CTX_data_main(C);
12288
14669
        Main *mainl;
12289
14670
 
12290
14671
        /* make mains */
12291
14672
        blo_split_main(&(*fd)->mainlist, mainvar);
12292
14673
 
12293
14674
        /* which one do we need? */
12294
 
        mainl = blo_find_main(*fd, &(*fd)->mainlist, dir, G.sce);
 
14675
        mainl = blo_find_main(*fd, &(*fd)->mainlist, filepath, G.main->name);
12295
14676
        
12296
14677
        /* needed for do_version */
12297
14678
        mainl->versionfile= (*fd)->fileversion;
12300
14681
        return mainl;
12301
14682
}
12302
14683
 
12303
 
Main* BLO_library_append_begin(const bContext *C, BlendHandle** bh, char *dir)
 
14684
Main* BLO_library_append_begin(Main *mainvar, BlendHandle** bh, const char *filepath)
12304
14685
{
12305
14686
        FileData *fd= (FileData*)(*bh);
12306
 
        return library_append_begin(C, &fd, dir);
12307
 
}
12308
 
 
12309
 
static void append_do_cursor(Scene *scene, Library *curlib, short flag)
12310
 
{
12311
 
        Base *centerbase;
12312
 
        Object *ob;
12313
 
        float *curs, centerloc[3], vec[3], min[3], max[3];
12314
 
        int count= 0;
12315
 
 
12316
 
        /* when not linking (appending)... */
12317
 
        if(flag & FILE_LINK) 
12318
 
                return;
12319
 
 
12320
 
        /* we're not appending at cursor */
12321
 
        if((flag & FILE_ATCURSOR) == 0) 
12322
 
                return;
12323
 
        
12324
 
        /* find the center of everything appended */
12325
 
        INIT_MINMAX(min, max);
12326
 
        centerbase= (scene->base.first);
12327
 
        while(centerbase) {
12328
 
                if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) {
12329
 
                        VECCOPY(vec, centerbase->object->loc);
12330
 
                        DO_MINMAX(vec, min, max);
12331
 
                        count++;
12332
 
                }
12333
 
                centerbase= centerbase->next;
12334
 
        }
12335
 
        /* we haven't found any objects to move to cursor */
12336
 
        if(!count) 
12337
 
                return;
12338
 
        
12339
 
        /* move from the center of the appended objects to cursor */
12340
 
        centerloc[0]= (min[0]+max[0])/2;
12341
 
        centerloc[1]= (min[1]+max[1])/2;
12342
 
        centerloc[2]= (min[2]+max[2])/2;
12343
 
        curs = scene->cursor;
12344
 
        VECSUB(centerloc,curs,centerloc);
12345
 
        
12346
 
        /* now translate the center of the objects */
12347
 
        centerbase= (scene->base.first);
12348
 
        while(centerbase) {
12349
 
                if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) {
12350
 
                        ob= centerbase->object;
12351
 
                        ob->loc[0] += centerloc[0];
12352
 
                        ob->loc[1] += centerloc[1];
12353
 
                        ob->loc[2] += centerloc[2];
12354
 
                }
12355
 
                centerbase= centerbase->next;
12356
 
        }
12357
 
}
12358
 
 
 
14687
        return library_append_begin(mainvar, &fd, filepath);
 
14688
}
 
14689
 
 
14690
 
 
14691
/* Context == NULL signifies not to do any scene manipulation */
12359
14692
static void library_append_end(const bContext *C, Main *mainl, FileData **fd, int idcode, short flag)
12360
14693
{
12361
 
        Main *mainvar= CTX_data_main(C);
12362
 
        Scene *scene= CTX_data_scene(C);
 
14694
        Main *mainvar;
 
14695
        Library *curlib;
12363
14696
 
12364
14697
        /* make main consistent */
12365
14698
        expand_main(*fd, mainl);
12366
14699
 
12367
14700
        /* do this when expand found other libs */
12368
14701
        read_libraries(*fd, &(*fd)->mainlist);
 
14702
        
 
14703
        curlib= mainl->curlib;
12369
14704
 
12370
14705
        /* make the lib path relative if required */
12371
 
        if(flag & FILE_RELPATH) {
 
14706
        if (flag & FILE_RELPATH) {
12372
14707
 
12373
14708
                /* use the full path, this could have been read by other library even */
12374
 
                BLI_strncpy(mainl->curlib->name, mainl->curlib->filepath, sizeof(mainl->curlib->name));
 
14709
                BLI_strncpy(curlib->name, curlib->filepath, sizeof(curlib->name));
12375
14710
                
12376
14711
                /* uses current .blend file as reference */
12377
 
                BLI_path_rel(mainl->curlib->name, G.sce);
 
14712
                BLI_path_rel(curlib->name, G.main->name);
12378
14713
        }
12379
14714
 
12380
14715
        blo_join_main(&(*fd)->mainlist);
12381
14716
        mainvar= (*fd)->mainlist.first;
 
14717
        mainl= NULL; /* blo_join_main free's mainl, cant use anymore */
12382
14718
 
12383
14719
        lib_link_all(*fd, mainvar);
12384
 
        lib_verify_nodetree(mainvar, 0);
12385
 
        fix_relpaths_library(G.sce, mainvar); /* make all relative paths, relative to the open blend file */
12386
 
 
12387
 
        /* give a base to loose objects. If group append, do it for objects too */
12388
 
        if(scene) {
12389
 
                if(idcode==ID_SCE) {
12390
 
                        /* dont instance anything when linking in scenes, assume the scene its self instances the data */
 
14720
        lib_verify_nodetree(mainvar, FALSE);
 
14721
        fix_relpaths_library(G.main->name, mainvar); /* make all relative paths, relative to the open blend file */
 
14722
 
 
14723
        if (C) {
 
14724
                Scene *scene= CTX_data_scene(C);
 
14725
 
 
14726
                /* give a base to loose objects. If group append, do it for objects too */
 
14727
                if (scene) {
 
14728
                        const short is_link= (flag & FILE_LINK) != 0;
 
14729
                        if (idcode==ID_SCE) {
 
14730
                                /* don't instance anything when linking in scenes, assume the scene its self instances the data */
 
14731
                        }
 
14732
                        else {
 
14733
                                give_base_to_objects(mainvar, scene, curlib, idcode, is_link);
 
14734
 
 
14735
                                if (flag & FILE_GROUP_INSTANCE) {
 
14736
                                        give_base_to_groups(mainvar, scene);
 
14737
                                }
 
14738
                        }
12391
14739
                }
12392
 
                else if(idcode==ID_GR) {
12393
 
                        if (flag & FILE_LINK) {
12394
 
                                give_base_to_objects(mainvar, scene, NULL, 0);
12395
 
                        } else {
12396
 
                                give_base_to_objects(mainvar, scene, mainl->curlib, 1);
12397
 
                        }
12398
 
 
12399
 
                        if (flag & FILE_GROUP_INSTANCE) {
12400
 
                                give_base_to_groups(mainvar, scene);
12401
 
                        }
12402
 
                } else {
12403
 
                        give_base_to_objects(mainvar, scene, NULL, 0);
 
14740
                else {
 
14741
                        printf("library_append_end, scene is NULL (objects wont get bases)\n");
12404
14742
                }
12405
14743
        }
12406
14744
        /* has been removed... erm, why? s..ton) */
12408
14746
        /* 20041208: put back. It only linked direct, not indirect objects (ton) */
12409
14747
        
12410
14748
        /* patch to prevent switch_endian happens twice */
12411
 
        if((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) {
 
14749
        if ((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) {
12412
14750
                blo_freefiledata( *fd );
12413
14751
                *fd = NULL;
12414
14752
        }       
12415
 
 
12416
 
        append_do_cursor(scene, mainl->curlib, flag);
12417
14753
}
12418
14754
 
12419
14755
void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag)
12423
14759
        *bh= (BlendHandle*)fd;
12424
14760
}
12425
14761
 
12426
 
/* this is a version of BLO_library_append needed by the BPython API, so
12427
 
 * scripts can load data from .blend files -- see Blender.Library module.*/
12428
 
/* append to scene */
12429
 
/* this should probably be moved into the Python code anyway */
12430
 
/* tentatively removed, Python should be able to use the split functions too: */
12431
 
/* BLO_library_append_begin, BLO_library_append_end, BLO_library_append_named_part */
12432
 
#if 0 
12433
 
void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, 
12434
 
                int idcode, short flag, Main *mainvar, Scene *scene, ReportList *reports)
 
14762
void *BLO_library_read_struct(FileData *fd, BHead *bh, const char *blockname)
12435
14763
{
12436
 
        FileData *fd= (FileData*)(*bh);
12437
 
 
12438
 
        /* try to append the requested object */
12439
 
        fd->reports= reports;
12440
 
        library_append(mainvar, scene, name, dir, idcode, 0, &fd, NULL, 0, flag );
12441
 
        if(fd) fd->reports= NULL;
12442
 
 
12443
 
        /* do we need to do this? */
12444
 
        if(scene)
12445
 
                DAG_scene_sort(scene);
12446
 
 
12447
 
        *bh= (BlendHandle*)fd;
 
14764
        return read_struct(fd, bh, blockname);
12448
14765
}
12449
 
#endif
12450
14766
 
12451
14767
/* ************* READ LIBRARY ************** */
12452
14768
 
12456
14772
        int a, tot= 0;
12457
14773
 
12458
14774
        a= set_listbasepointers(mainvar, lbarray);
12459
 
        while(a--) {
12460
 
                ID *id= lbarray[a]->first;
 
14775
        while (a--) {
 
14776
                ID *id;
12461
14777
 
12462
14778
                for (id= lbarray[a]->first; id; id= id->next)
12463
14779
                        if (id->flag & LIB_READ)
12473
14789
        ListBase *lbarray[MAX_LIBARRAY];
12474
14790
        int a, doit= 1;
12475
14791
 
12476
 
        while(doit) {
 
14792
        while (doit) {
12477
14793
                doit= 0;
12478
14794
 
12479
14795
                /* test 1: read libdata */
12480
14796
                mainptr= mainl->next;
12481
 
                while(mainptr) {
 
14797
                while (mainptr) {
12482
14798
                        int tot= mainvar_count_libread_blocks(mainptr);
12483
14799
                        
12484
14800
                        // printf("found LIB_READ %s\n", mainptr->curlib->name);
12485
 
                        if(tot) {
 
14801
                        if (tot) {
12486
14802
                                FileData *fd= mainptr->curlib->filedata;
12487
14803
 
12488
 
                                if(fd==NULL) {
 
14804
                                if (fd==NULL) {
12489
14805
 
12490
14806
                                        /* printf and reports for now... its important users know this */
12491
 
                                        BKE_reportf(basefd->reports, RPT_INFO, "read library:  '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
12492
 
                                        if(!G.background && basefd->reports) printf("read library: '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
 
14807
                                        BKE_reportf_wrap(basefd->reports, RPT_INFO,
 
14808
                                                         "read library:  '%s', '%s'\n",
 
14809
                                                         mainptr->curlib->filepath, mainptr->curlib->name);
12493
14810
 
12494
14811
                                        fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
12495
14812
                                        
12496
14813
                                        /* allow typing in a new lib path */
12497
 
                                        if(G.rt==-666) {
12498
 
                                                while(fd==NULL) {
12499
 
                                                        char newlib_path[240] = { 0 };
 
14814
                                        if (G.rt==-666) {
 
14815
                                                while (fd==NULL) {
 
14816
                                                        char newlib_path[FILE_MAX] = { 0 };
12500
14817
                                                        printf("Missing library...'\n");
12501
 
                                                        printf("        current file: %s\n", G.sce);
 
14818
                                                        printf("        current file: %s\n", G.main->name);
12502
14819
                                                        printf("        absolute lib: %s\n", mainptr->curlib->filepath);
12503
14820
                                                        printf("        relative lib: %s\n", mainptr->curlib->name);
12504
14821
                                                        printf("  enter a new path:\n");
12505
14822
 
12506
 
                                                        if(scanf("%s", newlib_path) > 0) {
12507
 
                                                                strcpy(mainptr->curlib->name, newlib_path);
12508
 
                                                                strcpy(mainptr->curlib->filepath, newlib_path);
12509
 
                                                                cleanup_path(G.sce, mainptr->curlib->filepath);
 
14823
                                                        if (scanf("%s", newlib_path) > 0) {
 
14824
                                                                BLI_strncpy(mainptr->curlib->name, newlib_path, sizeof(mainptr->curlib->name));
 
14825
                                                                BLI_strncpy(mainptr->curlib->filepath, newlib_path, sizeof(mainptr->curlib->filepath));
 
14826
                                                                cleanup_path(G.main->name, mainptr->curlib->filepath);
12510
14827
                                                                
12511
14828
                                                                fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
12512
14829
 
12513
 
                                                                if(fd) {
 
14830
                                                                if (fd) {
12514
14831
                                                                        printf("found: '%s', party on macuno!\n", mainptr->curlib->filepath);
12515
14832
                                                                }
12516
14833
                                                        }
12534
14851
                                        else mainptr->curlib->filedata= NULL;
12535
14852
 
12536
14853
                                        if (fd==NULL) {
12537
 
                                                BKE_reportf(basefd->reports, RPT_ERROR, "Can't find lib '%s'\n", mainptr->curlib->filepath);
12538
 
                                                if(!G.background && basefd->reports) printf("ERROR: can't find lib %s \n", mainptr->curlib->filepath);
 
14854
                                                BKE_reportf_wrap(basefd->reports, RPT_ERROR,
 
14855
                                                                 "Can't find lib '%s'\n",
 
14856
                                                                 mainptr->curlib->filepath);
12539
14857
                                        }
12540
14858
                                }
12541
 
                                if(fd) {
 
14859
                                if (fd) {
12542
14860
                                        doit= 1;
12543
14861
                                        a= set_listbasepointers(mainptr, lbarray);
12544
 
                                        while(a--) {
 
14862
                                        while (a--) {
12545
14863
                                                ID *id= lbarray[a]->first;
12546
14864
 
12547
 
                                                while(id) {
 
14865
                                                while (id) {
12548
14866
                                                        ID *idn= id->next;
12549
 
                                                        if(id->flag & LIB_READ) {
 
14867
                                                        if (id->flag & LIB_READ) {
12550
14868
                                                                ID *realid= NULL;
12551
14869
                                                                BLI_remlink(lbarray[a], id);
12552
14870
 
12553
14871
                                                                append_id_part(fd, mainptr, id, &realid);
12554
14872
                                                                if (!realid) {
12555
 
                                                                        BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
12556
 
                                                                        if(!G.background && basefd->reports) printf("LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
 
14873
                                                                        BKE_reportf_wrap(fd->reports, RPT_ERROR,
 
14874
                                                                                         "LIB ERROR: %s:'%s' missing from '%s'\n",
 
14875
                                                                                         BKE_idcode_to_name(GS(id->name)),
 
14876
                                                                                         id->name+2, mainptr->curlib->filepath);
12557
14877
                                                                }
12558
14878
                                                                
12559
14879
                                                                change_idid_adr(mainlist, basefd, id, realid);
12566
14886
 
12567
14887
                                        expand_main(fd, mainptr);
12568
14888
                                        
12569
 
                                        /* dang FileData... now new libraries need to be appended to original filedata, it is not a good replacement for the old global (ton) */
12570
 
                                        while( fd->mainlist.first ) {
 
14889
                                        /* dang FileData... now new libraries need to be appended to original filedata,
 
14890
                                         * it is not a good replacement for the old global (ton) */
 
14891
                                        while ( fd->mainlist.first ) {
12571
14892
                                                Main *mp= fd->mainlist.first;
12572
14893
                                                BLI_remlink(&fd->mainlist, mp);
12573
14894
                                                BLI_addtail(&basefd->mainlist, mp);
12580
14901
        }
12581
14902
        
12582
14903
        /* test if there are unread libblocks */
12583
 
        for(mainptr= mainl->next; mainptr; mainptr= mainptr->next) {
 
14904
        for (mainptr= mainl->next; mainptr; mainptr= mainptr->next) {
12584
14905
                a= set_listbasepointers(mainptr, lbarray);
12585
 
                while(a--) {
 
14906
                while (a--) {
12586
14907
                        ID *id= lbarray[a]->first;
12587
 
                        while(id) {
 
14908
                        while (id) {
12588
14909
                                ID *idn= id->next;
12589
 
                                if(id->flag & LIB_READ) {
 
14910
                                if (id->flag & LIB_READ) {
12590
14911
                                        BLI_remlink(lbarray[a], id);
12591
 
                                        BKE_reportf(basefd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
12592
 
                                        if(!G.background && basefd->reports)printf("LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
 
14912
                                        BKE_reportf_wrap(basefd->reports, RPT_ERROR,
 
14913
                                                         "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n",
 
14914
                                                         BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
12593
14915
                                        change_idid_adr(mainlist, basefd, id, NULL);
12594
14916
 
12595
14917
                                        MEM_freeN(id);
12600
14922
        }
12601
14923
        
12602
14924
        /* do versions, link, and free */
12603
 
        for(mainptr= mainl->next; mainptr; mainptr= mainptr->next) {
 
14925
        for (mainptr= mainl->next; mainptr; mainptr= mainptr->next) {
12604
14926
                /* some mains still have to be read, then
12605
14927
                 * versionfile is still zero! */
12606
 
                if(mainptr->versionfile) {
12607
 
                        if(mainptr->curlib->filedata) // can be zero... with shift+f1 append
 
14928
                if (mainptr->versionfile) {
 
14929
                        if (mainptr->curlib->filedata) // can be zero... with shift+f1 append
12608
14930
                                do_versions(mainptr->curlib->filedata, mainptr->curlib, mainptr);
12609
14931
                        else
12610
14932
                                do_versions(basefd, NULL, mainptr);
12611
14933
                }
12612
14934
                
12613
 
                if(mainptr->curlib->filedata)
 
14935
                if (mainptr->curlib->filedata)
12614
14936
                        lib_link_all(mainptr->curlib->filedata, mainptr);
12615
14937
                
12616
 
                if(mainptr->curlib->filedata) blo_freefiledata(mainptr->curlib->filedata);
 
14938
                if (mainptr->curlib->filedata) blo_freefiledata(mainptr->curlib->filedata);
12617
14939
                mainptr->curlib->filedata= NULL;
12618
14940
        }
12619
14941
}
12621
14943
 
12622
14944
/* reading runtime */
12623
14945
 
12624
 
BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize, ReportList *reports)
 
14946
BlendFileData *blo_read_blendafterruntime(int file, const char *name, int actualsize, ReportList *reports)
12625
14947
{
12626
14948
        BlendFileData *bfd = NULL;
12627
14949
        FileData *fd = filedata_new();