Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
A JS generator function that returns a list of vertices describing an isosuface given a density and level.
JavaScript HTML
Branch: master
Clone or download
Cannot retrieve the latest commit at this time.
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
.gitignore
.npmignore
LICENSE.md
README.md
index.js
package.json
screenshot.png

README.md

isosurface-generator

A JS generator function that returns a mesh describing an isosuface given a density and level. Since it's a generator function, you can perform this expensive calculation in a way that allows you to keep your UI responsive.

DEMO

Install

npm install isosurface-generator

Example

const isosurfaceGenerator = require('isosurface-generator');
const ndarray = require('ndarray');

const size = 8;

const density = ndarray(new Float32Array(size*size*size), [size, size, size]);

for (let i = 0; i < 1000; i++) {
  density.set(
    Math.floor(Math.random() * size),
    Math.floor(Math.random() * size),
    Math.floor(Math.random() * size),
    Math.random()
  );
}

let mesh;

for (let data of isosurfaceGenerator(density, 0.5)) {
  mesh = {
    positions: data.positions,
    cells: data.cells,
  };
  console.log('Fraction complete:', data.fraction);
  // await display update
}

API

require('isosurface-generator')(density, level)

Parameters

density is an ndarray (or an object that implements ndarray's .get method and .shape attribute)

level is the density value for which we're generating an isosurface

Return value

A generator function that will provide a mesh describing the isosurface mesh and the fraction complete:

const generator = isosurfaceGenerator(density, 0.5);

generator.next();

// Returns {
//   value: {
//     positions: [[1,2,3], [4,5,6], ...],
//     cells: [[1,2,3], [4,5,6], ...],
//     fraction: 0.009
//   },
//   done: false
// }

Resources

You can’t perform that action at this time.