Files
support-fins/web/finworker.js
T
matthewtrahan f5aa212db7 comments: point prop.js mentions at the web/prop/ module that owns the code
finworker, solids, cutout, fins, draw, tails.test, check_stl, the Onshape
port and PERFORMANCE-SPEC named prop.js for things that now live in
prop/config.js, sweep.js, contact.js, surface.js or clearance.js. The dated
notes in ROADMAP and IMPLEMENTATION-PLAN are left as written.
2026-09-26 17:46:36 -05:00

28 lines
1.3 KiB
JavaScript

// Off-main-thread support generation.
//
// buildFins -- and everything it imports (prop.js + web/prop/, inside.js, planes.js,
// overhangs.js) -- is pure mesh math with no DOM or three.js dependency; that is
// exactly why prototype/verify_fins.js can run it headless. So the whole build
// moves into a Worker. On a large or badly-posed part a single build can take a
// couple of seconds, and running it inline froze the entire page (orbit,
// buttons, sliders) until it finished. Here the main thread posts the topology +
// analysis + pose + options, we build, and post the triangles back; the page
// stays live the whole time.
//
// `analyze` deliberately stays on the main thread: it is ~1-2ms even on a big
// part and its result is shared with draw/orient/export, so duplicating it here
// would only add a place for the two to drift.
import { buildFins } from './fins.js';
self.onmessage = (e) => {
const { id, topology, result, rot, opts } = e.data;
try {
const built = buildFins(topology, result, rot, opts);
self.postMessage({ id, built });
} catch (err) {
// Report rather than die silently -- the main thread falls back to an inline
// build so a worker-only failure never leaves the user with no support.
self.postMessage({ id, error: String((err && err.stack) || err) });
}
};