nape-js API
    Preparing search index...

    Class Vec3

    3D vector used for constraint impulses and other 3-component values.

    Supports object pooling via Vec3.get() / dispose().

    Converted from nape-compiled.js lines 24120–25040.

    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Create a Vec3 with the given components. Defaults to (0, 0, 0).

      Parameters

      • x: number = 0

        The x component.

      • y: number = 0

        The y component.

      • z: number = 0

        The z component.

      Returns Vec3

    Accessors

    • get length(): number

      Magnitude of the 3D vector.

      Returns number

      The Euclidean length sqrt(x² + y² + z²).

    • set length(value: number): void

      Scale the vector to the given magnitude.

      Parameters

      • value: number

      Returns void

      If the vector has zero length.

    Methods

    • Return this Vec3 to the object pool.

      Returns void

      If this Vec3 has already been disposed.

    • Check whether this Vec3 is component-wise equal to another, within an optional epsilon tolerance.

      Parameters

      • other: Vec3

        The Vec3 to compare against.

      • epsilon: number = 0

        Maximum allowed difference per component (default 0).

      Returns boolean

      true if all three components differ by at most epsilon.

    • Squared magnitude. Faster than length as it avoids a square root.

      Returns number

      x² + y² + z².

    • Copy another Vec3's components into this one in-place.

      Parameters

      • vector: Vec3

        The source Vec3 to copy from.

      Returns this

      this for chaining.

    • Set all three components at once in-place.

      Parameters

      • x: number

        The new x component.

      • y: number

        The new y component.

      • z: number

        The new z component.

      Returns this

      this for chaining.

    • String representation { x: … y: … z: … }.

      Returns string

      A human-readable string of the three components.

    • Return the x and y components as a new Vec2.

      Parameters

      • weak: boolean = false

        If true, the returned Vec2 is a weak (pooled) reference.

      Returns Vec2

      A new Vec2 containing this vector's x and y components.

    • Allocate a Vec3 from the public object pool, or create a new one if the pool is empty.

      Parameters

      • x: number = 0

        Initial x component (default 0).

      • y: number = 0

        Initial y component (default 0).

      • z: number = 0

        Initial z component (default 0).

      Returns Vec3

      A Vec3 initialised with the given components.