Skip to main content

Fast and exact mesh booleans, spatial queries, arrangements, registration, and remeshing on NumPy arrays. NumPy in, NumPy out.

Project description

trueform — NumPy for Geometry

Fast and exact mesh booleans, spatial queries, arrangements, registration, and remeshing on NumPy arrays. NumPy in, NumPy out.

Read the article: The STL for Geometry — What the STL philosophy of separating algorithms from data looks like when applied to geometry.

polydera.com/trueform | Documentation | ▶ Try it live

Installation

pip install trueform

Quick Tour

Primitives — typed NumPy arrays, single or batched:

import numpy as np
import trueform as tf

triangle = tf.Triangle(a=[0, 0, 0], b=[1, 0, 0], c=[0, 1, 0])
segment = tf.Segment([[0, 0, 0], [1, 1, 1]])
ray = tf.Ray(origin=[0.2, 0.2, -1], direction=[0, 0, 1])

# Add a leading dimension for batches
pts = tf.Point(np.random.rand(1000, 3).astype(np.float32))
segs = tf.Segment(start=np.random.rand(500, 3), end=np.random.rand(500, 3))

Meshes are created from NumPy arrays or read from files:

points = np.array([
    [0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]
], dtype=np.float32)
faces = np.array([
    [0, 1, 2], [0, 2, 3], [0, 3, 1], [1, 3, 2]
], dtype=np.int32)

mesh = tf.Mesh(faces, points)

# Or read from file
mesh = tf.Mesh(*tf.read_stl("model.stl"))

Queries — same functions for any combination. Batches broadcast:

# Batch × Primitive — distance field to a plane
plane = tf.Plane(normal=[0, 0, 1], offset=0.0)
scalars = tf.distance(pts, plane)                    # shape (1000,)

# Batch × Form — closest point on mesh for each segment
ids, dist2s, closest = tf.neighbor_search(mesh, segs) # 3 arrays, shape (500,)

# Single × Single
dist2, pt_a, pt_b = tf.closest_metric_point_pair(triangle, segment)

if (t := tf.ray_cast(ray, triangle)) is not None:
    hit_point = ray.origin + t * np.array(ray.direction)

Boolean operations:

(result_faces, result_points), labels, face_labels = tf.boolean_union(mesh0, mesh1)

# With intersection curves
(result_faces, result_points), labels, face_labels, (paths, curve_points) = tf.boolean_union(
    mesh0, mesh1, return_curves=True
)

Remeshing:

# Decimate to 50%
dec_faces, dec_points = tf.decimated(mesh, 0.5)

# Isotropic remesh to uniform edge lengths
dec_mesh = tf.Mesh(dec_faces, dec_points)
mel = tf.mean_edge_length(dec_mesh)
rem_faces, rem_points = tf.isotropic_remeshed(dec_mesh, mel)

Full documentation covers mesh analysis, topology, isocontours, curvature, and more.

Examples

Run examples locally:

git clone https://github.com/polydera/trueform.git
cd trueform/python/examples
pip install vtk  # for interactive examples
python vtk/collision.py mesh.stl

Blender Integration

Cached meshes with automatic dirty-tracking for live preview add-ons. See Blender docs.

Benchmarks

Operation Input Time Speedup Baseline TrueForm
Boolean Union 2 × 1M 28 ms MeshLib (int32 exact + SoS) exact predicates, canonical topology
Mesh–Mesh Curves 2 × 1M 7 ms 233× CGAL Exact_predicates_inexact_constructions_kernel exact predicates, canonical topology
ICP Registration 1M 7.7 ms 93× libigl AABB tree, random subsampling
Self-Intersection 1M 78 ms 37× libigl EPECK (GMP/MPFR) exact predicates, canonical topology
Isocontours 1M, 16 cuts 3.8 ms 38× VTK vtkContourFilter exact predicates
Connected Components 1M 15 ms 10× CGAL parallel union-find
Boundary Paths 1M 12 ms 11× CGAL Hierholzer's algorithm
k-NN Query 500K 1.7 µs nanoflann k-d tree AABB tree
Mesh–Mesh Distance 2 × 1M 0.2 ms Coal (FCL) OBBRSS OBBRSS tree
Decimation (50%) 1M 72 ms 50× CGAL edge_collapse parallel partitioned collapse
Principal Curvatures 1M 25 ms 55× libigl parallel k-ring quadric fitting

Apple M4 Max, 16 threads, Clang -O3. Full methodology

License

Dual-licensed: PolyForm Noncommercial 1.0.0 for noncommercial use, commercial licenses available.

Contributing

See CONTRIBUTING.md and open issues.

Citation

