def _convert_entity(self): e: 'LWPolyline' = cast('LWPolyline', self.entity) if e.has_width: # use a mesh representation: tb = TraceBuilder.from_polyline(e) mb = MeshVertexMerger() # merges coincident vertices for face in tb.faces(): mb.add_face(Vec3.generate(face)) self._mesh = MeshBuilder.from_builder(mb) else: # use a path representation to support bulges! self._path = make_path(e)
def mesh(self, meshid: int = 0) -> MeshTransformer: """ Returns a :class:`ezdxf.render.MeshTransformer` object. Args: meshid: individual mesh ID, ``0`` is default """ mesh = MeshVertexMerger() for face in self.polygons: if meshid == face.meshid: mesh.add_face(face.vertices) return MeshTransformer.from_builder(mesh)
def _convert_entity(self): e: "LWPolyline" = cast("LWPolyline", self.entity) if e.has_width: # use a mesh representation: # TraceBuilder operates in OCS! ocs = e.ocs() elevation = e.dxf.elevation tb = TraceBuilder.from_polyline(e) mb = MeshVertexMerger() # merges coincident vertices for face in tb.faces_wcs(ocs, elevation): mb.add_face(face) self._mesh = MeshBuilder.from_builder(mb) else: # use a path representation to support bulges! self._path = make_path(e)
def _convert_entity(self): e: 'Polyline' = cast('Polyline', self.entity) if e.is_2d_polyline or e.is_3d_polyline: self._path = make_path(e) else: m = MeshVertexMerger.from_polyface(e) self._mesh = MeshBuilder.from_builder(m)
def _convert_entity(self): e: "Polyline" = cast("Polyline", self.entity) if e.is_2d_polyline and e.has_width: # TraceBuilder operates in OCS! ocs = e.ocs() elevation = e.dxf.elevation.z tb = TraceBuilder.from_polyline(e) mb = MeshVertexMerger() # merges coincident vertices for face in tb.faces_wcs(ocs, elevation): mb.add_face(face) self._mesh = MeshBuilder.from_builder(mb) elif e.is_2d_polyline or e.is_3d_polyline: self._path = make_path(e) else: m = MeshVertexMerger.from_polyface(e) self._mesh = MeshBuilder.from_builder(m)
def save_as_r2010_mesh(source: str, target: str): count = 0 doc = ezdxf.new('R2010') msp = doc.modelspace() converting_time = 0. t0 = perf_counter() for e in entities2(source): if e.dxftype() == TYPE: count += 1 if TYPE == 'POLYLINE': if PRINT_STATUS: print(f'Found {count}. POLYMESH') e = cast('Polyline', e) t1 = perf_counter() mesh = MeshVertexMerger.from_polyface(e) # render as MESH entity into modelspace of doc mesh.render(msp, dxfattribs={'color': e.dxf.color}) converting_time += perf_counter() - t1 else: if PRINT_STATUS and not (count % 10000): print(f'Found {count}. 3DFACE') e = cast('Face3d', e) t1 = perf_counter() msp.add_3dface(list(e), dxfattribs={'color': e.dxf.color}) converting_time += perf_counter() - t1 loading_time = perf_counter() - t0 - converting_time t0 = perf_counter() doc.saveas(target) t1 = perf_counter() print(f'Loading time from disk: {loading_time:.2f}s') print(f'Converting time : {converting_time:.2f}s') print(f'Time to save R2010: {t1 - t0:.2f}s')
def save_as(name): filename = SRCDIR / name print(f"opening DXF file: {filename}") start_time = time.time() doc = ezdxf.readfile(filename) msp = doc.modelspace() end_time = time.time() print(f"time for reading: {end_time - start_time:.1f} seconds") print(f"DXF version: {doc.dxfversion}") print(f"Database contains {len(doc.entitydb)} entities.") polyfaces = ( polyline for polyline in msp.query("POLYLINE") if polyline.is_poly_face_mesh ) # create a new documents doc1 = ezdxf.new() msp1 = doc1.modelspace() doc2 = ezdxf.new() msp2 = doc2.modelspace() for polyface in polyfaces: b = MeshVertexMerger.from_polyface(polyface) b.render_mesh( msp1, dxfattribs={ "layer": polyface.dxf.layer, "color": polyface.dxf.color, }, ) b.render_polyface( msp2, dxfattribs={ "layer": polyface.dxf.layer, "color": polyface.dxf.color, }, ) new_filename = OUTDIR / ("mesh_" + name) print(f"saving as mesh DXF file: {new_filename}") start_time = time.time() doc1.saveas(new_filename) end_time = time.time() print(f"time for saving: {end_time - start_time:.1f} seconds") new_filename = OUTDIR / ("recreated_polyface_" + name) print(f"saving as polyface DXF file: {new_filename}") start_time = time.time() doc2.saveas(new_filename) end_time = time.time() print(f"time for saving: {end_time - start_time:.1f} seconds")