Coder Social home page Coder Social logo

codelenny / stljs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cubehero/stljs

0.0 2.0 0.0 355 KB

Read and write STL (3D printable model) files to your heart's content

License: MIT License

Ruby 3.64% JavaScript 43.23% CoffeeScript 53.12%

stljs's Introduction

Stljs

A fast library to read and write STL files from Cubehero. It also allows you to export to PNG using POV-RAY.

Note: Currently, the readFile works for both binary and ascii files, but writing STL files is only in ASCII

This currently only works on node.js, but will expand to browser stl parsing soon

This is a fork of cubehero/stljs with a few bugs patched.

How to install

npm install @codelenny/stljs

If you'd like to also be able to render STL files, you'll need to install a program called pov-ray.

If you're on a mac, you can install it using homebrew.

brew install povray

If you're using ubuntu, you can install it using aptitude

aptitude install povray

Getting started

You have an STL file that you want to read. Here's what you do:

stljs = require('@codelenny/stljs')

stljs.readFile('teapot.stl'
  , (err, solid, name) ->
    # can now do stuff with solid
  , (err, polygon, name) ->
    # gets called on as each polygon is parsed
)

The readFile takes two functions, a callback when the parsing is done, and an optional progress callback, which gets called as each polygon is parsed.

Converting STL to PNG

Sometimes, you want to convert an STL file into a PNG file. To do that, we can

stljs = require('@codelenny/stljs')

stljs.imageify('teapot.stl', { width: 200, height: 100, dst: 'teapot.png' }
  , (err, povOutput, name) ->
    # done with converting the image
  , (err, povPolygon, name) -> 
    # called on each polygon is processed
)

NOTE: In order to use this feature, you need to have pov-ray installed on your system already. This can be installed separately through 'aptitude' on linux and 'brew' on macs

Contributing

Post an issue under 'issues' above, to see if what you want to do isn't already being in the works. Then submit a pull request.

License

MIT license

stljs's People

Contributors

iamwilhelm avatar codelenny avatar

Watchers

James Cloos avatar  avatar

stljs's Issues

Fix -s

povray is failing with the -s option. Switch to -D.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.