def test_from_polyface_type_error(msp): polyline = msp.add_polyline3d([(0, 0, 0), (1, 0, 0)]) with pytest.raises(TypeError): MeshBuilder.from_polyface(polyline) line = msp.add_line(start=(0, 0, 0), end=(1, 0, 0)) with pytest.raises(TypeError): MeshBuilder.from_polyface(line)
def cubes(self) -> Iterable[MeshBuilder]: """ Generates all cubes of the menger sponge as individual MeshBuilder() objects. Yields: MeshBuilder() """ faces = self.faces() for vertices in self: mesh = MeshBuilder() mesh.add_mesh(vertices=vertices, faces=faces) yield mesh
def pyramids(self) -> Iterable[MeshBuilder]: """ Generates all pyramids of the sierpinsky pyramid as individual MeshBuilder() objects. Yields: MeshBuilder() """ faces = self.faces() for vertices in self: mesh = MeshBuilder() mesh.add_mesh(vertices=vertices, faces=faces) yield mesh
def cube(center: bool = True, matrix: Matrix44 = None) -> MeshBuilder: """ Create a `cube <https://en.wikipedia.org/wiki/Cube>`_ as :class:`~ezdxf.render.MeshBuilder` object. Args: matrix: transformation matrix as :class:`~ezdxf.math.Matrix44` object center: 'mass' center of cube, ``(0, 0, 0)`` if ``True``, else first corner at ``(0, 0, 0)`` """ mesh = MeshBuilder() vertices = _cube0_vertices if center else _cube_vertices vectices = vertices if matrix is None else matrix.transform_vectors( vertices) mesh.add_mesh(vertices=vectices, faces=cube_faces) return mesh
def test_from_polymesh(msp): polymesh = msp.add_polymesh(size=(4, 4)) b = MeshBuilder.from_polyface(polymesh) n = polymesh.dxf.n_count m = polymesh.dxf.m_count nfaces = (n - 1) * (m - 1) assert len(b.vertices) == nfaces * 4 # unoptimized mesh builder assert len(b.faces) == nfaces
def cube(center: bool = True, matrix: Matrix44 = None) -> MeshBuilder: """ Create a cube as MeshBuilder() object. Args: matrix: transformation matrix center: 'mass' center of cube in (0, 0, 0) if True, else first corner at (0, 0, 0) Returns: MeshBuilder() """ mesh = MeshBuilder() vertices = _cube0_vertices if center else _cube_vertices vectices = vertices if matrix is None else matrix.transform_vectors( vertices) mesh.add_mesh(vertices=vectices, faces=cube_faces) return mesh
def test_has_none_planar_faces(): mesh = MeshBuilder() mesh.add_face(REGULAR_FACE) assert mesh.has_none_planar_faces() is False mesh.add_face(IRREGULAR_FACE) assert mesh.has_none_planar_faces() is True
def test_from_cube_polyface(cube_polyface): b = MeshBuilder.from_polyface(cube_polyface) assert len(b.vertices) == 24 # unoptimized mesh builder assert len(b.faces) == 6
def test_from_empty_polyface(msp): empty_polyface = msp.add_polyface() b = MeshBuilder.from_polyface(empty_polyface) assert len(b.vertices) == 0 assert len(b.faces) == 0