Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit098ece8e9e

README.md

math

The vector, colour and number helpers a build writes with, in the shapes three.js has them. sceneNouns re-exports Vector3, Color and MathUtils.

Vector3

Vector3(x, y, z) holds a point or direction; missing components are 0. Methods change the vector and return it, so calls chain; clone makes a copy.

set(x, y, z), setScalar(s), copy(v), clone(), add(v), sub(v), addScaledVector(v, s), multiply(v), multiplyScalar(s), divideScalar(s), negate(), dot(v), cross(v), lengthSq(), length(), normalize(), setLength(l), distanceTo(v), lerp(v, t), equals(v), toArray().

The operators +, -, unary -, * (by a number or component-wise by a vector) and == return new vectors.

local axis = Vector3(1, 0, 0):cross(Vector3(0, 1, 0)) -- (0, 0, 1)
local mid = (a + b) * 0.5

Color

A Color holds linear red, green and blue. Hex values and setRGB are sRGB, the way a colour is written.

Color() is white. Color(value) takes a hex string ("#a3141b", "a3141b", "#fa0"), a number (0xa3141b), a name ("red", "gold", "navy" and the other basic names) or another Color; Color(r, g, b) takes sRGB channels in 0 to 1. Any other value is an error that lists these forms.

Methods: set(value), setHex(n), setRGB(r, g, b), setHSL(h, s, l), copy(c), clone(), getHex(), getHexString(), getHSL() (returns h, s, l), lerp(c, t), add(c), multiplyScalar(s), equals(c), toArray().

A material's color and emissive take a Color wherever they take a hex string.

MathUtils

DEG2RAD, RAD2DEG, degToRad, radToDeg, clamp, lerp, inverseLerp, mapLinear, smoothstep, smootherstep, euclideanModulo, isPowerOfTwo, ceilPowerOfTwo, floorPowerOfTwo.

The random functions seededRandom(), randFloat(lo, hi), randInt(lo, hi) and randFloatSpread(range) draw from one sequence that setSeed(s) restarts. The sequence starts at the same place on every build, so a scene built twice has the same random values.