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

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

  • 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

  • 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

  • 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

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

    Parameters

    • result: Vector3

      defines the Vector3 object where to store the result

    Returns Vector3

    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

  • 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

    Parameters

    • plane: Plane

      defines the plane to project to

    • origin: Vector3

      defines the origin of the projection ray

    Returns Vector3

    the projected 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#49

    Parameters

    • plane: Plane

      defines the plane to project to

    • origin: Vector3

      defines the origin of the projection ray

    • result: Vector3

      defines the Vector3 where to store the result

    Returns void

  • 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

  • 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

  • Scale the current Vector3 values by a factor and add the result to a given Vector3 Example Playground https://playground.babylonjs.com/#R1F8YU#55

    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(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

  • 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

    Parameters

    • scale: number

      defines the multiplier factor

    • result: Vector3

      defines the Vector3 object where to store the result

    Returns Vector3

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

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

    Parameters

    Returns Vector3

    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

    Parameters

    Returns void

  • 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

    Parameters

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

  • 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.

    Parameters

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

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

    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

  • 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 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

    Parameters

    Returns Vector3

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

  • 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

    Parameters

    • start: Vector3

      the starting point

    • target: Vector3

      the target point

    • ref: Vector3

      the vector3 to store the result

    Returns Vector3

    ref in the form (pitch, yaw, 0)

  • Smooth interpolation between two vectors using Slerp Example Playground https://playground.babylonjs.com/#R1F8YU#110

    Parameters

    • source: Vector3

      source vector

    • goal: Vector3

      goal vector

    • deltaTime: number

      current interpolation frame

    • lerpTime: number

      total interpolation time

    • result: Vector3

      the smoothed vector

    Returns void

  • 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

    Parameters

    Returns Vector3

    the transformed Vector3

  • 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

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

      defines the Vector3 where to store the result

    Returns void

  • 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

    Parameters

    Returns void

  • 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

  • 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

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

      defines the Vector3 where to store the result

    Returns void

  • 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

    Parameters

    Returns void

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

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

      defines the Vector3 where to store the result

    Returns void

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

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

    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
  • Property
  • Method
  • Inherited constructor
  • Static method

Settings

Theme