npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gcode-preview

v2.15.0

Published

Preview a 3d print from a gcode file

Downloads

201

Readme

GCode Preview npm version MIT license

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

Try the online demo

Installation

npm version

npm install gcode-preview

or

yarn add gcode-preview

Quick start

  import * as GCodePreview from 'gcode-preview';

  const preview = GCodePreview.init({
      canvas: document.querySelector('canvas'),
      extrusionColor: 'hotpink'
  });
  
  // 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

New: multi-color support

Experimental: render extrusion as tubes

renderTubes : true

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 @sophiedeziel for rendering extrusion as tubes.
  • ❤️ Thank you @Sindarius for implementing G2/G3 arc support.
  • ❤️ Thank you @Zeng95 for providing a React & Typescript example.

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. https://github.com/mrdoob/three.js/issues/16904

Sponsors

A big thanks to these sponsors for their contributions.

Donate

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