Skip to main content

Crate meshbrep

Crate meshbrep 

Source
Expand description

Rebuild an exact boundary representation from a triangle mesh whose triangles each name the exact surface they came from, and write it as STEP.

A mesh kernel such as Manifold does booleans robustly but only on triangles. If every input triangle is tagged with the exact surface it approximates (a plane, cylinder, cone, sphere, torus or B-spline surface; spline builds the B-splines blends need), the tags survive the booleans, and the output mesh says which surface each region lies on. This crate turns that into a B-rep:

  • faces are connected regions on one surface (equal surfaces from different solids are merged, so two coplanar tops give one face);
  • edges are the boundaries between two faces, with exact curves where a closed form exists (lines, circles, ellipses) and cubic B-splines within a tolerance otherwise;
  • vertices are where three or more faces meet, solved on the exact surfaces; tangent surfaces are detected analytically and their contact lines used instead of an ill-conditioned solve;
  • seams and parameter-space curves are added on curved faces, so that a STEP reader trims them exactly instead of re-fitting;
  • triangles tagged Surface::Faceted become planar faces, so mesh-only regions mix with exact ones in one valid solid;
  • features of the mesh below the touching tolerance (edges shorter than it, needle triangles narrower) are cleaned up first, and so are faces and closed components of no area or volume.

Each face names the input triangles it came from (Report::face_triangles), and reconstruct_located names the triangles where a failure happened, so a caller can tag the faces it cannot have exact as Surface::Faceted and try again.

The mesh’s tessellation never reaches the output, only its topology: build it with the primitives (or the same rules: segment counts a multiple of 4 with vertices on the axes, spheres with poles and an equator) so that the mesh’s topology matches the exact model’s at tangencies.

Output is deterministic: the same input gives the same B-rep and the same STEP bytes on every platform (transcendental functions come from libm, not the platform).

use meshbrep::{primitives, reconstruct, validate, measure, write_step, Options, StepOptions};
use meshbrep::primitives::Transform;

let mesh = primitives::frustum(10.0, 5.0, 5.0, 32, &Transform::IDENTITY);
let brep = reconstruct(&mesh, &Options::default()).unwrap();
assert!(validate(&brep, 1e-6).is_valid());
let volume = measure(&brep).unwrap().volume;
assert!((volume - std::f64::consts::PI * 250.0).abs() < 1e-9);
let step = write_step(&brep, &StepOptions::default());
assert!(step.contains("CYLINDRICAL_SURFACE"));

Modules§

blend
Blend tools: the solids that round or chamfer the edges of a solid when a mesh kernel subtracts them (convex edges) or adds them (concave edges): straight edges, circles and arcs about an axis (Path::Arc, whose cross-section is revolved: revolve), and curves between faces that share no axis (Path::Curve, along which a ball is rolled: sweep, a B-spline blend).
primitives
Tagged meshes of simple solids, tessellated for reconstruction.
spline
B-spline surfaces (BSplineSurface): evaluating and projecting onto them, and building the ones blends need.

Structs§

BSpline
A clamped, non-rational B-spline curve in D dimensions: 3 for edges, 2 for curves in a surface’s parameter space.
BSplineSurface
A clamped B-spline surface, rational when weights is given: STEP’s B_SPLINE_SURFACE_WITH_KNOTS (with RATIONAL_B_SPLINE_SURFACE).
Brep
The reconstructed boundary representation.
Coedge
One use of an edge by a face.
Edge
An edge: a bounded piece of a curve between two vertices.
Face
A face: a region of one surface bounded by loops.
Failure
Why reconstruct_located failed, and where.
Frame
The parametrisation of a face’s surface: the placement written to STEP as its AXIS2_PLACEMENT_3D.
Loop
A closed loop of oriented edges.
Measure
Volume and area of a B-rep.
Options
Options for crate::reconstruct.
Report
What reconstruction measured and noticed.
Shell
A connected closed shell.
StepOptions
Names and dates for the file header and the product.
TaggedMesh
The input: a closed, oriented triangle mesh whose triangles each name the exact surface they approximate.
Tangency
Two surfaces of the input that touch without crossing.
Tolerances
Tolerances. Relative ones are multiplied by the model’s size (the largest edge of its bounding box).
Validation
What validate found.

Enums§

Contact
The set where two tangent surfaces touch.
Curve
A 3D curve. Each kind has a natural parameter t; an Edge uses the interval Edge::range of it.
Error
Why reconstruction failed.
Surface
An exact surface, in model coordinates.

Functions§

find_tangencies
Every pair of surfaces in surfaces that is tangent, with where they touch. Lengths are compared within tolerance (for a B-spline surface, which touches others along sides of its domain, this must cover how far it was fitted from them too).
measure
The volume and area of brep, integrated on its exact geometry.
reconstruct
Rebuilds the exact B-rep of a tagged mesh.
reconstruct_located
reconstruct, with the input triangles at a failure (see Failure::triangles).
validate
Checks brep:
write_step
Writes brep as a STEP AP214 file (AUTOMOTIVE_DESIGN schema), in millimetres, with parameter-space curves on curved faces and seam curves on periodic ones.

Type Aliases§

StopFn
A stop signal for Options::should_stop.