MeshBuilder¶
The MeshBuilder
is a helper class to create Mesh
entities. Stores a list of vertices and a faces list where each face is a list
of indices into the vertices list.
The MeshBuilder.render()
method, renders the mesh into a
Mesh
entity. The Mesh
entity
supports ngons in AutoCAD, ngons are polygons with more than 4 vertices.
The basic MeshBuilder
class does not support transformations.

class
ezdxf.render.
MeshBuilder
¶ 

faces
¶ List of faces as list of vertex indices, where a vertex index is the index of the vertex in the
vertices
list. A face requires at least three vertices,Mesh
supports ngons, so the count of vertices is not limited.

copy
()¶ Returns a copy of mesh.

faces_as_vertices
() → Iterable[List[Vec3]]¶ Iterate over all mesh faces as list of vertices.

add_vertices
(vertices: Iterable[Vertex]) → Sequence[int]¶ Add new vertices to the mesh, each vertex is a
(x, y, z)
tuple or aVec3
object, returns the indices of the vertices added to thevertices
list.e.g. adding 4 vertices to an empty mesh, returns the indices
(0, 1, 2, 3)
, adding additional 4 vertices returns the indices(4, 5, 6, 7)
.Parameters: vertices – list of vertices, vertex as (x, y, z)
tuple orVec3
objectsReturns: indices of the vertices added to the vertices
listReturn type: tuple

add_face
(vertices: Iterable[Vertex]) → None¶ Add a face as vertices list to the mesh. A face requires at least 3 vertices, each vertex is a
(x, y, z)
tuple orVec3
object. The new vertex indices are stored as face in thefaces
list.Parameters: vertices – list of at least 3 vertices [(x1, y1, z1), (x2, y2, z2), (x3, y3, y3), ...]

add_mesh
(vertices=None, faces=None, edges=None, mesh=None) → None¶ Add another mesh to this mesh.
A mesh can be a
MeshBuilder
,MeshVertexMerger
orMesh
object or requires the attributesvertices
andfaces
.Parameters:  vertices – list of vertices, a vertex is a
(x, y, z)
tuple orVec3
object  faces – list of faces, a face is a list of vertex indices
 mesh – another mesh entity
 vertices – list of vertices, a vertex is a

has_none_planar_faces
() → bool¶ Returns
True
if any face is none planar.

render_mesh
(layout: BaseLayout, dxfattribs: dict = None, matrix: Matrix44 = None, ucs: UCS = None)¶ Render mesh as
Mesh
entity into layout.Parameters:  layout –
BaseLayout
object  dxfattribs – dict of DXF attributes e.g.
{'layer': 'mesh', 'color': 7}
 matrix – transformation matrix of type
Matrix44
 ucs – transform vertices by
UCS
to WCS
 layout –

render_polyface
(layout: BaseLayout, dxfattribs: dict = None, matrix: Matrix44 = None, ucs: UCS = None)¶ Render mesh as
Polyface
entity into layout.Parameters:  layout –
BaseLayout
object  dxfattribs – dict of DXF attributes e.g.
{'layer': 'mesh', 'color': 7}
 matrix – transformation matrix of type
Matrix44
 ucs – transform vertices by
UCS
to WCS
 layout –

render_3dfaces
(layout: BaseLayout, dxfattribs: dict = None, matrix: Matrix44 = None, ucs: UCS = None)¶ Render mesh as
Face3d
entities into layout.Parameters:  layout –
BaseLayout
object  dxfattribs – dict of DXF attributes e.g.
{'layer': 'mesh', 'color': 7}
 matrix – transformation matrix of type
Matrix44
 ucs – transform vertices by
UCS
to WCS
 layout –

render_normals
(layout: BaseLayout, length: float = 1, relative=True, dxfattribs: dict = None)¶ Render face normals as
Line
entities into layout, useful to check orientation of mesh faces.Parameters:  layout –
BaseLayout
object  length – visual length of normal, use length < 0 to point normals in opposite direction
 relative – scale length relative to face size if
True
 dxfattribs – dict of DXF attributes e.g.
{'layer': 'normals', 'color': 6}
 layout –

