Shapes

Shape

Manifold3D generic shape class.

__add__

__add__(other: 'Shape') -> 'Shape'

Combine two shapes using union operation.

Parameters:

  • other (Shape): The other shape to combine with.

Returns:

  • self (Shape): The combined shape.

__and__

__and__(other: 'Shape') -> 'Shape'

Intersect this shape with another shape.

Parameters:

  • other (Shape): The shape to intersect with.

Returns:

  • self (Shape): The resulting shape after intersection.

__sub__

__sub__(other: 'Shape') -> 'Shape'

Subtract another shape from this shape.

Parameters:

  • other (Shape): The shape to subtract.

Returns:

  • self (Shape): The resulting shape after subtraction.

copy

copy(_internal: bool = False) -> 'Shape'

Create a copy of the shape.

Parameters:

  • _internal (bool): If True, copy internal properties like name, parent, and color. (internal use only)

Returns:

  • Shape: A new Shape instance with the same properties.

hull

hull(other: 'Shape') -> 'Shape'

Create a convex hull of this shape and another shape. This method combines the keepouts of both shapes and creates a bridge between their bounding boxes.

Parameters:

  • other (Shape): The other shape to combine with.

Returns:

  • self (Shape): The resulting shape after creating the hull.

mirror

mirror(axis: tuple[bool, bool, bool]) -> 'Shape'

Mirror the shape along the specified axes.

Parameters:

  • axis (tuple[bool, bool, bool]): A tuple indicating which axes to mirror (x, y, z).

Returns:

  • self (Shape): The mirrored shape.

resize

resize(size: tuple[int, int, int]) -> 'Shape'

Resize the shape to a given size in px/layer space.

Parameters:

  • size (tuple[int, int, int]): The new size in px/layer space.

Returns:

  • self (Shape): The resized shape.

rotate

rotate(rotation: tuple[float, float, float]) -> 'Shape'

Rotate the shape by a given rotation vector (in degrees).

Parameters:

  • rotation (tuple[float, float, float]): The rotation vector in degrees.

Returns:

  • self (Shape): The rotated shape.

translate

translate(translation: tuple[int, int, int]) -> 'Shape'

Translate the shape by a given translation vector.

Parameters:

  • translation (tuple[int, int, int]): The translation vector.

Returns:

  • self (Shape): The translated shape.

Cube

Bases: Shape

Manifold3D cube.

__init__

__init__(
    size: tuple[int, int, int],
    center: bool = False,
    quiet: bool = False,
    _no_validation: bool = False,
) -> None

Create a cube.

Parameters:

  • size (tuple[int, int, int]): Size of the cube in px/layer space.
  • center (bool): Whether to center the cube at the origin.
  • quiet (bool): If True, suppresses informational output.
  • _no_validation (bool): If True, skip validation checks for odd dimensions (internal use).

Cylinder

Bases: Shape

Manifold3D cylinder.

__init__

__init__(
    height: int,
    radius: float = None,
    bottom_r: float = None,
    top_r: float = None,
    center_xy: bool = True,
    center_z: bool = False,
    fn: int = 0,
    quiet: bool = False,
) -> None

Create a cylinder.

Parameters:

  • height (int): Height of the cylinder in layer space.
  • radius (float): Radius of the cylinder in px space.
  • bottom_r (float): Bottom radius of the cylinder in px space.
  • top_r (float): Top radius of the cylinder in px space.
  • center_xy (bool): Whether to center the cylinder in XY plane.
  • center_z (bool): Whether to center the cylinder in Z plane.
  • fn (int): Number of facets for the circular segments.
  • quiet (bool): If True, suppresses informational output.

Raises:

  • ValueError: Radius inputs are not multiples of 0.5 or are inconsistent.

Sphere

Bases: Shape

Manifold3D ellipsoid.

__init__

__init__(
    size: tuple[int, int, int],
    center: bool = True,
    fn: int = 0,
    quiet: bool = False,
    _no_validation: bool = False,
) -> None

Create a sphere.

Parameters:

  • size (tuple[int, int, int]): Size of the sphere in px/layer space.
  • center (bool): Whether to center the sphere at the origin.
  • fn (int): Number of facets for the circular segments.
  • quiet (bool): If True, suppresses informational output.
  • _no_validation (bool): If True, skip validation checks for odd dimensions (internal use).

RoundedCube

Bases: Shape

Manifold3D rounded cube.

__init__

