@scalenc/stl-to-png
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

stl-to-png

Create PNG images from 3D STL files. Creates beautifully rendered PNG output server-side with no GPU from ASCII and Binary STL's.

This code is forked from node-stl-to-thumbnail which is a fork from node-stl-thumbnailer by instructables. This fork adds typescript support and unit tests.

Installation

To install the this package, simply use your favorite package manager:

npm install stl-to-png
yarn add stl-to-png
pnpm add stl-to-png

Usage

The following snippet loads a file from the current directory (./input.stl), and creates a 500x500 PNG image in the current directory called ./output.png.

import { stl2png } from 'stl-to-png';
import fs from 'fs';
import path from 'path';

const stlData = fs.readFileSync(path.join(__dirname, 'input.stl'));
const pngData = stl2png(stlData, { width: 500, height: 500 });
fs.writeFileSync(path.join(__dirname, 'output.png'), pngData);

The following snippet adds some more styling to the previous example assuming a texture image metal.jpg in the current directory.

import { makeStandardMaterial, makeEdgeMaterial, makeLambertMaterial, makeTexture, stl2png } from 'stl-to-png';
import fs from 'fs';
import path from 'path';

const stlData = fs.readFileSync(path.join(__dirname, 'input.stl'));
const metal = fs.readFileSync(path.join(__dirname, 'metal.jpg'));
const pngData = stl2png(stlData, {
  materials: [makeLambertMaterial(0.2, makeTexture(metal)), makeStandardMaterial(0.7, 0x3097d1)],
  edgeMaterials: [makeEdgeMaterial(0.1, 0x287dad)],
});
fs.writeFileSync(path.join(__dirname, `output.png`), pngData);

Development

# build the code
yarn build

# unit tests
yarn test

CI

All branches are built and tested using Gitlab CI. Changes on the master branch will be deployed to npm.js

License


MIT

Package Sidebar

Install

npm i @scalenc/stl-to-png

Weekly Downloads

79

Version

1.1.2

License

MIT

Unpacked Size

159 kB

Total Files

18

Last publish

Collaborators

  • daniel.scalenc
  • stephan.scalenc