Skip to main content

High-performance pre-flight validation and geometry QA engine for COMPAS framework

Project description

COMPAS Forge 🛠️

[!NOTE] An Open-Source, High-Performance Rust-Backed Geometry Verification, Robotic Swept-Collision & Preflight Assembly Clearance Engine for the COMPAS Framework

COMPAS Forge Showcase

COMPAS Forge is an open-source, high-performance geometry verification and digital fabrication preflight suite developed to bridge the gap between computational design environments (such as Rhino, Grasshopper, and Blender) and real-world physical manufacturing.

Bound to the COMPAS ecosystem, this library provides microsecond-precision topological and physical validation checks, optimizing CAD models before exporting them to robotic paths or CNC machinery.

This is an open-source, research-oriented library designed for academic collaboration. We invite researchers, roboticists, and computational designers to contribute, extend fabrication profiles, and integrate advanced geometric solvers.


Key SOTA Architectural Features

  • Zero-Copy Memory Shared FFI (Pillar 1): Directly transmutes flat contiguous C-compatible memory layouts (PyBuffer) between Python and parallel Rust threads without copy-pasting, eliminating $O(N)$ string serialization overhead.
  • Continuous Collision Detection (CCD) with Rotational Sub-Stepping (Pillar 2): Supports simultaneous translation and rotation (helical sweep toolpaths) using piecewise temporal sub-stepping, evaluating exact Time of Impact (TOI) down to 6 decimal places in microseconds.
  • Parallel Assembly Contact Solver (Pillar 3): Combines parallel R-Tree broad-phase spatial filters with a robust 2D Sutherland-Hodgman Polygon Clipper to extract exact contact areas, centroids, and normals across thousands of adjacent blocks in milliseconds.
  • Universal COMPAS 1.x / 2.x Schema Parser: Embedded dual-format JSON deserializer that natively resolves both nested arrays and string-keyed maps, solving version compatibility breaks seamlessly.
  • Transparent Plugin Acceleration (Pillar 4): Integrated with COMPAS core plugin auto-discovery. Standard queries like .is_manifold() and .is_closed() are transparently intercepted and solved by the Rust engine.

Scaling Performance Benchmark

We evaluated the performance of the transparent plugin acceleration by querying .is_closed() on dense parametric geodesic dome structures. COMPAS pure-Python execution times are compared against COMPAS Forge's Rust FFI memory shared engine:

Mesh Facets (Count) Pure Python (ms) Rust Forge FFI (ms) Speedup Factor
400 0.476 ms 0.031 ms 15.35x
1,600 1.975 ms 0.070 ms 28.41x
3,600 4.169 ms 0.129 ms 32.29x
6,400 7.576 ms 0.215 ms 35.27x
10,000 11.240 ms 0.362 ms 31.06x
22,500 27.878 ms 0.737 ms 37.85x
40,000 49.254 ms 1.173 ms 41.99x

At 40,000 facets, pure-Python COMPAS takes ~49 ms to resolve watertightness, dropping the viewport frame rate below the interactive threshold (~20 FPS). COMPAS Forge processes the same geometry in 1.17 ms (~850 Hz), enabling lag-free real-time manipulation in CAD viewports (Rhino 8 / Grasshopper).

Performance Scaling

Installation

Standard Installation

Once released, COMPAS Forge can be installed from PyPI:

pip install compas-forge

Installation from Source

Requirements:

  • Rustc 1.96+
  • Python 3.11+
git clone https://github.com/moaminmo90/compas-forge.git
cd compas-forge
pip install -e .

Python API Usage Guide

1. Transparent COMPAS Core Acceleration

Simply install compas_forge. Native COMPAS queries are transparently routed to the Rust core under the hood:

from compas.datastructures import Mesh

mesh = Mesh.from_json("dense_model.json")

# Executed natively in Rust in microseconds!
if mesh.is_manifold() and mesh.is_closed():
    print("Mesh is valid and watertight.")

2. Rotational Continuous Collision Detection (CCD)

Evaluate continuous swept trajectories of simultaneous translations and rotations:

import compas_forge

