isosurface-generator

2.0.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i isosurface-generator

Weekly Downloads

5

Version

2.0.1

License

Unlicense

Last publish

Collaborators

  • wwwtyro