A simple GCode parser & previewer lib with 3D printing in mind. Written in Typescript.
A simple GCode parser & previewer lib with 3D printing in mind. Written in Typescript.
A simple G-code parser & viewer lib with 3D printing in mind. Written in Typescript.
Join us on discord
11-11-2024 This repo was moved to a brand new org which is a collaboration between @remcoder and @sophiedeziel for everything 3D printing related.
ReadableStream);WIDTH: / ;HEIGHT: slicer comments (adaptive layer height)try it out: https://codepen.io/remcoder/pen/PwYVXBg
Click to see the full-fledged demo:
The 3.0 release is currently in alpha. To install the latest alpha:
npm install gcode-preview@alpha
For the current stable 2.x release:
npm install gcode-preview
GCode Preview depends on three.js and supports three >=0.166.0 and ;HEIGHT: comments (emitted by PrusaSlicer,
SuperSlicer, OrcaSlicer and Bambu Studio) are picked up by the slicer metadata
pipeline and set the extrusion width and line height of the paths that follow,
so prints sliced with adaptive layer height render with the true dimensions of
each path. Dimensions resolve per path: the slicer-announced value wins, the
lineHeight / extrusionWidth options fill in for paths without one, and the
built-in defaults (0.6 width / 0.2 height) apply last.
GCode files that were sliced for a multi-tool system can be previewed as such. Pass an array of colors as the extrusionColor constructor option (or assign preview.sceneManager.extrusionColor at runtime), where the index in the array corresponds to the index of the tool: T0..T7.
example:
extrusionColor: ['hotpink', 'indigo', 'lime']Here, T0 is hotpink, T1 is indigo and T2 is lime.
Supported systems include:
Extrusions are rendered as tubes by default; pass renderTubes: false as a
constructor option to render flat lines (it can also be toggled at runtime
via preview.sceneManager.renderTubes):
new GCodePreview({ canvas, renderTubes: false });Thanks to @Sindarius arc commands are now supported, which means gcode processed by ArcWelder should be rendered correctly.
Thumbnail previews as generated by PrusaSlicer are detected and parsed. In the gcode these are found in comments, enclosed between 'thumbnail begin' and 'thumbnail end'. The images are encoded as base64 strings but split over multiple lines. These are now parsed and patched back together, but still kept a base64. This allows easy use in the browser for us as data urls.
Thumbnail Preview as generated by PrusaSlicer
The thumbnails can be accessed like this:
gcodePreview.parser.metadata.thumbnails['220x124']
Thumbnails have a .src property that will create a usable data url from the base64 string.
See an example in the demo source.
The build volume will be rendered if the buildVolume parameter is passed. It has the following type:
buildVolume: {
x: number;
y: number;
z: number;
smallGrid?: boolean;
}Negative dimensions are clamped to 0.
example:
To develop on gcode-preview run:
npm i && npm run dev
This runs the demo app which is fairly complete in using the libs features.
If you don't need the demo app, just run npm run dev:watch.
Both build a dev bundle in the dist directory.
Note the dev bundle:
See CONTRIBUTING.md for the full guidelines. In short, before submitting a PR run:
npm run check (test + typeCheck + lint)npm run build for a production buildnpm run test:coverage — CI requires 100% coverage for every file under src/To auto-fix simple issues:
npm run lint:fix or npm run prettier:fixFor working on production builds you can use:
npm run demo which does a prod build and launches the demo app using local servernpm run build or npm run build:watchIf you have found a bug or if have an idea for a feature, don't hesitate to create an issue on GitHub or talk to us on Discord.
Want to help out? We are open to your ideas and always willing to get you started! talk to us on Discord.
This is caused by the device recognition shield in Brave. By changing the setting for "Device Recognition" in Shield settings to "Allow all device recognition attemps" or "Only block cross-site device recognition attemps" you should not get this error. https://github.com/mrdoob/three.js/issues/16904
A big thanks to these sponsors for their contributions.
If you want to show gratitude you can always buy me beer/coffee/filament via ko-fi or PayPal ^_^
This project is licensed under the MIT License.
No open issues yet, or sync has not completed.