Options
All
  • Public
  • Public/Protected
  • All
Menu

Class used to store (x,y,z) vector representation A Vector3 is the main object used in 3D geometry It can represent either the coordinates of a point the space, either a direction Reminder: js uses a left handed forward facing system Example Playground - Overview - https://playground.babylonjs.com/#R1F8YU

Hierarchy

Index

Constructors

Accessors

Methods

Constructors

  • 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

Accessors

  • get hasAZeroComponent(): boolean
  • get isNonUniform(): boolean
  • Gets a boolean indicating that the vector is non uniform meaning x, y or z are not all the same

    Returns boolean

  • get x(): number
  • set x(value: number): void
  • Gets or sets the x coordinate

    Returns number

  • Gets or sets the x coordinate

    Parameters

    • value: number

    Returns void

  • get y(): number
  • set y(value: number): void
  • Gets or sets the y coordinate

    Returns number

  • Gets or sets the y coordinate

    Parameters

    • value: number

    Returns void

  • get z(): number
  • set z(value: number): void
  • Gets or sets the z coordinate

    Returns number

  • Gets or sets the z coordinate

    Parameters

    • value: number

    Returns void

  • Gets a backward Vector3 that must not be updated

    Returns DeepImmutableObject<Vector3>

  • Gets a backward Vector3 that must not be updated

    Returns DeepImmutableObject<Vector3>

