Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Wasm lib to quickly process DEM heightmaps, made for three.js 🌎🌍🌏 ⚡

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT
NotificationsYou must be signed in to change notification settings

blaze33/dem2mesh

Repository files navigation

A wasm library to quickly process DEM heightmaps forthree.js.

npm versionnpm bundle size

from heightmap to 3D terrain

Overview

Installation

npm install dem2mesh

alternatively:

yarn add dem2mesh

Initialization

letdem2meshimport('dem2mesh').then(pkg=>{dem2mesh=pkgdem2mesh.init()}

Usage

Currently works with 256x256px PNG images as input.The PNG images come from theterrain tile dataset hosted on Amazon.

cf.Get started with Mapzen Terrain Tiles.

The current s3 url format is:

https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png

Fetch one png tile to work with:

letpngfetch(tileURL).then(res=>res.arrayBuffer()).then(arrayBuffer=>png=newUint8Array(arrayBuffer))

Once initialized thedem2mesh exposes two functions:

  • dem2mesh.png2elevation
  • dem2mesh.png2mesh

dem2mesh.png2elevation(png)

Returns aFloat32Array of size256*256 containing elevation data which can be used to set the positions of aPlaneBufferGeometry geometry.

constheightmap=dem2mesh.png2elevation(png)constgeometry=newPlaneBufferGeometry(size,size,segments+2,segments+2)constnPosition=Math.sqrt(geometry.attributes.position.count)constnHeightmap=Math.sqrt(heightmap.length)constratio=nHeightmap/(nPosition)letx,yfor(leti=nPosition;i<geometry.attributes.position.count-nPosition;i++){if(i%(nPosition)===0||i%(nPosition)===nPosition-1)continuex=Math.floor(i/(nPosition))y=i%(nPosition)geometry.attributes.position.setZ(i,heightmap[Math.round(Math.round(x*ratio)*nHeightmap+y*ratio)]*0.075)}

dem2mesh.png2mesh(png, size, segments)

Returns 3 arrays, position, index and uv wich can be used to create a three.js BufferGeometry.

const[position,index,uv]=dem2mesh.png2mesh(png,size,segments)constgeometry=newBufferGeometry()geometry.setAttribute('position',newBufferAttribute(Float32Array.from(position),3))geometry.setIndex(newBufferAttribute(Uint16Array.from(index),1))geometry.setAttribute('uv',newBufferAttribute(Float32Array.from(uv),2))geometry.computeVertexNormals()

About

This package was built upon thewasm-pack-template.

📚 Read the template tutorial! 📚

Thewasm-pack-template is designed for compiling Rust libraries into WebAssembly andpublishing the resulting package to NPM.

Be sure to check outotherwasm-pack tutorials online for othertemplates and usages ofwasm-pack.

🚴 Contribution

🐑 Clone this Template

git clone https://github.com/blaze33/dem2mesh.gitcd dem2mesh

🛠️ Build withwasm-pack build

wasm-pack build

🔬 Test in Headless Browsers withwasm-pack test

wasm-pack test --headless --firefox

🔋 Batteries Included

About

Wasm lib to quickly process DEM heightmaps, made for three.js 🌎🌍🌏 ⚡

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp