Avatar

dupontgu

1 public val
Joined September 7, 2023

Generates a 3D model of a flat washer, in .stl format. Pass in number parameters for washer "thickness" ("t"), "hole_radius" ("hr"), and "outer_radius" ("r"):

https://dupontgu-washer_3d.web.val.run/?t=2&hr=8&r=10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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}"`,
},
});
}
Next