Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
cadrum
Rust CAD library powered by OpenCASCADE (OCCT 8.0.0-rc5).
Usage
| primitives | write read | transform | boolean |
|---|---|---|---|
| extrude | loft | sweep | bspline |
More examples with source code are available at lzpel.github.io/cadrum.
Add this to your Cargo.toml:
[]
= "^0.6"
Build
cargo build automatically downloads a prebuilt OCCT 8.0.0-rc5 binary for the targets below.
| Target | Prebuilt | |
|---|---|---|
x86_64-unknown-linux-gnu |
✅ | |
aarch64-unknown-linux-gnu |
✅ | |
x86_64-pc-windows-msvc |
✅ | |
x86_64-pc-windows-gnu |
✅ |
For other targets, build OCCT from source:
OCCT_ROOT=/path/to/occt cargo build --features source-build
If OCCT_ROOT is not set, built binaries are cached under target/.
Requirements when building OpenCASCADE from source
- C++17 compiler (GCC, Clang, or MSVC)
- CMake
Examples
Primitives
Primitive solids: box, cylinder, sphere, cone, torus — colored and exported as STEP + SVG.
//! Primitive solids: box, cylinder, sphere, cone, torus — colored and exported as STEP + SVG.
use Solid;
use DVec3;
Write read
Read and write: chain STEP, BRep text, and BRep binary round-trips with progressive rotation.
//! Read and write: chain STEP, BRep text, and BRep binary round-trips with progressive rotation.
use ;
use DVec3;
use FRAC_PI_8;
Transform
Transform operations: translate, rotate, scale, and mirror applied to a cone.
//! Transform operations: translate, rotate, scale, and mirror applied to a cone.
use Solid;
use DVec3;
use PI;
Boolean
Boolean operations: union, subtract, and intersect between a box and a cylinder.
//! Boolean operations: union, subtract, and intersect between a box and a cylinder.
use ;
use DVec3;
Extrude
Demo of Solid::extrude: push a closed 2D profile along a direction vector.
//! Demo of `Solid::extrude`: push a closed 2D profile along a direction vector.
//!
//! - **Box**: square polygon extruded along Z
//! - **Oblique cylinder**: circle extruded at a steep angle
//! - **L-beam**: L-shaped polygon extruded along Z
//! - **Heart**: BSpline heart-shaped profile extruded along Z
use ;
use DVec3;
/// Square polygon → box (simplest extrude).
/// Circle extruded at a steep angle → oblique cylinder.
/// L-shaped polygon → L-beam.
/// Heart-shaped BSpline profile extruded along Z.
Loft
Demo of Solid::loft: skin a smooth solid through cross-section wires.
//! Demo of `Solid::loft`: skin a smooth solid through cross-section wires.
//!
//! - **Frustum**: two circles of different radii → truncated cone (minimal loft)
//! - **Morph**: square polygon → circle (cross-section shape transition)
//! - **Tilted**: three non-parallel circular sections → twisted loft
use ;
use DVec3;
/// Two circles → frustum (minimal loft example).
/// Square polygon → circle (2-section morph loft).
/// Three non-parallel circular sections → twisted loft.
Sweep
Sweep showcase: M2 screw (helix spine) + U-shaped pipe (line+arc+line spine)
//! Sweep showcase: M2 screw (helix spine) + U-shaped pipe (line+arc+line spine)
//! + twisted ribbon (`Auxiliary` aux-spine mode).
//!
//! `ProfileOrient` controls how the profile is oriented as it travels along the spine:
//!
//! - `Fixed`: profile is parallel-transported without rotating. Cross-sections
//! stay parallel to the starting orientation. Suited for straight extrusions;
//! on a curved spine the profile drifts off the tangent and the result breaks.
//! - `Torsion`: profile follows the spine's principal normal (raw Frenet–Serret
//! frame). Suited for constant-curvature/torsion curves like helices and for
//! 3D free curves where the natural twist should carry into the profile.
//! Fails near inflection points where the principal normal flips.
//! - `Up(axis)`: profile keeps `axis` as its binormal — at every point the
//! profile is rotated around the tangent so one in-plane axis stays in the
//! tangent–`axis` plane. Suited for roads/rails/pipes that must preserve a
//! gravity direction. On a helix, `Up(helix_axis)` is equivalent to `Torsion`.
//! Fails when the tangent becomes parallel to `axis`.
//! - `Auxiliary(aux_spine)`: profile's tracked axis points from the main spine
//! toward a parallel auxiliary spine. Arbitrary twist control — e.g. a
//! helical `aux_spine` on a straight `spine` produces a twisted ribbon.
use ;
use DVec3;
// ==================== Component 1: M2 ISO screw ====================
// ==================== Component 2: U-shaped pipe ====================
// ==================== Component 3: Auxiliary-spine twisted ribbon ====================
// 直線 spine を `Auxiliary(&[helix])` で掃引すると、各点で profile の tracked 軸が
// 対応するヘリックス点を向くように回転される。pitch=h のヘリックスは [0, h] の
// あいだにちょうど 360° 一周するので、平たい長方形 profile は 1 回捻れた
// リボンになる — `Fixed` や `Torsion` だと直線 spine では profile は全く
// 回転しないので、ねじれが見えれば Auxiliary が効いている証拠。
// ==================== main: side-by-side layout ====================
//
// Each builder places its component at its final world position (screw at
// origin, U-pipe at x=6, ribbon at x=12) and applies its color, so main
// just concatenates them.
Bspline
use Solid;
use ;
use TAU;
// 2 field-period stellarator-like torus.
// `Solid::bspline` is fed a 2D control-point grid to build a periodic B-spline solid.
// Every variation below is invariant under phi → phi+π (or shifts by a multiple
// of 2π), so the resulting shape has 180° rotational symmetry around the Z axis:
// a(phi) = 1.8 + 0.6 * sin(2φ) radial semi-axis
// b(phi) = 1.0 + 0.4 * cos(2φ) Z semi-axis
// psi(phi) = 2 * phi cross-section twist (2 turns per loop)
// z_shift(phi) = 1.0 * sin(2φ) vertical undulation
const M: usize = 48; // toroidal (U) — must be even for 180° symmetry
const N: usize = 24; // poloidal (V) — arbitrary
const RING_R: f64 = 6.0;
Features
color(default): Colored STEP I/O via XDE. Enableswrite_step_with_colors,read_step_with_colors, and per-face color onSolid.source-build: Download and build OCCT from upstream sources via CMake. Enable this on triples without a published prebuilt.
Showcase
A browser-based configurator that lets you tweak dimensions of a STEP model and get an instant 3D preview and quote. cadrum powers the parametric reshaping and meshing on the backend.
Release Notes
0.6.0
source-buildfeature now gatescmake/walkdiras optional build-dependencies. Defaultcargo buildno longer compiles them, significantly reducing build time on prebuilt targets. Users on unsupported targets must enable--features source-build(behavior unchanged — previously these targets also failed, just with a download error instead of a clear message).x86_64-pc-windows-gnuprebuilt added via Docker cross-compilation with Debian mingw-w64 (posix thread model). All MinGW runtime DLLs are statically absorbed — the resulting exe depends only on Windows OS DLLs.- LGPL 2.1 §2 compliance: source builds now retain only the ~9 patched OCCT source files alongside the
.alibraries, removing the unmodified bulk (~88 MB of data/dox/tests). The patched files carry timestamped headers per §2(a). OCCT_ROOTrelative path handling fixed: resolved viaenv::current_dir()instead of the unreliableCARGO_TARGET_DIRheuristic.--target <triple>flag now works correctly.build.rsrestructured:resolve_occtuses match chains with#[cfg]for source-build vs prebuilt paths. Source-build code lives in#[cfg(feature = "source-build")] mod source.patch_occt_sourcessplit intowalk_occt_sources+patch_or_none(side-effect-free).- README simplified: Build section moved after Usage with a prebuilt target table + OS icons.
0.5.1
0.4.5 was published briefly but its version number was lower than the already-published 0.5.0 (OCCT 7.9.3, older feature set), so
cargo add cadrumwould silently pick up 0.5.0 instead of the newer 0.4.5 code. Re-released as 0.5.1 with identical contents. Prefer 0.5.1 over 0.4.5.
Solid::bspline<const M, const N>(grid, periodic)— new constructor: build a periodic B-spline solid from a 2D control-point grid. V (cross-section) is always periodic; U (longitudinal) is controlled by theperiodicflag (torus whentrue, capped pipe whenfalse). Implemented viaGeomAPI_PointsToBSplineSurface::Interpolateover an augmented grid plusSetUPeriodic/SetVPeriodic.write_svg/Mesh::to_svgnow takeshading: bool— opt-in Lambertian shading with head-on light. Whentrue, triangles are tinted by0.5 + 0.5 * (normal · dir)so curved/organic shapes read clearly;falsereproduces the pre-0.5.1 flat rendering. Breaking vs 0.5.0: existing callers must add the flag (passfalseto preserve earlier output).examples/08_bspline.rsrewritten: 2 field-period stellarator-like torus with twisted + vertically undulating elliptic cross-sections, exercisingSolid::bsplineandshading=true.tests/bspline.rsadded: verifies 180° point symmetry of the stellarator shape via XZ/YZ half-space intersection (s1 ≈ s3, s2 ≈ s4).Error::BsplineFailed(String)new variant. Breaking for downstream code that does exhaustivematchonError.- OCCT 8.0.0 deprecation warnings resolved in
make_bspline_edgeandmake_bspline_solid(NCollection_HArray1<gp_Pnt>via localusingalias to bypass theHandle()macro comma-splitting issue;NCollection_Array2<gp_Pnt>directly).
License
This project is licensed under the MIT License.
Compiled binaries include OpenCASCADE Technology (OCCT), which is licensed under the LGPL 2.1. Users who distribute applications built with cadrum must comply with the LGPL 2.1 terms. Since cadrum builds OCCT from source, end users can rebuild and relink OCCT to satisfy this requirement.