Class: TypedArrayHelper

SPE. TypedArrayHelper

new TypedArrayHelper(TypedArrayConstructor, size, componentSize, indexOffset)

A helper class for TypedArrays. Allows for easy resizing, assignment of various component-based types (Vector2s, Vector3s, Vector4s, Mat3s, Mat4s), as well as Colors (where components are `r`, `g`, `b`), Numbers, and setting from other TypedArrays.
Parameters:
Name Type Description
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
Author:
  • Luke Moody
Source:

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:
Name Type Description
index Number The index in the array to fetch.
Source:
Returns:
The component value at the given index.
Type
TypedArray

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:
Name Type Description
index Number The index in the array to fetch.
Source:
Returns:
The value at the given index.
Type
Number

grow(size) → {SPE.TypedArrayHelper}

Grows the internal array.
Parameters:
Name Type Description
size Number The new size of the typed array. Must be larger than `this.array.length`.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setColor(index, color) → {SPE.TypedArrayHelper}

Set a Color value at `index`.
Parameters:
Name Type Description
index Number The index at which to set the vec3 values from.
color Color Any object that has `r`, `g`, and `b` properties.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setFromArray(index, array) → {SPE.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:
Name Type Description
index Number The start position from which to copy into this array.
array TypedArray The array from which to copy; the source array.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setMat3(index, mat3) → {SPE.TypedArrayHelper}

Set a Matrix3 value at `index`.
Parameters:
Name Type Description
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.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setMat4(index, mat3) → {SPE.TypedArrayHelper}

Set a Matrix4 value at `index`.
Parameters:
Name Type Description
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.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setNumber(index, numericValue) → {SPE.TypedArrayHelper}

Set a Number value at `index`.
Parameters:
Name Type Description
index Number The index at which to set the vec3 values from.
numericValue Number The number to assign to this index in the array.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

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:
Name Type Description
size Number The new size of the array.
Source:

setVec2(index, vec2) → {SPE.TypedArrayHelper}

Set a Vector2 value at `index`.
Parameters:
Name Type Description
index Number The index at which to set the vec2 values from.
vec2 Vector2 Any object that has `x` and `y` properties.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setVec2Components(index, x, y) → {SPE.TypedArrayHelper}

Set a Vector2 value using raw components.
Parameters:
Name Type Description
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.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setVec3(index, vec2) → {SPE.TypedArrayHelper}

Set a Vector3 value at `index`.
Parameters:
Name Type Description
index Number The index at which to set the vec3 values from.
vec2 Vector3 Any object that has `x`, `y`, and `z` properties.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setVec3Components(index, x, y, z) → {SPE.TypedArrayHelper}

Set a Vector3 value using raw components.
Parameters:
Name Type Description
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.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setVec4(index, vec2) → {SPE.TypedArrayHelper}

Set a Vector4 value at `index`.
Parameters:
Name Type Description
index Number The index at which to set the vec4 values from.
vec2 Vector4 Any object that has `x`, `y`, `z`, and `w` properties.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

setVec4Components(index, x, y, z, w) → {SPE.TypedArrayHelper}

Set a Vector4 value using raw components.
Parameters:
Name Type Description
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.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

shrink(size) → {SPE.TypedArrayHelper}

Shrinks the internal array.
Parameters:
Name Type Description
size Number The new size of the typed array. Must be smaller than `this.array.length`.
Source:
Returns:
Instance of this class.
Type
SPE.TypedArrayHelper

splice(start, end) → {Object}

Perform a splice operation on this array's buffer.
Parameters:
Name Type Description
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.
Source:
Returns:
The SPE.TypedArrayHelper instance.
Type
Object