Merged changes in the trunk up to revision 30952.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sun, 1 Aug 2010 23:37:52 +0000 (23:37 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sun, 1 Aug 2010 23:37:52 +0000 (23:37 +0000)
18 files changed:
1  2 
release/scripts/ui/space_userpref.py
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/scene.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/render/render_shading.c
source/blender/editors/space_outliner/outliner.c
source/blender/editors/transform/transform.c
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/shadeinput.c
source/blender/render/intern/source/shadeoutput.c
source/creator/creator.c

index be386f19b593b1eca33c8c0042b20e44747afa81,7929aa64df7cbf05d4d5eeaf3ccb9f0b92eb7da4..c083a62a98ed934a6c9baf8f1687c94bd7b015eb
@@@ -196,14 -196,7 +196,14 @@@ class USERPREF_PT_interface(bpy.types.P
          col.prop(view, "auto_perspective")
          col.prop(view, "smooth_view")
          col.prop(view, "rotation_angle")
 -
 +        
 +        col.separator()
 +        col.separator()
 +        
 +        col.label(text="2D Viewports:")
 +        col.prop(view, "view2d_grid_minimum_spacing", text="Minimum Grid Spacing")
 +        col.prop(view, "timecode_style")
 +        
          col.separator()
          col.separator()
  
@@@ -336,8 -329,7 +336,7 @@@ class USERPREF_PT_edit(bpy.types.Panel)
  
          col = row.column()
          row = col.row(align=True)
-         row.label("Overlay Color:")
-         row.prop(edit, "sculpt_paint_overlay_col", text="")
+         row.prop(edit, "sculpt_paint_overlay_col", text="Sculpt Overlay Color")
  
          col.separator()
          col.separator()
index ef47c8c35b75047e881e83c5c8d223f1369daaf5,6852a487afafe406de09ed1bd320415cb3bd6ca6..967cd5f452089f22d3db19fb9949c7cd8269b78b
@@@ -99,7 -99,6 +99,7 @@@
  #include "BKE_particle.h"
  #include "BKE_gpencil.h"
  #include "BKE_fcurve.h"
 +#include "BKE_linestyle.h"
  
  #define MAX_IDPUP             60      /* was 24 */
  
@@@ -227,8 -226,6 +227,8 @@@ int id_make_local(ID *id, int test
                        return 0; /* can't be linked */
                case ID_GD:
                        return 0; /* not implemented */
 +              case ID_LS:
 +                      return 0; /* not implemented */
        }
  
        return 0;
@@@ -265,7 -262,8 +265,8 @@@ int id_copy(ID *id, ID **newid, int tes
                        if(!test) *newid= (ID*)copy_texture((Tex*)id);
                        return 1;
                case ID_IM:
-                       return 0; /* not implemented */
+                       if(!test) *newid= (ID*)copy_image((Image*)id);
+                       return 1;
                case ID_WV:
                        return 0; /* deprecated */
                case ID_LT:
                        return 0; /* can't be copied from here */
                case ID_GD:
                        return 0; /* not implemented */
 +              case ID_LS:
 +                      return 0; /* not implemented */
        }
        
        return 0;
@@@ -418,8 -414,6 +419,8 @@@ ListBase *which_libbase(Main *mainlib, 
                        return &(mainlib->wm);
                case ID_GD:
                        return &(mainlib->gpencil);
 +              case ID_LS:
 +                      return &(mainlib->linestyle);
        }
        return 0;
  }
@@@ -500,7 -494,6 +501,7 @@@ int set_listbasepointers(Main *main, Li
        lb[a++]= &(main->library);
        lb[a++]= &(main->wm);
        lb[a++]= &(main->gpencil);
 +      lb[a++]= &(main->linestyle);
        
        lb[a]= NULL;
  
@@@ -609,9 -602,6 +610,9 @@@ static ID *alloc_libblock_notest(short 
                case ID_GD:
                        id = MEM_callocN(sizeof(bGPdata), "Grease Pencil");
                        break;
 +              case ID_LS:
 +                      id = MEM_callocN(sizeof(FreestyleLineStyle), "Freestyle Line Style");
 +                      break;
        }
        return id;
  }
@@@ -817,9 -807,6 +818,9 @@@ void free_libblock(ListBase *lb, void *
                case ID_GD:
                        free_gpencil_data((bGPdata *)id);
                        break;
 +              case ID_LS:
 +                      FRS_free_linestyle((FreestyleLineStyle *)id);
 +                      break;
        }
  
        if (id->properties) {
@@@ -1407,3 -1394,12 +1408,12 @@@ void rename_id(ID *id, char *name
        
        new_id(lb, id, name);                           
  }
+ void name_uiprefix_id(char *name, ID *id)
+ {
+       name[0] = id->lib ? 'L':' ';
+       name[1] = id->flag & LIB_FAKEUSER ? 'F':' ';
+       name[2] = ' ';
+       strcpy(name+3, id->name+2);
+ }
index 05a05c157c9fc205a3003dc0cae35548468bc66b,6b79a7b4d62420cdb406d395d0ee6e6fbc133242..8adc658fccd990b11fce8b7be4126b2cd061d9c2
@@@ -140,7 -140,6 +140,7 @@@ void init_material(Material *ma
        ma->tx_limit= 0.0;
        ma->tx_falloff= 1.0;
        ma->shad_alpha= 1.0f;
 +      ma->vcol_alpha= 0;
        
        ma->gloss_mir = ma->gloss_tra= 1.0;
        ma->samp_gloss_mir = ma->samp_gloss_tra= 18;
@@@ -784,14 -783,14 +784,14 @@@ void init_render_material(Material *mat
        }
  }
  
- void init_render_materials(int r_mode, float *amb)
+ void init_render_materials(Main *bmain, int r_mode, float *amb)
  {
        Material *ma;
        
        /* clear these flags before going over materials, to make sure they
         * are cleared only once, otherwise node materials contained in other
         * node materials can go wrong */
-       for(ma= G.main->mat.first; ma; ma= ma->id.next) {
+       for(ma= bmain->mat.first; ma; ma= ma->id.next) {
                if(ma->id.us) {
                        ma->texco= 0;
                        ma->mapto= 0;
        }
  
        /* two steps, first initialize, then or the flags for layers */
-       for(ma= G.main->mat.first; ma; ma= ma->id.next) {
+       for(ma= bmain->mat.first; ma; ma= ma->id.next) {
                /* is_used flag comes back in convertblender.c */
                ma->flag &= ~MA_IS_USED;
                if(ma->id.us) 
@@@ -816,10 -815,10 +816,10 @@@ void end_render_material(Material *mat
                ntreeEndExecTree(mat->nodetree); /* has internal flag to detect it only does it once */
  }
  
- void end_render_materials(void)
+ void end_render_materials(Main *bmain)
  {
        Material *ma;
-       for(ma= G.main->mat.first; ma; ma= ma->id.next)
+       for(ma= bmain->mat.first; ma; ma= ma->id.next)
                if(ma->id.us) 
                        end_render_material(ma);
  }
index dacf1dd730705f5a6a7df3db110a37eb6877d5c5,48cef7e1bdebae376e752a90c3715203178953c2..22f19835f5ac8302b18889b292e81fd97e32ef2e
@@@ -74,8 -74,6 +74,8 @@@
  #include "BLI_math.h"
  #include "BLI_blenlib.h"
  
 +#include "FRS_freestyle_config.h"
 +
  //XXX #include "nla.h"
  
  #ifdef WIN32
@@@ -235,8 -233,7 +235,8 @@@ Scene *copy_scene(Main *bmain, Scene *s
  void free_scene(Scene *sce)
  {
        Base *base;
 -
 +      SceneRenderLayer *srl;
 +      
        base= sce->base.first;
        while(base) {
                base->object->id.us--;
                sce->r.ffcodecdata.properties = NULL;
        }
        
 +      for(srl= sce->r.layers.first; srl; srl= srl->next) {
 +              FRS_free_freestyle_config(srl);
 +      }
 +      
        BLI_freelistN(&sce->markers);
        BLI_freelistN(&sce->transform_spaces);
        BLI_freelistN(&sce->r.layers);
@@@ -402,6 -395,7 +402,7 @@@ Scene *add_scene(char *name
        sce->toolsettings->jointrilimit = 0.8f;
  
        sce->toolsettings->selectmode= SCE_SELECT_VERTEX;
+       sce->toolsettings->uv_selectmode= UV_SELECT_VERTEX;
        sce->toolsettings->normalsize= 0.1;
        sce->toolsettings->autokey_mode= U.autokey_mode;
  
@@@ -507,7 -501,7 +508,7 @@@ Base *object_in_scene(Object *ob, Scen
        return NULL;
  }
  
- void set_scene_bg(Scene *scene)
+ void set_scene_bg(Main *bmain, Scene *scene)
  {
        Scene *sce;
        Base *base;
        int flag;
        
        /* check for cyclic sets, for reading old files but also for definite security (py?) */
-       scene_check_setscene(scene);
+       scene_check_setscene(bmain, scene);
        
        /* can happen when switching modes in other scenes */
        if(scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT))
                scene->obedit= NULL;
  
        /* deselect objects (for dataselect) */
-       for(ob= G.main->object.first; ob; ob= ob->id.next)
+       for(ob= bmain->object.first; ob; ob= ob->id.next)
                ob->flag &= ~(SELECT|OB_FROMGROUP);
  
        /* group flags again */
-       for(group= G.main->group.first; group; group= group->id.next) {
+       for(group= bmain->group.first; group; group= group->id.next) {
                go= group->gobject.first;
                while(go) {
                        if(go->ob) go->ob->flag |= OB_FROMGROUP;
        }
  
        /* sort baselist */
-       DAG_scene_sort(scene);
+       DAG_scene_sort(bmain, scene);
        
        /* ensure dags are built for sets */
        for(sce= scene->set; sce; sce= sce->set)
                if(sce->theDag==NULL)
-                       DAG_scene_sort(sce);
+                       DAG_scene_sort(bmain, sce);
  
        /* copy layers and flags from bases to objects */
        for(base= scene->base.first; base; base= base->next) {
  }
  
  /* called from creator.c */
- Scene *set_scene_name(char *name)
+ Scene *set_scene_name(Main *bmain, char *name)
  {
        Scene *sce= (Scene *)find_id("SC", name);
        if(sce) {
-               set_scene_bg(sce);
+               set_scene_bg(bmain, sce);
                printf("Scene switch: '%s' in file: '%s'\n", name, G.sce);
                return sce;
        }
@@@ -877,7 -871,7 +878,7 @@@ void scene_select_base(Scene *sce, Bas
  }
  
  /* checks for cycle, returns 1 if it's all OK */
- int scene_check_setscene(Scene *sce)
+ int scene_check_setscene(Main *bmain, Scene *sce)
  {
        Scene *scene;
        int a, totscene;
        if(sce->set==NULL) return 1;
        
        totscene= 0;
-       for(scene= G.main->scene.first; scene; scene= scene->id.next)
+       for(scene= bmain->scene.first; scene; scene= scene->id.next)
                totscene++;
        
        for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
@@@ -913,14 -907,14 +914,14 @@@ float BKE_curframe(Scene *scene
        return ctime;
  }
  
- static void scene_update_tagged_recursive(Scene *scene, Scene *scene_parent)
+ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent)
  {
        Base *base;
  
        /* sets first, we allow per definition current scene to have
           dependencies on sets, but not the other way around. */
        if(scene->set)
-               scene_update_tagged_recursive(scene->set, scene_parent);
+               scene_update_tagged_recursive(bmain, scene->set, scene_parent);
  
        for(base= scene->base.first; base; base= base->next) {
                Object *ob= base->object;
  }
  
  /* this is called in main loop, doing tagged updates before redraw */
- void scene_update_tagged(Scene *scene)
+ void scene_update_tagged(Main *bmain, Scene *scene)
  {
        scene->physics_settings.quick_cache_step= 0;
  
        /* update all objects: drivers, matrices, displists, etc. flags set
           by depgraph or manual, no layer check here, gets correct flushed */
  
-       scene_update_tagged_recursive(scene, scene);
+       scene_update_tagged_recursive(bmain, scene, scene);
  
        /* recalc scene animation data here (for sequencer) */
        {
        }
  
        if(scene->physics_settings.quick_cache_step)
-               BKE_ptcache_quick_cache_all(scene);
+               BKE_ptcache_quick_cache_all(bmain, scene);
  
        /* in the future this should handle updates for all datablocks, not
           only objects and scenes. - brecht */
  }
  
  /* applies changes right away, does all sets too */
- void scene_update_for_newframe(Scene *sce, unsigned int lay)
+ void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
  {
        float ctime = BKE_curframe(sce);
        Scene *sce_iter;
  
        for(sce_iter= sce; sce_iter; sce_iter= sce_iter->set) {
                if(sce_iter->theDag==NULL)
-                       DAG_scene_sort(sce_iter);
+                       DAG_scene_sort(bmain, sce_iter);
        }
  
  
        /* Following 2 functions are recursive
         * so dont call within 'scene_update_tagged_recursive' */
-       DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
+       DAG_scene_update_flags(bmain, sce, lay);   // only stuff that moves or needs display still
  
        /* All 'standard' (i.e. without any dependencies) animation is handled here,
         * with an 'local' to 'macro' order of evaluation. This should ensure that
         * can be overridden by settings from Scene, which owns the Texture through a hierarchy
         * such as Scene->World->MTex/Texture) can still get correctly overridden.
         */
-       BKE_animsys_evaluate_all_animation(G.main, ctime);
+       BKE_animsys_evaluate_all_animation(bmain, ctime);
        /*...done with recusrive funcs */
  
        /* object_handle_update() on all objects, groups and sets */
-       scene_update_tagged_recursive(sce, sce);
+       scene_update_tagged_recursive(bmain, sce, sce);
  }
  
  /* return default layer, also used to patch old files */
@@@ -1008,7 -1002,6 +1009,7 @@@ void scene_add_render_layer(Scene *sce
        srl->lay= (1<<20) -1;
        srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
        srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
 +      FRS_add_freestyle_config( srl );
  }
  
  /* render simplification */
index f6b8ab461d70384204f9cd46f8b8fa40f8a4c136,1fab3d894fd807aa05b46f5de5a3b73cc073e8b8..019cb2fa3d6006b9ac17e8d78cf7bc08915b749d
@@@ -70,7 -70,6 +70,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"
@@@ -4137,7 -4136,6 +4137,7 @@@ static void lib_link_scene(FileData *fd
        Base *base, *next;
        Sequence *seq;
        SceneRenderLayer *srl;
 +      FreestyleLineSet *fls;
        TimeMarker *marker;
        
        sce= main->scene.first;
                        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);
 +                              }
                        }
                        /*Game Settings: Dome Warp Text*/
                        sce->gm.dome.warptext= newlibadr(fd, sce->id.lib, sce->gm.dome.warptext);
@@@ -4261,7 -4256,6 +4261,7 @@@ static void direct_link_scene(FileData 
        Editing *ed;
        Sequence *seq;
        MetaStack *ms;
 +      SceneRenderLayer *srl;
  
        sce->theDag = NULL;
        sce->dagisvalid = 0;
        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);
@@@ -5379,130 -5366,6 +5379,130 @@@ static void lib_link_group(FileData *fd
        }
  }
  
 +/* ************ READ LINE STYLE ***************** */
 +
 +static void lib_link_linestyle(FileData *fd, Main *main)
 +{
 +      FreestyleLineStyle *linestyle;
 +      LineStyleModifier *m;
 +
 +      linestyle = main->linestyle.first;
 +      while (linestyle) {
 +              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;
 +
 +      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 ******************** */
  
  
@@@ -5536,7 -5399,6 +5536,7 @@@ static 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";
        
@@@ -5703,9 -5565,6 +5703,9 @@@ static BHead *read_libblock(FileData *f
                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*/
@@@ -11219,10 -11078,6 +11219,6 @@@ static void do_versions(FileData *fd, L
  
                                                if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
                                                {
-                                                       GroupObject *go = NULL;
-                                                       Base *base = NULL;
-                                                       Scene *scene = NULL;
                                                        smd->domain->vorticity = 2.0f;
                                                        smd->domain->time_scale = 1.0f;
  
@@@ -11308,7 -11163,6 +11304,7 @@@ static void lib_link_all(FileData *fd, 
        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 */
  
@@@ -12228,23 -12082,6 +12224,23 @@@ static void expand_sound(FileData *fd, 
        expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
  }
  
 +static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *linestyle)
 +{
 +      LineStyleModifier *m;
 +
 +      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)
  {
                                                break;
                                        case ID_PA:
                                                expand_particlesettings(fd, mainvar, (ParticleSettings *)id);
 +                                              break;
 +                                      case ID_LS:
 +                                              expand_linestyle(fd, mainvar, (FreestyleLineStyle *)id);
 +                                              break;
                                        }
  
                                        doit= 1;
@@@ -12573,9 -12406,7 +12569,7 @@@ static void append_do_cursor(Scene *sce
                return;
        
        /* move from the center of the appended objects to cursor */
-       centerloc[0]= (min[0]+max[0])/2;
-       centerloc[1]= (min[1]+max[1])/2;
-       centerloc[2]= (min[2]+max[2])/2;
+       mid_v3_v3v3(centerloc, min, max);
        curs = scene->cursor;
        VECSUB(centerloc,curs,centerloc);
        
@@@ -12678,7 -12509,7 +12672,7 @@@ void BLO_script_library_append(BlendHan
  
        /* do we need to do this? */
        if(scene)
-               DAG_scene_sort(scene);
+               DAG_scene_sort(bmain, scene);
  
        *bh= (BlendHandle*)fd;
  }
index 4c7747a57ac429fdda9f13bdd03e822b0f5b6e09,3d32030326f1b6547f35c2337166bd072044c303..773e9ddc2d49d5dd9867fe87ffdbe88809c01238
@@@ -121,8 -121,6 +121,8 @@@ void uiTemplateDopeSheetFilter(uiLayou
                uiItemR(row, ptr, "display_armature", 0, "", 0);
        if (mainptr && mainptr->particle.first)
                uiItemR(row, ptr, "display_particle", 0, "", 0);
 +      if (mainptr && mainptr->linestyle.first)
 +              uiItemR(row, ptr, "display_linestyle", 0, "", 0);
        
        /* group-based filtering (only when groups are available */
        if (mainptr && mainptr->group.first) {
@@@ -220,9 -218,12 +220,12 @@@ static void id_search_cb(const bContex
                                        continue;
  
                        if(BLI_strcasestr(id->name+2, str)) {
+                               char name_ui[32];
+                               name_uiprefix_id(name_ui, id);
                                iconid= ui_id_icon_get((bContext*)C, id, 1);
  
-                               if(!uiSearchItemAdd(items, id->name+2, id, iconid))
+                               if(!uiSearchItemAdd(items, name_ui, id, iconid))
                                        break;
                        }
                }
@@@ -960,6 -961,7 +963,7 @@@ uiLayout *uiTemplateModifier(uiLayout *
  
  void do_constraint_panels(bContext *C, void *arg, int event)
  {
+       Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
        
                break;  // no handling
        case B_CONSTRAINT_CHANGETARGET:
                if (ob->pose) ob->pose->flag |= POSE_RECALC;    // checks & sorts pose channels
-               DAG_scene_sort(scene);
+               DAG_scene_sort(bmain, scene);
                break;
        default:
                break;
@@@ -1304,89 -1306,30 +1308,30 @@@ static void rna_update_cb(bContext *C, 
  
  #define B_BANDCOL 1
  
- static int vergcband(const void *a1, const void *a2)
- {
-       const CBData *x1=a1, *x2=a2;
-       if( x1->pos > x2->pos ) return 1;
-       else if( x1->pos < x2->pos) return -1;
-       return 0;
- }
- static void colorband_pos_cb(bContext *C, void *cb_v, void *coba_v)
- {
-       ColorBand *coba= coba_v;
-       int a;
-       if(coba->tot<2) return;
-       for(a=0; a<coba->tot; a++) coba->data[a].cur= a;
-       qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
-       for(a=0; a<coba->tot; a++) {
-               if(coba->data[a].cur==coba->cur) {
-                       coba->cur= a;
-                       break;
-               }
-       }
-       rna_update_cb(C, cb_v, NULL);
- }
  static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v)
  {
        ColorBand *coba= coba_v;
+       float pos= 0.5f;
  
-       if(coba->tot > 0) {
-               CBData *xnew, *x1, *x2;
-               float col[4];
-               xnew= &coba->data[coba->tot];
-               if(coba->tot > 1) {
-                       if(coba->cur > 0) {
-                               x1= &coba->data[coba->cur-1];
-                               x2= &coba->data[coba->cur];
-                       }
-                       else {
-                               x1= &coba->data[coba->cur];
-                               x2= &coba->data[coba->cur+1];
-                       }
-                       xnew->pos = x1->pos + ((x2->pos - x1->pos) / 2);
-               }
-               do_colorband(coba, xnew->pos, col);
-               xnew->r= col[0];
-               xnew->g= col[1];
-               xnew->b= col[2];
-               xnew->a= col[3];
+       if(coba->tot > 1) {
+               if(coba->cur > 0)       pos= (coba->data[coba->cur-1].pos + coba->data[coba->cur].pos) * 0.5f;
+               else                            pos= (coba->data[coba->cur+1].pos + coba->data[coba->cur].pos) * 0.5f;
        }
  
-       if(coba->tot < MAXCOLORBAND-1) coba->tot++;
-       coba->cur= coba->tot-1;
-       colorband_pos_cb(C, cb_v, coba_v);
-       ED_undo_push(C, "Add colorband");
+       if(colorband_element_add(coba, pos)) {
+               rna_update_cb(C, cb_v, NULL);
+               ED_undo_push(C, "Add colorband");       
+       }
  }
  
  static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v)
  {
        ColorBand *coba= coba_v;
-       int a;
  
-       if(coba->tot<2) return;
-       for(a=coba->cur; a<coba->tot; a++) {
-               coba->data[a]= coba->data[a+1];
+       if(colorband_element_remove(coba, coba->cur)) {
+               ED_undo_push(C, "Delete colorband");
+               rna_update_cb(C, cb_v, NULL);
        }
-       if(coba->cur) coba->cur--;
-       coba->tot--;
-       ED_undo_push(C, "Delete colorband");
-       rna_update_cb(C, cb_v, NULL);
  }
  
  static void colorband_flip_cb(bContext *C, void *cb_v, void *coba_v)
@@@ -1749,7 -1692,7 +1694,7 @@@ static void curvemap_tools_dofunc(bCont
  
        switch(event) {
                case 0: /* reset */
-                       curvemap_reset(cuma, &cumap->clipr,     cumap->preset);
+                       curvemap_reset(cuma, &cumap->clipr,     cumap->preset, CURVEMAP_SLOPE_POSITIVE);
                        curvemapping_changed(cumap, 0);
                        break;
                case 1:
@@@ -1829,7 -1772,7 +1774,7 @@@ static void curvemap_buttons_reset(bCon
        
        cumap->preset = CURVE_PRESET_LINE;
        for(a=0; a<CM_TOT; a++)
-               curvemap_reset(cumap->cm+a, &cumap->clipr, cumap->preset);
+               curvemap_reset(cumap->cm+a, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE);
        
        cumap->black[0]=cumap->black[1]=cumap->black[2]= 0.0f;
        cumap->white[0]=cumap->white[1]=cumap->white[2]= 1.0f;
@@@ -2232,7 -2175,7 +2177,7 @@@ static void list_item_row(bContext *C, 
                uiBlockSetEmboss(block, UI_EMBOSS);
                uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, ptr, "use_textures", i, 0, 0, 0, 0,  NULL);
        }
 -      else if(RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
 +      else if(RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer) || itemptr->type == &RNA_FreestyleLineSet) {
                uiItemL(sub, name, icon);
                uiBlockSetEmboss(block, UI_EMBOSS);
                uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "enabled", 0, 0, 0, 0, 0,  NULL);
index cd652664f73efd058766a8c91cc0dd26226f61f4,9fd0074b9f1c20d066b1305d0a84cb8dfa5478eb..ba4052601394c3e41ae8466e7cbbbb00da038c2e
@@@ -46,7 -46,6 +46,7 @@@
  #include "BKE_icons.h"
  #include "BKE_image.h"
  #include "BKE_library.h"
 +#include "BKE_linestyle.h"
  #include "BKE_main.h"
  #include "BKE_material.h"
  #include "BKE_node.h"
  
  #include "GPU_material.h"
  
 +#include "FRS_freestyle.h"
 +
  #include "RNA_access.h"
 +#include "RNA_enum_types.h"
  
  #include "WM_api.h"
  #include "WM_types.h"
@@@ -213,6 -209,21 +213,21 @@@ static void image_changed(Main *bmain, 
                        texture_changed(bmain, tex);
  }
  
+ static void scene_changed(Main *bmain, Scene *sce)
+ {
+       Object *ob;
+       Material *ma;
+       /* glsl */
+       for(ob=bmain->object.first; ob; ob=ob->id.next)
+               if(ob->gpulamp.first)
+                       GPU_lamp_free(ob);
+       for(ma=bmain->mat.first; ma; ma=ma->id.next)
+               if(ma->gpumaterial.first)
+                       GPU_material_free(ma);
+ }
  void ED_render_id_flush_update(Main *bmain, ID *id)
  {
        if(!id)
                case ID_IM:
                        image_changed(bmain, (Image*)id);
                        break;
+               case ID_SCE:
+                       scene_changed(bmain, (Scene*)id);
+                       break;
                default:
                        break;
        }
@@@ -709,495 -723,6 +727,495 @@@ void SCENE_OT_render_layer_remove(wmOpe
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
  }
  
 +static int freestyle_module_add_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +
 +      FRS_add_module(&srl->freestyleConfig);
 +
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_module_add(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Add Freestyle Module";
 +      ot->idname= "SCENE_OT_freestyle_module_add";
 +      ot->description="Add a style module into the list of modules.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_module_add_exec;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
 +static int freestyle_module_remove_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      PointerRNA ptr= CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
 +      FreestyleModuleConfig *module= ptr.data;
 +
 +      FRS_delete_module(&srl->freestyleConfig, module);
 +
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_module_remove(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Remove Freestyle Module";
 +      ot->idname= "SCENE_OT_freestyle_module_remove";
 +      ot->description="Remove the style module from the stack.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_module_remove_exec;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
 +static int freestyle_module_move_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      PointerRNA ptr= CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
 +      FreestyleModuleConfig *module= ptr.data;
 +      int dir= RNA_enum_get(op->ptr, "direction");
 +
 +      if (dir == 1) {
 +              FRS_move_module_up(&srl->freestyleConfig, module);
 +      } else {
 +              FRS_move_module_down(&srl->freestyleConfig, module);
 +      }
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_module_move(wmOperatorType *ot)
 +{
 +      static EnumPropertyItem direction_items[] = {
 +              {1, "UP", 0, "Up", ""},
 +              {-1, "DOWN", 0, "Down", ""},
 +              {0, NULL, 0, NULL, NULL}
 +      };
 +
 +      /* identifiers */
 +      ot->name= "Move Freestyle Module";
 +      ot->idname= "SCENE_OT_freestyle_module_move";
 +      ot->description="Change the position of the style module within in the list of style modules.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_module_move_exec;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      /* props */
 +      RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN");
 +}
 +
 +static int freestyle_lineset_add_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +
 +      FRS_add_lineset(&srl->freestyleConfig);
 +
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_lineset_add(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Add Line Set";
 +      ot->idname= "SCENE_OT_freestyle_lineset_add";
 +      ot->description="Add a line set into the list of line sets.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_lineset_add_exec;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
 +static int freestyle_active_lineset_poll(bContext *C)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +
 +      return FRS_get_active_lineset(&srl->freestyleConfig) != NULL;
 +}
 +
 +static int freestyle_lineset_remove_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +
 +      FRS_delete_active_lineset(&srl->freestyleConfig);
 +
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_lineset_remove(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Remove Line Set";
 +      ot->idname= "SCENE_OT_freestyle_lineset_remove";
 +      ot->description="Remove the active line set from the list of line sets.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_lineset_remove_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
 +static int freestyle_lineset_move_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      int dir= RNA_enum_get(op->ptr, "direction");
 +
 +      if (dir == 1) {
 +              FRS_move_active_lineset_up(&srl->freestyleConfig);
 +      } else {
 +              FRS_move_active_lineset_down(&srl->freestyleConfig);
 +      }
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot)
 +{
 +      static EnumPropertyItem direction_items[] = {
 +              {1, "UP", 0, "Up", ""},
 +              {-1, "DOWN", 0, "Down", ""},
 +              {0, NULL, 0, NULL, NULL}
 +      };
 +
 +      /* identifiers */
 +      ot->name= "Move Line Set";
 +      ot->idname= "SCENE_OT_freestyle_lineset_move";
 +      ot->description="Change the position of the active line set within the list of line sets.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_lineset_move_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      /* props */
 +      RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN");
 +}
 +
 +static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig);
 +
 +      if (!lineset) {
 +              BKE_report(op->reports, RPT_ERROR, "No active lineset to add a new line style to.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      lineset->linestyle->id.us--;
 +      lineset->linestyle = FRS_new_linestyle("LineStyle", NULL);
 +
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_linestyle_new(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "New Line Style";
 +      ot->idname= "SCENE_OT_freestyle_linestyle_new";
 +      ot->description="Create a new line style, reusable by multiple line sets.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_linestyle_new_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
 +static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig);
 +      int type= RNA_enum_get(op->ptr, "type");
 +
 +      if (!lineset) {
 +              BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      if (FRS_add_linestyle_color_modifier(lineset->linestyle, type) < 0) {
 +              BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_color_modifier_add(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Add Line Color Modifier";
 +      ot->idname= "SCENE_OT_freestyle_color_modifier_add";
 +      ot->description = "Add a line color modifier to the line style associated with the active lineset.";
 +      
 +      /* api callbacks */
 +      ot->invoke= WM_menu_invoke;
 +      ot->exec= freestyle_color_modifier_add_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +      
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +      
 +      /* properties */
 +      ot->prop= RNA_def_enum(ot->srna, "type", linestyle_color_modifier_type_items, 0, "Type", "");
 +}
 +
 +static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig);
 +      int type= RNA_enum_get(op->ptr, "type");
 +
 +      if (!lineset) {
 +              BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      if (FRS_add_linestyle_alpha_modifier(lineset->linestyle, type) < 0) {
 +              BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_alpha_modifier_add(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Add Alpha Transparency Modifier";
 +      ot->idname= "SCENE_OT_freestyle_alpha_modifier_add";
 +      ot->description = "Add an alpha transparency modifier to the line style associated with the active lineset.";
 +      
 +      /* api callbacks */
 +      ot->invoke= WM_menu_invoke;
 +      ot->exec= freestyle_alpha_modifier_add_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +      
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +      
 +      /* properties */
 +      ot->prop= RNA_def_enum(ot->srna, "type", linestyle_alpha_modifier_type_items, 0, "Type", "");
 +}
 +
 +static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig);
 +      int type= RNA_enum_get(op->ptr, "type");
 +
 +      if (!lineset) {
 +              BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      if (FRS_add_linestyle_thickness_modifier(lineset->linestyle, type) < 0) {
 +              BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_thickness_modifier_add(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Add Line Thickness Modifier";
 +      ot->idname= "SCENE_OT_freestyle_thickness_modifier_add";
 +      ot->description = "Add a line thickness modifier to the line style associated with the active lineset.";
 +      
 +      /* api callbacks */
 +      ot->invoke= WM_menu_invoke;
 +      ot->exec= freestyle_thickness_modifier_add_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +      
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +      
 +      /* properties */
 +      ot->prop= RNA_def_enum(ot->srna, "type", linestyle_thickness_modifier_type_items, 0, "Type", "");
 +}
 +
 +static int freestyle_modifier_toggle_fold_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
 +      LineStyleModifier *modifier= ptr.data;
 +
 +      if (modifier->flags & LS_MODIFIER_EXPANDED)
 +              modifier->flags &= ~LS_MODIFIER_EXPANDED;
 +      else
 +              modifier->flags |= LS_MODIFIER_EXPANDED;
 +
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_modifier_toggle_fold(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Toggle Modifier Fold";
 +      ot->idname= "SCENE_OT_freestyle_modifier_toggle_fold";
 +      ot->description="Fold/expand the modifier tab.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_modifier_toggle_fold_exec;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
 +static int freestyle_get_modifier_type(PointerRNA *ptr)
 +{
 +      if (RNA_struct_is_a(ptr->type, &RNA_LineStyleColorModifier))
 +              return LS_MODIFIER_TYPE_COLOR;
 +      else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleAlphaModifier))
 +              return LS_MODIFIER_TYPE_ALPHA;
 +      else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleThicknessModifier))
 +              return LS_MODIFIER_TYPE_THICKNESS;
 +      return -1;
 +}
 +
 +static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig);
 +      PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
 +      LineStyleModifier *modifier= ptr.data;
 +
 +      if (!lineset) {
 +              BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      switch (freestyle_get_modifier_type(&ptr)) {
 +      case LS_MODIFIER_TYPE_COLOR:
 +              FRS_remove_linestyle_color_modifier(lineset->linestyle, modifier);
 +              break;
 +      case LS_MODIFIER_TYPE_ALPHA:
 +              FRS_remove_linestyle_alpha_modifier(lineset->linestyle, modifier);
 +              break;
 +      case LS_MODIFIER_TYPE_THICKNESS:
 +              FRS_remove_linestyle_thickness_modifier(lineset->linestyle, modifier);
 +              break;
 +      default:
 +              BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_modifier_remove(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Remove Modifier";
 +      ot->idname= "SCENE_OT_freestyle_modifier_remove";
 +      ot->description="Remove the modifier from the list of modifiers.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_modifier_remove_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
 +static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay);
 +      FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig);
 +      PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
 +      LineStyleModifier *modifier= ptr.data;
 +      int dir= RNA_enum_get(op->ptr, "direction");
 +
 +      if (!lineset) {
 +              BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      switch (freestyle_get_modifier_type(&ptr)) {
 +      case LS_MODIFIER_TYPE_COLOR:
 +              FRS_move_linestyle_color_modifier(lineset->linestyle, modifier, dir);
 +              break;
 +      case LS_MODIFIER_TYPE_ALPHA:
 +              FRS_move_linestyle_alpha_modifier(lineset->linestyle, modifier, dir);
 +              break;
 +      case LS_MODIFIER_TYPE_THICKNESS:
 +              FRS_move_linestyle_thickness_modifier(lineset->linestyle, modifier, dir);
 +              break;
 +      default:
 +              BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier.");
 +              return OPERATOR_CANCELLED;
 +      }
 +      WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
 +      
 +      return OPERATOR_FINISHED;
 +}
 +
 +void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
 +{
 +      static EnumPropertyItem direction_items[] = {
 +              {1, "UP", 0, "Up", ""},
 +              {-1, "DOWN", 0, "Down", ""},
 +              {0, NULL, 0, NULL, NULL}
 +      };
 +
 +      /* identifiers */
 +      ot->name= "Move Modifier";
 +      ot->idname= "SCENE_OT_freestyle_modifier_move";
 +      ot->description="Move the modifier within the list of modifiers.";
 +      
 +      /* api callbacks */
 +      ot->exec= freestyle_modifier_move_exec;
 +      ot->poll= freestyle_active_lineset_poll;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      /* props */
 +      RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN");
 +}
 +
  static int texture_slot_move(bContext *C, wmOperator *op)
  {
        ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
index fc85d2a80bb386e34ea1c75d3031e00698f3369f,ad04e28ee4a6e23ee754feb3a156106637487921..5bdcc5d37fbc79ce24fa239f11f1e7f96c363475
@@@ -3186,7 -3186,7 +3186,7 @@@ static void object_delete_cb(bContext *
                if(scene->obedit==base->object) 
                        ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
                
-               ED_base_object_free_and_unlink(scene, base);
+               ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
                te->directdata= NULL;
                tselem->id= NULL;
        }
@@@ -3337,7 -3337,7 +3337,7 @@@ void outliner_del(bContext *C, Scene *s
                ;//             del_seq();
        else {
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
-               DAG_scene_sort(scene);
+               DAG_scene_sort(CTX_data_main(C), scene);
                ED_undo_push(C, "Delete Objects");
        }
  }
@@@ -3356,6 -3356,7 +3356,7 @@@ static EnumPropertyItem prop_object_op_
  
  static int outliner_object_operation_exec(bContext *C, wmOperator *op)
  {
+       Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
        SpaceOops *soops= CTX_wm_space_outliner(C);
        int event;
        }
        else if(event==4) {
                outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
-               DAG_scene_sort(scene);
+               DAG_scene_sort(bmain, scene);
                str= "Delete Objects";
        }
        else if(event==5) {     /* disabled, see above (ton) */
@@@ -4470,6 -4471,11 +4471,6 @@@ static void outliner_draw_iconrow(bCont
        int active;
  
        for(te= lb->first; te; te= te->next) {
 -              
 -              /* exit drawing early */
 -              if((*offsx) - OL_X > xmax)
 -                      break;
 -
                tselem= TREESTORE(te);
                
                /* object hierarchy always, further constrained on level */
index ce9dcd9b7408166937a5e81d492bccd6f3a1526e,926d8ffd00744bc2c37334a47315f258a2d0435f..beeacfdc8d00740d90793a7e5b06e06053c40bfd
@@@ -556,6 -556,9 +556,6 @@@ int transformEvent(TransInfo *t, wmEven
  
        if (event->type == MOUSEMOVE)
        {
 -              if (t->modifiers & MOD_CONSTRAINT_SELECT)
 -                      t->con.mode |= CON_SELECT;
 -
                t->mval[0] = event->x - t->ar->winrct.xmin;
                t->mval[1] = event->y - t->ar->winrct.ymin;
  
@@@ -1364,17 -1367,17 +1364,17 @@@ void saveTransform(bContext *C, TransIn
                }
        }
  
-       /* XXX convert stupid flag to enum */
+       /* convert flag to enum */
        switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
        {
        case (T_PROP_EDIT|T_PROP_CONNECTED):
-               proportional = 2;
+               proportional = PROP_EDIT_CONNECTED;
                break;
        case T_PROP_EDIT:
-               proportional = 1;
+               proportional = PROP_EDIT_ON;
                break;
        default:
-               proportional = 0;
+               proportional = PROP_EDIT_OFF;
        }
  
        // If modal, save settings back in scene if not set as operator argument
  
                /* save settings if not set in operator */
                if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) {
-                       ts->proportional = proportional;
+                       if (t->obedit)
+                               ts->proportional = proportional;
+                       else
+                               ts->proportional_objects = (proportional != PROP_EDIT_OFF);
                }
  
                if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) {
@@@ -1692,9 -1698,6 +1695,9 @@@ void transformApply(const bContext *C, 
  {
        if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT)))
        {
 +              if (t->modifiers & MOD_CONSTRAINT_SELECT)
 +                      t->con.mode |= CON_SELECT;
 +
                selectConstraint(t);
                if (t->transform) {
                        t->transform(t, t->mval);  // calls recalcData()
@@@ -2171,21 -2174,19 +2174,19 @@@ void initWarp(TransInfo *t
        /* we need min/max in view space */
        for(i = 0; i < t->total; i++) {
                float center[3];
-               VECCOPY(center, t->data[i].center);
+               copy_v3_v3(center, t->data[i].center);
                mul_m3_v3(t->data[i].mtx, center);
                mul_m4_v3(t->viewmat, center);
                sub_v3_v3(center, t->viewmat[3]);
                if (i)
                        minmax_v3_v3v3(min, max, center);
                else {
-                       VECCOPY(max, center);
-                       VECCOPY(min, center);
+                       copy_v3_v3(max, center);
+                       copy_v3_v3(min, center);
                }
        }
-       
-       t->center[0]= (min[0]+max[0])/2.0f;
-       t->center[1]= (min[1]+max[1])/2.0f;
-       t->center[2]= (min[2]+max[2])/2.0f;
+       mid_v3_v3v3(t->center, min, max);
  
        if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
        t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
index 4c6ea48f692c94b7bccdd095e6e90640b1bf67f2,0000000000000000000000000000000000000000..91c0cca76c99953858697539c0ba28942169c239
mode 100644,000000..100644
--- /dev/null
@@@ -1,341 -1,0 +1,341 @@@
-       set_scene_bg( freestyle_scene );
 +# include "BlenderStrokeRenderer.h"
 +# include "../stroke/Canvas.h"
 +# include "../application/AppConfig.h"
 +
 +# include "BlenderTextureManager.h"
 +
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "DNA_camera_types.h"
 +#include "DNA_customdata_types.h"
 +#include "DNA_listBase.h"
 +#include "DNA_mesh_types.h"
 +#include "DNA_meshdata_types.h"
 +#include "DNA_object_types.h"
 +#include "DNA_screen_types.h"
 +
 +#include "BKE_customdata.h"
 +#include "BKE_global.h"
 +#include "BKE_library.h" /* free_libblock */
 +#include "BKE_material.h"
 +#include "BKE_main.h" /* struct Main */
 +#include "BKE_object.h"
 +#include "BKE_scene.h"
 +
 +#include "RE_pipeline.h"
 +
 +#ifdef __cplusplus
 +}
 +#endif
 +
 +
 +BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count)
 +:StrokeRenderer(){
 +      
 +      // TEMPORARY - need a  texture manager
 +      _textureManager = new BlenderTextureManager;
 +      _textureManager->load();
 +
 +      // Scene.New("FreestyleStrokes")
 +      old_scene = re->scene;
 +
 +      ListBase lb;
 +      char name[22];
 +      snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name+2);
 +      freestyle_scene = add_scene(name);
 +      lb = freestyle_scene->r.layers;
 +      freestyle_scene->r= old_scene->r;
 +      freestyle_scene->r.layers= lb;
-       set_scene_bg( old_scene );
++      set_scene_bg( G.main, freestyle_scene );
 +
 +      // image dimensions
 +      float ycor = ((float)re->r.yasp) / ((float)re->r.xasp);
 +      float width = freestyle_scene->r.xsch;
 +      float height = freestyle_scene->r.ysch * ycor;
 +
 +      // Camera
 +      Object* object_camera = add_object(freestyle_scene, OB_CAMERA);
 +      
 +      Camera* camera = (Camera *) object_camera->data;
 +      camera->type = CAM_ORTHO;
 +      camera->ortho_scale = max(width,height);
 +    camera->clipsta = 0.1f;
 +    camera->clipend = 100.0f;
 +
 +    _z_delta = 0.00001f;
 +    _z = camera->clipsta + _z_delta;
 +
 +    // test
 +    //_z = 999.90f; _z_delta = 0.01f;
 +      
 +      object_camera->loc[0] = 0.5 * width;
 +      object_camera->loc[1] = 0.5 * height;
 +      object_camera->loc[2] = 1.0;
 +      
 +      freestyle_scene->camera = object_camera;
 +      
 +      // Material
 +      material = add_material("stroke_material");
 +      material->mode |= MA_VERTEXCOLP;
 +      material->mode |= MA_TRANSP;
 +      material->mode |= MA_SHLESS;
 +      material->vcol_alpha = 1;
 +}
 +
 +BlenderStrokeRenderer::~BlenderStrokeRenderer(){
 +      
 +      if(0 != _textureManager)
 +      {
 +              delete _textureManager;
 +              _textureManager = 0;
 +      }
 +
 +      // The freestyle_scene object is not released here.  Instead,
 +      // the scene is released in free_all_freestyle_renders() in
 +      // source/blender/render/intern/source/pipeline.c, after the
 +      // compositor has finished.
 +
 +      // release objects and data blocks
 +      Base *b = (Base *)freestyle_scene->base.first;
 +      while(b) {
 +              Object *ob = b->object;
 +              void *data = ob->data;
 +              char name[24];
 +              strcpy(name, ob->id.name);
 +              //cout << "removing " << name[0] << name[1] << ":" << (name+2) << endl;
 +              switch (ob->type) {
 +              case OB_MESH:
 +                      free_libblock( &G.main->object, ob );
 +                      free_libblock( &G.main->mesh, data );
 +                      break;
 +              case OB_CAMERA:
 +                      free_libblock( &G.main->object, ob );
 +                      free_libblock( &G.main->camera, data );
 +                      freestyle_scene->camera = NULL;
 +                      break;
 +              default:
 +                      cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" << (name+2) << endl;
 +              }
 +              b = b->next;
 +      }
 +      BLI_freelistN( &freestyle_scene->base );
 +
 +      // release material
 +      free_libblock( &G.main->mat, material );
 +      
-       RE_RenderFreestyleStrokes(freestyle_render, freestyle_scene);
++      set_scene_bg( G.main, old_scene );
 +}
 +
 +float BlenderStrokeRenderer::get_stroke_vertex_z(void) const {
 +    float z = _z;
 +    BlenderStrokeRenderer *self = const_cast<BlenderStrokeRenderer *>(this);
 +    if (!(_z < _z_delta * 100000.0f))
 +        self->_z_delta *= 10.0f;
 +    self->_z += _z_delta;
 +    return -z;
 +}
 +
 +void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const{
 +  RenderStrokeRepBasic(iStrokeRep);
 +}
 +
 +void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
 +      
 +      ////////////////////
 +      //  Build up scene
 +      ////////////////////
 +      
 +        vector<Strip*>& strips = iStrokeRep->getStrips();
 +        Strip::vertex_container::iterator v[3];
 +        StrokeVertexRep *svRep[3];
 +        Vec3r color[3];
 +        unsigned int vertex_index;
 +        float ycor = ((float)freestyle_scene->r.yasp) / ((float)freestyle_scene->r.xasp);
 +        float width = freestyle_scene->r.xsch;
 +        float height = freestyle_scene->r.ysch * ycor;
 +        Vec2r p;
 +      
 +        for(vector<Strip*>::iterator s=strips.begin(), send=strips.end();
 +        s!=send;
 +        ++s){         
 +              
 +          Strip::vertex_container& strip_vertices = (*s)->vertices();
 +              int strip_vertex_count = (*s)->sizeStrip();
 +              int m, n, visible_faces, visible_segments;
 +              bool visible;
 +
 +              // iterate over all vertices and count visible faces and strip segments
 +              // (note: a strip segment is a series of visible faces, while two strip
 +              // segments are separated by one or more invisible faces)
 +              v[0] = strip_vertices.begin();
 +          v[1] = v[0]; ++(v[1]);
 +          v[2] = v[1]; ++(v[2]);
 +              visible_faces = visible_segments = 0;
 +              visible = false;
 +          for (n = 2; n < strip_vertex_count; n++)
 +              {
 +                      svRep[0] = *(v[0]);
 +                      svRep[1] = *(v[1]);
 +                      svRep[2] = *(v[2]);
 +                      m = 0;
 +                      for (int j = 0; j < 3; j++) {
 +                              p = svRep[j]->point2d();
 +                              if (p[0] < 0.0 || p[0] > width || p[1] < 0.0 || p[1] > height)
 +                                      m++;
 +                      }
 +                      if (m == 3) {
 +                              visible = false;
 +                      } else {
 +                              visible_faces++;
 +                              if (!visible)
 +                                      visible_segments++;
 +                              visible = true;
 +                      }
 +                      ++v[0]; ++v[1]; ++v[2];
 +              }
 +              if (visible_faces == 0)
 +                      continue;
 +
 +              // me = Mesh.New()
 +              Object* object_mesh = add_object(freestyle_scene, OB_MESH);
 +              Mesh* mesh = (Mesh *) object_mesh->data;
 +              MEM_freeN(mesh->bb);
 +              mesh->bb= NULL;
 +              mesh->id.us = 0;
 +              
 +#if 1
 +              // me.materials = [mat]
 +              mesh->mat = ( Material ** ) MEM_mallocN( 1 * sizeof( Material * ), "MaterialList" );
 +              mesh->mat[0] = material;
 +              mesh->totcol = 1;
 +              test_object_materials( (ID*) mesh );
 +#else
 +              assign_material(object_mesh, material, object_mesh->totcol+1);
 +              object_mesh->actcol= object_mesh->totcol;
 +#endif
 +              
 +              // vertices allocation
 +              mesh->totvert = visible_faces + visible_segments * 2;
 +              mesh->mvert = (MVert*) CustomData_add_layer( &mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert);
 +                      
 +              // faces allocation
 +              mesh->totface = visible_faces;
 +              mesh->mface = (MFace*) CustomData_add_layer( &mesh->fdata, CD_MFACE, CD_CALLOC, NULL, mesh->totface);
 +              
 +              // colors allocation  - me.vertexColors = True
 +              mesh->mcol = (MCol *) CustomData_add_layer( &mesh->fdata, CD_MCOL, CD_CALLOC, NULL, mesh->totface );
 +
 +              ////////////////////
 +              //  Data copy
 +              ////////////////////
 +              
 +              MVert* vertices = mesh->mvert;
 +              MFace* faces = mesh->mface;
 +              MCol* colors = mesh->mcol;
 +              
 +          v[0] = strip_vertices.begin();
 +          v[1] = v[0]; ++(v[1]);
 +          v[2] = v[1]; ++(v[2]);
 +
 +              vertex_index = 0;
 +              visible = false;
 +              
 +          for (n = 2; n < strip_vertex_count; n++)
 +              {
 +                      svRep[0] = *(v[0]);
 +                      svRep[1] = *(v[1]);
 +                      svRep[2] = *(v[2]);
 +                      m = 0;
 +                      for (int j = 0; j < 3; j++) {
 +                              p = svRep[j]->point2d();
 +                              if (p[0] < 0.0 || p[0] > width || p[1] < 0.0 || p[1] > height)
 +                                      m++;
 +                      }
 +                      if (m == 3) {
 +                              visible = false;
 +                      } else {
 +                              if (!visible) {
 +                                      vertex_index += 2;
 +
 +                                      // first vertex
 +                                      vertices->co[0] = svRep[0]->point2d()[0];
 +                                      vertices->co[1] = svRep[0]->point2d()[1];
 +                                      vertices->co[2] = get_stroke_vertex_z();
 +                                      ++vertices;
 +                                      
 +                                      // second vertex
 +                                      vertices->co[0] = svRep[1]->point2d()[0];
 +                                      vertices->co[1] = svRep[1]->point2d()[1];
 +                                      vertices->co[2] = get_stroke_vertex_z();
 +                                      ++vertices;
 +                              }
 +                              visible = true;
 +
 +                              // vertex
 +                              vertices->co[0] = svRep[2]->point2d()[0];
 +                              vertices->co[1] = svRep[2]->point2d()[1];
 +                              vertices->co[2] = get_stroke_vertex_z();
 +                              
 +                              // faces
 +                              faces->v1 = vertex_index - 2;
 +                              faces->v2 = vertex_index - 1;
 +                              faces->v3 = vertex_index;
 +                              faces->v4 = 0;
 +                              
 +                              // colors
 +                              // red and blue are swapped - cf DNA_meshdata_types.h : MCol    
 +                              color[0] = svRep[0]->color();
 +                              color[1] = svRep[1]->color();
 +                              color[2] = svRep[2]->color();
 +
 +                              colors->r = (short)(255.0f*(color[0])[2]);
 +                              colors->g = (short)(255.0f*(color[0])[1]);
 +                              colors->b = (short)(255.0f*(color[0])[0]);
 +                              colors->a = (short)(255.0f*svRep[0]->alpha());
 +                              ++colors;
 +                              
 +                              colors->r = (short)(255.0f*(color[1])[2]);
 +                              colors->g = (short)(255.0f*(color[1])[1]);
 +                              colors->b = (short)(255.0f*(color[1])[0]);
 +                              colors->a = (short)(255.0f*svRep[1]->alpha());
 +                              ++colors;
 +                              
 +                              colors->r = (short)(255.0f*(color[2])[2]);
 +                              colors->g = (short)(255.0f*(color[2])[1]);
 +                              colors->b = (short)(255.0f*(color[2])[0]);
 +                              colors->a = (short)(255.0f*svRep[2]->alpha());
 +                              ++colors;
 +
 +                              ++faces; ++vertices; ++colors;
 +                              ++vertex_index;
 +                      }
 +                      ++v[0]; ++v[1]; ++v[2];
 +
 +              } // loop over strip vertices 
 +      
 +      } // loop over strips   
 +
 +}
 +
 +Render* BlenderStrokeRenderer::RenderScene( Render *re ) {
 +    Camera *camera = (Camera *)freestyle_scene->camera->data;
 +    if (camera->clipend < _z)
 +        camera->clipend = _z + _z_delta * 100.0f;
 +    //cout << "clipsta " << camera->clipsta << ", clipend " << camera->clipend << endl;
 +
 +      freestyle_scene->r.mode &= ~( R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR );
 +      freestyle_scene->r.scemode &= ~( R_SINGLE_LAYER );
 +      freestyle_scene->r.planes = R_PLANES32;
 +      freestyle_scene->r.imtype = R_PNG;
 +      if (freestyle_scene->r.mode & R_BORDER)
 +              freestyle_scene->r.mode |= R_CROP;
 +      
 +      Render *freestyle_render = RE_NewRender(freestyle_scene->id.name);
 +
++      RE_RenderFreestyleStrokes(freestyle_render, G.main, freestyle_scene);
 +      return freestyle_render;
 +}
index cf1ec0131f0ed1604b0300b0e4f4d510f44164ee,984aa5a67051016a46943f69ea2332989a5171fd..d58bc3aa9bcc662d0c6719ac0d055264495a9d73
@@@ -40,7 -40,6 +40,7 @@@ extern "C" 
  #include "DNA_vec_types.h"
  #include "DNA_listBase.h"
  #include "DNA_ID.h"
 +#include "DNA_freestyle_types.h"
  
  struct Object;
  struct World;
@@@ -162,9 -161,6 +162,9 @@@ typedef struct SceneRenderLayer 
        
        int passflag;                   /* pass_xor has to be after passflag */
        int pass_xor;
 +      
 +      struct FreestyleConfig freestyleConfig;
 +      
  } SceneRenderLayer;
  
  /* srl->layflag */
  #define SCE_LAY_EDGE  8
  #define SCE_LAY_SKY           16
  #define SCE_LAY_STRAND        32
 -      /* flags between 32 and 0x8000 are set to 1 already, for future options */
 +#define SCE_LAY_FRS           64
 +      /* flags between 64 and 0x8000 are set to 1 already, for future options */
  
  #define SCE_LAY_ALL_Z         0x8000
  #define SCE_LAY_XOR                   0x10000
@@@ -729,11 -724,13 +729,13 @@@ typedef struct ToolSettings 
        /* Transform */
        short snap_mode, snap_flag, snap_target;
        short proportional, prop_mode;
+       char proportional_objects; /* proportional edit, object mode */
+       char pad[3];
  
-       int auto_normalize, intpad; /*auto normalizing mode in wpaint*/
+       int auto_normalize; /*auto normalizing mode in wpaint*/
  
        short sculpt_paint_settings; /* user preferences for sculpt and paint */
-       short pad;
+       short pad1;
        int sculpt_paint_unified_size; /* unified radius of brush in pixels */
        float sculpt_paint_unified_unprojected_radius;/* unified radius of brush in Blender units */
        float sculpt_paint_unified_alpha; /* unified strength of brush */
@@@ -874,7 -871,6 +876,7 @@@ typedef struct Scene 
  #define R_NO_OVERWRITE        0x400000 /* skip existing files */
  #define R_TOUCH                       0x800000 /* touch files before rendering */
  #define R_SIMPLIFY            0x1000000
 +#define R_EDGE_FRS            0x2000000 /* R_EDGE for Freestyle */
  
  /* seq_flag */
  #define R_SEQ_GL_PREV 1
index 289d4864e96aa2c4d060c4174f38b4ee6f4df23f,027120b4f35a9aa49f2ac2631eae04c23ea671d7..5aab403e71af20e375780c2e7aad81788694e226
@@@ -34,7 -34,6 +34,7 @@@
  #include "DNA_particle_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_userdef_types.h"
 +#include "DNA_linestyle_types.h"
  
  /* Include for Bake Options */
  #include "RE_pipeline.h"
@@@ -174,8 -173,6 +174,8 @@@ EnumPropertyItem image_type_items[] = 
  
  #include "RE_pipeline.h"
  
 +#include "FRS_freestyle.h"
 +
  static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
  {
        ListBaseIterator *internal= iter->internal;
@@@ -206,7 -203,7 +206,7 @@@ static Base *rna_Scene_object_link(Scen
  
        ob->recalc |= OB_RECALC_ALL;
  
-       DAG_scene_sort(scene);
+       DAG_scene_sort(G.main, scene);
  
        return base;
  }
@@@ -232,8 -229,8 +232,8 @@@ static void rna_Scene_object_unlink(Sce
        ob->id.us--;
  
        /* needed otherwise the depgraph will contain free'd objects which can crash, see [#20958] */
-       DAG_scene_sort(scene);
-       DAG_ids_flush_update(0);
+       DAG_scene_sort(G.main, scene);
+       DAG_ids_flush_update(G.main, 0);
  
        WM_main_add_notifier(NC_SCENE|ND_OB_ACTIVE, scene);
  }
@@@ -682,6 -679,13 +682,13 @@@ static int rna_RenderSettings_engine_ge
        return 0;
  }
  
+ static void rna_Scene_glsl_update(Main *bmain, Scene *unused, PointerRNA *ptr)
+ {
+       Scene *scene= (Scene*)ptr->id.data;
+       DAG_id_flush_update(&scene->id, 0);
+ }
  static void rna_RenderSettings_color_management_update(Main *bmain, Scene *unused, PointerRNA *ptr)
  {
        /* reset image nodes */
                        }
                }
        }
+       rna_Scene_glsl_update(bmain, unused, ptr);
  }
  
  static void rna_SceneRenderLayer_name_set(PointerRNA *ptr, const char *value)
@@@ -832,7 -838,7 +841,7 @@@ static void rna_Scene_use_simplify_upda
        for(SETLOOPER(scene, base))
                object_simplify_update(base->object);
        
-       DAG_ids_flush_update(0);
+       DAG_ids_flush_update(bmain, 0);
        WM_main_add_notifier(NC_GEOM|ND_DATA, NULL);
  }
  
@@@ -907,49 -913,6 +916,49 @@@ static void rna_TimeLine_remove(Scene *
        MEM_freeN(marker);
  }
  
 +static PointerRNA rna_FreestyleLineSet_linestyle_get(PointerRNA *ptr)
 +{
 +      FreestyleLineSet *lineset= (FreestyleLineSet *)ptr->data;
 +
 +      return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineStyle, lineset->linestyle);
 +}
 +
 +static void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value)
 +{
 +      FreestyleLineSet *lineset= (FreestyleLineSet*)ptr->data;
 +
 +      lineset->linestyle->id.us--;
 +      lineset->linestyle = (FreestyleLineStyle *)value.data;
 +      lineset->linestyle->id.us++;
 +}
 +
 +static PointerRNA rna_FreestyleSettings_active_lineset_get(PointerRNA *ptr)
 +{
 +      FreestyleConfig *config= (FreestyleConfig *)ptr->data;
 +      FreestyleLineSet *lineset= FRS_get_active_lineset(config);
 +      return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineSet, lineset);
 +}
 +
 +static void rna_FreestyleSettings_active_lineset_index_range(PointerRNA *ptr, int *min, int *max)
 +{
 +      FreestyleConfig *config= (FreestyleConfig *)ptr->data;
 +      *min= 0;
 +      *max= BLI_countlist(&config->linesets)-1;
 +      *max= MAX2(0, *max);
 +}
 +
 +static int rna_FreestyleSettings_active_lineset_index_get(PointerRNA *ptr)
 +{
 +      FreestyleConfig *config= (FreestyleConfig *)ptr->data;
 +      return FRS_get_active_lineset_index(config);
 +}
 +
 +static void rna_FreestyleSettings_active_lineset_index_set(PointerRNA *ptr, int value)
 +{
 +      FreestyleConfig *config= (FreestyleConfig *)ptr->data;
 +      FRS_set_active_lineset_index(config, value);
 +}
 +
  #else
  
  static void rna_def_transform_orientation(BlenderRNA *brna)
@@@ -1046,6 -1009,12 +1055,12 @@@ static void rna_def_tool_settings(Blend
        RNA_def_property_ui_text(prop, "Proportional Editing", "Proportional editing mode");
        RNA_def_property_update(prop, NC_SCENE|ND_TOOLSETTINGS, NULL); /* header redraw */
  
+       prop= RNA_def_property(srna, "proportional_editing_objects", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "proportional_objects", 0);
+       RNA_def_property_ui_text(prop, "Proportional Editing Objects", "Proportional editing object mode");
+       RNA_def_property_ui_icon(prop, ICON_PROP_OFF, 1);
+       RNA_def_property_update(prop, NC_SCENE|ND_TOOLSETTINGS, NULL); /* header redraw */
        prop= RNA_def_property(srna, "proportional_editing_falloff", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "prop_mode");
        RNA_def_property_enum_items(prop, proportional_falloff_items);
@@@ -1375,12 -1344,6 +1390,12 @@@ void rna_def_render_layer_common(Struct
        if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
  
 +      prop= RNA_def_property(srna, "freestyle", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_FRS);
 +      RNA_def_property_ui_text(prop, "Freestyle", "Render stylized strokes in this Layer.");
 +      if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 +      else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 +
        /* passes */
        prop= RNA_def_property(srna, "pass_combined", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_COMBINED);
        else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
  }
  
 +static void rna_def_freestyle_settings(BlenderRNA *brna)
 +{
 +      StructRNA *srna;
 +      PropertyRNA *prop;
 +
 +      static EnumPropertyItem negation_items[] = {
 +              {0, "INCLUSIVE", 0, "Inclusive", "Select feature edges satisfying the given edge type conditions."},
 +              {FREESTYLE_LINESET_FE_NOT, "EXCLUSIVE", 0, "Exclusive", "Select feature edges not satisfying the given edge type conditions."},
 +              {0, NULL, 0, NULL, NULL}};
 +
 +      static EnumPropertyItem combination_items[] = {
 +              {0, "AND", 0, "Logical AND", "Combine feature edge type conditions by logical AND (logical conjunction)."},
 +              {FREESTYLE_LINESET_FE_OR, "OR", 0, "Logical OR", "Combine feature edge type conditions by logical OR (logical disjunction)."},
 +              {0, NULL, 0, NULL, NULL}};
 +
 +      static EnumPropertyItem freestyle_ui_mode_items[] = {
 +              {FREESTYLE_CONTROL_SCRIPT_MODE, "SCRIPT", 0, "Python Scripting Mode", "Advanced mode for using style modules in Python"},
 +              {FREESTYLE_CONTROL_EDITOR_MODE, "EDITOR", 0, "Parameter Editor Mode", "Basic mode for interactive style parameter editing"},
 +              {0, NULL, 0, NULL, NULL}};
 +
 +      static EnumPropertyItem visibility_items[] ={
 +              {FREESTYLE_QI_VISIBLE, "VISIBLE", 0, "Visible", "Select visible feature edges."},
 +              {FREESTYLE_QI_HIDDEN, "HIDDEN", 0, "Hidden", "Select hidden feature edges."},
 +              {FREESTYLE_QI_RANGE, "RANGE", 0, "QI Range", "Select feature edges within a range of quantitative invisibility (QI) values."},
 +              {0, NULL, 0, NULL, NULL}};
 +
 +      /* FreestyleLineSet */
 +
 +      srna= RNA_def_struct(brna, "FreestyleLineSet", NULL);
 +      RNA_def_struct_ui_text(srna, "Freestyle Line Set", "Line set for associating lines and style parameters.");
 +
 +      /* access to line style settings is redirected through functions */
 +      /* to allow proper id-buttons functionality */
 +      prop= RNA_def_property(srna, "linestyle", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "FreestyleLineStyle");
 +      RNA_def_property_flag(prop, PROP_EDITABLE|PROP_NEVER_NULL);
 +      RNA_def_property_pointer_funcs(prop, "rna_FreestyleLineSet_linestyle_get", "rna_FreestyleLineSet_linestyle_set", NULL);
 +      RNA_def_property_ui_text(prop, "Line Style", "Line style settings");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
 +      RNA_def_property_string_sdna(prop, NULL, "name");
 +      RNA_def_property_ui_text(prop, "Line Set Name", "Line set name");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +      RNA_def_struct_name_property(srna, prop);
 +
 +      prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "flags", FREESTYLE_LINESET_ENABLED);
 +      RNA_def_property_ui_text(prop, "Enabled", "Enable or disable the line set.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_by_visibility", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "selection", FREESTYLE_SEL_VISIBILITY);
 +      RNA_def_property_ui_text(prop, "Selection by Visibility", "Select feature edges based on visibility.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_by_edge_types", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "selection", FREESTYLE_SEL_EDGE_TYPES);
 +      RNA_def_property_ui_text(prop, "Selection by Edge Types", "Select feature edges based on edge types.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "edge_type_negation", PROP_ENUM, PROP_NONE);
 +      RNA_def_property_enum_bitflag_sdna(prop, NULL, "flags");
 +      RNA_def_property_enum_items(prop, negation_items);
 +      RNA_def_property_ui_text(prop, "Edge Type Negation", "Set the negation operation for conditions on feature edge types.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "edge_type_combination", PROP_ENUM, PROP_NONE);
 +      RNA_def_property_enum_bitflag_sdna(prop, NULL, "flags");
 +      RNA_def_property_enum_items(prop, combination_items);
 +      RNA_def_property_ui_text(prop, "Edge Type Combination", "Set the combination operation for conditions on feature edge types.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
 +      RNA_def_property_collection_sdna(prop, NULL, "objects", NULL);
 +      RNA_def_property_struct_type(prop, "Object");
 +      RNA_def_property_ui_text(prop, "Target Objects", "A list of objects on which stylized lines are drawn.");
 +
 +      prop= RNA_def_property(srna, "select_silhouette", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_SILHOUETTE);
 +      RNA_def_property_ui_text(prop, "Silhouette", "Select silhouette edges.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_border", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_BORDER);
 +      RNA_def_property_ui_text(prop, "Border", "Select border edges.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_crease", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_CREASE);
 +      RNA_def_property_ui_text(prop, "Crease", "Select crease edges.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_ridge", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_RIDGE);
 +      RNA_def_property_ui_text(prop, "Ridge", "Select ridges.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_valley", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_VALLEY);
 +      RNA_def_property_ui_text(prop, "Valley", "Select valleys.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_suggestive_contour", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_SUGGESTIVE_CONTOUR);
 +      RNA_def_property_ui_text(prop, "Suggestive Contour", "Select suggestive contours.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_material_boundary", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_MATERIAL_BOUNDARY);
 +      RNA_def_property_ui_text(prop, "Material Boundary", "Select edges at material boundaries.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_contour", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_CONTOUR);
 +      RNA_def_property_ui_text(prop, "Contour", "Select contours.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "select_external_contour", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "edge_types", FREESTYLE_FE_EXTERNAL_CONTOUR);
 +      RNA_def_property_ui_text(prop, "External Contour", "Select external contours.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "visibility", PROP_ENUM, PROP_NONE);
 +      RNA_def_property_enum_sdna(prop, NULL, "qi");
 +      RNA_def_property_enum_items(prop, visibility_items);
 +      RNA_def_property_ui_text(prop, "Visibility", "Determine how to use visibility for feature edge selection.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "qi_start", PROP_INT, PROP_UNSIGNED);
 +      RNA_def_property_int_sdna(prop, NULL, "qi_start");
 +      RNA_def_property_range(prop, 0, INT_MAX);
 +      RNA_def_property_ui_text(prop, "Start", "First QI value of the QI range");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "qi_end", PROP_INT, PROP_UNSIGNED);
 +      RNA_def_property_int_sdna(prop, NULL, "qi_end");
 +      RNA_def_property_range(prop, 0, INT_MAX);
 +      RNA_def_property_ui_text(prop, "End", "Last QI value of the QI range");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      /* FreestyleModuleSettings */
 +
 +      srna= RNA_def_struct(brna, "FreestyleModuleSettings", NULL);
 +      RNA_def_struct_sdna(srna, "FreestyleModuleConfig");
 +      RNA_def_struct_ui_text(srna, "Freestyle Module", "Style module configuration for specifying a style module.");
 +
 +      prop= RNA_def_property(srna, "module_path", PROP_STRING, PROP_FILEPATH);
 +      RNA_def_property_string_sdna(prop, NULL, "module_path");
 +      RNA_def_property_ui_text(prop, "Module Path", "Path to a style module file.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "is_displayed", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "is_displayed", 1);
 +      RNA_def_property_ui_text(prop, "Is Displayed", "Enable this style module during the rendering.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      /* FreestyleSettings */
 +
 +      srna= RNA_def_struct(brna, "FreestyleSettings", NULL);
 +      RNA_def_struct_sdna(srna, "FreestyleConfig");
 +      RNA_def_struct_nested(brna, srna, "SceneRenderLayer");
 +      RNA_def_struct_ui_text(srna, "Frestyle Settings", "Freestyle settings for a SceneRenderLayer datablock.");
 +
 +      prop= RNA_def_property(srna, "modules", PROP_COLLECTION, PROP_NONE);
 +      RNA_def_property_collection_sdna(prop, NULL, "modules", NULL);
 +      RNA_def_property_struct_type(prop, "FreestyleModuleSettings");
 +      RNA_def_property_ui_text(prop, "Style modules", "A list of style modules (to be applied from top to bottom).");
 +
 +      prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
 +      RNA_def_property_enum_sdna(prop, NULL, "mode");
 +      RNA_def_property_enum_items(prop, freestyle_ui_mode_items);
 +      RNA_def_property_ui_text(prop, "Control Mode", "Select the Freestyle control mode");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "suggestive_contours", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "flags", FREESTYLE_SUGGESTIVE_CONTOURS_FLAG);
 +      RNA_def_property_ui_text(prop, "Suggestive Contours", "Enable suggestive contours.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "ridges_and_valleys", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "flags", FREESTYLE_RIDGES_AND_VALLEYS_FLAG);
 +      RNA_def_property_ui_text(prop, "Ridges and Valleys", "Enable ridges and valleys.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "material_boundaries", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "flags", FREESTYLE_MATERIAL_BOUNDARIES_FLAG);
 +      RNA_def_property_ui_text(prop, "Material Boundaries", "Enable material boundaries.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "sphere_radius", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_float_sdna(prop, NULL, "sphere_radius");
 +      RNA_def_property_range(prop, 0.0, 1000.0);
 +      RNA_def_property_ui_text(prop, "Sphere Radius", "Sphere radius for computing curvatures.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "dkr_epsilon", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_float_sdna(prop, NULL, "dkr_epsilon");
 +      RNA_def_property_range(prop, 0.0, 1000.0);
 +      RNA_def_property_ui_text(prop, "Kr Derivative Epsilon", "Kr derivative epsilon for computing suggestive contours.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "crease_angle", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_float_sdna(prop, NULL, "crease_angle");
 +      RNA_def_property_range(prop, 0.0, 180.0);
 +      RNA_def_property_ui_text(prop, "Crease Angle", "Angular threshold in degrees (between 0 and 180) for detecting crease edges.");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "linesets", PROP_COLLECTION, PROP_NONE);
 +      RNA_def_property_collection_sdna(prop, NULL, "linesets", NULL);
 +      RNA_def_property_struct_type(prop, "FreestyleLineSet");
 +      RNA_def_property_ui_text(prop, "Line Sets", "Line sets for associating lines and style parameters");
 +
 +      prop= RNA_def_property(srna, "active_lineset", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "FreestyleLineSet");
 +      RNA_def_property_pointer_funcs(prop, "rna_FreestyleSettings_active_lineset_get", NULL, NULL);
 +      RNA_def_property_ui_text(prop, "Active Line Set", "Active line set being displayed");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "active_lineset_index", PROP_INT, PROP_UNSIGNED);
 +      RNA_def_property_int_funcs(prop, "rna_FreestyleSettings_active_lineset_index_get", "rna_FreestyleSettings_active_lineset_index_set", "rna_FreestyleSettings_active_lineset_index_range");
 +      RNA_def_property_ui_text(prop, "Active Line Set Index", "Index of active line set slot");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +}
 +
  static void rna_def_scene_game_data(BlenderRNA *brna)
  {
        StructRNA *srna;
        prop= RNA_def_property(srna, "glsl_lights", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_LIGHTS);
        RNA_def_property_ui_text(prop, "GLSL Lights", "Use lights for GLSL rendering");
-       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
+       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, "rna_Scene_glsl_update");
  
        prop= RNA_def_property(srna, "glsl_shaders", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_SHADERS);
        RNA_def_property_ui_text(prop, "GLSL Shaders", "Use shaders for GLSL rendering");
-       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
+       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, "rna_Scene_glsl_update");
  
        prop= RNA_def_property(srna, "glsl_shadows", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_SHADOWS);
        RNA_def_property_ui_text(prop, "GLSL Shadows", "Use shadows for GLSL rendering");
-       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
+       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, "rna_Scene_glsl_update");
  
        prop= RNA_def_property(srna, "glsl_ramps", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_RAMPS);
        RNA_def_property_ui_text(prop, "GLSL Ramps", "Use ramps for GLSL rendering");
-       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
+       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, "rna_Scene_glsl_update");
  
        prop= RNA_def_property(srna, "glsl_nodes", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_NODES);
        RNA_def_property_ui_text(prop, "GLSL Nodes", "Use nodes for GLSL rendering");
-       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
+       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, "rna_Scene_glsl_update");
  
        prop= RNA_def_property(srna, "glsl_extra_textures", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_EXTRA_TEX);
        RNA_def_property_ui_text(prop, "GLSL Extra Textures", "Use extra textures like normal or specular maps for GLSL rendering");
-       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
+       RNA_def_property_update(prop, NC_SCENE|NA_EDITED, "rna_Scene_glsl_update");
  }
  
  static void rna_def_scene_render_layer(BlenderRNA *brna)
  {
        StructRNA *srna;
 +      PropertyRNA *prop;
  
        srna= RNA_def_struct(brna, "SceneRenderLayer", NULL);
        RNA_def_struct_ui_text(srna, "Scene Render Layer", "Render layer");
        RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
  
        rna_def_render_layer_common(srna, 1);
 +
 +      /* Freestyle */
 +
 +      rna_def_freestyle_settings(brna);
 +
 +      prop= RNA_def_property(srna, "freestyle_settings", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_flag(prop, PROP_NEVER_NULL);
 +      RNA_def_property_pointer_sdna(prop, NULL, "freestyleConfig");
 +      RNA_def_property_struct_type(prop, "FreestyleSettings");
 +      RNA_def_property_ui_text(prop, "Freestyle Settings", "");
  }
  
  static void rna_def_scene_render_data(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Edge Color", "");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        
 +      prop= RNA_def_property(srna, "freestyle", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "mode", R_EDGE_FRS);
 +      RNA_def_property_ui_text(prop, "Edge", "Draw stylized strokes using Freestyle.");
 +      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 +
        /* threads */
        prop= RNA_def_property(srna, "threads", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "threads");
@@@ -3472,7 -3194,7 +3487,7 @@@ void RNA_def_scene(BlenderRNA *brna
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_struct_type(prop, "GreasePencil");
        RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil datablock");
 -      
 +
        /* Transform Orientations */
        prop= RNA_def_property(srna, "orientations", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "transform_spaces", NULL);
index 378a386478d0045bdc315ba02a6ac1b45ec6f4b0,af7f3fcf38765fee788d31265a67de6669ee9098..1ec17b1ba7a517583be4eebbf05d258b96c80789
  
  struct bNodeTree;
  struct Image;
+ struct Main;
  struct NodeBlurData;
  struct Object;
- struct ReportList;
  struct RenderData;
  struct RenderEngine;
  struct RenderEngineType;
  struct RenderResult;
  struct ReportList;
+ struct ReportList;
  struct Scene;
  struct SceneRenderLayer;
  
@@@ -208,12 -209,11 +209,12 @@@ void RE_init_threadcount(Render *re)
  void RE_TileProcessor(struct Render *re);
  
  /* only RE_NewRender() needed, main Blender render calls */
- void RE_BlenderFrame(struct Render *re, struct Scene *scene, struct SceneRenderLayer *srl, unsigned int lay, int frame);
- void RE_BlenderAnim(struct Render *re, struct Scene *scene, unsigned int lay, int sfra, int efra, int tfra, struct ReportList *reports);
- void RE_RenderFreestyleStrokes(struct Render *re, struct Scene *scene);
+ void RE_BlenderFrame(struct Render *re, struct Main *bmain, struct Scene *scene, struct SceneRenderLayer *srl, unsigned int lay, int frame);
+ void RE_BlenderAnim(struct Render *re, struct Main *bmain, struct Scene *scene, unsigned int lay, int sfra, int efra, int tfra, struct ReportList *reports);
++void RE_RenderFreestyleStrokes(struct Render *re, struct Main *bmain, struct Scene *scene);
  
  /* main preview render call */
- void RE_PreviewRender(struct Render *re, struct Scene *scene);
+ void RE_PreviewRender(struct Render *re, struct Main *bmain, struct Scene *scene);
  
  void RE_ReadRenderResult(struct Scene *scene, struct Scene *scenode);
  void RE_WriteRenderResult(RenderResult *rr, char *filename, int compress);
@@@ -249,7 -249,7 +250,7 @@@ void RE_zbuf_accumulate_vecblur(struct 
  #define RE_BAKE_DISPLACEMENT  5
  #define RE_BAKE_SHADOW                        6
  
- void RE_Database_Baking(struct Render *re, struct Scene *scene, unsigned int lay, int type, struct Object *actob);
+ void RE_Database_Baking(struct Render *re, struct Main *bmain, struct Scene *scene, unsigned int lay, int type, struct Object *actob);
  
  void RE_DataBase_GetView(struct Render *re, float mat[][4]);
  void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[][4]);
index 2af3bf6d26e4e74f064088cb673c5b784f6f4275,b124102f50ba263e5ff8240c0a419e57349a4eba..65eda26ef9b7d1fa961cf7b4408096fbf229976c
@@@ -55,6 -55,7 +55,7 @@@ struct RenderBuckets
  struct ObjectInstanceRen;
  struct RayObject;
  struct RayFace;
+ struct Main;
  
  #define TABLEINITSIZE 1024
  #define LAMPINITSIZE 256
@@@ -170,7 -171,8 +171,8 @@@ struct Rende
        /* shadow counter, detect shadow-reuse for shaders */
        int shadowsamplenr[BLENDER_MAX_THREADS];
        
-       /* scene, and its full copy of renderdata and world */
+       /* main, scene, and its full copy of renderdata and world */
+       struct Main *main;
        Scene *scene;
        RenderData r;
        World wrld;
        ListBase volumes;
        ListBase volume_precache_parts;
  
 +      ListBase freestyle_renders;
 +
        /* arena for allocating data for use during render, for
                * example dynamic TFaces to go in the VlakRen structure.
                */
@@@ -589,23 -589,21 +591,21 @@@ typedef struct LampRen 
  #define R_HALO                        2
  #define R_SEC_FIELD           4
  #define R_LAMPHALO            8
- #define R_GLOB_NOPUNOFLIP     16
- #define R_NEED_TANGENT        32
- #define R_BAKE_TRACE  128
- #define R_BAKING              256
+ #define R_NEED_TANGENT        16
+ #define R_BAKE_TRACE  32
+ #define R_BAKING              64
  
  /* vlakren->flag (vlak = face in dutch) char!!! */
  #define R_SMOOTH              1
  #define R_HIDDEN              2
  /* strand flag, means special handling */
  #define R_STRAND              4
- #define R_NOPUNOFLIP  8
- #define R_FULL_OSA            16
- #define R_FACE_SPLIT  32
+ #define R_FULL_OSA            8
+ #define R_FACE_SPLIT  16
  /* Tells render to divide face other way. */
- #define R_DIVIDE_24           64      
+ #define R_DIVIDE_24           32      
  /* vertex normals are tangent or view-corrected vector, for hair strands */
- #define R_TANGENT             128             
+ #define R_TANGENT             64              
  
  /* strandbuffer->flag */
  #define R_STRAND_BSPLINE      1
index 07ffc7b804c7e96c79ba28819b8d29750a24bca0,e9004f6a90f62cd05ef5e02dd1a922dd1b22e30e..3c690d87f4a322b55f5c486d176953a94f8edf07
@@@ -42,7 -42,6 +42,7 @@@
  #include "BKE_utildefines.h"
  #include "BKE_global.h"
  #include "BKE_image.h"
 +#include "BKE_library.h"
  #include "BKE_main.h"
  #include "BKE_node.h"
  #include "BKE_object.h"
@@@ -68,9 -67,6 +68,9 @@@
  
  #include "RE_pipeline.h"
  
 +#include "FRS_freestyle.h"
 +#include "FRS_freestyle_config.h"
 +
  /* internal */
  #include "render_types.h"
  #include "renderpipeline.h"
@@@ -650,7 -646,6 +650,7 @@@ static RenderResult *new_render_result(
                rl->lay= (1<<20) -1;
                rl->layflag= 0x7FFF;    /* solid ztra halo strand */
                rl->passflag= SCE_PASS_COMBINED;
 +              FRS_add_freestyle_config( srl );
                
                re->r.actlay= 0;
        }
@@@ -1759,7 -1754,6 +1759,7 @@@ void RE_TileProcessor(Render *re
  /* ************  This part uses API, for rendering Blender scenes ********** */
  
  static int external_render_3d(Render *re, int do_all);
 +static void add_freestyle(Render *re);
  
  static void do_render_3d(Render *re)
  {
                if(!re->test_break(re->tbh))
                        add_halo_flare(re);
        
 +      /* Freestyle  */
 +      if( re->r.mode & R_EDGE_FRS && re->r.renderer==R_INTERN)
 +              if(!re->test_break(re->tbh))
 +                      add_freestyle(re);
 +              
        /* free all render verts etc */
        RE_Database_Free(re);
        
@@@ -2157,7 -2146,7 +2157,7 @@@ static void render_scene(Render *re, Sc
        resc->lay= sce->lay;
        
        /* ensure scene has depsgraph, base flags etc OK */
-       set_scene_bg(sce);
+       set_scene_bg(re->main, sce);
  
        /* copy callbacks */
        resc->display_draw= re->display_draw;
@@@ -2175,7 -2164,7 +2175,7 @@@ static void tag_scenes_for_render(Rende
        bNode *node;
        Scene *sce;
        
-       for(sce= G.main->scene.first; sce; sce= sce->id.next)
+       for(sce= re->main->scene.first; sce; sce= sce->id.next)
                sce->id.flag &= ~LIB_DOIT;
        
        re->scene->id.flag |= LIB_DOIT;
@@@ -2244,66 -2233,6 +2244,66 @@@ static void render_composit_stats(void 
  }
  
  
 +/* invokes Freestyle stroke rendering */
 +static void add_freestyle(Render *re)
 +{
 +      SceneRenderLayer *srl;
 +      LinkData *link;
 +
 +      FRS_init_stroke_rendering(re);
 +
 +      for(srl= (SceneRenderLayer *)re->scene->r.layers.first; srl; srl= srl->next) {
 +
 +              link = (LinkData *)MEM_callocN(sizeof(LinkData), "LinkData to Freestyle render");
 +              BLI_addtail(&re->freestyle_renders, link);
 +
 +              if( FRS_is_freestyle_enabled(srl) ) {
 +                      link->data = (void *)FRS_do_stroke_rendering(re, srl);
 +              }
 +      }
 +
 +      FRS_finish_stroke_rendering(re);
 +}
 +
 +/* merges the results of Freestyle stroke rendering into a given render result */
 +static void composite_freestyle_renders(Render *re, int sample)
 +{
 +      Render *freestyle_render;
 +      SceneRenderLayer *srl;
 +      LinkData *link;
 +
 +      link = (LinkData *)re->freestyle_renders.first;
 +      for(srl= (SceneRenderLayer *)re->scene->r.layers.first; srl; srl= srl->next) {
 +              if( FRS_is_freestyle_enabled(srl) ) {
 +                      freestyle_render = (Render *)link->data;
 +                      read_render_result(freestyle_render, sample);
 +                      FRS_composite_result(re, srl, freestyle_render);
 +                      RE_FreeRenderResult(freestyle_render->result);
 +                      freestyle_render->result = NULL;
 +              }
 +              link = link->next;
 +      }
 +}
 +
 +/* releases temporary scenes and renders for Freestyle stroke rendering */
 +static void free_all_freestyle_renders(void)
 +{
 +      Render *re1, *freestyle_render;
 +      LinkData *link;
 +
 +      for(re1= RenderGlobal.renderlist.first; re1; re1= re1->next) {
 +              for (link = (LinkData *)re1->freestyle_renders.first; link; link = link->next) {
 +                      if (link->data) {
 +                              freestyle_render = (Render *)link->data;
 +                              free_libblock(&G.main->scene, freestyle_render->scene);
 +                              RE_FreeRender(freestyle_render);
 +                      }
 +              }
 +              BLI_freelistN( &re1->freestyle_renders );
 +      }
 +}
 +
 +
  /* reads all buffers, calls optional composite, merges in first result->rectf */
  static void do_merge_fullsample(Render *re, bNodeTree *ntree)
  {
                        
                        tag_scenes_for_render(re);
                        for(re1= RenderGlobal.renderlist.first; re1; re1= re1->next) {
 -                              if(re1->scene->id.flag & LIB_DOIT)
 -                                      if(re1->r.scemode & R_FULL_SAMPLE)
 +                              if(re1->scene->id.flag & LIB_DOIT) {
 +                                      if(re1->r.scemode & R_FULL_SAMPLE) {
                                                read_render_result(re1, sample);
 +                                              composite_freestyle_renders(re1, sample);
 +                                      }
 +                              }
                        }
                }
  
@@@ -2393,7 -2319,7 +2393,7 @@@ void RE_MergeFullSample(Render *re, Sce
        /* first call RE_ReadRenderResult on every renderlayer scene. this creates Render structs */
        
        /* tag scenes unread */
-       for(scene= G.main->scene.first; scene; scene= scene->id.next) 
+       for(scene= re->main->scene.first; scene; scene= scene->id.next) 
                scene->id.flag |= LIB_DOIT;
        
        for(node= ntree->nodes.first; node; node= node->next) {
@@@ -2468,7 -2394,7 +2468,7 @@@ static void do_render_composite_fields_
                                R.stats_draw= re->stats_draw;
                                
                                if (update_newframe)
-                                       scene_update_for_newframe(re->scene, re->lay);
+                                       scene_update_for_newframe(re->main, re->scene, re->lay);
                                
                                if(re->r.scemode & R_FULL_SAMPLE) 
                                        do_merge_fullsample(re, ntree);
                        do_merge_fullsample(re, NULL);
        }
  
 +      free_all_freestyle_renders();
 +
        /* weak... the display callback wants an active renderlayer pointer... */
        re->result->renlay= render_get_active_layer(re, re->result);
        re->display_draw(re->ddh, re->result, NULL);
@@@ -2533,7 -2457,7 +2533,7 @@@ static void do_render_seq(Render * re
  
        if(recurs_depth==0) {
                /* otherwise sequencer animation isnt updated */
-               BKE_animsys_evaluate_all_animation(G.main, (float)cfra); // XXX, was BKE_curframe(re->scene)
+               BKE_animsys_evaluate_all_animation(re->main, (float)cfra); // XXX, was BKE_curframe(re->scene)
        }
  
        recurs_depth++;
@@@ -2768,7 -2692,7 +2768,7 @@@ static void update_physics_cache(Rende
        BKE_ptcache_make_cache(&baker);
  }
  /* evaluating scene options for general Blender render */
- static int render_initialize_from_scene(Render *re, Scene *scene, SceneRenderLayer *srl, unsigned int lay, int anim, int anim_init)
+ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *srl, unsigned int lay, int anim, int anim_init)
  {
        int winx, winy;
        rcti disprect;
                disprect.ymax= winy;
        }
        
+       re->main= bmain;
        re->scene= scene;
        re->lay= lay;
        
  }
  
  /* general Blender frame render call */
- void RE_BlenderFrame(Render *re, Scene *scene, SceneRenderLayer *srl, unsigned int lay, int frame)
+ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *srl, unsigned int lay, int frame)
  {
        /* ugly global still... is to prevent preview events and signal subsurfs etc to make full resol */
        G.rendering= 1;
        
        scene->r.cfra= frame;
        
-       if(render_initialize_from_scene(re, scene, srl, lay, 0, 0)) {
+       if(render_initialize_from_main(re, bmain, scene, srl, lay, 0, 0)) {
                MEM_reset_peak_memory();
                do_render_all_options(re);
        }
        G.rendering= 0;
  }
  
- void RE_RenderFreestyleStrokes(Render *re, Scene *scene)
++void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene)
 +{
 +      re->result_ok= 0;
 +      scene->r.cfra= 1;
-       if(render_initialize_from_scene(re, scene, NULL, scene->lay, 0, 0)) {
++      if(render_initialize_from_main(re, bmain, scene, NULL, scene->lay, 0, 0)) {
 +              do_render_fields_blur_3d(re);
 +      }
 +      re->result_ok= 1;
 +}
 +
  static int do_write_image_or_movie(Render *re, Scene *scene, bMovieHandle *mh, ReportList *reports)
  {
        char name[FILE_MAX];
  }
  
  /* saves images to disk */
- void RE_BlenderAnim(Render *re, Scene *scene, unsigned int lay, int sfra, int efra, int tfra, ReportList *reports)
+ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, unsigned int lay, int sfra, int efra, int tfra, ReportList *reports)
  {
        bMovieHandle *mh= BKE_get_movie_handle(scene->r.imtype);
        int cfrao= scene->r.cfra;
        int nfra;
        
        /* do not fully call for each frame, it initializes & pops output window */
-       if(!render_initialize_from_scene(re, scene, NULL, lay, 0, 1))
+       if(!render_initialize_from_main(re, bmain, scene, NULL, lay, 0, 1))
                return;
        
        /* ugly global still... is to prevent renderwin events and signal subsurfs etc to make full resol */
                        char name[FILE_MAX];
                        
                        /* only border now, todo: camera lens. (ton) */
-                       render_initialize_from_scene(re, scene, NULL, lay, 1, 0);
+                       render_initialize_from_main(re, bmain, scene, NULL, lay, 1, 0);
  
                        if(nfra!=scene->r.cfra) {
                                /*
                                else
                                        updatelay= re->lay;
  
-                               scene_update_for_newframe(scene, updatelay);
+                               scene_update_for_newframe(bmain, scene, updatelay);
                                continue;
                        }
                        else
        G.rendering= 0;
  }
  
- void RE_PreviewRender(Render *re, Scene *sce)
+ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
  {
        int winx, winy;
  
  
        RE_InitState(re, NULL, &sce->r, NULL, winx, winy, NULL);
  
+       re->main = bmain;
        re->scene = sce;
        re->lay = sce->lay;
  
index 4c31e6ea9be085a83ea59f729ba13e42d7316236,56ab56d04111393449731267fad241beab58091a..394f90fea5eaa2ec07d24c71feeb7ecefd25e5d8
@@@ -130,7 -130,7 +130,7 @@@ void shade_material_loop(ShadeInput *sh
        }
        
        /* depth >= 1 when ray-shading */
-       if(shi->depth==0) {
+       if(shi->depth==0 || shi->volume_depth > 0) {
                if(R.r.mode & R_RAYTRACE) {
                        if(shi->ray_mirror!=0.0f || ((shi->mat->mode & MA_TRANSP) && (shi->mat->mode & MA_RAYTRANSP) && shr->alpha!=1.0f)) {
                                /* ray trace works on combined, but gives pass info */
@@@ -273,7 -273,8 +273,8 @@@ void shade_input_set_triangle_i(ShadeIn
        shi->mode= shi->mat->mode_l;            /* or-ed result for all nodes */
  
        /* facenormal copy, can get flipped */
-       shi->flippednor= RE_vlakren_get_normal(&R, obi, vlr, shi->facenor);
+       shi->flippednor= 0;
+       RE_vlakren_get_normal(&R, obi, vlr, shi->facenor);
        
        /* calculate vertexnormals */
        if(vlr->flag & R_SMOOTH) {
                        mul_m3_v3(obi->nmat, shi->n2);
                        mul_m3_v3(obi->nmat, shi->n3);
                }
-               if(!(vlr->flag & (R_NOPUNOFLIP|R_TANGENT))) {
-                       if(INPR(shi->facenor, shi->n1) < 0.0f) {
-                               shi->n1[0]= -shi->n1[0];
-                               shi->n1[1]= -shi->n1[1];
-                               shi->n1[2]= -shi->n1[2];
-                       }
-                       if(INPR(shi->facenor, shi->n2) < 0.0f) {
-                               shi->n2[0]= -shi->n2[0];
-                               shi->n2[1]= -shi->n2[1];
-                               shi->n2[2]= -shi->n2[2];
-                       }
-                       if(INPR(shi->facenor, shi->n3) < 0.0f) {
-                               shi->n3[0]= -shi->n3[0];
-                               shi->n3[1]= -shi->n3[1];
-                               shi->n3[2]= -shi->n3[2];
-                       }
-               }
        }
  }
  
@@@ -826,6 -809,10 +809,10 @@@ void shade_input_set_normals(ShadeInpu
        /* used in nodes */
        VECCOPY(shi->vno, shi->vn);
  
+       /* flip normals to viewing direction */
+       if(!(shi->vlr->flag & R_TANGENT))
+               if(dot_v3v3(shi->facenor, shi->view) < 0.0f)
+                       shade_input_flip_normals(shi);
  }
  
  /* use by raytrace, sss, bake to flip into the right direction */
@@@ -1042,7 -1029,6 +1029,7 @@@ void shade_input_set_shade_texco(ShadeI
                        shi->actcol= obr->actmcol;
  
                        if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) {
 +                              float alpha[8];
                                for (i=0; (mcol=RE_vlakren_get_mcol(obr, vlr, i, &name, 0)); i++) {
                                        ShadeInputCol *scol= &shi->col[i];
                                        char *cp1, *cp2, *cp3;
                                        scol->col[0]= (l*((float)cp3[3]) - u*((float)cp1[3]) - v*((float)cp2[3]))/255.0f;
                                        scol->col[1]= (l*((float)cp3[2]) - u*((float)cp1[2]) - v*((float)cp2[2]))/255.0f;
                                        scol->col[2]= (l*((float)cp3[1]) - u*((float)cp1[1]) - v*((float)cp2[1]))/255.0f;
 +
 +                                      alpha[i]= (l*((float)cp3[0]) - u*((float)cp1[0]) - v*((float)cp2[0]))/255.0f;
                                }
  
                                if(shi->totcol) {
                                        shi->vcol[0]= shi->col[shi->actcol].col[0];
                                        shi->vcol[1]= shi->col[shi->actcol].col[1];
                                        shi->vcol[2]= shi->col[shi->actcol].col[2];
 -                                      shi->vcol[3]= 1.0f;
 +                                      shi->vcol[3]= shi->mat->vcol_alpha ? alpha[shi->actcol] : 1.0f;
                                }
                                else {
                                        shi->vcol[0]= 0.0f;
index 449d3da0b6d9363a251e9a6264efacee5eefff60,81de553b20909361860cc06b2259980198fa5f7b..00eb6e3d17d8324f0e307afbe48770d1e23d2d80
@@@ -1590,7 -1590,7 +1590,7 @@@ void shade_lamp_loop(ShadeInput *shi, S
                        shi->r= shi->vcol[0];
                        shi->g= shi->vcol[1];
                        shi->b= shi->vcol[2];
 -                      if(ma->mode & (MA_FACETEXTURE_ALPHA))
 +                      if((ma->mode & (MA_FACETEXTURE_ALPHA)) || ma->vcol_alpha)
                                shi->alpha= shi->vcol[3];
                }
                if(ma->texco)
                if(((passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
                        || (passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) {
                        /* AO was calculated for scanline already */
-                       if(shi->depth)
+                       if(shi->depth || shi->volume_depth)
                                ambient_occlusion(shi);
                        VECCOPY(shr->ao, shi->ao);
                        VECCOPY(shr->env, shi->env); // XXX multiply
diff --combined source/creator/creator.c
index fbe9d100b14236c497fbfabcd5c15ef4d0829af6,415f1064dbb6a040e968158af615c6940b0eaacb..8deb66d7f1f7ec9a08a1079f93cd179010d4ba30
@@@ -96,8 -96,6 +96,8 @@@
  #include "GPU_draw.h"
  #include "GPU_extensions.h"
  
 +#include "FRS_freestyle.h"
 +
  /* for passing information between creator and gameengine */
  #include "SYS_System.h"
  
@@@ -680,6 -678,7 +680,7 @@@ static int render_frame(int argc, char 
  {
        bContext *C = data;
        if (CTX_data_scene(C)) {
+               Main *bmain= CTX_data_main(C);
                Scene *scene= CTX_data_scene(C);
  
                if (argc > 1) {
  
                        frame = MIN2(MAXFRAME, MAX2(MINAFRAME, frame));
  
-                       RE_BlenderAnim(re, scene, scene->lay, frame, frame, scene->r.frame_step, &reports);
+                       RE_BlenderAnim(re, bmain, scene, scene->lay, frame, frame, scene->r.frame_step, &reports);
                        return 1;
                } else {
                        printf("\nError: frame number must follow '-f / --render-frame'.\n");
@@@ -719,11 -718,12 +720,12 @@@ static int render_animation(int argc, c
  {
        bContext *C = data;
        if (CTX_data_scene(C)) {
+               Main *bmain= CTX_data_main(C);
                Scene *scene= CTX_data_scene(C);
                Render *re= RE_NewRender(scene->id.name);
                ReportList reports;
                BKE_reports_init(&reports, RPT_PRINT);
-               RE_BlenderAnim(re, scene, scene->lay, scene->r.sfra, scene->r.efra, scene->r.frame_step, &reports);
+               RE_BlenderAnim(re, bmain, scene, scene->lay, scene->r.sfra, scene->r.efra, scene->r.frame_step, &reports);
        } else {
                printf("\nError: no blend loaded. cannot use '-a'.\n");
        }
@@@ -734,7 -734,7 +736,7 @@@ static int set_scene(int argc, char **a
  {
        if(argc > 1) {
                bContext *C= data;
-               Scene *sce= set_scene_name(argv[1]);
+               Scene *sce= set_scene_name(CTX_data_main(C), argv[1]);
                if(sce) {
                        CTX_data_scene_set(C, sce);
                }
@@@ -1128,10 -1128,6 +1130,10 @@@ int main(int argc, char **argv
        CTX_py_init_set(C, 1);
        WM_keymap_init(C);
  
 +      /* initialize Freestyle */
 +      FRS_initialize();
 +      FRS_set_context(C);
 +
        /* OK we are ready for it */
        BLI_argsParse(ba, 4, load_file, C);