@pixi/3d
    Preparing search index...

    Class Vector4

    A four-component vector, such as a position with a w, an RGBA colour or a plane equation

    Math methods work on all four components, change the vector they're called on and return it; pass an out point last to write the result there instead. Where a method takes a point, any PointData4D works, such as a plain { x, y, z, w } object.

    const clip = new Vector4(point.x, point.y, point.z, 1).applyMatrix4(camera.viewProjection);

    if (clip.w > 0) clip.divideScalar(clip.w);

    Implements

    Index
    • Creates a new Vector4

      Parameters

      • x: number = 0

        The x component

      • y: number = 0

        The y component

      • z: number = 0

        The z component

      • w: number = 1

        The fourth component, defaults to 1

      Returns Vector4

    w: number = 1

    The fourth component, by convention 1 for a position and 0 for a direction

    const behindCamera = clip.w <= 0;
    
    x: number = 0

    The x component

    const screenX = clip.x / clip.w;
    
    y: number = 0

    The y component

    const screenY = clip.y / clip.w;
    
    z: number = 0

    The z component

    const depth = clip.z / clip.w;
    
    • get shared(): Vector4

      A static Vector4 reset to (0, 0, 0, 1) on every access, for a result used straight away

      Important

      This vector is shared and temporary. Do not store references to it.

      Returns Vector4

      const clipW = Vector4.shared.set(point.x, point.y, point.z).applyMatrix4(camera.viewProjection).w;
      
    • Adds v to this vector

      Parameters

      • v: PointData4D

        The point to add

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      baseColor.add(hitFlash, displayColor);
      
    • Adds v * s to this vector

      Parameters

      • v: PointData4D

        The point to scale and add

      • s: number

        The scalar applied to v

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      color.addScaledVector(colorStep, fadeSpeed * dt);
      
    • Computes the angle between this vector and v across all four components

      Returns π/2 when either vector has zero length.

      Parameters

      Returns number

      The angle in radians, from 0 to π

    • Multiplies this vector by m, w included, without a divide

      A position (w = 1) picks up the matrix's translation and a direction (w = 0) doesn't. With a projection matrix the result is in clip space; divide by w to get x and y from -1 to 1 across the view.

      Parameters

      • m: Matrix4

        The matrix to apply

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      clip.set(point.x, point.y, point.z).applyMatrix4(camera.viewProjection);
      
    • Clamps each component of this vector between the matching components of min and max

      Assumes min <= max componentwise.

      Parameters

      • min: PointData4D

        The lower bound per component

      • max: PointData4D

        The upper bound per component

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      hdrColor.clamp({ x: 0, y: 0, z: 0, w: 0 }, { x: 1, y: 1, z: 1, w: 1 }, displayColor);
      
    • Creates a copy of this vector

      Returns Vector4

      const startColor = color.clone();
      
    • Copies x, y, z, w from the given point into this vector

      Parameters

      Returns this

      previousClip.copyFrom(clip);
      
    • Copies this vector's x, y, z, w into the given point

      Type Parameters

      Parameters

      • p: T

        The point to copy into

      Returns T

      The given point

      clip.copyTo(previousClip);
      
    • Computes the distance from this vector to v across all four components

      Parameters

      Returns number

      const colorDifference = pixel.distanceTo(keyColor);
      
    • Computes the squared distance from this vector to v

      Cheaper than Vector4#distanceTo and enough to compare distances.

      Parameters

      Returns number

      if (pixel.distanceToSquared(keyColor) < tolerance * tolerance) pixel.w = 0;
      
    • Divides each component of this vector by the matching component of v

      Parameters

      • v: PointData4D

        The point to divide by

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      hdrColor.divide(whitePoint, displayColor);
      
    • Divides each component of this vector by the scalar s

      Parameters

      • s: number

        The scalar to divide by

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      clip.divideScalar(clip.w);
      
    • Computes the dot product of this vector and v

      With a plane (nx, ny, nz, d) whose normal has unit length and a point whose w is 1, it's the point's signed distance from the plane.

      Parameters

      Returns number

      const inFront = clipPlane.dot(point) > 0;
      
    • Checks whether x, y, z and w all match p exactly, with no tolerance

      Parameters

      Returns boolean

      if (!tint.equals(lastTint)) applyTint(tint);
      
    • Reads x, y, z, w from array starting at offset

      Parameters

      • array: Float32Array<ArrayBufferLike> | number[]

        The source array

      • offset: number = 0

        Index of the first component in array

      Returns this

      tangent.fromArray(tangents, vertexIndex * 4);
      
    • Computes the length of this vector across all four components

      Returns number

    • Computes the squared length of this vector

      Cheaper than Vector4#magnitude, since it skips the square root, and enough to compare lengths.

      Returns number

      const moving = velocity.magnitudeSquared() > 0.0001;
      
    • Sets each component to the larger of this vector's and v's

      Parameters

      • v: PointData4D

        The point to compare against

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      color.max({ x: 0, y: 0, z: 0, w: 0 });
      
    • Sets each component to the smaller of this vector's and v's

      Parameters

      • v: PointData4D

        The point to compare against

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      color.min({ x: 1, y: 1, z: 1, w: 1 });
      
    • Multiplies each component of this vector by the matching component of v

      Parameters

      • v: PointData4D

        The point to multiply by

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      baseColor.multiply(teamTint, displayColor);
      
    • Multiplies each component of this vector by the scalar s

      Parameters

      • s: number

        The scalar to multiply by

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      color.multiplyScalar(brightness);
      
    • Negates each component of this vector

      Parameters

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      clipPlane.negate();
      
    • Scales this vector to unit length across all four components

      A zero vector stays zero.

      Parameters

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

    • Sets all four components

      Parameters

      • x: number = 0

        The x component

      • y: number = x

        The y component, defaults to x

      • z: number = x

        The z component, defaults to x

      • w: number = 1

        The fourth component, defaults to 1, not to x

      Returns this

      position.set(0, 2, -5);
      direction.set(0, 0, -1, 0);
    • Scales this vector so its length across all four components equals length

      A zero vector stays zero.

      Parameters

      • length: number

        The target length

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

    • Subtracts v from this vector

      Parameters

      • v: PointData4D

        The point to subtract

      • out: PointLike4D = ...

        The target to write the result into, defaults to this vector

      Returns this

      The out point

      targetColor.subtract(color, colorStep);
      
    • Writes this vector's values into array starting at offset

      Type Parameters

      • T extends Float32Array<ArrayBufferLike> | number[] = number[]

      Parameters

      • array: T = ...

        The destination array; a new one is allocated when omitted

      • offset: number = 0

        Index of the first component in array

      Returns T

      The destination array

      color.toArray(instanceColors, instanceIndex * 4);
      
    • Builds a debug string for this vector

      Returns string

      A string of the form [@pixi/3d/math:Vector4 x=... y=... z=... w=...]

      console.log(clip.toString());