Skip to content

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 shapes rings in board mm, keyed by item id; items supplies 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, Black or any CSS colour.
  • A board placed with reference() is one translucent group under References in 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 ​

InputEffect
drag, scrollorbit, zoom
hovernames the part and pad or the net, kind and layer, outlines what a click would select
click, cmd+click, shift+click, double-clickselect 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 dotedit as in 2D with the same writes, on the plane of the part's side, editing.md
corner buttonsframe the board, top, bottom, iso; toggle grid, focus fade, exploded view
explode slidergap 0 to 15 mm, 4 by default; a callout names each layer with thickness and material
hover a layer or calloutthat 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:
OptionValues
opacity25% by default, for substrate, mask, copper and bodies
colourMonochrome greys the rest
surfaceShaded, or Edges for edges sharper than 30° and no faces
depthGrouped, the default, one body; Stacked, every surface showing through

Model descriptors ​

modelUsed 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 box or no model is never solid: a dashed amber outline, its ref and no model, in the view; a shot draws its body box. A referenced board leaves it out. pcbjs model check, inspect and README-fab count it as no model, the --json report as models.missing.
  • A bare footprint, hole, test point, pogo pad, fiducial or mounting hole, per layout.md Silk refs, defaults to height 0 and draws nothing. A zero size or height box counts as no body.
  • @pcbjs/ui/models builds hashed generated meshes, shared by the view, GLB, shots and references; the view adds printed codes. Its modelMeshes(spec, context) reuses one generator and composeModel(parts) combines primitives and generated bodies with the stdlib palette. See models.md for a runnable authoring script. makeFootprint fills a chip or led model's body and height from its definition.
  • Resistor tolerance comes from .source({ tolerance: '1%' }); marking overrides the code.

Model files ​

KeyMeaning
fileSTEP or STP, glTF or GLB, or WRL by extension; a model file has no kind
offsetmm
rotatedegrees about x, y, z
scalefactor per axis
fallbackdrawn until the mesh arrives; the stdlib keeps its generated model or outline here
  • file resolves from the model literal's file: lib/parts.tsx names ../models/x.step. Absolute paths and file: 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 model note 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 off height. A matching side with wrong height reads lying on its side?.

Conversion and cache ​

  • @pcbjs/step converts each file once per content in Node: STEP through occt-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 height its height in reference-collision and a mate's default gap, references.md.
  • Site data per footprint: step: { file, mesh, transform, bounds, courtyard, issue }, no mesh when the file is missing, and a generated body's mesh.
  • Dev serves /__pcbjs/model/<hash>; pcbjs build copies used ones to models/<hash>.bin.
  • occt-import-js and OpenCascade are LGPL-2.1, unmodified.

Fetched on first use ​

fileFrom
kicad:<Lib>.3dshapes/<Name>.stepan installed KiCad library, else KiCad's packages3D on GitLab at tag 10.0.7
lcsc:C123EasyEDA'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 as kicad:…, which pcbjs import and kicadFootprint() write; in code a library model is kicad: only.
  • Downloads are shared per user under .pcbjs/models/fetched/{kicad-10.0.7,lcsc,<host>}/, with URL, licence and date in LICENSES.md. To refetch, delete the file there and its cache file shown by pcbjs 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=1 skips downloads.
  • pcbjs model fetch [entry...] downloads what is missing. pcbjs doctor shows 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.

PlatformDirectory
macOS~/Library/Caches/pcbjs
Linux$XDG_CACHE_HOME/pcbjs, else ~/.cache/pcbjs
Windows%LOCALAPPDATA%/pcbjs
anyPCBJS_CACHE_DIR when set
  • The directory, mode 0700, holds meshes/<hash>.bin keyed by content and options, boards/<hash>.bin, fetched/ and downloads/ by content hash, and index.json with each file's source, options, size and last use.
  • pcbjs model cache ls lists the files with size, last use and source; prune --older 90 removes what went unused 90 days, --max-size 500 the least recently used down to 500 MB, --all everything; path prints 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/cache holds compile stages and is separate.
  • In CI, set PCBJS_CACHE_DIR to a workspace path and cache it, keyed on the model sources such as hashFiles('**/models/LICENSES.md').

How it builds ​

  • packages/export/src/scene/geometry.ts extrudes 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.ts cuts in Node: each item less nearby drills, and covered, its part under the mask; shapes also 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 height z is (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.
  • board holds a diel:<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; then barrels and reference:<name> per reference().
  • copper:<layer> has net:<name> children, unioned less drills, and netless copper. bodies:<side> has part:<ref> children: file or generated meshes placed by the node matrix, glowing LED lenses, else body boxes.
  • Every node has extras.pcbjs: kind, ref, layer or net where they apply, and explode, its own offset in metres at full explode, 4 mm per stack step; a stacked reference carries side, F or B, and that side's bodies' explode.
  • copper:<layer> also lists items: [{ 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.

MIT licensed. A proof of concept, pre 0.1.