Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenloader / intern / readfile.c
index 80597b8..cb67fe0 100644 (file)
@@ -59,6 +59,7 @@
 #include "DNA_actuator_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_camera_types.h"
+#include "DNA_cachefile_types.h"
 #include "DNA_cloth_types.h"
 #include "DNA_controller_types.h"
 #include "DNA_constraint_types.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_brush.h"
+#include "BKE_cachefile.h"
 #include "BKE_cloth.h"
 #include "BKE_constraint.h"
 #include "BKE_context.h"
 #include "BKE_sequencer.h"
 #include "BKE_outliner_treehash.h"
 #include "BKE_sound.h"
-
+#include "BKE_colortools.h"
 
 #include "NOD_common.h"
 #include "NOD_socket.h"
@@ -2689,6 +2691,36 @@ static void direct_link_animdata(FileData *fd, AnimData *adt)
        adt->actstrip = newdataadr(fd, adt->actstrip);
 }      
 
+/* ************ READ CACHEFILES *************** */
+
+static void lib_link_cachefiles(FileData *fd, Main *bmain)
+{
+       CacheFile *cache_file;
+
+       /* only link ID pointers */
+       for (cache_file = bmain->cachefiles.first; cache_file; cache_file = cache_file->id.next) {
+               if (cache_file->id.tag & LIB_TAG_NEED_LINK) {
+                       cache_file->id.tag &= ~LIB_TAG_NEED_LINK;
+               }
+
+               BLI_listbase_clear(&cache_file->object_paths);
+               cache_file->handle = NULL;
+
+               if (cache_file->adt) {
+                       lib_link_animdata(fd, &cache_file->id, cache_file->adt);
+               }
+       }
+}
+
+static void direct_link_cachefile(FileData *fd, CacheFile *cache_file)
+{
+       cache_file->handle = NULL;
+
+       /* relink animdata */
+       cache_file->adt = newdataadr(fd, cache_file->adt);
+       direct_link_animdata(fd, cache_file->adt);
+}
+
 /* ************ READ MOTION PATHS *************** */
 
 /* direct data for cache */
@@ -4554,8 +4586,11 @@ static void lib_link_object(FileData *fd, Main *main)
                        if (ob->pd)
                                lib_link_partdeflect(fd, &ob->id, ob->pd);
                        
-                       if (ob->soft)
+                       if (ob->soft) {
+                               ob->soft->collision_group = newlibadr(fd, ob->id.lib, ob->soft->collision_group);
+
                                ob->soft->effector_weights->group = newlibadr(fd, ob->id.lib, ob->soft->effector_weights->group);
+                       }
                        
                        lib_link_modifiers(fd, ob);
 
@@ -5488,6 +5523,22 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                        sce->toolsettings->wpaint->wpaint_prev = NULL;
                        sce->toolsettings->wpaint->tot = 0;
                }
+               /* relink grease pencil drawing brushes */
+               link_list(fd, &sce->toolsettings->gp_brushes);
+               for (bGPDbrush *brush = sce->toolsettings->gp_brushes.first; brush; brush = brush->next) {
+                       brush->cur_sensitivity = newdataadr(fd, brush->cur_sensitivity);
+                       if (brush->cur_sensitivity) {
+                               direct_link_curvemapping(fd, brush->cur_sensitivity);
+                       }
+                       brush->cur_strength = newdataadr(fd, brush->cur_strength);
+                       if (brush->cur_strength) {
+                               direct_link_curvemapping(fd, brush->cur_strength);
+                       }
+                       brush->cur_jitter = newdataadr(fd, brush->cur_jitter);
+                       if (brush->cur_jitter) {
+                               direct_link_curvemapping(fd, brush->cur_jitter);
+                       }
+               }
        }
 
        if (sce->ed) {
@@ -5763,7 +5814,8 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
        bGPDlayer *gpl;
        bGPDframe *gpf;
        bGPDstroke *gps;
-       
+       bGPDpalette *palette;
+
        /* we must firstly have some grease-pencil data to link! */
        if (gpd == NULL)
                return;
@@ -5771,11 +5823,19 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
        /* relink animdata */
        gpd->adt = newdataadr(fd, gpd->adt);
        direct_link_animdata(fd, gpd->adt);
-       
+
+       /* relink palettes */
+       link_list(fd, &gpd->palettes);
+       for (palette = gpd->palettes.first; palette; palette = palette->next) {
+               link_list(fd, &palette->colors);
+       }
+
        /* relink layers */
        link_list(fd, &gpd->layers);
        
        for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+               /* parent */
+               gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent);
                /* relink frames */
                link_list(fd, &gpl->frames);
                gpl->actframe = newdataadr(fd, gpl->actframe);
