Skip to content

Model mesh binary ​

pcbjs caches and serves converted model geometry in the PCBM format. This is distinct from a STEP source file, a GLB export and the JSON model descriptor. The encoder and decoder in step/binary.ts own its byte-level contract.

Encoding rules ​

All multibyte values are little-endian. The header and every block start on a four-byte boundary. Mesh positions use millimetres in the source model's frame; placement transforms belong to the consuming model descriptor. RGB values are linear, not sRGB bytes.

File header ​

OffsetTypeMeaning
04 bytesASCII PCBM
4uint16Version 2; the reader also accepts version 1
6uint16Reserved, written as zero
8uint32Mesh count

The first mesh begins at byte 12. Meshes follow consecutively in the declared order.

Per-mesh header ​

Relative offsetTypeMeaning
0, 4, 8Three float32 valuesLinear red, green and blue
12uint32Vertex count N
16uint32Index count I
20uint32Index element size S, either 2 or 4 bytes
24uint32Material JSON byte length M, version 2 only

Version 2 has a 28-byte header followed by M bytes of UTF-8 material JSON, padded to a four-byte boundary. A zero length means the legacy colour-derived material. Version 1 has a 24-byte header and no material block.

Geometry follows the header and optional material block:

  1. Positions: 3 × N float32 values, x/y/z per vertex, occupying 12 × N bytes.
  2. Normals: 3 × N signed int8 values, one x/y/z triple per vertex, padded to a four-byte boundary.
  3. Indices: I unsigned integers of size S, padded to a four-byte boundary. Three indices form a triangle.

The encoder rounds normal components multiplied by 127 and clamps to [-127, 127]. The decoder reconstructs and normalizes each triple. This is a quantized representation; normals are not preserved as original float32 values.

The encoder chooses two-byte indices for at most 65,535 vertices, otherwise four-byte indices. The next mesh starts after the final padding. Padding is not geometry and must not be interpreted as extra indices.

Materials ​

Material JSON carries the supported scalar PBR subset: metalness, roughness, opacity, alphaMode, alphaCutoff, doubleSided, linear emissive RGB and optional name. Base colour stays in the fixed header. Explicit materials use glTF defaults for omitted fields; absent material metadata retains the legacy colour heuristic. A material name labels the material; it is not a texture or shader reference.

The writer validates and orders these fields before encoding. Mesh merging includes material properties in its key, so equal colours with different surface properties remain distinct. Textures and material extensions are not represented. Conversion and generated-model cache versions must change when their output semantics change.

Reader behavior and limitations ​

The current decoder rejects a missing/short header, wrong magic, unsupported version, truncated blocks and malformed material metadata. It returns float32 position/normal arrays and uint32 indices. A zero normal triple remains zero after normalization's zero-length guard. Older readers cannot read version 2; newer readers preserve version 1's colour-only behavior.

Version acceptance and buffer bounds checks do not establish that every numeric or topology constraint is validated for arbitrary hostile files. The format requires the declared index sizes and meaningful triangle indices; do not infer a complete schema-validation guarantee from the decoder. validateMesh separately checks geometry and normal/winding consistency without repairing it or proving watertightness. This format is an implementation artifact served with the matching pcbjs build, not a promise of lossless source-model round trips.

Model conversion options, hashes, cache ownership and placement are specified in 3D descriptors and model artifacts. A change to this binary contract requires coordinated readers/writers and an appropriate format/cache compatibility review.

MIT licensed. A proof of concept, pre 0.1.