Merged changes in the trunk up to revision 54110.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 26 Jan 2013 23:49:13 +0000 (23:49 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 26 Jan 2013 23:49:13 +0000 (23:49 +0000)
Conflicts resolved:
source/blender/blenfont/SConscript
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/makesdna/intern/makesdna.c
source/blender/makesrna/intern/rna_scene.c

74 files changed:
1  2 
CMakeLists.txt
SConstruct
build_files/scons/config/linux-config.py
build_files/scons/tools/btools.py
doc/python_api/sphinx_doc_gen.py
intern/cycles/blender/addon/ui.py
release/scripts/startup/bl_operators/__init__.py
release/scripts/startup/bl_ui/__init__.py
release/scripts/startup/bl_ui/properties_render.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/CMakeLists.txt
source/blender/SConscript
source/blender/blenfont/BLF_translation.h
source/blender/blenfont/CMakeLists.txt
source/blender/blenfont/SConscript
source/blender/blenkernel/BKE_main.h
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/bpath.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/CMakeLists.txt
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/bmesh/CMakeLists.txt
source/blender/bmesh/bmesh_class.h
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/operators/bmo_similar.c
source/blender/editors/include/UI_resources.h
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/resources.c
source/blender/editors/mesh/CMakeLists.txt
source/blender/editors/mesh/editmesh_select.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/space_view3d/drawobject.c
source/blender/makesdna/DNA_ID.h
source/blender/makesdna/DNA_material_types.h
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesdna/DNA_space_types.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesdna/intern/makesdna.c
source/blender/makesrna/RNA_access.h
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/SConscript
source/blender/makesrna/intern/CMakeLists.txt
source/blender/makesrna/intern/SConscript
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_action.c
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/python/bmesh/bmesh_py_types.c
source/blender/python/intern/CMakeLists.txt
source/blender/python/intern/bpy_app.c
source/blender/python/intern/bpy_app_build_options.c
source/blender/render/CMakeLists.txt
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pipeline.c
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_files.c
source/blenderplayer/bad_level_call_stubs/stubs.c
source/creator/CMakeLists.txt
source/creator/creator.c

diff --combined CMakeLists.txt
index b6630b6ad8dbf1718b89b73ad7b331678fbf3e0c,59dbeaed36b27f4d3d85fdaab6688e7214680fe4..e623cfe290e64b702878f9be8d08be30c43db78a
@@@ -135,7 -135,6 +135,6 @@@ option(WITH_GAMEENGINE    "Enable Game 
  option(WITH_PLAYER        "Build Player" OFF)
  option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
  option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
- option(WITH_COMPOSITOR_LEGACY "Enable legacy compositor" OFF)
  
  # GHOST Windowing Library Options
  option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
@@@ -234,9 -233,6 +233,9 @@@ option(WITH_LZMA          "Enable best 
  # Camera/motion tracking
  option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
  
 +# Freestyle
 +option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
 +
  # Misc
  option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
  option(WITH_RAYOPTIMIZATION   "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
@@@ -1330,6 -1326,11 +1329,11 @@@ elseif(WIN32
                                        optimized boost_locale-${BOOST_POSTFIX}
                                        debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
                        endif()
+                       if(WITH_CYCLES_OSL)
+                               set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
+                                       optimized boost_wave-${BOOST_POSTFIX}
+                                       debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
+                       endif()
                        set(BOOST_LIBPATH ${BOOST}/lib)
                        set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
                endif()
diff --combined SConstruct
index 171ebc8ddef86e33cfd27c073825a8d4988d26bc,b7665d14228ba572fafa8611e943eee25232fc0f..e3e58270cdda2fa8677d9d2f0298f136fb2d3fd7
@@@ -269,7 -269,6 +269,7 @@@ if 'blenderlite' in B.targets
      target_env_defs['WITH_BF_PYTHON'] = False
      target_env_defs['WITH_BF_3DMOUSE'] = False
      target_env_defs['WITH_BF_LIBMV'] = False
 +    target_env_defs['WITH_BF_FREESTYLE'] = False
  
      # Merge blenderlite, let command line to override
      for k,v in target_env_defs.iteritems():
@@@ -575,6 -574,23 +575,23 @@@ data_to_c_simple("release/datafiles/bru
  data_to_c_simple("release/datafiles/brushicons/twist.png")
  data_to_c_simple("release/datafiles/brushicons/vertexdraw.png")
  
+ data_to_c_simple("release/datafiles/matcaps/mc01.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc02.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc03.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc04.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc05.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc06.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc07.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc08.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc09.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc10.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc11.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc12.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc13.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc14.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc15.jpg")
+ data_to_c_simple("release/datafiles/matcaps/mc16.jpg")
  ##### END DATAFILES ##########
  
  Help(opts.GenerateHelpText(env))
@@@ -684,10 -700,6 +701,10 @@@ if env['OURPLATFORM']!='darwin'
                  if VERSION_RELEASE_CYCLE == "release" and "addons_contrib" in dn:
                      dn.remove('addons_contrib')
  
 +                # do not install freestyle if disabled
 +                if not env['WITH_BF_FREESTYLE'] and "freestyle" in dn:
 +                    dn.remove("freestyle")
 +
                  dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
                  dir += os.sep + os.path.basename(scriptpath) + dp[len(scriptpath):]
  
index 05d846d74336ac73c9762a9b24cc0b9672787fde,068273e35ef3e633cbde293d64bdd256bd4653ed..22e82662ae782b25b4b48d33185c495321a7d0e0
@@@ -5,9 -5,10 +5,10 @@@ py = FindPython(
  BF_PYTHON_ABI_FLAGS = py['ABI_FLAGS']
  BF_PYTHON = py['PYTHON']
  BF_PYTHON_LIBPATH = py['LIBPATH']
+ BF_PYTHON_CONFIG = py['CONFIG']
  BF_PYTHON_VERSION = py['VERSION']
  WITH_BF_STATICPYTHON = False
- BF_PYTHON_INC = '${BF_PYTHON}/include/python${BF_PYTHON_VERSION}${BF_PYTHON_ABI_FLAGS}'
+ BF_PYTHON_INC = '${BF_PYTHON}/include/python${BF_PYTHON_VERSION}${BF_PYTHON_ABI_FLAGS} ' + BF_PYTHON_CONFIG
  BF_PYTHON_BINARY = '${BF_PYTHON}/bin/python${BF_PYTHON_VERSION}'
  BF_PYTHON_LIB = 'python${BF_PYTHON_VERSION}${BF_PYTHON_ABI_FLAGS}'  # BF_PYTHON+'/lib/python'+BF_PYTHON_VERSION+'/config/libpython'+BF_PYTHON_VERSION+'.a'
  BF_PYTHON_LINKFLAGS = ['-Xlinker', '-export-dynamic']
@@@ -193,7 -194,7 +194,7 @@@ BF_OCIO_LIB = 'OpenColorIO yaml-cpp tin
  BF_OCIO_LIB_STATIC = '${BF_OCIO_LIBPATH}/libOpenColorIO.a ${BF_OCIO_LIBPATH}/libtinyxml.a ${BF_OCIO_LIBPATH}/libyaml-cpp.a'
  BF_OCIO_LIBPATH = '${BF_OCIO}/lib'
  
- WITH_BF_BOOST = False
+ WITH_BF_BOOST = True
  WITH_BF_STATICBOOST = False
  BF_BOOST = '/usr'
  BF_BOOST_INC = '${BF_BOOST}/include'
@@@ -225,9 -226,6 +226,9 @@@ BF_3DMOUSE_LIBPATH = '${BF_3DMOUSE}/lib
  BF_3DMOUSE_LIB = 'spnav'
  BF_3DMOUSE_LIB_STATIC = '${BF_3DMOUSE_LIBPATH}/libspnav.a'
  
 +#Freestyle
 +WITH_BF_FREESTYLE = True
 +
  ##
  CC = 'gcc'
  CXX = 'g++'
index 82d7350bfcef922e102d728ea1eca473adf3c55a,ee6dd20ecc033c4fa6381cf2f34562a73f49c8ab..9a31ba650f5f0e5ab8bd2a9d171a393a3387ee97
@@@ -108,7 -108,7 +108,7 @@@ def validate_arguments(args, bc)
              'WITH_BF_STATICFFMPEG', 'BF_FFMPEG_LIB_STATIC',
              'WITH_BF_OGG', 'BF_OGG', 'BF_OGG_LIB',
              'WITH_BF_FRAMESERVER',
-             'WITH_BF_COMPOSITOR', 'WITH_BF_COMPOSITOR_LEGACY',
+             'WITH_BF_COMPOSITOR',
              'WITH_BF_JPEG', 'BF_JPEG', 'BF_JPEG_INC', 'BF_JPEG_LIB', 'BF_JPEG_LIBPATH', 'WITH_BF_STATICJPEG', 'BF_JPEG_LIB_STATIC',
              'WITH_BF_OPENJPEG', 'BF_OPENJPEG', 'BF_OPENJPEG_INC', 'BF_OPENJPEG_LIB', 'BF_OPENJPEG_LIBPATH',
              'WITH_BF_REDCODE', 'BF_REDCODE', 'BF_REDCODE_INC', 'BF_REDCODE_LIB', 'BF_REDCODE_LIBPATH',
              'WITH_BF_TIFF', 'BF_TIFF', 'BF_TIFF_INC', 'BF_TIFF_LIB', 'BF_TIFF_LIBPATH', 'WITH_BF_STATICTIFF', 'BF_TIFF_LIB_STATIC',
              'WITH_BF_ZLIB', 'BF_ZLIB', 'BF_ZLIB_INC', 'BF_ZLIB_LIB', 'BF_ZLIB_LIBPATH', 'WITH_BF_STATICZLIB', 'BF_ZLIB_LIB_STATIC',
              'WITH_BF_INTERNATIONAL',
 +            'WITH_BF_FREESTYLE',
              'WITH_BF_ICONV', 'BF_ICONV', 'BF_ICONV_INC', 'BF_ICONV_LIB', 'BF_ICONV_LIBPATH',
              'WITH_BF_GAMEENGINE',
              'WITH_BF_BULLET', 'BF_BULLET', 'BF_BULLET_INC', 'BF_BULLET_LIB',
@@@ -387,8 -386,6 +387,8 @@@ def read_opts(env, cfg, args)
  
          (BoolVariable('WITH_BF_INTERNATIONAL', 'Use Boost::locale if true', True)),
  
 +        (BoolVariable('WITH_BF_FREESTYLE', 'Build advanced edge renderer', True)),
 +
          (BoolVariable('WITH_BF_ICONV', 'Use iconv if true', True)),
          ('BF_ICONV', 'iconv base path', ''),
          ('BF_ICONV_INC', 'iconv include path', ''),
          ('BF_BOOST_LIB_STATIC', 'Boost static library', ''),
  
          (BoolVariable('WITH_GHOST_XDND', 'Build with drag-n-drop support on Linux platforms using XDND protocol', True)),
-         (BoolVariable('WITH_BF_COMPOSITOR_LEGACY', 'Enable the legacy compositor', False)),
  
          (BoolVariable('WITH_BF_CYCLES_OSL', 'Build with OSL sypport in Cycles', False)),
          (BoolVariable('WITH_BF_STATICOSL', 'Staticly link to OSL', False)),
index 89659c10adda48dbc9bfce702fa22b983a77ae73,7457ae02d6c3689c0460868354216d2db33d5d9d..4311ae56f8eef2290fec8f2b1d53dceb62bd0de2
@@@ -262,7 -262,6 +262,7 @@@ else
          "mathutils",
          "mathutils.geometry",
          "mathutils.noise",
 +        "Freestyle",
          ]
  
      # ------
@@@ -450,7 -449,6 +450,7 @@@ if ARGS.sphinx_build_pdf
  ClassMethodDescriptorType = type(dict.__dict__['fromkeys'])
  MethodDescriptorType = type(dict.get)
  GetSetDescriptorType = type(int.real)
 +StaticMethodType = type(staticmethod(lambda: None))
  from types import MemberDescriptorType
  
  _BPY_STRUCT_FAKE = "bpy_struct"
@@@ -614,10 -612,10 +614,10 @@@ def pyfunc2sphinx(ident, fw, identifier
      '''
      function or class method to sphinx
      '''
-     
      if type(py_func) == type(bpy.types.Space.draw_handler_add):
          return
-     
      arg_str = inspect.formatargspec(*inspect.getargspec(py_func))
  
      if not is_class:
@@@ -915,12 -913,6 +915,12 @@@ def pymodule2sphinx(basepath, module_na
              if type(descr) == GetSetDescriptorType:
                  py_descr2sphinx("   ", fw, descr, module_name, type_name, key)
  
 +        for key, descr in descr_items:
 +            if type(descr) == StaticMethodType:
 +                descr = getattr(value, key)
 +                write_indented_lines("   ", fw, descr.__doc__ or "Undocumented", False)
 +                fw("\n")
 +
          fw("\n\n")
  
      file.close()
@@@ -992,6 -984,7 +992,7 @@@ context_type_map = 
      "world": ("World", False),
  }
  
  def pycontext2sphinx(basepath):
      # Only use once. very irregular
  
          "sequencer_context_dir",
      )
  
      unique = set()
      blend_cdll = ctypes.CDLL("")
      for ctx_str in context_strings:
@@@ -1551,7 -1543,7 +1551,7 @@@ def write_rst_contents(basepath)
          # mathutils
          "mathutils", "mathutils.geometry", "mathutils.noise",
          # misc
 -        "bgl", "blf", "gpu", "aud", "bpy_extras",
 +        "Freestyle", "bgl", "blf", "gpu", "aud", "bpy_extras",
          # bmesh, submodules are in own page
          "bmesh",
          )
@@@ -1699,7 -1691,6 +1699,7 @@@ def write_rst_importable_modules(basepa
          "mathutils"         : "Math Types & Utilities",
          "mathutils.geometry": "Geometry Utilities",
          "mathutils.noise"   : "Noise Utilities",
 +        "Freestyle"         : "Freestyle Data Types & Operators",
      }
      for mod_name, mod_descr in importable_modules.items():
          if mod_name not in EXCLUDE_MODULES:
index 6a3a0c6323641fd086c6173d39da9abddeb13367,fded07ab2270657eb062cc4d5480a0d78ad88323..ccc2a0ecbda45656ad601cb580ef23c8c9372dea
@@@ -220,69 -220,10 +220,69 @@@ class CyclesRender_PT_performance(Cycle
          sub.prop(rd, "use_persistent_data", text="Persistent Images")
  
  
 +class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
 +    bl_label = "Post Processing"
 +    bl_options = {'DEFAULT_CLOSED'}
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        rd = context.scene.render
 +
 +        split = layout.split()
 +
 +        col = split.column()
 +        col.prop(rd, "use_compositing")
 +        col.prop(rd, "use_sequencer")
 +
 +        col = split.column()
 +        col.prop(rd, "dither_intensity", text="Dither", slider=True)
 +
 +
 +class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
 +    bl_label = "Depth of Field"
 +    bl_context = "data"
 +
 +    @classmethod
 +    def poll(cls, context):
 +        return context.camera and CyclesButtonsPanel.poll(context)
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        cam = context.camera
 +        ccam = cam.cycles
 +
 +        split = layout.split()
 +
 +        col = split.column()
 +        col.label("Focus:")
 +        col.prop(cam, "dof_object", text="")
 +
 +        sub = col.row()
 +        sub.active = cam.dof_object is None
 +        sub.prop(cam, "dof_distance", text="Distance")
 +
 +        col = split.column()
 +
 +        col.label("Aperture:")
 +        sub = col.column(align=True)
 +        sub.prop(ccam, "aperture_type", text="")
 +        if ccam.aperture_type == 'RADIUS':
 +            sub.prop(ccam, "aperture_size", text="Size")
 +        elif ccam.aperture_type == 'FSTOP':
 +            sub.prop(ccam, "aperture_fstop", text="Number")
 +
 +        sub = col.column(align=True)
 +        sub.prop(ccam, "aperture_blades", text="Blades")
 +        sub.prop(ccam, "aperture_rotation", text="Rotation")
 +
 +
  class CyclesRender_PT_layers(CyclesButtonsPanel, Panel):
      bl_label = "Layers"
 -    bl_options = {'DEFAULT_CLOSED'}
 -    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +    bl_options = {'HIDE_HEADER'}
 +    bl_context = "render_layer"
 +    COMPAT_ENGINES = {'CYCLES'}
  
      def draw(self, context):
          layout = self.layout
  
          row = layout.row()
          rl = rd.layers.active
 -        row.prop(rl, "name")
 +        if rl:
 +            row.prop(rl, "name")
          row.prop(rd, "use_single_layer", text="", icon_only=True)
  
 +
 +class CyclesRender_PT_layer_options(CyclesButtonsPanel, Panel):
 +    bl_label = "Layer"
 +    bl_options = {'DEFAULT_CLOSED'}
 +    bl_context = "render_layer"
 +    COMPAT_ENGINES = {'CYCLES'}
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        scene = context.scene
 +        rd = scene.render
 +        rl = rd.layers.active
 +
          split = layout.split()
  
          col = split.column()
          col.prop(rl, "samples")
          col.prop(rl, "use_sky", "Use Environment")
  
 +
 +class CyclesRender_PT_layer_passes(CyclesButtonsPanel, Panel):
 +    bl_label = "Layer"
 +    bl_options = {'DEFAULT_CLOSED'}
 +    bl_context = "render_layer"
 +    COMPAT_ENGINES = {'CYCLES'}
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        scene = context.scene
 +        rd = scene.render
 +        rl = rd.layers.active
 +
          split = layout.split()
  
          col = split.column()
          col.prop(rl, "use_pass_environment")
  
  
 -class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
 -    bl_label = "Post Processing"
 -    bl_options = {'DEFAULT_CLOSED'}
 -
 -    def draw(self, context):
 -        layout = self.layout
 -
 -        rd = context.scene.render
 -
 -        split = layout.split()
 -
 -        col = split.column()
 -        col.prop(rd, "use_compositing")
 -        col.prop(rd, "use_sequencer")
 -
 -        col = split.column()
 -        col.prop(rd, "dither_intensity", text="Dither", slider=True)
 -
 -
 -class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
 -    bl_label = "Depth of Field"
 -    bl_context = "data"
 -
 -    @classmethod
 -    def poll(cls, context):
 -        return context.camera and CyclesButtonsPanel.poll(context)
 -
 -    def draw(self, context):
 -        layout = self.layout
 -
 -        cam = context.camera
 -        ccam = cam.cycles
 -
 -        split = layout.split()
 -
 -        col = split.column()
 -        col.label("Focus:")
 -        col.prop(cam, "dof_object", text="")
 -
 -        sub = col.row()
 -        sub.active = cam.dof_object is None
 -        sub.prop(cam, "dof_distance", text="Distance")
 -
 -        col = split.column()
 -
 -        col.label("Aperture:")
 -        sub = col.column(align=True)
 -        sub.prop(ccam, "aperture_type", text="")
 -        if ccam.aperture_type == 'RADIUS':
 -            sub.prop(ccam, "aperture_size", text="Size")
 -        elif ccam.aperture_type == 'FSTOP':
 -            sub.prop(ccam, "aperture_fstop", text="Number")
 -
 -        sub = col.column(align=True)
 -        sub.prop(ccam, "aperture_blades", text="Blades")
 -        sub.prop(ccam, "aperture_rotation", text="Rotation")
 -
 -
  class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
      bl_label = ""
      bl_context = "material"
@@@ -976,84 -946,96 +976,96 @@@ class CyclesParticle_PT_textures(Cycles
              slot = part.texture_slots[part.active_texture_index]
              layout.template_ID(slot, "texture", new="texture.new")
  
  class CyclesRender_PT_CurveRendering(CyclesButtonsPanel, Panel):
      bl_label = "Cycles Hair Rendering"
      bl_context = "particle"
-     
      @classmethod
      def poll(cls, context):
+         scene = context.scene
+         cscene = scene.cycles
          psys = context.particle_system
          device_type = context.user_preferences.system.compute_device_type
-         experimental = context.scene.cycles.feature_set == 'EXPERIMENTAL' and (context.scene.cycles.device == 'CPU' or device_type == 'NONE')
+         experimental = ((cscene.feature_set == 'EXPERIMENTAL') and (cscene.device == 'CPU' or device_type == 'NONE'))
          return CyclesButtonsPanel.poll(context) and experimental and psys
-         
      def draw_header(self, context):
-         cscene = context.scene.cycles_curves
-         self.layout.prop(cscene, "use_curves", text="")
-     
+         ccscene = context.scene.cycles_curves
+         self.layout.prop(ccscene, "use_curves", text="")
      def draw(self, context):
          layout = self.layout
-         
          scene = context.scene
-         cscene = scene.cycles_curves
-         
-         layout.active = cscene.use_curves
-         
-         layout.prop(cscene, "preset", text="Mode")
-         
-         if cscene.preset == 'CUSTOM':
-             layout.prop(cscene, "primitive", text="Primitive")
-         
-             if cscene.primitive == 'TRIANGLES':
-                 layout.prop(cscene, "triangle_method", text="Method")
-                 if cscene.triangle_method == 'TESSELLATED':
-                     layout.prop(cscene, "resolution", text="Resolution")
-                 layout.prop(cscene, "use_smooth", text="Smooth")
-             elif cscene.primitive == 'LINE_SEGMENTS':
-                 layout.prop(cscene, "use_backfacing", text="Check back-faces")
-                 
+         ccscene = scene.cycles_curves
+         layout.active = ccscene.use_curves
+         layout.prop(ccscene, "preset", text="Mode")
+         if ccscene.preset == 'CUSTOM':
+             layout.prop(ccscene, "primitive", text="Primitive")
+             if ccscene.primitive == 'TRIANGLES':
+                 layout.prop(ccscene, "triangle_method", text="Method")
+                 if ccscene.triangle_method == 'TESSELLATED_TRIANGLES':
+                     layout.prop(ccscene, "resolution", text="Resolution")
+                 layout.prop(ccscene, "use_smooth", text="Smooth")
+             elif ccscene.primitive == 'LINE_SEGMENTS':
+                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
                  row = layout.row()
-                 row.prop(cscene, "use_encasing", text="Exclude encasing")
+                 row.prop(ccscene, "use_encasing", text="Exclude encasing")
                  sub = row.row()
-                 sub.active = cscene.use_encasing
-                 sub.prop(cscene, "encasing_ratio", text="Ratio for encasing")
-                 
-                 layout.prop(cscene, "line_method", text="Method")
-                 layout.prop(cscene, "use_tangent_normal", text="Use tangent normal as default")
-                 layout.prop(cscene, "use_tangent_normal_geometry", text="Use tangent normal geometry")
-                 layout.prop(cscene, "use_tangent_normal_correction", text="Correct tangent normal for slope")
-                 layout.prop(cscene, "interpolation", text="Interpolation")
-                 
+                 sub.active = ccscene.use_encasing
+                 sub.prop(ccscene, "encasing_ratio", text="Ratio for encasing")
+                 layout.prop(ccscene, "line_method", text="Method")
+                 layout.prop(ccscene, "use_tangent_normal", text="Use tangent normal as default")
+                 layout.prop(ccscene, "use_tangent_normal_geometry", text="Use tangent normal geometry")
+                 layout.prop(ccscene, "use_tangent_normal_correction", text="Correct tangent normal for slope")
+                 layout.prop(ccscene, "interpolation", text="Interpolation")
+                 row = layout.row()
+                 row.prop(ccscene, "segments", text="Segments")
+                 row.prop(ccscene, "normalmix", text="Ray Mix")
+             elif ccscene.primitive in {'CURVE_SEGMENTS', 'CURVE_RIBBONS'}:
+                 layout.prop(ccscene, "subdivisions", text="Curve subdivisions")
+                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
+                 layout.prop(ccscene, "interpolation", text="Interpolation")
                  row = layout.row()
-                 row.prop(cscene, "segments", text="Segments")
-                 row.prop(cscene, "normalmix", text="Ray Mix")
-             
+                 row.prop(ccscene, "segments", text="Segments")
              row = layout.row()
-             row.prop(cscene, "use_cache", text="Export cache with children")
-             if cscene.use_cache:
-                 row.prop(cscene, "use_parents", text="Include parents")  
-             
+             row.prop(ccscene, "use_parents", text="Include parents")
  class CyclesParticle_PT_CurveSettings(CyclesButtonsPanel, Panel):
      bl_label = "Cycles Hair Settings"
      bl_context = "particle"
-     
      @classmethod
      def poll(cls, context):
-         use_curves = context.scene.cycles_curves.use_curves and context.particle_system
+         scene = context.scene
+         cscene = scene.cycles
+         ccscene = scene.cycles_curves
+         use_curves = ccscene.use_curves and context.particle_system
          device_type = context.user_preferences.system.compute_device_type
-         experimental = context.scene.cycles.feature_set == 'EXPERIMENTAL' and (context.scene.cycles.device == 'CPU' or device_type == 'NONE')
+         experimental = cscene.feature_set == 'EXPERIMENTAL' and (cscene.device == 'CPU' or device_type == 'NONE')
          return CyclesButtonsPanel.poll(context) and experimental and use_curves
  
      def draw(self, context):
          layout = self.layout
-         
          psys = context.particle_settings
          cpsys = psys.cycles
-         
          row = layout.row()
          row.prop(cpsys, "shape", text="Shape")
          row.prop(cpsys, "use_closetip", text="Close tip")
-         
          layout.label(text="Width multiplier:")
          row = layout.row()
          row.prop(cpsys, "root_width", text="Root")
@@@ -1120,74 -1102,79 +1132,79 @@@ def draw_pause(self, context)
  
  
  def get_panels():
+     types = bpy.types
      return (
-         bpy.types.RENDER_PT_render,
-         bpy.types.RENDER_PT_output,
-         bpy.types.RENDER_PT_encoding,
-         bpy.types.RENDER_PT_dimensions,
-         bpy.types.RENDER_PT_stamp,
-         bpy.types.SCENE_PT_scene,
-         bpy.types.SCENE_PT_audio,
-         bpy.types.SCENE_PT_unit,
-         bpy.types.SCENE_PT_keying_sets,
-         bpy.types.SCENE_PT_keying_set_paths,
-         bpy.types.SCENE_PT_physics,
-         bpy.types.WORLD_PT_context_world,
-         bpy.types.DATA_PT_context_mesh,
-         bpy.types.DATA_PT_context_camera,
-         bpy.types.DATA_PT_context_lamp,
-         bpy.types.DATA_PT_context_speaker,
-         bpy.types.DATA_PT_texture_space,
-         bpy.types.DATA_PT_curve_texture_space,
-         bpy.types.DATA_PT_mball_texture_space,
-         bpy.types.DATA_PT_vertex_groups,
-         bpy.types.DATA_PT_shape_keys,
-         bpy.types.DATA_PT_uv_texture,
-         bpy.types.DATA_PT_vertex_colors,
-         bpy.types.DATA_PT_camera,
-         bpy.types.DATA_PT_camera_display,
-         bpy.types.DATA_PT_lens,
-         bpy.types.DATA_PT_speaker,
-         bpy.types.DATA_PT_distance,
-         bpy.types.DATA_PT_cone,
-         bpy.types.DATA_PT_customdata,
-         bpy.types.DATA_PT_custom_props_mesh,
-         bpy.types.DATA_PT_custom_props_camera,
-         bpy.types.DATA_PT_custom_props_lamp,
-         bpy.types.DATA_PT_custom_props_speaker,
-         bpy.types.TEXTURE_PT_clouds,
-         bpy.types.TEXTURE_PT_wood,
-         bpy.types.TEXTURE_PT_marble,
-         bpy.types.TEXTURE_PT_magic,
-         bpy.types.TEXTURE_PT_blend,
-         bpy.types.TEXTURE_PT_stucci,
-         bpy.types.TEXTURE_PT_image,
-         bpy.types.TEXTURE_PT_image_sampling,
-         bpy.types.TEXTURE_PT_image_mapping,
-         bpy.types.TEXTURE_PT_musgrave,
-         bpy.types.TEXTURE_PT_voronoi,
-         bpy.types.TEXTURE_PT_distortednoise,
-         bpy.types.TEXTURE_PT_voxeldata,
-         bpy.types.TEXTURE_PT_pointdensity,
-         bpy.types.TEXTURE_PT_pointdensity_turbulence,
-         bpy.types.TEXTURE_PT_mapping,
-         bpy.types.TEXTURE_PT_influence,
-         bpy.types.TEXTURE_PT_colors,
-         bpy.types.PARTICLE_PT_context_particles,
-         bpy.types.PARTICLE_PT_emission,
-         bpy.types.PARTICLE_PT_hair_dynamics,
-         bpy.types.PARTICLE_PT_cache,
-         bpy.types.PARTICLE_PT_velocity,
-         bpy.types.PARTICLE_PT_rotation,
-         bpy.types.PARTICLE_PT_physics,
-         bpy.types.PARTICLE_PT_boidbrain,
-         bpy.types.PARTICLE_PT_render,
-         bpy.types.PARTICLE_PT_draw,
-         bpy.types.PARTICLE_PT_children,
-         bpy.types.PARTICLE_PT_field_weights,
-         bpy.types.PARTICLE_PT_force_fields,
-         bpy.types.PARTICLE_PT_vertexgroups,
-         bpy.types.PARTICLE_PT_custom_props,
+         types.RENDER_PT_render,
+         types.RENDER_PT_output,
+         types.RENDER_PT_encoding,
+         types.RENDER_PT_dimensions,
+         types.RENDER_PT_stamp,
+         types.SCENE_PT_scene,
+         types.SCENE_PT_color_management,
+         types.SCENE_PT_audio,
+         types.SCENE_PT_unit,
+         types.SCENE_PT_keying_sets,
+         types.SCENE_PT_keying_set_paths,
+         types.SCENE_PT_physics,
+         types.WORLD_PT_context_world,
+         types.DATA_PT_context_mesh,
+         types.DATA_PT_context_camera,
+         types.DATA_PT_context_lamp,
+         types.DATA_PT_context_speaker,
+         types.DATA_PT_texture_space,
+         types.DATA_PT_curve_texture_space,
+         types.DATA_PT_mball_texture_space,
+         types.DATA_PT_vertex_groups,
+         types.DATA_PT_shape_keys,
+         types.DATA_PT_uv_texture,
+         types.DATA_PT_vertex_colors,
+         types.DATA_PT_camera,
+         types.DATA_PT_camera_display,
+         types.DATA_PT_lens,
+         types.DATA_PT_speaker,
+         types.DATA_PT_distance,
+         types.DATA_PT_cone,
+         types.DATA_PT_customdata,
+         types.DATA_PT_custom_props_mesh,
+         types.DATA_PT_custom_props_camera,
+         types.DATA_PT_custom_props_lamp,
+         types.DATA_PT_custom_props_speaker,
+         types.TEXTURE_PT_clouds,
+         types.TEXTURE_PT_wood,
+         types.TEXTURE_PT_marble,
+         types.TEXTURE_PT_magic,
+         types.TEXTURE_PT_blend,
+         types.TEXTURE_PT_stucci,
+         types.TEXTURE_PT_image,
+         types.TEXTURE_PT_image_sampling,
+         types.TEXTURE_PT_image_mapping,
+         types.TEXTURE_PT_musgrave,
+         types.TEXTURE_PT_voronoi,
+         types.TEXTURE_PT_distortednoise,
+         types.TEXTURE_PT_voxeldata,
+         types.TEXTURE_PT_pointdensity,
+         types.TEXTURE_PT_pointdensity_turbulence,
+         types.TEXTURE_PT_mapping,
+         types.TEXTURE_PT_influence,
+         types.TEXTURE_PT_colors,
+         types.PARTICLE_PT_context_particles,
+         types.PARTICLE_PT_emission,
+         types.PARTICLE_PT_hair_dynamics,
+         types.PARTICLE_PT_cache,
+         types.PARTICLE_PT_velocity,
+         types.PARTICLE_PT_rotation,
+         types.PARTICLE_PT_physics,
+         types.SCENE_PT_rigid_body_world,
+         types.SCENE_PT_rigid_body_cache,
+         types.SCENE_PT_rigid_body_field_weights,
+         types.PARTICLE_PT_boidbrain,
+         types.PARTICLE_PT_render,
+         types.PARTICLE_PT_draw,
+         types.PARTICLE_PT_children,
+         types.PARTICLE_PT_field_weights,
+         types.PARTICLE_PT_force_fields,
+         types.PARTICLE_PT_vertexgroups,
+         types.PARTICLE_PT_custom_props,
          )
  
  
index c12b0b00f540fad5302b3fd510c04b731644f417,3ff02420bbd5c81c98b0734cb4530afa7fda4750..64851a3a4c13919e3767980c407031f350ee23c7
@@@ -22,7 -22,7 +22,7 @@@ if "bpy" in locals()
      from imp import reload as _reload
      for val in _modules_loaded.values():
          _reload(val)
 -_modules = (
 +_modules = [
      "add_mesh_torus",
      "anim",
      "clip",
@@@ -35,6 -35,7 +35,7 @@@
      "object_randomize_transform",
      "object_quick_effects",
      "presets",
+     "rigidbody",
      "screen_play_rendered_anim",
      "sequencer",
      "uvcalc_follow_active",
      "vertexpaint_dirt",
      "view3d",
      "wm",
 -)
 +]
 +
 +import bpy
 +
 +if bpy.app.build_options.freestyle:
 +    _modules.append("freestyle")
  __import__(name=__name__, fromlist=_modules)
  _namespace = globals()
 -_modules_loaded = {name: _namespace[name] for name in _modules}
 +_modules_loaded = {name: _namespace[name] for name in _modules if name != 'bpy'}
  del _namespace
  
  
 -import bpy
 -
 -
  def register():
      bpy.utils.register_module(__name__)
  
index 3a47b9d2d7734f565df5eb1f5ddfa116dc06a120,982c723f08ea56a22024bc873f65610c6519ad7e..94f324d62d0dd108806e7191cdbc87ece66f0302
@@@ -48,10 -48,11 +48,12 @@@ _modules = 
      "properties_physics_dynamicpaint",
      "properties_physics_field",
      "properties_physics_fluid",
+     "properties_physics_rigidbody",
+     "properties_physics_rigidbody_constraint",
      "properties_physics_smoke",
      "properties_physics_softbody",
      "properties_render",
 +    "properties_render_layer",
      "properties_scene",
      "properties_texture",
      "properties_world",
@@@ -134,6 -135,7 +136,7 @@@ def register()
  def unregister():
      bpy.utils.unregister_module(__name__)
  
  # Define a default UIList, when a list does not need any custom drawing...
  class UI_UL_list(bpy.types.UIList):
      pass
index 77bb2d3d50ed383eb398c8483cf420ef67aa0422,29e32401d2b53b4be88b3787332e0660c8fc78de..cb5a473dba19ae287ec927a57f7f9680dbf56f73
@@@ -19,7 -19,7 +19,7 @@@
  
  # <pep8 compliant>
  import bpy
 -from bpy.types import Menu, Panel, UIList
 +from bpy.types import Menu, Panel
  
  
  class RENDER_MT_presets(Menu):
@@@ -43,6 -43,24 +43,7 @@@ class RENDER_MT_framerate_presets(Menu)
      draw = Menu.draw_preset
  
  
 -class RENDER_UL_renderlayers(UIList):
 -    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
 -        # assert(isinstance(item, bpy.types.SceneRenderLayer)
 -        layer = item
 -        if self.layout_type in {'DEFAULT', 'COMPACT'}:
 -            layout.label(layer.name, icon_value=icon)
 -            layout.prop(layer, "use", text="", index=index)
 -        elif self.layout_type in {'GRID'}:
 -            layout.alignment = 'CENTER'
 -            layout.label("", icon_value=icon)
 -
 -#     else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
 -#             uiItemL(sub, name, icon);
 -#             uiBlockSetEmboss(block, UI_EMBOSS);
 -#             uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0,  NULL);
 -#     }
 -
  class RenderButtonsPanel():
      bl_space_type = 'PROPERTIES'
      bl_region_type = 'WINDOW'
  
      @classmethod
      def poll(cls, context):
 -        rd = context.scene.render
 -        return context.scene and (rd.engine in cls.COMPAT_ENGINES)
 +        scene = context.scene
 +        return scene and (scene.render.engine in cls.COMPAT_ENGINES)
 +
 +
 +class RenderFreestyleButtonsPanel(RenderButtonsPanel):
 +    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
 +
 +    @classmethod
 +    def poll(cls, context):
 +        if not super().poll(context):
 +            return False
 +        return bpy.app.build_options.freestyle
  
  
  class RENDER_PT_render(RenderButtonsPanel, Panel):
          layout.prop(rd, "display_mode", text="Display")
  
  
 -class RENDER_PT_layers(RenderButtonsPanel, Panel):
 -    bl_label = "Layers"
 -    bl_options = {'DEFAULT_CLOSED'}
 -    COMPAT_ENGINES = {'BLENDER_RENDER'}
 -
 -    def draw(self, context):
 -        layout = self.layout
 -
 -        scene = context.scene
 -        rd = scene.render
 -
 -        row = layout.row()
 -        row.template_list("RENDER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
 -
 -        col = row.column(align=True)
 -        col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
 -        col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
 -
 -        row = layout.row()
 -        rl = rd.layers.active
 -        if rl:
 -            row.prop(rl, "name")
 -        row.prop(rd, "use_single_layer", text="", icon_only=True)
 -
 -        split = layout.split()
 -
 -        col = split.column()
 -        col.prop(scene, "layers", text="Scene")
 -        col.label(text="")
 -        col.prop(rl, "light_override", text="Light")
 -        col.prop(rl, "material_override", text="Material")
 -
 -        col = split.column()
 -        col.prop(rl, "layers", text="Layer")
 -        col.label(text="Mask Layers:")
 -        col.prop(rl, "layers_zmask", text="")
 -
 -        layout.separator()
 -        layout.label(text="Include:")
 -
 -        split = layout.split()
 -
 -        col = split.column()
 -        col.prop(rl, "use_zmask")
 -        row = col.row()
 -        row.prop(rl, "invert_zmask", text="Negate")
 -        row.active = rl.use_zmask
 -        col.prop(rl, "use_all_z")
 -
 -        col = split.column()
 -        col.prop(rl, "use_solid")
 -        col.prop(rl, "use_halo")
 -        col.prop(rl, "use_ztransp")
 -
 -        col = split.column()
 -        col.prop(rl, "use_sky")
 -        col.prop(rl, "use_edge_enhance")
 -        col.prop(rl, "use_strand")
 -
 -        layout.separator()
 -
 -        split = layout.split()
 -
 -        col = split.column()
 -        col.label(text="Passes:")
 -        col.prop(rl, "use_pass_combined")
 -        col.prop(rl, "use_pass_z")
 -        col.prop(rl, "use_pass_vector")
 -        col.prop(rl, "use_pass_normal")
 -        col.prop(rl, "use_pass_uv")
 -        col.prop(rl, "use_pass_mist")
 -        col.prop(rl, "use_pass_object_index")
 -        col.prop(rl, "use_pass_material_index")
 -        col.prop(rl, "use_pass_color")
 -
 -        col = split.column()
 -        col.label()
 -        col.prop(rl, "use_pass_diffuse")
 -        row = col.row()
 -        row.prop(rl, "use_pass_specular")
 -        row.prop(rl, "exclude_specular", text="")
 -        row = col.row()
 -        row.prop(rl, "use_pass_shadow")
 -        row.prop(rl, "exclude_shadow", text="")
 -        row = col.row()
 -        row.prop(rl, "use_pass_emit")
 -        row.prop(rl, "exclude_emit", text="")
 -        row = col.row()
 -        row.prop(rl, "use_pass_ambient_occlusion")
 -        row.prop(rl, "exclude_ambient_occlusion", text="")
 -        row = col.row()
 -        row.prop(rl, "use_pass_environment")
 -        row.prop(rl, "exclude_environment", text="")
 -        row = col.row()
 -        row.prop(rl, "use_pass_indirect")
 -        row.prop(rl, "exclude_indirect", text="")
 -        row = col.row()
 -        row.prop(rl, "use_pass_reflection")
 -        row.prop(rl, "exclude_reflection", text="")
 -        row = col.row()
 -        row.prop(rl, "use_pass_refraction")
 -        row.prop(rl, "exclude_refraction", text="")
 -
 -
  class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
      bl_label = "Dimensions"
      COMPAT_ENGINES = {'BLENDER_RENDER'}
@@@ -245,7 -357,7 +246,7 @@@ class RENDER_PT_performance(RenderButto
          subsub = sub.column()
          subsub.enabled = rd.threads_mode == 'FIXED'
          subsub.prop(rd, "threads")
-         
          sub = col.column(align=True)
          sub.label(text="Tile Size:")
          sub.prop(rd, "tile_x", text="X")
@@@ -308,29 -420,6 +309,29 @@@ class RENDER_PT_post_processing(RenderB
          sub.prop(rd, "edge_color", text="")
  
  
 +class RENDER_PT_freestyle(RenderFreestyleButtonsPanel, Panel):
 +    bl_label = "Freestyle"
 +    bl_options = {'DEFAULT_CLOSED'}
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw_header(self, context):
 +        rd = context.scene.render
 +        self.layout.prop(rd, "use_freestyle", text="")
 +
 +    def draw(self, context):
 +        rd = context.scene.render
 +
 +        layout = self.layout
 +        layout.active = rd.use_freestyle
 +
 +        row = layout.row()
 +        row.label(text="Line Thickness:")
 +        row.prop(rd, "line_thickness_mode", expand=True)
 +        row = layout.row()
 +        row.active = (rd.line_thickness_mode == 'ABSOLUTE')
 +        row.prop(rd, "unit_line_thickness")
 +
 +
  class RENDER_PT_stamp(RenderButtonsPanel, Panel):
      bl_label = "Stamp"
      bl_options = {'DEFAULT_CLOSED'}
index a35fb149aae20994535d9cb0b2d539a890033177,d1f9ea586542a09fdcf5c87022f9ad92f0ff5690..6c5cc93947b5c049632d395ded1873d469cfa23b
@@@ -1066,12 -1066,14 +1066,14 @@@ class VIEW3D_MT_make_links(Menu)
  
      def draw(self, context):
          layout = self.layout
+         operator_context_default = layout.operator_context
          if(len(bpy.data.scenes) > 10):
-             layout.operator_context = 'INVOKE_DEFAULT'
+             layout.operator_context = 'INVOKE_REGION_WIN'
              layout.operator("object.make_links_scene", text="Objects to Scene...", icon='OUTLINER_OB_EMPTY')
          else:
+             layout.operator_context = 'EXEC_REGION_WIN'
              layout.operator_menu_enum("object.make_links_scene", "scene", text="Objects to Scene...")
+         layout.operator_context = operator_context_default
  
          layout.operator_enum("object.make_links_data", "type")  # inline
  
@@@ -1537,7 -1539,7 +1539,7 @@@ class VIEW3D_MT_pose_group(Menu)
  
      def draw(self, context):
          layout = self.layout
-         
          pose = context.active_object.pose
  
          layout.operator_context = 'EXEC_AREA'
@@@ -1710,19 -1712,37 +1712,37 @@@ class VIEW3D_MT_edit_mesh_specials(Menu
  
          layout.operator("mesh.subdivide", text="Subdivide").smoothness = 0.0
          layout.operator("mesh.subdivide", text="Subdivide Smooth").smoothness = 1.0
+         layout.separator()
          layout.operator("mesh.merge", text="Merge...")
          layout.operator("mesh.remove_doubles")
+         layout.separator()
          layout.operator("mesh.hide", text="Hide").unselected = False
          layout.operator("mesh.reveal", text="Reveal")
          layout.operator("mesh.select_all", text="Select Inverse").action = 'INVERT'
+         layout.separator()
          layout.operator("mesh.flip_normals")
          layout.operator("mesh.vertices_smooth", text="Smooth")
          layout.operator("mesh.vertices_smooth_laplacian", text="Laplacian Smooth")
+         layout.separator()
          layout.operator("mesh.inset")
          layout.operator("mesh.bevel", text="Bevel")
          layout.operator("mesh.bridge_edge_loops")
+         layout.separator()
          layout.operator("mesh.faces_shade_smooth")
          layout.operator("mesh.faces_shade_flat")
+         layout.separator()
          layout.operator("mesh.blend_from_shape")
          layout.operator("mesh.shape_propagate_to_all")
          layout.operator("mesh.select_vertex_path")
@@@ -1789,10 -1809,11 +1809,11 @@@ class VIEW3D_MT_edit_mesh_vertices(Menu
          layout.operator("mesh.split")
          layout.operator_menu_enum("mesh.separate", "type")
          layout.operator("mesh.vert_connect")
-         layout.operator("mesh.vert_slide")
+         layout.operator("transform.vert_slide")
  
          layout.separator()
  
+         layout.operator("mesh.bevel").vertex_only = True
          layout.operator("mesh.vertices_smooth")
          layout.operator("mesh.remove_doubles")
          layout.operator("mesh.sort_elements", text="Sort Vertices").elements = {'VERT'}
@@@ -1839,12 -1860,6 +1860,12 @@@ class VIEW3D_MT_edit_mesh_edges(Menu)
  
          layout.separator()
  
 +        if context.scene and bpy.app.build_options.freestyle:
 +            layout.operator("mesh.mark_freestyle_edge").clear = False
 +            layout.operator("mesh.mark_freestyle_edge", text="Clear Freestyle Edge").clear = True
 +
 +        layout.separator()
 +
          layout.operator("mesh.edge_rotate", text="Rotate Edge CW").use_ccw = False
          layout.operator("mesh.edge_rotate", text="Rotate Edge CCW").use_ccw = True
  
@@@ -1885,12 -1900,6 +1906,12 @@@ class VIEW3D_MT_edit_mesh_faces(Menu)
  
          layout.separator()
  
 +        if context.scene and bpy.app.build_options.freestyle:
 +            layout.operator("mesh.mark_freestyle_face").clear = False
 +            layout.operator("mesh.mark_freestyle_face", text="Clear Freestyle Face").clear = True
 +
 +        layout.separator()
 +
          layout.operator("mesh.quads_convert_to_tris")
          layout.operator("mesh.tris_convert_to_quads")
  
@@@ -2394,9 -2403,6 +2415,6 @@@ class VIEW3D_PT_view3d_display(Panel)
          col.prop(view, "show_outline_selected")
          col.prop(view, "show_all_objects_origin")
          col.prop(view, "show_relationship_lines")
-         if ob and ob.type == 'MESH':
-             mesh = ob.data
-             col.prop(mesh, "show_all_edges")
  
          col = layout.column()
          col.active = display_all
              col.label(text="Shading:")
              col.prop(gs, "material_mode", text="")
              col.prop(view, "show_textured_solid")
+         if view.viewport_shade == 'SOLID':
+             col.prop(view, "use_matcap")
+             if view.use_matcap:
+                 col.template_icon_view(view, "matcap_icon")
          col.prop(view, "show_backface_culling")
  
          layout.separator()
@@@ -2494,9 -2503,6 +2515,9 @@@ class VIEW3D_PT_view3d_meshdisplay(Pane
          col.prop(mesh, "show_edge_bevel_weight", text="Bevel Weights")
          col.prop(mesh, "show_edge_seams", text="Seams")
          col.prop(mesh, "show_edge_sharp", text="Sharp")
 +        if context.scene and bpy.app.build_options.freestyle:
 +            col.prop(mesh, "show_freestyle_edge_marks", text="Freestyle Edge Marks")
 +            col.prop(mesh, "show_freestyle_face_marks", text="Freestyle Face Marks")
  
          col.separator()
          col.label(text="Normals:")
index e89ec2b255af1f74973ac4817675a9ecb49ebd79,36b05fd31f43bca2102ae99d62b90ebfea8d63d0..ddfc7c06fb6889f6923650bff1703105b087d4c0
@@@ -66,6 -66,7 +66,7 @@@ set(SRC_DNA_IN
        ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_packedFile_types.h
        ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_particle_types.h
        ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_property_types.h
+       ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_rigidbody_types.h
        ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_scene_types.h
        ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_screen_types.h
        ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_sdna_types.h
@@@ -106,6 -107,10 +107,10 @@@ add_subdirectory(modifiers
  add_subdirectory(makesdna)
  add_subdirectory(makesrna)
  
+ if(WITH_BULLET)
+       add_subdirectory(rigidbody)
+ endif()
  if(WITH_COMPOSITOR)
        add_subdirectory(opencl)  # later on this may be used more generally
        add_subdirectory(compositor)
@@@ -138,11 -143,3 +143,11 @@@ endif(
  if(WITH_OPENCOLLADA)
        add_subdirectory(collada)
  endif()
 +
 +if(WITH_FREESTYLE)
 +      list(APPEND SRC_DNA_INC
 +              ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_linestyle_types.h
 +      )
 +      add_subdirectory(freestyle)
 +endif()
 +
index 5675575e24595dae0af100f197fed72105d03ff6,80457c739b6d7316112746521f266e297fad35c6..e103aaf8befc964f1bfb132b43eb6028a6e1d044
@@@ -61,12 -61,12 +61,15 @@@ if env['WITH_BF_OPENEXR']
  if env['WITH_BF_QUICKTIME']:
      SConscript (['quicktime/SConscript'])
  
+ if env['WITH_BF_BULLET']:
+     SConscript (['rigidbody/SConscript'])
  if env['WITH_BF_COLLADA']:
      SConscript (['collada/SConscript'])
      
  if env['WITH_BF_COMPOSITOR']:
      SConscript (['compositor/SConscript',
                   'opencl/SConscript'])
 +
 +if env['WITH_BF_FREESTYLE']:
 +    SConscript (['freestyle/SConscript'])
index 9a2789d36ccbe5159e2bbdd797fbb68cfa5ee8d5,35ca5f19bdc890dc7dcf4a7969c48f1d3744844c..5b2c4e87165841e9e3cffa929dd766a2cc4a44c5
@@@ -33,6 -33,8 +33,8 @@@
  #ifndef __BLF_TRANSLATION_H__
  #define __BLF_TRANSLATION_H__
  
+ #include "BLI_utildefines.h"  /* for bool type */
  #define TEXT_DOMAIN_NAME "blender"
  
  /* blf_lang.c */
@@@ -48,24 -50,30 +50,30 @@@ void BLF_lang_free(void)
  
  /* Set the current locale. */
  void BLF_lang_set(const char *);
- /* Get the current locale (short code, e.g. es_ES). */
+ /* Get the current locale ([partial] ISO code, e.g. es_ES). */
  const char *BLF_lang_get(void);
  
+ /* Get locale's elements (if relevant pointer is not NULL and element actually exists, e.g. if there is no variant,
+  * *variant and *language_variant will always be NULL).
+  * Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them.
+  * NOTE: Always available, even in non-WITH_INTERNATIONAL builds.
+  */
+ void BLF_locale_explode(const char *locale, char **language, char **country, char **variant,
+                         char **language_country, char **language_variant);
  /* Get EnumPropertyItem's for translations menu. */
  struct EnumPropertyItem *BLF_RNA_lang_enum_properties(void);
  
  /* blf_translation.c  */
  
- #ifdef WITH_INTERNATIONAL
  unsigned char *BLF_get_unifont(int *unifont_size);
  void BLF_free_unifont(void);
- #endif
  
  const char *BLF_pgettext(const char *msgctxt, const char *msgid);
  
  /* translation */
int BLF_translate_iface(void);
int BLF_translate_tooltips(void);
bool BLF_translate_iface(void);
bool BLF_translate_tooltips(void);
  const char *BLF_translate_do_iface(const char *msgctxt, const char *msgid);
  const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid);
  
  
  /* Those macros should be used everywhere in UI code. */
  #ifdef WITH_INTERNATIONAL
- /*    #define _(msgid) BLF_gettext(msgid) */
      #define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid)
      #define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid)
      #define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid)
      #define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid)
+ /*#  define _(msgid) BLF_gettext(msgid) */
#  define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid)
#  define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid)
#  define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid)
#  define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid)
  #else
- /*    #define _(msgid) msgid */
      #define IFACE_(msgid) msgid
      #define TIP_(msgid) msgid
      #define CTX_IFACE_(context, msgid) msgid
      #define CTX_TIP_(context, msgid)   msgid
+ /*#  define _(msgid) msgid */
#  define IFACE_(msgid) msgid
#  define TIP_(msgid)   msgid
#  define CTX_IFACE_(context, msgid) msgid
#  define CTX_TIP_(context, msgid)   msgid
  #endif
  
  /* Helper macro, when we want to define a same msgid for multiple msgctxt...
   * things, and limit the number of existing contexts!
   */
  
- /* Default, void context. Just in case... */
- #define BLF_I18NCONTEXT_DEFAULT ""
+ /* Default, void context.
+  * WARNING! The "" context is not the same as no (NULL) context at mo/boost::locale level!
+  */
+ #define BLF_I18NCONTEXT_DEFAULT NULL  /* Translated as None in Python. */
+ #define BLF_I18NCONTEXT_DEFAULT_BPY_INTERN ""  /* Only used in code, never exposed to user! */
  
  /* Default context for operator names/labels. */
  #define BLF_I18NCONTEXT_OPERATOR_DEFAULT "Operator"
  #define BLF_I18NCONTEXT_ID_BRUSH                "Brush"
  #define BLF_I18NCONTEXT_ID_CAMERA               "Camera"
  #define BLF_I18NCONTEXT_ID_CURVE                "Curve"
 +#ifdef WITH_FREESTYLE
 +#  define BLF_I18NCONTEXT_ID_FREESTYLELINESTYLE   "FreestyleLineStyle"
 +#endif
  #define BLF_I18NCONTEXT_ID_GPENCIL              "GPencil"
  #define BLF_I18NCONTEXT_ID_GROUP                "Group"
  #define BLF_I18NCONTEXT_ID_ID                   "ID"
  #define BLF_I18NCONTEXT_ID_MOVIECLIP            "MovieClip"
  #define BLF_I18NCONTEXT_ID_MASK                 "Mask"
  
+ /* Helper for bpy.app.i18n object... */
+ typedef struct
+ {
+       const char *c_id;
+       const char *py_id;
+       const char *value;
+ } BLF_i18n_contexts_descriptor;
+ #define BLF_I18NCONTEXTS_ITEM(ctxt_id, py_id) {#ctxt_id, py_id, ctxt_id}
+ #define BLF_I18NCONTEXTS_DESC {                                                                                        \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT, "default"),                                                         \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"),                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ACTION, "id_action"),                                                     \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ARMATURE, "id_armature"),                                                 \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_BRUSH, "id_brush"),                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_CAMERA, "id_camera"),                                                     \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_CURVE, "id_curve"),                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_GPENCIL, "id_gpencil"),                                                   \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_GROUP, "id_group"),                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ID, "id_id"),                                                             \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_IMAGE, "id_image"),                                                       \
+       /*BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_IPO, "id_ipo"),*/                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SHAPEKEY, "id_shapekey"),                                                 \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LAMP, "id_lamp"),                                                         \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LIBRARY, "id_library"),                                                   \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LATTICE, "id_lattice"),                                                   \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MATERIAL, "id_material"),                                                 \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_METABALL, "id_metaball"),                                                 \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MESH, "id_mesh"),                                                         \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_NODETREE, "id_nodetree"),                                                 \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_OBJECT, "id_object"),                                                     \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_PARTICLESETTINGS, "id_particlesettings"),                                 \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SCENE, "id_scene"),                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SCREEN, "id_screen"),                                                     \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SEQUENCE, "id_sequence"),                                                 \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SPEAKER, "id_speaker"),                                                   \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SOUND, "id_sound"),                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_TEXTURE, "id_texture"),                                                   \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_TEXT, "id_text"),                                                         \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_VFONT, "id_vfont"),                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_WORLD, "id_world"),                                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_WINDOWMANAGER, "id_windowmanager"),                                       \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MOVIECLIP, "id_movieclip"),                                               \
+       BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MASK, "id_mask"),                                                         \
+       {NULL, NULL, NULL}                                                                                                 \
+ }
  #endif /* __BLF_TRANSLATION_H__ */