classmethod
from_mesh
(other: Union[MeshBuilder, Mesh]) → T¶ Create new mesh from other mesh as class method.
Parameters: other – mesh of type MeshBuilder
and inherited or DXFMesh
entity or any object providing attributesvertices
,edges
andfaces
.

classmethod
from_polyface
(other: Union[Polymesh, Polyface]) → T¶

classmethod
from_builder
(other: MeshBuilder)¶ Create new mesh from other mesh builder, faster than
from_mesh()
but supports onlyMeshBuilder
and inherited classes.

MeshTransformer¶
Same functionality as MeshBuilder
but supports inplace transformation.

class
ezdxf.render.
MeshTransformer
¶ Subclass of
MeshBuilder

subdivide
(level: int = 1, quads=True) → MeshTransformer¶ Returns a new
MeshTransformer
object with subdivided faces and edges.Parameters:  level – subdivide levels from 1 to max of 5
 quads – create quad faces if
True
else create triangles

transform
(matrix: Matrix44)¶ Transform mesh inplace by applying the transformation matrix.
Parameters: matrix – 4x4 transformation matrix as Matrix44
object

translate
(dx: float = 0, dy: float = 0, dz: float = 0)¶ Translate mesh inplace.
Parameters:  dx – translation in xaxis
 dy – translation in yaxis
 dz – translation in zaxis

scale
(sx: float = 1, sy: float = 1, sz: float = 1)¶ Scale mesh inplace.
Parameters:  sx – scale factor for xaxis
 sy – scale factor for yaxis
 sz – scale factor for zaxis

scale_uniform
(s: float)¶ Scale mesh uniform inplace.
Parameters: s – scale factor for x, y and zaxis

rotate_x
(angle: float)¶ Rotate mesh around xaxis about angle inplace.
Parameters: angle – rotation angle in radians

rotate_y
(angle: float)¶ Rotate mesh around yaxis about angle inplace.
Parameters: angle – rotation angle in radians

rotate_z
(angle: float)¶ Rotate mesh around zaxis about angle inplace.
Parameters: angle – rotation angle in radians

rotate_axis
(axis: Vertex, angle: float)¶ Rotate mesh around an arbitrary axis located in the origin (0, 0, 0) about angle.
Parameters:  axis – rotation axis as Vec3
 angle – rotation angle in radians

MeshVertexMerger¶
Same functionality as MeshBuilder
, but created meshes with unique
vertices and no doublets, but MeshVertexMerger
needs extra memory for
bookkeeping and also does not support transformations. Location of merged
vertices is the location of the first vertex with the same key.
This class is intended as intermediate object to create a compact meshes and
convert them to MeshTransformer
objects to apply transformations to the
mesh:
mesh = MeshVertexMerger()
# create your mesh
mesh.add_face(...)
# convert mesh to MeshTransformer object
return MeshTransformer.from_builder(mesh)

class
ezdxf.render.
MeshVertexMerger
(precision: int = 6)¶ Subclass of
MeshBuilder
Mesh with unique vertices and no doublets, but needs extra memory for bookkeeping.
MeshVertexMerger
creates a key for every vertex by rounding its components by the Pythonround()
function and a given precision value. Each vertex with the same key gets the same vertex index, which is the index of first vertex with this key, so all vertices with the same key will be located at the location of this first vertex. If you want an average location of and for all vertices with the same key look at theMeshAverageVertexMerger
class.Parameters: precision – floating point precision for vertex rounding
MeshAverageVertexMerger¶
This is an extended version of MeshVertexMerger
.
Location of merged vertices is the average location of all vertices with the
same key, this needs extra memory and runtime in comparison to
MeshVertexMerger
and this class also does not support
transformations.

class
ezdxf.render.
MeshAverageVertexMerger
(precision: int = 6)¶ Subclass of
MeshBuilder
Mesh with unique vertices and no doublets, but needs extra memory for bookkeeping and runtime for calculation of average vertex location.
MeshAverageVertexMerger
creates a key for every vertex by rounding its components by the Pythonround()
function and a given precision value. Each vertex with the same key gets the same vertex index, which is the index of first vertex with this key, the difference to theMeshVertexMerger
class is the calculation of the average location for all vertices with the same key, this needs extra memory to keep track of the count of vertices for each key and extra runtime for updating the vertex location each time a vertex with an existing key is added.Parameters: precision – floating point precision for vertex rounding