• Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple GCode parser & previewer with 3D printing in mind. Written in Typescript.

GCode Preview npm version MIT license Buy Me A Coffee

A simple G-code parser & viewer with 3D printing in mind. Written in Typescript.

Try the online demo

Demo Animation

Installation

npm version

npm install gcode-preview

or

yarn add gcode-preview

Quick start

  import * as GCodePreview from 'gcode-preview';

  const preview = GCodePreview.init({
      document.querySelector('canvas'),
  });
  
  // draw a diagonal line
  const gcode = 'G0 X0 Y0 Z0.2\nG1 X42 Y42 E10';
  preview.processGCode(gcode);

Vue.js / React / Svelte integration

There's a Vue.js example that has a Vue component to wrap the library.

@Zeng95 provided a React & Typescript example that has a React component to wrap the library.

There is a Svelte example with a Svelte component.

Features

G2/G3 arc support

Thanks to @Sindarius arc commands are now supported, which means gcode processed by ArcWelder should be rendered correctly.

3D WebGL + pan/zoom/rotate controls

Demo Animation

Thumbnail preview

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.

image

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.

Build volume

The build volume will be rendered if the buildVolume parameter is passed. It has the following type:

buildVolume: { 
  x: number; 
  y: number; 
  z: number
}

example:

Demo

Go try the interactive demo.

Contributing

If you have found a bug or if have an idea for a feature, don't hesitate to create an issue.

It would be great if you want to help! Maybe you'd like to help out with:

  • testing GCode Preview with a variety of gcode files, from different slicers
  • making GCode Preview suitable for different printer types, like Deltas, Belt printers, IDEX, etc.
  • reporting any bugs you find and add as much detail as possible, or even better, a screenshot
  • even better yet: send in a pull request :-)
  • apart from the main code, lots of improvements can still be made in:
    • documentation
    • unit tests

Contributors

  • ❀️ Thank you @Zeng95 for providing a React & Typescript example
  • ❀️ Thanks to @Sindarius for implementing G2/G3 arc support

Changelog

Jump to the CHANGELOG

Known issues

Preview doesn't render in Brave

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. mrdoob/three.js#16904

Sponsors

A big thanks to these sponsors for their contributions.

Q42

Duet3D

Donate

If you want to show gratitude you can always buy me beer/coffee/filament via a Paypal donation ^_^

More Repositories

1

Pxxl.js

With pxxl.js and the included BDF font files you can 'render' a text to an array of pixel coordinates. You can then use the pixel coordinates to do your own drawing.
JavaScript
121
star
2

chronos

Reactive time utilities for Meteor. Includes reactive replacements for new Date() and moment().
JavaScript
37
star
3

computron

Computron is for creating reactive computations, just like ReactiveVar is for reactive values
JavaScript
8
star
4

OctoPrint-GCodeThumbs

OctoPrint plugin to enrich the file list with a preview thumbnail for each gcode file.
Python
8
star
5

dataroles.js

Clean separation of style vs behavior using data-* attributes.
JavaScript
8
star
6

retrofyme

See yourself in 8bit retro style. By leveraging the GetUserMedia api and the color palettes of some good old 8-bit computers, a 'retrofied' version of yourself is rendered.
HTML
4
star
7

realstuffforabstractpeople.com

my website
JavaScript
3
star
8

SublimeHandcraft

A Sublime Text 2 plugin for working with Handcraft prototypes
Python
3
star
9

konami

Run a callback when the Konami code is entered
JavaScript
3
star
10

retrofy

convert the font and colors of a webpage to give it that good ol' 8-bit look we so love :-P
JavaScript
3
star
11

quat.js

quaternion math
JavaScript
2
star
12

cube-puzzle

Hey Russ, here's your darn puzzle.
TypeScript
1
star
13

rgb_plasma

JavaScript
1
star
14

on-demand

Film1 On Demand movies sorted by IMDB rating
CSS
1
star
15

rgb-matrix

Web interface to control a ColorDuino LED matrix
JavaScript
1
star
16

Milight-Remote-Control

Demo Android App to Remote Control Milight lamps via the v6 wifi bridge
Kotlin
1
star
17

gcode-preview-vue-demo

This example project demonstrates the use of my gcode-preview in a Vue.js app.
G-code
1
star
18

PrintSchedule

Simple 3D Print Schedule for my good friend Russell ⚑️
Svelte
1
star
19

RijksMemoryGame

JavaScript
1
star
20

frans

website for my father-in-law
Python
1
star
21

bbh

website for my brother in-law
JavaScript
1
star
22

polyhedral-dice-calculator

Simple Android app for rolling any combination of RPG dice, as simple as using a calculator. You can even roll non-existent dice like 1d3 or 1d7! Just enter the formula and ROLL!
Kotlin
1
star
23

sudoku-colors

Each cell is colored dynamically, based on the number of filled in cells in its row (red), column (blue) and quadrant (green). This gives each sudoku a unique color pattern. Also whenever a number is added, the colors change accordingly. So when there are no more valid options, everything is white and you have completed the sudoku.
JavaScript
1
star