UNPKG

7.49 kBTypeScriptView Raw
1import { Camera } from "../cameras/Camera.js";
2import { BufferAttribute } from "../core/BufferAttribute.js";
3import { InterleavedBufferAttribute } from "../core/InterleavedBufferAttribute.js";
4import { RGB } from "./Color.js";
5import { Cylindrical } from "./Cylindrical.js";
6import { Euler } from "./Euler.js";
7import { Matrix3 } from "./Matrix3.js";
8import { Matrix4 } from "./Matrix4.js";
9import { QuaternionLike } from "./Quaternion.js";
10import { Spherical } from "./Spherical.js";
11
12export type Vector3Tuple = [number, number, number];
13
14export interface Vector3Like {
15 readonly x: number;
16 readonly y: number;
17 readonly z: number;
18}
19
20/**
21 * 3D vector.
22 *
23 * see {@link https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js}
24 *
25 * @example
26 * const a = new THREE.Vector3( 1, 0, 0 );
27 * const b = new THREE.Vector3( 0, 1, 0 );
28 * const c = new THREE.Vector3();
29 * c.crossVectors( a, b );
30 */
31export class Vector3 {
32 constructor(x?: number, y?: number, z?: number);
33
34 /**
35 * @default 0
36 */
37 x: number;
38
39 /**
40 * @default 0
41 */
42 y: number;
43
44 /**
45 * @default 0
46 */
47 z: number;
48 readonly isVector3: true;
49
50 /**
51 * Sets value of this vector.
52 */
53 set(x: number, y: number, z: number): this;
54
55 /**
56 * Sets all values of this vector.
57 */
58 setScalar(scalar: number): this;
59
60 /**
61 * Sets x value of this vector.
62 */
63 setX(x: number): this;
64
65 /**
66 * Sets y value of this vector.
67 */
68 setY(y: number): this;
69
70 /**
71 * Sets z value of this vector.
72 */
73 setZ(z: number): this;
74
75 setComponent(index: number, value: number): this;
76
77 getComponent(index: number): number;
78
79 /**
80 * Clones this vector.
81 */
82 clone(): this;
83
84 /**
85 * Copies value of v to this vector.
86 */
87 copy(v: Vector3Like): this;
88
89 /**
90 * Adds v to this vector.
91 */
92 add(v: Vector3Like): this;
93
94 addScalar(s: number): this;
95
96 /**
97 * Sets this vector to a + b.
98 */
99 addVectors(a: Vector3Like, b: Vector3Like): this;
100
101 addScaledVector(v: Vector3, s: number): this;
102
103 /**
104 * Subtracts v from this vector.
105 */
106 sub(a: Vector3Like): this;
107
108 subScalar(s: number): this;
109
110 /**
111 * Sets this vector to a - b.
112 */
113 subVectors(a: Vector3Like, b: Vector3Like): this;
114
115 multiply(v: Vector3Like): this;
116
117 /**
118 * Multiplies this vector by scalar s.
119 */
120 multiplyScalar(s: number): this;
121
122 multiplyVectors(a: Vector3Like, b: Vector3Like): this;
123
124 applyEuler(euler: Euler): this;
125
126 applyAxisAngle(axis: Vector3, angle: number): this;
127
128 applyMatrix3(m: Matrix3): this;
129
130 applyNormalMatrix(m: Matrix3): this;
131
132 applyMatrix4(m: Matrix4): this;
133
134 applyQuaternion(q: QuaternionLike): this;
135
136 project(camera: Camera): this;
137
138 unproject(camera: Camera): this;
139
140 transformDirection(m: Matrix4): this;
141
142 divide(v: Vector3Like): this;
143
144 /**
145 * Divides this vector by scalar s.
146 * Set vector to ( 0, 0, 0 ) if s == 0.
147 */
148 divideScalar(s: number): this;
149
150 min(v: Vector3Like): this;
151
152 max(v: Vector3Like): this;
153
154 clamp(min: Vector3Like, max: Vector3Like): this;
155
156 clampScalar(min: number, max: number): this;
157
158 clampLength(min: number, max: number): this;
159
160 floor(): this;
161
162 ceil(): this;
163
164 round(): this;
165
166 roundToZero(): this;
167
168 /**
169 * Inverts this vector.
170 */
171 negate(): this;
172
173 /**
174 * Computes dot product of this vector and v.
175 */
176 dot(v: Vector3Like): number;
177
178 /**
179 * Computes squared length of this vector.
180 */
181 lengthSq(): number;
182
183 /**
184 * Computes length of this vector.
185 */
186 length(): number;
187
188 /**
189 * Computes the Manhattan length of this vector.
190 *
191 * see {@link http://en.wikipedia.org/wiki/Taxicab_geometry|Wikipedia: Taxicab Geometry}
192 */
193 manhattanLength(): number;
194
195 /**
196 * Normalizes this vector.
197 */
198 normalize(): this;
199
200 /**
201 * Normalizes this vector and multiplies it by l.
202 */
203 setLength(l: number): this;
204 lerp(v: Vector3Like, alpha: number): this;
205
206 lerpVectors(v1: Vector3Like, v2: Vector3Like, alpha: number): this;
207
208 /**
209 * Sets this vector to cross product of itself and v.
210 */
211 cross(a: Vector3Like): this;
212
213 /**
214 * Sets this vector to cross product of a and b.
215 */
216 crossVectors(a: Vector3Like, b: Vector3Like): this;
217 projectOnVector(v: Vector3): this;
218 projectOnPlane(planeNormal: Vector3): this;
219 reflect(vector: Vector3Like): this;
220 angleTo(v: Vector3): number;
221
222 /**
223 * Computes distance of this vector to v.
224 */
225 distanceTo(v: Vector3Like): number;
226
227 /**
228 * Computes squared distance of this vector to v.
229 */
230 distanceToSquared(v: Vector3Like): number;
231
232 /**
233 * Computes the Manhattan length (distance) from this vector to the given vector v
234 *
235 * see {@link http://en.wikipedia.org/wiki/Taxicab_geometry|Wikipedia: Taxicab Geometry}
236 */
237 manhattanDistanceTo(v: Vector3Like): number;
238
239 setFromSpherical(s: Spherical): this;
240 setFromSphericalCoords(r: number, phi: number, theta: number): this;
241 setFromCylindrical(s: Cylindrical): this;
242 setFromCylindricalCoords(radius: number, theta: number, y: number): this;
243 setFromMatrixPosition(m: Matrix4): this;
244 setFromMatrixScale(m: Matrix4): this;
245 setFromMatrixColumn(matrix: Matrix4, index: number): this;
246 setFromMatrix3Column(matrix: Matrix3, index: number): this;
247
248 /**
249 * Sets this vector's {@link x}, {@link y} and {@link z} components from the x, y, and z components of the specified {@link Euler Euler Angle}.
250 */
251 setFromEuler(e: Euler): this;
252
253 /**
254 * Sets this vector's {@link x}, {@link y} and {@link z} components from the r, g, and b components of the specified
255 * {@link Color | color}.
256 */
257 setFromColor(color: RGB): this;
258
259 /**
260 * Checks for strict equality of this vector and v.
261 */
262 equals(v: Vector3Like): boolean;
263
264 /**
265 * Sets this vector's x, y and z value from the provided array or array-like.
266 * @param array the source array or array-like.
267 * @param offset (optional) offset into the array. Default is 0.
268 */
269 fromArray(array: number[] | ArrayLike<number>, offset?: number): this;
270
271 /**
272 * Returns an array [x, y, z], or copies x, y and z into the provided array.
273 * @param array (optional) array to store the vector to. If this is not provided, a new array will be created.
274 * @param offset (optional) optional offset into the array.
275 * @return The created or provided array.
276 */
277 toArray(array?: number[], offset?: number): number[];
278 toArray(array?: Vector3Tuple, offset?: 0): Vector3Tuple;
279
280 /**
281 * Copies x, y and z into the provided array-like.
282 * @param array array-like to store the vector to.
283 * @param offset (optional) optional offset into the array-like.
284 * @return The provided array-like.
285 */
286 toArray(array: ArrayLike<number>, offset?: number): ArrayLike<number>;
287
288 fromBufferAttribute(attribute: BufferAttribute | InterleavedBufferAttribute, index: number): this;
289
290 /**
291 * Sets this vector's x, y and z from Math.random
292 */
293 random(): this;
294
295 randomDirection(): this;
296
297 /**
298 * Iterating through a Vector3 instance will yield its components (x, y, z) in the corresponding order.
299 */
300 [Symbol.iterator](): Iterator<number>;
301}