geom-parse-stl
Version:
Parse a STL (StereoLithography) ASCII string, ArrayBuffer or ArrayBuffer with ASCII data, and return a simplicial complex.
137 lines (93 loc) • 5.57 kB
Markdown
# geom-parse-stl
[](https://www.npmjs.com/package/geom-parse-stl)
[](https://www.npmjs.com/package/geom-parse-stl)
[](https://bundlephobia.com/package/geom-parse-stl)
[](https://github.com/dmnsgn/geom-parse-stl/blob/main/package.json)
[](https://github.com/microsoft/TypeScript)
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
[](https://github.com/eslint/eslint)
[](https://github.com/dmnsgn/geom-parse-stl/blob/main/LICENSE.md)
Parse a STL (StereoLithography) ASCII string, ArrayBuffer or ArrayBuffer with ASCII data, and return a simplicial complex.
[](https://paypal.me/dmnsgn)
[](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[](https://twitter.com/dmnsgn)
## Installation
```bash
npm install geom-parse-stl
```
## Usage
```js
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
<!-- api-start -->
## Modules
<dl>
<dt><a href="#module_geom-parse-stl">geom-parse-stl</a></dt>
<dd></dd>
</dl>
## Typedefs
<dl>
<dt><a href="#SimplicialComplex">SimplicialComplex</a> : <code>object</code></dt>
<dd><p>Geometry definition.</p>
</dd>
</dl>
<a name="module_geom-parse-stl"></a>
## geom-parse-stl
- [geom-parse-stl](#module_geom-parse-stl)
- [.parseStlAscii(asciiString)](#module_geom-parse-stl.parseStlAscii) ⇒ [<code>SimplicialComplex</code>](#SimplicialComplex)
- [.parseStlBinary(arrayBuffer)](#module_geom-parse-stl.parseStlBinary) ⇒ [<code>SimplicialComplex</code>](#SimplicialComplex)
- [.parseStl(stl)](#module_geom-parse-stl.parseStl) ⇒ [<code>SimplicialComplex</code>](#SimplicialComplex)
<a name="module_geom-parse-stl.parseStlAscii"></a>
### geom-parse-stl.parseStlAscii(asciiString) ⇒ [<code>SimplicialComplex</code>](#SimplicialComplex)
Parse a STL ASCII string and return a simplicial complex.
**Kind**: static method of [<code>geom-parse-stl</code>](#module_geom-parse-stl)
| Param | Type |
| ----------- | ------------------- |
| asciiString | <code>string</code> |
<a name="module_geom-parse-stl.parseStlBinary"></a>
### geom-parse-stl.parseStlBinary(arrayBuffer) ⇒ [<code>SimplicialComplex</code>](#SimplicialComplex)
Parse a STL ArrayBuffer or ArrayBuffer with ASCII data and return a simplicial complex.
**Kind**: static method of [<code>geom-parse-stl</code>](#module_geom-parse-stl)
| Param | Type |
| ----------- | ------------------------ |
| arrayBuffer | <code>ArrayBuffer</code> |
<a name="module_geom-parse-stl.parseStl"></a>
### geom-parse-stl.parseStl(stl) ⇒ [<code>SimplicialComplex</code>](#SimplicialComplex)
Parse a STL (StereoLithography) ASCII string, ArrayBuffer or ArrayBuffer with ASCII data, and return a simplicial complex.
**Kind**: static method of [<code>geom-parse-stl</code>](#module_geom-parse-stl)
**See**: https://paulbourke.net/dataformats/stl/
| Param | Type |
| ----- | ----------------------------------------------- |
| stl | <code>string</code> \| <code>ArrayBuffer</code> |
<a name="SimplicialComplex"></a>
## SimplicialComplex : <code>object</code>
Geometry definition.
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| ----------- | ------------------------------------------------------------------------------- | --------------------- |
| positions | <code>Float32Array</code> | |
| faceNormals | <code>Float32Array</code> | |
| cells | <code>Uint8Array</code> \| <code>Uint16Array</code> \| <code>Uint32Array</code> | |
| [name] | <code>string</code> | The STL "solid" name. |
<!-- api-end -->
## License
MIT. See [license file](https://github.com/dmnsgn/geom-parse-stl/blob/main/LICENSE.md).