Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ engine/src/nurb/threemf.py the 3MF reader, standard library only, Bambu mu
engine/src/nurb/measurements.py measured(), and the refusal to guess
engine/src/nurb/edit.py the keyword-default rewrite behind Apply
engine/src/nurb/labels.py a person's names for spots on a part, snapped to the surface and checked against each build
engine/src/nurb/text.py add_text(), lettering in the bundled fonts in engine/src/nurb/fonts/, carried as its own body for colour
engine/src/nurb/render.py headless PNG through the numpy rasterizer in raster.py
engine/src/nurb/raster.py GLB in, flat-shaded PNG out: the four views, the composite, and the PNG encoder
engine/src/nurb/slicing.py the handoff to an installed slicer, and the two numbers back
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ The chat inside the app runs the agent you already have: Claude Code, Codex, Gem

**A live view of every change.** Every edit updates the viewer without moving your camera. Orbit it and watch it evolve as you talk, and a build that fails leaves the last good version on screen.

**Sliders for every dimension.** Each parameter of the part gets a slider. Drag until it looks right, click `Apply`, and the change is saved where the AI sees it too.
**Sliders for every dimension.** Each parameter of the part gets a slider, words on the part get a text box, and choices like a font get a picker. Drag or type until it looks right, click `Save as default`, and the change is saved where the AI sees it too.

**Print problems caught before the printer.** Thirteen printability rules run against the exact solid, not an approximation: overhangs, thin walls, floating islands, warp-prone first layers, parts that tip over. Findings pin themselves to the exact faces they fired on, so a "wall too thin" warning points at the exact spot on the model.
**Text on parts.** Name tags, bin labels, filament swatches, a part number on an enclosure. Change the words by typing, and the part rebuilds as you type. Letters can stand up, be engraved, or sit flush in a second colour, and the 3MF puts them on their own filament so your slicer opens it two-colour. Text is drawn in fonts nurb ships, so a part builds the same on every computer, and a check warns when letters are too small for your nozzle.

**Print problems caught before the printer.** Fifteen printability rules run against the exact solid, not an approximation: overhangs, thin walls, floating islands, warp-prone first layers, parts that tip over. Findings pin themselves to the exact faces they fired on, so a "wall too thin" warning points at the exact spot on the model.

**Print time and filament cost up front.** The viewer's print time row drives the slicer you already have (OrcaSlicer or Bambu Studio) and answers with minutes and grams, so a design change that doubles the print time is caught while the design can still move.

Expand All @@ -46,6 +48,7 @@ The AI cannot see, so the checks are its eyes. Rules run against the exact solid

