UNPKG

cesium-pocket

Version:

cesium的插件库;基于vue3的开发

1,393 lines 1.76 MB
import { defineComponent as cs, ref as Rt, onMounted as ls, nextTick as us, onUnmounted as wi, createElementBlock as _n, openBlock as $n, createTextVNode as Oc, createElementVNode as Zt, toDisplayString as $r, mergeModels as kc, useModel as Hc, computed as mo, normalizeStyle as jA, renderSlot as VA, Fragment as Nc, renderList as Rc, withDirectives as jc, vShow as Vc } from "vue"; import { Viewer as fs, Math as ts, Cartesian2 as Xs, Cartesian3 as Sn, Cartographic as FA, SceneTransforms as Fc, Ray as Gc, PinBuilder as qc, EntityCollection as Jc, ScreenSpaceEventType as vs, ScreenSpaceEventHandler as Yc, VerticalOrigin as hr, Color as ea } from "cesium"; import { L as Es } from "./index-i533HtMV.js"; import { P as dm } from "./index-i533HtMV.js"; /** * @license * Copyright 2010-2025 Three.js Authors * SPDX-License-Identifier: MIT */ const qa = "179", Xc = 0, vo = 1, Kc = 2, GA = 1, Wc = 2, Pn = 3, Tn = 0, bt = 1, $t = 2, Qn = 0, Ei = 1, Eo = 2, To = 3, Co = 4, Zc = 5, Xn = 100, _c = 101, $c = 102, el = 103, tl = 104, nl = 200, il = 201, sl = 202, rl = 203, ta = 204, na = 205, al = 206, ol = 207, Al = 208, cl = 209, ll = 210, ul = 211, fl = 212, dl = 213, hl = 214, ia = 0, sa = 1, ra = 2, Bi = 3, aa = 4, oa = 5, Aa = 6, ca = 7, qA = 0, Pl = 1, pl = 2, Un = 0, gl = 1, ml = 2, vl = 3, El = 4, Tl = 5, Cl = 6, Ml = 7, Mo = "attached", wl = "detached", JA = 300, Di = 301, Ii = 302, la = 303, ua = 304, or = 306, yi = 1e3, xn = 1001, nr = 1002, Bt = 1003, YA = 1004, Wi = 1005, Ut = 1006, Ks = 1007, gn = 1008, nn = 1009, XA = 1010, KA = 1011, ns = 1012, Ja = 1013, ei = 1014, Yt = 1015, ds = 1016, Ya = 1017, Xa = 1018, is = 1020, WA = 35902, ZA = 1021, _A = 1022, jt = 1023, ss = 1026, rs = 1027, Ka = 1028, Wa = 1029, $A = 1030, Za = 1031, _a = 1033, Ws = 33776, Zs = 33777, _s = 33778, $s = 33779, fa = 35840, da = 35841, ha = 35842, Pa = 35843, pa = 36196, ga = 37492, ma = 37496, va = 37808, Ea = 37809, Ta = 37810, Ca = 37811, Ma = 37812, wa = 37813, Ba = 37814, Da = 37815, Ia = 37816, ya = 37817, ba = 37818, Sa = 37819, za = 37820, xa = 37821, er = 36492, Qa = 36494, Ua = 36495, ec = 36283, La = 36284, Oa = 36285, ka = 36286, as = 2300, os = 2301, Pr = 2302, wo = 2400, Bo = 2401, Do = 2402, Bl = 2500, Dl = 0, tc = 1, Ha = 2, Il = 3200, yl = 3201, nc = 0, bl = 1, zn = "", mt = "srgb", It = "srgb-linear", ir = "linear", _e = "srgb", ii = 7680, Io = 519, Sl = 512, zl = 513, xl = 514, ic = 515, Ql = 516, Ul = 517, Ll = 518, Ol = 519, Na = 35044, yo = "300 es", en = 2e3, sr = 2001; class Ui { /** * Adds the given event listener to the given event type. * * @param {string} type - The type of event to listen to. * @param {Function} listener - The function that gets called when the event is fired. */ addEventListener(e, t) { this._listeners === void 0 && (this._listeners = {}); const n = this._listeners; n[e] === void 0 && (n[e] = []), n[e].indexOf(t) === -1 && n[e].push(t); } /** * Returns `true` if the given event listener has been added to the given event type. * * @param {string} type - The type of event. * @param {Function} listener - The listener to check. * @return {boolean} Whether the given event listener has been added to the given event type. */ hasEventListener(e, t) { const n = this._listeners; return n === void 0 ? !1 : n[e] !== void 0 && n[e].indexOf(t) !== -1; } /** * Removes the given event listener from the given event type. * * @param {string} type - The type of event. * @param {Function} listener - The listener to remove. */ removeEventListener(e, t) { const n = this._listeners; if (n === void 0) return; const i = n[e]; if (i !== void 0) { const r = i.indexOf(t); r !== -1 && i.splice(r, 1); } } /** * Dispatches an event object. * * @param {Object} event - The event that gets fired. */ dispatchEvent(e) { const t = this._listeners; if (t === void 0) return; const n = t[e.type]; if (n !== void 0) { e.target = this; const i = n.slice(0); for (let r = 0, a = i.length; r < a; r++) i[r].call(this, e); e.target = null; } } } const vt = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"]; let bo = 1234567; const _i = Math.PI / 180, bi = 180 / Math.PI; function Xt() { const s = Math.random() * 4294967295 | 0, e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, n = Math.random() * 4294967295 | 0; return (vt[s & 255] + vt[s >> 8 & 255] + vt[s >> 16 & 255] + vt[s >> 24 & 255] + "-" + vt[e & 255] + vt[e >> 8 & 255] + "-" + vt[e >> 16 & 15 | 64] + vt[e >> 24 & 255] + "-" + vt[t & 63 | 128] + vt[t >> 8 & 255] + "-" + vt[t >> 16 & 255] + vt[t >> 24 & 255] + vt[n & 255] + vt[n >> 8 & 255] + vt[n >> 16 & 255] + vt[n >> 24 & 255]).toLowerCase(); } function Ne(s, e, t) { return Math.max(e, Math.min(t, s)); } function $a(s, e) { return (s % e + e) % e; } function kl(s, e, t, n, i) { return n + (s - e) * (i - n) / (t - e); } function Hl(s, e, t) { return s !== e ? (t - s) / (e - s) : 0; } function $i(s, e, t) { return (1 - t) * s + t * e; } function Nl(s, e, t, n) { return $i(s, e, 1 - Math.exp(-t * n)); } function Rl(s, e = 1) { return e - Math.abs($a(s, e * 2) - e); } function jl(s, e, t) { return s <= e ? 0 : s >= t ? 1 : (s = (s - e) / (t - e), s * s * (3 - 2 * s)); } function Vl(s, e, t) { return s <= e ? 0 : s >= t ? 1 : (s = (s - e) / (t - e), s * s * s * (s * (s * 6 - 15) + 10)); } function Fl(s, e) { return s + Math.floor(Math.random() * (e - s + 1)); } function Gl(s, e) { return s + Math.random() * (e - s); } function ql(s) { return s * (0.5 - Math.random()); } function Jl(s) { s !== void 0 && (bo = s); let e = bo += 1831565813; return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296; } function Yl(s) { return s * _i; } function Xl(s) { return s * bi; } function Kl(s) { return (s & s - 1) === 0 && s !== 0; } function Wl(s) { return Math.pow(2, Math.ceil(Math.log(s) / Math.LN2)); } function Zl(s) { return Math.pow(2, Math.floor(Math.log(s) / Math.LN2)); } function _l(s, e, t, n, i) { const r = Math.cos, a = Math.sin, o = r(t / 2), A = a(t / 2), c = r((e + n) / 2), l = a((e + n) / 2), u = r((e - n) / 2), f = a((e - n) / 2), h = r((n - e) / 2), p = a((n - e) / 2); switch (i) { case "XYX": s.set(o * l, A * u, A * f, o * c); break; case "YZY": s.set(A * f, o * l, A * u, o * c); break; case "ZXZ": s.set(A * u, A * f, o * l, o * c); break; case "XZX": s.set(o * l, A * p, A * h, o * c); break; case "YXY": s.set(A * h, o * l, A * p, o * c); break; case "ZYZ": s.set(A * p, A * h, o * l, o * c); break; default: console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + i); } } function qt(s, e) { switch (e.constructor) { case Float32Array: return s; case Uint32Array: return s / 4294967295; case Uint16Array: return s / 65535; case Uint8Array: return s / 255; case Int32Array: return Math.max(s / 2147483647, -1); case Int16Array: return Math.max(s / 32767, -1); case Int8Array: return Math.max(s / 127, -1); default: throw new Error("Invalid component type."); } } function Ke(s, e) { switch (e.constructor) { case Float32Array: return s; case Uint32Array: return Math.round(s * 4294967295); case Uint16Array: return Math.round(s * 65535); case Uint8Array: return Math.round(s * 255); case Int32Array: return Math.round(s * 2147483647); case Int16Array: return Math.round(s * 32767); case Int8Array: return Math.round(s * 127); default: throw new Error("Invalid component type."); } } const $l = { DEG2RAD: _i, RAD2DEG: bi, /** * Generate a [UUID]{@link https://en.wikipedia.org/wiki/Universally_unique_identifier} * (universally unique identifier). * * @static * @method * @return {string} The UUID. */ generateUUID: Xt, /** * Clamps the given value between min and max. * * @static * @method * @param {number} value - The value to clamp. * @param {number} min - The min value. * @param {number} max - The max value. * @return {number} The clamped value. */ clamp: Ne, /** * Computes the Euclidean modulo of the given parameters that * is `( ( n % m ) + m ) % m`. * * @static * @method * @param {number} n - The first parameter. * @param {number} m - The second parameter. * @return {number} The Euclidean modulo. */ euclideanModulo: $a, /** * Performs a linear mapping from range `<a1, a2>` to range `<b1, b2>` * for the given value. * * @static * @method * @param {number} x - The value to be mapped. * @param {number} a1 - Minimum value for range A. * @param {number} a2 - Maximum value for range A. * @param {number} b1 - Minimum value for range B. * @param {number} b2 - Maximum value for range B. * @return {number} The mapped value. */ mapLinear: kl, /** * Returns the percentage in the closed interval `[0, 1]` of the given value * between the start and end point. * * @static * @method * @param {number} x - The start point * @param {number} y - The end point. * @param {number} value - A value between start and end. * @return {number} The interpolation factor. */ inverseLerp: Hl, /** * Returns a value linearly interpolated from two known points based on the given interval - * `t = 0` will return `x` and `t = 1` will return `y`. * * @static * @method * @param {number} x - The start point * @param {number} y - The end point. * @param {number} t - The interpolation factor in the closed interval `[0, 1]`. * @return {number} The interpolated value. */ lerp: $i, /** * Smoothly interpolate a number from `x` to `y` in a spring-like manner using a delta * time to maintain frame rate independent movement. For details, see * [Frame rate independent damping using lerp]{@link http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/}. * * @static * @method * @param {number} x - The current point. * @param {number} y - The target point. * @param {number} lambda - A higher lambda value will make the movement more sudden, * and a lower value will make the movement more gradual. * @param {number} dt - Delta time in seconds. * @return {number} The interpolated value. */ damp: Nl, /** * Returns a value that alternates between `0` and the given `length` parameter. * * @static * @method * @param {number} x - The value to pingpong. * @param {number} [length=1] - The positive value the function will pingpong to. * @return {number} The alternated value. */ pingpong: Rl, /** * Returns a value in the range `[0,1]` that represents the percentage that `x` has * moved between `min` and `max`, but smoothed or slowed down the closer `x` is to * the `min` and `max`. * * See [Smoothstep]{@link http://en.wikipedia.org/wiki/Smoothstep} for more details. * * @static * @method * @param {number} x - The value to evaluate based on its position between min and max. * @param {number} min - The min value. Any x value below min will be `0`. * @param {number} max - The max value. Any x value above max will be `1`. * @return {number} The alternated value. */ smoothstep: jl, /** * A [variation on smoothstep]{@link https://en.wikipedia.org/wiki/Smoothstep#Variations} * that has zero 1st and 2nd order derivatives at x=0 and x=1. * * @static * @method * @param {number} x - The value to evaluate based on its position between min and max. * @param {number} min - The min value. Any x value below min will be `0`. * @param {number} max - The max value. Any x value above max will be `1`. * @return {number} The alternated value. */ smootherstep: Vl, /** * Returns a random integer from `<low, high>` interval. * * @static * @method * @param {number} low - The lower value boundary. * @param {number} high - The upper value boundary * @return {number} A random integer. */ randInt: Fl, /** * Returns a random float from `<low, high>` interval. * * @static * @method * @param {number} low - The lower value boundary. * @param {number} high - The upper value boundary * @return {number} A random float. */ randFloat: Gl, /** * Returns a random integer from `<-range/2, range/2>` interval. * * @static * @method * @param {number} range - Defines the value range. * @return {number} A random float. */ randFloatSpread: ql, /** * Returns a deterministic pseudo-random float in the interval `[0, 1]`. * * @static * @method * @param {number} [s] - The integer seed. * @return {number} A random float. */ seededRandom: Jl, /** * Converts degrees to radians. * * @static * @method * @param {number} degrees - A value in degrees. * @return {number} The converted value in radians. */ degToRad: Yl, /** * Converts radians to degrees. * * @static * @method * @param {number} radians - A value in radians. * @return {number} The converted value in degrees. */ radToDeg: Xl, /** * Returns `true` if the given number is a power of two. * * @static * @method * @param {number} value - The value to check. * @return {boolean} Whether the given number is a power of two or not. */ isPowerOfTwo: Kl, /** * Returns the smallest power of two that is greater than or equal to the given number. * * @static * @method * @param {number} value - The value to find a POT for. * @return {number} The smallest power of two that is greater than or equal to the given number. */ ceilPowerOfTwo: Wl, /** * Returns the largest power of two that is less than or equal to the given number. * * @static * @method * @param {number} value - The value to find a POT for. * @return {number} The largest power of two that is less than or equal to the given number. */ floorPowerOfTwo: Zl, /** * Sets the given quaternion from the [Intrinsic Proper Euler Angles]{@link https://en.wikipedia.org/wiki/Euler_angles} * defined by the given angles and order. * * Rotations are applied to the axes in the order specified by order: * rotation by angle `a` is applied first, then by angle `b`, then by angle `c`. * * @static * @method * @param {Quaternion} q - The quaternion to set. * @param {number} a - The rotation applied to the first axis, in radians. * @param {number} b - The rotation applied to the second axis, in radians. * @param {number} c - The rotation applied to the third axis, in radians. * @param {('XYX'|'XZX'|'YXY'|'YZY'|'ZXZ'|'ZYZ')} order - A string specifying the axes order. */ setQuaternionFromProperEuler: _l, /** * Normalizes the given value according to the given typed array. * * @static * @method * @param {number} value - The float value in the range `[0,1]` to normalize. * @param {TypedArray} array - The typed array that defines the data type of the value. * @return {number} The normalize value. */ normalize: Ke, /** * Denormalizes the given value according to the given typed array. * * @static * @method * @param {number} value - The value to denormalize. * @param {TypedArray} array - The typed array that defines the data type of the value. * @return {number} The denormalize (float) value in the range `[0,1]`. */ denormalize: qt }; class Ve { /** * Constructs a new 2D vector. * * @param {number} [x=0] - The x value of this vector. * @param {number} [y=0] - The y value of this vector. */ constructor(e = 0, t = 0) { Ve.prototype.isVector2 = !0, this.x = e, this.y = t; } /** * Alias for {@link Vector2#x}. * * @type {number} */ get width() { return this.x; } set width(e) { this.x = e; } /** * Alias for {@link Vector2#y}. * * @type {number} */ get height() { return this.y; } set height(e) { this.y = e; } /** * Sets the vector components. * * @param {number} x - The value of the x component. * @param {number} y - The value of the y component. * @return {Vector2} A reference to this vector. */ set(e, t) { return this.x = e, this.y = t, this; } /** * Sets the vector components to the same value. * * @param {number} scalar - The value to set for all vector components. * @return {Vector2} A reference to this vector. */ setScalar(e) { return this.x = e, this.y = e, this; } /** * Sets the vector's x component to the given value * * @param {number} x - The value to set. * @return {Vector2} A reference to this vector. */ setX(e) { return this.x = e, this; } /** * Sets the vector's y component to the given value * * @param {number} y - The value to set. * @return {Vector2} A reference to this vector. */ setY(e) { return this.y = e, this; } /** * Allows to set a vector component with an index. * * @param {number} index - The component index. `0` equals to x, `1` equals to y. * @param {number} value - The value to set. * @return {Vector2} A reference to this vector. */ setComponent(e, t) { switch (e) { case 0: this.x = t; break; case 1: this.y = t; break; default: throw new Error("index is out of range: " + e); } return this; } /** * Returns the value of the vector component which matches the given index. * * @param {number} index - The component index. `0` equals to x, `1` equals to y. * @return {number} A vector component value. */ getComponent(e) { switch (e) { case 0: return this.x; case 1: return this.y; default: throw new Error("index is out of range: " + e); } } /** * Returns a new vector with copied values from this instance. * * @return {Vector2} A clone of this instance. */ clone() { return new this.constructor(this.x, this.y); } /** * Copies the values of the given vector to this instance. * * @param {Vector2} v - The vector to copy. * @return {Vector2} A reference to this vector. */ copy(e) { return this.x = e.x, this.y = e.y, this; } /** * Adds the given vector to this instance. * * @param {Vector2} v - The vector to add. * @return {Vector2} A reference to this vector. */ add(e) { return this.x += e.x, this.y += e.y, this; } /** * Adds the given scalar value to all components of this instance. * * @param {number} s - The scalar to add. * @return {Vector2} A reference to this vector. */ addScalar(e) { return this.x += e, this.y += e, this; } /** * Adds the given vectors and stores the result in this instance. * * @param {Vector2} a - The first vector. * @param {Vector2} b - The second vector. * @return {Vector2} A reference to this vector. */ addVectors(e, t) { return this.x = e.x + t.x, this.y = e.y + t.y, this; } /** * Adds the given vector scaled by the given factor to this instance. * * @param {Vector2} v - The vector. * @param {number} s - The factor that scales `v`. * @return {Vector2} A reference to this vector. */ addScaledVector(e, t) { return this.x += e.x * t, this.y += e.y * t, this; } /** * Subtracts the given vector from this instance. * * @param {Vector2} v - The vector to subtract. * @return {Vector2} A reference to this vector. */ sub(e) { return this.x -= e.x, this.y -= e.y, this; } /** * Subtracts the given scalar value from all components of this instance. * * @param {number} s - The scalar to subtract. * @return {Vector2} A reference to this vector. */ subScalar(e) { return this.x -= e, this.y -= e, this; } /** * Subtracts the given vectors and stores the result in this instance. * * @param {Vector2} a - The first vector. * @param {Vector2} b - The second vector. * @return {Vector2} A reference to this vector. */ subVectors(e, t) { return this.x = e.x - t.x, this.y = e.y - t.y, this; } /** * Multiplies the given vector with this instance. * * @param {Vector2} v - The vector to multiply. * @return {Vector2} A reference to this vector. */ multiply(e) { return this.x *= e.x, this.y *= e.y, this; } /** * Multiplies the given scalar value with all components of this instance. * * @param {number} scalar - The scalar to multiply. * @return {Vector2} A reference to this vector. */ multiplyScalar(e) { return this.x *= e, this.y *= e, this; } /** * Divides this instance by the given vector. * * @param {Vector2} v - The vector to divide. * @return {Vector2} A reference to this vector. */ divide(e) { return this.x /= e.x, this.y /= e.y, this; } /** * Divides this vector by the given scalar. * * @param {number} scalar - The scalar to divide. * @return {Vector2} A reference to this vector. */ divideScalar(e) { return this.multiplyScalar(1 / e); } /** * Multiplies this vector (with an implicit 1 as the 3rd component) by * the given 3x3 matrix. * * @param {Matrix3} m - The matrix to apply. * @return {Vector2} A reference to this vector. */ applyMatrix3(e) { const t = this.x, n = this.y, i = e.elements; return this.x = i[0] * t + i[3] * n + i[6], this.y = i[1] * t + i[4] * n + i[7], this; } /** * If this vector's x or y value is greater than the given vector's x or y * value, replace that value with the corresponding min value. * * @param {Vector2} v - The vector. * @return {Vector2} A reference to this vector. */ min(e) { return this.x = Math.min(this.x, e.x), this.y = Math.min(this.y, e.y), this; } /** * If this vector's x or y value is less than the given vector's x or y * value, replace that value with the corresponding max value. * * @param {Vector2} v - The vector. * @return {Vector2} A reference to this vector. */ max(e) { return this.x = Math.max(this.x, e.x), this.y = Math.max(this.y, e.y), this; } /** * If this vector's x or y value is greater than the max vector's x or y * value, it is replaced by the corresponding value. * If this vector's x or y value is less than the min vector's x or y value, * it is replaced by the corresponding value. * * @param {Vector2} min - The minimum x and y values. * @param {Vector2} max - The maximum x and y values in the desired range. * @return {Vector2} A reference to this vector. */ clamp(e, t) { return this.x = Ne(this.x, e.x, t.x), this.y = Ne(this.y, e.y, t.y), this; } /** * If this vector's x or y values are greater than the max value, they are * replaced by the max value. * If this vector's x or y values are less than the min value, they are * replaced by the min value. * * @param {number} minVal - The minimum value the components will be clamped to. * @param {number} maxVal - The maximum value the components will be clamped to. * @return {Vector2} A reference to this vector. */ clampScalar(e, t) { return this.x = Ne(this.x, e, t), this.y = Ne(this.y, e, t), this; } /** * If this vector's length is greater than the max value, it is replaced by * the max value. * If this vector's length is less than the min value, it is replaced by the * min value. * * @param {number} min - The minimum value the vector length will be clamped to. * @param {number} max - The maximum value the vector length will be clamped to. * @return {Vector2} A reference to this vector. */ clampLength(e, t) { const n = this.length(); return this.divideScalar(n || 1).multiplyScalar(Ne(n, e, t)); } /** * The components of this vector are rounded down to the nearest integer value. * * @return {Vector2} A reference to this vector. */ floor() { return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this; } /** * The components of this vector are rounded up to the nearest integer value. * * @return {Vector2} A reference to this vector. */ ceil() { return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this; } /** * The components of this vector are rounded to the nearest integer value * * @return {Vector2} A reference to this vector. */ round() { return this.x = Math.round(this.x), this.y = Math.round(this.y), this; } /** * The components of this vector are rounded towards zero (up if negative, * down if positive) to an integer value. * * @return {Vector2} A reference to this vector. */ roundToZero() { return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this; } /** * Inverts this vector - i.e. sets x = -x and y = -y. * * @return {Vector2} A reference to this vector. */ negate() { return this.x = -this.x, this.y = -this.y, this; } /** * Calculates the dot product of the given vector with this instance. * * @param {Vector2} v - The vector to compute the dot product with. * @return {number} The result of the dot product. */ dot(e) { return this.x * e.x + this.y * e.y; } /** * Calculates the cross product of the given vector with this instance. * * @param {Vector2} v - The vector to compute the cross product with. * @return {number} The result of the cross product. */ cross(e) { return this.x * e.y - this.y * e.x; } /** * Computes the square of the Euclidean length (straight-line length) from * (0, 0) to (x, y). If you are comparing the lengths of vectors, you should * compare the length squared instead as it is slightly more efficient to calculate. * * @return {number} The square length of this vector. */ lengthSq() { return this.x * this.x + this.y * this.y; } /** * Computes the Euclidean length (straight-line length) from (0, 0) to (x, y). * * @return {number} The length of this vector. */ length() { return Math.sqrt(this.x * this.x + this.y * this.y); } /** * Computes the Manhattan length of this vector. * * @return {number} The length of this vector. */ manhattanLength() { return Math.abs(this.x) + Math.abs(this.y); } /** * Converts this vector to a unit vector - that is, sets it equal to a vector * with the same direction as this one, but with a vector length of `1`. * * @return {Vector2} A reference to this vector. */ normalize() { return this.divideScalar(this.length() || 1); } /** * Computes the angle in radians of this vector with respect to the positive x-axis. * * @return {number} The angle in radians. */ angle() { return Math.atan2(-this.y, -this.x) + Math.PI; } /** * Returns the angle between the given vector and this instance in radians. * * @param {Vector2} v - The vector to compute the angle with. * @return {number} The angle in radians. */ angleTo(e) { const t = Math.sqrt(this.lengthSq() * e.lengthSq()); if (t === 0) return Math.PI / 2; const n = this.dot(e) / t; return Math.acos(Ne(n, -1, 1)); } /** * Computes the distance from the given vector to this instance. * * @param {Vector2} v - The vector to compute the distance to. * @return {number} The distance. */ distanceTo(e) { return Math.sqrt(this.distanceToSquared(e)); } /** * Computes the squared distance from the given vector to this instance. * If you are just comparing the distance with another distance, you should compare * the distance squared instead as it is slightly more efficient to calculate. * * @param {Vector2} v - The vector to compute the squared distance to. * @return {number} The squared distance. */ distanceToSquared(e) { const t = this.x - e.x, n = this.y - e.y; return t * t + n * n; } /** * Computes the Manhattan distance from the given vector to this instance. * * @param {Vector2} v - The vector to compute the Manhattan distance to. * @return {number} The Manhattan distance. */ manhattanDistanceTo(e) { return Math.abs(this.x - e.x) + Math.abs(this.y - e.y); } /** * Sets this vector to a vector with the same direction as this one, but * with the specified length. * * @param {number} length - The new length of this vector. * @return {Vector2} A reference to this vector. */ setLength(e) { return this.normalize().multiplyScalar(e); } /** * Linearly interpolates between the given vector and this instance, where * alpha is the percent distance along the line - alpha = 0 will be this * vector, and alpha = 1 will be the given one. * * @param {Vector2} v - The vector to interpolate towards. * @param {number} alpha - The interpolation factor, typically in the closed interval `[0, 1]`. * @return {Vector2} A reference to this vector. */ lerp(e, t) { return this.x += (e.x - this.x) * t, this.y += (e.y - this.y) * t, this; } /** * Linearly interpolates between the given vectors, where alpha is the percent * distance along the line - alpha = 0 will be first vector, and alpha = 1 will * be the second one. The result is stored in this instance. * * @param {Vector2} v1 - The first vector. * @param {Vector2} v2 - The second vector. * @param {number} alpha - The interpolation factor, typically in the closed interval `[0, 1]`. * @return {Vector2} A reference to this vector. */ lerpVectors(e, t, n) { return this.x = e.x + (t.x - e.x) * n, this.y = e.y + (t.y - e.y) * n, this; } /** * Returns `true` if this vector is equal with the given one. * * @param {Vector2} v - The vector to test for equality. * @return {boolean} Whether this vector is equal with the given one. */ equals(e) { return e.x === this.x && e.y === this.y; } /** * Sets this vector's x value to be `array[ offset ]` and y * value to be `array[ offset + 1 ]`. * * @param {Array<number>} array - An array holding the vector component values. * @param {number} [offset=0] - The offset into the array. * @return {Vector2} A reference to this vector. */ fromArray(e, t = 0) { return this.x = e[t], this.y = e[t + 1], this; } /** * Writes the components of this vector to the given array. If no array is provided, * the method returns a new instance. * * @param {Array<number>} [array=[]] - The target array holding the vector components. * @param {number} [offset=0] - Index of the first element in the array. * @return {Array<number>} The vector components. */ toArray(e = [], t = 0) { return e[t] = this.x, e[t + 1] = this.y, e; } /** * Sets the components of this vector from the given buffer attribute. * * @param {BufferAttribute} attribute - The buffer attribute holding vector data. * @param {number} index - The index into the attribute. * @return {Vector2} A reference to this vector. */ fromBufferAttribute(e, t) { return this.x = e.getX(t), this.y = e.getY(t), this; } /** * Rotates this vector around the given center by the given angle. * * @param {Vector2} center - The point around which to rotate. * @param {number} angle - The angle to rotate, in radians. * @return {Vector2} A reference to this vector. */ rotateAround(e, t) { const n = Math.cos(t), i = Math.sin(t), r = this.x - e.x, a = this.y - e.y; return this.x = r * n - a * i + e.x, this.y = r * i + a * n + e.y, this; } /** * Sets each component of this vector to a pseudo-random value between `0` and * `1`, excluding `1`. * * @return {Vector2} A reference to this vector. */ random() { return this.x = Math.random(), this.y = Math.random(), this; } *[Symbol.iterator]() { yield this.x, yield this.y; } } class On { /** * Constructs a new quaternion. * * @param {number} [x=0] - The x value of this quaternion. * @param {number} [y=0] - The y value of this quaternion. * @param {number} [z=0] - The z value of this quaternion. * @param {number} [w=1] - The w value of this quaternion. */ constructor(e = 0, t = 0, n = 0, i = 1) { this.isQuaternion = !0, this._x = e, this._y = t, this._z = n, this._w = i; } /** * Interpolates between two quaternions via SLERP. This implementation assumes the * quaternion data are managed in flat arrays. * * @param {Array<number>} dst - The destination array. * @param {number} dstOffset - An offset into the destination array. * @param {Array<number>} src0 - The source array of the first quaternion. * @param {number} srcOffset0 - An offset into the first source array. * @param {Array<number>} src1 - The source array of the second quaternion. * @param {number} srcOffset1 - An offset into the second source array. * @param {number} t - The interpolation factor in the range `[0,1]`. * @see {@link Quaternion#slerp} */ static slerpFlat(e, t, n, i, r, a, o) { let A = n[i + 0], c = n[i + 1], l = n[i + 2], u = n[i + 3]; const f = r[a + 0], h = r[a + 1], p = r[a + 2], g = r[a + 3]; if (o === 0) { e[t + 0] = A, e[t + 1] = c, e[t + 2] = l, e[t + 3] = u; return; } if (o === 1) { e[t + 0] = f, e[t + 1] = h, e[t + 2] = p, e[t + 3] = g; return; } if (u !== g || A !== f || c !== h || l !== p) { let P = 1 - o; const d = A * f + c * h + l * p + u * g, w = d >= 0 ? 1 : -1, M = 1 - d * d; if (M > Number.EPSILON) { const y = Math.sqrt(M), b = Math.atan2(y, d * w); P = Math.sin(P * b) / y, o = Math.sin(o * b) / y; } const E = o * w; if (A = A * P + f * E, c = c * P + h * E, l = l * P + p * E, u = u * P + g * E, P === 1 - o) { const y = 1 / Math.sqrt(A * A + c * c + l * l + u * u); A *= y, c *= y, l *= y, u *= y; } } e[t] = A, e[t + 1] = c, e[t + 2] = l, e[t + 3] = u; } /** * Multiplies two quaternions. This implementation assumes the quaternion data are managed * in flat arrays. * * @param {Array<number>} dst - The destination array. * @param {number} dstOffset - An offset into the destination array. * @param {Array<number>} src0 - The source array of the first quaternion. * @param {number} srcOffset0 - An offset into the first source array. * @param {Array<number>} src1 - The source array of the second quaternion. * @param {number} srcOffset1 - An offset into the second source array. * @return {Array<number>} The destination array. * @see {@link Quaternion#multiplyQuaternions}. */ static multiplyQuaternionsFlat(e, t, n, i, r, a) { const o = n[i], A = n[i + 1], c = n[i + 2], l = n[i + 3], u = r[a], f = r[a + 1], h = r[a + 2], p = r[a + 3]; return e[t] = o * p + l * u + A * h - c * f, e[t + 1] = A * p + l * f + c * u - o * h, e[t + 2] = c * p + l * h + o * f - A * u, e[t + 3] = l * p - o * u - A * f - c * h, e; } /** * The x value of this quaternion. * * @type {number} * @default 0 */ get x() { return this._x; } set x(e) { this._x = e, this._onChangeCallback(); } /** * The y value of this quaternion. * * @type {number} * @default 0 */ get y() { return this._y; } set y(e) { this._y = e, this._onChangeCallback(); } /** * The z value of this quaternion. * * @type {number} * @default 0 */ get z() { return this._z; } set z(e) { this._z = e, this._onChangeCallback(); } /** * The w value of this quaternion. * * @type {number} * @default 1 */ get w() { return this._w; } set w(e) { this._w = e, this._onChangeCallback(); } /** * Sets the quaternion components. * * @param {number} x - The x value of this quaternion. * @param {number} y - The y value of this quaternion. * @param {number} z - The z value of this quaternion. * @param {number} w - The w value of this quaternion. * @return {Quaternion} A reference to this quaternion. */ set(e, t, n, i) { return this._x = e, this._y = t, this._z = n, this._w = i, this._onChangeCallback(), this; } /** * Returns a new quaternion with copied values from this instance. * * @return {Quaternion} A clone of this instance. */ clone() { return new this.constructor(this._x, this._y, this._z, this._w); } /** * Copies the values of the given quaternion to this instance. * * @param {Quaternion} quaternion - The quaternion to copy. * @return {Quaternion} A reference to this quaternion. */ copy(e) { return this._x = e.x, this._y = e.y, this._z = e.z, this._w = e.w, this._onChangeCallback(), this; } /** * Sets this quaternion from the rotation specified by the given * Euler angles. * * @param {Euler} euler - The Euler angles. * @param {boolean} [update=true] - Whether the internal `onChange` callback should be executed or not. * @return {Quaternion} A reference to this quaternion. */ setFromEuler(e, t = !0) { const n = e._x, i = e._y, r = e._z, a = e._order, o = Math.cos, A = Math.sin, c = o(n / 2), l = o(i / 2), u = o(r / 2), f = A(n / 2), h = A(i / 2), p = A(r / 2); switch (a) { case "XYZ": this._x = f * l * u + c * h * p, this._y = c * h * u - f * l * p, this._z = c * l * p + f * h * u, this._w = c * l * u - f * h * p; break; case "YXZ": this._x = f * l * u + c * h * p, this._y = c * h * u - f * l * p, this._z = c * l * p - f * h * u, this._w = c * l * u + f * h * p; break; case "ZXY": this._x = f * l * u - c * h * p, this._y = c * h * u + f * l * p, this._z = c * l * p + f * h * u, this._w = c * l * u - f * h * p; break; case "ZYX": this._x = f * l * u - c * h * p, this._y = c * h * u + f * l * p, this._z = c * l * p - f * h * u, this._w = c * l * u + f * h * p; break; case "YZX": this._x = f * l * u + c * h * p, this._y = c * h * u + f * l * p, this._z = c * l * p - f * h * u, this._w = c * l * u - f * h * p; break; case "XZY": this._x = f * l * u - c * h * p, this._y = c * h * u - f * l * p, this._z = c * l * p + f * h * u, this._w = c * l * u + f * h * p; break; default: console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + a); } return t === !0 && this._onChangeCallback(), this; } /** * Sets this quaternion from the given axis and angle. * * @param {Vector3} axis - The normalized axis. * @param {number} angle - The angle in radians. * @return {Quaternion} A reference to this quaternion. */ setFromAxisAngle(e, t) { const n = t / 2, i = Math.sin(n); return this._x = e.x * i, this._y = e.y * i, this._z = e.z * i, this._w = Math.cos(n), this._onChangeCallback(), this; } /** * Sets this quaternion from the given rotation matrix. * * @param {Matrix4} m - A 4x4 matrix of which the upper 3x3 of matrix is a pure rotation matrix (i.e. unscaled). * @return {Quaternion} A reference to this quaternion. */ setFromRotationMatrix(e) { const t = e.elements, n = t[0], i = t[4], r = t[8], a = t[1], o = t[5], A = t[9], c = t[2], l = t[6], u = t[10], f = n + o + u; if (f > 0) { const h = 0.5 / Math.sqrt(f + 1); this._w = 0.25 / h, this._x = (l - A) * h, this._y = (r - c) * h, this._z = (a - i) * h; } else if (n > o && n > u) { const h = 2 * Math.sqrt(1 + n - o - u); this._w = (l - A) / h, this._x = 0.25 * h, this._y = (i + a) / h, this._z = (r + c) / h; } else if (o > u) { const h = 2 * Math.sqrt(1 + o - n - u); this._w = (r - c) / h, this._x = (i + a) / h, this._y = 0.25 * h, this._z = (A + l) / h; } else { const h = 2 * Math.sqrt(1 + u - n - o); this._w = (a - i) / h, this._x = (r + c) / h, this._y = (A + l) / h, this._z = 0.25 * h; } return this._onChangeCallback(), this; } /** * Sets this quaternion to the rotation required to rotate the direction vector * `vFrom` to the direction vector `vTo`. * * @param {Vector3} vFrom - The first (normalized) direction vector. * @param {Vector3} vTo - The second (normalized) direction vector. * @return {Quaternion} A reference to this quaternion. */ setFromUnitVectors(e, t) { let n = e.dot(t) + 1; return n < 1e-8 ? (n = 0, Math.abs(e.x) > Math.abs(e.z) ? (this._x = -e.y, this._y = e.x, this._z = 0, this._w = n) : (this._x = 0, this._y = -e.z, this._z = e.y, this._w = n)) : (this._x = e.y * t.z - e.z * t.y, this._y = e.z * t.x - e.x * t.z, this._z = e.x * t.y - e.y * t.x, this._w = n), this.normalize(); } /** * Returns the angle between this quaternion and the given one in radians. * * @param {Quaternion} q - The quaternion to compute the angle with. * @return {number} The angle in radians. */ angleTo(e) { return 2 * Math.acos(Math.abs(Ne(this.dot(e), -1, 1))); } /** * Rotates this quaternion by a given angular step to the given quaternion. * The method ensures that the final quaternion will not overshoot `q`. * * @param {Quaternion} q - The target quaternion. * @param {number} step - The angular step in radians. * @return {Quaternion} A reference to this quaternion. */ rotateTowards(e, t) { const n = this.angleTo(e); if (n === 0) return this; const i = Math.min(1, t / n); return this.slerp(e, i), this; } /** * Sets this quaternion to the identity quaternion; that is, to the * quaternion that represents "no rotation". * * @return {Quaternion} A reference to this quaternion. */ identity() { return this.set(0, 0, 0, 1); } /** * Inverts this quaternion via {@link Quaternion#conjugate}. The * quaternion is assumed to have unit length. * * @return {Quaternion} A reference to this quaternion. */ invert() { return this.conjugate(); } /** * Returns the rotational conjugate of this quaternion. The conjugate of a * quaternion represents the same rotation in the opposite direction about * the rotational axis. * * @return {Quaternion} A reference to this quaternion. */ conjugate() { return this._x *= -1, this._y *= -1, this._z *= -1, this._onChangeCallback(), this; } /** * Calculates the dot product of this quaternion and the given one. * * @param {Quaternion} v - The quaternion to compute the dot product with. * @return {number} The result of the dot product. */ dot(e) { return this._x * e._x + this._y * e._y + this._z * e._z + this._w * e._w; } /** * Computes the squared Euclidean length (straight-line length) of this quaternion, * considered as a 4 dimensional vector. This can be useful if you are comparing the * lengths of two quaternions, as this is a slightly more efficient calculation than * {@link Quaternion#length}. * * @return {number} The squared Euclidean length. */ lengthSq() { return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w; } /** * Computes the Euclidean length (straight-line length) of this quaternion, * considered as a 4 dimensional vector. * * @return {number} The Euclidean length. */ length() { return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w); } /** * Normalizes this quaternion - that is, calculated the quaternion that performs * the same rotation as this one, but has a length equal to `1`. * * @return {Quaternion} A reference to this quaternion. */ normalize() { let e = this.length(); return e === 0 ? (this._x = 0, this._y = 0, this._z = 0, this._w = 1) : (e = 1 / e, this._x = this._x * e, this._y = this._y * e, this._z = this._z * e, this._w = this._w * e), this._onChangeCallback(), this; } /** * Multiplies this quaternion by the given one. * * @param {Quaternion} q - The quaternion. * @return {Quaternion} A reference to this quaternion. */ multiply(e) { return this.multiplyQuaternions(this, e); } /** * Pre-multiplies this quaternion by the given one. * * @param {Quaternion} q - The quaternion. * @return {Quaternion} A reference to this quaternion. */ premultiply(e) { return this.multiplyQuaternions(e, this); } /** * Multiplies the given quaternions and stores the result in this instance. * * @param {Quaternion} a - The first quaternion. * @param {Quaternion} b - The second quaternion. * @return {Quaternion} A reference to this quaternion. */ multiplyQuaternions(e, t) { const n = e._x, i = e._y, r = e._z, a = e._w, o = t._x, A = t._y, c = t._z, l = t._w; return this._x = n * l + a * o + i * c - r * A, this._y = i * l + a * A + r * o - n * c, this._z = r * l + a * c + n * A - i * o, this._w = a * l - n * o - i * A - r * c, this._onChangeCallback(), this; } /** * Performs a spherical linear interpolation between quaternions. * * @param {Quaternion} qb - The target quaternion. * @param {number} t - The interpolation factor in the closed interval `[0, 1]`. * @return {Quaternion} A reference to this quaternion. */ slerp(e, t) { if (t === 0) return this; if (t === 1) return this.copy(e); const n = this._x, i = this._y, r = this._z, a = this._w; let o = a * e._w + n * e._x + i * e._y + r * e._z; if (o < 0 ? (this._w = -e._w, this._x = -e._x, this._y = -e._y, this._z = -e._z, o = -o) : this.copy(e), o >= 1) return this._w = a, this._x = n, this._y = i, this._z = r, this; const A = 1 - o * o; if (A <= Number.EPSILON) { const h = 1 - t; return this._w = h * a + t * this._w, this._x = h * n + t * this._x, this._y = h * i + t * this._y, this._z = h * r + t * this._z, this.normalize(), this; } const c = Math.sqrt(A), l = Math.atan2(c, o), u = Math.sin((1 - t) * l) / c, f = Math.sin(t * l) / c; return this._w = a * u + this._w * f, this._x = n * u + this._x * f, this._y = i * u + this._y * f, this._z = r * u + this._z * f, this._onChangeCallback(), this; } /** * Performs a spherical linear interpolation between the given quaternions * and stores the result in this quaternion. * * @param {Quaternion} qa - The source quaternion. * @param {Quaternion} qb - The target quaternion. * @param {number} t - The interpolation factor in the closed interval `[0, 1]`. * @return {Quaternion} A reference to this quaternion. */ slerpQuaternions(e, t, n) { return this.copy(e).slerp(t, n); } /** * Sets this quaternion to a uniformly random, normalized quaternion. * * @return {Quaternion} A reference to this quaternion. */ random() { const e = 2 * Math.PI * Math.random(), t = 2 * Math.PI * Math.random(), n = Math.random(), i = Math.sqrt(1 - n), r = Math.sqrt(n); return this.set( i * Math.sin(e), i * Math.cos(e), r * Math.sin(t), r * Math.cos(t) ); } /** * Returns `true` if this quaternion is equal with the given one. * * @param {Quaternion} quaternion - The quaternion to test for equality. * @return {boolean} Whether this quaternion is equal with the given one. */ equals(e) { return e._x === this._x && e._y === this._y && e._z === this._z && e._w === this._w; } /** * Sets this quaternion's components from the given array. * * @param {Array<number>} array - An array holding the quaternion component values. * @param {number} [offset=0] - The offset into the array. * @return {Quaternion} A reference to this quaternion. */ fromArray(e, t = 0) { return this._x = e[t], this._y = e[t + 1], this._z = e[t + 2], this._w = e[t + 3], this._onChangeCallback(), this; } /** * Writes the components of this quaternion to the given array. If no array is provided, * the method returns a new instance. * * @