index a3afd853cbae259a5582bf5af900ec7b3583e745,7bb80c343232e1d0a39f8501554b9d6c738dcb59..42298133d7d7e9b92aea3d6d4cf92592717ca6cf
@@@ -29,6 -29,7 +29,7 @@@ set(IN
        ../editors/include
        ../makesdna
        ../makesrna
+       ../python
        ../imbuf
        ../../../intern/guardedalloc
        ../../../intern/locale
@@@ -58,10 -59,6 +59,10 @@@ if(WITH_INTERNATIONAL
        add_definitions(-DWITH_INTERNATIONAL)
  endif()
  
 +if(WITH_FREESTYLE)
 +      add_definitions(-DWITH_FREESTYLE)
 +endif()
 +
  add_definitions(-DGLEW_STATIC)
  
  blender_add_lib(bf_blenfont "${SRC}" "${INC}" "${INC_SYS}")
index 354a030775e1e978620d5388870693349d0a966b,3529330a308e909a84a0ac0554ef8a398f2caaac..8273ddf1e4019182d032913886ccf6bd8ef38533
@@@ -31,7 -31,7 +31,7 @@@ Import ('env'
  sources = env.Glob('intern/*.c')
  
  incs = '. intern  #/intern/guardedalloc #/intern/locale ../blenkernel ../blenlib ../blenloader'
- incs += ' ../makesdna ../makesrna ../imbuf ../editors/include'
+ incs += ' ../makesdna ../makesrna ../python ../imbuf ../editors/include'
  incs += ' #/extern/glew/include'
  incs += ' ' + env['BF_FREETYPE_INC']
  
@@@ -43,7 -43,4 +43,7 @@@ if sys.platform == 'win32' or env['OURP
  if env['WITH_BF_INTERNATIONAL']:
      defs.append('WITH_INTERNATIONAL')
  
- env.BlenderLib ( 'bf_blenfont', sources, Split(incs), Split(defs), libtype=['core','player'], priority=[210,210] )
 +if env['WITH_BF_FREESTYLE']:
 +    defs.append('WITH_FREESTYLE')
 +
+ env.BlenderLib ( 'bf_blenfont', sources, Split(incs), defines=defs, libtype=['core','player'], priority=[210,210] )
index be42ee524deb1668df1dfbb792cf284c74a3ff2f,8e4d370e8a041c5f14d72ea3b9e546a586d62f21..7c36ff07da529296a273db2bef26c774a064a8b4
@@@ -88,9 -88,6 +88,9 @@@ typedef struct Main 
        ListBase gpencil;
        ListBase movieclip;
        ListBase mask;
 +#ifdef WITH_FREESTYLE
 +      ListBase linestyle;
 +#endif
  
        char id_tag_update[256];
  } Main;
  }
  #endif
  
- #endif
+ #endif  /* __BKE_MAIN_H__ */
index 23f23acad6bd937c458ed3901bc9ed6a24085c58,fefd4c89fbe330b5b16afad33a46b1590c95f3da..2eeecefe231ceba283ce8e57e596f2e9fc966f5c
@@@ -128,6 -128,7 +128,7 @@@ set(SR
        intern/pointcache.c
        intern/property.c
        intern/report.c
+       intern/rigidbody.c
        intern/sca.c
        intern/scene.c
        intern/screen.c
        intern/world.c
        intern/writeavi.c
        intern/writeframeserver.c
 -
 +      
        BKE_DerivedMesh.h
        BKE_action.h
        BKE_addon.h
        BKE_pointcache.h
        BKE_property.h
        BKE_report.h
+       BKE_rigidbody.h
        BKE_sca.h
        BKE_scene.h
        BKE_screen.h
@@@ -261,7 -263,10 +263,10 @@@ if(WITH_BULLET
        list(APPEND INC_SYS
                ${BULLET_INCLUDE_DIRS}
        )
-       add_definitions(-DUSE_BULLET)
+       list(APPEND INC
+               ../rigidbody
+       )
+       add_definitions(-DWITH_BULLET)
  endif()
  
  #if(WITH_MOD_CLOTH_ELTOPO)
@@@ -419,17 -424,6 +424,17 @@@ if(WITH_INTERNATIONAL
        add_definitions(-DWITH_INTERNATIONAL)
  endif()
  
 +if(WITH_FREESTYLE)
 +      list(APPEND SRC
 +              intern/linestyle.c
 +              BKE_linestyle.h
 +      )
 +      list(APPEND INC
 +              ../freestyle
 +      )
 +      add_definitions(-DWITH_FREESTYLE)
 +endif()
 +
  ## Warnings as errors, this is too strict!
  #if(MSVC)
  #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
index 2998da824efe295942c429a759d5b50bdb3b360a,e53e4724071e765344b40522dc3305fbd39e2f41..bcdf37da1047627a598ccfe40fdfe077f92ac4d0
@@@ -41,6 -41,7 +41,7 @@@ incs += ' ../render/extern/include ../m
  incs += ' ../imbuf ../ikplugin ../avi #/intern/elbeem/extern ../nodes ../modifiers'
  incs += ' #/intern/iksolver/extern ../blenloader'
  incs += ' #/extern/bullet2/src'
+ incs += ' ../rigidbody'
  incs += ' #/intern/opennl/extern #/intern/bsp/extern'
  incs += ' ../gpu #/extern/glew/include'
  incs += ' ../bmesh'
@@@ -110,7 -111,7 +111,7 @@@ if env['WITH_BF_QUICKTIME']
      incs += ' ' + env['BF_QUICKTIME_INC']
  
  if env['WITH_BF_BULLET']:
-     defs.append('USE_BULLET')
+     defs.append('WITH_BULLET')
  
  if env['OURPLATFORM'] == 'darwin':
      if env['WITH_BF_OPENMP']:
@@@ -147,12 -148,6 +148,12 @@@ if env['WITH_BF_FFTW3']
  if env['WITH_BF_INTERNATIONAL']:
      defs.append('WITH_INTERNATIONAL')
  
 +if env['WITH_BF_FREESTYLE']:
 +    defs.append('WITH_FREESTYLE')
 +    incs += ' ../freestyle'
 +else:
 +    sources.remove(os.path.join('intern', 'linestyle.c'))
 +
  if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'):
      incs += ' ' + env['BF_PTHREADS_INC']
  
index 6db1052d6bd6b855d1aa79ffe4ac038ade9b3fb2,b0021050e8f5076e97d3fef31a4d07e0465ba3f4..624e86d5787e85a798713f2c5bc1bb0d072670a0
@@@ -70,9 -70,6 +70,9 @@@
  #include "DNA_vfont_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_smoke_types.h"
 +#ifdef WITH_FREESTYLE
 +#  include "DNA_freestyle_types.h"
 +#endif
  
  #include "BLI_blenlib.h"
  #include "BLI_utildefines.h"
@@@ -462,6 -459,10 +462,10 @@@ void BKE_bpath_traverse_id(Main *bmain
                                        OceanModifierData *omd = (OceanModifierData *) md;
                                        rewrite_path_fixed(omd->cachepath, visit_cb, absbase, bpath_user_data);
                                }
+                               else if (md->type == eModifierType_MeshCache) {
+                                       MeshCacheModifierData *mcmd = (MeshCacheModifierData *) md;
+                                       rewrite_path_fixed(mcmd->filepath, visit_cb, absbase, bpath_user_data);
+                               }
                        }
  
                        if (ob->soft) {
                                }
                                SEQ_END
                        }
 +#ifdef WITH_FREESTYLE
 +                      {
 +                              SceneRenderLayer *srl = scene->r.layers.first;
 +
 +                              for(; srl; srl = srl->next) {
 +                                      FreestyleModuleConfig* module = srl->freestyleConfig.modules.first;
 +                                      for (; module; module = module->next) {
 +                                              rewrite_path_fixed(module->module_path, visit_cb, absbase, bpath_user_data);
 +                                      }
 +                              }
 +                      }
 +#endif
                        break;
                }
                case ID_ME:
index 98625807ddcd136fe6285f2db38c4ba2463c58f0,817068ae41eb274e00195d86c949a0540822e572..610237abcddb6cbbdba4510ad341de807df6474a
@@@ -47,6 -47,7 +47,7 @@@
  #include "DNA_brush_types.h"
  #include "DNA_camera_types.h"
  #include "DNA_group_types.h"
+ #include "DNA_gpencil_types.h"
  #include "DNA_ipo_types.h"
  #include "DNA_key_types.h"
  #include "DNA_lamp_types.h"
@@@ -54,6 -55,8 +55,8 @@@
  #include "DNA_material_types.h"
  #include "DNA_mesh_types.h"
  #include "DNA_meta_types.h"
+ #include "DNA_movieclip_types.h"
+ #include "DNA_mask_types.h"
  #include "DNA_nla_types.h"
  #include "DNA_node_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_vfont_types.h"
  #include "DNA_windowmanager_types.h"
  #include "DNA_world_types.h"
- #include "DNA_gpencil_types.h"
- #include "DNA_movieclip_types.h"
- #include "DNA_mask_types.h"
  
  #include "BLI_blenlib.h"
  #include "BLI_dynstr.h"
  #include "BLI_utildefines.h"
  #include "BKE_bpath.h"
  
+ #include "BKE_action.h"
  #include "BKE_animsys.h"
+ #include "BKE_armature.h"
+ #include "BKE_brush.h"
  #include "BKE_camera.h"
  #include "BKE_context.h"
- #include "BKE_lamp.h"
- #include "BKE_library.h"
- #include "BKE_main.h"
- #include "BKE_global.h"
- #include "BKE_sound.h"
- #include "BKE_object.h"
- #include "BKE_screen.h"
- #include "BKE_mesh.h"
- #include "BKE_material.h"
  #include "BKE_curve.h"
- #include "BKE_mball.h"
- #include "BKE_text.h"
- #include "BKE_texture.h"
- #include "BKE_scene.h"
+ #include "BKE_fcurve.h"
+ #include "BKE_font.h"
+ #include "BKE_global.h"
+ #include "BKE_group.h"
+ #include "BKE_gpencil.h"
+ #include "BKE_idprop.h"
  #include "BKE_icons.h"
  #include "BKE_image.h"
  #include "BKE_ipo.h"
  #include "BKE_key.h"
- #include "BKE_world.h"
- #include "BKE_font.h"
- #include "BKE_group.h"
+ #include "BKE_lamp.h"
  #include "BKE_lattice.h"
- #include "BKE_armature.h"
- #include "BKE_action.h"
+ #include "BKE_library.h"
+ #include "BKE_mesh.h"
+ #include "BKE_material.h"
+ #include "BKE_main.h"
+ #include "BKE_mball.h"
+ #include "BKE_movieclip.h"
+ #include "BKE_mask.h"
  #include "BKE_node.h"
- #include "BKE_brush.h"
- #include "BKE_idprop.h"
+ #include "BKE_object.h"
  #include "BKE_particle.h"
- #include "BKE_gpencil.h"
- #include "BKE_fcurve.h"
+ #include "BKE_packedFile.h"
  #include "BKE_speaker.h"
- #include "BKE_movieclip.h"
- #include "BKE_mask.h"
+ #include "BKE_sound.h"
+ #include "BKE_screen.h"
+ #include "BKE_scene.h"
+ #include "BKE_text.h"
+ #include "BKE_texture.h"
+ #include "BKE_world.h"
 +#ifdef WITH_FREESTYLE
 +#  include "BKE_linestyle.h"
 +#endif
  
  #include "RNA_access.h"
  
   * only use this definition, makes little and big endian systems
   * work fine, in conjunction with MAKE_ID */
  
- /* from blendef: */
- #define GS(a)  (*((short *)(a)))
  /* ************* general ************************ */
  
  
@@@ -281,10 -276,6 +279,10 @@@ int id_make_local(ID *id, int test
                        return 0; /* can't be linked */
                case ID_GD:
                        return 0; /* not implemented */
 +#ifdef WITH_FREESTYLE
 +              case ID_LS:
 +                      return 0; /* not implemented */
 +#endif
        }
  
        return 0;
@@@ -379,11 -370,6 +377,11 @@@ int id_copy(ID *id, ID **newid, int tes
                case ID_MSK:
                        if (!test) *newid = (ID *)BKE_mask_copy((Mask *)id);
                        return 1;
 +#ifdef WITH_FREESTYLE
 +              case ID_LS:
 +                      if(!test) *newid= (ID*)FRS_copy_linestyle((FreestyleLineStyle*)id);
 +                      return 1;
 +#endif
        }
        
        return 0;
@@@ -514,10 -500,6 +512,10 @@@ ListBase *which_libbase(Main *mainlib, 
                        return &(mainlib->movieclip);
                case ID_MSK:
                        return &(mainlib->mask);
 +#ifdef WITH_FREESTYLE
 +              case ID_LS:
 +                      return &(mainlib->linestyle);
 +#endif
        }
        return NULL;
  }
@@@ -602,9 -584,6 +600,9 @@@ int set_listbasepointers(Main *main, Li
        lb[a++] = &(main->wm);
        lb[a++] = &(main->movieclip);
        lb[a++] = &(main->mask);
 +#ifdef WITH_FREESTYLE
 +      lb[a++] = &(main->linestyle);
 +#endif
        
        lb[a] = NULL;
  
@@@ -719,11 -698,6 +717,11 @@@ static ID *alloc_libblock_notest(short 
                case ID_MSK:
                        id = MEM_callocN(sizeof(Mask), "Mask");
                        break;
 +#ifdef WITH_FREESTYLE
 +              case ID_LS:
 +                      id = MEM_callocN(sizeof(FreestyleLineStyle), "Freestyle Line Style");
 +                      break;
 +#endif
        }
        return id;
  }
@@@ -795,9 -769,10 +793,10 @@@ void *BKE_libblock_copy(ID *id
        return idn;
  }
  
- static void BKE_library_free(Library *UNUSED(lib))
+ static void BKE_library_free(Library *lib)
  {
-       /* no freeing needed for libraries yet */
+       if (lib->packedfile)
+               freePackedFile(lib->packedfile);
  }
  
  static void (*free_windowmanager_cb)(bContext *, wmWindowManager *) = NULL;
@@@ -948,11 -923,6 +947,11 @@@ void BKE_libblock_free(ListBase *lb, vo
                case ID_MSK:
                        BKE_mask_free(bmain, (Mask *)id);
                        break;
 +#ifdef WITH_FREESTYLE
 +              case ID_LS:
 +                      FRS_free_linestyle((FreestyleLineStyle *)id);
 +                      break;
 +#endif
        }
  
        BLI_remlink(lb, id);
index 4655dd04261ddeb6f859a6e822c5bdd3951c3cc1,f19dc93198d1cdb01917c0f90b58e5bd5d88f6e9..ad0a149a42c141958adb9eb63d31d6888e91b363
@@@ -153,9 -153,6 +153,9 @@@ void init_material(Material *ma
        ma->tx_limit = 0.0;
        ma->tx_falloff = 1.0;
        ma->shad_alpha = 1.0f;
 +#ifdef WITH_FREESTYLE
 +      ma->vcol_alpha = 0;
 +#endif
        
        ma->gloss_mir = ma->gloss_tra = 1.0;
        ma->samp_gloss_mir = ma->samp_gloss_tra = 18;
@@@ -684,19 -681,6 +684,6 @@@ Material *give_node_material(Material *
        return NULL;
  }
  
- /* GS reads the memory pointed at in a specific ordering. There are,
-  * however two definitions for it. I have jotted them down here, both,
-  * but I think the first one is actually used. The thing is that
-  * big-endian systems might read this the wrong way round. OTOH, we
-  * constructed the IDs that are read out with this macro explicitly as
-  * well. I expect we'll sort it out soon... */
- /* from blendef: */
- #define GS(a)   (*((short *)(a)))
- /* from misc_util: flip the bytes from x  */
- /*  #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
  void resize_object_material(Object *ob, const short totcol)
  {
        Material **newmatar;
index 5a22973164e089cddd5739b037dd3c00bd0802de,b5e82586f5a33a11dba03cebd741326e734a368a..8a6309593f19702a221e5dfc31273ae4cd0c9dc7
@@@ -83,6 -83,7 +83,7 @@@
  #include "BKE_fcurve.h"
  #include "BKE_group.h"
  #include "BKE_icons.h"
+ #include "BKE_image.h"
  #include "BKE_key.h"
  #include "BKE_lamp.h"
  #include "BKE_lattice.h"
@@@ -97,6 -98,7 +98,7 @@@
  #include "BKE_particle.h"
  #include "BKE_pointcache.h"
  #include "BKE_property.h"
+ #include "BKE_rigidbody.h"
  #include "BKE_sca.h"
  #include "BKE_scene.h"
  #include "BKE_sequencer.h"
  
  #include "GPU_material.h"
  
 +#ifdef WITH_FREESTYLE
 +#  include "FRS_freestyle.h"
 +#endif
 +
  /* Local function protos */
  float originmat[3][3];  /* after BKE_object_where_is_calc(), can be used in other functions (bad!) */
  
@@@ -312,6 -310,9 +314,9 @@@ void free_sculptsession(Object *ob
                if (ss->texcache)
                        MEM_freeN(ss->texcache);
  
+               if (ss->tex_pool)
+                       BKE_image_pool_free(ss->tex_pool);
                if (ss->layer_co)
                        MEM_freeN(ss->layer_co);
  
@@@ -386,6 -387,8 +391,8 @@@ void BKE_object_free(Object *ob
        BKE_free_constraints(&ob->constraints);
        
        free_partdeflect(ob->pd);
+       BKE_rigidbody_free_object(ob);
+       BKE_rigidbody_free_constraint(ob);
  
        if (ob->soft) sbFree(ob->soft);
        if (ob->bsoft) bsbFree(ob->bsoft);
@@@ -666,16 -669,6 +673,16 @@@ void BKE_object_unlink(Object *ob
                                }
                                SEQ_END
                        }
 +
 +#ifdef WITH_FREESTYLE
 +                      {
 +                              SceneRenderLayer *srl;
 +
 +                              for (srl= sce->r.layers.first; srl; srl= srl->next) {
 +                                      FRS_unlink_target_object(&srl->freestyleConfig, ob);
 +                              }
 +                      }
 +#endif
                }
  
                sce = sce->id.next;
@@@ -1296,6 -1289,8 +1303,8 @@@ static Object *object_copy_do(Object *o
        }
        obn->soft = copy_softbody(ob->soft, copy_caches);
        obn->bsoft = copy_bulletsoftbody(ob->bsoft);
+       obn->rigidbody_object = BKE_rigidbody_copy_object(ob);
+       obn->rigidbody_constraint = BKE_rigidbody_copy_constraint(ob);
  
        BKE_object_copy_particlesystems(obn, ob);
        
@@@ -2153,6 -2148,8 +2162,8 @@@ void BKE_object_where_is_calc_time(Scen
                BKE_object_to_mat4(ob, ob->obmat);
        }
        
+       BKE_rigidbody_sync_transforms(scene, ob, ctime);
+       
        /* solve constraints */
        if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
                bConstraintOb *cob;
@@@ -2714,8 -2711,10 +2725,10 @@@ void BKE_object_handle_update(Scene *sc
  
                                case OB_ARMATURE:
                                        if (ob->id.lib && ob->proxy_from) {
-                                               // printf("pose proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name);
-                                               BKE_pose_copy_result(ob->pose, ob->proxy_from->pose);
+                                               if (BKE_pose_copy_result(ob->pose, ob->proxy_from->pose) == false) {
+                                                       printf("Proxy copy error, lib Object: %s proxy Object: %s\n",
+                                                              ob->id.name + 2, ob->proxy_from->id.name + 2);
+                                               }
                                        }
                                        else {
                                                BKE_pose_where_is(scene, ob);
index eb56f34b99b35c3c4497ba55fd9cd31ce07306ea,9e8cf985f71693590cc4132430f4d839c626d2b5..285646191f755217b49279f6827086e4bfa5733a
@@@ -46,6 -46,7 +46,7 @@@
  #include "DNA_group_types.h"
  #include "DNA_node_types.h"
  #include "DNA_object_types.h"
+ #include "DNA_rigidbody_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_screen_types.h"
  #include "DNA_sequence_types.h"
@@@ -72,6 -73,7 +73,7 @@@
  #include "BKE_object.h"
  #include "BKE_paint.h"
  #include "BKE_pointcache.h"
+ #include "BKE_rigidbody.h"
  #include "BKE_scene.h"
  #include "BKE_sequencer.h"
  #include "BKE_world.h"
  //XXX #include "BIF_previewrender.h"
  //XXX #include "BIF_editseq.h"
  
 +#ifdef WITH_FREESTYLE
 +#  include "FRS_freestyle_config.h"
 +#endif
 +
  #ifdef WIN32
  #else
  #include <sys/time.h>
@@@ -314,6 -312,9 +316,9 @@@ void BKE_scene_free(Scene *sce
        BKE_free_animdata((ID *)sce);
        BKE_keyingsets_free(&sce->keyingsets);
        
+       if (sce->rigidbody_world)
+               BKE_rigidbody_free_world(sce->rigidbody_world);
+       
        if (sce->r.avicodecdata) {
                free_avicodecdata(sce->r.avicodecdata);
                MEM_freeN(sce->r.avicodecdata);
                sce->r.ffcodecdata.properties = NULL;
        }
        
 +#ifdef WITH_FREESTYLE
 +      {
 +              SceneRenderLayer *srl;
 +
 +              for (srl = sce->r.layers.first; srl; srl = srl->next) {
 +                      FRS_free_freestyle_config(srl);
 +              }
 +      }
 +#endif
 +      
        BLI_freelistN(&sce->markers);
        BLI_freelistN(&sce->transform_spaces);
        BLI_freelistN(&sce->r.layers);
@@@ -950,6 -941,18 +955,18 @@@ Base *BKE_scene_base_add(Scene *sce, Ob
        return b;
  }
  
+ void BKE_scene_base_unlink(Scene *sce, Base *base)
+ {
+       /* remove rigid body constraint from world before removing object */
+       if (base->object->rigidbody_constraint)
+               BKE_rigidbody_remove_constraint(sce, base->object);
+       /* remove rigid body object from world before removing object */
+       if (base->object->rigidbody_object)
+               BKE_rigidbody_remove_object(sce, base->object);
+       
+       BLI_remlink(&sce->base, base);
+ }
  void BKE_scene_base_deselect_all(Scene *sce)
  {
        Base *b;
@@@ -1205,6 -1208,12 +1222,12 @@@ void BKE_scene_update_for_newframe(Mai
        BKE_animsys_evaluate_all_animation(bmain, sce, ctime);
        /*...done with recusrive funcs */
  
+       /* run rigidbody sim */
+       // XXX: this position may still change, objects not being updated correctly before simulation is run
+       // NOTE: current position is so that rigidbody sim affects other objects
+       if (BKE_scene_check_rigidbody_active(sce))
+               BKE_rigidbody_do_simulation(sce, ctime);
        /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later 
         * when trying to find materials with drivers that need evaluating [#32017] 
         */
@@@ -1243,9 -1252,6 +1266,9 @@@ SceneRenderLayer *BKE_scene_add_render_
        srl->lay = (1 << 20) - 1;
        srl->layflag = 0x7FFF;   /* solid ztra halo edge strand */
        srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
 +#ifdef WITH_FREESTYLE
 +      FRS_add_freestyle_config(srl);
 +#endif
  
        return srl;
  }
@@@ -1393,3 -1399,8 +1416,8 @@@ int BKE_scene_check_color_management_en
  {
        return strcmp(scene->display_settings.display_device, "None") != 0;
  }
+ int BKE_scene_check_rigidbody_active(const Scene *scene)
+ {
+       return scene && scene->rigidbody_world && scene->rigidbody_world->group && !(scene->rigidbody_world->flag & RBW_FLAG_MUTED);
+ }
index 01409a0f7e4fd7ba380eb5b45e0040833b6cbc2e,2e10407bee8dd11f719ec0fb2663cfdaf944373a..ce6e158b6d978cdb268ed8cb382e069ea56bc83f
@@@ -964,11 -964,7 +964,11 @@@ static void ccgDM_getFinalEdge(DerivedM
  
                edgeFlag = (ccgdm->edgeFlags) ? &ccgdm->edgeFlags[i] : NULL;
                if (edgeFlag)
 +#ifdef WITH_FREESTYLE
 +                      flags |= (*edgeFlag & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER;
 +#else
                        flags |= (*edgeFlag & (ME_SEAM | ME_SHARP)) | ME_EDGEDRAW | ME_EDGERENDER;
 +#endif
                else
                        flags |= ME_EDGEDRAW | ME_EDGERENDER;
  
@@@ -1017,7 -1013,11 +1017,11 @@@ static void ccgDM_getFinalFace(DerivedM
                mf->flag = faceFlags[i].flag;
                mf->mat_nr = faceFlags[i].mat_nr;
        }
-       else mf->flag = ME_SMOOTH;
+       else {
+               mf->flag = ME_SMOOTH;
 -      }
++}
+       mf->edcode = 0;
  }
  
  /* Translate GridHidden into the ME_HIDE flag for MVerts. Assumes
@@@ -1097,6 -1097,14 +1101,14 @@@ void subsurf_copy_grid_paint_mask(Deriv
        }
  }
  
+ /* utility functon */
+ BLI_INLINE void ccgDM_to_MVert(MVert *mv, const CCGKey *key, CCGElem *elem)
+ {
+       copy_v3_v3(mv->co, CCG_elem_co(key, elem));
+       normal_float_to_short_v3(mv->no, CCG_elem_no(key, elem));
+       mv->flag = mv->bweight = 0;
+ }
  static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
  {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
        int totvert, totedge, totface;
        int gridSize = ccgSubSurf_getGridSize(ss);
        int edgeSize = ccgSubSurf_getEdgeSize(ss);
-       int i = 0;
+       unsigned int i = 0;
  
        CCG_key_top_level(&key, ss);
  
                int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
  
                vd = ccgSubSurf_getFaceCenterData(f);
-               copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd));
-               normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd));
-               i++;
+               ccgDM_to_MVert(&mvert[i++], &key, vd);
                
                for (S = 0; S < numVerts; S++) {
-                       for (x = 1; x < gridSize - 1; x++, i++) {
+                       for (x = 1; x < gridSize - 1; x++) {
                                vd = ccgSubSurf_getFaceGridEdgeData(ss, f, S, x);
-                               copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd));
-                               normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd));
+                               ccgDM_to_MVert(&mvert[i++], &key, vd);
                        }
                }
  
                for (S = 0; S < numVerts; S++) {
                        for (y = 1; y < gridSize - 1; y++) {
-                               for (x = 1; x < gridSize - 1; x++, i++) {
+                               for (x = 1; x < gridSize - 1; x++) {
                                        vd = ccgSubSurf_getFaceGridData(ss, f, S, x, y);
-                                       copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd));
-                                       normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd));
+                                       ccgDM_to_MVert(&mvert[i++], &key, vd);
                                }
                        }
                }
                CCGEdge *e = ccgdm->edgeMap[index].edge;
                int x;
  
