Skip to content

kumiki.csg.meshcsg

Flat import path

kumiki/__init__.py re-exports everything on this page via from kumiki import *, so every name below is also available directly as kumiki.TriangleSolid -- you do not need to import from the submodule path shown in the heading above.

kumiki.csg.meshcsg

Closed triangle solids imported from mesh files.

TriangleSolid dataclass

TriangleSolid(vertices: tuple[tuple[float, float, float], ...], faces: tuple[tuple[int, int, int], ...], transform: Transform = identity())

Bases: HasFeatures, CutCSG

Represent a closed mesh with vertices in transform's local space.

vertices instance-attribute

vertices: tuple[tuple[float, float, float], ...]

faces instance-attribute

faces: tuple[tuple[int, int, int], ...]

transform class-attribute instance-attribute

transform: Transform = field(default_factory=Transform.identity)

mesh cached property

mesh

__repr__

__repr__() -> str
Source code in kumiki/csg/meshcsg.py
def __repr__(self) -> str:
    return f"TriangleSolid({len(self.vertices)} vertices, {len(self.faces)} faces)"

carriers

carriers()
Source code in kumiki/csg/meshcsg.py
def carriers(self):
    return face_plane_carriers(self)

is_point_on_boundary

is_point_on_boundary(point: V3, eps: Optional[Numeric] = None) -> bool
Source code in kumiki/csg/meshcsg.py
def is_point_on_boundary(self, point: V3, eps: Optional[Numeric] = None) -> bool:
    return self._nearest(point, 1e-8 if eps is None else float(eps))[1] >= 0

contains_point

contains_point(point: V3, eps: Optional[Numeric] = None) -> bool
Source code in kumiki/csg/meshcsg.py
def contains_point(self, point: V3, eps: Optional[Numeric] = None) -> bool:
    if self.is_point_on_boundary(point, eps):
        return True
    # Sum the signed solid angles; closed outward meshes enclose 4*pi steradians.
    vectors = self.mesh.triangles - np.asarray(list(point), dtype=float)
    a, b, c = vectors[:, 0], vectors[:, 1], vectors[:, 2]
    la, lb, lc = (np.linalg.norm(v, axis=1) for v in (a, b, c))
    numerator = np.einsum('ij,ij->i', a, np.cross(b, c))
    denominator = la * lb * lc + np.einsum('ij,ij->i', a, b) * lc + np.einsum('ij,ij->i', b, c) * la + np.einsum('ij,ij->i', c, a) * lb
    return bool(abs(np.sum(2 * np.arctan2(numerator, denominator))) > 2 * np.pi)

get_outward_normal

get_outward_normal(point: V3, eps: Optional[Numeric] = None) -> Optional[V3]
Source code in kumiki/csg/meshcsg.py
def get_outward_normal(self, point: V3, eps: Optional[Numeric] = None) -> Optional[V3]:
    _, index = self._nearest(point, 1e-8 if eps is None else float(eps))
    return None if index < 0 else create_v3(*self.mesh.face_normals[index])

get_aabb

get_aabb() -> AxisAlignedBoundingBox
Source code in kumiki/csg/meshcsg.py
def get_aabb(self) -> AxisAlignedBoundingBox:
    low, high = self.mesh.bounds
    return AxisAlignedBoundingBox(*low, *high)