* Merged changes in the trunk up to revision 33492.
[blender-staging.git] / source / blender / blenloader / intern / readfile.c
index 20ef7f04daf38b1d51ec603351cee2e8fc7ed3f7..c21a882454fcebe024ca0677d19b6043031e52cb 100644 (file)
@@ -62,6 +62,7 @@
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_lamp_types.h"
+#include "DNA_linestyle_types.h"
 #include "DNA_meta_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
@@ -4190,6 +4191,7 @@ static void lib_link_scene(FileData *fd, Main *main)
        Base *base, *next;
        Sequence *seq;
        SceneRenderLayer *srl;
+       FreestyleLineSet *fls;
        TimeMarker *marker;
        
        sce= main->scene.first;
@@ -4270,6 +4272,10 @@ static void lib_link_scene(FileData *fd, Main *main)
                        for(srl= sce->r.layers.first; srl; srl= srl->next) {
                                srl->mat_override= newlibadr_us(fd, sce->id.lib, srl->mat_override);
                                srl->light_override= newlibadr_us(fd, sce->id.lib, srl->light_override);
+                               for(fls=srl->freestyleConfig.linesets.first; fls; fls= fls->next) {
+                                       fls->linestyle= newlibadr_us(fd, sce->id.lib, fls->linestyle);
+                                       fls->group= newlibadr_us(fd, sce->id.lib, fls->group);
+                               }
                        }
                        /*Game Settings: Dome Warp Text*/
                        sce->gm.dome.warptext= newlibadr(fd, sce->id.lib, sce->gm.dome.warptext);
@@ -4304,6 +4310,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        Editing *ed;
        Sequence *seq;
        MetaStack *ms;
+       SceneRenderLayer *srl;
 
        sce->theDag = NULL;
        sce->dagisvalid = 0;
@@ -4473,6 +4480,13 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        link_list(fd, &(sce->transform_spaces));
        link_list(fd, &(sce->r.layers));
 
+       for(srl= sce->r.layers.first; srl; srl= srl->next) {
+               link_list(fd, &(srl->freestyleConfig.modules));
+       }
+       for(srl= sce->r.layers.first; srl; srl= srl->next) {
+               link_list(fd, &(srl->freestyleConfig.linesets));
+       }
+       
        sce->nodetree= newdataadr(fd, sce->nodetree);
        if(sce->nodetree)
                direct_link_nodetree(fd, sce->nodetree);
@@ -5407,6 +5421,138 @@ static void lib_link_group(FileData *fd, Main *main)
        }
 }
 