# Pose: [x, y, z, qx, qy, qz, qw]
pose_a_start = [-2.5, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
pose_a_end   = [ 2.5, 0.0, 0.0, 0.0, 0.0, 0.707, 0.707] # Rotates 90 deg

result = compas_forge.check_swept_collision_zero_copy(
    mesh_a, pose_a_start, pose_a_end,
    mesh_b, pose_b_start, pose_b_end
)

if result["has_collision"]:
    print(f"Collision at Time of Impact: {result['time_of_impact']:.6f} s")

3. Assembly Contact Solver (Sutherland-Hodgman)

Extract exact contact polygons, centroids, and areas from touching blocks:

import compas_forge

blocks = {"block_0": mesh_0, "block_1": mesh_1}
contacts = compas_forge.compute_assembly_contacts_zero_copy(blocks, tolerance=0.005)

for contact in contacts:
    print(f"Contact between {contact['block_a']} and {contact['block_b']}")
    print(f"Contact Area: {contact['area_m2']} m² | Centroid: {contact['centroid']}")

CLI Usage Guide

# 1. Run general diagnostics
python -m compas_forge check my_mesh.json

# 2. Run continuous swept-collision
python -m compas_forge swept mesh_a.json -2.5,0,0,0,0,0,1 2.5,0,0,0,0,0.7,0.7 mesh_b.json 0,0,0,0,0,0,1 0,0,0,0,0,0,1

# 3. Resolve assembly contacts
python -m compas_forge contacts block_1.json block_2.json --tolerance 0.005

Examples & Reproducibility Sandbox

We provide ready-to-run educational scripts inside the examples/ directory to demonstrate and replicate our SOTA algorithms instantly:

  1. Zero-Copy Mesh Healing (examples/example_zero_copy_healing.py): Repairs 1,000s of vertex duplicates and face normal directions in-memory and reconstructs a healthy COMPAS Mesh in milliseconds.
  2. Rotational Sweep Collision (examples/example_continuous_collision.py): Runs continuous swept collision detection on two moving, rotating objects.
  3. Voussoir Arch Assembly Solver (examples/example_assembly_contacts.py): Synthesizes a 30-block voussoir arch and solves 29 contact interfaces with centroids and normal vectors in milliseconds.

To run any example:

python examples/example_zero_copy_healing.py

To regenerate the scaling benchmark chart:

python generate_benchmarks.py

Mathematical Formulations & Algorithms

1. Mesh Volume via Gauss's Divergence Theorem

$$ V = \frac{1}{6} \sum_i \mathbf{p}_0 \cdot \left(\mathbf{p}_1 \times \mathbf{p}_2\right) $$

2. Best-Fit Newell Plane & Planarity Deviation

$$ n_x = \sum_{i=0}^{N-1} (y_i - y_{i+1})(z_i + z_{i+1}) $$ $$ n_y = \sum_{i=0}^{N-1} (z_i - z_{i+1})(x_i + x_{i+1}) $$ $$ n_z = \sum_{i=0}^{N-1} (x_i - x_{i+1})(y_i + y_{i+1}) $$

The maximum perpendicular distance $d_{max}$ of any vertex $\mathbf{v}i$ to the centroid plane $\mathbf{c}$ is evaluated as: $$ d{max} = \max_i \left|(\mathbf{v}_i - \mathbf{c}) \cdot \mathbf{n}\right| $$

3. Topological Invariants (Euler & Genus)

$$ \chi = V - E + F $$ $$ g = \frac{2 - \chi}{2} $$


Author


License

Licensed under the MIT License.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

compas_forge-0.2.0-cp311-abi3-win_amd64.whl (6.3 MB view details)

Uploaded CPython 3.11+Windows x86-64

compas_forge-0.2.0-cp311-abi3-manylinux_2_34_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ x86-64

compas_forge-0.2.0-cp311-abi3-macosx_11_0_arm64.whl (6.4 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file compas_forge-0.2.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for compas_forge-0.2.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5f3af186302162e9fd7c2c2bf313578f34084da5e0538d18b5c968601f741f11
MD5 35b694a0f709c103e9d78bc8b44372d3
BLAKE2b-256 f7751989d613489bc2030725cc81fe9214d8e9e01219012c2058d604c704b665

See more details on using hashes here.

File details

Details for the file compas_forge-0.2.0-cp311-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for compas_forge-0.2.0-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c67cf2496d34520faa6b88852664adb8cf6ddb57b52fb3f2ba893058e4b58690
MD5 d04220328176634cb98571f1707bc9c8
BLAKE2b-256 7d938c12017547a4f9cfd45a0ac23cc7fa7409f92eaf1ac06a204dbabdbf04d3

See more details on using hashes here.

File details

Details for the file compas_forge-0.2.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for compas_forge-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0143204958aee00cefb9fc3b5e32371ad479b9b22c374e31da481c6fc00ae621
MD5 9fcf53e18a195df0ce0d62ddf0909c44
BLAKE2b-256 0882d14b6f0f442ba3faf5581e3a30fc284f9de480a0ad195c97049f84755379

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