```
solids more than one body, or none: a part that came apart
text letters too small for their strokes to print
mesh a valid solid whose triangles do not close, as the slicer would see it
overhang downward faces past 45 degrees, bridges told from cantilevers
floating a region whose first layer would be laid on air
Expand Down Expand Up @@ -115,4 +118,6 @@ nurb uses **Open CASCADE Technology** (OCCT) for all B-rep geometry, reached thr

nurb **does** redistribute [three.js](https://threejs.org) (MIT), bundled into the workbench page so it works with no network. Same for the workbench's fonts, [JetBrains Mono](https://www.jetbrains.com/lp/mono/) and [Instrument Sans](https://github.com/Instrument/instrument-sans), both SIL OFL 1.1.

nurb also redistributes the fonts it draws text on parts with, each with its license beside it in `engine/src/nurb/fonts/`: [Liberation Sans](https://github.com/liberationfonts/liberation-fonts) Bold, [Archivo Black](https://github.com/Omnibus-Type/ArchivoBlack) and [Stardos Stencil](https://fonts.google.com/specimen/Stardos+Stencil) Bold, all SIL OFL 1.1.

Other dependencies: trimesh (MIT), websockets (BSD-3-Clause), numpy (BSD-3-Clause), and the official MCP SDK `mcp` (MIT), which brings starlette, uvicorn, httpx2, pydantic and jsonschema with it: 27 packages and about 27 MB in a bare venv, measured on mcp 2.2.0. Pillow (MIT-CMU) downscales reference photos before a model reads them.
32 changes: 21 additions & 11 deletions desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -794,17 +794,27 @@ function App() {
if (found) openPart(found.project_id, found.name);
}),
listen<string>("test-param", (event) => {
// The range input's own events, through React's native setter, so the
// page sees exactly what a drag produces.
const [name, value] = event.payload.split("=");
const input = document.querySelector<HTMLInputElement>(
`input[type="range"][aria-label="${name.replace(/_/g, " ")}"]`,
);
if (!input) return;
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
setter?.call(input, value);
input.dispatchEvent(new Event("input", { bubbles: true }));
input.dispatchEvent(new Event("change", { bubbles: true }));
// The control's own events, through React's native setter, so the page sees
// exactly what a drag, a keystroke or a pick produces. Split on the first "="
// only, because typed text can hold one.
const at = event.payload.indexOf("=");
const shown = event.payload.slice(0, at).replace(/_/g, " ");
const value = event.payload.slice(at + 1);
const label = Array.from(document.querySelectorAll("label")).find((l) => l.textContent === shown);
const target =
document.querySelector<HTMLElement>(`input[type="range"][aria-label="${shown}"]`) ??
(label?.htmlFor ? document.getElementById(label.htmlFor) : null);
if (!target) return;
if (target.getAttribute("role") === "radiogroup") {
Array.from(target.querySelectorAll<HTMLButtonElement>('[role="radio"]'))
.find((b) => b.textContent === value)
?.click();
return;
}
const proto = target instanceof HTMLSelectElement ? HTMLSelectElement.prototype : HTMLInputElement.prototype;
Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(target, value);
target.dispatchEvent(new Event("input", { bubbles: true }));
target.dispatchEvent(new Event("change", { bubbles: true }));
}),
];
return () => {
Expand Down
1 change: 1 addition & 0 deletions desktop/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const FIRST_RUN_PLACEHOLDERS = [
"a bracket for the 25 mm rail above my bench",
"a knob to replace the one I snapped off",
"a bin that fits the drawer, not the other way round",
"a keychain tag with my dog's name on it",
];

// A locked-down webview throws on plain access, so an unreadable store counts as
Expand Down
29 changes: 7 additions & 22 deletions engine/examples/notch/parts/fit_coupon.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# fit_coupon

<!-- AUTO: regenerated on every build. Do not hand-edit. -->
Size: 6.50 x 25.16 x 30.00 mm, 2600.6 mm3, 1 solid, 88 faces
Slivers: 65 under 1.0mm2, smallest 0.181mm2, 65 accepted
Size: 6.50 x 25.16 x 30.00 mm, 2609.5 mm3, 1 solid, 326 faces
Checks: clean
<!-- /AUTO -->

Expand Down Expand Up @@ -31,32 +30,17 @@ keep the one that feels right, then set the constant in `system.py`. Each is abo
- 30mm slab matches the light-part default, so the coupon engages a bracket the same
way a hook does.

## Accepted
## Text

The raised label is lettering, and lettering is made of small faces. All 65 are in
the glyphs; the coupon itself has no chamfers and so no corner triangles. The number
tracks whatever the label says, so a coupon built at a different clearance or bracket
count will not match it. That is tolerable here in a way it would not be on a real
part: this is a gauge, and the only surface that has to come out right is the channel.
The caption goes on with `add_text`, in the bundled font, so it builds the same on every machine and the card's numbers are the part's rather than one machine's. The checks judge the slab without the caption: a glyph's flanks are small faces and its 0.5mm relief is not a wall, and before the caption was text that `min_wall` had to be switched off here and 65 glyph slivers accepted. The text rule judges the caption on its own, which is why it is 7.5mm: at the old 6mm the bundled sans draws 0.82mm strokes, under the 1.0mm this library prints reliably.

**`min_wall` is switched off here, and that is a statement about the rule rather than
about the part.** The ray cast finds the label before it finds anything structural: it
cannot tell a relief from a wall, so it returns the lettering's 0.5mm stand-off, and on
a machine with a different system font it returns that font's stroke instead. Measured
0.500 on one build and 0.480 on another, of the same part, at different places in the
same word. No threshold can be both meaningful and stable against that.
## Accepted

The walls that matter here are not in doubt and are not the ones being measured: the web
in front of the channel is 1.8mm, and the section behind the detent dimple is 1.0mm, the
same as every 6mm slab in this library. Both are fixed by the fit geometry rather than
chosen, and neither depends on a font.
Nothing. The slab has no chamfers, so no corner triangles, and the caption's faces are the text rule's to judge.

```toml
[part]
min_wall = 0.0

