heightfield.procNode
- README.md1.4 KB
- heightfield.module
- init.luau944 B
This package holds more than this page lists. See all of its files in its world.
README.md
shape.heightfield
Ground from a grid of heights: a mesh in the XZ plane facing +Y, centred on the origin, each sample lifted to its height, with the normals of its slopes.
In a scene: HeightfieldGeometry(width, depth, heights, columns).
| Input | Default | Meaning |
|---|---|---|
width | 1 | Its size along X. |
depth | 1 | Its size along Z. |
heights | {} | The heights, row by row along Z, columns samples a row along X: sample c of row r is heights[r * columns + c + 1]. |
columns | 2 | Samples a row, along X. |
The rows are as many as the heights make: #heights / columns. The grid is the
one a HeightfieldCollider holds for the same heights (rows along its Z,
cols along its X, extent = { x = width, y = 1, z = depth }), so a player
walks on the ground the mesh draws. The model states the heights alone, not
the vertices and triangles they make.
The node answers geometry: a mesh with positions, normals and uvs. Its body is
a call into the module in its own folder, so a graph of many parts cooks
without a device dispatch per shape.
local heights = {}
for r = 0, 32 do
for c = 0, 32 do
table.insert(heights, math.noise(c / 8, r / 8) * 3)
end
end
Mesh(HeightfieldGeometry(64, 64, heights, 33), MeshStandardMaterial({ color = "#5d7a3a" }), "ground")