The Death Of Editmesh - Part 1
authorJoseph Eagar <joeedh@gmail.com>
Thu, 28 Jan 2010 00:45:30 +0000 (00:45 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Thu, 28 Jan 2010 00:45:30 +0000 (00:45 +0000)
I've removed editmesh altogether (other then scanfill, which is
seperate code that happens to reuse the editmesh structures).
The compatibility layer I had written for old editmesh tools
was more trouble then it was worth, though it did help in the
early stages of this project.

There's a fair amount of breakage, and there's bunches of tools
(mostly minor ones) I need to port over still.  Biggest ones are
join triangles and loop to region, and spin/screw.

This probably isn't really testable, I'll hopefully have more
work done on this soon, but might not be before next week.

43 files changed:
projectfiles_vc9/BL_bmesh/BL_bmesh.vcproj
projectfiles_vc9/blender/editors/ED_editors.vcproj
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/editderivedbmesh.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/bmesh/intern/bmesh_opdefines.c
source/blender/bmesh/intern/bmesh_operators_private.h
source/blender/bmesh/intern/bmesh_to_editmesh.c
source/blender/bmesh/intern/editmesh_to_bmesh.c
source/blender/bmesh/operators/connectops.c
source/blender/bmesh/operators/join_triangles.c [new file with mode: 0644]
source/blender/bmesh/operators/primitiveops.c [new file with mode: 0644]
source/blender/bmesh/operators/removedoubles.c
source/blender/bmesh/operators/subdivideop.c
source/blender/editors/armature/reeb.c
source/blender/editors/include/ED_mesh.h
source/blender/editors/mesh/bmesh_select.c
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/mesh/bmeshutils.c
source/blender/editors/mesh/editbmesh_add.c [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/editmesh_tools.c [deleted file]
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/object/object_hook.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_transform.c
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/uvedit/uvedit_ops.c

index 3664ed4fe4c92f380fdf9ce26b1982a60ca54c03..bf534d94fd9b529e96502268616ec93890d9d76a 100644 (file)
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
-       ProjectType="Visual C++"
-       Version="9.00"
-       Name="BL_bmesh"
-       ProjectGUID="{6A51010A-9393-4D77-84B4-5BBCDA6E7C25}"
-       RootNamespace="BL_bmesh"
-       TargetFrameworkVersion="196613"
-       >
-       <Platforms>
-               <Platform
-                       Name="Win32"
-               />
-       </Platforms>
-       <ToolFiles>
-       </ToolFiles>
-       <Configurations>
-               <Configuration
-                       Name="Debug|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
-                       ConfigurationType="4"
-                       CharacterSet="2"
-                       >
-                       <Tool
-                               Name="VCPreBuildEventTool"
-                       />
-                       <Tool
-                               Name="VCCustomBuildTool"
-                       />
-                       <Tool
-                               Name="VCXMLDataGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCWebServiceProxyGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCMIDLTool"
-                       />
-                       <Tool
-                               Name="VCCLCompilerTool"
-                               Optimization="0"
-                               AdditionalIncludeDirectories="..\..\..\..\lib\windows\pthreads\include;..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\lib\windows\zlib\include;..\..\..\..\lib\windows\sdl\include;..\..\..\..\lib\windows\ffmpeg\include;..\..\..\..\build\msvc_9\intern\bmfont\include;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\iksolver\include;..\..\..\source\blender;..\..\..\source\blender\avi;..\..\..\source\blender\imbuf;..\..\..\source\blender\editors\include;..\..\..\source\blender\python;..\..\..\source\blender\blenlib;..\..\..\source\blender\blenkernel;..\..\..\source\blender\makesdna;..\..\..\source\blender\makesrna;..\..\..\source\blender\nodes;..\..\..\source\blender\blenloader;..\..\..\source\kernel\gen_system;..\..\..\source\blender\renderconverter;..\..\..\source\blender\render\extern\include;..\..\..\source\gameengine\SoundSystem;..\..\..\..\build\msvc_9\extern\verse\include;..\..\..\..\build\msvc_9\intern\opennl\include;..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\source\blender\gpu;..\..\source\blender\blenkernel;..\..\source\blender\makesdna;..\..\source\blender\blenlib;..\..\source\blender\bmesh;..\..\source\blender\editors\include;..\..\source\blender\bmesh\operators;..\..\source\blender\bmesh\intern;..\..\source\blender\editors\mesh"
-                               MinimalRebuild="true"
-                               BasicRuntimeChecks="3"
-                               RuntimeLibrary="1"
-                               WarningLevel="3"
-                               DebugInformationFormat="4"
-                       />
-                       <Tool
-                               Name="VCManagedResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCPreLinkEventTool"
-                       />
-                       <Tool
-                               Name="VCLibrarianTool"
-                               OutputFile="..\..\..\build\msvc_9\libs\debug\BL_bmesh.lib"
-                       />
-                       <Tool
-                               Name="VCALinkTool"
-                       />
-                       <Tool
-                               Name="VCXDCMakeTool"
-                       />
-                       <Tool
-                               Name="VCBscMakeTool"
-                       />
-                       <Tool
-                               Name="VCFxCopTool"
-                       />
-                       <Tool
-                               Name="VCPostBuildEventTool"
-                       />
-               </Configuration>
-               <Configuration
-                       Name="Release|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
-                       ConfigurationType="4"
-                       CharacterSet="2"
-                       WholeProgramOptimization="1"
-                       >
-                       <Tool
-                               Name="VCPreBuildEventTool"
-                       />
-                       <Tool
-                               Name="VCCustomBuildTool"
-                       />
-                       <Tool
-                               Name="VCXMLDataGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCWebServiceProxyGeneratorTool"
-                       />
-                       <Tool
-                               Name="VCMIDLTool"
-                       />
-                       <Tool
-                               Name="VCCLCompilerTool"
-                               Optimization="2"
-                               EnableIntrinsicFunctions="true"
-                               AdditionalIncludeDirectories="..\..\..\..\lib\windows\pthreads\include;..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\lib\windows\zlib\include;..\..\..\..\lib\windows\sdl\include;..\..\..\..\lib\windows\ffmpeg\include;..\..\..\..\build\msvc_9\intern\bmfont\include;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\iksolver\include;..\..\..\source\blender;..\..\..\source\blender\avi;..\..\..\source\blender\imbuf;..\..\..\source\blender\editors\include;..\..\..\source\blender\python;..\..\..\source\blender\blenlib;..\..\..\source\blender\blenkernel;..\..\..\source\blender\makesdna;..\..\..\source\blender\makesrna;..\..\..\source\blender\nodes;..\..\..\source\blender\blenloader;..\..\..\source\kernel\gen_system;..\..\..\source\blender\renderconverter;..\..\..\source\blender\render\extern\include;..\..\..\source\gameengine\SoundSystem;..\..\..\..\build\msvc_9\extern\verse\include;..\..\..\..\build\msvc_9\intern\opennl\include;..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\source\blender\gpu;..\..\source\blender\blenkernel;..\..\source\blender\makesdna;..\..\source\blender\blenlib;..\..\source\blender\bmesh;..\..\source\blender\editors\include;..\..\source\blender\bmesh\operators;..\..\source\blender\bmesh\intern;..\..\source\blender\editors\mesh"
-                               RuntimeLibrary="0"
-                               EnableFunctionLevelLinking="true"
-                               WarningLevel="3"
-                               DebugInformationFormat="3"
-                       />
-                       <Tool
-                               Name="VCManagedResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCResourceCompilerTool"
-                       />
-                       <Tool
-                               Name="VCPreLinkEventTool"
-                       />
-                       <Tool
-                               Name="VCLibrarianTool"
-                               OutputFile="..\..\..\build\msvc_9\libs\BL_bmesh.lib"
-                       />
-                       <Tool
-                               Name="VCALinkTool"
-                       />
-                       <Tool
-                               Name="VCXDCMakeTool"
-                       />
-                       <Tool
-                               Name="VCBscMakeTool"
-                       />
-                       <Tool
-                               Name="VCFxCopTool"
-                       />
-                       <Tool
-                               Name="VCPostBuildEventTool"
-                       />
-               </Configuration>
-       </Configurations>
-       <References>
-               <ProjectReference
-                       ReferencedProjectIdentifier="{31628053-825D-4C06-8A21-D13883489718}"
-                       RelativePathToProject=".\blenlib\BLI_blenlib.vcproj"
-               />
-               <ProjectReference
-                       ReferencedProjectIdentifier="{CAE37E91-6570-43AC-A4B4-7A37A4B0FC94}"
-                       RelativePathToProject=".\blenkernel\BKE_blenkernel.vcproj"
-               />
-               <ProjectReference
-                       ReferencedProjectIdentifier="{E013786A-9575-4F34-81B2-33290357EE87}"
-                       RelativePathToProject=".\makesdna\DNA_makesdna.vcproj"
-               />
-               <ProjectReference
-                       ReferencedProjectIdentifier="{1CC733F1-6AB5-4904-8F63-C08C46B79DD9}"
-                       RelativePathToProject="..\..\intern\guardedalloc\make\msvc_9_0\guardedalloc.vcproj"
-               />
-       </References>
-       <Files>
-               <Filter
-                       Name="Source Files"
-                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
-                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
-                       >
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_construct.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\bmesh_dupeops.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_eulers.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_filters.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_interp.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_iterators.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_marking.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_mesh.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_mods.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_opdefines.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_operators.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_operators_private.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_polygon.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_private.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_queries.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_structure.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_structure.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_to_editmesh.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_walkers.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\connectops.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\createops.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\dissolveops.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\edgesplitop.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\intern\editmesh_to_bmesh.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\extrudeops.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\mesh_conv.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\mirror.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\removedoubles.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\subdivideop.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\triangulateop.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\operators\utils.c"
-                               >
-                       </File>
-               </Filter>
-               <Filter
-                       Name="Header Files"
-                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
-                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
-                       >
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_error.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_filters.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_iterators.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_marking.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_operator_api.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_operators.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_queries.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\source\blender\bmesh\bmesh_walkers.h"
-                               >
-                       </File>
-               </Filter>
-       </Files>
-       <Globals>
-       </Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="9.00"\r
+       Name="BL_bmesh"\r
+       ProjectGUID="{6A51010A-9393-4D77-84B4-5BBCDA6E7C25}"\r
+       RootNamespace="BL_bmesh"\r
+       TargetFrameworkVersion="196613"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="4"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\..\lib\windows\pthreads\include;..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\lib\windows\zlib\include;..\..\..\..\lib\windows\sdl\include;..\..\..\..\lib\windows\ffmpeg\include;..\..\..\..\build\msvc_9\intern\bmfont\include;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\iksolver\include;..\..\..\source\blender;..\..\..\source\blender\avi;..\..\..\source\blender\imbuf;..\..\..\source\blender\editors\include;..\..\..\source\blender\python;..\..\..\source\blender\blenlib;..\..\..\source\blender\blenkernel;..\..\..\source\blender\makesdna;..\..\..\source\blender\makesrna;..\..\..\source\blender\nodes;..\..\..\source\blender\blenloader;..\..\..\source\kernel\gen_system;..\..\..\source\blender\renderconverter;..\..\..\source\blender\render\extern\include;..\..\..\source\gameengine\SoundSystem;..\..\..\..\build\msvc_9\extern\verse\include;..\..\..\..\build\msvc_9\intern\opennl\include;..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\source\blender\gpu;..\..\source\blender\blenkernel;..\..\source\blender\makesdna;..\..\source\blender\blenlib;..\..\source\blender\bmesh;..\..\source\blender\editors\include;..\..\source\blender\bmesh\operators;..\..\source\blender\bmesh\intern;..\..\source\blender\editors\mesh"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="1"\r
+                               WarningLevel="3"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                               OutputFile="..\..\..\build\msvc_9\libs\debug\BL_bmesh.lib"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="4"\r
+                       CharacterSet="2"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               EnableIntrinsicFunctions="true"\r
+                               AdditionalIncludeDirectories="..\..\..\..\lib\windows\pthreads\include;..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\lib\windows\zlib\include;..\..\..\..\lib\windows\sdl\include;..\..\..\..\lib\windows\ffmpeg\include;..\..\..\..\build\msvc_9\intern\bmfont\include;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\iksolver\include;..\..\..\source\blender;..\..\..\source\blender\avi;..\..\..\source\blender\imbuf;..\..\..\source\blender\editors\include;..\..\..\source\blender\python;..\..\..\source\blender\blenlib;..\..\..\source\blender\blenkernel;..\..\..\source\blender\makesdna;..\..\..\source\blender\makesrna;..\..\..\source\blender\nodes;..\..\..\source\blender\blenloader;..\..\..\source\kernel\gen_system;..\..\..\source\blender\renderconverter;..\..\..\source\blender\render\extern\include;..\..\..\source\gameengine\SoundSystem;..\..\..\..\build\msvc_9\extern\verse\include;..\..\..\..\build\msvc_9\intern\opennl\include;..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\source\blender\gpu;..\..\source\blender\blenkernel;..\..\source\blender\makesdna;..\..\source\blender\blenlib;..\..\source\blender\bmesh;..\..\source\blender\editors\include;..\..\source\blender\bmesh\operators;..\..\source\blender\bmesh\intern;..\..\source\blender\editors\mesh"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="true"\r
+                               WarningLevel="3"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                               OutputFile="..\..\..\build\msvc_9\libs\BL_bmesh.lib"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+               <ProjectReference\r
+                       ReferencedProjectIdentifier="{31628053-825D-4C06-8A21-D13883489718}"\r
+                       RelativePathToProject=".\blenlib\BLI_blenlib.vcproj"\r
+               />\r
+               <ProjectReference\r
+                       ReferencedProjectIdentifier="{CAE37E91-6570-43AC-A4B4-7A37A4B0FC94}"\r
+                       RelativePathToProject=".\blenkernel\BKE_blenkernel.vcproj"\r
+               />\r
+               <ProjectReference\r
+                       ReferencedProjectIdentifier="{E013786A-9575-4F34-81B2-33290357EE87}"\r
+                       RelativePathToProject=".\makesdna\DNA_makesdna.vcproj"\r
+               />\r
+               <ProjectReference\r
+                       ReferencedProjectIdentifier="{1CC733F1-6AB5-4904-8F63-C08C46B79DD9}"\r
+                       RelativePathToProject="..\..\intern\guardedalloc\make\msvc_9_0\guardedalloc.vcproj"\r
+               />\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_construct.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\bmesh_dupeops.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_eulers.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_filters.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_interp.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_iterators.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_marking.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_mesh.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_mods.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_opdefines.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_operators.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_operators_private.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_polygon.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_private.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_queries.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_structure.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_structure.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_to_editmesh.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\bmesh_walkers.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\connectops.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\createops.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\dissolveops.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\edgesplitop.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\intern\editmesh_to_bmesh.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\extrudeops.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\join_triangles.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\mesh_conv.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\mirror.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\primitiveops.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\removedoubles.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\subdivideop.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\triangulateop.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\operators\utils.c"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_error.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_filters.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_iterators.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_marking.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_operator_api.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_operators.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_queries.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\source\blender\bmesh\bmesh_walkers.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index 9a78c04b45032fd2862285a66a5d39c15fe274a2..9cafa103ddaaa56b35b8a79842f08640fbf18ae3 100644 (file)
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editbmesh_bvh.c"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editbmesh_bvh.h"\r
+                               RelativePath="..\..\..\source\blender\editors\mesh\editbmesh_add.c"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editface.c"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editmesh.c"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editmesh_add.c"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editmesh_lib.c"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editmesh_loop.c"\r
+                               RelativePath="..\..\..\source\blender\editors\mesh\editbmesh_bvh.c"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editmesh_mods.c"\r
+                               RelativePath="..\..\..\source\blender\editors\mesh\editbmesh_bvh.h"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\mesh\editmesh_tools.c"\r
+                               RelativePath="..\..\..\source\blender\editors\mesh\editface.c"\r
                                >\r
                        </File>\r
                        <File\r
index f1d04358d9cfe5760bf36fe846d6a1a3fcdbe161..c0b11791c1e672e0a2b7f8be757da8b862dc75d5 100644 (file)
@@ -151,6 +151,9 @@ typedef struct DMFaceIter {
 
        int index;
        int len;
+
+       /*you can set mat_nr and flags, and the backends 
+         must detect and update the internal faces*/
        int mat_nr;
        int flags;
 
index f1ab1d61fdf442ba16a0e4e454b7bf89219c96fd..0801bb27a6a41626f219ac95f1aaa13733481185 100644 (file)
@@ -66,6 +66,9 @@ struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
 
   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, 
index ad70539535464a5b861f3e95d188efd00991b63a..91e33eef08a4bbb048557396a305f8643721819e 100644 (file)
@@ -1841,6 +1841,10 @@ void cddm_stepiter(void *self)
        CDDM_FaceIter *iter = self;
        MPoly *mp;
        
+       mp = iter->cddm->mpoly + iter->head.index;
+       mp->flag = iter->head.flags;
+       mp->mat_nr = iter->head.mat_nr;
+
        iter->head.index++;
        if (iter->head.index >= iter->cddm->dm.numPolyData) {
                iter->head.done = 1;
@@ -1937,8 +1941,13 @@ DMFaceIter *cdDM_newFaceIter(DerivedMesh *source)
        iter->liter.cddm = cddm;
 
        iter->cddm = cddm;
-       iter->head.index = -1;
-       iter->head.step(iter);
+
+       if (source->numFaceData) {
+               iter->head.index = -1;
+               iter->head.step(iter);
+       } else {
+               iter->head.done = 1;
+       }
 
        return (DMFaceIter*) iter;
 }
index 896d29fd0f836d7dd8a18c1eae3ffb712584a39e..04f04ca6a8cd6372ba22f8b6d92ad8d0c15e6ee4 100644 (file)
@@ -70,6 +70,7 @@
 #include "BKE_mesh.h"
 #include "BKE_shrinkwrap.h"
 #include "BKE_mesh.h"
+#include "BKE_tessmesh.h"
 
 #ifndef DISABLE_PYTHON
 #include "BPY_extern.h"
@@ -406,7 +407,7 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f
 {
        DerivedMesh *dm;
        Mesh *me= ob->data;
-       EditMesh *em = BKE_mesh_get_editmesh(me);
+       BMEditMesh *em = me->edit_btmesh;
        float vec[3] = {0.0f, 0.0f, 0.0f}, tvec[3];
        float normal[3] = {0.0f, 0.0f, 0.0f}, plane[3];
        float imat[3][3], tmat[3][3];
@@ -423,7 +424,7 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f
        /* get DerivedMesh */
        if (em) {
                /* target is in editmode, so get a special derived mesh */
-               dm = CDDM_from_editmesh(em, ob->data);
+               dm = CDDM_from_BMEditMesh(em, ob->data);
                freeDM= 1;
        }
        else {
@@ -503,8 +504,6 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f
        /* free temporary DerivedMesh created (in EditMode case) */
        if (dm && freeDM)
                dm->release(dm);
-       if (em)
-               BKE_mesh_end_editmesh(me, em);
 }
 
 /* function that sets the given matrix based on given vertex group in lattice */
index 4f10edf242ef70c21d34e2dea189ad8d19711a1a..d1a503b36dd7a4159ed57632e21279dc0d14eccc 100644 (file)
@@ -1387,6 +1387,11 @@ void bmDM_faceIterStep(void *self)
 {
        bmDM_faceIter *iter = self;
        
+       if (iter->f) {
+               iter->f->mat_nr = iter->head.mat_nr;
+               iter->f->head.flag = MEFlags_To_BMFlags(iter->head.flags, BM_FACE);
+       }
+
        iter->f = iter->nextf;
 
        iter->head.mat_nr = iter->f->mat_nr;
index 63533ef1adbf47e4fd89fc6715efe946edbeaf37..a7df7a4447595f5da21c66f01a34c09aae97b3f5 100644 (file)
 
 #include "bmesh.h"
 
-EditMesh *BKE_mesh_get_editmesh(Mesh *me)
-{
-       return bmesh_to_editmesh(me->edit_btmesh->bm);
-}
-
-void free_editMesh(EditMesh *em);
-void BKE_mesh_end_editmesh(Mesh *me, EditMesh *em)
-{
-       BM_Free_Mesh(me->edit_btmesh->bm);
-       me->edit_btmesh->bm = editmesh_to_bmesh(em);
-       BMEdit_RecalcTesselation(me->edit_btmesh);
-       free_editMesh(em);
-       MEM_freeN(em);
-}
-
 static void mesh_ensure_tesselation_customdata(Mesh *me)
 {
        int tottex, totcol;
@@ -1605,9 +1590,19 @@ static void mesh_loops_to_corners(CustomData *fdata, CustomData *ldata,
        }
 }
 
-/*this function recreates a tesselation.
+/*
+  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.
 
-  returns number of tesselation faces.*/
+  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(CustomData *fdata, 
                            CustomData *ldata, CustomData *pdata,
                            MVert *mvert, int totface, int totloop, 
index 9ef10eda6c4230b8fa133a29d017a886481c53c8..c0446375acd4c385883c625130597a38119553dd 100644 (file)
@@ -7501,7 +7501,6 @@ static void meshdeformModifier_do(
 {
        MeshDeformModifierData *mmd = (MeshDeformModifierData*) md;
        Mesh *me= (mmd->object)? mmd->object->data: NULL;
-       EditMesh *em = (me)? BKE_mesh_get_editmesh(me): NULL;
        BMEditMesh *bem = me->edit_btmesh;
        DerivedMesh *tmpdm, *cagedm;
        MDeformVert *dvert = NULL;
index d7738fc3f5455aa1d6ae862ca9b8a6ee3871982d..687c9b8c7bfb74a92ac9a023c8e3be12755eb8e9 100644 (file)
@@ -1816,25 +1816,27 @@ static void ob_parbone(Object *ob, Object *par, float mat[][4])
 
 static void give_parvert(Object *par, int nr, float *vec)
 {
-       EditMesh *em;
+       BMEditMesh *em;
        int a, count;
        
        vec[0]=vec[1]=vec[2]= 0.0f;
        
        if(par->type==OB_MESH) {
                Mesh *me= par->data;
-               em = BKE_mesh_get_editmesh(me);
+               em = me->edit_btmesh;
 
                if(em) {
-                       EditVert *eve;
-                       
-                       for(eve= em->verts.first; eve; eve= eve->next) {
-                               if(eve->keyindex==nr) {
+                       BMVert *eve;
+                       BMIter iter;
+
+                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                               int *keyindex = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_SHAPE_KEYINDEX);
+                               
+                               if(keyindex && *keyindex==nr) {
                                        memcpy(vec, eve->co, sizeof(float)*3);
                                        break;
                                }
                        }
-                       BKE_mesh_end_editmesh(me, em);
                }
                else {
                        DerivedMesh *dm = par->derivedFinal;
index 8a5e1b24c019b9031229e9d2eaf55c547a0b74f8..991d9f548b0f0db2170cfd7325bd175c6a79a0f6 100644 (file)
@@ -1433,13 +1433,13 @@ void cgdm_faceIterStep(void *self)
                return;
        }
 
-       fiter->head.index++;
-       
-       if (fiter->head.index >= ccgSubSurf_getNumFinalFaces(fiter->cgdm->ss)) {
+       if (fiter->head.index+1 >= ccgSubSurf_getNumFinalFaces(fiter->cgdm->ss)) {
                fiter->head.done = 1;
                return;
        };
 
+       fiter->head.index++;
+       
        fiter->mf++;
 
        fiter->head.flags = fiter->mface->flag;
index eb8d48896c7e39a0de65ef0c8048791745452bce..0576031c703a4a48347f8bd6dcd2d49324aecefb 100644 (file)
@@ -578,15 +578,6 @@ BMOpDefine def_extrudefaceregion = {
        0
 };
 
-BMOpDefine def_makefgonsop = {
-       "makefgon",
-       {{BMOP_OPSLOT_INT, "trifan"}, /*use triangle fans instead of 
-                                       real interpolation*/
-        {0} /*null-terminating sentinel*/},
-       bmesh_make_fgons_exec,
-       0
-};
-
 BMOpDefine def_dissolvevertsop = {
        "dissolveverts",
        {{BMOP_OPSLOT_ELEMENT_BUF, "verts"},
@@ -644,9 +635,10 @@ BMOpDefine def_subdop = {
        {BMOP_OPSLOT_MAPPING, "custompatterns"},
        {BMOP_OPSLOT_MAPPING, "edgepercents"},
        
-       /*these next two can have multiple types of elements in them.*/
+       /*these next three can have multiple types of elements in them.*/
        {BMOP_OPSLOT_ELEMENT_BUF, "outinner"},
        {BMOP_OPSLOT_ELEMENT_BUF, "outsplit"},
+       {BMOP_OPSLOT_ELEMENT_BUF, "geomout"}, /*contains all output geometry*/
 
        {BMOP_OPSLOT_INT, "quadcornertype"}, //quad corner type, see bmesh_operators.h
        {BMOP_OPSLOT_INT, "gridfill"}, //fill in fully-selected faces with a grid
@@ -658,22 +650,6 @@ BMOpDefine def_subdop = {
        0
 };
 
-BMOpDefine def_edit2bmesh = {
-       "editmesh_to_bmesh",
-       {{BMOP_OPSLOT_PNT, "em"}, {BMOP_OPSLOT_MAPPING, "map"},
-       {0} /*null-terminating sentinel*/},
-       edit2bmesh_exec,
-       0
-};
-
-BMOpDefine def_bmesh2edit = {
-       "bmesh_to_editmesh",
-       {{BMOP_OPSLOT_PNT, "emout"},
-       {0} /*null-terminating sentinel*/},
-       bmesh2edit_exec,
-       0
-};
-
 BMOpDefine def_delop = {
        "del",
        {{BMOP_OPSLOT_ELEMENT_BUF, "geom"}, {BMOP_OPSLOT_INT, "context"},
@@ -837,19 +813,114 @@ BMOpDefine def_edgesplit = {
        0
 };
 
+/*
+  Create Grid
+
+  Creates a grid with a variable number of subdivisions
+*/
+BMOpDefine def_create_grid = {
+       "create_grid",
+       {{BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, //output verts
+        {BMOP_OPSLOT_INT,         "xsegments"}, //number of x segments
+        {BMOP_OPSLOT_INT,         "ysegments"}, //number of y segments
+        {BMOP_OPSLOT_FLT,         "size"}, //size of the grid
+        {BMOP_OPSLOT_MAT,         "mat"}, //matrix to multiply the new geometry with
+        {0, /*null-terminating sentinel*/}},
+       bmesh_create_grid_exec,
+       0,
+};
+
+/*
+  Create UV Sphere
+
+  Creates a grid with a variable number of subdivisions
+*/
+BMOpDefine def_create_uvsphere = {
+       "create_uvsphere",
+       {{BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, //output verts
+        {BMOP_OPSLOT_INT,         "segments"}, //number of u segments
+        {BMOP_OPSLOT_INT,         "revolutions"}, //number of v segment
+        {BMOP_OPSLOT_FLT,         "diameter"}, //diameter
+        {BMOP_OPSLOT_MAT,         "mat"}, //matrix to multiply the new geometry with--
+        {0, /*null-terminating sentinel*/}},
+       bmesh_create_uvsphere_exec,
+       0,
+};
+
+/*
+  Create Ico Sphere
+
+  Creates a grid with a variable number of subdivisions
+*/
+BMOpDefine def_create_icosphere = {
+       "create_icosphere",
+       {{BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, //output verts
+        {BMOP_OPSLOT_INT,         "subdivisions"}, //how many times to recursively subdivide the sphere
+        {BMOP_OPSLOT_FLT,       "diameter"}, //diameter
+        {BMOP_OPSLOT_MAT, "mat"}, //matrix to multiply the new geometry with
+        {0, /*null-terminating sentinel*/}},
+       bmesh_create_icosphere_exec,
+       0,
+};
+
+/*
+  Create Suzanne
+
+  Creates a monkey.  Be wary.
+*/
+BMOpDefine def_create_monkey = {
+       "create_monkey",
+       {{BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, //output verts
+        {BMOP_OPSLOT_MAT, "mat"}, //matrix to multiply the new geometry with--
+        {0, /*null-terminating sentinel*/}},
+       bmesh_create_monkey_exec,
+       0,
+};
+
+/*
+  Create Cone
+
+  Creates a cone with variable depth at both ends
+*/
+BMOpDefine def_create_cone = {
+       "create_cone",
+       {{BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, //output verts
+        {BMOP_OPSLOT_INT, "cap_ends"}, //wheter or not to fill in the ends with faces
+        {BMOP_OPSLOT_INT, "segments"},
+        {BMOP_OPSLOT_FLT, "diameter1"}, //diameter of one end
+        {BMOP_OPSLOT_FLT, "diameter2"}, //diameter of the opposite
+        {BMOP_OPSLOT_FLT, "depth"}, //distance between ends
+        {BMOP_OPSLOT_MAT, "mat"}, //matrix to multiply the new geometry with--
+        {0, /*null-terminating sentinel*/}},
+       bmesh_create_monkey_exec,
+       0,
+};
+
+/*
+  Create Cone
+
+  Creates a cone with variable depth at both ends
+*/
+BMOpDefine def_create_cube = {
+       "create_cube",
+       {{BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, //output verts
+        {BMOP_OPSLOT_FLT, "size"}, //size of the cube
+        {BMOP_OPSLOT_MAT, "mat"}, //matrix to multiply the new geometry with--
+        {0, /*null-terminating sentinel*/}},
+       bmesh_create_cube_exec,
+       0,
+};
+
 BMOpDefine *opdefines[] = {
        &def_splitop,
        &def_dupeop,
        &def_delop,
-       &def_edit2bmesh,
-       &def_bmesh2edit,
        &def_subdop,
        &def_triangop,
        &def_dissolvefacesop,
        &def_dissolveedgessop,
        &def_dissolveedgeloopsop,
        &def_dissolvevertsop,
-       &def_makefgonsop,
        &def_extrudefaceregion,
        &def_connectverts,
        //&def_makeprim,
@@ -892,6 +963,12 @@ BMOpDefine *opdefines[] = {
        &def_scale,
        &def_edgesplit,
        &def_automerge,
+       &def_create_uvsphere,
+       &def_create_grid,
+       &def_create_icosphere,
+       &def_create_monkey,
+       &def_create_cone,
+       &def_create_cube,
 };
 
 int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));
index e5e05921195457bd72973879e0c26434bce46cea..eb0f402b5ff83f454afeb79eba1f7b1b68cbb649 100644 (file)
@@ -61,5 +61,11 @@ void bmesh_vertexshortestpath_exec(BMesh *bm, BMOperator *op);
 void bmesh_scale_exec(BMesh *bm, BMOperator *op);
 void bmesh_edgesplitop_exec(BMesh *bm, BMOperator *op);
 void bmesh_automerge_exec(BMesh *bm, BMOperator *op);
+void bmesh_create_cone_exec(BMesh *bm, BMOperator *op);
+void bmesh_create_monkey_exec(BMesh *bm, BMOperator *op);
+void bmesh_create_icosphere_exec(BMesh *bm, BMOperator *op);
+void bmesh_create_uvsphere_exec(BMesh *bm, BMOperator *op);
+void bmesh_create_grid_exec(BMesh *bm, BMOperator *op);
+void bmesh_create_cube_exec(BMesh *bm, BMOperator *op);
 
 #endif
index 1bad95ab0b184a45da40db1b8675ea45d93b0316..6f43df4d75bf84c750ed2e54ee38d2e2463c5a4e 100644 (file)
@@ -1,3 +1,4 @@
+#if 0
 #include "MEM_guardedalloc.h"
 #include "BKE_customdata.h" 
 #include "DNA_listBase.h"
@@ -313,4 +314,5 @@ EditMesh *bmesh_to_editmesh(BMesh *bmesh)
        BMO_Finish_Op(bmesh, &conv);
        
        return em;
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
index cf30f4ae5aa742ef4376e354120b6e59e5c9383b..a2a3763967092caf34ddd865da31301b422d81b8 100644 (file)
@@ -1,3 +1,4 @@
+#if 0
 
 #include "MEM_guardedalloc.h"
 #include "BKE_customdata.h" 
@@ -471,4 +472,5 @@ BMesh *init_editmesh_to_bmesh(EditMesh *em, BMOperator *op)
        BMO_Set_Pnt(op, "em", em);
 
        return bm;
-}
\ No newline at end of file
+}
+#endif
index 3337a91e2c491a9b30050ff67b254bbc78ca8043..673b34415aebde4fb3263e6913aa14c4948e05ad 100644 (file)
@@ -101,27 +101,3 @@ void connectverts_exec(BMesh *bm, BMOperator *op)
        BLI_array_free(loops);
        BLI_array_free(verts);
 }
-
-int BM_ConnectVerts(EditMesh *em, int flag) 
-{
-       EditMesh *em2;
-       BMesh *bm = editmesh_to_bmesh(em);
-       BMOperator op;
-       
-       BMO_Init_Op(&op, "connectverts");
-       BMO_HeaderFlag_To_Slot(bm, &op, "verts", flag, BM_VERT);
-       BMO_Exec_Op(bm, &op);
-       BMO_Finish_Op(bm, &op);
-       
-       if (BMO_GetSlot(&op, "edgeout")->len > 0 && 
-           BMO_GetError(bm, NULL, NULL)==0)
-       {
-               em2 = bmesh_to_editmesh(bm);
-               set_editMesh(em, em2);
-               MEM_freeN(em2);
-
-               return 1;
-       }
-
-       return 0;
-}
\ No newline at end of file
diff --git a/source/blender/bmesh/operators/join_triangles.c b/source/blender/bmesh/operators/join_triangles.c
new file mode 100644 (file)
index 0000000..2c85672
--- /dev/null
@@ -0,0 +1,119 @@
+#if 0
+#include "MEM_guardedalloc.h"
+#include "BKE_customdata.h" 
+#include "DNA_listBase.h"
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include <string.h>
+#include "BKE_utildefines.h"
+#include "BKE_mesh.h"
+#include "BKE_global.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_cdderivedmesh.h"
+
+#include "BLI_editVert.h"
+#include "mesh_intern.h"
+#include "ED_mesh.h"
+
+#include "BLI_math.h"
+#include "BLI_array.h"
+#include "BLI_blenlib.h"
+#include "BLI_edgehash.h"
+
+#include "BLI_heap.h"
+
+#include "bmesh.h"
+
+/*
+ * JOIN_TRIANGLES.C
+ *
+ * utility bmesh operators, e.g. transform, 
+ * translate, rotate, scale, etc.
+ *
+*/
+
+/*assumes edges are validated before reaching this point*/
+static float measure_facepair(BMesh *bm, BMVert *v1, BMVert *v2, 
+                                                         BMVert *v3, BMVert *v4, float limit)
+{
+       /*gives a 'weight' to a pair of triangles that join an edge to decide how good a join they would make*/
+       /*Note: this is more complicated than it needs to be and should be cleaned up...*/
+       float no1[3], no2[3], measure = 0.0f, angle1, angle2, diff;
+       float edgeVec1[3], edgeVec2[3], edgeVec3[3], edgeVec4[3];
+       float minarea, maxarea, areaA, areaB;
+
+       /*First Test: Normal difference*/
+       normal_tri_v3(n1, v1->co, v2->co, v3->co);
+       normal_tri_v3(n2, v1->co, v3->co, v4->co);
+
+       if(no1[0] == no2[0] && no1[1] == no2[1] && no1[2] == no2[2]) angle1 = 0.0f;
+       else angle1 = angle_v2v2(no1, no2);
+
+       normal_tri_v3(n1, v2->co, v3->co, v4->co);
+       normal_tri_v3(n2, v4->co, v1->co, v2->co);
+
+       if(no1[0] == no2[0] && no1[1] == no2[1] && no1[2] == no2[2]) angle2 = 0.0f;
+       else angle2 = angle_v2v2(no1, no2);
+
+       measure += (angle1/360.0f) + (angle2/360.0f);
+       if(measure > limit) return measure;
+
+       /*Second test: Colinearity*/
+       sub_v3_v3v3(edgeVec1, v1->co, v2->co);
+       sub_v3_v3v3(edgeVec2, v2->co, v3->co);
+       sub_v3_v3v3(edgeVec3, v3->co, v4->co);
+       sub_v3_v3v3(edgeVec4, v4->co, v1->co);  
+
+       diff = 0.0;
+
+       diff = (
+               fabs(angle_v2v2(edgeVec1, edgeVec2) - 90) +
+               fabs(angle_v2v2(edgeVec2, edgeVec3) - 90) +
+               fabs(angle_v2v2(edgeVec3, edgeVec4) - 90) +
+               fabs(angle_v2v2(edgeVec4, edgeVec1) - 90)) / 360.0f;
+       if(!diff) return 0.0;
+
+       measure +=  diff;
+       if(measure > limit) return measure;
+
+       /*Third test: Concavity*/
+       areaA = area_tri_v3(v1->co, v2->co, v3->co) + area_tri_v3(v1->co, v3->co, v4->co);
+       areaB = area_tri_v3(v2->co, v3->co, v4->co) + area_tri_v3(v4->co, v1->co, v2->co);
+
+       if(areaA <= areaB) minarea = areaA;
+       else minarea = areaB;
+
+       if(areaA >= areaB) maxarea = areaA;
+       else maxarea = areaB;
+
+       if(!maxarea) measure += 1;
+       else measure += (1 - (minarea / maxarea));
+
+       return measure;
+}
+
+#define T2QUV_LIMIT 0.005
+#define T2QCOL_LIMIT 3
+
+static int compareFaceAttribs(BMesh *bm, BMEdge *e)
+{
+       MTexPoly *tp1, *tp2;
+       MLoopCol *lcol1, *lcol2, *lcol3, *lcol4;
+       MLoopUV *luv1, *luv2, *luv3, *luv4;
+       BMLoop *l1, *l2;
+       
+       l1 = e->loop
+       l2 = (BMLoop*)e->loop->radial.next->data;
+
+
+}
+
+void bmesh_jointriangles_exec(BMesh *bm, BMOperator *op)
+{
+       
+}
+
+#endif
diff --git a/source/blender/bmesh/operators/primitiveops.c b/source/blender/bmesh/operators/primitiveops.c
new file mode 100644 (file)
index 0000000..ba32d09
--- /dev/null
@@ -0,0 +1,581 @@
+#include "MEM_guardedalloc.h"
+
+#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_math.h"
+#include "BLI_ghash.h"
+#include "BLI_blenlib.h"
+#include "BLI_array.h"
+
+#include "bmesh.h"
+#include "mesh_intern.h"
+#include "bmesh_private.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/* ************************ primitives ******************* */
+
+static float icovert[12][3] = {
+       {0.0f,0.0f,-200.0f}, 
+       {144.72f, -105.144f,-89.443f},
+       {-55.277f, -170.128,-89.443f}, 
+       {-178.885f,0.0f,-89.443f},
+       {-55.277f,170.128f,-89.443f}, 
+       {144.72f,105.144f,-89.443f},
+       {55.277f,-170.128f,89.443f},
+       {-144.72f,-105.144f,89.443f},
+       {-144.72f,105.144f,89.443f},
+       {55.277f,170.128f,89.443f},
+       {178.885f,0.0f,89.443f},
+       {0.0f,0.0f,200.0f}
+};
+
+static short icoface[20][3] = {
+       {1,0,2},
+       {1,0,5},
+       {2,0,3},
+       {3,0,4},
+       {4,0,5},
+       {1,5,10},
+       {2,1,6},
+       {3,2,7},
+       {4,3,8},
+       {5,4,9},
+       {10,1,6},
+       {6,2,7},
+       {7,3,8},
+       {8,4,9},
+       {9,5,10},
+       {6,10,11},
+       {7,6,11},
+       {8,7,11},
+       {9,8,11},
+       {10,9,11}
+};
+
+// HACK: these can also be found in cmoview.tga.c, but are here so that they can be found by linker
+// this hack is only used so that scons+mingw + split-sources hack works
+       // ------------------------------- start copied code
+/* these are not the monkeys you are looking for */
+int monkeyo= 4;
+int monkeynv= 271;
+int monkeynf= 250;
+signed char monkeyv[271][3]= {
+{-71,21,98},{-63,12,88},{-57,7,74},{-82,-3,79},{-82,4,92},
+{-82,17,100},{-92,21,102},{-101,12,95},{-107,7,83},
+{-117,31,84},{-109,31,95},{-96,31,102},{-92,42,102},
+{-101,50,95},{-107,56,83},{-82,66,79},{-82,58,92},
+{-82,46,100},{-71,42,98},{-63,50,88},{-57,56,74},
+{-47,31,72},{-55,31,86},{-67,31,97},{-66,31,99},
+{-70,43,100},{-82,48,103},{-93,43,105},{-98,31,105},
+{-93,20,105},{-82,31,106},{-82,15,103},{-70,20,100},
+{-127,55,95},{-127,45,105},{-127,-87,94},{-127,-41,100},
+{-127,-24,102},{-127,-99,92},{-127,52,77},{-127,73,73},
+{-127,115,-70},{-127,72,-109},{-127,9,-106},{-127,-49,-45},
+{-101,-24,72},{-87,-56,73},{-82,-89,73},{-80,-114,68},
+{-85,-121,67},{-104,-124,71},{-127,-126,74},{-71,-18,68},
+{-46,-5,69},{-21,19,57},{-17,55,76},{-36,62,80},
+{-64,77,88},{-86,97,94},{-107,92,97},{-119,63,96},
+{-106,53,99},{-111,39,98},{-101,12,95},{-79,2,90},
+{-64,8,86},{-47,24,83},{-45,38,83},{-50,48,85},
+{-72,56,92},{-95,60,97},{-127,-98,94},{-113,-92,94},
+{-112,-107,91},{-119,-113,89},{-127,-114,88},{-127,-25,96},
+{-127,-18,95},{-114,-19,95},{-111,-29,96},{-116,-37,95},
+{-76,-6,86},{-48,7,80},{-34,26,77},{-32,48,84},
+{-39,53,93},{-71,70,102},{-87,82,107},{-101,79,109},
+{-114,55,108},{-111,-13,104},{-100,-57,91},{-95,-90,88},
+{-93,-105,85},{-97,-117,81},{-106,-119,81},{-127,-121,82},
+{-127,6,93},{-127,27,98},{-85,61,95},{-106,18,96},
+{-110,27,97},{-112,-88,94},{-117,-57,96},{-127,-57,96},
+{-127,-42,95},{-115,-35,100},{-110,-29,102},{-113,-17,100},
+{-122,-16,100},{-127,-26,106},{-121,-19,104},{-115,-20,104},
+{-113,-29,106},{-117,-32,103},{-127,-37,103},{-94,-40,71},
+{-106,-31,91},{-104,-40,91},{-97,-32,71},{-127,-112,88},
+{-121,-111,88},{-115,-105,91},{-115,-95,93},{-127,-100,84},
+{-115,-96,85},{-115,-104,82},{-121,-109,81},{-127,-110,81},
+{-105,28,100},{-103,20,99},{-84,55,97},{-92,54,99},
+{-73,51,99},{-55,45,89},{-52,37,88},{-53,25,87},
+{-66,13,92},{-79,8,95},{-98,14,100},{-104,38,100},
+{-100,48,100},{-97,46,97},{-102,38,97},{-96,16,97},
+{-79,11,93},{-68,15,90},{-57,27,86},{-56,36,86},
+{-59,43,87},{-74,50,96},{-91,51,98},{-84,52,96},
+{-101,22,96},{-102,29,96},{-113,59,78},{-102,85,79},
+{-84,88,76},{-65,71,71},{-40,58,63},{-25,52,59},
+{-28,21,48},{-50,0,53},{-71,-12,60},{-127,115,37},
+{-127,126,-10},{-127,-25,-86},{-127,-59,24},{-127,-125,59},
+{-127,-103,44},{-127,-73,41},{-127,-62,36},{-18,30,7},
+{-17,41,-6},{-28,34,-56},{-68,56,-90},{-33,-6,9},
+{-51,-16,-21},{-45,-1,-55},{-84,7,-85},{-97,-45,52},
+{-104,-53,33},{-90,-91,49},{-95,-64,50},{-85,-117,51},
+{-109,-97,47},{-111,-69,46},{-106,-121,56},{-99,-36,55},
+{-100,-29,60},{-101,-22,64},{-100,-50,21},{-89,-40,-34},
+{-83,-19,-69},{-69,111,-49},{-69,119,-9},{-69,109,30},
+{-68,67,55},{-34,52,43},{-46,58,36},{-45,90,7},
+{-25,72,16},{-25,79,-15},{-45,96,-25},{-45,87,-57},
+{-25,69,-46},{-48,42,-75},{-65,3,-70},{-22,42,-26},
+{-75,-22,19},{-72,-25,-27},{-13,52,-30},{-28,-18,-16},
+{6,-13,-42},{37,7,-55},{46,41,-54},{31,65,-54},
+{4,61,-40},{3,53,-37},{25,56,-50},{35,37,-52},
+{28,10,-52},{5,-5,-39},{-21,-9,-17},{-9,46,-28},
+{-6,39,-37},{-14,-3,-27},{6,0,-47},{25,12,-57},
+{31,32,-57},{23,46,-56},{4,44,-46},{-19,37,-27},
+{-20,22,-35},{-30,12,-35},{-22,11,-35},{-19,2,-35},
+{-23,-2,-35},{-34,0,-9},{-35,-3,-22},{-35,5,-24},
+{-25,26,-27},{-13,31,-34},{-13,30,-41},{-23,-2,-41},
+{-18,2,-41},{-21,10,-41},{-29,12,-41},{-19,22,-41},
+{6,42,-53},{25,44,-62},{34,31,-63},{28,11,-62},
+{7,0,-54},{-14,-2,-34},{-5,37,-44},{-13,14,-42},
+{-7,8,-43},{1,16,-47},{-4,22,-45},{3,30,-48},
+{8,24,-49},{15,27,-50},{12,35,-50},{4,56,-62},
+{33,60,-70},{48,38,-64},{41,7,-68},{6,-11,-63},
+{-26,-16,-42},{-17,49,-49},
+};
+
+signed char monkeyf[250][4]= {
+{27,4,5,26}, {25,4,5,24}, {3,6,5,4}, {1,6,5,2}, {5,6,7,4}, 
+{3,6,7,2}, {5,8,7,6}, {3,8,7,4}, {7,8,9,6}, 
+{5,8,9,4}, {7,10,9,8}, {5,10,9,6}, {9,10,11,8}, 
+{7,10,11,6}, {9,12,11,10}, {7,12,11,8}, {11,6,13,12}, 
+{5,4,13,12}, {3,-2,13,12}, {-3,-4,13,12}, {-5,-10,13,12}, 
+{-11,-12,14,12}, {-13,-18,14,13}, {-19,4,5,13}, {10,12,4,4}, 
+{10,11,9,9}, {8,7,9,9}, {7,5,6,6}, {6,3,4,4}, 
+{5,1,2,2}, {4,-1,0,0}, {3,-3,-2,-2}, {22,67,68,23}, 
+{20,65,66,21}, {18,63,64,19}, {16,61,62,17}, {14,59,60,15}, 
+{12,19,48,57}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 
+{18,19,48,47}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 
+{18,19,48,47}, {18,-9,-8,47}, {18,27,45,46}, {26,55,43,44}, 
+{24,41,42,54}, {22,39,40,23}, {20,37,38,21}, {18,35,36,19}, 
+{16,33,34,17}, {14,31,32,15}, {12,39,30,13}, {11,48,45,38}, 
+{8,36,-19,9}, {8,-20,44,47}, {42,45,46,43}, {18,19,40,39}, 
+{16,17,38,37}, {14,15,36,35}, {32,44,43,33}, {12,33,32,42}, 
+{19,44,43,42}, {40,41,42,-27}, {8,9,39,-28}, {15,43,42,16}, 
+{13,43,42,14}, {11,43,42,12}, {9,-30,42,10}, {37,12,38,-32}, 
+{-33,37,45,46}, {-33,40,41,39}, {38,40,41,37}, {36,40,41,35}, 
+{34,40,41,33}, {36,39,38,37}, {35,40,39,38}, {1,2,14,21}, 
+{1,2,40,13}, {1,2,40,39}, {1,24,12,39}, {-34,36,38,11}, 
+{35,38,36,37}, {-37,8,35,37}, {-11,-12,-45,40}, {-11,-12,39,38}, 
+{-11,-12,37,36}, {-11,-12,35,34}, {33,34,40,41}, {33,34,38,39}, 
+{33,34,36,37}, {33,-52,34,35}, {33,37,36,34}, {33,35,34,34}, 
+{8,7,37,36}, {-32,7,35,46}, {-34,-33,45,46}, {4,-33,43,34}, 
+{-34,-33,41,42}, {-34,-33,39,40}, {-34,-33,37,38}, {-34,-33,35,36}, 
+{-34,-33,33,34}, {-34,-33,31,32}, {-34,-4,28,30}, {-5,-34,28,27}, 
+{-35,-44,36,27}, {26,35,36,45}, {24,25,44,45}, {25,23,44,42}, 
+{25,24,41,40}, {25,24,39,38}, {25,24,37,36}, {25,24,35,34}, 
+{25,24,33,32}, {25,24,31,30}, {15,24,29,38}, {25,24,27,26}, 
+{23,12,37,26}, {11,12,35,36}, {-86,-59,36,-80}, {-60,-61,36,35}, 
+{-62,-63,36,35}, {-64,-65,36,35}, {-66,-67,36,35}, {-68,-69,36,35}, 
+{-70,-71,36,35}, {-72,-73,36,35}, {-74,-75,36,35}, {42,43,53,58}, 
+{40,41,57,56}, {38,39,55,57}, {-81,-80,37,56}, {-83,-82,55,52}, 
+{-85,-84,51,49}, {-87,-86,48,49}, {47,50,51,48}, {46,48,51,49}, 
+{43,46,49,44}, {-92,-91,45,42}, {-23,49,50,-20}, {-94,40,48,-24}, 
+{-96,-22,48,49}, {-97,48,21,-90}, {-100,36,50,23}, {22,49,48,-100}, 
+{-101,47,46,22}, {21,45,35,25}, {33,34,44,41}, {13,14,28,24}, 
+{-107,26,30,-106}, {14,46,45,15}, {14,44,43,-110}, {-111,42,23,-110}, 
+{6,7,45,46}, {45,44,47,46}, {45,46,47,48}, {47,46,49,48}, 
+{17,49,47,48}, {17,36,46,48}, {35,36,44,45}, {35,36,40,43}, 
+{35,36,38,39}, {-4,-3,37,35}, {-123,34,33,1}, {-9,-8,-7,-6}, 
+{-10,-7,32,-125}, {-127,-11,-126,-126}, {-7,-6,5,31}, {4,5,33,30}, 
+{4,39,33,32}, {4,35,32,38}, {20,21,39,38}, {4,37,38,5}, 
+{-11,-10,36,3}, {-11,15,14,35}, {13,16,34,34}, {-13,14,13,13}, 
+{-3,1,30,29}, {-3,28,29,1}, {-2,31,28,-1}, {12,13,27,30}, 
+{-2,26,12,12}, {35,29,42,36}, {34,35,36,33}, {32,35,36,31}, 
+{30,35,36,29}, {28,35,36,27}, {26,35,36,25}, {34,39,38,35}, 
+{32,39,38,33}, {30,39,38,31}, {28,39,38,29}, {26,39,38,27}, 
+{25,31,32,38}, {-18,-17,45,44}, {-18,17,28,44}, {-24,-20,42,-23}, 
+{11,35,27,14}, {25,28,39,41}, {37,41,40,38}, {34,40,36,35}, 
+{32,40,39,33}, {30,39,31,40}, {21,29,39,22}, {-31,37,28,4}, 
+{-32,33,35,36}, {32,33,34,34}, {18,35,36,48}, {34,25,40,35}, 
+{24,25,38,39}, {24,25,36,37}, {24,25,34,35}, {24,25,32,33}, 
+{24,13,41,31}, {17,11,41,35}, {15,16,34,35}, {13,14,34,35}, 
+{11,12,34,35}, {9,10,34,35}, {7,8,34,35}, {26,25,37,36}, 
+{35,36,37,38}, {37,36,39,38}, {37,38,39,40}, {25,31,36,39}, 
+{18,34,35,30}, {17,22,30,33}, {19,29,21,20}, {16,26,29,17}, 
+{24,29,28,25}, {22,31,28,23}, {20,31,30,21}, {18,31,30,19}, 
+{16,30,17,17}, {-21,-22,35,34}, {-21,-22,33,32}, {-21,-22,31,30}, 
+{-21,-22,29,28}, {-21,-22,27,26}, {-28,-22,25,31}, {24,28,29,30}, 
+{23,24,26,27}, {23,24,25,25}, {-69,-35,-32,27}, {-70,26,25,-66}, 
+{-68,-67,24,-33}, 
+};
+
+#define VERT_MARK      1
+
+#define EDGE_ORIG      1
+#define EDGE_MARK      2
+
+#define FACE_MARK      1
+
+void bmesh_create_grid_exec(BMesh *bm, BMOperator *op)
+{
+       BMOperator bmop, prevop;
+       BMVert *eve, *preveve;
+       BMEdge *e;
+       float vec[3], mat[4][4], phi, phid, dia=BMO_Get_Float(op, "size");
+       int a, tot=BMO_Get_Int(op, "xsegments"), seg=BMO_Get_Int(op, "ysegments");
+
+       if (tot < 2) tot = 2;
+       if (seg < 2) seg = 2;
+
+       BMO_Get_Mat4(op, "mat", mat);
+
+       /* one segment first: the X axis */
+       phi= 1.0; 
+       phid= 2.0/((float)tot-1);
+       for(a=0;a<tot;a++) {
+               vec[0]= dia*phi;
+               vec[1]= - dia;
+               vec[2]= 0.0f;
+               mul_m4_v3(mat,vec);
+
+               eve= BM_Make_Vert(bm, vec, NULL);
+               BM_Select(bm, eve, 1);
+
+               if (a) {
+                       e = BM_Make_Edge(bm, preveve, eve, NULL, 1);
+                       BMO_SetFlag(bm, e, EDGE_ORIG);
+               }
+
+               preveve = eve;
+               phi-=phid;
+       }
+
+       /* extrude and translate */
+       vec[0]= vec[2]= 0.0;
+       vec[1]= dia*phid;
+       mul_mat3_m4_v3(mat, vec);
+               
+       for(a=0;a<seg-1;a++) {
+               if (a) {
+                       BMO_InitOpf(bm, &bmop, "extrude_edge_only edges=%s", &prevop, "geomout");
+                       BMO_Exec_Op(bm, &bmop);
+                       BMO_Finish_Op(bm, &prevop);
+
+                       BMO_Flag_Buffer(bm, &bmop, "geomout", VERT_MARK, BM_VERT);
+               } else {
+                       BMO_InitOpf(bm, &bmop, "extrude_edge_only edges=%fe", EDGE_ORIG);
+                       BMO_Exec_Op(bm, &bmop);
+                       BMO_Flag_Buffer(bm, &bmop, "geomout", VERT_MARK, BM_VERT);
+               }
+
+               BMO_CallOpf(bm, "translate vec=%v verts=%s", vec, &bmop, "geomout");
+               prevop = bmop;
+       }
+
+       if (a)
+               BMO_Finish_Op(bm, &bmop);
+
+       BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}
+
+void bmesh_create_uvsphere_exec(BMesh *bm, BMOperator *op)
+{
+       BMOperator bmop, prevop;
+       BMVert *eve, *preveve, *v1;
+       BMEdge *e;
+       BMIter iter;
+       float vec[3], mat[4][4], cmat[3][3], phi, q[4];
+       float phid, dia=BMO_Get_Float(op, "diameter");
+       int a, seg=BMO_Get_Int(op, "segments"), tot=BMO_Get_Int(op, "revolutions");
+
+       BMO_Get_Mat4(op, "mat", mat);
+
+       phid= 2.0f*(float)M_PI/tot;
+       phi= .25f*(float)M_PI;
+
+       /* one segment first */
+       phi= 0; 
+       phid/=2;
+       for(a=0; a<=tot; a++) {
+               vec[0]= dia*sin(phi);
+               vec[1]= 0.0;
+               vec[2]= dia*cos(phi);
+               eve= BM_Make_Vert(bm, vec, NULL);
+               BMO_SetFlag(bm, eve, VERT_MARK);
+
+               if(a==0) v1= eve;
+               else {
+                       e = BM_Make_Edge(bm, preveve, eve, NULL, 0);
+                       BMO_SetFlag(bm, e, EDGE_ORIG);
+               }
+
+               phi+= phid;
+               preveve = eve;
+       }
+
+       /* extrude and rotate */
+       phi= M_PI/seg;
+       q[0]= cos(phi);
+       q[3]= sin(phi);
+       q[1]=q[2]= 0;
+       quat_to_mat3(cmat, q);
+
+       for(a=0; a<seg; a++) {
+               if (a) {
+                       BMO_InitOpf(bm, &bmop, "extrude_edge_only edges=%s", &prevop, "geomout");
+                       BMO_Exec_Op(bm, &bmop);
+                       BMO_Finish_Op(bm, &prevop);
+               } else {
+                       BMO_InitOpf(bm, &bmop, "extrude_edge_only edges=%fe", EDGE_ORIG);
+                       BMO_Exec_Op(bm, &bmop);
+               }
+
+               BMO_Flag_Buffer(bm, &bmop, "geomout", VERT_MARK, BM_VERT);
+               BMO_CallOpf(bm, "rotate cent=%v mat=%m3 verts=%s", vec, cmat, &bmop, "geomout");
+               
+               prevop = bmop;
+       }
+
+       if (a)
+               BMO_Finish_Op(bm, &bmop);
+
+       BMO_CallOpf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, 0.001f);
+
+       /* and now do imat */
+       BM_ITER(eve, &iter, bm, BM_VERTS_OF_MESH, NULL) {
+               if(BMO_TestFlag(bm, eve, VERT_MARK)) {
+                       mul_m4_v3(mat, eve->co);
+               }
+       }
+
+       BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}
+
+void bmesh_create_icosphere_exec(BMesh *bm, BMOperator *op)
+{
+       BMVert *eva[12];
+       float vec[3], mat[4][4], phi, phid;
+       float dia = BMO_Get_Float(op, "diameter");
+       int a, subdiv = BMO_Get_Int(op, "subdivisions");
+
+       BMO_Get_Mat4(op, "mat", mat);
+
+       phid= 2.0f*(float)M_PI/subdiv;
+       phi= .25f*(float)M_PI;
+
+       dia/=200;
+       for(a=0;a<12;a++) {
+               vec[0]= dia*icovert[a][0];
+               vec[1]= dia*icovert[a][1];
+               vec[2]= dia*icovert[a][2];
+               eva[a]= BM_Make_Vert(bm, vec, NULL);
+
+               mul_m4_v3(mat, eva[a]->co);
+               BM_Select(bm, eva[a], 1);
+       }
+
+       for(a=0;a<20;a++) {
+               BMFace *evtemp;
+               BMVert *v1, *v2, *v3;
+
+               v1= eva[ icoface[a][0] ];
+               v2= eva[ icoface[a][1] ];
+               v3= eva[ icoface[a][2] ];
+
+               evtemp = BM_Make_QuadTri(bm, v1, v2, v3, NULL, NULL, 0);
+               BMO_SetFlag(bm, evtemp, FACE_MARK);
+       }
+
+       dia*=200;
+
+       for(a=1; a<subdiv; a++) {
+               BMOperator bmop;
+
+               BMO_InitOpf(bm, &bmop, "esubd edges=%he smooth=%f numcuts=%i gridfill=%i", EDGE_MARK, dia, 1, 1);
+               BMO_Exec_Op(bm, &bmop);
+               BMO_Flag_Buffer(bm, &bmop, "geomout", VERT_MARK, BM_VERT);
+               BMO_Finish_Op(bm, &bmop);
+       }
+
+       BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}
+
+void bmesh_create_monkey_exec(BMesh *bm, BMOperator *op)
+{
+       BMVert *eve;
+       BMVert **tv= MEM_mallocN(sizeof(*tv)*monkeynv*2, "tv");
+       float mat[4][4];
+       int i;
+
+       BMO_Get_Mat4(op, "mat", mat);
+
+       for (i=0; i<monkeynv; i++) {
+               float v[3];
+
+               v[0]= (monkeyv[i][0]+127)/128.0, v[1]= monkeyv[i][1]/128.0, v[2]= monkeyv[i][2]/128.0;
+
+               tv[i]= BM_Make_Vert(bm, v, NULL);
+               BMO_SetFlag(bm, tv[i], VERT_MARK);
+
+               tv[monkeynv+i]= (fabs(v[0]= -v[0])<0.001)?tv[i]: (eve=BM_Make_Vert(bm, v, NULL), mul_m4_v3(mat, eve->co), eve);
+               BMO_SetFlag(bm, tv[monkeynv+i], VERT_MARK);
+
+               mul_m4_v3(mat, tv[i]->co);
+       }
+
+       for (i=0; i<monkeynf; i++) {
+               BM_Make_QuadTri(bm, tv[monkeyf[i][0]+i-monkeyo], tv[monkeyf[i][1]+i-monkeyo], tv[monkeyf[i][2]+i-monkeyo], (monkeyf[i][3]!=monkeyf[i][2])?tv[monkeyf[i][3]+i-monkeyo]:NULL, NULL, 0);
+               BM_Make_QuadTri(bm, tv[monkeynv+monkeyf[i][2]+i-monkeyo], tv[monkeynv+monkeyf[i][1]+i-monkeyo], tv[monkeynv+monkeyf[i][0]+i-monkeyo], (monkeyf[i][3]!=monkeyf[i][2])?tv[monkeynv+monkeyf[i][3]+i-monkeyo]:NULL, NULL, 0);
+       }
+
+       MEM_freeN(tv);
+
+       BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}
+
+void bmesh_create_cone_exec(BMesh *bm, BMOperator *op)
+{
+       BMVert *v1, *v2, *lastv1=NULL, *lastv2=NULL, *cent1, *cent2, *firstv1, *firstv2;
+       float vec[3], mat[4][4], phi, phid;
+       float dia1 = BMO_Get_Float(op, "diameter1");
+       float dia2 = BMO_Get_Float(op, "diameter2");
+       float depth = BMO_Get_Float(op, "depth");
+       int cap_ends = BMO_Get_Int(op, "cap_ends"), segs=BMO_Get_Int(op, "segments");
+       int a;
+
+       BMO_Get_Mat4(op, "mat", mat);
+
+       phid= 2.0f*(float)M_PI/segs;
+       phi= .25f*(float)M_PI;
+
+       depth *= 0.5f;
+       if (cap_ends) {
+               vec[0] = vec[1] = 0.0f;
+               vec[2] = -depth;
+
+               cent1 = BM_Make_Vert(bm, vec, NULL);
+
+               vec[0] = vec[1] = 0.0f;
+               vec[2] = depth;
+               cent2 = BM_Make_Vert(bm, vec, NULL);
+
+               BMO_SetFlag(bm, cent1, VERT_MARK);
+               BMO_SetFlag(bm, cent2, VERT_MARK);
+       }
+
+       for (a=0; a<segs; a++) {
+               vec[0]= dia1*sin(phi);
+               vec[1]= dia1*cos(phi);
+               vec[2]= -depth;
+               mul_m4_v3(mat, vec);
+               v1 = BM_Make_Vert(bm, vec, NULL);
+
+               vec[0]= dia2*sin(phi);
+               vec[1]= dia2*cos(phi);
+               vec[2]= depth;
+               mul_m4_v3(mat, vec);
+               v2 = BM_Make_Vert(bm, vec, NULL);
+
+               BMO_SetFlag(bm, v1, VERT_MARK);
+               BMO_SetFlag(bm, v2, VERT_MARK);
+
+               if (a) {
+                       if (cap_ends) {
+                               BM_Make_QuadTri(bm, cent1, lastv1, v1, NULL, NULL, 0);
+                       }
+                       BM_Make_QuadTri(bm, lastv1, lastv2, v2, v1, NULL, 0);
+               } else {
+                       firstv1 = v1;
+                       firstv2 = v2;
+               }
+
+               lastv1 = v1;
+               lastv2 = v2;
+       }
+
+       if (!a)
+               return;
+
+       if (cap_ends) {
+               BM_Make_QuadTri(bm, cent1, firstv1, v1, NULL, NULL, 0);
+       }
+
+       BM_Make_QuadTri(bm, firstv1, firstv2, v2, v1, NULL, 0);
+
+       BMO_CallOpf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, 0.000001);
+       BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}
+
+void bmesh_create_cube_exec(BMesh *bm, BMOperator *op)
+{
+       BMVert *v1, *v2, *v3, *v4, *v5, *v6, *v7, *v8;
+       float vec[3], mat[4][4], off = BMO_Get_Float(op, "size") / 2.0f;
+
+       BMO_Get_Mat4(op, "mat", mat);
+
+       if (!off) off = 0.5f;
+
+       vec[0] = -off;
+       vec[1] = -off;
+       vec[2] = -off;
+       mul_m4_v3(mat, vec);
+       v1 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v1, VERT_MARK);
+
+       vec[0] = -off;
+       vec[1] = off;
+       vec[2] = -off;
+       mul_m4_v3(mat, vec);
+       v2 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v2, VERT_MARK);
+
+       vec[0] = off;
+       vec[1] = off;
+       vec[2] = -off;
+       mul_m4_v3(mat, vec);
+       v3 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v3, VERT_MARK);
+
+       vec[0] = off;
+       vec[1] = -off;
+       vec[2] = -off;
+       mul_m4_v3(mat, vec);
+       v4 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v4, VERT_MARK);
+
+       vec[0] = -off;
+       vec[1] = -off;
+       vec[2] = off;
+       mul_m4_v3(mat, vec);
+       v5 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v5, VERT_MARK);
+
+       vec[0] = -off;
+       vec[1] = off;
+       vec[2] = off;
+       mul_m4_v3(mat, vec);
+       v6 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v6, VERT_MARK);
+
+       vec[0] = off;
+       vec[1] = off;
+       vec[2] = off;
+       mul_m4_v3(mat, vec);
+       v7 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v7, VERT_MARK);
+
+       vec[0] = off;
+       vec[1] = -off;
+       vec[2] = off;
+       mul_m4_v3(mat, vec);
+       v8 = BM_Make_Vert(bm, vec, NULL);
+       BMO_SetFlag(bm, v8, VERT_MARK);
+
+       /*the four sides*/
+       BM_Make_QuadTri(bm, v5, v6, v2, v1, NULL, 0);
+       BM_Make_QuadTri(bm, v6, v7, v3, v2, NULL, 0);
+       BM_Make_QuadTri(bm, v7, v8, v4, v3, NULL, 0);
+       BM_Make_QuadTri(bm, v8, v5, v1, v4, NULL, 0);
+       
+       /*top/bottom*/
+       BM_Make_QuadTri(bm, v1, v2, v3, v4, NULL, 0);
+       BM_Make_QuadTri(bm, v8, v7, v6, v5, NULL, 0);
+
+       BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}
index c7ab4af3ada458a2235eddac92c98a42b79d050e..f8c0086d7faaa3ecf6317a382210445162f78daf 100644 (file)
@@ -475,8 +475,10 @@ void bmesh_removedoubles_exec(BMesh *bm, BMOperator *op)
                        float vec[3];
                        
                        v2 = verts[j];
-                       if ((v2->co[0]+v2->co[1]+v2->co[2]) - (v->co[0]+v->co[1]+v->co[2])
-                            > distsqr) break;
+                       //if ((v2->co[0]+v2->co[1]+v2->co[2]) - (v->co[0]+v->co[1]+v->co[2])
+                       //     > distsqr) break;
+                       if ((v2->co[0]-v->co[0]) + (v2->co[1]-v->co[1]) + (v2->co[2]-v->co[2]) > distsqr*4.0f)
+                               break;
 
                        vec[0] = v->co[0] - v2->co[0];
                        vec[1] = v->co[1] - v2->co[1];
index f8e1723b0097fe0e34241589507843c470e8203c..701bce4ca88219c68b551ec10d4446f18f7cc5c5 100644 (file)
@@ -964,6 +964,9 @@ void esubdivide_exec(BMesh *bmesh, BMOperator *op)
                         ELE_INNER, BM_ALL);
        BMO_Flag_To_Slot(bmesh, op, "outsplit",
                         ELE_SPLIT, BM_ALL);
+       
+       BMO_Flag_To_Slot(bmesh, op, "geomout",
+                        ELE_INNER|ELE_SPLIT, BM_ALL);
 }
 
 /*editmesh-emulating function*/
index e205c19e79796b5673390686ee0da653a4e2a198..69a29475434598fc217474b4346e6a98027e34c4 100644 (file)
@@ -3386,6 +3386,8 @@ static int iteratorStopped(void *arg)
 
 ReebGraph *BIF_ReebGraphMultiFromEditMesh(bContext *C)
 {
+       return NULL;
+#if 0
        Scene *scene = CTX_data_scene(C);
        Object *obedit = CTX_data_edit_object(C);
        EditMesh *em =BKE_mesh_get_editmesh(((Mesh*)obedit->data));
@@ -3491,6 +3493,7 @@ ReebGraph *BIF_ReebGraphMultiFromEditMesh(bContext *C)
        MEM_freeN(em);
        
        return rg;
+#endif
 }
 
 #if 0
index 273dc50317bf8d6cde7815270de7b40ffbcc962a..8f7a71ca460466a72f4023d74215ccf6944a5644 100644 (file)
@@ -91,13 +91,16 @@ void EDBM_MakeEditBMesh(struct ToolSettings *ts, struct Scene *scene, struct Obj
 void EDBM_FreeEditBMesh(struct BMEditMesh *tm);
 void EDBM_LoadEditBMesh(struct Scene *scene, struct Object *ob);
 
-void EDBM_init_index_arrays(struct BMEditMesh *tm, int forvert, int foredge, int forface);
-void EDBM_free_index_arrays(struct BMEditMesh *tm);
-struct BMVert *EDBM_get_vert_for_index(struct BMEditMesh *tm, int index);
-struct BMEdge *EDBM_get_edge_for_index(struct BMEditMesh *tm, int index);
-struct BMFace *EDBM_get_face_for_index(struct BMEditMesh *tm, int index);
+void EDBM_init_index_arrays(struct BMEditMesh *em, int forvert, int foredge, int forface);
+void EDBM_free_index_arrays(struct BMEditMesh *em);
+struct BMVert *EDBM_get_vert_for_index(struct BMEditMesh *em, int index);
+struct BMEdge *EDBM_get_edge_for_index(struct BMEditMesh *em, int index);
+struct BMFace *EDBM_get_face_for_index(struct BMEditMesh *em, int index);
 struct BMFace *EDBM_get_actFace(struct BMEditMesh *em, int sloppy);
 
+int EDBM_CallAndSelectOpf(struct BMEditMesh *em, struct wmOperator *op, 
+                                                 char *selectslot, char *fmt, ...);
+
 /*flushes based on the current select mode.  if in vertex select mode,
   verts select/deselect edges and faces, if in edge select mode,
   edges select/deselect faces and vertices, and in face select mode faces select/deselect
index 960d7ca45b77e0c4d77ede2446cac883935ea490..aa6a700eb6fdd4d9b935a575ce5619df47aa5976 100644 (file)
@@ -1786,15 +1786,17 @@ void MESH_OT_select_less(wmOperatorType *ot)
 static int mesh_select_nth_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
        int nth = RNA_int_get(op->ptr, "nth");
 
+#if 0 //BMESH_TODO
        if(EM_deselect_nth(em, nth) == 0) {
                BKE_report(op->reports, RPT_ERROR, "Mesh has no active vert/edge/face.");
                return OPERATOR_CANCELLED;
        }
-
-       BKE_mesh_end_editmesh(obedit->data, em);
+#else
+               BKE_report(op->reports, RPT_ERROR, "Unimplemented");
+#endif
 
        DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
@@ -2053,3 +2055,21 @@ int EM_deselect_nth(EditMesh *em, int nth)
 #endif
        return 1;
 }
+
+void em_setup_viewcontext(bContext *C, ViewContext *vc)
+{
+       view3d_set_viewcontext(C, vc);
+       
+       if(vc->obedit) {
+               Mesh *me= vc->obedit->data;
+               vc->em= me->edit_btmesh;
+       }
+}
+
+/* poll call for mesh operators requiring a view3d context */
+int EM_view3d_poll(bContext *C)
+{
+       if(ED_operator_editmesh(C) && ED_operator_view3d_active(C))
+               return 1;
+       return 0;
+}
index e92eab07c1b2557b1968df94ecc0bbfb72791442..c1e659de1065a94d6aadab30dba82a35657ea9be 100644 (file)
@@ -3653,3 +3653,1137 @@ void MESH_OT_solidify(wmOperatorType *ot)
        prop= RNA_def_float(ot->srna, "thickness", 0.01f, -FLT_MAX, FLT_MAX, "thickness", "", -10.0f, 10.0f);
        RNA_def_property_ui_range(prop, -10, 10, 0.1, 4);
 }
+
+#define TRAIL_POLYLINE 1 /* For future use, They don't do anything yet */
+#define TRAIL_FREEHAND 2
+#define TRAIL_MIXED    3 /* (1|2) */
+#define TRAIL_AUTO     4 
+#define        TRAIL_MIDPOINTS 8
+
+typedef struct CutCurve {
+       float  x; 
+       float  y;
+} CutCurve;
+
+/* ******************************************************************** */
+/* Knife Subdivide Tool.  Subdivides edges intersected by a mouse trail
+       drawn by user.
+       
+       Currently mapped to KKey when in MeshEdit mode.
+       Usage:
+               Hit Shift K, Select Centers or Exact
+               Hold LMB down to draw path, hit RETKEY.
+               ESC cancels as expected.
+   
+       Contributed by Robert Wenzlaff (Det. Thorn).
+
+    2.5 revamp:
+    - non modal (no menu before cutting)
+    - exit on mouse release
+    - polygon/segment drawing can become handled by WM cb later
+
+       bmesh port version
+*/
+
+#define KNIFE_EXACT            1
+#define KNIFE_MIDPOINT 2
+#define KNIFE_MULTICUT 3
+
+static EnumPropertyItem knife_items[]= {
+       {KNIFE_EXACT, "EXACT", 0, "Exact", ""},
+       {KNIFE_MIDPOINT, "MIDPOINTS", 0, "Midpoints", ""},
+       {KNIFE_MULTICUT, "MULTICUT", 0, "Multicut", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+/* seg_intersect() Determines if and where a mouse trail intersects an EditEdge */
+
+static float bm_seg_intersect(BMEdge *e, CutCurve *c, int len, char mode,
+                              struct GHash *gh, int *isected)
+{
+#define MAXSLOPE 100000
+       float  x11, y11, x12=0, y12=0, x2max, x2min, y2max;
+       float  y2min, dist, lastdist=0, xdiff2, xdiff1;
+       float  m1, b1, m2, b2, x21, x22, y21, y22, xi;
+       float  yi, x1min, x1max, y1max, y1min, perc=0; 
+       float  *scr;
+       float  threshold = 0.0;
+       int  i;
+       
+       //threshold = 0.000001; /*tolerance for vertex intersection*/
+       // XXX  threshold = scene->toolsettings->select_thresh / 100;
+       
+       /* Get screen coords of verts */
+       scr = BLI_ghash_lookup(gh, e->v1);
+       x21=scr[0];
+       y21=scr[1];
+       
+       scr = BLI_ghash_lookup(gh, e->v2);
+       x22=scr[0];
+       y22=scr[1];
+       
+       xdiff2=(x22-x21);  
+       if (xdiff2) {
+               m2=(y22-y21)/xdiff2;
+               b2= ((x22*y21)-(x21*y22))/xdiff2;
+       }
+       else {
+               m2=MAXSLOPE;  /* Verticle slope  */
+               b2=x22;      
+       }
+
+       *isected = 0;
+
+       /*check for *exact* vertex intersection first*/
+       if(mode!=KNIFE_MULTICUT){
+               for (i=0; i<len; i++){
+                       if (i>0){
+                               x11=x12;
+                               y11=y12;
+                       }
+                       else {
+                               x11=c[i].x;
+                               y11=c[i].y;
+                       }
+                       x12=c[i].x;
+                       y12=c[i].y;
+                       
+                       /*test e->v1*/
+                       if((x11 == x21 && y11 == y21) || (x12 == x21 && y12 == y21)){
+                               perc = 0;
+                               *isected = 1;
+                               return(perc);
+                       }
+                       /*test e->v2*/
+                       else if((x11 == x22 && y11 == y22) || (x12 == x22 && y12 == y22)){
+                               perc = 0;
+                               *isected = 2;
+                               return(perc);
+                       }
+               }
+       }
+       
+       /*now check for edge interesect (may produce vertex intersection as well)*/
+       for (i=0; i<len; i++){
+               if (i>0){
+                       x11=x12;
+                       y11=y12;
+               }
+               else {
+                       x11=c[i].x;
+                       y11=c[i].y;
+               }
+               x12=c[i].x;
+               y12=c[i].y;
+               
+               /* Perp. Distance from point to line */
+               if (m2!=MAXSLOPE) dist=(y12-m2*x12-b2);/* /sqrt(m2*m2+1); Only looking for */
+                       /* change in sign.  Skip extra math */  
+               else dist=x22-x12;      
+               
+               if (i==0) lastdist=dist;
+               
+               /* if dist changes sign, and intersect point in edge's Bound Box*/
+               if ((lastdist*dist)<=0){
+                       xdiff1=(x12-x11); /* Equation of line between last 2 points */
+                       if (xdiff1){
+                               m1=(y12-y11)/xdiff1;
+                               b1= ((x12*y11)-(x11*y12))/xdiff1;
+                       }
+                       else{
+                               m1=MAXSLOPE;
+                               b1=x12;
+                       }
+                       x2max=MAX2(x21,x22)+0.001; /* prevent missed edges   */
+                       x2min=MIN2(x21,x22)-0.001; /* due to round off error */
+                       y2max=MAX2(y21,y22)+0.001;
+                       y2min=MIN2(y21,y22)-0.001;
+                       
+                       /* Found an intersect,  calc intersect point */
+                       if (m1==m2){ /* co-incident lines */
+                               /* cut at 50% of overlap area*/
+                               x1max=MAX2(x11, x12);
+                               x1min=MIN2(x11, x12);
+                               xi= (MIN2(x2max,x1max)+MAX2(x2min,x1min))/2.0;  
+                               
+                               y1max=MAX2(y11, y12);
+                               y1min=MIN2(y11, y12);
+                               yi= (MIN2(y2max,y1max)+MAX2(y2min,y1min))/2.0;
+                       }                       
+                       else if (m2==MAXSLOPE){ 
+                               xi=x22;
+                               yi=m1*x22+b1;
+                       }
+                       else if (m1==MAXSLOPE){ 
+                               xi=x12;
+                               yi=m2*x12+b2;
+                       }
+                       else {
+                               xi=(b1-b2)/(m2-m1);
+                               yi=(b1*m2-m1*b2)/(m2-m1);
+                       }
+                       
+                       /* Intersect inside bounding box of edge?*/
+                       if ((xi>=x2min)&&(xi<=x2max)&&(yi<=y2max)&&(yi>=y2min)){
+                               /*test for vertex intersect that may be 'close enough'*/
+                               if(mode!=KNIFE_MULTICUT){
+                                       if(xi <= (x21 + threshold) && xi >= (x21 - threshold)){
+                                               if(yi <= (y21 + threshold) && yi >= (y21 - threshold)){
+                                                       *isected = 1;
+                                                       perc = 0;
+                                                       break;
+                                               }
+                                       }
+                                       if(xi <= (x22 + threshold) && xi >= (x22 - threshold)){
+                                               if(yi <= (y22 + threshold) && yi >= (y22 - threshold)){
+                                                       *isected = 2;
+                                                       perc = 0;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if ((m2<=1.0)&&(m2>=-1.0)) perc = (xi-x21)/(x22-x21);   
+                               else perc=(yi-y21)/(y22-y21); /*lower slope more accurate*/
+                               //isect=32768.0*(perc+0.0000153); /* Percentage in 1/32768ths */
+                               
+                               break;
+                       }
+               }       
+               lastdist=dist;
+       }
+       return(perc);
+} 
+
+#define MAX_CUTS 256
+
+static int knife_cut_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       BMEditMesh *em= (((Mesh *)obedit->data))->edit_btmesh;
+       BMesh *bm = em->bm;
+       ARegion *ar= CTX_wm_region(C);
+       BMVert *bv;
+       BMIter iter;
+       BMEdge *be;
+       BMOperator bmop;
+       CutCurve curve[MAX_CUTS];
+       struct GHash *gh;
+       float isect=0.0;
+       float  *scr, co[4];
+       int len=0, isected, flag, i;
+       short numcuts=1, mode= RNA_int_get(op->ptr, "type");
+       
+       /* edit-object needed for matrix, and ar->regiondata for projections to work */
+       if (ELEM3(NULL, obedit, ar, ar->regiondata))
+               return OPERATOR_CANCELLED;
+       
+       if (bm->totvertsel < 2) {
+               error("No edges are selected to operate on");
+               return OPERATOR_CANCELLED;;
+       }
+
+       /* get the cut curve */
+       RNA_BEGIN(op->ptr, itemptr, "path") {
+               
+               RNA_float_get_array(&itemptr, "loc", (float *)&curve[len]);
+               len++;
+               if(len>= MAX_CUTS) break;
+       }
+       RNA_END;
+       
+       if(len<2) {
+               return OPERATOR_CANCELLED;
+       }
+
+       /*the floating point coordinates of verts in screen space will be stored in a hash table according to the vertices pointer*/
+       gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+       for(bv=BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);bv;bv=BMIter_Step(&iter)){
+               scr = MEM_mallocN(sizeof(float)*2, "Vertex Screen Coordinates");
+               VECCOPY(co, bv->co);
+               co[3]= 1.0;
+               mul_m4_v4(obedit->obmat, co);
+               project_float(ar, co, scr);
+               BLI_ghash_insert(gh, bv, scr);
+       }
+       
+       BMO_Init_Op(&bmop, "esubd");
+       
+       i = 0;
+       /*store percentage of edge cut for KNIFE_EXACT here.*/
+       for (be=BMIter_New(&iter, bm, BM_EDGES_OF_MESH, NULL); be; be=BMIter_Step(&iter)) {
+               if( BM_Selected(bm, be) ) {
+                       isect= bm_seg_intersect(be, curve, len, mode, gh, &isected);
+                       
+                       if (isect != 0.0f) {
+                               if (mode != KNIFE_MULTICUT && mode != KNIFE_MIDPOINT) {
+                                       BMO_Insert_MapFloat(bm, &bmop, 
+                                              "edgepercents",
+                                              be, isect);
+
+                               }
+                               BMO_SetFlag(bm, be, 1);
+                       } else BMO_ClearFlag(bm, be, 1);
+               } else BMO_ClearFlag(bm, be, 1);
+       }
+       
+       BMO_Flag_To_Slot(bm, &bmop, "edges", 1, BM_EDGE);
+
+       BMO_Set_Int(&bmop, "numcuts", numcuts);
+       flag = B_KNIFE;
+       if (mode == KNIFE_MIDPOINT) numcuts = 1;
+       BMO_Set_Int(&bmop, "flag", flag);
+       BMO_Set_Float(&bmop, "radius", 0);
+       
+       BMO_Exec_Op(bm, &bmop);
+       BMO_Finish_Op(bm, &bmop);
+       
+       BLI_ghash_free(gh, NULL, (GHashValFreeFP)WMEM_freeN);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_knife_cut(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+       
+       ot->name= "Knife Cut";
+       ot->description= "Cut selected edges and faces into parts.";
+       ot->idname= "MESH_OT_knife_cut";
+       
+       ot->invoke= WM_gesture_lines_invoke;
+       ot->modal= WM_gesture_lines_modal;
+       ot->exec= knife_cut_exec;
+       
+       ot->poll= EM_view3d_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", knife_items, KNIFE_EXACT, "Type", "");
+       prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
+       
+       /* internal */
+       RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
+}
+
+static int mesh_separate_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Scene *scene= CTX_data_scene(C);
+       Base *base= CTX_data_active_base(C);
+       int retval= 0, type= RNA_enum_get(op->ptr, "type");
+       
+       if(type == 0)
+               retval= mesh_separate_selected(scene, base);
+       else if(type == 1)
+               retval= mesh_separate_material (scene, base);
+       else if(type == 2)
+               retval= mesh_separate_loose(scene, base);
+          
+       if(retval) {
+               WM_event_add_notifier(C, NC_GEOM|ND_DATA, base->object->data);
+               return OPERATOR_FINISHED;
+       }
+
+#endif
+       return OPERATOR_CANCELLED;
+}
+
+/* *************** Operator: separate parts *************/
+
+static EnumPropertyItem prop_separate_types[] = {
+       {0, "SELECTED", 0, "Selection", ""},
+       {1, "MATERIAL", 0, "By Material", ""},
+       {2, "LOOSE", 0, "By loose parts", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+void MESH_OT_separate(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Separate";
+       ot->description= "Separate selected geometry into a new mesh.";
+       ot->idname= "MESH_OT_separate";
+       
+       /* api callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= mesh_separate_exec;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", prop_separate_types, 0, "Type", "");
+}
+
+
+static int fill_mesh_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+
+       fill_mesh(em);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+
+}
+
+void MESH_OT_fill(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Fill";
+       ot->idname= "MESH_OT_fill";
+
+       /* api callbacks */
+       ot->exec= fill_mesh_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int beauty_fill_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+
+       beauty_fill(em);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_beauty_fill(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Beauty Fill";
+       ot->idname= "MESH_OT_beauty_fill";
+
+       /* api callbacks */
+       ot->exec= beauty_fill_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/********************** Quad/Tri Operators *************************/
+
+static int quads_convert_to_tris_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
+
+       //convert_to_triface(em,0);
+       if (!EDBM_CallOpf(em, op, "triangulate faces=%hf", BM_SELECT))
+               return OPERATOR_CANCELLED;
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_quads_convert_to_tris(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Quads to Tris";
+       ot->idname= "MESH_OT_quads_convert_to_tris";
+
+       /* api callbacks */
+       ot->exec= quads_convert_to_tris_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int tris_convert_to_quads_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+
+       join_triangles(em);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_tris_convert_to_quads(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Tris to Quads";
+       ot->idname= "MESH_OT_tris_convert_to_quads";
+
+       /* api callbacks */
+       ot->exec= tris_convert_to_quads_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int edge_flip_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+
+       edge_flip(em);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_edge_flip(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Edge Flip";
+       ot->idname= "MESH_OT_edge_flip";
+
+       /* api callbacks */
+       ot->exec= edge_flip_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int split_mesh(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+
+       WM_cursor_wait(1);
+
+       /* make duplicate first */
+       adduplicateflag(em, SELECT);
+       /* old faces have flag 128 set, delete them */
+       delfaceflag(em, 128);
+       recalc_editnormals(em);
+
+       WM_cursor_wait(0);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+       return OPERATOR_FINISHED;
+#endif
+}
+
+void MESH_OT_split(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Split";
+       ot->idname= "MESH_OT_split";
+
+       /* api callbacks */
+       ot->exec= split_mesh;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+
+static int spin_mesh(bContext *C, wmOperator *op, float *dvec, int steps, float degr, int dupli )
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       ToolSettings *ts= CTX_data_tool_settings(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+       EditVert *eve,*nextve;
+       float nor[3]= {0.0f, 0.0f, 0.0f};
+       float si, n[3], q[4], cmat[3][3], imat[3][3], tmat[3][3];
+       float cent[3], bmat[3][3];
+       float phi;
+       short a, ok= 1;
+
+       RNA_float_get_array(op->ptr, "center", cent);
+
+       /* imat and center and size */
+       copy_m3_m4(bmat, obedit->obmat);
+       invert_m3_m3(imat,bmat);
+
+       cent[0]-= obedit->obmat[3][0];
+       cent[1]-= obedit->obmat[3][1];
+       cent[2]-= obedit->obmat[3][2];
+       mul_m3_v3(imat, cent);
+
+       phi= degr*M_PI/360.0;
+       phi/= steps;
+       if(ts->editbutflag & B_CLOCKWISE) phi= -phi;
+
+       RNA_float_get_array(op->ptr, "axis", n);
+       normalize_v3(n);
+
+       q[0]= (float)cos(phi);
+       si= (float)sin(phi);
+       q[1]= n[0]*si;
+       q[2]= n[1]*si;
+       q[3]= n[2]*si;
+       quat_to_mat3( cmat,q);
+
+       mul_m3_m3m3(tmat,cmat,bmat);
+       mul_m3_m3m3(bmat,imat,tmat);
+
+       if(dupli==0)
+               if(ts->editbutflag & B_KEEPORIG)
+                       adduplicateflag(em, 1);
+
+       for(a=0; a<steps; a++) {
+               if(dupli==0) ok= extrudeflag(obedit, em, SELECT, nor, 0);
+               else adduplicateflag(em, SELECT);
+
+               if(ok==0)
+                       break;
+
+               rotateflag(em, SELECT, cent, bmat);
+               if(dvec) {
+                       mul_m3_v3(bmat,dvec);
+                       translateflag(em, SELECT, dvec);
+               }
+       }
+
+       if(ok==0) {
+               /* no vertices or only loose ones selected, remove duplicates */
+               eve= em->verts.first;
+               while(eve) {
+                       nextve= eve->next;
+                       if(eve->f & SELECT) {
+                               BLI_remlink(&em->verts,eve);
+                               free_editvert(em, eve);
+                       }
+                       eve= nextve;
+               }
+       }
+       else {
+               recalc_editnormals(em);
+
+               EM_fgon_flags(em);
+
+               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       }
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+       return ok;
+#endif
+}
+
+static int spin_mesh_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       int ok;
+
+       ok= spin_mesh(C, op, NULL, RNA_int_get(op->ptr,"steps"), RNA_float_get(op->ptr,"degrees"), RNA_boolean_get(op->ptr,"dupli"));
+       if(ok==0) {
+               BKE_report(op->reports, RPT_ERROR, "No valid vertices are selected");
+               return OPERATOR_CANCELLED;
+       }
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+/* get center and axis, in global coords */
+static int spin_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+#if 0
+       Scene *scene = CTX_data_scene(C);
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
+
+       RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
+       RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]);
+
+       return spin_mesh_exec(C, op);
+#endif
+}
+
+void MESH_OT_spin(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Spin";
+       ot->idname= "MESH_OT_spin";
+
+       /* api callbacks */
+       ot->invoke= spin_mesh_invoke;
+       ot->exec= spin_mesh_exec;
+       ot->poll= EM_view3d_poll;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX);
+       RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates");
+       RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f);
+
+       RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
+       RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
+
+}
+
+static int screw_mesh_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+       EditVert *eve,*v1=0,*v2=0;
+       EditEdge *eed;
+       float dvec[3], nor[3];
+       int steps, turns;
+
+       turns= RNA_int_get(op->ptr, "turns");
+       steps= RNA_int_get(op->ptr, "steps");
+
+       /* clear flags */
+       for(eve= em->verts.first; eve; eve= eve->next)
+               eve->f1= 0;
+
+       /* edges set flags in verts */
+       for(eed= em->edges.first; eed; eed= eed->next) {
+               if(eed->v1->f & SELECT) {
+                       if(eed->v2->f & SELECT) {
+                               /* watch: f1 is a byte */
+                               if(eed->v1->f1<2) eed->v1->f1++;
+                               if(eed->v2->f1<2) eed->v2->f1++;
+                       }
+               }
+       }
+       /* find two vertices with eve->f1==1, more or less is wrong */
+       for(eve= em->verts.first; eve; eve= eve->next) {
+               if(eve->f1==1) {
+                       if(v1==NULL) v1= eve;
+                       else if(v2==NULL) v2= eve;
+                       else {
+                               v1= NULL;
+                               break;
+                       }
+               }
+       }
+       if(v1==NULL || v2==NULL) {
+               BKE_report(op->reports, RPT_ERROR, "You have to select a string of connected vertices too");
+               BKE_mesh_end_editmesh(obedit->data, em);
+               return OPERATOR_CANCELLED;
+       }
+
+       /* calculate dvec */
+       dvec[0]= ( v1->co[0]- v2->co[0] )/steps;
+       dvec[1]= ( v1->co[1]- v2->co[1] )/steps;
+       dvec[2]= ( v1->co[2]- v2->co[2] )/steps;
+
+       VECCOPY(nor, obedit->obmat[2]);
+
+       if(nor[0]*dvec[0]+nor[1]*dvec[1]+nor[2]*dvec[2]>0.000) {
+               dvec[0]= -dvec[0];
+               dvec[1]= -dvec[1];
+               dvec[2]= -dvec[2];
+       }
+
+       if(spin_mesh(C, op, dvec, turns*steps, 360.0f*turns, 0)) {
+               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+               WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+               BKE_mesh_end_editmesh(obedit->data, em);
+               return OPERATOR_FINISHED;
+       }
+       else {
+               BKE_report(op->reports, RPT_ERROR, "No valid vertices are selected");
+               BKE_mesh_end_editmesh(obedit->data, em);
+               return OPERATOR_CANCELLED;
+       }
+#endif
+}
+
+/* get center and axis, in global coords */
+static int screw_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+#if 0
+       Scene *scene = CTX_data_scene(C);
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
+
+       RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
+       RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]);
+#endif
+       return screw_mesh_exec(C, op);
+}
+
+void MESH_OT_screw(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Screw";
+       ot->idname= "MESH_OT_screw";
+
+       /* api callbacks */
+       ot->invoke= screw_mesh_invoke;
+       ot->exec= screw_mesh_exec;
+       ot->poll= EM_view3d_poll;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /*props */
+       RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256);
+       RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256);
+
+       RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
+       RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
+}
+
+static int region_to_loop(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+       EditEdge *eed;
+       EditFace *efa;
+       int selected= 0;
+
+       for(eed=em->edges.first; eed; eed=eed->next) eed->f1 = 0;
+
+       for(efa=em->faces.first; efa; efa=efa->next){
+               if(efa->f&SELECT){
+                       efa->e1->f1++;
+                       efa->e2->f1++;
+                       efa->e3->f1++;
+                       if(efa->e4)
+                               efa->e4->f1++;
+
+                       selected= 1;
+               }
+       }
+
+       if(!selected)
+               return OPERATOR_CANCELLED;
+
+       EM_clear_flag_all(em, SELECT);
+
+       for(eed=em->edges.first; eed; eed=eed->next){
+               if(eed->f1 == 1) EM_select_edge(eed, 1);
+       }
+
+       em->selectmode = SCE_SELECT_EDGE;
+       EM_selectmode_set(em);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_region_to_loop(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Region to Loop";
+       ot->idname= "MESH_OT_region_to_loop";
+
+       /* api callbacks */
+       ot->exec= region_to_loop;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+static int loop_to_region(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+
+
+       EditFace *efa;
+       ListBase allcollections={NULL,NULL};
+       Collection *edgecollection;
+       int testflag;
+
+       build_edgecollection(em, &allcollections);
+
+       for(edgecollection = (Collection *)allcollections.first; edgecollection; edgecollection=edgecollection->next){
+               if(validate_loop(em, edgecollection)){
+                       testflag = loop_bisect(em, edgecollection);
+                       for(efa=em->faces.first; efa; efa=efa->next){
+                               if(efa->f1 == testflag){
+                                       if(efa->f&SELECT) EM_select_face(efa, 0);
+                                       else EM_select_face(efa,1);
+                               }
+                       }
+               }
+       }
+
+       for(efa=em->faces.first; efa; efa=efa->next){ /*fix this*/
+               if(efa->f&SELECT) EM_select_face(efa,1);
+       }
+
+       freecollections(&allcollections);
+       BKE_mesh_end_editmesh(obedit->data, em);
+
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_loop_to_region(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Loop to Region";
+       ot->idname= "MESH_OT_loop_to_region";
+
+       /* api callbacks */
+       ot->exec= loop_to_region;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+int select_by_number_vertices_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       EditFace *efa;
+       int numverts= RNA_enum_get(op->ptr, "type");
+
+       /* Selects trias/qiads or isolated verts, and edges that do not have 2 neighboring
+        * faces
+        */
+
+       /* for loose vertices/edges, we first select all, loop below will deselect */
+       if(numverts==5) {
+               EM_set_flag_all(em, SELECT);
+       }
+       else if(em->selectmode!=SCE_SELECT_FACE) {
+               BKE_report(op->reports, RPT_ERROR, "Only works in face selection mode");
+               return OPERATOR_CANCELLED;
+       }
+       
+       for(efa= em->faces.first; efa; efa= efa->next) {
+               if (efa->e4) {
+                       EM_select_face(efa, (numverts==4) );
+               }
+               else {
+                       EM_select_face(efa, (numverts==3) );
+               }
+       }
+
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_select_by_number_vertices(wmOperatorType *ot)
+{
+       static const EnumPropertyItem type_items[]= {
+               {3, "TRIANGLES", 0, "Triangles", NULL},
+               {4, "QUADS", 0, "Triangles", NULL},
+               {5, "OTHER", 0, "Other", NULL},
+               {0, NULL, 0, NULL, NULL}};
+
+       /* identifiers */
+       ot->name= "Select by Number of Vertices";
+       ot->description= "Select vertices or faces by vertex count.";
+       ot->idname= "MESH_OT_select_by_number_vertices";
+       
+       /* api callbacks */
+       ot->exec= select_by_number_vertices_exec;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_enum(ot->srna, "type", type_items, 3, "Type", "Type of elements to select.");
+}
+
+
+int select_mirror_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+
+       int extend= RNA_boolean_get(op->ptr, "extend");
+
+       EM_select_mirrored(obedit, em, extend);
+
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+#endif
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_select_mirror(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select Mirror";
+       ot->description= "Select mesh items at mirrored locations.";
+       ot->idname= "MESH_OT_select_mirror";
+
+       /* api callbacks */
+       ot->exec= select_mirror_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection");
+}
+
+static int select_sharp_edges_exec(bContext *C, wmOperator *op)
+{
+       /* Find edges that have exactly two neighboring faces,
+       * check the angle between those faces, and if angle is
+       * small enough, select the edge
+       */
+}
+
+void MESH_OT_edges_select_sharp(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select Sharp Edges";
+       ot->description= "Marked selected edges as sharp.";
+       ot->idname= "MESH_OT_edges_select_sharp";
+       
+       /* api callbacks */
+       ot->exec= select_sharp_edges_exec;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_float(ot->srna, "sharpness", 0.01f, 0.0f, FLT_MAX, "sharpness", "", 0.0f, 180.0f);
+}
+
+static int select_linked_flat_faces_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       
+       select_linked_flat_faces(em, op, RNA_float_get(op->ptr, "sharpness"));
+       
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+       return OPERATOR_FINISHED;
+#endif
+}
+
+void MESH_OT_faces_select_linked_flat(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select Linked Flat Faces";
+       ot->description= "Select linked faces by angle.";
+       ot->idname= "MESH_OT_faces_select_linked_flat";
+       
+       /* api callbacks */
+       ot->exec= select_linked_flat_faces_exec;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_float(ot->srna, "sharpness", 0.0f, 0.0f, FLT_MAX, "sharpness", "", 0.0f, 180.0f);
+}
+
+static int select_non_manifold_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       
+       select_non_manifold(em, op);
+       
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+       return OPERATOR_FINISHED;
+#endif
+}
+
+void MESH_OT_select_non_manifold(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select Non Manifold";
+       ot->description= "Select all non-manifold vertices or edges.";
+       ot->idname= "MESH_OT_select_non_manifold";
+       
+       /* api callbacks */
+       ot->exec= select_non_manifold_exec;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int mesh_select_random_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       
+       if(!RNA_boolean_get(op->ptr, "extend"))
+               EM_deselect_all(em);
+       
+       selectrandom_mesh(em, RNA_float_get(op->ptr, "percent")/100.0f);
+               
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+       
+       BKE_mesh_end_editmesh(obedit->data, em);
+#endif
+       return OPERATOR_FINISHED;       
+}
+
+void MESH_OT_select_random(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select Random";
+       ot->description= "Randomly select vertices.";
+       ot->idname= "MESH_OT_select_random";
+
+       /* api callbacks */
+       ot->exec= mesh_select_random_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly.", 0.f, 100.0f);
+       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first.");
+}
index fc740b699d4f55dc31094300914af865341066ff..d0f89eda31337de149088378cb4f044dc2133dea 100644 (file)
@@ -118,33 +118,6 @@ void EDBM_stats_update(BMEditMesh *em)
        }
 }
 
-/*this function is defunct, dead*/
-void EDBM_Tesselate(EditMesh *em)
-{
-       EditMesh *em2;
-       EditFace *efa;
-       BMesh *bm;
-       int found=0;
-       
-       for (efa=em->faces.first; efa; efa=efa->next) {
-               if ((efa->e1->h & EM_FGON) || (efa->e2->h & EM_FGON) ||
-                   (efa->e3->h & EM_FGON) || (efa->e4&&(efa->e4->h&EM_FGON)))
-               {
-                       found = 1;
-                       break;
-               }
-       }
-
-       if (found) {
-               bm = editmesh_to_bmesh(em);
-               em2 = bmesh_to_editmesh(bm);
-               set_editMesh(em, em2);
-
-               MEM_freeN(em2);
-               BM_Free_Mesh(bm);
-       }
-}
-
 int EDBM_InitOpf(BMEditMesh *em, BMOperator *bmop, wmOperator *op, char *fmt, ...)
 {
        BMesh *bm = em->bm;
@@ -228,6 +201,32 @@ int EDBM_CallOpf(BMEditMesh *em, wmOperator *op, char *fmt, ...)
        return EDBM_FinishOp(em, &bmop, op, 1);
 }
 
+int EDBM_CallAndSelectOpf(BMEditMesh *em, wmOperator *op, char *selectslot, char *fmt, ...)
+{
+       BMesh *bm = em->bm;
+       BMOperator bmop;
+       va_list list;
+
+       va_start(list, fmt);
+
+       if (!BMO_VInitOpf(bm, &bmop, fmt, list)) {
+               BKE_report(op->reports, RPT_ERROR,
+                          "Parse error in EDBM_CallOpf");
+               va_end(list);
+               return 0;
+       }
+
+       if (!em->emcopy)
+               em->emcopy = BMEdit_Copy(em);
+       em->emcopyusers++;
+
+       BMO_Exec_Op(bm, &bmop);
+       BMO_HeaderFlag_Buffer(em->bm, &bmop, selectslot, BM_SELECT, BM_ALL);
+
+       va_end(list);
+       return EDBM_FinishOp(em, &bmop, op, 1);
+}
+
 int EDBM_CallOpfSilent(BMEditMesh *em, char *fmt, ...)
 {
        BMesh *bm = em->bm;
@@ -258,12 +257,10 @@ void EDBM_MakeEditBMesh(ToolSettings *ts, Scene *scene, Object *ob)
        BMesh *bm;
 
        if (!me->mpoly && me->totface) {
-               printf("yeek!! bmesh conversion issue! may lose shapekeys!\n");
-
-               em = make_editMesh(scene, ob);
-               bm = editmesh_to_bmesh(em);
-       
-               free_editMesh(em);
+               printf("yeek!! bmesh conversion issue! may lose lots of geometry!\n");
+               
+               /*BMESH_TODO need to write smarter code here*/
+               bm = BKE_mesh_to_bmesh(me, ob);
        } else {
                bm = BKE_mesh_to_bmesh(me, ob);
        }
@@ -788,7 +785,8 @@ MTexPoly *EDBM_get_active_mtexpoly(BMEditMesh *em, BMFace **act_efa, int sloppy)
 int EDBM_texFaceCheck(BMEditMesh *em)
 {
        /* some of these checks could be a touch overkill */
-       return em && em->bm->totface && CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY);
+       return em && em->bm->totface && CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY) &&
+                  CustomData_has_layer(&em->bm->ldata, CD_MLOOPCOL);
 }
 
 int EDBM_vertColorCheck(BMEditMesh *em)
diff --git a/source/blender/editors/mesh/editbmesh_add.c b/source/blender/editors/mesh/editbmesh_add.c
new file mode 100644 (file)
index 0000000..b263180
--- /dev/null
@@ -0,0 +1,529 @@
+ /* $Id: bmesh_tools.c
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2004 by Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Joseph Eagar
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <math.h>
+#include <float.h>
+
+#include "MEM_guardedalloc.h"
+#include "PIL_time.h"
+
+#include "BLO_sys_types.h" // for intptr_t support
+
+#include "DNA_mesh_types.h"
+#include "DNA_material_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_key_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "RNA_types.h"
+#include "RNA_define.h"
+#include "RNA_access.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_editVert.h"
+#include "BLI_rand.h"
+#include "BLI_ghash.h"
+#include "BLI_linklist.h"
+#include "BLI_heap.h"
+#include "BLI_array.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_utildefines.h"
+#include "BKE_bmesh.h"
+#include "BKE_report.h"
+#include "BKE_tessmesh.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_mesh.h"
+#include "ED_view3d.h"
+#include "ED_util.h"
+#include "ED_screen.h"
+#include "ED_transform.h"
+#include "ED_object.h"
+
+#include "UI_interface.h"
+
+#include "mesh_intern.h"
+#include "bmesh.h"
+
+#include "editbmesh_bvh.h"
+
+
+/* uses context to figure out transform for primitive */
+/* returns standard diameter */
+static float new_primitive_matrix(bContext *C, float *loc, float *rot, float primmat[][4])
+{
+       Object *obedit= CTX_data_edit_object(C);
+       View3D *v3d =CTX_wm_view3d(C);
+       float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3];
+       
+       unit_m4(primmat);
+
+       eul_to_mat3(rmat, rot);
+       invert_m3(rmat);
+       
+       /* inverse transform for initial rotation and object */
+       copy_m3_m4(mat, obedit->obmat);
+       mul_m3_m3m3(cmat, rmat, mat);
+       invert_m3_m3(imat, cmat);
+       copy_m4_m3(primmat, imat);
+
+       /* center */
+       VECCOPY(primmat[3], loc);
+       VECSUB(primmat[3], primmat[3], obedit->obmat[3]);
+       invert_m3_m3(imat, mat);
+       mul_m3_v3(imat, primmat[3]);
+       
+       if(v3d) return v3d->grid;
+       return 1.0f;
+}
+
+/* ********* add primitive operators ************* */
+
+static void make_prim_init(bContext *C, float *dia, float mat[][4], 
+                                                  int *state, float *loc, float *rot)
+{
+       Object *obedit= CTX_data_edit_object(C);
+
+       *state = 0;
+       if(obedit==NULL || obedit->type!=OB_MESH) {
+               obedit= ED_object_add_type(C, OB_MESH, loc, rot, FALSE);
+               
+               /* create editmode */
+               ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
+               *state = 1;
+       }
+       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+
+       *dia *= new_primitive_matrix(C, loc, rot, mat);
+}
+
+static void make_prim_finish(bContext *C, int *state, int enter_editmode)
+{
+       Object *obedit = CTX_data_edit_object(C);
+
+       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       /* userdef */
+       if (*state && !enter_editmode) {
+               ED_object_exit_editmode(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */
+       }
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+
+}
+static int add_primitive_plane_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit;
+       Mesh *me;
+       BMEditMesh *em;
+       float loc[3], rot[3], mat[4][4], dia;
+       int enter_editmode;
+       int state;
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+       make_prim_init(C, &dia, mat, &state, loc, rot);
+
+       obedit = CTX_data_edit_object(C);
+       me = obedit->data;
+       em = me->edit_btmesh;
+
+       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
+                       "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, sqrt(2.0), mat)) 
+               return OPERATOR_CANCELLED;
+       
+       /* BMESH_TODO make plane side this: sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */
+       make_prim_finish(C, &state, enter_editmode);
+
+       return OPERATOR_FINISHED;       
+}
+
+void MESH_OT_primitive_plane_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Plane";
+       ot->description= "Construct a filled planar mesh with 4 vertices.";
+       ot->idname= "MESH_OT_primitive_plane_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_plane_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_cube_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit;
+       Mesh *me;
+       BMEditMesh *em;
+       float loc[3], rot[3], mat[4][4], dia;
+       int enter_editmode;
+       int state;
+
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+
+       make_prim_init(C, &dia, mat, &state, loc, rot);
+
+       obedit= CTX_data_edit_object(C);
+       me = obedit->data;
+       em = me->edit_btmesh;
+
+       if (!EDBM_CallAndSelectOpf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, 2.0f)) 
+               return OPERATOR_CANCELLED;
+       
+       /* BMESH_TODO make plane side this: sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */
+       make_prim_finish(C, &state, enter_editmode);
+
+       return OPERATOR_FINISHED;       
+}
+
+void MESH_OT_primitive_cube_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Cube";
+       ot->description= "Construct a cube mesh.";
+       ot->idname= "MESH_OT_primitive_cube_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_cube_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_circle_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       int enter_editmode;
+       float loc[3], rot[3];
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+
+       make_prim_ext(C, loc, rot, enter_editmode,
+                       PRIM_CIRCLE, RNA_int_get(op->ptr, "vertices"), 0, 0,
+                       RNA_float_get(op->ptr,"radius"), 0.0f, 0,
+                       RNA_boolean_get(op->ptr, "fill"));
+#endif
+       return OPERATOR_FINISHED;       
+}
+
+void MESH_OT_primitive_circle_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Circle";
+       ot->description= "Construct a circle mesh.";
+       ot->idname= "MESH_OT_primitive_circle_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_circle_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 3, 500);
+       RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
+       RNA_def_boolean(ot->srna, "fill", 0, "Fill", "");
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_tube_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       int enter_editmode;
+       float loc[3], rot[3];
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+
+       make_prim_ext(C, loc, rot, enter_editmode,
+                       PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0,
+                       RNA_float_get(op->ptr, "radius"),
+                       RNA_float_get(op->ptr, "depth"), 1, 
+                       RNA_boolean_get(op->ptr, "cap_ends"));
+#endif
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_primitive_tube_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Tube";
+       ot->description= "Construct a tube mesh.";
+       ot->idname= "MESH_OT_primitive_tube_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_tube_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
+       RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
+       RNA_def_boolean(ot->srna, "cap_ends", 1, "Cap Ends", "");
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_cone_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       int enter_editmode;
+       float loc[3], rot[3];
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+
+       make_prim_ext(C, loc, rot, enter_editmode,
+                       PRIM_CONE, RNA_int_get(op->ptr, "vertices"), 0, 0,
+                       RNA_float_get(op->ptr,"radius"), RNA_float_get(op->ptr, "depth"),
+                       0, RNA_boolean_get(op->ptr, "cap_end"));
+#endif
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_primitive_cone_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Cone";
+       ot->description= "Construct a conic mesh (ends filled).";
+       ot->idname= "MESH_OT_primitive_cone_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_cone_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
+       RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
+       RNA_def_boolean(ot->srna, "cap_end", 0, "Cap End", "");
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_grid_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       int enter_editmode;
+       float loc[3], rot[3];
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+
+       make_prim_ext(C, loc, rot, enter_editmode,
+                       PRIM_GRID, RNA_int_get(op->ptr, "x_subdivisions"),
+                       RNA_int_get(op->ptr, "y_subdivisions"), 0,
+                       RNA_float_get(op->ptr,"size"), 0.0f, 0, 1);
+#endif
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_primitive_grid_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Grid";
+       ot->description= "Construct a grid mesh.";
+       ot->idname= "MESH_OT_primitive_grid_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_grid_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_int(ot->srna, "x_subdivisions", 10, INT_MIN, INT_MAX, "X Subdivisions", "", 3, 1000);
+       RNA_def_int(ot->srna, "y_subdivisions", 10, INT_MIN, INT_MAX, "Y Subdivisions", "", 3, 1000);
+       RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, FLT_MAX);
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       int enter_editmode;
+       float loc[3], rot[3];
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+
+       make_prim_ext(C, loc, rot, enter_editmode,
+                       PRIM_MONKEY, 0, 0, 2, 0.0f, 0.0f, 0, 0);
+#endif
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Monkey";
+       ot->description= "Construct a Suzanne mesh.";
+       ot->idname= "MESH_OT_primitive_monkey_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_monkey_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+
+static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit;
+       Mesh *me;
+       BMEditMesh *em;
+       float loc[3], rot[3], mat[4][4], dia;
+       int enter_editmode;
+       int state;
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+       make_prim_init(C, &dia, mat, &state, loc, rot);
+
+       obedit = CTX_data_edit_object(C);
+       me = obedit->data;
+       em = me->edit_btmesh;
+
+       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
+                       "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4", 
+                       RNA_int_get(op->ptr, "rings"), RNA_int_get(op->ptr, "segments"),
+                       RNA_float_get(op->ptr,"size"), mat)) 
+               return OPERATOR_CANCELLED;
+       
+       make_prim_finish(C, &state, enter_editmode);
+
+       return OPERATOR_FINISHED;       
+}
+
+void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add UV Sphere";
+       ot->description= "Construct a UV sphere mesh.";
+       ot->idname= "MESH_OT_primitive_uv_sphere_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_uvsphere_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_int(ot->srna, "segments", 32, INT_MIN, INT_MAX, "Segments", "", 3, 500);
+       RNA_def_int(ot->srna, "rings", 24, INT_MIN, INT_MAX, "Rings", "", 3, 500);
+       RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, 100.00);
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
+{
+#if 0
+       int enter_editmode;
+       float loc[3], rot[3];
+       
+       ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode);
+
+       make_prim_ext(C, loc, rot, enter_editmode,
+                       PRIM_ICOSPHERE, 0, 0, RNA_int_get(op->ptr, "subdivisions"),
+                       RNA_float_get(op->ptr,"size"), 0.0f, 0, 0);
+#endif
+
+       return OPERATOR_FINISHED;       
+}
+
+void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Ico Sphere";
+       ot->description= "Construct an Icosphere mesh.";
+       ot->idname= "MESH_OT_primitive_ico_sphere_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_icosphere_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* props */
+       RNA_def_int(ot->srna, "subdivisions", 2, 0, 6, "Subdivisions", "", 0, 8);
+       RNA_def_float(ot->srna, "size", 1.0f, 0.0f, FLT_MAX, "Size", "", 0.001f, 100.00);
+
+       ED_object_add_generic_props(ot, TRUE);
+}
index 4fa7a19a1b3a7e9a068be04a95fe0ce05bf18362..396ba6b0fde7df176fdcad31281bf388c488ad95 100644 (file)
@@ -61,6 +61,7 @@
 #include "BKE_utildefines.h"
 #include "BKE_customdata.h"
 #include "BKE_context.h"
