feat: enable cone STEP export and harden kernel load

Bump occt-wasm 3.6.0 -> 3.6.1, which fixes the multi-solid STEP writer
that dropped a cone's lateral CONICAL_SURFACE. Verified end-to-end: a
cone keeps its full surface and exact volume in a multi-solid assembly,
so cones now map to exact B-Rep alongside box/cylinder/sphere.

- Add "cone" to EXACT_KINDS and restore the cone build branch
  (full and truncated cones, honoring resized footprint).
- Drop the obsolete cone-bug skip and its special-cased reason string.
- brepKernel: clear the cached promise on a failed load so a transient
  kernel fetch failure can be retried instead of poisoning the session.
- Update the export panel copy to list cones as exact geometry.
This commit is contained in:
Andy Aragon
2026-06-29 15:03:32 +03:00
committed by Formsmith
parent 80b12ee9f7
commit a0fa3559b3
5 changed files with 27 additions and 23 deletions
@@ -7469,7 +7469,7 @@ function TopActionPanel({
<ToolbarExportIcon /> <ToolbarExportIcon />
{stepExporting ? "Building STEP…" : "Download STEP (B-Rep)"} {stepExporting ? "Building STEP…" : "Download STEP (B-Rep)"}
</button> </button>
<p className="export-step-note">STEP keeps boxes, cylinders and spheres as exact CAD geometry (OpenCascade). Other shapes are skipped.</p> <p className="export-step-note">STEP keeps boxes, cylinders, spheres and cones as exact CAD geometry (OpenCascade). Other shapes are skipped.</p>
</div> </div>
) : null} ) : null}
{panel === "tips" ? ( {panel === "tips" ? (
+7 -1
View File
@@ -17,12 +17,18 @@ type OcctWasmModule = typeof import("occt-wasm");
let brepReady: Promise<Brep> | null = null; let brepReady: Promise<Brep> | null = null;
export async function loadBrepWithOcct(): Promise<Brep> { export async function loadBrepWithOcct(): Promise<Brep> {
// Cache the in-flight/resolved load, but drop a rejected attempt so a transient
// failure (e.g. a blip fetching the 22 MB wasm) can be retried on the next call
// instead of poisoning STEP for the rest of the session.
brepReady ??= (async () => { brepReady ??= (async () => {
const brep = await import("brepjs"); const brep = await import("brepjs");
const occt = (await import(/* webpackIgnore: true */ OCCT_INDEX_URL)) as unknown as OcctWasmModule; const occt = (await import(/* webpackIgnore: true */ OCCT_INDEX_URL)) as unknown as OcctWasmModule;
const kernel = await occt.OcctKernel.init({ wasm: OCCT_WASM_URL }); const kernel = await occt.OcctKernel.init({ wasm: OCCT_WASM_URL });
brep.registerKernel("occt-wasm", brep.OcctWasmAdapter.fromKernel(kernel)); brep.registerKernel("occt-wasm", brep.OcctWasmAdapter.fromKernel(kernel));
return brep; return brep;
})(); })().catch((error) => {
brepReady = null;
throw error;
});
return brepReady; return brepReady;
} }
+13 -16
View File
@@ -18,18 +18,13 @@ export type StepExportResult = {
// rigid placement are mapped to B-Rep. Everything else (swept/tessellated/text // rigid placement are mapped to B-Rep. Everything else (swept/tessellated/text
// shapes) is reported as skipped rather than faceted into a low-fidelity STEP. // shapes) is reported as skipped rather than faceted into a low-fidelity STEP.
// //
// Cone construction is correct in the kernel (verified volume/bbox), but the // Cones are exact: the multi-solid STEP writer that used to drop a cone's lateral
// occt-wasm multi-solid STEP writer drops a cone's lateral CONICAL_SURFACE when // CONICAL_SURFACE was fixed upstream in occt-wasm 3.6.1 (verified end-to-end —
// more than one solid is written to a file (both exportAssemblySTEP and a plain // cone keeps its full surface and volume in a multi-solid assembly).
// compound). A lone cone via exportSTEP is fine. Until that upstream writer bug const EXACT_KINDS: ReadonlySet<WorkplaneShape["kind"]> = new Set(["box", "cylinder", "sphere", "cone"]);
// is fixed, cones are reported as skipped rather than exported as a corrupt disk.
const EXACT_KINDS: ReadonlySet<WorkplaneShape["kind"]> = new Set(["box", "cylinder", "sphere"]);
const SIZE_EPS = 0.0005; const SIZE_EPS = 0.0005;
function unsupportedReason(kind: WorkplaneShape["kind"]): string { function unsupportedReason(): string {
if (kind === "cone") {
return "cone STEP export blocked by an upstream occt-wasm multi-solid writer bug (drops CONICAL_SURFACE)";
}
return "no exact B-Rep mapping"; return "no exact B-Rep mapping";
} }
@@ -38,7 +33,7 @@ function unsupportedReason(kind: WorkplaneShape["kind"]): string {
// the origin (Z, then Y, then X) reproduces that product before the shape is // the origin (Z, then Y, then X) reproduces that product before the shape is
// translated off-origin. Circular cylinders/cones ignore yaw, matching the // translated off-origin. Circular cylinders/cones ignore yaw, matching the
// editor's meshYawDegrees so the exported diameter is invariant. // editor's meshYawDegrees so the exported diameter is invariant.
function shapeYawDegrees(shape: WorkplaneShape): number { export function shapeYawDegrees(shape: WorkplaneShape): number {
const round = shape.kind === "cylinder" || shape.kind === "cone"; const round = shape.kind === "cylinder" || shape.kind === "cone";
const circular = Math.abs(shapeWidth(shape) - shapeDepth(shape)) < SIZE_EPS; const circular = Math.abs(shapeWidth(shape) - shapeDepth(shape)) < SIZE_EPS;
return round && circular ? 0 : shape.rotation; return round && circular ? 0 : shape.rotation;
@@ -82,6 +77,8 @@ function buildExactSolid(brep: Brep, shape: WorkplaneShape): BuildOutcome {
if (Math.abs(width - depth) >= SIZE_EPS) { if (Math.abs(width - depth) >= SIZE_EPS) {
return { skip: "elliptical base is not an exact OCCT primitive" }; return { skip: "elliptical base is not an exact OCCT primitive" };
} }
// Honor the resized footprint (width) while keeping the shape's own
// top/base radius ratio, so a truncated cone stays truncated after resize.
const baseRadius = width / 2; const baseRadius = width / 2;
const topScale = shape.baseRadius ? (shape.topRadius ?? 0) / shape.baseRadius : 0; const topScale = shape.baseRadius ? (shape.topRadius ?? 0) / shape.baseRadius : 0;
solid = brep.cone(baseRadius, baseRadius * topScale, height, { axis: [0, 1, 0], centered: true }); solid = brep.cone(baseRadius, baseRadius * topScale, height, { axis: [0, 1, 0], centered: true });
@@ -160,7 +157,7 @@ function describe(shape: WorkplaneShape, reason: string): SkippedShape {
return { name: shape.name, kind: shape.kind, reason }; return { name: shape.name, kind: shape.kind, reason };
} }
type Aabb = { min: [number, number, number]; max: [number, number, number] }; export type Aabb = { min: [number, number, number]; max: [number, number, number] };
// World-space AABB used to decide whether a hole actually reaches a body. A hole // World-space AABB used to decide whether a hole actually reaches a body. A hole
// is only cut from a body when their boxes overlap, so a body far from every hole // is only cut from a body when their boxes overlap, so a body far from every hole
@@ -170,7 +167,7 @@ type Aabb = { min: [number, number, number]; max: [number, number, number] };
// Axis-aligned shapes get a tight box. Rotated shapes fall back to the box that // Axis-aligned shapes get a tight box. Rotated shapes fall back to the box that
// encloses the bounding sphere (rotation-invariant, never under-reports), trading // encloses the bounding sphere (rotation-invariant, never under-reports), trading
// tightness for the guarantee that a real intersection is never missed. // tightness for the guarantee that a real intersection is never missed.
function worldAabb(shape: WorkplaneShape): Aabb { export function worldAabb(shape: WorkplaneShape): Aabb {
const w = shapeWidth(shape); const w = shapeWidth(shape);
const d = shapeDepth(shape); const d = shapeDepth(shape);
const h = shape.height; const h = shape.height;
@@ -187,7 +184,7 @@ function worldAabb(shape: WorkplaneShape): Aabb {
return { min: [cx - hx, cy - hy, cz - hz], max: [cx + hx, cy + hy, cz + hz] }; return { min: [cx - hx, cy - hy, cz - hz], max: [cx + hx, cy + hy, cz + hz] };
} }
function aabbsOverlap(a: Aabb, b: Aabb): boolean { export function aabbsOverlap(a: Aabb, b: Aabb): boolean {
return ( return (
a.min[0] <= b.max[0] && a.min[0] <= b.max[0] &&
a.max[0] >= b.min[0] && a.max[0] >= b.min[0] &&
@@ -205,7 +202,7 @@ export async function exportShapesToStep(shapes: WorkplaneShape[]): Promise<Step
const holes: { box: Aabb; solid: BrepSolid }[] = []; const holes: { box: Aabb; solid: BrepSolid }[] = [];
for (const shape of shapes.filter((s) => s.hole)) { for (const shape of shapes.filter((s) => s.hole)) {
if (!EXACT_KINDS.has(shape.kind)) { if (!EXACT_KINDS.has(shape.kind)) {
skipped.push(describe(shape, `hole ${unsupportedReason(shape.kind)}; cut omitted`)); skipped.push(describe(shape, `hole ${unsupportedReason()}; cut omitted`));
continue; continue;
} }
const built = buildExactSolid(brep, shape); const built = buildExactSolid(brep, shape);
@@ -226,7 +223,7 @@ export async function exportShapesToStep(shapes: WorkplaneShape[]): Promise<Step
} else if (EXACT_KINDS.has(shape.kind)) { } else if (EXACT_KINDS.has(shape.kind)) {
built = buildExactSolid(brep, shape); built = buildExactSolid(brep, shape);
} else { } else {
const reason = shape.kind === "mesh" ? "imported mesh has no B-Rep source; re-import as STEP to round-trip" : unsupportedReason(shape.kind); const reason = shape.kind === "mesh" ? "imported mesh has no B-Rep source; re-import as STEP to round-trip" : unsupportedReason();
skipped.push(describe(shape, reason)); skipped.push(describe(shape, reason));
continue; continue;
} }
+4 -4
View File
@@ -15,7 +15,7 @@
"lucide-react": "^0.511.0", "lucide-react": "^0.511.0",
"manifold-3d": "^3.5.0", "manifold-3d": "^3.5.0",
"next": "^15.3.2", "next": "^15.3.2",
"occt-wasm": "^3.6.0", "occt-wasm": "^3.6.1",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"tailwind-merge": "^3.3.0", "tailwind-merge": "^3.3.0",
@@ -2344,9 +2344,9 @@
} }
}, },
"node_modules/occt-wasm": { "node_modules/occt-wasm": {
"version": "3.6.0", "version": "3.6.1",
"resolved": "https://registry.npmjs.org/occt-wasm/-/occt-wasm-3.6.0.tgz", "resolved": "https://registry.npmjs.org/occt-wasm/-/occt-wasm-3.6.1.tgz",
"integrity": "sha512-qDTnqaRL73DkrqM7cdCJN8FStJm28W9TVXqJXofZQihlA/mX6mnkmE19FkWNrSsixVE676FMtL3V80lzAbG+GQ==", "integrity": "sha512-j25qLLPoLAmYEN7+hO+hU7gX2WPmLBL9XavAunSyPYGUcJRiMYqrgtuD+cf/um8vQxrnZrWW0ZqpfHevki8RHw==",
"license": "MIT OR Apache-2.0", "license": "MIT OR Apache-2.0",
"dependencies": { "dependencies": {
"comlink": "^4.4.2" "comlink": "^4.4.2"
+2 -1
View File
@@ -13,6 +13,7 @@
"typecheck": "tsc -p apps/web/tsconfig.json --noEmit", "typecheck": "tsc -p apps/web/tsconfig.json --noEmit",
"test": "vitest run --config tests/vitest.config.ts", "test": "vitest run --config tests/vitest.config.ts",
"test:watch": "vitest --config tests/vitest.config.ts", "test:watch": "vitest --config tests/vitest.config.ts",
"test:e2e": "vitest run --config tests/vitest.e2e.config.ts",
"perf": "vitest run --config tests/vitest.perf.config.ts --reporter verbose", "perf": "vitest run --config tests/vitest.perf.config.ts --reporter verbose",
"ci": "npm run typecheck && npm run test", "ci": "npm run typecheck && npm run test",
"docker:build": "docker build -f deploy/docker/Dockerfile -t sketchforge:local .", "docker:build": "docker build -f deploy/docker/Dockerfile -t sketchforge:local .",
@@ -28,7 +29,7 @@
"lucide-react": "^0.511.0", "lucide-react": "^0.511.0",
"manifold-3d": "^3.5.0", "manifold-3d": "^3.5.0",
"next": "^15.3.2", "next": "^15.3.2",
"occt-wasm": "^3.6.0", "occt-wasm": "^3.6.1",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"tailwind-merge": "^3.3.0", "tailwind-merge": "^3.3.0",