Merged changes in the trunk up to revision 41768.
[blender-staging.git] / source / blender / blenloader / intern / readfile.c
index 3fd661a52dae058c639f7c8e6a42defa81b2e8a7..1fc790803108273bc5f41652ea5f072ad0aec569 100644 (file)
@@ -66,6 +66,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"
@@ -4626,6 +4627,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;
@@ -4711,6 +4713,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);
@@ -4744,6 +4750,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        Editing *ed;
        Sequence *seq;
        MetaStack *ms;
+       SceneRenderLayer *srl;
 
        sce->theDag = NULL;
        sce->dagisvalid = 0;
@@ -4915,6 +4922,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);
@@ -5975,6 +5989,177 @@ static void lib_link_movieclip(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) {
+                               switch (m->type) {
+                               case LS_MODIFIER_DISTANCE_FROM_OBJECT:
+                                       {
+                                               LineStyleColorModifier_DistanceFromObject *cm = (LineStyleColorModifier_DistanceFromObject *)m;
+                                               cm->target = newlibadr(fd, linestyle->id.lib, cm->target);
+                                       }
+                                       break;
+                               }
+                       }
+                       for (m = linestyle->alpha_modifiers.first; m; m = m->next){
+                               switch (m->type) {
+                               case LS_MODIFIER_DISTANCE_FROM_OBJECT:
+                                       {
+                                               LineStyleAlphaModifier_DistanceFromObject *am = (LineStyleAlphaModifier_DistanceFromObject *)m;
+                                               am->target = newlibadr(fd, linestyle->id.lib, am->target);
+                                       }
+                                       break;
+                               }
+                       }
+                       for (m = linestyle->thickness_modifiers.first; m; m = m->next){
+                               switch (m->type) {
+                               case LS_MODIFIER_DISTANCE_FROM_OBJECT:
+                                       {
+                                               LineStyleThicknessModifier_DistanceFromObject *tm = (LineStyleThicknessModifier_DistanceFromObject *)m;
+                                               tm->target = newlibadr(fd, linestyle->id.lib, tm->target);
+                                       }
+                                       break;
+                               }
+                       }
+               }
+               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;
+       case LS_MODIFIER_MATERIAL:
+               {
+                       LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)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;
+       case LS_MODIFIER_MATERIAL:
+               {
+                       LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)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;
+       case LS_MODIFIER_MATERIAL:
+               {
+                       LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier;
+                       m->curve = newdataadr(fd, m->curve);
+                       direct_link_curvemapping(fd, m->curve);
+               }
+               break;
+       }
+}
+
+static void direct_link_linestyle_geometry_modifier(FileData *fd, LineStyleModifier *modifier)
+{
+}
+
+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);
+       link_list(fd, &linestyle->geometry_modifiers);
+       for(modifier=linestyle->geometry_modifiers.first; modifier; modifier= modifier->next)
+               direct_link_linestyle_geometry_modifier(fd, modifier);
+}
+
 /* ************** GENERAL & MAIN ******************** */
 
 
@@ -6010,6 +6195,7 @@ static const char *dataname(short id_code)
                case ID_PA: return "Data from PA";
                case ID_GD: return "Data from GD";
                case ID_MC: return "Data from MC";
+               case ID_LS: return "Data from LS";
        }
        return "Data from Lib Block";
        
@@ -6182,6 +6368,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                case ID_MC:
                        direct_link_movieclip(fd, (MovieClip *)id);
                        break;
+               case ID_LS:
+                       direct_link_linestyle(fd, (FreestyleLineStyle *)id);
+                       break;
        }
        
        /*link direct data of ID properties*/
@@ -12445,6 +12634,28 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
+       /* default values in Freestyle settings */
+       {
+               Scene *sce;
+               SceneRenderLayer *srl;
+               FreestyleLineStyle *linestyle;
+
+               for(sce = main->scene.first; sce; sce = sce->id.next) {
+                       for(srl= sce->r.layers.first; srl; srl= srl->next) {
+                               if (srl->freestyleConfig.mode == 0)
+                                       srl->freestyleConfig.mode= FREESTYLE_CONTROL_EDITOR_MODE;
+                               if (srl->freestyleConfig.raycasting_algorithm == 0)
+                                       srl->freestyleConfig.raycasting_algorithm= FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE;
+                       }
+               }
+               for(linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
+                       if (linestyle->chaining == 0)
+                               linestyle->chaining= LS_CHAINING_PLAIN;
+                       if (linestyle->rounds == 0)
+                               linestyle->rounds= 3;
+               }
+       }
+       
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 
@@ -12490,6 +12701,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_brush(fd, main);
        lib_link_particlesettings(fd, main);
        lib_link_movieclip(fd, main);
+       lib_link_linestyle(fd, main);
 
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
 
@@ -13373,6 +13585,7 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
 {
        Base *base;
        SceneRenderLayer *srl;
+       FreestyleLineSet *lineset;
 
        for(base= sce->base.first; base; base= base->next) {
                expand_doit(fd, mainvar, base->object);
@@ -13393,6 +13606,12 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
        for(srl= sce->r.layers.first; srl; srl= srl->next) {
                expand_doit(fd, mainvar, srl->mat_override);
                expand_doit(fd, mainvar, srl->light_override);
+
+               for (lineset= srl->freestyleConfig.linesets.first; lineset; lineset= lineset->next) {
+                       if (lineset->group)
+                               expand_doit(fd, mainvar, lineset->group);
+                       expand_doit(fd, mainvar, lineset->linestyle);
+               }
        }
 
        if(sce->r.dometext)
@@ -13446,6 +13665,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)
 {
@@ -13529,6 +13767,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;