UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

1,079 lines 215 kB
import type { Viewport } from "./math.viewport.js"; import type { DeepImmutable, Nullable, FloatArray, float, Tuple } from "../types.js"; import type { Plane } from "./math.plane.js"; import type { TransformNode } from "../Meshes/transformNode.js"; import type { Dimension, Tensor, TensorLike, TensorStatic } from "./tensor.js"; import type { IVector2Like, IVector3Like, IVector4Like, IQuaternionLike, IMatrixLike, IPlaneLike, IVector3LikeInternal } from "./math.like.js"; /** * Represents a vector of any dimension */ export interface Vector<N extends number[], I> extends Tensor<N, I> { /** * @see Tensor.dimension */ readonly dimension: Readonly<Dimension<N>>; /** * @see Tensor.rank */ readonly rank: 1; /** * Gets the length of the vector * @returns the vector length (float) */ length(): number; /** * Gets the vector squared length * @returns the vector squared length (float) */ lengthSquared(): number; /** * Normalize the vector * @returns the current updated Vector */ normalize(): this; /** * Normalize the current Vector with the given input length. * Please note that this is an in place operation. * @param len the length of the vector * @returns the current updated Vector */ normalizeFromLength(len: number): this; /** * Normalize the current Vector to a new vector * @returns the new Vector */ normalizeToNew(): Vector<N, I>; /** * Normalize the current Vector to the reference * @param reference define the Vector to update * @returns the updated Vector */ normalizeToRef<T extends I>(reference: T): T; } /** * Static side of Vector */ export interface VectorStatic<T extends Vector<any[], _I>, _I = TensorLike<T>> extends TensorStatic<T, _I> { /** * Checks if a given vector is inside a specific range * @param value defines the vector to test * @param min defines the minimum range * @param max defines the maximum range */ CheckExtends(value: _I, min: _I, max: _I): void; /** * Returns a new Vector equal to the normalized given vector * @param vector defines the vector to normalize * @returns a new Vector */ Normalize(vector: DeepImmutable<T>): T; /** * Normalize a given vector into a second one * @param vector defines the vector to normalize * @param result defines the vector where to store the result * @returns result input */ NormalizeToRef(vector: DeepImmutable<T>, result: T): T; } /** * Class representing a vector containing 2 coordinates * Example Playground - Overview - https://playground.babylonjs.com/#QYBWV4#9 */ export declare class Vector2 implements Vector<Tuple<number, 2>, IVector2Like>, IVector2Like { /** [0] defines the first coordinate */ x: number; /** [0] defines the second coordinate */ y: number; /** * If the first vector is flagged with integers (as everything is 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 Vector2 instances that it creates. * But the original Vector2 instances are unchanged and has a "deprecated map". * If we keep using the Vector2 instances from step 1, it will now be a poison pill which will mess up optimizations in any code it touches. */ static _V8PerformanceHack: DeepImmutable<Vector2>; private static _ZeroReadOnly; /** * @see Tensor.dimension */ readonly dimension: Readonly<[2]>; /** * @see Tensor.rank */ readonly rank: 1; /** * Creates a new Vector2 from the given x and y coordinates * @param x defines the first coordinate * @param y defines the second coordinate */ constructor( /** [0] defines the first coordinate */ x?: number, /** [0] defines the second coordinate */ y?: number); /** * Gets a string with the Vector2 coordinates * @returns a string with the Vector2 coordinates */ toString(): string; /** * Gets class name * @returns the string "Vector2" */ getClassName(): string; /** * Gets current vector hash code * @returns the Vector2 hash code as a number */ getHashCode(): number; /** * Sets the Vector2 coordinates in the given array or Float32Array from the given index. * Example Playground https://playground.babylonjs.com/#QYBWV4#15 * @param array defines the source array * @param index defines the offset in source array * @returns the current Vector2 */ toArray(array: FloatArray, index?: number): this; /** * Update the current vector from an array * Example Playground https://playground.babylonjs.com/#QYBWV4#39 * @param array defines the destination array * @param offset defines the offset in the destination array * @returns the current Vector2 */ fromArray(array: FloatArray, offset?: number): this; /** * Copy the current vector to an array * Example Playground https://playground.babylonjs.com/#QYBWV4#40 * @returns a new array with 2 elements: the Vector2 coordinates. */ asArray(): [number, number]; /** * Sets the Vector2 coordinates with the given Vector2 coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#24 * @param source defines the source Vector2 * @returns the current updated Vector2 */ copyFrom(source: DeepImmutable<IVector2Like>): this; /** * Sets the Vector2 coordinates with the given floats * Example Playground https://playground.babylonjs.com/#QYBWV4#25 * @param x defines the first coordinate * @param y defines the second coordinate * @returns the current updated Vector2 */ copyFromFloats(x: number, y: number): this; /** * Sets the Vector2 coordinates with the given floats * Example Playground https://playground.babylonjs.com/#QYBWV4#62 * @param x defines the first coordinate * @param y defines the second coordinate * @returns the current updated Vector2 */ set(x: number, y: number): this; /** * Copies the given float to the current Vector2 coordinates * @param v defines the x and y coordinates of the operand * @returns the current updated Vector2 */ setAll(v: number): this; /** * Add another vector with the current one * Example Playground https://playground.babylonjs.com/#QYBWV4#11 * @param otherVector defines the other vector * @returns a new Vector2 set with the addition of the current Vector2 and the given one coordinates */ add(otherVector: DeepImmutable<IVector2Like>): Vector2; /** * Sets the "result" coordinates with the addition of the current Vector2 and the given one coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#12 * @param otherVector defines the other vector * @param result defines the target vector * @returns result input */ addToRef<T extends IVector2Like>(otherVector: DeepImmutable<IVector2Like>, result: T): T; /** * Set the Vector2 coordinates by adding the given Vector2 coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#13 * @param otherVector defines the other vector * @returns the current updated Vector2 */ addInPlace(otherVector: DeepImmutable<IVector2Like>): this; /** * Adds the given coordinates to the current Vector2 * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @returns the current updated Vector2 */ addInPlaceFromFloats(x: number, y: number): this; /** * Gets a new Vector2 by adding the current Vector2 coordinates to the given Vector3 x, y coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#14 * @param otherVector defines the other vector * @returns a new Vector2 */ addVector3(otherVector: IVector3Like): Vector2; /** * Gets a new Vector2 set with the subtracted coordinates of the given one from the current Vector2 * Example Playground https://playground.babylonjs.com/#QYBWV4#61 * @param otherVector defines the other vector * @returns a new Vector2 */ subtract(otherVector: DeepImmutable<IVector2Like>): Vector2; /** * Sets the "result" coordinates with the subtraction of the given one from the current Vector2 coordinates. * Example Playground https://playground.babylonjs.com/#QYBWV4#63 * @param otherVector defines the other vector * @param result defines the target vector * @returns result input */ subtractToRef<T extends IVector2Like>(otherVector: DeepImmutable<IVector2Like>, result: T): T; /** * Sets the current Vector2 coordinates by subtracting from it the given one coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#88 * @param otherVector defines the other vector * @returns the current updated Vector2 */ subtractInPlace(otherVector: DeepImmutable<IVector2Like>): this; /** * Multiplies in place the current Vector2 coordinates by the given ones * Example Playground https://playground.babylonjs.com/#QYBWV4#43 * @param otherVector defines the other vector * @returns the current updated Vector2 */ multiplyInPlace(otherVector: DeepImmutable<IVector2Like>): this; /** * Returns a new Vector2 set with the multiplication of the current Vector2 and the given one coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#42 * @param otherVector defines the other vector * @returns a new Vector2 */ multiply(otherVector: DeepImmutable<IVector2Like>): Vector2; /** * Sets "result" coordinates with the multiplication of the current Vector2 and the given one coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#44 * @param otherVector defines the other vector * @param result defines the target vector * @returns result input */ multiplyToRef<T extends IVector2Like>(otherVector: DeepImmutable<IVector2Like>, result: T): T; /** * Gets a new Vector2 set with the Vector2 coordinates multiplied by the given floats * Example Playground https://playground.babylonjs.com/#QYBWV4#89 * @param x defines the first coordinate * @param y defines the second coordinate * @returns a new Vector2 */ multiplyByFloats(x: number, y: number): Vector2; /** * Returns a new Vector2 set with the Vector2 coordinates divided by the given one coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#27 * @param otherVector defines the other vector * @returns a new Vector2 */ divide(otherVector: DeepImmutable<IVector2Like>): Vector2; /** * Sets the "result" coordinates with the Vector2 divided by the given one coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#30 * @param otherVector defines the other vector * @param result defines the target vector * @returns result input */ divideToRef<T extends IVector2Like>(otherVector: DeepImmutable<IVector2Like>, result: T): T; /** * Divides the current Vector2 coordinates by the given ones * Example Playground https://playground.babylonjs.com/#QYBWV4#28 * @param otherVector defines the other vector * @returns the current updated Vector2 */ divideInPlace(otherVector: DeepImmutable<IVector2Like>): this; /** * Updates the current Vector2 with the minimal coordinate values between its and the given vector ones * @param other defines the second operand * @returns the current updated Vector2 */ minimizeInPlace(other: DeepImmutable<IVector2Like>): this; /** * Updates the current Vector2 with the maximal coordinate values between its and the given vector ones. * @param other defines the second operand * @returns the current updated Vector2 */ maximizeInPlace(other: DeepImmutable<IVector2Like>): this; /** * Updates the current Vector2 with the minimal coordinate values between its and the given coordinates * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @returns the current updated Vector2 */ minimizeInPlaceFromFloats(x: number, y: number): this; /** * Updates the current Vector2 with the maximal coordinate values between its and the given coordinates. * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @returns the current updated Vector2 */ maximizeInPlaceFromFloats(x: number, y: number): this; /** * Returns a new Vector2 set with the subtraction of the given floats from the current Vector2 coordinates * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @returns the resulting Vector2 */ subtractFromFloats(x: number, y: number): Vector2; /** * Subtracts the given floats from the current Vector2 coordinates and set the given vector "result" with this result * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @param result defines the Vector2 object where to store the result * @returns the result */ subtractFromFloatsToRef<T extends IVector2Like>(x: number, y: number, result: T): T; /** * Gets a new Vector2 with current Vector2 negated coordinates * @returns a new Vector2 */ negate(): Vector2; /** * Negate this vector in place * Example Playground https://playground.babylonjs.com/#QYBWV4#23 * @returns this */ negateInPlace(): this; /** * Negate the current Vector2 and stores the result in the given vector "result" coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#41 * @param result defines the Vector3 object where to store the result * @returns the result */ negateToRef<T extends IVector2Like>(result: T): T; /** * Multiply the Vector2 coordinates by * Example Playground https://playground.babylonjs.com/#QYBWV4#59 * @param scale defines the scaling factor * @returns the current updated Vector2 */ scaleInPlace(scale: number): this; /** * Returns a new Vector2 scaled by "scale" from the current Vector2 * Example Playground https://playground.babylonjs.com/#QYBWV4#52 * @param scale defines the scaling factor * @returns a new Vector2 */ scale(scale: number): Vector2; /** * Scale the current Vector2 values by a factor to a given Vector2 * Example Playground https://playground.babylonjs.com/#QYBWV4#57 * @param scale defines the scale factor * @param result defines the Vector2 object where to store the result * @returns result input */ scaleToRef<T extends IVector2Like>(scale: number, result: T): T; /** * Scale the current Vector2 values by a factor and add the result to a given Vector2 * Example Playground https://playground.babylonjs.com/#QYBWV4#58 * @param scale defines the scale factor * @param result defines the Vector2 object where to store the result * @returns result input */ scaleAndAddToRef<T extends IVector2Like>(scale: number, result: T): T; /** * Gets a boolean if two vectors are equals * Example Playground https://playground.babylonjs.com/#QYBWV4#31 * @param otherVector defines the other vector * @returns true if the given vector coordinates strictly equal the current Vector2 ones */ equals(otherVector: DeepImmutable<IVector2Like>): boolean; /** * Gets a boolean if two vectors are equals (using an epsilon value) * Example Playground https://playground.babylonjs.com/#QYBWV4#32 * @param otherVector defines the other vector * @param epsilon defines the minimal distance to consider equality * @returns true if the given vector coordinates are close to the current ones by a distance of epsilon. */ equalsWithEpsilon(otherVector: DeepImmutable<IVector2Like>, epsilon?: number): boolean; /** * Returns true if the current Vector2 coordinates equals the given floats * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @returns true if both vectors are equal */ equalsToFloats(x: number, y: number): boolean; /** * Gets a new Vector2 from current Vector2 floored values * Example Playground https://playground.babylonjs.com/#QYBWV4#35 * eg (1.2, 2.31) returns (1, 2) * @returns a new Vector2 */ floor(): Vector2; /** * Gets the current Vector2's floored values and stores them in result * @param result the Vector2 to store the result in * @returns the result Vector2 */ floorToRef<T extends IVector2Like>(result: T): T; /** * Gets a new Vector2 from current Vector2 fractional values * Example Playground https://playground.babylonjs.com/#QYBWV4#34 * eg (1.2, 2.31) returns (0.2, 0.31) * @returns a new Vector2 */ fract(): Vector2; /** * Gets the current Vector2's fractional values and stores them in result * @param result the Vector2 to store the result in * @returns the result Vector2 */ fractToRef<T extends IVector2Like>(result: T): T; /** * Gets a new Vector2 rotated by the given angle * @param angle defines the rotation angle * @returns a new Vector2 */ rotate(angle: number): Vector2; /** * Rotate the current vector into a given result vector * Example Playground https://playground.babylonjs.com/#QYBWV4#49 * @param angle defines the rotation angle * @param result defines the result vector where to store the rotated vector * @returns result input */ rotateToRef<T extends IVector2Like>(angle: number, result: T): T; /** * Gets the length of the vector * @returns the vector length (float) */ length(): number; /** * Gets the vector squared length * @returns the vector squared length (float) */ lengthSquared(): number; /** * Normalize the vector * Example Playground https://playground.babylonjs.com/#QYBWV4#48 * @returns the current updated Vector2 */ normalize(): this; /** * Normalize the current Vector2 with the given input length. * Please note that this is an in place operation. * @param len the length of the vector * @returns the current updated Vector2 */ normalizeFromLength(len: number): this; /** * Normalize the current Vector2 to a new vector * @returns the new Vector2 */ normalizeToNew(): Vector2; /** * Normalize the current Vector2 to the reference * @param result define the Vector to update * @returns the updated Vector2 */ normalizeToRef<T extends IVector2Like>(result: T): T; /** * Gets a new Vector2 copied from the Vector2 * Example Playground https://playground.babylonjs.com/#QYBWV4#20 * @returns a new Vector2 */ clone(): Vector2; /** * Gets the dot product of the current vector and the vector "otherVector" * @param otherVector defines second vector * @returns the dot product (float) */ dot(otherVector: DeepImmutable<IVector2Like>): number; /** * Gets a new Vector2(0, 0) * @returns a new Vector2 */ static Zero(): Vector2; /** * Gets a new Vector2(1, 1) * @returns a new Vector2 */ static One(): Vector2; /** * Returns a new Vector2 with random values between min and max * @param min the minimum random value * @param max the maximum random value * @returns a Vector2 with random values between min and max */ static Random(min?: number, max?: number): Vector2; /** * Sets a Vector2 with random values between min and max * @param min the minimum random value * @param max the maximum random value * @param ref the ref to store the values in * @returns the ref with random values between min and max */ static RandomToRef<T extends Vector2>(min: number | undefined, max: number | undefined, ref: T): T; /** * Gets a zero Vector2 that must not be updated */ static get ZeroReadOnly(): DeepImmutable<Vector2>; /** * Gets a new Vector2 set from the given index element of the given array * Example Playground https://playground.babylonjs.com/#QYBWV4#79 * @param array defines the data source * @param offset defines the offset in the data source * @returns a new Vector2 */ static FromArray(array: DeepImmutable<ArrayLike<number>>, offset?: number): Vector2; /** * Sets "result" from the given index element of the given array * Example Playground https://playground.babylonjs.com/#QYBWV4#80 * @param array defines the data source * @param offset defines the offset in the data source * @param result defines the target vector * @returns result input */ static FromArrayToRef<T extends Vector2>(array: DeepImmutable<ArrayLike<number>>, offset: number, result: T): T; /** * Sets the given vector "result" with the given floats. * @param x defines the x coordinate of the source * @param y defines the y coordinate of the source * @param result defines the Vector2 where to store the result * @returns the result vector */ static FromFloatsToRef<T extends Vector2>(x: number, y: number, result: T): T; /** * Gets a new Vector2 located for "amount" (float) on the CatmullRom spline defined by the given four Vector2 * Example Playground https://playground.babylonjs.com/#QYBWV4#65 * @param value1 defines 1st point of control * @param value2 defines 2nd point of control * @param value3 defines 3rd point of control * @param value4 defines 4th point of control * @param amount defines the interpolation factor * @returns a new Vector2 */ static CatmullRom(value1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>, value3: DeepImmutable<IVector2Like>, value4: DeepImmutable<IVector2Like>, amount: number): Vector2; /** * Sets reference with same the coordinates than "value" ones if the vector "value" is in the square defined by "min" and "max". * If a coordinate of "value" is lower than "min" coordinates, the returned Vector2 is given this "min" coordinate. * If a coordinate of "value" is greater than "max" coordinates, the returned Vector2 is given this "max" coordinate * @param value defines the value to clamp * @param min defines the lower limit * @param max defines the upper limit * @param ref the reference * @returns the reference */ static ClampToRef<T extends Vector2>(value: DeepImmutable<IVector2Like>, min: DeepImmutable<IVector2Like>, max: DeepImmutable<IVector2Like>, ref: T): T; /** * Returns a new Vector2 set with same the coordinates than "value" ones if the vector "value" is in the square defined by "min" and "max". * If a coordinate of "value" is lower than "min" coordinates, the returned Vector2 is given this "min" coordinate. * If a coordinate of "value" is greater than "max" coordinates, the returned Vector2 is given this "max" coordinate * Example Playground https://playground.babylonjs.com/#QYBWV4#76 * @param value defines the value to clamp * @param min defines the lower limit * @param max defines the upper limit * @returns a new Vector2 */ static Clamp(value: DeepImmutable<IVector2Like>, min: DeepImmutable<IVector2Like>, max: DeepImmutable<IVector2Like>): Vector2; /** * Returns a new Vector2 located for "amount" (float) on the Hermite spline defined by the vectors "value1", "value2", "tangent1", "tangent2" * Example Playground https://playground.babylonjs.com/#QYBWV4#81 * @param value1 defines the 1st control point * @param tangent1 defines the outgoing tangent * @param value2 defines the 2nd control point * @param tangent2 defines the incoming tangent * @param amount defines the interpolation factor * @returns a new Vector2 */ static Hermite(value1: DeepImmutable<IVector2Like>, tangent1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>, tangent2: DeepImmutable<IVector2Like>, amount: number): Vector2; /** * Returns a new Vector2 which is the 1st derivative of the Hermite spline defined by the vectors "value1", "value2", "tangent1", "tangent2". * Example Playground https://playground.babylonjs.com/#QYBWV4#82 * @param value1 defines the first control point * @param tangent1 defines the first tangent * @param value2 defines the second control point * @param tangent2 defines the second tangent * @param time define where the derivative must be done * @returns 1st derivative */ static Hermite1stDerivative(value1: DeepImmutable<IVector2Like>, tangent1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>, tangent2: DeepImmutable<IVector2Like>, time: number): Vector2; /** * Returns a new Vector2 which is the 1st derivative of the Hermite spline defined by the vectors "value1", "value2", "tangent1", "tangent2". * Example Playground https://playground.babylonjs.com/#QYBWV4#83 * @param value1 defines the first control point * @param tangent1 defines the first tangent * @param value2 defines the second control point * @param tangent2 defines the second tangent * @param time define where the derivative must be done * @param result define where the derivative will be stored * @returns result input */ static Hermite1stDerivativeToRef<T extends Vector2>(value1: DeepImmutable<IVector2Like>, tangent1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>, tangent2: DeepImmutable<IVector2Like>, time: number, result: T): T; /** * Returns a new Vector2 located for "amount" (float) on the linear interpolation between the vector "start" adn the vector "end". * Example Playground https://playground.babylonjs.com/#QYBWV4#84 * @param start defines the start vector * @param end defines the end vector * @param amount defines the interpolation factor * @returns a new Vector2 */ static Lerp(start: DeepImmutable<IVector2Like>, end: DeepImmutable<IVector2Like>, amount: number): Vector2; /** * Sets the given vector "result" with the result of the linear interpolation from the vector "start" for "amount" to the vector "end" * @param start defines the start value * @param end defines the end value * @param amount max defines amount between both (between 0 and 1) * @param result defines the Vector2 where to store the result * @returns result input */ static LerpToRef(start: DeepImmutable<IVector2Like>, end: DeepImmutable<IVector2Like>, amount: number, result: Vector2): Vector2; /** * Gets the dot product of the vector "left" and the vector "right" * Example Playground https://playground.babylonjs.com/#QYBWV4#90 * @param left defines first vector * @param right defines second vector * @returns the dot product (float) */ static Dot(left: DeepImmutable<IVector2Like>, right: DeepImmutable<IVector2Like>): number; /** * Returns a new Vector2 equal to the normalized given vector * Example Playground https://playground.babylonjs.com/#QYBWV4#46 * @param vector defines the vector to normalize * @returns a new Vector2 */ static Normalize(vector: DeepImmutable<Vector2>): Vector2; /** * Normalize a given vector into a second one * Example Playground https://playground.babylonjs.com/#QYBWV4#50 * @param vector defines the vector to normalize * @param result defines the vector where to store the result * @returns result input */ static NormalizeToRef<T extends Vector2>(vector: DeepImmutable<Vector2>, result: T): T; /** * Gets a new Vector2 set with the minimal coordinate values from the "left" and "right" vectors * Example Playground https://playground.babylonjs.com/#QYBWV4#86 * @param left defines 1st vector * @param right defines 2nd vector * @returns a new Vector2 */ static Minimize(left: DeepImmutable<IVector2Like>, right: DeepImmutable<IVector2Like>): Vector2; /** * Gets a new Vector2 set with the maximal coordinate values from the "left" and "right" vectors * Example Playground https://playground.babylonjs.com/#QYBWV4#86 * @param left defines 1st vector * @param right defines 2nd vector * @returns a new Vector2 */ static Maximize(left: DeepImmutable<IVector2Like>, right: DeepImmutable<IVector2Like>): Vector2; /** * Gets a new Vector2 set with the transformed coordinates of the given vector by the given transformation matrix * Example Playground https://playground.babylonjs.com/#QYBWV4#17 * @param vector defines the vector to transform * @param transformation defines the matrix to apply * @returns a new Vector2 */ static Transform(vector: DeepImmutable<IVector2Like>, transformation: DeepImmutable<Matrix>): Vector2; /** * Transforms the given vector coordinates by the given transformation matrix and stores the result in the vector "result" coordinates * Example Playground https://playground.babylonjs.com/#QYBWV4#19 * @param vector defines the vector to transform * @param transformation defines the matrix to apply * @param result defines the target vector * @returns result input */ static TransformToRef<T extends Vector2>(vector: DeepImmutable<IVector2Like>, transformation: DeepImmutable<Matrix>, result: T): T; /** * Determines if a given vector is included in a triangle * Example Playground https://playground.babylonjs.com/#QYBWV4#87 * @param p defines the vector to test * @param p0 defines 1st triangle point * @param p1 defines 2nd triangle point * @param p2 defines 3rd triangle point * @returns true if the point "p" is in the triangle defined by the vectors "p0", "p1", "p2" */ static PointInTriangle(p: DeepImmutable<IVector2Like>, p0: DeepImmutable<IVector2Like>, p1: DeepImmutable<IVector2Like>, p2: DeepImmutable<IVector2Like>): boolean; /** * Gets the distance between the vectors "value1" and "value2" * Example Playground https://playground.babylonjs.com/#QYBWV4#71 * @param value1 defines first vector * @param value2 defines second vector * @returns the distance between vectors */ static Distance(value1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>): number; /** * Returns the squared distance between the vectors "value1" and "value2" * Example Playground https://playground.babylonjs.com/#QYBWV4#72 * @param value1 defines first vector * @param value2 defines second vector * @returns the squared distance between vectors */ static DistanceSquared(value1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>): number; /** * Gets a new Vector2 located at the center of the vectors "value1" and "value2" * Example Playground https://playground.babylonjs.com/#QYBWV4#86 * Example Playground https://playground.babylonjs.com/#QYBWV4#66 * @param value1 defines first vector * @param value2 defines second vector * @returns a new Vector2 */ static Center(value1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>): Vector2; /** * Gets the center of the vectors "value1" and "value2" and stores the result in the vector "ref" * Example Playground https://playground.babylonjs.com/#QYBWV4#66 * @param value1 defines first vector * @param value2 defines second vector * @param ref defines third vector * @returns ref */ static CenterToRef<T extends Vector2>(value1: DeepImmutable<IVector2Like>, value2: DeepImmutable<IVector2Like>, ref: T): T; /** * Gets the shortest distance (float) between the point "p" and the segment defined by the two points "segA" and "segB". * Example Playground https://playground.babylonjs.com/#QYBWV4#77 * @param p defines the middle point * @param segA defines one point of the segment * @param segB defines the other point of the segment * @returns the shortest distance */ static DistanceOfPointFromSegment(p: DeepImmutable<Vector2>, segA: DeepImmutable<Vector2>, segB: DeepImmutable<Vector2>): number; } /** * 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 */ export declare class Vector3 implements Vector<Tuple<number, 3>, IVector3LikeInternal>, IVector3Like { /** * 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. */ static _V8PerformanceHack: DeepImmutable<Vector3>; private static _UpReadOnly; private static _DownReadOnly; private static _LeftHandedForwardReadOnly; private static _RightHandedForwardReadOnly; private static _LeftHandedBackwardReadOnly; private static _RightHandedBackwardReadOnly; private static _RightReadOnly; private static _LeftReadOnly; private static _ZeroReadOnly; private static _OneReadOnly; /** * @see Tensor.dimension */ readonly dimension: Readonly<[3]>; /** * @see Tensor.rank */ readonly rank: 1; /** @internal */ _x: number; /** @internal */ _y: number; /** @internal */ _z: number; /** @internal */ _isDirty: boolean; /** Gets or sets the x coordinate */ get x(): number; set x(value: number); /** Gets or sets the y coordinate */ get y(): number; set y(value: number); /** Gets or sets the z coordinate */ get z(): number; set z(value: number); /** * Creates a new Vector3 object from the given x, y, z (floats) coordinates. * @param x defines the first coordinates (on X axis) * @param y defines the second coordinates (on Y axis) * @param z defines the third coordinates (on Z axis) */ constructor(x?: number, y?: number, z?: number); /** * Creates a string representation of the Vector3 * Example Playground https://playground.babylonjs.com/#R1F8YU#67 * @returns a string with the Vector3 coordinates. */ toString(): string; /** * Gets the class name * @returns the string "Vector3" */ getClassName(): string; /** * Creates the Vector3 hash code * @returns a number which tends to be unique between Vector3 instances */ getHashCode(): number; /** * Creates an array containing three elements : the coordinates of the Vector3 * Example Playground https://playground.babylonjs.com/#R1F8YU#10 * @returns a new array of numbers */ asArray(): Tuple<number, 3>; /** * 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 * @param array defines the destination array * @param index defines the offset in the destination array * @returns the current Vector3 */ toArray(array: FloatArray, index?: number): this; /** * Update the current vector from an array * Example Playground https://playground.babylonjs.com/#R1F8YU#24 * @param array defines the destination array * @param offset defines the offset in the destination array * @returns the current Vector3 */ fromArray(array: DeepImmutable<FloatArray>, offset?: number): this; /** * 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 a new Quaternion object, computed from the Vector3 coordinates */ toQuaternion(): Quaternion; /** * Adds the given vector to the current Vector3 * Example Playground https://playground.babylonjs.com/#R1F8YU#4 * @param otherVector defines the second operand * @returns the current updated Vector3 */ addInPlace(otherVector: DeepImmutable<Vector3>): this; /** * Adds the given coordinates to the current Vector3 * Example Playground https://playground.babylonjs.com/#R1F8YU#5 * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @param z defines the z coordinate of the operand * @returns the current updated Vector3 */ addInPlaceFromFloats(x: number, y: number, z: number): this; /** * Gets a new Vector3, result of the addition the current Vector3 and the given vector * Example Playground https://playground.babylonjs.com/#R1F8YU#3 * @param otherVector defines the second operand * @returns the resulting Vector3 */ add(otherVector: DeepImmutable<IVector3LikeInternal>): 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 * @param otherVector defines the second operand * @param result defines the Vector3 object where to store the result * @returns the result */ addToRef<T extends IVector3LikeInternal>(otherVector: DeepImmutable<IVector3LikeInternal>, result: T): T; /** * Subtract the given vector from the current Vector3 * Example Playground https://playground.babylonjs.com/#R1F8YU#61 * @param otherVector defines the second operand * @returns the current updated Vector3 */ subtractInPlace(otherVector: DeepImmutable<IVector3LikeInternal>): this; /** * Returns a new Vector3, result of the subtraction of the given vector from the current Vector3 * Example Playground https://playground.babylonjs.com/#R1F8YU#60 * @param otherVector defines the second operand * @returns the resulting Vector3 */ subtract(otherVector: DeepImmutable<IVector3LikeInternal>): Vector3; /** * Subtracts the given vector from the current Vector3 and stores the result in the vector "result". * Example Playground https://playground.babylonjs.com/#R1F8YU#63 * @param otherVector defines the second operand * @param result defines the Vector3 object where to store the result * @returns the result */ subtractToRef<T extends IVector3LikeInternal>(otherVector: DeepImmutable<IVector3LikeInternal>, result: T): T; /** * 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 * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @param z defines the z coordinate of the operand * @returns the resulting Vector3 */ subtractFromFloats(x: number, y: number, z: number): 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 * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @param z defines the z coordinate of the operand * @param result defines the Vector3 object where to store the result * @returns the result */ subtractFromFloatsToRef<T extends IVector3LikeInternal>(x: number, y: number, z: number, result: T): T; /** * Gets a new Vector3 set with the current Vector3 negated coordinates * Example Playground https://playground.babylonjs.com/#R1F8YU#35 * @returns a new Vector3 */ negate(): Vector3; /** * Negate this vector in place * Example Playground https://playground.babylonjs.com/#R1F8YU#36 * @returns this */ negateInPlace(): this; /** * Negate the current Vector3 and stores the result in the given vector "result" coordinates * Example Playground https://playground.babylonjs.com/#R1F8YU#37 * @param result defines the Vector3 object where to store the result * @returns the result */ negateToRef<T extends IVector3LikeInternal>(result: T): T; /** * Multiplies the Vector3 coordinates by the float "scale" * Example Playground https://playground.babylonjs.com/#R1F8YU#56 * @param scale defines the multiplier factor * @returns the current updated Vector3 */ scaleInPlace(scale: number): this; /** * Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float "scale" * Example Playground https://playground.babylonjs.com/#R1F8YU#53 * @param scale defines the multiplier factor * @returns a new Vector3 */ scale(scale: number): 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 * @param scale defines the multiplier factor * @param result defines the Vector3 object where to store the result * @returns the result */ scaleToRef<T extends IVector3LikeInternal>(scale: number, result: T): T; /** * 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 * @param result defines the Vector3 object where to store the resultant normal * @returns the result */ getNormalToRef(result: Vector3): Vector3; /** * Rotates the vector using the given unit quaternion and stores the new vector in result * Example Playground https://playground.babylonjs.com/#R1F8YU#9 * @param q the unit quaternion representing the rotation * @param result the output vector * @returns the result */ applyRotationQuaternionToRef<T extends Vector3>(q: Quaternion, result: T): T; /** * Rotates the vector in place using the given unit quaternion * Example Playground https://playground.babylonjs.com/#R1F8YU#8 * @param q the unit quaternion representing the rotation * @returns the current updated Vector3 */ applyRotationQuaternionInPlace(q: Quaternion): this; /** * Rotates the vector using the given unit quaternion and returns the new vector * Example Playground https://playground.babylonjs.com/#R1F8YU#7 * @param q the unit quaternion representing the rotation * @returns a new Vector3 */ applyRotationQuaternion(q: Quaternion): 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 * @param scale defines the scale factor * @param result defines the Vector3 object where to store the result * @returns result input */ scaleAndAddToRef<T extends IVector3LikeInternal>(scale: number, 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#48 * @param plane defines the plane to project to * @param origin defines the origin of the projection ray * @returns the projected vector3 */ projectOnPlane(plane: Plane, origin: Vector3): 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 * @param plane defines the plane to project to * @param origin defines the origin of the projection ray * @param result defines the Vector3 where to store the result * @returns result input */ projectOnPlaneToRef<T extends Vector3>(plane: Plane, origin: Vector3, result: T): T; /** * Returns true if the current Vector3 and the given vector coordinates are strictly equal * Example Playground https://playground.babylonjs.com/#R1F8YU#19 * @param otherVector defines the second operand * @returns true if both vectors are equals */ equals(otherVector: DeepImmutable<Vector3>): boolean; /** * Returns true if the current Vector3 and the given vector coordinates are distant less than epsilon * Example Playground https://playground.babylonjs.com/#R1F8YU#21 * @param otherVector defines the second operand * @param epsilon defines the minimal distance to define values as equals * @returns true if both vectors are distant less than epsilon */ equalsWithEpsilon(otherVector: DeepImmutable<Vector3>, epsilon?: number): boolean; /** * Returns true if the current Vector3 coordinates equals the given floats * Example Playground https://playground.babylonjs.com/#R1F8YU#20 * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @param z defines the z coordinate of the operand * @returns true if both vectors are equal */ equalsToFloats(x: number, y: number, z: number): boolean; /** * Multiplies the current Vector3 coordinates by the given ones * Example Playground https://playground.babylonjs.com/#R1F8YU#32 * @param otherVector defines the second operand * @returns the current updated Vector3 */ multiplyInPlace(otherVector: DeepImmutable<IVector3LikeInternal>): this; /** * Returns a new Vector3, result of the multiplication of the current Vector3 by the given vector * Example Playground https://playground.babylonjs.com/#R1F8YU#31 * @param otherVector defines the second operand * @returns the new Vector3 */ multiply(otherVector: DeepImmutable<IVector3LikeInternal>): 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 * @param otherVector defines the second operand * @param result defines the Vector3 object where to store the result * @returns the result */ multiplyToRef<T extends IVector3LikeInternal>(otherVector: DeepImmutable<IVector3LikeInternal>, result: T): T; /** * 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 * @param x defines the x coordinate of the operand * @param y defines the y coordinate of the operand * @param z defines the z coordinate of the operand * @returns the new Vector3 */ multiplyByFloats(x: number, y: number, z: number): Vector3; /** * Returns a new Vector3 set with the result of the division of the current Vector3 coordinates by the given ones * Example Playground https://playground.babylonjs.com/#R1F8YU#16 * @param otherVector defines the second operand * @returns the new Vector3 */ divide(otherVector: DeepImmutable<IVector3LikeInternal>): Vector3; /** * 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 * @param otherVector defines the second operand * @param result defines the Vector3 object where to store the result * @returns the result */ divideToRef<T extends IVector3LikeInternal>(otherVector: DeepImmutable<IVector3LikeInternal>, result: T):