Differentiable rasterizer for CAD Boolean operations — JAX-native B-Rep kernel with stratum-aware gradients.
Project description
BRepAX
JAX-native differentiable B-Rep kernel with NURBS support.
BRepAX loads STEP files into a JAX computation graph, enabling gradient-based optimization of CAD geometry through Boolean operations. It provides stratum-aware differentiation that handles topological transitions at Boolean boundaries, and supports both analytical primitives and freeform B-spline surfaces.
Installation
pip install brepax
Quick Start
import jax
import jax.numpy as jnp
from brepax.io.step import read_step
from brepax.brep.triangulate import (
triangulate_shape, divergence_volume,
mesh_surface_area, mesh_center_of_mass,
)
# Load STEP file and compute volume via divergence theorem
shape = read_step("part.step")
tris, params = triangulate_shape(shape)
vol = divergence_volume(tris) # exact for watertight mesh
area = mesh_surface_area(tris) # sum of triangle areas
com = mesh_center_of_mass(tris) # surface integral (Eberly 2002)
# Gradient of volume w.r.t. all triangle vertices
grad = jax.grad(divergence_volume)(tris)
Parametric Optimization
from brepax.brep.triangulate import extract_mesh_topology, evaluate_mesh
# Separate topology (one-time) from evaluation (differentiable)
topology = extract_mesh_topology(shape)
def volume_fn(radius):
tris = evaluate_mesh(topology, {"radius": radius}, uv_scale_param="radius")
return divergence_volume(tris)
# Gradient flows from volume through vertices to design parameter
grad = jax.grad(volume_fn)(jnp.array(5.0))
Features
Primitives
9 geometric types with differentiable SDF interface: Plane, Cylinder, Sphere, Cone, Torus, Box, FiniteCylinder, Disk, and BSplineSurface (rational NURBS with weights).
STEP Pipeline
- Read STEP files via OCCT (cadquery-ocp-novtk)
- Convert all face types to primitives (100% conversion on 4,080 faces across 28 test files)
- PMC-based CSG-Stump reconstruction (tested up to 664 faces)
- OCCT mesh hybrid triangulation with JAX-native vertex re-evaluation
Volume and Mass Properties (Divergence Theorem)
Mesh-based computation via the divergence theorem, working for all surface types including freeform B-spline. Validated on 32 models (< 0.5% error vs OCCT GProp). All are polynomial in vertex positions, giving exact gradients with no grid artifacts or singularities.
| Function | Formula | Degree |
|---|---|---|
divergence_volume |
(1/6) sum(v0 . (v1 x v2)) |
3 |
mesh_surface_area |
(1/2) sum(norm(cross(e1, e2))) |
-- |
mesh_center_of_mass |
First moments via surface integral | 4 |
mesh_inertia_tensor |
Second moments (Tonon 2004) | 5 |
Differentiable Metrics
10 metrics, all differentiable via jax.grad. 8 of 10 work for all surface
types; wall thickness metrics require analytical surfaces via CSG-Stump.
| Metric | Method | BSpline |
|---|---|---|
divergence_volume |
Divergence theorem on mesh | Yes |
mesh_surface_area |
Triangle area sum | Yes |
mesh_center_of_mass |
Divergence theorem variant | Yes |
mesh_inertia_tensor |
Divergence theorem variant | Yes |
draft_angle_violation |
SDF gradient near surface | Yes |
mean_curvature / max_curvature |
AD Hessian of SDF | Yes |
thin_wall_volume |
Sigmoid indicator on SDF grid | Analytical only |
min_wall_thickness |
Soft-argmax on SDF grid | Analytical only |
Parametric Optimization
extract_mesh_topology + evaluate_mesh separate watertight mesh topology
(from OCCT, one-time) from vertex evaluation (JAX-native, differentiable).
Design parameters flow through surface evaluation to volume:
- Sphere radius: Newton convergence in 4 steps
- Cylinder radius: Multi-face with disk cap tracking, 4 steps
- BSpline control points: Exact gradient, Newton convergence in 1 step
Boolean Operations
Union, subtract, intersect with stratum-dispatched gradients. Analytical exact gradients for bounded primitive pairs in 3 of 4 topological configurations.
Documentation
Full documentation: lv416e.github.io/brepax
License
Apache License 2.0. See LICENSE 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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brepax-0.4.0.tar.gz.
File metadata
- Download URL: brepax-0.4.0.tar.gz
- Upload date:
- Size: 324.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eff5edfbe5ed71eae3d954bce227a2e3dc8b2cbd3ed34466fbbe35f65bf05d9
|
|
| MD5 |
6453bb299780d424a267698142434990
|
|
| BLAKE2b-256 |
5c2a8c38504b50e702738cbe96349ad205bb72c5ffa9cb393b75459a0bc5aa7f
|
Provenance
The following attestation bundles were made for brepax-0.4.0.tar.gz:
Publisher:
release-please.yaml on lv416e/brepax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brepax-0.4.0.tar.gz -
Subject digest:
2eff5edfbe5ed71eae3d954bce227a2e3dc8b2cbd3ed34466fbbe35f65bf05d9 - Sigstore transparency entry: 1340172945
- Sigstore integration time:
-
Permalink:
lv416e/brepax@5a291ca8e6acc7a8b9d06eb48bb88dd0eddee5d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lv416e
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yaml@5a291ca8e6acc7a8b9d06eb48bb88dd0eddee5d8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file brepax-0.4.0-py3-none-any.whl.
File metadata
- Download URL: brepax-0.4.0-py3-none-any.whl
- Upload date:
- Size: 85.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c190802385859ae29bfd67bdbab54a15823b097294f57c1b081faa304b97353e
|
|
| MD5 |
75245e2bf496e4187040b2751ac7ce13
|
|
| BLAKE2b-256 |
5a1233502ccc29e77a2ab80bbe3ba52a95694c7c9a475c10e9ef22c3afc0cd84
|
Provenance
The following attestation bundles were made for brepax-0.4.0-py3-none-any.whl:
Publisher:
release-please.yaml on lv416e/brepax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brepax-0.4.0-py3-none-any.whl -
Subject digest:
c190802385859ae29bfd67bdbab54a15823b097294f57c1b081faa304b97353e - Sigstore transparency entry: 1340172948
- Sigstore integration time:
-
Permalink:
lv416e/brepax@5a291ca8e6acc7a8b9d06eb48bb88dd0eddee5d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lv416e
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yaml@5a291ca8e6acc7a8b9d06eb48bb88dd0eddee5d8 -
Trigger Event:
push
-
Statement type: