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.4.tar.gz (918.4 kB 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.4-cp313-cp313-win_amd64.whl (24.3 MB view details)

Uploaded CPython 3.13Windows x86-64

trueform-0.9.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (68.2 MB view details)

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

trueform-0.9.4-cp313-cp313-macosx_11_0_arm64.whl (42.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

trueform-0.9.4-cp312-cp312-win_amd64.whl (24.3 MB view details)

Uploaded CPython 3.12Windows x86-64

trueform-0.9.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (68.2 MB view details)

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

trueform-0.9.4-cp312-cp312-macosx_11_0_arm64.whl (42.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

trueform-0.9.4-cp311-cp311-win_amd64.whl (24.3 MB view details)

Uploaded CPython 3.11Windows x86-64

trueform-0.9.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (68.2 MB view details)

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

trueform-0.9.4-cp311-cp311-macosx_11_0_arm64.whl (42.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for trueform-0.9.4.tar.gz
Algorithm Hash digest
SHA256 0a900aa9bbfcd6706599913d798fe7a85fbe74510a4bcc69acac7346aafadf6b
MD5 4a23e93da5881b2f96ac7fa36f053613
BLAKE2b-256 26b385253ef92f32f5f3562a36cf0b2812369a615dde270e957a435d776cdd36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trueform-0.9.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 24.3 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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c2ac46ed2ae141fb8b05beb83d4fb4c529f7741d72f7e9ee528314c24cf72945
MD5 dbc181120837f2c49fc45de424c2c5f7
BLAKE2b-256 200749b15ba5d935b09de75a5d7c4c335ded566a14b9acc49669a8dcd4c56a7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trueform-0.9.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5d96a86cfbd3bff86a26ff3293d900019592ef561da04b8e75bf9410dca9d733
MD5 0902f6dbea6a7de24b9b96af7557304c
BLAKE2b-256 1a9f3ce8d060e340f21b439c8df7aee231b3f1e2eedb67f57feb9dee22741320

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trueform-0.9.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a500ad824737df276cb9673db87de29607ecd2a4d85f9dcd4c7eae27dcaa30a4
MD5 00047b99e2fce3b3832e65727775abdb
BLAKE2b-256 44178102e168f0fffdc41e9d77450ee83b412d7468bd7195ac4208cdb2d504fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trueform-0.9.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 24.3 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f8d906d0b63a9ef00cd9e00406ebb37b7680050b8f9c9409f4211ac694183e5a
MD5 c9f34764ac63a0e02ffd8274b9eab355
BLAKE2b-256 edb4b19575f6e0a3d297c0ebb7c96255db4b1fbb936e9d5815b5fcfd1cc7612b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trueform-0.9.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6565b220cd90fdf591e3dea686e5e4be9e5e9f2f9e0504141f9b70baedea3f05
MD5 3ad3cdcd30aca98d030af70d0464687c
BLAKE2b-256 0bf39a6571493f3456171dabb4d63c5273584ff6f8e0fdb57f7f8e9817659f7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trueform-0.9.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c7c67cbebc1916766a7434c7e92428911514e8389edcbc63dd07c0151507d5d9
MD5 743c160a62fbd59147ed9ca88133543d
BLAKE2b-256 2f13c857e8c41672ebfef3b7fc299facff0439a938a074fe3bfbe493585b12bd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trueform-0.9.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 24.3 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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 056ace5aee716c42c513292b7e946367981c401805a63a73aa0e819671e7fd84
MD5 4fafd8770dbf342fec6a8257a0b6c2c2
BLAKE2b-256 9c00fb203e6c59ecdc00fe1cf26540d439334e5d036ff4f2669e7c47070fd734

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trueform-0.9.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5b93ba75effdb3ccdc2f1d680ca7f201192cf98abf92a1a2611be3b926cf2527
MD5 7cd87f21c07a422b3d94572b9f4c3c22
BLAKE2b-256 fb72448d8fc3c344aae6b06cd8b7da7465184e6552e3a4501a1629a28662b0f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trueform-0.9.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 328cff9357c29d399890d1d1d62077a0ad8bab15028d48777239d14dc626dca6
MD5 b22a52fac7788747e6a103f028636e45
BLAKE2b-256 4c67c9292a4b84887f1b9dd2c1fa8a62921375afb6b4391ee741b9c3f57c6684

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