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
+13 -5
View File
@@ -6474,13 +6474,21 @@ export function SketchForgeEditor({
}, [commitShapes, shapes]);
const selectFile = useCallback(async (file: File) => {
if (!importExtensionSupported(file.name)) {
setNotice("Unsupported file type. Use STL.");
const isStep = /\.(step|stp)$/i.test(file.name);
if (!isStep && !importExtensionSupported(file.name)) {
setNotice("Unsupported file type. Use STL or STEP.");
return;
}
try {
const nextShape = importedShapeFromStl(file.name, await file.arrayBuffer());
let nextShape: WorkplaneShape;
if (isStep) {
setNotice("Reading STEP… first import loads the OpenCascade kernel (~22 MB), one time per session");
const { importedShapeFromStep } = await import("@/lib/stepImport");
nextShape = await importedShapeFromStep(file.name, await file.arrayBuffer());
} else {
nextShape = importedShapeFromStl(file.name, await file.arrayBuffer());
}
commitShapes([...shapes, nextShape], nextShape.id, `Imported ${file.name}`);
setTopPanel(null);
} catch (error) {
@@ -6954,7 +6962,7 @@ export function SketchForgeEditor({
ref={fileInputRef}
className="hidden-file-input"
type="file"
accept=".stl"
accept=".stl,.step,.stp"
onChange={(event) => {
if (event.currentTarget.files) {
selectFiles(event.currentTarget.files);
@@ -7441,7 +7449,7 @@ function TopActionPanel({
}}
>
<ToolbarImportIcon />
<strong>Drop STL files</strong>
<strong>Drop STL or STEP files</strong>
<span>or click to choose from your computer</span>
</button>
</div>