+#include "BKE_tessmesh.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -94,40 +95,54 @@ void object_facesel_flush_dm(Object *ob)
 {
        Mesh *me= get_mesh(ob);
        DerivedMesh *dm= ob->derivedFinal;
-       MFace *faces, *mf, *mf_orig;
-       int *index_array = NULL;
+       MPoly *faces, *mf, *mf_orig;
+       DMFaceIter *fiter;
+       int *index = NULL;
        int totface;
        int i;
        
        if(me==NULL || dm==NULL)
                return;
 
-       index_array = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+       fiter = dm->newFaceIter(dm);
+       totface = dm->getNumFaces(dm);
 
-       if(!index_array)
-               return;
-       
-       faces = dm->getTessFaceArray(dm);
-       totface = dm->getNumTessFaces(dm);
-       
-       mf= faces;
-       
-       for (i= 0; i<totface; i++, mf++) { /* loop over derived mesh faces */
-               mf_orig= me->mface + index_array[i];
-               mf->flag= mf_orig->flag;;
+       for (i=0; !fiter->done; fiter->step(fiter), i++) {
+               index = fiter->getCDData(fiter, CD_ORIGINDEX, -1);
+               if (!index) {
+                       fiter->free(fiter);
+                       return;
+               }
+               
+               mf_orig = me->mpoly + *index;
+               fiter->flags = mf_orig->flag; 
        }
+
+       fiter->free(fiter);
 }
 
 /* returns 0 if not found, otherwise 1 */
-int facesel_face_pick(struct bContext *C, Mesh *me, short *mval, unsigned int *index, short rect)
+int facesel_face_pick(struct bContext *C, Mesh *me, Object *ob, 
+                                         short *mval, unsigned int *index, short rect)
 {
+       Scene *scene = CTX_data_scene(C);
        ViewContext vc;
        view3d_set_viewcontext(C, &vc);
 
-       if (!me || me->totface==0)
+       if (!me || me->totpoly==0)
                return 0;
 
-// XXX         if (v3d->flag & V3D_INVALID_BACKBUF) {
+       /*we can't assume mfaces have a correct origindex layer that indices to mpolys.
+         so instead we have to regenerate the tesselation faces altogether.
+         
+         the final 0, 0 paramters causes it to use the index of each mpoly, instead
+         of reading from the origindex layer.*/
+       me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata, 
+               me->mvert, me->totface, me->totloop, me->totpoly, 0, 0);
+       mesh_update_customdata_pointers(me);
+       makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH);
+
+       // XXX  if (v3d->flag & V3D_INVALID_BACKBUF) {
 // XXX drawview.c!             check_backbuf();
 // XXX         persp(PERSP_VIEW);
 // XXX         }
