API

Class Vector3

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

Implements

Index
add addInPlace addInPlaceFromFloats addToRef applyRotationQuaternion applyRotationQuaternionInPlace applyRotationQuaternionToRef asArray clone copyFrom copyFromFloats cross divide divideInPlace divideToRef dot equals equalsToFloats equalsWithEpsilon floor floorToRef fract fractToRef fromArray getClassName getHashCode getNormalToRef isNonUniformWithinEpsilon length lengthSquared maximizeInPlace maximizeInPlaceFromFloats minimizeInPlace minimizeInPlaceFromFloats multiply multiplyByFloats multiplyInPlace multiplyToRef negate negateInPlace negateToRef normalize normalizeFromLength normalizeToNew normalizeToRef projectOnPlane projectOnPlaneToRef reorderInPlace rotateByQuaternionAroundPointToRef rotateByQuaternionToRef scale scaleAndAddToRef scaleInPlace scaleToRef set setAll subtract subtractFromFloats subtractFromFloatsToRef subtractInPlace subtractToRef toArray toQuaternion toString Backward CatmullRom Center CenterToRef CheckExtends Clamp ClampToRef Cross CrossToRef Distance DistanceSquared Dot Down Forward FromArray FromArrayToRef FromFloatArray FromFloatArrayToRef FromFloatsToRef GetAngleBetweenVectors GetAngleBetweenVectorsOnPlane GetClipFactor Hermite Hermite1stDerivative Hermite1stDerivativeToRef Left Lerp LerpToRef Maximize Minimize Normalize NormalizeToRef One PitchYawRollToMoveBetweenPoints PitchYawRollToMoveBetweenPointsToRef Project ProjectOnTriangleToRef ProjectToRef Random RandomToRef Reflect ReflectToRef Right RotationFromAxis RotationFromAxisToRef SlerpToRef SmoothToRef TransformCoordinates TransformCoordinatesFromFloatsToRef TransformCoordinatesToRef TransformNormal TransformNormalFromFloatsToRef TransformNormalToRef Unproject UnprojectFloatsToRef UnprojectFromTransform UnprojectToRef Up Zero
  • Creates a new Vector3 object from the given x, y, z (floats) coordinates.

    Parameters

    • x: number = 0

      defines the first coordinates (on X axis)

    • y: number = 0

      defines the second coordinates (on Y axis)

    • z: number = 0

      defines the third coordinates (on Z axis)

    Returns Vector3

dimension: readonly [3]

Tensor.dimension

rank: 1

Tensor.rank

_V8PerformanceHack: DeepImmutableObject<Vector3> = ...

If the first vector is flagged with integers (as everything is 0,0,0), V8 stores all of the properties as integers internally because it doesn't know any better yet. If subsequent vectors are created with non-integer values, V8 determines that it would be best to represent these properties as doubles instead of integers, and henceforth it will use floating-point representation for all Vector3 instances that it creates. But the original Vector3 instances are unchanged and has a "deprecated map". If we keep using the Vector3 instances from step 1, it will now be a poison pill which will mess up optimizations in any code it touches.

  • 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 vector is non uniform to a certain number of decimal places

  • 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

    • T extends IVector3LikeInternal

    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

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

    Type Parameters

    Parameters

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

    result input

    Please use FromArrayToRef instead.

  • Sets a Vector3 with random values between min and max

    Type Parameters

    Parameters

    • min: number = 0

      the minimum random value

    • max: number = 1

      the maximum random value

    • ref: T

      the ref to store the values in

    Returns T

    the ref with random values between min and max

  • 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: DeepImmutable<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 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: DeepImmutable<Matrix>

      defines the transformation matrix

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

      defines the Vector3 where to store the result

    Returns T

    result input