-               for (x = 1; x < edgeSize - 1; x++, i++) {
-                       vd = ccgSubSurf_getEdgeData(ss, e, x);
-                       copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd));
+               for (x = 1; x < edgeSize - 1; x++) {
                        /* This gives errors with -debug-fpe
                         * the normals don't seem to be unit length.
                         * this is most likely caused by edges with no
                         * faces which are now zerod out, see comment in:
                         * ccgSubSurf__calcVertNormals(), - campbell */
-                       normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd));
+                       vd = ccgSubSurf_getEdgeData(ss, e, x);
+                       ccgDM_to_MVert(&mvert[i++], &key, vd);
                }
        }
  
                CCGVert *v = ccgdm->vertMap[index].vert;
  
                vd = ccgSubSurf_getVertData(ss, v);
-               copy_v3_v3(mvert[i].co, CCG_elem_co(&key, vd));
-               normal_float_to_short_v3(mvert[i].no, CCG_elem_no(&key, vd));
-               i++;
+               ccgDM_to_MVert(&mvert[i++], &key, vd);
        }
  }
  
+ /* utility functon */
+ BLI_INLINE void ccgDM_to_MEdge(MEdge *med, const int v1, const int v2, const short flag)
+ {
+       med->v1 = v1;
+       med->v2 = v2;
+       med->crease = med->bweight = 0;
+       med->flag = flag;
+ }
  static void ccgDM_copyFinalEdgeArray(DerivedMesh *dm, MEdge *medge)
  {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
        int totedge, totface;
        int gridSize = ccgSubSurf_getGridSize(ss);
        int edgeSize = ccgSubSurf_getEdgeSize(ss);
-       int i = 0;
+       unsigned int i = 0;
        short *edgeFlags = ccgdm->edgeFlags;
+       const short ed_interior_flag = ccgdm->drawInteriorEdges ? (ME_EDGEDRAW | ME_EDGERENDER) : 0;
  
        totface = ccgSubSurf_getNumFaces(ss);
        for (index = 0; index < totface; index++) {
  
                for (S = 0; S < numVerts; S++) {
                        for (x = 0; x < gridSize - 1; x++) {
-                               MEdge *med = &medge[i];
-                               if (ccgdm->drawInteriorEdges)
-                                       med->flag = ME_EDGEDRAW | ME_EDGERENDER;
-                               med->v1 = getFaceIndex(ss, f, S, x, 0, edgeSize, gridSize);
-                               med->v2 = getFaceIndex(ss, f, S, x + 1, 0, edgeSize, gridSize);
-                               i++;
+                               ccgDM_to_MEdge(&medge[i++],
+                                              getFaceIndex(ss, f, S, x,     0, edgeSize, gridSize),
+                                              getFaceIndex(ss, f, S, x + 1, 0, edgeSize, gridSize),
+                                              ed_interior_flag);
                        }
  
                        for (x = 1; x < gridSize - 1; x++) {
                                for (y = 0; y < gridSize - 1; y++) {
-                                       MEdge *med;
-                                       med = &medge[i];
-                                       if (ccgdm->drawInteriorEdges)
-                                               med->flag = ME_EDGEDRAW | ME_EDGERENDER;
-                                       med->v1 = getFaceIndex(ss, f, S, x, y,
-                                                              edgeSize, gridSize);
-                                       med->v2 = getFaceIndex(ss, f, S, x, y + 1,
-                                                              edgeSize, gridSize);
-                                       i++;
-                                       med = &medge[i];
-                                       if (ccgdm->drawInteriorEdges)
-                                               med->flag = ME_EDGEDRAW | ME_EDGERENDER;
-                                       med->v1 = getFaceIndex(ss, f, S, y, x,
-                                                              edgeSize, gridSize);
-                                       med->v2 = getFaceIndex(ss, f, S, y + 1, x,
-                                                              edgeSize, gridSize);
-                                       i++;
+                                       ccgDM_to_MEdge(&medge[i++],
+                                                      getFaceIndex(ss, f, S, x, y,    edgeSize, gridSize),
+                                                      getFaceIndex(ss, f, S, x, y + 1, edgeSize, gridSize),
+                                                      ed_interior_flag);
+                                       ccgDM_to_MEdge(&medge[i++],
+                                                      getFaceIndex(ss, f, S, y, x,     edgeSize, gridSize),
+                                                      getFaceIndex(ss, f, S, y + 1, x, edgeSize, gridSize),
+                                                      ed_interior_flag);
                                }
                        }
                }
        totedge = ccgSubSurf_getNumEdges(ss);
        for (index = 0; index < totedge; index++) {
                CCGEdge *e = ccgdm->edgeMap[index].edge;
-               unsigned int flags = 0;
+               short ed_flag = 0;
                int x;
                int edgeIdx = GET_INT_FROM_POINTER(ccgSubSurf_getEdgeEdgeHandle(e));
  
-               if (!ccgSubSurf_getEdgeNumFaces(e)) flags |= ME_LOOSEEDGE;
+               if (!ccgSubSurf_getEdgeNumFaces(e)) {
+                       ed_flag |= ME_LOOSEEDGE;
+               }
  
                if (edgeFlags) {
                        if (edgeIdx != -1) {
-                               flags |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER);
 +#ifdef WITH_FREESTYLE
-                               flags |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP)) | ME_EDGEDRAW | ME_EDGERENDER);
++                              ed_flag |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER);
 +#else