Methods

  • addInPlaceFromFloats(x: number, y: number, z: number): Vector3
  • Adds the given coordinates to the current Vector3 Example Playground https://playground.babylonjs.com/#R1F8YU#5

    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

  • Adds the current Vector3 to the given one and stores the result in the vector "result" Example Playground https://playground.babylonjs.com/#R1F8YU#6

    Type Parameters

    Parameters

    • otherVector: DeepImmutableObject<Vector3>

      defines the second operand

    • result: T

      defines the Vector3 object where to store the result

    Returns T

    the result

  • applyRotationQuaternionToRef<T>(q: Quaternion, result: T): T
  • Rotates the vector using the given unit quaternion and stores the new vector in result Example Playground https://playground.babylonjs.com/#R1F8YU#9

    Type Parameters

    Parameters

    • q: Quaternion

      the unit quaternion representing the rotation

    • result: T

      the output vector

    Returns T

    the result

  • asArray(): number[]
  • Creates an array containing three elements : the coordinates of the Vector3 Example Playground https://playground.babylonjs.com/#R1F8YU#10

    Returns number[]

    a new array of numbers

  • copyFromFloats(x: number, y: number, z: number): Vector3
  • Copies the given floats to the current Vector3 coordinates Example Playground https://playground.babylonjs.com/#R1F8YU#13

    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

  • Returns a new Vector3 as the cross product of the current vector and the "other" one The cross product is then orthogonal to both current and "other" Example Playground https://playground.babylonjs.com/#R1F8YU#14

    Parameters

    • other: Vector3

      defines the right operand

    Returns Vector3

    the cross product

  • Divides the current Vector3 coordinates by the given ones and stores the result in the given vector "result" Example Playground https://playground.babylonjs.com/#R1F8YU#18

    Type Parameters

    Parameters

    • otherVector: DeepImmutableObject<Vector3>

      defines the second operand

    • result: T

      defines the Vector3 object where to store the result

    Returns T

    the result

  • equalsToFloats(x: number, y: number, z: number): boolean
  • Returns true if the current Vector3 coordinates equals the given floats Example Playground https://playground.babylonjs.com/#R1F8YU#20

    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 equal

  • Returns true if the current Vector3 and the given vector coordinates are distant less than epsilon Example Playground https://playground.babylonjs.com/#R1F8YU#21

    Parameters

    • otherVector: DeepImmutableObject<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

  • Update the current vector from an array Example Playground https://playground.babylonjs.com/#R1F8YU#24

    Parameters

    • array: FloatArray

      defines the destination array

    • Optional index: number

      defines the offset in the destination array

    Returns Vector3

    the current Vector3

  • getClassName(): string
  • Gets the class name

    Returns string

    the string "Vector3"

  • getHashCode(): number
  • Creates the Vector3 hash code

    Returns number

    a number which tends to be unique between Vector3 instances

  • Creates a vector normal (perpendicular) to the current Vector3 and stores the result in the given vector Out of the infinite possibilities the normal chosen is the one formed by rotating the current vector 90 degrees about an axis which lies perpendicular to the current vector and its projection on the xz plane. In the case of a current vector in the xz plane the normal is calculated to be along the y axis. Example Playground https://playground.babylonjs.com/#R1F8YU#230 Example Playground https://playground.babylonjs.com/#R1F8YU#231

    Parameters

    Returns Vector3

  • isNonUniformWithinEpsilon(epsilon: number): boolean
  • Due to float precision, scale of a mesh could be uniform but float values are off by a small fraction Check if is non uniform within a certain amount of decimal places to account for this

    Parameters

    • epsilon: number

      the amount the values can differ

    Returns boolean

    if the the vector is non uniform to a certain number of decimal places

  • length(): number
  • lengthSquared(): number
  • maximizeInPlaceFromFloats(x: number, y: number, z: number): Vector3
  • Updates the current Vector3 with the maximal coordinate values between its and the given coordinates. Example Playground https://playground.babylonjs.com/#R1F8YU#28

    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

  • minimizeInPlaceFromFloats(x: number, y: number, z: number): Vector3
  • Updates the current Vector3 with the minimal coordinate values between its and the given coordinates Example Playground https://playground.babylonjs.com/#R1F8YU#30

    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

  • multiplyByFloats(x: number, y: number, z: number): Vector3
  • Returns a new Vector3 set with the result of the multiplication of the current Vector3 coordinates by the given floats Example Playground https://playground.babylonjs.com/#R1F8YU#34

    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

  • Multiplies the current Vector3 by the given one and stores the result in the given vector "result" Example Playground https://playground.babylonjs.com/#R1F8YU#33

    Type Parameters

    Parameters

    • otherVector: DeepImmutableObject<Vector3>

      defines the second operand

    • result: T

      defines the Vector3 object where to store the result

    Returns T

    the result

  • negateToRef<T>(result: T): T
  • Negate the current Vector3 and stores the result in the given vector "result" coordinates Example Playground https://playground.babylonjs.com/#R1F8YU#37

    Type Parameters

    Parameters

    • result: T

      defines the Vector3 object where to store the result

    Returns T

    the result

  • normalizeFromLength(len: number): Vector3
  • Normalize the current Vector3 with the given input length. Please note that this is an in place operation. Example Playground https://playground.babylonjs.com/#R1F8YU#123

    Parameters

    • len: number

      the length of the vector

    Returns Vector3

    the current updated Vector3

  • normalizeToRef<T>(reference: T): T
  • Normalize the current Vector3 to the reference Example Playground https://playground.babylonjs.com/#R1F8YU#125

    Type Parameters

    Parameters

    • reference: T

      define the Vector3 to update

    Returns T

    the updated Vector3

  • Projects the current point Vector3 to a plane along a ray starting from a specified origin and passing through the current point Vector3. Example Playground https://playground.babylonjs.com/#R1F8YU#48

    Type Parameters

    Parameters

    • plane: Plane

      defines the plane to project to

    • origin: Vector3

      defines the origin of the projection ray

    Returns T

    the projected vector3

  • projectOnPlaneToRef<T>(plane: Plane, origin: Vector3, result: T): T
  • Projects the current point Vector3 to a plane along a ray starting from a specified origin and passing through the current point Vector3. Example Playground https://playground.babylonjs.com/#R1F8YU#49

    Type Parameters

    Parameters

    • plane: Plane

      defines the plane to project to

    • origin: Vector3

      defines the origin of the projection ray

    • result: T

      defines the Vector3 where to store the result

    Returns T

    result input

  • reorderInPlace(order: string): Vector3
  • Reorders the x y z properties of the vector in place Example Playground https://playground.babylonjs.com/#R1F8YU#44

    Parameters

    • order: string

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

    Returns Vector3

    the current updated vector

  • rotateByQuaternionAroundPointToRef<T>(quaternion: Quaternion, point: Vector3, result: T): T
  • Rotates a vector around a given point Example Playground https://playground.babylonjs.com/#R1F8YU#46

    Type Parameters

    Parameters

    • quaternion: Quaternion

      the rotation quaternion

    • point: Vector3

      the point to rotate around

    • result: T

      vector to store the result

    Returns T

    the resulting vector

  • rotateByQuaternionToRef<T>(quaternion: Quaternion, result: T): T
  • Rotates the vector around 0,0,0 by a quaternion Example Playground https://playground.babylonjs.com/#R1F8YU#47

    Type Parameters

    Parameters

    • quaternion: Quaternion

      the rotation quaternion

    • result: T

      vector to store the result

    Returns T

    the resulting vector

  • Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float "scale" Example Playground https://playground.babylonjs.com/#R1F8YU#53

    Parameters

    • scale: number

      defines the multiplier factor

    Returns Vector3

    a new Vector3

  • scaleAndAddToRef<T>(scale: number, result: T): T
  • Scale the current Vector3 values by a factor and add the result to a given Vector3 Example Playground https://playground.babylonjs.com/#R1F8YU#55

    Type Parameters

    Parameters

    • scale: number

      defines the scale factor

    • result: T

      defines the Vector3 object where to store the result

    Returns T

    result input

  • scaleInPlace(scale: number): Vector3
  • Multiplies the Vector3 coordinates by the float "scale" Example Playground https://playground.babylonjs.com/#R1F8YU#56

    Parameters

    • scale: number

      defines the multiplier factor

    Returns Vector3

    the current updated Vector3

  • scaleToRef<T>(scale: number, result: T): T
  • Multiplies the current Vector3 coordinates by the float "scale" and stores the result in the given vector "result" coordinates Example Playground https://playground.babylonjs.com/#R1F8YU#57

    Type Parameters

    Parameters

    • scale: number

      defines the multiplier factor

    • result: T

      defines the Vector3 object where to store the result

    Returns T

    the result

  • set(x: number, y: number, z: number): Vector3
  • Copies the given floats to the current Vector3 coordinates Example Playground https://playground.babylonjs.com/#R1F8YU#58

    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

  • Copies the given float to the current Vector3 coordinates Example Playground https://playground.babylonjs.com/#R1F8YU#59

    Parameters

    • v: number

      defines the x, y and z coordinates of the operand

    Returns Vector3

    the current updated Vector3

  • 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 Example Playground https://playground.babylonjs.com/#R1F8YU#62

    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<T>(x: number, y: number, z: number, result: T): T
  • Subtracts the given floats from the current Vector3 coordinates and set the given vector "result" with this result Example Playground https://playground.babylonjs.com/#R1F8YU#64

    Type Parameters

    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: T

      defines the Vector3 object where to store the result

    Returns T

    the result

  • Subtracts the given vector from the current Vector3 and stores the result in the vector "result". Example Playground https://playground.babylonjs.com/#R1F8YU#63

    Type Parameters

    Parameters

    • otherVector: DeepImmutableObject<Vector3>

      defines the second operand

    • result: T

      defines the Vector3 object where to store the result

    Returns T

    the result

  • Populates the given array or Float32Array from the given index with the successive coordinates of the Vector3 Example Playground https://playground.babylonjs.com/#R1F8YU#65

    Parameters

    • array: FloatArray

      defines the destination array

    • Optional index: number

      defines the offset in the destination array

    Returns Vector3

    the current Vector3

  • Converts the current Vector3 into a quaternion (considering that the Vector3 contains Euler angles representation of a rotation) Example Playground https://playground.babylonjs.com/#R1F8YU#66

    Returns Quaternion

    a new Quaternion object, computed from the Vector3 coordinates

  • toString(): string
  • Backward(rightHandedSystem?: boolean): Vector3
  • Returns a new Vector3 set to (0.0, 0.0, -1.0) Example Playground https://playground.babylonjs.com/#R1F8YU#71

    Parameters

    • Optional rightHandedSystem: boolean

      is the scene right-handed (negative-z)

    Returns Vector3

    a new Backward Vector3

  • 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 Example Playground https://playground.babylonjs.com/#R1F8YU#76

    Type Parameters

    Parameters

    Returns T

    the new Vector3

  • 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 Example Playground https://playground.babylonjs.com/#R1F8YU#77

    Type Parameters

    Parameters

    Returns T

    result input

  • Forward(rightHandedSystem?: boolean): Vector3
  • Returns a new Vector3 set to (0.0, 0.0, 1.0) Example Playground https://playground.babylonjs.com/#R1F8YU#71

    Parameters

    • Optional rightHandedSystem: boolean

      is the scene right-handed (negative z)

    Returns Vector3

    a new forward Vector3

  • Returns a new Vector3 set from the index "offset" of the given array Example Playground https://playground.babylonjs.com/#R1F8YU#83

    Parameters

    • array: DeepImmutableObject<ArrayLike<number>>

      defines the source array

    • Optional offset: number

      defines the offset in the source array

    Returns Vector3

    the new Vector3

  • Sets the given vector "result" with the element values from the index "offset" of the given array Example Playground https://playground.babylonjs.com/#R1F8YU#84

    Type Parameters

    Parameters

    • array: DeepImmutableObject<ArrayLike<number>>

      defines the source array

    • offset: number

      defines the offset in the source array

    • result: T

      defines the Vector3 where to store the result

    Returns T

    result input

  • Returns a new Vector3 set from the index "offset" of the given Float32Array

    deprecated

    Please use FromArray instead.

    Parameters

    • array: DeepImmutableObject<Float32Array>

      defines the source array

    • Optional offset: number

      defines the offset in the source array

    Returns Vector3

    the new Vector3

  • Sets the given vector "result" with the element values from the index "offset" of the given Float32Array

    deprecated

    Please use FromArrayToRef instead.

    Type Parameters

    Parameters

    • array: DeepImmutableObject<Float32Array>

      defines the source array

    • offset: number

      defines the offset in the source array

    • result: T

      defines the Vector3 where to store the result

    Returns T

  • FromFloatsToRef<T>(x: number, y: number, z: number, result: T): T
  • Sets the given vector "result" with the given floats. Example Playground https://playground.babylonjs.com/#R1F8YU#85

    Type Parameters

    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: T

      defines the Vector3 where to store the result

    Returns T

  • Get angle between two vectors projected on a plane Example Playground https://playground.babylonjs.com/#R1F8YU#87 Expectation compute time: 0.01 ms (median) and 0.02 ms (percentile 95%)

    Parameters

    • vector0: Vector3

      angle between vector0 and vector1

    • vector1: Vector3

      angle between vector0 and vector1

    • normal: Vector3

      Normal of the projection plane

    Returns number

    the angle in radians (float) between vector0 and vector1 projected on the plane with the specified normal

  • Returns a new Vector3 located for "amount" (float) on the linear interpolation between the vectors "start" and "end" Example Playground https://playground.babylonjs.com/#R1F8YU#95

    Type Parameters

    Parameters

    Returns T

    the new Vector3

  • Sets the given vector "result" with the result of the linear interpolation from the vector "start" for "amount" to the vector "end" Example Playground https://playground.babylonjs.com/#R1F8YU#93

    Type Parameters

    Parameters

    Returns T

    result input

  • Sets the given vector "result" with the normalization of the given first vector Example Playground https://playground.babylonjs.com/#R1F8YU#98

    Type Parameters

    Parameters

    Returns T

    result input

  • Returns a new Vector3 set to (1.0, 1.0, 1.0)

    Returns Vector3

    a new Vector3

  • Gets the rotation that aligns the roll axis (Y) to the line joining the start point to the target point Example PG https://playground.babylonjs.com/#R1F8YU#188

    Parameters

    Returns Vector3

    the rotation in the form (pitch, yaw, 0)

  • PitchYawRollToMoveBetweenPointsToRef<T>(start: Vector3, target: Vector3, ref: T): T
  • Gets the rotation that aligns the roll axis (Y) to the line joining the start point to the target point and stores it in the ref Vector3 Example PG https://playground.babylonjs.com/#R1F8YU#189

    Type Parameters

    Parameters

    • start: Vector3

      the starting point

    • target: Vector3

      the target point

    • ref: T

      the vector3 to store the result

    Returns T

    ref in the form (pitch, yaw, 0)

  • Random(min?: number, max?: number): Vector3
  • Returns a new Vector3 with random values between min and max

    Parameters

    • Optional min: number

      the minimum random value

    • Optional max: number

      the maximum random value

    Returns Vector3

    a Vector3 with random values between min and max

  • Reflects a vector off the plane defined by a normalized normal

    Type Parameters

    Parameters

    Returns Vector3

    the resulting vector

  • Reflects a vector off the plane defined by a normalized normal to reference

    Type Parameters

    Parameters

    Returns T

    the resulting vector

  • SlerpToRef<T>(vector0: Vector3, vector1: Vector3, slerp: number, result: T): T
  • SmoothToRef<T>(source: Vector3, goal: Vector3, deltaTime: number, lerpTime: number, result: T): T
  • Smooth interpolation between two vectors using Slerp Example Playground https://playground.babylonjs.com/#R1F8YU#110

    Type Parameters

    Parameters

    • source: Vector3

      source vector

    • goal: Vector3

      goal vector

    • deltaTime: number

      current interpolation frame

    • lerpTime: number

      total interpolation time

    • result: T

      the smoothed vector

    Returns T

  • Returns a new Vector3 set with the result of the transformation by the given matrix of the given vector. This method computes transformed coordinates only, not transformed direction vectors (ie. it takes translation in account) Example Playground https://playground.babylonjs.com/#R1F8YU#111

    Type Parameters

    Parameters

    Returns Vector3

    the transformed Vector3

  • TransformCoordinatesFromFloatsToRef<T>(x: number, y: number, z: number, transformation: DeepImmutableObject<Matrix>, result: T): T
  • 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 transformed coordinates only, not transformed direction vectors Example Playground https://playground.babylonjs.com/#R1F8YU#115

    Type Parameters

    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: DeepImmutableObject<Matrix>

      defines the transformation matrix

    • result: T

      defines the Vector3 where to store the result

    Returns T

    result input

  • Sets the given vector "result" coordinates with the result of the transformation by the given matrix of the given vector This method computes transformed coordinates only, not transformed direction vectors (ie. it takes translation in account) Example Playground https://playground.babylonjs.com/#R1F8YU#113

    Type Parameters

    Parameters

    Returns T

    result input

  • 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) Example Playground https://playground.babylonjs.com/#R1F8YU#112

    Parameters

    Returns Vector3

    the new Vector3

  • TransformNormalFromFloatsToRef<T>(x: number, y: number, z: number, transformation: DeepImmutableObject<Matrix>, result: T): T
  • 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) Example Playground https://playground.babylonjs.com/#R1F8YU#116

    Type Parameters

    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: DeepImmutableObject<Matrix>

      defines the transformation matrix

    • result: T

      defines the Vector3 where to store the result

    Returns T

    result input

  • 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) Example Playground https://playground.babylonjs.com/#R1F8YU#114

    Type Parameters

    Parameters

    Returns T

    result input

  • Unproject from screen space to object space Example Playground https://playground.babylonjs.com/#R1F8YU#120

    Type Parameters

    Parameters

    • sourceX: number

      defines the screen space x coordinate to use

    • sourceY: number

      defines the screen space y coordinate to use

    • sourceZ: number

      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: DeepImmutableObject<Matrix>

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

    • view: DeepImmutableObject<Matrix>

      defines the view matrix to use

    • projection: DeepImmutableObject<Matrix>

      defines the projection matrix to use

    • result: T

      defines the Vector3 where to store the result

    Returns T

    result input

  • Unproject from screen space to object space Example Playground https://playground.babylonjs.com/#R1F8YU#121

    Type Parameters

    Parameters

    • source: DeepImmutable<T>

      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: DeepImmutableObject<Matrix>

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

    • transform: DeepImmutableObject<Matrix>

      defines the transform (view x projection) matrix to use

    Returns T

    the new Vector3

  • Returns a new Vector3 set to (0.0, 0.0, 0.0)

    Returns Vector3

    a new empty Vector3

Legend

  • Constructor
  • Property
  • Method
  • Accessor
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme