v0.7 of trueform gives NumPy arrays geometric meaning. Wrap a (3,) array and it's a Point. (2, 3) is a Segment. (N, 3) is N points. Eight primitives (Point, Line, Ray, Segment, Triangle, Polygon, Plane, AABB) and three forms (Mesh, EdgeMesh, PointCloud) backed by spatial and topological structures. Every query broadcasts over batches the way you'd expect, in parallel.
pip install trueform
import numpy as np
import trueform as tf
mesh = tf.Mesh(*tf.read_stl("dragon.stl"))
plane = tf.Plane(normal=np.float32([1, 2, 0]), origin=mesh.points.mean(axis=0))
scalars = tf.distance(tf.Point(mesh.points), plane)
Same function, different target. Swap the plane for a mesh, the tree builds on first query:
mesh_b = tf.Mesh(*tf.read_stl("other.stl"))
distances = tf.distance(tf.Point(mesh.points), mesh_b)
Two meshes, not touching. Find the closest pair of surface points and bring them together without collision:
tf.intersects(mesh, mesh_b)
(id_a, id_b), (dist2, pt_a, pt_b) = tf.neighbor_search(mesh, mesh_b)
direction = pt_a - pt_b
T = np.eye(4, dtype=np.float32)
T[:3, 3] = direction * (1 - 0.01 / np.sqrt(dist2))
mesh_b.transformation = T
tf.intersects(mesh, mesh_b)
Voxelize a mesh. Build a grid of bounding boxes, check which ones the mesh occupies:
lo, hi = mesh.points.min(axis=0), mesh.points.max(axis=0)
grid = np.mgrid[lo[0]:hi[0]:100j, lo[1]:hi[1]:100j, lo[2]:hi[2]:100j].reshape(3, -1).T.astype(np.float32)
step = ((hi - lo) / 100).astype(np.float32)
voxels = tf.AABB(min=grid, max=grid + step)
occupied = tf.intersects(mesh, voxels)
Depth map. Cast a grid of rays downward:
xy = np.mgrid[lo[0]:hi[0]:500j, lo[1]:hi[1]:500j].reshape(2, -1).T.astype(np.float32)
origins = np.column_stack([xy, np.full(250000, hi[2] + 0.1, dtype=np.float32)])
rays = tf.Ray(origin=origins, direction=np.tile([0, 0, -1], (250000, 1)).astype(np.float32))
face_ids, ts = tf.ray_cast(rays, mesh, config=(0.0, 10.0))
depth_map = ts.reshape(500, 500)
The scalar field from the first example feeds directly into cutting. Isobands slices along threshold values, returns per-face labels and intersection curves:
(cut_faces, cut_points), labels, (paths, curve_pts) = tf.isobands(
mesh, scalars, [0.0], return_curves=True
)
components, component_ids = tf.split_into_components(
tf.Mesh(cut_faces, cut_points), labels
)
bottom_faces, bottom_points = components[0]
top_faces, top_points = components[1]
cap_faces, cap_points = tf.triangulated((paths, curve_pts))
NumPy in, NumPy out. C++ backend, parallelized across cores.
Documentation · GitHub · Benchmarks