rhodonite
    Preparing search index...

    Class AnimatedVector4

    An animated 4D vector that interpolates between keyframe values over time. This class extends Vector4 and provides animation capabilities by sampling from animation tracks and optionally blending between two tracks.

    const samplers = new Map();
    const animatedVector = new AnimatedVector4(samplers, 'track1');
    animatedVector.setTime(2.5);
    console.log(animatedVector.x, animatedVector.y, animatedVector.z, animatedVector.w);

    Hierarchy (View Summary)

    Implements

    Index
    • Creates a new AnimatedVector4 instance.

      Parameters

      • animationSamplers: AnimationSamplers

        Map containing animation samplers keyed by track names

      • activeAnimationTrackName: string

        The name of the initial active animation track

      Returns AnimatedVector4

      When the specified animation track is not found in the samplers

    _v: TypedArray = ...

    Internal typed array storage for vector components

    isLoop: boolean = true

    Whether the animation should loop when it reaches the end.

    • get blendingRatio(): number

      Gets the current blending ratio between animation tracks.

      Returns number

      The current blending ratio

    • set blendingRatio(value: number): void

      Sets the blending ratio between the first and second animation tracks. A value of 0 means only the first track is used, 1 means only the second track, and values in between create a linear blend.

      Parameters

      • value: number

        The blending ratio (typically between 0 and 1)

      Returns void

    • get bytesPerComponent(): number

      Gets the number of bytes per component in the underlying typed array.

      Returns number

      The number of bytes per element (4 for Float32Array, 8 for Float64Array)

    • get className(): string

      Gets the class name of this vector type.

      Returns string

      The string "Vector4"

    • get glslStrAsFloat(): string

      Converts the vector to a GLSL vec4 string representation with float precision.

      Returns string

      A GLSL-compatible vec4 string (e.g., "vec4(1.0, 2.0, 3.0, 4.0)")

    • get glslStrAsInt(): string

      Converts the vector to a GLSL ivec4 string representation with integer values.

      Returns string

      A GLSL-compatible ivec4 string (e.g., "ivec4(1, 2, 3, 4)")

    • get glslStrAsUint(): string

      Converts the vector to a GLSL uvec4 string representation with unsigned integer values.

      Returns string

      A GLSL-compatible uvec4 string (e.g., "uvec4(1u, 2u, 3u, 4u)")

    • get w(): number

      Gets the w component of the vector, updating the animation if necessary.

      Returns number

      The current w component value

    • get wgslStrAsFloat(): string

      Converts the vector to a WGSL vec4f string representation with float precision.

      Returns string

      A WGSL-compatible vec4f string (e.g., "vec4f(1.0, 2.0, 3.0, 4.0)")

    • get wgslStrAsInt(): string

      Converts the vector to a WGSL vec4i string representation with integer values.

      Returns string

      A WGSL-compatible vec4i string (e.g., "vec4i(1, 2, 3, 4)")

    • get wgslStrAsUint(): string

      Converts the vector to a WGSL vec4u string representation with unsigned integer values.

      Returns string

      A WGSL-compatible vec4u string (e.g., "vec4u(1u, 2u, 3u, 4u)")

    • get x(): number

      Gets the x component of the vector, updating the animation if necessary.

      Returns number

      The current x component value

    • get y(): number

      Gets the y component of the vector, updating the animation if necessary.

      Returns number

      The current y component value

    • get z(): number

      Gets the z component of the vector, updating the animation if necessary.

      Returns number

      The current z component value

    • get compositionType(): CompositionTypeClass<"VEC4">

      Gets the composition type identifier for this vector type.

      Returns CompositionTypeClass<"VEC4">

      The CompositionType.Vec4 identifier

    • Gets the component value at the specified index.

      Parameters

      • i: number

        The index (0=x, 1=y, 2=z, 3=w)

      Returns number

      The component value at the specified index

    • Creates a deep copy of this vector.

      Returns Vector4

      A new Vector4 instance with the same component values

    • Removes an animation sampler for the specified track.

      Parameters

      • trackName: string

        The name of the animation track to remove

      Returns void

    • Calculates the dot product between this vector and another vector. The dot product is the sum of the products of corresponding components.

      Parameters

      • vec: IVector4

        The vector to calculate dot product with

      Returns number

      The dot product of the two vectors

    • Converts the vector to a flat array representation.

      Returns number[]

      An array containing the vector components [x, y, z, w]

    • Gets an array of all available animation track names.

      Returns string[]

      An array containing all animation track names

    • Gets the animation sampler for the specified track.

      Parameters

      • trackName: string

        The name of the animation track

      Returns AnimationSampler

      The animation sampler for the specified track

      When the specified animation track is not found

    • Number of actual interpolations performed. Intended for tests and benchmarks.

      Returns number

    • Gets the track name of the sampler that is actually bound as the first animation. This can differ from the requested active track when that track has no sampler.

      Returns string

      The track name of the currently evaluated first sampler

    • Gets the name of the first (primary) active animation track.

      Returns string

      The name of the first active animation track

    • Gets the maximum end time of the specified animation track.

      Parameters

      • trackName: string

        The name of the animation track

      Returns number

      The maximum end time of the track

      When the specified animation track is not found

    • Gets the minimum start time of the specified animation track.

      Parameters

      • trackName: string

        The name of the animation track

      Returns number

      The minimum start time of the track

      When the specified animation track is not found

    • Returns the vector components as a regular JavaScript array.

      Returns number[]

      An array containing the x, y, z, and w components

    • Gets the track name of the sampler that is actually bound as the second animation. This can differ from the requested active track when that track has no sampler.

      Returns string | undefined

      The track name of the currently evaluated second sampler, or undefined if none is bound

    • Gets the name of the second (secondary) active animation track.

      Returns string | undefined

      The name of the second active animation track, or undefined if not set

    • Gets the internal value array without allocating a copy. Do not mutate the returned array.

      Returns TypedArray

    • Drops the memoized interpolation result. Call this after mutating sampler data directly.

      Returns void

    • Checks if this vector is a dummy vector (has no components).

      Returns boolean

      True if the vector has no components, false otherwise

    • Checks if this vector is approximately equal to another vector within a specified tolerance.

      Parameters

      • vec: IVector4

        The vector to compare with

      • delta: number = Number.EPSILON

        The tolerance value for comparison (default: Number.EPSILON)

      Returns boolean

      True if the vectors are approximately equal, false otherwise

    • Checks if this vector is strictly equal to another vector (exact component equality).

      Parameters

      • vec: IVector4

        The vector to compare with

      Returns boolean

      True if all components are exactly equal, false otherwise

    • Checks if the internal storage shares the same ArrayBuffer as the provided one. Useful for determining if vectors share underlying memory.

      Parameters

      • arrayBuffer: ArrayBuffer

        The ArrayBuffer to compare against

      Returns boolean

      True if the same ArrayBuffer is used, false otherwise

    • Calculates the length (magnitude) of the vector using the Euclidean norm.

      Returns number

      The length of the vector

    • Calculates the squared length (magnitude) of the vector. This is more efficient than length() when only comparing magnitudes.

      Returns number

      The squared length of the vector

    • Calculates the distance from this vector to another vector.

      Parameters

      • vec: IVector4

        The target vector to calculate distance to

      Returns number

      The distance between the two vectors

    • Sets or adds an animation sampler for the specified track.

      Parameters

      • animationTrackName: string

        The name of the animation track

      • animationSampler: AnimationSampler

        The animation sampler to set for this track

      Returns void

    • Sets the first (primary) active animation track.

      Parameters

      • animationTrackName: string

        The name of the animation track to set as primary

      Returns void

    • Sets the internal Float32Array data and triggers an update.

      Parameters

      • array: Float32Array

        The Float32Array to set as the internal data

      Returns void

    • Sets the second (secondary) active animation track for blending.

      Parameters

      • animationTrackName: string

        The name of the animation track to set as secondary

      Returns void

    • Sets the animation time for this vector. When set, this overrides the global time.

      Parameters

      • time: number

        The time value in seconds

      Returns void

    • Sets the time and blending ratio and evaluates the value at most once.

      Parameters

      • time: number
      • blendingRatio: number

      Returns void

    • Converts the vector to a string representation in the format "(x, y, z, w)".

      Returns string

      A string representation of the vector

    • Converts the vector to an approximately formatted string representation with financial precision. Each component is formatted to a fixed number of decimal places.

      Returns string

      A string with space-separated components followed by a newline

    • Switches back to using the global animation time instead of a custom time. This removes any previously set custom time.

      Returns void

    • Gets the component value at the specified index. Alias for the at() method for convenience.

      Parameters

      • i: number

        The index of the component to retrieve

      Returns number

      The component value at the given index

    • Adds two vectors component-wise and returns a new vector.

      Parameters

      • l_vec: IVector4

        The left operand vector

      • r_vec: IVector4

        The right operand vector

      Returns Vector4

      A new Vector4 containing the sum (l_vec + r_vec)

    • Adds two vectors component-wise and stores the result in the output vector. This method modifies the output vector in-place for better performance.

      Parameters

      • l_vec: IVector4

        The left operand vector

      • r_vec: IVector4

        The right operand vector

      • out: IMutableVector4

        The output vector to store the result (will be modified)

      Returns IMutableVector4

      The modified output vector containing the sum

    • Divides a vector by a scalar value and returns a new vector. If the divisor is zero, the result components will be set to 0 and an error will be logged.

      Parameters

      • vec: IVector4

        The vector to divide

      • value: number

        The scalar value to divide by

      Returns Vector4

      A new Vector4 with each component divided by the scalar

    • Divides a vector by a scalar value and stores the result in the output vector. If the divisor is zero, the result components will be set to 0 and an error will be logged. This method modifies the output vector in-place for better performance.

      Parameters

      • vec: IVector4

        The vector to divide

      • value: number

        The scalar value to divide by

      • out: IMutableVector4

        The output vector to store the result (will be modified)

      Returns IMutableVector4

      The modified output vector with each component divided by the scalar

    • Divides the left vector by the right vector component-wise and returns a new vector. If any component of the right vector is zero, the corresponding result component will be set to 0.

      Parameters

      • l_vec: IVector4

        The left operand vector (dividend)

      • r_vec: IVector4

        The right operand vector (divisor)

      Returns Vector4

      A new Vector4 with component-wise division result

    • Divides the left vector by the right vector component-wise and stores the result in the output vector. If any component of the right vector is zero, the corresponding result component will be set to 0. This method modifies the output vector in-place for better performance.

      Parameters

      • l_vec: IVector4

        The left operand vector (dividend)

      • r_vec: IVector4

        The right operand vector (divisor)

      • out: IMutableVector4

        The output vector to store the result (will be modified)

      Returns IMutableVector4

      The modified output vector with component-wise division result

    • Calculates the dot product of two vectors. The dot product is the sum of the products of corresponding components.

      Parameters

      • l_vec: IVector4

        The left operand vector

      • r_vec: IVector4

        The right operand vector

      Returns number

      The dot product of the two vectors

    • Creates a dummy vector with no components (empty array). This is used as a placeholder when a vector is needed but not yet initialized.

      Returns Vector4

      A new dummy Vector4 with empty components

    • Creates a new Vector4 from an ArrayBuffer. The ArrayBuffer should contain at least 16 bytes (4 float32 values).

      Parameters

      • arrayBuffer: ArrayBuffer

        The ArrayBuffer containing vector data

      Returns Vector4

      A new Vector4 instance using the ArrayBuffer data

    • Creates a new Vector4 from individual component values.

      Parameters

      • x: number

        The X component value

      • y: number

        The Y component value

      • z: number

        The Z component value

      • w: number

        The W component value

      Returns Vector4

      A new Vector4 instance with the specified component values

    • Creates a new Vector4 by copying values from an array. Takes the first 4 elements from the array. If the array has fewer than 4 elements, the remaining components will be undefined.

      Parameters

      • array: number[]

        Array containing numeric values (at least 4 elements recommended)

      Returns Vector4

      A new Vector4 instance with copied values

    • Creates a new Vector4 from a 4-element array by copying the values.

      Parameters

      • array: Array4<number>

        Array containing exactly 4 numeric values [x, y, z, w]

      Returns Vector4

      A new Vector4 instance with the copied values

    • Creates a new Vector4 by copying from a Float32Array. This creates a new Float32Array copy of the input data.

      Parameters

      • float32Array: Float32Array

        The Float32Array to copy from

      Returns Vector4

      A new Vector4 instance with copied Float32Array data

    • Creates a new Vector4 from a Vector3, setting the W component to 1. This is commonly used for converting 3D positions to homogeneous coordinates.

      Parameters

      • vec3: IVector3

        The source Vector3 to copy from

      Returns Vector4

      A new Vector4 with (vec3.x, vec3.y, vec3.z, 1.0)

    • Creates a new Vector4 by copying values from another Vector4.

      Parameters

      • vec4: IVector4

        The source Vector4 to copy from

      Returns Vector4

      A new Vector4 instance with copied values from the source vector

    • Creates a new Vector4 from a Float32Array. The Float32Array is used directly without copying.

      Parameters

      • float32Array: Float32Array

        The Float32Array containing vector components

      Returns Vector4

      A new Vector4 instance using the provided Float32Array

    • Calculates the distance between two vectors.

      Parameters

      Returns number

      The distance between the two vectors

    • Calculates the squared length (magnitude) of a vector. This is more efficient than length() when only comparing magnitudes.

      Parameters

      • vec: IVector4

        The vector to calculate squared length for

      Returns number

      The squared length of the vector

    • Multiplies a vector by a scalar value and returns a new vector. This operation scales the vector while preserving its direction.

      Parameters

      • vec: IVector4

        The vector to multiply

      • value: number

        The scalar value to multiply by

      Returns Vector4

      A new Vector4 with each component multiplied by the scalar

    • Multiplies a vector by a scalar value and stores the result in the output vector. This method modifies the output vector in-place for better performance.

      Parameters

      • vec: IVector4

        The vector to multiply

      • value: number

        The scalar value to multiply by

      • out: IMutableVector4

        The output vector to store the result (will be modified)

      Returns IMutableVector4

      The modified output vector with each component multiplied by the scalar

    • Multiplies two vectors component-wise and returns a new vector. This is also known as the Hadamard product or element-wise multiplication.

      Parameters

      • l_vec: IVector4

        The left operand vector

      • r_vec: IVector4

        The right operand vector

      Returns Vector4

      A new Vector4 with each component being the product of corresponding components

    • Multiplies two vectors component-wise and stores the result in the output vector. This method modifies the output vector in-place for better performance.

      Parameters

      • l_vec: IVector4

        The left operand vector

      • r_vec: IVector4

        The right operand vector

      • out: IMutableVector4

        The output vector to store the result (will be modified)

      Returns IMutableVector4

      The modified output vector with component-wise multiplication result

    • Creates a normalized version of the given vector. A normalized vector has a length of 1 while maintaining its direction.

      Parameters

      Returns Vector4

      A new normalized Vector4

    • Creates a vector with all components set to 1 (1, 1, 1, 1).

      Returns Vector4

      A new Vector4 with all components set to 1

    • Subtracts the right vector from the left vector component-wise and returns a new vector.

      Parameters

      • l_vec: IVector4

        The left operand vector (minuend)

      • r_vec: IVector4

        The right operand vector (subtrahend)

      Returns Vector4

      A new Vector4 containing the difference (l_vec - r_vec)

    • Subtracts the right vector from the left vector component-wise and stores the result in the output vector. This method modifies the output vector in-place for better performance.

      Parameters

      • l_vec: IVector4

        The left operand vector (minuend)

      • r_vec: IVector4

        The right operand vector (subtrahend)

      • out: IMutableVector4

        The output vector to store the result (will be modified)

      Returns IMutableVector4

      The modified output vector containing the difference

    • Creates a zero vector (0, 0, 0, 0).

      Returns Vector4

      A new Vector4 with all components set to zero