@@ -144,7 +159,7 @@ int facesel_face_pick(struct bContext *C, Mesh *me, short *mval, unsigned int *i
                *index = view3d_sample_backbuf(&vc, mval[0], mval[1]);
        }
 
-       if ((*index)<=0 || (*index)>(unsigned int)me->totface)
+       if ((*index)<=0 || (*index)>(unsigned int)me->totpoly)
                return 0;
 
        (*index)--;
@@ -154,41 +169,37 @@ int facesel_face_pick(struct bContext *C, Mesh *me, short *mval, unsigned int *i
 
 /* last_sel, use em->act_face otherwise get the last selected face in the editselections
  * at the moment, last_sel is mainly useful for gaking sure the space image dosnt flicker */
-MTFace *EM_get_active_mtface(EditMesh *em, EditFace **act_efa, MCol **mcol, int sloppy)
+MTexPoly *EDBM_get_active_mtface(BMEditMesh *em, BMFace **act_efa, int sloppy)
 {
-       EditFace *efa = NULL;
+       BMFace *efa = NULL;
+       BMLoop *l;
+       BMIter iter, liter;
        
-       if(!EM_texFaceCheck(em))
+       if(!EDBM_texFaceCheck(em))
                return NULL;
        
-       efa = EM_get_actFace(em, sloppy);
+       efa = EDBM_get_actFace(em, sloppy);
        
        if (efa) {
-               if (mcol) {
-                       if (CustomData_has_layer(&em->fdata, CD_MCOL))
-                               *mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
-                       else
-                               *mcol = NULL;
-               }
                if (act_efa) *act_efa = efa; 
-               return CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+               return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
        }
+
        if (act_efa) *act_efa= NULL;
-       if(mcol) *mcol = NULL;
        return NULL;
 }
 
 void reveal_tface(Scene *scene)
 {
        Mesh *me;
-       MFace *mface;
+       MPoly *mface;
        int a;
        
        me= get_mesh(OBACT);
-       if(me==0 || me->totface==0) return;
+       if(me==0 || me->totpoly==0) return;
        
-       mface= me->mface;
-       a= me->totface;
+       mface= me->mpoly;
+       a= me->totpoly;
        while(a--) {
                if(mface->flag & ME_HIDE) {
                        mface->flag |= ME_FACE_SEL;
@@ -204,20 +215,20 @@ void reveal_tface(Scene *scene)
 void hide_tface(Scene *scene)
 {
        Mesh *me;
-       MFace *mface;
+       MPoly *mface;
        int a;
        int shift=0, alt= 0; // XXX
        
        me= get_mesh(OBACT);
-       if(me==0 || me->totface==0) return;
+       if(me==0 || me->totpoly==0) return;
        
        if(alt) {
                reveal_tface(scene);
                return;
        }
        
-       mface= me->mface;
-       a= me->totface;
+       mface= me->mpoly;
+       a= me->totpoly;
        while(a--) {
                if(mface->flag & ME_HIDE);
                else {
@@ -239,30 +250,30 @@ void hide_tface(Scene *scene)
 
 /* Set tface seams based on edge data, uses hash table to find seam edges. */
 
-static void hash_add_face(EdgeHash *ehash, MFace *mf)
+static void hash_add_face(EdgeHash *ehash, MPoly *mf, MLoop *mloop)
 {
-       BLI_edgehash_insert(ehash, mf->v1, mf->v2, NULL);
-       BLI_edgehash_insert(ehash, mf->v2, mf->v3, NULL);
-       if(mf->v4) {
-               BLI_edgehash_insert(ehash, mf->v3, mf->v4, NULL);
-               BLI_edgehash_insert(ehash, mf->v4, mf->v1, NULL);
-       }
-       else
-               BLI_edgehash_insert(ehash, mf->v3, mf->v1, NULL);
+       MLoop *ml, *ml2;
+       int i;
+
+       for (i=0, ml=mloop; i<mf->totloop; i++, ml++) {
+               ml2 = mloop + (i+1) % mf->totloop;
+               BLI_edgehash_insert(ehash, ml->v, ml2->v, NULL);
+       }
 }
 
 
 void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int index)
 {
-       MFace *mf;
-       int a, doit=1, mark=0;
-       char *linkflag;
        EdgeHash *ehash, *seamhash;
+       MPoly *mf;
+       MLoop *ml;
        MEdge *med;
+       char *linkflag;
+       int a, b, doit=1, mark=0;
 
        ehash= BLI_edgehash_new();
        seamhash = BLI_edgehash_new();
-       linkflag= MEM_callocN(sizeof(char)*me->totface, "linkflaguv");
+       linkflag= MEM_callocN(sizeof(char)*me->totpoly, "linkflaguv");
 
        for(med=me->medge, a=0; a < me->totedge; a++, med++)
                if(med->flag & ME_SEAM)
@@ -270,17 +281,17 @@ void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int index)
 
        if (mode==0 || mode==1) {
                /* only put face under cursor in array */
-               mf= ((MFace*)me->mface) + index;
-               hash_add_face(ehash, mf);
+               mf= ((MPoly*)me->mpoly) + index;
+               hash_add_face(ehash, mf, me->mloop + mf->loopstart);
                linkflag[index]= 1;
        }
        else {
                /* fill array by selection */
-               mf= me->mface;
-               for(a=0; a<me->totface; a++, mf++) {
+               mf= me->mpoly;
+               for(a=0; a<me->totpoly; a++, mf++) {
                        if(mf->flag & ME_HIDE);
                        else if(mf->flag & ME_FACE_SEL) {
-                               hash_add_face(ehash, mf);
+                               hash_add_face(ehash, mf, me->mloop + mf->loopstart);
                                linkflag[a]= 1;
                        }
                }
@@ -290,35 +301,26 @@ void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int index)
                doit= 0;
 
                /* expand selection */
-               mf= me->mface;
-               for(a=0; a<me->totface; a++, mf++) {
+               mf= me->mpoly;
+               for(a=0; a<me->totpoly; a++, mf++) {
                        if(mf->flag & ME_HIDE)
                                continue;
 
                        if(!linkflag[a]) {
+                               MLoop *mnextl;
                                mark= 0;
 
-                               if(!BLI_edgehash_haskey(seamhash, mf->v1, mf->v2))
-                                       if(BLI_edgehash_haskey(ehash, mf->v1, mf->v2))
-                                               mark= 1;
-                               if(!BLI_edgehash_haskey(seamhash, mf->v2, mf->v3))
-                                       if(BLI_edgehash_haskey(ehash, mf->v2, mf->v3))
-                                               mark= 1;
-                               if(mf->v4) {
-                                       if(!BLI_edgehash_haskey(seamhash, mf->v3, mf->v4))
-                                               if(BLI_edgehash_haskey(ehash, mf->v3, mf->v4))
-                                                       mark= 1;
-                                       if(!BLI_edgehash_haskey(seamhash, mf->v4, mf->v1))
-                                               if(BLI_edgehash_haskey(ehash, mf->v4, mf->v1))
-                                                       mark= 1;
+                               ml = me->mloop + mf->loopstart;
+                               for (b=0; b<mf->totloop; b++, ml++) {
+                                       mnextl = b < mf->totloop-1 ? ml - 1 : me->mloop + mf->loopstart;
+                                       if (!BLI_edgehash_haskey(seamhash, ml->v, mnextl->v))
+                                               if (!BLI_edgehash_haskey(ehash, ml->v, mnextl->v))
+                                                       mark = 1;
                                }
-                               else if(!BLI_edgehash_haskey(seamhash, mf->v3, mf->v1))
-                                       if(BLI_edgehash_haskey(ehash, mf->v3, mf->v1))
-                                               mark = 1;
 
                                if(mark) {
                                        linkflag[a]= 1;
-                                       hash_add_face(ehash, mf);
+                                       hash_add_face(ehash, mf, me->mloop + mf->loopstart);
                                        doit= 1;
                                }
                        }
@@ -330,24 +332,24 @@ void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int index)
        BLI_edgehash_free(seamhash, NULL);
 
        if(mode==0 || mode==2) {
-               for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+               for(a=0, mf=me->mpoly; a<me->totpoly; a++, mf++)
                        if(linkflag[a])
                                mf->flag |= ME_FACE_SEL;
                        else
                                mf->flag &= ~ME_FACE_SEL;
        }
        else if(mode==1) {
-               for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+               for(a=0, mf=me->mpoly; a<me->totpoly; a++, mf++)
                        if(linkflag[a] && (mf->flag & ME_FACE_SEL))
                                break;
 
-               if (a<me->totface) {
-                       for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+               if (a<me->totpoly) {
+                       for(a=0, mf=me->mpoly; a<me->totpoly; a++, mf++)
                                if(linkflag[a])
                                        mf->flag &= ~ME_FACE_SEL;
                }
                else {
-                       for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+                       for(a=0, mf=me->mface; a<me->totpoly; a++, mf++)
                                if(linkflag[a])
                                        mf->flag |= ME_FACE_SEL;
                }
@@ -365,7 +367,7 @@ void select_linked_tfaces(bContext *C, Object *ob, short mval[2], int mode)
        unsigned int index=0;
 
        me = get_mesh(ob);
-       if(me==0 || me->totface==0) return;
+       if(me==0 || me->totpoly==0) return;
 
        if (mode==0 || mode==1) {
                // XXX - Causes glitches, not sure why
@@ -383,7 +385,7 @@ void select_linked_tfaces(bContext *C, Object *ob, short mval[2], int mode)
 void selectall_tface(Object *ob, int action)
 {
        Mesh *me;
-       MFace *mface;
+       MPoly *mface;
        int a;
 
        me= get_mesh(ob);
@@ -392,8 +394,8 @@ void selectall_tface(Object *ob, int action)
        if (action == SEL_TOGGLE) {
                action = SEL_SELECT;
 
-               mface= me->mface;
-               a= me->totface;
+               mface= me->mpoly;
+               a= me->totpoly;
                while(a--) {
                        if((mface->flag & ME_HIDE) == 0 && mface->flag & ME_FACE_SEL) {
                                action = SEL_DESELECT;
@@ -403,8 +405,8 @@ void selectall_tface(Object *ob, int action)
                }
        }
        
-       mface= me->mface;
-       a= me->totface;
+       mface= me->mpoly;
+       a= me->totpoly;
        while(a--) {
                if((mface->flag & ME_HIDE) == 0) {
                        switch (action) {
@@ -429,14 +431,14 @@ void selectall_tface(Object *ob, int action)
 void selectswap_tface(Scene *scene)
 {
        Mesh *me;
-       MFace *mface;
+       MPoly *mface;
        int a;
                
        me= get_mesh(OBACT);
        if(me==0) return;
        
-       mface= me->mface;
-       a= me->totface;
+       mface= me->mpoly;
+       a= me->totpoly;
        while(a--) {
                if(mface->flag & ME_HIDE);
                else {
@@ -454,49 +456,39 @@ int minmax_tface(Scene *scene, float *min, float *max)
 {
        Object *ob;
        Mesh *me;
-       MFace *mf;
-       MTFace *tf;
+       MPoly *mf;
+       MTexPoly *tf;
+       MLoop *ml;
        MVert *mv;
-       int a, ok=0;
+       int a, b, ok=0;
        float vec[3], bmat[3][3];
        
        ob = OBACT;
        if (ob==0) return ok;
+
        me= get_mesh(ob);
-       if(me==0 || me->mtface==0) return ok;
+       if(!me || !me->mtpoly) return ok;
        
        copy_m3_m4(bmat, ob->obmat);
 
        mv= me->mvert;
-       mf= me->mface;
-       tf= me->mtface;
-       for (a=me->totface; a>0; a--, mf++, tf++) {
+       mf= me->mpoly;
+       tf= me->mtpoly;
+       for (a=me->totpoly; a>0; a--, mf++, tf++) {
                if (mf->flag & ME_HIDE || !(mf->flag & ME_FACE_SEL))
                        continue;
 
-               VECCOPY(vec, (mv+mf->v1)->co);
-               mul_m3_v3(bmat, vec);
-               add_v3_v3v3(vec, vec, ob->obmat[3]);
-               DO_MINMAX(vec, min, max);               
-
-               VECCOPY(vec, (mv+mf->v2)->co);
-               mul_m3_v3(bmat, vec);
-               add_v3_v3v3(vec, vec, ob->obmat[3]);
-               DO_MINMAX(vec, min, max);               
-
-               VECCOPY(vec, (mv+mf->v3)->co);
-               mul_m3_v3(bmat, vec);
-               add_v3_v3v3(vec, vec, ob->obmat[3]);
-               DO_MINMAX(vec, min, max);               
-
-               if (mf->v4) {
-                       VECCOPY(vec, (mv+mf->v4)->co);
+               ml = me->mloop + mf->totloop;
+               for (b=0; b<mf->totloop; b++, ml++) {
+                       VECCOPY(vec, (mv+ml->v)->co);
                        mul_m3_v3(bmat, vec);
                        add_v3_v3v3(vec, vec, ob->obmat[3]);
-                       DO_MINMAX(vec, min, max);
+                       DO_MINMAX(vec, min, max);               
                }
+
                ok= 1;
        }
+
        return ok;
 }
 
@@ -504,12 +496,12 @@ int minmax_tface(Scene *scene, float *min, float *max)
 
 #define ME_SEAM_DONE 2         /* reuse this flag */
 
-static float edgetag_cut_cost(EditMesh *em, int e1, int e2, int vert)
+static float edgetag_cut_cost(BMEditMesh *em, int e1, int e2, int vert)
 {
-       EditVert *v = EM_get_vert_for_index(vert);
-       EditEdge *eed1 = EM_get_edge_for_index(e1), *eed2 = EM_get_edge_for_index(e2);
-       EditVert *v1 = EM_get_vert_for_index( (eed1->v1->tmp.l == vert)? eed1->v2->tmp.l: eed1->v1->tmp.l );
-       EditVert *v2 = EM_get_vert_for_index( (eed2->v1->tmp.l == vert)? eed2->v2->tmp.l: eed2->v1->tmp.l );
+       BMVert *v = EDBM_get_vert_for_index(em, vert);
+       BMEdge *eed1 = EDBM_get_edge_for_index(em, e1), *eed2 = EDBM_get_edge_for_index(em, e2);
+       BMVert *v1 = EDBM_get_vert_for_index(em, (BMINDEX_GET(eed1->v1) == vert)? BMINDEX_GET(eed1->v2): BMINDEX_GET(eed1->v1) );
+       BMVert *v2 = EDBM_get_vert_for_index(em, (BMINDEX_GET(eed2->v1) == vert)? BMINDEX_GET(eed2->v2): BMINDEX_GET(eed2->v1) );
        float cost, d1[3], d2[3];
 
        cost = len_v3v3(v1->co, v->co);
@@ -523,16 +515,17 @@ static float edgetag_cut_cost(EditMesh *em, int e1, int e2, int vert)
        return cost;
 }
 
-static void edgetag_add_adjacent(EditMesh *em, Heap *heap, int mednum, int vertnum, int *nedges, int *edges, int *prevedge, float *cost)
+static void edgetag_add_adjacent(BMEditMesh *em, Heap *heap, int mednum, int vertnum, 
+                                                                int *nedges, int *edges, int *prevedge, float *cost)
 {
        int startadj, endadj = nedges[vertnum+1];
 
        for (startadj = nedges[vertnum]; startadj < endadj; startadj++) {
                int adjnum = edges[startadj];
-               EditEdge *eedadj = EM_get_edge_for_index(adjnum);
+               BMEdge *eedadj = EDBM_get_edge_for_index(em, adjnum);
                float newcost;
 
-               if (eedadj->f2 & ME_SEAM_DONE)
+               if (eedadj->head.eflag2 & ME_SEAM_DONE)
                        continue;
 
                newcost = cost[mednum] + edgetag_cut_cost(em, mednum, adjnum, vertnum);
@@ -545,20 +538,20 @@ static void edgetag_add_adjacent(EditMesh *em, Heap *heap, int mednum, int vertn
        }
 }
 
-void edgetag_context_set(Scene *scene, EditEdge *eed, int val)
+void edgetag_context_set(BMEditMesh *em, Scene *scene, BMEdge *eed, int val)
 {
        
        switch (scene->toolsettings->edge_mode) {
        case EDGE_MODE_SELECT:
-               EM_select_edge(eed, val);
+               BM_Select(em->bm, eed, val);
                break;
        case EDGE_MODE_TAG_SEAM:
-               if (val)                {eed->seam = 255;}
-               else                    {eed->seam = 0;}
+               if (val)                {BM_SetHFlag(eed, BM_SEAM);}
+               else                    {BM_ClearHFlag(eed, BM_SEAM);}
                break;
        case EDGE_MODE_TAG_SHARP:
-               if (val)                {eed->sharp = 1;}
-               else                    {eed->sharp = 0;}
+               if (val)                {BM_SetHFlag(eed, BM_SEAM);}
+               else                    {BM_ClearHFlag(eed, BM_SEAM);}
                break;                          
        case EDGE_MODE_TAG_CREASE:      
                if (val)                {eed->crease = 1.0f;}
@@ -571,15 +564,15 @@ void edgetag_context_set(Scene *scene, EditEdge *eed, int val)
        }
 }
 
-int edgetag_context_check(Scene *scene, EditEdge *eed)
+int edgetag_context_check(Scene *scene, BMEdge *eed)
 {
        switch (scene->toolsettings->edge_mode) {
        case EDGE_MODE_SELECT:
-               return (eed->f & SELECT) ? 1 : 0;
+               return BM_TestHFlag(eed, BM_SELECT) ? 1 : 0;
        case EDGE_MODE_TAG_SEAM:
-               return eed->seam ? 1 : 0;
+               return BM_TestHFlag(eed, BM_SEAM);
        case EDGE_MODE_TAG_SHARP:
-               return eed->sharp ? 1 : 0;
+               return BM_TestHFlag(eed, BM_SHARP);
        case EDGE_MODE_TAG_CREASE:      
                return eed->crease ? 1 : 0;
        case EDGE_MODE_TAG_BEVEL:
@@ -589,28 +582,29 @@ int edgetag_context_check(Scene *scene, EditEdge *eed)
 }
 
 
-int edgetag_shortest_path(Scene *scene, EditMesh *em, EditEdge *source, EditEdge *target)
+int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, BMEdge *target)
 {
-       EditEdge *eed;
-       EditVert *ev;
-       
+       BMEdge *eed;
+       BMVert *ev;
+       BMIter iter;
        Heap *heap;
        float *cost;
        int a, totvert=0, totedge=0, *nedges, *edges, *prevedge, mednum = -1, nedgeswap = 0;
 
 
        /* we need the vert */
-       for (ev= em->verts.first, totvert=0; ev; ev= ev->next) {
-               ev->tmp.l = totvert;
+       BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+               BMINDEX_SET(ev, totvert);
                totvert++;
        }
 
-       for (eed= em->edges.first; eed; eed = eed->next) {
-               eed->f2 = 0;
-               if (eed->h) {
-                       eed->f2 |= ME_SEAM_DONE;
+       BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+               eed->head.eflag2 = 0;
+               if (BM_TestHFlag(eed, BM_SELECT)) {
+                       eed->head.eflag2 |= ME_SEAM_DONE;
                }
-               eed->tmp.l = totedge;
+
+               BMINDEX_SET(eed, totedge);
                totedge++;
        }
 
@@ -621,9 +615,9 @@ int edgetag_shortest_path(Scene *scene, EditMesh *em, EditEdge *source, EditEdge
        cost = MEM_mallocN(sizeof(*cost)*totedge, "SeamPathCost");
 
        /* count edges, compute adjacent edges offsets and fill adjacent edges */
-       for (eed= em->edges.first; eed; eed = eed->next) {
-               nedges[eed->v1->tmp.l+1]++;
-               nedges[eed->v2->tmp.l+1]++;
+       BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+               nedges[BMINDEX_GET(eed->v1)+1]++;
+               nedges[BMINDEX_GET(eed->v2)+1]++;
        }
 
        for (a=1; a<totvert; a++) {
@@ -633,107 +627,108 @@ int edgetag_shortest_path(Scene *scene, EditMesh *em, EditEdge *source, EditEdge
        }
        nedges[0] = nedges[1] = 0;
 
-       for (a=0, eed= em->edges.first; eed; a++, eed = eed->next) {
-               edges[nedges[eed->v1->tmp.l+1]++] = a;
-               edges[nedges[eed->v2->tmp.l+1]++] = a;
+       BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+               edges[nedges[BMINDEX_GET(eed->v1)+1]++] = a;
+               edges[nedges[BMINDEX_GET(eed->v2)+1]++] = a;
 
                cost[a] = 1e20f;
                prevedge[a] = -1;
+               a++;
        }
 
        /* regular dijkstra shortest path, but over edges instead of vertices */
        heap = BLI_heap_new();
-       BLI_heap_insert(heap, 0.0f, SET_INT_IN_POINTER(source->tmp.l));
-       cost[source->tmp.l] = 0.0f;
-
-       EM_init_index_arrays(em, 1, 1, 0);
+       BLI_heap_insert(heap, 0.0f, SET_INT_IN_POINTER(BMINDEX_GET(source)));
+       cost[BMINDEX_GET(source)] = 0.0f;
 
+       EDBM_init_index_arrays(em, 1, 1, 0);
 
        while (!BLI_heap_empty(heap)) {
                mednum = GET_INT_FROM_POINTER(BLI_heap_popmin(heap));
-               eed = EM_get_edge_for_index( mednum );
+               eed = EDBM_get_edge_for_index(em, mednum);
 
-               if (mednum == target->tmp.l)
+               if (mednum == BMINDEX_GET(target))
                        break;
 
-               if (eed->f2 & ME_SEAM_DONE)
+               if (eed->head.eflag2 & ME_SEAM_DONE)
                        continue;
 
-               eed->f2 |= ME_SEAM_DONE;
+               eed->head.eflag2 |= ME_SEAM_DONE;
 
-               edgetag_add_adjacent(em, heap, mednum, eed->v1->tmp.l, nedges, edges, prevedge, cost);
-               edgetag_add_adjacent(em, heap, mednum, eed->v2->tmp.l, nedges, edges, prevedge, cost);
+               edgetag_add_adjacent(em, heap, mednum, BMINDEX_GET(eed->v1), nedges, edges, prevedge, cost);
+               edgetag_add_adjacent(em, heap, mednum, BMINDEX_GET(eed->v2), nedges, edges, prevedge, cost);
        }
        
-       
        MEM_freeN(nedges);
        MEM_freeN(edges);
        MEM_freeN(cost);
        BLI_heap_free(heap, NULL);
 
-       for (eed= em->edges.first; eed; eed = eed->next) {
-               eed->f2 &= ~ME_SEAM_DONE;
+       BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+               eed->head.eflag2 &= ~ME_SEAM_DONE;
        }
 
-       if (mednum != target->tmp.l) {
+       if (mednum != BMINDEX_GET(target)) {
                MEM_freeN(prevedge);
-               EM_free_index_arrays();
+               EDBM_free_index_arrays(em);
                return 0;
        }
 
        /* follow path back to source and mark as seam */
-       if (mednum == target->tmp.l) {
+       if (mednum == BMINDEX_GET(target)) {
                short allseams = 1;
 
-               mednum = target->tmp.l;
+               mednum = BMINDEX_GET(target);
                do {
-                       eed = EM_get_edge_for_index( mednum );
+                       eed = EDBM_get_edge_for_index(eed, mednum);
                        if (!edgetag_context_check(scene, eed)) {
                                allseams = 0;
                                break;
                        }
                        mednum = prevedge[mednum];
-               } while (mednum != source->tmp.l);
+               } while (mednum != BMINDEX_GET(source));
 
-               mednum = target->tmp.l;
+               mednum = BMINDEX_GET(target);
                do {
-                       eed = EM_get_edge_for_index( mednum );
+                       eed = EDBM_get_edge_for_index(em, mednum);
                        if (allseams)
-                               edgetag_context_set(scene, eed, 0);
+                               edgetag_context_set(em, scene, eed, 0);
                        else
-                               edgetag_context_set(scene, eed, 1);
+                               edgetag_context_set(em, scene, eed, 1);
                        mednum = prevedge[mednum];
                } while (mednum != -1);
        }
 
        MEM_freeN(prevedge);
-       EM_free_index_arrays();
+       EDBM_free_index_arrays(em);
        return 1;
 }
 
 /* *************************************** */
 
-static void seam_edgehash_insert_face(EdgeHash *ehash, MFace *mf)
+static void seam_edgehash_insert_face(EdgeHash *ehash, MPoly *mf, MLoop *loopstart)
 {
-       BLI_edgehash_insert(ehash, mf->v1, mf->v2, NULL);
-       BLI_edgehash_insert(ehash, mf->v2, mf->v3, NULL);
-       if (mf->v4) {
-               BLI_edgehash_insert(ehash, mf->v3, mf->v4, NULL);
-               BLI_edgehash_insert(ehash, mf->v4, mf->v1, NULL);
-       }
-       else
-               BLI_edgehash_insert(ehash, mf->v3, mf->v1, NULL);
+       MLoop *ml1, *ml2;
+       int a;
+
+       for (a=0; a<mf->totloop; a++) {
+               ml1 = loopstart + a;
+               ml2 = loopstart + (a+1) % mf->totloop;
+
+               BLI_edgehash_insert(ehash, ml1->v, ml2->v, NULL);
+       }
 }
 
 void seam_mark_clear_tface(Scene *scene, short mode)
 {
        Mesh *me;
-       MFace *mf;
+       MPoly *mf;
+       MLoop *ml1, *ml2;
        MEdge *med;
-       int a;
+       int a, b;
        
        me= get_mesh(OBACT);
-       if(me==0 ||  me->totface==0) return;
+       if(me==0 ||  me->totpoly==0) return;
 
        if (mode == 0)
                mode = pupmenu("Seams%t|Mark Border Seam %x1|Clear Seam %x2");
@@ -744,9 +739,9 @@ void seam_mark_clear_tface(Scene *scene, short mode)
        if (mode == 2) {
                EdgeHash *ehash = BLI_edgehash_new();
 
-               for (a=0, mf=me->mface; a<me->totface; a++, mf++)
+               for (a=0, mf=me->mpoly; a<me->totpoly; a++, mf++)
                        if (!(mf->flag & ME_HIDE) && (mf->flag & ME_FACE_SEL))
-                               seam_edgehash_insert_face(ehash, mf);
+                               seam_edgehash_insert_face(ehash, mf, me->mloop + mf->loopstart);
 
                for (a=0, med=me->medge; a<me->totedge; a++, med++)
                        if (BLI_edgehash_haskey(ehash, med->v1, med->v2))
@@ -759,11 +754,11 @@ void seam_mark_clear_tface(Scene *scene, short mode)
                EdgeHash *ehash1 = BLI_edgehash_new();
                EdgeHash *ehash2 = BLI_edgehash_new();
 
-               for (a=0, mf=me->mface; a<me->totface; a++, mf++) {
+               for (a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) {
                        if ((mf->flag & ME_HIDE) || !(mf->flag & ME_FACE_SEL))
-                               seam_edgehash_insert_face(ehash1, mf);
+                               seam_edgehash_insert_face(ehash1, mf, me->mloop + mf->loopstart);
                        else
-                               seam_edgehash_insert_face(ehash2, mf);
+                               seam_edgehash_insert_face(ehash2, mf, me->mloop + mf->loopstart);
                }
 
                for (a=0, med=me->medge; a<me->totedge; a++, med++)
@@ -786,21 +781,24 @@ void seam_mark_clear_tface(Scene *scene, short mode)
 int face_select(struct bContext *C, Object *ob, short mval[2], int extend)
 {
        Mesh *me;
-       MFace *mface, *msel;
+       MPoly *mface, *msel;
        unsigned int a, index;
        
        /* Get the face under the cursor */
        me = get_mesh(ob);
 
-       if (!facesel_face_pick(C, me, mval, &index, 1))
+       if (!facesel_face_pick(C, me, ob, mval, &index, 1))
                return 0;
        
-       msel= (((MFace*)me->mface)+index);
+       if (index >= me->totpoly || index < 0)
+               return 0;
+
+       msel= me->mpoly + index;
        if (msel->flag & ME_HIDE) return 0;
        
        /* clear flags */
-       mface = me->mface;
-       a = me->totface;
+       mface = me->mpoly;
+       a = me->totpoly;
        if (!extend) {
                while (a--) {
                        mface->flag &= ~ME_FACE_SEL;
@@ -830,28 +828,28 @@ int face_select(struct bContext *C, Object *ob, short mval[2], int extend)
 void face_borderselect(struct bContext *C, Object *ob, rcti *rect, int select, int extend)
 {
        Mesh *me;
-       MFace *mface;
+       MPoly *mface;
        struct ImBuf *ibuf;
        unsigned int *rt;
-       int a, sx, sy, index;
        char *selar;
+       int a, sx, sy, index;
        
        ViewContext vc;
        view3d_set_viewcontext(C, &vc);
 
        me= get_mesh(ob);
        if(me==0) return;
-       if(me->totface==0) return;
+       if(me->totpoly==0) return;
 
-       selar= MEM_callocN(me->totface+1, "selar");
+       selar= MEM_callocN(me->totpoly+1, "selar");
 
        sx= (rect->xmax-rect->xmin+1);
        sy= (rect->ymax-rect->ymin+1);
        if(sx*sy<=0) return;
 
        if (extend == 0 && select) {
-               mface= me->mface;
-               for(a=1; a<=me->totface; a++, mface++) {
+               mface= me->mpoly;
+               for(a=1; a<=me->totpoly; a++, mface++) {
                        if((mface->flag & ME_HIDE) == 0)
                                mface->flag &= ~ME_FACE_SEL;
                }
@@ -873,8 +871,8 @@ void face_borderselect(struct bContext *C, Object *ob, rcti *rect, int select, i
                rt++;
        }
 
-       mface= me->mface;
-       for(a=1; a<=me->totface; a++, mface++) {
+       mface= me->mpoly;
+       for(a=1; a<=me->totpoly; a++, mface++) {
                if(selar[a]) {
                        if(mface->flag & ME_HIDE);
                        else {
diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c
deleted file mode 100644 (file)
index 0b6c589..0000000
+++ /dev/null
@@ -1,1622 +0,0 @@
-/**
- * $Id$
- *
- * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation, full recode 2002-2008
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "PIL_time.h"
-
-#include "DNA_customdata_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_object_types.h"
-#include "DNA_object_force.h"
-#include "DNA_screen_types.h"
-#include "DNA_key_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_material_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_userdef_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_editVert.h"
-#include "BLI_dynstr.h"
-#include "BLI_rand.h"
-#include "BLI_mempool.h"
-
-#include "BKE_cloth.h"
-#include "BKE_context.h"
-#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_global.h"
-#include "BKE_key.h"
-#include "BKE_library.h"
-#include "BKE_main.h"
-#include "BKE_material.h"
-#include "BKE_mesh.h"
-#include "BKE_modifier.h"
-#include "BKE_object.h"
-#include "BKE_paint.h"
-#include "BKE_pointcache.h"
-#include "BKE_softbody.h"
-#include "BKE_texture.h"
-#include "BKE_utildefines.h"
-#include "BKE_tessmesh.h"
-
-#include "LBM_fluidsim.h"
-
-
-#include "ED_mesh.h"
-#include "ED_object.h"
-#include "ED_retopo.h"
-#include "ED_screen.h"
-#include "ED_util.h"
-#include "ED_view3d.h"
-
-#include "RNA_access.h"
-#include "RNA_define.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-/* own include */
-#include "mesh_intern.h"
-
-#include "bmesh.h"
-
-/* 
-editmesh.c:
-       - add/alloc/free data
-       - hashtables
-       - enter/exit editmode
-*/
-
-/* XXX */
-static void BIF_undo_push() {}
-static void error() {}
-
-
-/* ***************** HASH ********************* */
-
-
-#define EDHASHSIZE             (512*512)
-#define EDHASH(a, b)   (a % EDHASHSIZE)
-
-
-/* ************ ADD / REMOVE / FIND ****************** */
-
-static void init_editMesh(EditMesh *em) {
-       if (!em->vertpool) em->vertpool = BLI_mempool_create(sizeof(EditVert), 1, 512);
-       if (!em->edgepool) em->edgepool = BLI_mempool_create(sizeof(EditEdge), 1, 512);
-       if (!em->facepool) em->facepool = BLI_mempool_create(sizeof(EditFace), 1, 512);
-}
-
-EditVert *addvertlist(EditMesh *em, float *vec, EditVert *example)
-{
-       EditVert *eve;
-       static int hashnr= 0;
-       
-       if (!em->vertpool) init_editMesh(em);
-
-       eve= BLI_mempool_calloc(em->vertpool);
-
-       BLI_addtail(&em->verts, eve);
-       em->totvert++;
-       
-       if(vec) VECCOPY(eve->co, vec);
-
-       eve->hash= hashnr++;
-       if( hashnr>=EDHASHSIZE) hashnr= 0;
-
-       /* new verts get keyindex of -1 since they did not
-        * have a pre-editmode vertex order
-        */
-       eve->keyindex = -1;
-
-       if(example) {
-               CustomData_em_copy_data(&em->vdata, &em->vdata, example->data, &eve->data);
-               eve->bweight = example->bweight;
-       }
-       else {
-               CustomData_em_set_default(&em->vdata, &eve->data);
-       }
-
-       return eve;
-}
-
-void free_editvert (EditMesh *em, EditVert *eve)
-{
-
-       EM_remove_selection(em, eve, EDITVERT);
-       CustomData_em_free_block(&em->vdata, &eve->data);
-       BLI_mempool_free(em->vertpool, eve);
-       
-       em->totvert--;
-}
-
-
-EditEdge *findedgelist(EditMesh *em, EditVert *v1, EditVert *v2)
-{
-       EditVert *v3;
-       struct HashEdge *he;
-
-       /* swap ? */
-       if( v1 > v2) {
-               v3= v2; 
-               v2= v1; 
-               v1= v3;
-       }
-       
-       if(em->hashedgetab==NULL)
-               em->hashedgetab= MEM_callocN(EDHASHSIZE*sizeof(struct HashEdge), "hashedgetab");
-
-       he= em->hashedgetab + EDHASH(v1->hash, v2->hash);
-       
-       while(he) {
-               
-               if(he->eed && he->eed->v1==v1 && he->eed->v2==v2) return he->eed;
-               
-               he= he->next;
-       }
-       return 0;
-}
-
-static void insert_hashedge(EditMesh *em, EditEdge *eed)
-{
-       /* assuming that eed is not in the list yet, and that a find has been done before */
-       
-       struct HashEdge *first, *he;
-
-       first= em->hashedgetab + EDHASH(eed->v1->hash, eed->v2->hash);
-
-       if( first->eed==0 ) {
-               first->eed= eed;
-       }
-       else {
-               he= &eed->hash; 
-               he->eed= eed;
-               he->next= first->next;
-               first->next= he;
-       }
-}
-
-static void remove_hashedge(EditMesh *em, EditEdge *eed)
-{
-       /* assuming eed is in the list */
-       
-       struct HashEdge *first, *he, *prev=NULL;
-
-       he=first= em->hashedgetab + EDHASH(eed->v1->hash, eed->v2->hash);
-
-       while(he) {
-               if(he->eed == eed) {
-                       /* remove from list */
-                       if(he==first) {
-                               if(first->next) {
-                                       he= first->next;
-                                       first->eed= he->eed;
-                                       first->next= he->next;
-                               }
-                               else he->eed= 0;
-                       }
-                       else {
-                               prev->next= he->next;
-                       }
-                       return;
-               }
-               prev= he;
-               he= he->next;
-       }
-}
-
-EditEdge *addedgelist(EditMesh *em, EditVert *v1, EditVert *v2, EditEdge *example)
-{
-       EditVert *v3;
-       EditEdge *eed;
-       int swap= 0;
-       
-       if(v1==v2) return NULL;
-       if(v1==NULL || v2==NULL) return NULL;
-
-       /* swap ? */
-       if(v1>v2) {
-               v3= v2; 
-               v2= v1; 
-               v1= v3;
-               swap= 1;
-       }
-       
-       /* find in hashlist */
-       if (!em->edgepool) init_editMesh(em);
-       eed= findedgelist(em, v1, v2);
-
-       if(eed==NULL) {
-       
-               eed= (EditEdge *)BLI_mempool_calloc(em->edgepool);
-               eed->v1= v1;
-               eed->v2= v2;
-               BLI_addtail(&em->edges, eed);
-               eed->dir= swap;
-               insert_hashedge(em, eed);
-               em->totedge++;
-               
-               /* copy edge data:
-                  rule is to do this with addedgelist call, before addfacelist */
-               if(example) {
-                       eed->crease= example->crease;
-                       eed->bweight= example->bweight;
-                       eed->sharp = example->sharp;
-                       eed->seam = example->seam;
-                       eed->h |= (example->h & EM_FGON);
-               }
-       }
-
-       return eed;
-}
-
-void remedge(EditMesh *em, EditEdge *eed)
-{
-       BLI_remlink(&em->edges, eed);
-       remove_hashedge(em, eed);
-       
-       em->totedge--;
-}
-
-void free_editedge(EditMesh *em, EditEdge *eed)
-{
-       EM_remove_selection(em, eed, EDITEDGE);
-
-       BLI_mempool_free(em->edgepool, eed);
-}
-
-void free_editface(EditMesh *em, EditFace *efa)
-{
-       EM_remove_selection(em, efa, EDITFACE);
-       
-       if (em->act_face==efa) {
-               EM_set_actFace(em, em->faces.first == efa ? NULL : em->faces.first);
-       }
-               
-       CustomData_em_free_block(&em->fdata, &efa->data);
-       BLI_mempool_free(em->facepool, efa);
-       
-       em->totface--;
-}
-
-void free_vertlist(EditMesh *em, ListBase *edve) 
-{
-       EditVert *eve, *next;
-
-       if (!edve) return;
-
-       eve= edve->first;
-       while(eve) {
-               next= eve->next;
-               free_editvert(em, eve);
-               eve= next;
-       }
-       edve->first= edve->last= NULL;
-       em->totvert= em->totvertsel= 0;
-}
-
-void free_edgelist(EditMesh *em, ListBase *lb)
-{
-       EditEdge *eed, *next;
-       
-       eed= lb->first;
-       while(eed) {
-               next= eed->next;
-               free_editedge(em, eed);
-               eed= next;
-       }
-       lb->first= lb->last= NULL;
-       em->totedge= em->totedgesel= 0;
-}
-
-void free_facelist(EditMesh *em, ListBase *lb)
-{
-       EditFace *efa, *next;
-       
-       efa= lb->first;
-       while(efa) {
-               next= efa->next;
-               free_editface(em, efa);
-               efa= next;
-       }
-       lb->first= lb->last= NULL;
-       em->totface= em->totfacesel= 0;
-}
-
-EditFace *addfacelist(EditMesh *em, EditVert *v1, EditVert *v2, EditVert *v3, EditVert *v4, EditFace *example, EditFace *exampleEdges)
-{
-       EditFace *efa;
-       EditEdge *e1, *e2=0, *e3=0, *e4=0;
-
-       /* added sanity check... seems to happen for some tools, or for enter editmode for corrupted meshes */
-       if(v1==v4 || v2==v4 || v3==v4) v4= NULL;
-       
-       /* add face to list and do the edges */
-       if(exampleEdges) {
-               e1= addedgelist(em, v1, v2, exampleEdges->e1);
-               e2= addedgelist(em, v2, v3, exampleEdges->e2);
-               if(v4) e3= addedgelist(em, v3, v4, exampleEdges->e3); 
-               else e3= addedgelist(em, v3, v1, exampleEdges->e3);
-               if(v4) e4= addedgelist(em, v4, v1, exampleEdges->e4);
-       }
-       else {
-               e1= addedgelist(em, v1, v2, NULL);
-               e2= addedgelist(em, v2, v3, NULL);
-               if(v4) e3= addedgelist(em, v3, v4, NULL); 
-               else e3= addedgelist(em, v3, v1, NULL);
-               if(v4) e4= addedgelist(em, v4, v1, NULL);
-       }
-       
-       if(v1==v2 || v2==v3 || v1==v3) return NULL;
-       if(e2==0) return NULL;
-
-       if (!em->facepool) init_editMesh(em);
-       efa= (EditFace *)BLI_mempool_calloc(em->facepool);
-
-       efa->v1= v1;
-       efa->v2= v2;
-       efa->v3= v3;
-       efa->v4= v4;
-
-       efa->e1= e1;
-       efa->e2= e2;
-       efa->e3= e3;
-       efa->e4= e4;
-
-       if(example) {
-               efa->mat_nr= example->mat_nr;
-               efa->flag= example->flag;
-               CustomData_em_copy_data(&em->fdata, &em->fdata, example->data, &efa->data);
-       }
-       else {
-               efa->mat_nr= em->mat_nr;
-
-               CustomData_em_set_default(&em->fdata, &efa->data);
-       }
-
-       BLI_addtail(&em->faces, efa);
-       em->totface++;
-       
-       if(efa->v4) {
-               normal_quad_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
-               cent_quad_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
-       }
-       else {
-               normal_tri_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co);
-               cent_tri_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co);
-       }
-
-       return efa;
-}
-
-/* ************************ end add/new/find ************  */
-
-/* ************************ Edit{Vert,Edge,Face} utilss ***************************** */
-
-/* some nice utility functions */
-
-EditVert *editedge_getOtherVert(EditEdge *eed, EditVert *eve)
-{
-       if (eve==eed->v1) {
-               return eed->v2;
-       } else if (eve==eed->v2) {
-               return eed->v1;
-       } else {
-               return NULL;
-       }
-}
-
-EditVert *editedge_getSharedVert(EditEdge *eed, EditEdge *eed2) 
-{
-       if (eed->v1==eed2->v1 || eed->v1==eed2->v2) {
-               return eed->v1;
-       } else if (eed->v2==eed2->v1 || eed->v2==eed2->v2) {
-               return eed->v2;
-       } else {
-               return NULL;
-       }
-}
-
-int editedge_containsVert(EditEdge *eed, EditVert *eve) 
-{
-       return (eed->v1==eve || eed->v2==eve);
-}
-
-int editface_containsVert(EditFace *efa, EditVert *eve) 
-{
-       return (efa->v1==eve || efa->v2==eve || efa->v3==eve || (efa->v4 && efa->v4==eve));
-}
-
-int editface_containsEdge(EditFace *efa, EditEdge *eed) 
-{
-       return (efa->e1==eed || efa->e2==eed || efa->e3==eed || (efa->e4 && efa->e4==eed));
-}
-
-
-/* ************************ stuct EditMesh manipulation ***************************** */
-
-void set_editMesh(EditMesh *dst, EditMesh *src)
-{
-       free_editMesh(dst);
-       *dst = *src;
-}
-
-/* do not free editmesh itself here */
-void free_editMesh(EditMesh *em)
-{
-       if(em==NULL) return;
-
-       if(em->verts.first) free_vertlist(em, &em->verts);
-       if(em->edges.first) free_edgelist(em, &em->edges);
-       if(em->faces.first) free_facelist(em, &em->faces);
-       if(em->selected.first) BLI_freelistN(&(em->selected));
-       
-       if (em->vertpool) BLI_mempool_destroy(em->vertpool);
-       if (em->edgepool) BLI_mempool_destroy(em->edgepool);
-       if (em->facepool) BLI_mempool_destroy(em->facepool);
-       em->vertpool = em->edgepool = em->facepool = NULL;
-       
-       CustomData_free(&em->vdata, 0);
-       CustomData_free(&em->fdata, 0);
-
-       if(em->derivedFinal) {
-               if (em->derivedFinal!=em->derivedCage) {
-                       em->derivedFinal->needsFree= 1;
-                       em->derivedFinal->release(em->derivedFinal);
-               }
-               em->derivedFinal= NULL;
-       }
-       if(em->derivedCage) {
-               em->derivedCage->needsFree= 1;
-               em->derivedCage->release(em->derivedCage);
-               em->derivedCage= NULL;
-       }
-
-       /* DEBUG: hashtabs are slowest part of enter/exit editmode. here a testprint */
-#if 0
-       if(em->hashedgetab) {
-               HashEdge *he, *hen;
-               int a, used=0, max=0, nr;
-               he= em->hashedgetab;
-               for(a=0; a<EDHASHSIZE; a++, he++) {
-                       if(he->eed) used++;
-                       hen= he->next;
-                       nr= 0;
-                       while(hen) {
-                               nr++;
-                               hen= hen->next;
-                       }
-                       if(max<nr) max= nr;
-               }
-               printf("hastab used %d max %d\n", used, max);
-       }
-#endif
-       if(em->hashedgetab) MEM_freeN(em->hashedgetab);
-       em->hashedgetab= NULL;
-       
-       if(em->allverts) MEM_freeN(em->allverts);
-       if(em->alledges) MEM_freeN(em->alledges);
-       if(em->allfaces) MEM_freeN(em->allfaces);
-       
-       em->allverts= em->curvert= NULL;
-       em->alledges= em->curedge= NULL;
-       em->allfaces= em->curface= NULL;
-       
-       mesh_octree_table(NULL, NULL, NULL, 'e');
-       
-       em->totvert= em->totedge= em->totface= 0;
-
-// XXX if(em->retopo_paint_data) retopo_free_paint_data(em->retopo_paint_data);
-       em->retopo_paint_data= NULL;
-       em->act_face = NULL;
-}
-
-static void editMesh_set_hash(EditMesh *em)
-{
-       EditEdge *eed;
-
-       if(em->hashedgetab) MEM_freeN(em->hashedgetab);
-       em->hashedgetab= NULL;
-       
-       for(eed=em->edges.first; eed; eed= eed->next)  {
-               if( findedgelist(em, eed->v1, eed->v2)==NULL )
-                       insert_hashedge(em, eed);
-       }
-
-}
-
-
-/* ************************ IN & OUT EDITMODE ***************************** */
-
-
-static void edge_normal_compare(EditEdge *eed, EditFace *efa1)
-{
-       EditFace *efa2;
-       float cent1[3], cent2[3];
-       float inp;
-       
-       efa2 = eed->tmp.f;
-       if(efa1==efa2) return;
-       
-       inp= efa1->n[0]*efa2->n[0] + efa1->n[1]*efa2->n[1] + efa1->n[2]*efa2->n[2];
-       if(inp<0.999 && inp >-0.999) eed->f2= 1;
-               
-       if(efa1->v4) cent_quad_v3(cent1, efa1->v1->co, efa1->v2->co, efa1->v3->co, efa1->v4->co);
-       else cent_tri_v3(cent1, efa1->v1->co, efa1->v2->co, efa1->v3->co);
-       if(efa2->v4) cent_quad_v3(cent2, efa2->v1->co, efa2->v2->co, efa2->v3->co, efa2->v4->co);
-       else cent_tri_v3(cent2, efa2->v1->co, efa2->v2->co, efa2->v3->co);
-       
-       sub_v3_v3v3(cent1, cent2, cent1);
-       normalize_v3(cent1);
-       inp= cent1[0]*efa1->n[0] + cent1[1]*efa1->n[1] + cent1[2]*efa1->n[2]; 
-
-       if(inp < -0.001 ) eed->f1= 1;
-}
-
-#if 0
-typedef struct {
-       EditEdge *eed;
-       float noLen,no[3];
-       int adjCount;
-} EdgeDrawFlagInfo;
-
-static int edgeDrawFlagInfo_cmp(const void *av, const void *bv)
-{
-       const EdgeDrawFlagInfo *a = av;
-       const EdgeDrawFlagInfo *b = bv;
-
-       if (a->noLen<b->noLen) return -1;
-       else if (a->noLen>b->noLen) return 1;
-       else return 0;
-}
-#endif
-
-static void edge_drawflags(Mesh *me, EditMesh *em)
-{
-       EditVert *eve;
-       EditEdge *eed, *e1, *e2, *e3, *e4;
-       EditFace *efa;
-       
-       /* - count number of times edges are used in faces: 0 en 1 time means draw edge
-        * - edges more than 1 time used: in *tmp.f is pointer to first face
-        * - check all faces, when normal differs to much: draw (flag becomes 1)
-        */
-
-       /* later on: added flags for 'cylinder' and 'sphere' intersection tests in old
-          game engine (2.04)
-        */
-       
-       recalc_editnormals(em);
-       
-       /* init */
-       eve= em->verts.first;
-       while(eve) {
-               eve->f1= 1;             /* during test it's set at zero */
-               eve= eve->next;
-       }
-       eed= em->edges.first;
-       while(eed) {
-               eed->f2= eed->f1= 0;
-               eed->tmp.f = 0;
-               eed= eed->next;
-       }
-
-       efa= em->faces.first;
-       while(efa) {
-               e1= efa->e1;
-               e2= efa->e2;
-               e3= efa->e3;
-               e4= efa->e4;
-               if(e1->f2<4) e1->f2+= 1;
-               if(e2->f2<4) e2->f2+= 1;
-               if(e3->f2<4) e3->f2+= 1;
-               if(e4 && e4->f2<4) e4->f2+= 1;
-               
-               if(e1->tmp.f == 0) e1->tmp.f = (void *) efa;
-               if(e2->tmp.f == 0) e2->tmp.f = (void *) efa;
-               if(e3->tmp.f ==0) e3->tmp.f = (void *) efa;
-               if(e4 && (e4->tmp.f == 0)) e4->tmp.f = (void *) efa;
-               
-               efa= efa->next;
-       }
-
-       if(me->drawflag & ME_ALLEDGES) {
-               efa= em->faces.first;
-               while(efa) {
-                       if(efa->e1->f2>=2) efa->e1->f2= 1;
-                       if(efa->e2->f2>=2) efa->e2->f2= 1;
-                       if(efa->e3->f2>=2) efa->e3->f2= 1;
-                       if(efa->e4 && efa->e4->f2>=2) efa->e4->f2= 1;
-                       
-                       efa= efa->next;
-               }               
-       }       
-       else {
-               
-               /* handle single-edges for 'test cylinder flag' (old engine) */
-               
-               eed= em->edges.first;
-               while(eed) {
-                       if(eed->f2==1) eed->f1= 1;
-                       eed= eed->next;
-               }
-
-               /* all faces, all edges with flag==2: compare normal */
-               efa= em->faces.first;
-               while(efa) {
-                       if(efa->e1->f2==2) edge_normal_compare(efa->e1, efa);
-                       else efa->e1->f2= 1;
-                       if(efa->e2->f2==2) edge_normal_compare(efa->e2, efa);
-                       else efa->e2->f2= 1;
-                       if(efa->e3->f2==2) edge_normal_compare(efa->e3, efa);
-                       else efa->e3->f2= 1;
-                       if(efa->e4) {
-                               if(efa->e4->f2==2) edge_normal_compare(efa->e4, efa);
-                               else efa->e4->f2= 1;
-                       }
-                       efa= efa->next;
-               }
-               
-               /* sphere collision flag */
-               
-               eed= em->edges.first;
-               while(eed) {
-                       if(eed->f1!=1) {
-                               eed->v1->f1= eed->v2->f1= 0;
-                       }
-                       eed= eed->next;
-               }
-               
-       }
-}
-
-/* turns Mesh into editmesh */
-EditMesh *make_editMesh(Scene *scene, Object *ob)
-{
-       Mesh *me= ob->data;
-       MFace *mface;
-       MVert *mvert;
-       MSelect *mselect;
-       KeyBlock *actkey;
-       EditMesh *em;
-       EditVert *eve, **evlist, *eve1, *eve2, *eve3, *eve4;
-       EditFace *efa;
-       EditEdge *eed;
-       EditSelection *ese;
-       float *co, (*keyco)[3]= NULL;
-       int tot, a, eekadoodle= 0;
-
-       em= MEM_callocN(sizeof(EditMesh), "editmesh");
-       
-       em->selectmode= scene->toolsettings->selectmode; // warning needs to be synced
-       em->act_face = NULL;
-       em->totvert= tot= me->totvert;
-       em->totedge= me->totedge;
-       em->totface= me->totface;
-       
-       if(tot==0) {
-               return;
-       }
-       
-       if(ob->actcol > 0)
-               em->mat_nr= ob->actcol-1;
-
-       actkey = ob_get_keyblock(ob);
-       if(actkey) {
-               keyco= actkey->data;
-               em->shapenr= ob->shapenr;
-       }
-
-       /* make editverts */
-       CustomData_copy(&me->vdata, &em->vdata, CD_MASK_EDITMESH, CD_CALLOC, 0);
-       mvert= me->mvert;
-
-       evlist= (EditVert **)MEM_mallocN(tot*sizeof(void *),"evlist");
-       for(a=0; a<tot; a++, mvert++) {
-               
-               co= mvert->co;
-
-               /* edit the shape key coordinate if available */
-               if(keyco && a < actkey->totelem)
-                       co= keyco[a];
-
-               eve= addvertlist(em, co, NULL);
-               evlist[a]= eve;
-               
-               /* face select sets selection in next loop */
-               if(!paint_facesel_test(ob))
-                       eve->f |= (mvert->flag & 1);
-               
-               if (mvert->flag & ME_HIDE) eve->h= 1;           
-               eve->no[0]= mvert->no[0]/32767.0;
-               eve->no[1]= mvert->no[1]/32767.0;
-               eve->no[2]= mvert->no[2]/32767.0;
-
-               eve->bweight= ((float)mvert->bweight)/255.0f;
-
-               /* lets overwrite the keyindex of the editvert
-                * with the order it used to be in before
-                * editmode
-                */
-               eve->keyindex = a;
-
-               CustomData_to_em_block(&me->vdata, &em->vdata, a, &eve->data);
-       }
-
-       if(actkey && actkey->totelem!=me->totvert);
-       else {
-               MEdge *medge= me->medge;
-               
-               CustomData_copy(&me->edata, &em->edata, CD_MASK_EDITMESH, CD_CALLOC, 0);
-               /* make edges */
-               for(a=0; a<me->totedge; a++, medge++) {
-                       eed= addedgelist(em, evlist[medge->v1], evlist[medge->v2], NULL);
-                       /* eed can be zero when v1 and v2 are identical, dxf import does this... */
-                       if(eed) {
-                               eed->crease= ((float)medge->crease)/255.0f;
-                               eed->bweight= ((float)medge->bweight)/255.0f;
-                               
-                               if(medge->flag & ME_SEAM) eed->seam= 1;
-                               if(medge->flag & ME_SHARP) eed->sharp = 1;
-                               if(medge->flag & SELECT) eed->f |= SELECT;
-                               if(medge->flag & ME_FGON) eed->h= EM_FGON;      // 2 different defines!
-                               if(medge->flag & ME_HIDE) eed->h |= 1;
-                               if(em->selectmode==SCE_SELECT_EDGE) 
-                                       EM_select_edge(eed, eed->f & SELECT);           // force edge selection to vertices, seems to be needed ...
-                               CustomData_to_em_block(&me->edata,&em->edata, a, &eed->data);
-                       }
-               }
-               
-               CustomData_copy(&me->fdata, &em->fdata, CD_MASK_EDITMESH, CD_CALLOC, 0);
-
-               /* make faces */
-               mface= me->mface;
-
-               for(a=0; a<me->totface; a++, mface++) {
-                       eve1= evlist[mface->v1];
-                       eve2= evlist[mface->v2];
-                       if(!mface->v3) eekadoodle= 1;
-                       eve3= evlist[mface->v3];
-                       if(mface->v4) eve4= evlist[mface->v4]; else eve4= NULL;
-                       
-                       efa= addfacelist(em, eve1, eve2, eve3, eve4, NULL, NULL);
-
-                       if(efa) {
-                               CustomData_to_em_block(&me->fdata, &em->fdata, a, &efa->data);
-
-                               efa->mat_nr= mface->mat_nr;
-                               efa->flag= mface->flag & ~ME_HIDE;
-                               
-                               /* select and hide face flag */
-                               if(mface->flag & ME_HIDE) {
-                                       efa->h= 1;
-                               } else {
-                                       if (a==me->act_face) {
-                                               EM_set_actFace(em, efa);
-                                       }
-                                       
-                                       /* dont allow hidden and selected */
-                                       if(mface->flag & ME_FACE_SEL) {
-                                               efa->f |= SELECT;
-                                               
-                                               if(paint_facesel_test(ob)) {
-                                                       EM_select_face(efa, 1); /* flush down */
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-       
-       if(eekadoodle)
-               error("This Mesh has old style edgecodes, please put it in the bugtracker!");
-       
-       MEM_freeN(evlist);
-       
-       if(me->mselect){
-               //restore editselections
-               EM_init_index_arrays(em, 1,1,1);
-               mselect = me->mselect;
-               
-               for(a=0; a<me->totselect; a++, mselect++){
-                       /*check if recorded selection is still valid, if so copy into editmesh*/
-                       if( (mselect->type == EDITVERT && me->mvert[mselect->index].flag & SELECT) || (mselect->type == EDITEDGE && me->medge[mselect->index].flag & SELECT) || (mselect->type == EDITFACE && me->mface[mselect->index].flag & ME_FACE_SEL) ){
-                               ese = MEM_callocN(sizeof(EditSelection), "Edit Selection");
-                               ese->type = mselect->type;      
-                               if(ese->type == EDITVERT) ese->data = EM_get_vert_for_index(mselect->index); else
-                               if(ese->type == EDITEDGE) ese->data = EM_get_edge_for_index(mselect->index); else
-                               if(ese->type == EDITFACE) ese->data = EM_get_face_for_index(mselect->index);
-                               BLI_addtail(&(em->selected),ese);
-                       }
-               }
-               EM_free_index_arrays();
-       }
-       /* this creates coherent selections. also needed for older files */
-       EM_selectmode_set(em);
-       /* paranoia check to enforce hide rules */
-       EM_hide_reset(em);
-       /* sets helper flags which arent saved */
-       EM_fgon_flags(em);
-       
-       if (EM_get_actFace(em, 0)==NULL) {
-               EM_set_actFace(em, em->faces.first ); /* will use the first face, this is so we alwats have an active face */
-       }
-}
-
-/* makes Mesh out of editmesh */
-void load_editMesh(Scene *scene, Object *ob, EditMesh *em)
-{
-       Mesh *me= ob->data;
-       MVert *mvert, *oldverts;
-       MEdge *medge;
-       MFace *mface;
-       MSelect *mselect;
-       EditVert *eve;
-       EditFace *efa, *efa_act;
-       EditEdge *eed;
-       EditSelection *ese;
-       float *fp, *newkey, *oldkey, nor[3];
-       int i, a, ototvert;
-       
-       /* this one also tests of edges are not in faces: */
-       /* eed->f2==0: not in face, f2==1: draw it */
-       /* eed->f1 : flag for dynaface (cylindertest, old engine) */
-       /* eve->f1 : flag for dynaface (sphere test, old engine) */
-       /* eve->f2 : being used in vertexnormals */
-       edge_drawflags(me, em);
-       
-       EM_stats_update(em);
-       
-       /* new Vertex block */
-       if(em->totvert==0) mvert= NULL;
-       else mvert= MEM_callocN(em->totvert*sizeof(MVert), "loadeditMesh vert");
-
-       /* new Edge block */
-       if(em->totedge==0) medge= NULL;
-       else medge= MEM_callocN(em->totedge*sizeof(MEdge), "loadeditMesh edge");
-       
-       /* new Face block */
-       if(em->totface==0) mface= NULL;
-       else mface= MEM_callocN(em->totface*sizeof(MFace), "loadeditMesh face");
-
-       /* lets save the old verts just in case we are actually working on
-        * a key ... we now do processing of the keys at the end */
-       oldverts= me->mvert;
-       ototvert= me->totvert;
-
-       /* don't free this yet */
-       CustomData_set_layer(&me->vdata, CD_MVERT, NULL);
-
-       /* free custom data */
-       CustomData_free(&me->vdata, me->totvert);
-       CustomData_free(&me->edata, me->totedge);
-       CustomData_free(&me->fdata, me->totface);
-
-       /* add new custom data */
-       me->totvert= em->totvert;
-       me->totedge= em->totedge;
-       me->totface= em->totface;
-
-       CustomData_copy(&em->vdata, &me->vdata, CD_MASK_MESH, CD_CALLOC, me->totvert);
-       CustomData_copy(&em->edata, &me->edata, CD_MASK_MESH, CD_CALLOC, me->totedge);
-       CustomData_copy(&em->fdata, &me->fdata, CD_MASK_MESH, CD_CALLOC, me->totface);
-
-       CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert);
-       CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge);
-       CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, mface, me->totface);
-       mesh_update_customdata_pointers(me);
-
-       /* the vertices, use ->tmp.l as counter */
-       eve= em->verts.first;
-       a= 0;
-
-       while(eve) {
-               VECCOPY(mvert->co, eve->co);
-
-               mvert->mat_nr= 32767;  /* what was this for, halos? */
-               
-               /* vertex normal */
-               VECCOPY(nor, eve->no);
-               mul_v3_fl(nor, 32767.0);
-               VECCOPY(mvert->no, nor);
-
-               /* note: it used to remove me->dvert when it was not in use, cancelled
-                  that... annoying when you have a fresh vgroup */
-               CustomData_from_em_block(&em->vdata, &me->vdata, eve->data, a);
-
-               eve->tmp.l = a++;  /* counter */
-                       
-               mvert->flag= 0;
-               mvert->flag |= (eve->f & SELECT);
-               if (eve->h) mvert->flag |= ME_HIDE;
-               
-               mvert->bweight= (char)(255.0*eve->bweight);
-
-               eve= eve->next;
-               mvert++;
-       }
-
-       /* the edges */
-       a= 0;
-       eed= em->edges.first;
-       while(eed) {
-               medge->v1= (unsigned int) eed->v1->tmp.l;
-               medge->v2= (unsigned int) eed->v2->tmp.l;
-               
-               medge->flag= (eed->f & SELECT) | ME_EDGERENDER;
-               if(eed->f2<2) medge->flag |= ME_EDGEDRAW;
-               if(eed->f2==0) medge->flag |= ME_LOOSEEDGE;
-               if(eed->sharp) medge->flag |= ME_SHARP;
-               if(eed->seam) medge->flag |= ME_SEAM;
-               if(eed->h & EM_FGON) medge->flag |= ME_FGON;    // different defines yes
-               if(eed->h & 1) medge->flag |= ME_HIDE;
-               
-               medge->crease= (char)(255.0*eed->crease);
-               medge->bweight= (char)(255.0*eed->bweight);
-               CustomData_from_em_block(&em->edata, &me->edata, eed->data, a);         
-
-               eed->tmp.l = a++;
-               
-               medge++;
-               eed= eed->next;
-       }
-
-       /* the faces */
-       a = 0;
-       efa= em->faces.first;
-       efa_act= EM_get_actFace(em, 0);
-       i = 0;
-       me->act_face = -1;
-       while(efa) {
-               mface= &((MFace *) me->mface)[i];
-               
-               mface->v1= (unsigned int) efa->v1->tmp.l;
-               mface->v2= (unsigned int) efa->v2->tmp.l;
-               mface->v3= (unsigned int) efa->v3->tmp.l;
-               if (efa->v4) mface->v4 = (unsigned int) efa->v4->tmp.l;
-
-               mface->mat_nr= efa->mat_nr;
-               
-               mface->flag= efa->flag;
-               /* bit 0 of flag is already taken for smooth... */
-               
-               if(efa->h) {
-                       mface->flag |= ME_HIDE;
-                       mface->flag &= ~ME_FACE_SEL;
-               } else {
-                       if(efa->f & 1) mface->flag |= ME_FACE_SEL;
-                       else mface->flag &= ~ME_FACE_SEL;
-               }
-               
-               /* mat_nr in vertex */
-               if(me->totcol>1) {
-                       mvert= me->mvert+mface->v1;
-                       if(mvert->mat_nr == (char)32767) mvert->mat_nr= mface->mat_nr;
-                       mvert= me->mvert+mface->v2;
-                       if(mvert->mat_nr == (char)32767) mvert->mat_nr= mface->mat_nr;
-                       mvert= me->mvert+mface->v3;
-                       if(mvert->mat_nr == (char)32767) mvert->mat_nr= mface->mat_nr;
-                       if(mface->v4) {
-                               mvert= me->mvert+mface->v4;
-                               if(mvert->mat_nr == (char)32767) mvert->mat_nr= mface->mat_nr;
-                       }
-               }
-                       
-               /* watch: efa->e1->f2==0 means loose edge */ 
-                       
-               if(efa->e1->f2==1) {
-                       efa->e1->f2= 2;
-               }                       
-               if(efa->e2->f2==1) {
-                       efa->e2->f2= 2;
-               }
-               if(efa->e3->f2==1) {
-                       efa->e3->f2= 2;
-               }
-               if(efa->e4 && efa->e4->f2==1) {
-                       efa->e4->f2= 2;
-               }
-
-               CustomData_from_em_block(&em->fdata, &me->fdata, efa->data, i);
-
-               /* no index '0' at location 3 or 4 */
-               test_index_face(mface, &me->fdata, i, efa->v4?4:3);
-               
-               if (efa_act == efa)
-                       me->act_face = a;
-
-               efa->tmp.l = a++;
-               i++;
-               efa= efa->next;
-       }
-
-       /* patch hook indices and vertex parents */
-       {
-               Object *ob;
-               ModifierData *md;
-               EditVert **vertMap = NULL;
-               int i,j;
-
-               for (ob=G.main->object.first; ob; ob=ob->id.next) {
-                       if (ob->parent==ob && ELEM(ob->partype, PARVERT1,PARVERT3)) {
-                               
-                               /* duplicate code from below, make it function later...? */
-                               if (!vertMap) {
-                                       vertMap = MEM_callocN(sizeof(*vertMap)*ototvert, "vertMap");
-                                       
-                                       for (eve=em->verts.first; eve; eve=eve->next) {
-                                               if (eve->keyindex!=-1)
-                                                       vertMap[eve->keyindex] = eve;
-                                       }
-                               }
-                               if(ob->par1 < ototvert) {
-                                       eve = vertMap[ob->par1];
-                                       if(eve) ob->par1= eve->tmp.l;
-                               }
-                               if(ob->par2 < ototvert) {
-                                       eve = vertMap[ob->par2];
-                                       if(eve) ob->par2= eve->tmp.l;
-                               }
-                               if(ob->par3 < ototvert) {
-                                       eve = vertMap[ob->par3];
-                                       if(eve) ob->par3= eve->tmp.l;
-                               }
-                               
-                       }
-                       if (ob->data==me) {
-                               for (md=ob->modifiers.first; md; md=md->next) {
-                                       if (md->type==eModifierType_Hook) {
-                                               HookModifierData *hmd = (HookModifierData*) md;
-
-                                               if (!vertMap) {
-                                                       vertMap = MEM_callocN(sizeof(*vertMap)*ototvert, "vertMap");
-
-                                                       for (eve=em->verts.first; eve; eve=eve->next) {
-                                                               if (eve->keyindex!=-1)
-                                                                       vertMap[eve->keyindex] = eve;
-                                                       }
-                                               }
-                                               
-                                               for (i=j=0; i<hmd->totindex; i++) {
-                                                       if(hmd->indexar[i] < ototvert) {
-                                                               eve = vertMap[hmd->indexar[i]];
-                                                               
-                                                               if (eve) {
-                                                                       hmd->indexar[j++] = eve->tmp.l;
-                                                               }
-                                                       }
-                                                       else j++;
-                                               }
-
-                                               hmd->totindex = j;
-                                       }
-                               }
-                       }
-               }
-
-               if (vertMap) MEM_freeN(vertMap);
-       }
-
-       /* are there keys? */
-       if(me->key) {
-               KeyBlock *currkey;
-               KeyBlock *actkey= BLI_findlink(&me->key->block, em->shapenr-1);
-
-               /* Lets reorder the key data so that things line up roughly
-                * with the way things were before editmode */
-               currkey = me->key->block.first;
-               while(currkey) {
-                       
-                       fp= newkey= MEM_callocN(me->key->elemsize*em->totvert,  "currkey->data");
-                       oldkey = currkey->data;
-
-                       eve= em->verts.first;
-
-                       i = 0;
-                       mvert = me->mvert;
-                       while(eve) {
-                               if (eve->keyindex >= 0 && eve->keyindex < currkey->totelem) { // valid old vertex
-                                       if(currkey == actkey) {
-                                               if(actkey == me->key->refkey) {
-                                                       VECCOPY(fp, mvert->co);
-                                               }
-                                               else {
-                                                       VECCOPY(fp, mvert->co);
-                                                       if(oldverts) {
-                                                               VECCOPY(mvert->co, oldverts[eve->keyindex].co);
-                                                       }
-                                               }
-                                       }
-                                       else {
-                                               if(oldkey) {
-                                                       VECCOPY(fp, oldkey + 3 * eve->keyindex);
-                                               }
-                                       }
-                               }
-                               else {
-                                       VECCOPY(fp, mvert->co);
-                               }
-                               fp+= 3;
-                               ++i;
-                               ++mvert;
-                               eve= eve->next;
-                       }
-                       currkey->totelem= em->totvert;
-                       if(currkey->data) MEM_freeN(currkey->data);
-                       currkey->data = newkey;
-                       
-                       currkey= currkey->next;
-               }
-       }
-
-       if(oldverts) MEM_freeN(oldverts);
-       
-       i = 0;
-       for(ese=em->selected.first; ese; ese=ese->next) i++;
-       me->totselect = i;
-       if(i==0) mselect= NULL;
-       else mselect= MEM_callocN(i*sizeof(MSelect), "loadeditMesh selections");
-       
-       if(me->mselect) MEM_freeN(me->mselect);
-       me->mselect= mselect;
-       
-       for(ese=em->selected.first; ese; ese=ese->next){
-               mselect->type = ese->type;
-               if(ese->type == EDITVERT) mselect->index = ((EditVert*)ese->data)->tmp.l;
-               else if(ese->type == EDITEDGE) mselect->index = ((EditEdge*)ese->data)->tmp.l;
-               else if(ese->type == EDITFACE) mselect->index = ((EditFace*)ese->data)->tmp.l;
-               mselect++;
-       }
-       
-       /* to be sure: clear ->tmp.l pointers */
-       eve= em->verts.first;
-       while(eve) {
-               eve->tmp.l = 0;
-               eve= eve->next;
-       }
-       
-       eed= em->edges.first;
-       while(eed) { 
-               eed->tmp.l = 0;
-               eed= eed->next;
-       }
-       
-       efa= em->faces.first;
-       while(efa) {
-               efa->tmp.l = 0;
-               efa= efa->next;
-       }
-       
-       /* remake softbody of all users */
-       if(me->id.us>1) {
-               Base *base;
-               for(base= scene->base.first; base; base= base->next)
-                       if(base->object->data==me)
-                               base->object->recalc |= OB_RECALC_DATA;
-       }
-
-       mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
-}
-
-void remake_editMesh(Scene *scene, Object *ob)
-{
-       make_editMesh(scene, ob);
-       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
-       BIF_undo_push("Undo all changes");
-}
-
-/* *************** Operator: separate parts *************/
-
-static EnumPropertyItem prop_separate_types[] = {
-       {0, "SELECTED", 0, "Selection", ""},
-       {1, "MATERIAL", 0, "By Material", ""},
-       {2, "LOOSE", 0, "By loose parts", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-/* return 1: success */
-static int mesh_separate_selected(Scene *scene, Base *editbase)
-{
-#if 0
-       EditMesh *em, *emnew;
-       EditVert *eve, *v1;
-       EditEdge *eed, *e1;
-       EditFace *efa, *f1;
-       Object *obedit;
-       Mesh *me, *menew;
-       Base *basenew;
-       
-       if(editbase==NULL) return 0;
-       
-       obedit= editbase->object;
-       me= obedit->data;
-       em= BKE_mesh_get_editmesh(me);
-       if(me->key) {
-               error("Can't separate with vertex keys");
-               BKE_mesh_end_editmesh(me, em);
-               return 0;
-       }
-       
-       if(em->selected.first) 
-               BLI_freelistN(&(em->selected)); /* clear the selection order */
-               
-       EM_selectmode_set(em);  // enforce full consistent selection flags 
-       
-       EM_stats_update(em);
-       
-       if(em->totvertsel==0) {
-               BKE_mesh_end_editmesh(me, em);
-               return 0;
-       }
-       
-       /* we are going to work as follows:
-        * 1. add a linked duplicate object: this will be the new one, we remember old pointer
-        * 2. give new object empty mesh and put in editmode
-        * 3: do a split if needed on current editmesh.
-        * 4. copy over: all NOT selected verts, edges, faces
-        * 5. call load_editMesh() on the new object
-        */
-       
-       /* 1 */
-       basenew= ED_object_add_duplicate(scene, editbase, 0);   /* 0 = fully linked */
-       ED_base_object_select(basenew, BA_DESELECT);
-       
-       /* 2 */
-       basenew->object->data= menew= add_mesh(me->id.name+2);  /* empty */
-       assign_matarar(basenew->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */
-       me->id.us--;
-       emnew = make_editMesh(scene, basenew->object);
-       //emnew= menew->edit_mesh;
-       CustomData_copy(&em->vdata, &emnew->vdata, CD_MASK_EDITMESH, CD_DEFAULT, 0);
-       CustomData_copy(&em->edata, &emnew->edata, CD_MASK_EDITMESH, CD_DEFAULT, 0);
-       CustomData_copy(&em->fdata, &emnew->fdata, CD_MASK_EDITMESH, CD_DEFAULT, 0);
-       
-       /* 3 */
-       /* SPLIT: first make duplicate */
-       adduplicateflag(em, SELECT);
-       /* SPLIT: old faces have 3x flag 128 set, delete these ones */
-       delfaceflag(em, 128);
-       /* since we do tricky things with verts/edges/faces, this makes sure all is selected coherent */
-       EM_selectmode_set(em);
-       
-       /* 4 */
-       /* move over: everything that is selected */
-       for(eve= em->verts.first; eve; eve= v1) {
-               v1= eve->next;
-               if(eve->f & SELECT) {
-                       BLI_remlink(&em->verts, eve);
-                       BLI_addtail(&emnew->verts, eve);
-               }
-       }
-       
-       for(eed= em->edges.first; eed; eed= e1) {
-               e1= eed->next;
-               if(eed->f & SELECT) {
-                       BLI_remlink(&em->edges, eed);
-                       BLI_addtail(&emnew->edges, eed);
-               }
-       }
-       
-       for(efa= em->faces.first; efa; efa= f1) {
-               f1= efa->next;
-               if (efa == em->act_face && (efa->f & SELECT)) {
-                       EM_set_actFace(em, NULL);
-               }
-
-               if(efa->f & SELECT) {
-                       BLI_remlink(&em->faces, efa);
-                       BLI_addtail(&emnew->faces, efa);
-               }
-       }
-
-       /* 5 */
-       load_editMesh(scene, basenew->object, emnew);
-       free_editMesh(emnew);
-       MEM_freeN(menew->edit_mesh);
-       menew->edit_mesh= NULL;
-       
-       /* hashedges are invalid now, make new! */
-       editMesh_set_hash(em);
-
-       DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);       
-       DAG_id_flush_update(&basenew->object->id, OB_RECALC_DATA);      
-
-       BKE_mesh_end_editmesh(me, em);
-
-       return 1;
-#endif
-}
-
-/* return 1: success */
-static int mesh_separate_material(Scene *scene, Base *editbase)
-{
-#if 0
-       Mesh *me= editbase->object->data;
-       EditMesh *em= BKE_mesh_get_editmesh(me);
-       unsigned char curr_mat;
-       
-       for (curr_mat = 1; curr_mat < editbase->object->totcol; ++curr_mat) {
-               /* clear selection, we're going to use that to select material group */
-               EM_clear_flag_all(em, SELECT);
-               /* select the material */
-               EM_select_by_material(em, curr_mat);
-               /* and now separate */
-               if(0==mesh_separate_selected(scene, editbase)) {
-                       BKE_mesh_end_editmesh(me, em);
-                       return 0;
-               }
-       }
-
-       BKE_mesh_end_editmesh(me, em);
-       return 1;
-#endif
-}
-
-/* return 1: success */
-static int mesh_separate_loose(Scene *scene, Base *editbase)
-{
-       return 0;
-#if 0
-       Mesh *me;
-       EditMesh *em;
-       int doit= 1;
-       
-       me= editbase->object->data;
-       em= BKE_mesh_get_editmesh(me);
-       
-       if(me->key) {
-               error("Can't separate with vertex keys");
-               BKE_mesh_end_editmesh(me, em);
-               return 0;
-       }
-       
-       EM_clear_flag_all(em, SELECT);
-       
-       while(doit && em->verts.first) {
-               /* Select a random vert to start with */
-               EditVert *eve= em->verts.first;
-               eve->f |= SELECT;
-               
-               selectconnected_mesh_all(em);
-               
-               /* and now separate */
-               doit= mesh_separate_selected(scene, editbase);
-       }
-
-       BKE_mesh_end_editmesh(me, em);
-       return 1;
-#endif
-}
-
-
-static int mesh_separate_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       Base *base= CTX_data_active_base(C);
-       int retval= 0, type= RNA_enum_get(op->ptr, "type");
-       
-       if(type == 0)
-               retval= mesh_separate_selected(scene, base);
-       else if(type == 1)
-               retval= mesh_separate_material (scene, base);
-       else if(type == 2)
-               retval= mesh_separate_loose(scene, base);
-          
-       if(retval) {
-               WM_event_add_notifier(C, NC_GEOM|ND_DATA, base->object->data);
-               return OPERATOR_FINISHED;
-       }
-       return OPERATOR_CANCELLED;
-}
-
-void MESH_OT_separate(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Separate";
-       ot->description= "Separate selected geometry into a new mesh.";
-       ot->idname= "MESH_OT_separate";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= mesh_separate_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_separate_types, 0, "Type", "");
-}
-
-
-/* ******************************************** */
-
-/* *************** UNDO ***************************** */
-/* new mesh undo, based on pushing editmesh data itself */
-/* reuses same code as for global and curve undo... unify that (ton) */
-
-/* only one 'hack', to save memory it doesn't store the first push, but does a remake editmesh */
-
-/* a compressed version of editmesh data */
-
-typedef struct EditVertC
-{
-       float no[3];
-       float co[3];
-       unsigned char f, h;
-       short bweight;
-       int keyindex;
-} EditVertC;
-
-typedef struct EditEdgeC
-{
-       int v1, v2;
-       unsigned char f, h, seam, sharp, pad;
-       short crease, bweight, fgoni;
-} EditEdgeC;
-
-typedef struct EditFaceC
-{
-       int v1, v2, v3, v4;
-       unsigned char flag, f, h, fgonf, pad1;
-       short mat_nr;
-} EditFaceC;
-
-typedef struct EditSelectionC{
-       short type;
-       int index;
-}EditSelectionC;
-
-typedef struct UndoMesh {
-       EditVertC *verts;
-       EditEdgeC *edges;
-       EditFaceC *faces;
-       EditFaceC *act_face;
-       EditSelectionC *selected;
-       int totvert, totedge, totface, totsel;
-       short selectmode;
-       RetopoPaintData *retopo_paint_data;
-       char retopo_mode;
-       CustomData vdata, edata, fdata;
-} UndoMesh;
-
-
-/* *************** END UNDO *************/
-
-static EditVert **g_em_vert_array = NULL;
-static EditEdge **g_em_edge_array = NULL;
-static EditFace **g_em_face_array = NULL;
-
-void EM_init_index_arrays(EditMesh *em, int forVert, int forEdge, int forFace)
-{
-       EditVert *eve;
-       EditEdge *eed;
-       EditFace *efa;
-       int i;
-
-       if (forVert) {
-               em->totvert= BLI_countlist(&em->verts);
-
-               if(em->totvert) {
-                       g_em_vert_array = MEM_mallocN(sizeof(*g_em_vert_array)*em->totvert, "em_v_arr");
-
-                       for (i=0,eve=em->verts.first; eve; i++,eve=eve->next)
-                               g_em_vert_array[i] = eve;
-               }
-       }
-
-       if (forEdge) {
-               em->totedge= BLI_countlist(&em->edges);
-
-               if(em->totedge) {
-                       g_em_edge_array = MEM_mallocN(sizeof(*g_em_edge_array)*em->totedge, "em_e_arr");
-
-                       for (i=0,eed=em->edges.first; eed; i++,eed=eed->next)
-                               g_em_edge_array[i] = eed;
-               }
-       }
-
-       if (forFace) {
-               em->totface= BLI_countlist(&em->faces);
-
-               if(em->totface) {
-                       g_em_face_array = MEM_mallocN(sizeof(*g_em_face_array)*em->totface, "em_f_arr");
-
-                       for (i=0,efa=em->faces.first; efa; i++,efa=efa->next)
-                               g_em_face_array[i] = efa;
-               }
-       }
-}
-
-void EM_free_index_arrays(void)
-{
-       if (g_em_vert_array) MEM_freeN(g_em_vert_array);
-       if (g_em_edge_array) MEM_freeN(g_em_edge_array);
-       if (g_em_face_array) MEM_freeN(g_em_face_array);
-       g_em_vert_array = NULL;
-       g_em_edge_array = NULL;
-       g_em_face_array = NULL;
-}
-
-EditVert *EM_get_vert_for_index(int index)
-{
-       return g_em_vert_array?g_em_vert_array[index]:NULL;
-}
-
-EditEdge *EM_get_edge_for_index(int index)
-{
-       return g_em_edge_array?g_em_edge_array[index]:NULL;
-}
-
-EditFace *EM_get_face_for_index(int index)
-{
-       return g_em_face_array?g_em_face_array[index]:NULL;
-}
-
-/* can we edit UV's for this mesh?*/
-int EM_texFaceCheck(EditMesh *em)
-{
-       /* some of these checks could be a touch overkill */
-       if (    (em) &&
-                       (em->faces.first) &&
-                       (CustomData_has_layer(&em->fdata, CD_MTFACE)))
-               return 1;
-       return 0;
-}
-
-/* can we edit colors for this mesh?*/
-int EM_vertColorCheck(EditMesh *em)
-{
-       /* some of these checks could be a touch overkill */
-       if (    (em) &&
-                       (em->faces.first) &&
-                       (CustomData_has_layer(&em->fdata, CD_MCOL)))
-               return 1;
-       return 0;
-}
-
-
-void em_setup_viewcontext(bContext *C, ViewContext *vc)
-{
-       view3d_set_viewcontext(C, vc);
-       
-       if(vc->obedit) {
-               Mesh *me= vc->obedit->data;
-               vc->em= me->edit_btmesh;
-       }
-}
diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c
deleted file mode 100644 (file)
index ad61dff..0000000
+++ /dev/null
@@ -1,1554 +0,0 @@
-/**
- * $Id: 
- *
- * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2004 by Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_space_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_windowmanager_types.h"
-
-#include "RNA_types.h"
-#include "RNA_define.h"
-#include "RNA_access.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_editVert.h"
-
-#include "BKE_context.h"
-#include "BKE_depsgraph.h"
-#include "BKE_global.h"
-#include "BKE_library.h"
-#include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_utildefines.h"
-#include "BKE_report.h"
-#include "BKE_tessmesh.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "ED_mesh.h"
-#include "ED_retopo.h"
-#include "ED_screen.h"
-#include "ED_transform.h"
-#include "ED_util.h"
-#include "ED_view3d.h"
-#include "ED_object.h"
-
-#include "bmesh.h"
-
-#include "mesh_intern.h"
-
-/* bpymenu removed XXX */
-
-/* XXX */
-#define add_numbut(a, b, c, d, e, f, g) {}
-/* XXX */
-
-static float icovert[12][3] = {
-       {0.0f,0.0f,-200.0f}, 
-       {144.72f, -105.144f,-89.443f},
-       {-55.277f, -170.128,-89.443f}, 
-       {-178.885f,0.0f,-89.443f},
-       {-55.277f,170.128f,-89.443f}, 
-       {144.72f,105.144f,-89.443f},
-       {55.277f,-170.128f,89.443f},
-       {-144.72f,-105.144f,89.443f},
-       {-144.72f,105.144f,89.443f},
-       {55.277f,170.128f,89.443f},
-       {178.885f,0.0f,89.443f},
-       {0.0f,0.0f,200.0f}
-};
-static short icoface[20][3] = {
-       {1,0,2},
-       {1,0,5},
-       {2,0,3},
-       {3,0,4},
-       {4,0,5},
-       {1,5,10},
-       {2,1,6},
-       {3,2,7},
-       {4,3,8},
-       {5,4,9},
-       {10,1,6},
-       {6,2,7},
-       {7,3,8},
-       {8,4,9},
-       {9,5,10},
-       {6,10,11},
-       {7,6,11},
-       {8,7,11},
-       {9,8,11},
-       {10,9,11}
-};
-
-/* ********************** */
-
-/* selected faces get hidden edges */
-int make_fgon(EditMesh *em, wmOperator *op, int make)
-{
-       EditFace *efa;
-       EditEdge *eed;
-       EditVert *eve;
-       float *nor=NULL;        // reference
-       int done=0;
-       
-       if(make==0) {
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if(efa->f & SELECT) {
-                               efa->fgonf= 0;
-                               efa->e1->h &= ~EM_FGON;
-                               efa->e2->h &= ~EM_FGON;
-                               efa->e3->h &= ~EM_FGON;
-                               if(efa->e4) efa->e4->h &= ~EM_FGON;
-                               done= 1;
-                       }
-               }
-               EM_fgon_flags(em);      // redo flags and indices for fgons
-               
-               return done;
-       }
-
-       /* tagging edges. rule is:
-          - edge used by exactly 2 selected faces
-          - no vertices allowed with only tagged edges (return)
-          - face normals are allowed to difffer
-        
-       */
-       for(eed= em->edges.first; eed; eed= eed->next) {
-               eed->f1= 0;     // amount of selected
-               eed->f2= 0; // amount of unselected
-       }
-       
-       for(efa= em->faces.first; efa; efa= efa->next) {
-               if(efa->f & SELECT) {
-                       if(nor==NULL) nor= efa->n;
-                       if(efa->e1->f1 < 3) efa->e1->f1++;
-                       if(efa->e2->f1 < 3) efa->e2->f1++;
-                       if(efa->e3->f1 < 3) efa->e3->f1++;
-                       if(efa->e4 && efa->e4->f1 < 3) efa->e4->f1++;
-               }
-               else {
-                       if(efa->e1->f2 < 3) efa->e1->f2++;
-                       if(efa->e2->f2 < 3) efa->e2->f2++;
-                       if(efa->e3->f2 < 3) efa->e3->f2++;
-                       if(efa->e4 && efa->e4->f2 < 3) efa->e4->f2++;
-               }
-       }
-       // now eed->f1 becomes tagged edge
-       for(eed= em->edges.first; eed; eed= eed->next) {
-               if(eed->f1==2 && eed->f2==0) eed->f1= 1;
-               else eed->f1= 0;
-       }
-       
-       // no vertices allowed with only tagged edges
-       for(eve= em->verts.first; eve; eve= eve->next) eve->f1= 0;
-       for(eed= em->edges.first; eed; eed= eed->next) {
-               if(eed->f1) {
-                       eed->v1->f1 |= 1;
-                       eed->v2->f1 |= 1;
-               }
-               else {
-                       eed->v1->f1 |= 2;
-                       eed->v2->f1 |= 2;
-               }
-       }
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->f1==1) break;
-       }
-       if(eve) {
-               BKE_report(op->reports, RPT_ERROR, "Cannot make a polygon with interior vertices");
-               return 0;
-       }
-       
-       // check for faces
-       if(nor==NULL) {
-               BKE_report(op->reports, RPT_ERROR, "No faces were selected to make FGon");
-               return 0;
-       }
-
-       // and there we go
-       for(eed= em->edges.first; eed; eed= eed->next) {
-               if(eed->f1) {
-                       eed->h |= EM_FGON;
-                       done= 1;
-               }
-       }
-       
-       if(done)
-               EM_fgon_flags(em);      // redo flags and indices for fgons
-       return done;
-}
-
-static int make_fgon_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-
-       if( make_fgon(em, op, 1) ) {
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);      
-               WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
-               BKE_mesh_end_editmesh(obedit->data, em);
-               return OPERATOR_FINISHED;
-       }
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_CANCELLED;
-}
-
-void MESH_OT_fgon_make(struct wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Make F-gon";
-       ot->description= "Make fgon from selected faces.";
-       ot->idname= "MESH_OT_fgon_make";
-       
-       /* api callbacks */
-       ot->exec= make_fgon_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-static int clear_fgon_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       
-       if( make_fgon(em, op, 0) ) {
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);      
-               WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-               
-               BKE_mesh_end_editmesh(obedit->data, em);
-               return OPERATOR_FINISHED;
-       }
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_CANCELLED;
-}
-
-void MESH_OT_fgon_clear(struct wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Clear F-gon";
-       ot->description= "Clear fgon from selected face.";
-       ot->idname= "MESH_OT_fgon_clear";
-       
-       /* api callbacks */
-       ot->exec= clear_fgon_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-/* precondition; 4 vertices selected, check for 4 edges and create face */
-static EditFace *addface_from_edges(EditMesh *em)
-{
-       EditEdge *eed, *eedar[4]={NULL, NULL, NULL, NULL};
-       EditVert *v1=NULL, *v2=NULL, *v3=NULL, *v4=NULL;
-       int a;
-       
-       /* find the 4 edges */
-       for(eed= em->edges.first; eed; eed= eed->next) {
-               if( (eed->f & SELECT) || (eed->v1->f & eed->v2->f & SELECT) ) {
-                       if(eedar[0]==NULL) eedar[0]= eed;
-                       else if(eedar[1]==NULL) eedar[1]= eed;
-                       else if(eedar[2]==NULL) eedar[2]= eed;
-                       else eedar[3]= eed;
-                       
-               }
-       }
-       
-       
-       if(eedar[3]) {
-               /* first 2 points */
-               v1= eedar[0]->v1;
-               v2= eedar[0]->v2;
-               
-               /* find the 2 edges connected to first edge */
-               for(a=1; a<4; a++) {
-                       if( eedar[a]->v1 == v2) v3= eedar[a]->v2;
-                       else if(eedar[a]->v2 == v2) v3= eedar[a]->v1;
-                       else if( eedar[a]->v1 == v1) v4= eedar[a]->v2;
-                       else if(eedar[a]->v2 == v1) v4= eedar[a]->v1;
-               }
-               
-               /* verify if last edge exists */
-               if(v3 && v4) {
-                       for(a=1; a<4; a++) {
-                               if( eedar[a]->v1==v3 && eedar[a]->v2==v4) break;
-                               if( eedar[a]->v2==v3 && eedar[a]->v1==v4) break;
-                       }
-                       if(a!=4) {
-                               return addfacelist(em, v1, v2, v3, v4, NULL, NULL);
-                       }
-               }
-       }
-       return NULL;
-}
-
-/* ******************************* */
-
-/* this also allows to prevent triangles being made in quads */
-static int compareface_overlaps(EditFace *vl1, EditFace *vl2)
-{
-       EditVert *v1, *v2, *v3, *v4;
-       int equal= 0;
-       
-       v1= vl2->v1;
-       v2= vl2->v2;
-       v3= vl2->v3;
-       v4= vl2->v4;
-       
-       if(vl1==vl2) return 0;
-       
-       if(v4==NULL && vl1->v4==NULL) {
-               if(vl1->v1==v1 || vl1->v2==v1 || vl1->v3==v1) equal++;
-               if(vl1->v1==v2 || vl1->v2==v2 || vl1->v3==v2) equal++;
-               if(vl1->v1==v3 || vl1->v2==v3 || vl1->v3==v3) equal++;
-       }
-       else {
-               if(vl1->v1==v1 || vl1->v2==v1 || vl1->v3==v1 || vl1->v4==v1) equal++;
-               if(vl1->v1==v2 || vl1->v2==v2 || vl1->v3==v2 || vl1->v4==v2) equal++;
-               if(vl1->v1==v3 || vl1->v2==v3 || vl1->v3==v3 || vl1->v4==v3) equal++;
-               if(vl1->v1==v4 || vl1->v2==v4 || vl1->v3==v4 || vl1->v4==v4) equal++;
-       }
-
-       if(v4 && vl1->v4) {
-               if(equal==4) return 1;
-       }
-       else 
-               if(equal>=3) return 1;
-       
-       return 0;
-}
-
-/* checks for existance, and for tria overlapping inside quad */
-static EditFace *exist_face_overlaps(EditMesh *em, EditVert *v1, EditVert *v2, EditVert *v3, EditVert *v4)
-{
-       EditFace *efa, efatest;
-       
-       efatest.v1= v1;
-       efatest.v2= v2;
-       efatest.v3= v3;
-       efatest.v4= v4;
-       
-       efa= em->faces.first;
-       while(efa) {
-               if(compareface_overlaps(&efatest, efa)) return efa;
-               efa= efa->next;
-       }
-       return NULL;
-}
-
-/* will be new face smooth or solid? depends on smoothness of face neighbours
- * of new face, if function return 1, then new face will be smooth, when functio
- * will return zero, then new face will be solid */
-static void fix_new_face(EditMesh *em, EditFace *eface)
-{
-       struct EditFace *efa;
-       struct EditEdge *eed=NULL;
-       struct EditVert *v1 = eface->v1, *v2 = eface->v2, *v3 = eface->v3, *v4 = eface->v4;
-       struct EditVert *ev1=NULL, *ev2=NULL;
-       short smooth=0; /* "total smoothnes" of faces in neighbourhood */
-       short coef;     /* "weight" of smoothness */
-       short count=0;  /* number of edges with same direction as eface */
-       short vi00=0, vi01=0, vi10=0, vi11=0; /* vertex indexes */
-
-       efa = em->faces.first;
-
-       while(efa) {
-
-               if(efa==eface) {
-                       efa = efa->next;
-                       continue;
-               }
-
-               coef = 0;
-               ev1 = ev2 = NULL;
-               eed = NULL;
-
-               if(efa->v1==v1 || efa->v2==v1 || efa->v3==v1 || efa->v4==v1) {
-                       ev1 = v1;
-                       coef++;
-               }
-               if(efa->v1==v2 || efa->v2==v2 || efa->v3==v2 || efa->v4==v2) {
-                       if(ev1) ev2 = v2;
-                       else ev1 = v2;
-                       coef++;
-               }
-               if(efa->v1==v3 || efa->v2==v3 || efa->v3==v3 || efa->v4==v3) {
-                       if(coef<2) {
-                               if(ev1) ev2 = v3;
-                               else ev1 = v3;
-                       }
-                       coef++;
-               }
-               if((v4) && (efa->v1==v4 || efa->v2==v4 || efa->v3==v4 || efa->v4==v4)) {
-                       if(ev1 && coef<2) ev2 = v4;
-                       coef++;
-               }
-
-               /* "democracy" of smoothness */
-               if(efa->flag & ME_SMOOTH)
-                       smooth += coef;
-               else
-                       smooth -= coef;
-
-               /* try to find edge using vertexes ev1 and ev2 */
-               if((ev1) && (ev2) && (ev1!=ev2)) eed = findedgelist(em, ev1, ev2);
-
-               /* has bordering edge of efa same direction as edge of eface ? */
-               if(eed) {
-                       if(eed->v1==v1) vi00 = 1;
-                       else if(eed->v1==v2) vi00 = 2;
-                       else if(eed->v1==v3) vi00 = 3;
-                       else if(v4 && eed->v1==v4) vi00 = 4;
-
-                       if(eed->v2==v1) vi01 = 1;
-                       else if(eed->v2==v2) vi01 = 2;
-                       else if(eed->v2==v3) vi01 = 3;
-                       else if(v4 && eed->v2==v4) vi01 = 4;
-
-                       if(v4) {
-                               if(vi01==1 && vi00==4) vi00 = 0;
-                               if(vi01==4 && vi00==1) vi01 = 0;
-                       }
-                       else {
-                               if(vi01==1 && vi00==3) vi00 = 0;
-                               if(vi01==3 && vi00==1) vi01 = 0;
-                       }
-
-                       if(eed->v1==efa->v1) vi10 = 1;
-                       else if(eed->v1==efa->v2) vi10 = 2;
-                       else if(eed->v1==efa->v3) vi10 = 3;
-                       else if(efa->v4 && eed->v1==efa->v4) vi10 = 4;
-
-                       if(eed->v2==efa->v1) vi11 = 1;
-                       else if(eed->v2==efa->v2) vi11 = 2;
-                       else if(eed->v2==efa->v3) vi11 = 3;
-                       else if(efa->v4 && eed->v2==efa->v4) vi11 = 4;
-
-                       if(efa->v4) {
-                               if(vi11==1 && vi10==4) vi10 = 0;
-                               if(vi11==4 && vi10==1) vi11 = 0;
-                       }
-                       else {
-                               if(vi11==1 && vi10==3) vi10 = 0;
-                               if(vi11==3 && vi10==1) vi11 = 0;
-                       }
-
-                       if(((vi00>vi01) && (vi10>vi11)) ||
-                               ((vi00<vi01) && (vi10<vi11)))
-                               count++;
-                       else
-                               count--;
-               }
-
-               efa = efa->next;
-       }
-
-       /* set up smoothness according voting of face in neighbourhood */
-       if(smooth >= 0)
-               eface->flag |= ME_SMOOTH;
-       else
-               eface->flag &= ~ME_SMOOTH;
-
-       /* flip face, when too much "face normals" in neighbourhood is different */
-       if(count > 0) {
-               flipface(em, eface);
-       }
-}
-
-/* only adds quads or trias when there's edges already */
-void addfaces_from_edgenet(EditMesh *em)
-{
-       EditVert *eve1, *eve2, *eve3, *eve4;
-       
-       for(eve1= em->verts.first; eve1; eve1= eve1->next) {
-               for(eve2= em->verts.first; (eve1->f & 1) && eve2; eve2= eve2->next) {
-                       if(findedgelist(em, eve1,eve2)) {
-                               for(eve3= em->verts.first; (eve2->f & 1) && eve3; eve3= eve3->next) {
-                                       if((eve2!=eve3 && (eve3->f & 1) && findedgelist(em, eve1,eve3))) {
-                                               EditEdge *sh_edge= NULL;
-                                               EditVert *sh_vert= NULL;
-                                               
-                                               sh_edge= findedgelist(em, eve2,eve3);
-                                               
-                                               if(sh_edge) { /* Add a triangle */
-                                                       if(!exist_face_overlaps(em, eve1,eve2,eve3,NULL))
-                                                               fix_new_face(em, addfacelist(em, eve1,eve2,eve3,NULL,NULL,NULL));
-                                               }
-                                               else { /* Check for a shared vertex */
-                                                       for(eve4= em->verts.first; eve4; eve4= eve4->next) {
-                                                               if(eve4!=eve1 && eve4!=eve2 && eve4!=eve3 && (eve4->f & 1) &&
-                                                                  !findedgelist(em, eve1,eve4) && findedgelist(em, eve2,eve4) &&
-                                                                  findedgelist(em, eve3,eve4)) {
-                                                                       sh_vert= eve4;
-                                                                       break;
-                                                               }
-                                                       }
-                                                       
-                                                       if(sh_vert) {
-                                                               if(sh_vert) {
-                                                                       if(!exist_face_overlaps(em, eve1,eve2,eve4,eve3))
-                                                                               fix_new_face(em, addfacelist(em, eve1,eve2,eve4,eve3,NULL,NULL));
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-
-       EM_select_flush(em);
-       
-// XXX DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-}
-
-static void addedgeface_mesh(Mesh *me, BMEditMesh *bem, wmOperator *op)
-{
-       EditMesh *em;
-       EditVert *eve, *neweve[4];
-       EditEdge *eed;
-       EditFace *efa;
-       short amount=0;
-       
-       /*return if bmesh vert connect does anything.*/
-       if (bem->selectmode & SCE_SELECT_VERTEX) {
-               BMesh *bm = bem->bm;
-               BMOperator bmop;
-               int len, ok;
-               
-               EDBM_InitOpf(bem, &bmop, op, "connectverts verts=%hv", BM_SELECT);
-               BMO_Exec_Op(bem->bm, &bmop);
-
-               len = BMO_GetSlot(&bmop, "edgeout")->len;               
-
-               ok = EDBM_FinishOp(bem, &bmop, op, 1);
-               if (!ok) return;
-
-               if (len) return;        
-       }
-
-       /*return if bmesh face dissolve finds stuff to
-         dissolve.  this entire tool should be
-         bmeshafied eventually, but until then
-         hacks like this to integrate with it
-         are necassary.*/
-       if (bem->selectmode & SCE_SELECT_VERTEX) {
-               BMesh *bm = bem->bm;
-               BMOperator bmop;
-               int len, ok;
-               
-               EDBM_InitOpf(bem, &bmop, op, "dissolvefaces faces=%hf", BM_SELECT);
-               BMO_Exec_Op(bem->bm, &bmop);
-
-               len = BMO_GetSlot(&bmop, "regionout")->len;             
-               
-               ok = EDBM_FinishOp(bem, &bmop, op, 1);
-               if (!ok) return;
-
-               if (len) return;        
-       }
-
-       em = BKE_mesh_get_editmesh(me);
-
-       /* how many selected ? */
-       if(em->selectmode & SCE_SELECT_EDGE) {
-               /* in edge mode finding selected vertices means flushing down edge codes... */
-               /* can't make face with only edge selection info... */
-               EM_selectmode_set(em);
-       }
-       
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->f & SELECT) {
-                       amount++;
-                       if(amount>4) break;                     
-                       neweve[amount-1]= eve;
-               }
-       }
-
-       if(amount==2) {
-               eed= addedgelist(em, neweve[0], neweve[1], NULL);
-               EM_select_edge(eed, 1);
-               
-               BKE_mesh_end_editmesh(me, em);
-               // XXX          DAG_id_flush_update(obedit->data, OB_RECALC_DATA);      
-               return;
-       }
-       else if(amount > 4) {
-               addfaces_from_edgenet(em);
-               BKE_mesh_end_editmesh(me, em);
-               return;
-       }
-       else if(amount<2) {
-               BKE_report(op->reports, RPT_ERROR, "More vertices are needed to make an edge/face");
-               BKE_mesh_end_editmesh(me, em);
-               return;
-       }
-
-       efa= NULL; // check later
-
-       if(amount==3) {
-               
-               if(exist_face_overlaps(em, neweve[0], neweve[1], neweve[2], NULL)==0) {
-                       efa= addfacelist(em, neweve[0], neweve[1], neweve[2], 0, NULL, NULL);
-                       EM_select_face(efa, 1);
-               }
-               else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
-       }
-       else if(amount==4) {
-               /* this test survives when theres 2 triangles */
-               if(exist_face(em, neweve[0], neweve[1], neweve[2], neweve[3])==0) {
-                       int tria= 0;
-                       
-                       /* remove trias if they exist, 4 cases.... */
-                       if(exist_face(em, neweve[0], neweve[1], neweve[2], NULL)) tria++;
-                       if(exist_face(em, neweve[0], neweve[1], neweve[3], NULL)) tria++;
-                       if(exist_face(em, neweve[0], neweve[2], neweve[3], NULL)) tria++;
-                       if(exist_face(em, neweve[1], neweve[2], neweve[3], NULL)) tria++;
-               
-                       if(tria==2) join_triangles(em);
-                       else if(exist_face_overlaps(em, neweve[0], neweve[1], neweve[2], neweve[3])==0) {
-                                /* If there are 4 Verts, But more selected edges, we need to call addfaces_from_edgenet */
-                                       EditEdge *eedcheck;
-                                       int count;
-                                       count = 0;
-                                       for(eedcheck= em->edges.first; eedcheck; eedcheck= eedcheck->next) {
-                                               if(eedcheck->f & SELECT) {
-                                                       count++;
-                                               }
-                                       }       
-                               
-                               if(count++ > 4){
-                                       addfaces_from_edgenet(em);
-                                       BKE_mesh_end_editmesh(me, em);
-                                       return;
-                               } else {
-                               /* if 4 edges exist, we just create the face, convex or not */
-                                       efa= addface_from_edges(em);
-                                       if(efa==NULL) {
-                                               
-                                               /* the order of vertices can be anything, 6 cases to check */
-                                               if( convex(neweve[0]->co, neweve[1]->co, neweve[2]->co, neweve[3]->co) ) {
-                                                       efa= addfacelist(em, neweve[0], neweve[1], neweve[2], neweve[3], NULL, NULL);
-                                               }
-                                               else if( convex(neweve[0]->co, neweve[2]->co, neweve[3]->co, neweve[1]->co) ) {
-                                                       efa= addfacelist(em, neweve[0], neweve[2], neweve[3], neweve[1], NULL, NULL);
-                                               }
-                                               else if( convex(neweve[0]->co, neweve[2]->co, neweve[1]->co, neweve[3]->co) ) {
-                                                       efa= addfacelist(em, neweve[0], neweve[2], neweve[1], neweve[3], NULL, NULL);
-                                               }
-                                               else if( convex(neweve[0]->co, neweve[1]->co, neweve[3]->co, neweve[2]->co) ) {
-                                                       efa= addfacelist(em, neweve[0], neweve[1], neweve[3], neweve[2], NULL, NULL);
-                                               }
-                                               else if( convex(neweve[0]->co, neweve[3]->co, neweve[2]->co, neweve[1]->co) ) {
-                                                       efa= addfacelist(em, neweve[0], neweve[3], neweve[2], neweve[1], NULL, NULL);
-                                               }
-                                               else if( convex(neweve[0]->co, neweve[3]->co, neweve[1]->co, neweve[2]->co) ) {
-                                                       efa= addfacelist(em, neweve[0], neweve[3], neweve[1], neweve[2], NULL, NULL);
-                                               }
-                                               else printf("cannot find nice quad from concave set of vertices\n");
-                                       }
-                               }
-                       }
-                       else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
-               }
-               else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
-       }
-       
-       if(efa) {
-               EM_select_face(efa, 1);
-
-               fix_new_face(em, efa);
-               
-               recalc_editnormals(em);
-       }
-
-       BKE_mesh_end_editmesh(me, em);
-}
-
-/* ************************ primitives ******************* */
-
-// HACK: these can also be found in cmoview.tga.c, but are here so that they can be found by linker
-// this hack is only used so that scons+mingw + split-sources hack works
-       // ------------------------------- start copied code
-/* these are not the monkeys you are looking for */
-int monkeyo= 4;
-int monkeynv= 271;
-int monkeynf= 250;
-signed char monkeyv[271][3]= {
-{-71,21,98},{-63,12,88},{-57,7,74},{-82,-3,79},{-82,4,92},
-{-82,17,100},{-92,21,102},{-101,12,95},{-107,7,83},
-{-117,31,84},{-109,31,95},{-96,31,102},{-92,42,102},
-{-101,50,95},{-107,56,83},{-82,66,79},{-82,58,92},
-{-82,46,100},{-71,42,98},{-63,50,88},{-57,56,74},
-{-47,31,72},{-55,31,86},{-67,31,97},{-66,31,99},
-{-70,43,100},{-82,48,103},{-93,43,105},{-98,31,105},
-{-93,20,105},{-82,31,106},{-82,15,103},{-70,20,100},
-{-127,55,95},{-127,45,105},{-127,-87,94},{-127,-41,100},
-{-127,-24,102},{-127,-99,92},{-127,52,77},{-127,73,73},
-{-127,115,-70},{-127,72,-109},{-127,9,-106},{-127,-49,-45},
-{-101,-24,72},{-87,-56,73},{-82,-89,73},{-80,-114,68},
-{-85,-121,67},{-104,-124,71},{-127,-126,74},{-71,-18,68},
-{-46,-5,69},{-21,19,57},{-17,55,76},{-36,62,80},
-{-64,77,88},{-86,97,94},{-107,92,97},{-119,63,96},
-{-106,53,99},{-111,39,98},{-101,12,95},{-79,2,90},
-{-64,8,86},{-47,24,83},{-45,38,83},{-50,48,85},
-{-72,56,92},{-95,60,97},{-127,-98,94},{-113,-92,94},
-{-112,-107,91},{-119,-113,89},{-127,-114,88},{-127,-25,96},
-{-127,-18,95},{-114,-19,95},{-111,-29,96},{-116,-37,95},
-{-76,-6,86},{-48,7,80},{-34,26,77},{-32,48,84},
-{-39,53,93},{-71,70,102},{-87,82,107},{-101,79,109},
-{-114,55,108},{-111,-13,104},{-100,-57,91},{-95,-90,88},
-{-93,-105,85},{-97,-117,81},{-106,-119,81},{-127,-121,82},
-{-127,6,93},{-127,27,98},{-85,61,95},{-106,18,96},
-{-110,27,97},{-112,-88,94},{-117,-57,96},{-127,-57,96},
-{-127,-42,95},{-115,-35,100},{-110,-29,102},{-113,-17,100},
-{-122,-16,100},{-127,-26,106},{-121,-19,104},{-115,-20,104},
-{-113,-29,106},{-117,-32,103},{-127,-37,103},{-94,-40,71},
-{-106,-31,91},{-104,-40,91},{-97,-32,71},{-127,-112,88},
-{-121,-111,88},{-115,-105,91},{-115,-95,93},{-127,-100,84},
-{-115,-96,85},{-115,-104,82},{-121,-109,81},{-127,-110,81},
-{-105,28,100},{-103,20,99},{-84,55,97},{-92,54,99},
-{-73,51,99},{-55,45,89},{-52,37,88},{-53,25,87},
-{-66,13,92},{-79,8,95},{-98,14,100},{-104,38,100},
-{-100,48,100},{-97,46,97},{-102,38,97},{-96,16,97},
-{-79,11,93},{-68,15,90},{-57,27,86},{-56,36,86},
-{-59,43,87},{-74,50,96},{-91,51,98},{-84,52,96},
-{-101,22,96},{-102,29,96},{-113,59,78},{-102,85,79},
-{-84,88,76},{-65,71,71},{-40,58,63},{-25,52,59},
-{-28,21,48},{-50,0,53},{-71,-12,60},{-127,115,37},
-{-127,126,-10},{-127,-25,-86},{-127,-59,24},{-127,-125,59},
-{-127,-103,44},{-127,-73,41},{-127,-62,36},{-18,30,7},
-{-17,41,-6},{-28,34,-56},{-68,56,-90},{-33,-6,9},
-{-51,-16,-21},{-45,-1,-55},{-84,7,-85},{-97,-45,52},
-{-104,-53,33},{-90,-91,49},{-95,-64,50},{-85,-117,51},
-{-109,-97,47},{-111,-69,46},{-106,-121,56},{-99,-36,55},
-{-100,-29,60},{-101,-22,64},{-100,-50,21},{-89,-40,-34},
-{-83,-19,-69},{-69,111,-49},{-69,119,-9},{-69,109,30},
-{-68,67,55},{-34,52,43},{-46,58,36},{-45,90,7},
-{-25,72,16},{-25,79,-15},{-45,96,-25},{-45,87,-57},
-{-25,69,-46},{-48,42,-75},{-65,3,-70},{-22,42,-26},
-{-75,-22,19},{-72,-25,-27},{-13,52,-30},{-28,-18,-16},
-{6,-13,-42},{37,7,-55},{46,41,-54},{31,65,-54},
-{4,61,-40},{3,53,-37},{25,56,-50},{35,37,-52},
-{28,10,-52},{5,-5,-39},{-21,-9,-17},{-9,46,-28},
-{-6,39,-37},{-14,-3,-27},{6,0,-47},{25,12,-57},
-{31,32,-57},{23,46,-56},{4,44,-46},{-19,37,-27},
-{-20,22,-35},{-30,12,-35},{-22,11,-35},{-19,2,-35},
-{-23,-2,-35},{-34,0,-9},{-35,-3,-22},{-35,5,-24},
-{-25,26,-27},{-13,31,-34},{-13,30,-41},{-23,-2,-41},
-{-18,2,-41},{-21,10,-41},{-29,12,-41},{-19,22,-41},
-{6,42,-53},{25,44,-62},{34,31,-63},{28,11,-62},
-{7,0,-54},{-14,-2,-34},{-5,37,-44},{-13,14,-42},
-{-7,8,-43},{1,16,-47},{-4,22,-45},{3,30,-48},
-{8,24,-49},{15,27,-50},{12,35,-50},{4,56,-62},
-{33,60,-70},{48,38,-64},{41,7,-68},{6,-11,-63},
-{-26,-16,-42},{-17,49,-49},
-};
-
-signed char monkeyf[250][4]= {
-{27,4,5,26}, {25,4,5,24}, {3,6,5,4}, {1,6,5,2}, {5,6,7,4}, 
-{3,6,7,2}, {5,8,7,6}, {3,8,7,4}, {7,8,9,6}, 
-{5,8,9,4}, {7,10,9,8}, {5,10,9,6}, {9,10,11,8}, 
-{7,10,11,6}, {9,12,11,10}, {7,12,11,8}, {11,6,13,12}, 
-{5,4,13,12}, {3,-2,13,12}, {-3,-4,13,12}, {-5,-10,13,12}, 
-{-11,-12,14,12}, {-13,-18,14,13}, {-19,4,5,13}, {10,12,4,4}, 
-{10,11,9,9}, {8,7,9,9}, {7,5,6,6}, {6,3,4,4}, 
-{5,1,2,2}, {4,-1,0,0}, {3,-3,-2,-2}, {22,67,68,23}, 
-{20,65,66,21}, {18,63,64,19}, {16,61,62,17}, {14,59,60,15}, 
-{12,19,48,57}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 
-{18,19,48,47}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 
-{18,19,48,47}, {18,-9,-8,47}, {18,27,45,46}, {26,55,43,44}, 
-{24,41,42,54}, {22,39,40,23}, {20,37,38,21}, {18,35,36,19}, 
-{16,33,34,17}, {14,31,32,15}, {12,39,30,13}, {11,48,45,38}, 
-{8,36,-19,9}, {8,-20,44,47}, {42,45,46,43}, {18,19,40,39}, 
-{16,17,38,37}, {14,15,36,35}, {32,44,43,33}, {12,33,32,42}, 
-{19,44,43,42}, {40,41,42,-27}, {8,9,39,-28}, {15,43,42,16}, 
-{13,43,42,14}, {11,43,42,12}, {9,-30,42,10}, {37,12,38,-32}, 
-{-33,37,45,46}, {-33,40,41,39}, {38,40,41,37}, {36,40,41,35}, 
-{34,40,41,33}, {36,39,38,37}, {35,40,39,38}, {1,2,14,21}, 
-{1,2,40,13}, {1,2,40,39}, {1,24,12,39}, {-34,36,38,11}, 
-{35,38,36,37}, {-37,8,35,37}, {-11,-12,-45,40}, {-11,-12,39,38}, 
-{-11,-12,37,36}, {-11,-12,35,34}, {33,34,40,41}, {33,34,38,39}, 
-{33,34,36,37}, {33,-52,34,35}, {33,37,36,34}, {33,35,34,34}, 
-{8,7,37,36}, {-32,7,35,46}, {-34,-33,45,46}, {4,-33,43,34}, 
-{-34,-33,41,42}, {-34,-33,39,40}, {-34,-33,37,38}, {-34,-33,35,36}, 
-{-34,-33,33,34}, {-34,-33,31,32}, {-34,-4,28,30}, {-5,-34,28,27}, 
-{-35,-44,36,27}, {26,35,36,45}, {24,25,44,45}, {25,23,44,42}, 
-{25,24,41,40}, {25,24,39,38}, {25,24,37,36}, {25,24,35,34}, 
-{25,24,33,32}, {25,24,31,30}, {15,24,29,38}, {25,24,27,26}, 
-{23,12,37,26}, {11,12,35,36}, {-86,-59,36,-80}, {-60,-61,36,35}, 
-{-62,-63,36,35}, {-64,-65,36,35}, {-66,-67,36,35}, {-68,-69,36,35}, 
-{-70,-71,36,35}, {-72,-73,36,35}, {-74,-75,36,35}, {42,43,53,58}, 
-{40,41,57,56}, {38,39,55,57}, {-81,-80,37,56}, {-83,-82,55,52}, 
-{-85,-84,51,49}, {-87,-86,48,49}, {47,50,51,48}, {46,48,51,49}, 
-{43,46,49,44}, {-92,-91,45,42}, {-23,49,50,-20}, {-94,40,48,-24}, 
-{-96,-22,48,49}, {-97,48,21,-90}, {-100,36,50,23}, {22,49,48,-100}, 
-{-101,47,46,22}, {21,45,35,25}, {33,34,44,41}, {13,14,28,24}, 
-{-107,26,30,-106}, {14,46,45,15}, {14,44,43,-110}, {-111,42,23,-110}, 
-{6,7,45,46}, {45,44,47,46}, {45,46,47,48}, {47,46,49,48}, 
-{17,49,47,48}, {17,36,46,48}, {35,36,44,45}, {35,36,40,43}, 
-{35,36,38,39}, {-4,-3,37,35}, {-123,34,33,1}, {-9,-8,-7,-6}, 
-{-10,-7,32,-125}, {-127,-11,-126,-126}, {-7,-6,5,31}, {4,5,33,30}, 
-{4,39,33,32}, {4,35,32,38}, {20,21,39,38}, {4,37,38,5}, 
-{-11,-10,36,3}, {-11,15,14,35}, {13,16,34,34}, {-13,14,13,13}, 
-{-3,1,30,29}, {-3,28,29,1}, {-2,31,28,-1}, {12,13,27,30}, 
-{-2,26,12,12}, {35,29,42,36}, {34,35,36,33}, {32,35,36,31}, 
-{30,35,36,29}, {28,35,36,27}, {26,35,36,25}, {34,39,38,35}, 
-{32,39,38,33}, {30,39,38,31}, {28,39,38,29}, {26,39,38,27}, 
-{25,31,32,38}, {-18,-17,45,44}, {-18,17,28,44}, {-24,-20,42,-23}, 
-{11,35,27,14}, {25,28,39,41}, {37,41,40,38}, {34,40,36,35}, 
-{32,40,39,33}, {30,39,31,40}, {21,29,39,22}, {-31,37,28,4}, 
-{-32,33,35,36}, {32,33,34,34}, {18,35,36,48}, {34,25,40,35}, 
-{24,25,38,39}, {24,25,36,37}, {24,25,34,35}, {24,25,32,33}, 
-{24,13,41,31}, {17,11,41,35}, {15,16,34,35}, {13,14,34,35}, 
-{11,12,34,35}, {9,10,34,35}, {7,8,34,35}, {26,25,37,36}, 
-{35,36,37,38}, {37,36,39,38}, {37,38,39,40}, {25,31,36,39}, 
-{18,34,35,30}, {17,22,30,33}, {19,29,21,20}, {16,26,29,17}, 
-{24,29,28,25}, {22,31,28,23}, {20,31,30,21}, {18,31,30,19}, 
-{16,30,17,17}, {-21,-22,35,34}, {-21,-22,33,32}, {-21,-22,31,30}, 
-{-21,-22,29,28}, {-21,-22,27,26}, {-28,-22,25,31}, {24,28,29,30}, 
-{23,24,26,27}, {23,24,25,25}, {-69,-35,-32,27}, {-70,26,25,-66}, 
-{-68,-67,24,-33}, 
-};
-       // ------------------------------- end copied code
-
-
-#define PRIM_PLANE             0
-#define PRIM_CUBE              1
-#define PRIM_CIRCLE            4
-#define PRIM_CYLINDER  5
-#define PRIM_CONE              7
-#define PRIM_GRID              10
-#define PRIM_UVSPHERE  11
-#define PRIM_ICOSPHERE         12
-#define PRIM_MONKEY            13
-
-static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int seg,
-               int subdiv, float dia, float depth, int ext, int fill)
-{
-       /*
-        * type - for the type of shape
-        * dia - the radius for cone,sphere cylinder etc.
-        * depth - 
-        * ext - extrude
-        * fill - end capping, and option to fill in circle
-        * cent[3] - center of the data. 
-        * */
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       EditVert *eve, *v1=NULL, *v2, *v3, *v4=NULL, *vtop, *vdown;
-       float phi, phid, vec[3];
-       float q[4], cmat[3][3], nor[3]= {0.0, 0.0, 0.0};
-       short a, b;
-       
-       EM_clear_flag_all(em, SELECT);
-
-       phid= 2.0f*(float)M_PI/tot;
-       phi= .25f*(float)M_PI;
-
-       switch(type) {
-       case PRIM_GRID: /*  grid */
-               /* clear flags */
-               eve= em->verts.first;
-               while(eve) {
-                       eve->f= 0;
-                       eve= eve->next;
-               }
-               /* one segment first: the X axis */
-               phi= 1.0; 
-               phid= 2.0/((float)tot-1);
-               for(a=0;a<tot;a++) {
-                       vec[0]= dia*phi;
-                       vec[1]= - dia;
-                       vec[2]= 0.0f;
-                       mul_m4_v3(mat,vec);
-                       eve= addvertlist(em, vec, NULL);
-                       eve->f= 1+2+4;
-                       if (a) {
-                               addedgelist(em, eve->prev, eve, NULL);
-                       }
-                       phi-=phid;
-               }
-               /* extrude and translate */
-               vec[0]= vec[2]= 0.0;
-               vec[1]= dia*phid;
-               mul_mat3_m4_v3(mat, vec);
-               
-               for(a=0;a<seg-1;a++) {
-                       extrudeflag_vert(obedit, em, 2, nor, 0);        // nor unused
-                       translateflag(em, 2, vec);
-               }
-               break;
-       case PRIM_UVSPHERE: /*  UVsphere */
-               
-               /* clear all flags */
-               eve= em->verts.first;
-               while(eve) {
-                       eve->f= 0;
-                       eve= eve->next;
-               }
-               
-               /* one segment first */
-               phi= 0; 
-               phid/=2;
-               for(a=0; a<=tot; a++) {
-                       vec[0]= dia*sin(phi);
-                       vec[1]= 0.0;
-                       vec[2]= dia*cos(phi);
-                       eve= addvertlist(em, vec, NULL);
-                       eve->f= 1+2+4;
-                       if(a==0) v1= eve;
-                       else addedgelist(em, eve->prev, eve, NULL);
-                       phi+= phid;
-               }
-               
-               /* extrude and rotate */
-               phi= M_PI/seg;
-               q[0]= cos(phi);
-               q[3]= sin(phi);
-               q[1]=q[2]= 0;
-               quat_to_mat3( cmat,q);
-               
-               for(a=0; a<seg; a++) {
-                       extrudeflag_vert(obedit, em, 2, nor, 0); // nor unused
-                       rotateflag(em, 2, v1->co, cmat);
-               }
-
-               removedoublesflag(em, 4, 0, 0.0001);
-
-               /* and now do imat */
-               eve= em->verts.first;
-               while(eve) {
-                       if(eve->f & SELECT) {
-                               mul_m4_v3(mat,eve->co);
-                       }
-                       eve= eve->next;
-               }
-               break;
-       case PRIM_ICOSPHERE: /* Icosphere */
-               {
-                       EditVert *eva[12];
-                       EditEdge *eed;
-                       
-                       /* clear all flags */
-                       eve= em->verts.first;
-                       while(eve) {
-                               eve->f= 0;
-                               eve= eve->next;
-                       }
-                       dia/=200;
-                       for(a=0;a<12;a++) {
-                               vec[0]= dia*icovert[a][0];
-                               vec[1]= dia*icovert[a][1];
-                               vec[2]= dia*icovert[a][2];
-                               eva[a]= addvertlist(em, vec, NULL);
-                               eva[a]->f= 1+2;
-                       }
-                       for(a=0;a<20;a++) {
- &nbs