Skip to main content

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

Project description

COMPAS Forge 🛠️

License Python Rust COMPAS Status

An Open-Source, High-Performance Rust-Backed Geometry Verification & 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.


Installation

Standard Installation

Once released, COMPAS Forge can be installed from PyPI:

pip install compas-forge

Installation from Source

If you wish to modify the Rust core, ensure that you have the Rust toolchain installed.

Requirements:

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

Python API Usage Guide

You can import compas_forge directly inside Python scripts, Grasshopper Python components, or Blender scripts.


1. High-Fidelity Preflight Verification

Verify whether a model complies with manufacturing constraints such as dimensions, weight, watertightness, and robotic fabrication profile limits.

import compas_forge

# Run preflight against the KUKA robotic timber fabrication profile
report = compas_forge.run_preflight_profile(
    "my_geometry.json",
    "kuka-timber"
)

if report["is_compliant"]:
    print("✔️ Model is safe for robotic toolpaths.")
else:
    print("❌ Preflight violations found!")
    print(f"  • Watertight: {report['is_watertight']}")
    print(f"  • Calculated Mass: {report['estimated_mass_kg']:.3f} kg")
    print(f"  • Open Holes / Naked Edges: {report['boundary_edges_count']}")

2. Auto-Repairing Topological Defects

Automatically weld duplicate vertices and unify face winding directions using a Rust-backed BFS dual-graph traversal.

import json
import compas_forge

# Repair on the fly and fetch a detailed audit trail
repair_report = compas_forge.fix_geometry_file("dirty_mesh.json")

print("Mesh repaired successfully:")
print(f"  • Merged Vertices: {repair_report['welded_count']}")
print(f"  • Corrected Face Windings: {repair_report['flipped_count']}")

# Export the clean COMPAS structure back to JSON
fixed_data = json.loads(repair_report["fixed_json"])

with open("repaired_mesh.json", "w", encoding="utf-8") as f:
    json.dump(fixed_data, f, indent=4)

3. Assembly Collision & Clearance Solver

Find spatial interferences and clearance violations among multiple CAD components using R*-Tree broad-phase filtering and exact narrow-phase distance checks.

import compas_forge

assembly_files = {
    "beam_a.json": open("beam_a.json", encoding="utf-8").read(),
    "beam_b.json": open("beam_b.json", encoding="utf-8").read(),
}

# Find collisions with a strict 5cm safety clearance threshold
violations = compas_forge.check_assembly_clashes(
    assembly_files,
    clearance_tolerance=0.05
)

for idx, violation in enumerate(violations, 1):
    incident_type = (
        "Collision"
        if violation["has_intersection"]
        else "Clearance Violation"
    )

    print(
        f"[{idx}] "
        f"{violation['part_a']} <-> {violation['part_b']} | "
        f"Distance: {violation['minimum_distance']:.5f} m | "
        f"Type: {incident_type}"
    )

CLI Usage Guide

COMPAS Forge is also packaged with an auto-documented command line interface built with click.


1. General Help Menu

python -m compas_forge --help

2. Run Preflight Audit

python -m compas_forge preflight my_geometry.json \
  --profile kuka-timber \
  -r preflight_report.html

3. Run Assembly Clash Detection

python -m compas_forge clash mesh_a.json mesh_b.json \
  --clearance 0.05

4. Execute Mesh Repair Auto-Fixer

python -m compas_forge fix dirty_mesh.json \
  -o repaired_mesh.json

Mathematical Formulations & Algorithms

1. Mesh Volume via Gauss's Divergence Theorem

The exact volume $V$ of an arbitrary closed manifold mesh is calculated by summing signed tetrahedra formed from the origin to each boundary triangle:

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

where $\mathbf{p}_0$, $\mathbf{p}_1$, and $\mathbf{p}_2$ are the vertex coordinates of each triangulated face.


2. Best-Fit Newell Plane & Planarity Deviation

AEC facade rationalization and timber stock cutting often require robust flatness evaluation. Best-fit reference plane normals are calculated using Newell's method:

$$ 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

Algebraic topology validation checks the Euler characteristic $\chi$ and genus $g$ of closed manifold meshes to guarantee topological integrity:

$$ \chi = V - E + F $$

$$ g = \frac{2 - \chi}{2} $$

where $V$ is the vertex count, $E$ is the unique undirected edge count, and $F$ is the face count.


Author & Academic Profile

Developed by Mohammad Amin Moradi at the intersection of computational geometry, systems programming, and digital fabrication in AEC.


License

Licensed under the MIT License.

See the LICENSE file for details.

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.1.1-cp311-abi3-win_amd64.whl (566.1 kB view details)

Uploaded CPython 3.11+Windows x86-64

compas_forge-0.1.1-cp311-abi3-manylinux_2_34_x86_64.whl (775.8 kB view details)

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

compas_forge-0.1.1-cp311-abi3-macosx_11_0_arm64.whl (658.1 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

compas_forge-0.1.1-cp310-abi3-win_amd64.whl (470.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

compas_forge-0.1.1-cp310-abi3-manylinux_2_34_x86_64.whl (673.8 kB view details)

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

compas_forge-0.1.1-cp310-abi3-macosx_11_0_arm64.whl (562.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for compas_forge-0.1.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bffd2cabafbbc1119bf83bf3b4a63c6eae6b77749e324a7c93529de02087ae69
MD5 0f29446a7cedaf6dff43e204eb3a9329
BLAKE2b-256 fd01facc7d1f39ff8ca1247cec7c9478d6c6c4e81cb1e20421a1637665cc31ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for compas_forge-0.1.1-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b52e739bfa116ce57f432ee6ac2630b571ae0a46f5de71a3a0af019156b05869
MD5 f3c611d9dffac5fed728400865abaabe
BLAKE2b-256 85b0dc549a1dbe577f3dfd08fafc0f434852035e2e17000cd199345ba670ea92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for compas_forge-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 669f17024154b4d8af8f14015b3f70703146854a47d878b9ff5dd262407132c8
MD5 9b2f1cf709e545803b84c6725af722d4
BLAKE2b-256 b4e0ff56ed8655c92f10adb0e46e3249f5f30111220e643b1ca83eb87b18da8d

See more details on using hashes here.

File details

Details for the file compas_forge-0.1.1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for compas_forge-0.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a1d4beb5c116065ef1d05002ad29b829388b3fa2582ae5e98232ea4a33503a99
MD5 1b7956e405206e7d45a45a4b6c8fb43a
BLAKE2b-256 b38c37fc9dd91749207496a2c1a6486bd5325019ccd2d231987a315d7bd05cb2

See more details on using hashes here.

File details

Details for the file compas_forge-0.1.1-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for compas_forge-0.1.1-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 189ccc20add43c38a81c13319326faea66c2601dcf4e2fecd163bc03ede0b81f
MD5 b36072807b4b6b5ecfbf321e330991fb
BLAKE2b-256 4ac6d78750d37f147578572d1a464c54d9fdeeaea474e9133024729fe21ccbe5

See more details on using hashes here.

File details

Details for the file compas_forge-0.1.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for compas_forge-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 778ce718837a3d1873ee1b8c2d212aa76e6f527173c0863df534f15e162934c5
MD5 456d8677cf278f675b8c8b449ba5f8fa
BLAKE2b-256 87a2689a9cf3b659038e84d7fdd3f634c00d8f2861b19fbadfa50a5f0455ec26

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