geom-parse-stl
v1.0.0
Published
Parse a STL (StereoLithography) ASCII string, ArrayBuffer or ArrayBuffer with ASCII data, and return a simplicial complex.
Maintainers
Readme
geom-parse-stl
Parse a STL (StereoLithography) ASCII string, ArrayBuffer or ArrayBuffer with ASCII data, and return a simplicial complex.
Installation
npm install geom-parse-stlUsage
import { parseStl } from "geom-parse-stl";
import computeNormals from "geom-normals";
// Fetch the file
const url = "./MyModel.stl";
const response = await fetch(url);
const buffer = await response.arrayBuffer();
// Parse STL arraybuffer (ASCII or binary)
const geometry = parseStl(buffer);
// Optionally compute normals
geometry.normals = computeNormals(geometry.positions, geometry.cells);
console.log(geometry);
// {
// positions: Float32Array [x, y, z, x, y, z, ...],
// faceNormals: Float32Array [x, y, z, x, y, z, ...]
// cells: Uint8/16/32/Array [a, b, c, a, b, c, ...],
// normals: Float32Array [x, y, z, x, y, z, ...]
// }API
Modules
Typedefs
geom-parse-stl
geom-parse-stl.parseStlAscii(asciiString) ⇒ SimplicialComplex
Parse a STL ASCII string and return a simplicial complex.
Kind: static method of geom-parse-stl
| Param | Type | | ----------- | ------------------- | | asciiString | string |
geom-parse-stl.parseStlBinary(arrayBuffer) ⇒ SimplicialComplex
Parse a STL ArrayBuffer or ArrayBuffer with ASCII data and return a simplicial complex.
Kind: static method of geom-parse-stl
| Param | Type | | ----------- | ------------------------ | | arrayBuffer | ArrayBuffer |
geom-parse-stl.parseStl(stl) ⇒ SimplicialComplex
Parse a STL (StereoLithography) ASCII string, ArrayBuffer or ArrayBuffer with ASCII data, and return a simplicial complex.
Kind: static method of geom-parse-stl See: https://paulbourke.net/dataformats/stl/
| Param | Type | | ----- | ----------------------------------------------- | | stl | string | ArrayBuffer |
SimplicialComplex : object
Geometry definition.
Kind: global typedef Properties
| Name | Type | Description | | ----------- | ------------------------------------------------------------------------------- | --------------------- | | positions | Float32Array | | | faceNormals | Float32Array | | | cells | Uint8Array | Uint16Array | Uint32Array | | | [name] | string | The STL "solid" name. |
License
MIT. See license file.
