Builtin Library
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). Default0. The input value that lands ontoMin: where the source range starts.fromMax(Float). Default1. The input value that lands ontoMax: where the source range ends.toMin(Float). Default0. WhatfromMinbecomes.toMax(Float). Default1. WhatfromMaxbecomes. BelowtoMinthe mapping runs backwards.clamp(Bool). Defaultfalse. true holds the result inside the output range, taken from the two output values whichever way round they are.
Outputs
field: a field ofa'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.