3D descriptors and model artifacts
3D geometry, generated and imported models, and their cache. Advanced. Clicks name the same items as in 2D. Fetching and fitting model files: models.md.
ts
import { R0603, PinHeader } from '@pcbjs/lib'
const R1 = R0603('5.1k', { model: { file: './models/R_0603_1608Metric.step' } })
const J2 = PinHeader(4)({ model: { file: 'kicad:Connector_PinHeader_2.54mm.3dshapes/PinHeader_1x04_P2.54mm_Vertical.step', offset: [0, 0, 0], rotate: [0, 0, 0] } })What it draws
- Pads, tracks, vias, zones, graphics and text use
shapesrings in board mm, keyed by item id;itemssupplies kind, layers, net, ref, pad and drill. - Copper uses stackup thickness and depth.
- Each net and layer forms one seamless copper region under its mask skin. Hover, click and source highlights identify individual items, drawn over the merge while lit.
- A plated hole has a barrel; a drill cuts board, copper and silk, a slot a stadium as the drill file routes it. NPTH holes cut the mask too.
- The mask is a slab with pad openings plus a skin over outer copper. Mask and silk colours come from the stackup:
Green,Blackor any CSS colour. - A board placed with
reference()is one translucent group underReferencesin the layer list, references.md. Exploded, a stacked one moves with its mating side's parts. - Rail visibility also controls 3D.
- Findings use 2D dots, viewer.md: DRC on its layer, ERC on its pad or part, following explode in one camera-facing instanced draw; click to frame. Ratsnest dashes: 1.2 px at fit, 0.8 to 2.5 by zoom, 1.5 times with a finding, twice focused, marching only when focused; labels per viewer.md.
Interaction
| Input | Effect |
|---|---|
| drag, scroll | orbit, zoom |
| hover | names the part and pad or the net, kind and layer, outlines what a click would select |
| click, cmd+click, shift+click, double-click | select as in 2D, viewer.md: the level's child, the leaf, add or remove, enter |
drag a selected part, the ring, a control point; R, L, a dot | edit as in 2D with the same writes, on the plane of the part's side, editing.md |
| corner buttons | frame the board, top, bottom, iso; toggle grid, focus fade, exploded view |
| explode slider | gap 0 to 15 mm, 4 by default; a callout names each layer with thickness and material |
| hover a layer or callout | that callout opaque, every other layer dimmed |
- Framing includes board, parts, references and exploded stack, excluding the grid, which uses 2D steps. Explode toggles refit in the same view; its slider keeps framing; reduced motion jumps.
- Focus controls open below their button, and the explode slider shows its separation in millimetres. Selection badges wrap below the controls; pointer bubbles flip at the viewport edges and follow without a position transition.
- Mask skins use their physical stack height without a depth bias toward the camera, so transparent solder mask cannot cover the silkscreen above it at overview zoom. Layer hover and fading preserve this ordering.
- Callouts stand in one column right of the stack, leaders from each layer's rightmost point; part and silk planes show the outline and a faint grid.
- The selection is a silhouette outline from an id buffer, highlight.md; what a live rebuild made stale turns see-through, never picked.
- A selection fades the rest, viewer.md; the popover under the focus fade button, remembered per browser, sets:
| Option | Values |
|---|---|
| opacity | 25% by default, for substrate, mask, copper and bodies |
| colour | Monochrome greys the rest |
| surface | Shaded, or Edges for edges sharper than 30° and no faces |
| depth | Grouped, the default, one body; Stacked, every surface showing through |
Model descriptors
model | Used by |
|---|---|
{ kind: 'chip', part: 'R' | 'C' | 'L' | 'D', body: [l, w], cap, height, marking? } | chip passives, cap the end cap length; a resistor prints resistorCode, such as 331 |
{ kind: 'led', body, height, cap, color?, lens? } | chip LEDs: an opaque lens in the color of chip(), stdlib.md, else grey-white |
{ kind: 'led', body, height, window, lead, color? } | PLCC-4 LEDs such as WS2812B: lens window diameter, lead pad size |
{ kind: 'header', pins, rows, pitch, pinLength? } | PinHeader |
{ kind: 'sot23', pins: 3 | 5 | 6 } | SOT-23, SOT-23-5 and SOT-23-6 |
{ kind: 'ic', w, h, height, color? } | SOT-223, SOIC, TSSOP, QFN, QFP |
{ kind: 'box', w, h, height, reason? } | no model: your own footprint without one, or a fetched model not downloaded |
{ file, offset?, rotate?, scale?, fallback? } | a STEP, glTF or WRL file; the stdlib's switches, crystals, connectors, modules and battery holder fetch theirs |
- A
boxor nomodelis never solid: a dashed amber outline, its ref andno model, in the view; a shot draws its body box. A referenced board leaves it out.pcbjs model check,inspectand README-fab count it asno model, the--jsonreport asmodels.missing. - A bare footprint, hole, test point, pogo pad, fiducial or mounting hole, per layout.md Silk refs, defaults to
height0 and draws nothing. A zero size or height box counts asno body. @pcbjs/ui/modelsbuilds hashed generated meshes, shared by the view, GLB, shots and references; the view adds printed codes. ItsmodelMeshes(spec, context)reuses one generator andcomposeModel(parts)combines primitives and generated bodies with the stdlib palette. See models.md for a runnable authoring script.makeFootprintfills achiporledmodel'sbodyandheightfrom its definition.- Resistor tolerance comes from
.source({ tolerance: '1%' });markingoverrides the code.
Model files
| Key | Meaning |
|---|---|
file | STEP or STP, glTF or GLB, or WRL by extension; a model file has no kind |
offset | mm |
rotate | degrees about x, y, z |
scale | factor per axis |
fallback | drawn until the mesh arrives; the stdlib keeps its generated model or outline here |
fileresolves from themodelliteral's file:lib/parts.tsxnames../models/x.step. Absolute paths andfile:URLs stay. Shared sibling libraries resolve from the importing project's source root in CLI, project and workspace sessions, independently of the server working directory.- The frame is KiCad's, a
.kicad_mod(model ...)line maps one to one: mm, origin at the footprint origin, x along footprint x, y along footprint -y, z up. Scale, then turn by the negated angles about x, y, z, then offset. - Units: STEP carries its own; glTF is metres, y up; WRL is KiCad's 2.54 mm unit. A back part turns over about its y axis.
- A missing file is the ERC warning
model-missing; the view draws the fallback. - glTF/GLB preserve linear base RGB, metalness, roughness, opacity/alpha mode and cutoff, double-sidedness and emissive RGB through the mesh cache, live view and GLB export. Textures, normal maps, skinning, animation and material extensions are not supported. Export static triangle geometry with scalar materials; Draco and meshopt compression are rejected. A colour-only STEP/WRL or legacy mesh keeps the existing metal/plastic heuristic.
- Referenced boards keep these surface properties and sidedness beneath their reference tint. Reference opacity overrides the source alpha mode and cutoff so the assembly stays visible as a mechanical reference.
- An amber outline and Part panel
modelnote flag boxes over 1 mm beyond the courtyard or under a fifth of it, tops below the board face, SMD bodies over 0.2 mm into it, or heights over 1.6 times offheight. A matching side with wrong height readslying on its side?.
Conversion and cache
@pcbjs/stepconverts each file once per content in Node: STEP throughocct-import-js, OpenCascade in WASM, glTF, GLB and WRL through its own readers. Curved faces within 0.02 mm and 0.3 rad; meshes merge only when colour and supported material properties match. STEP is imported, not generated.- PCBM v2 stores material properties with geometry; the reader also accepts v1 colour-only meshes. Converter and generated-model version keys invalidate old caches after material or geometry changes.
- Referenced-board caches include these model versions too; existing packaged reference data remains readable with its original format version.
- The mesh is
.pcbjs/models/<hash>.bin, the sha256 of content and options, converted once per user. - The stage cache keys on each model file's content: one that appears, changes or goes reruns the 3D model and
model-missing; a fetched one still waiting is watched where it lands. - The model box gives a footprint without
heightits height inreference-collisionand a mate's defaultgap, references.md. - Site data per footprint:
step: { file, mesh, transform, bounds, courtyard, issue }, nomeshwhen the file is missing, and a generated body'smesh. - Dev serves
/__pcbjs/model/<hash>;pcbjs buildcopies used ones tomodels/<hash>.bin. occt-import-jsand OpenCascade are LGPL-2.1, unmodified.
Fetched on first use
file | From |
|---|---|
kicad:<Lib>.3dshapes/<Name>.step | an installed KiCad library, else KiCad's packages3D on GitLab at tag 10.0.7 |
lcsc:C123 | EasyEDA's model of the LCSC part, as pcbjs model add lcsc:C123 |
https://… | the URL |
- A KiCad file's
${KICAD9_3DMODEL_DIR}/…and KiCad's other model variables are read askicad:…, whichpcbjs importandkicadFootprint()write; in code a library model iskicad:only. - Downloads are shared per user under
.pcbjs/models/fetched/{kicad-10.0.7,lcsc,<host>}/, with URL, licence and date inLICENSES.md. To refetch, delete the file there and its cache file shown bypcbjs model cache ls. - Each compile fetches in a child process. Failures keep the dashed outline and clean checks, printing the parts and
pcbjs model fetch.PCBJS_OFFLINE=1skips downloads. pcbjs model fetch [entry...]downloads what is missing.pcbjs doctorshows the KiCad library and cache.- No model file ships in a package: @pcbjs/lib holds each model's source and alignment.
Model cache
Converted, generated and referenced-board meshes, fetched models and pcbjs model add downloads are shared per user. Each project's .pcbjs/models hard-links them, copying when links fail; other projects reuse conversions and downloads.
| Platform | Directory |
|---|---|
| macOS | ~/Library/Caches/pcbjs |
| Linux | $XDG_CACHE_HOME/pcbjs, else ~/.cache/pcbjs |
| Windows | %LOCALAPPDATA%/pcbjs |
| any | PCBJS_CACHE_DIR when set |
- The directory, mode 0700, holds
meshes/<hash>.binkeyed by content and options,boards/<hash>.bin,fetched/anddownloads/by content hash, andindex.jsonwith each file's source, options, size and last use. pcbjs model cache lslists the files with size, last use and source;prune --older 90removes what went unused 90 days,--max-size 500the least recently used down to 500 MB,--alleverything;pathprints the directory.- Pruning never breaks a project: links keep their files; a missing one converts or downloads again.
- An unwritable directory leaves the project cache alone, saying so once.
.pcbjs/cacheholds compile stages and is separate.- In CI, set
PCBJS_CACHE_DIRto a workspace path and cache it, keyed on the model sources such ashashFiles('**/models/LICENSES.md').
How it builds
packages/export/src/scene/geometry.tsextrudes copper, silk, mask skins, pours and holed slabs in whole batches on a web worker pool. Many-holed pours triangulate per cell. Clipper unions each net's copper less drills; each layer, skin side or body material is one draw.packages/export/src/items.tscuts in Node: each item less nearby drills, andcovered, its part under the mask;shapesalso holds each side's mask openings.- Geometries are cached by their rings' hash; a small board builds on the main thread.
The GLB
pcbjs build, build --lib and pcbjs shot generate one board GLB, see render.md. Build writes boards/<name>.glb, cached by board and model content.
- Metres, y up: board
(x, y)at heightzis(x, z, y) / 1000, so the top is +y and the board reads unmirrored from above. Flat faces carry no normals; a reader shades them by their winding. boardholds adiel:<n>slice per dielectric, its outer faces a PNG of the laminate, the finish in the mask openings and the edge cuts, at most 4096 px square and mipmapped.- Beside it, one node per stack group, bottom to top:
bodies:B,B.SilkS,B.Mask,copper:B.Cu, inner copper,copper:F.Cu,F.Mask,F.SilkS,bodies:F; thenbarrelsandreference:<name>perreference(). copper:<layer>hasnet:<name>children, unioned less drills, andnetlesscopper.bodies:<side>haspart:<ref>children: file or generated meshes placed by the node matrix, glowing LED lenses, else body boxes.- Every node has
extras.pcbjs:kind,ref,layerornetwhere they apply, andexplode, its own offset in metres at full explode, 4 mm per stack step; a stacked reference carriesside,ForB, and that side's bodies'explode. copper:<layer>also listsitems: [{ uid, kind, net, accessor }]: each item's face away from the board as an accessor of triangle corners in metres, never drawn, so a pad in a merged pour can be selected and framed by its uid.
Placement previews replace original copper until layers arrive or cancellation. Unrelated pieces and merged members stay visible.