viral-viewer-2 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -82,22 +82,30 @@ function workerFunction() {
82
82
  case 1:
83
83
  console.log('receive structural');
84
84
  progressStructuralGeometries(event.data.materials, event.data.data, (buffer, colorString, opacity) => {
85
+ const geometry = new BufferGeometry();
86
+ geometry.setAttribute("position", new BufferAttribute(buffer, 3));
87
+ geometry.computeVertexNormals();
85
88
  self.postMessage({
86
89
  type: 1,
87
90
  buffer: buffer,
88
91
  materialColorString: colorString,
89
92
  materialOpacity: opacity,
93
+ geometry: geometry
90
94
  });
91
95
  });
92
96
  break;
93
97
  case 2:
94
98
  console.log('receive none structural');
95
99
  progressNoneStructuralGeometries(event.data.materials, event.data.data, (buffer, colorString, opacity) => {
100
+ const geometry = new BufferGeometry();
101
+ geometry.setAttribute("position", new BufferAttribute(buffer, 3));
102
+ geometry.computeVertexNormals();
96
103
  self.postMessage({
97
104
  type: 1,
98
105
  buffer: buffer,
99
106
  materialColorString: colorString,
100
107
  materialOpacity: opacity,
108
+ geometry: geometry
101
109
  });
102
110
  });
103
111
  break;
@@ -105,28 +113,889 @@ function workerFunction() {
105
113
  break;
106
114
  }
107
115
  }, false);