[accepted]
sliver = 65
sliver = 0
```

## Don't
Expand All @@ -74,6 +58,7 @@ sliver = 65

## Changelog

- 2026-11-17: caption drawn with `add_text` in the bundled font, and 7.5mm instead of 6mm so its strokes clear the 1.0mm wall. The card now holds on every machine, and `min_wall` is back on.
- 2026-07-26: **0.25 settled.** 0.20 printed too tight to seat, 0.30 slid on loosely,
so the usable window is about 0.1mm wide and 0.25 is the middle of it. That width is
the same order as FDM extrusion variation, which is the real reason to stop here:
Expand Down
11 changes: 3 additions & 8 deletions engine/examples/notch/parts/fit_coupon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def fit_coupon(
bracket_count=1,
item_height=30.0,
item_depth=6.0,
label_size=6.0,
label_size=7.5,
label_relief=0.5,
draft=False,
):
Expand Down Expand Up @@ -48,10 +48,5 @@ def fit_coupon(
caption = f"{side_clearance:.2f}" if bracket_count == 1 else (
f"{bracket_count}x {side_clearance:.2f}"
)
front = Plane(
origin=(-item_depth, span(bracket_count), -item_height / 2),
x_dir=(0, -1, 0),
z_dir=(-1, 0, 0),
)
label = front * Text(caption, label_size)
return body + extrude(label, label_relief)
front = body.faces().filter_by(Axis.X).sort_by(Axis.X)[0]
return add_text(body, caption, front, size=label_size, depth=label_relief)
40 changes: 40 additions & 0 deletions engine/examples/tags/parts/name_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""A keychain tag with a name on it."""

from nurb import *


@part
def name_tag(
text="Biscuit",
style: Literal["raised", "engraved", "flush"] = "raised",
font: Literal["Standard", "Heavy", "Stencil"] = "Standard",
length=60.0,
width=20.0,
thickness=3.0,
ring_hole=5.0,
letter_depth=0.6,
):
"""A flat tag with a hole for the key ring and a name across the rest.

text: the name on the tag
style: raised letters stand up, engraved ones are cut in, flush ones are filled level in a second colour
font: the lettering
length: tag length, ring end included
width: tag width
thickness: plate thickness
ring_hole: diameter of the key ring hole
letter_depth: how far the letters stand up or sink in
"""
if letter_depth >= thickness:
reject(f"letter_depth {letter_depth} cuts through a {thickness}mm tag: keep it under {thickness}", param="letter_depth")
corner = width / 4
tag = extrude(RectangleRounded(length, width, corner), thickness)
ring = Pos(-length / 2 + width / 2, 0) * Cylinder(ring_hole / 2, thickness * 3)
tag = tag - ring

# Write between the ring hole and where the far end starts to round off, so the
# letters crowd neither.
start = -length / 2 + width / 2 + ring_hole / 2
end = length / 2 - corner
area = Plane.XY.offset(thickness) * Pos((start + end) / 2, 0) * Rectangle(end - start, width)
return add_text(tag, text, area.face(), style=style, font=font, depth=letter_depth)
1 change: 1 addition & 0 deletions engine/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ build-backend = "uv_build"
module-name = "nurb"
source-include = [
"src/nurb/doctrine.md",
"src/nurb/fonts/*",
"src/nurb/printers.toml",
"src/nurb/tools.json",
"src/nurb/workbench/**/*",
Expand Down
12 changes: 12 additions & 0 deletions engine/src/nurb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def dispenser(width=80, height=120, wall=2):
"""

import importlib.metadata as _metadata
from typing import Literal # noqa: F401 -- a choice parameter: style: Literal["a", "b"] = "a"

import build123d as _b3d
from build123d import * # noqa: F401,F403 -- geometry vocabulary
Expand All @@ -23,7 +24,16 @@ def dispenser(width=80, height=120, wall=2):
from .orient import stand # noqa: E402
from .polish import chamfer, polish # noqa: E402 -- must win, see below
from .registry import part, reject # noqa: E402 -- must win over any build123d name
from .text import add_text # noqa: E402

# `add_text` is here because text on a part is the most common thing people print with
# words on it, and build123d's Text quietly draws in Arial when the font it was asked
# for is missing, which builds different geometry on a different machine. This one
# only draws with the fonts nurb ships, fits the text to the face, and keeps raised
# and flush letters as their own body so they show and export in a second colour.
# `Literal` is here because a parameter with named options (a font, a style) is
# declared as `style: Literal["raised", "flush"] = "raised"`, and the viewer shows it
# as a picker. The keyword default is still the one declaration.
# `polish` is here because the doctrine prescribes the algorithm and every project
# would otherwise write it: chamfer is all or nothing, so one edge that cannot land
# takes the pass down and the set gets narrowed by hand until it builds.
Expand Down Expand Up @@ -75,6 +85,8 @@ def dispenser(width=80, height=120, wall=2):
"use",
"hinge",
"obstacle",
"add_text",
"Literal",
]
# The version lives in pyproject.toml and nowhere else; a second copy here would drift.
try:
Expand Down
11 changes: 10 additions & 1 deletion engine/src/nurb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,22 @@ def shadowed_names():
)


# typing's own docstring describes type theory, not what a part file does with it.
SAID = {
"Literal": (
'Literal["raised", "flush"]',
'Annotate a parameter with its options, `style: Literal["raised", "flush"] = "raised"`, and the viewer shows a picker.',
),
}


def entries():
"""(signature, summary) rows for each of the three groups a part file should know."""
import build123d

import nurb

own = [(_signature(o), _summary(o)) for o in (getattr(nurb, n) for n in own_names())]
own = [SAID.get(n) or (_signature(getattr(nurb, n)), _summary(getattr(nurb, n))) for n in own_names()]
shadowed = [
(_signature(o), _summary(o)) for o in (getattr(nurb, n) for n in shadowed_names())
]
Expand Down
3 changes: 2 additions & 1 deletion engine/src/nurb/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def privacy_cover(open_deg=0.0):
import sys
from dataclasses import dataclass, field

from .registry import PartDef, declared, param_docs
from .registry import PartDef, choices, declared, param_docs

# Findings come from checks.py's vocabulary so an assembly's report reads exactly like
# a part's: same severities, same line format, same sorting.
Expand Down Expand Up @@ -348,6 +348,7 @@ def wrapped(**kwargs):
params=params,
accepts_draft=True,
docs=param_docs(fn, params),
choices=choices(fn, params),
)
return wrapped

Expand Down
Loading
Loading