Vector3

Classed used to store (x,y,z) vector representation A Vector3 is the main object used in 3D geometry It can represent etiher the coordinates of a point the space, either a direction Reminder: Babylon.js uses a left handed forward facing system

Hierarchy

Index

Constructors

constructor

Find examples in Playground
  • new Vector3(x?: number, y?: number, z?: number): Vector3
  • Creates a new Vector3 object from the given x, y, z (floats) coordinates.

    Parameters

    • Optional x: number

      defines the first coordinates (on X axis)

    • Optional y: number

      defines the second coordinates (on Y axis)

    • Optional z: number

      defines the third coordinates (on Z axis)

    Returns Vector3

Properties

isNonUniform

Find examples in Playground
isNonUniform: boolean

Gets a boolean indicating that the vector is non uniform meaning x, y or z are not all the same

x

Find examples in Playground
x: number

Defines the first coordinates (on X axis)

y

Find examples in Playground
y: number

Defines the second coordinates (on Y axis)

z

Find examples in Playground
z: number

Defines the third coordinates (on Z axis)

Methods

add

Find examples in Playground
  • Gets a new Vector3, result of the addition the current Vector3 and the given vector

    Parameters

    Returns Vector3

    the resulting Vector3

addInPlace

Find examples in Playground
  • Adds the given vector to the current Vector3

    Parameters

    Returns Vector3

    the current updated Vector3

addInPlaceFromFloats

Find examples in Playground
  • addInPlaceFromFloats(x: number, y: number, z: number): Vector3
  • Adds the given coordinates to the current Vector3

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns Vector3

    the current updated Vector3

addToRef

Find examples in Playground
  • Adds the current Vector3 to the given one and stores the result in the vector "result"

    Parameters

    Returns Vector3

    the current Vector3

asArray

Find examples in Playground
  • asArray(): number[]
  • Creates an array containing three elements : the coordinates of the Vector3

    Returns number[]

    a new array of numbers

clone

Find examples in Playground
  • Creates a new Vector3 copied from the current Vector3

    Returns Vector3

    the new Vector3

copyFrom

Find examples in Playground
  • Copies the given vector coordinates to the current Vector3 ones

    Parameters

    Returns Vector3

    the current updated Vector3

copyFromFloats

Find examples in Playground
  • copyFromFloats(x: number, y: number, z: number): Vector3
  • Copies the given floats to the current Vector3 coordinates

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns Vector3

    the current updated Vector3

divide

Find examples in Playground
  • Returns a new Vector3 set with the result of the division of the current Vector3 coordinates by the given ones

    Parameters

    Returns Vector3

    the new Vector3

divideInPlace

Find examples in Playground
  • Divides the current Vector3 coordinates by the given ones.

    Parameters

    • otherVector: Vector3

      defines the second operand

    Returns Vector3

    the current updated Vector3

divideToRef

Find examples in Playground
  • Divides the current Vector3 coordinates by the given ones and stores the result in the given vector "result"

    Parameters

    Returns Vector3

    the current Vector3

equals

Find examples in Playground
  • Returns true if the current Vector3 and the given vector coordinates are strictly equal

    Parameters

    Returns boolean

    true if both vectors are equals

equalsToFloats

Find examples in Playground
  • equalsToFloats(x: number, y: number, z: number): boolean
  • Returns true if the current Vector3 coordinates equals the given floats

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns boolean

    true if both vectors are equals

equalsWithEpsilon

Find examples in Playground
  • Returns true if the current Vector3 and the given vector coordinates are distant less than epsilon

    Parameters

    • otherVector: DeepImmutable<Vector3>

      defines the second operand

    • Optional epsilon: number

      defines the minimal distance to define values as equals

    Returns boolean

    true if both vectors are distant less than epsilon

floor

Find examples in Playground
  • Gets a new Vector3 from current Vector3 floored values

    Returns Vector3

    a new Vector3

fract

Find examples in Playground
  • Gets a new Vector3 from current Vector3 floored values

    Returns Vector3

    a new Vector3

getClassName

Find examples in Playground
  • getClassName(): string
  • Gets the class name

    Returns string

    the string "Vector3"

getHashCode

Find examples in Playground
  • getHashCode(): number
  • Creates the Vector3 hash code

    Returns number

    a number which tends to be unique between Vector3 instances

length

Find examples in Playground
  • length(): number
  • Gets the length of the Vector3

    Returns number

    the length of the Vecto3

lengthSquared

Find examples in Playground
  • lengthSquared(): number
  • Gets the squared length of the Vector3

    Returns number

    squared length of the Vector3

