New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

marching-cubes-fast

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marching-cubes-fast

fast sparse marching cubes implementation - runtime proportional to surface area rather than volume

latest
npmnpm
Version
0.0.172
Version published
Weekly downloads
13
225%
Maintainers
1
Weekly downloads
 
Created
Source

marching-cubes-fast

Fast sparse marching cubes implementation.

Rather than scaling with volume O(N3) , this tool has runtime O(NH), where H is the Hausdorff dimension of the surface of the scalar field. In practice this means that the runtime is approximately proportional to the surface area (H≈2).

How it works:

This tool breaks down the space like an octree and only runs the Marching Cubes kernel on voxels near the surface. Each octant queries the signed distance function from its center and if the result is farther than the covering radius of the octant, the octant is discarded. The process is repeated recursively.

You can also use this to create sparse voxel sets (simply skipping the Marching Cubes step), or to run the Marching Cubes kernel on a list of arbitrary voxels, even if they are different sizes (for level-of-detail effects, etc).

Based on isosurface by mikolalysenko, in turn based on Paul Bourke's original

Installation

npm i marching-cubes-fast

Usage

var mcf = require('marching-cubes-fast');

//create a signed distance function - here we have 3d simplex noise

var {SimplexNoise} = require('simplex-noise');
var simplex = new SimplexNoise(1004);
var dfSimplex3d = function(x,y,z){
    var s = 20.0
    return simplex.noise3D(x/s,y/s,z/s)+0.5;
}

//polygonize the field - convert it to triangles with marching cubes

var resolution = 32; //scanning resolution, must be a power of 2
var scanBounds = [[0,0,0],[resolution,resolution,resolution]]; //bounding box to scan over

var result = mcf.marchingCubes(resolution, dfSimplex3d, scanBounds);

//if you want a list of voxels only...
//var voxels = mcf.getSubBlocksRecursive(scanBounds, iterations, dfSimplex3d);
//also getSubBlocksRecursiveIncVolume -- includes volume as well as edges 
//voxels array returned in the same format as scanBounds

//if you want to run marching cubes on your own list of voxels...
//var result = mcf.marchingCubesVoxelList(dfSimplex3d, listOfVoxels); //array of voxels, where each voxel is a bounding box like scanBounds

//^^^ note that the voxels can be different sizes! level-of-detail effects etc, possible

console.log(result);

// marching cubes result...

// {
//     positions: [  //vertices
//         [ 0.2039299646182391, 1, 0 ],
//         [ 0, 0.7943976862618888, 0 ],
//         [ 0, 1, 0.8012346044071122 ],
//          ...
//     cells: [      //faces
//         [ 1, 0, 2 ],       [ 3, 4, 5 ],
//         [ 14, 12, 13 ],    [ 14, 13, 10 ],
//         [ 16, 18, 15 ],    [ 19, 21, 20 ],
//         ...

//view the result with ascii-raytracer

var ti = require('triangles-index');
var art = require('ascii-raytracer');
var tris1 = ti.deindexTriangles_meshView(result);
var config = {
    tris:tris1,
    triangleColors: tris1.map(t=>[Math.random(),Math.random(),Math.random()]),
    resolution: 64,
    aspectRatio: 1.0,
    cameraPos: [22,29,-12],
    cameraRot: [2.2,-4.4]
}
art.runScene(config);

https://i.imgur.com/Eah0Dx4.png

See Also

stonks

Keywords

marching

FAQs

Package last updated on 22 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts