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 __init__(self, mesh: MeshBuilder = None, meshid: int = 0): if mesh is None: self.polygons = [] # type: List[Polygon] else: self.polygons = [ Polygon(face, meshid) for face in mesh.faces_as_vertices() ]
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 _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 _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 draw_polyline_entity(self, entity: DXFGraphic): dxftype = entity.dxftype() if dxftype == 'POLYLINE': e = cast(Polyface, entity) if e.is_polygon_mesh or e.is_poly_face_mesh: self.draw_mesh_builder_entity( MeshBuilder.from_polyface(e), self._resolve_properties(entity), ) return entity = cast(Union[LWPolyline, Polyline], entity) if not entity.has_arc: properties = self._resolve_properties(entity) if dxftype == 'LWPOLYLINE': self.out.draw_line_string(Vector.generate( entity.vertices_in_wcs()), close=entity.closed, properties=properties) else: # POLYLINE if entity.is_2d_polyline: ocs = entity.ocs() elevation = Vector(entity.dxf.elevation).z vertices = ocs.points_to_wcs( Vector(p[0], p[1], elevation) for p in entity.points()) else: vertices = Vector.generate(entity.points()) self.out.draw_line_string(vertices, close=entity.is_closed, properties=properties) return self.parent_stack.append(entity) self.out.set_current_entity(entity, tuple(self.parent_stack)) # todo: end points of virtual entities are not in correct order # can't use self.out.start_path() for child in entity.virtual_entities(): # all child entities have the same properties as the parent, # no visibility check required: self.draw_entity(child) # self.out.end_path() self.parent_stack.pop() self.out.set_current_entity(None)
def draw_polyline_entity(self, entity: DXFGraphic, properties: Properties) -> None: dxftype = entity.dxftype() if dxftype == 'POLYLINE': e = cast(Polyface, entity) if e.is_polygon_mesh or e.is_poly_face_mesh: # draw 3D mesh or poly-face entity self.draw_mesh_builder_entity( MeshBuilder.from_polyface(e), properties, ) return entity = cast(Union[LWPolyline, Polyline], entity) is_lwpolyline = dxftype == 'LWPOLYLINE' if entity.has_width: # draw banded 2D polyline elevation = 0.0 ocs = entity.ocs() transform = ocs.transform if transform: if is_lwpolyline: # stored as float elevation = entity.dxf.elevation else: # stored as vector (0, 0, elevation) elevation = Vec3(entity.dxf.elevation).z trace = TraceBuilder.from_polyline( entity, segments=self.circle_approximation_count // 2 ) for polygon in trace.polygons(): # polygon is a sequence of Vec2() if transform: points = ocs.points_to_wcs( Vec3(v.x, v.y, elevation) for v in polygon ) else: points = Vec3.generate(polygon) # Set default SOLID filling for LWPOLYLINE properties.filling = Filling() self.out.draw_filled_polygon(points, properties) return path = Path.from_lwpolyline(entity) \ if is_lwpolyline else Path.from_polyline(entity) self.out.draw_path(path, properties)
def draw_mesh_builder_entity(self, builder: MeshBuilder, properties: Properties) -> None: for face in builder.faces_as_vertices(): self.out.draw_path(Path.from_vertices(face, close=True), properties=properties)
def draw_mesh_entity(self, entity: DXFGraphic, properties: Properties) -> None: builder = MeshBuilder.from_mesh(entity) self.draw_mesh_builder_entity(builder, properties)
def _convert_entity(self): self._mesh = MeshBuilder.from_mesh(self.entity)
def draw_mesh_builder_entity(self, builder: MeshBuilder, properties: Properties) -> None: for face in builder.faces_as_vertices(): self.out.draw_line_string(face, close=True, properties=properties)
def draw_mesh_entity(self, entity: DXFGraphic) -> None: properties = self._resolve_properties(entity) builder = MeshBuilder.from_mesh(entity) self.draw_mesh_builder_entity(builder, properties)
(1, 0, 1), (1, 1, 1), (0, 1, 1), ] # 6 cube faces cube_faces = [ [0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [3, 7, 6, 2], [0, 4, 7, 3], ] doc = ezdxf.new("R2018") msp = doc.modelspace() mesh = msp.add_mesh(dxfattribs=GfxAttribs(color=6)) with mesh.edit_data() as mesh_data: mesh_data.vertices = cube_vertices mesh_data.faces = cube_faces # Add the same mesh as PolyFaceMesh: mesh_builder = MeshBuilder.from_mesh(mesh) mesh_builder.render_polyface( msp, dxfattribs=GfxAttribs(color=6), matrix=Matrix44.translate(5, 0, 0), ) doc.saveas(DIR / "cube_mesh_1.dxf")