maximizeInPlace

Find examples in Playground
  • Updates the current Vector3 with the maximal coordinate values between its and the given vector ones.

    Parameters

    Returns Vector3

    the current updated Vector3

maximizeInPlaceFromFloats

Find examples in Playground
  • maximizeInPlaceFromFloats(x: number, y: number, z: number): Vector3
  • Updates the current Vector3 with the maximal coordinate values between its and the given coordinates.

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns Vector3

    the current updated Vector3

minimizeInPlace

Find examples in Playground
  • Updates the current Vector3 with the minimal coordinate values between its and the given vector ones

    Parameters

    Returns Vector3

    the current updated Vector3

minimizeInPlaceFromFloats

Find examples in Playground
  • minimizeInPlaceFromFloats(x: number, y: number, z: number): Vector3
  • Updates the current Vector3 with the minimal coordinate values between its and the given coordinates

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns Vector3

    the current updated Vector3

multiply

Find examples in Playground
  • Returns a new Vector3, result of the multiplication of the current Vector3 by the given vector

    Parameters

    Returns Vector3

    the new Vector3

multiplyByFloats

Find examples in Playground
  • multiplyByFloats(x: number, y: number, z: number): Vector3
  • Returns a new Vector3 set with the result of the mulliplication of the current Vector3 coordinates by the given floats

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns Vector3

    the new Vector3

multiplyInPlace

Find examples in Playground
  • Multiplies the current Vector3 coordinates by the given ones

    Parameters

    Returns Vector3

    the current updated Vector3

multiplyToRef

Find examples in Playground
  • Multiplies the current Vector3 by the given one and stores the result in the given vector "result"

    Parameters

    Returns Vector3

    the current Vector3

negate

Find examples in Playground
  • Gets a new Vector3 set with the current Vector3 negated coordinates

    Returns Vector3

    a new Vector3

normalize

Find examples in Playground
  • Normalize the current Vector3. Please note that this is an in place operation.

    Returns Vector3

    the current updated Vector3

normalizeFromLength

Find examples in Playground
  • normalizeFromLength(len: number): Vector3
  • Normalize the current Vector3 with the given input length. Please note that this is an in place operation.

    Parameters

    • len: number

      the length of the vector

    Returns Vector3

    the current updated Vector3

normalizeToNew

Find examples in Playground
  • Normalize the current Vector3 to a new vector

    Returns Vector3

    the new Vector3

normalizeToRef

Find examples in Playground
  • Normalize the current Vector3 to the reference

    Parameters

    Returns Vector3

    the updated Vector3

reorderInPlace

Find examples in Playground
  • reorderInPlace(order: string): this
  • Reorders the x y z properties of the vector in place

    Parameters

    • order: string

      new ordering of the properties (eg. for vector 1,2,3 with "ZYX" will produce 3,2,1)

    Returns this

    the current updated vector

rotateByQuaternionAroundPointToRef

Find examples in Playground
  • Rotates a vector around a given point

    Parameters

    • quaternion: Quaternion

      the rotation quaternion

    • point: Vector3

      the point to rotate around

    • result: Vector3

      vector to store the result

    Returns Vector3

    the resulting vector

rotateByQuaternionToRef

Find examples in Playground
  • Rotates the vector around 0,0,0 by a quaternion

    Parameters

    • quaternion: Quaternion

      the rotation quaternion

    • result: Vector3

      vector to store the result

    Returns Vector3

    the resulting vector

scale

Find examples in Playground
  • Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float "scale"

    Parameters

    • scale: number

      defines the multiplier factor

    Returns Vector3

    a new Vector3

scaleAndAddToRef

Find examples in Playground
  • Scale the current Vector3 values by a factor and add the result to a given Vector3

    Parameters

    • scale: number

      defines the scale factor

    • result: Vector3

      defines the Vector3 object where to store the result

    Returns Vector3

    the unmodified current Vector3

scaleInPlace

Find examples in Playground
  • scaleInPlace(scale: number): Vector3
  • Multiplies the Vector3 coordinates by the float "scale"

    Parameters

    • scale: number

      defines the multiplier factor

    Returns Vector3

    the current updated Vector3

scaleToRef

Find examples in Playground
  • Multiplies the current Vector3 coordinates by the float "scale" and stores the result in the given vector "result" coordinates

    Parameters

    • scale: number

      defines the multiplier factor

    • result: Vector3

      defines the Vector3 object where to store the result

    Returns Vector3

    the current Vector3

set

