svn merge ^/trunk/blender -r43830:43864
authorCampbell Barton <ideasman42@gmail.com>
Fri, 3 Feb 2012 01:30:21 +0000 (01:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 3 Feb 2012 01:30:21 +0000 (01:30 +0000)
339 files changed:
CMakeLists.txt
build_files/cmake/cmake_consistency_check_config.py
build_files/cmake/cmake_static_check_cppcheck.py
intern/cycles/blender/blender_mesh.cpp
release/plugins/sequence/Makefile [deleted file]
release/scripts/modules/bpy_extras/mesh_utils.py
release/scripts/modules/bpy_types.py
release/scripts/presets/keyconfig/maya.py
release/scripts/startup/bl_operators/uvcalc_follow_active.py
release/scripts/startup/bl_operators/uvcalc_lightmap.py
release/scripts/startup/bl_operators/uvcalc_smart_project.py
release/scripts/startup/bl_ui/properties_data_modifier.py
release/scripts/startup/bl_ui/space_info.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/CMakeLists.txt
source/blender/SConscript
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/BKE_bmesh.h
source/blender/blenkernel/BKE_cdderivedmesh.h
source/blender/blenkernel/BKE_customdata.h
source/blender/blenkernel/BKE_key.h
source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/BKE_modifier.h
source/blender/blenkernel/BKE_multires.h
source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/BKE_tessmesh.h [new file with mode: 0644]
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/BME_Customdata.c
source/blender/blenkernel/intern/BME_conversions.c
source/blender/blenkernel/intern/BME_eulers.c
source/blender/blenkernel/intern/BME_mesh.c
source/blender/blenkernel/intern/BME_structure.c
source/blender/blenkernel/intern/BME_tools.c
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/bvhutils.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/collision.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenkernel/intern/editderivedmesh.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/fluidsim.c
source/blender/blenkernel/intern/key.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/mesh_validate.c
source/blender/blenkernel/intern/modifiers_bmesh.c [new file with mode: 0644]
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/navmesh_conversion.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/shrinkwrap.c
source/blender/blenkernel/intern/smoke.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/BLI_editVert.h
source/blender/blenlib/BLI_scanfill.h
source/blender/blenlib/BLI_smallhash.h [new file with mode: 0755]
source/blender/blenlib/BLI_sparsemap.h [new file with mode: 0755]
source/blender/blenlib/BLI_threads.h
source/blender/blenlib/CMakeLists.txt
source/blender/blenlib/SConscript
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/math_base_inline.c
source/blender/blenlib/intern/pbvh.c
source/blender/blenlib/intern/scanfill.c
source/blender/blenlib/intern/smallhash.c [new file with mode: 0644]
source/blender/blenlib/intern/threads.c
source/blender/blenloader/SConscript
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/blenpluginapi/SConscript
source/blender/bmesh/CMakeLists.txt [new file with mode: 0644]
source/blender/bmesh/SConscript [new file with mode: 0644]
source/blender/bmesh/bmesh.h [new file with mode: 0644]
source/blender/bmesh/bmesh_class.h [new file with mode: 0644]
source/blender/bmesh/bmesh_error.h [new file with mode: 0644]
source/blender/bmesh/bmesh_filters.h [new file with mode: 0644]
source/blender/bmesh/bmesh_iterators.h [new file with mode: 0644]
source/blender/bmesh/bmesh_marking.h [new file with mode: 0644]
source/blender/bmesh/bmesh_operator_api.h [new file with mode: 0644]
source/blender/bmesh/bmesh_operators.h [new file with mode: 0644]
source/blender/bmesh/bmesh_queries.h [new file with mode: 0644]
source/blender/bmesh/bmesh_walkers.h [new file with mode: 0644]
source/blender/bmesh/editmesh_tools.c [moved from source/blender/editors/mesh/editmesh_tools.c with 53% similarity]
source/blender/bmesh/intern/bmesh_construct.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_eulers.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_filters.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_inline.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_interp.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_iterators.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_iterators_inline.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_marking.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_mesh.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_mods.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_newcore.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_opdefines.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_operators.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_operators_private.h [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_polygon.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_private.h [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_queries.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_structure.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_structure.h [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_to_editmesh.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_walkers.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_walkers_impl.c [new file with mode: 0644]
source/blender/bmesh/intern/bmesh_walkers_private.h [new file with mode: 0644]
source/blender/bmesh/intern/editmesh_to_bmesh.c [new file with mode: 0644]
source/blender/bmesh/intern/in-progress/BME_conversions.c [new file with mode: 0644]
source/blender/bmesh/operators/bevel.c [new file with mode: 0644]
source/blender/bmesh/operators/bmesh_dupeops.c [new file with mode: 0644]
source/blender/bmesh/operators/connectops.c [new file with mode: 0644]
source/blender/bmesh/operators/createops.c [new file with mode: 0644]
source/blender/bmesh/operators/dissolveops.c [new file with mode: 0644]
source/blender/bmesh/operators/edgesplitop.c [new file with mode: 0644]
source/blender/bmesh/operators/extrudeops.c [new file with mode: 0644]
source/blender/bmesh/operators/join_triangles.c [new file with mode: 0644]
source/blender/bmesh/operators/mesh_conv.c [new file with mode: 0644]
source/blender/bmesh/operators/mirror.c [new file with mode: 0644]
source/blender/bmesh/operators/primitiveops.c [new file with mode: 0644]
source/blender/bmesh/operators/removedoubles.c [new file with mode: 0644]
source/blender/bmesh/operators/subdivideop.c [new file with mode: 0644]
source/blender/bmesh/operators/subdivideop.h [new file with mode: 0644]
source/blender/bmesh/operators/triangulateop.c [new file with mode: 0644]
source/blender/bmesh/operators/utils.c [new file with mode: 0644]
source/blender/bmesh/tools/BME_bevel.c [new file with mode: 0644]
source/blender/bmesh/tools/BME_dupe_ops.c [new file with mode: 0644]
source/blender/bmesh/tools/BME_duplicate.c [new file with mode: 0644]
source/blender/bmesh/tools/BME_extrude.c [new file with mode: 0644]
source/blender/bmesh/tools/BME_weld.c [new file with mode: 0644]
source/blender/collada/GeometryExporter.cpp
source/blender/collada/MeshImporter.cpp
source/blender/editors/animation/SConscript
source/blender/editors/armature/SConscript
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/meshlaplacian.c
source/blender/editors/armature/reeb.c
source/blender/editors/curve/SConscript
source/blender/editors/curve/editcurve.c
source/blender/editors/curve/editfont.c
source/blender/editors/datafiles/SConscript
source/blender/editors/gpencil/SConscript
source/blender/editors/include/ED_mesh.h
source/blender/editors/include/ED_object.h
source/blender/editors/include/ED_toolmode.h [new file with mode: 0755]
source/blender/editors/include/ED_util.h
source/blender/editors/include/ED_uvedit.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/interface/SConscript
source/blender/editors/interface/interface_templates.c
source/blender/editors/mesh/CMakeLists.txt
source/blender/editors/mesh/SConscript
source/blender/editors/mesh/bmesh_select.c [new file with mode: 0644]
source/blender/editors/mesh/bmesh_selecthistory.c [new file with mode: 0644]
source/blender/editors/mesh/bmesh_tools.c [new file with mode: 0644]
source/blender/editors/mesh/bmeshutils.c [new file with mode: 0644]
source/blender/editors/mesh/editbmesh_add.c [new file with mode: 0644]
source/blender/editors/mesh/editbmesh_bvh.c [new file with mode: 0644]
source/blender/editors/mesh/editbmesh_bvh.h [new file with mode: 0644]
source/blender/editors/mesh/editface.c
source/blender/editors/mesh/editmesh.c [deleted file]
source/blender/editors/mesh/editmesh_add.c [deleted file]
source/blender/editors/mesh/editmesh_lib.c [deleted file]
source/blender/editors/mesh/editmesh_loop.c [deleted file]
source/blender/editors/mesh/editmesh_mods.c [deleted file]
source/blender/editors/mesh/knifetool.c [new file with mode: 0755]
source/blender/editors/mesh/loopcut.c
source/blender/editors/mesh/mesh_data.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_navmesh.c
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/metaball/mball_edit.c
source/blender/editors/object/CMakeLists.txt
source/blender/editors/object/SConscript
source/blender/editors/object/object_add.c
source/blender/editors/object/object_bake.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_hook.c
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_lattice.c
source/blender/editors/object/object_modifier.c
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_transform.c
source/blender/editors/object/object_vgroup.c
source/blender/editors/physics/SConscript
source/blender/editors/physics/particle_edit.c
source/blender/editors/physics/particle_object.c
source/blender/editors/render/CMakeLists.txt
source/blender/editors/render/SConscript
source/blender/editors/render/render_shading.c
source/blender/editors/screen/CMakeLists.txt
source/blender/editors/screen/SConscript
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt_paint/CMakeLists.txt
source/blender/editors/sculpt_paint/SConscript
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_utils.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_undo.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/editors/space_api/CMakeLists.txt
source/blender/editors/space_api/SConscript
source/blender/editors/space_buttons/SConscript
source/blender/editors/space_image/CMakeLists.txt
source/blender/editors/space_image/SConscript
source/blender/editors/space_image/space_image.c
source/blender/editors/space_info/CMakeLists.txt
source/blender/editors/space_info/SConscript
source/blender/editors/space_info/info_stats.c
source/blender/editors/space_node/SConscript
source/blender/editors/space_view3d/CMakeLists.txt
source/blender/editors/space_view3d/SConscript
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/drawvolume.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/space_view3d/view3d_header.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/space_view3d/view3d_toolbar.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/editors/transform/CMakeLists.txt
source/blender/editors/transform/SConscript
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_manipulator.c
source/blender/editors/transform/transform_orientations.c
source/blender/editors/transform/transform_snap.c
source/blender/editors/util/CMakeLists.txt
source/blender/editors/util/SConscript
source/blender/editors/util/crazyspace.c
source/blender/editors/util/ed_util.c
source/blender/editors/util/editmode_undo.c
source/blender/editors/util/undo.c
source/blender/editors/uvedit/CMakeLists.txt
source/blender/editors/uvedit/SConscript
source/blender/editors/uvedit/uvedit_buttons.c
source/blender/editors/uvedit/uvedit_draw.c
source/blender/editors/uvedit/uvedit_intern.h
source/blender/editors/uvedit/uvedit_ops.c
source/blender/editors/uvedit/uvedit_parametrizer.c
source/blender/editors/uvedit/uvedit_parametrizer.h
source/blender/editors/uvedit/uvedit_smart_stitch.c
source/blender/editors/uvedit/uvedit_unwrap_ops.c
source/blender/gpu/intern/gpu_buffers.c
source/blender/makesdna/DNA_customdata_types.h
source/blender/makesdna/DNA_defs.h
source/blender/makesdna/DNA_key_types.h
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesdna/DNA_meshdata_types.h
source/blender/makesdna/DNA_modifier_types.h
source/blender/makesdna/DNA_vec_types.h
source/blender/makesdna/intern/SConscript
source/blender/makesdna/intern/dna_genfile.c
source/blender/makesrna/RNA_access.h
source/blender/makesrna/SConscript
source/blender/makesrna/intern/CMakeLists.txt
source/blender/makesrna/intern/SConscript
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_mesh_api.c
source/blender/makesrna/intern/rna_mesh_utils.h [new file with mode: 0644]
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_object_api.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_ui_api.c
source/blender/modifiers/CMakeLists.txt
source/blender/modifiers/MOD_modifiertypes.h
source/blender/modifiers/SConscript
source/blender/modifiers/intern/MOD_armature.c
source/blender/modifiers/intern/MOD_array.c
source/blender/modifiers/intern/MOD_bevel.c
source/blender/modifiers/intern/MOD_boolean.c
source/blender/modifiers/intern/MOD_boolean_util.c
source/blender/modifiers/intern/MOD_build.c
source/blender/modifiers/intern/MOD_cast.c
source/blender/modifiers/intern/MOD_collision.c
source/blender/modifiers/intern/MOD_curve.c
source/blender/modifiers/intern/MOD_decimate.c
source/blender/modifiers/intern/MOD_displace.c
source/blender/modifiers/intern/MOD_edgesplit.c
source/blender/modifiers/intern/MOD_explode.c
source/blender/modifiers/intern/MOD_fluidsim_util.c
source/blender/modifiers/intern/MOD_hook.c
source/blender/modifiers/intern/MOD_lattice.c
source/blender/modifiers/intern/MOD_mask.c
source/blender/modifiers/intern/MOD_meshdeform.c
source/blender/modifiers/intern/MOD_mirror.c
source/blender/modifiers/intern/MOD_multires.c
source/blender/modifiers/intern/MOD_ngoninterp.c [new file with mode: 0644]
source/blender/modifiers/intern/MOD_ocean.c
source/blender/modifiers/intern/MOD_particleinstance.c
source/blender/modifiers/intern/MOD_particlesystem.c
source/blender/modifiers/intern/MOD_remesh.c
source/blender/modifiers/intern/MOD_screw.c
source/blender/modifiers/intern/MOD_shapekey.c
source/blender/modifiers/intern/MOD_shrinkwrap.c
source/blender/modifiers/intern/MOD_simpledeform.c
source/blender/modifiers/intern/MOD_smooth.c
source/blender/modifiers/intern/MOD_solidify.c
source/blender/modifiers/intern/MOD_subsurf.c
source/blender/modifiers/intern/MOD_surface.c
source/blender/modifiers/intern/MOD_util.c
source/blender/modifiers/intern/MOD_util.h
source/blender/modifiers/intern/MOD_uvproject.c
source/blender/modifiers/intern/MOD_warp.c
source/blender/modifiers/intern/MOD_wave.c
source/blender/modifiers/intern/MOD_weightvgedit.c
source/blender/modifiers/intern/MOD_weightvgmix.c
source/blender/modifiers/intern/MOD_weightvgproximity.c
source/blender/render/SConscript
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/render_texture.c
source/blender/render/intern/source/strand.c
source/blender/windowmanager/SConscript
source/blender/windowmanager/intern/wm_gesture.c
source/blenderplayer/CMakeLists.txt
source/blenderplayer/bad_level_call_stubs/stubs.c
source/creator/CMakeLists.txt
source/creator/creator.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Ketsji/KX_NavMeshObject.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

index 47d40bb48c28d19952483fa596137bfbf288583e..4cd52245fefe2f4613eed2a9e90f95d1ad921f9c 100644 (file)
@@ -129,7 +129,7 @@ option(WITH_BUILDINFO     "Include extra build details (only disable for develop
 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
-option(WITH_GAMEENGINE    "Enable Game Engine" ON)
+option(WITH_GAMEENGINE    "Enable Game Engine" OFF)  # DISABLE FOR BMESH UNTIL NAVMESH IS WORKING
 option(WITH_PLAYER        "Build Player" OFF)
 
 # GHOST Windowing Library Options
index a6215b40ae8335113f0cb04fb9b4cffd98d80316..2634b1ae5677ca204881fec66fce0c1d24a309e5 100644 (file)
@@ -49,6 +49,15 @@ IGNORE = (
     "extern/recastnavigation/Recast/Include/RecastTimer.h",
     "intern/audaspace/SRC/AUD_SRCResampleFactory.h",
     "intern/audaspace/SRC/AUD_SRCResampleReader.h",
+
+    # for bmesh branch only
+    "source/blender/bmesh/editmesh_tools.c",
+    "source/blender/bmesh/intern/in-progress/BME_conversions.c",
+    "source/blender/bmesh/tools/BME_bevel.c",
+    "source/blender/bmesh/tools/BME_dupe_ops.c",
+    "source/blender/bmesh/tools/BME_duplicate.c",
+    "source/blender/bmesh/tools/BME_extrude.c",
+    "source/blender/bmesh/tools/BME_weld.c",
     )
 
 UTF8_CHECK = True
index 6c13f3a079a12826d46a01a86468be393b71ef45..aba199876981f3f2ecc663c91881a70a2d0ce420 100644 (file)
@@ -40,7 +40,7 @@ CHECKER_ARGS = [
        "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR,
     # "--max-configs=1",  # speeds up execution
     #  "--check-config", # when includes are missing
-    #  "--enable=all",  # if you want sixty hundred pedantic suggestions
+    "--enable=all",  # if you want sixty hundred pedantic suggestions
     ]
 
 
@@ -49,6 +49,8 @@ def main():
 
     check_commands = []
     for c, inc_dirs, defs in source_info:
+        if not 'bevel' in c: continue
+        if 'MOD' in c: continue
         cmd = ([CHECKER_BIN] +
                 CHECKER_ARGS +
                [c] +
@@ -61,7 +63,7 @@ def main():
     process_functions = []
 
     def my_process(i, c, cmd):
-        percent = 100.0 * (i / (len(check_commands) - 1))
+        percent = 100.0 * (i / (len(check_commands)))
         percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
 
         sys.stdout.flush()
index bc43809e46c935b05c7121ae520aa664b7ec95b1..c7844782e78c5d95c30bb3a62ec91e4a70692801 100644 (file)
@@ -115,9 +115,9 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
 
        /* create vertex color attributes */
        {
-               BL::Mesh::vertex_colors_iterator l;
+               BL::Mesh::tessface_vertex_colors_iterator l;
 
-               for(b_mesh.vertex_colors.begin(l); l != b_mesh.vertex_colors.end(); ++l) {
+               for(b_mesh.tessface_vertex_colors.begin(l); l != b_mesh.tessface_vertex_colors.end(); ++l) {
                        if(!mesh_need_attribute(scene, mesh, ustring(l->name().c_str())))
                                continue;
 
@@ -147,9 +147,9 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
 
        /* create uv map attributes */
        {
-               BL::Mesh::uv_textures_iterator l;
+               BL::Mesh::tessface_uv_textures_iterator l;
 
-               for(b_mesh.uv_textures.begin(l); l != b_mesh.uv_textures.end(); ++l) {
+               for(b_mesh.tessface_uv_textures.begin(l); l != b_mesh.tessface_uv_textures.end(); ++l) {
                        Attribute::Standard std = (l->active_render())? Attribute::STD_UV: Attribute::STD_NONE;
                        ustring name = ustring(l->name().c_str());
 
diff --git a/release/plugins/sequence/Makefile b/release/plugins/sequence/Makefile
deleted file mode 100644 (file)
index 2b12e62..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): none yet.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-all: plugins
-
-plugins:
-       @/bin/sh -c 'for i in *.c; do ../bmake $$i; done;'
-
-clean:
-       rm -rf *.o *.so
index 8149675000ffcd9366f2cf5b4201c7b8a9b24a83..1f37447a68ef11fe6691d0093aa5db7c3fffce6c 100644 (file)
@@ -140,8 +140,7 @@ def edge_loops_from_faces(mesh, faces=None, seams=()):
     edges = {}
 
     for f in faces:
-#        if len(f) == 4:
-        if f.vertices_raw[3] != 0:
+        if len(f.vertices) == 4:
             edge_keys = f.edge_keys
             for i, edkey in enumerate(f.edge_keys):
                 edges.setdefault(edkey, []).append(edge_keys[OTHER_INDEX[i]])
index 088e239e9a54d097a7cad66477eebf2a520be085..eeb8f375c3de0e8422b076296d931eece939af5d 100644 (file)
@@ -202,7 +202,7 @@ class _GenericBone:
     @property
     def center(self):
         """The midpoint between the head and the tail."""
-        return (self.head + self.tail) * 0.5
+        return self.head.lerp(self.tail, 0.5)
 
     @property
     def length(self):
@@ -373,7 +373,8 @@ class Mesh(bpy_types.ID):
         """
         self.vertices.add(len(vertices))
         self.edges.add(len(edges))
-        self.faces.add(len(faces))
+        self.loops.add(sum((len(f) for f in faces)))
+        self.polygons.add(len(faces))
 
         vertices_flat = [f for v in vertices for f in v]
         self.vertices.foreach_set("co", vertices_flat)
@@ -383,19 +384,15 @@ class Mesh(bpy_types.ID):
         self.edges.foreach_set("vertices", edges_flat)
         del edges_flat
 
-        def treat_face(f):
-            if len(f) == 3:
-                if f[2] == 0:
-                    return f[2], f[0], f[1], 0
-                else:
-                    return f[0], f[1], f[2], 0
-            elif f[2] == 0 or f[3] == 0:
-                return f[2], f[3], f[0], f[1]
-            return f
-
-        faces_flat = [v for f in faces for v in treat_face(f)]
-        self.faces.foreach_set("vertices_raw", faces_flat)
-        del faces_flat
+        # this is different in bmesh
+        loop_index = 0
+        for i, p in enumerate(self.polygons):
+            f = faces[i]
+            loop_len = len(f)
+            p.loop_start = loop_index
+            p.loop_total = loop_len
+            p.vertices = f
+            loop_index += loop_len
 
     @property
     def edge_keys(self):
@@ -445,6 +442,20 @@ class MeshFace(StructRNA):
                     ord_ind(verts[3], verts[0]),
                     )
 
+class MeshPolygon(StructRNA):
+    __slots__ = ()
+
+    @property
+    def edge_keys(self):
+        verts = self.vertices[:]
+        vlen = len(self.vertices)
+        return [ord_ind(verts[i], verts[(i+1) % vlen]) for i in range(vlen)]
+
+    @property
+    def loops(self):
+        start = self.loop_start
+        end = start + self.loop_total
+        return range(start, end)
 
 class Text(bpy_types.ID):
     __slots__ = ()
@@ -639,7 +650,7 @@ class _GenericUI:
         draw_funcs = cls._dyn_ui_initialize()
         try:
             draw_funcs.remove(draw_func)
-        except:
+        except ValueError:
             pass
 
 
index 5e1e5d0d778e01efad5e19489e0118e8d05268c7..40bf1a9d1245db815b6d5909e436d9bb1acc322a 100644 (file)
@@ -346,9 +346,7 @@ kmi = km.keymap_items.new('mesh.split', 'Y', 'PRESS')
 kmi = km.keymap_items.new('mesh.dupli_extrude_cursor', 'ACTIONMOUSE', 'CLICK', ctrl=True)
 kmi = km.keymap_items.new('mesh.delete', 'X', 'PRESS')
 kmi = km.keymap_items.new('mesh.delete', 'DEL', 'PRESS')
-kmi = km.keymap_items.new('mesh.knife_cut', 'LEFTMOUSE', 'PRESS', key_modifier='K')
-kmi = km.keymap_items.new('mesh.knife_cut', 'LEFTMOUSE', 'PRESS', shift=True, key_modifier='K')
-kmi.properties.type = 'MIDPOINTS'
+kmi = km.keymap_items.new('mesh.knifetool', 'K', 'PRESS')
 kmi = km.keymap_items.new('object.vertex_parent_set', 'P', 'PRESS', ctrl=True)
 kmi = km.keymap_items.new('wm.call_menu', 'W', 'PRESS', ctrl=True)
 kmi.properties.name = 'VIEW3D_MT_edit_mesh_specials'
index 919677fff8b53369ec8fcb7e7626c58df5fd25b4..338dc1a2a1e0d216a052d8ab9388bfea211928d3 100644 (file)
@@ -30,6 +30,7 @@ def extend(obj, operator, EXTEND_MODE):
 
     me = obj.data
     me_verts = me.vertices
+
     # script will fail without UVs
     if not me.uv_textures:
         me.uv_textures.new()
@@ -52,17 +53,15 @@ def extend(obj, operator, EXTEND_MODE):
         '''
 
         def face_edge_vs(vi):
-            # assume a quad
-            return [(vi[0], vi[1]), (vi[1], vi[2]), (vi[2], vi[3]), (vi[3], vi[0])]
+            vlen = len(vi)
+            return [(vi[i], vi[(i+1) % vlen]) for i in range(vlen)]
 
         vidx_source = face_source.vertices
         vidx_target = face_target.vertices
 
-        faceUVsource = me.uv_textures.active.data[face_source.index]
-        uvs_source = [faceUVsource.uv1, faceUVsource.uv2, faceUVsource.uv3, faceUVsource.uv4]
-
-        faceUVtarget = me.uv_textures.active.data[face_target.index]
-        uvs_target = [faceUVtarget.uv1, faceUVtarget.uv2, faceUVtarget.uv3, faceUVtarget.uv4]
+        uv_layer = me.uv_loop_layers.active.data
+        uvs_source = [uv_layer[i].uv for i in face_source.loops]
+        uvs_target = [uv_layer[i].uv for i in face_target.loops]
 
         # vertex index is the key, uv is the value
 
@@ -135,15 +134,12 @@ def extend(obj, operator, EXTEND_MODE):
             uvs_vhash_target[edgepair_outer_target[iB]][:] = uvs_vhash_source[edgepair_inner_source[0]] + (uvs_vhash_source[edgepair_inner_source[0]] - uvs_vhash_source[edgepair_outer_source[1]])
             uvs_vhash_target[edgepair_outer_target[iA]][:] = uvs_vhash_source[edgepair_inner_source[1]] + (uvs_vhash_source[edgepair_inner_source[1]] - uvs_vhash_source[edgepair_outer_source[0]])
 
-    if not me.uv_textures:
-        me.uv_textures.new()
-
-    face_act = me.faces.active
+    face_act = me.polygons.active
     if face_act == -1:
         operator.report({'ERROR'}, "No active face")
         return
 
-    face_sel = [f for f in me.faces if len(f.vertices) == 4 and f.select]
+    face_sel = [f for f in me.polygons if len(f.vertices) == 4 and f.select]
 
     face_act_local_index = -1
     for i, f in enumerate(face_sel):
index 99a492fab4af6598b9a56d6d52e885d3c670ae19..793b2a4ce2a4913ce4a70023bef03e1b1ef5a730 100644 (file)
@@ -88,8 +88,8 @@ class prettyface(object):
             self.children = []
 
         else:  # blender face
-            # self.uv = data.uv
-            self.uv = data.id_data.uv_textures.active.data[data.index].uv  # XXX25
+            uv_layer = data.id_data.uv_loop_layers.active.data
+            self.uv = [uv_layer[i].uv for i in data.loops]
 
             # cos = [v.co for v in data]
             cos = [data.id_data.vertices[v].co for v in data.vertices]  # XXX25
@@ -158,7 +158,8 @@ class prettyface(object):
                 I = [i for a, i in angles_co]
 
                 #~ fuv = f.uv
-                fuv = f.id_data.uv_textures.active.data[f.index].uv  # XXX25
+                uv_layer = f.id_data.uv_loop_layers.active.data
+                fuv = [uv_layer[i].uv for i in f.loops]  # XXX25
 
                 if self.rot:
                     fuv[I[2]] = p1
@@ -219,15 +220,10 @@ def lightmap_uvpack(meshes,
         face_groups = []
 
     for me in meshes:
-        # Add face UV if it does not exist.
-        # All new faces are selected.
-        if not me.uv_textures:
-            me.uv_textures.new()
-
         if PREF_SEL_ONLY:
-            faces = [f for f in me.faces if f.select]
+            faces = [f for f in me.polygons if f.select]
         else:
-            faces = me.faces[:]
+            faces = me.polygons[:]
 
         if PREF_PACK_IN_ONE:
             face_groups[0].extend(faces)
@@ -237,6 +233,11 @@ def lightmap_uvpack(meshes,
         if PREF_NEW_UVLAYER:
             me.uv_textures.new()
 
+        # Add face UV if it does not exist.
+        # All new faces are selected.
+        if not me.uv_textures:
+            me.uv_textures.new()
+
     for face_sel in face_groups:
         print("\nStarting unwrap")
 
@@ -504,7 +505,7 @@ def lightmap_uvpack(meshes,
 
             for f in face_sel:
                 # f.image = image
-                f.id_data.uv_textures.active.data[f.index].image = image  # XXX25
+                f.id_data.uv_loop_layers.active.data[f.index].image = image  # XXX25
 
     for me in meshes:
         me.update()
@@ -528,7 +529,7 @@ def unwrap(operator, context, **kwargs):
         if obj and obj.type == 'MESH':
             meshes = [obj.data]
     else:
-        meshes = list({me for obj in context.selected_objects if obj.type == 'MESH' for me in (obj.data,) if me.faces and me.library is None})
+        meshes = list({me for obj in context.selected_objects if obj.type == 'MESH' for me in (obj.data,) if me.polygons and me.library is None})
 
     if not meshes:
         operator.report({'ERROR'}, "No mesh object")
index b79fc0c01b322722fdc3a31e5b97c483045bab54..8fee21cdad5863bd4692a1f992b10d0c90ffb8a2 100644 (file)
@@ -757,12 +757,9 @@ def VectoQuat(vec):
 
 class thickface(object):
     __slost__= "v", "uv", "no", "area", "edge_keys"
-    def __init__(self, face, uvface, mesh_verts):
+    def __init__(self, face, uv_layer, mesh_verts):
         self.v = [mesh_verts[i] for i in face.vertices]
-        if len(self.v)==4:
-            self.uv = uvface.uv1, uvface.uv2, uvface.uv3, uvface.uv4
-        else:
-            self.uv = uvface.uv1, uvface.uv2, uvface.uv3
+        self.uv = [uv_layer[i].uv for i in face.loops]
 
         self.no = face.normal
         self.area = face.area
@@ -892,13 +889,13 @@ def main(context,
         if not me.uv_textures: # Mesh has no UV Coords, don't bother.
             me.uv_textures.new()
 
-        uv_layer = me.uv_textures.active.data
+        uv_layer = me.uv_loop_layers.active.data
         me_verts = list(me.vertices)
 
         if USER_ONLY_SELECTED_FACES:
-            meshFaces = [thickface(f, uv_layer[i], me_verts) for i, f in enumerate(me.faces) if f.select]
+            meshFaces = [thickface(f, uv_layer, me_verts) for i, f in enumerate(me.polygons) if f.select]
         else:
-               meshFaces = [thickface(f, uv_layer[i], me_verts) for i, f in enumerate(me.faces)]
+            meshFaces = [thickface(f, uv_layer, me_verts) for i, f in enumerate(me.polygons)]
 
         if not meshFaces:
             continue
index 766daba58b8388ed6ce7cad659effcfb2cf876fa..7af8d79a01eb54c9e237232e80ca54e3289e9689 100644 (file)
@@ -46,7 +46,11 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     # the mt.type enum is (ab)used for a lookup on function names
     # ...to avoid lengthy if statements
     # so each type must have a function here.
-
+       
+    def NGONINTERP(self, layout, ob, md):
+        split = layout.split()
+        split.prop(md, "resolution")
+        
     def ARMATURE(self, layout, ob, md):
         split = layout.split()
 
@@ -122,6 +126,12 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         split.prop(md, "width")
         split.prop(md, "use_only_vertices")
 
+        # BMESH_BRANCH ONLY
+        split = layout.split()
+        split.prop(md, "use_even_offset")
+        split.prop(md, "use_distance_offset")
+        # END BMESH_BRANCH ONLY
+
         layout.label(text="Limit Method:")
         layout.row().prop(md, "limit_method", expand=True)
         if md.limit_method == 'ANGLE':
index 901f709fb5b4531b2fb61649e7964571d2bd305b..fab422dfb4308594881b79d089f6a6c2356f11cc 100644 (file)
@@ -170,6 +170,8 @@ class INFO_MT_file_export(Menu):
         if hasattr(bpy.types, "WM_OT_collada_export"):
             self.layout.operator("wm.collada_export", text="COLLADA (.dae)")
 
+        self.layout.operator("export_mesh.wavefront", text="Wavefront (.obj), BMesh")
+
 
 class INFO_MT_file_external_data(Menu):
     bl_label = "External Data"
index 1dba79b34d71330e0add69f3ff129cab9cb3770d..3aa9434073d29e3838d1470c40e8535ae9669cf2 100644 (file)
@@ -523,11 +523,10 @@ class VIEW3D_MT_select_edit_mesh(Menu):
 
         layout.separator()
 
-        layout.operator("mesh.select_by_number_vertices", text="Triangles").type = 'TRIANGLES'
-        layout.operator("mesh.select_by_number_vertices", text="Quads").type = 'QUADS'
+        layout.operator("mesh.select_by_number_vertices", text = "By Number of Verts")
         if context.scene.tool_settings.mesh_select_mode[2] == False:
             layout.operator("mesh.select_non_manifold", text="Non Manifold")
-        layout.operator("mesh.select_by_number_vertices", text="Loose Verts/Edges").type = 'OTHER'
+        layout.operator("mesh.select_loose_verts", text = "Loose Verts/Edges")
         layout.operator("mesh.select_similar", text="Similar")
 
         layout.separator()
@@ -1503,7 +1502,9 @@ class VIEW3D_MT_edit_mesh_specials(Menu):
         layout.operator_context = 'INVOKE_REGION_WIN'
 
         layout.operator("mesh.subdivide", text="Subdivide").smoothness = 0.0
+        """
         layout.operator("mesh.subdivide", text="Subdivide Smooth").smoothness = 1.0
+        """
         layout.operator("mesh.merge", text="Merge...")
         layout.operator("mesh.remove_doubles")
         layout.operator("mesh.hide", text="Hide")
@@ -1511,7 +1512,7 @@ class VIEW3D_MT_edit_mesh_specials(Menu):
         layout.operator("mesh.select_all").action = 'INVERT'
         layout.operator("mesh.flip_normals")
         layout.operator("mesh.vertices_smooth", text="Smooth")
-        layout.operator("mesh.bevel", text="Bevel")
+        layout.operator("mesh.bevel", text="Bevel")
         layout.operator("mesh.faces_shade_smooth")
         layout.operator("mesh.faces_shade_flat")
         layout.operator("mesh.blend_from_shape")
@@ -1585,6 +1586,7 @@ class VIEW3D_MT_edit_mesh_vertices(Menu):
         layout.operator("mesh.rip_move")
         layout.operator("mesh.split")
         layout.operator("mesh.separate")
+        layout.operator("mesh.vert_connect")
 
         layout.separator()
 
@@ -1633,6 +1635,10 @@ class VIEW3D_MT_edit_mesh_edges(Menu):
 
         layout.separator()
 
+        layout.operator("mesh.bridge_edge_loops", text="Bridge Two Edge Loops")
+
+        layout.separator()
+
         layout.operator("TRANSFORM_OT_edge_slide")
         layout.operator("TRANSFORM_OT_edge_crease")
         layout.operator("mesh.loop_multi_select", text="Edge Loop").ring = False
@@ -1665,11 +1671,6 @@ class VIEW3D_MT_edit_mesh_faces(Menu):
 
         layout.separator()
 
-        layout.operator("mesh.fgon_make")
-        layout.operator("mesh.fgon_clear")
-
-        layout.separator()
-
         layout.operator("mesh.quads_convert_to_tris")
         layout.operator("mesh.tris_convert_to_quads")
         layout.operator("mesh.edge_flip")
@@ -1689,9 +1690,9 @@ class VIEW3D_MT_edit_mesh_faces(Menu):
         layout.separator()
 
         layout.operator_menu_enum("mesh.uvs_rotate", "direction")
-        layout.operator_menu_enum("mesh.uvs_mirror", "axis")
+        layout.operator("mesh.uvs_reverse")
         layout.operator_menu_enum("mesh.colors_rotate", "direction")
-        layout.operator_menu_enum("mesh.colors_mirror", "axis")
+        layout.operator("mesh.colors_reverse")
 
 
 class VIEW3D_MT_edit_mesh_normals(Menu):
index 21c6ad66f16db336166a68040a8007afd363caec..cb17a87fd76a023a9eb90ad5de210a73f75ff05a 100644 (file)
@@ -92,6 +92,7 @@ add_subdirectory(editors)
 add_subdirectory(windowmanager)
 add_subdirectory(blenkernel)
 add_subdirectory(blenlib)
+add_subdirectory(bmesh)
 add_subdirectory(render)
 add_subdirectory(blenfont)
 add_subdirectory(blenloader)
index ea5101f811110ff08d48cff99a450243e8efe895..c3a7089f425659874bdd047c11b904d38bc2689f 100644 (file)
@@ -3,6 +3,7 @@ Import ('env')
 import sys
 
 SConscript(['avi/SConscript',
+            'bmesh/SConscript',
             'blenkernel/SConscript',
             'blenlib/SConscript',
             'blenloader/SConscript',
index a887412bbf47a41bccac0572f0d01de6e8e52fb0..69abfe3c34d80c1c31f7e7b8c3fa19fb81e37cb6 100644 (file)
 #ifndef BKE_DERIVEDMESH_H
 #define BKE_DERIVEDMESH_H
 
-/** \file BKE_DerivedMesh.h
- *  \ingroup bke
- *
- *  \todo
- *  - Make drawMapped* functions take a predicate function that
- *    determines whether to draw the edge (this predicate can
- *    also set color, etc). This will be slightly more general 
- *    and allow some of the functions to be collapsed.
- *  - Once accessor functions are added then single element draw
- *    functions can be implemented using primitive accessors.
- *  - Add function to dispatch to renderer instead of using
- *    conversion to DLM.
+/*
+  Basic design of the DerivedMesh system:
+
+  DerivedMesh is a common set of interfaces for mesh systems.
+
+  There are three main mesh data structures in Blender: Mesh, CDDM, and BMesh.
+  These, and a few others, all implement DerivedMesh interfaces, 
+  which contains unified drawing interfaces, a few utility interfaces, 
+  and a bunch of read-only interfaces intended mostly for conversion from 
+  one format to another.
+
+  All Mesh structures in blender make use of CustomData, which is used to store
+  per-element attributes and interpolate them (e.g. uvs, vcols, vgroups, etc).
+  
+  Mesh is the "serialized" structure, used for storing object-mode mesh data
+  and also for saving stuff to disk.  It's interfaces are also what DerivedMesh
+  uses to communicate with.
+  
+  CDDM is a little mesh library, that uses Mesh data structures in the backend.
+  It's mostly used for modifiers, and has the advantages of not taking much
+  resources.
+
+  BMesh is a full-on brep, used for editmode, some modifiers, etc.  It's much
+  more capable (if memory-intensive) then CDDM.
+
+  DerivedMesh is somewhat hackish.  Many places assumes that a DerivedMesh is
+  a CDDM (most of the time by simply copying it and converting it to one).
+  CDDM is the original structure for modifiers, but has since been superseded
+  by BMesh, at least for the foreseeable future.
+*/
+
+/* 
+ * Note: This sturcture is read-only, for all practical purposes.
+ *       At some point in the future, we may want to consider
+ *       creating a replacement structure that implements a proper
+ *       abstract mesh kernel interface.  Or, we can leave this
+ *       as it is and stick with using BMesh and CDDM.
  */
 
+
 #include "DNA_customdata_types.h"
+#include "DNA_meshdata_types.h"
+
 #include "BKE_customdata.h"
 #include "BKE_bvhutils.h"
 
@@ -53,20 +81,26 @@ struct MTFace;
 struct Object;
 struct Scene;
 struct Mesh;
-struct EditMesh;
+struct BMEditMesh;
 struct KeyBlock;
 struct ModifierData;
 struct MCol;
 struct ColorBand;
 struct GPUVertexAttribs;
 struct GPUDrawObject;
+struct BMEditMesh;
 struct ListBase;
 struct PBVH;
 
 /* number of sub-elements each mesh element has (for interpolation) */
 #define SUB_ELEMS_VERT 0
 #define SUB_ELEMS_EDGE 2
-#define SUB_ELEMS_FACE 4
+#define SUB_ELEMS_FACE 50
+
+/*
+Note: all mface interfaces now officially operate on tesselated data.
+      Also, the mface origindex layer indexes mpolys, not mfaces.
+*/
 
 typedef struct DMGridData {
        float co[3];
@@ -80,15 +114,15 @@ typedef struct DMGridAdjacency {
 
 typedef enum DerivedMeshType {
        DM_TYPE_CDDM,
-       DM_TYPE_EDITMESH,
+       DM_TYPE_EDITBMESH,
        DM_TYPE_CCGDM
 } DerivedMeshType;
 
 typedef struct DerivedMesh DerivedMesh;
 struct DerivedMesh {
        /* Private DerivedMesh data, only for internal DerivedMesh use */
-       CustomData vertData, edgeData, faceData;
-       int numVertData, numEdgeData, numFaceData;
+       CustomData vertData, edgeData, faceData, loopData, polyData;
+       int numVertData, numEdgeData, numTessFaceData, numLoopData, numPolyData;
        int needsFree; /* checked on ->release, is set to 0 for cached results */
        int deformedOnly; /* set by modifier stack if only deformed from original */
        BVHCache bvhCache;
@@ -96,23 +130,29 @@ struct DerivedMesh {
        DerivedMeshType type;
        float auto_bump_scale;
 
+       /* calculate vert and face normals */
+       void (*calcNormals)(DerivedMesh *dm);
+
+       /* recalculates mesh tesselation */
+       void (*recalcTesselation)(DerivedMesh *dm);
+
        /* Misc. Queries */
 
        /* Also called in Editmode */
        int (*getNumVerts)(DerivedMesh *dm);
-       /* Also called in Editmode */
-       int (*getNumFaces)(DerivedMesh *dm);
-
        int (*getNumEdges)(DerivedMesh *dm);
+       int (*getNumTessFaces)(DerivedMesh *dm);
+       int (*getNumLoops)(DerivedMesh *dm);
+       int (*getNumPolys)(DerivedMesh *dm);
 
-       /* copy a single vert/edge/face from the derived mesh into
+       /* copy a single vert/edge/tesselated face from the derived mesh into
         * *{vert/edge/face}_r. note that the current implementation
         * of this function can be quite slow, iterating over all
         * elements (editmesh)
         */
        void (*getVert)(DerivedMesh *dm, int index, struct MVert *vert_r);
        void (*getEdge)(DerivedMesh *dm, int index, struct MEdge *edge_r);
-       void (*getFace)(DerivedMesh *dm, int index, struct MFace *face_r);
+       void (*getTessFace)(DerivedMesh *dm, int index, struct MFace *face_r);
 
        /* return a pointer to the entire array of verts/edges/face from the
         * derived mesh. if such an array does not exist yet, it will be created,
@@ -121,21 +161,27 @@ struct DerivedMesh {
         */
        struct MVert *(*getVertArray)(DerivedMesh *dm);
        struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
-       struct MFace *(*getFaceArray)(DerivedMesh *dm);
+       struct MFace *(*getTessFaceArray)(DerivedMesh *dm);
+       struct MLoop *(*getLoopArray)(DerivedMesh *dm);
+       struct MPoly *(*getPolyArray)(DerivedMesh *dm);
 
        /* copy all verts/edges/faces from the derived mesh into
         * *{vert/edge/face}_r (must point to a buffer large enough)
         */
        void (*copyVertArray)(DerivedMesh *dm, struct MVert *vert_r);
        void (*copyEdgeArray)(DerivedMesh *dm, struct MEdge *edge_r);
-       void (*copyFaceArray)(DerivedMesh *dm, struct MFace *face_r);
+       void (*copyTessFaceArray)(DerivedMesh *dm, struct MFace *face_r);
+       void (*copyLoopArray)(DerivedMesh *dm, struct MLoop *loop_r);
+       void (*copyPolyArray)(DerivedMesh *dm, struct MPoly *poly_r);
 
        /* return a copy of all verts/edges/faces from the derived mesh
         * it is the caller's responsibility to free the returned pointer
         */
        struct MVert *(*dupVertArray)(DerivedMesh *dm);
        struct MEdge *(*dupEdgeArray)(DerivedMesh *dm);
-       struct MFace *(*dupFaceArray)(DerivedMesh *dm);
+       struct MFace *(*dupTessFaceArray)(DerivedMesh *dm);
+       struct MLoop *(*dupLoopArray)(DerivedMesh *dm);
+       struct MPoly *(*dupPolyArray)(DerivedMesh *dm);
 
        /* return a pointer to a single element of vert/edge/face custom data
         * from the derived mesh (this gives a pointer to the actual data, not
@@ -143,7 +189,7 @@ struct DerivedMesh {
         */
        void *(*getVertData)(DerivedMesh *dm, int index, int type);
        void *(*getEdgeData)(DerivedMesh *dm, int index, int type);
-       void *(*getFaceData)(DerivedMesh *dm, int index, int type);
+       void *(*getTessFaceData)(DerivedMesh *dm, int index, int type);
 
        /* return a pointer to the entire array of vert/edge/face custom data
         * from the derived mesh (this gives a pointer to the actual data, not
@@ -151,8 +197,21 @@ struct DerivedMesh {
         */
        void *(*getVertDataArray)(DerivedMesh *dm, int type);
        void *(*getEdgeDataArray)(DerivedMesh *dm, int type);
-       void *(*getFaceDataArray)(DerivedMesh *dm, int type);
-
+       void *(*getTessFaceDataArray)(DerivedMesh *dm, int type);
+       
+       /*retrieves the base CustomData structures for 
+         verts/edges/tessfaces/loops/facdes*/
+       CustomData *(*getVertDataLayout)(DerivedMesh *dm);
+       CustomData *(*getEdgeDataLayout)(DerivedMesh *dm);
+       CustomData *(*getTessFaceDataLayout)(DerivedMesh *dm);
+       CustomData *(*getLoopDataLayout)(DerivedMesh *dm);
+       CustomData *(*getPolyDataLayout)(DerivedMesh *dm);
+       
+       /*copies all customdata for an element source into dst at index dest*/
+       void (*copyFromVertCData)(DerivedMesh *dm, int source, CustomData *dst, int dest);
+       void (*copyFromEdgeCData)(DerivedMesh *dm, int source, CustomData *dst, int dest);
+       void (*copyFromFaceCData)(DerivedMesh *dm, int source, CustomData *dst, int dest);
+       
        /* optional grid access for subsurf */
        int (*getNumGrids)(DerivedMesh *dm);
        int (*getGridSize)(DerivedMesh *dm);
@@ -255,8 +314,8 @@ struct DerivedMesh {
         *  o Drawing options too complicated to enumerate, look at code.
         */
        void (*drawFacesTex)(DerivedMesh *dm,
-                                                int (*setDrawOptions)(struct MTFace *tface,
-                                                        int has_mcol, int matnr),
+                            int (*setDrawOptions)(struct MTFace *tface,
+                            int has_vcol, int matnr),
                                                int (*compareDrawOptions)(void *userData,
                                                         int cur_index,
                                                         int next_index),
@@ -357,15 +416,16 @@ void DM_init_funcs(DerivedMesh *dm);
  * of vertices, edges and faces (doesn't allocate memory for them, just
  * sets up the custom data layers)
  */
-void DM_init(DerivedMesh *dm, DerivedMeshType type,
-             int numVerts, int numEdges, int numFaces);
+void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges, 
+             int numFaces, int numLoops, int numPolys);
 
 /* utility function to initialise a DerivedMesh for the desired number
  * of vertices, edges and faces, with a layer setup copied from source
  */
 void DM_from_template(DerivedMesh *dm, DerivedMesh *source,
-                                         DerivedMeshType type,
-                                         int numVerts, int numEdges, int numFaces);
+                         DerivedMeshType type,
+                         int numVerts, int numEdges, int numFaces,
+                     int numLoops, int numPolys);
 
 /* utility function to release a DerivedMesh's layers
  * returns 1 if DerivedMesh has to be released by the backend, 0 otherwise
@@ -374,7 +434,7 @@ int DM_release(DerivedMesh *dm);
 
 /* utility function to convert a DerivedMesh to a Mesh
  */
-void DM_to_mesh(DerivedMesh *dm, struct Mesh *me);
+void DM_to_mesh(DerivedMesh *dm, struct Mesh *me, struct Object *ob);
 
 /* utility function to convert a DerivedMesh to a shape key block 
  */
@@ -392,11 +452,15 @@ void DM_set_only_copy(DerivedMesh *dm, CustomDataMask mask);
  * freed, see BKE_customdata.h for the different options
  */
 void DM_add_vert_layer(struct DerivedMesh *dm, int type, int alloctype,
-                                          void *layer);
+                       void *layer);
 void DM_add_edge_layer(struct DerivedMesh *dm, int type, int alloctype,
-                                          void *layer);
-void DM_add_face_layer(struct DerivedMesh *dm, int type, int alloctype,
-                                          void *layer);
+                       void *layer);
+void DM_add_tessface_layer(struct DerivedMesh *dm, int type, int alloctype,
+                           void *layer);
+void DM_add_loop_layer(DerivedMesh *dm, int type, int alloctype,
+                       void *layer);
+void DM_add_poly_layer(struct DerivedMesh *dm, int type, int alloctype,
+                       void *layer);
 
 /* custom data access functions
  * return pointer to data from first layer which matches type
@@ -405,7 +469,7 @@ void DM_add_face_layer(struct DerivedMesh *dm, int type, int alloctype,
  */
 void *DM_get_vert_data(struct DerivedMesh *dm, int index, int type);
 void *DM_get_edge_data(struct DerivedMesh *dm, int index, int type);
-void *DM_get_face_data(struct DerivedMesh *dm, int index, int type);
+void *DM_get_tessface_data(struct DerivedMesh *dm, int index, int type);
 
 /* custom data layer access functions
  * return pointer to first data layer which matches type (a flat array)
@@ -414,7 +478,8 @@ void *DM_get_face_data(struct DerivedMesh *dm, int index, int type);
  */
 void *DM_get_vert_data_layer(struct DerivedMesh *dm, int type);
 void *DM_get_edge_data_layer(struct DerivedMesh *dm, int type);
-void *DM_get_face_data_layer(struct DerivedMesh *dm, int type);
+void *DM_get_tessface_data_layer(struct DerivedMesh *dm, int type);
+void *DM_get_poly_data_layer(struct DerivedMesh *dm, int type);
 
 /* custom data setting functions
  * copy supplied data into first layer of type using layer's copy function
@@ -422,7 +487,7 @@ void *DM_get_face_data_layer(struct DerivedMesh *dm, int type);
  */
 void DM_set_vert_data(struct DerivedMesh *dm, int index, int type, void *data);
 void DM_set_edge_data(struct DerivedMesh *dm, int index, int type, void *data);
-void DM_set_face_data(struct DerivedMesh *dm, int index, int type, void *data);
+void DM_set_tessface_data(struct DerivedMesh *dm, int index, int type, void *data);
 
 /* custom data copy functions
  * copy count elements from source_index in source to dest_index in dest
@@ -432,7 +497,11 @@ void DM_copy_vert_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                                           int source_index, int dest_index, int count);
 void DM_copy_edge_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                                           int source_index, int dest_index, int count);
-void DM_copy_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+void DM_copy_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                       int source_index, int dest_index, int count);
+void DM_copy_loop_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                       int source_index, int dest_index, int count);
+void DM_copy_poly_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                                           int source_index, int dest_index, int count);
 
 /* custom data free functions
@@ -441,7 +510,14 @@ void DM_copy_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
  */
 void DM_free_vert_data(struct DerivedMesh *dm, int index, int count);
 void DM_free_edge_data(struct DerivedMesh *dm, int index, int count);
-void DM_free_face_data(struct DerivedMesh *dm, int index, int count);
+void DM_free_tessface_data(struct DerivedMesh *dm, int index, int count);
+void DM_free_loop_data(struct DerivedMesh *dm, int index, int count);
+void DM_free_poly_data(struct DerivedMesh *dm, int index, int count);
+
+/*sets up mpolys for a DM based on face iterators in source*/
+void DM_DupPolys(DerivedMesh *source, DerivedMesh *target);
+
+void DM_ensure_tessface(DerivedMesh *dm);
 
 /* interpolates vertex data from the vertices indexed by src_indices in the
  * source mesh using the given weights and stores the result in the vertex
@@ -472,12 +548,20 @@ void DM_interp_edge_data(struct DerivedMesh *source, struct DerivedMesh *dest,
  * vert_weights[i] multiplied by weights[i].
  */
 typedef float FaceVertWeight[SUB_ELEMS_FACE][SUB_ELEMS_FACE];
-void DM_interp_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+void DM_interp_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                                                 int *src_indices,
                                                 float *weights, FaceVertWeight *vert_weights,
                                                 int count, int dest_index);
 
-void DM_swap_face_data(struct DerivedMesh *dm, int index, const int *corner_indices);
+void DM_swap_tessface_data(struct DerivedMesh *dm, int index, const int *corner_indices);
+
+void DM_interp_loop_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index);
+
+void DM_interp_poly_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index);
 
 /* Temporary? A function to give a colorband to derivedmesh for vertexcolor ranges */
 void vDM_ColorBand_store(struct ColorBand *coba);
@@ -493,11 +577,15 @@ DerivedMesh *mesh_get_derived_final(struct Scene *scene, struct Object *ob,
 DerivedMesh *mesh_get_derived_deform(struct Scene *scene, struct Object *ob,
                                                                         CustomDataMask dataMask);
 
-DerivedMesh *mesh_create_derived_for_modifier(struct Scene *scene, struct Object *ob, struct ModifierData *md);
+DerivedMesh *mesh_create_derived_for_modifier(struct Scene *scene, struct Object *ob,
+                                                                                         struct ModifierData *md, int build_shapekey_layers);
 
 DerivedMesh *mesh_create_derived_render(struct Scene *scene, struct Object *ob,
                                                                                CustomDataMask dataMask);
 
+DerivedMesh *getEditDerivedBMesh(struct BMEditMesh *em, struct Object *ob,
+                                           float (*vertexCos)[3]);
+
 DerivedMesh *mesh_create_derived_index_render(struct Scene *scene, struct Object *ob, CustomDataMask dataMask, int index);
 
                /* same as above but wont use render settings */
@@ -516,20 +604,21 @@ DerivedMesh *mesh_create_derived_no_virtual(struct Scene *scene, struct Object *
 DerivedMesh *mesh_create_derived_physics(struct Scene *scene, struct Object *ob, float (*vertCos)[3],
                                                                                        CustomDataMask dataMask);
 
-DerivedMesh *editmesh_get_derived(struct EditMesh *em, float (*vertexCos)[3]);
-DerivedMesh *editmesh_get_derived_base(struct Object *, struct EditMesh *em);
-DerivedMesh *editmesh_get_derived_cage(struct Scene *scene, struct Object *, 
-                                                                          struct EditMesh *em, CustomDataMask dataMask);
-DerivedMesh *editmesh_get_derived_cage_and_final(struct Scene *scene, struct Object *, 
-                                                                                                struct EditMesh *em, DerivedMesh **final_r,
+DerivedMesh *editbmesh_get_derived(struct BMEditMesh *em, float (*vertexCos)[3]);
+DerivedMesh *editbmesh_get_derived_base(struct Object *, struct BMEditMesh *em);
+DerivedMesh *editbmesh_get_derived_cage(struct Scene *scene, struct Object *, 
+                                                                          struct BMEditMesh *em, CustomDataMask dataMask);
+DerivedMesh *editbmesh_get_derived_cage_and_final(struct Scene *scene, struct Object *, 
+                                                struct BMEditMesh *em, DerivedMesh **final_r,
                                                                                                 CustomDataMask dataMask);
-float (*editmesh_get_vertex_cos(struct EditMesh *em, int *numVerts_r))[3];
-int editmesh_modifier_is_enabled(struct Scene *scene, struct ModifierData *md, DerivedMesh *dm);
-void makeDerivedMesh(struct Scene *scene, struct Object *ob, struct EditMesh *em, CustomDataMask dataMask);
+float (*editbmesh_get_vertex_cos(struct BMEditMesh *em, int *numVerts_r))[3];
+int editbmesh_modifier_is_enabled(struct Scene *scene, struct ModifierData *md, DerivedMesh *dm);
+void makeDerivedMesh(struct Scene *scene, struct Object *ob, struct BMEditMesh *em, 
+       CustomDataMask dataMask, int build_shapekey_layers);
 
 /* returns an array of deform matrices for crazyspace correction, and the
    number of modifiers left */
-int editmesh_get_first_deform_matrices(struct Scene *, struct Object *, struct EditMesh *em,
+int editbmesh_get_first_deform_matrices(struct Scene *, struct Object *, struct BMEditMesh *em,
                                                                           float (**deformmats)[3][3], float (**deformcos)[3]);
 
 /* returns an array of deform matrices for crazyspace correction when sculpting,
@@ -574,16 +663,6 @@ typedef struct DMVertexAttribs {
        int tottface, totmcol, tottang, totorco;
 } DMVertexAttribs;
 
-/* should be local, bmesh replaces this */
-typedef struct {
-       DerivedMesh dm;
-
-       struct EditMesh *em;
-       float (*vertexCos)[3];
-       float (*vertexNos)[3];
-       float (*faceNos)[3];
-} EditMeshDerivedMesh;
-
 void DM_vertex_attributes_from_gpu(DerivedMesh *dm,
        struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
 
index 50fef032b75ff3271eadb0c01c0c8db07f0ba4d8..48f1df2bd73b6c9727e36f3a3218bee5499a4588 100644 (file)
@@ -90,6 +90,7 @@ extern void BKE_reset_undo(void);
 extern char *BKE_undo_menu_string(void);
 extern void BKE_undo_number(struct bContext *C, int nr);
 extern const char *BKE_undo_get_name(int nr, int *active);
+void BKE_undo_save(char *fname);
 extern void BKE_undo_save_quit(void);
 extern struct Main *BKE_undo_get_main(struct Scene **scene);
 
index c8df6c4f455e6a939cb913379f8bd06c291eca46..85ecaf0bb275842e89c7d0d9644ee7c4b46592fb 100644 (file)
@@ -51,6 +51,7 @@ struct BME_Edge;
 struct BME_Poly;
 struct BME_Loop;
 
+/*NOTE: this is the bmesh 1.0 code.  it's completely outdated.*/
 
 /*Notes on further structure Cleanup:
        -Remove the tflags, they belong in custom data layers
@@ -208,6 +209,10 @@ int BME_loop_reverse(struct BME_Mesh *bm, struct BME_Poly *f);
 #define BME_BEVEL_RUNNING              (1<<9)
 #define BME_BEVEL_RES                  (1<<10)
 
+#define BME_BEVEL_EVEN                 (1<<11) /* this is a new setting not related to old (trunk bmesh bevel code) but adding
+                                         * here because they are mixed - campbell */
+#define BME_BEVEL_DIST                 (1<<12) /* same as above */
+
 typedef struct BME_TransData {
        BME_Mesh *bm; /* the bmesh the vert belongs to */
        BME_Vert *v;  /* pointer to the vert this tdata applies to */
index c71c86e110d97ba7cb9a908221353aaecf29decf..3f421331f0a2718750a591e067bd047f7be09c80 100644 (file)
 #include "BKE_DerivedMesh.h"
 
 struct DerivedMesh;
+struct BMEditMesh;
 struct EditMesh;
 struct Mesh;
 struct Object;
 
 /* creates a new CDDerivedMesh */
-struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces);
+struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces,
+                             int numLoops, int numPolys);
+
+/*tests if a given DerivedMesh is a CDDM*/
+int CDDM_Check(struct DerivedMesh *dm);
 
 /* creates a CDDerivedMesh from the given Mesh, this will reference the
    original data in Mesh, but it is safe to apply vertex coordinates or
@@ -51,8 +56,11 @@ struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces);
    data to not overwrite the original */
 struct DerivedMesh *CDDM_from_mesh(struct Mesh *mesh, struct Object *ob);
 
-/* creates a CDDerivedMesh from the given EditMesh */
-struct DerivedMesh *CDDM_from_editmesh(struct EditMesh *em, struct Mesh *me);
+/* creates a CDDerivedMesh from the given BMEditMesh */
+DerivedMesh *CDDM_from_BMEditMesh(struct BMEditMesh *em, struct Mesh *me, int use_mdisps, int use_tessface);
+
+/* merge verts  */
+DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap);
 
 /* creates a CDDerivedMesh from the given curve object */
 struct DerivedMesh *CDDM_from_curve(struct Object *ob);
@@ -61,17 +69,28 @@ struct DerivedMesh *CDDM_from_curve(struct Object *ob);
 /* useful for OrcoDM creation for curves with constructive modifiers */
 DerivedMesh *CDDM_from_curve_customDB(struct Object *ob, struct ListBase *dispbase);
 
+struct BMEditMesh *CDDM_To_BMesh(struct Object *ob, struct DerivedMesh *dm,
+                                 struct BMEditMesh *existing, int do_tesselate);
+
+
 /* Copies the given DerivedMesh with verts, faces & edges stored as
  * custom element data.
  */
 struct DerivedMesh *CDDM_copy(struct DerivedMesh *dm);
+struct DerivedMesh *CDDM_copy_from_tessface(struct DerivedMesh *dm);
 
 /* creates a CDDerivedMesh with the same layer stack configuration as the
  * given DerivedMesh and containing the requested numbers of elements.
  * elements are initialised to all zeros
  */
 struct DerivedMesh *CDDM_from_template(struct DerivedMesh *source,
-                                                                 int numVerts, int numEdges, int numFaces);
+                                  int numVerts, int numEdges, int numFaces,
+                                  int numLoops, int numPolys);
+
+/*converts mfaces to mpolys.  note things may break if there are not valid
+ *medges surrounding each mface.
+ */
+void CDDM_tessfaces_to_faces(struct DerivedMesh *dm);
 
 /* applies vertex coordinates or normals to a CDDerivedMesh. if the MVert
  * layer is a referenced layer, it will be duplicate to not overwrite the
@@ -82,19 +101,31 @@ void CDDM_apply_vert_normals(struct DerivedMesh *cddm, short (*vertNormals)[3]);
 
 /* recalculates vertex and face normals for a CDDerivedMesh
  */
+void CDDM_calc_normals_mapping(struct DerivedMesh *dm);
 void CDDM_calc_normals(struct DerivedMesh *dm);
+void CDDM_calc_normals_tessface(struct DerivedMesh *dm);
 
 /* calculates edges for a CDDerivedMesh (from face data)
  * this completely replaces the current edge data in the DerivedMesh
+ * builds edges from the tesselated face data.
  */
+void CDDM_calc_edges_tessface(struct DerivedMesh *dm);
+
+/* same as CDDM_calc_edges_tessface only makes edges from ngon faces instead of tesselation
+   faces*/
 void CDDM_calc_edges(struct DerivedMesh *dm);
 
+/* reconstitute face triangulation */
+void CDDM_recalc_tesselation(struct DerivedMesh *dm);
+void CDDM_recalc_tesselation_ex(struct DerivedMesh *dm, const int do_face_nor_cpy);
+
 /* lowers the number of vertices/edges/faces in a CDDerivedMesh
  * the layer data stays the same size
  */
 void CDDM_lower_num_verts(struct DerivedMesh *dm, int numVerts);
 void CDDM_lower_num_edges(struct DerivedMesh *dm, int numEdges);
-void CDDM_lower_num_faces(struct DerivedMesh *dm, int numFaces);
+void CDDM_lower_num_polys(struct DerivedMesh *dm, int numPolys);
+void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces);
 
 /* vertex/edge/face access functions
  * should always succeed if index is within bounds
@@ -102,7 +133,9 @@ void CDDM_lower_num_faces(struct DerivedMesh *dm, int numFaces);
  */
 struct MVert *CDDM_get_vert(struct DerivedMesh *dm, int index);
 struct MEdge *CDDM_get_edge(struct DerivedMesh *dm, int index);
-struct MFace *CDDM_get_face(struct DerivedMesh *dm, int index);
+struct MFace *CDDM_get_tessface(struct DerivedMesh *dm, int index);
+struct MLoop *CDDM_get_loop(struct DerivedMesh *dm, int index);
+struct MPoly *CDDM_get_face(struct DerivedMesh *dm, int index);
 
 /* vertex/edge/face array access functions - return the array holding the
  * desired data
@@ -111,6 +144,18 @@ struct MFace *CDDM_get_face(struct DerivedMesh *dm, int index);
  */
 struct MVert *CDDM_get_verts(struct DerivedMesh *dm);
 struct MEdge *CDDM_get_edges(struct DerivedMesh *dm);
-struct MFace *CDDM_get_faces(struct DerivedMesh *dm);
+struct MFace *CDDM_get_tessfaces(struct DerivedMesh *dm);
+struct MLoop *CDDM_get_loops(struct DerivedMesh *dm);
+struct MPoly *CDDM_get_polys(struct DerivedMesh *dm);
+
+/*Assigns news m*** layers to the cddm.  Note that you must handle
+  freeing the old ones yourself.  Also you must ensure dm->num****Data
+  is correct.*/
+void CDDM_set_mvert(struct DerivedMesh *dm, struct MVert *mvert);
+void CDDM_set_medge(struct DerivedMesh *dm, struct MEdge *medge);
+void CDDM_set_mface(struct DerivedMesh *dm, struct MFace *mface);
+void CDDM_set_mloop(struct DerivedMesh *dm, struct MLoop *mloop);
+void CDDM_set_mpoly(struct DerivedMesh *dm, struct MPoly *mpoly);
+
 #endif
 
index 7ad25ac7e7974352dc5ddf77e24912d7f7fac3b6..b69ad4d1b8b5dadd297bf3135a9dbe4c59ef9b57 100644 (file)
@@ -40,11 +40,15 @@ extern "C" {
 
 #include "../blenloader/BLO_sys_types.h" /* XXX, should have a more generic include for this */
 
+struct BMesh;
 struct ID;
 struct CustomData;
 struct CustomDataLayer;
 typedef uint64_t CustomDataMask;
 
+/*a data type large enough to hold 1 element from any customdata layer type*/
+typedef struct {unsigned char data[64];} CDBlockBytes;
+
 extern const CustomDataMask CD_MASK_BAREMESH;
 extern const CustomDataMask CD_MASK_MESH;
 extern const CustomDataMask CD_MASK_EDITMESH;
@@ -69,6 +73,25 @@ extern const CustomDataMask CD_MASK_FACECORNERS;
 
 #define CD_TYPE_AS_MASK(_type) (CustomDataMask)((CustomDataMask)1 << (CustomDataMask)(_type))
 
+/* Checks if the layer at physical offset layern (in data->layers) support math
+ * the below operations.
+ */
+int CustomData_layer_has_math(struct CustomData *data, int layern);
+
+/*copies the "value" (e.g. mloopuv uv or mloopcol colors) from one block to
+  another, while not overwriting anything else (e.g. flags).  probably only
+  implemented for mloopuv/mloopcol, for now.*/
+void CustomData_data_copy_value(int type, void *source, void *dest);
+
+/* compares if data1 is equal to data2.  type is a valid CustomData type
+ * enum (e.g. CD_MLOOPUV). the layer type's equal function is used to compare
+ * the data, if it exists, otherwise memcmp is used.*/
+int CustomData_data_equals(int type, void *data1, void *data2);
+void CustomData_data_initminmax(int type, void *min, void *max);
+void CustomData_data_dominmax(int type, void *data, void *min, void *max);
+void CustomData_data_multiply(int type, void *data, float fac);
+void CustomData_data_add(int type, void *data1, void *data2);
+
 /* initialises a CustomData object with the same layer setup as source.
  * mask is a bitfield where (mask & (1 << (layer type))) indicates
  * if a layer should be copied or not. alloctype must be one of the above. */
@@ -83,6 +106,12 @@ void CustomData_update_typemap(struct CustomData *data);
 void CustomData_merge(const struct CustomData *source, struct CustomData *dest,
                                          CustomDataMask mask, int alloctype, int totelem);
 
+/*bmesh version of CustomData_merge; merges the layouts of source and dest,
+  then goes through the mesh and makes sure all the customdata blocks are
+  consistent with the new layout.*/
+void CustomData_bmesh_merge(struct CustomData *source, struct CustomData *dest, 
+                            int mask, int alloctype, struct BMesh *bm, int type);
+
 /* frees data associated with a CustomData object (doesn't free the object
  * itself, though)
  */
@@ -308,8 +337,9 @@ int CustomData_verify_versions(struct CustomData *data, int index);
 
 /*BMesh specific customdata stuff*/
 void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata,
-                             struct CustomData *ldata);
+                             struct CustomData *ldata, int totloop, int totpoly);
 void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata, int total);
+void CustomData_bmesh_update_active_layers(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata);
 void CustomData_bmesh_init_pool(struct CustomData *data, int allocsize);
 
 /* External file storage */
index c055bb2004b34b4586b8d98418ab89969b14c5f1..529d0680cf9389a93eabbee27756fefc57577f78 100644 (file)
@@ -48,8 +48,10 @@ extern "C" {
 #endif
 
 void free_key(struct Key *sc); 
+void free_key_nolib(struct Key *key);
 struct Key *add_key(struct ID *id);
 struct Key *copy_key(struct Key *key);
+struct Key *copy_key_nolib(struct Key *key);
 void make_local_key(struct Key *key);
 void sort_keys(struct Key *key);
 
index 30a4b154e31a8148dea63f0fb3ae594499a66932..b1cb62d4d5ab7a068f0cfcf5237db8ea5b75b5a8 100644 (file)
@@ -36,7 +36,8 @@
 struct BoundBox;
 struct DispList;
 struct ListBase;
-struct EditMesh;
+struct BMEditMesh;
+struct BMesh;
 struct Mesh;
 struct MPoly;
 struct MLoop;
@@ -60,19 +61,50 @@ struct UvElement;
 extern "C" {
 #endif
 
-struct EditMesh *BKE_mesh_get_editmesh(struct Mesh *me);
-void BKE_mesh_end_editmesh(struct Mesh *me, struct EditMesh *em);
+struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
+
+/*
+ * this function recreates a tesselation.
+ * returns number of tesselation faces.
+ *
+ * use_poly_origindex sets whether or not the tesselation faces' origindex
+ * layer should point to original poly indices or real poly indices.
+ *
+ * use_face_origindex sets the tesselation faces' origindex layer
+ * to point to the tesselation faces themselves, not the polys.
+ *
+ * if both of the above are 0, it'll use the indices of the mpolys of the MPoly
+ * data in pdata, and ignore the origindex layer altogether.
+ */
+int mesh_recalcTesselation(struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
+                           struct MVert *mvert,
+                           int totface, int totloop, int totpoly,
+                           const int do_face_normals);
 
 /* for forwards compat only quad->tri polys to mface, skip ngons.
  */
 int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
        struct CustomData *pdata, int totface, int totloop, int totpoly);
 
+/*calculates a face normal.*/
+void mesh_calc_poly_normal(struct MPoly *mpoly, struct MLoop *loopstart, 
+                           struct MVert *mvarray, float no[3]);
+
+void mesh_calc_poly_normal_coords(struct MPoly *mpoly, struct MLoop *loopstart,
+                                  const float (*vertex_coords)[3], float no[3]);
+
+void mesh_calc_poly_center(struct MPoly *mpoly, struct MLoop *loopstart,
+                           struct MVert *mvarray, float cent[3]);
+
+float mesh_calc_poly_area(struct MPoly *mpoly, struct MLoop *loopstart,
+                          struct MVert *mvarray, float polynormal[3]);
+
 void unlink_mesh(struct Mesh *me);
-void free_mesh(struct Mesh *me);
+void free_mesh(struct Mesh *me, int unlink);
 struct Mesh *add_mesh(const char *name);
 struct Mesh *copy_mesh(struct Mesh *me);
-void mesh_update_customdata_pointers(struct Mesh *me);
+void mesh_update_customdata_pointers(struct Mesh *me, const short do_ensure_tess_cd);
+
 void make_local_mesh(struct Mesh *me);
 void boundbox_mesh(struct Mesh *me, float *loc, float *size);
 void tex_space_mesh(struct Mesh *me);
@@ -82,17 +114,26 @@ int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex,
 struct Mesh *get_mesh(struct Object *ob);
 void set_mesh(struct Object *ob, struct Mesh *me);
 void mball_to_mesh(struct ListBase *lb, struct Mesh *me);
-int nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *_totvert,
-       struct MEdge **alledge, int *_totedge, struct MFace **allface, int *_totface);
-int nurbs_to_mdata_customdb(struct Object *ob, struct ListBase *dispbase,
-       struct MVert **allvert, int *_totvert, struct MEdge **alledge, int *_totedge,
-       struct MFace **allface, int *_totface);
+int nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert,
+       struct MEdge **alledge, int *totedge, struct MFace **allface, struct MLoop **allloop, struct MPoly **allpoly, 
+       int *totface, int *totloop, int *totpoly);
+int nurbs_to_mdata_customdb(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert,
+       struct MEdge **alledge, int *_totedge, struct MFace **allface, struct MLoop **allloop, struct MPoly **allpoly, 
+       int *_totface, int *_totloop, int *_totpoly);
 void nurbs_to_mesh(struct Object *ob);
 void mesh_to_curve(struct Scene *scene, struct Object *ob);
 void free_dverts(struct MDeformVert *dvert, int totvert);
 void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert); /* __NLA */
 void mesh_delete_material_index(struct Mesh *me, short index);
 void mesh_set_smooth_flag(struct Object *meshOb, int enableSmooth);
+void convert_mfaces_to_mpolys(struct Mesh *mesh);
+void mesh_calc_normals_tessface(struct MVert *mverts, int numVerts,struct  MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
+
+/*used for unit testing; compares two meshes, checking only
+  differences we care about.  should be usable with leaf's
+  testing framework I get RNA work done, will use hackish
+  testing code for now.*/
+const char *mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh);
 
 struct BoundBox *mesh_get_bb(struct Object *ob);
 void mesh_get_texspace(struct Mesh *me, float *loc_r, float *rot_r, float *size_r);
@@ -106,7 +147,21 @@ void mesh_strip_loose_edges(struct Mesh *me);
        /* Calculate vertex and face normals, face normals are returned in *faceNors_r if non-NULL
         * and vertex normals are stored in actual mverts.
         */
-void mesh_calc_normals(struct MVert *mverts, int numVerts, struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
+void mesh_calc_normals_mapping(
+        struct MVert *mverts, int numVerts,
+        struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
+        struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]);
+       /* extended version of 'mesh_calc_normals' with option not to calc vertex normals */
+void mesh_calc_normals_mapping_ex(
+        struct MVert *mverts, int numVerts,
+        struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
+        struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
+        const short only_face_normals);
+
+void mesh_calc_normals(
+        struct MVert *mverts, int numVerts,
+        struct MLoop *mloop, struct MPoly *mpolys,
+        int numLoops, int numPolys, float (*polyNors_r)[3]);
 
        /* Return a newly MEM_malloc'd array of all the mesh vertex locations
         * (_numVerts_r_ may be NULL) */
@@ -146,7 +201,7 @@ typedef struct UvElement {
        /* Next UvElement corresponding to same vertex */
        struct UvElement *next;
        /* Face the element belongs to */
-       struct EditFace *face;
+       struct BMFace *face;
        /* Index in the editFace of the uv */
        unsigned char tfindex;
        /* Whether this element is the first of coincident elements */
@@ -161,8 +216,7 @@ typedef struct UvElement {
  * to make that many islands, he can bite me :p */
 #define INVALID_ISLAND 0xFFFF
 
-
-UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned int totface, unsigned int totvert, int selected, float *limit);
+UvVertMap *make_uv_vert_map(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, int selected, float *limit);
 UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v);
 void free_uv_vert_map(UvVertMap *vmap);
 
index f72bc5b93ec5dd0a860a94f01b11925ba3e65aa3..947e630273eecdd518abff72246dc5194bb95fcb 100644 (file)
@@ -45,6 +45,7 @@ struct ListBase;
 struct LinkNode;
 struct bArmature;
 struct ModifierData;
+struct BMEditMesh;
 
 typedef enum {
        /* Should not be used, only for None modifier type */
@@ -154,13 +155,13 @@ typedef struct ModifierTypeInfo {
         */
        void (*deformVertsEM)(
                                struct ModifierData *md, struct Object *ob,
-                               struct EditMesh *editData, struct DerivedMesh *derivedData,
+                               struct BMEditMesh *editData, struct DerivedMesh *derivedData,
                                float (*vertexCos)[3], int numVerts);
 
        /* Set deform matrix per vertex for crazyspace correction */
        void (*deformMatricesEM)(
                                struct ModifierData *md, struct Object *ob,
-                               struct EditMesh *editData, struct DerivedMesh *derivedData,
+                               struct BMEditMesh *editData, struct DerivedMesh *derivedData,
                                float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
 
        /********************* Non-deform modifier functions *********************/
@@ -198,7 +199,7 @@ typedef struct ModifierTypeInfo {
         */
        struct DerivedMesh *(*applyModifierEM)(
                                                                struct ModifierData *md, struct Object *ob,
-                                                               struct EditMesh *editData,
+                                                               struct BMEditMesh *editData,
                                                                struct DerivedMesh *derivedData);
 
 
index 4f1262cd52357770a02936ccec07f879638e0538..ce6e12345e80552506a447bc70797573dad60f60 100644 (file)
@@ -71,6 +71,14 @@ int multiresModifier_reshapeFromDeformMod(struct Scene *scene, struct MultiresMo
 
 void multires_stitch_grids(struct Object *);
 
+/*switch mdisp data in dm between tangent and object space*/
+enum {
+       MULTIRES_SPACE_TANGENT,
+       MULTIRES_SPACE_OBJECT,
+       MULTIRES_SPACE_ABSOLUTE,
+};
+void multires_set_space(struct DerivedMesh *dm, struct Object *ob, int from, int to);
+
 /* Related to the old multires */
 void multires_free(struct Multires *mr);
 void multires_load_old(struct Object *ob, struct Mesh *me);
index dcbd045f62d14b6b9c34f7fae2c88e6766267d51..5c878102bc2e67af0c462e6291faae11be0d0f22 100644 (file)
@@ -46,6 +46,10 @@ struct _CCGEdge;
 struct _CCGFace;
 struct _CCGSubsurf;
 struct _CCGVert;
+struct EdgeHash;
+struct PBVH;
+struct DMGridData;
+struct DMGridAdjacency;
 
 /**************************** External *****************************/
 
@@ -74,6 +78,8 @@ typedef struct CCGDerivedMesh {
        short *edgeFlags;
        char *faceFlags;
 
+       int *reverseFaceMap;
+
        struct PBVH *pbvh;
        struct ListBase *fmap;
        struct IndexNode *fmap_mem;
@@ -95,6 +101,8 @@ typedef struct CCGDerivedMesh {
 
                void (*update)(DerivedMesh*);
        } multires;
+
+       struct EdgeHash *ehash;
 } CCGDerivedMesh;
 
 #endif
diff --git a/source/blender/blenkernel/BKE_tessmesh.h b/source/blender/blenkernel/BKE_tessmesh.h
new file mode 100644 (file)
index 0000000..67afb86
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef _BKE_TESSMESH_H
+#define _BKE_TESSMESH_H
+
+#include "bmesh.h"
+
+struct BMesh;
+struct BMLoop;
+struct BMFace;
+struct Mesh;
+struct DerivedMesh;
+
+/*
+ok: the EDBM module is for editmode bmesh stuff.  in contrast, the 
+    BMEdit module is for code shared with blenkernel that concerns
+    the BMEditMesh structure.
+*/
+
+/*this structure replaces EditMesh.
+  through this, you get access to both the edit bmesh,
+  it's tesselation, and various stuff that doesn't belong in the BMesh
+  struct itself.
+  
+  the entire derivedmesh and modifier system works with this structure,
+  and not BMesh.  Mesh->edit_bmesh stores a pointer to this structure.*/
+typedef struct BMEditMesh {
+       struct BMesh *bm;
+
+       /*this is for undoing failed operations*/
+       struct BMEditMesh *emcopy;
+       int emcopyusers;
+       
+       /*we store tesselations as triplets of three loops,
+         which each define a triangle.*/
+       struct BMLoop *(*looptris)[3];
+       int tottri;
+
+       /*derivedmesh stuff*/
+       struct DerivedMesh *derivedFinal, *derivedCage;
+       int lastDataMask;
+       
+       /*retopo data pointer*/
+       struct RetopoPaintData *retopo_paint_data;
+
+       /*index tables, to map indices to elements via
+         EDBM_init_index_arrays and associated functions.  don't
+         touch this or read it directly.*/
+       struct BMVert **vert_index;
+       struct BMEdge **edge_index;
+       struct BMFace **face_index;
+
+       /*selection mode*/
+       short selectmode;
+       short mat_nr;
+
+       /*Mesh structure this editmesh came from, if it came from one*/
+       struct Mesh *me;
+       struct Object *ob;
+
+       /*temp variables for x-mirror editing*/
+       int mirror_cdlayer; /* -1 is invalid */
+       int mirr_free_arrays;
+} BMEditMesh;
+
+/* undo triggers editmesh tessface update, this is odd but works OK.
+ * BMESH_TODO, look into having the update elsewhere. */
+#define BMESH_EM_UNDO_RECALC_TESSFACE_WORKAROUND
+
+void BMEdit_RecalcTesselation(BMEditMesh *tm);
+BMEditMesh *BMEdit_Create(BMesh *bm, int do_tesselate);
+BMEditMesh *BMEdit_Copy(BMEditMesh *tm);
+void BMEdit_Free(BMEditMesh *em);
+void BMEdit_UpdateLinkedCustomData(BMEditMesh *em);
+
+#endif /* _BKE_TESSMESH_H */
index 42e6f1d8fb21113f6ee3c338ed1efbfb219015f3..dc93885c05c9d0dd57675f5a54eb9f20cf239c12 100644 (file)
@@ -34,6 +34,7 @@ set(INC
        ../imbuf
        ../makesdna
        ../makesrna
+       ../bmesh
        ../modifiers
        ../nodes
        ../render/extern/include
@@ -114,6 +115,7 @@ set(SRC
        intern/mesh.c
        intern/mesh_validate.c
        intern/modifier.c
+       intern/modifiers_bmesh.c
        intern/movieclip.c
        intern/multires.c
        intern/nla.c
@@ -227,6 +229,7 @@ set(SRC
        BKE_speaker.h
        BKE_subsurf.h
        BKE_suggestions.h
+       BKE_tessmesh.h
        BKE_text.h
        BKE_texture.h
        BKE_tracking.h
index 62a8aa8362f1cf95456425705baa58c6863f754d..d949f0c73db34dbd3236164b7ff81365b2291bdd 100644 (file)
@@ -12,6 +12,7 @@ incs += ' #/intern/iksolver/extern ../blenloader'
 incs += ' #/extern/bullet2/src'
 incs += ' #/intern/opennl/extern #/intern/bsp/extern'
 incs += ' ../gpu #/extern/glew/include'
+incs += ' ../bmesh'
 incs += ' #/intern/smoke/extern'
 incs += ' #/intern/mikktspace'
 incs += ' #/intern/audaspace/intern'
index bb909dcbbddd182f1462c4afb691095bd5816f23..af0e5c93aba10266241bfdc6b72c924b71c26c03 100644 (file)
@@ -1,4 +1,5 @@
-/*
+#if 0
+/**
  * BME_customdata.c    jan 2007
  *
  *     Custom Data functions for Bmesh
@@ -83,7 +84,7 @@ void BME_CD_Create(BME_CustomData *data, BME_CustomDataInit *init, int initalloc
        if(data->totlayer){
                /*alloc memory*/
                data->layers = MEM_callocN(sizeof(BME_CustomDataLayer)*data->totlayer, "BMesh Custom Data Layers");
-               data->pool = BLI_mempool_create(data->totsize, initalloc, initalloc, FALSE, FALSE);
+               data->pool = BLI_mempool_create(data->totsize, initalloc, initalloc, TRUE);
                /*initialize layer data*/
                for(i=0; i < BME_CD_NUMTYPES; i++){
                        if(init->layout[i]){
@@ -196,3 +197,4 @@ void BME_CD_set_default(BME_CustomData *data, void **block)
                        typeInfo->set_default((char*)*block + offset, 1);
        }
 }
+#endif
index ce1da6132cdfcbfbbb801add91228cb39f9a8a9b..65a8ee8e0bb1395c1bfc8d65f911568b64494a40 100644 (file)
@@ -1,4 +1,5 @@
-/*
+#if 0
+/**
  * BME_mesh.c    jan 2007
  *
  *     BMesh mesh level functions.
@@ -267,7 +268,7 @@ BME_Mesh *BME_editmesh_to_bmesh(EditMesh *em) {
        CustomData_copy(&em->fdata, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
 
        /*copy face corner data*/
-       CustomData_to_bmeshpoly(&em->fdata, &bm->pdata, &bm->ldata);
+       CustomData_to_bmeshpoly(&em->fdata, &bm->pdata, &bm->ldata, 0, 0);
        /*initialize memory pools*/
        CustomData_bmesh_init_pool(&bm->vdata, allocsize[0]);
        CustomData_bmesh_init_pool(&bm->edata, allocsize[1]);
@@ -462,7 +463,7 @@ BME_Mesh *BME_derivedmesh_to_bmesh(DerivedMesh *dm)
        CustomData_copy(&dm->faceData, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
 
        /*copy face corner data*/
-       CustomData_to_bmeshpoly(&dm->faceData, &bm->pdata, &bm->ldata);
+       CustomData_to_bmeshpoly(&dm->faceData, &bm->pdata, &bm->ldata, 0, 0);
        /*initialize memory pools*/
        CustomData_bmesh_init_pool(&bm->vdata, allocsize[0]);
        CustomData_bmesh_init_pool(&bm->edata, allocsize[1]);
@@ -474,10 +475,10 @@ BME_Mesh *BME_derivedmesh_to_bmesh(DerivedMesh *dm)
 
        totvert = dm->getNumVerts(dm);
        totedge = dm->getNumEdges(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
        mvert = dm->getVertArray(dm);
        medge = dm->getEdgeArray(dm);
-       mface = dm->getFaceArray(dm);
+       mface = dm->getTessFaceArray(dm);
 
        vert_array = MEM_mallocN(sizeof(*vert_array)*totvert,"BME_derivedmesh_to_bmesh BME_Vert* array");
 
@@ -574,7 +575,8 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
        }
        
        /*convert back to mesh*/
-       result = CDDM_from_template(dm,totvert,totedge,totface);
+       /*BMESH_TODO this should add in mloops and mpolys as well*/
+       result = CDDM_from_template(dm,totvert,totedge,totface, 0, 0);
        CustomData_merge(&bm->vdata, &result->vertData, CD_MASK_BMESH, CD_CALLOC, totvert);
        CustomData_merge(&bm->edata, &result->edgeData, CD_MASK_BMESH, CD_CALLOC, totedge);
        CustomData_merge(&bm->pdata, &result->faceData, CD_MASK_BMESH, CD_CALLOC, totface);
@@ -617,7 +619,7 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
                }
        }
        if(totface){
-               mface = CDDM_get_faces(result);
+               mface = CDDM_get_tessfaces(result);
                origindex = result->getFaceDataArray(result, CD_ORIGINDEX);
                /*make faces*/
                for(i=0,f=bm->polys.first;f;f=f->next){
@@ -646,3 +648,4 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
        BLI_edgehash_free(edge_hash, NULL);
        return result;
 }
+#endif
index 25970dd8d91287be3f936df36f5e3341ff062922..215493fb6cf9349937e6da926a96b59b4e5c6035 100644 (file)
@@ -1,4 +1,5 @@
-/*
+#if 0
+/**
  * BME_eulers.c    jan 2007
  *
  *     BMesh Euler construction API.
@@ -131,13 +132,13 @@ BME_Edge *BME_ME(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2){
        
        #ifndef BME_FASTEULER
        /*count valance of v1*/
-       if(v1->edge){ 
-               d1 = BME_disk_getpointer(v1->edge,v1);
+       if(v1->e){ 
+               d1 = BME_disk_getpointer(v1->e,v1);
                if(d1) valance1 = BME_cycle_length(d1);
                else BME_error();
        }
-       if(v2->edge){
-               d2 = BME_disk_getpointer(v2->edge,v2);
+       if(v2->e){
+               d2 = BME_disk_getpointer(v2->e,v2);
                if(d2) valance2 = BME_cycle_length(d2);
                else BME_error();
        }
@@ -205,7 +206,7 @@ BME_Poly *BME_MF(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge **elist, int
                elist[i]->eflag1 |= MF_CANDIDATE;
                
                /*if elist[i] has a loop, count its radial length*/
-               if(elist[i]->loop) elist[i]->eflag2 = BME_cycle_length(&(elist[i]->loop->radial));
+               if(elist[i]->loop) elist[i]->eflag2 = BME_cycle_length(&(elist[i]->l->radial));
                else elist[i]->eflag2 = 0;
        }
        
@@ -275,8 +276,8 @@ BME_Poly *BME_MF(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge **elist, int
                for(i=0;i<len;i++){
                        curvert = vlist[i];
                        l = BME_create_loop(bm,curvert,NULL,f,NULL);
-                       if(!(f->loopbase)) f->loopbase = l;
-                       BME_cycle_append(f->loopbase, l);
+                       if(!(f->loopbase)) f->lbase = l;
+                       BME_cycle_append(f->lbase, l);
                }
                
                /*take care of edge pointers and radial cycle*/
@@ -300,7 +301,7 @@ BME_Poly *BME_MF(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge **elist, int
                f->len = len;
                
                /*Validation Loop cycle*/
-               edok = BME_cycle_validate(len, f->loopbase);
+               edok = BME_cycle_validate(len, f->lbase);
                if(!edok) BME_error();
                for(i=0, l = f->loopbase; i<len; i++, l=l->next){
                        /*validate loop vert pointers*/
@@ -328,7 +329,7 @@ BME_Poly *BME_MF(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge **elist, int
  */
 
 int BME_KV(BME_Mesh *bm, BME_Vert *v){
-       if(v->edge == NULL){ 
+       if(v->e == NULL){ 
                BLI_remlink(&(bm->verts), v);
                BME_free_vert(bm,v);
                return 1;
@@ -351,7 +352,7 @@ int BME_KE(BME_Mesh *bm, BME_Edge *e){
        int edok;
        
        /*Make sure that no faces!*/
-       if(e->loop == NULL){
+       if(e->l == NULL){
                BME_disk_remove_edge(e, e->v1);
                BME_disk_remove_edge(e, e->v2);
                
@@ -387,14 +388,14 @@ int BME_KF(BME_Mesh *bm, BME_Poly *bply){
        
        /*add validation to make sure that radial cycle is cleaned up ok*/
        /*deal with radial cycle first*/
-       len = BME_cycle_length(bply->loopbase);
+       len = BME_cycle_length(bply->lbase);
        for(i=0, curloop=bply->loopbase; i < len; i++, curloop = curloop->next) 
                BME_radial_remove_loop(curloop, curloop->e);
        
        /*now deallocate the editloops*/
        for(i=0; i < len; i++){
-               newbase = bply->loopbase->next;
-               oldbase = bply->loopbase;
+               newbase = bply->lbase->next;
+               oldbase = bply->lbase;
                BME_cycle_remove(oldbase, oldbase);
                BME_free_loop(bm, oldbase);
                bply->loopbase = newbase;
@@ -454,24 +455,24 @@ BME_Vert *BME_SEMV(BME_Mesh *bm, BME_Vert *tv, BME_Edge *e, BME_Edge **re){
        /*add ne to tv's disk cycle*/
        BME_disk_append_edge(ne, tv);
        /*verify disk cycles*/
-       diskbase = BME_disk_getpointer(ov->edge,ov);
+       diskbase = BME_disk_getpointer(ov->e,ov);
        edok = BME_cycle_validate(valance1, diskbase);
        if(!edok) BME_error();
-       diskbase = BME_disk_getpointer(tv->edge,tv);
+       diskbase = BME_disk_getpointer(tv->e,tv);
        edok = BME_cycle_validate(valance2, diskbase);
        if(!edok) BME_error();
-       diskbase = BME_disk_getpointer(nv->edge,nv);
+       diskbase = BME_disk_getpointer(nv->e,nv);
        edok = BME_cycle_validate(2, diskbase);
        if(!edok) BME_error();
        
        /*Split the radial cycle if present*/
-       if(e->loop){
+       if(e->l){
                BME_Loop *nl,*l;
                BME_CycleNode *radEBase=NULL, *radNEBase=NULL;
-               int radlen = BME_cycle_length(&(e->loop->radial));
+               int radlen = BME_cycle_length(&(e->l->radial));
                /*Take the next loop. Remove it from radial. Split it. Append to appropriate radials.*/
-               while(e->loop){
-                       l=e->loop;
+               while(e->l){
+                       l=e->l;
                        l->f->len++;
                        BME_radial_remove_loop(l,e);
                        
@@ -524,17 +525,17 @@ BME_Vert *BME_SEMV(BME_Mesh *bm, BME_Vert *tv, BME_Edge *e, BME_Edge **re){
                                        
                }
                
-               e->loop = radEBase->data;
-               ne->loop = radNEBase->data;
+               e->l = radEBase->data;
+               ne->l = radNEBase->data;
                
                /*verify length of radial cycle*/
-               edok = BME_cycle_validate(radlen,&(e->loop->radial));
+               edok = BME_cycle_validate(radlen,&(e->l->radial));
                if(!edok) BME_error();
-               edok = BME_cycle_validate(radlen,&(ne->loop->radial));
+               edok = BME_cycle_validate(radlen,&(ne->l->radial));
                if(!edok) BME_error();
                
                /*verify loop->v and loop->next->v pointers for e*/
-               for(i=0,l=e->loop; i < radlen; i++, l = l->radial.next->data){
+               for(i=0,l=e->l; i < radlen; i++, l = l->radial_next){
                        if(!(l->e == e)) BME_error();
                        if(!(l->radial.data == l)) BME_error();
                        if(l->prev->e != ne && l->next->e != ne) BME_error();
@@ -543,11 +544,11 @@ BME_Vert *BME_SEMV(BME_Mesh *bm, BME_Vert *tv, BME_Edge *e, BME_Edge **re){
                        if(l->v == l->next->v) BME_error();
                        if(l->e == l->next->e) BME_error();
                        /*verify loop cycle for kloop->f*/
-                       edok = BME_cycle_validate(l->f->len, l->f->loopbase);
+                       edok = BME_cycle_validate(l->f->len, l->f->lbase);
                        if(!edok) BME_error();
                }
                /*verify loop->v and loop->next->v pointers for ne*/
-               for(i=0,l=ne->loop; i < radlen; i++, l = l->radial.next->data){
+               for(i=0,l=ne->l; i < radlen; i++, l = l->radial_next){
                        if(!(l->e == ne)) BME_error();
                        if(!(l->radial.data == l)) BME_error();
                        if(l->prev->e != e && l->next->e != e) BME_error();
@@ -556,7 +557,7 @@ BME_Vert *BME_SEMV(BME_Mesh *bm, BME_Vert *tv, BME_Edge *e, BME_Edge **re){
                        if(l->v == l->next->v) BME_error();
                        if(l->e == l->next->e) BME_error();
                        /*verify loop cycle for kloop->f. Redundant*/
-                       edok = BME_cycle_validate(l->f->len, l->f->loopbase);
+                       edok = BME_cycle_validate(l->f->len, l->f->lbase);
                        if(!edok) BME_error();
                }
        }
@@ -601,7 +602,7 @@ BME_Poly *BME_SFME(BME_Mesh *bm, BME_Poly *f, BME_Vert *v1, BME_Vert *v2, BME_Lo
        
        
        /*verify that v1 and v2 are in face.*/
-       len = BME_cycle_length(f->loopbase);
+       len = BME_cycle_length(f->lbase);
        for(i = 0, curloop = f->loopbase; i < len; i++, curloop = curloop->next){
                if(curloop->v == v1) v1loop = curloop;
                else if(curloop->v == v2) v2loop = curloop;
@@ -635,7 +636,7 @@ BME_Poly *BME_SFME(BME_Mesh *bm, BME_Poly *f, BME_Vert *v1, BME_Vert *v2, BME_Lo
        /*I dont know how many loops are supposed to be in each face at this point! FIXME!*/
        
        /*go through all of f2's loops and make sure they point to it properly.*/
-       f2len = BME_cycle_length(f2->loopbase);
+       f2len = BME_cycle_length(f2->lbase);
        for(i=0, curloop = f2->loopbase; i < f2len; i++, curloop = curloop->next) curloop->f = f2;
        
        /*link up the new loops into the new edges radial*/
@@ -645,7 +646,7 @@ BME_Poly *BME_SFME(BME_Mesh *bm, BME_Poly *f, BME_Vert *v1, BME_Vert *v2, BME_Lo
        
        f2->len = f2len;
        
-       f1len = BME_cycle_length(f->loopbase);
+       f1len = BME_cycle_length(f->lbase);
        f->len = f1len;
        
        if(rl) *rl = f2loop;
@@ -693,7 +694,7 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
        int len,radlen=0, halt = 0, i, valance1, valance2,edok;
        
        if(BME_vert_in_edge(ke,kv) == 0) return 0;
-       diskbase = BME_disk_getpointer(kv->edge, kv);
+       diskbase = BME_disk_getpointer(kv->e, kv);
        len = BME_cycle_length(diskbase);
        
        if(len == 2){
@@ -706,9 +707,9 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
                else{
                        
                        /*For verification later, count valance of ov and tv*/
-                       diskbase = BME_disk_getpointer(ov->edge, ov);
+                       diskbase = BME_disk_getpointer(ov->e, ov);
                        valance1 = BME_cycle_length(diskbase);
-                       diskbase = BME_disk_getpointer(tv->edge, tv);
+                       diskbase = BME_disk_getpointer(tv->e, tv);
                        valance2 = BME_cycle_length(diskbase);
                        
                        /*remove oe from kv's disk cycle*/
@@ -723,10 +724,10 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
                        
 
                        /*deal with radial cycle of ke*/
-                       if(ke->loop){
+                       if(ke->l){
                                /*first step, fix the neighboring loops of all loops in ke's radial cycle*/
-                               radlen = BME_cycle_length(&(ke->loop->radial));
-                               for(i=0,killoop = ke->loop; i<radlen; i++, killoop = BME_radial_nextloop(killoop)){
+                               radlen = BME_cycle_length(&(ke->l->radial));
+                               for(i=0,killoop = ke->l; i<radlen; i++, killoop = BME_radial_nextloop(killoop)){
                                        /*relink loops and fix vertex pointer*/
                                        killoop->next->prev = killoop->prev;
                                        killoop->prev->next = killoop->next;
@@ -734,11 +735,11 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
                                        
                                        /*fix len attribute of face*/
                                        killoop->f->len--;
-                                       if(killoop->f->loopbase == killoop) killoop->f->loopbase = killoop->next;
+                                       if(killoop->f->loopbase == killoop) killoop->f->lbase = killoop->next;
                                }
                                /*second step, remove all the hanging loops attached to ke*/
-                               killoop = ke->loop;
-                               radlen = BME_cycle_length(&(ke->loop->radial));
+                               killoop = ke->l;
+                               radlen = BME_cycle_length(&(ke->l->radial));
                                /*make sure we have enough room in bm->lpar*/
                                if(bm->lparlen < radlen){
                                        MEM_freeN(bm->lpar);
@@ -749,7 +750,7 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
                                i=0;
                                while(i<radlen){
                                        bm->lpar[i] = killoop;
-                                       killoop = killoop->radial.next->data;
+                                       killoop = killoop->radial_next;
                                        i++;
                                }
                                i=0;
@@ -758,22 +759,22 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
                                        i++;
                                }
                                /*Validate radial cycle of oe*/
-                               edok = BME_cycle_validate(radlen,&(oe->loop->radial));
+                               edok = BME_cycle_validate(radlen,&(oe->l->radial));
                                
                        }
                        
 
                        /*Validate disk cycles*/
-                       diskbase = BME_disk_getpointer(ov->edge,ov);
+                       diskbase = BME_disk_getpointer(ov->e,ov);
                        edok = BME_cycle_validate(valance1, diskbase);
                        if(!edok) BME_error();
-                       diskbase = BME_disk_getpointer(tv->edge,tv);
+                       diskbase = BME_disk_getpointer(tv->e,tv);
                        edok = BME_cycle_validate(valance2, diskbase);
                        if(!edok) BME_error();
                        
                        /*Validate loop cycle of all faces attached to oe*/
-                       for(i=0,nextl = oe->loop; i<radlen; i++, nextl = BME_radial_nextloop(nextl)){
-                               edok = BME_cycle_validate(nextl->f->len,nextl->f->loopbase);
+                       for(i=0,nextl = oe->l; i<radlen; i++, nextl = BME_radial_nextloop(nextl)){
+                               edok = BME_cycle_validate(nextl->f->len,nextl->f->lbase);
                                if(!edok) BME_error();
                        }
                        /*deallocate edge*/
@@ -903,8 +904,8 @@ BME_Poly *BME_JFKE(BME_Mesh *bm, BME_Poly *f1, BME_Poly *f2, BME_Edge *e)
        
        if(f1 == f2) return NULL; //can't join a face to itself
        /*verify that e is in both f1 and f2*/
-       f1len = BME_cycle_length(f1->loopbase);
-       f2len = BME_cycle_length(f2->loopbase);
+       f1len = BME_cycle_length(f1->lbase);
+       f2len = BME_cycle_length(f2->lbase);
        for(i=0, curloop = f1->loopbase; i < f1len; i++, curloop = curloop->next){
                if(curloop->e == e){ 
                        f1loop = curloop;
@@ -943,19 +944,19 @@ BME_Poly *BME_JFKE(BME_Mesh *bm, BME_Poly *f1, BME_Poly *f2, BME_Edge *e)
        f2loop->prev->next = f1loop->next;
        
        /*if f1loop was baseloop, give f1loop->next the base.*/
-       if(f1->loopbase == f1loop) f1->loopbase = f1loop->next;
+       if(f1->loopbase == f1loop) f1->lbase = f1loop->next;
        
        /*validate the new loop*/
-       loopok = BME_cycle_validate((f1len+f2len)-2, f1->loopbase);
+       loopok = BME_cycle_validate((f1len+f2len)-2, f1->lbase);
        if(!loopok) BME_error();
        
        /*make sure each loop points to the proper face*/
-       newlen = BME_cycle_length(f1->loopbase);
+       newlen = BME_cycle_length(f1->lbase);
        for(i = 0, curloop = f1->loopbase; i < newlen; i++, curloop = curloop->next) curloop->f = f1;
        
        f1->len = newlen;
        
-       edok = BME_cycle_validate(f1->len, f1->loopbase);
+       edok = BME_cycle_validate(f1->len, f1->lbase);
        if(!edok) BME_error();
        
        /*remove edge from the disk cycle of its two vertices.*/
@@ -971,3 +972,4 @@ BME_Poly *BME_JFKE(BME_Mesh *bm, BME_Poly *f1, BME_Poly *f2, BME_Edge *e)
        BME_free_poly(bm, f2);  
        return f1;
 }
+#endif
index cda66de6f22bb16cc398cd361a3e4300f91af8b3..dcca2da5414ff23ed6a6066b4729c8c427b77062 100644 (file)
@@ -1,4 +1,5 @@
-/*
+#if 0
+/**
  * BME_mesh.c    jan 2007
  *
  *     BMesh mesh level functions.
@@ -55,10 +56,10 @@ BME_Mesh *BME_make_mesh(int allocsize[4])
        /*allocate the structure*/
        BME_Mesh *bm = MEM_callocN(sizeof(BME_Mesh),"BMesh");
        /*allocate the memory pools for the mesh elements*/
-       bm->vpool = BLI_mempool_create(sizeof(BME_Vert), allocsize[0], allocsize[0], FALSE, FALSE);
-       bm->epool = BLI_mempool_create(sizeof(BME_Edge), allocsize[1], allocsize[1], FALSE, FALSE);
-       bm->lpool = BLI_mempool_create(sizeof(BME_Loop), allocsize[2], allocsize[2], FALSE, FALSE);
-       bm->ppool = BLI_mempool_create(sizeof(BME_Poly), allocsize[3], allocsize[3], FALSE, FALSE);
+       bm->vpool = BLI_mempool_create(sizeof(BME_Vert), allocsize[0], allocsize[0], TRUE, FALSE);
+       bm->epool = BLI_mempool_create(sizeof(BME_Edge), allocsize[1], allocsize[1], TRUE, FALSE);
+       bm->lpool = BLI_mempool_create(sizeof(BME_Loop), allocsize[2], allocsize[2], TRUE, FALSE);
+       bm->ppool = BLI_mempool_create(sizeof(BME_Poly), allocsize[3], allocsize[3], TRUE, FALSE);
        return bm;
 }
 /*     
@@ -82,7 +83,7 @@ void BME_free_mesh(BME_Mesh *bm)
                do{
                        CustomData_bmesh_free_block(&bm->ldata, &l->data);
                        l = l->next;
-               }while(l!=f->loopbase);
+               }while(l!=f->lbase);
        }
 
        /*Free custom data pools, This should probably go in CustomData_free?*/
@@ -196,9 +197,9 @@ int BME_validate_mesh(struct BME_Mesh *bm, int halt)
                if(e->v1 == e->v2) VHALT(halt);
                /*validate e->d1.data and e->d2.data*/
                if(e->d1.data != e || e->d2.data != e) VHALT(halt);
-               /*validate e->loop->e*/
-               if(e->loop){
-                       if(e->loop->e != e) VHALT(halt);
+               /*validate e->l->e*/
+               if(e->l){
+                       if(e->l->e != e) VHALT(halt);
                }
        }
        
@@ -210,17 +211,17 @@ int BME_validate_mesh(struct BME_Mesh *bm, int halt)
        }
        /*Validate vertices and disk cycle*/
        for(v=bm->verts.first; v; v=v->next){
-               /*validate v->edge pointer*/
+               /*validate v->e pointer*/
                if(v->tflag1){
-                       if(v->edge){
-                               ok = BME_vert_in_edge(v->edge,v);
+                       if(v->e){
+                               ok = BME_vert_in_edge(v->e,v);
                                if(!ok) VHALT(halt);
                                /*validate length of disk cycle*/
-                               diskbase = BME_disk_getpointer(v->edge, v);
+                               diskbase = BME_disk_getpointer(v->e, v);
                                ok = BME_cycle_validate(v->tflag1, diskbase);
                                if(!ok) VHALT(halt);
                                /*validate that each edge in disk cycle contains V*/
-                               for(i=0, e=v->edge; i < v->tflag1; i++, e = BME_disk_nextedge(e,v)){
+                               for(i=0, e=v->e; i < v->tflag1; i++, e = BME_disk_nextedge(e,v)){
                                        ok = BME_vert_in_edge(e, v);
                                        if(!ok) VHALT(halt);
                                }
@@ -242,7 +243,7 @@ int BME_validate_mesh(struct BME_Mesh *bm, int halt)
        for(e=bm->edges.first; e; e=e->next) e->tflag2 = 0; //store incident faces
        /*Validate the loop cycle integrity.*/
        for(f=bm->polys.first; f; f=f->next){
-               ok = BME_cycle_length(f->loopbase);
+               ok = BME_cycle_length(f->lbase);
                if(ok > 1){
                        f->tflag1 = ok;
                }
@@ -253,11 +254,11 @@ int BME_validate_mesh(struct BME_Mesh *bm, int halt)
                        if(!ok) VHALT(halt);
                        /*verify radial node data pointer*/
                        if(l->radial.data != l) VHALT(halt);
-                       /*validate l->e->loop poitner*/
-                       if(l->e->loop == NULL) VHALT(halt);
+                       /*validate l->e->l poitner*/
+                       if(l->e->l == NULL) VHALT(halt);
                        /*validate l->f pointer*/
                        if(l->f != f) VHALT(halt);
-                       /*see if l->e->loop is actually in radial cycle*/
+                       /*see if l->e->l is actually in radial cycle*/
                        
                        l->e->tflag2++;
                 }
@@ -265,8 +266,8 @@ int BME_validate_mesh(struct BME_Mesh *bm, int halt)
        
        /*validate length of radial cycle*/
        for(e=bm->edges.first; e; e=e->next){
-               if(e->loop){
-                       ok = BME_cycle_validate(e->tflag2,&(e->loop->radial));
+               if(e->l){
+                       ok = BME_cycle_validate(e->tflag2,&(e->l->radial));
                        if(!ok) VHALT(halt);
                }
        }
@@ -283,3 +284,4 @@ int BME_validate_mesh(struct BME_Mesh *bm, int halt)
 void BME_error(void){
        printf("BME modelling error!");
 }
+#endif
index 6d8a8339e46487c7ebd6fa0cd23e551482781e0f..789812a99c8004709099d04b5cf2d291dd736e54 100644 (file)
@@ -1,4 +1,5 @@
-/*
+#if 0
+/**
  * BME_structure.c    jan 2007
  *
  *     Low level routines for manipulating the BMesh structure.
@@ -30,7 +31,7 @@
  *
  * ***** END GPL LICENSE BLOCK *****
  */
-
+#if 0
 /** \file blender/blenkernel/intern/BME_structure.c
  *  \ingroup bke
  */
@@ -90,7 +91,7 @@ BME_Vert *BME_addvertlist(BME_Mesh *bm, BME_Vert *example){
        v->EID = bm->nextv;
        v->co[0] = v->co[1] = v->co[2] = 0.0f;
        v->no[0] = v->no[1] = v->no[2] = 0.0f;
-       v->edge = NULL;
+       v->e = NULL;
        v->data = NULL;
        v->eflag1 = v->eflag2 = v->tflag1 = v->tflag2 = 0;
        v->flag = v->h = 0;
@@ -118,7 +119,7 @@ BME_Edge *BME_addedgelist(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge *ex
        e->d1.next = e->d1.prev = e->d2.next = e->d2.prev = NULL;
        e->d1.data = e;
        e->d2.data = e;
-       e->loop = NULL;
+       e->l = NULL;
        e->data = NULL;
        e->eflag1 = e->eflag2 = e->tflag1 = e->tflag2 = 0;
        e->flag = e->h = 0;
@@ -243,7 +244,7 @@ void BME_free_loop(BME_Mesh *bm, BME_Loop *l){
  *                     BME_disk_getpointer
  *
  *     2: The Radial Cycle - A circle of face edges (BME_Loop) around an edge
- *        Base: edge->loop->radial structure.
+ *        Base: edge->l->radial structure.
  *
  *             The radial cycle is similar to the radial cycle in the radial edge data structure.*
  *             Unlike the radial edge however, the radial cycle does not require a large amount of memory 
@@ -259,7 +260,7 @@ void BME_free_loop(BME_Mesh *bm, BME_Loop *l){
  *             
  *
  *     3: The Loop Cycle - A circle of face edges around a polygon.
- *     Base: polygon->loopbase.
+ *     Base: polygon->lbase.
  *
  *        The loop cycle keeps track of a faces vertices and edges. It should be noted that the
  *     direction of a loop cycle is either CW or CCW depending on the face normal, and is 
@@ -447,15 +448,15 @@ int BME_disk_append_edge(BME_Edge *e, BME_Vert *v)
        if(BME_vert_in_edge(e, v) == 0) return 0; /*check to make sure v is in e*/
        
        /*check for loose vert first*/
-       if(v->edge == NULL){
-               v->edge = e;
+       if(v->e == NULL){
+               v->e = e;
                base = tail = BME_disk_getpointer(e, v);
                BME_cycle_append(base, tail); /*circular reference is ok!*/
                return 1;
        }
        
-       /*insert e at the end of disk cycle and make it the new v->edge*/
-       base = BME_disk_getpointer(v->edge, v);
+       /*insert e at the end of disk cycle and make it the new v->e*/
+       base = BME_disk_getpointer(v->e, v);
        tail = BME_disk_getpointer(e, v);
        BME_cycle_append(base, tail);
        return 1;
@@ -478,18 +479,18 @@ void BME_disk_remove_edge(BME_Edge *e, BME_Vert *v)
        BME_Edge *newbase;
        int len;
        
-       base = BME_disk_getpointer(v->edge, v);
+       base = BME_disk_getpointer(v->e, v);
        remnode = BME_disk_getpointer(e, v);
        
-       /*first deal with v->edge pointer...*/
+       /*first deal with v->e pointer...*/
        len = BME_cycle_length(base);
        if(len == 1) newbase = NULL;
-       else if(v->edge == e) newbase = base->next-> data;
-       else newbase = v->edge;
+       else if(v->e == e) newbase = base->next-> data;
+       else newbase = v->e;
        
        /*remove and rebase*/
        BME_cycle_remove(base, remnode);
-       v->edge = newbase;
+       v->e = newbase;
 }
 
 /**
@@ -542,12 +543,12 @@ int BME_disk_count_edgeflag(BME_Vert *v, int eflag, int tflag){
        BME_Edge *curedge;
        int i, len=0, count=0;
        
-       if(v->edge){
+       if(v->e){
                if(eflag && tflag) return 0; /*tflag and eflag are reserved for different functions!*/
-               diskbase = BME_disk_getpointer(v->edge, v);
+               diskbase = BME_disk_getpointer(v->e, v);
                len = BME_cycle_length(diskbase);
                
-               for(i = 0, curedge=v->edge; i<len; i++){
+               for(i = 0, curedge=v->e; i<len; i++){
                        if(tflag){
                                if(curedge->tflag1 == tflag) count++;
                        }
@@ -565,11 +566,11 @@ int BME_disk_hasedge(BME_Vert *v, BME_Edge *e){
        BME_Edge *curedge;
        int i, len=0;
        
-       if(v->edge){
-               diskbase = BME_disk_getpointer(v->edge,v);
+       if(v->e){
+               diskbase = BME_disk_getpointer(v->e,v);
                len = BME_cycle_length(diskbase);
                
-               for(i = 0, curedge=v->edge; i<len; i++){
+               for(i = 0, curedge=v->e; i<len; i++){
                        if(curedge == e) return 1;
                        else curedge=BME_disk_nextedge(curedge, v);
                }
@@ -579,12 +580,12 @@ int BME_disk_hasedge(BME_Vert *v, BME_Edge *e){
 /*end disk cycle routines*/
 
 BME_Loop *BME_radial_nextloop(BME_Loop *l){
-       return (BME_Loop*)(l->radial.next->data);
+       return (BME_Loop*)(l->radial_next);
 }
 
 void BME_radial_append(BME_Edge *e, BME_Loop *l){
-       if(e->loop == NULL) e->loop = l;
-       BME_cycle_append(&(e->loop->radial), &(l->radial));
+       if(e->l == NULL) e->l = l;
+       BME_cycle_append(&(e->l->radial), &(l->radial));
 }
 
 void BME_radial_remove_loop(BME_Loop *l, BME_Edge *e)
@@ -592,15 +593,15 @@ void BME_radial_remove_loop(BME_Loop *l, BME_Edge *e)
        BME_Loop *newbase;
        int len;
        
-       /*deal with edge->loop pointer*/
-       len = BME_cycle_length(&(e->loop->radial));
+       /*deal with edge->l pointer*/
+       len = BME_cycle_length(&(e->l->radial));
        if(len == 1) newbase = NULL;
-       else if(e->loop == l) newbase = e->loop->radial.next->data;
-       else newbase = e->loop;
+       else if(e->l == l) newbase = e->l->radial_next;
+       else newbase = e->l;
        
        /*remove and rebase*/
-       BME_cycle_remove(&(e->loop->radial), &(l->radial));
-       e->loop = newbase;
+       BME_cycle_remove(&(e->l->radial), &(l->radial));
+       e->l = newbase;
 }
 
 int BME_radial_find_face(BME_Edge *e,BME_Poly *f)
@@ -609,8 +610,8 @@ int BME_radial_find_face(BME_Edge *e,BME_Poly *f)
        BME_Loop *curloop;
        int i, len;
        
-       len = BME_cycle_length(&(e->loop->radial));
-       for(i = 0, curloop = e->loop; i < len; i++, curloop = curloop->radial.next->data){
+       len = BME_cycle_length(&(e->l->radial));
+       for(i = 0, curloop = e->l; i < len; i++, curloop = curloop->radial_next){
                if(curloop->f == f) return 1;
        }
        return 0;
@@ -620,9 +621,11 @@ struct BME_Loop *BME_loop_find_loop(struct BME_Poly *f, struct BME_Vert *v) {
        BME_Loop *l;
        int i, len;
        
-       len = BME_cycle_length(f->loopbase);
+       len = BME_cycle_length(f->lbase);
        for (i = 0, l=f->loopbase; i < len; i++, l=l->next) {
                if (l->v == v) return l;
        }
        return NULL;
 }
+#endif
+#endif
index 44258f92024660932c489981ec478454f1956f66..32e608623d5ad633247f06bc061d5ea299484551 100644 (file)
@@ -1,4 +1,5 @@
-/*
+#if 0
+/**
  * BME_tools.c    jan 2007
  *
  *     Functions for changing the topology of a mesh.
@@ -130,20 +131,20 @@ static int BME_is_nonmanifold_vert(BME_Mesh *UNUSED(bm), BME_Vert *v) {
        BME_Loop *l;
        int len, count, flag;
 
-       if (v->edge == NULL) {
+       if (v->e == NULL) {
                /* loose vert */
                return 1;
        }
 
        /* count edges while looking for non-manifold edges */
-       oe = v->edge;
-       for (len=0,e=v->edge; e != oe || (e == oe && len == 0); len++,e=BME_disk_nextedge(e,v)) {
-               if (e->loop == NULL) {
+       oe = v->e;
+       for (len=0,e=v->e; e != oe || (e == oe && len == 0); len++,e=BME_disk_nextedge(e,v)) {
+               if (e->l == NULL) {
                        /* loose edge */
                        return 1;
                }
 
-               if (BME_cycle_length(&(e->loop->radial)) > 2) {
+               if (BME_cycle_length(&(e->l->radial)) > 2) {
                        /* edge shared by more than two faces */
                        return 1;
                }
@@ -152,28 +153,28 @@ static int BME_is_nonmanifold_vert(BME_Mesh *UNUSED(bm), BME_Vert *v) {
        count = 1;
        flag = 1;
        e = NULL;
-       oe = v->edge;
-       l = oe->loop;
+       oe = v->e;
+       l = oe->l;
        while(e != oe) {
                if (l->v == v) l = l->prev;
                else l = l->next;
                e = l->e;
                count++; /* count the edges */
 
-               if (flag && l->radial.next->data == l) {
+               if (flag && l->radial_next == l) {
                        /* we've hit the edge of an open mesh, reset once */
                        flag = 0;
                        count = 1;
                        oe = e;
                        e = NULL;
-                       l = oe->loop;
+                       l = oe->l;
                }
-               else if (l->radial.next->data == l) {
+               else if (l->radial_next == l) {
                        /* break the loop */
                        e = oe;
                }
                else {
-                       l = l->radial.next->data;
+                       l = l->radial_next;
                }
        }
 
@@ -190,8 +191,8 @@ static int BME_is_nonmanifold_vert(BME_Mesh *UNUSED(bm), BME_Vert *v) {
 static BME_Poly *BME_JFKE_safe(BME_Mesh *bm, BME_Poly *f1, BME_Poly *f2, BME_Edge *e) {
        BME_Loop *l1, *l2;
 
-       l1 = e->loop;
-       l2 = l1->radial.next->data;
+       l1 = e->l;
+       l2 = l1->radial_next;
        if (l1->v == l2->v) {
                BME_loop_reverse(bm, f2);
        }
@@ -243,8 +244,8 @@ static void BME_data_facevert_edgesplit(BME_Mesh *bm, BME_Vert *v1, BME_Vert *UN
        w[0] = 1.0f - fac;
        w[1] = fac;
 
-       if(!e1->loop) return;
-       l = e1->loop;
+       if(!e1->l) return;
+       l = e1->l;
        do{
                if(l->v == v1){ 
                        v1loop = l;
@@ -261,8 +262,8 @@ static void BME_data_facevert_edgesplit(BME_Mesh *bm, BME_Vert *v1, BME_Vert *UN
                src[1] = v2loop->data;                                  
 
                CustomData_bmesh_interp(&bm->ldata, src,w, NULL, 2, vloop->data);                               
-               l = l->radial.next->data;
-       }while(l!=e1->loop);
+               l = l->radial_next;
+       }while(l!=e1->l);
 }
 
 
@@ -299,8 +300,8 @@ static void BME_collapse_vert(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv, float fa
        w[0] = 1.0f - fac;
        w[1] = fac;
 
-       if(ke->loop){
-               l = ke->loop;
+       if(ke->l){
+               l = ke->l;
                do{
                        if(l->v == tv && l->next->v == kv){
                                tvloop = l;
@@ -310,8 +311,8 @@ static void BME_collapse_vert(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv, float fa
                                src[1] = tvloop->data;
                                CustomData_bmesh_interp(&bm->ldata, src,w, NULL, 2, kvloop->data);                                                              
                        }
-                       l=l->radial.next->data;
-               }while(l!=ke->loop);
+                       l=l->radial_next;
+               }while(l!=ke->l);
        }
        BME_JEKV(bm,ke,kv);
 }
@@ -419,12 +420,12 @@ static BME_Vert *BME_bevel_split_edge(BME_Mesh *bm, BME_Vert *v, BME_Vert *v1, B
                 * so... here we walk around edges to find the needed verts */
                forward = 1;
                /* is_split_vert = 0; */ /* UNUSED */
-               if (v->edge == NULL) {
+               if (v->e == NULL) {
                        //printf("We can't split a loose vert's edge!\n");
                        return NULL;
                }
-               e1 = v->edge; /* we just use the first two edges */
-               e2 = BME_disk_nextedge(v->edge, v);
+               e1 = v->e; /* we just use the first two edges */
+               e2 = BME_disk_nextedge(v->e, v);
                if (e1 == e2) {
                        //printf("You need at least two edges to use BME_bevel_split_edge()\n");
                        return NULL;
@@ -605,8 +606,8 @@ static float BME_bevel_set_max(BME_Vert *v1, BME_Vert *v2, float value, BME_Tran
 static BME_Vert *BME_bevel_wire(BME_Mesh *bm, BME_Vert *v, float value, int res, int UNUSED(options), BME_TransData_Head *td) {
        BME_Vert *ov1, *ov2, *v1, *v2;
 
-       ov1 = BME_edge_getothervert(v->edge, v);
-       ov2 = BME_edge_getothervert(BME_disk_nextedge(v->edge, v), v);
+       ov1 = BME_edge_getothervert(v->e, v);
+       ov2 = BME_edge_getothervert(BME_disk_nextedge(v->e, v), v);
 
        /* split the edges */
        v1 = BME_bevel_split_edge(bm,v,ov1,NULL,NULL,value,td);
@@ -621,7 +622,7 @@ static BME_Vert *BME_bevel_wire(BME_Mesh *bm, BME_Vert *v, float value, int res,
 
        /* remove the original vert */
        if (res) {
-               BME_JEKV(bm,v->edge,v);
+               BME_JEKV(bm,v->e,v);
        }
 
        return v1;
@@ -646,7 +647,7 @@ static BME_Loop *BME_bevel_edge(BME_Mesh *bm, BME_Loop *l, float value, int UNUS
        /* first, check to see if this edge was inset previously */
        if ((l->prev->e->tflag1 & BME_BEVEL_ORIG) == 0
                && (l->v->tflag1 & BME_BEVEL_NONMAN) == 0) {
-               kl = l->prev->radial.next->data;
+               kl = l->prev->radial_next;
                if (kl->v == l->v) kl = kl->prev;
                else kl = kl->next;
                kv = l->v;
@@ -666,14 +667,14 @@ static BME_Loop *BME_bevel_edge(BME_Mesh *bm, BME_Loop *l, float value, int UNUS
                l = l->next;
                if (kl->v == kv) {
                        BME_split_face(bm,kl->f,kl->prev->v,kl->next->v,&nl,kl->prev->e);
-                       BME_JFKE(bm,((BME_Loop*)kl->prev->radial.next->data)->f,kl->f,kl->prev->e);
+                       BME_JFKE(bm,((BME_Loop*)kl->prev->radial_next)->f,kl->f,kl->prev->e);
                        BME_collapse_vert(bm, kl->e, kv, 1.0);
                        //BME_JEKV(bm,kl->e,kv);
                        
                }
                else {
                        BME_split_face(bm,kl->f,kl->next->next->v,kl->v,&nl,kl->next->e);
-                       BME_JFKE(bm,((BME_Loop*)kl->next->radial.next->data)->f,kl->f,kl->next->e);
+                       BME_JFKE(bm,((BME_Loop*)kl->next->radial_next)->f,kl->f,kl->next->e);
                        BME_collapse_vert(bm, kl->e, kv, 1.0);
                        //BME_JEKV(bm,kl->e,kv);
                }
@@ -684,7 +685,7 @@ static BME_Loop *BME_bevel_edge(BME_Mesh *bm, BME_Loop *l, float value, int UNUS
        /* first, check to see if this edge was inset previously  */
        if ((l->next->e->tflag1 & BME_BEVEL_ORIG) == 0
                && (l->next->v->tflag1 & BME_BEVEL_NONMAN) == 0) {
-               kl = l->next->radial.next->data;
+               kl = l->next->radial_next;
                if (kl->v == l->next->v) kl = kl->prev;
                else kl = kl->next;
                kv = l->next->v;
@@ -703,13 +704,13 @@ static BME_Loop *BME_bevel_edge(BME_Mesh *bm, BME_Loop *l, float value, int UNUS
        if (kv) {
                if (kl->v == kv) {
                        BME_split_face(bm,kl->f,kl->prev->v,kl->next->v,&nl,kl->prev->e);
-                       BME_JFKE(bm,((BME_Loop*)kl->prev->radial.next->data)->f,kl->f,kl->prev->e);
+                       BME_JFKE(bm,((BME_Loop*)kl->prev->radial_next)->f,kl->f,kl->prev->e);
                        BME_collapse_vert(bm, kl->e, kv, 1.0);
                        //BME_JEKV(bm,kl->e,kv);
                }
                else {
                        BME_split_face(bm,kl->f,kl->next->next->v,kl->v,&nl,kl->next->e);
-                       BME_JFKE(bm,((BME_Loop*)kl->next->radial.next->data)->f,kl->f,kl->next->e);
+                       BME_JFKE(bm,((BME_Loop*)kl->next->radial_next)->f,kl->f,kl->next->e);
                        BME_collapse_vert(bm, kl->e, kv, 1.0);
                        //BME_JEKV(bm,kl->e,kv);
                }
@@ -718,7 +719,7 @@ static BME_Loop *BME_bevel_edge(BME_Mesh *bm, BME_Loop *l, float value, int UNUS
        if ((v1->tflag1 & BME_BEVEL_NONMAN)==0 || (v2->tflag1 & BME_BEVEL_NONMAN)==0) {
                BME_split_face(bm,f,v2,v1,&l,e);
                l->e->tflag1 = BME_BEVEL_BEVEL;
-               l = l->radial.next->data;
+               l = l->radial_next;
        }
 
        if (l->f != f){
@@ -885,8 +886,8 @@ static float BME_bevel_get_angle(BME_Mesh *UNUSED(bm), BME_Edge *e, BME_Vert *v)
        BME_Loop *l1, *l2;
        float vec1[3], vec2[3], vec3[3], vec4[3];
 
-       l1 = e->loop;
-       l2 = e->loop->radial.next->data;
+       l1 = e->l;
+       l2 = e->l->radial_next;
        if (l1->v == v) {
                v1 = l1->prev->v;
                v2 = l1->next->v;
@@ -925,7 +926,7 @@ static int BME_face_sharededges(BME_Poly *f1, BME_Poly *f2){
        do{
                if(BME_radial_find_face(l->e,f2)) count++;
                l = l->next;
-       }while(l != f1->loopbase);
+       }while(l != f1->lbase);
        
        return count;
 }
@@ -970,11 +971,11 @@ static BME_Mesh *BME_bevel_initialize(BME_Mesh *bm, int options, int UNUSED(defg
                 */
 
                /* get disk cycle length */
-               if (v->edge == NULL) {
+               if (v->e == NULL) {
                        len = 0;
                }
                else {
-                       len = BME_cycle_length(BME_disk_getpointer(v->edge,v));
+                       len = BME_cycle_length(BME_disk_getpointer(v->e,v));
                        /* we'll assign a default transform data to every vert (except the loose ones) */
                        /* vtd = */ /* UNUSED */ BME_assign_transdata(td, bm, v, v->co, v->co, NULL, NULL, 0, -1, -1, NULL);
                }
@@ -1041,13 +1042,13 @@ static BME_Mesh *BME_bevel_initialize(BME_Mesh *bm, int options, int UNUSED(defg
                 * i.e. the vert's weight is the average of the weights of its weighted edges
                 */
 
-               if (e->loop == NULL) {
+               if (e->l == NULL) {
                        len = 0;
                        e->v1->tflag1 |= BME_BEVEL_NONMAN;
                        e->v2->tflag1 |= BME_BEVEL_NONMAN;
                }
                else {
-                       len = BME_cycle_length(&(e->loop->radial));
+                       len = BME_cycle_length(&(e->l->radial));
                }
 
                if (len > 2) {
@@ -1111,7 +1112,7 @@ static BME_Mesh *BME_bevel_initialize(BME_Mesh *bm, int options, int UNUSED(defg
        for (e=bm->edges.first; e; e=e->next){
                if(e->tflag1 & BME_BEVEL_BEVEL){
                        int count = 0;
-                       count = BME_face_sharededges(e->loop->f, ((BME_Loop*)e->loop->radial.next->data)->f);
+                       count = BME_face_sharededges(e->l->f, ((BME_Loop*)e->l->radial_next)->f);
                        if(count > 1){
                                e->tflag1 &= ~BME_BEVEL_BEVEL;
                        }       
@@ -1162,26 +1163,26 @@ static void bmesh_dissolve_disk(BME_Mesh *bm, BME_Vert *v){
        BME_Edge *e;
        int done, len;
        
-       if(v->edge){
+       if(v->e){
                done = 0;
                while(!done){
                        done = 1;
-                       e = v->edge; /*loop the edge looking for a edge to dissolve*/
+                       e = v->e; /*loop the edge looking for a edge to dissolve*/
                        do{
                                f = NULL;
-                               len = BME_cycle_length(&(e->loop->radial));
+                               len = BME_cycle_length(&(e->l->radial));
                                if(len == 2){
-                                       f = BME_JFKE_safe(bm,e->loop->f, ((BME_Loop*)(e->loop->radial.next->data))->f, e);
+                                       f = BME_JFKE_safe(bm,e->l->f, ((BME_Loop*)(e->l->radial_next))->f, e);
                                }
                                if(f){ 
                                        done = 0;
                                        break;
                                }
                                e = BME_disk_nextedge(e,v);
-                       }while(e != v->edge);
+                       }while(e != v->e);
                }
-               BME_collapse_vert(bm, v->edge, v, 1.0);
-               //BME_JEKV(bm,v->edge,v);
+               BME_collapse_vert(bm, v->e, v, 1.0);
+               //BME_JEKV(bm,v->e,v);
        }
 }
 static BME_Mesh *BME_bevel_mesh(BME_Mesh *bm, float value, int res, int options, int UNUSED(defgrp_index), BME_TransData_Head *td) {
@@ -1207,7 +1208,7 @@ static BME_Mesh *BME_bevel_mesh(BME_Mesh *bm, float value, int res, int options,
                else if (res && ((v->tflag1 & BME_BEVEL_BEVEL) && (v->tflag1 & BME_BEVEL_ORIG))) {
                        int count = 0;
                        /* first, make sure we're not sitting on an edge to be removed */
-                       oe = v->edge;
+                       oe = v->e;
                        e = BME_disk_nextedge(oe,v);
                        while ((e->tflag1 & BME_BEVEL_BEVEL) && (e->tflag1 & BME_BEVEL_ORIG)) {
                                e = BME_disk_nextedge(e,v);
@@ -1221,7 +1222,7 @@ static BME_Mesh *BME_bevel_mesh(BME_Mesh *bm, float value, int res, int options,
                        while ( (e = BME_disk_next_edgeflag(oe, v, 0, BME_BEVEL_ORIG | BME_BEVEL_BEVEL)) ) {
                                count++;
                                /* join the faces (we'll split them later) */
-                               f = BME_JFKE_safe(bm,e->loop->f,((BME_Loop*)e->loop->radial.next->data)->f,e);
+                               f = BME_JFKE_safe(bm,e->l->f,((BME_Loop*)e->l->radial_next)->f,e);
                                if (!f){
                                        //printf("Non-manifold geometry not getting tagged right?\n");
                                }
@@ -1232,10 +1233,10 @@ static BME_Mesh *BME_bevel_mesh(BME_Mesh *bm, float value, int res, int options,
 
                        /* all original edges marked to be beveled have been removed;
                         * now we need to link up the edges for this "corner" */
-                       len = BME_cycle_length(BME_disk_getpointer(v->edge, v));
-                       for (i=0,e=v->edge; i < len; i++,e=BME_disk_nextedge(e,v)) {
-                               l = e->loop;
-                               l2 = l->radial.next->data;
+                       len = BME_cycle_length(BME_disk_getpointer(v->e, v));
+                       for (i=0,e=v->e; i < len; i++,e=BME_disk_nextedge(e,v)) {
+                               l = e->l;
+                               l2 = l->radial_next;
                                if (l->v != v) l = l->next;
                                if (l2->v != v) l2 = l2->next;
                                /* look for faces that have had the original edges removed via JFKE */
@@ -1341,3 +1342,4 @@ BME_Mesh *BME_bevel(BME_Mesh *bm, float value, int res, int options, int defgrp_
        BME_free_transdata(td);
        return bm;
 }
+#endif
index 27aeeb95903997935cc5b7f1f76611cbbf44cd0b..b4af827b44d4573facffcd5dcdb1ee80242574ca 100644 (file)
@@ -31,7 +31,7 @@
 
 
 #include <string.h>
-
+#include "limits.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -46,6 +46,7 @@
 #include "BLI_editVert.h"
 #include "BLI_math.h"
 #include "BLI_memarena.h"
+#include "BLI_array.h"
 #include "BLI_pbvh.h"
 #include "BLI_utildefines.h"
 #include "BLI_linklist.h"
@@ -60,6 +61,9 @@
 #include "BKE_texture.h"
 #include "BKE_multires.h"
 #include "BKE_armature.h"
+#include "BKE_particle.h"
+#include "BKE_tessmesh.h"
+#include "BKE_bvhutils.h"
 #include "BKE_deform.h"
 
 #ifdef WITH_GAMEENGINE
@@ -78,6 +82,9 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
 
 extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
 
+static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob);
+static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
+
 ///////////////////////////////////
 ///////////////////////////////////
 
@@ -109,20 +116,48 @@ static MEdge *dm_getEdgeArray(DerivedMesh *dm)
        return medge;
 }
 
-static MFace *dm_getFaceArray(DerivedMesh *dm)
+static MFace *dm_getTessFaceArray(DerivedMesh *dm)
 {
        MFace *mface = CustomData_get_layer(&dm->faceData, CD_MFACE);
 
        if (!mface) {
                mface = CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL,
-                       dm->getNumFaces(dm));
+                       dm->getNumTessFaces(dm));
                CustomData_set_layer_flag(&dm->faceData, CD_MFACE, CD_FLAG_TEMPORARY);
-               dm->copyFaceArray(dm, mface);
+               dm->copyTessFaceArray(dm, mface);
        }
 
        return mface;
 }
 
+static MLoop *dm_getLoopArray(DerivedMesh *dm)
+{
+       MLoop *mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
+
+       if (!mloop) {
+               mloop = CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL,
+                       dm->getNumLoops(dm));
+               CustomData_set_layer_flag(&dm->loopData, CD_MLOOP, CD_FLAG_TEMPORARY);
+               dm->copyLoopArray(dm, mloop);
+       }
+
+       return mloop;
+}
+
+static MPoly *dm_getPolyArray(DerivedMesh *dm)
+{
+       MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
+
+       if (!mpoly) {
+               mpoly = CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL,
+                       dm->getNumPolys(dm));
+               CustomData_set_layer_flag(&dm->polyData, CD_MPOLY, CD_FLAG_TEMPORARY);
+               dm->copyPolyArray(dm, mpoly);
+       }
+
+       return mpoly;
+}
+
 static MVert *dm_dupVertArray(DerivedMesh *dm)
 {
        MVert *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumVerts(dm),
@@ -145,41 +180,98 @@ static MEdge *dm_dupEdgeArray(DerivedMesh *dm)
 
 static MFace *dm_dupFaceArray(DerivedMesh *dm)
 {
-       MFace *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumFaces(dm),
+       MFace *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumTessFaces(dm),
                                                         "dm_dupFaceArray tmp");
 
-       if(tmp) dm->copyFaceArray(dm, tmp);
+       if(tmp) dm->copyTessFaceArray(dm, tmp);
+
+       return tmp;
+}
+
+static MLoop *dm_dupLoopArray(DerivedMesh *dm)
+{
+       MLoop *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumLoops(dm),
+                                                        "dm_dupLoopArray tmp");
+
+       if(tmp) dm->copyLoopArray(dm, tmp);
+
+       return tmp;
+}
+
+static MPoly *dm_dupPolyArray(DerivedMesh *dm)
+{
+       MPoly *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumPolys(dm),
+                                                        "dm_dupPolyArray tmp");
+
+       if(tmp) dm->copyPolyArray(dm, tmp);
 
        return tmp;
 }
 
+static CustomData *dm_getVertCData(DerivedMesh *dm)
+{
+       return &dm->vertData;
+}
+
+static CustomData *dm_getEdgeCData(DerivedMesh *dm)
+{
+       return &dm->edgeData;
+}
+
+static CustomData *dm_getTessFaceCData(DerivedMesh *dm)
+{
+       return &dm->faceData;
+}
+
+static CustomData *dm_getLoopCData(DerivedMesh *dm)
+{
+       return &dm->loopData;
+}
+
+static CustomData *dm_getPolyCData(DerivedMesh *dm)
+{
+       return &dm->polyData;
+}
+
 void DM_init_funcs(DerivedMesh *dm)
 {
        /* default function implementations */
        dm->getVertArray = dm_getVertArray;
        dm->getEdgeArray = dm_getEdgeArray;
-       dm->getFaceArray = dm_getFaceArray;
+       dm->getTessFaceArray = dm_getTessFaceArray;
+       dm->getLoopArray = dm_getLoopArray;
+       dm->getPolyArray = dm_getPolyArray;
        dm->dupVertArray = dm_dupVertArray;
        dm->dupEdgeArray = dm_dupEdgeArray;
-       dm->dupFaceArray = dm_dupFaceArray;
+       dm->dupTessFaceArray = dm_dupFaceArray;
+       dm->dupLoopArray = dm_dupLoopArray;
+       dm->dupPolyArray = dm_dupPolyArray;
+
+       dm->getVertDataLayout = dm_getVertCData;
+       dm->getEdgeDataLayout = dm_getEdgeCData;
+       dm->getTessFaceDataLayout = dm_getTessFaceCData;
+       dm->getLoopDataLayout = dm_getLoopCData;
+       dm->getPolyDataLayout = dm_getPolyCData;
 
        dm->getVertData = DM_get_vert_data;
        dm->getEdgeData = DM_get_edge_data;
-       dm->getFaceData = DM_get_face_data;
+       dm->getTessFaceData = DM_get_tessface_data;
        dm->getVertDataArray = DM_get_vert_data_layer;
        dm->getEdgeDataArray = DM_get_edge_data_layer;
-       dm->getFaceDataArray = DM_get_face_data_layer;
+       dm->getTessFaceDataArray = DM_get_tessface_data_layer;
 
        bvhcache_init(&dm->bvhCache);
 }
 
-void DM_init(DerivedMesh *dm, DerivedMeshType type,
-                        int numVerts, int numEdges, int numFaces)
+void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges,
+            int numTessFaces, int numLoops, int numPolys)
 {
        dm->type = type;
        dm->numVertData = numVerts;
        dm->numEdgeData = numEdges;
-       dm->numFaceData = numFaces;
+       dm->numTessFaceData = numTessFaces;
+       dm->numLoopData = numLoops;
+       dm->numPolyData = numPolys;
 
        DM_init_funcs(dm);
        
@@ -188,19 +280,26 @@ void DM_init(DerivedMesh *dm, DerivedMeshType type,
 }
 
 void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type,
-                                         int numVerts, int numEdges, int numFaces)
+                      int numVerts, int numEdges, int numTessFaces,
+                      int numLoops, int numPolys)
 {
        CustomData_copy(&source->vertData, &dm->vertData, CD_MASK_DERIVEDMESH,
                                        CD_CALLOC, numVerts);
        CustomData_copy(&source->edgeData, &dm->edgeData, CD_MASK_DERIVEDMESH,
                                        CD_CALLOC, numEdges);
        CustomData_copy(&source->faceData, &dm->faceData, CD_MASK_DERIVEDMESH,
-                                       CD_CALLOC, numFaces);
+                                       CD_CALLOC, numTessFaces);
+       CustomData_copy(&source->loopData, &dm->loopData, CD_MASK_DERIVEDMESH,
+                       CD_CALLOC, numLoops);
+       CustomData_copy(&source->polyData, &dm->polyData, CD_MASK_DERIVEDMESH,
+                       CD_CALLOC, numPolys);
 
        dm->type = type;
        dm->numVertData = numVerts;
        dm->numEdgeData = numEdges;
-       dm->numFaceData = numFaces;
+       dm->numTessFaceData = numTessFaces;
+       dm->numLoopData = numLoops;
+       dm->numPolyData = numPolys;
 
        DM_init_funcs(dm);
 
@@ -214,63 +313,158 @@ int DM_release(DerivedMesh *dm)
                GPU_drawobject_free( dm );
                CustomData_free(&dm->vertData, dm->numVertData);
                CustomData_free(&dm->edgeData, dm->numEdgeData);
-               CustomData_free(&dm->faceData, dm->numFaceData);
+               CustomData_free(&dm->faceData, dm->numTessFaceData);
+               CustomData_free(&dm->loopData, dm->numLoopData);
+               CustomData_free(&dm->polyData, dm->numPolyData);
 
                return 1;
        }
        else {
                CustomData_free_temporary(&dm->vertData, dm->numVertData);
                CustomData_free_temporary(&dm->edgeData, dm->numEdgeData);
-               CustomData_free_temporary(&dm->faceData, dm->numFaceData);
+               CustomData_free_temporary(&dm->faceData, dm->numTessFaceData);
+               CustomData_free_temporary(&dm->loopData, dm->numLoopData);
+               CustomData_free_temporary(&dm->polyData, dm->numPolyData);
 
                return 0;
        }
 }
 
-void DM_to_mesh(DerivedMesh *dm, Mesh *me)
+void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
+{
+       CustomData_free(&target->loopData, source->numLoopData);
+       CustomData_free(&target->polyData, source->numPolyData);
+
+       CustomData_copy(&source->loopData, &target->loopData, CD_MASK_DERIVEDMESH, CD_DUPLICATE, source->numLoopData);
+       CustomData_copy(&source->polyData, &target->polyData, CD_MASK_DERIVEDMESH, CD_DUPLICATE, source->numPolyData);
+
+       target->numLoopData = source->numLoopData;
+       target->numPolyData = source->numPolyData;
+
+       if (!CustomData_has_layer(&target->polyData, CD_MPOLY)) {
+               MPoly *mpoly;
+               MLoop *mloop;
+
+               mloop = source->dupLoopArray(source);
+               mpoly = source->dupPolyArray(source);
+               CustomData_add_layer(&target->loopData, CD_MLOOP, CD_ASSIGN, mloop, source->numLoopData);
+               CustomData_add_layer(&target->polyData, CD_MPOLY, CD_ASSIGN, mpoly, source->numPolyData);
+       }
+}
+
+/* note: until all modifiers can take MPoly's as input,
+ * use this at the start of modifiers  */
+void DM_ensure_tessface(DerivedMesh *dm)
+{
+       const int numTessFaces = dm->getNumTessFaces(dm);
+       const int numPolys =     dm->getNumPolys(dm);
+
+       if ( (numTessFaces == 0) && (numPolys != 0)) {
+               dm->recalcTesselation(dm);
+
+               if (dm->getNumTessFaces(dm) != 0) {
+                       /* printf("info %s: polys -> ngons calculated\n", __func__); */
+               }
+               else {
+                       printf("warning %s: could not create tessfaces from %d polygons, dm->type=%d\n",
+                              __func__, numPolys, dm->type);
+               }
+       }
+}
+
+void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
 {
        /* dm might depend on me, so we need to do everything with a local copy */
        Mesh tmp = *me;
-       int totvert, totedge, totface;
-
+       int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly;
+       int did_shapekeys=0;
+       
        memset(&tmp.vdata, 0, sizeof(tmp.vdata));
        memset(&tmp.edata, 0, sizeof(tmp.edata));
        memset(&tmp.fdata, 0, sizeof(tmp.fdata));
+       memset(&tmp.ldata, 0, sizeof(tmp.ldata));
+       memset(&tmp.pdata, 0, sizeof(tmp.pdata));
 
        totvert = tmp.totvert = dm->getNumVerts(dm);
        totedge = tmp.totedge = dm->getNumEdges(dm);
-       totface = tmp.totface = dm->getNumFaces(dm);
+       totloop = tmp.totloop = dm->getNumLoops(dm);
+       totpoly = tmp.totpoly = dm->getNumPolys(dm);
 
        CustomData_copy(&dm->vertData, &tmp.vdata, CD_MASK_MESH, CD_DUPLICATE, totvert);
        CustomData_copy(&dm->edgeData, &tmp.edata, CD_MASK_MESH, CD_DUPLICATE, totedge);
-       CustomData_copy(&dm->faceData, &tmp.fdata, CD_MASK_MESH, CD_DUPLICATE, totface);
+       CustomData_copy(&dm->loopData, &tmp.ldata, CD_MASK_MESH, CD_DUPLICATE, totloop);
+       CustomData_copy(&dm->polyData, &tmp.pdata, CD_MASK_MESH, CD_DUPLICATE, totpoly);
 
+       if (CustomData_has_layer(&dm->vertData, CD_SHAPEKEY)) {
+               KeyBlock *kb;
+               int uid;
+               
+               if (ob) {
+                       kb = BLI_findlink(&me->key->block, ob->shapenr-1);
+                       if (kb) {
+                               uid = kb->uid;
+                       }
+                       else {
+                               printf("%s: error - could not find active shapekey %d!\n",
+                                      __func__, ob->shapenr-1);
+
+                               uid = INT_MAX;
+                       }
+               }
+               else {
+                       /*if no object, set to INT_MAX so we don't mess up any shapekey layers*/
+                       uid = INT_MAX;
+               }
+
+               shapekey_layers_to_keyblocks(dm, me, uid);
+               did_shapekeys = 1;
+       }
+       
        /* not all DerivedMeshes store their verts/edges/faces in CustomData, so
           we set them here in case they are missing */
        if(!CustomData_has_layer(&tmp.vdata, CD_MVERT))
                CustomData_add_layer(&tmp.vdata, CD_MVERT, CD_ASSIGN, dm->dupVertArray(dm), totvert);
        if(!CustomData_has_layer(&tmp.edata, CD_MEDGE))
                CustomData_add_layer(&tmp.edata, CD_MEDGE, CD_ASSIGN, dm->dupEdgeArray(dm), totedge);
-       if(!CustomData_has_layer(&tmp.fdata, CD_MFACE))
-               CustomData_add_layer(&tmp.fdata, CD_MFACE, CD_ASSIGN, dm->dupFaceArray(dm), totface);
+       if(!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
+               tmp.mloop = dm->dupLoopArray(dm);
+               tmp.mpoly = dm->dupPolyArray(dm);
+
+               CustomData_add_layer(&tmp.ldata, CD_MLOOP, CD_ASSIGN, tmp.mloop, tmp.totloop);
+               CustomData_add_layer(&tmp.pdata, CD_MPOLY, CD_ASSIGN, tmp.mpoly, tmp.totpoly);
+       }
 
        /* object had got displacement layer, should copy this layer to save sculpted data */
        /* NOTE: maybe some other layers should be copied? nazgul */
-       if(CustomData_has_layer(&me->fdata, CD_MDISPS)) {
-               if (totface == me->totface) {
-                       MDisps *mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
-                       CustomData_add_layer(&tmp.fdata, CD_MDISPS, CD_DUPLICATE, mdisps, totface);
+       if(CustomData_has_layer(&me->ldata, CD_MDISPS)) {
+               if (totloop == me->totloop) {
+                       MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
+                       CustomData_add_layer(&tmp.ldata, CD_MDISPS, CD_DUPLICATE, mdisps, totloop);
                }
        }
 
-       mesh_update_customdata_pointers(&tmp);
+       /* yes, must be before _and_ after tesselate */
+       mesh_update_customdata_pointers(&tmp, TRUE);
+
+       tmp.totface = mesh_recalcTesselation(&tmp.fdata, &tmp.ldata, &tmp.pdata,
+                                            tmp.mvert,
+                                            tmp.totface, tmp.totloop, tmp.totpoly,
+                                            TRUE);
+
+       mesh_update_customdata_pointers(&tmp, TRUE);
+
 
        CustomData_free(&me->vdata, me->totvert);
        CustomData_free(&me->edata, me->totedge);
        CustomData_free(&me->fdata, me->totface);
-
-       /* if the number of verts has changed, remove invalid data */
-       if(tmp.totvert != me->totvert) {
+       CustomData_free(&me->ldata, me->totloop);
+       CustomData_free(&me->pdata, me->totpoly);
+
+       /*  ok, this should now use new CD shapekey data,
+           which shouuld be fed through the modifier 
+               stack*/
+       if(tmp.totvert != me->totvert && !did_shapekeys && me->key) {
+               printf("YEEK! this should be recoded! Shape key loss!!!\n");
                if(tmp.key) tmp.key->id.us--;
                tmp.key = NULL;
        }
@@ -315,9 +509,19 @@ void DM_add_edge_layer(DerivedMesh *dm, int type, int alloctype, void *layer)
        CustomData_add_layer(&dm->edgeData, type, alloctype, layer, dm->numEdgeData);
 }
 
-void DM_add_face_layer(DerivedMesh *dm, int type, int alloctype, void *layer)
+void DM_add_tessface_layer(DerivedMesh *dm, int type, int alloctype, void *layer)
 {
-       CustomData_add_layer(&dm->faceData, type, alloctype, layer, dm->numFaceData);
+       CustomData_add_layer(&dm->faceData, type, alloctype, layer, dm->numTessFaceData);
+}
+
+void DM_add_loop_layer(DerivedMesh *dm, int type, int alloctype, void *layer)
+{
+       CustomData_add_layer(&dm->loopData, type, alloctype, layer, dm->numLoopData);
+}
+
+void DM_add_poly_layer(DerivedMesh *dm, int type, int alloctype, void *layer)
+{
+       CustomData_add_layer(&dm->polyData, type, alloctype, layer, dm->numPolyData);
 }
 
 void *DM_get_vert_data(DerivedMesh *dm, int index, int type)
@@ -330,7 +534,7 @@ void *DM_get_edge_data(DerivedMesh *dm, int index, int type)
        return CustomData_get(&dm->edgeData, index, type);
 }
 
-void *DM_get_face_data(DerivedMesh *dm, int index, int type)
+void *DM_get_tessface_data(DerivedMesh *dm, int index, int type)
 {
        return CustomData_get(&dm->faceData, index, type);
 }
@@ -351,14 +555,19 @@ void *DM_get_edge_data_layer(DerivedMesh *dm, int type)
        return CustomData_get_layer(&dm->edgeData, type);
 }
 
-void *DM_get_face_data_layer(DerivedMesh *dm, int type)
+void *DM_get_tessface_data_layer(DerivedMesh *dm, int type)
 {
-       if(type == CD_MFACE)
-               return dm->getFaceArray(dm);
+       if (type == CD_MFACE)
+               return dm->getTessFaceArray(dm);
 
        return CustomData_get_layer(&dm->faceData, type);
 }
 
+void *DM_get_poly_data_layer(DerivedMesh *dm, int type)
+{
+       return CustomData_get_layer(&dm->polyData, type);
+}
+
 void DM_set_vert_data(DerivedMesh *dm, int index, int type, void *data)
 {
        CustomData_set(&dm->vertData, index, type, data);
@@ -369,7 +578,7 @@ void DM_set_edge_data(DerivedMesh *dm, int index, int type, void *data)
        CustomData_set(&dm->edgeData, index, type, data);
 }
 
-void DM_set_face_data(DerivedMesh *dm, int index, int type, void *data)
+void DM_set_tessface_data(DerivedMesh *dm, int index, int type, void *data)
 {
        CustomData_set(&dm->faceData, index, type, data);
 }
@@ -388,13 +597,27 @@ void DM_copy_edge_data(DerivedMesh *source, DerivedMesh *dest,
                                                 source_index, dest_index, count);
 }
 
-void DM_copy_face_data(DerivedMesh *source, DerivedMesh *dest,
+void DM_copy_tessface_data(DerivedMesh *source, DerivedMesh *dest,
                                           int source_index, int dest_index, int count)
 {
        CustomData_copy_data(&source->faceData, &dest->faceData,
                                                 source_index, dest_index, count);
 }
 
+void DM_copy_loop_data(DerivedMesh *source, DerivedMesh *dest,
+                       int source_index, int dest_index, int count)
+{
+       CustomData_copy_data(&source->loopData, &dest->loopData,
+                            source_index, dest_index, count);
+}
+
+void DM_copy_poly_data(DerivedMesh *source, DerivedMesh *dest,
+                       int source_index, int dest_index, int count)
+{
+       CustomData_copy_data(&source->polyData, &dest->polyData,
+                            source_index, dest_index, count);
+}
+
 void DM_free_vert_data(struct DerivedMesh *dm, int index, int count)
 {
        CustomData_free_elem(&dm->vertData, index, count);
@@ -405,11 +628,21 @@ void DM_free_edge_data(struct DerivedMesh *dm, int index, int count)
        CustomData_free_elem(&dm->edgeData, index, count);
 }
 
-void DM_free_face_data(struct DerivedMesh *dm, int index, int count)
+void DM_free_tessface_data(struct DerivedMesh *dm, int index, int count)
 {
        CustomData_free_elem(&dm->faceData, index, count);
 }
 
+void DM_free_loop_data(struct DerivedMesh *dm, int index, int count)
+{
+       CustomData_free_elem(&dm->loopData, index, count);
+}
+
+void DM_free_poly_data(struct DerivedMesh *dm, int index, int count)
+{
+       CustomData_free_elem(&dm->polyData, index, count);
+}
+
 void DM_interp_vert_data(DerivedMesh *source, DerivedMesh *dest,
                                                 int *src_indices, float *weights,
                                                 int count, int dest_index)
@@ -427,7 +660,7 @@ void DM_interp_edge_data(DerivedMesh *source, DerivedMesh *dest,
                                          weights, (float*)vert_weights, count, dest_index);
 }
 
-void DM_interp_face_data(DerivedMesh *source, DerivedMesh *dest,
+void DM_interp_tessface_data(DerivedMesh *source, DerivedMesh *dest,
                                                 int *src_indices,
                                                 float *weights, FaceVertWeight *vert_weights,
                                                 int count, int dest_index)
@@ -436,13 +669,28 @@ void DM_interp_face_data(DerivedMesh *source, DerivedMesh *dest,
                                          weights, (float*)vert_weights, count, dest_index);
 }
 
-void DM_swap_face_data(DerivedMesh *dm, int index, const int *corner_indices)
+void DM_swap_tessface_data(DerivedMesh *dm, int index, const int *corner_indices)
 {
        CustomData_swap(&dm->faceData, index, corner_indices);
 }
 
-///
+void DM_interp_loop_data(DerivedMesh *source, DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index)
+{
+       CustomData_interp(&source->loopData, &dest->loopData, src_indices,
+                         weights, NULL, count, dest_index);
+}
 
+void DM_interp_poly_data(DerivedMesh *source, DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index)
+{
+       CustomData_interp(&source->polyData, &dest->polyData, src_indices,
+                         weights, NULL, count, dest_index);
+}
+
+///
 DerivedMesh *mesh_create_derived(Mesh *me, Object *ob, float (*vertCos)[3])
 {
        DerivedMesh *dm = CDDM_from_mesh(me, ob);
@@ -458,17 +706,25 @@ DerivedMesh *mesh_create_derived(Mesh *me, Object *ob, float (*vertCos)[3])
        return dm;
 }
 
-DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, ModifierData *md)
+/***/
+
+DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, 
+                                              ModifierData *md, int build_shapekey_layers)
 {
        Mesh *me = ob->data;
        ModifierTypeInfo *mti = modifierType_getInfo(md->type);
        DerivedMesh *dm;
+       KeyBlock *kb;
 
        md->scene= scene;
        
        if (!(md->mode&eModifierMode_Realtime)) return NULL;
        if (mti->isDisabled && mti->isDisabled(md, 0)) return NULL;
-
+       
+       if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr-1))) {
+               key_to_mesh(kb, me);
+       }
+       
        if (mti->type==eModifierTypeType_OnlyDeform) {
                int numVerts;
                float (*deformedVerts)[3] = mesh_getVertexCos(me, &numVerts);
@@ -476,9 +732,16 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, Modifier
                mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, 0, 0);
                dm = mesh_create_derived(me, ob, deformedVerts);
 
+               if (build_shapekey_layers)
+                       add_shapekey_layers(dm, me, ob);
+               
                MEM_freeN(deformedVerts);
        } else {
                DerivedMesh *tdm = mesh_create_derived(me, ob, NULL);
+
+               if (build_shapekey_layers)
+                       add_shapekey_layers(tdm, me, ob);
+               
                dm = mti->applyModifier(md, ob, tdm, 0, 0);
 
                if(tdm != dm) tdm->release(tdm);
@@ -487,22 +750,22 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, Modifier
        return dm;
 }
 
-static float *get_editmesh_orco_verts(EditMesh *em)
+static float *get_editbmesh_orco_verts(BMEditMesh *em)
 {
-       EditVert *eve;
+       BMIter iter;
+       BMVert *eve;
        float *orco;
        int a, totvert;
 
        /* these may not really be the orco's, but it's only for preview.
         * could be solver better once, but isn't simple */
 
-       totvert= 0;
-       for(eve=em->verts.first; eve; eve=eve->next)
-               totvert++;
+       totvert= em->bm->totvert;
        
        orco = MEM_mallocN(sizeof(float)*3*totvert, "EditMesh Orco");
 
-       for(a=0, eve=em->verts.first; eve; eve=eve->next, a+=3) {
+       eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+       for (a=0; eve; eve=BMIter_Step(&iter), a+=3) {
                copy_v3_v3(orco+a, eve->co);
        }
        
@@ -510,8 +773,7 @@ static float *get_editmesh_orco_verts(EditMesh *em)
 }
 
 /* orco custom data layer */
-
-static void *get_orco_coords_dm(Object *ob, EditMesh *em, int layer, int *free)
+static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free)
 {
        *free= 0;
 
@@ -520,7 +782,7 @@ static void *get_orco_coords_dm(Object *ob, EditMesh *em, int layer, int *free)
                *free= 1;
 
                if(em)
-                       return (float(*)[3])get_editmesh_orco_verts(em);
+                       return (float(*)[3])get_editbmesh_orco_verts(em);
                else
                        return (float(*)[3])get_mesh_orco_verts(ob);
        }
@@ -541,13 +803,13 @@ static void *get_orco_coords_dm(Object *ob, EditMesh *em, int layer, int *free)
        return NULL;
 }
 
-static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, EditMesh *em, int layer)
+static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int layer)
 {
        DerivedMesh *dm;
        float (*orco)[3];
        int free;
 
-       if(em) dm= CDDM_from_editmesh(em, me);
+       if(em) dm= CDDM_from_BMEditMesh(em, me, FALSE, FALSE);
        else dm= CDDM_from_mesh(me, ob);
 
        orco= get_orco_coords_dm(ob, em, layer, &free);
@@ -562,7 +824,8 @@ static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, EditMesh *em, int layer
        return dm;
 }
 
-static void add_orco_dm(Object *ob, EditMesh *em, DerivedMesh *dm, DerivedMesh *orcodm, int layer)
+static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm,
+                                               DerivedMesh *orcodm, int layer)
 {
        float (*orco)[3], (*layerorco)[3];
        int totvert, free;
@@ -775,19 +1038,35 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
 {
        ColorBand *coba= stored_cb;     /* warning, not a local var */
 
-       MFace *mf = dm->getFaceArray(dm);
-       int numFaces = dm->getNumFaces(dm);
-       int numVerts = dm->getNumVerts(dm);
        unsigned char *wtcol_v;
-       unsigned char *wtcol_f = dm->getFaceDataArray(dm, CD_WEIGHT_MCOL);
-       int i;
+#if 0 /* See coment below. */
+       unsigned char *wtcol_f = dm->getTessFaceDataArray(dm, CD_WEIGHT_MCOL);
+#endif
+       unsigned char(*wtcol_l)[4] = CustomData_get_layer(dm->getLoopDataLayout(dm), CD_WEIGHT_MLOOPCOL);
+#if 0 /* See coment below. */
+       MFace *mf = dm->getTessFaceArray(dm);
+#endif
+       MLoop *mloop = dm->getLoopArray(dm), *ml;
+       MPoly *mp = dm->getPolyArray(dm);
+       int numFaces = dm->getNumTessFaces(dm);
+       int numVerts = dm->getNumVerts(dm);
+       int totloop;
+       int i, j;
 
+#if 0 /* See comment below */
        /* If no CD_WEIGHT_MCOL existed yet, add a new one! */
        if (!wtcol_f)
                wtcol_f = CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numFaces);
 
        if (wtcol_f) {
                unsigned char *wtcol_f_step = wtcol_f;
+# else
+       /* XXX We have to create a CD_WEIGHT_MCOL, else it might sigsev (after a SubSurf mod, eg)... */
+       if(!dm->getTessFaceDataArray(dm, CD_WEIGHT_MCOL))
+               CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numFaces);
+
+       {
+#endif
 
                /* Weights are given by caller. */
                if (weights) {
@@ -813,7 +1092,13 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
                        wtcol_v = calc_weightpaint_vert_array(ob, dm, draw_flag, coba);
 
                /* Now copy colors in all face verts. */
+               /*first add colors to the tesselation faces*/
+               /* XXX Why update that layer? We have to update WEIGHT_MLOOPCOL anyway, 
+                *     and tesselation recreates mface layers from mloop/mpoly ones, so no
+                *     need to fill WEIGHT_MCOL here. */
+#if 0
                for (i = 0; i < numFaces; i++, mf++, wtcol_f_step += (4 * 4)) {
+                       /*origindex being NULL means we're operating on original mesh data*/
 #if 0
                        unsigned int fidx= mf->v4 ? 3:2;
 
@@ -830,13 +1115,137 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
 
                        do {
                                copy_v4_v4_char((char *)&wtcol_f_step[fidx * 4],
-                                                       (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
+                                               (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
                        } while (fidx--);
                }
+#endif
+               /*now add to loops, so the data can be passed through the modifier stack*/
+               /* If no CD_WEIGHT_MLOOPCOL existed yet, we have to add a new one! */
+               if (!wtcol_l) {
+                       BLI_array_declare(wtcol_l);
+                       totloop = 0;
+                       for (i=0; i<dm->numPolyData; i++, mp++) {
+                               ml = mloop + mp->loopstart;
+
+                               BLI_array_growitems(wtcol_l, mp->totloop);
+                               for (j = 0; j < mp->totloop; j++, ml++, totloop++) {
+                                       copy_v4_v4_char((char *)&wtcol_l[totloop],
+                                                       (char *)&wtcol_v[4 * ml->v]);
+                               }
+                       }
+                       CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_ASSIGN, wtcol_l, totloop);
+               }
+               else {
+                       totloop = 0;
+                       for (i=0; i < dm->numPolyData; i++, mp++) {
+                               ml = mloop + mp->loopstart;
+
+                               for (j=0; j < mp->totloop; j++, ml++, totloop++) {
+                                       copy_v4_v4_char((char *)&wtcol_l[totloop],
+                                                       (char *)&wtcol_v[4 * ml->v]);
+                               }
+                       }
+               }
                MEM_freeN(wtcol_v);
        }
 }
 
+
+static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid)
+{
+       KeyBlock *kb;
+       int i, j, tot;
+       
+       if (!me->key)
+               return; 
+       
+       tot = CustomData_number_of_layers(&dm->vertData, CD_SHAPEKEY);
+       for (i=0; i<tot; i++) {
+               CustomDataLayer *layer = &dm->vertData.layers[CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i)];
+               float (*cos)[3], (*kbcos)[3];
+               
+               for (kb=me->key->block.first; kb; kb=kb->next) {
+                       if (kb->uid == layer->uid)
+                               break;
+               }
+               
+               if (!kb) {
+                       kb = add_keyblock(me->key, layer->name);
+                       kb->uid = layer->uid;
+               }
+               
+               if (kb->data)
+                       MEM_freeN(kb->data);
+               
+               cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i);
+               kb->totelem = dm->numVertData;
+
+               kb->data = kbcos = MEM_mallocN(sizeof(float)*3*kb->totelem, "kbcos DerivedMesh.c");
+               if (kb->uid == actshape_uid) {
+                       MVert *mvert = dm->getVertArray(dm);
+                       
+                       for (j=0; j<dm->numVertData; j++, kbcos++, mvert++) {
+                               copy_v3_v3(*kbcos, mvert->co);
+                       }
+               } else {
+                       for (j=0; j<kb->totelem; j++, cos++, kbcos++) {
+                               copy_v3_v3(*kbcos, *cos);
+                       }
+               }
+       }
+       
+       for (kb=me->key->block.first; kb; kb=kb->next) {
+               if (kb->totelem != dm->numVertData) {
+                       if (kb->data)
+                               MEM_freeN(kb->data);
+                       
+                       kb->totelem = dm->numVertData;
+                       kb->data = MEM_callocN(sizeof(float)*3*kb->totelem, "kb->data derivedmesh.c");
+                       fprintf(stderr, "%s: lost a shapekey layer! (bmesh internal error)\n", __func__);
+               }
+       }
+}
+
+static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob))
+{
+       KeyBlock *kb;
+       Key *key = me->key;
+       int i;
+       const size_t shape_alloc_len = sizeof(float) * 3 * me->totvert;
+
+       if (!me->key)
+               return;
+
+       /* ensure we can use mesh vertex count for derived mesh custom data */
+       if (me->totvert != dm->getNumVerts(dm)) {
+               fprintf(stderr,
+                       "%s: vertex size mismatch (mesh/dm) '%s' (%d != %d)\n",
+                       __func__, me->id.name+2, me->totvert, dm->getNumVerts(dm));
+               return;
+       }
+
+       for (i=0, kb=key->block.first; kb; kb=kb->next, i++) {
+               int ci;
+               float *array;
+
+               if (me->totvert != kb->totelem) {
+                       fprintf(stderr,
+                               "%s: vertex size mismatch (mesh/keyblock) '%s' (%d != %d)\n",
+                               __func__, me->id.name+2, me->totvert, kb->totelem);
+                       array = MEM_callocN(shape_alloc_len, __func__);
+               }
+               else {
+                       array = MEM_mallocN(shape_alloc_len, __func__);
+                       memcpy(array, kb->data, shape_alloc_len);
+               }
+
+               CustomData_add_layer_named(&dm->vertData, CD_SHAPEKEY, CD_ASSIGN, array, dm->numVertData, kb->name);
+               ci = CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i);
+
+               dm->vertData.layers[ci].uid = kb->uid;
+       }
+}
+
 /* new value for useDeform -1  (hack for the gameengine):
  * - apply only the modifier stack of the object, skipping the virtual modifiers,
  * - don't apply the key
@@ -845,14 +1254,15 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
 static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos)[3],
                                                                DerivedMesh **deform_r, DerivedMesh **final_r,
                                                                int useRenderParams, int useDeform,
-                                                               int needMapping, CustomDataMask dataMask, int index, int useCache)
+                                                               int needMapping, CustomDataMask dataMask, 
+                                                               int index, int useCache, int build_shapekey_layers)
 {
        Mesh *me = ob->data;
        ModifierData *firstmd, *md, *previewmd = NULL;
        LinkNode *datamasks, *curr;
        CustomDataMask mask, nextmask, append_mask = 0;
        float (*deformedVerts)[3] = NULL;
-       DerivedMesh *dm, *orcodm, *clothorcodm, *finaldm;
+       DerivedMesh *dm=NULL, *orcodm, *clothorcodm, *finaldm;
        int numVerts = me->totvert;
        int required_mode;
        int isPrevDeform= FALSE;
@@ -940,7 +1350,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                 */
                if (deform_r) {
                        *deform_r = CDDM_from_mesh(me, ob);
-
+                        
+                       if (build_shapekey_layers)
+                               add_shapekey_layers(dm, me, ob);
+                       
                        if(deformedVerts) {
                                CDDM_apply_vert_coords(*deform_r, deformedVerts);
                                CDDM_calc_normals(*deform_r);
@@ -1054,6 +1467,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                        } else {
                                dm = CDDM_from_mesh(me, ob);
 
+                               if (build_shapekey_layers)
+                                       add_shapekey_layers(dm, me, ob);
+
                                if(deformedVerts) {
                                        CDDM_apply_vert_coords(dm, deformedVerts);
                                        CDDM_calc_normals(dm);
@@ -1073,11 +1489,11 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                                        /* calc */
                                        DM_add_vert_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
                                        DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
-                                       DM_add_face_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
+                                       DM_add_poly_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
 
                                        range_vn_i(DM_get_vert_data_layer(dm, CD_ORIGINDEX), dm->numVertData, 0);
                                        range_vn_i(DM_get_edge_data_layer(dm, CD_ORIGINDEX), dm->numEdgeData, 0);
-                                       range_vn_i(DM_get_face_data_layer(dm, CD_ORIGINDEX), dm->numFaceData, 0);
+                                       range_vn_i(DM_get_poly_data_layer(dm, CD_ORIGINDEX), dm->numPolyData, 0);
                                }
                        }
 
@@ -1096,7 +1512,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                        /* add an origspace layer if needed */
                        if(((CustomDataMask)GET_INT_FROM_POINTER(curr->link)) & CD_MASK_ORIGSPACE)
                                if(!CustomData_has_layer(&dm->faceData, CD_ORIGSPACE))
-                                       DM_add_face_layer(dm, CD_ORIGSPACE, CD_DEFAULT, NULL);
+                                       DM_add_tessface_layer(dm, CD_ORIGSPACE, CD_DEFAULT, NULL);
 
                        ndm = mti->applyModifier(md, ob, dm, useRenderParams, useCache);
 
@@ -1196,10 +1612,21 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                        DM_update_weight_mcol(ob, finaldm, draw_flag, NULL, 0, NULL);
 #endif
        } else {
-               finaldm = CDDM_from_mesh(me, ob);
+               int recalc_normals= 0;
 
+               finaldm = CDDM_from_mesh(me, ob);
+               
+               if(build_shapekey_layers) {
+                       add_shapekey_layers(finaldm, me, ob);
+                       recalc_normals= 1;
+               }
+               
                if(deformedVerts) {
                        CDDM_apply_vert_coords(finaldm, deformedVerts);
+                       recalc_normals= 1;
+               }
+
+               if(recalc_normals) {
                        CDDM_calc_normals(finaldm);
                }
 
@@ -1228,6 +1655,21 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
        }
 #endif /* WITH_GAMEENGINE */
 
+       /* --------------------------------------------------------------------- */
+       /* First calculate the polygon and vertex normals, re-tesselation
+        * copies these into the tessface's normal layer */
+       finaldm->calcNormals(finaldm);
+       /* Re-tesselation is necessary to push render data (uvs, textures, colors)
+        * from loops and polys onto the tessfaces. This may be currently be
+        * redundantin cases where the render mode doesn't use these inputs, but
+        * ideally eventually tesselation would happen on-demand, and this is one
+        * of the primary places it would be needed. */
+       finaldm->recalcTesselation(finaldm);
+       /* Need to watch this, it can cause issues, see bug [#29338]             */
+       /* take care with this block, we really need testing frameworks          */
+       /* --------------------------------------------------------------------- */
+
+
        *final_r = finaldm;
 
        if(orcodm)
@@ -1241,21 +1683,24 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
        BLI_linklist_free(datamasks, NULL);
 }
 
-float (*editmesh_get_vertex_cos(EditMesh *em, int *numVerts_r))[3]
+float (*editbmesh_get_vertex_cos(BMEditMesh *em, int *numVerts_r))[3]
 {
-       int i, numVerts = *numVerts_r = BLI_countlist(&em->verts);
+       int i, numVerts = *numVerts_r = em->bm->totvert;
        float (*cos)[3];
-       EditVert *eve;
+       BMIter iter;
+       BMVert *eve;
 
-       cos = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos");
-       for (i=0,eve=em->verts.first; i<numVerts; i++,eve=eve->next) {
+       cos = MEM_mallocN(sizeof(float)*3*numVerts, "vertexcos");
+
+       eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+       for (i=0; eve; eve=BMIter_Step(&iter), i++) {
                copy_v3_v3(cos[i], eve->co);
        }
 
        return cos;
 }
 
-int editmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *dm)
+int editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *dm)
 {
        ModifierTypeInfo *mti = modifierType_getInfo(md->type);
        int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
@@ -1269,7 +1714,7 @@ int editmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *dm
        return 1;
 }
 
-static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, DerivedMesh **cage_r,
+static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, DerivedMesh **cage_r,
                                                                        DerivedMesh **final_r,
                                                                        CustomDataMask dataMask)
 {
@@ -1284,7 +1729,7 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri
        modifiers_clearErrors(ob);
 
        if(cage_r && cageIndex == -1) {
-               *cage_r = editmesh_get_derived(em, NULL);
+               *cage_r = getEditDerivedBMesh(em, ob, NULL);
        }
 
        dm = NULL;
@@ -1298,7 +1743,7 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri
 
                md->scene= scene;
                
-               if(!editmesh_modifier_is_enabled(scene, md, dm))
+               if(!editbmesh_modifier_is_enabled(scene, md, dm))
                        continue;
 
                /* add an orco layer if needed by this modifier */
@@ -1326,7 +1771,7 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri
                                                MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv");
                                        dm->getVertCos(dm, deformedVerts);
                                } else {
-                                       deformedVerts = editmesh_get_vertex_cos(em, &numVerts);
+                                       deformedVerts = editbmesh_get_vertex_cos(em, &numVerts);
                                }
                        }
 
@@ -1352,7 +1797,7 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri
                                }
 
                        } else {
-                               dm = CDDM_from_editmesh(em, ob->data);
+                               dm = CDDM_from_BMEditMesh(em, ob->data, FALSE, FALSE);
 
                                if(deformedVerts) {
                                        CDDM_apply_vert_coords(dm, deformedVerts);
@@ -1388,7 +1833,7 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri
 
                        if(mask & CD_MASK_ORIGSPACE)
                                if(!CustomData_has_layer(&dm->faceData, CD_ORIGSPACE))
-                                       DM_add_face_layer(dm, CD_ORIGSPACE, CD_DEFAULT, NULL);
+                                       DM_add_tessface_layer(dm, CD_ORIGSPACE, CD_DEFAULT, NULL);
                        
                        if (mti->applyModifierEM)
                                ndm = mti->applyModifierEM(md, ob, em, dm);
@@ -1416,7 +1861,7 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri
                                *cage_r = dm;
                        } else {
                                *cage_r =
-                                       editmesh_get_derived(em,
+                                       getEditDerivedBMesh(em, ob,
                                                deformedVerts ? MEM_dupallocN(deformedVerts) : NULL);
                        }
                }
@@ -1434,16 +1879,26 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri
                if(!(cage_r && dm == *cage_r)) dm->release(dm);
 
                CDDM_apply_vert_coords(*final_r, deformedVerts);
-               CDDM_calc_normals(*final_r);
+               CDDM_calc_normals(*final_r); /* was CDDM_calc_normals_mapping - campbell */
        } else if (dm) {
                *final_r = dm;
+               (*final_r)->calcNormals(*final_r); /* BMESH_ONLY - BMESH_TODO. check if this is needed */
        } else if (!deformedVerts && cage_r && *cage_r) {
                *final_r = *cage_r;
+               (*final_r)->calcNormals(*final_r); /* BMESH_ONLY - BMESH_TODO. check if this is needed */
        } else {
-               *final_r = editmesh_get_derived(em, deformedVerts);
+               *final_r = getEditDerivedBMesh(em, ob, deformedVerts);
                deformedVerts = NULL;
+               (*final_r)->calcNormals(*final_r); /* BMESH_ONLY - BMESH_TODO. check if this is needed */
        }
 
+       /* --- */
+       /* BMESH_ONLY, ensure tessface's used for drawing,
+        * but dont recalculate if the last modifier in the stack gives us tessfaces  */
+       DM_ensure_tessface(*final_r);
+       if (cage_r && (*cage_r != *final_r)) DM_ensure_tessface(*cage_r);
+       /* --- */
+
        /* add an orco layer if needed */
        if(dataMask & CD_MASK_ORCO)
                add_orco_dm(ob, em, *final_r, orcodm, CD_ORCO);
@@ -1487,18 +1942,19 @@ static void clear_mesh_caches(Object *ob)
        }
 }
 
-static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask)
+static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask,
+                            int build_shapekey_layers)
 {
        Object *obact = scene->basact?scene->basact->object:NULL;
-       int editing = paint_facesel_test(ob) || paint_vertsel_test(ob);/* paint_vertsel_test */
+       int editing = paint_facesel_test(ob);
        /* weight paint and face select need original indices because of selection buffer drawing */
-       int needMapping = (ob==obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT|OB_MODE_VERTEX_PAINT)));
+       int needMapping = (ob==obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT|OB_MODE_VERTEX_PAINT|OB_MODE_TEXTURE_PAINT)));
 
        clear_mesh_caches(ob);
 
        mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform,
                                                &ob->derivedFinal, 0, 1,
-                                               needMapping, dataMask, -1, 1);
+                                               needMapping, dataMask, -1, 1, build_shapekey_layers);
 
        DM_set_object_boundbox (ob, ob->derivedFinal);
 
@@ -1507,7 +1963,7 @@ static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask)
        ob->lastDataMask = dataMask;
 }
 
-static void editmesh_build_data(Scene *scene, Object *obedit, EditMesh *em, CustomDataMask dataMask)
+static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
 {
        clear_mesh_caches(obedit);
 
@@ -1524,7 +1980,7 @@ static void editmesh_build_data(Scene *scene, Object *obedit, EditMesh *em, Cust
                em->derivedCage = NULL;
        }
 
-       editmesh_calc_modifiers(scene, obedit, em, &em->derivedCage, &em->derivedFinal, dataMask);
+       editbmesh_calc_modifiers(scene, obedit, em, &em->derivedCage, &em->derivedFinal, dataMask);
        DM_set_object_boundbox (obedit, em->derivedFinal);
 
        em->lastDataMask = dataMask;
@@ -1532,12 +1988,13 @@ static void editmesh_build_data(Scene *scene, Object *obedit, EditMesh *em, Cust
        em->derivedCage->needsFree = 0;
 }
 
-void makeDerivedMesh(Scene *scene, Object *ob, EditMesh *em, CustomDataMask dataMask)
+void makeDerivedMesh(Scene *scene, Object *ob, BMEditMesh *em,
+                     CustomDataMask dataMask, int build_shapekey_layers)
 {
        if (em) {
-               editmesh_build_data(scene, ob, em, dataMask);
+               editbmesh_build_data(scene, ob, em, dataMask);
        } else {
-               mesh_build_data(scene, ob, dataMask);
+               mesh_build_data(scene, ob, dataMask, build_shapekey_layers);
        }
 }
 
@@ -1549,7 +2006,7 @@ DerivedMesh *mesh_get_derived_final(Scene *scene, Object *ob, CustomDataMask dat
         * the data we need, rebuild the derived mesh
         */
        if(!ob->derivedFinal || (dataMask & ob->lastDataMask) != dataMask)
-               mesh_build_data(scene, ob, dataMask);
+               mesh_build_data(scene, ob, dataMask, 0);
 
        return ob->derivedFinal;
 }
@@ -1560,7 +2017,7 @@ DerivedMesh *mesh_get_derived_deform(Scene *scene, Object *ob, CustomDataMask da
         * the data we need, rebuild the derived mesh
         */
        if(!ob->derivedDeform || (dataMask & ob->lastDataMask) != dataMask)
-               mesh_build_data(scene, ob, dataMask);
+               mesh_build_data(scene, ob, dataMask, 0);
 
        return ob->derivedDeform;
 }
@@ -1569,7 +2026,7 @@ DerivedMesh *mesh_create_derived_render(Scene *scene, Object *ob, CustomDataMask
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1578,7 +2035,7 @@ DerivedMesh *mesh_create_derived_index_render(Scene *scene, Object *ob, CustomDa
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, index, 0);
+       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, index, 0, 0);
 
        return final;
 }
@@ -1587,7 +2044,7 @@ DerivedMesh *mesh_create_derived_view(Scene *scene, Object *ob, CustomDataMask d
 {
        DerivedMesh *final;
 
-       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 0, 1, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 0, 1, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1597,7 +2054,7 @@ DerivedMesh *mesh_create_derived_no_deform(Scene *scene, Object *ob, float (*ver
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, 0, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, 0, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1607,7 +2064,7 @@ DerivedMesh *mesh_create_derived_no_virtual(Scene *scene, Object *ob, float (*ve
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 0, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1617,7 +2074,7 @@ DerivedMesh *mesh_create_derived_physics(Scene *scene, Object *ob, float (*vertC
 {
        DerivedMesh *final;
        
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 1, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 1, dataMask, -1, 0, 0);
 
        return final;
 }
@@ -1628,14 +2085,14 @@ DerivedMesh *mesh_create_derived_no_deform_render(Scene *scene, Object *ob,
 {
        DerivedMesh *final;
 
-       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 1, 0, 0, dataMask, -1, 0);
+       mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 1, 0, 0, dataMask, -1, 0, 0);
 
        return final;
 }
 
 /***/
 
-DerivedMesh *editmesh_get_derived_cage_and_final(Scene *scene, Object *obedit, EditMesh *em, DerivedMesh **final_r,
+DerivedMesh *editbmesh_get_derived_cage_and_final(Scene *scene, Object *obedit, BMEditMesh *em, DerivedMesh **final_r,
                                                                                                 CustomDataMask dataMask)
 {
        /* if there's no derived mesh or the last data mask used doesn't include
@@ -1643,27 +2100,27 @@ DerivedMesh *editmesh_get_derived_cage_and_final(Scene *scene, Object *obedit, E
         */
        if(!em->derivedCage ||
           (em->lastDataMask & dataMask) != dataMask)
-               editmesh_build_data(scene, obedit, em, dataMask);
+               editbmesh_build_data(scene, obedit, em, dataMask);
 
        *final_r = em->derivedFinal;
        return em->derivedCage;
 }
 
-DerivedMesh *editmesh_get_derived_cage(Scene *scene, Object *obedit, EditMesh *em, CustomDataMask dataMask)
+DerivedMesh *editbmesh_get_derived_cage(Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
 {
        /* if there's no derived mesh or the last data mask used doesn't include
         * the data we need, rebuild the derived mesh
         */
        if(!em->derivedCage ||
           (em->lastDataMask & dataMask) != dataMask)
-               editmesh_build_data(scene, obedit, em, dataMask);
+               editbmesh_build_data(scene, obedit, em, dataMask);
 
        return em->derivedCage;
 }
 
-DerivedMesh *editmesh_get_derived_base(Object *UNUSED(obedit), EditMesh *em)
+DerivedMesh *editbmesh_get_derived_base(Object *obedit, BMEditMesh *em)
 {
-       return editmesh_get_derived(em, NULL);
+       return getEditDerivedBMesh(em, obedit, NULL);
 }
 
 
@@ -1703,7 +2160,7 @@ float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob)
        if(ob->type!=OB_MESH || me->totvert==0)
                return NULL;
        
-       dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+       dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH|CD_MASK_ORIGINDEX);
        vertexcosnos= MEM_callocN(6*sizeof(float)*me->totvert, "vertexcosnos map");
        
        if(dm->foreachMappedVert) {
@@ -1733,7 +2190,7 @@ typedef struct
        MVert * mvert;          // vertices & normals
        float (*orco)[3];
        float (*tangent)[4];    // destination
-       int numFaces;
+       int numTessFaces;
 
 } SGLSLMeshToTangent;
 
@@ -1743,7 +2200,7 @@ typedef struct
 static int GetNumFaces(const SMikkTSpaceContext * pContext)
 {
        SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
-       return pMesh->numFaces;
+       return pMesh->numTessFaces;
 }
 
 static int GetNumVertsOfFace(const SMikkTSpaceContext * pContext, const int face_num)
@@ -1832,15 +2289,15 @@ void DM_add_tangent_layer(DerivedMesh *dm)
        if(CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1)
                return;
 
-       nors = dm->getFaceDataArray(dm, CD_NORMAL);
+       nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
 
        /* check we have all the needed layers */
        totvert= dm->getNumVerts(dm);
-       totface= dm->getNumFaces(dm);
+       totface= dm->getNumTessFaces(dm);
 
        mvert= dm->getVertArray(dm);
-       mface= dm->getFaceArray(dm);
-       mtface= dm->getFaceDataArray(dm, CD_MTFACE);
+       mface= dm->getTessFaceArray(dm);
+       mtface= dm->getTessFaceDataArray(dm, CD_MTFACE);
 
        if(!mtface) {
                orco= dm->getVertDataArray(dm, CD_ORCO);
@@ -1849,8 +2306,8 @@ void DM_add_tangent_layer(DerivedMesh *dm)
        }
        
        /* create tangent layer */
-       DM_add_face_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
-       tangent= DM_get_face_data_layer(dm, CD_TANGENT);
+       DM_add_tessface_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
+       tangent= DM_get_tessface_data_layer(dm, CD_TANGENT);
        
        /* allocate some space */
        arena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "tangent layer arena");
@@ -1870,7 +2327,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
                mesh2tangent.mvert = mvert;
                mesh2tangent.orco = orco;
                mesh2tangent.tangent = tangent;
-               mesh2tangent.numFaces = totface;
+               mesh2tangent.numTessFaces = totface;
 
                sContext.m_pUserData = &mesh2tangent;
                sContext.m_pInterface = &sInterface;
@@ -1963,11 +2420,11 @@ void DM_add_tangent_layer(DerivedMesh *dm)
 void DM_calc_auto_bump_scale(DerivedMesh *dm)
 {
        /* int totvert= dm->getNumVerts(dm); */ /* UNUSED */
-       int totface= dm->getNumFaces(dm);
+       int totface= dm->getNumTessFaces(dm);
 
        MVert * mvert = dm->getVertArray(dm);
-       MFace * mface = dm->getFaceArray(dm);
-       MTFace * mtface = dm->getFaceDataArray(dm, CD_MTFACE);
+       MFace * mface = dm->getTessFaceArray(dm);
+       MTFace * mtface = dm->getTessFaceDataArray(dm, CD_MTFACE);
 
        if(mtface)
        {
@@ -2124,15 +2581,8 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
        memset(attribs, 0, sizeof(DMVertexAttribs));
 
        vdata = &dm->vertData;
-       fdata = &dm->faceData;
-
-       /* ugly hack, editmesh derivedmesh doesn't copy face data, this way we
-        * can use offsets instead */
-       if(dm->type == DM_TYPE_EDITMESH)
-               tfdata = &((EditMeshDerivedMesh*)dm)->em->fdata;
-       else
-               tfdata = fdata;
-
+       fdata = tfdata = dm->getTessFaceDataLayout(dm);
+       
        /* calc auto bump scale if necessary */
        if(dm->auto_bump_scale<=0.0f)
                DM_calc_auto_bump_scale(dm);
@@ -2158,8 +2608,30 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
                                attribs->tface[a].array = tfdata->layers[layer].data;
                                attribs->tface[a].emOffset = tfdata->layers[layer].offset;
                                attribs->tface[a].glIndex = gattribs->layer[b].glindex;
-                               attribs->tface[a].glTexco = gattribs->layer[b].gltexco;
+                               /* attribs->tface[a].glTexco = gattribs->layer[b].gltexco; */ /* BMESH_TODO, trunk has this but not bmesh, need to investigate whats going on here - campbell */
                        }
+                       /* BMESH ONLY, may need to get this working?, otherwise remove */
+                       /* else {
+                               int player;
+                               CustomData *pdata = dm->getPolyDataLayout(dm);
+                               
+                               if(gattribs->layer[b].name[0])
+                                       player = CustomData_get_named_layer_index(pdata, CD_MTEXPOLY,
+                                               gattribs->layer[b].name);
+                               else
+                                       player = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY);
+                               
+                               if (player != -1) {
+                                       a = attribs->tottface++;
+       
+                                       attribs->tface[a].array = NULL;
+                                       attribs->tface[a].emOffset = pdata->layers[layer].offset;
+                                       attribs->tface[a].glIndex = gattribs->layer[b].glindex;
+                                       attribs->tface[a].glTexco = gattribs->layer[b].gltexco;
+                                       
+                               }
+                       }
+                       */
                }
                else if(gattribs->layer[b].type == CD_MCOL) {
                        /* vertex colors */
@@ -2262,7 +2734,7 @@ static void navmesh_drawColored(DerivedMesh *dm)
                DEBUG_VBO( "Using legacy code. drawNavMeshColored\n" );
                //glShadeModel(GL_SMOOTH);
                glBegin(glmode = GL_QUADS);
-               for(a = 0; a < dm->numFaceData; a++, mface++) {
+               for(a = 0; a < dm->numTessFaceData; a++, mface++) {
                        int new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES;
                        int pi = polygonIdx[a];
                        if (pi <= 0) {
@@ -2315,7 +2787,7 @@ static void navmesh_DM_drawFacesSolid(DerivedMesh *dm,
 static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm)
 {
        DerivedMesh *result;
-       int maxFaces = dm->getNumFaces(dm);
+       int maxFaces = dm->getNumPolys(dm);
        int *recastData;
        int vertsPerPoly=0, nverts=0, ndtris=0, npolys=0;
        float* verts=NULL;
@@ -2429,14 +2901,15 @@ char *DM_debug_info(DerivedMesh *dm)
        BLI_dynstr_appendf(dynstr, "    'ptr': '%p',\n", (void *)dm);
        switch (dm->type) {
                case DM_TYPE_CDDM:     tstr = "DM_TYPE_CDDM";     break;
-               case DM_TYPE_EDITMESH: tstr = "DM_TYPE_EDITMESH";  break;
+               case DM_TYPE_EDITBMESH: tstr = "DM_TYPE_EDITMESH";  break;
                case DM_TYPE_CCGDM:    tstr = "DM_TYPE_CCGDM";     break;
                default:               tstr = "UNKNOWN";           break;
        }
        BLI_dynstr_appendf(dynstr, "    'type': '%s',\n", tstr);
        BLI_dynstr_appendf(dynstr, "    'numVertData': %d,\n", dm->numVertData);
        BLI_dynstr_appendf(dynstr, "    'numEdgeData': %d,\n", dm->numEdgeData);
-       BLI_dynstr_appendf(dynstr, "    'numFaceData': %d,\n", dm->numFaceData);
+       BLI_dynstr_appendf(dynstr, "    'numTessFaceData': %d,\n", dm->numTessFaceData);
+       BLI_dynstr_appendf(dynstr, "    'numPolyData': %d,\n", dm->numPolyData);
        BLI_dynstr_appendf(dynstr, "    'deformedOnly': %d,\n", dm->deformedOnly);
 
        BLI_dynstr_appendf(dynstr, "    'vertexLayers': (\n");
@@ -2447,8 +2920,12 @@ char *DM_debug_info(DerivedMesh *dm)
        dm_debug_info_layers(dynstr, dm, dm->getEdgeDataArray);
        BLI_dynstr_appendf(dynstr, "    ),\n");
 
-       BLI_dynstr_appendf(dynstr, "    'faceLayers': (\n");
-       dm_debug_info_layers(dynstr, dm, dm->getFaceDataArray);
+       BLI_dynstr_appendf(dynstr, "    'tessFaceLayers': (\n");
+       dm_debug_info_layers(dynstr, dm, dm->getTessFaceDataArray);
+       BLI_dynstr_appendf(dynstr, "    ),\n");
+
+       BLI_dynstr_appendf(dynstr, "    'PolyLayers': (\n");
+       dm_debug_info_layers(dynstr, dm, DM_get_poly_data_layer);
        BLI_dynstr_appendf(dynstr, "    ),\n");
 
        BLI_dynstr_appendf(dynstr, "}\n");
index fabc35361b9ad720906bb16535dcf48918e58398..11700d7f0728f2831409c3758992ede3ce72e11e 100644 (file)
@@ -65,6 +65,7 @@
 #include "BKE_particle.h"
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
+#include "BKE_tessmesh.h"
 #include "BKE_depsgraph.h"
 #include "BKE_anim.h"
 #include "BKE_report.h"
@@ -898,7 +899,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
        Scene *sce = NULL;
        Group *group = NULL;
        GroupObject * go = NULL;
-       EditMesh *em;
+       BMEditMesh *em;
        float vec[3], no[3], pmat[4][4];
        int totvert, a, oblay;
        unsigned int lay;
@@ -908,11 +909,10 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
        /* simple preventing of too deep nested groups */
        if(level>MAX_DUPLI_RECUR) return;
        
-       em = BKE_mesh_get_editmesh(me);
+       em = me->edit_btmesh;
        
        if(em) {
-               dm= editmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
-               BKE_mesh_end_editmesh(me, em);
+               dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
        } else
                dm= mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH);
        
@@ -974,7 +974,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
                                        /* mballs have a different dupli handling */
                                        if(ob->type!=OB_MBALL) ob->flag |= OB_DONE;     /* doesnt render */
 
-                                       if(me->edit_mesh) {
+                                       if(me->edit_btmesh) {
                                                dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void*) &vdd);
                                        }
                                        else {
@@ -1015,44 +1015,45 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
        DupliObject *dob;
        DerivedMesh *dm;
        Mesh *me= par->data;
-       MTFace *mtface;
-       MFace *mface;
+       MLoopUV *mloopuv;
+       MPoly *mpoly, *mp;
+       MLoop *mloop;
        MVert *mvert;
        float pmat[4][4], imat[3][3], (*orco)[3] = NULL, w;
        int lay, oblay, totface, a;
        Scene *sce = NULL;
        Group *group = NULL;
        GroupObject *go = NULL;
-       EditMesh *em;
+       BMEditMesh *em;
        float ob__obmat[4][4]; /* needed for groups where the object matrix needs to be modified */
        
        /* simple preventing of too deep nested groups */
        if(level>MAX_DUPLI_RECUR) return;
        
        copy_m4_m4(pmat, par->obmat);
-       
-       em = BKE_mesh_get_editmesh(me);
+       em = me->edit_btmesh;
+
        if(em) {
-               dm= editmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
-               BKE_mesh_end_editmesh(me, em);
+               dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
        }
        else {
                dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH);
        }
 
-       totface= dm->getNumFaces(dm);
-       mface= dm->getFaceArray(dm);
+       totface= dm->getNumPolys(dm);
+       mpoly= dm->getPolyArray(dm);
+       mloop= dm->getLoopArray(dm);
        mvert= dm->getVertArray(dm);
 
        if(G.rendering) {
 
                orco= (float(*)[3])get_mesh_orco_verts(par);
                transform_mesh_orco_verts(me, orco, me->totvert, 0);
-               mtface= me->mtface;
+               mloopuv= me->mloopuv;
        }
        else {
                orco= NULL;
-               mtface= NULL;
+               mloopuv= NULL;
        }
        
        /* having to loop on scene OR group objects is NOT FUN */
@@ -1096,22 +1097,36 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                        /* mballs have a different dupli handling */
                                        if(ob->type!=OB_MBALL) ob->flag |= OB_DONE;     /* doesnt render */
 
-                                       for(a=0; a<totface; a++) {
-                                               int mv1 = mface[a].v1;
-                                               int mv2 = mface[a].v2;
-                                               int mv3 = mface[a].v3;
-                                               int mv4 = mface[a].v4;
-                                               float *v1= mvert[mv1].co;
-                                               float *v2= mvert[mv2].co;
-                                               float *v3= mvert[mv3].co;
-                                               float *v4= (mv4)? mvert[mv4].co: NULL;
+                                       for(a=0, mp= mpoly; a<totface; a++, mp++) {
+                                               int mv1;
+                                               int mv2;
+                                               int mv3;
+                                               /* int mv4; */ /* UNUSED */
+                                               float *v1;
+                                               float *v2;
+                                               float *v3;
+                                               /* float *v4; */ /* UNUSED */
                                                float cent[3], quat[4], mat[3][3], mat3[3][3], tmat[4][4], obmat[4][4];
+                                               MLoop *loopstart= mloop + mp->loopstart;
+
+                                               if (mp->totloop < 3) {
+                                                       /* highly unlikely but to be safe */
+                                                       continue;
+                                               }
+                                               else {
+                                                       v1= mvert[(mv1= loopstart[0].v)].co;
+                                                       v2= mvert[(mv2= loopstart[1].v)].co;
+                                                       v3= mvert[(mv3= loopstart[2].v)].co;
+                                                       /*
+                                                       if (mp->totloop > 3) {
+                                                               v4= mvert[(mv4= loopstart[3].v)].co;
+                                                       }
+                                                       */
+                                               }
 
                                                /* translation */
-                                               if(v4)
-                                                       cent_quad_v3(cent, v1, v2, v3, v4);
-                                               else
-                                                       cent_tri_v3(cent, v1, v2, v3);
+                                               mesh_calc_poly_center(mp, loopstart, mvert, cent);
+
                                                mul_m4_v3(pmat, cent);
                                                
                                                sub_v3_v3v3(cent, cent, pmat[3]);
@@ -1127,7 +1142,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                                
                                                /* scale */
                                                if(par->transflag & OB_DUPLIFACES_SCALE) {
-                                                       float size= v4? area_quad_v3(v1, v2, v3, v4): area_tri_v3(v1, v2, v3);
+                                                       float size= mesh_calc_poly_area(mp, loopstart, mvert, NULL);
                                                        size= sqrtf(size) * par->dupfacesca;
                                                        mul_m3_fl(mat, size);
                                                }
@@ -1140,23 +1155,19 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                                
                                                dob= new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIFACES, animated);
                                                if(G.rendering) {
-                                                       w= (mv4)? 0.25f: 1.0f/3.0f;
+                                                       w= 1.0f / (float)mp->totloop;
 
                                                        if(orco) {
-                                                               madd_v3_v3v3fl(dob->orco, dob->orco, orco[mv1], w);
-                                                               madd_v3_v3v3fl(dob->orco, dob->orco, orco[mv2], w);
-                                                               madd_v3_v3v3fl(dob->orco, dob->orco, orco[mv3], w);
-                                                               if (mv4) {
-                                                                       madd_v3_v3v3fl(dob->orco, dob->orco, orco[mv4], w);
+                                                               int j;
+                                                               for (j = 0; j < mpoly->totloop; j++) {
+                                                                       madd_v3_v3fl(dob->orco, orco[loopstart[j].v], w);
                                                                }
                                                        }
 
-                                                       if(mtface) {
-                                                               madd_v2_v2v2fl(dob->uv, dob->uv, mtface[a].uv[0], w);
-                                                               madd_v2_v2v2fl(dob->uv, dob->uv, mtface[a].uv[1], w);
-                                                               madd_v2_v2v2fl(dob->uv, dob->uv, mtface[a].uv[2], w);
-                                                               if (mv4) {
-                                                                       madd_v2_v2v2fl(dob->uv, dob->uv, mtface[a].uv[3], w);
+                                                       if(mloopuv) {
+                                                               int j;
+                                                               for (j = 0; j < mpoly->totloop; j++) {
+                                                                       madd_v2_v2fl(dob->orco, mloopuv[loopstart[j].v].uv, w);
                                                                }
                                                        }
                                                }
index 02b9330d5882ed451727864b97f8ed48db90c45a..9511ce0c4282df99caf2a1df49eac3cc0d29f100 100644 (file)
@@ -945,7 +945,6 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
                        else dvert = NULL;
                } else
                        dvert = NULL;
-
                if(armature_def_nr >= 0 && dvert) {
                        armature_weight= defvert_find_weight(dvert, armature_def_nr);
 
index a8644618945ee58aa459f77b24b545b5e0c0d26e..9534dfd9d0b1e8cd9dc5eac03c8711165641b6d8 100644 (file)
@@ -57,6 +57,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_bpath.h"
 #include "BLI_dynstr.h"
+#include "BLI_path_util.h"
 #include "BLI_utildefines.h"
 #include "BLI_callbacks.h"
 
@@ -698,11 +699,19 @@ char *BKE_undo_menu_string(void)
 
        /* saves quit.blend */
 void BKE_undo_save_quit(void)
+{
+       char str[FILE_MAXDIR+FILE_MAXFILE];
+
+       BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
+
+       BKE_undo_save(str);
+}
+
+void BKE_undo_save(char *fname)
 {
        UndoElem *uel;
        MemFileChunk *chunk;
        int file;
-       char str[FILE_MAX];
        
        if( (U.uiflag & USER_GLOBALUNDO)==0) return;
        
@@ -715,9 +724,7 @@ void BKE_undo_save_quit(void)
        /* no undo state to save */
        if(undobase.first==undobase.last) return;
                
-       BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
-
-       file = open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
+       file = open(fname, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
        if(file == -1) {
                //XXX error("Unable to save %s, check you have permissions", str);
                return;
@@ -731,8 +738,8 @@ void BKE_undo_save_quit(void)
        
        close(file);
        
-       if(chunk) ; //XXX error("Unable to save %s, internal error", str);
-       else printf("Saved session recovery to %s\n", str);
+       if(chunk) ; //XXX error("Unable to save %s, internal error", fname);
+       else printf("Saved session recovery to %s\n", fname);
 }
 
 /* sets curscene */
index 1aad0a242f98b9c56059cae58da41e37864b59c6..c9ab126d7abfba5512d8931f459c2c2a36d59181 100644 (file)
@@ -41,7 +41,7 @@
 #include "BLI_linklist.h"
 
 #include "BKE_DerivedMesh.h"
-
+#include "BKE_tessmesh.h"
 
 #include "BLI_math.h"
 #include "MEM_guardedalloc.h"
@@ -555,7 +555,7 @@ BVHTree* bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float
 
                data->mesh = mesh;
                data->vert = mesh->getVertDataArray(mesh, CD_MVERT);
-               data->face = mesh->getFaceDataArray(mesh, CD_MFACE);
+               data->face = mesh->getTessFaceDataArray(mesh, CD_MFACE);
 
                data->sphere_radius = epsilon;
        }
@@ -572,22 +572,87 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float
        if(tree == NULL)
        {
                int i;
-               int numFaces= mesh->getNumFaces(mesh);
-               MVert *vert     = mesh->getVertDataArray(mesh, CD_MVERT);
-               MFace *face = mesh->getFaceDataArray(mesh, CD_MFACE);
+               int numFaces= mesh->getNumTessFaces(mesh);
 
-               if(vert != NULL && face != NULL)
+               /* BMESH spesific check that we have tessfaces,
+                * we _could_ tesselate here but rather not - campbell
+                *
+                * this assert checks we have tessfaces,
+                * if not caller should use DM_ensure_tessface() */
+               BLI_assert(!(numFaces == 0 && mesh->getNumPolys(mesh) != 0));
+
+               if(numFaces != 0)
                {
                        /* Create a bvh-tree of the given target */
                        tree = BLI_bvhtree_new(numFaces, epsilon, tree_type, axis);
                        if(tree != NULL)
                        {
-                               /* XXX, for snap only, em & dm are assumed to be aligned, since dm is the em's cage */
-                               EditMesh *em= data->em_evil;
+                               BMEditMesh *em= data->em_evil;
                                if(em) {
-                                       EditFace *efa= em->faces.first;
-                                       for(i = 0; i < numFaces; i++, efa= efa->next) {
-                                               if(!(efa->f & 1) && efa->h==0 && !((efa->v1->f&1)+(efa->v2->f&1)+(efa->v3->f&1)+(efa->v4?efa->v4->f&1:0))) {
+                                       /*data->em_evil is only set for snapping, and only for the mesh of the object
+                                         which is currently open in edit mode. When set, the bvhtree should not contain
+                                         faces that will interfere with snapping (e.g. faces that are hidden/selected
+                                         or faces that have selected verts).*/
+
+                                       /* XXX, for snap only, em & dm are assumed to be aligned, since dm is the em's cage */
+
+                                       /*Insert BMesh-tesselation triangles into the bvh tree, unless they are hidden