MeshBuilder causes self intersections #611
-
I'm trying to convert roof geometries, based on a 3d city model, into DXF. These roofs usually consist of >4 3d-points and should be exported as "areas". Thus they are converted using the MeshBuilder. During conversion, the MeshBuilder seems to call subdivide_ngons, which adds a point. Depending on the geometry, this leads to self intersections. Is there a better way to solve this? import ezdxf
#create a new document
doc = ezdxf.new(dxfversion="R2013")
msp = doc.modelspace()
layout = doc.layouts.get("Model")
# create a easy 3d shape
# z = y for planarity
coords = [[0,0,0], [3,0,0], [3,1,1], [8,1,1], [8,0,0], [10,0,0], [10,10,10], [0,10,10], [0,0,0]]
# add coords as mesh
mb = ezdxf.render.MeshBuilder()
mb.add_face(coords)
# render calls subdivide_ngons,
# which adds a point at 4.67, 2.44
# and causes some self-intersections
mb.render_3dfaces(layout)
# how it should look
# but only as line
pl = msp.add_polyline3d(coords)
pl.rgb=[255,0,0]
doc.saveas("c:/temp/example.dxf") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Ezdxf is not a sophisticated 3d library so try to keep things simple. In this case you add an n-gon to a |
Beta Was this translation helpful? Give feedback.
Ezdxf is not a sophisticated 3d library so try to keep things simple. In this case you add an n-gon to a
MeshBuilder
which is basically ok because the main target entity ofMeshBuilder
is theMESH
entity, which support n-gons. The problem here is the rendering of the mesh as3DFACE
objects, which supports only triangles and quadrilaterals but not n-gons. The subdiv algorithm which divides n-gons into triagles is very simple and can not handle concave shapes as you see. The only solution is to subdivide the n-gons into convex shapes by yourself or using theMESH
entity. A third party library like CGAL may help to subdivide the polygon.