Find examples in Playground
  • set(x: number, y: number, z: number): Vector3
  • Copies the given floats to the current Vector3 coordinates

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns Vector3

    the current updated Vector3

setAll

Find examples in Playground
  • Copies the given float to the current Vector3 coordinates

    Parameters

    • v: number

      defines the x, y and z coordinates of the operand

    Returns Vector3

    the current updated Vector3

subtract

Find examples in Playground
  • Returns a new Vector3, result of the subtraction of the given vector from the current Vector3

    Parameters

    Returns Vector3

    the resulting Vector3

subtractFromFloats

Find examples in Playground
  • subtractFromFloats(x: number, y: number, z: number): Vector3
  • Returns a new Vector3 set with the subtraction of the given floats from the current Vector3 coordinates

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    Returns Vector3

    the resulting Vector3

subtractFromFloatsToRef

Find examples in Playground
  • subtractFromFloatsToRef(x: number, y: number, z: number, result: Vector3): Vector3
  • Subtracts the given floats from the current Vector3 coordinates and set the given vector "result" with this result

    Parameters

    • x: number

      defines the x coordinate of the operand

    • y: number

      defines the y coordinate of the operand

    • z: number

      defines the z coordinate of the operand

    • result: Vector3

      defines the Vector3 object where to store the result

    Returns Vector3

    the current Vector3

subtractInPlace

Find examples in Playground
  • Subtract the given vector from the current Vector3

    Parameters

    Returns Vector3

    the current updated Vector3

subtractToRef

Find examples in Playground
  • Subtracts the given vector from the current Vector3 and stores the result in the vector "result".

    Parameters

    Returns Vector3

    the current Vector3

toArray

Find examples in Playground
  • Populates the given array or Float32Array from the given index with the successive coordinates of the Vector3

    Parameters

    • array: FloatArray

      defines the destination array

    • Optional index: number

      defines the offset in the destination array

    Returns Vector3

    the current Vector3

toQuaternion

Find examples in Playground
  • Converts the current Vector3 into a quaternion (considering that the Vector3 contains Euler angles representation of a rotation)

    Returns Quaternion

    a new Quaternion object, computed from the Vector3 coordinates

toString

Find examples in Playground
  • toString(): string
  • Creates a string representation of the Vector3

    Returns string

    a string with the Vector3 coordinates.

Static Backward

Find examples in Playground
  • Returns a new Vector3 set to (0.0, 0.0, -1.0)

    Returns Vector3

    a new forward Vector3

Static CatmullRom

Find examples in Playground
  • Returns a new Vector3 located for "amount" on the CatmullRom interpolation spline defined by the vectors "value1", "value2", "value3", "value4"

    Parameters

    Returns Vector3

    the new Vector3

Static Center

Find examples in Playground

Static Clamp

Find examples in Playground
  • Returns a new Vector3 set with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max" If a coordinate value of "value" is lower than one of the "min" coordinate, then this "value" coordinate is set with the "min" one If a coordinate value of "value" is greater than one of the "max" coordinate, then this "value" coordinate is set with the "max" one

    Parameters

    Returns Vector3

    the new Vector3

Static ClampToRef

Find examples in Playground
  • Sets the given vector "result" with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max" If a coordinate value of "value" is lower than one of the "min" coordinate, then this "value" coordinate is set with the "min" one If a coordinate value of "value" is greater than one of the "max" coordinate, then this "value" coordinate is set with the "max" one

    Parameters

    Returns void

Static Cross

Find examples in Playground
  • Returns a new Vector3 as the cross product of the vectors "left" and "right" The cross product is then orthogonal to both "left" and "right"

    Parameters

    Returns Vector3

    the cross product

Static CrossToRef

Find examples in Playground
  • Sets the given vector "result" with the cross product of "left" and "right" The cross product is then orthogonal to both "left" and "right"

    Parameters

    • left: Vector3

      defines the left operand

    • right: Vector3

      defines the right operand

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static Distance

Find examples in Playground
  • Returns the distance between the vectors "value1" and "value2"

    Parameters

    Returns number

    the distance

Static DistanceSquared

Find examples in Playground
  • Returns the squared distance between the vectors "value1" and "value2"

    Parameters

    Returns number

    the squared distance

Static Dot

Find examples in Playground
  • Returns the dot product (float) between the vectors "left" and "right"

    Parameters

    Returns number

    the dot product

Static Down

Find examples in Playground
  • Returns a new Vector3 set to (0.0, -1.0, 0.0)

    Returns Vector3

    a new down Vector3

Static Forward