@@ -5788,9 +5848,12 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
                                gps->points = newdataadr(fd, gps->points);
                                
                                /* the triangulation is not saved, so need to be recalculated */
-                               gps->flag |= GP_STROKE_RECALC_CACHES;
                                gps->triangles = NULL;
                                gps->tot_triangles = 0;
+                               gps->flag |= GP_STROKE_RECALC_CACHES;
+                               /* the color pointer is not saved, so need to be recalculated using the color name */
+                               gps->palcolor = NULL;
+                               gps->flag |= GP_STROKE_RECALC_COLOR;
                        }
                }
        }
@@ -5947,10 +6010,8 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                snode->id = newlibadr(fd, sc->id.lib, snode->id);
                                                snode->from = newlibadr(fd, sc->id.lib, snode->from);
                                                
-                                               if (snode->id) {
-                                                       ntree = ntreeFromID(snode->id);
-                                                       snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree);
-                                               }
+                                               ntree = snode->id ? ntreeFromID(snode->id) : NULL;
+                                               snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree);
                                                
                                                for (path = snode->treepath.first; path; path = path->next) {
                                                        if (path == snode->treepath.first) {
@@ -6329,11 +6390,8 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
                                        snode->id = restore_pointer_by_name(id_map, snode->id, USER_REAL);
                                        snode->from = restore_pointer_by_name(id_map, snode->from, USER_IGNORE);
                                        
-                                       if (snode->id) {
-                                               ntree = ntreeFromID(snode->id);
-                                               snode->nodetree = ntree ? ntree :
-                                                                         restore_pointer_by_name(id_map, (ID *)snode->nodetree, USER_REAL);
-                                       }
+                                       ntree = snode->id ? ntreeFromID(snode->id) : NULL;
+                                       snode->nodetree = ntree ? ntree : restore_pointer_by_name(id_map, (ID *)snode->nodetree, USER_REAL);
                                        
                                        for (path = snode->treepath.first; path; path = path->next) {
                                                if (path == snode->treepath.first) {
@@ -7497,6 +7555,7 @@ static const char *dataname(short id_code)
                case ID_MC: return "Data from MC";
                case ID_MSK: return "Data from MSK";
                case ID_LS: return "Data from LS";
+               case ID_CF: return "Data from CF";
        }
        return "Data from Lib Block";
        
@@ -7745,6 +7804,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
                case ID_PC:
                        direct_link_paint_curve(fd, (PaintCurve *)id);
                        break;
+               case ID_CF:
+                       direct_link_cachefile(fd, (CacheFile *)id);
+                       break;
        }
        
        oldnewmap_free_unused(fd->datamap);
@@ -7937,6 +7999,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_mask(fd, main);
        lib_link_linestyle(fd, main);
        lib_link_gpencil(fd, main);
+       lib_link_cachefiles(fd, main);
 
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
        
@@ -8797,7 +8860,7 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
                expand_doit(fd, mainvar, ob->proxy);
        if (ob->proxy_group)
                expand_doit(fd, mainvar, ob->proxy_group);
-       
+
        for (sens = ob->sensors.first; sens; sens = sens->next) {
                if (sens->type == SENS_MESSAGE) {
                        bMessageSensor *ms = sens->data;
@@ -8876,8 +8939,18 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
                }
        }
        
-       if (ob->pd && ob->pd->tex)
+       if (ob->pd) {
                expand_doit(fd, mainvar, ob->pd->tex);
+               expand_doit(fd, mainvar, ob->pd->f_source);
+       }
+
+       if (ob->soft) {
+               expand_doit(fd, mainvar, ob->soft->collision_group);
+
+               if (ob->soft->effector_weights) {
+                       expand_doit(fd, mainvar, ob->soft->effector_weights->group);
+               }
+       }
 
        if (ob->rigidbody_constraint) {
                expand_doit(fd, mainvar, ob->rigidbody_constraint->ob1);
@@ -8977,6 +9050,13 @@ static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
                expand_animdata(fd, mainvar, ca->adt);
 }
 
+static void expand_cachefile(FileData *fd, Main *mainvar, CacheFile *cache_file)
+{
+       if (cache_file->adt) {
+               expand_animdata(fd, mainvar, cache_file->adt);
+       }
+}
+
 static void expand_speaker(FileData *fd, Main *mainvar, Speaker *spk)
 {
        expand_doit(fd, mainvar, spk->sound);
@@ -9169,6 +9249,9 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
                                        case ID_GD:
                                                expand_gpencil(fd, mainvar, (bGPdata *)id);
                                                break;
+                                       case ID_CF:
+                                               expand_cachefile(fd, mainvar, (CacheFile *)id);
+                                               break;
                                        }
                                        
                                        do_it = true;