108
- class Matrix4 {
116
+ //#region Threejs Types
117
+ const StaticDrawUsage = 35044;
118
+ class EventDispatcher {
109
119
  constructor() {
110
- this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
120
+ this._listeners = {};
121
+ }
122
+ addEventListener(type, listener) {
123
+ if (this._listeners[type] === undefined)
124
+ this._listeners[type] = [];
125
+ const listeners = this._listeners[type];
126
+ if (listeners.indexOf(listener) === -1) {
127
+ listeners.push(listener);
128
+ }
129
+ }
130
+ hasEventListener(type, listener) {
131
+ if (this._listeners[type] === undefined)
132
+ return false;
133
+ const listeners = this._listeners[type];
134
+ return listeners !== undefined && listeners.indexOf(listener) !== -1;
135
+ }
136
+ removeEventListener(type, listener) {
137
+ if (this._listeners[type] === undefined)
138
+ return;
139
+ const listeners = this._listeners[type];
140
+ if (listeners !== undefined) {
141
+ const index = listeners.indexOf(listener);
142
+ if (index !== -1) {
143
+ listeners.splice(index, 1);
144
+ }
145
+ }
146
+ }
147
+ dispatchEvent(event) {
148
+ if (this._listeners[event.type] === undefined)
149
+ return;
150
+ const listeners = this._listeners[event.type];
151
+ if (listeners !== undefined) {
152
+ event.target = this;
153
+ // Make a copy, in case listeners are removed while iterating.
154
+ const array = listeners.slice(0);
155
+ for (let i = 0, l = array.length; i < l; i++) {
156
+ array[i].call(this, event);
157
+ }
158
+ event.target = undefined;
159
+ }
160
+ }
161
+ }
162
+ const _lut = [];
163
+ for (let i = 0; i < 256; i++) {
164
+ _lut[i] = (i < 16 ? '0' : '') + (i).toString(16);
165
+ }
166
+ const DEG2RAD = Math.PI / 180;
167
+ const RAD2DEG = 180 / Math.PI;
168
+ const generateUUID = () => {
169
+ const d0 = Math.random() * 0xffffffff | 0;
170
+ const d1 = Math.random() * 0xffffffff | 0;
171
+ const d2 = Math.random() * 0xffffffff | 0;
172
+ const d3 = Math.random() * 0xffffffff | 0;
173
+ const uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' +
174
+ _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' +
175
+ _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] +
176
+ _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff];
177
+ // .toUpperCase() here flattens concatenated strings to save heap memory space.
178
+ return uuid.toUpperCase();
179
+ };
180
+ function clamp(value, min, max) {
181
+ return Math.max(min, Math.min(max, value));
182
+ }
183
+ // Compute euclidean modulo of n % m
184
+ // https://en.wikipedia.org/wiki/Modulo_operation
185
+ function euclideanModulo(n, m) {
186
+ return ((n % m) + m) % m;
187
+ }
188
+ // https://en.wikipedia.org/wiki/Linear_interpolation
189
+ function lerp(x, y, t) {
190
+ return (1 - t) * x + t * y;
191
+ }
192
+ function isPowerOfTwo(value) {
193
+ return (value & (value - 1)) === 0 && value !== 0;
194
+ }
195
+ function floorPowerOfTwo(value) {
196
+ return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
197
+ }
198
+ //#region Color
199
+ const _colorKeywords = {
200
+ 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
201
+ 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
202
+ 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
203
+ 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
204
+ 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
205
+ 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
206
+ 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
207
+ 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
208
+ 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
209
+ 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
210
+ 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
211
+ 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
212
+ 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
213
+ 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
214
+ 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
215
+ 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
216
+ 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
217
+ 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
218
+ 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
219
+ 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
220
+ 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
221
+ 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
222
+ 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
223
+ 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32
224
+ };
225
+ const _hslA = { h: 0, s: 0, l: 0 };
226
+ const _hslB = { h: 0, s: 0, l: 0 };
227
+ function hue2rgb(p, q, t) {
228
+ if (t < 0)
229
+ t += 1;
230
+ if (t > 1)
231
+ t -= 1;
232
+ if (t < 1 / 6)
233
+ return p + (q - p) * 6 * t;
234
+ if (t < 1 / 2)
235
+ return q;
236
+ if (t < 2 / 3)
237
+ return p + (q - p) * 6 * (2 / 3 - t);
238
+ return p;
239
+ }
240
+ function SRGBToLinear(c) {
241
+ return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
242
+ }
243
+ function LinearToSRGB(c) {
244
+ return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
245
+ }
246
+ class Color {
247
+ constructor(r, g, b) {
248
+ this.r = 0;
249
+ this.g = 0;
250
+ this.b = 0;
251
+ if (g === undefined && b === undefined) {
252
+ // r is THREE.Color, hex, or string
253
+ return this.set(r);
254
+ }
255
+ return this.setRGB(r, g, b);
256
+ }
257
+ set(value) {
258
+ if (value && value.isColor) {
259
+ this.copy(value);
260
+ }
261
+ else if (typeof value === 'number') {
262
+ this.setHex(value);
263
+ }
264
+ else if (typeof value === 'string') {
265
+ this.setStyle(value);
266
+ }
267
+ return this;
268
+ }
269
+ setScalar(scalar) {
270
+ this.r = scalar;
271
+ this.g = scalar;
272
+ this.b = scalar;
273
+ return this;
274
+ }
275
+ setHex(hex) {
276
+ hex = Math.floor(hex);
277
+ this.r = ((hex >> 16) & 255) / 255;
278
+ this.g = ((hex >> 8) & 255) / 255;
279
+ this.b = (hex & 255) / 255;
280
+ return this;
281
+ }
282
+ setRGB(r, g, b) {
283
+ this.r = r;
284
+ this.g = g;
285
+ this.b = b;
286
+ return this;
287
+ }
288
+ setHSL(h, s, l) {
289
+ // h, s, l ranges are in 0.0 - 1.0
290
+ h = euclideanModulo(h, 1);
291
+ s = clamp(s, 0, 1);
292
+ l = clamp(l, 0, 1);
293
+ if (s === 0) {
294
+ this.r = this.g = this.b = l;
295
+ }
296
+ else {
297
+ const p = l <= 0.5 ? l * (1 + s) : l + s - (l * s);
298
+ const q = 2 * l - p;
299
+ this.r = hue2rgb(q, p, h + 1 / 3);
300
+ this.g = hue2rgb(q, p, h);
301
+ this.b = hue2rgb(q, p, h - 1 / 3);
302
+ }
303
+ return this;
304
+ }
305
+ setStyle(style) {
306
+ function handleAlpha(string) {
307
+ if (string === undefined)
308
+ return;
309
+ if (parseFloat(string) < 1) {
310
+ console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
311
+ }
312
+ }
313
+ let m;
314
+ if ((m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style))) {
315
+ // rgb / hsl
316
+ let color;
317
+ const name = m[1];
318
+ const components = m[2];
319
+ switch (name) {
320
+ case 'rgb':
321
+ case 'rgba':
322
+ if ((color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
323
+ // rgb(255,0,0) rgba(255,0,0,0.5)
324
+ this.r = Math.min(255, parseInt(color[1], 10)) / 255;
325
+ this.g = Math.min(255, parseInt(color[2], 10)) / 255;
326
+ this.b = Math.min(255, parseInt(color[3], 10)) / 255;
327
+ handleAlpha(color[4]);
328
+ return this;
329
+ }
330
+ if ((color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
331
+ // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
332
+ this.r = Math.min(100, parseInt(color[1], 10)) / 100;
333
+ this.g = Math.min(100, parseInt(color[2], 10)) / 100;
334
+ this.b = Math.min(100, parseInt(color[3], 10)) / 100;
335
+ handleAlpha(color[4]);
336
+ return this;
337
+ }
338
+ break;
339
+ case 'hsl':
340
+ case 'hsla':
341
+ if ((color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
342
+ // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
343
+ const h = parseFloat(color[1]) / 360;
344
+ const s = parseInt(color[2], 10) / 100;
345
+ const l = parseInt(color[3], 10) / 100;
346
+ handleAlpha(color[4]);
347
+ return this.setHSL(h, s, l);
348
+ }
349
+ break;
350
+ }
351
+ }
352
+ else if ((m = /^\#([A-Fa-f\d]+)$/.exec(style))) {
353
+ // hex color
354
+ const hex = m[1];
355
+ const size = hex.length;
356
+ if (size === 3) {
357
+ // #ff0
358
+ this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
359
+ this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
360
+ this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
361
+ return this;
362
+ }
363
+ else if (size === 6) {
364
+ // #ff0000
365
+ this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
366
+ this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
367
+ this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
368
+ return this;
369
+ }
370
+ }
371
+ if (style && style.length > 0) {
372
+ return this.setColorName(style);
373
+ }
374
+ return this;
375
+ }
376
+ setColorName(style) {
377
+ // color keywords
378
+ let key = style.toLowerCase();
379
+ const hex = _colorKeywords[key];
380
+ if (hex !== undefined) {
381
+ // red
382
+ this.setHex(hex);
383
+ }
384
+ else {
385
+ // unknown color
386
+ console.warn('THREE.Color: Unknown color ' + style);
387
+ }
388
+ return this;
389
+ }
390
+ clone() {
391
+ return new Color(this.r, this.g, this.b);
392
+ }
393
+ copy(color) {
394
+ this.r = color.r;
395
+ this.g = color.g;
396
+ this.b = color.b;
397
+ return this;
398
+ }
399
+ copyGammaToLinear(color, gammaFactor = 2.0) {
400
+ this.r = Math.pow(color.r, gammaFactor);
401
+ this.g = Math.pow(color.g, gammaFactor);
402
+ this.b = Math.pow(color.b, gammaFactor);
403
+ return this;
404
+ }
405
+ copyLinearToGamma(color, gammaFactor = 2.0) {
406
+ const safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
407
+ this.r = Math.pow(color.r, safeInverse);
408
+ this.g = Math.pow(color.g, safeInverse);
409
+ this.b = Math.pow(color.b, safeInverse);
410
+ return this;
411
+ }
412
+ convertGammaToLinear(gammaFactor) {
413
+ this.copyGammaToLinear(this, gammaFactor);
414
+ return this;
415
+ }
416
+ convertLinearToGamma(gammaFactor) {
417
+ this.copyLinearToGamma(this, gammaFactor);
418
+ return this;
419
+ }
420
+ copySRGBToLinear(color) {
421
+ this.r = SRGBToLinear(color.r);
422
+ this.g = SRGBToLinear(color.g);
423
+ this.b = SRGBToLinear(color.b);
424
+ return this;
425
+ }
426
+ copyLinearToSRGB(color) {
427
+ this.r = LinearToSRGB(color.r);
428
+ this.g = LinearToSRGB(color.g);
429
+ this.b = LinearToSRGB(color.b);
430
+ return this;
431
+ }
432
+ convertSRGBToLinear() {
433
+ this.copySRGBToLinear(this);
434
+ return this;
435
+ }
436
+ convertLinearToSRGB() {
437
+ this.copyLinearToSRGB(this);
438
+ return this;
439
+ }
440
+ getHex() {
441
+ return (this.r * 255) << 16 ^ (this.g * 255) << 8 ^ (this.b * 255) << 0;
442
+ }
443
+ getHexString() {
444
+ return ('000000' + this.getHex().toString(16)).slice(-6);
445
+ }
446
+ getHSL(target) {
447
+ const r = this.r, g = this.g, b = this.b;
448
+ const max = Math.max(r, g, b);
449
+ const min = Math.min(r, g, b);
450
+ let hue = 0, saturation = 0;
451
+ const lightness = (min + max) / 2.0;
452
+ if (min === max) {
453
+ hue = 0;
454
+ saturation = 0;
455
+ }
456
+ else {
457
+ const delta = max - min;
458
+ saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
459
+ switch (max) {
460
+ case r:
461
+ hue = (g - b) / delta + (g < b ? 6 : 0);
462
+ break;
463
+ case g:
464
+ hue = (b - r) / delta + 2;
465
+ break;
466
+ case b:
467
+ hue = (r - g) / delta + 4;
468
+ break;
469
+ }
470
+ hue /= 6;
471
+ }
472
+ target.h = hue;
473
+ target.s = saturation;
474
+ target.l = lightness;
475
+ return target;
476
+ }
477
+ getStyle() {
478
+ return 'rgb(' + (this.r * 255) + ',' + (this.g * 255) + ',' + (this.b * 255) + ')';
479
+ }
480
+ offsetHSL(h, s, l) {
481
+ this.getHSL(_hslA);
482
+ _hslA.h += h;
483
+ _hslA.s += s;
484
+ _hslA.l += l;
485
+ this.setHSL(_hslA.h, _hslA.s, _hslA.l);
486
+ return this;
487
+ }
488
+ add(color) {
489
+ this.r += color.r;
490
+ this.g += color.g;
491
+ this.b += color.b;
492
+ return this;
493
+ }
494
+ addColors(color1, color2) {
495
+ this.r = color1.r + color2.r;
496
+ this.g = color1.g + color2.g;
497
+ this.b = color1.b + color2.b;
498
+ return this;
499
+ }
500
+ addScalar(s) {
501
+ this.r += s;
502
+ this.g += s;
503
+ this.b += s;
504
+ return this;
505
+ }
506
+ sub(color) {
507
+ this.r = Math.max(0, this.r - color.r);
508
+ this.g = Math.max(0, this.g - color.g);
509
+ this.b = Math.max(0, this.b - color.b);
510
+ return this;
511
+ }
512
+ multiply(color) {
513
+ this.r *= color.r;
514
+ this.g *= color.g;
515
+ this.b *= color.b;
516
+ return this;
517
+ }
518
+ multiplyScalar(s) {
519
+ this.r *= s;
520
+ this.g *= s;
521
+ this.b *= s;
522
+ return this;
523
+ }
524
+ lerp(color, alpha) {
525
+ this.r += (color.r - this.r) * alpha;
526
+ this.g += (color.g - this.g) * alpha;
527
+ this.b += (color.b - this.b) * alpha;
528
+ return this;
529
+ }
530
+ lerpColors(color1, color2, alpha) {
531
+ this.r = color1.r + (color2.r - color1.r) * alpha;
532
+ this.g = color1.g + (color2.g - color1.g) * alpha;
533
+ this.b = color1.b + (color2.b - color1.b) * alpha;
534
+ return this;
535
+ }
536
+ lerpHSL(color, alpha) {
537
+ this.getHSL(_hslA);
538
+ color.getHSL(_hslB);
539
+ const h = lerp(_hslA.h, _hslB.h, alpha);
540
+ const s = lerp(_hslA.s, _hslB.s, alpha);
541
+ const l = lerp(_hslA.l, _hslB.l, alpha);
542
+ this.setHSL(h, s, l);
543
+ return this;
544
+ }
545
+ equals(c) {
546
+ return c.r === this.r && c.g === this.g && c.b === this.b;
111
547
  }
112
548
  fromArray(array, offset = 0) {
113
- for (let i = 0; i < 16; i++) {
114
- this.elements[i] = array[i + offset];
549
+ this.r = array[offset];
550
+ this.g = array[offset + 1];
551
+ this.b = array[offset + 2];
552
+ return this;
553
+ }
554
+ toArray(array = [], offset = 0) {
555
+ array[offset] = this.r;
556
+ array[offset + 1] = this.g;
557
+ array[offset + 2] = this.b;
558
+ return array;
559
+ }
560
+ fromBufferAttribute(attribute, index) {
561
+ this.r = attribute.getX(index);
562
+ this.g = attribute.getY(index);
563
+ this.b = attribute.getZ(index);
564
+ if (attribute.normalized === true) {
565
+ // assuming Uint8Array
566
+ this.r /= 255;
567
+ this.g /= 255;
568
+ this.b /= 255;
569
+ }
570
+ return this;
571
+ }
572
+ toJSON() {
573
+ return this.getHex();
574
+ }
575
+ }
576
+ //#endregion
577
+ //#region Base Unit
578
+ class Vector2 {
579
+ constructor(x = 0, y = 0) {
580
+ this.x = x;
581
+ this.y = y;
582
+ }
583
+ get width() {
584
+ return this.x;
585
+ }
586
+ set width(value) {
587
+ this.x = value;
588
+ }
589
+ get height() {
590
+ return this.y;
591
+ }
592
+ set height(value) {
593
+ this.y = value;
594
+ }
595
+ set(x, y) {
596
+ this.x = x;
597
+ this.y = y;
598
+ return this;
599
+ }
600
+ setScalar(scalar) {
601
+ this.x = scalar;
602
+ this.y = scalar;
603
+ return this;
604
+ }
605
+ setX(x) {
606
+ this.x = x;
607
+ return this;
608
+ }
609
+ setY(y) {
610
+ this.y = y;
611
+ return this;
612
+ }
613
+ setComponent(index, value) {
614
+ switch (index) {
615
+ case 0:
616
+ this.x = value;
617
+ break;
618
+ case 1:
619
+ this.y = value;
620
+ break;
621
+ default:
622
+ throw new Error('index is out of range: ' + index);
623
+ }
624
+ return this;
625
+ }
626
+ getComponent(index) {
627
+ switch (index) {
628
+ case 0:
629
+ return this.x;
630
+ case 1:
631
+ return this.y;
632
+ default:
633
+ throw new Error('index is out of range: ' + index);
634
+ }
635
+ }
636
+ clone() {
637
+ return new this.constructor(this.x, this.y);
638
+ }
639
+ copy(v) {
640
+ this.x = v.x;
641
+ this.y = v.y;
642
+ return this;
643
+ }
644
+ add(v, w) {
645
+ if (w !== undefined) {
646
+ console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
647
+ return this.addVectors(v, w);
648
+ }
649
+ this.x += v.x;
650
+ this.y += v.y;
651
+ return this;
652
+ }
653
+ addScalar(s) {
654
+ this.x += s;
655
+ this.y += s;
656
+ return this;
657
+ }
658
+ addVectors(a, b) {
659
+ this.x = a.x + b.x;
660
+ this.y = a.y + b.y;
661
+ return this;
662
+ }
663
+ addScaledVector(v, s) {
664
+ this.x += v.x * s;
665
+ this.y += v.y * s;
666
+ return this;
667
+ }
668
+ sub(v, w) {
669
+ if (w !== undefined) {
670
+ console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
671
+ return this.subVectors(v, w);
672
+ }
673
+ this.x -= v.x;
674
+ this.y -= v.y;
675
+ return this;
676
+ }
677
+ subScalar(s) {
678
+ this.x -= s;
679
+ this.y -= s;
680
+ return this;
681
+ }
682
+ subVectors(a, b) {
683
+ this.x = a.x - b.x;
684
+ this.y = a.y - b.y;
685
+ return this;
686
+ }
687
+ multiply(v) {
688
+ this.x *= v.x;
689
+ this.y *= v.y;
690
+ return this;
691
+ }
692
+ multiplyScalar(scalar) {
693
+ this.x *= scalar;
694
+ this.y *= scalar;
695
+ return this;
696
+ }
697
+ divide(v) {
698
+ this.x /= v.x;
699
+ this.y /= v.y;
700
+ return this;
701
+ }
702
+ divideScalar(scalar) {
703
+ return this.multiplyScalar(1 / scalar);
704
+ }
705
+ applyMatrix3(m) {
706
+ const x = this.x, y = this.y;
707
+ const e = m.elements;
708
+ this.x = e[0] * x + e[3] * y + e[6];
709
+ this.y = e[1] * x + e[4] * y + e[7];
710
+ return this;
711
+ }
712
+ min(v) {
713
+ this.x = Math.min(this.x, v.x);
714
+ this.y = Math.min(this.y, v.y);
715
+ return this;
716
+ }
717
+ max(v) {
718
+ this.x = Math.max(this.x, v.x);
719
+ this.y = Math.max(this.y, v.y);
720
+ return this;
721
+ }
722
+ clamp(min, max) {
723
+ // assumes min < max, componentwise
724
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
725
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
726
+ return this;
727
+ }
728
+ clampScalar(minVal, maxVal) {
729
+ this.x = Math.max(minVal, Math.min(maxVal, this.x));
730
+ this.y = Math.max(minVal, Math.min(maxVal, this.y));
731
+ return this;
732
+ }
733
+ clampLength(min, max) {
734
+ const length = this.length();
735
+ return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
736
+ }
737
+ floor() {
738
+ this.x = Math.floor(this.x);
739
+ this.y = Math.floor(this.y);
740
+ return this;
741
+ }
742
+ ceil() {
743
+ this.x = Math.ceil(this.x);
744
+ this.y = Math.ceil(this.y);
745
+ return this;
746
+ }
747
+ round() {
748
+ this.x = Math.round(this.x);
749
+ this.y = Math.round(this.y);
750
+ return this;
751
+ }
752
+ roundToZero() {
753
+ this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
754
+ this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
755
+ return this;
756
+ }
757
+ negate() {
758
+ this.x = -this.x;
759
+ this.y = -this.y;
760
+ return this;
761
+ }
762
+ dot(v) {
763
+ return this.x * v.x + this.y * v.y;
764
+ }
765
+ cross(v) {
766
+ return this.x * v.y - this.y * v.x;
767
+ }
768
+ lengthSq() {
769
+ return this.x * this.x + this.y * this.y;
770
+ }
771
+ length() {
772
+ return Math.sqrt(this.x * this.x + this.y * this.y);
773
+ }
774
+ manhattanLength() {
775
+ return Math.abs(this.x) + Math.abs(this.y);
776
+ }
777
+ normalize() {
778
+ return this.divideScalar(this.length() || 1);
779
+ }
780
+ angle() {
781
+ // computes the angle in radians with respect to the positive x-axis
782
+ const angle = Math.atan2(-this.y, -this.x) + Math.PI;
783
+ return angle;
784
+ }
785
+ distanceTo(v) {
786
+ return Math.sqrt(this.distanceToSquared(v));
787
+ }
788
+ distanceToSquared(v) {
789
+ const dx = this.x - v.x, dy = this.y - v.y;
790
+ return dx * dx + dy * dy;
791
+ }
792
+ manhattanDistanceTo(v) {
793
+ return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
794
+ }
795
+ setLength(length) {
796
+ return this.normalize().multiplyScalar(length);
797
+ }
798
+ lerp(v, alpha) {
799
+ this.x += (v.x - this.x) * alpha;
800
+ this.y += (v.y - this.y) * alpha;
801
+ return this;
802
+ }
803
+ lerpVectors(v1, v2, alpha) {
804
+ this.x = v1.x + (v2.x - v1.x) * alpha;
805
+ this.y = v1.y + (v2.y - v1.y) * alpha;
806
+ return this;
807
+ }
808
+ equals(v) {
809
+ return v.x === this.x && v.y === this.y;
810
+ }
811
+ fromArray(array, offset = 0) {
812
+ this.x = array[offset];
813
+ this.y = array[offset + 1];
814
+ return this;
815
+ }
816
+ toArray(array = [], offset = 0) {
817
+ array[offset] = this.x;
818
+ array[offset + 1] = this.y;
819
+ return array;
820
+ }
821
+ fromBufferAttribute(attribute, index, offset) {
822
+ if (offset !== undefined) {
823
+ console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
115
824
  }
825
+ this.x = attribute.getX(index);
826
+ this.y = attribute.getY(index);
827
+ return this;
828
+ }
829
+ rotateAround(center, angle) {
830
+ const c = Math.cos(angle), s = Math.sin(angle);
831
+ const x = this.x - center.x;
832
+ const y = this.y - center.y;
833
+ this.x = x * c - y * s + center.x;
834
+ this.y = x * s + y * c + center.y;
116
835
  return this;
117
836
  }
837
+ random() {
838
+ this.x = Math.random();
839
+ this.y = Math.random();
840
+ return this;
841
+ }
842
+ *[Symbol.iterator]() {
843
+ yield this.x;
844
+ yield this.y;
845
+ }
118
846
  }
119
847
  class Vector3 {
120
- constructor(x, y, z) {
121
- this.x = 0;
122
- this.y = 0;
123
- this.z = 0;
848
+ constructor(x = 0, y = 0, z = 0) {
849
+ this.x = x;
850
+ this.y = y;
851
+ this.z = z;
852
+ }
853
+ set(x, y, z) {
854
+ if (z === undefined)
855
+ z = this.z; // sprite.scale.set(x, y)
856
+ this.x = x;
857
+ this.y = y;
858
+ this.z = z;
859
+ return this;
860
+ }
861
+ setScalar(scalar) {
862
+ this.x = scalar;
863
+ this.y = scalar;
864
+ this.z = scalar;
865
+ return this;
866
+ }
867
+ setX(x) {
124
868
  this.x = x;
869
+ return this;
870
+ }
871
+ setY(y) {
125
872
  this.y = y;
873
+ return this;
874
+ }
875
+ setZ(z) {
126
876
  this.z = z;
877
+ return this;
878
+ }
879
+ setComponent(index, value) {
880
+ switch (index) {
881
+ case 0:
882
+ this.x = value;
883
+ break;
884
+ case 1:
885
+ this.y = value;
886
+ break;
887
+ case 2:
888
+ this.z = value;
889
+ break;
890
+ default:
891
+ throw new Error('index is out of range: ' + index);
892
+ }
893
+ return this;
894
+ }
895
+ getComponent(index) {
896
+ switch (index) {
897
+ case 0:
898
+ return this.x;
899
+ case 1:
900
+ return this.y;
901
+ case 2:
902
+ return this.z;
903
+ default:
904
+ throw new Error('index is out of range: ' + index);
905
+ }
906
+ }
907
+ clone() {
908
+ return new Vector3(this.x, this.y, this.z);
909
+ }
910
+ copy(v) {
911
+ this.x = v.x;
912
+ this.y = v.y;
913
+ this.z = v.z;
914
+ return this;
915
+ }
916
+ add(v, w) {
917
+ if (w !== undefined) {
918
+ console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
919
+ return this.addVectors(v, w);
920
+ }
921
+ this.x += v.x;
922
+ this.y += v.y;
923
+ this.z += v.z;
924
+ return this;
925
+ }
926
+ addScalar(s) {
927
+ this.x += s;
928
+ this.y += s;
929
+ this.z += s;
930
+ return this;
931
+ }
932
+ addVectors(a, b) {
933
+ this.x = a.x + b.x;
934
+ this.y = a.y + b.y;
935
+ this.z = a.z + b.z;
936
+ return this;
937
+ }
938
+ addScaledVector(v, s) {
939
+ this.x += v.x * s;
940
+ this.y += v.y * s;
941
+ this.z += v.z * s;
942
+ return this;
943
+ }
944
+ sub(v, w) {
945
+ if (w !== undefined) {
946
+ console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
947
+ return this.subVectors(v, w);
948
+ }
949
+ this.x -= v.x;
950
+ this.y -= v.y;
951
+ this.z -= v.z;
952
+ return this;
953
+ }
954
+ subScalar(s) {
955
+ this.x -= s;
956
+ this.y -= s;
957
+ this.z -= s;
958
+ return this;
959
+ }
960
+ subVectors(a, b) {
961
+ this.x = a.x - b.x;
962
+ this.y = a.y - b.y;
963
+ this.z = a.z - b.z;
964
+ return this;
965
+ }
966
+ multiply(v, w) {
967
+ if (w !== undefined) {
968
+ console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
969
+ return this.multiplyVectors(v, w);
970
+ }
971
+ this.x *= v.x;
972
+ this.y *= v.y;
973
+ this.z *= v.z;
974
+ return this;
975
+ }
976
+ multiplyScalar(scalar) {
977
+ this.x *= scalar;
978
+ this.y *= scalar;
979
+ this.z *= scalar;
980
+ return this;
981
+ }
982
+ multiplyVectors(a, b) {
983
+ this.x = a.x * b.x;
984
+ this.y = a.y * b.y;
985
+ this.z = a.z * b.z;
986
+ return this;
987
+ }
988
+ applyMatrix3(m) {
989
+ const x = this.x, y = this.y;
990
+ const e = m.elements;
991
+ this.x = e[0] * x + e[3] * y + e[6];
992
+ this.y = e[1] * x + e[4] * y + e[7];
993
+ return this;
127
994
  }
128
995
  applyMatrix4(m) {
129
- const x = this.x, y = this.y, z = this.z;
996
+ const x = this.x;
997
+ const y = this.y;
998
+ const z = this.z;
130
999
  const e = m.elements;
131
1000
  const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
132
1001
  this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
@@ -134,7 +1003,1746 @@ function workerFunction() {
134
1003
  this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
135
1004
  return this;
136
1005
  }
1006
+ setFromMatrix3Column(m, index) {
1007
+ return this.fromArray(m.elements, index * 3);
1008
+ }
1009
+ fromArray(array, offset = 0) {
1010
+ this.x = array[offset];
1011
+ this.y = array[offset + 1];
1012
+ this.z = array[offset + 2];
1013
+ return this;
1014
+ }
1015
+ toArray(array = [], offset = 0) {
1016
+ array[offset] = this.x;
1017
+ array[offset + 1] = this.y;
1018
+ array[offset + 2] = this.z;
1019
+ return array;
1020
+ }
1021
+ fromBufferAttribute(attribute, index, offset) {
1022
+ if (offset !== undefined) {
1023
+ console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
1024
+ }
1025
+ this.x = attribute.getX(index);
1026
+ this.y = attribute.getY(index);
1027
+ this.z = attribute.getZ(index);
1028
+ return this;
1029
+ }
1030
+ applyNormalMatrix(m) {
1031
+ this.applyMatrix3(m);
1032
+ this.normalize();
1033
+ return this;
1034
+ }
1035
+ normalize() {
1036
+ const length = this.length() || 1;
1037
+ return this.divideScalar(length);
1038
+ }
1039
+ length() {
1040
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1041
+ }
1042
+ divideScalar(scalar) {
1043
+ return this.multiplyScalar(1 / scalar);
1044
+ }
1045
+ transformDirection(m) {
1046
+ const x = this.x, y = this.y, z = this.z;
1047
+ const e = m.elements;
1048
+ this.x = e[0] * x + e[4] * y + e[8] * z;
1049
+ this.y = e[1] * x + e[5] * y + e[9] * z;
1050
+ this.z = e[2] * x + e[6] * y + e[10] * z;
1051
+ return this.normalize();
1052
+ }
1053
+ min(v) {
1054
+ this.x = Math.min(this.x, v.x);
1055
+ this.y = Math.min(this.y, v.y);
1056
+ this.z = Math.min(this.z, v.z);
1057
+ return this;
1058
+ }
1059
+ max(v) {
1060
+ this.x = Math.max(this.x, v.x);
1061
+ this.y = Math.max(this.y, v.y);
1062
+ this.z = Math.max(this.z, v.z);
1063
+ return this;
1064
+ }
1065
+ dot(v) {
1066
+ return this.x * v.x + this.y * v.y + this.z * v.z;
1067
+ }
1068
+ distanceToSquared(v) {
1069
+ const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
1070
+ return dx * dx + dy * dy + dz * dz;
1071
+ }
1072
+ distanceTo(v) {
1073
+ return Math.sqrt(this.distanceToSquared(v));
1074
+ }
1075
+ lengthSq() {
1076
+ return this.x * this.x + this.y * this.y + this.z * this.z;
1077
+ }
1078
+ equals(v) {
1079
+ return ((v.x === this.x) && (v.y === this.y) && (v.z === this.z));
1080
+ }
1081
+ negate() {
1082
+ this.x = -this.x;
1083
+ this.y = -this.y;
1084
+ this.z = -this.z;
1085
+ return this;
1086
+ }
1087
+ cross(v, w) {
1088
+ if (w !== undefined) {
1089
+ console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
1090
+ return this.crossVectors(v, w);
1091
+ }
1092
+ return this.crossVectors(this, v);
1093
+ }
1094
+ crossVectors(a, b) {
1095
+ const ax = a.x, ay = a.y, az = a.z;
1096
+ const bx = b.x, by = b.y, bz = b.z;
1097
+ this.x = ay * bz - az * by;
1098
+ this.y = az * bx - ax * bz;
1099
+ this.z = ax * by - ay * bx;
1100
+ return this;
1101
+ }
1102
+ clamp(min, max) {
1103
+ // assumes min < max, componentwise
1104
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
1105
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
1106
+ this.z = Math.max(min.z, Math.min(max.z, this.z));
1107
+ return this;
1108
+ }
1109
+ }
1110
+ class Vector4 {
1111
+ constructor(x = 0, y = 0, z = 0, w = 1) {
1112
+ this.x = x;
1113
+ this.y = y;
1114
+ this.z = z;
1115
+ this.w = w;
1116
+ }
1117
+ get width() {
1118
+ return this.z;
1119
+ }
1120
+ set width(value) {
1121
+ this.z = value;
1122
+ }
1123
+ get height() {
1124
+ return this.w;
1125
+ }
1126
+ set height(value) {
1127
+ this.w = value;
1128
+ }
1129
+ set(x, y, z, w) {
1130
+ this.x = x;
1131
+ this.y = y;
1132
+ this.z = z;
1133
+ this.w = w;
1134
+ return this;
1135
+ }
1136
+ setScalar(scalar) {
1137
+ this.x = scalar;
1138
+ this.y = scalar;
1139
+ this.z = scalar;
1140
+ this.w = scalar;
1141
+ return this;
1142
+ }
1143
+ setX(x) {
1144
+ this.x = x;
1145
+ return this;
1146
+ }
1147
+ setY(y) {
1148
+ this.y = y;
1149
+ return this;
1150
+ }
1151
+ setZ(z) {
1152
+ this.z = z;
1153
+ return this;
1154
+ }
1155
+ setW(w) {
1156
+ this.w = w;
1157
+ return this;
1158
+ }
1159
+ setComponent(index, value) {
1160
+ switch (index) {
1161
+ case 0:
1162
+ this.x = value;
1163
+ break;
1164
+ case 1:
1165
+ this.y = value;
1166
+ break;
1167
+ case 2:
1168
+ this.z = value;
1169
+ break;
1170
+ case 3:
1171
+ this.w = value;
1172
+ break;
1173
+ default:
1174
+ throw new Error('index is out of range: ' + index);
1175
+ }
1176
+ return this;
1177
+ }
1178
+ getComponent(index) {
1179
+ switch (index) {
1180
+ case 0:
1181
+ return this.x;
1182
+ case 1:
1183
+ return this.y;
1184
+ case 2:
1185
+ return this.z;
1186
+ case 3:
1187
+ return this.w;
1188
+ default:
1189
+ throw new Error('index is out of range: ' + index);
1190
+ }
1191
+ }
1192
+ clone() {
1193
+ return new this.constructor(this.x, this.y, this.z, this.w);
1194
+ }
1195
+ copy(v) {
1196
+ this.x = v.x;
1197
+ this.y = v.y;
1198
+ this.z = v.z;
1199
+ this.w = v.w !== undefined ? v.w : 1;
1200
+ return this;
1201
+ }
1202
+ add(v, w) {
1203
+ if (w !== undefined) {
1204
+ console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
1205
+ return this.addVectors(v, w);
1206
+ }
1207
+ this.x += v.x;
1208
+ this.y += v.y;
1209
+ this.z += v.z;
1210
+ this.w += v.w;
1211
+ return this;
1212
+ }
1213
+ addScalar(s) {
1214
+ this.x += s;
1215
+ this.y += s;
1216
+ this.z += s;
1217
+ this.w += s;
1218
+ return this;
1219
+ }
1220
+ addVectors(a, b) {
1221
+ this.x = a.x + b.x;
1222
+ this.y = a.y + b.y;
1223
+ this.z = a.z + b.z;
1224
+ this.w = a.w + b.w;
1225
+ return this;
1226
+ }
1227
+ addScaledVector(v, s) {
1228
+ this.x += v.x * s;
1229
+ this.y += v.y * s;
1230
+ this.z += v.z * s;
1231
+ this.w += v.w * s;
1232
+ return this;
1233
+ }
1234
+ sub(v, w) {
1235
+ if (w !== undefined) {
1236
+ console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
1237
+ return this.subVectors(v, w);
1238
+ }
1239
+ this.x -= v.x;
1240
+ this.y -= v.y;
1241
+ this.z -= v.z;
1242
+ this.w -= v.w;
1243
+ return this;
1244
+ }
1245
+ subScalar(s) {
1246
+ this.x -= s;
1247
+ this.y -= s;
1248
+ this.z -= s;
1249
+ this.w -= s;
1250
+ return this;
1251
+ }
1252
+ subVectors(a, b) {
1253
+ this.x = a.x - b.x;
1254
+ this.y = a.y - b.y;
1255
+ this.z = a.z - b.z;
1256
+ this.w = a.w - b.w;
1257
+ return this;
1258
+ }
1259
+ multiply(v) {
1260
+ this.x *= v.x;
1261
+ this.y *= v.y;
1262
+ this.z *= v.z;
1263
+ this.w *= v.w;
1264
+ return this;
1265
+ }
1266
+ multiplyScalar(scalar) {
1267
+ this.x *= scalar;
1268
+ this.y *= scalar;
1269
+ this.z *= scalar;
1270
+ this.w *= scalar;
1271
+ return this;
1272
+ }
1273
+ applyMatrix4(m) {
1274
+ const x = this.x, y = this.y, z = this.z, w = this.w;
1275
+ const e = m.elements;
1276
+ this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
1277
+ this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
1278
+ this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
1279
+ this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
1280
+ return this;
1281
+ }
1282
+ divideScalar(scalar) {
1283
+ return this.multiplyScalar(1 / scalar);
1284
+ }
1285
+ setAxisAngleFromQuaternion(q) {
1286
+ this.w = 2 * Math.acos(q.w);
1287
+ const s = Math.sqrt(1 - q.w * q.w);
1288
+ if (s < 0.0001) {
1289
+ this.x = 1;
1290
+ this.y = 0;
1291
+ this.z = 0;
1292
+ }
1293
+ else {
1294
+ this.x = q.x / s;
1295
+ this.y = q.y / s;
1296
+ this.z = q.z / s;
1297
+ }
1298
+ return this;
1299
+ }
1300
+ setAxisAngleFromRotationMatrix(m) {
1301
+ const epsilon = 0.01;
1302
+ const epsilon2 = 0.1;
1303
+ const te = m.elements;
1304
+ const m11 = te[0], m12 = te[4], m13 = te[8];
1305
+ const m21 = te[1], m22 = te[5], m23 = te[9];
1306
+ const m31 = te[2], m32 = te[6], m33 = te[10];
1307
+ if (Math.abs(m12 - m21) < epsilon &&
1308
+ Math.abs(m13 - m31) < epsilon &&
1309
+ Math.abs(m23 - m32) < epsilon) {
1310
+ if (Math.abs(m12 + m21) < epsilon2 &&
1311
+ Math.abs(m13 + m31) < epsilon2 &&
1312
+ Math.abs(m23 + m32) < epsilon2 &&
1313
+ Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
1314
+ this.set(1, 0, 0, 0);
1315
+ return this;
1316
+ }
1317
+ this.set(0, 0.707106781, 0.707106781, Math.PI);
1318
+ return this;
1319
+ }
1320
+ let s = Math.sqrt((m32 - m23) * (m32 - m23) +
1321
+ (m13 - m31) * (m13 - m31) +
1322
+ (m21 - m12) * (m21 - m12));
1323
+ if (Math.abs(s) < 0.001)
1324
+ s = 1;
1325
+ this.x = (m32 - m23) / s;
1326
+ this.y = (m13 - m31) / s;
1327
+ this.z = (m21 - m12) / s;
1328
+ this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
1329
+ return this;
1330
+ }
1331
+ min(v) {
1332
+ this.x = Math.min(this.x, v.x);
1333
+ this.y = Math.min(this.y, v.y);
1334
+ this.z = Math.min(this.z, v.z);
1335
+ this.w = Math.min(this.w, v.w);
1336
+ return this;
1337
+ }
1338
+ max(v) {
1339
+ this.x = Math.max(this.x, v.x);
1340
+ this.y = Math.max(this.y, v.y);
1341
+ this.z = Math.max(this.z, v.z);
1342
+ this.w = Math.max(this.w, v.w);
1343
+ return this;
1344
+ }
1345
+ clamp(min, max) {
1346
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
1347
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
1348
+ this.z = Math.max(min.z, Math.min(max.z, this.z));
1349
+ this.w = Math.max(min.w, Math.min(max.w, this.w));
1350
+ return this;
1351
+ }
1352
+ clampScalar(minVal, maxVal) {
1353
+ this.x = Math.max(minVal, Math.min(maxVal, this.x));
1354
+ this.y = Math.max(minVal, Math.min(maxVal, this.y));
1355
+ this.z = Math.max(minVal, Math.min(maxVal, this.z));
1356
+ this.w = Math.max(minVal, Math.min(maxVal, this.w));
1357
+ return this;
1358
+ }
1359
+ clampLength(min, max) {
1360
+ const length = this.length();
1361
+ return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1362
+ }
1363
+ floor() {
1364
+ this.x = Math.floor(this.x);
1365
+ this.y = Math.floor(this.y);
1366
+ this.z = Math.floor(this.z);
1367
+ this.w = Math.floor(this.w);
1368
+ return this;
1369
+ }
1370
+ ceil() {
1371
+ this.x = Math.ceil(this.x);
1372
+ this.y = Math.ceil(this.y);
1373
+ this.z = Math.ceil(this.z);
1374
+ this.w = Math.ceil(this.w);
1375
+ return this;
1376
+ }
1377
+ round() {
1378
+ this.x = Math.round(this.x);
1379
+ this.y = Math.round(this.y);
1380
+ this.z = Math.round(this.z);
1381
+ this.w = Math.round(this.w);
1382
+ return this;
1383
+ }
1384
+ roundToZero() {
1385
+ this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
1386
+ this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
1387
+ this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
1388
+ this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
1389
+ return this;
1390
+ }
1391
+ negate() {
1392
+ this.x = -this.x;
1393
+ this.y = -this.y;
1394
+ this.z = -this.z;
1395
+ this.w = -this.w;
1396
+ return this;
1397
+ }
1398
+ dot(v) {
1399
+ return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
1400
+ }
1401
+ lengthSq() {
1402
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
1403
+ }
1404
+ length() {
1405
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
1406
+ }
1407
+ manhattanLength() {
1408
+ return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
1409
+ }
1410
+ normalize() {
1411
+ return this.divideScalar(this.length() || 1);
1412
+ }
1413
+ setLength(length) {
1414
+ return this.normalize().multiplyScalar(length);
1415
+ }
1416
+ lerp(v, alpha) {
1417
+ this.x += (v.x - this.x) * alpha;
1418
+ this.y += (v.y - this.y) * alpha;
1419
+ this.z += (v.z - this.z) * alpha;
1420
+ this.w += (v.w - this.w) * alpha;
1421
+ return this;
1422
+ }
1423
+ lerpVectors(v1, v2, alpha) {
1424
+ this.x = v1.x + (v2.x - v1.x) * alpha;
1425
+ this.y = v1.y + (v2.y - v1.y) * alpha;
1426
+ this.z = v1.z + (v2.z - v1.z) * alpha;
1427
+ this.w = v1.w + (v2.w - v1.w) * alpha;
1428
+ return this;
1429
+ }
1430
+ equals(v) {
1431
+ return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
1432
+ }
1433
+ fromArray(array, offset = 0) {
1434
+ this.x = array[offset];
1435
+ this.y = array[offset + 1];
1436
+ this.z = array[offset + 2];
1437
+ this.w = array[offset + 3];
1438
+ return this;
1439
+ }
1440
+ toArray(array = [], offset = 0) {
1441
+ array[offset] = this.x;
1442
+ array[offset + 1] = this.y;
1443
+ array[offset + 2] = this.z;
1444
+ array[offset + 3] = this.w;
1445
+ return array;
1446
+ }
1447
+ fromBufferAttribute(attribute, index, offset) {
1448
+ if (offset !== undefined) {
1449
+ console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
1450
+ }
1451
+ this.x = attribute.getX(index);
1452
+ this.y = attribute.getY(index);
1453
+ this.z = attribute.getZ(index);
1454
+ this.w = attribute.getW(index);
1455
+ return this;
1456
+ }
1457
+ random() {
1458
+ this.x = Math.random();
1459
+ this.y = Math.random();
1460
+ this.z = Math.random();
1461
+ this.w = Math.random();
1462
+ return this;
1463
+ }
1464
+ *[Symbol.iterator]() {
1465
+ yield this.x;
1466
+ yield this.y;
1467
+ yield this.z;
1468
+ yield this.w;
1469
+ }
1470
+ }
1471
+ class Matrix3 {
1472
+ constructor() {
1473
+ this.elements = [
1474
+ 1, 0, 0,
1475
+ 0, 1, 0,
1476
+ 0, 0, 1
1477
+ ];
1478
+ if (arguments.length > 0) {
1479
+ console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
1480
+ }
1481
+ }
1482
+ set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
1483
+ const te = this.elements;
1484
+ te[0] = n11;
1485
+ te[1] = n21;
1486
+ te[2] = n31;
1487
+ te[3] = n12;
1488
+ te[4] = n22;
1489
+ te[5] = n32;
1490
+ te[6] = n13;
1491
+ te[7] = n23;
1492
+ te[8] = n33;
1493
+ return this;
1494
+ }
1495
+ identity() {
1496
+ this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
1497
+ return this;
1498
+ }
1499
+ copy(m) {
1500
+ const te = this.elements;
1501
+ const me = m.elements;
1502
+ te[0] = me[0];
1503
+ te[1] = me[1];
1504
+ te[2] = me[2];
1505
+ te[3] = me[3];
1506
+ te[4] = me[4];
1507
+ te[5] = me[5];
1508
+ te[6] = me[6];
1509
+ te[7] = me[7];
1510
+ te[8] = me[8];
1511
+ return this;
1512
+ }
1513
+ extractBasis(xAxis, yAxis, zAxis) {
1514
+ xAxis.setFromMatrix3Column(this, 0);
1515
+ yAxis.setFromMatrix3Column(this, 1);
1516
+ zAxis.setFromMatrix3Column(this, 2);
1517
+ return this;
1518
+ }
1519
+ setFromMatrix4(m) {
1520
+ const me = m.elements;
1521
+ this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
1522
+ return this;
1523
+ }
1524
+ multiply(m) {
1525
+ return this.multiplyMatrices(this, m);
1526
+ }
1527
+ premultiply(m) {
1528
+ return this.multiplyMatrices(m, this);
1529
+ }
1530
+ multiplyMatrices(a, b) {
1531
+ const ae = a.elements;
1532
+ const be = b.elements;
1533
+ const te = this.elements;
1534
+ const a11 = ae[0], a12 = ae[3], a13 = ae[6];
1535
+ const a21 = ae[1], a22 = ae[4], a23 = ae[7];
1536
+ const a31 = ae[2], a32 = ae[5], a33 = ae[8];
1537
+ const b11 = be[0], b12 = be[3], b13 = be[6];
1538
+ const b21 = be[1], b22 = be[4], b23 = be[7];
1539
+ const b31 = be[2], b32 = be[5], b33 = be[8];
1540
+ te[0] = a11 * b11 + a12 * b21 + a13 * b31;
1541
+ te[3] = a11 * b12 + a12 * b22 + a13 * b32;
1542
+ te[6] = a11 * b13 + a12 * b23 + a13 * b33;
1543
+ te[1] = a21 * b11 + a22 * b21 + a23 * b31;
1544
+ te[4] = a21 * b12 + a22 * b22 + a23 * b32;
1545
+ te[7] = a21 * b13 + a22 * b23 + a23 * b33;
1546
+ te[2] = a31 * b11 + a32 * b21 + a33 * b31;
1547
+ te[5] = a31 * b12 + a32 * b22 + a33 * b32;
1548
+ te[8] = a31 * b13 + a32 * b23 + a33 * b33;
1549
+ return this;
1550
+ }
1551
+ multiplyScalar(s) {
1552
+ const te = this.elements;
1553
+ te[0] *= s;
1554
+ te[3] *= s;
1555
+ te[6] *= s;
1556
+ te[1] *= s;
1557
+ te[4] *= s;
1558
+ te[7] *= s;
1559
+ te[2] *= s;
1560
+ te[5] *= s;
1561
+ te[8] *= s;
1562
+ return this;
1563
+ }
1564
+ determinant() {
1565
+ const te = this.elements;
1566
+ const a = te[0], b = te[1], c = te[2], d = te[3], e = te[4], f = te[5], g = te[6], h = te[7], i = te[8];
1567
+ return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
1568
+ }
1569
+ invert() {
1570
+ const te = this.elements;
1571
+ const n11 = te[0], n21 = te[1], n31 = te[2], n12 = te[3], n22 = te[4], n32 = te[5], n13 = te[6], n23 = te[7], n33 = te[8], t11 = n33 * n22 - n32 * n23, t12 = n32 * n13 - n33 * n12, t13 = n23 * n12 - n22 * n13, det = n11 * t11 + n21 * t12 + n31 * t13;
1572
+ if (det === 0)
1573
+ return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
1574
+ const detInv = 1 / det;
1575
+ te[0] = t11 * detInv;
1576
+ te[1] = (n31 * n23 - n33 * n21) * detInv;
1577
+ te[2] = (n32 * n21 - n31 * n22) * detInv;
1578
+ te[3] = t12 * detInv;
1579
+ te[4] = (n33 * n11 - n31 * n13) * detInv;
1580
+ te[5] = (n31 * n12 - n32 * n11) * detInv;
1581
+ te[6] = t13 * detInv;
1582
+ te[7] = (n21 * n13 - n23 * n11) * detInv;
1583
+ te[8] = (n22 * n11 - n21 * n12) * detInv;
1584
+ return this;
1585
+ }
1586
+ transpose() {
1587
+ let tmp;
1588
+ const m = this.elements;
1589
+ tmp = m[1];
1590
+ m[1] = m[3];
1591
+ m[3] = tmp;
1592
+ tmp = m[2];
1593
+ m[2] = m[6];
1594
+ m[6] = tmp;
1595
+ tmp = m[5];
1596
+ m[5] = m[7];
1597
+ m[7] = tmp;
1598
+ return this;
1599
+ }
1600
+ getNormalMatrix(matrix4) {
1601
+ return this.setFromMatrix4(matrix4).invert().transpose();
1602
+ }
1603
+ transposeIntoArray(r) {
1604
+ const m = this.elements;
1605
+ r[0] = m[0];
1606
+ r[1] = m[3];
1607
+ r[2] = m[6];
1608
+ r[3] = m[1];
1609
+ r[4] = m[4];
1610
+ r[5] = m[7];
1611
+ r[6] = m[2];
1612
+ r[7] = m[5];
1613
+ r[8] = m[8];
1614
+ return this;
1615
+ }
1616
+ setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
1617
+ const c = Math.cos(rotation);
1618
+ const s = Math.sin(rotation);
1619
+ this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
1620
+ return this;
1621
+ }
1622
+ scale(sx, sy) {
1623
+ const te = this.elements;
1624
+ te[0] *= sx;
1625
+ te[3] *= sx;
1626
+ te[6] *= sx;
1627
+ te[1] *= sy;
1628
+ te[4] *= sy;
1629
+ te[7] *= sy;
1630
+ return this;
1631
+ }
1632
+ rotate(theta) {
1633
+ const c = Math.cos(theta);
1634
+ const s = Math.sin(theta);
1635
+ const te = this.elements;
1636
+ const a11 = te[0], a12 = te[3], a13 = te[6];
1637
+ const a21 = te[1], a22 = te[4], a23 = te[7];
1638
+ te[0] = c * a11 + s * a21;
1639
+ te[3] = c * a12 + s * a22;
1640
+ te[6] = c * a13 + s * a23;
1641
+ te[1] = -s * a11 + c * a21;
1642
+ te[4] = -s * a12 + c * a22;
1643
+ te[7] = -s * a13 + c * a23;
1644
+ return this;
1645
+ }
1646
+ translate(tx, ty) {
1647
+ const te = this.elements;
1648
+ te[0] += tx * te[2];
1649
+ te[3] += tx * te[5];
1650
+ te[6] += tx * te[8];
1651
+ te[1] += ty * te[2];
1652
+ te[4] += ty * te[5];
1653
+ te[7] += ty * te[8];
1654
+ return this;
1655
+ }
1656
+ equals(matrix) {
1657
+ const te = this.elements;
1658
+ const me = matrix.elements;
1659
+ for (let i = 0; i < 9; i++) {
1660
+ if (te[i] !== me[i])
1661
+ return false;
1662
+ }
1663
+ return true;
1664
+ }
1665
+ fromArray(array, offset = 0) {
1666
+ for (let i = 0; i < 9; i++) {
1667
+ this.elements[i] = array[i + offset];
1668
+ }
1669
+ return this;
1670
+ }
1671
+ toArray(array = [], offset = 0) {
1672
+ const te = this.elements;
1673
+ array[offset] = te[0];
1674
+ array[offset + 1] = te[1];
1675
+ array[offset + 2] = te[2];
1676
+ array[offset + 3] = te[3];
1677
+ array[offset + 4] = te[4];
1678
+ array[offset + 5] = te[5];
1679
+ array[offset + 6] = te[6];
1680
+ array[offset + 7] = te[7];
1681
+ array[offset + 8] = te[8];
1682
+ return array;
1683
+ }
1684
+ clone() {
1685
+ return new Matrix3().fromArray(this.elements);
1686
+ }
1687
+ }
1688
+ class Matrix4 {
1689
+ constructor() {
1690
+ this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
1691
+ }
1692
+ fromArray(array, offset = 0) {
1693
+ for (let i = 0; i < 16; i++) {
1694
+ this.elements[i] = array[i + offset];
1695
+ }
1696
+ return this;
1697
+ }
1698
+ getMaxScaleOnAxis() {
1699
+ const te = this.elements;
1700
+ const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
1701
+ const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
1702
+ const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
1703
+ return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
1704
+ }
1705
+ }
1706
+ class Box3 {
1707
+ constructor(min = new Vector3(+Infinity, +Infinity, +Infinity), max = new Vector3(-Infinity, -Infinity, -Infinity)) {
1708
+ this.min = min;
1709
+ this.max = max;
1710
+ }
1711
+ set(min, max) {
1712
+ this.min.copy(min);
1713
+ this.max.copy(max);
1714
+ return this;
1715
+ }
1716
+ setFromArray(array) {
1717
+ let minX = +Infinity;
1718
+ let minY = +Infinity;
1719
+ let minZ = +Infinity;
1720
+ let maxX = -Infinity;
1721
+ let maxY = -Infinity;
1722
+ let maxZ = -Infinity;
1723
+ for (let i = 0, l = array.length; i < l; i += 3) {
1724
+ const x = array[i];
1725
+ const y = array[i + 1];
1726
+ const z = array[i + 2];
1727
+ if (x < minX)
1728
+ minX = x;
1729
+ if (y < minY)
1730
+ minY = y;
1731
+ if (z < minZ)
1732
+ minZ = z;
1733
+ if (x > maxX)
1734
+ maxX = x;
1735
+ if (y > maxY)
1736
+ maxY = y;
1737
+ if (z > maxZ)
1738
+ maxZ = z;
1739
+ }
1740
+ this.min.set(minX, minY, minZ);
1741
+ this.max.set(maxX, maxY, maxZ);
1742
+ return this;
1743
+ }
1744
+ setFromBufferAttribute(attribute) {
1745
+ let minX = +Infinity;
1746
+ let minY = +Infinity;
1747
+ let minZ = +Infinity;
1748
+ let maxX = -Infinity;
1749
+ let maxY = -Infinity;
1750
+ let maxZ = -Infinity;
1751
+ for (let i = 0, l = attribute.count; i < l; i++) {
1752
+ const x = attribute.getX(i);
1753
+ const y = attribute.getY(i);
1754
+ const z = attribute.getZ(i);
1755
+ if (x < minX)
1756
+ minX = x;
1757
+ if (y < minY)
1758
+ minY = y;
1759
+ if (z < minZ)
1760
+ minZ = z;
1761
+ if (x > maxX)
1762
+ maxX = x;
1763
+ if (y > maxY)
1764
+ maxY = y;
1765
+ if (z > maxZ)
1766
+ maxZ = z;
1767
+ }
1768
+ this.min.set(minX, minY, minZ);
1769
+ this.max.set(maxX, maxY, maxZ);
1770
+ return this;
1771
+ }
1772
+ setFromPoints(points) {
1773
+ this.makeEmpty();
1774
+ for (let i = 0, il = points.length; i < il; i++) {
1775
+ this.expandByPoint(points[i]);
1776
+ }
1777
+ return this;
1778
+ }
1779
+ setFromCenterAndSize(center, size) {
1780
+ const halfSize = new Vector3().copy(size).multiplyScalar(0.5);
1781
+ this.min.copy(center).sub(halfSize);
1782
+ this.max.copy(center).add(halfSize);
1783
+ return this;
1784
+ }
1785
+ setFromObject(object) {
1786
+ this.makeEmpty();
1787
+ return this.expandByObject(object);
1788
+ }
1789
+ clone() {
1790
+ return new Box3().copy(this);
1791
+ }
1792
+ copy(box) {
1793
+ this.min.copy(box.min);
1794
+ this.max.copy(box.max);
1795
+ return this;
1796
+ }
1797
+ makeEmpty() {
1798
+ this.min.x = this.min.y = this.min.z = +Infinity;
1799
+ this.max.x = this.max.y = this.max.z = -Infinity;
1800
+ return this;
1801
+ }
1802
+ isEmpty() {
1803
+ return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
1804
+ }
1805
+ getCenter(target) {
1806
+ return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
1807
+ }
1808
+ getSize(target) {
1809
+ return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
1810
+ }
1811
+ expandByPoint(point) {
1812
+ this.min.min(point);
1813
+ this.max.max(point);
1814
+ return this;
1815
+ }
1816
+ expandByVector(vector) {
1817
+ this.min.sub(vector);
1818
+ this.max.add(vector);
1819
+ return this;
1820
+ }
1821
+ expandByScalar(scalar) {
1822
+ this.min.addScalar(-scalar);
1823
+ this.max.addScalar(scalar);
1824
+ return this;
1825
+ }
1826
+ expandByObject(object) {
1827
+ object.updateWorldMatrix(false, false);
1828
+ const geometry = object.geometry;
1829
+ if (geometry !== undefined) {
1830
+ if (geometry.boundingBox === null) {
1831
+ geometry.computeBoundingBox();
1832
+ }
1833
+ const box = new Box3().copy(geometry.boundingBox);
1834
+ box.applyMatrix4(object.matrixWorld);
1835
+ this.union(box);
1836
+ }
1837
+ const children = object.children;
1838
+ for (let i = 0, l = children.length; i < l; i++) {
1839
+ this.expandByObject(children[i]);
1840
+ }
1841
+ return this;
1842
+ }
1843
+ containsPoint(point) {
1844
+ return point.x < this.min.x || point.x > this.max.x ||
1845
+ point.y < this.min.y || point.y > this.max.y ||
1846
+ point.z < this.min.z || point.z > this.max.z ? false : true;
1847
+ }
1848
+ containsBox(box) {
1849
+ return this.min.x <= box.min.x && box.max.x <= this.max.x &&
1850
+ this.min.y <= box.min.y && box.max.y <= this.max.y &&
1851
+ this.min.z <= box.min.z && box.max.z <= this.max.z;
1852
+ }
1853
+ getParameter(point, target) {
1854
+ return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
1855
+ }
1856
+ intersectsBox(box) {
1857
+ return box.max.x < this.min.x || box.min.x > this.max.x ||
1858
+ box.max.y < this.min.y || box.min.y > this.max.y ||
1859
+ box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
1860
+ }
1861
+ intersectsSphere(sphere) {
1862
+ this.clampPoint(sphere.center, _vector$b);
1863
+ return _vector$b.distanceToSquared(sphere.center) <= (sphere.radius * sphere.radius);
1864
+ }
1865
+ intersectsPlane(plane) {
1866
+ let min, max;
1867
+ if (plane.normal.x > 0) {
1868
+ min = plane.normal.x * this.min.x;
1869
+ max = plane.normal.x * this.max.x;
1870
+ }
1871
+ else {
1872
+ min = plane.normal.x * this.max.x;
1873
+ max = plane.normal.x * this.min.x;
1874
+ }
1875
+ if (plane.normal.y > 0) {
1876
+ min += plane.normal.y * this.min.y;
1877
+ max += plane.normal.y * this.max.y;
1878
+ }
1879
+ else {
1880
+ min += plane.normal.y * this.max.y;
1881
+ max += plane.normal.y * this.min.y;
1882
+ }
1883
+ if (plane.normal.z > 0) {
1884
+ min += plane.normal.z * this.min.z;
1885
+ max += plane.normal.z * this.max.z;
1886
+ }
1887
+ else {
1888
+ min += plane.normal.z * this.max.z;
1889
+ max += plane.normal.z * this.min.z;
1890
+ }
1891
+ return (min <= -plane.constant && max >= -plane.constant);
1892
+ }
1893
+ intersectsTriangle(triangle) {
1894
+ if (this.isEmpty()) {
1895
+ return false;
1896
+ }
1897
+ this.getCenter(_center);
1898
+ _extents.subVectors(this.max, _center);
1899
+ _v0$2.subVectors(triangle.a, _center);
1900
+ _v1$7.subVectors(triangle.b, _center);
1901
+ _v2$3.subVectors(triangle.c, _center);
1902
+ _f0.subVectors(_v1$7, _v0$2);
1903
+ _f1.subVectors(_v2$3, _v1$7);
1904
+ _f2.subVectors(_v0$2, _v2$3);
1905
+ let axes = [
1906
+ 0, -_f0.z, _f0.y,
1907
+ 0, -_f1.z, _f1.y,
1908
+ 0, -_f2.z, _f2.y,
1909
+ _f0.z, 0, -_f0.x,
1910
+ _f1.z, 0, -_f1.x,
1911
+ _f2.z, 0, -_f2.x,
1912
+ -_f0.y, _f0.x, 0,
1913
+ -_f1.y, _f1.x, 0,
1914
+ -_f2.y, _f2.x, 0
1915
+ ];
1916
+ if (!satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents)) {
1917
+ return false;
1918
+ }
1919
+ axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
1920
+ if (!satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents)) {
1921
+ return false;
1922
+ }
1923
+ _triangleNormal.crossVectors(_f0, _f1);
1924
+ axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
1925
+ return satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents);
1926
+ }
1927
+ clampPoint(point, target) {
1928
+ return target.copy(point).clamp(this.min, this.max);
1929
+ }
1930
+ distanceToPoint(point) {
1931
+ const clampedPoint = _vector$b.copy(point).clamp(this.min, this.max);
1932
+ return clampedPoint.sub(point).length();
1933
+ }
1934
+ getBoundingSphere(target) {
1935
+ this.getCenter(target.center);
1936
+ target.radius = this.getSize(_vector$b).length() * 0.5;
1937
+ return target;
1938
+ }
1939
+ intersect(box) {
1940
+ this.min.max(box.min);
1941
+ this.max.min(box.max);
1942
+ if (this.isEmpty()) {
1943
+ this.makeEmpty();
1944
+ }
1945
+ return this;
1946
+ }
1947
+ union(box) {
1948
+ this.min.min(box.min);
1949
+ this.max.max(box.max);
1950
+ return this;
1951
+ }
1952
+ applyMatrix4(matrix) {
1953
+ if (this.isEmpty()) {
1954
+ return this;
1955
+ }
1956
+ _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
1957
+ _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
1958
+ _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
1959
+ _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
1960
+ _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
1961
+ _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
1962
+ _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
1963
+ _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
1964
+ this.setFromPoints(_points);
1965
+ return this;
1966
+ }
1967
+ translate(offset) {
1968
+ this.min.add(offset);
1969
+ this.max.add(offset);
1970
+ return this;
1971
+ }
1972
+ equals(box) {
1973
+ return box.min.equals(this.min) && box.max.equals(this.max);
1974
+ }
1975
+ }
1976
+ const _points = [
1977
+ /*@__PURE__*/ new Vector3(),
1978
+ /*@__PURE__*/ new Vector3(),
1979
+ /*@__PURE__*/ new Vector3(),
1980
+ /*@__PURE__*/ new Vector3(),
1981
+ /*@__PURE__*/ new Vector3(),
1982
+ /*@__PURE__*/ new Vector3(),
1983
+ /*@__PURE__*/ new Vector3(),
1984
+ /*@__PURE__*/ new Vector3()
1985
+ ];
1986
+ const _vector$b = /*@__PURE__*/ new Vector3();
1987
+ const _box$3 = /*@__PURE__*/ new Box3();
1988
+ // triangle centered vertices
1989
+ const _v0$2 = /*@__PURE__*/ new Vector3();
1990
+ const _v1$7 = /*@__PURE__*/ new Vector3();
1991
+ const _v2$3 = /*@__PURE__*/ new Vector3();
1992
+ // triangle edge vectors
1993
+ const _f0 = /*@__PURE__*/ new Vector3();
1994
+ const _f1 = /*@__PURE__*/ new Vector3();
1995
+ const _f2 = /*@__PURE__*/ new Vector3();
1996
+ const _center = /*@__PURE__*/ new Vector3();
1997
+ const _extents = /*@__PURE__*/ new Vector3();
1998
+ const _triangleNormal = /*@__PURE__*/ new Vector3();
1999
+ const _testAxis = /*@__PURE__*/ new Vector3();
2000
+ function satForAxes(axes, v0, v1, v2, extents) {
2001
+ for (let i = 0, j = axes.length - 3; i <= j; i += 3) {
2002
+ const _testAxis = new Vector3().fromArray(axes, i);
2003
+ // Project the AABB onto the separating axis
2004
+ const r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z);
2005
+ // Project all 3 vertices of the triangle onto the separating axis
2006
+ const p0 = v0.dot(_testAxis);
2007
+ const p1 = v1.dot(_testAxis);
2008
+ const p2 = v2.dot(_testAxis);
2009
+ // Actual test, basically see if either of the most extreme of the triangle points intersects r
2010
+ if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
2011
+ // Points of the projected triangle are outside the projected half-length of the AABB
2012
+ // The axis is separating, and we can exit
2013
+ return false;
2014
+ }
2015
+ }
2016
+ return true;
2017
+ }
2018
+ const _box$2 = /*@__PURE__*/ new Box3();
2019
+ const _v1$6 = /*@__PURE__*/ new Vector3();
2020
+ const _toFarthestPoint = /*@__PURE__*/ new Vector3();
2021
+ const _toPoint = /*@__PURE__*/ new Vector3();
2022
+ class Sphere {
2023
+ constructor(center = new Vector3(), radius = -1) {
2024
+ this.center = center;
2025
+ this.radius = radius;
2026
+ }
2027
+ set(center, radius) {
2028
+ this.center.copy(center);
2029
+ this.radius = radius;
2030
+ return this;
2031
+ }
2032
+ setFromPoints(points, optionalCenter) {
2033
+ const center = this.center;
2034
+ if (optionalCenter !== undefined) {
2035
+ center.copy(optionalCenter);
2036
+ }
2037
+ else {
2038
+ const box = new Box3();
2039
+ box.setFromPoints(points);
2040
+ box.getCenter(center);
2041
+ }
2042
+ let maxRadiusSq = 0;
2043
+ for (let i = 0, il = points.length; i < il; i++) {
2044
+ maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
2045
+ }
2046
+ this.radius = Math.sqrt(maxRadiusSq);
2047
+ return this;
2048
+ }
2049
+ copy(sphere) {
2050
+ this.center.copy(sphere.center);
2051
+ this.radius = sphere.radius;
2052
+ return this;
2053
+ }
2054
+ isEmpty() {
2055
+ return this.radius < 0;
2056
+ }
2057
+ makeEmpty() {
2058
+ this.center.set(0, 0, 0);
2059
+ this.radius = -1;
2060
+ return this;
2061
+ }
2062
+ containsPoint(point) {
2063
+ return point.distanceToSquared(this.center) <= this.radius * this.radius;
2064
+ }
2065
+ distanceToPoint(point) {
2066
+ return point.distanceTo(this.center) - this.radius;
2067
+ }
2068
+ intersectsSphere(sphere) {
2069
+ const radiusSum = this.radius + sphere.radius;
2070
+ return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
2071
+ }
2072
+ intersectsBox(box) {
2073
+ return box.intersectsSphere(this);
2074
+ }
2075
+ intersectsPlane(plane) {
2076
+ return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
2077
+ }
2078
+ clampPoint(point, target) {
2079
+ const deltaLengthSq = this.center.distanceToSquared(point);
2080
+ target.copy(point);
2081
+ if (deltaLengthSq > this.radius * this.radius) {
2082
+ target.sub(this.center).normalize().multiplyScalar(this.radius).add(this.center);
2083
+ }
2084
+ return target;
2085
+ }
2086
+ getBoundingBox(target) {
2087
+ if (this.isEmpty()) {
2088
+ target.makeEmpty();
2089
+ return target;
2090
+ }
2091
+ target.set(this.center, this.center);
2092
+ target.expandByScalar(this.radius);
2093
+ return target;
2094
+ }
2095
+ applyMatrix4(matrix) {
2096
+ this.center.applyMatrix4(matrix);
2097
+ this.radius *= matrix.getMaxScaleOnAxis();
2098
+ return this;
2099
+ }
2100
+ translate(offset) {
2101
+ this.center.add(offset);
2102
+ return this;
2103
+ }
2104
+ expandByPoint(point) {
2105
+ _toPoint.subVectors(point, this.center);
2106
+ const lengthSq = _toPoint.lengthSq();
2107
+ if (lengthSq > this.radius * this.radius) {
2108
+ const length = Math.sqrt(lengthSq);
2109
+ const missingRadiusHalf = (length - this.radius) * 0.5;
2110
+ this.center.add(_toPoint.multiplyScalar(missingRadiusHalf / length));
2111
+ this.radius += missingRadiusHalf;
2112
+ }
2113
+ return this;
2114
+ }
2115
+ union(sphere) {
2116
+ _toFarthestPoint.subVectors(sphere.center, this.center).normalize().multiplyScalar(sphere.radius);
2117
+ this.expandByPoint(_v1$6.copy(sphere.center).add(_toFarthestPoint));
2118
+ this.expandByPoint(_v1$6.copy(sphere.center).sub(_toFarthestPoint));
2119
+ return this;
2120
+ }
2121
+ equals(sphere) {
2122
+ return sphere.center.equals(this.center) && sphere.radius === this.radius;
2123
+ }
2124
+ clone() {
2125
+ return new Sphere().copy(this);
2126
+ }
2127
+ }
2128
+ class Plane {
2129
+ constructor(normal = new Vector3(1, 0, 0), constant = 0) {
2130
+ // normal is assumed to be normalized
2131
+ this.normal = normal;
2132
+ this.constant = constant;
2133
+ }
2134
+ set(normal, constant) {
2135
+ this.normal.copy(normal);
2136
+ this.constant = constant;
2137
+ return this;
2138
+ }
2139
+ setComponents(x, y, z, w) {
2140
+ this.normal.set(x, y, z);
2141
+ this.constant = w;
2142
+ return this;
2143
+ }
2144
+ setFromNormalAndCoplanarPoint(normal, point) {
2145
+ this.normal.copy(normal);
2146
+ this.constant = -point.dot(this.normal);
2147
+ return this;
2148
+ }
2149
+ setFromCoplanarPoints(a, b, c) {
2150
+ const normal = new Vector3().subVectors(c, b).cross(new Vector3().subVectors(a, b)).normalize();
2151
+ this.setFromNormalAndCoplanarPoint(normal, a);
2152
+ return this;
2153
+ }
2154
+ copy(plane) {
2155
+ this.normal.copy(plane.normal);
2156
+ this.constant = plane.constant;
2157
+ return this;
2158
+ }
2159
+ normalize() {
2160
+ // Note: will lead to a divide by zero if the plane is invalid.
2161
+ const inverseNormalLength = 1.0 / this.normal.length();
2162
+ this.normal.multiplyScalar(inverseNormalLength);
2163
+ this.constant *= inverseNormalLength;
2164
+ return this;
2165
+ }
2166
+ negate() {
2167
+ this.constant *= -1;
2168
+ this.normal.negate();
2169
+ return this;
2170
+ }
2171
+ distanceToPoint(point) {
2172
+ return this.normal.dot(point) + this.constant;
2173
+ }
2174
+ distanceToSphere(sphere) {
2175
+ return this.distanceToPoint(sphere.center) - sphere.radius;
2176
+ }
2177
+ projectPoint(point, target) {
2178
+ return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
2179
+ }
2180
+ intersectLine(line, target) {
2181
+ const direction = line.delta(new Vector3());
2182
+ const denominator = this.normal.dot(direction);
2183
+ if (denominator === 0) {
2184
+ // Line is coplanar, return origin
2185
+ if (this.distanceToPoint(line.start) === 0) {
2186
+ return target.copy(line.start);
2187
+ }
2188
+ // Unsure if this is the correct method to handle this case.
2189
+ return null;
2190
+ }
2191
+ const t = -(line.start.dot(this.normal) + this.constant) / denominator;
2192
+ if (t < 0 || t > 1) {
2193
+ return null;
2194
+ }
2195
+ return target.copy(direction).multiplyScalar(t).add(line.start);
2196
+ }
2197
+ intersectsLine(line) {
2198
+ // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
2199
+ const startSign = this.distanceToPoint(line.start);
2200
+ const endSign = this.distanceToPoint(line.end);
2201
+ return (startSign < 0 && endSign > 0) || (endSign < 0 && startSign > 0);
2202
+ }
2203
+ intersectsBox(box) {
2204
+ return box.intersectsPlane(this);
2205
+ }
2206
+ intersectsSphere(sphere) {
2207
+ return sphere.intersectsPlane(this);
2208
+ }
2209
+ coplanarPoint(target) {
2210
+ return target.copy(this.normal).multiplyScalar(-this.constant);
2211
+ }
2212
+ applyMatrix4(matrix, optionalNormalMatrix) {
2213
+ const normalMatrix = optionalNormalMatrix || new Matrix3().getNormalMatrix(matrix);
2214
+ const referencePoint = this.coplanarPoint(new Vector3()).applyMatrix4(matrix);
2215
+ const normal = this.normal.applyMatrix3(normalMatrix).normalize();
2216
+ this.constant = -referencePoint.dot(normal);
2217
+ return this;
2218
+ }
2219
+ translate(offset) {
2220
+ this.constant -= offset.dot(this.normal);
2221
+ return this;
2222
+ }
2223
+ equals(plane) {
2224
+ return plane.normal.equals(this.normal) && plane.constant === this.constant;
2225
+ }
2226
+ clone() {
2227
+ return new Plane().copy(this);
2228
+ }
2229
+ }
2230
+ const _v0$1 = /*@__PURE__*/ new Vector3();
2231
+ const _v1$3 = /*@__PURE__*/ new Vector3();
2232
+ const _v2$2 = /*@__PURE__*/ new Vector3();
2233
+ const _v3$1 = /*@__PURE__*/ new Vector3();
2234
+ const _vab = /*@__PURE__*/ new Vector3();
2235
+ const _vac = /*@__PURE__*/ new Vector3();
2236
+ const _vbc = /*@__PURE__*/ new Vector3();
2237
+ const _vap = /*@__PURE__*/ new Vector3();
2238
+ const _vbp = /*@__PURE__*/ new Vector3();
2239
+ const _vcp = /*@__PURE__*/ new Vector3();
2240
+ class Triangle {
2241
+ constructor(a = new Vector3(), b = new Vector3(), c = new Vector3()) {
2242
+ this.a = a;
2243
+ this.b = b;
2244
+ this.c = c;
2245
+ }
2246
+ static getNormal(a, b, c, target) {
2247
+ target.subVectors(c, b);
2248
+ _v0$1.subVectors(a, b);
2249
+ target.cross(_v0$1);
2250
+ const targetLengthSq = target.lengthSq();
2251
+ if (targetLengthSq > 0) {
2252
+ return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
2253
+ }
2254
+ return target.set(0, 0, 0);
2255
+ }
2256
+ // static/instance method to calculate barycentric coordinates
2257
+ // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
2258
+ static getBarycoord(point, a, b, c, target) {
2259
+ _v0$1.subVectors(c, a);
2260
+ _v1$3.subVectors(b, a);
2261
+ _v2$2.subVectors(point, a);
2262
+ const dot00 = _v0$1.dot(_v0$1);
2263
+ const dot01 = _v0$1.dot(_v1$3);
2264
+ const dot02 = _v0$1.dot(_v2$2);
2265
+ const dot11 = _v1$3.dot(_v1$3);
2266
+ const dot12 = _v1$3.dot(_v2$2);
2267
+ const denom = (dot00 * dot11 - dot01 * dot01);
2268
+ // collinear or singular triangle
2269
+ if (denom === 0) {
2270
+ // arbitrary location outside of triangle?
2271
+ // not sure if this is the best idea, maybe should be returning undefined
2272
+ return target.set(-2, -1, -1);
2273
+ }
2274
+ const invDenom = 1 / denom;
2275
+ const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
2276
+ const v = (dot00 * dot12 - dot01 * dot02) * invDenom;
2277
+ // barycentric coordinates must always sum to 1
2278
+ return target.set(1 - u - v, v, u);
2279
+ }
2280
+ static containsPoint(point, a, b, c) {
2281
+ this.getBarycoord(point, a, b, c, _v3$1);
2282
+ return (_v3$1.x >= 0) && (_v3$1.y >= 0) && ((_v3$1.x + _v3$1.y) <= 1);
2283
+ }
2284
+ static getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
2285
+ this.getBarycoord(point, p1, p2, p3, _v3$1);
2286
+ target.set(0, 0, undefined);
2287
+ target.addScaledVector(uv1, _v3$1.x);
2288
+ target.addScaledVector(uv2, _v3$1.y);
2289
+ target.addScaledVector(uv3, _v3$1.z);
2290
+ return target;
2291
+ }
2292
+ static isFrontFacing(a, b, c, direction) {
2293
+ _v0$1.subVectors(c, b);
2294
+ _v1$3.subVectors(a, b);
2295
+ // strictly front facing
2296
+ return (_v0$1.cross(_v1$3).dot(direction) < 0) ? true : false;
2297
+ }
2298
+ set(a, b, c) {
2299
+ this.a.copy(a);
2300
+ this.b.copy(b);
2301
+ this.c.copy(c);
2302
+ return this;
2303
+ }
2304
+ setFromPointsAndIndices(points, i0, i1, i2) {
2305
+ this.a.copy(points[i0]);
2306
+ this.b.copy(points[i1]);
2307
+ this.c.copy(points[i2]);
2308
+ return this;
2309
+ }
2310
+ setFromAttributeAndIndices(attribute, i0, i1, i2) {
2311
+ this.a.fromBufferAttribute(attribute, i0);
2312
+ this.b.fromBufferAttribute(attribute, i1);
2313
+ this.c.fromBufferAttribute(attribute, i2);
2314
+ return this;
2315
+ }
2316
+ clone() {
2317
+ return new Triangle().copy(this);
2318
+ }
2319
+ copy(triangle) {
2320
+ this.a.copy(triangle.a);
2321
+ this.b.copy(triangle.b);
2322
+ this.c.copy(triangle.c);
2323
+ return this;
2324
+ }
2325
+ getArea() {
2326
+ _v0$1.subVectors(this.c, this.b);
2327
+ _v1$3.subVectors(this.a, this.b);
2328
+ return _v0$1.cross(_v1$3).length() * 0.5;
2329
+ }
2330
+ getMidpoint(target) {
2331
+ return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
2332
+ }
2333
+ getNormal(target) {
2334
+ return Triangle.getNormal(this.a, this.b, this.c, target);
2335
+ }
2336
+ getPlane(target) {
2337
+ return target.setFromCoplanarPoints(this.a, this.b, this.c);
2338
+ }
2339
+ getBarycoord(point, target) {
2340
+ return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
2341
+ }
2342
+ getUV(point, uv1, uv2, uv3, target) {
2343
+ return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
2344
+ }
2345
+ containsPoint(point) {
2346
+ return Triangle.containsPoint(point, this.a, this.b, this.c);
2347
+ }
2348
+ isFrontFacing(direction) {
2349
+ return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
2350
+ }
2351
+ intersectsBox(box) {
2352
+ return box.intersectsTriangle(this);
2353
+ }
2354
+ closestPointToPoint(p, target) {
2355
+ const a = this.a, b = this.b, c = this.c;
2356
+ let v, w;
2357
+ // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
2358
+ // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
2359
+ // under the accompanying license; see chapter 5.1.5 for detailed explanation.
2360
+ // basically, we're distinguishing which of the voronoi regions of the triangle
2361
+ // the point lies in with the minimum amount of redundant computation.
2362
+ _vab.subVectors(b, a);
2363
+ _vac.subVectors(c, a);
2364
+ _vap.subVectors(p, a);
2365
+ const d1 = _vab.dot(_vap);
2366
+ const d2 = _vac.dot(_vap);
2367
+ if (d1 <= 0 && d2 <= 0) {
2368
+ // vertex region of A; barycentric coords (1, 0, 0)
2369
+ return target.copy(a);
2370
+ }
2371
+ _vbp.subVectors(p, b);
2372
+ const d3 = _vab.dot(_vbp);
2373
+ const d4 = _vac.dot(_vbp);
2374
+ if (d3 >= 0 && d4 <= d3) {
2375
+ // vertex region of B; barycentric coords (0, 1, 0)
2376
+ return target.copy(b);
2377
+ }
2378
+ const vc = d1 * d4 - d3 * d2;
2379
+ if (vc <= 0 && d1 >= 0 && d3 <= 0) {
2380
+ v = d1 / (d1 - d3);
2381
+ // edge region of AB; barycentric coords (1-v, v, 0)
2382
+ return target.copy(a).addScaledVector(_vab, v);
2383
+ }
2384
+ _vcp.subVectors(p, c);
2385
+ const d5 = _vab.dot(_vcp);
2386
+ const d6 = _vac.dot(_vcp);
2387
+ if (d6 >= 0 && d5 <= d6) {
2388
+ // vertex region of C; barycentric coords (0, 0, 1)
2389
+ return target.copy(c);
2390
+ }
2391
+ const vb = d5 * d2 - d1 * d6;
2392
+ if (vb <= 0 && d2 >= 0 && d6 <= 0) {
2393
+ w = d2 / (d2 - d6);
2394
+ // edge region of AC; barycentric coords (1-w, 0, w)
2395
+ return target.copy(a).addScaledVector(_vac, w);
2396
+ }
2397
+ const va = d3 * d6 - d5 * d4;
2398
+ if (va <= 0 && (d4 - d3) >= 0 && (d5 - d6) >= 0) {
2399
+ _vbc.subVectors(c, b);
2400
+ w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
2401
+ // edge region of BC; barycentric coords (0, 1-w, w)
2402
+ return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
2403
+ }
2404
+ // face region
2405
+ const denom = 1 / (va + vb + vc);
2406
+ // u = va * denom
2407
+ v = vb * denom;
2408
+ w = vc * denom;
2409
+ return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
2410
+ }
2411
+ equals(triangle) {
2412
+ return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
2413
+ }
2414
+ }
2415
+ //#endregion
2416
+ const _vector$9 = /*@__PURE__*/ new Vector3(0, 0, 0);
2417
+ const _vector2$1 = /*@__PURE__*/ new Vector2();
2418
+ class BufferAttribute {
2419
+ constructor(array, itemSize, normalized = true) {
2420
+ this.name = '';
2421
+ if (Array.isArray(array)) {
2422
+ throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
2423
+ }
2424
+ this.array = array;
2425
+ this.itemSize = itemSize;
2426
+ this.count = array !== undefined ? array.length / itemSize : 0;
2427
+ this.normalized = normalized === true;
2428
+ this.usage = StaticDrawUsage;
2429
+ this.updateRange = { offset: 0, count: -1 };
2430
+ this.version = 0;
2431
+ }
2432
+ onUploadCallback() { }
2433
+ set needsUpdate(value) {
2434
+ if (value === true)
2435
+ this.version++;
2436
+ }
2437
+ setUsage(value) {
2438
+ this.usage = value;
2439
+ return this;
2440
+ }
2441
+ copy(source) {
2442
+ this.name = source.name;
2443
+ this.array = source.array;
2444
+ this.itemSize = source.itemSize;
2445
+ this.count = source.count;
2446
+ this.normalized = source.normalized;
2447
+ this.usage = source.usage;
2448
+ return this;
2449
+ }
2450
+ copyAt(index1, attribute, index2) {
2451
+ index1 *= this.itemSize;
2452
+ index2 *= attribute.itemSize;
2453
+ for (let i = 0, l = this.itemSize; i < l; i++) {
2454
+ this.array[index1 + i] = attribute.array[index2 + i];
2455
+ }
2456
+ return this;
2457
+ }
2458
+ copyArray(array) {
2459
+ this.array.set(array);
2460
+ return this;
2461
+ }
2462
+ copyColorsArray(colors) {
2463
+ const array = this.array;
2464
+ let offset = 0;
2465
+ for (let i = 0, l = colors.length; i < l; i++) {
2466
+ let color = colors[i];
2467
+ if (color === undefined) {
2468
+ console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
2469
+ color = new Color(255, 255, 255);
2470
+ }
2471
+ array[offset++] = color.r;
2472
+ array[offset++] = color.g;
2473
+ array[offset++] = color.b;
2474
+ }
2475
+ return this;
2476
+ }
2477
+ copyVector2sArray(vectors) {
2478
+ const array = this.array;
2479
+ let offset = 0;
2480
+ for (let i = 0, l = vectors.length; i < l; i++) {
2481
+ let vector = vectors[i];
2482
+ if (vector === undefined) {
2483
+ console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
2484
+ vector = new Vector2();
2485
+ }
2486
+ array[offset++] = vector.x;
2487
+ array[offset++] = vector.y;
2488
+ }
2489
+ return this;
2490
+ }
2491
+ copyVector3sArray(vectors) {
2492
+ const array = this.array;
2493
+ let offset = 0;
2494
+ for (let i = 0, l = vectors.length; i < l; i++) {
2495
+ let vector = vectors[i];
2496
+ if (vector === undefined) {
2497
+ console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
2498
+ vector = new Vector3(0, 0, 0);
2499
+ }
2500
+ array[offset++] = vector.x;
2501
+ array[offset++] = vector.y;
2502
+ array[offset++] = vector.z;
2503
+ }
2504
+ return this;
2505
+ }
2506
+ copyVector4sArray(vectors) {
2507
+ const array = this.array;
2508
+ let offset = 0;
2509
+ for (let i = 0, l = vectors.length; i < l; i++) {
2510
+ let vector = vectors[i];
2511
+ if (vector === undefined) {
2512
+ console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
2513
+ vector = new Vector4();
2514
+ }
2515
+ array[offset++] = vector.x;
2516
+ array[offset++] = vector.y;
2517
+ array[offset++] = vector.z;
2518
+ array[offset++] = vector.w;
2519
+ }
2520
+ return this;
2521
+ }
2522
+ applyMatrix3(m) {
2523
+ if (this.itemSize === 2) {
2524
+ for (let i = 0, l = this.count; i < l; i++) {
2525
+ _vector2$1.fromBufferAttribute(this, i);
2526
+ _vector2$1.applyMatrix3(m);
2527
+ this.setXY(i, _vector2$1.x, _vector2$1.y);
2528
+ }
2529
+ }
2530
+ else if (this.itemSize === 3) {
2531
+ for (let i = 0, l = this.count; i < l; i++) {
2532
+ _vector$9.fromBufferAttribute(this, i);
2533
+ _vector$9.applyMatrix3(m);
2534
+ this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2535
+ }
2536
+ }
2537
+ return this;
2538
+ }
2539
+ applyMatrix4(m) {
2540
+ for (let i = 0, l = this.count; i < l; i++) {
2541
+ _vector$9.x = this.getX(i);
2542
+ _vector$9.y = this.getY(i);
2543
+ _vector$9.z = this.getZ(i);
2544
+ _vector$9.applyMatrix4(m);
2545
+ this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2546
+ }
2547
+ return this;
2548
+ }
2549
+ applyNormalMatrix(m) {
2550
+ for (let i = 0, l = this.count; i < l; i++) {
2551
+ _vector$9.x = this.getX(i);
2552
+ _vector$9.y = this.getY(i);
2553
+ _vector$9.z = this.getZ(i);
2554
+ _vector$9.applyNormalMatrix(m);
2555
+ this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2556
+ }
2557
+ return this;
2558
+ }
2559
+ transformDirection(m) {
2560
+ for (let i = 0, l = this.count; i < l; i++) {
2561
+ _vector$9.x = this.getX(i);
2562
+ _vector$9.y = this.getY(i);
2563
+ _vector$9.z = this.getZ(i);
2564
+ _vector$9.transformDirection(m);
2565
+ this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2566
+ }
2567
+ return this;
2568
+ }
2569
+ set(value, offset = 0) {
2570
+ this.array.set(value, offset);
2571
+ return this;
2572
+ }
2573
+ getX(index) {
2574
+ return this.array[index * this.itemSize];
2575
+ }
2576
+ setX(index, x) {
2577
+ this.array[index * this.itemSize] = x;
2578
+ return this;
2579
+ }
2580
+ getY(index) {
2581
+ return this.array[index * this.itemSize + 1];
2582
+ }
2583
+ setY(index, y) {
2584
+ this.array[index * this.itemSize + 1] = y;
2585
+ return this;
2586
+ }
2587
+ getZ(index) {
2588
+ return this.array[index * this.itemSize + 2];
2589
+ }
2590
+ setZ(index, z) {
2591
+ this.array[index * this.itemSize + 2] = z;
2592
+ return this;
2593
+ }
2594
+ getW(index) {
2595
+ return this.array[index * this.itemSize + 3];
2596
+ }
2597
+ setW(index, w) {
2598
+ this.array[index * this.itemSize + 3] = w;
2599
+ return this;
2600
+ }
2601
+ setXY(index, x, y) {
2602
+ index *= this.itemSize;
2603
+ this.array[index + 0] = x;
2604
+ this.array[index + 1] = y;
2605
+ return this;
2606
+ }
2607
+ setXYZ(index, x, y, z) {
2608
+ index *= this.itemSize;
2609
+ this.array[index + 0] = x;
2610
+ this.array[index + 1] = y;
2611
+ this.array[index + 2] = z;
2612
+ return this;
2613
+ }
2614
+ setXYZW(index, x, y, z, w) {
2615
+ index *= this.itemSize;
2616
+ this.array[index + 0] = x;
2617
+ this.array[index + 1] = y;
2618
+ this.array[index + 2] = z;
2619
+ this.array[index + 3] = w;
2620
+ return this;
2621
+ }
2622
+ onUpload(callback) {
2623
+ this.onUploadCallback = callback;
2624
+ return this;
2625
+ }
2626
+ clone() {
2627
+ return new this.constructor(this.array, this.itemSize).copy(this);
2628
+ }
2629
+ toJSON() {
2630
+ const data = {
2631
+ itemSize: this.itemSize,
2632
+ type: this.array.constructor.name,
2633
+ array: Array.prototype.slice.call(this.array),
2634
+ normalized: this.normalized,
2635
+ name: '',
2636
+ usage: 0,
2637
+ updateRange: {
2638
+ offset: 0,
2639
+ count: 0
2640
+ }
2641
+ };
2642
+ if (this.name !== '')
2643
+ data.name = this.name;
2644
+ if (this.usage !== StaticDrawUsage)
2645
+ data.usage = this.usage;
2646
+ if (this.updateRange.offset !== 0 || this.updateRange.count !== -1)
2647
+ data.updateRange = this.updateRange;
2648
+ return data;
2649
+ }
2650
+ }
2651
+ let _id = 0;
2652
+ const _vector$8 = /*@__PURE__*/ new Vector3();
2653
+ class BufferGeometry extends EventDispatcher {
2654
+ constructor() {
2655
+ super();
2656
+ Object.defineProperty(this, 'id', { value: _id++ });
2657
+ this.uuid = generateUUID();
2658
+ this.name = '';
2659
+ this.type = 'BufferGeometry';
2660
+ this.index = null;
2661
+ this.attributes = {};
2662
+ this.morphAttributes = {};
2663
+ this.morphTargetsRelative = false;
2664
+ this.groups = [];
2665
+ this.boundingBox = null;
2666
+ this.boundingSphere = null;
2667
+ this.drawRange = { start: 0, count: Infinity };
2668
+ this.userData = {};
2669
+ }
2670
+ setAttribute(name, attribute) {
2671
+ this.attributes[name] = attribute;
2672
+ return this;
2673
+ }
2674
+ getAttribute(name) {
2675
+ return this.attributes[name];
2676
+ }
2677
+ computeVertexNormals() {
2678
+ const index = this.index;
2679
+ const positionAttribute = this.getAttribute('position');
2680
+ if (positionAttribute !== undefined) {
2681
+ let normalAttribute = this.getAttribute('normal');
2682
+ if (normalAttribute === undefined) {
2683
+ normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
2684
+ this.setAttribute('normal', normalAttribute);
2685
+ }
2686
+ else {
2687
+ // reset existing normals to zero
2688
+ for (let i = 0, il = normalAttribute.count; i < il; i++) {
2689
+ normalAttribute.setXYZ(i, 0, 0, 0);
2690
+ }
2691
+ }
2692
+ const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
2693
+ const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
2694
+ const cb = new Vector3(), ab = new Vector3();
2695
+ // indexed elements
2696
+ if (index) {
2697
+ for (let i = 0, il = index.count; i < il; i += 3) {
2698
+ const vA = index.getX(i + 0);
2699
+ const vB = index.getX(i + 1);
2700
+ const vC = index.getX(i + 2);
2701
+ pA.fromBufferAttribute(positionAttribute, vA);
2702
+ pB.fromBufferAttribute(positionAttribute, vB);
2703
+ pC.fromBufferAttribute(positionAttribute, vC);
2704
+ cb.subVectors(pC, pB);
2705
+ ab.subVectors(pA, pB);
2706
+ cb.cross(ab);
2707
+ nA.fromBufferAttribute(normalAttribute, vA);
2708
+ nB.fromBufferAttribute(normalAttribute, vB);
2709
+ nC.fromBufferAttribute(normalAttribute, vC);
2710
+ nA.add(cb);
2711
+ nB.add(cb);
2712
+ nC.add(cb);
2713
+ normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
2714
+ normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
2715
+ normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
2716
+ }
2717
+ }
2718
+ else {
2719
+ // non-indexed elements (unconnected triangle soup)
2720
+ for (let i = 0, il = positionAttribute.count; i < il; i += 3) {
2721
+ pA.fromBufferAttribute(positionAttribute, i + 0);
2722
+ pB.fromBufferAttribute(positionAttribute, i + 1);
2723
+ pC.fromBufferAttribute(positionAttribute, i + 2);
2724
+ cb.subVectors(pC, pB);
2725
+ ab.subVectors(pA, pB);
2726
+ cb.cross(ab);
2727
+ normalAttribute.setXYZ(i + 0, cb.x, cb.y, cb.z);
2728
+ normalAttribute.setXYZ(i + 1, cb.x, cb.y, cb.z);
2729
+ normalAttribute.setXYZ(i + 2, cb.x, cb.y, cb.z);
2730
+ }
2731
+ }
2732
+ this.normalizeNormals();
2733
+ normalAttribute.needsUpdate = true;
2734
+ }
2735
+ }
2736
+ normalizeNormals() {
2737
+ const normals = this.attributes.normal;
2738
+ for (let i = 0, il = normals.count; i < il; i++) {
2739
+ _vector$8.fromBufferAttribute(normals, i);
2740
+ _vector$8.normalize();
2741
+ normals.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.z);
2742
+ }
2743
+ }
137
2744
  }
2745
+ //#endregion
138
2746
  }
139
2747
  exports.workerCode = workerFunction;
140
2748
  //# sourceMappingURL=load-model-worker-2.script.js.map