+                               ed_flag |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP)) | ME_EDGEDRAW | ME_EDGERENDER);
 +#endif
                        }
                }
                else {
-                       flags |= ME_EDGEDRAW | ME_EDGERENDER;
+                       ed_flag |= ME_EDGEDRAW | ME_EDGERENDER;
                }
  
                for (x = 0; x < edgeSize - 1; x++) {
-                       MEdge *med = &medge[i];
-                       med->v1 = getEdgeIndex(ss, e, x, edgeSize);
-                       med->v2 = getEdgeIndex(ss, e, x + 1, edgeSize);
-                       med->flag = flags;
-                       i++;
+                       ccgDM_to_MEdge(&medge[i++],
+                                      getEdgeIndex(ss, e, x, edgeSize),
+                                      getEdgeIndex(ss, e, x + 1, edgeSize),
+                                      ed_flag);
                }
        }
  }
@@@ -1286,6 -1281,7 +1289,7 @@@ static void ccgDM_copyFinalFaceArray(De
                                                              edgeSize, gridSize);
                                        mf->mat_nr = mat_nr;
                                        mf->flag = flag;
+                                       mf->edcode = 0;
  
                                        i++;
                                }
index f438e6bdec3d444c32f541f752d39c159a217d77,e5851109d87ea585340a36322da6a5260c97b396..82ff09b5999a2091a5ebb6b0413933cf9211698d
@@@ -38,6 -38,7 +38,7 @@@ set(INC_SY
  
  set(SRC
        intern/BLI_args.c
+       intern/BLI_array.c
        intern/BLI_dynstr.c
        intern/BLI_ghash.c
        intern/BLI_heap.c
@@@ -164,10 -165,6 +165,10 @@@ if(WITH_OPENMP
        add_definitions(-DPARALLEL=1)
  endif()
  
 +if(WITH_FREESTYLE)
 +      add_definitions(-DWITH_FREESTYLE)
 +endif()
 +
  if(WIN32)
        list(APPEND INC
                ../../../intern/utfconv
index df68f71184373ae49180b35a62d3b9132361a84a,070cb4676a1e5c10f9cb7ce270fba3444b4ecf87..fdf23458c769f05247e8dbf9b0de250d6b29d50c
@@@ -70,9 -70,6 +70,9 @@@
  #include "DNA_key_types.h"
  #include "DNA_lattice_types.h"
  #include "DNA_lamp_types.h"
 +#ifdef WITH_FREESTYLE
 +#  include "DNA_linestyle_types.h"
 +#endif
  #include "DNA_meta_types.h"
  #include "DNA_material_types.h"
  #include "DNA_mesh_types.h"
@@@ -84,6 -81,7 +84,7 @@@
  #include "DNA_packedFile_types.h"
  #include "DNA_particle_types.h"
  #include "DNA_property_types.h"
+ #include "DNA_rigidbody_types.h"
  #include "DNA_text_types.h"
  #include "DNA_view3d_types.h"
  #include "DNA_screen_types.h"
   * - initialize FileGlobal and copy pointers to Global
   */
  
- /* also occurs in library.c */
- /* GS reads the memory pointed at in a specific ordering. There are,
-  * however two definitions for it. I have jotted them down here, both,
-  * but I think the first one is actually used. The thing is that
-  * big-endian systems might read this the wrong way round. OTOH, we
-  * constructed the IDs that are read out with this macro explicitly as
-  * well. I expect we'll sort it out soon... */
- /* from blendef: */
- #define GS(a) (*((short *)(a)))
- /* from misc_util: flip the bytes from x  */
- /*  #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
  /***/
  
  typedef struct OldNew {
@@@ -1086,10 -1070,10 +1073,10 @@@ FileData *blo_openblendermemory(void *m
                        }
                }
                else
 -                      fd->read = fd_read_from_memory;
 +              fd->read = fd_read_from_memory;
                        
                fd->flags |= FD_FLAGS_NOT_MY_BUFFER;
 -
 +              
                return blo_decode_and_check(fd, reports);
        }
  }
@@@ -1219,19 -1203,19 +1206,19 @@@ static void *newdataadr(FileData *fd, v
        return oldnewmap_lookup_and_inc(fd->datamap, adr);
  }
  
 -static void *newglobadr(FileData *fd, void *adr)          /* direct datablocks with global linking */
 +static void *newglobadr(FileData *fd, void *adr)              /* direct datablocks with global linking */
  {
        return oldnewmap_lookup_and_inc(fd->globmap, adr);
  }
  
 -static void *newimaadr(FileData *fd, void *adr)                   /* used to restore image data after undo */
 +static void *newimaadr(FileData *fd, void *adr)               /* used to restore image data after undo */
  {
        if (fd->imamap && adr)
                return oldnewmap_lookup_and_inc(fd->imamap, adr);
        return NULL;
  }
  
 -static void *newmclipadr(FileData *fd, void *adr)      /* used to restore movie clip data after undo */
 +static void *newmclipadr(FileData *fd, void *adr)              /* used to restore movie clip data after undo */
  {
        if (fd->movieclipmap && adr)
                return oldnewmap_lookup_and_inc(fd->movieclipmap, adr);
@@@ -1242,7 -1226,7 +1229,7 @@@ static void *newpackedadr(FileData *fd
  {
        if (fd->packedmap && adr)
                return oldnewmap_lookup_and_inc(fd->packedmap, adr);
 -      
 +
        return oldnewmap_lookup_and_inc(fd->datamap, adr);
  }
  
@@@ -1442,6 -1426,8 +1429,8 @@@ void blo_end_movieclip_pointer_map(File
        }
  }
  
+ /* XXX disabled this feature - packed files also belong in temp saves and quit.blend, to make restore work */
  static void insert_packedmap(FileData *fd, PackedFile *pf)
  {
        oldnewmap_insert(fd->packedmap, pf, pf, 0);
@@@ -1865,6 -1851,7 +1854,7 @@@ static PreviewImage *direct_link_previe
                        if (prv->rect[i]) {
                                prv->rect[i] = newdataadr(fd, prv->rect[i]);
                        }
+                       prv->gputexture[i] = NULL;
                }
        }
        
@@@ -2726,14 -2713,15 +2716,15 @@@ static void lib_link_pose(FileData *fd
  {
        bPoseChannel *pchan;
        bArmature *arm = ob->data;
-       int rebuild;
+       int rebuild = 0;
        
        if (!pose || !arm)
                return;
        
-       
-       /* always rebuild to match proxy or lib changes */
-       rebuild = ob->proxy || (ob->id.lib==NULL && arm->id.lib);
+       /* always rebuild to match proxy or lib changes, but on Undo */
+       if (fd->memfile == NULL)
+               if (ob->proxy || (ob->id.lib==NULL && arm->id.lib))
+                       rebuild = 1;
        
        if (ob->proxy) {
                /* sync proxy layer */
@@@ -3343,7 -3331,7 +3334,7 @@@ static void direct_link_texture(FileDat
        tex->env = newdataadr(fd, tex->env);
        if (tex->env) {
                tex->env->ima = NULL;
 -              memset(tex->env->cube, 0, 6 * sizeof(void *));
 +              memset(tex->env->cube, 0, 6*sizeof(void *));
                tex->env->ok= 0;
        }
        tex->pd = newdataadr(fd, tex->pd);
@@@ -4178,8 -4166,6 +4169,6 @@@ static void lib_link_object(FileData *f
                                else {
                                        /* this triggers object_update to always use a copy */
                                        ob->proxy->proxy_from = ob;
-                                       /* force proxy updates after load/undo, a bit weak */
-                                       ob->recalc = ob->proxy->recalc = (OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
                                }
                        }
                        ob->proxy_group = newlibadr(fd, ob->id.lib, ob->proxy_group);
                        
                        lib_link_particlesystems(fd, ob, &ob->id, &ob->particlesystem);
                        lib_link_modifiers(fd, ob);
+                       if (ob->rigidbody_constraint) {
+                               ob->rigidbody_constraint->ob1 = newlibadr(fd, ob->id.lib, ob->rigidbody_constraint->ob1);
+                               ob->rigidbody_constraint->ob2 = newlibadr(fd, ob->id.lib, ob->rigidbody_constraint->ob2);
+                       }
                }
        }
        
@@@ -4800,6 -4791,20 +4794,20 @@@ static void direct_link_object(FileDat
        }
        ob->bsoft = newdataadr(fd, ob->bsoft);
        ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */
+       
+       ob->rigidbody_object = newdataadr(fd, ob->rigidbody_object);
+       if (ob->rigidbody_object) {
+               RigidBodyOb *rbo = ob->rigidbody_object;
+               
+               /* must nullify the references to physics sim objects, since they no-longer exist 
+                * (and will need to be recalculated) 
+                */
+               rbo->physics_object = NULL;
+               rbo->physics_shape = NULL;
+       }
+       ob->rigidbody_constraint = newdataadr(fd, ob->rigidbody_constraint);
+       if (ob->rigidbody_constraint)
+               ob->rigidbody_constraint->physics_constraint = NULL;
  
        link_list(fd, &ob->particlesystem);
        direct_link_particlesystems(fd, &ob->particlesystem);
@@@ -5018,6 -5023,18 +5026,18 @@@ static void lib_link_scene(FileData *fd
                        BKE_sequencer_update_muting(sce->ed);
                        BKE_sequencer_update_sound_bounds_all(sce);
                        
+                       
+                       /* rigidbody world relies on it's linked groups */
+                       if (sce->rigidbody_world) {
+                               RigidBodyWorld *rbw = sce->rigidbody_world;
+                               if (rbw->group)
+                                       rbw->group = newlibadr(fd, sce->id.lib, rbw->group);
+                               if (rbw->constraints)
+                                       rbw->constraints = newlibadr(fd, sce->id.lib, rbw->constraints);
+                               if (rbw->effector_weights)
+                                       rbw->effector_weights->group = newlibadr(fd, sce->id.lib, rbw->effector_weights->group);
+                       }
+                       
                        if (sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
                                composite_patch(sce->nodetree, sce);
                        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);
 +#ifdef WITH_FREESTYLE
 +                              {
 +                                      FreestyleLineSet *fls;
 +
 +                                      for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
 +                                              fls->linestyle = newlibadr_us(fd, sce->id.lib, fls->linestyle);
 +                                              fls->group = newlibadr_us(fd, sce->id.lib, fls->group);
 +                                      }
 +                              }
 +#endif
                        }
                        /*Game Settings: Dome Warp Text*/
                        sce->gm.dome.warptext = newlibadr(fd, sce->id.lib, sce->gm.dome.warptext);
@@@ -5104,6 -5111,7 +5124,7 @@@ static void direct_link_scene(FileData 
        Editing *ed;
        Sequence *seq;
        MetaStack *ms;
+       RigidBodyWorld *rbw;
        
        sce->theDag = NULL;
        sce->dagisvalid = 0;
                if (sce->toolsettings->vpaint) {
                        sce->toolsettings->vpaint->vpaint_prev = NULL;
                        sce->toolsettings->vpaint->tot = 0;
 -              }
 +      }
                if (sce->toolsettings->wpaint) {
                        sce->toolsettings->wpaint->wpaint_prev = NULL;
                        sce->toolsettings->wpaint->tot = 0;
        link_list(fd, &(sce->markers));
        link_list(fd, &(sce->transform_spaces));
        link_list(fd, &(sce->r.layers));
 +
 +#ifdef WITH_FREESTYLE
 +      {
 +              SceneRenderLayer *srl;
 +
 +              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));
 +              }
 +      }
 +#endif
        
        sce->nodetree = newdataadr(fd, sce->nodetree);
        if (sce->nodetree) {
        }
  
        direct_link_view_settings(fd, &sce->view_settings);
+       
+       sce->rigidbody_world = newdataadr(fd, sce->rigidbody_world);
+       rbw = sce->rigidbody_world;
+       if (rbw) {
+               /* must nullify the reference to physics sim object, since it no-longer exist 
+                * (and will need to be recalculated) 
+                */
+               rbw->physics_world = NULL;
+               rbw->objects = NULL;
+               rbw->numbodies = 0;
+               /* set effector weights */
+               rbw->effector_weights = newdataadr(fd, rbw->effector_weights);
+               if (!rbw->effector_weights)
+                       rbw->effector_weights = BKE_add_effector_weights(NULL);
+               /* link cache */
+               direct_link_pointcache_list(fd, &rbw->ptcaches, &rbw->pointcache, FALSE);
+               /* make sure simulation starts from the beginning after loading file */
+               if (rbw->pointcache)
+                       rbw->ltime = rbw->pointcache->startframe;
+       }
  }
  
  /* ************ READ WM ***************** */
@@@ -5570,7 -5587,14 +5613,14 @@@ static void lib_link_screen(FileData *f
        }
  }
  
