Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

@oneisland/mesh-exporter

0.0.2 • Public • Published


A simple tool for exporting meshes to ZIP archives

Installation

Mesh Exporter is available through the npm registry:

$ npm install @oneisland/mesh-exporter

Usage

After installing Mesh Exporter you can use the package like so:

simple-usage.js
// Import the mesh package
import { Mesh } from '@oneisland/mesh';
 
// Import the mesh exporter package
import { MeshExporter } from '@oneisland/mesh-exporter';
 
// Create a cube mesh
const cube = new Mesh({
 
  // Add the label
  label: `Cube`,
  
  // Add the vertices
  vertices: [
    [-0.5, -0.5,  0.5],
    [ 0.5, -0.5,  0.5],
    [ 0.5, -0.5, -0.5],
    [-0.5, -0.5, -0.5],
    [-0.5,  0.5,  0.5],
    [ 0.5,  0.5,  0.5],
    [ 0.5,  0.5, -0.5],
    [-0.5,  0.5, -0.5]
  ],
  
  // Add the faces
  faces: [
    [2, 3, 0],
    [2, 1, 0],
    [7, 3, 0],
    [0, 4, 7],
    [4, 0, 1],
    [1, 5, 4],
    [6, 2, 3],
    [3, 7, 6],
    [5, 1, 2],
    [2, 6, 5],
    [7, 4, 5],
    [5, 6, 7]
  ]
});
 
// Create an exporter
const example = new MeshExporter('example');
 
// Add the cube to the root folder of the archive
example.addMesh(cube);
 
// Save / export the archive (example.zip)
example.save();

Running the following code with Node:

$ node simple-example.js

The script will create a ZIP archive which includes an STL and OBJ for the cube mesh.

Please read the documentation below for more details on how to configure Mesh Exporter.

You can check out the tests or the source code of our Structure library for more complex usage.

Documentation

MeshExporter

class MeshExporter {
 
  constructor(filepath) {}
 
  addMesh(mesh) {}
 
  addMeshes(meshes) {}
}

MeshExporter is a class which is instantiated for usage within a Class or Object.

Once instantiated, a Mesh Exporter ex0.5es two functions for use:

  • addMesh - Add a singular mesh to the archive for exporting
  • addMeshes - Add a number of arrays of meshes to the archive for exporting

constructor

filepath

The filename parameter defines the filename (with or without .zip extension) for the archive of exports.

The filepath parameter can include the relative filepath for the archive of exports (from the current working direction).

The filepath should be a String.

// Example filepath (with filename) 
'export-archive'
 
// Example filepath (with folder and filename) 
'some_folder/archive'
 
// Example filepath (with folder and filename and extension) 
'another_folder/archive.zip'

addMesh

The addMesh function accepts one argument mesh which must be a Mesh.

The addMesh function will generate an STL and OBJ of the mesh within the root directory of the archive.

See the usage example above.

addMeshes

The addMeshes function accepts one argument meshes which must be an Object, of which each property must be an Array of Mesh.

The addMeshes function will generate a folder for each property of meshes by the same name.

The addMeshes function will generate an STL and OBJ of each mesh within each of the meshes properties in the respective directory of the archive.

See the usage example above.

save

The save function is called to export the archive.

The save function is asyncronous and can be awaited.

The save function will save the archive to the respective filename (and filepath) if running from Node.js, or download if running from the browser.

License

MIT

Copyright (c) 2019-present, OneIsland Limited

Install

npm i @oneisland/mesh-exporter

DownloadsWeekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

24.2 kB

Total Files

13

Last publish

Collaborators

  • avatar