Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

field.map_range

Remaps each component from [fromMin, fromMax] to [toMin, toMax], optionally clamped to the output range. Equal fromMin and fromMax leave the span 1, so the remap is a shift followed by the output span. The four bounds are live slots.

Inputs

  • a (Field | Float | Vec2 | Vec3 | Vec4). The field being remapped. Every component goes through the same remap, and the output keeps a's type and component count.
  • fromMin (Float). Default 0. The input value that lands on toMin: where the source range starts.
  • fromMax (Float). Default 1. The input value that lands on toMax: where the source range ends.
  • toMin (Float). Default 0. What fromMin becomes.
  • toMax (Float). Default 1. What fromMax becomes. Below toMin the mapping runs backwards.
  • clamp (Bool). Default false. true holds the result inside the output range, taken from the two output values whichever way round they are.

Outputs

  • field: a field of a's type and component count.

Example

local points = g.points.grid({ countX = 4, countZ = 1, spacing = 1 })
local out = g.attribute.set({ geometry = points, name = "v", value = g.field.map_range({ a = g.field.position().x, fromMin = 0, fromMax = 3, toMin = 10, toMax = 20 }) })

x from 0 to 3 lands on 10 to 20: -1.5 gives 5 and 1.5 gives 15. With clamp = true the result stays inside the output range.