npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gl-isosurface3d

v0.5.0

Published

3D isosurface generator

Downloads

56

Readme

gl-isosurface3d

Visualization module for isosurfaces.

Example

var createScene      = require('gl-plot3d')
var createIsosurface = require('gl-isosurface3d')

var scene = createScene()

var width = 64
var height = 64
var depth = 64

var data = new Uint16Array(width*height*depth)
for (var z=0; z<depth; z++)
for (var y=0; y<height; y++)
for (var x=0; x<width; x++) {
	var value = 1500 + 500 * (
		Math.sin(3 * 2*Math.PI*(z/depth-0.5)) +
		Math.cos(4 * 2*Math.PI*(x/width-0.5)) +
		Math.sin(5 * 2*Math.PI*(h/height-0.5))
	);
	data[z*height*width + y*width + x] = value
}

var dims = [width, height, depth]
var bounds = [[0,0,0], [width, height, depth]]

var isoPlot = createIsosurface({
	values: data,
	dimensions: dims,
	isoBounds: [1600, 2000],
	vertexIntensityBounds: [1000, 2000],
	smoothNormals:  true,
	isoCaps: true,
	singleMesh: false,
	colormap: 'portland',
	capsColormap: 'jet'
}, bounds)

var mesh = createIsosurface.createTriMesh(gl, isoPlot)
var capMesh = createIsosurface.createTriMesh(gl, isoPlot.caps)

scene.add(mesh)
scene.add(capMesh)

Try out the example in your browser

Install

npm i gl-isosurface3d

Basic interface

Constructor

var isosurface = require('gl-isosurface3d')(params, bounds)

Creates an isosurface out of a 3D array.

  • params is an object that has the following properties:

    • values (Required) An flattened 3D array of values
    • dimensions (Required) The dimensions of the array
    • isoBounds (Recommended) The range of values to envelop with the isosurface. Defaults to [1, Infinity], which creates an isosurface that has all values 1 and larger inside it.
    • vertexIntensityBounds (Optional) The range of values to map to [0..1] intensities. Defaults to the minimum and maximum values of the values array.
    • smoothNormals (Optional) Generate vertex normals for the isosurface. Defaults to false.
    • isoCaps (Optional) Generate caps for the isosurface. Defaults to false.
    • singleMesh (Optional) Merge isosurface and isocap meshes into a single mesh. Defaults to false, in which case the isocap mesh is stored in isoPlot.caps.
    • colormap Name of the colormap to use for coloring the isosurface.
    • capsColormap Name of the colormap to use for coloring the isocaps when using singleMesh = false. Defaults to the isosurface colormap.
  • bounds is a bounds object that tells what part of the 3D array to display. It defaults to [[0, 0, 0], [width, height, depth]].

Returns An isosurface object that can be passed to isosurface3d.createTriMesh.

var drawable = require('gl-isosurface3d').createTriMesh(params)

Creates a drawable out of the isosurface triangle data. This is a version of gl-mesh3d optimized for fast loading of unindexed triangle meshes.

  • params is an object that has the following properties:

    • gl A reference to the WebGL context
    • positions (Required) Vertex positions array for the mesh, encoded as a flat Float32Array.
    • vertexNormals (Required) Vertex normals for the mesh, encoded as a flat Float32Array.
    • vertexIntensity Intensities of the vertices, used for intensity texture lookups.
    • colormap Name of the colormap to use for coloring the vertices.
    • vertexIntensityBounds intensity range for the colormap
    • ambientLight ambient light color * intensity
    • diffuseLight diffuse light color * intensity
    • specularLight specular light color
    • lightPosition location of light
    • roughness surface roughness
    • fresnel surface glossiness/"rim light" factor
    • opacity surface opacity

Returns A drawable object that can be drawn on the passed gl context with drawable.draw(cameraParams);

Credits

(c) 2013-2017 Mikola Lysenko, Ilmari Heikkinen. MIT License