- /* Only for undo files, or to restore a screen after reading without UI... */
+ /**
+  * Only for undo files, or to restore a screen after reading without UI...
+  *
+  * user
+  * - 0: no usercount change
+  * - 1: ensure a user
+  * - 2: ensure a real user (even if a fake one is set)
+  */
  static void *restore_pointer_by_name(Main *mainp, ID *id, int user)
  {
        if (id) {
@@@ -5878,7 -5902,7 +5928,7 @@@ static void direct_link_region(FileDat
                pa->activedata = NULL;
                pa->type = NULL;
        }
 -
 +      
        link_list(fd, &ar->ui_lists);
  
        for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
@@@ -6029,6 -6053,7 +6079,7 @@@ static void direct_link_screen(FileDat
                                v3d->afterdraw_xray.first = v3d->afterdraw_xray.last = NULL;
                                v3d->afterdraw_xraytransp.first = v3d->afterdraw_xraytransp.last = NULL;
                                v3d->properties_storage = NULL;
+                               v3d->defmaterial = NULL;
                                
                                /* render can be quite heavy, set to wire on load */
                                if (v3d->drawtype == OB_RENDER)
                                sclip->scopes.track_preview = NULL;
                                sclip->draw_context = NULL;
                                sclip->scopes.ok = 0;
 -                      }
 +              }
                }
                
                sa->actionzones.first = sa->actionzones.last = NULL;
