utils

These utils are available in the main scene scope
Source:

Methods

(static) clamp(value, min, max) → {number}

Clamp a number
Parameters:
Name Type Description
value number The value
min number Minimum to clamp to
max number Maximum to clamp to
Source:

(static) degToRad(theta) → {number}

Convert degress to radians.
Parameters:
Name Type Description
theta number The angle in degrees
Source:

(static) glslFloat(n)

Format a float value for inclusion in glsl source code. Useful when rendering textures dynamically etc. See example here.
Parameters:
Name Type Description
n number The number to format
Source:

(static) lerp(value1, value2, amount) → {number}

Perform a linear interpolation between value1 and value2 using amount to weight between them.
Parameters:
Name Type Description
value1 number First value
value2 number Second value
amount number The weight
Source:

(static) normedColorStr(color) → {string}

Format a color for inclusion in glsl source code (i.e. return a normalized triplet of values in the range 0 - 1 encoded as a string: '0.34, 0.1, 0.1'). Useful when rendering textures dynamically etc. See example here.
Parameters:
Name Type Description
color string A hex rgb color value ('#ffffff')
Source:

(static) radToDeg(theta) → {number}

Convert radians to degrees.
Parameters:
Name Type Description
theta number The angle in radians
Source:

(static) range(…limit) → {Array.<number>}

Range helper function
Parameters:
Name Type Attributes Description
limit number <repeatable>
A single integer x, giving the range [0, ..., x - 1], or two integers x, y, giving the range [x, ..., y - 1]
Source:
Example
const a = range(10);
// a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const b = range(4, 8);
// b = [4, 5, 6, 7]

(static) range2d(…limit) → {Array.<Array.<number>>}

2d range helper function
Parameters:
Name Type Attributes Description
limit number <repeatable>
One integer xy, giving the range [[0,0], ..., [xy-1, xy-1]], or two integers x, y, giving the range [[0,0], ..., [x-1, y-1]], or four integers x, x2, y, y2, giving the range [[x1, y1], ..., [x2-1, y2-1]]
Source:
Example
const a = range2d(2);
// a = [[0,0],[0,1],[1,0],[1,1]]
const b = range2d(3, 4);
// b = [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3]]
const c = range2d(2, 4, 0, 2);
// c = [[2,0],[2,1],[3,0],[3,1]]

(static) range3d(…limit) → {Array.<Array.<number>>}

3d range helper function
Parameters:
Name Type Attributes Description
limit number <repeatable>
Three integers, x, y, z, giving the range [[0,0,0], ..., [x-1, y-1, z-1]], or six integers, x, x2, y, y2, z, z2, giving the range [[x,y,z], ..., [x2-1, y2-1, z2-1]].
Source:
Example
const a = range2d(2, 2, 2);
// a = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
const b = range3d(0, 2,  0, 4,  0, 2);
// b = [[2,2,0],[2,2,1],[2,3,0],[2,3,1],[3,2,0],[3,2,1],[3,3,0],[3,3,1]]

(static) subRange(rangeA, rangeB)

Subtract on range from another. Note that the ranges used must have the same dimensions.
Parameters:
Name Type Description
rangeA Array.<number> | Array.<Array.<range>> | Array.<Array.<Array.<range>>> The range to subtract from
rangeB Array.<number> | Array.<Array.<range>> | Array.<Array.<Array.<range>>> The range to subtract
Source:
Example
const a = subRange(range2d(5), range2d(2, 3));
// a = [[0,3],[0,4],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]]

(static) tileSeamless3d(data, size) → {number}

Blend edges in a 3d array (useful for tiling volume textures). Read more here. See example here
Parameters:
Name Type Description
data Array.<Array.<Array.<number>>> The data to tile in 3d
size number The cubic size of the volume to tile
Source:

(static) vec2()

vec2 - a standard glMatrix vec2 (constructor) function. See the glMatrix api reference for details
Source:

(static) vec3()

vec3 - a standard glMatrix vec3 (constructor) function. See the glMatrix api reference for details
Source: