Skip to content

wwwtyro/isosurface-generator

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

A JS generator function that returns a list of vertices describing an isosuface given a density and level.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published