vec3.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /**
  2. * Copyright (c) 2017-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. /*
  8. * This code has been modified from https://github.com/toji/gl-matrix/,
  9. * copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a copy
  12. * of this software and associated documentation files (the "Software"), to deal
  13. * in the Software without restriction, including without limitation the rights
  14. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. * copies of the Software, and to permit persons to whom the Software is
  16. * furnished to do so, subject to the following conditions:
  17. */
  18. import { Mat4 } from './mat4';
  19. import { spline as _spline, quadraticBezier as _quadraticBezier, clamp } from '../../interpolate';
  20. import { NumberArray } from '../../../mol-util/type-helpers';
  21. import { Mat3 } from './mat3';
  22. import { Quat } from './quat';
  23. import { EPSILON } from './common';
  24. export { ReadonlyVec3 };
  25. interface Vec3 extends Array<number> { [d: number]: number, '@type': 'vec3', length: 3 }
  26. interface ReadonlyVec3 extends Array<number> { readonly [d: number]: number, '@type': 'vec3', length: 3 }
  27. function Vec3() {
  28. return Vec3.zero();
  29. }
  30. namespace Vec3 {
  31. export function zero(): Vec3 {
  32. const out = [0.1, 0.0, 0.0];
  33. out[0] = 0;
  34. return out as any;
  35. }
  36. export function clone(a: Vec3): Vec3 {
  37. const out = zero();
  38. out[0] = a[0];
  39. out[1] = a[1];
  40. out[2] = a[2];
  41. return out;
  42. }
  43. export function hasNaN(a: Vec3) {
  44. return isNaN(a[0]) || isNaN(a[1]) || isNaN(a[2]);
  45. }
  46. export function setNaN(out: Vec3) {
  47. out[0] = NaN;
  48. out[1] = NaN;
  49. out[2] = NaN;
  50. return out;
  51. }
  52. export function fromObj(v: { x: number, y: number, z: number }): Vec3 {
  53. return create(v.x, v.y, v.z);
  54. }
  55. export function toObj(v: Vec3) {
  56. return { x: v[0], y: v[1], z: v[2] };
  57. }
  58. export function fromArray(v: Vec3, array: ArrayLike<number>, offset: number) {
  59. v[0] = array[offset + 0];
  60. v[1] = array[offset + 1];
  61. v[2] = array[offset + 2];
  62. return v;
  63. }
  64. export function toArray(v: Vec3, out: NumberArray, offset: number) {
  65. out[offset + 0] = v[0];
  66. out[offset + 1] = v[1];
  67. out[offset + 2] = v[2];
  68. return out;
  69. }
  70. export function create(x: number, y: number, z: number): Vec3 {
  71. const out = zero();
  72. out[0] = x;
  73. out[1] = y;
  74. out[2] = z;
  75. return out;
  76. }
  77. export function ofArray(array: ArrayLike<number>) {
  78. const out = zero();
  79. out[0] = array[0];
  80. out[1] = array[1];
  81. out[2] = array[2];
  82. return out;
  83. }
  84. export function set(out: Vec3, x: number, y: number, z: number): Vec3 {
  85. out[0] = x;
  86. out[1] = y;
  87. out[2] = z;
  88. return out;
  89. }
  90. export function copy(out: Vec3, a: Vec3) {
  91. out[0] = a[0];
  92. out[1] = a[1];
  93. out[2] = a[2];
  94. return out;
  95. }
  96. export function add(out: Vec3, a: Vec3, b: Vec3) {
  97. out[0] = a[0] + b[0];
  98. out[1] = a[1] + b[1];
  99. out[2] = a[2] + b[2];
  100. return out;
  101. }
  102. export function sub(out: Vec3, a: Vec3, b: Vec3) {
  103. out[0] = a[0] - b[0];
  104. out[1] = a[1] - b[1];
  105. out[2] = a[2] - b[2];
  106. return out;
  107. }
  108. export function mul(out: Vec3, a: Vec3, b: Vec3) {
  109. out[0] = a[0] * b[0];
  110. out[1] = a[1] * b[1];
  111. out[2] = a[2] * b[2];
  112. return out;
  113. }
  114. export function div(out: Vec3, a: Vec3, b: Vec3) {
  115. out[0] = a[0] / b[0];
  116. out[1] = a[1] / b[1];
  117. out[2] = a[2] / b[2];
  118. return out;
  119. }
  120. export function scale(out: Vec3, a: Vec3, b: number) {
  121. out[0] = a[0] * b;
  122. out[1] = a[1] * b;
  123. out[2] = a[2] * b;
  124. return out;
  125. }
  126. /** Scales b, then adds a and b together */
  127. export function scaleAndAdd(out: Vec3, a: Vec3, b: Vec3, scale: number) {
  128. out[0] = a[0] + (b[0] * scale);
  129. out[1] = a[1] + (b[1] * scale);
  130. out[2] = a[2] + (b[2] * scale);
  131. return out;
  132. }
  133. /** Scales b, then subtracts b from a */
  134. export function scaleAndSub(out: Vec3, a: Vec3, b: Vec3, scale: number) {
  135. out[0] = a[0] - (b[0] * scale);
  136. out[1] = a[1] - (b[1] * scale);
  137. out[2] = a[2] - (b[2] * scale);
  138. return out;
  139. }
  140. export function addScalar(out: Vec3, a: Vec3, b: number) {
  141. out[0] = a[0] + b;
  142. out[1] = a[1] + b;
  143. out[2] = a[2] + b;
  144. return out;
  145. }
  146. export function subScalar(out: Vec3, a: Vec3, b: number) {
  147. out[0] = a[0] - b;
  148. out[1] = a[1] - b;
  149. out[2] = a[2] - b;
  150. return out;
  151. }
  152. /**
  153. * Math.round the components of a Vec3
  154. */
  155. export function round(out: Vec3, a: Vec3) {
  156. out[0] = Math.round(a[0]);
  157. out[1] = Math.round(a[1]);
  158. out[2] = Math.round(a[2]);
  159. return out;
  160. }
  161. /**
  162. * Math.ceil the components of a Vec3
  163. */
  164. export function ceil(out: Vec3, a: Vec3) {
  165. out[0] = Math.ceil(a[0]);
  166. out[1] = Math.ceil(a[1]);
  167. out[2] = Math.ceil(a[2]);
  168. return out;
  169. }
  170. /**
  171. * Math.floor the components of a Vec3
  172. */
  173. export function floor(out: Vec3, a: Vec3) {
  174. out[0] = Math.floor(a[0]);
  175. out[1] = Math.floor(a[1]);
  176. out[2] = Math.floor(a[2]);
  177. return out;
  178. }
  179. /**
  180. * Math.trunc the components of a Vec3
  181. */
  182. export function trunc(out: Vec3, a: Vec3) {
  183. out[0] = Math.trunc(a[0]);
  184. out[1] = Math.trunc(a[1]);
  185. out[2] = Math.trunc(a[2]);
  186. return out;
  187. }
  188. /**
  189. * Math.abs the components of a Vec3
  190. */
  191. export function abs(out: Vec3, a: Vec3) {
  192. out[0] = Math.abs(a[0]);
  193. out[1] = Math.abs(a[1]);
  194. out[2] = Math.abs(a[2]);
  195. return out;
  196. }
  197. /**
  198. * Returns the minimum of two Vec3's
  199. */
  200. export function min(out: Vec3, a: Vec3, b: Vec3) {
  201. out[0] = Math.min(a[0], b[0]);
  202. out[1] = Math.min(a[1], b[1]);
  203. out[2] = Math.min(a[2], b[2]);
  204. return out;
  205. }
  206. /**
  207. * Returns the maximum of two Vec3's
  208. */
  209. export function max(out: Vec3, a: Vec3, b: Vec3) {
  210. out[0] = Math.max(a[0], b[0]);
  211. out[1] = Math.max(a[1], b[1]);
  212. out[2] = Math.max(a[2], b[2]);
  213. return out;
  214. }
  215. export function distance(a: Vec3, b: Vec3) {
  216. const x = b[0] - a[0],
  217. y = b[1] - a[1],
  218. z = b[2] - a[2];
  219. return Math.sqrt(x * x + y * y + z * z);
  220. }
  221. export function squaredDistance(a: Vec3, b: Vec3) {
  222. const x = b[0] - a[0],
  223. y = b[1] - a[1],
  224. z = b[2] - a[2];
  225. return x * x + y * y + z * z;
  226. }
  227. export function magnitude(a: Vec3) {
  228. const x = a[0],
  229. y = a[1],
  230. z = a[2];
  231. return Math.sqrt(x * x + y * y + z * z);
  232. }
  233. export function squaredMagnitude(a: Vec3) {
  234. const x = a[0],
  235. y = a[1],
  236. z = a[2];
  237. return x * x + y * y + z * z;
  238. }
  239. export function setMagnitude(out: Vec3, a: Vec3, l: number) {
  240. return scale(out, normalize(out, a), l);
  241. }
  242. /**
  243. * Negates the components of a vec3
  244. */
  245. export function negate(out: Vec3, a: Vec3) {
  246. out[0] = -a[0];
  247. out[1] = -a[1];
  248. out[2] = -a[2];
  249. return out;
  250. }
  251. /**
  252. * Returns the inverse of the components of a Vec3
  253. */
  254. export function inverse(out: Vec3, a: Vec3) {
  255. out[0] = 1.0 / a[0];
  256. out[1] = 1.0 / a[1];
  257. out[2] = 1.0 / a[2];
  258. return out;
  259. }
  260. export function normalize(out: Vec3, a: Vec3) {
  261. const x = a[0],
  262. y = a[1],
  263. z = a[2];
  264. let len = x * x + y * y + z * z;
  265. if (len > 0) {
  266. len = 1 / Math.sqrt(len);
  267. out[0] = a[0] * len;
  268. out[1] = a[1] * len;
  269. out[2] = a[2] * len;
  270. }
  271. return out;
  272. }
  273. export function dot(a: Vec3, b: Vec3) {
  274. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  275. }
  276. export function cross(out: Vec3, a: Vec3, b: Vec3) {
  277. const ax = a[0], ay = a[1], az = a[2],
  278. bx = b[0], by = b[1], bz = b[2];
  279. out[0] = ay * bz - az * by;
  280. out[1] = az * bx - ax * bz;
  281. out[2] = ax * by - ay * bx;
  282. return out;
  283. }
  284. /**
  285. * Performs a linear interpolation between two Vec3's
  286. */
  287. export function lerp(out: Vec3, a: Vec3, b: Vec3, t: number) {
  288. const ax = a[0],
  289. ay = a[1],
  290. az = a[2];
  291. out[0] = ax + t * (b[0] - ax);
  292. out[1] = ay + t * (b[1] - ay);
  293. out[2] = az + t * (b[2] - az);
  294. return out;
  295. }
  296. const slerpRelVec = zero();
  297. export function slerp(out: Vec3, a: Vec3, b: Vec3, t: number) {
  298. const d = clamp(dot(a, b), -1, 1);
  299. const theta = Math.acos(d) * t;
  300. scaleAndAdd(slerpRelVec, b, a, -d);
  301. normalize(slerpRelVec, slerpRelVec);
  302. return add(out, scale(out, a, Math.cos(theta)), scale(slerpRelVec, slerpRelVec, Math.sin(theta)));
  303. }
  304. /**
  305. * Performs a hermite interpolation with two control points
  306. */
  307. export function hermite(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number) {
  308. const factorTimes2 = t * t;
  309. const factor1 = factorTimes2 * (2 * t - 3) + 1;
  310. const factor2 = factorTimes2 * (t - 2) + t;
  311. const factor3 = factorTimes2 * (t - 1);
  312. const factor4 = factorTimes2 * (3 - 2 * t);
  313. out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
  314. out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
  315. out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
  316. return out;
  317. }
  318. /**
  319. * Performs a bezier interpolation with two control points
  320. */
  321. export function bezier(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number) {
  322. const inverseFactor = 1 - t;
  323. const inverseFactorTimesTwo = inverseFactor * inverseFactor;
  324. const factorTimes2 = t * t;
  325. const factor1 = inverseFactorTimesTwo * inverseFactor;
  326. const factor2 = 3 * t * inverseFactorTimesTwo;
  327. const factor3 = 3 * factorTimes2 * inverseFactor;
  328. const factor4 = factorTimes2 * t;
  329. out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
  330. out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
  331. out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
  332. return out;
  333. }
  334. export function quadraticBezier(out: Vec3, a: Vec3, b: Vec3, c: Vec3, t: number) {
  335. out[0] = _quadraticBezier(a[0], b[0], c[0], t);
  336. out[1] = _quadraticBezier(a[1], b[1], c[1], t);
  337. out[2] = _quadraticBezier(a[2], b[2], c[2], t);
  338. return out;
  339. }
  340. /**
  341. * Performs a spline interpolation with two control points and a tension parameter
  342. */
  343. export function spline(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number, tension: number) {
  344. out[0] = _spline(a[0], b[0], c[0], d[0], t, tension);
  345. out[1] = _spline(a[1], b[1], c[1], d[1], t, tension);
  346. out[2] = _spline(a[2], b[2], c[2], d[2], t, tension);
  347. return out;
  348. }
  349. /**
  350. * Generates a random vector with the given scale
  351. */
  352. export function random(out: Vec3, scale: number) {
  353. const r = Math.random() * 2.0 * Math.PI;
  354. const z = (Math.random() * 2.0) - 1.0;
  355. const zScale = Math.sqrt(1.0 - z * z) * scale;
  356. out[0] = Math.cos(r) * zScale;
  357. out[1] = Math.sin(r) * zScale;
  358. out[2] = z * scale;
  359. return out;
  360. }
  361. /**
  362. * Transforms the Vec3 with a Mat4. 4th vector component is implicitly '1'
  363. */
  364. export function transformMat4(out: Vec3, a: Vec3, m: Mat4) {
  365. const x = a[0], y = a[1], z = a[2],
  366. w = 1 / ((m[3] * x + m[7] * y + m[11] * z + m[15]) || 1.0);
  367. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) * w;
  368. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) * w;
  369. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) * w;
  370. return out;
  371. }
  372. /**
  373. * Like `transformMat4` but with offsets into arrays
  374. */
  375. export function transformMat4Offset(out: NumberArray, a: NumberArray, m: NumberArray, outO: number, aO: number, oM: number) {
  376. const x = a[0 + aO], y = a[1 + aO], z = a[2 + aO],
  377. w = 1 / ((m[3 + oM] * x + m[7 + oM] * y + m[11 + oM] * z + m[15 + oM]) || 1.0);
  378. out[0 + outO] = (m[0 + oM] * x + m[4 + oM] * y + m[8 + oM] * z + m[12 + oM]) * w;
  379. out[1 + outO] = (m[1 + oM] * x + m[5 + oM] * y + m[9 + oM] * z + m[13 + oM]) * w;
  380. out[2 + outO] = (m[2 + oM] * x + m[6 + oM] * y + m[10 + oM] * z + m[14 + oM]) * w;
  381. return out;
  382. }
  383. /**
  384. * Transforms the Vec3 with a Mat3.
  385. */
  386. export function transformMat3(out: Vec3, a: Vec3, m: Mat3) {
  387. const x = a[0], y = a[1], z = a[2];
  388. out[0] = x * m[0] + y * m[3] + z * m[6];
  389. out[1] = x * m[1] + y * m[4] + z * m[7];
  390. out[2] = x * m[2] + y * m[5] + z * m[8];
  391. return out;
  392. }
  393. /** Transforms the Vec3 with a quat */
  394. export function transformQuat(out: Vec3, a: Vec3, q: Quat) {
  395. // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations
  396. const x = a[0], y = a[1], z = a[2];
  397. const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
  398. // calculate quat * vec
  399. const ix = qw * x + qy * z - qz * y;
  400. const iy = qw * y + qz * x - qx * z;
  401. const iz = qw * z + qx * y - qy * x;
  402. const iw = -qx * x - qy * y - qz * z;
  403. // calculate result * inverse quat
  404. out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  405. out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  406. out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  407. return out;
  408. }
  409. /** Computes the angle between 2 vectors, reports in radians. */
  410. export function angle(a: Vec3, b: Vec3) {
  411. const denominator = Math.sqrt(squaredMagnitude(a) * squaredMagnitude(b));
  412. if (denominator === 0) return Math.PI / 2;
  413. const theta = dot(a, b) / denominator;
  414. return Math.acos(clamp(theta, -1, 1)); // clamp to avoid numerical problems
  415. }
  416. const tmp_dh_ab = zero();
  417. const tmp_dh_cb = zero();
  418. const tmp_dh_bc = zero();
  419. const tmp_dh_dc = zero();
  420. const tmp_dh_abc = zero();
  421. const tmp_dh_bcd = zero();
  422. const tmp_dh_cross = zero();
  423. /**
  424. * Computes the dihedral angles of 4 points, reports in radians.
  425. */
  426. export function dihedralAngle(a: Vec3, b: Vec3, c: Vec3, d: Vec3): number {
  427. sub(tmp_dh_ab, a, b);
  428. sub(tmp_dh_cb, c, b);
  429. sub(tmp_dh_bc, b, c);
  430. sub(tmp_dh_dc, d, c);
  431. cross(tmp_dh_abc, tmp_dh_ab, tmp_dh_cb);
  432. cross(tmp_dh_bcd, tmp_dh_bc, tmp_dh_dc);
  433. const _angle = angle(tmp_dh_abc, tmp_dh_bcd);
  434. cross(tmp_dh_cross, tmp_dh_abc, tmp_dh_bcd);
  435. return dot(tmp_dh_cb, tmp_dh_cross) > 0 ? _angle : -_angle;
  436. }
  437. /**
  438. * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
  439. */
  440. export function exactEquals(a: Vec3, b: Vec3) {
  441. return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
  442. }
  443. /**
  444. * Returns whether or not the vectors have approximately the same elements in the same position.
  445. */
  446. export function equals(a: Vec3, b: Vec3) {
  447. const a0 = a[0], a1 = a[1], a2 = a[2];
  448. const b0 = b[0], b1 = b[1], b2 = b[2];
  449. return (Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
  450. Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
  451. Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)));
  452. }
  453. const rotTemp = zero();
  454. export function makeRotation(mat: Mat4, a: Vec3, b: Vec3): Mat4 {
  455. const by = angle(a, b);
  456. if (Math.abs(by) < 0.0001) return Mat4.setIdentity(mat);
  457. if (Math.abs(by - Math.PI) < EPSILON) {
  458. // here, axis can be [0,0,0] but the rotation is a simple flip
  459. return Mat4.fromScaling(mat, negUnit);
  460. }
  461. const axis = cross(rotTemp, a, b);
  462. return Mat4.fromRotation(mat, by, axis);
  463. }
  464. export function isZero(v: Vec3) {
  465. return v[0] === 0 && v[1] === 0 && v[2] === 0;
  466. }
  467. /** Project `point` onto `vector` starting from `origin` */
  468. export function projectPointOnVector(out: Vec3, point: Vec3, vector: Vec3, origin: Vec3) {
  469. sub(out, copy(out, point), origin);
  470. const scalar = dot(vector, out) / squaredMagnitude(vector);
  471. return add(out, scale(out, copy(out, vector), scalar), origin);
  472. }
  473. export function projectOnVector(out: Vec3, p: Vec3, vector: Vec3 ) {
  474. const scalar = dot(vector, p) / squaredMagnitude(vector);
  475. return scale(out, vector, scalar);
  476. }
  477. const tmpProject = zero();
  478. export function projectOnPlane(out: Vec3, p: Vec3, normal: Vec3) {
  479. projectOnVector(tmpProject, p, normal);
  480. return sub(out, p, tmpProject);
  481. }
  482. /** Get a vector that is similar to `b` but orthogonal to `a` */
  483. export function orthogonalize(out: Vec3, a: Vec3, b: Vec3) {
  484. return normalize(out, cross(out, cross(out, a, b), a));
  485. }
  486. /**
  487. * Get a vector like `a` that point into the same general direction as `b`,
  488. * i.e. where the dot product is > 0
  489. */
  490. export function matchDirection(out: Vec3, a: Vec3, b: Vec3) {
  491. if (dot(a, b) > 0) copy(out, a);
  492. else negate(out, copy(out, a));
  493. return out;
  494. }
  495. const triangleNormalTmpAB = zero();
  496. const triangleNormalTmpAC = zero();
  497. /** Calculate normal for the triangle defined by `a`, `b` and `c` */
  498. export function triangleNormal(out: Vec3, a: Vec3, b: Vec3, c: Vec3) {
  499. sub(triangleNormalTmpAB, b, a);
  500. sub(triangleNormalTmpAC, c, a);
  501. return normalize(out, cross(out, triangleNormalTmpAB, triangleNormalTmpAC));
  502. }
  503. export function toString(a: Vec3, precision?: number) {
  504. return `[${a[0].toPrecision(precision)} ${a[1].toPrecision(precision)} ${a[2].toPrecision(precision)}]`;
  505. }
  506. export const origin: ReadonlyVec3 = create(0, 0, 0);
  507. export const unit: ReadonlyVec3 = create(1, 1, 1);
  508. export const negUnit: ReadonlyVec3 = create(-1, -1, -1);
  509. export const unitX: ReadonlyVec3 = create(1, 0, 0);
  510. export const unitY: ReadonlyVec3 = create(0, 1, 0);
  511. export const unitZ: ReadonlyVec3 = create(0, 0, 1);
  512. export const negUnitX: ReadonlyVec3 = create(-1, 0, 0);
  513. export const negUnitY: ReadonlyVec3 = create(0, -1, 0);
  514. export const negUnitZ: ReadonlyVec3 = create(0, 0, -1);
  515. }
  516. export { Vec3 };