geom-export-obj
Version:
Convert one (or more) simplicial complex geometry (positions/cells/normals/uvs/vertexColors) into an OBJ string (optionally optimized with number precision to reduce its size).
168 lines (117 loc) • 8.81 kB
Markdown
# geom-export-obj
[](https://www.npmjs.com/package/geom-export-obj)
[](https://www.npmjs.com/package/geom-export-obj)
[](https://bundlephobia.com/package/geom-export-obj)
[](https://github.com/dmnsgn/geom-export-obj/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-export-obj/blob/main/LICENSE.md)
Convert one (or more) simplicial complex geometry (positions/cells/normals/uvs/vertexColors) into an OBJ string (optionally optimized with number precision to reduce its size).
[](https://paypal.me/dmnsgn)
[](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[](https://twitter.com/dmnsgn)

## Installation
```bash
npm install geom-export-obj
```
## Usage
```js
import geomExportObj from "geom-export-obj";
import { cube } from "primitive-geometry";
console.log(geomExportObj(cube()).output);
```
## API
<!-- api-start -->
## Modules
<dl>
<dt><a href="#module_geomExportObj">geomExportObj</a></dt>
<dd></dd>
</dl>
## Typedefs
<dl>
<dt><a href="#SimplicialComplex">SimplicialComplex</a> : <code>object</code></dt>
<dd><p>Geometry definition. All optional.</p>
</dd>
<dt><a href="#GeomExportObjOffsets">GeomExportObjOffsets</a> : <code>object</code></dt>
<dd><p>Offsets to for cells. Useful if appending to another obj string. Used internally.</p>
</dd>
<dt><a href="#GeomExportObjOptions">GeomExportObjOptions</a> : <code>object</code></dt>
<dd><p>Options for exporter.</p>
</dd>
<dt><a href="#GeomExportObjReturnValue">GeomExportObjReturnValue</a> : <code>object</code></dt>
<dd></dd>
</dl>
<a name="module_geomExportObj"></a>
## geomExportObj
- [geomExportObj](#module_geomExportObj)
- [geomExportObj(geometries, [options])](#exp_module_geomExportObj--geomExportObj) ⇒ [<code>GeomExportObjReturnValue</code>](#GeomExportObjReturnValue) ⏏
- [.parse(geometry, [offsets], [defaultName], [precision])](#module_geomExportObj--geomExportObj.parse) ⇒ <code>string</code>
<a name="exp_module_geomExportObj--geomExportObj"></a>
### geomExportObj(geometries, [options]) ⇒ [<code>GeomExportObjReturnValue</code>](#GeomExportObjReturnValue) ⏏
Parse one or more simplicial complex geometry and return an obj string and vertices offsets.
**Kind**: Exported function
| Param | Type | Default |
| ---------- | -------------------------------------------------------------------------------------------------------------------------- | --------------- |
| geometries | [<code>SimplicialComplex</code>](#SimplicialComplex) \| [<code>Array.<SimplicialComplex></code>](#SimplicialComplex) | |
| [options] | [<code>GeomExportObjOptions</code>](#GeomExportObjOptions) | <code>{}</code> |
<a name="module_geomExportObj--geomExportObj.parse"></a>
#### geomExportObj.parse(geometry, [offsets], [defaultName], [precision]) ⇒ <code>string</code>
Parse a simplicial complex and return an obj string
**Kind**: static method of [<code>geomExportObj</code>](#exp_module_geomExportObj--geomExportObj)
**See**
- http://paulbourke.net/dataformats/obj/
- https://paulbourke.net/dataformats/obj/colour.html
| Param | Type | Default | Description |
| ------------- | ---------------------------------------------------------- | -------------------------------------------------- | --------------------------------------------------------------- |
| geometry | [<code>SimplicialComplex</code>](#SimplicialComplex) | | |
| [offsets] | [<code>GeomExportObjOffsets</code>](#GeomExportObjOffsets) | <code>{ positions: 0, normals: 0, uvs: 0 }}</code> | |
| [defaultName] | <code>string</code> | | A name for the object if geometry.name is not specified. |
| [precision] | <code>number</code> | | Decimal digit precision for positions/normals/uvs/vertexColors. |
<a name="SimplicialComplex"></a>
## SimplicialComplex : <code>object</code>
Geometry definition. All optional.
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| -------------- | --------------------------------- | ------------------------- |
| positions | <code>Array.<number></code> | |
| normals | <code>Array.<number></code> | |
| uvs | <code>Array.<number></code> | |
| cells | <code>Array.<number></code> | |
| name | <code>string</code> | The object name. |
| [materialName] | <code>string</code> | The object material name. |
<a name="GeomExportObjOffsets"></a>
## GeomExportObjOffsets : <code>object</code>
Offsets to for cells. Useful if appending to another obj string. Used internally.
**Kind**: global typedef
**Properties**
| Name | Type |
| --------- | ------------------- |
| positions | <code>number</code> |
| normals | <code>number</code> |
| uvs | <code>number</code> |
<a name="GeomExportObjOptions"></a>
## GeomExportObjOptions : <code>object</code>
Options for exporter.
**Kind**: global typedef
**Properties**
| Name | Type | Default | Description |
| ----------- | ---------------------------------------------------------- | ------------------------------------------------- | --------------------------------------------------------------- |
| [header] | <code>string</code> | <code>"# geom-export-obj\\n"</code> | Header to be prepended to the file. |
| [prefix] | <code>string</code> | <code>"Mesh\_"</code> | Prefix for object names. |
| [offsets] | [<code>GeomExportObjOffsets</code>](#GeomExportObjOffsets) | <code>{ positions: 0, normals: 0, uvs: 0 }</code> | The initial offsets for cells. |
| [precision] | <code>number</code> | | Decimal digit precision for positions/normals/uvs/vertexColors. |
<a name="GeomExportObjReturnValue"></a>
## GeomExportObjReturnValue : <code>object</code>
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| ------- | ---------------------------------------------------------- | -------------------- |
| output | <code>string</code> | The obj as a string. |
| offsets | [<code>GeomExportObjOffsets</code>](#GeomExportObjOffsets) | |
<!-- api-end -->
## License
MIT. See [license file](https://github.com/dmnsgn/geom-export-obj/blob/main/LICENSE.md).