TypedArrayHelper Class
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
FunctionThe constructor to use (Float32Array, Uint8Array, etc.)
-
size
NumberThe size of the array to create
-
componentSize
NumberThe number of components per-value (ie. 3 for a vec3, 9 for a Mat3, etc.)
-
indexOffset
NumberThe index in the array from which to start assigning values. Default 0 if none provided
Item Index
Methods
getComponentValueAtIndex
-
index
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
NumberThe index in the array to fetch.
Returns:
The component value at the given index.
getValueAtIndex
-
index
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
NumberThe index in the array to fetch.
Returns:
The value at the given index.
grow
-
size
Grows the internal array.
Parameters:
-
size
NumberThe new size of the typed array. Must be larger than this.array.length.
Returns:
Instance of this class.
setColor
-
index
-
color
Set a Color value at index.
Parameters:
-
index
NumberThe index at which to set the vec3 values from.
-
color
ColorAny object that has r, g, and b properties.
Returns:
Instance of this class.
setFromArray
-
index
-
array
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
NumberThe start position from which to copy into this array.
-
array
TypedArrayThe array from which to copy; the source array.
Returns:
Instance of this class.
setMat3
-
index
-
mat3
Set a Matrix3 value at index.
Parameters:
-
index
NumberThe index at which to set the matrix values from.
-
mat3
Matrix3The 3x3 matrix to set from. Must have a TypedArray property named elements to copy from.
Returns:
Instance of this class.
setMat4
-
index
-
mat3
Set a Matrix4 value at index.
Parameters:
-
index
NumberThe index at which to set the matrix values from.
-
mat3
Matrix4The 4x4 matrix to set from. Must have a TypedArray property named elements to copy from.
Returns:
Instance of this class.
setNumber
-
index
-
numericValue
Set a Number value at index.
Parameters:
-
index
NumberThe index at which to set the vec3 values from.
-
numericValue
NumberThe number to assign to this index in the array.
Returns:
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
NumberThe new size of the array.
setVec2
-
index
-
vec2
Set a Vector2 value at index.
Parameters:
-
index
NumberThe index at which to set the vec2 values from.
-
vec2
Vector2Any object that has x and y properties.
Returns:
Instance of this class.
setVec2Components
-
index
-
x
-
y
Set a Vector2 value using raw components.
Parameters:
-
index
NumberThe index at which to set the vec2 values from.
-
x
NumberThe Vec2"s x component.
-
y
NumberThe Vec2"s y component.
Returns:
Instance of this class.
setVec3
-
index
-
vec2
Set a Vector3 value at index.
Parameters:
-
index
NumberThe index at which to set the vec3 values from.
-
vec2
Vector3Any object that has x, y, and z properties.
Returns:
Instance of this class.
setVec3Components
-
index
-
x
-
y
-
z
Set a Vector3 value using raw components.
Parameters:
-
index
NumberThe index at which to set the vec3 values from.
-
x
NumberThe Vec3"s x component.
-
y
NumberThe Vec3"s y component.
-
z
NumberThe Vec3"s z component.
Returns:
Instance of this class.
setVec4
-
index
-
vec2
Set a Vector4 value at index.
Parameters:
-
index
NumberThe index at which to set the vec4 values from.
-
vec2
Vector4Any object that has x, y, z, and w properties.
Returns:
Instance of this class.
setVec4Components
-
index
-
x
-
y
-
z
-
w
Set a Vector4 value using raw components.
Parameters:
-
index
NumberThe index at which to set the vec4 values from.
-
x
NumberThe Vec4"s x component.
-
y
NumberThe Vec4"s y component.
-
z
NumberThe Vec4"s z component.
-
w
NumberThe Vec4"s w component.
Returns:
Instance of this class.
shrink
-
size
Shrinks the internal array.
Parameters:
-
size
NumberThe new size of the typed array. Must be smaller than this.array.length.
Returns:
Instance of this class.
splice
-
start
-
end
Perform a splice operation on this arrays buffer.
Parameters:
-
start
NumberThe start index of the splice. Will be multiplied by the number of components for this attribute.
-
end
NumberThe end index of the splice. Will be multiplied by the number of components for this attribute.
Returns:
The TypedArrayHelper instance.