Skip to main content

Class: Vec3

Defined in: math/vector3.ts:23

Static operations on Vector3. Mutating operations (set, add, subtract, multiply, multiplyComponents, divide, normalize, floorComponents) mutate their target argument in place and return it, rather than allocating a new Vector3. Read-only operations (magnitude, magnitudeSquared, equals, toString, toFloat32Array) and clone never mutate their arguments.

Constructors​

Constructor​

new Vec3(): Vec3

Returns​

Vec3

Accessors​

backward​

Get Signature​

get static backward(): Vector3

Defined in: math/vector3.ts:84

A unit vector pointing backward (0, 0, -1). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3


down​

Get Signature​

get static down(): Vector3

Defined in: math/vector3.ts:52

A unit vector pointing downward (0, -1, 0). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3


forward​

Get Signature​

get static forward(): Vector3

Defined in: math/vector3.ts:76

A unit vector pointing forward (0, 0, 1). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3


left​

Get Signature​

get static left(): Vector3

Defined in: math/vector3.ts:60

A unit vector pointing left (-1, 0, 0). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3


one​

Get Signature​

get static one(): Vector3

Defined in: math/vector3.ts:36

A vector with components of 1 (1, 1, 1). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3


Get Signature​

get static right(): Vector3

Defined in: math/vector3.ts:68

A unit vector pointing right (1, 0, 0). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3


up​

Get Signature​

get static up(): Vector3

Defined in: math/vector3.ts:44

A unit vector pointing upward (0, 1, 0). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3


zero​

Get Signature​

get static zero(): Vector3

Defined in: math/vector3.ts:28

A zero vector (0, 0, 0). A fresh vector is created on every access, so it's always safe to mutate.

Returns​

Vector3

Methods​

add()​

static add(target, value): Vector3

Defined in: math/vector3.ts:108

Adds another vector into target, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

value​

Vector3

The vector to add.

Returns​

Vector3

target, for chaining.


clone()​

static clone(vector): Vector3

Defined in: math/vector3.ts:225

Creates a deep copy of a vector.

Parameters​

vector​

Vector3

The vector to copy.

Returns​

Vector3

A new Vector3 with the same component values.


divide()​

static divide(target, scalar): Vector3

Defined in: math/vector3.ts:164

Divides target by a scalar value, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

scalar​

number

The scalar value to divide by.

Returns​

Vector3

target, for chaining.


equals()​

static equals(a, b): boolean

Defined in: math/vector3.ts:244

Checks if two vectors are equal.

Parameters​

a​

Vector3

The first vector.

b​

Vector3

The second vector.

Returns​

boolean

True if the vectors have the same components, false otherwise.


floorComponents()​

static floorComponents(target): Vector3

Defined in: math/vector3.ts:212

Rounds target's components down to the nearest integer, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

Returns​

Vector3

target, for chaining.


magnitude()​

static magnitude(vector): number

Defined in: math/vector3.ts:187

Calculates the magnitude (length) of a vector.

Parameters​

vector​

Vector3

The vector.

Returns​

number

The magnitude of the vector.


magnitudeSquared()​

static magnitudeSquared(vector): number

Defined in: math/vector3.ts:178

Calculates the squared magnitude of a vector. This is faster than Vec3.magnitude as it avoids the square root.

Parameters​

vector​

Vector3

The vector.

Returns​

number

The squared magnitude of the vector.


multiply()​

static multiply(target, scalar): Vector3

Defined in: math/vector3.ts:136

Multiplies target by a scalar value, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

scalar​

number

The scalar value to multiply by.

Returns​

Vector3

target, for chaining.


multiplyComponents()​

static multiplyComponents(target, value): Vector3

Defined in: math/vector3.ts:150

Multiplies target's components by another vector's components, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

value​

Vector3

The vector to multiply components with.

Returns​

Vector3

target, for chaining.


normalize()​

static normalize(target): Vector3

Defined in: math/vector3.ts:197

Normalizes target to unit length in the same direction, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

Returns​

Vector3

target, for chaining.

Throws​

An error if target has zero length, since its direction is undefined.


set()​

static set(target, value): Vector3

Defined in: math/vector3.ts:94

Sets a vector's components to match another vector, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

value​

Vector3

The vector to copy components from.

Returns​

Vector3

target, for chaining.


subtract()​

static subtract(target, value): Vector3

Defined in: math/vector3.ts:122

Subtracts another vector from target, mutating it in place.

Parameters​

target​

Vector3

The vector to mutate.

value​

Vector3

The vector to subtract.

Returns​

Vector3

target, for chaining.


toFloat32Array()​

static toFloat32Array(vector): Float32Array

Defined in: math/vector3.ts:253

Converts a vector to a glsl-compatible float32 array.

Parameters​

vector​

Vector3

The vector.

Returns​

Float32Array

The 3d vector array (e.g. [5, 3, 8] for { x: 5, y: 3, z: 8 }).


toString()​

static toString(vector): string

Defined in: math/vector3.ts:234

Returns a string representation of a vector.

Parameters​

vector​

Vector3

The vector.

Returns​

string

A string in the format "(x, y, z)" with components rounded to 1 decimal place.