$ show xyz-tools/gcode-preview
gcode-preview is a TypeScript library for rendering 3D-print toolpath previews from G-code files in web applications. It parses G-code command streams, interprets motion and extrusion commands, organizes the resulting paths into layers and tool segments, and renders them as either flat colored lines or volumetric tubes using Three.js. The library is structured as a pipeline of independently testable modules: a line-oriented parser, a stateful interpreter, a job/path model, and a Three.js scene manager. A Vue 3 demo application is included to exercise the library, but the repository is fundamentally a reusable npm package with ESM and UMD builds, unit tests, Firebase-hosted demo infrastructure, and publishing CI.
The LLM identified 4 files worth highlighting for reuse:
A self-contained G-code line parser that tokenizes commands, extracts parameters, and captures embedded thumbnail metadata. It can be extracted and reused for G-code analysis, validation, or preprocessing, and its streaming support handles large files without loading the entire input into memory.
ExtrusionGeometry builds a custom Three.js BufferGeometry that renders polylines as volumetric tubes with configurable diameter. This is a reusable WebGL rendering component for any path/tube visualization, avoiding reliance on heavyweight CAD geometry libraries.
TravelTypeIndexer, LayersIndexer, and ToolIndexer implement a small strategy pattern for slicing path collections by movement mode, layer height, or tool number. The indexer interfaces are generic enough to be reused in any structured path or track dataset that needs multiple access paths.
A self-contained Three.js ShaderMaterial helper that supports per-point color attributes and clipping planes, designed for rendering many colored line segments efficiently. It can be dropped into other Three.js projects requiring high-performance colored polyline visualization.