Find examples in Playground
  • Returns a new Vector3 set to (0.0, 0.0, 1.0)

    Returns Vector3

    a new forward Vector3

Static FromArray

Find examples in Playground
  • Returns a new Vector3 set from the index "offset" of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the source array

    • Optional offset: number

      defines the offset in the source array

    Returns Vector3

    the new Vector3

Static FromArrayToRef

Find examples in Playground
  • Sets the given vector "result" with the element values from the index "offset" of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the source array

    • offset: number

      defines the offset in the source array

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static FromFloatArray

Find examples in Playground
  • Returns a new Vector3 set from the index "offset" of the given Float32Array This function is deprecated. Use FromArray instead

    Parameters

    • array: DeepImmutable<Float32Array>

      defines the source array

    • Optional offset: number

      defines the offset in the source array

    Returns Vector3

    the new Vector3

Static FromFloatArrayToRef

Find examples in Playground
  • Sets the given vector "result" with the element values from the index "offset" of the given Float32Array This function is deprecated. Use FromArrayToRef instead.

    Parameters

    • array: DeepImmutable<Float32Array>

      defines the source array

    • offset: number

      defines the offset in the source array

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static FromFloatsToRef

Find examples in Playground
  • FromFloatsToRef(x: number, y: number, z: number, result: Vector3): void
  • Sets the given vector "result" with the given floats.

    Parameters

    • x: number

      defines the x coordinate of the source

    • y: number

      defines the y coordinate of the source

    • z: number

      defines the z coordinate of the source

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static GetAngleBetweenVectors

Find examples in Playground

Static GetClipFactor

Find examples in Playground

Static Hermite

Find examples in Playground
  • Returns a new Vector3 located for "amount" (float) on the Hermite interpolation spline defined by the vectors "value1", "tangent1", "value2", "tangent2"

    Parameters

    Returns Vector3

    the new Vector3

Static Left

Find examples in Playground
  • Returns a new Vector3 set to (-1.0, 0.0, 0.0)

    Returns Vector3

    a new left Vector3

Static Lerp

Find examples in Playground
  • Returns a new Vector3 located for "amount" (float) on the linear interpolation between the vectors "start" and "end"

    Parameters

    Returns Vector3

    the new Vector3

Static LerpToRef

Find examples in Playground
  • Sets the given vector "result" with the result of the linear interpolation from the vector "start" for "amount" to the vector "end"

    Parameters

    Returns void

Static Maximize

Find examples in Playground

Static Minimize

Find examples in Playground

Static Normalize

Find examples in Playground
  • Returns a new Vector3 as the normalization of the given vector

    Parameters

    Returns Vector3

    the new Vector3

Static NormalizeToRef

Find examples in Playground
  • Sets the given vector "result" with the normalization of the given first vector

    Parameters

    Returns void

Static One

Find examples in Playground
  • Returns a new Vector3 set to (1.0, 1.0, 1.0)

    Returns Vector3

    a new unit Vector3

Static Project

Find examples in Playground

Static Right

Find examples in Playground
  • Returns a new Vector3 set to (1.0, 0.0, 0.0)

    Returns Vector3

    a new right Vector3

Static RotationFromAxis

Find examples in Playground
  • Given three orthogonal normalized left-handed oriented Vector3 axis in space (target system), RotationFromAxis() returns the rotation Euler angles (ex : rotation.x, rotation.y, rotation.z) to apply to something in order to rotate it from its local system to the given target system Note: axis1, axis2 and axis3 are normalized during this operation

    Parameters

    Returns Vector3

    a new Vector3

Static RotationFromAxisToRef

Find examples in Playground
  • The same than RotationFromAxis but updates the given ref Vector3 parameter instead of returning a new Vector3

    Parameters

    Returns void

Static TransformCoordinates

Find examples in Playground
  • Returns a new Vector3 set with the result of the transformation by the given matrix of the given vector. This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)

    Parameters

    Returns Vector3

    the transformed Vector3

Static TransformCoordinatesFromFloatsToRef

Find examples in Playground
  • TransformCoordinatesFromFloatsToRef(x: number, y: number, z: number, transformation: DeepImmutable<Matrix>, result: Vector3): void
  • Sets the given vector "result" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z) This method computes tranformed coordinates only, not transformed direction vectors

    Parameters

    • x: number

      define the x coordinate of the source vector

    • y: number

      define the y coordinate of the source vector

    • z: number

      define the z coordinate of the source vector

    • transformation: DeepImmutable<Matrix>

      defines the transformation matrix

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static TransformCoordinatesToRef

