TypedArrayHelper Class

Module: Lights

A helper class for TypedArrays.

Allows for easy resizing, assignment of various component-based types (e.g. Vector2, Vector3, Mat3, Color, ...) Numbers, and setting from other TypedArrays.

Constructor

TypedArrayHelper

(
  • TypedArrayConstructor
  • size
  • componentSize
  • indexOffset
)

Parameters:

  • TypedArrayConstructor Function

    The constructor to use (Float32Array, Uint8Array, etc.)

  • size Number

    The size of the array to create

  • componentSize Number

    The number of components per-value (ie. 3 for a vec3, 9 for a Mat3, etc.)

  • indexOffset Number

    The index in the array from which to start assigning values. Default 0 if none provided

Methods

getComponentValueAtIndex

(
  • index
)
TypedArray

Returns the component value of the array at the given index, taking into account the indexOffset property of this class.

If the componentSize is set to 3, then it will return a new TypedArray of length 3.

Parameters:

  • index Number

    The index in the array to fetch.

Returns:

TypedArray:

The component value at the given index.

getValueAtIndex

(
  • index
)
Number

Returns the value of the array at the given index, taking into account the indexOffset property of this class.

Note that this function ignores the component size and will just return a single value.

Parameters:

  • index Number

    The index in the array to fetch.

Returns:

Number:

The value at the given index.

grow

(
  • size
)
TypedArrayHelper

Grows the internal array.

Parameters:

  • size Number

    The new size of the typed array. Must be larger than this.array.length.

Returns:

TypedArrayHelper:

Instance of this class.

setColor

(
  • index
  • color
)
TypedArrayHelper

Set a Color value at index.

Parameters:

  • index Number

    The index at which to set the vec3 values from.

  • color Color

    Any object that has r, g, and b properties.

Returns:

TypedArrayHelper:

Instance of this class.

setFromArray

(
  • index
  • array
)
TypedArrayHelper

Copies from the given TypedArray into this one, using the index argument as the start position.

Alias for TypedArray.set. Will automatically resize if the given source array is of a larger size than the internal array.

Parameters:

  • index Number

    The start position from which to copy into this array.

  • array TypedArray

    The array from which to copy; the source array.

Returns:

TypedArrayHelper:

Instance of this class.

setMat3

(
  • index
  • mat3
)
TypedArrayHelper

Set a Matrix3 value at index.

Parameters:

  • index Number

    The index at which to set the matrix values from.

  • mat3 Matrix3

    The 3x3 matrix to set from. Must have a TypedArray property named elements to copy from.

Returns:

TypedArrayHelper:

Instance of this class.

setMat4

(
  • index
  • mat3
)
TypedArrayHelper

Set a Matrix4 value at index.

Parameters:

  • index Number

    The index at which to set the matrix values from.

  • mat3 Matrix4

    The 4x4 matrix to set from. Must have a TypedArray property named elements to copy from.

Returns:

TypedArrayHelper:

Instance of this class.

setNumber

(
  • index
  • numericValue
)
TypedArrayHelper

Set a Number value at index.

Parameters:

  • index Number

    The index at which to set the vec3 values from.

  • numericValue Number

    The number to assign to this index in the array.

Returns:

TypedArrayHelper:

Instance of this class.

setSize

(
  • size
)

Sets the size of the internal array.

Delegates to this.shrink or this.grow depending on size argument's relation to the current size of the internal array.

Note that if the array is to be shrunk, data will be lost.

Parameters:

  • size Number

    The new size of the array.

setVec2

(
  • index
  • vec2
)
TypedArrayHelper

Set a Vector2 value at index.

Parameters:

  • index Number

    The index at which to set the vec2 values from.

  • vec2 Vector2

    Any object that has x and y properties.

Returns:

TypedArrayHelper:

Instance of this class.

setVec2Components

(
  • index
  • x
  • y
)
TypedArrayHelper

Set a Vector2 value using raw components.

Parameters:

  • index Number

    The index at which to set the vec2 values from.

  • x Number

    The Vec2"s x component.

  • y Number

    The Vec2"s y component.

Returns:

TypedArrayHelper:

Instance of this class.

setVec3

(
  • index
  • vec2
)
TypedArrayHelper

Set a Vector3 value at index.

Parameters:

  • index Number

    The index at which to set the vec3 values from.

  • vec2 Vector3

    Any object that has x, y, and z properties.

Returns:

TypedArrayHelper:

Instance of this class.

setVec3Components

(
  • index
  • x
  • y
  • z
)
TypedArrayHelper

Set a Vector3 value using raw components.

Parameters:

  • index Number

    The index at which to set the vec3 values from.

  • x Number

    The Vec3"s x component.

  • y Number

    The Vec3"s y component.

  • z Number

    The Vec3"s z component.

Returns:

TypedArrayHelper:

Instance of this class.

setVec4

(
  • index
  • vec2
)
TypedArrayHelper

Set a Vector4 value at index.

Parameters:

  • index Number

    The index at which to set the vec4 values from.

  • vec2 Vector4

    Any object that has x, y, z, and w properties.

Returns:

TypedArrayHelper:

Instance of this class.

setVec4Components

(
  • index
  • x
  • y
  • z
  • w
)
TypedArrayHelper

Set a Vector4 value using raw components.

Parameters:

  • index Number

    The index at which to set the vec4 values from.

  • x Number

    The Vec4"s x component.

  • y Number

    The Vec4"s y component.

  • z Number

    The Vec4"s z component.

  • w Number

    The Vec4"s w component.

Returns:

TypedArrayHelper:

Instance of this class.

shrink

(
  • size
)
TypedArrayHelper

Shrinks the internal array.

Parameters:

  • size Number

    The new size of the typed array. Must be smaller than this.array.length.

Returns:

TypedArrayHelper:

Instance of this class.

splice

(
  • start
  • end
)
Object

Perform a splice operation on this arrays buffer.

Parameters:

  • start Number

    The start index of the splice. Will be multiplied by the number of components for this attribute.

  • end Number

    The end index of the splice. Will be multiplied by the number of components for this attribute.

Returns:

Object:

The TypedArrayHelper instance.