@rulecad/model-link
A model in a link: compressed into the URL fragment, never uploaded; STL and Bambu-ready 3MF made in the browser.
npm install @rulecad/model-link
Try it
A model made in this page, packed into a link. The model rides in the link's #fragment, which browsers never send, so nothing is uploaded.
Drag to turn, scroll to zoom
Reference
Share a printable model as a link. The model is compressed into the URL's #fragment, which browsers never send to the server, so a public web page can open a private design and nothing is uploaded. It also writes STL files, and 3MF files in Bambu Studio's project layout with each part on its own filament (AMS) slot. No dependencies: it uses the browser's own CompressionStream, which Node 20+ has too.
import { fromParts, encode, decode, stl, threemf } from '@rulecad/model-link';
const model = {
title: 'Soap tray', version: '1.0.0',
...fromParts([
{ name: 'tray', triangles }, // [[[x, y, z] ×3], …], mm, Z up
{ name: 'logo', triangles: logoTriangles, slot: 2 }, // printed in the AMS's second filament
]),
};
const link = `https://your-viewer.example/#m=${await encode(model)}`;
const back = await decode(link.split('#m=')[1]);
const stlBytes = stl(back); // Uint8Array, binary STL
const zip = await threemf(back); // Uint8Array, a .3mf (one object, two parts on slots 1 and 2)
- Precision: corners are snapped to a grid about 1/5000 of the model's size, and shared corners are stored once.
- Many copies of one shape (nine keycaps):
fromShapes()stores each shape once and a transform per copy, anddecode()expands them. - Things that move: a model can carry
motion: its items, the joints between them (fixed, revolute, prismatic, cylindrical, ball, path), named poses, and which item each part moves with.jointValues(motion, pose)gives every joint's values, followers included, andplaceItems(motion, values)gives where each item is. The page uses these for its sliders, andcaduses the same functions to place an assembly, so both agree. The format is described at the top of the motion section inmodel-link.mjs. - A machine's link: a model can carry
task(the tool's anchor and the plane it moves on, with what the margins read),steps(a step file cut down bycompactSteps(file), small enough for a link),wires(routes drawn faint, never parts) andbuild(the build page's text and numbers). All of it is checked as data when a link is decoded, and a page never runs any of it. The formats are in the comment at the top of the "a machine's link" section inmodel-link.mjs. - Safety: links are data, never code.
decode()checks the format and sizes (LIMITS), refuses damaged links, and refuses links from a newer format version. A part's filament slot must be a whole number from 1 to 16, and a board's fab file must be a zip holding only a board's files (Gerbers, drill files, parts list, placement and notes, by their file extensions), so a link can't put text of its own into a 3MF or hand out any other file. The 3MF writers refuse a slot that isn't a whole number from 1 to 16 too. - Short links:
parseHash(location.hash)also reads#s=<id>, a GitHub Gist holding the data, andfromGist(id)fetches it without signing in. - The file says who made it:
stl(m, keep, { generator })andthreemf(m, keep, { generator }); the default isrulecad. - Reproducible files: a 3MF records the day it was made;
bambu3mf(objects, { date: '2026-10-14' })fixes it, so the same model gives the same bytes. bambu3mf([{ name, parts: [{ name, triangles, slot }] }])writes a 3MF from triangles directly. It has been checked by loading the files back into Bambu Studio; other slicers read the same file as plain objects.zip([[name, text], …])writes a ZIP of text files, with the platform's own compression (no library).