@software{trueform2025,
    title={trueform: the STL for Geometry},
    author={Sajovic, {\v{Z}}iga and {et al.}},
    organization={Polydera},
    year={2025},
    url={https://github.com/polydera/trueform}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trueform-0.9.7.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

trueform-0.9.7-cp313-cp313-win_amd64.whl (24.8 MB view details)

Uploaded CPython 3.13Windows x86-64

trueform-0.9.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (69.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

trueform-0.9.7-cp313-cp313-macosx_11_0_arm64.whl (43.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

trueform-0.9.7-cp312-cp312-win_amd64.whl (24.8 MB view details)

Uploaded CPython 3.12Windows x86-64

trueform-0.9.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (69.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

trueform-0.9.7-cp312-cp312-macosx_11_0_arm64.whl (43.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

trueform-0.9.7-cp311-cp311-win_amd64.whl (24.8 MB view details)

Uploaded CPython 3.11Windows x86-64

trueform-0.9.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (69.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

trueform-0.9.7-cp311-cp311-macosx_11_0_arm64.whl (43.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file trueform-0.9.7.tar.gz.

File metadata

  • Download URL: trueform-0.9.7.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trueform-0.9.7.tar.gz
Algorithm Hash digest
SHA256 46046fddc6b5e880f2e5870056a9207fbe641441a765fe81420712477101aaa3
MD5 7ca44ebde3beef27c87fdbc0705c8ef4
BLAKE2b-256 e680fcf9264ad1a6fa651c56ba20087bbc07a3899870f232db639e9e754bb502

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: trueform-0.9.7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 24.8 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trueform-0.9.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8ac5765e92c1232655c731dfa587e5806749c6ce32100f08a3786feca83296fc
MD5 a34d597518ab682df2b1d72ba4ca53f5
BLAKE2b-256 c0d4fba39760e3b1f0e8c8d615a47fff83a8a3c0fd512a6ea0c992a084e20a97

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for trueform-0.9.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8edd25f50432309e3d63677896b856a7bd8d31f5ada69669f9e0bd355f007123
MD5 cd43c23e5d8650b823c66493ca0bb51d
BLAKE2b-256 817b69cf760d90a4009d86e552a646d2df9e726c4a113ca65f0da284ca666a3a

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trueform-0.9.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c1c17b09d9cec7127a063b7c66d589dba2186c1feceb2450a7b136d907950433
MD5 d1d145d85e25492a9a30d14a61ab5987
BLAKE2b-256 74279a87d69a917ecf2b796d7b236cf29acc9db90f99bdbbce323ae5142fef79

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: trueform-0.9.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 24.8 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trueform-0.9.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 63e4192c2efa13a84275fe5dcd04aee56c1e1a4236c2300f559a62c647424c11
MD5 2d2e2162daf05e279fbd559307411dc0
BLAKE2b-256 eb22472be68e2b0f45c62f1ce37e28e6492153026558c0d2aaa10f572f869484

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for trueform-0.9.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 95b566055aa1cda3cb6c3f0e0a9dbb7313e8087f1557fe9c86fd609669af7d1a
MD5 c4fe39b3c452b52757002890e8f21caa
BLAKE2b-256 438ca7eec1e881ca05d3429d4ec6defe6c8d76e9fa436b2b81a05072e6bfa1f9

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trueform-0.9.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e1338f53938ff461c557e60b68740efd01d0f5a32dbcd2cbd83c515691393b9
MD5 184918d42c9483e63f4e98e061a0c389
BLAKE2b-256 a65bdf681de21a44a6a6cdbff57ffa9a148b511b70c2e795ff2e3779f1bb97d9

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: trueform-0.9.7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 24.8 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trueform-0.9.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b88f6c3c0b8417d5048986281820c4d98e07089110d33fdaf853909852358db1
MD5 34fea715420927f77e02c458f7e3a2c6
BLAKE2b-256 61417c8668e80b701b182a4890e7d980a60259a43501eacb1976104911b865e9

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for trueform-0.9.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 16990837ca32985f610dc7fdf35b3c456dc823a8ad7a5fd3c7125a24b2f9613e
MD5 5e273d5dc83492cb1605d20bb1ea0b92
BLAKE2b-256 114c87c7c526f7a03c01f23c600298824be8f5bd7a39feb03469695223b9b0b5

See more details on using hashes here.

File details

Details for the file trueform-0.9.7-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trueform-0.9.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6554cc27ae51d18fcb0dbdbacae479d3bededa29dce3ef251b876ace057e4f8
MD5 5009ce4d88c512338fa693d567134c46
BLAKE2b-256 c082eafdb21bced3fdbf58ff8293615c744bce94ff085328e5db9bd871ba2054

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page