Repository navigation
Replies: 1 comment
|
Open3D cannot read DXF. # pip install ezdxf mapbox-earcut open3d
import ezdxf, numpy as np, open3d as o3d
from ezdxf import path
import mapbox_earcut as earcut
doc = ezdxf.readfile("part.dxf")
ent = doc.modelspace().query("LWPOLYLINE").first # or CIRCLE, SPLINE, POLYLINE...
# flattening() also handles arcs/bulges/splines (0.05 = max chord error in drawing units)
xy = np.array([(v.x, v.y) for v in path.make_path(ent).flattening(0.05)], dtype=np.float64)
if np.allclose(xy[0], xy[-1]):
xy = xy[:-1] # drop duplicated closing point
tris = earcut.triangulate_float64(xy, np.array([len(xy)], dtype=np.uint32)).reshape(-1, 3)
face = o3d.t.geometry.TriangleMesh()
face.vertex.positions = o3d.core.Tensor(np.c_[xy, np.zeros(len(xy))], o3d.core.float32)
face.triangle.indices = o3d.core.Tensor(tris, o3d.core.int32)
solid = face.extrude_linear([0, 0, 10]) # 10 drawing units along +Z
mesh = solid.to_legacy()
mesh.compute_vertex_normals()
o3d.io.write_triangle_mesh("part.stl", mesh)
o3d.visualization.draw_geometries([mesh])I tested this with a closed 5-point LWPOLYLINE (area 1000) extruded by 10. The result was a watertight mesh with volume exactly 10000. Notes:
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello,
Is it possible to import a dxf file for extruding it?
Thanks a lot.
All reactions