3d.jhampton.io (print library and parametric template maker)
3d-printingthreejsphp3mfstlparametricbambu
3d.jhampton.io (site name "Build Plate") serves 3D print files with an in-browser viewer and hosts /create, a client-side maker for customizable prints (Cat Tag, Keychain, Name Plate, Gridfinity Bin and Baseplate, Box, Battery Holder, Cable Clip, S-Hook, Door Hook, Phone Stand, Plant Marker). It is set up for Justin's Bambu Lab X2D (Bambu Lab X2D (Justin's printer)). Source ~/dev/justinahampton/3d/ (read 3d/README.md first), deploy tools/deploy-3d.sh, harness tests/3d/run.sh.
The library
- PHP front controller via
FallbackResource; model pages with a three.js viewer (STL, 3MF, OBJ) showing size in mm, triangle count and volume; downloads; print settings; notes. - No bucket: print files are small, so uploads go through the server to disk (
/var/www/3d-data/,models.json+files/<slug>/), 256 MB ceiling in nginx. Files are streamed byfile.php, looked up in the catalog (A JSON file as the database (flat-file catalogs)). - Thumbnails are WebP snapshots the browser takes from the viewer (auto on first open, retake from any angle).
- Colors come from the file. The site has its own 3MF reader (
assets/threemf.js) because three's 3MFLoader replaced every material with one: it reads core base materials and color groups, components (includingp:pathparts in a second model file), Bambumodel_settings.config(filament per part),project_settings.configfilament_colour, and whole-trianglepaint_color, producing one mesh per color. See 3MF files and the Bambu Studio project layout. - Admin API auth = session plus an
X-3D-Adminheader, or anX-3D-Tokenfor the CLI.
The template maker (/create)
- Registry
lib/templates.phpplus one module per template exporting{fields, build(values), tips, filename}.buildreturns parts[{name, color, only?, geometry}]: three.js geometry in mm, Z up, sitting on z=0, non-indexed, watertight.only: '3mf'keeps a part (like a flush inlay) out of the STL. - Everything is client-side; nothing typed reaches the server. Values persist per template in
localStorage, so a changed default only shows after "reset". - Three downloads: Bambu Studio project (default; embeds real X2D settings and per-part filament assignments), STL, plain 3MF.
- Every template gets a filament-type select, and color fields offer only that filament's real Bambu colors (41 types, 291 colors, generated from Bambu Studio's
filaments_color_codes.json). - The recipe travels in the file: the Bambu download carries
Metadata/create_recipe.json({v, template, values}), so an uploaded model can be reopened as "edit a copy in Create". Text cannot be recovered from a mesh, so files made before this have no recipe. build()may throwrefuse(reason)when the part will not fit the bed; a failed build disables downloads instead of leaving the previous model downloadable.
Design rules learned from Justin
- Build what he names. He asked for a "sphere" tag shape; a flat-topped dome labeled "Sphere" came back with "By 'sphere', I meant sphere." Build the literal thing and state the consequence in the product (a ball touches the bed at one point: supports and a brim; the ball download turns
enable_supporton). Offer alternatives in addition, never as silent substitutes. - Cat Tag defaults are his (canon since 2026-10-10): circle, 38 mm, 4.5 mm thick, letters flush (cut 0.6 mm and filled by a second-color inlay).
- Text can be raised or inset (negative height); flat shapes cut reverse text into the underside, mirrored to read when turned over like a page, so the tag still prints flat.
- Functional parts are side profiles extruded and printed lying down so layers run along the load (hooks, clips, stands). A door hook is 3 mm thick because that is the gap above a door. A slot for a printed foot is thickness + 0.4 mm. All functional fits are unprinted guesses until a real print says otherwise.
Phone UI lessons
- A sticky 3D preview above a long form fights the on-screen keyboard. The fix: the preview scrolls away to a 128 px pinned mini-preview (tap to open over the form); focusing a field closes it and moves the field under the strip using
visualViewport. The stage box never changes height (negative stickytop, frozen--stage-h), so there is no layout shift or scroll-anchoring feedback. touch-action: noneon a 3D viewer makes a thumb orbit instead of scroll. Usepan-ywith one finger scrolling the page and two fingers to tilt and zoom.- Number fields get -/+ steppers (phones have no spinner and often no minus key); avoid
inputmode=decimalon fields that can go negative. - Custom controls (color popover with swatches, picture tiles, segmented switches) overlay a hidden native
<select>that still holds the value, so forms and tests keep working.
See also
- Slicing from the command line with Bambu Studio (flatpak), including two-color prints
- Generating watertight print meshes in code (three.js, earcut, manifold)
- three.js in a static site (bundling, viewers, snapshots)
- Gridfinity dimensions (bins and baseplates)
Linked from
- 3MF files and the Bambu Studio project layout
- Bambu Lab X2D (Justin's printer)
- Designing a printable replacement part from photos and calipers
- Generating watertight print meshes in code (three.js, earcut, manifold)
- Gridfinity dimensions (bins and baseplates)
- justinahampton.com and its subdomains
- Slicing from the command line with Bambu Studio (flatpak), including two-color prints
- three.js in a static site (bundling, viewers, snapshots)