A simple script to create a "vectorized style" mesh from a flatten mesh:

The principle is in fact simple:
When flattened each edge correspond:
- either to 2 faces which have the same normal
- or to 2 faces with opposite normals
So the script keeps only edges of the second case.
... but I'm not sure this corresponds to what is wanted in the question, specially after the last edits of it... ?
import bpy
import bmesh
#Create a new mesh from a geometry
def CreateMesh( scene, name, location, vertices, edges, polygons ):
mesh = bpy.data.meshes.new( name )
obj = bpy.data.objects.new( name, mesh )
obj.location = location
scene.objects.link( obj )
scene.objects.active = obj
obj.select = True
mesh.from_pydata( vertices, edges, polygons )
mesh.update()
return obj
#Determinate edges corresponding to opposite faces and make mesh verts/edges from that
def FlatGeometry( obj ):
bm = bmesh.new()
bm.from_mesh( obj.data )
bm.edges.ensure_lookup_table()
bm.verts.ensure_lookup_table()
epsilon = 0.000001
vertices = []
edges = []
vertexCount = 0
mapping = dict()
try:
#Iterate on edges and keep only the one corresponding to opposite faces (ie. f1.normal.dot( f2.normal ) < epsilon
for e in iter( e for e in bm.edges if e.link_faces and (len(e.link_faces) == 1 or e.link_faces[0].normal.dot( e.link_faces[1].normal ) < epsilon ) ):
#First vertex of the edge
v = e.verts[0]
if v.index not in mapping: #Not stored
mapping[v.index] = vertexCount #Store it
vertices.append( v.co.copy() ) #And its coordinates
vertexCount += 1 #Next index
v1 = mapping[v.index] #Get the vertex index
v = e.verts[1]
#Second vertex for the edge: same principle
if v.index not in mapping:
mapping[v.index] = vertexCount
vertices.append( v.co.copy() )
vertexCount += 1
v2 = mapping[v.index]
#Create the edge
edges.append( (v1, v2) )
return vertices, edges
finally:
del bm
print( '------------' )
obj = bpy.context.object
vertices, edges = FlatGeometry( obj )
CreateMesh( bpy.context.scene, "test", (0,0,0), vertices, edges, [] )
Edit: bug corrected
Changed
vertices.append( v.co )
by
vertices.append( v.co.copy() )
... vectors in Python are not structs