Find examples in Playground
  • Sets the given vector "result" coordinates with the result of the transformation by the given matrix of the given vector This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account)

    Parameters

    Returns void

Static TransformNormal

Find examples in Playground
  • Returns a new Vector3 set with the result of the normal transformation by the given matrix of the given vector This methods computes transformed normalized direction vectors only (ie. it does not apply translation)

    Parameters

    Returns Vector3

    the new Vector3

Static TransformNormalFromFloatsToRef

Find examples in Playground
  • Sets the given vector "result" with the result of the normal transformation by the given matrix of the given floats (x, y, z) This methods computes transformed normalized direction vectors only (ie. it does not apply translation)

    Parameters

    • x: number

      define the x coordinate of the source vector

    • y: number

      define the y coordinate of the source vector

    • z: number

      define the z coordinate of the source vector

    • transformation: DeepImmutable<Matrix>

      defines the transformation matrix

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static TransformNormalToRef

Find examples in Playground
  • Sets the given vector "result" with the result of the normal transformation by the given matrix of the given vector This methods computes transformed normalized direction vectors only (ie. it does not apply translation)

    Parameters

    Returns void

Static Unproject

Find examples in Playground
  • Unproject from screen space to object space

    Parameters

    • source: DeepImmutable<Vector3>

      defines the screen space Vector3 to use

    • viewportWidth: number

      defines the current width of the viewport

    • viewportHeight: number

      defines the current height of the viewport

    • world: DeepImmutable<Matrix>

      defines the world matrix to use (can be set to Identity to go to world space)

    • view: DeepImmutable<Matrix>

      defines the view matrix to use

    • projection: DeepImmutable<Matrix>

      defines the projection matrix to use

    Returns Vector3

    the new Vector3

Static UnprojectFloatsToRef

Find examples in Playground
  • Unproject from screen space to object space

    Parameters

    • sourceX: float

      defines the screen space x coordinate to use

    • sourceY: float

      defines the screen space y coordinate to use

    • sourceZ: float

      defines the screen space z coordinate to use

    • viewportWidth: number

      defines the current width of the viewport

    • viewportHeight: number

      defines the current height of the viewport

    • world: DeepImmutable<Matrix>

      defines the world matrix to use (can be set to Identity to go to world space)

    • view: DeepImmutable<Matrix>

      defines the view matrix to use

    • projection: DeepImmutable<Matrix>

      defines the projection matrix to use

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static UnprojectFromTransform

Find examples in Playground
  • Unproject from screen space to object space

    Parameters

    • source: Vector3

      defines the screen space Vector3 to use

    • viewportWidth: number

      defines the current width of the viewport

    • viewportHeight: number

      defines the current height of the viewport

    • world: DeepImmutable<Matrix>

      defines the world matrix to use (can be set to Identity to go to world space)

    • transform: DeepImmutable<Matrix>

      defines the transform (view x projection) matrix to use

    Returns Vector3

    the new Vector3

Static UnprojectRayToRef

Find examples in Playground
  • Unproject a ray from screen space to object space

    Parameters

    • sourceX: float

      defines the screen space x coordinate to use

    • sourceY: float

      defines the screen space y coordinate to use

    • viewportWidth: number

      defines the current width of the viewport

    • viewportHeight: number

      defines the current height of the viewport

    • world: DeepImmutable<Matrix>

      defines the world matrix to use (can be set to Identity to go to world space)

    • view: DeepImmutable<Matrix>

      defines the view matrix to use

    • projection: DeepImmutable<Matrix>

      defines the projection matrix to use

    • ray: Ray

      defines the Ray where to store the result

    Returns void

Static UnprojectToRef

Find examples in Playground
  • Unproject from screen space to object space

    Parameters

    • source: DeepImmutable<Vector3>

      defines the screen space Vector3 to use

    • viewportWidth: number

      defines the current width of the viewport

    • viewportHeight: number

      defines the current height of the viewport

    • world: DeepImmutable<Matrix>

      defines the world matrix to use (can be set to Identity to go to world space)

    • view: DeepImmutable<Matrix>

      defines the view matrix to use

    • projection: DeepImmutable<Matrix>

      defines the projection matrix to use

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

Static Up

Find examples in Playground
  • Returns a new Vector3 set to (0.0, 1.0, 0.0)

    Returns Vector3

    a new up Vector3

Static Zero

Find examples in Playground
  • Returns a new Vector3 set to (0.0, 0.0, 0.0)

    Returns Vector3

    a new empty Vector3

Generated using TypeDoc