+/* ************ READ LINE STYLE ***************** */
+
+static void lib_link_linestyle(FileData *fd, Main *main)
+{
+       FreestyleLineStyle *linestyle;
+       LineStyleModifier *m;
+
+       linestyle = main->linestyle.first;
+       while (linestyle) {
+               if (linestyle->id.flag & LIB_NEEDLINK) {
+                       linestyle->id.flag -= LIB_NEEDLINK;
+
+                       if (linestyle->id.properties) IDP_LibLinkProperty(linestyle->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+                       if (linestyle->adt) lib_link_animdata(fd, &linestyle->id, linestyle->adt);
+                       for (m = linestyle->color_modifiers.first; m; m = m->next) {
+                               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+                                       LineStyleColorModifier_DistanceFromObject *cm = (LineStyleColorModifier_DistanceFromObject *)m;
+                                       cm->target = newlibadr(fd, linestyle->id.lib, cm->target);
+                               }
+                       }
+                       for (m = linestyle->alpha_modifiers.first; m; m = m->next){
+                               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+                                       LineStyleAlphaModifier_DistanceFromObject *am = (LineStyleAlphaModifier_DistanceFromObject *)m;
+                                       am->target = newlibadr(fd, linestyle->id.lib, am->target);
+                               }
+                       }
+                       for (m = linestyle->thickness_modifiers.first; m; m = m->next){
+                               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+                                       LineStyleThicknessModifier_DistanceFromObject *tm = (LineStyleThicknessModifier_DistanceFromObject *)m;
+                                       tm->target = newlibadr(fd, linestyle->id.lib, tm->target);
+                               }
+                       }
+               }
+               linestyle = linestyle->id.next;
+       }
+}
+
+static void direct_link_linestyle_color_modifier(FileData *fd, LineStyleModifier *modifier)
+{
+       switch (modifier->type) {
+       case LS_MODIFIER_ALONG_STROKE:
+               {
+                       LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier;
+                       m->color_ramp = newdataadr(fd, m->color_ramp);
+               }
+               break;
+       case LS_MODIFIER_DISTANCE_FROM_CAMERA:
+               {
+                       LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *)modifier;
+                       m->color_ramp = newdataadr(fd, m->color_ramp);
+               }
+               break;
+       case LS_MODIFIER_DISTANCE_FROM_OBJECT:
+               {
+                       LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *)modifier;
+                       m->color_ramp = newdataadr(fd, m->color_ramp);
+               }
+               break;
+       }
+}
+
+static void direct_link_linestyle_alpha_modifier(FileData *fd, LineStyleModifier *modifier)
+{
+       switch (modifier->type) {
+       case LS_MODIFIER_ALONG_STROKE:
+               {
+                       LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier;
+                       m->curve = newdataadr(fd, m->curve);
+                       direct_link_curvemapping(fd, m->curve);
+               }
+               break;
+       case LS_MODIFIER_DISTANCE_FROM_CAMERA:
+               {
+                       LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *)modifier;
+                       m->curve = newdataadr(fd, m->curve);
+                       direct_link_curvemapping(fd, m->curve);
+               }
+               break;
+       case LS_MODIFIER_DISTANCE_FROM_OBJECT:
+               {
+                       LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *)modifier;
+                       m->curve = newdataadr(fd, m->curve);
+                       direct_link_curvemapping(fd, m->curve);
+               }
+               break;
+       }
+}
+
+static void direct_link_linestyle_thickness_modifier(FileData *fd, LineStyleModifier *modifier)
+{
+       switch (modifier->type) {
+       case LS_MODIFIER_ALONG_STROKE:
+               {
+                       LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *)modifier;
+                       m->curve = newdataadr(fd, m->curve);
+                       direct_link_curvemapping(fd, m->curve);
+               }
+               break;
+       case LS_MODIFIER_DISTANCE_FROM_CAMERA:
+               {
+                       LineStyleThicknessModifier_DistanceFromCamera *m = (LineStyleThicknessModifier_DistanceFromCamera *)modifier;
+                       m->curve = newdataadr(fd, m->curve);
+                       direct_link_curvemapping(fd, m->curve);
+               }
+               break;
+       case LS_MODIFIER_DISTANCE_FROM_OBJECT:
+               {
+                       LineStyleThicknessModifier_DistanceFromObject *m = (LineStyleThicknessModifier_DistanceFromObject *)modifier;
+                       m->curve = newdataadr(fd, m->curve);
+                       direct_link_curvemapping(fd, m->curve);
+               }
+               break;
+       }
+}
+
+static void direct_link_linestyle(FileData *fd, FreestyleLineStyle *linestyle)
+{
+       LineStyleModifier *modifier;
+
+       linestyle->adt= newdataadr(fd, linestyle->adt);
+       direct_link_animdata(fd, linestyle->adt);
+       link_list(fd, &linestyle->color_modifiers);
+       for(modifier=linestyle->color_modifiers.first; modifier; modifier= modifier->next)
+               direct_link_linestyle_color_modifier(fd, modifier);
+       link_list(fd, &linestyle->alpha_modifiers);
+       for(modifier=linestyle->alpha_modifiers.first; modifier; modifier= modifier->next)
+               direct_link_linestyle_alpha_modifier(fd, modifier);
+       link_list(fd, &linestyle->thickness_modifiers);
+       for(modifier=linestyle->thickness_modifiers.first; modifier; modifier= modifier->next)
+               direct_link_linestyle_thickness_modifier(fd, modifier);
+}
+
 /* ************** GENERAL & MAIN ******************** */
 
 
@@ -5440,6 +5586,7 @@ static const char *dataname(short id_code)
                case ID_BR: return "Data from BR";
                case ID_PA: return "Data from PA";
                case ID_GD: return "Data from GD";
+               case ID_LS: return "Data from LS";
        }
        return "Data from Lib Block";
        
@@ -5607,6 +5754,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                case ID_GD:
                        direct_link_gpencil(fd, (bGPdata *)id);
                        break;
+               case ID_LS:
+                       direct_link_linestyle(fd, (FreestyleLineStyle *)id);
+                       break;
        }
        
        /*link direct data of ID properties*/
@@ -11231,6 +11381,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_nodetree(fd, main);    /* has to be done after scene/materials, this will verify group nodes */
        lib_link_brush(fd, main);
        lib_link_particlesettings(fd, main);
+       lib_link_linestyle(fd, main);
 
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
 
@@ -12154,6 +12305,25 @@ static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
        expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
 }
 
+static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *linestyle)
+{
+       LineStyleModifier *m;
+
+       if (linestyle->adt)
+               expand_animdata(fd, mainvar, linestyle->adt);
+       for (m = linestyle->color_modifiers.first; m; m = m->next) {
+               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
+                       expand_doit(fd, mainvar, ((LineStyleColorModifier_DistanceFromObject *)m)->target);
+       }
+       for (m = linestyle->alpha_modifiers.first; m; m = m->next){
+               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
+                       expand_doit(fd, mainvar, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target);
+       }
+       for (m = linestyle->thickness_modifiers.first; m; m = m->next){
+               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
+                       expand_doit(fd, mainvar, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target);
+       }
+}
 
 static void expand_main(FileData *fd, Main *mainvar)
 {
@@ -12234,6 +12404,10 @@ static void expand_main(FileData *fd, Main *mainvar)
                                                break;
                                        case ID_PA:
                                                expand_particlesettings(fd, mainvar, (ParticleSettings *)id);
+                                               break;
+                                       case ID_LS:
+                                               expand_linestyle(fd, mainvar, (FreestyleLineStyle *)id);
+                                               break;
                                        }
 
                                        doit= 1;