export async function washer_3d(request: Request): Promise<Response> {
const u = new URL(request.url);
const params = Object.fromEntries(u.searchParams.entries());
let t = params["thickness"] ?? params["t"];
let ir = params["hole_radius"] ?? params["hole"] ?? params["hr"];
let _or = params["outer_radius"] ?? params["r"];
if (!t || !ir || !_or) {
return new Response("Missing parameter! Please specify thickness, hole_radius, and outer_radius.");
}
t = parseFloat(t);
ir = parseFloat(ir);
_or = parseFloat(_or);
const stl = await import("npm:@jscad/stl-serializer");
const jscad = await import("npm:@jscad/modeling");
const { circle } = jscad.primitives;
const { extrudeLinear } = jscad.extrusions;
const { subtract } = jscad.booleans;
const inner = circle({ radius: ir, segments: 100 });
const outer = circle({ radius: _or, segments: 100 });
const diff = subtract(outer, inner);
const model = extrudeLinear({ height: t }, diff);
const rawData = stl.serialize({ binary: true }, model);
const blob = new Blob(rawData);
const filename = `washer-${_or}-${ir}-${t}.stl`;
return new Response(blob, {
headers: {
"Content-Type": "binary/octet-stream",
"Content-Disposition": `attachment; filename="${filename}"`,
},
});
}