@@@ -6556,181 -6581,6 +6607,181 @@@ static void lib_link_mask(FileData *fd
        }
  }
  
 +#ifdef WITH_FREESTYLE
 +/* ************ READ LINE STYLE ***************** */
 +
 +static void lib_link_linestyle(FileData *fd, Main *main)
 +{
 +      FreestyleLineStyle *linestyle;
 +      LineStyleModifier *m;
 +
 +      linestyle = main->linestyle.first;
 +      while (linestyle) {
 +              if (linestyle->id.flag & LIB_NEED_LINK) {
 +                      linestyle->id.flag -= LIB_NEED_LINK;
 +
 +                      if (linestyle->id.properties)
 +                              IDP_LibLinkProperty(linestyle->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 +                      if (linestyle->adt)
 +                              lib_link_animdata(fd, &linestyle->id, linestyle->adt);
 +                      for (m = linestyle->color_modifiers.first; m; m = m->next) {
 +                              switch (m->type) {
 +                              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                                      {
 +                                              LineStyleColorModifier_DistanceFromObject *cm = (LineStyleColorModifier_DistanceFromObject *)m;
 +                                              cm->target = newlibadr(fd, linestyle->id.lib, cm->target);
 +                                      }
 +                                      break;
 +                              }
 +                      }
 +                      for (m = linestyle->alpha_modifiers.first; m; m = m->next){
 +                              switch (m->type) {
 +                              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                                      {
 +                                              LineStyleAlphaModifier_DistanceFromObject *am = (LineStyleAlphaModifier_DistanceFromObject *)m;
 +                                              am->target = newlibadr(fd, linestyle->id.lib, am->target);
 +                                      }
 +                                      break;
 +                              }
 +                      }
 +                      for (m = linestyle->thickness_modifiers.first; m; m = m->next){
 +                              switch (m->type) {
 +                              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                                      {
 +                                              LineStyleThicknessModifier_DistanceFromObject *tm = (LineStyleThicknessModifier_DistanceFromObject *)m;
 +                                              tm->target = newlibadr(fd, linestyle->id.lib, tm->target);
 +                                      }
 +                                      break;
 +                              }
 +                      }
 +              }
 +              linestyle = linestyle->id.next;
 +      }
 +}
 +
 +static void direct_link_linestyle_color_modifier(FileData *fd, LineStyleModifier *modifier)
 +{
 +      switch (modifier->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              {
 +                      LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              {
 +                      LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              {
 +                      LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              {
 +                      LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      }
 +}
 +
 +static void direct_link_linestyle_alpha_modifier(FileData *fd, LineStyleModifier *modifier)
 +{
 +      switch (modifier->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              {
 +                      LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              {
 +                      LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              {
 +                      LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              {
 +                      LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      }
 +}
 +
 +static void direct_link_linestyle_thickness_modifier(FileData *fd, LineStyleModifier *modifier)
 +{
 +      switch (modifier->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              {
 +                      LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              {
 +                      LineStyleThicknessModifier_DistanceFromCamera *m = (LineStyleThicknessModifier_DistanceFromCamera *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              {
 +                      LineStyleThicknessModifier_DistanceFromObject *m = (LineStyleThicknessModifier_DistanceFromObject *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              {
 +                      LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      }
 +}
 +
 +static void direct_link_linestyle_geometry_modifier(FileData *UNUSED(fd), LineStyleModifier *UNUSED(modifier))
 +{
 +}
 +
 +static void direct_link_linestyle(FileData *fd, FreestyleLineStyle *linestyle)
 +{
 +      LineStyleModifier *modifier;
 +
 +      linestyle->adt= newdataadr(fd, linestyle->adt);
 +      direct_link_animdata(fd, linestyle->adt);
 +      link_list(fd, &linestyle->color_modifiers);
 +      for(modifier = linestyle->color_modifiers.first; modifier; modifier = modifier->next)
 +              direct_link_linestyle_color_modifier(fd, modifier);
 +      link_list(fd, &linestyle->alpha_modifiers);
 +      for(modifier = linestyle->alpha_modifiers.first; modifier; modifier = modifier->next)
 +              direct_link_linestyle_alpha_modifier(fd, modifier);
 +      link_list(fd, &linestyle->thickness_modifiers);
 +      for(modifier = linestyle->thickness_modifiers.first; modifier; modifier = modifier->next)
 +              direct_link_linestyle_thickness_modifier(fd, modifier);
 +      link_list(fd, &linestyle->geometry_modifiers);
 +      for(modifier = linestyle->geometry_modifiers.first; modifier; modifier = modifier->next)
 +              direct_link_linestyle_geometry_modifier(fd, modifier);
 +}
 +#endif
 +
  /* ************** GENERAL & MAIN ******************** */
  
  
@@@ -6765,9 -6615,6 +6816,9 @@@ static const char *dataname(short id_co
                case ID_PA: return "Data from PA";
                case ID_GD: return "Data from GD";
                case ID_MC: return "Data from MC";
 +#ifdef WITH_FREESTYLE
 +              case ID_LS: return "Data from LS";
 +#endif
        }
        return "Data from Lib Block";
        
@@@ -6944,11 -6791,6 +6995,11 @@@ static BHead *read_libblock(FileData *f
                case ID_MSK:
                        direct_link_mask(fd, (Mask *)id);
                        break;
 +#ifdef WITH_FREESTYLE
 +              case ID_LS:
 +                      direct_link_linestyle(fd, (FreestyleLineStyle *)id);
 +                      break;
 +#endif
        }
        
        oldnewmap_free_unused(fd->datamap);
@@@ -7081,7 -6923,7 +7132,7 @@@ static void do_versions_nodetree_conver
                        /* Convert degrees to radians. */
                        NodeDefocus *nqd = node->storage;
                        /* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
 -                      nqd->rotation = DEG2RADF(nqd->rotation * 255.0f);
 +                      nqd->rotation = DEG2RADF(nqd->rotation*255.0f);
                }
                else if (node->type == CMP_NODE_CHROMA_MATTE) {
                        /* Convert degrees to radians. */
                        /* Convert degrees to radians. */
                        NodeGlare *ndg = node->storage;
                        /* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
 -                      ndg->angle_ofs = DEG2RADF(ndg->angle_ofs * 255.0f);
 +                      ndg->angle_ofs = DEG2RADF(ndg->angle_ofs*255.0f);
                }
                /* XXX TexMapping struct is used by other nodes too (at least node_composite_mapValue),
                 *     but not the rot part...
@@@ -8803,13 -8645,13 +8854,13 @@@ static void do_versions(FileData *fd, L
                        SEQ_END
  
                        if (scene->r.bake_samples == 0)
 -                      scene->r.bake_samples = 256;
 +                              scene->r.bake_samples = 256;
                }
  
                for (image = main->image.first; image; image = image->id.next) {
                        if (image->flag & IMA_DO_PREMUL)
                                image->alpha_mode = IMA_ALPHA_STRAIGHT;
 -              }
 +      }
  
                for (tex = main->tex.first; tex; tex = tex->id.next) {
                        if (tex->type == TEX_IMAGE && (tex->imaflag & TEX_USEALPHA) == 0) {
                }
        }
  
+       if (!MAIN_VERSION_ATLEAST(main, 265, 9)) {
+               Brush *br;
+               for (br = main->brush.first; br; br = br->id.next) {
+                       if (br->ob_mode & OB_MODE_TEXTURE_PAINT) {
+                               br->mtex.brush_map_mode = MTEX_MAP_MODE_TILED;
+                       }
+               }
+       }
        // if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {
  
 +#ifdef WITH_FREESTYLE
 +      /* default values in Freestyle settings */
 +      {
 +              Scene *sce;
 +              SceneRenderLayer *srl;
 +              FreestyleLineStyle *linestyle;
 +
 +              for(sce = main->scene.first; sce; sce = sce->id.next) {
 +                      if (sce->r.line_thickness_mode == 0) {
 +                              sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE;
 +                              sce->r.unit_line_thickness = 1.0f;
 +                      }
 +                      for(srl = sce->r.layers.first; srl; srl = srl->next) {
 +                              if (srl->freestyleConfig.mode == 0)
 +                                      srl->freestyleConfig.mode = FREESTYLE_CONTROL_EDITOR_MODE;
 +                              if (srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE ||
 +                                  srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL) {
 +                                      srl->freestyleConfig.raycasting_algorithm = 0; /* deprecated */
 +                                      srl->freestyleConfig.flags |= FREESTYLE_CULLING;
 +                              }
 +                      }
 +              }
 +              for(linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
 +#if 1
 +                      /* disable the Misc panel for now */
 +                      if (linestyle->panel == LS_PANEL_MISC) {
 +                              linestyle->panel = LS_PANEL_STROKES;
 +                      }
 +#endif
 +                      if (linestyle->thickness_position == 0) {
 +                              linestyle->thickness_position = LS_THICKNESS_CENTER;
 +                              linestyle->thickness_ratio = 0.5f;
 +                      }
 +                      if (linestyle->chaining == 0)
 +                              linestyle->chaining = LS_CHAINING_PLAIN;
 +                      if (linestyle->rounds == 0)
 +                              linestyle->rounds = 3;
 +              }
 +      }
 +#endif
 +
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
  
@@@ -8927,8 -8737,8 +8987,8 @@@ static void lib_link_all(FileData *fd, 
        
        /* No load UI for undo memfiles */
        if (fd->memfile == NULL) {
 -              lib_link_windowmanager(fd, main);
 -              lib_link_screen(fd, main);
 +      lib_link_windowmanager(fd, main);
 +      lib_link_screen(fd, main);
        }
        lib_link_scene(fd, main);
        lib_link_object(fd, main);
        lib_link_particlesettings(fd, main);
        lib_link_movieclip(fd, main);
        lib_link_mask(fd, main);
 +#ifdef WITH_FREESTYLE
 +      lib_link_linestyle(fd, main);
 +#endif
  
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
        
@@@ -9017,7 -8824,7 +9077,7 @@@ static BHead *read_userdef(BlendFileDat
                for (kmi=keymap->items.first; kmi; kmi=kmi->next)
                        direct_link_keymapitem(fd, kmi);
        }
 -
 +      
        for (addon = user->addons.first; addon; addon = addon->next) {
                addon->prop = newdataadr(fd, addon->prop);
                if (addon->prop) {
@@@ -9237,7 -9044,7 +9297,7 @@@ static void expand_doit_library(void *f
                                        return;
                                }
                                else
 -                                      id = is_yet_read(fd, ptr, bhead);
 +                              id = is_yet_read(fd, ptr, bhead);
                                
                                if (id == NULL) {
                                        read_libblock(fd, ptr, bhead, LIB_READ+LIB_INDIRECT, NULL);
@@@ -9882,7 -9689,12 +9942,12 @@@ static void expand_object(FileData *fd
        
        if (ob->pd && ob->pd->tex)
                expand_doit(fd, mainvar, ob->pd->tex);
-       
+       if (ob->rigidbody_constraint) {
+               expand_doit(fd, mainvar, ob->rigidbody_constraint->ob1);
+               expand_doit(fd, mainvar, ob->rigidbody_constraint->ob2);
+       }
  }
  
  static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
        for (srl = sce->r.layers.first; srl; srl = srl->next) {
                expand_doit(fd, mainvar, srl->mat_override);
                expand_doit(fd, mainvar, srl->light_override);
 +
 +#ifdef WITH_FREESTYLE
 +              {
 +                      FreestyleLineSet *lineset;
 +
 +                      for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
 +                              if (lineset->group)
 +                                      expand_doit(fd, mainvar, lineset->group);
 +                              expand_doit(fd, mainvar, lineset->linestyle);
 +                      }
 +              }
 +#endif
        }
        
        if (sce->r.dometext)
                }
                SEQ_END
        }
+       
+       if (sce->rigidbody_world) {
+               expand_doit(fd, mainvar, sce->rigidbody_world->group);
+               expand_doit(fd, mainvar, sce->rigidbody_world->constraints);
+       }
  
  #ifdef DURIAN_CAMERA_SWITCH
        {
@@@ -10014,28 -9819,6 +10084,28 @@@ static void expand_mask(FileData *fd, M
        }
  }
  
 +#ifdef WITH_FREESTYLE
 +static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *linestyle)
 +{
 +      LineStyleModifier *m;
 +
 +      if (linestyle->adt)
 +              expand_animdata(fd, mainvar, linestyle->adt);
 +      for (m = linestyle->color_modifiers.first; m; m = m->next) {
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
 +                      expand_doit(fd, mainvar, ((LineStyleColorModifier_DistanceFromObject *)m)->target);
 +      }
 +      for (m = linestyle->alpha_modifiers.first; m; m = m->next){
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
 +                      expand_doit(fd, mainvar, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target);
 +      }
 +      for (m = linestyle->thickness_modifiers.first; m; m = m->next){
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
 +                      expand_doit(fd, mainvar, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target);
 +      }
 +}
 +#endif
 +
  void BLO_main_expander(void (*expand_doit_func)(void *, Main *, void *))
  {
        expand_doit = expand_doit_func;
@@@ -10053,7 -9836,7 +10123,7 @@@ void BLO_expand_main(void *fdhandle, Ma
                
                a = set_listbasepointers(mainvar, lbarray);
                while (a--) {
-                       id= lbarray[a]->first;
+                       id = lbarray[a]->first;
                        while (id) {
                                if (id->flag & LIB_NEED_EXPAND) {
                                        switch (GS(id->name)) {
                                        case ID_MSK:
                                                expand_mask(fd, mainvar, (Mask *)id);
                                                break;
 +#ifdef WITH_FREESTYLE
 +                                      case ID_LS:
 +                                              expand_linestyle(fd, mainvar, (FreestyleLineStyle *)id);
 +                                              break;
 +#endif
                                        }
                                        
                                        do_it = TRUE;
@@@ -10201,7 -9979,7 +10271,7 @@@ static void give_base_to_objects(Main *
                                
                                if (do_it) {
                                        base = MEM_callocN(sizeof(Base), "add_ext_base");
-                                       BLI_addtail(&(sce->base), base);
+                                       BLI_addtail(&sce->base, base);
                                        base->lay = ob->lay;
                                        base->object = ob;
                                        base->flag = ob->flag;
@@@ -10551,9 -10329,9 +10621,9 @@@ static void read_libraries(FileData *ba
                                                BLI_strncpy(fd->relabase, mainptr->curlib->filepath, sizeof(fd->relabase));
                                        }
                                        else {
 -                                              BKE_reportf_wrap(basefd->reports, RPT_INFO, TIP_("Read library:  '%s', '%s'"),
 -                                                                               mainptr->curlib->filepath, mainptr->curlib->name);
 -                                              fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
 +                                      BKE_reportf_wrap(basefd->reports, RPT_INFO, TIP_("Read library:  '%s', '%s'"),
 +                                                       mainptr->curlib->filepath, mainptr->curlib->name);
 +                                      fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
                                        }
                                        /* allow typing in a new lib path */
                                        if (G.debug_value == -666) {
index 63d8c9b0e0e86ac1fa55cc760a115d217c74bdb8,e7a5367084984cdbb0c655ab23ecfad2bd41aa2c..475d96fd7096408d637d370a8bd6d9c25fab3fc9
  #include "DNA_key_types.h"
  #include "DNA_lattice_types.h"
  #include "DNA_lamp_types.h"
 +#ifdef WITH_FREESTYLE
 +#  include "DNA_linestyle_types.h"
 +#endif
  #include "DNA_meta_types.h"
  #include "DNA_mesh_types.h"
  #include "DNA_meshdata_types.h"
  #include "DNA_packedFile_types.h"
  #include "DNA_particle_types.h"
  #include "DNA_property_types.h"
+ #include "DNA_rigidbody_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_sdna_types.h"
  #include "DNA_sequence_types.h"
@@@ -1490,6 -1488,14 +1491,14 @@@ static void write_objects(WriteData *wd
                        }
                        writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft);
                        
+                       if (ob->rigidbody_object) {
+                               // TODO: if any extra data is added to handle duplis, will need separate function then
+                               writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object);
+                       }
+                       if (ob->rigidbody_constraint) {
+                               writestruct(wd, DATA, "RigidBodyCon", 1, ob->rigidbody_constraint);
+                       }
                        write_particlesystems(wd, &ob->particlesystem);
                        write_modifiers(wd, &ob->modifiers);
                }
@@@ -1515,7 -1521,7 +1524,7 @@@ static void write_vfonts(WriteData *wd
  
                        /* direct data */
  
-                       if (vf->packedfile && !wd->current) {
+                       if (vf->packedfile) {
                                pf = vf->packedfile;
                                writestruct(wd, DATA, "PackedFile", 1, pf);
                                writedata(wd, DATA, pf->size, pf->data);
@@@ -1965,7 -1971,7 +1974,7 @@@ static void write_images(WriteData *wd
                        writestruct(wd, ID_IM, "Image", 1, ima);
                        if (ima->id.properties) IDP_WriteProperty(ima->id.properties, wd);
  
-                       if (ima->packedfile && !wd->current) {
+                       if (ima->packedfile) {
                                pf = ima->packedfile;
                                writestruct(wd, DATA, "PackedFile", 1, pf);
                                writedata(wd, DATA, pf->size, pf->data);
@@@ -2290,25 -2296,8 +2299,25 @@@ static void write_scenes(WriteData *wd
                for (ts = sce->transform_spaces.first; ts; ts = ts->next)
                        writestruct(wd, DATA, "TransformOrientation", 1, ts);
                
 -              for (srl= sce->r.layers.first; srl; srl= srl->next)
 +              for (srl = sce->r.layers.first; srl; srl = srl->next) {
                        writestruct(wd, DATA, "SceneRenderLayer", 1, srl);
 +                      
 +#ifdef WITH_FREESTYLE
 +                      {
 +                              FreestyleModuleConfig *fmc;
 +                              FreestyleLineSet *fls;
 +
 +                              for(fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
 +                                      writestruct(wd, DATA, "FreestyleModuleConfig", 1, fmc);
 +                              }
 +                      
 +                              for(fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
 +                                      writestruct(wd, DATA, "FreestyleLineSet", 1, fls);
 +                              }
 +
 +                      }
 +#endif
 +              }
                
                if (sce->nodetree) {
                        writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree);
                }
  
                write_view_settings(wd, &sce->view_settings);
+               
+               /* writing RigidBodyWorld data to the blend file */
+               if (sce->rigidbody_world) {
+                       writestruct(wd, DATA, "RigidBodyWorld", 1, sce->rigidbody_world);
+                       writestruct(wd, DATA, "EffectorWeights", 1, sce->rigidbody_world->effector_weights);
+                       write_pointcaches(wd, &(sce->rigidbody_world->ptcaches));
+               }
+               
                sce= sce->id.next;
        }
        /* flush helps the compression for undo-save */
@@@ -2574,14 -2570,18 +2590,18 @@@ static void write_libraries(WriteData *
                        }
                }
                
+               /* to be able to restore quit.blend and temp saves, the packed blend has to be in undo buffers... */
+               /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the]
+                  quit.blend and temp saves */
                if (foundone) {
                        writestruct(wd, ID_LI, "Library", 1, main->curlib);
  
-                       if (main->curlib->packedfile && !wd->current) {
+                       if (main->curlib->packedfile) {
                                PackedFile *pf = main->curlib->packedfile;
                                writestruct(wd, DATA, "PackedFile", 1, pf);
                                writedata(wd, DATA, pf->size, pf->data);
-                               printf("write packed .blend: %s\n", main->curlib->name);
+                               if (wd->current == NULL)
+                                       printf("write packed .blend: %s\n", main->curlib->name);
                        }
                        
                        while (a--) {
@@@ -2712,7 -2712,7 +2732,7 @@@ static void write_sounds(WriteData *wd
                        writestruct(wd, ID_SO, "bSound", 1, sound);
                        if (sound->id.properties) IDP_WriteProperty(sound->id.properties, wd);
  
-                       if (sound->packedfile && !wd->current) {
+                       if (sound->packedfile) {
                                pf = sound->packedfile;
                                writestruct(wd, DATA, "PackedFile", 1, pf);
                                writedata(wd, DATA, pf->size, pf->data);
@@@ -2902,209 -2902,6 +2922,209 @@@ static void write_masks(WriteData *wd, 
        mywrite(wd, MYWRITE_FLUSH, 0);
  }
  
 +#ifdef WITH_FREESTYLE
 +static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      const char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      struct_name = "LineStyleColorModifier_AlongStroke";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      struct_name = "LineStyleColorModifier_DistanceFromCamera";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      struct_name = "LineStyleColorModifier_DistanceFromObject";
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      struct_name = "LineStyleColorModifier_Material";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleColorModifier"; /* this should not happen */
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp);
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Material *)m)->color_ramp);
 +                      break;
 +              }
 +      }
 +}
 +
 +static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      const char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      struct_name = "LineStyleAlphaModifier_AlongStroke";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      struct_name = "LineStyleAlphaModifier_DistanceFromCamera";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      struct_name = "LineStyleAlphaModifier_DistanceFromObject";
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      struct_name = "LineStyleAlphaModifier_Material";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleAlphaModifier"; /* this should not happen */
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_AlongStroke *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_Material *)m)->curve);
 +                      break;
 +              }
 +      }
 +}
 +
 +static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      const char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      struct_name = "LineStyleThicknessModifier_AlongStroke";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      struct_name = "LineStyleThicknessModifier_DistanceFromCamera";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      struct_name = "LineStyleThicknessModifier_DistanceFromObject";
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      struct_name = "LineStyleThicknessModifier_Material";
 +                      break;
 +              case LS_MODIFIER_CALLIGRAPHY:
 +                      struct_name = "LineStyleThicknessModifier_Calligraphy";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleThicknessModifier"; /* this should not happen */
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_AlongStroke *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_Material *)m)->curve);
 +                      break;
 +              }
 +      }
 +}
 +
 +static void write_linestyle_geometry_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      const char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_SAMPLING:
 +                      struct_name = "LineStyleGeometryModifier_Sampling";
 +                      break;
 +              case LS_MODIFIER_BEZIER_CURVE:
 +                      struct_name = "LineStyleGeometryModifier_BezierCurve";
 +                      break;
 +              case LS_MODIFIER_SINUS_DISPLACEMENT:
 +                      struct_name = "LineStyleGeometryModifier_SinusDisplacement";
 +                      break;
 +              case LS_MODIFIER_SPATIAL_NOISE:
 +                      struct_name = "LineStyleGeometryModifier_SpatialNoise";
 +                      break;
 +              case LS_MODIFIER_PERLIN_NOISE_1D:
 +                      struct_name = "LineStyleGeometryModifier_PerlinNoise1D";
 +                      break;
 +              case LS_MODIFIER_PERLIN_NOISE_2D:
 +                      struct_name = "LineStyleGeometryModifier_PerlinNoise2D";
 +                      break;
 +              case LS_MODIFIER_BACKBONE_STRETCHER:
 +                      struct_name = "LineStyleGeometryModifier_BackboneStretcher";
 +                      break;
 +              case LS_MODIFIER_TIP_REMOVER:
 +                      struct_name = "LineStyleGeometryModifier_TipRemover";
 +                      break;
 +              case LS_MODIFIER_POLYGONIZATION:
 +                      struct_name = "LineStyleGeometryModifier_Polygonalization";
 +                      break;
 +              case LS_MODIFIER_GUIDING_LINES:
 +                      struct_name = "LineStyleGeometryModifier_GuidingLines";
 +                      break;
 +              case LS_MODIFIER_BLUEPRINT:
 +                      struct_name = "LineStyleGeometryModifier_Blueprint";
 +                      break;
 +              case LS_MODIFIER_2D_OFFSET:
 +                      struct_name = "LineStyleGeometryModifier_2DOffset";
 +                      break;
 +              case LS_MODIFIER_2D_TRANSFORM:
 +                      struct_name = "LineStyleGeometryModifier_2DTransform";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleGeometryModifier"; /* this should not happen */
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +}
 +
 +static void write_linestyles(WriteData *wd, ListBase *idbase)
 +{
 +      FreestyleLineStyle *linestyle;
 +
 +      for (linestyle = idbase->first; linestyle; linestyle = linestyle->id.next) {
 +              if (linestyle->id.us>0 || wd->current) {
 +                      writestruct(wd, ID_LS, "FreestyleLineStyle", 1, linestyle);
 +                      if (linestyle->id.properties)
 +                              IDP_WriteProperty(linestyle->id.properties, wd);
 +                      if (linestyle->adt)
 +                              write_animdata(wd, linestyle->adt);
 +                      write_linestyle_color_modifiers(wd, &linestyle->color_modifiers);
 +                      write_linestyle_alpha_modifiers(wd, &linestyle->alpha_modifiers);
 +                      write_linestyle_thickness_modifiers(wd, &linestyle->thickness_modifiers);
 +                      write_linestyle_geometry_modifiers(wd, &linestyle->geometry_modifiers);
 +              }
 +      }
 +}
 +#endif
 +
  /* context is usually defined by WM, two cases where no WM is available:
   * - for forward compatibility, curscreen has to be saved
   * - for undofile, curscene needs to be saved */
@@@ -3211,9 -3008,6 +3231,9 @@@ static int write_file_handle(Main *main
        write_brushes  (wd, &mainvar->brush);
        write_scripts  (wd, &mainvar->script);
        write_gpencils (wd, &mainvar->gpencil);
 +#ifdef WITH_FREESTYLE
 +      write_linestyles(wd, &mainvar->linestyle);
 +#endif
        write_libraries(wd,  mainvar->next);
  
        if (write_user_block) {
index 0606222bb1759210ad2d948a812659afb13d0b37,42a1a5e0f3e701ae74c68682b46baaef27857321..d49686f204a09b930577f6cc7d7733e20833c2a5
@@@ -41,7 -41,6 +41,6 @@@ set(INC_SY
  set(SRC
        operators/bmo_bevel.c
        operators/bmo_connect.c
-       operators/bmo_slide.c
        operators/bmo_create.c
        operators/bmo_dissolve.c
        operators/bmo_dupe.c
@@@ -135,8 -134,4 +134,8 @@@ if(WITH_INTERNATIONAL
        add_definitions(-DWITH_INTERNATIONAL)
  endif()
  
 +if(WITH_FREESTYLE)
 +      add_definitions(-DWITH_FREESTYLE)
 +endif()
 +
  blender_add_lib(bf_bmesh "${SRC}" "${INC}" "${INC_SYS}")
index e838b130cef410e05918e15bf42835d71aaf0bc0,4fa3a69356f52af5b0c8b4faa200006b3e586b92..4461a7afdd7b3ef452fc6faa97e841348b9d8644
@@@ -246,9 -246,6 +246,9 @@@ enum 
  
        /* spare tag, assumed dirty, use define in each function to name based on use */
        // _BM_ELEM_TAG_ALT = (1 << 6),  // UNUSED
 +#ifdef WITH_FREESTYLE
 +      BM_ELEM_FREESTYLE = (1 << 6), /* used for Freestyle faces and edges */
 +#endif
  
        BM_ELEM_INTERNAL_TAG = (1 << 7) /* for low level internal API tagging,
                                       * since tools may want to tag verts and
  };
  
  /* defines */
  #define BM_ELEM_CD_GET_VOID_P(ele, offset) \
-       ((void)0, (void *)((char *)(ele)->head.data + (offset)))
+       (assert(offset != -1), (void *)((char *)(ele)->head.data + (offset)))
  
  #define BM_ELEM_CD_SET_FLOAT(ele, offset, f) \
-       { *((float *)((char *)(ele)->head.data + (offset))) = (f); } (void)0
+       { assert(offset != -1); *((float *)((char *)(ele)->head.data + (offset))) = (f); } (void)0
  
  #define BM_ELEM_CD_GET_FLOAT(ele, offset) \
-       ((void)0, *((float *)((char *)(ele)->head.data + (offset))))
+       (assert(offset != -1), *((float *)((char *)(ele)->head.data + (offset))))
  
  #define BM_ELEM_CD_GET_FLOAT_AS_UCHAR(ele, offset) \
-       (unsigned char)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f)
+       (assert(offset != -1), (unsigned char)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f))
  
  /*forward declarations*/
  
index 5eeee45e7a9d0cb4e474634525ca04bb9d11c630,fddb7b4bf2c333cd3cfea4015927272c5bcda837..fa58ccd98bce57f53151c1ddea1780343269f4a0
@@@ -53,7 -53,7 +53,7 @@@ static void bm_loop_attrs_copy(BMesh *s
   * \brief Make Quad/Triangle
   *
   * Creates a new quad or triangle from a list of 3 or 4 vertices.
-  * If \a nodouble is TRUE, then a check is done to see if a face
+  * If \a no_double is true, then a check is done to see if a face
   * with these vertices already exists and returns it instead.
   *
   * If a pointer to an example face is provided, it's custom data
  
  BMFace *BM_face_create_quad_tri(BMesh *bm,
                                  BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4,
-                                 const BMFace *example, const int nodouble)
+                                 const BMFace *example, const bool no_double)
  {
        BMVert *vtar[4] = {v1, v2, v3, v4};
-       return BM_face_create_quad_tri_v(bm, vtar, v4 ? 4 : 3, example, nodouble);
+       return BM_face_create_quad_tri_v(bm, vtar, v4 ? 4 : 3, example, no_double);
  }
  
- BMFace *BM_face_create_quad_tri_v(BMesh *bm, BMVert **verts, int len, const BMFace *example, const int nodouble)
+ BMFace *BM_face_create_quad_tri_v(BMesh *bm, BMVert **verts, int len, const BMFace *example, const bool no_double)
  {
        BMFace *f = NULL;
-       int is_overlap = FALSE;
+       bool is_overlap = false;
  
        /* sanity check - debug mode only */
        if (len == 3) {
@@@ -97,7 -97,7 +97,7 @@@
        }
  
  
-       if (nodouble) {
+       if (no_double) {
                /* check if face exists or overlaps */
                is_overlap = BM_face_exists(verts, len, &f);
        }
@@@ -793,7 -793,7 +793,7 @@@ void BM_elem_attrs_copy(BMesh *source_m
  
        /* First we copy select */
        if (BM_elem_flag_test((BMElem *)sheader, BM_ELEM_SELECT)) {
-               BM_elem_select_set(target_mesh, (BMElem *)target, TRUE);
+               BM_elem_select_set(target_mesh, (BMElem *)target, true);
        }
        
        /* Now we copy flags */
@@@ -1002,28 -1002,18 +1002,28 @@@ char BM_vert_flag_from_mflag(const cha
  }
  char BM_edge_flag_from_mflag(const short meflag)
  {
 -      return ( ((meflag & SELECT)        ? BM_ELEM_SELECT : 0) |
 -               ((meflag & ME_SEAM)       ? BM_ELEM_SEAM   : 0) |
 -               ((meflag & ME_EDGEDRAW)   ? BM_ELEM_DRAW   : 0) |
 -               ((meflag & ME_SHARP) == 0 ? BM_ELEM_SMOOTH : 0) | /* invert */
 -               ((meflag & ME_HIDE)       ? BM_ELEM_HIDDEN : 0)
 +      return ( ((meflag & SELECT)            ? BM_ELEM_SELECT    : 0) |
 +               ((meflag & ME_SEAM)           ? BM_ELEM_SEAM      : 0) |
 +               ((meflag & ME_EDGEDRAW)       ? BM_ELEM_DRAW      : 0) |
 +               ((meflag & ME_SHARP) == 0     ? BM_ELEM_SMOOTH    : 0) | /* invert */
 +               ((meflag & ME_HIDE)           ? BM_ELEM_HIDDEN    : 0) |
 +#ifdef WITH_FREESTYLE
 +               ((meflag & ME_FREESTYLE_EDGE) ? BM_ELEM_FREESTYLE : 0)
 +#else
 +               0
 +#endif
                 );
  }
  char BM_face_flag_from_mflag(const char  meflag)
  {
 -      return ( ((meflag & ME_FACE_SEL)  ? BM_ELEM_SELECT : 0) |
 -               ((meflag & ME_SMOOTH)    ? BM_ELEM_SMOOTH : 0) |
 -               ((meflag & ME_HIDE)      ? BM_ELEM_HIDDEN : 0)
 +      return ( ((meflag & ME_FACE_SEL)       ? BM_ELEM_SELECT    : 0) |
 +               ((meflag & ME_SMOOTH)         ? BM_ELEM_SMOOTH    : 0) |
 +               ((meflag & ME_HIDE)           ? BM_ELEM_HIDDEN    : 0) |
 +#ifdef WITH_FREESTYLE
 +               ((meflag & ME_FREESTYLE_FACE) ? BM_ELEM_FREESTYLE : 0)
 +#else
 +               0
 +#endif
                 );
  }
  
@@@ -1041,15 -1031,12 +1041,15 @@@ short BM_edge_flag_to_mflag(BMEdge *eed
  {
        const char hflag = eed->head.hflag;
  
 -      return ( ((hflag & BM_ELEM_SELECT)       ? SELECT       : 0) |
 -               ((hflag & BM_ELEM_SEAM)         ? ME_SEAM      : 0) |
 -               ((hflag & BM_ELEM_DRAW)         ? ME_EDGEDRAW  : 0) |
 -               ((hflag & BM_ELEM_SMOOTH) == 0  ? ME_SHARP     : 0) |
 -               ((hflag & BM_ELEM_HIDDEN)       ? ME_HIDE      : 0) |
 -               ((BM_edge_is_wire(eed))         ? ME_LOOSEEDGE : 0) | /* not typical */
 +      return ( ((hflag & BM_ELEM_SELECT)       ? SELECT            : 0) |
 +               ((hflag & BM_ELEM_SEAM)         ? ME_SEAM           : 0) |
 +               ((hflag & BM_ELEM_DRAW)         ? ME_EDGEDRAW       : 0) |
 +               ((hflag & BM_ELEM_SMOOTH) == 0  ? ME_SHARP          : 0) |
 +               ((hflag & BM_ELEM_HIDDEN)       ? ME_HIDE           : 0) |
 +#ifdef WITH_FREESTYLE
 +               ((hflag & BM_ELEM_FREESTYLE)    ? ME_FREESTYLE_EDGE : 0) |
 +#endif
 +               ((BM_edge_is_wire(eed))         ? ME_LOOSEEDGE      : 0) | /* not typical */
                 ME_EDGERENDER
                 );
  }
@@@ -1057,13 -1044,8 +1057,13 @@@ char  BM_face_flag_to_mflag(BMFace *efa
  {
        const char hflag = efa->head.hflag;
  
 -      return ( ((hflag & BM_ELEM_SELECT) ? ME_FACE_SEL : 0) |
 -               ((hflag & BM_ELEM_SMOOTH) ? ME_SMOOTH   : 0) |
 -               ((hflag & BM_ELEM_HIDDEN) ? ME_HIDE     : 0)
 +      return ( ((hflag & BM_ELEM_SELECT)    ? ME_FACE_SEL       : 0) |
 +               ((hflag & BM_ELEM_SMOOTH)    ? ME_SMOOTH         : 0) |
 +               ((hflag & BM_ELEM_HIDDEN)    ? ME_HIDE           : 0) |
 +#ifdef WITH_FREESTYLE
 +               ((hflag & BM_ELEM_FREESTYLE) ? ME_FREESTYLE_FACE : 0)
 +#else
 +               0
 +#endif
                 );
  }
index a8cc152bd4efe9e205b34f981523e552f4feda49,baabcffd1627c354f2f05363063ae3408d859e37..454f9ab2ad3249bfca645a353474b3220c7f6aae
@@@ -185,21 -185,21 +185,21 @@@ void bmo_similar_faces_exec(BMesh *bm, 
        for (i = 0; i < num_total; i++) {
                fm = f_ext[i].f;
                if (!BMO_elem_flag_test(bm, fm, FACE_MARK) && !BM_elem_flag_test(fm, BM_ELEM_HIDDEN)) {
-                       int cont = TRUE;
-                       for (idx = 0; idx < num_sels && cont == TRUE; idx++) {
+                       bool cont = true;
+                       for (idx = 0; idx < num_sels && cont == true; idx++) {
                                fs = f_ext[indices[idx]].f;
                                switch (type) {
                                        case SIMFACE_MATERIAL:
                                                if (fm->mat_nr == fs->mat_nr) {
                                                        BMO_elem_flag_enable(bm, fm, FACE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                        case SIMFACE_IMAGE:
                                                if (f_ext[i].t == f_ext[indices[idx]].t) {
                                                        BMO_elem_flag_enable(bm, fm, FACE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                                angle = angle_normalized_v3v3(fs->no, fm->no);  /* if the angle between the normals -> 0 */
                                                if (angle <= thresh_radians) {
                                                        BMO_elem_flag_enable(bm, fm, FACE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                                        delta_fl = f_ext[i].d - f_ext[indices[idx]].d;
                                                        if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
                                                                BMO_elem_flag_enable(bm, fm, FACE_MARK);
-                                                               cont = FALSE;
+                                                               cont = false;
                                                        }
                                                }
                                                break;
                                                delta_fl = f_ext[i].area - f_ext[indices[idx]].area;
                                                if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
                                                        BMO_elem_flag_enable(bm, fm, FACE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                                delta_i = fm->len - fs->len;
                                                if (bm_sel_similar_cmp_i(delta_i, compare)) {
                                                        BMO_elem_flag_enable(bm, fm, FACE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                                delta_fl = f_ext[i].perim - f_ext[indices[idx]].perim;
                                                if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
                                                        BMO_elem_flag_enable(bm, fm, FACE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
 +#ifdef WITH_FREESTYLE
 +                                      case SIMFACE_FREESTYLE:
 +                                              if (BM_elem_flag_test(fm, BM_ELEM_FREESTYLE) == BM_elem_flag_test(fs, BM_ELEM_FREESTYLE)) {
 +                                                      BMO_elem_flag_enable(bm, fm, FACE_MARK);
 +                                                      cont = FALSE;
 +                                              }
 +                                              break;
 +#endif
                                        default:
                                                BLI_assert(0);
                                }
@@@ -381,15 -373,15 +381,15 @@@ void bmo_similar_edges_exec(BMesh *bm, 
        for (i = 0; i < num_total; i++) {
                e = e_ext[i].e;
                if (!BMO_elem_flag_test(bm, e, EDGE_MARK) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) {
-                       int cont = TRUE;
-                       for (idx = 0; idx < num_sels && cont == TRUE; idx++) {
+                       bool cont = true;
+                       for (idx = 0; idx < num_sels && cont == true; idx++) {
                                es = e_ext[indices[idx]].e;
                                switch (type) {
                                        case SIMEDGE_LENGTH:
                                                delta_fl = e_ext[i].length - e_ext[indices[idx]].length;
                                                if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
                                                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
  
                                                if (angle / (float)(M_PI / 2.0) <= thresh) {
                                                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                                delta_i = e_ext[i].faces - e_ext[indices[idx]].faces;
                                                if (bm_sel_similar_cmp_i(delta_i, compare)) {
                                                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                                        if (e_ext[indices[idx]].faces == 2) {
                                                                if (fabsf(e_ext[i].angle - e_ext[indices[idx]].angle) <= thresh) {
                                                                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                                       cont = FALSE;
+                                                                       cont = false;
                                                                }
                                                        }
                                                }
                                                else {
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
  
                                                        if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
                                                                BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                               cont = FALSE;
+                                                               cont = false;
                                                        }
                                                }
                                                break;
  
                                                        if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
                                                                BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                               cont = FALSE;
+                                                               cont = false;
                                                        }
                                                }
                                                break;
                                        case SIMEDGE_SEAM:
                                                if (BM_elem_flag_test(e, BM_ELEM_SEAM) == BM_elem_flag_test(es, BM_ELEM_SEAM)) {
                                                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                        case SIMEDGE_SHARP:
                                                if (BM_elem_flag_test(e, BM_ELEM_SMOOTH) == BM_elem_flag_test(es, BM_ELEM_SMOOTH)) {
                                                        BMO_elem_flag_enable(bm, e, EDGE_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
 +#ifdef WITH_FREESTYLE
 +                                      case SIMEDGE_FREESTYLE:
 +                                              if (BM_elem_flag_test(e, BM_ELEM_FREESTYLE) == BM_elem_flag_test(es, BM_ELEM_FREESTYLE)) {
 +                                                      BMO_elem_flag_enable(bm, e, EDGE_MARK);
 +                                                      cont = FALSE;
 +                                              }
 +                                              break;
 +#endif
                                        default:
                                                BLI_assert(0);
                                }
@@@ -578,15 -562,15 +578,15 @@@ void bmo_similar_verts_exec(BMesh *bm, 
        for (i = 0; i < num_total; i++) {
                v = v_ext[i].v;
                if (!BMO_elem_flag_test(bm, v, VERT_MARK) && !BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
-                       int cont = TRUE;
-                       for (idx = 0; idx < num_sels && cont == TRUE; idx++) {
+                       bool cont = true;
+                       for (idx = 0; idx < num_sels && cont == true; idx++) {
                                vs = v_ext[indices[idx]].v;
                                switch (type) {
                                        case SIMVERT_NORMAL:
                                                /* compare the angle between the normals */
                                                if (angle_normalized_v3v3(v->no, vs->no) <= thresh_radians) {
                                                        BMO_elem_flag_enable(bm, v, VERT_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
                                        case SIMVERT_FACE:
                                                delta_i = v_ext[i].num_faces - v_ext[indices[idx]].num_faces;
                                                if (bm_sel_similar_cmp_i(delta_i, compare)) {
                                                        BMO_elem_flag_enable(bm, v, VERT_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
  
                                                if (v_ext[i].dvert != NULL && v_ext[indices[idx]].dvert != NULL) {
                                                        if (defvert_find_shared(v_ext[i].dvert, v_ext[indices[idx]].dvert) != -1) {
                                                                BMO_elem_flag_enable(bm, v, VERT_MARK);
-                                                               cont = FALSE;
+                                                               cont = false;
                                                        }
                                                }
                                                break;
                                                delta_i = v_ext[i].num_edges - v_ext[indices[idx]].num_edges;
                                                if (bm_sel_similar_cmp_i(delta_i, compare)) {
                                                        BMO_elem_flag_enable(bm, v, VERT_MARK);
-                                                       cont = FALSE;
+                                                       cont = false;
                                                }
                                                break;
                                        default:
index 29b1a74e859483249aae5bb210850da6bf693eb4,f8eae840471a09158c8f23ef605550a91b6112df..df07e05ec067e5d4994a4ad4370ac7acc0b80cc7
@@@ -147,6 -147,8 +147,8 @@@ enum 
        TH_NODE_CONVERTOR,
        TH_NODE_GROUP,
        TH_NODE_FRAME,
+       TH_NODE_MATTE,
+       TH_NODE_DISTORT,
        
        TH_CONSOLE_OUTPUT,
        TH_CONSOLE_INPUT,
        TH_STITCH_PREVIEW_UNSTITCHABLE,
        TH_STITCH_PREVIEW_ACTIVE,
  
 +/* #ifdef WITH_FREESTYLE */
 +      TH_FREESTYLE_EDGE_MARK,
 +      TH_FREESTYLE_FACE_MARK,
 +/* #endif */
 +
        TH_MATCH,           /* highlight color for search matches */
        TH_SELECT_HIGHLIGHT, /* highlight color for selected outliner item */
  
index f704ac0e20355d9138f077a1f69031409c92a575,3385d334b71f4fc72caf4f4c476e5c8ec4df5217..ec2b4f5adf056b084e35283eefa4f993992b920f
  #include "DNA_dynamicpaint_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_object_types.h"
+ #include "DNA_object_force.h"
  
  #include "BLI_utildefines.h"
  #include "BLI_string.h"
  #include "BLI_ghash.h"
  #include "BLI_rect.h"
+ #include "BLI_math.h"
+ #include "BLI_listbase.h"
  
  #include "BLF_api.h"
  #include "BLF_translation.h"
  #include "BKE_animsys.h"
  #include "BKE_colortools.h"
  #include "BKE_context.h"
+ #include "BKE_depsgraph.h"
+ #include "BKE_displist.h"
  #include "BKE_dynamicpaint.h"
  #include "BKE_global.h"
  #include "BKE_library.h"
  #include "BKE_main.h"
- #include "BKE_object.h"
  #include "BKE_material.h"
- #include "BKE_texture.h"
+ #include "BKE_modifier.h"
+ #include "BKE_object.h"
+ #include "BKE_particle.h"
  #include "BKE_report.h"
- #include "BKE_displist.h"
  #include "BKE_sca.h"
  #include "BKE_scene.h"
  #include "BKE_screen.h"
+ #include "BKE_texture.h"
  
  #include "ED_screen.h"
  #include "ED_object.h"
  #include "ED_render.h"
+ #include "ED_util.h"
  
  #include "RNA_access.h"
  #include "RNA_enum_types.h"
@@@ -322,9 -329,6 +329,9 @@@ static const char *template_id_browse_t
                        case ID_MA:  return N_("Browse Material to be linked");
                        case ID_TE:  return N_("Browse Texture to be linked");
                        case ID_IM:  return N_("Browse Image to be linked");
 +#ifdef WITH_FREESTYLE
 +                      case ID_LS:  return N_("Browse Line Style Data to be linked");
 +#endif
                        case ID_LT:  return N_("Browse Lattice Data to be linked");
                        case ID_LA:  return N_("Browse Lamp Data to be linked");
                        case ID_CA:  return N_("Browse Camera Data to be linked");
@@@ -360,9 -364,6 +367,9 @@@ static const char *template_id_context(
                        case ID_MA:  return BLF_I18NCONTEXT_ID_MATERIAL;
                        case ID_TE:  return BLF_I18NCONTEXT_ID_TEXTURE;
                        case ID_IM:  return BLF_I18NCONTEXT_ID_IMAGE;
 +#ifdef WITH_FREESTYLE
 +                      case ID_LS:  return BLF_I18NCONTEXT_ID_FREESTYLELINESTYLE;
 +#endif
                        case ID_LT:  return BLF_I18NCONTEXT_ID_LATTICE;
                        case ID_LA:  return BLF_I18NCONTEXT_ID_LAMP;
                        case ID_CA:  return BLF_I18NCONTEXT_ID_CAMERA;
@@@ -518,11 -519,7 +525,11 @@@ static void template_ID(bContext *C, ui
                                                 BLF_I18NCONTEXT_ID_NODETREE,
                                                 BLF_I18NCONTEXT_ID_BRUSH,
                                                 BLF_I18NCONTEXT_ID_PARTICLESETTINGS,
 -                                               BLF_I18NCONTEXT_ID_GPENCIL);
 +                                               BLF_I18NCONTEXT_ID_GPENCIL,
 +#ifdef WITH_FREESTYLE
 +                                                                               BLF_I18NCONTEXT_ID_FREESTYLELINESTYLE
 +#endif
 +              );
                
                if (newop) {
                        but = uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN,
@@@ -726,21 -723,6 +733,6 @@@ void uiTemplatePathBuilder(uiLayout *la
  
  #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
  
- #include <string.h>
- #include "DNA_object_force.h"
- #include "BKE_depsgraph.h"
- #include "BKE_modifier.h"
- #include "BKE_particle.h"
- #include "ED_util.h"
- #include "BLI_math.h"
- #include "BLI_listbase.h"
- #include "ED_object.h"
  static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
  {
        Scene *scene = CTX_data_scene(C);
@@@ -1564,6 -1546,88 +1556,88 @@@ void uiTemplateColorRamp(uiLayout *layo
        MEM_freeN(cb);
  }
  
+ /********************* Icon viewer Template ************************/
+ /* ID Search browse menu, open */
+ static uiBlock *icon_view_menu(bContext *C, ARegion *ar, void *arg_litem)
+ {
+       static RNAUpdateCb cb;
+       uiBlock *block;
+       uiBut *but;
+       int icon;
+       EnumPropertyItem *item;
+       int a, free;
+       /* arg_litem is malloced, can be freed by parent button */
+       cb = *((RNAUpdateCb *)arg_litem);
+       
+       icon = RNA_property_enum_get(&cb.ptr, cb.prop);
+       
+       block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW);
+       
+       
+       RNA_property_enum_items(C, &cb.ptr, cb.prop, &item, NULL, &free);
+       
+       for (a = 0; item[a].identifier; a++) {
+               int x, y;
+               
+               x = (a % 8) * UI_UNIT_X * 6;
+               y = (a / 8) * UI_UNIT_X * 6;
+               
+               icon = item[a].icon;
+               but = uiDefIconButR_prop(block, ROW, 0, icon, x, y, UI_UNIT_X * 6, UI_UNIT_Y * 6, &cb.ptr, cb.prop, -1, 0, icon, -1, -1, NULL);
+               uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW);
+       }
+       uiBoundsBlock(block, 0.3f * U.widget_unit);
+       uiBlockSetDirection(block, UI_TOP);
+       uiEndBlock(C, block);
+               
+       if (free) {
+               MEM_freeN(item);
+       }
+       
+       return block;
+ }
+ void uiTemplateIconView(uiLayout *layout, PointerRNA *ptr, const char *propname)
+ {
+       PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
+       RNAUpdateCb *cb;
+       uiBlock *block;
+       uiBut *but;
+ //    rctf rect;  /* UNUSED */
+       int icon;
+       
+       if (!prop || RNA_property_type(prop) != PROP_ENUM)
+               return;
+       
+       icon = RNA_property_enum_get(ptr, prop);
+       
+       cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
+       cb->ptr = *ptr;
+       cb->prop = prop;
+       
+ //    rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
+ //    rect.ymin = 0; rect.ymax = 10.0f * UI_UNIT_X;
+       
+       block = uiLayoutAbsoluteBlock(layout);
+       but = uiDefBlockButN(block, icon_view_menu, MEM_dupallocN(cb), "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6, "");
+       
+ //    but = uiDefIconButR_prop(block, ROW, 0, icon, 0, 0, BLI_rctf_size_x(&rect), BLI_rctf_size_y(&rect), ptr, prop, -1, 0, icon, -1, -1, NULL);
+       
+       but->icon = icon;
+       uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW);
+       
+       uiButSetNFunc(but, rna_update_cb, MEM_dupallocN(cb), NULL);
+       
+       MEM_freeN(cb);
+ }
  /********************* Histogram Template ************************/
  
  void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, const char *propname)
@@@ -2030,16 -2094,22 +2104,22 @@@ static void curvemap_buttons_layout(uiL
        }
  
        if (cmp) {
-               const float range_clamp[2]   = {0.0f, 1.0f};
-               const float range_unclamp[2] = {-1000.0f, 1000.0f};  /* arbitrary limits here */
-               const float *range = (cumap->flag & CUMA_DO_CLIP) ? range_clamp : range_unclamp;
+               rctf bounds;
+               if (cumap->flag & CUMA_DO_CLIP) {
+                       bounds = cumap->clipr;
+               }
+               else {
+                       bounds.xmin = bounds.ymin = -1000.0;
+                       bounds.xmax = bounds.ymax =  1000.0;
+               }
  
                uiLayoutRow(layout, TRUE);
                uiBlockSetNFunc(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap);
                bt = uiDefButF(block, NUM, 0, "X", 0, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y,
-                              &cmp->x, range[0], range[1], 1, 5, "");
+                              &cmp->x, bounds.xmin, bounds.xmax, 1, 5, "");
                bt = uiDefButF(block, NUM, 0, "Y", 0, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y,
-                              &cmp->y, range[0], range[1], 1, 5, "");
+                              &cmp->y, bounds.ymin, bounds.ymax, 1, 5, "");
        }
  
        /* black/white levels */
@@@ -2360,7 -2430,7 +2440,7 @@@ static void uilist_draw_item_default(st
                uiItemL(layout, name, icon);
                break;
        }
 -
 +              
        /* free name */
        if (namebuf) {
                MEM_freeN(namebuf);
@@@ -2443,7 -2513,7 +2523,7 @@@ void uiTemplateList(uiLayout *layout, b
        if (ui_list_type == NULL) {
                RNA_warning("List type %s not found", listtype_name);
                return;
 -      }
 +                      }
  
        draw_item = ui_list_type->draw_item ? ui_list_type->draw_item : uilist_draw_item_default;
  
                ui_list = MEM_callocN(sizeof(uiList), __func__);
                BLI_strncpy(ui_list->list_id, ui_list_id, sizeof(ui_list->list_id));
                BLI_addtail(&ar->ui_lists, ui_list);
 -      }
 +                                      }
  
        /* Because we can't actually pass type across save&load... */
        ui_list->type = ui_list_type;
                                        if (icon == ICON_DOT)
                                                icon = ICON_NONE;
                                        draw_item(ui_list, C, row, dataptr, &itemptr, icon, active_dataptr, active_propname, i);
 -                              }
 +      }
  
                                i++;
 -                      }
 +}
                        RNA_PROP_END;
                }
  
index 471193d10d8bfae53ea0f897faea60e7d14fb269,e3fbbc26d0d8b16c675b6fc9aba6e2585a0c31b8..7efda2f56c341cb1fea3385e868d2c2fd5886487
@@@ -359,12 -359,6 +359,12 @@@ const unsigned char *UI_ThemeGetColorPt
                                        cp = ts->handle_sel_vect; break;
                                case TH_HANDLE_SEL_ALIGN:
                                        cp = ts->handle_sel_align; break;
 +#ifdef WITH_FREESTYLE
 +                              case TH_FREESTYLE_EDGE_MARK:
 +                                      cp = ts->freestyle_edge_mark; break;
 +                              case TH_FREESTYLE_FACE_MARK:
 +                                      cp = ts->freestyle_face_mark; break;
 +#endif
  
                                case TH_SYNTAX_B:
                                        cp = ts->syntaxb; break;
                                        cp = ts->syntaxc; break;
                                case TH_NODE_FRAME:
                                        cp = ts->movie; break;
+                               case TH_NODE_MATTE:
+                                       cp = ts->syntaxs; break;
+                               case TH_NODE_DISTORT:
+                                       cp = ts->syntaxd; break;
                                case TH_NODE_CURVING:
                                        cp = &ts->noodle_curving; break;
  
@@@ -753,10 -751,6 +757,10 @@@ void ui_theme_init_default(void
        rgba_char_args_set(btheme->tv3d.button_text_hi, 255, 255, 255, 255);
        rgba_char_args_set(btheme->tv3d.button_title, 0, 0, 0, 255);
        rgba_char_args_set(btheme->tv3d.title, 0, 0, 0, 255);
 +#ifdef WITH_FREESTYLE
 +      rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
 +      rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
 +#endif
  
        btheme->tv3d.facedot_size = 4;
  
@@@ -2014,21 -2008,6 +2018,21 @@@ void init_userdef_do_versions(void
                }
        }
  
 +#ifdef WITH_FREESTYLE
 +      /* Freestyle color settings */
 +      {
 +              bTheme *btheme;
 +
 +              for (btheme = U.themes.first; btheme; btheme = btheme->next) {
 +                      /* check for alpha == 0 is safe, then color was never set */
 +                      if (btheme->tv3d.freestyle_edge_mark[3] == 0) {
 +                              rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
 +                              rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
 +                      }
 +              }
 +      }
 +#endif
 +
        /* GL Texture Garbage Collection (variable abused above!) */
        if (U.textimeout == 0) {
                U.texcollectrate = 60;
                        btheme->tclip.panelcolors = btheme->tui.panel;
                }
        }
-       
        if (bmain->versionfile < 266) {
                bTheme *btheme;
                
                }
        }
  
+       if (!MAIN_VERSION_ATLEAST(bmain, 265, 9)) {
+               bTheme *btheme;
+               for (btheme = U.themes.first; btheme; btheme = btheme->next) {
+                       rgba_char_args_test_set(btheme->tnode.syntaxs, 151, 116, 116, 255);  /* matte nodes */
+                       rgba_char_args_test_set(btheme->tnode.syntaxd, 116, 151, 151, 255);  /* distort nodes */
+               }
+       }
        if (U.pixelsize == 0.0f)
                U.pixelsize = 1.0f;
        
index 3180886b2b687787f936a5efd85436714f4471fe,169e7a60fb1084d5cf74940f825723a466910d4e..b51d55aaf0e6e0c96cc5638b6077ef2d9499d82d
@@@ -48,7 -48,6 +48,6 @@@ set(SR
        editmesh_select.c
        editmesh_tools.c
        editmesh_utils.c
-       editmesh_slide.c
        mesh_data.c
        mesh_ops.c
        meshtools.c
@@@ -73,10 -72,6 +72,10 @@@ if(WITH_INTERNATIONAL
        add_definitions(-DWITH_INTERNATIONAL)
  endif()
  
 +if(WITH_FREESTYLE)
 +      add_definitions(-DWITH_FREESTYLE)
 +endif()
 +
  if(WITH_BULLET)
        add_definitions(-DWITH_BULLET)
  endif()
index 38887307a76000015c61ef68f2c496239490e3a8,e85649831f2051e3a7527c03f0dfc352246f9596..88d826c2f9838502a343d258785ebe7536aaa2c6
@@@ -681,9 -681,6 +681,9 @@@ static EnumPropertyItem prop_similar_ty
        {SIMEDGE_BEVEL, "BEVEL", 0, "Bevel", ""},
        {SIMEDGE_SEAM, "SEAM", 0, "Seam", ""},
        {SIMEDGE_SHARP, "SHARP", 0, "Sharpness", ""},
 +#ifdef WITH_FREESTYLE
 +      {SIMEDGE_FREESTYLE, "FREESTYLE_EDGE", 0, "Freestyle Edge Marks", ""},
 +#endif
  
        {SIMFACE_MATERIAL, "MATERIAL", 0, "Material", ""},
        {SIMFACE_IMAGE, "IMAGE", 0, "Image", ""},
        {SIMFACE_PERIMETER, "PERIMETER", 0, "Perimeter", ""},
        {SIMFACE_NORMAL, "NORMAL", 0, "Normal", ""},
        {SIMFACE_COPLANAR, "COPLANAR", 0, "Co-planar", ""},
 +#ifdef WITH_FREESTYLE
 +      {SIMFACE_FREESTYLE, "FREESTYLE_FACE", 0, "Freestyle Face Marks", ""},
 +#endif
  
        {0, NULL, 0, NULL, NULL}
  };
@@@ -869,11 -863,7 +869,11 @@@ static EnumPropertyItem *select_similar
                        }
                }
                else if (em->selectmode & SCE_SELECT_FACE) {
 +#ifdef WITH_FREESTYLE
 +                      for (a = SIMFACE_MATERIAL; a <= SIMFACE_FREESTYLE; a++) {
 +#else
                        for (a = SIMFACE_MATERIAL; a <= SIMFACE_COPLANAR; a++) {
 +#endif
                                RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a);
                        }
                }
@@@ -995,8 -985,8 +995,8 @@@ static void walker_select(BMEditMesh *e
                 BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP,
                 BMW_FLAG_TEST_HIDDEN,
                 BMW_NIL_LAY);
-       ele = BMW_begin(&walker, start);
-       for (; ele; ele = BMW_step(&walker)) {
+       for (ele = BMW_begin(&walker, start); ele; ele = BMW_step(&walker)) {
                if (!select) {
                        BM_select_history_remove(bm, ele);
                }
@@@ -1323,11 -1313,6 +1323,11 @@@ static void edgetag_context_set(BMesh *
                case EDGE_MODE_TAG_SHARP:
                        BM_elem_flag_set(e, BM_ELEM_SMOOTH, !val);
                        break;
 +#ifdef WITH_FREESTYLE
 +              case EDGE_MODE_TAG_FREESTYLE:
 +                      BM_elem_flag_set(e, BM_ELEM_FREESTYLE, val);
 +                      break;
 +#endif
                case EDGE_MODE_TAG_CREASE:
                        BM_elem_float_data_set(&bm->edata, e, CD_CREASE, (val) ? 1.0f : 0.0f);
                        break;
@@@ -1346,10 -1331,6 +1346,10 @@@ static int edgetag_context_check(Scene 
                        return BM_elem_flag_test(e, BM_ELEM_SEAM);
                case EDGE_MODE_TAG_SHARP:
                        return !BM_elem_flag_test(e, BM_ELEM_SMOOTH);
 +#ifdef WITH_FREESTYLE
 +              case EDGE_MODE_TAG_FREESTYLE:
 +                      return !BM_elem_flag_test(e, BM_ELEM_FREESTYLE);
 +#endif
                case EDGE_MODE_TAG_CREASE:
                        return BM_elem_float_data_get(&bm->edata, e, CD_CREASE) ? TRUE : FALSE;
                case EDGE_MODE_TAG_BEVEL:
@@@ -1515,11 -1496,6 +1515,11 @@@ static int mouse_mesh_shortest_path_edg
                        case EDGE_MODE_TAG_BEVEL:
                                me->drawflag |= ME_DRAWBWEIGHTS;
                                break;
 +#ifdef WITH_FREESTYLE
 +                      case EDGE_MODE_TAG_FREESTYLE:
 +                              me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
 +                              break;
 +#endif
                }
                
                EDBM_update_generic(em, FALSE, FALSE);
@@@ -1782,7 -1758,7 +1782,7 @@@ void MESH_OT_select_shortest_path(wmOpe
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
  }
  
  /* ************************************************** */
@@@ -2286,8 -2262,7 +2286,7 @@@ static int edbm_select_linked_pick_invo
                         BMW_FLAG_TEST_HIDDEN,
                         BMW_NIL_LAY);
  
-               efa = BMW_begin(&walker, efa);
-               for (; efa; efa = BMW_step(&walker)) {
+               for (efa = BMW_begin(&walker, efa); efa; efa = BMW_step(&walker)) {
                        BM_face_select_set(bm, efa, sel);
                }
                BMW_end(&walker);
                         BMW_FLAG_TEST_HIDDEN,
                         BMW_NIL_LAY);
  
-               e = BMW_begin(&walker, eed->v1);
-               for (; e; e = BMW_step(&walker)) {
+               for (e = BMW_begin(&walker, eed->v1); e; e = BMW_step(&walker)) {
                        BM_edge_select_set(bm, e, sel);
                }
                BMW_end(&walker);
@@@ -2380,8 -2354,7 +2378,7 @@@ static int edbm_select_linked_exec(bCon
  
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
                        if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
-                               efa = BMW_begin(&walker, efa);
-                               for (; efa; efa = BMW_step(&walker)) {
+                               for (efa = BMW_begin(&walker, efa); efa; efa = BMW_step(&walker)) {
                                        BM_face_select_set(bm, efa, TRUE);
                                }
                        }
  
                BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
                        if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
-                               e = BMW_begin(&walker, v);
-                               for (; e; e = BMW_step(&walker)) {
-                                       BM_vert_select_set(em->bm, e->v1, TRUE);
-                                       BM_vert_select_set(em->bm, e->v2, TRUE);
+                               for (e = BMW_begin(&walker, v); e; e = BMW_step(&walker)) {
+                                       BM_edge_select_set(em->bm, e, true);
                                }
                        }
                }
@@@ -2859,6 -2830,9 +2854,9 @@@ static int edbm_select_non_manifold_exe
        BMEdge *e;
        BMIter iter;
  
+       if (!RNA_boolean_get(op->ptr, "extend"))
+               EDBM_flag_disable_all(em, BM_ELEM_SELECT);
        /* Selects isolated verts, and edges that do not have 2 neighboring
         * faces
         */
@@@ -2898,6 -2872,9 +2896,9 @@@ void MESH_OT_select_non_manifold(wmOper
        
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       /* props */
+       RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend the selection");
  }
  
  static int edbm_select_random_exec(bContext *C, wmOperator *op)
@@@ -2962,8 -2939,7 +2963,7 @@@ void MESH_OT_select_random(wmOperatorTy
        /* props */
        RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f,
                                 "Percent", "Percentage of elements to select randomly", 0.f, 100.0f);
-       RNA_def_boolean(ot->srna, "extend", 0,
-                       "Extend Selection", "Extend selection instead of deselecting everything first");
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
  }
  
  static int edbm_select_next_loop_exec(bContext *C, wmOperator *UNUSED(op))
index 27c68ce21bc3350e91dc4c5e0878e3afe406e461,3e8219bfd1c5699cf70cee8661c837fd0a15a5c6..b411cd2bd27b611805a157140f667918c3bb9b35
@@@ -387,7 -387,7 +387,7 @@@ static short edbm_extrude_edge(Object *
                if (ele->head.htype == BM_FACE) {
                        f = (BMFace *)ele;
                        add_normal_aligned(nor, f->no);
-               };
+               }
        }
  
        normalize_v3(nor);
@@@ -3190,8 -3190,7 +3190,7 @@@ static int mesh_separate_loose(Main *bm
                         BMW_FLAG_NOP,
                         BMW_NIL_LAY);
  
-               e = BMW_begin(&walker, v_seed);
-               for (; e; e = BMW_step(&walker)) {
+               for (e = BMW_begin(&walker, v_seed); e; e = BMW_step(&walker)) {
                        if (!BM_elem_flag_test(e->v1, BM_ELEM_TAG)) { BM_elem_flag_enable(e->v1, BM_ELEM_TAG); tot++; }
                        if (!BM_elem_flag_test(e->v2, BM_ELEM_TAG)) { BM_elem_flag_enable(e->v2, BM_ELEM_TAG); tot++; }
                }
@@@ -3838,6 -3837,9 +3837,9 @@@ static int edbm_select_face_by_sides_ex
        const int numverts = RNA_int_get(op->ptr, "number");
        const int type = RNA_enum_get(op->ptr, "type");
  
+       if (!RNA_boolean_get(op->ptr, "extend"))
+               EDBM_flag_disable_all(em, BM_ELEM_SELECT);
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
  
                int select;
@@@ -3897,9 -3899,10 +3899,10 @@@ void MESH_OT_select_face_by_sides(wmOpe
        /* properties */
        RNA_def_int(ot->srna, "number", 4, 3, INT_MAX, "Number of Vertices", "", 3, INT_MAX);
        RNA_def_enum(ot->srna, "type", type_items, 1, "Type", "Type of comparison to make");
+       RNA_def_boolean(ot->srna, "extend", TRUE, "Extend", "Extend the selection");
  }
  
- static int edbm_select_loose_verts_exec(bContext *C, wmOperator *UNUSED(op))
+ static int edbm_select_loose_verts_exec(bContext *C, wmOperator *op)
  {
        Object *obedit = CTX_data_edit_object(C);
        BMEditMesh *em = BMEdit_FromObject(obedit);
        BMEdge *eed;
        BMIter iter;
  
+       if (!RNA_boolean_get(op->ptr, "extend"))
+               EDBM_flag_disable_all(em, BM_ELEM_SELECT);
        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                if (!eve->e) {
                        BM_vert_select_set(em->bm, eve, TRUE);
@@@ -3938,6 -3944,9 +3944,9 @@@ void MESH_OT_select_loose_verts(wmOpera
  
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       /* props */
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
  }
  
  static int edbm_select_mirror_exec(bContext *C, wmOperator *op)
@@@ -4593,7 -4602,7 +4602,7 @@@ static int edbm_noise_exec(bContext *C
                BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                        if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
                                float tin, dum;
-                               externtex(ma->mtex[0], eve->co, &tin, &dum, &dum, &dum, &dum, 0);
+                               externtex(ma->mtex[0], eve->co, &tin, &dum, &dum, &dum, &dum, 0, NULL);
                                eve->co[2] += fac * tin;
                        }
                }
@@@ -5750,109 -5759,3 +5759,109 @@@ void MESH_OT_symmetrize(struct wmOperat
                                BMO_SYMMETRIZE_NEGATIVE_X,
                                "Direction", "Which sides to copy from and to");
  }
 +
 +#ifdef WITH_FREESTYLE
 +static int edbm_mark_freestyle_edge(bContext *C, wmOperator *op)
 +{
 +      Object *obedit = CTX_data_edit_object(C);
 +      Mesh *me = ((Mesh *)obedit->data);
 +      BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
 +      BMEdge *eed;
 +      BMIter iter;
 +      int clear = RNA_boolean_get(op->ptr, "clear");
 +
 +      if (em == NULL)
 +              return OPERATOR_FINISHED;
 +
 +      /* auto-enable seams drawing */
 +      if (clear == 0) {
 +              me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
 +      }
 +
 +      if (clear) {
 +              BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
 +                      if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_disable(eed, BM_ELEM_FREESTYLE);
 +              }
 +      }
 +      else {
 +              BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
 +                      if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_enable(eed, BM_ELEM_FREESTYLE);
 +              }
 +      }
 +
 +      DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +void MESH_OT_mark_freestyle_edge(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name = "Mark Freestyle Edge";
 +      ot->description = "(un)mark selected edges as Freestyle feature edges";
 +      ot->idname = "MESH_OT_mark_freestyle_edge";
 +
 +      /* api callbacks */
 +      ot->exec = edbm_mark_freestyle_edge;
 +      ot->poll = ED_operator_editmesh;
 +
 +      /* flags */
 +      ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
 +}
 +
 +static int edbm_mark_freestyle_face_exec(bContext *C, wmOperator *op)
 +{
 +      Object *obedit = CTX_data_edit_object(C);
 +      Mesh *me = ((Mesh *)obedit->data);
 +      BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
 +      BMFace *efa;
 +      BMIter iter;
 +      int clear = RNA_boolean_get(op->ptr, "clear");
 +
 +      if (em == NULL) return OPERATOR_FINISHED;
 +
 +      /* auto-enable Freestyle face mark drawing */
 +      if(!clear) {
 +              me->drawflag |= ME_DRAW_FREESTYLE_FACE;
 +      }
 +
 +      if(clear) {
 +              BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
 +                      if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_disable(efa, BM_ELEM_FREESTYLE);
 +              }
 +      } else {
 +              BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
 +                      if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_enable(efa, BM_ELEM_FREESTYLE);
 +              }
 +      }
 +
 +      DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +void MESH_OT_mark_freestyle_face(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name = "Mark Freestyle Face";
 +      ot->description = "(un)mark selected faces for exclusion from Freestyle feature edge detection";
 +      ot->idname = "MESH_OT_mark_freestyle_face";
 +
 +      /* api callbacks */
 +      ot->exec = edbm_mark_freestyle_face_exec;
 +      ot->poll = ED_operator_editmesh;
 +
 +      /* flags */
 +      ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
 +}
 +#endif
index 790a7eae487fad650d307fccdd633664c58d3b96,9ea15f93250b0b690e066e96cd961e30e798c4e6..fe4917acdacb0177133edec7fcfa6e0f6262722f
@@@ -131,9 -131,6 +131,9 @@@ void MESH_OT_select_random(struct wmOpe
  void MESH_OT_loop_multi_select(struct wmOperatorType *ot);
  void MESH_OT_mark_seam(struct wmOperatorType *ot);
  void MESH_OT_mark_sharp(struct wmOperatorType *ot);
 +#ifdef WITH_FREESTYLE
 +void MESH_OT_mark_freestyle_edge(struct wmOperatorType *ot);
 +#endif
  void MESH_OT_vertices_smooth(struct wmOperatorType *ot);
  void MESH_OT_vertices_smooth_laplacian(struct wmOperatorType *ot);
  void MESH_OT_noise(struct wmOperatorType *ot);
@@@ -183,9 -180,6 +183,9 @@@ void MESH_OT_rip(struct wmOperatorType 
  void MESH_OT_shape_propagate_to_all(struct wmOperatorType *ot);
  void MESH_OT_blend_from_shape(struct wmOperatorType *ot);
  void MESH_OT_sort_elements(struct wmOperatorType *ot);
 +#ifdef WITH_FREESTYLE
 +void MESH_OT_mark_freestyle_face(struct wmOperatorType *ot);
 +#endif
  
  /* ******************* mesh_data.c */
  
@@@ -216,7 -210,6 +216,6 @@@ void MESH_OT_bevel(struct wmOperatorTyp
  void MESH_OT_bridge_edge_loops(struct wmOperatorType *ot);
  void MESH_OT_inset(struct wmOperatorType *ot);
  void MESH_OT_wireframe(struct wmOperatorType *ot);
- void MESH_OT_vert_slide(struct wmOperatorType *ot);
  
  void MESH_OT_convex_hull(struct wmOperatorType *ot);
  
index 372d6feec0c76c7d3dac38ff7ecee3d8d75f81d6,4fdbb9310b096dbc33897cc10f28b054272b9708..9403299b0cdd5f368bc8bc02954fdb3b034e0072
@@@ -111,9 -111,6 +111,9 @@@ void ED_operatortypes_mesh(void
        WM_operatortype_append(MESH_OT_faces_shade_smooth);
        WM_operatortype_append(MESH_OT_faces_shade_flat);
        WM_operatortype_append(MESH_OT_sort_elements);
 +#ifdef WITH_FREESTYLE
 +      WM_operatortype_append(MESH_OT_mark_freestyle_face);
 +#endif
  
        WM_operatortype_append(MESH_OT_delete);
        WM_operatortype_append(MESH_OT_edge_collapse);
        WM_operatortype_append(MESH_OT_loop_multi_select);
        WM_operatortype_append(MESH_OT_mark_seam);
        WM_operatortype_append(MESH_OT_mark_sharp);
 +#ifdef WITH_FREESTYLE
 +      WM_operatortype_append(MESH_OT_mark_freestyle_edge);
 +#endif
        WM_operatortype_append(MESH_OT_vertices_smooth);
        WM_operatortype_append(MESH_OT_vertices_smooth_laplacian);
        WM_operatortype_append(MESH_OT_noise);
        WM_operatortype_append(MESH_OT_solidify);
        WM_operatortype_append(MESH_OT_select_nth);
        WM_operatortype_append(MESH_OT_vert_connect);
-       WM_operatortype_append(MESH_OT_vert_slide);
        WM_operatortype_append(MESH_OT_knife_tool);
  
        WM_operatortype_append(MESH_OT_bevel);
@@@ -269,10 -262,14 +268,14 @@@ void ED_keymap_mesh(wmKeyConfig *keycon
        keymap = WM_keymap_find(keyconf, "Mesh", 0, 0);
        keymap->poll = ED_operator_editmesh;
        
-       WM_keymap_add_item(keymap, "MESH_OT_loopcut_slide", RKEY, KM_PRESS, KM_CTRL, 0);
-       WM_keymap_add_item(keymap, "MESH_OT_bevel", BKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "MESH_OT_loopcut_slide", RKEY, KM_PRESS, KM_CTRL, 0);        
        WM_keymap_add_item(keymap, "MESH_OT_inset", IKEY, KM_PRESS, 0, 0);
  
+       kmi = WM_keymap_add_item(keymap, "MESH_OT_bevel", BKEY, KM_PRESS, KM_CTRL, 0);
+       RNA_boolean_set(kmi->ptr, "vertex_only", FALSE);
+       kmi = WM_keymap_add_item(keymap, "MESH_OT_bevel", BKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
+       RNA_boolean_set(kmi->ptr, "vertex_only", TRUE);
        /* selecting */
        /* standard mouse selection goes via space_view3d */
        kmi = WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "MESH_OT_vert_connect", JKEY, KM_PRESS, 0, 0);
  
        /* Vertex Slide */
-       WM_keymap_add_item(keymap, "MESH_OT_vert_slide", VKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "TRANSFORM_OT_vert_slide", VKEY, KM_PRESS, KM_SHIFT, 0);
        /* use KM_CLICK because same key is used for tweaks */
        kmi = WM_keymap_add_item(keymap, "MESH_OT_dupli_extrude_cursor", ACTIONMOUSE, KM_CLICK, KM_CTRL, 0);
        RNA_boolean_set(kmi->ptr, "rotate_source", TRUE);
index 7ef8dc49a5d614a3228bba16cea130b46a5f6252,6dd3ecca244fd0846716cddf7504c7c3f4f12e56..fc8d5d26455ed8d78e51cb986d3650f16256441a
@@@ -88,6 -88,7 +88,7 @@@
  #include "ED_types.h"
  
  #include "UI_resources.h"
+ #include "UI_interface_icons.h"
  
  #include "WM_api.h"
  #include "BLF_api.h"
@@@ -126,11 -127,7 +127,11 @@@ typedef struct drawDMEdgesSel_userData 
  } drawDMEdgesSel_userData;
  
  typedef struct drawDMFacesSel_userData {
 +#ifdef WITH_FREESTYLE
 +      unsigned char *cols[4];
 +#else
        unsigned char *cols[3];
 +#endif
  
        DerivedMesh *dm;
        BMEditMesh *em;
@@@ -172,17 -169,26 +173,26 @@@ static void ob_wire_color_blend_theme_i
  }
  
  /* this condition has been made more complex since editmode can draw textures */
- static int check_object_draw_texture(Scene *scene, View3D *v3d, int drawtype)
+ static bool check_object_draw_texture(Scene *scene, View3D *v3d, int drawtype)
  {
        /* texture and material draw modes */
-       if (ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) && drawtype > OB_SOLID)
-               return TRUE;
+       if (ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) && drawtype > OB_SOLID) {
+               return true;
+       }
  
        /* textured solid */
-       if (v3d->drawtype == OB_SOLID && (v3d->flag2 & V3D_SOLID_TEX) && !BKE_scene_use_new_shading_nodes(scene))
-               return TRUE;
+       if ((v3d->drawtype == OB_SOLID) &&
+           (v3d->flag2 & V3D_SOLID_TEX) &&
+           (BKE_scene_use_new_shading_nodes(scene) == false))
+       {
+               return true;
+       }
        
-       return FALSE;
+       if (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) {
+               return true;
+       }
+       
+       return false;
  }
  
  static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
  
  /* check for glsl drawing */
  
- int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, const short dt)
+ int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, const char dt)
  {
        if (!GPU_glsl_support())
                return 0;
                return 0;
        if (ob == OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
                return 0;
+       
+       if (v3d->flag2 & V3D_SHOW_SOLID_MATCAP)
+               return 1;
+       
        if (BKE_scene_use_new_shading_nodes(scene))
                return 0;
        
@@@ -1081,7 -1091,7 +1095,7 @@@ static void draw_transp_spot_volume(Lam
  }
  
  static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
-                      const short dt, const short dflag, const unsigned char ob_wire_col[4])
+                      const char dt, const short dflag, const unsigned char ob_wire_col[4])
  {
        Object *ob = base->object;
        const float pixsize = ED_view3d_pixel_size(rv3d, ob->obmat[3]);
@@@ -2291,23 -2301,6 +2305,23 @@@ static void draw_dm_edges_sharp(BMEditM
        dm->drawMappedEdges(dm, draw_dm_edges_sharp__setDrawOptions, em);
  }
  
 +#ifdef WITH_FREESTYLE
 +/* Draw only Freestyle feature edges */
 +static DMDrawOption draw_dm_edges_freestyle__setDrawOptions(void *userData, int index)
 +{
 +      BMEdge *eed = EDBM_edge_at_index(userData, index);
 +
 +      if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_FREESTYLE))
 +              return DM_DRAW_OPTION_NORMAL;
 +      else
 +              return DM_DRAW_OPTION_SKIP;
 +}
 +
 +static void draw_dm_edges_freestyle(BMEditMesh *em, DerivedMesh *dm)
 +{
 +      dm->drawMappedEdges(dm, draw_dm_edges_freestyle__setDrawOptions, em);
 +}
 +#endif
  
  /* Draw faces with color set based on selection
   * return 2 for the active face so it renders with stipple enabled */
@@@ -2326,11 -2319,7 +2340,11 @@@ static DMDrawOption draw_dm_faces_sel__
                        return DM_DRAW_OPTION_STIPPLE;
                }
                else {
 +#ifdef WITH_FREESTYLE
 +                      col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(efa, BM_ELEM_FREESTYLE) ? 3 : 0];
 +#else
                        col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
 +#endif
                        if (col[3] == 0)
                                return DM_DRAW_OPTION_SKIP;
                        glColor4ubv(col);
@@@ -2361,13 -2350,8 +2375,13 @@@ static int draw_dm_faces_sel__compareDr
        if (efa == data->efa_act || next_efa == data->efa_act)
                return 0;
  
 +#ifdef WITH_FREESTYLE
 +      col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(efa, BM_ELEM_FREESTYLE) ? 3 : 0];
 +      next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(next_efa, BM_ELEM_FREESTYLE) ? 3 : 0];
 +#else
        col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
        next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : 0];
 +#endif
  
        if (col[3] == 0 || next_col[3] == 0)
                return 0;
  }
  
  /* also draws the active face */
 +#ifdef WITH_FREESTYLE
 +static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
 +                              unsigned char *selCol, unsigned char *actCol, unsigned char *markCol, BMFace *efa_act)
 +#else
  static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
                                unsigned char *selCol, unsigned char *actCol, BMFace *efa_act)
 +#endif
  {
        drawDMFacesSel_userData data;
        data.dm = dm;
        data.em = em;
        data.cols[1] = selCol;
        data.cols[2] = actCol;
 +#ifdef WITH_FREESTYLE
 +      data.cols[3] = markCol;
 +#endif
        data.efa_act = efa_act;
        /* double lookup */
        data.orig_index_mf_to_mpoly = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
@@@ -2677,16 -2653,21 +2691,21 @@@ static void draw_em_measure_stats(View3
                BMFace *f;
                int n;
  
- #define DRAW_EM_MEASURE_STATS_FACEAREA()                                      \
-       if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {                               \
-               mul_v3_fl(vmid, 1.0f / (float)n);                                     \
-               if (unit->system)                                                     \
-                       bUnit_AsString(numstr, sizeof(numstr),                            \
-                                      (double)(area * unit->scale_length),               \
-                                      3, unit->system, B_UNIT_LENGTH, do_split, FALSE);  \
-               else                                                                  \
-                       BLI_snprintf(numstr, sizeof(numstr), conv_float, area);           \
-               view3d_cached_text_draw_add(vmid, numstr, 0, txt_flag, col);          \
+ #define DRAW_EM_MEASURE_STATS_FACEAREA()                                                 \
+       if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {                                          \
+               mul_v3_fl(vmid, 1.0f / (float)n);                                                \
+               if (unit->system) {                                                              \
+                       bUnit_AsString(numstr, sizeof(numstr),                                       \
+                                      (double)(area * unit->scale_length * unit->scale_length),     \
+                                      3, unit->system, B_UNIT_AREA, do_split, FALSE);               \
+                       view3d_cached_text_draw_add(vmid, numstr, 0,                                 \
+                                                   /* Metric system uses unicode "squared" sign! */ \
+                                                   txt_flag ^ V3D_CACHE_TEXT_ASCII, col);           \
+               }                                                                                \
+               else {                                                                           \
+                       BLI_snprintf(numstr, sizeof(numstr), conv_float, area);                      \
+                       view3d_cached_text_draw_add(vmid, numstr, 0, txt_flag, col);                 \
+               }                                                                                \
        } (void)0
  
                UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
@@@ -2858,7 -2839,7 +2877,7 @@@ static DMDrawOption draw_em_fancy__setG
  }
  
  static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
-                           Object *ob, BMEditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, const short dt)
+                           Object *ob, BMEditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, const char dt)
  
  {
        Mesh *me = ob->data;
        
        if (me->drawflag & ME_DRAWFACES) {  /* transp faces */
                unsigned char col1[4], col2[4], col3[4];
 +#ifdef WITH_FREESTYLE
 +              unsigned char col4[4];
 +#endif
  
                UI_GetThemeColor4ubv(TH_FACE, col1);
                UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
                UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
 +#ifdef WITH_FREESTYLE
 +              UI_GetThemeColor4ubv(TH_FREESTYLE_FACE_MARK, col4);
 +#endif
  
                glEnable(GL_BLEND);
                glDepthMask(0);  /* disable write in zbuffer, needed for nice transp */
                if (check_object_draw_texture(scene, v3d, dt))
                        col1[3] = 0;
  
 +#ifdef WITH_FREESTYLE
 +              if (!(me->drawflag & ME_DRAW_FREESTYLE_FACE))
 +                      col4[3] = 0;
 +
 +              draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
 +#else
                draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
 +#endif
  
                glDisable(GL_BLEND);
                glDepthMask(1);  /* restore write in zbuffer */
                /* even if draw faces is off it would be nice to draw the stipple face
                 * Make all other faces zero alpha except for the active
                 * */
 -              unsigned char col1[4], col2[4], col3[4];
 -              col1[3] = col2[3] = 0; /* don't draw */
 +              /* col4 is only used by WITH_FREESTYLE, but keeping it here spares some #ifdef's... */
 +              unsigned char col1[4], col2[4], col3[4], col4[4];
 +              col1[3] = col2[3] = col4[3] = 0; /* don't draw */
                UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
  
                glEnable(GL_BLEND);
                glDepthMask(0);  /* disable write in zbuffer, needed for nice transp */
  
 +#ifdef WITH_FREESTYLE
 +              draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
 +#else
                draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
 +#endif
  
                glDisable(GL_BLEND);
                glDepthMask(1);  /* restore write in zbuffer */
                        glLineWidth(1);
                }
  
 +#ifdef WITH_FREESTYLE
 +              if(me->drawflag & ME_DRAW_FREESTYLE_EDGE) {
 +                      UI_ThemeColor(TH_FREESTYLE_EDGE_MARK);
 +                      glLineWidth(2);
 +      
 +                      draw_dm_edges_freestyle(em, cageDM);
 +      
 +                      glColor3ub(0,0,0);
 +                      glLineWidth(1);
 +              }
 +#endif
 +      
                if (me->drawflag & ME_DRAWCREASES && CustomData_has_layer(&em->bm->edata, CD_CREASE)) {
                        draw_dm_creases(em, cageDM);
                }
@@@ -3094,7 -3045,7 +3113,7 @@@ static void draw_mesh_object_outline(Vi
  }
  
  static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
-                             const short dt, const unsigned char ob_wire_col[4], const short dflag)
+                             const char dt, const unsigned char ob_wire_col[4], const short dflag)
  {
        Object *ob = base->object;
        Mesh *me = ob->data;
                        glDepthMask(0);  /* disable write in zbuffer, selected edge wires show better */
                }
                
-               dm->drawEdges(dm, (dt == OB_WIRE || totface == 0), me->drawflag & ME_ALLEDGES);
+               dm->drawEdges(dm, (dt == OB_WIRE || totface == 0), (ob->dtx & OB_DRAW_ALL_EDGES));
  
                if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
                        glDepthMask(1);
  
  /* returns 1 if nothing was drawn, for detecting to draw an object center */
  static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
-                             const short dt, const unsigned char ob_wire_col[4], const short dflag)
+                             const char dt, const unsigned char ob_wire_col[4], const short dflag)
  {
        Object *ob = base->object;
        Object *obedit = scene->obedit;
@@@ -3651,7 -3602,7 +3670,7 @@@ static void drawCurveDMWired(Object *ob
  }
  
  /* return 1 when nothing was drawn */
- static int drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, const short dt)
+ static int drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt)
  {
        Object *ob = base->object;
        DerivedMesh *dm = ob->derivedFinal;
   * \return 1 when nothing was drawn
   */
  static int drawDispList_nobackface(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
-                                    const short dt, const short dflag, const unsigned char ob_wire_col[4])
+                                    const char dt, const short dflag, const unsigned char ob_wire_col[4])
  {
        Object *ob = base->object;
        ListBase *lb = NULL;
        return FALSE;
  }
  static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
-                         const short dt, const short dflag, const unsigned char ob_wire_col[4])
+                         const char dt, const short dflag, const unsigned char ob_wire_col[4])
  {
        int retval;
  
@@@ -4977,9 -4928,9 +4996,9 @@@ static void ob_draw_RE_motion(float com
        glEnd();
  }
  
- /*place to add drawers */
+ /* place to add drawers */
  
- static void tekenhandlesN(Nurb *nu, short sel, short hide_handles)
+ static void drawhandlesN(Nurb *nu, short sel, short hide_handles)
  {
        BezTriple *bezt;
        float *fp;
        glEnd();
  }
  
- static void tekenhandlesN_active(Nurb *nu)
+ static void drawhandlesN_active(Nurb *nu)
  {
        BezTriple *bezt;
        float *fp;
        glLineWidth(1);
  }
  
- static void tekenvertsN(Nurb *nu, short sel, short hide_handles, void *lastsel)
+ static void drawvertsN(Nurb *nu, short sel, short hide_handles, void *lastsel)
  {
        BezTriple *bezt;
        BPoint *bp;
@@@ -5330,7 -5281,7 +5349,7 @@@ static void draw_editnurb(Object *ob, N
  }
  
  static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, Nurb *nurb,
-                      const short dt, const short dflag, const unsigned char ob_wire_col[4])
+                      const char dt, const short dflag, const unsigned char ob_wire_col[4])
  {
        ToolSettings *ts = scene->toolsettings;
        Object *ob = base->object;
        for (nu = nurb; nu; nu = nu->next) {
                if (nu->type == CU_BEZIER) {
                        if (index == cu->actnu && !hide_handles)
-                               tekenhandlesN_active(nu);
-                       tekenhandlesN(nu, 0, hide_handles);
+                               drawhandlesN_active(nu);
+                       drawhandlesN(nu, 0, hide_handles);
                }
                index++;
        }
        /* selected handles */
        for (nu = nurb; nu; nu = nu->next) {
                if (nu->type == CU_BEZIER && (cu->drawflag & CU_HIDE_HANDLES) == 0)
-                       tekenhandlesN(nu, 1, hide_handles);
-               tekenvertsN(nu, 0, hide_handles, NULL);
+                       drawhandlesN(nu, 1, hide_handles);
+               drawvertsN(nu, 0, hide_handles, NULL);
        }
        
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
        for (nu = nurb; nu; nu = nu->next) {
-               tekenvertsN(nu, 1, hide_handles, cu->lastsel);
+               drawvertsN(nu, 1, hide_handles, cu->lastsel);
        }
        
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
@@@ -5478,39 -5429,6 +5497,6 @@@ static void draw_empty_cone(float size
        gluDeleteQuadric(qobj);
  }
  
- /* draw points on curve speed handles */
- #if 0  /* XXX old animation system stuff */
- static void curve_draw_speed(Scene *scene, Object *ob)
- {
-       Curve *cu = ob->data;
-       IpoCurve *icu;
-       BezTriple *bezt;
-       float loc[4], dir[3];
-       int a;
-       
-       if (cu->ipo == NULL)
-               return;
-       
-       icu = cu->ipo->curve.first;
-       if (icu == NULL || icu->totvert < 2)
-               return;
-       
-       glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
-       bglBegin(GL_POINTS);
-       for (a = 0, bezt = icu->bezt; a < icu->totvert; a++, bezt++) {
-               if (where_on_path(ob, bezt->vec[1][1], loc, dir)) {
-                       UI_ThemeColor((bezt->f2 & SELECT) && ob == OBACT ? TH_VERTEX_SELECT : TH_VERTEX);
-                       bglVertex3fv(loc);
-               }
-       }
-       glPointSize(1.0);
-       bglEnd();
- }
- #endif  /* XXX old animation system stuff */
  static void draw_textcurs(RegionView3D *rv3d, float textcurs[4][2])
  {
        cpack(0);
@@@ -5614,7 -5532,7 +5600,7 @@@ static void drawcircle_size(float size
  
  }
  
- /* needs fixing if non-identity matrice used */
+ /* needs fixing if non-identity matrix used */
  static void drawtube(const float vec[3], float radius, float height, float tmat[4][4])
  {
        float cur[3];
        glVertex3f(cur[0], cur[1] - radius, cur[2]);
        glEnd();
  }
- /* needs fixing if non-identity matrice used */
+ /* needs fixing if non-identity matrix used */
  static void drawcone(const float vec[3], float radius, float height, float tmat[4][4])
  {
        float cur[3];
        glVertex3f(cur[0], cur[1] - radius, cur[2]);
        glEnd();
  }
  /* return TRUE if nothing was drawn */
  static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
-                      const short dt, const short dflag, const unsigned char ob_wire_col[4])
+                      const char dt, const short dflag, const unsigned char ob_wire_col[4])
  {
        Object *ob = base->object;
        MetaBall *mb;
        }
        
        while (ml) {
                /* draw radius */
                if (mb->editelems) {
                        if ((dflag & DRAW_CONSTCOLOR) == 0) {
@@@ -6292,6 -6211,34 +6279,34 @@@ static void draw_object_wire_color(Scen
        r_ob_wire_col[3] = 255;
  }
  
+ static void draw_object_matcap_check(Scene *scene, View3D *v3d, Object *ob)
+ {
+       /* fixed rule, active object draws as matcap */
+       if (ob == OBACT) {
+               if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))
+                       return;
+                       
+               if (v3d->defmaterial == NULL) {
+                       extern Material defmaterial;
+                       
+                       v3d->defmaterial = MEM_mallocN(sizeof(Material), "matcap material");
+                       *(v3d->defmaterial) = defmaterial;
+                       v3d->defmaterial->gpumaterial.first = v3d->defmaterial->gpumaterial.last = NULL;
+                       v3d->defmaterial->preview = NULL;
+               }
+       &