Log inGet started
What it does

terrain

Heightmap terrain substrate. Build a mesh from a flat heightmap, sample it, save / load it as a .terrain asset, optionally spawn an entity in one call. Wraps the Internal __terrain.* FFI binding (FBM noise, mesh tessellation, bilinear sample) into one ergonomic Luau surface. Exposed as the global terrain via --!global terrain; the higher-level system surface (terrainSystem.*) lives in ~terrainSystem.modules.terrainSystem.

Exports

Build verbs:

  • terrain.create(opts) -> TerrainHandle? — heightmap → handle.
  • terrain.fromNoise(opts) -> TerrainHandle? — FBM noise → handle.
  • terrain.heightmap(opts) -> { number }? — pure FBM heightmap step.
  • terrain.spawn(opts) -> (entityId, TerrainHandle) — build + spawn entity with a Model component (and optional material) in one call.

Queries (call with the handle returned by a build verb):

  • terrain.heightAt(handle, x, z) -> number? — bilinear height with handle.originY folded in.
  • terrain.normalAt(handle, x, z) -> (nx, ny, nz) — three numbers.
  • terrain.slopeAt(handle, x, z) -> number? — slope in radians.

Asset round-trip:

  • terrain.fromAsset(source) -> TerrainHandle? — read a .terrain asset.
  • terrain.toAsset(handle, path, opts?) -> (boolean, string?) — write a .terrain asset.

Types

type TerrainHandle = {
    mesh: any,                -- renderer-ready AssetRef envelope
    heights: { number },     -- flat width*depth heightmap, row-major
    width: number,           -- grid resolution along +X
    depth: number,           -- grid resolution along +Z
    sizeX: number,           -- world width
    sizeZ: number,           -- world depth
    originX: number,         -- world center X (mesh centered here)
    originY: number,         -- world Y offset added to every vertex
    originZ: number,         -- world center Z
    name: string?,           -- mesh asset name when one was supplied
    material: any?,          -- asset's default material (when loaded)
}

Heightmap convention: row-major, Lua-indexed. heights[z * width + x + 1] is the height at grid cell (x, z).

Usage

Build from a Luau-computed heightmap:

local h = terrain.create({
    heights = myFlatTable,
    width = 64, depth = 64,
    sizeX = 80, sizeZ = 80,
})

Build a noise terrain in one call:

local h = terrain.fromNoise({
    width = 128, depth = 128, sizeX = 100, sizeZ = 100,
    seed = 7, octaves = 5, frequency = 0.02, amplitude = 12,
    ridge = true, bowl = 0.6,
})

Build + spawn an entity in one call:

local eid, h = terrain.spawn({
    width = 64, depth = 64, sizeX = 80, sizeZ = 80,
    entityName = "ground", material = "@me::materials.grass",
})

Sample for placement:

local y = terrain.heightAt(h, 12.5, -3.0)
local nx, ny, nz = terrain.normalAt(h, 12.5, -3.0)
local slope = terrain.slopeAt(h, 12.5, -3.0)

Round-trip via the .terrain asset format:

local ok, path = terrain.toAsset(h, "/source/terrain/island.terrain")
local h2 = terrain.fromAsset("/source/terrain/island.terrain")

Notes

  • The heavy work — mesh tessellation, central-difference normals, FBM noise, bilinear sample — runs in Rust through __terrain.*. This module is the thin Luau adapter; user code should never call __terrain.* directly.
  • terrain.spawn adds only Model + Material — no collider. Add a Collider component to the returned entity if you need terrain-vs-physics interaction: entity(eid).component.add("MeshCollider", { fit = "exact" }).
  • Determinism: same seed → identical heights on every platform (native / WASM / Android). The FBM uses an integer hash, not the OS RNG.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

This asset doesn't declare a schema or structured payload.

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

0items
This part has no composite children. See the Files segment for its leaf payloads.
This part has no leaf payloads.

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.