JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q30262F
  • License MIT

generate a triangle mesh from a distance function

Package Exports

  • generate-heightmap-mesh
  • generate-heightmap-mesh/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (generate-heightmap-mesh) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

generate-heightmap-mesh

generate a triangle mesh from a distance function

npm i generate-heightmap-mesh
//height function format:
function(x,y,z,scale){ //note - y is usually assumed to be constant
    return height_at_point(x/scale,y,z/scale);
}

by default the height function generates islands created from simplex noise

var gen = require('generate-heightmap-mesh');

var resolution = 256; //x-z resolution of mesh
var size = 64;
var boundingBox_XZ = [[-size,0,-size],[size,0,size]];
var df = gen.dfHillsWorld2D; //default distance function
var yCoordinate=0.0; //y-coord to use in 3d distance function sampler
var df_scaleXZ=100.0; //scale df along x-z, default 100 -- you can leave this constant to have the bounding box reveal more land as it expands, OR make this value proportional to the bounding box, to have the result expand to the same size as the bounding box
var df_scaleY=4; //scale result height, default 4
var postSimplifyFactor=0.5; //default 1 [no simplify] -- if less than 1, decimate triangles to the fraction indicated

var triangles = gen.generateHeightmapMeshXZ(resolution, boundingBox_XZ, df, yCoordinate, df_scaleXZ, df_scaleY, postSimplifyFactor);

//view result with ascii-raytracer
var art = require('ascii-raytracer');
var config = {
    triangles:triangles,
    resolution: 64,
    aspectRatio: 1.0,
    cameraMode: 0,
    mouseControl:true,
    antiAlias: true
}

art.runScene(config);

1

resulting heightmap mesh