__init__(
    size: tuple[int, int, int],
    radius: tuple[float, float, float],
    center: bool = False,
    fn: int = 0,
    quiet: bool = False,
    _no_validation: bool = False,
) -> None

Create a rounded cube.

Parameters:

  • size (tuple[int, int, int]): Size of the rounded cube in px/layer space.
  • radius (tuple[float, float, float]): Radius of the rounded corners in px/layer space.
  • center (bool): Whether to center the rounded cube at the origin.
  • fn (int): Number of facets for the circular segments.
  • quiet (bool): If True, suppresses informational output.
  • _no_validation (bool): If True, skip validation checks for odd dimensions (internal use).

TextExtrusion

Bases: Shape

Manifold3D text extrusion shapes.

__init__

__init__(
    text: str,
    height: int = 1,
    font: str = "OpenSans-Medium",
    font_size: int = 10,
    quiet: bool = False,
) -> None

Create a text extrusion.

Parameters:

  • text (str): The text to extrude.
  • height (int): Height of the extrusion in layer space.
  • font (str): Embedded font name or a path to a .ttf/.otf font file. Available embedded fonts: OpenSans-Medium, Inconsolata-Medium.
  • font_size (int): Font size in px.
  • quiet (bool): If True, suppresses informational output.

ImportModel

Bases: Shape

Load a 3D model file and convert it to a Manifold3D object.

It checks for common mesh issues such as watertightness, winding consistency, and emptiness.

If the mesh cannot be repaired or is still not watertight, it raises an error.

__init__

__init__(filename: str, quiet: bool = False) -> None

Create an imported model.

Parameters:

  • filename (str): Path to the 3D model file.
  • quiet (bool): If True, suppresses informational output.

Raises:

  • ValueError: Mesh cannot be repaired or remains non-watertight.

TPMS

Bases: Shape

Manifold3D triply periodic minimal surface (TPMS) shapes.

This class generates a TPMS shape using a level set method.

__init__

__init__(
    size: tuple[int, int, int],
    cells: tuple[int, int, int] = (1, 1, 1),
    func: Callable[[int, int, int], int] = diamond,
    fill: float = 0.0,
    refinement: int = 10,
    quiet: bool = False,
) -> None

Create a TPMS shape.

Parameters:

  • size (tuple[int, int, int]): Size of the TPMS unit cell in px/layer space.
  • cells (tuple[int, int, int]): Number of unit cells in each dimension.
  • func (Callable[[float, float, float], float]): Function defining the TPMS shape. Can use gyroid, diamond, schwarz_p, fischer_koch_s, double_diamond, double_gyroid, or a custom function.
  • fill (float): Level set value for the TPMS shape ranges from -1 to 1 (isosurface at 0).
  • refinement (int): Number of subdivisions for the level set grid.
  • quiet (bool): If True, suppresses informational output.

diamond

diamond(x: float, y: float, z: float) -> float

Diamond TPMS function (uses @njit decorator for performance).

Parameters:

  • x (float): X coordinate.
  • y (float): Y coordinate.
  • z (float): Z coordinate.

Returns:

  • float: Level set value.

double_diamond

double_diamond(x: float, y: float, z: float) -> float

Double Diamond TPMS function (uses @njit decorator for performance).

Parameters:

  • x (float): X coordinate.
  • y (float): Y coordinate.
  • z (float): Z coordinate.

Returns:

  • float: Level set value.

double_gyroid

double_gyroid(x: float, y: float, z: float) -> float

Double Gyroid TPMS function (uses @njit decorator for performance).

Parameters:

  • x (float): X coordinate.
  • y (float): Y coordinate.
  • z (float): Z coordinate.

Returns:

  • float: Level set value.

fischer_koch_s

fischer_koch_s(x: float, y: float, z: float) -> float

Fischer-Koch S TPMS function (uses @njit decorator for performance).

Parameters:

  • x (float): X coordinate.
  • y (float): Y coordinate.
  • z (float): Z coordinate.

Returns:

  • float: Level set value.

gyroid

gyroid(x: float, y: float, z: float) -> float

Gyroid TPMS function (uses @njit decorator for performance).

Parameters:

  • x (float): X coordinate.
  • y (float): Y coordinate.
  • z (float): Z coordinate.

Returns:

  • float: Level set value.

schwarz_p

schwarz_p(x: float, y: float, z: float) -> float

Schwarz P TPMS function (uses @njit decorator for performance).

Parameters:

  • x (float): X coordinate.
  • y (float): Y coordinate.
  • z (float): Z coordinate.

Returns:

  • float: Level set value.