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 🙏

© 2026 – Pkg Stats / Ryan Hefner

threejs-heightfield

v0.1.0

Published

Bake three.js meshes into fast heightfields: height lookup, slope and ray-marching for placing things on terrain

Readme

threejs-heightfield

Ground under a three.js scene as a fast (x, z) => y lookup. Bake any mesh or group into a heightfield once, then sample heights, measure slope and ray-march it without per-object raycasts. It's the base layer that threejs-grass and the other threejs-worldgen packages use to put things on terrain.

npm i threejs-heightfield three
import { bakeHeightfield, createHeightSampler, raycastHeight, slopeAt } from 'threejs-heightfield'

const height = bakeHeightfield(terrainMesh)        // any Object3D; world transforms included
height(12, -40)                                      // terrain height there, NaN off the terrain
slopeAt(height, 12, -40)                             // rise / run, e.g. to keep trees off cliffs
raycastHeight(height, camera.position, rayDir)      // Vector3 hit point or null, e.g. for brushes

const flat = createHeightSampler()                   // no terrain: y = 0 everywhere
const hills = createHeightSampler((x, z) => Math.sin(x * 0.03) * 4) // functions pass straight through

| Export | What it does | |---|---| | bakeHeightfield(root, maxResolution = 1024) | Rasterises every mesh under root on the CPU into a bilinear height lookup. Where surfaces overlap, the highest wins. | | createHeightSampler(terrain?, maxResolution?) | Accepts a mesh, a height function or nothing, and returns a HeightFn. | | slopeAt(sample, x, z, e = 0.25) | Gradient magnitude by central differences. | | raycastHeight(sample, origin, dir, maxDistance = 2000, step = 0.5) | Ray-march then bisect against any HeightFn. | | type HeightFn / type Terrain | (x, z) => number / Object3D \| HeightFn |

Imports from three/webgpu, like threejs-grass. Full API docs: https://askalice.github.io/threejs-worldgen/docs/.

License

Apache-2.0