feat: add B-Rep STEP import with exact round-trip

Import STEP/STP files as tessellated mesh bodies (Tier 1) while retaining
each body's exact OpenCascade B-Rep, normalized to the body's local frame
(lib/stepImport). On STEP export, re-emit imported bodies from that stored
B-Rep with the editor's placement reapplied via rigid kernel ops: rigid and
uniform-scaled placements stay exact analytic geometry, and non-uniform
resize degrades to valid B-splines (Tier 2). Closes import -> edit -> export.

A shared lazy occt-wasm loader (lib/brepKernel) is reused by import and
export so the kernel loads at most once per session, on first use.
This commit is contained in:
Andy Aragon
2026-06-29 15:03:32 +03:00
committed by Formsmith
parent b292cc14eb
commit 80b12ee9f7
6 changed files with 178 additions and 38 deletions
+8 -3
View File
@@ -10,7 +10,12 @@ function fileExtension(fileName: string) {
return fileName.split(".").pop()?.toLowerCase() ?? "";
}
function importedShapeFromTriangleSoup(fileName: string, rawPositions: number[], rawNormals: number[] | undefined): WorkplaneShape {
export function importedShapeFromTriangleSoup(
fileName: string,
rawPositions: number[],
rawNormals: number[] | undefined,
sourceFormat: NonNullable<WorkplaneShape["importedMesh"]>["sourceFormat"] = "stl",
): WorkplaneShape {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(rawPositions, 3));
if (rawNormals?.length === rawPositions.length) {
@@ -55,7 +60,7 @@ function importedShapeFromTriangleSoup(fileName: string, rawPositions: number[],
return {
id: createLocalId("uploaded-mesh"),
name: fileName.replace(/\.[^.]+$/, "") || "Imported STL",
name: fileName.replace(/\.[^.]+$/, "") || `Imported ${sourceFormat.toUpperCase()}`,
kind: "mesh",
color: "#0098c7",
x: 10,
@@ -74,7 +79,7 @@ function importedShapeFromTriangleSoup(fileName: string, rawPositions: number[],
baseDepth: depth,
baseHeight: height,
triangleCount,
sourceFormat: "stl",
sourceFormat,
},
locked: false,
hidden: false,