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:
-
TypedArrayConstructorFunctionThe constructor to use (Float32Array, Uint8Array, etc.)
-
sizeNumberThe size of the array to create
-
componentSizeNumberThe number of components per-value (ie. 3 for a vec3, 9 for a Mat3, etc.)
-
indexOffsetNumberThe 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:
-
indexNumberThe 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:
-
indexNumberThe index in the array to fetch.
Returns:
The value at the given index.
grow
-
size
Grows the internal array.
Parameters:
-
sizeNumberThe 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:
-
indexNumberThe index at which to set the vec3 values from.
-
colorColorAny 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:
-
indexNumberThe start position from which to copy into this array.
-
arrayTypedArrayThe array from which to copy; the source array.
Returns:
Instance of this class.
setMat3
-
index -
mat3
Set a Matrix3 value at index.
Parameters:
-
indexNumberThe index at which to set the matrix values from.
-
mat3Matrix3The 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:
-
indexNumberThe index at which to set the matrix values from.
-
mat3Matrix4The 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:
-
indexNumberThe index at which to set the vec3 values from.
-
numericValueNumberThe 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:
-
sizeNumberThe new size of the array.
setVec2
-
index -
vec2
Set a Vector2 value at index.
Parameters:
-
indexNumberThe index at which to set the vec2 values from.
-
vec2Vector2Any object that has x and y properties.
Returns:
Instance of this class.
setVec2Components
-
index -
x -
y
Set a Vector2 value using raw components.
Parameters:
-
indexNumberThe index at which to set the vec2 values from.
-
xNumberThe Vec2"s x component.
-
yNumberThe Vec2"s y component.
Returns:
Instance of this class.
setVec3
-
index -
vec2
Set a Vector3 value at index.
Parameters:
-
indexNumberThe index at which to set the vec3 values from.
-
vec2Vector3Any 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:
-
indexNumberThe index at which to set the vec3 values from.
-
xNumberThe Vec3"s x component.
-
yNumberThe Vec3"s y component.
-
zNumberThe Vec3"s z component.
Returns:
Instance of this class.
setVec4
-
index -
vec2
Set a Vector4 value at index.
Parameters:
-
indexNumberThe index at which to set the vec4 values from.
-
vec2Vector4Any 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:
-
indexNumberThe index at which to set the vec4 values from.
-
xNumberThe Vec4"s x component.
-
yNumberThe Vec4"s y component.
-
zNumberThe Vec4"s z component.
-
wNumberThe Vec4"s w component.
Returns:
Instance of this class.
shrink
-
size
Shrinks the internal array.
Parameters:
-
sizeNumberThe 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:
-
startNumberThe start index of the splice. Will be multiplied by the number of components for this attribute.
-
endNumberThe end index of the splice. Will be multiplied by the number of components for this attribute.
Returns:
The TypedArrayHelper instance.
