BlueGit

timfa filemanager

Files

filemanager / public / vendor / three / three.module.js

three.module.js

formatting
timfa Tim Falken · pushed by timfa · 6 months ago
68827177 History
three.module.js 1.2 MiB Download Raw
1/**
2 * @license
3 * Copyright 2010-2024 Three.js Authors
4 * SPDX-License-Identifier: MIT
5 */
6const REVISION = '166';
7
8const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
9const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
10const CullFaceNone = 0;
11const CullFaceBack = 1;
12const CullFaceFront = 2;
13const CullFaceFrontBack = 3;
14const BasicShadowMap = 0;
15const PCFShadowMap = 1;
16const PCFSoftShadowMap = 2;
17const VSMShadowMap = 3;
18const FrontSide = 0;
19const BackSide = 1;
20const DoubleSide = 2;
21const NoBlending = 0;
22const NormalBlending = 1;
23const AdditiveBlending = 2;
24const SubtractiveBlending = 3;
25const MultiplyBlending = 4;
26const CustomBlending = 5;
27const AddEquation = 100;
28const SubtractEquation = 101;
29const ReverseSubtractEquation = 102;
30const MinEquation = 103;
31const MaxEquation = 104;
32const ZeroFactor = 200;
33const OneFactor = 201;
34const SrcColorFactor = 202;
35const OneMinusSrcColorFactor = 203;
36const SrcAlphaFactor = 204;
37const OneMinusSrcAlphaFactor = 205;
38const DstAlphaFactor = 206;
39const OneMinusDstAlphaFactor = 207;
40const DstColorFactor = 208;
41const OneMinusDstColorFactor = 209;
42const SrcAlphaSaturateFactor = 210;
43const ConstantColorFactor = 211;
44const OneMinusConstantColorFactor = 212;
45const ConstantAlphaFactor = 213;
46const OneMinusConstantAlphaFactor = 214;
47const NeverDepth = 0;
48const AlwaysDepth = 1;
49const LessDepth = 2;
50const LessEqualDepth = 3;
51const EqualDepth = 4;
52const GreaterEqualDepth = 5;
53const GreaterDepth = 6;
54const NotEqualDepth = 7;
55const MultiplyOperation = 0;
56const MixOperation = 1;
57const AddOperation = 2;
58const NoToneMapping = 0;
59const LinearToneMapping = 1;
60const ReinhardToneMapping = 2;
61const CineonToneMapping = 3;
62const ACESFilmicToneMapping = 4;
63const CustomToneMapping = 5;
64const AgXToneMapping = 6;
65const NeutralToneMapping = 7;
66const AttachedBindMode = 'attached';
67const DetachedBindMode = 'detached';
68
69const UVMapping = 300;
70const CubeReflectionMapping = 301;
71const CubeRefractionMapping = 302;
72const EquirectangularReflectionMapping = 303;
73const EquirectangularRefractionMapping = 304;
74const CubeUVReflectionMapping = 306;
75const RepeatWrapping = 1000;
76const ClampToEdgeWrapping = 1001;
77const MirroredRepeatWrapping = 1002;
78const NearestFilter = 1003;
79const NearestMipmapNearestFilter = 1004;
80const NearestMipMapNearestFilter = 1004;
81const NearestMipmapLinearFilter = 1005;
82const NearestMipMapLinearFilter = 1005;
83const LinearFilter = 1006;
84const LinearMipmapNearestFilter = 1007;
85const LinearMipMapNearestFilter = 1007;
86const LinearMipmapLinearFilter = 1008;
87const LinearMipMapLinearFilter = 1008;
88const UnsignedByteType = 1009;
89const ByteType = 1010;
90const ShortType = 1011;
91const UnsignedShortType = 1012;
92const IntType = 1013;
93const UnsignedIntType = 1014;
94const FloatType = 1015;
95const HalfFloatType = 1016;
96const UnsignedShort4444Type = 1017;
97const UnsignedShort5551Type = 1018;
98const UnsignedInt248Type = 1020;
99const UnsignedInt5999Type = 35902;
100const AlphaFormat = 1021;
101const RGBFormat = 1022;
102const RGBAFormat = 1023;
103const LuminanceFormat = 1024;
104const LuminanceAlphaFormat = 1025;
105const DepthFormat = 1026;
106const DepthStencilFormat = 1027;
107const RedFormat = 1028;
108const RedIntegerFormat = 1029;
109const RGFormat = 1030;
110const RGIntegerFormat = 1031;
111const RGBIntegerFormat = 1032;
112const RGBAIntegerFormat = 1033;
113
114const RGB_S3TC_DXT1_Format = 33776;
115const RGBA_S3TC_DXT1_Format = 33777;
116const RGBA_S3TC_DXT3_Format = 33778;
117const RGBA_S3TC_DXT5_Format = 33779;
118const RGB_PVRTC_4BPPV1_Format = 35840;
119const RGB_PVRTC_2BPPV1_Format = 35841;
120const RGBA_PVRTC_4BPPV1_Format = 35842;
121const RGBA_PVRTC_2BPPV1_Format = 35843;
122const RGB_ETC1_Format = 36196;
123const RGB_ETC2_Format = 37492;
124const RGBA_ETC2_EAC_Format = 37496;
125const RGBA_ASTC_4x4_Format = 37808;
126const RGBA_ASTC_5x4_Format = 37809;
127const RGBA_ASTC_5x5_Format = 37810;
128const RGBA_ASTC_6x5_Format = 37811;
129const RGBA_ASTC_6x6_Format = 37812;
130const RGBA_ASTC_8x5_Format = 37813;
131const RGBA_ASTC_8x6_Format = 37814;
132const RGBA_ASTC_8x8_Format = 37815;
133const RGBA_ASTC_10x5_Format = 37816;
134const RGBA_ASTC_10x6_Format = 37817;
135const RGBA_ASTC_10x8_Format = 37818;
136const RGBA_ASTC_10x10_Format = 37819;
137const RGBA_ASTC_12x10_Format = 37820;
138const RGBA_ASTC_12x12_Format = 37821;
139const RGBA_BPTC_Format = 36492;
140const RGB_BPTC_SIGNED_Format = 36494;
141const RGB_BPTC_UNSIGNED_Format = 36495;
142const RED_RGTC1_Format = 36283;
143const SIGNED_RED_RGTC1_Format = 36284;
144const RED_GREEN_RGTC2_Format = 36285;
145const SIGNED_RED_GREEN_RGTC2_Format = 36286;
146const LoopOnce = 2200;
147const LoopRepeat = 2201;
148const LoopPingPong = 2202;
149const InterpolateDiscrete = 2300;
150const InterpolateLinear = 2301;
151const InterpolateSmooth = 2302;
152const ZeroCurvatureEnding = 2400;
153const ZeroSlopeEnding = 2401;
154const WrapAroundEnding = 2402;
155const NormalAnimationBlendMode = 2500;
156const AdditiveAnimationBlendMode = 2501;
157const TrianglesDrawMode = 0;
158const TriangleStripDrawMode = 1;
159const TriangleFanDrawMode = 2;
160const BasicDepthPacking = 3200;
161const RGBADepthPacking = 3201;
162const TangentSpaceNormalMap = 0;
163const ObjectSpaceNormalMap = 1;
164
165// Color space string identifiers, matching CSS Color Module Level 4 and WebGPU names where available.
166const NoColorSpace = '';
167const SRGBColorSpace = 'srgb';
168const LinearSRGBColorSpace = 'srgb-linear';
169const DisplayP3ColorSpace = 'display-p3';
170const LinearDisplayP3ColorSpace = 'display-p3-linear';
171
172const LinearTransfer = 'linear';
173const SRGBTransfer = 'srgb';
174
175const Rec709Primaries = 'rec709';
176const P3Primaries = 'p3';
177
178const ZeroStencilOp = 0;
179const KeepStencilOp = 7680;
180const ReplaceStencilOp = 7681;
181const IncrementStencilOp = 7682;
182const DecrementStencilOp = 7683;
183const IncrementWrapStencilOp = 34055;
184const DecrementWrapStencilOp = 34056;
185const InvertStencilOp = 5386;
186
187const NeverStencilFunc = 512;
188const LessStencilFunc = 513;
189const EqualStencilFunc = 514;
190const LessEqualStencilFunc = 515;
191const GreaterStencilFunc = 516;
192const NotEqualStencilFunc = 517;
193const GreaterEqualStencilFunc = 518;
194const AlwaysStencilFunc = 519;
195
196const NeverCompare = 512;
197const LessCompare = 513;
198const EqualCompare = 514;
199const LessEqualCompare = 515;
200const GreaterCompare = 516;
201const NotEqualCompare = 517;
202const GreaterEqualCompare = 518;
203const AlwaysCompare = 519;
204
205const StaticDrawUsage = 35044;
206const DynamicDrawUsage = 35048;
207const StreamDrawUsage = 35040;
208const StaticReadUsage = 35045;
209const DynamicReadUsage = 35049;
210const StreamReadUsage = 35041;
211const StaticCopyUsage = 35046;
212const DynamicCopyUsage = 35050;
213const StreamCopyUsage = 35042;
214
215const GLSL1 = '100';
216const GLSL3 = '300 es';
217
218const WebGLCoordinateSystem = 2000;
219const WebGPUCoordinateSystem = 2001;
220
221/**
222 * https://github.com/mrdoob/eventdispatcher.js/
223 */
224
225class EventDispatcher
226{
227
228 addEventListener (type, listener)
229 {
230
231 if (this._listeners === undefined) this._listeners = {};
232
233 const listeners = this._listeners;
234
235 if (listeners[type] === undefined)
236 {
237
238 listeners[type] = [];
239
240 }
241
242 if (listeners[type].indexOf(listener) === - 1)
243 {
244
245 listeners[type].push(listener);
246
247 }
248
249 }
250
251 hasEventListener (type, listener)
252 {
253
254 if (this._listeners === undefined) return false;
255
256 const listeners = this._listeners;
257
258 return listeners[type] !== undefined && listeners[type].indexOf(listener) !== - 1;
259
260 }
261
262 removeEventListener (type, listener)
263 {
264
265 if (this._listeners === undefined) return;
266
267 const listeners = this._listeners;
268 const listenerArray = listeners[type];
269
270 if (listenerArray !== undefined)
271 {
272
273 const index = listenerArray.indexOf(listener);
274
275 if (index !== - 1)
276 {
277
278 listenerArray.splice(index, 1);
279
280 }
281
282 }
283
284 }
285
286 dispatchEvent (event)
287 {
288
289 if (this._listeners === undefined) return;
290
291 const listeners = this._listeners;
292 const listenerArray = listeners[event.type];
293
294 if (listenerArray !== undefined)
295 {
296
297 event.target = this;
298
299 // Make a copy, in case listeners are removed while iterating.
300 const array = listenerArray.slice(0);
301
302 for (let i = 0, l = array.length; i < l; i++)
303 {
304
305 array[i].call(this, event);
306
307 }
308
309 event.target = null;
310
311 }
312
313 }
314
315}
316
317const _lut = ['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'];
318
319let _seed = 1234567;
320
321
322const DEG2RAD = Math.PI / 180;
323const RAD2DEG = 180 / Math.PI;
324
325// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
326function generateUUID ()
327{
328
329 const d0 = Math.random() * 0xffffffff | 0;
330 const d1 = Math.random() * 0xffffffff | 0;
331 const d2 = Math.random() * 0xffffffff | 0;
332 const d3 = Math.random() * 0xffffffff | 0;
333 const uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' +
334 _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' +
335 _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] +
336 _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff];
337
338 // .toLowerCase() here flattens concatenated strings to save heap memory space.
339 return uuid.toLowerCase();
340
341}
342
343function clamp (value, min, max)
344{
345
346 return Math.max(min, Math.min(max, value));
347
348}
349
350// compute euclidean modulo of m % n
351// https://en.wikipedia.org/wiki/Modulo_operation
352function euclideanModulo (n, m)
353{
354
355 return ((n % m) + m) % m;
356
357}
358
359// Linear mapping from range <a1, a2> to range <b1, b2>
360function mapLinear (x, a1, a2, b1, b2)
361{
362
363 return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
364
365}
366
367// https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/
368function inverseLerp (x, y, value)
369{
370
371 if (x !== y)
372 {
373
374 return (value - x) / (y - x);
375
376 } else
377 {
378
379 return 0;
380
381 }
382
383}
384
385// https://en.wikipedia.org/wiki/Linear_interpolation
386function lerp (x, y, t)
387{
388
389 return (1 - t) * x + t * y;
390
391}
392
393// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
394function damp (x, y, lambda, dt)
395{
396
397 return lerp(x, y, 1 - Math.exp(- lambda * dt));
398
399}
400
401// https://www.desmos.com/calculator/vcsjnyz7x4
402function pingpong (x, length = 1)
403{
404
405 return length - Math.abs(euclideanModulo(x, length * 2) - length);
406
407}
408
409// http://en.wikipedia.org/wiki/Smoothstep
410function smoothstep (x, min, max)
411{
412
413 if (x <= min) return 0;
414 if (x >= max) return 1;
415
416 x = (x - min) / (max - min);
417
418 return x * x * (3 - 2 * x);
419
420}
421
422function smootherstep (x, min, max)
423{
424
425 if (x <= min) return 0;
426 if (x >= max) return 1;
427
428 x = (x - min) / (max - min);
429
430 return x * x * x * (x * (x * 6 - 15) + 10);
431
432}
433
434// Random integer from <low, high> interval
435function randInt (low, high)
436{
437
438 return low + Math.floor(Math.random() * (high - low + 1));
439
440}
441
442// Random float from <low, high> interval
443function randFloat (low, high)
444{
445
446 return low + Math.random() * (high - low);
447
448}
449
450// Random float from <-range/2, range/2> interval
451function randFloatSpread (range)
452{
453
454 return range * (0.5 - Math.random());
455
456}
457
458// Deterministic pseudo-random float in the interval [ 0, 1 ]
459function seededRandom (s)
460{
461
462 if (s !== undefined) _seed = s;
463
464 // Mulberry32 generator
465
466 let t = _seed += 0x6D2B79F5;
467
468 t = Math.imul(t ^ t >>> 15, t | 1);
469
470 t ^= t + Math.imul(t ^ t >>> 7, t | 61);
471
472 return ((t ^ t >>> 14) >>> 0) / 4294967296;
473
474}
475
476function degToRad (degrees)
477{
478
479 return degrees * DEG2RAD;
480
481}
482
483function radToDeg (radians)
484{
485
486 return radians * RAD2DEG;
487
488}
489
490function isPowerOfTwo (value)
491{
492
493 return (value & (value - 1)) === 0 && value !== 0;
494
495}
496
497function ceilPowerOfTwo (value)
498{
499
500 return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
501
502}
503
504function floorPowerOfTwo (value)
505{
506
507 return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
508
509}
510
511function setQuaternionFromProperEuler (q, a, b, c, order)
512{
513
514 // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
515
516 // rotations are applied to the axes in the order specified by 'order'
517 // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
518 // angles are in radians
519
520 const cos = Math.cos;
521 const sin = Math.sin;
522
523 const c2 = cos(b / 2);
524 const s2 = sin(b / 2);
525
526 const c13 = cos((a + c) / 2);
527 const s13 = sin((a + c) / 2);
528
529 const c1_3 = cos((a - c) / 2);
530 const s1_3 = sin((a - c) / 2);
531
532 const c3_1 = cos((c - a) / 2);
533 const s3_1 = sin((c - a) / 2);
534
535 switch (order)
536 {
537
538 case 'XYX':
539 q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
540 break;
541
542 case 'YZY':
543 q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
544 break;
545
546 case 'ZXZ':
547 q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
548 break;
549
550 case 'XZX':
551 q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
552 break;
553
554 case 'YXY':
555 q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
556 break;
557
558 case 'ZYZ':
559 q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
560 break;
561
562 default:
563 console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
564
565 }
566
567}
568
569function denormalize (value, array)
570{
571
572 switch (array.constructor)
573 {
574
575 case Float32Array:
576
577 return value;
578
579 case Uint32Array:
580
581 return value / 4294967295.0;
582
583 case Uint16Array:
584
585 return value / 65535.0;
586
587 case Uint8Array:
588
589 return value / 255.0;
590
591 case Int32Array:
592
593 return Math.max(value / 2147483647.0, - 1.0);
594
595 case Int16Array:
596
597 return Math.max(value / 32767.0, - 1.0);
598
599 case Int8Array:
600
601 return Math.max(value / 127.0, - 1.0);
602
603 default:
604
605 throw new Error('Invalid component type.');
606
607 }
608
609}
610
611function normalize (value, array)
612{
613
614 switch (array.constructor)
615 {
616
617 case Float32Array:
618
619 return value;
620
621 case Uint32Array:
622
623 return Math.round(value * 4294967295.0);
624
625 case Uint16Array:
626
627 return Math.round(value * 65535.0);
628
629 case Uint8Array:
630
631 return Math.round(value * 255.0);
632
633 case Int32Array:
634
635 return Math.round(value * 2147483647.0);
636
637 case Int16Array:
638
639 return Math.round(value * 32767.0);
640
641 case Int8Array:
642
643 return Math.round(value * 127.0);
644
645 default:
646
647 throw new Error('Invalid component type.');
648
649 }
650
651}
652
653const MathUtils = {
654 DEG2RAD: DEG2RAD,
655 RAD2DEG: RAD2DEG,
656 generateUUID: generateUUID,
657 clamp: clamp,
658 euclideanModulo: euclideanModulo,
659 mapLinear: mapLinear,
660 inverseLerp: inverseLerp,
661 lerp: lerp,
662 damp: damp,
663 pingpong: pingpong,
664 smoothstep: smoothstep,
665 smootherstep: smootherstep,
666 randInt: randInt,
667 randFloat: randFloat,
668 randFloatSpread: randFloatSpread,
669 seededRandom: seededRandom,
670 degToRad: degToRad,
671 radToDeg: radToDeg,
672 isPowerOfTwo: isPowerOfTwo,
673 ceilPowerOfTwo: ceilPowerOfTwo,
674 floorPowerOfTwo: floorPowerOfTwo,
675 setQuaternionFromProperEuler: setQuaternionFromProperEuler,
676 normalize: normalize,
677 denormalize: denormalize
678};
679
680class Vector2
681{
682
683 constructor(x = 0, y = 0)
684 {
685
686 Vector2.prototype.isVector2 = true;
687
688 this.x = x;
689 this.y = y;
690
691 }
692
693 get width ()
694 {
695
696 return this.x;
697
698 }
699
700 set width (value)
701 {
702
703 this.x = value;
704
705 }
706
707 get height ()
708 {
709
710 return this.y;
711
712 }
713
714 set height (value)
715 {
716
717 this.y = value;
718
719 }
720
721 set (x, y)
722 {
723
724 this.x = x;
725 this.y = y;
726
727 return this;
728
729 }
730
731 setScalar (scalar)
732 {
733
734 this.x = scalar;
735 this.y = scalar;
736
737 return this;
738
739 }
740
741 setX (x)
742 {
743
744 this.x = x;
745
746 return this;
747
748 }
749
750 setY (y)
751 {
752
753 this.y = y;
754
755 return this;
756
757 }
758
759 setComponent (index, value)
760 {
761
762 switch (index)
763 {
764
765 case 0: this.x = value; break;
766 case 1: this.y = value; break;
767 default: throw new Error('index is out of range: ' + index);
768
769 }
770
771 return this;
772
773 }
774
775 getComponent (index)
776 {
777
778 switch (index)
779 {
780
781 case 0: return this.x;
782 case 1: return this.y;
783 default: throw new Error('index is out of range: ' + index);
784
785 }
786
787 }
788
789 clone ()
790 {
791
792 return new this.constructor(this.x, this.y);
793
794 }
795
796 copy (v)
797 {
798
799 this.x = v.x;
800 this.y = v.y;
801
802 return this;
803
804 }
805
806 add (v)
807 {
808
809 this.x += v.x;
810 this.y += v.y;
811
812 return this;
813
814 }
815
816 addScalar (s)
817 {
818
819 this.x += s;
820 this.y += s;
821
822 return this;
823
824 }
825
826 addVectors (a, b)
827 {
828
829 this.x = a.x + b.x;
830 this.y = a.y + b.y;
831
832 return this;
833
834 }
835
836 addScaledVector (v, s)
837 {
838
839 this.x += v.x * s;
840 this.y += v.y * s;
841
842 return this;
843
844 }
845
846 sub (v)
847 {
848
849 this.x -= v.x;
850 this.y -= v.y;
851
852 return this;
853
854 }
855
856 subScalar (s)
857 {
858
859 this.x -= s;
860 this.y -= s;
861
862 return this;
863
864 }
865
866 subVectors (a, b)
867 {
868
869 this.x = a.x - b.x;
870 this.y = a.y - b.y;
871
872 return this;
873
874 }
875
876 multiply (v)
877 {
878
879 this.x *= v.x;
880 this.y *= v.y;
881
882 return this;
883
884 }
885
886 multiplyScalar (scalar)
887 {
888
889 this.x *= scalar;
890 this.y *= scalar;
891
892 return this;
893
894 }
895
896 divide (v)
897 {
898
899 this.x /= v.x;
900 this.y /= v.y;
901
902 return this;
903
904 }
905
906 divideScalar (scalar)
907 {
908
909 return this.multiplyScalar(1 / scalar);
910
911 }
912
913 applyMatrix3 (m)
914 {
915
916 const x = this.x, y = this.y;
917 const e = m.elements;
918
919 this.x = e[0] * x + e[3] * y + e[6];
920 this.y = e[1] * x + e[4] * y + e[7];
921
922 return this;
923
924 }
925
926 min (v)
927 {
928
929 this.x = Math.min(this.x, v.x);
930 this.y = Math.min(this.y, v.y);
931
932 return this;
933
934 }
935
936 max (v)
937 {
938
939 this.x = Math.max(this.x, v.x);
940 this.y = Math.max(this.y, v.y);
941
942 return this;
943
944 }
945
946 clamp (min, max)
947 {
948
949 // assumes min < max, componentwise
950
951 this.x = Math.max(min.x, Math.min(max.x, this.x));
952 this.y = Math.max(min.y, Math.min(max.y, this.y));
953
954 return this;
955
956 }
957
958 clampScalar (minVal, maxVal)
959 {
960
961 this.x = Math.max(minVal, Math.min(maxVal, this.x));
962 this.y = Math.max(minVal, Math.min(maxVal, this.y));
963
964 return this;
965
966 }
967
968 clampLength (min, max)
969 {
970
971 const length = this.length();
972
973 return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
974
975 }
976
977 floor ()
978 {
979
980 this.x = Math.floor(this.x);
981 this.y = Math.floor(this.y);
982
983 return this;
984
985 }
986
987 ceil ()
988 {
989
990 this.x = Math.ceil(this.x);
991 this.y = Math.ceil(this.y);
992
993 return this;
994
995 }
996
997 round ()
998 {
999
1000 this.x = Math.round(this.x);
1001 this.y = Math.round(this.y);
1002
1003 return this;
1004
1005 }
1006
1007 roundToZero ()
1008 {
1009
1010 this.x = Math.trunc(this.x);
1011 this.y = Math.trunc(this.y);
1012
1013 return this;
1014
1015 }
1016
1017 negate ()
1018 {
1019
1020 this.x = - this.x;
1021 this.y = - this.y;
1022
1023 return this;
1024
1025 }
1026
1027 dot (v)
1028 {
1029
1030 return this.x * v.x + this.y * v.y;
1031
1032 }
1033
1034 cross (v)
1035 {
1036
1037 return this.x * v.y - this.y * v.x;
1038
1039 }
1040
1041 lengthSq ()
1042 {
1043
1044 return this.x * this.x + this.y * this.y;
1045
1046 }
1047
1048 length ()
1049 {
1050
1051 return Math.sqrt(this.x * this.x + this.y * this.y);
1052
1053 }
1054
1055 manhattanLength ()
1056 {
1057
1058 return Math.abs(this.x) + Math.abs(this.y);
1059
1060 }
1061
1062 normalize ()
1063 {
1064
1065 return this.divideScalar(this.length() || 1);
1066
1067 }
1068
1069 angle ()
1070 {
1071
1072 // computes the angle in radians with respect to the positive x-axis
1073
1074 const angle = Math.atan2(- this.y, - this.x) + Math.PI;
1075
1076 return angle;
1077
1078 }
1079
1080 angleTo (v)
1081 {
1082
1083 const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
1084
1085 if (denominator === 0) return Math.PI / 2;
1086
1087 const theta = this.dot(v) / denominator;
1088
1089 // clamp, to handle numerical problems
1090
1091 return Math.acos(clamp(theta, - 1, 1));
1092
1093 }
1094
1095 distanceTo (v)
1096 {
1097
1098 return Math.sqrt(this.distanceToSquared(v));
1099
1100 }
1101
1102 distanceToSquared (v)
1103 {
1104
1105 const dx = this.x - v.x, dy = this.y - v.y;
1106 return dx * dx + dy * dy;
1107
1108 }
1109
1110 manhattanDistanceTo (v)
1111 {
1112
1113 return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
1114
1115 }
1116
1117 setLength (length)
1118 {
1119
1120 return this.normalize().multiplyScalar(length);
1121
1122 }
1123
1124 lerp (v, alpha)
1125 {
1126
1127 this.x += (v.x - this.x) * alpha;
1128 this.y += (v.y - this.y) * alpha;
1129
1130 return this;
1131
1132 }
1133
1134 lerpVectors (v1, v2, alpha)
1135 {
1136
1137 this.x = v1.x + (v2.x - v1.x) * alpha;
1138 this.y = v1.y + (v2.y - v1.y) * alpha;
1139
1140 return this;
1141
1142 }
1143
1144 equals (v)
1145 {
1146
1147 return ((v.x === this.x) && (v.y === this.y));
1148
1149 }
1150
1151 fromArray (array, offset = 0)
1152 {
1153
1154 this.x = array[offset];
1155 this.y = array[offset + 1];
1156
1157 return this;
1158
1159 }
1160
1161 toArray (array = [], offset = 0)
1162 {
1163
1164 array[offset] = this.x;
1165 array[offset + 1] = this.y;
1166
1167 return array;
1168
1169 }
1170
1171 fromBufferAttribute (attribute, index)
1172 {
1173
1174 this.x = attribute.getX(index);
1175 this.y = attribute.getY(index);
1176
1177 return this;
1178
1179 }
1180
1181 rotateAround (center, angle)
1182 {
1183
1184 const c = Math.cos(angle), s = Math.sin(angle);
1185
1186 const x = this.x - center.x;
1187 const y = this.y - center.y;
1188
1189 this.x = x * c - y * s + center.x;
1190 this.y = x * s + y * c + center.y;
1191
1192 return this;
1193
1194 }
1195
1196 random ()
1197 {
1198
1199 this.x = Math.random();
1200 this.y = Math.random();
1201
1202 return this;
1203
1204 }
1205
1206 *[Symbol.iterator] ()
1207 {
1208
1209 yield this.x;
1210 yield this.y;
1211
1212 }
1213
1214}
1215
1216class Matrix3
1217{
1218
1219 constructor(n11, n12, n13, n21, n22, n23, n31, n32, n33)
1220 {
1221
1222 Matrix3.prototype.isMatrix3 = true;
1223
1224 this.elements = [
1225
1226 1, 0, 0,
1227 0, 1, 0,
1228 0, 0, 1
1229
1230 ];
1231
1232 if (n11 !== undefined)
1233 {
1234
1235 this.set(n11, n12, n13, n21, n22, n23, n31, n32, n33);
1236
1237 }
1238
1239 }
1240
1241 set (n11, n12, n13, n21, n22, n23, n31, n32, n33)
1242 {
1243
1244 const te = this.elements;
1245
1246 te[0] = n11; te[1] = n21; te[2] = n31;
1247 te[3] = n12; te[4] = n22; te[5] = n32;
1248 te[6] = n13; te[7] = n23; te[8] = n33;
1249
1250 return this;
1251
1252 }
1253
1254 identity ()
1255 {
1256
1257 this.set(
1258
1259 1, 0, 0,
1260 0, 1, 0,
1261 0, 0, 1
1262
1263 );
1264
1265 return this;
1266
1267 }
1268
1269 copy (m)
1270 {
1271
1272 const te = this.elements;
1273 const me = m.elements;
1274
1275 te[0] = me[0]; te[1] = me[1]; te[2] = me[2];
1276 te[3] = me[3]; te[4] = me[4]; te[5] = me[5];
1277 te[6] = me[6]; te[7] = me[7]; te[8] = me[8];
1278
1279 return this;
1280
1281 }
1282
1283 extractBasis (xAxis, yAxis, zAxis)
1284 {
1285
1286 xAxis.setFromMatrix3Column(this, 0);
1287 yAxis.setFromMatrix3Column(this, 1);
1288 zAxis.setFromMatrix3Column(this, 2);
1289
1290 return this;
1291
1292 }
1293
1294 setFromMatrix4 (m)
1295 {
1296
1297 const me = m.elements;
1298
1299 this.set(
1300
1301 me[0], me[4], me[8],
1302 me[1], me[5], me[9],
1303 me[2], me[6], me[10]
1304
1305 );
1306
1307 return this;
1308
1309 }
1310
1311 multiply (m)
1312 {
1313
1314 return this.multiplyMatrices(this, m);
1315
1316 }
1317
1318 premultiply (m)
1319 {
1320
1321 return this.multiplyMatrices(m, this);
1322
1323 }
1324
1325 multiplyMatrices (a, b)
1326 {
1327
1328 const ae = a.elements;
1329 const be = b.elements;
1330 const te = this.elements;
1331
1332 const a11 = ae[0], a12 = ae[3], a13 = ae[6];
1333 const a21 = ae[1], a22 = ae[4], a23 = ae[7];
1334 const a31 = ae[2], a32 = ae[5], a33 = ae[8];
1335
1336 const b11 = be[0], b12 = be[3], b13 = be[6];
1337 const b21 = be[1], b22 = be[4], b23 = be[7];
1338 const b31 = be[2], b32 = be[5], b33 = be[8];
1339
1340 te[0] = a11 * b11 + a12 * b21 + a13 * b31;
1341 te[3] = a11 * b12 + a12 * b22 + a13 * b32;
1342 te[6] = a11 * b13 + a12 * b23 + a13 * b33;
1343
1344 te[1] = a21 * b11 + a22 * b21 + a23 * b31;
1345 te[4] = a21 * b12 + a22 * b22 + a23 * b32;
1346 te[7] = a21 * b13 + a22 * b23 + a23 * b33;
1347
1348 te[2] = a31 * b11 + a32 * b21 + a33 * b31;
1349 te[5] = a31 * b12 + a32 * b22 + a33 * b32;
1350 te[8] = a31 * b13 + a32 * b23 + a33 * b33;
1351
1352 return this;
1353
1354 }
1355
1356 multiplyScalar (s)
1357 {
1358
1359 const te = this.elements;
1360
1361 te[0] *= s; te[3] *= s; te[6] *= s;
1362 te[1] *= s; te[4] *= s; te[7] *= s;
1363 te[2] *= s; te[5] *= s; te[8] *= s;
1364
1365 return this;
1366
1367 }
1368
1369 determinant ()
1370 {
1371
1372 const te = this.elements;
1373
1374 const a = te[0], b = te[1], c = te[2],
1375 d = te[3], e = te[4], f = te[5],
1376 g = te[6], h = te[7], i = te[8];
1377
1378 return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
1379
1380 }
1381
1382 invert ()
1383 {
1384
1385 const te = this.elements,
1386
1387 n11 = te[0], n21 = te[1], n31 = te[2],
1388 n12 = te[3], n22 = te[4], n32 = te[5],
1389 n13 = te[6], n23 = te[7], n33 = te[8],
1390
1391 t11 = n33 * n22 - n32 * n23,
1392 t12 = n32 * n13 - n33 * n12,
1393 t13 = n23 * n12 - n22 * n13,
1394
1395 det = n11 * t11 + n21 * t12 + n31 * t13;
1396
1397 if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
1398
1399 const detInv = 1 / det;
1400
1401 te[0] = t11 * detInv;
1402 te[1] = (n31 * n23 - n33 * n21) * detInv;
1403 te[2] = (n32 * n21 - n31 * n22) * detInv;
1404
1405 te[3] = t12 * detInv;
1406 te[4] = (n33 * n11 - n31 * n13) * detInv;
1407 te[5] = (n31 * n12 - n32 * n11) * detInv;
1408
1409 te[6] = t13 * detInv;
1410 te[7] = (n21 * n13 - n23 * n11) * detInv;
1411 te[8] = (n22 * n11 - n21 * n12) * detInv;
1412
1413 return this;
1414
1415 }
1416
1417 transpose ()
1418 {
1419
1420 let tmp;
1421 const m = this.elements;
1422
1423 tmp = m[1]; m[1] = m[3]; m[3] = tmp;
1424 tmp = m[2]; m[2] = m[6]; m[6] = tmp;
1425 tmp = m[5]; m[5] = m[7]; m[7] = tmp;
1426
1427 return this;
1428
1429 }
1430
1431 getNormalMatrix (matrix4)
1432 {
1433
1434 return this.setFromMatrix4(matrix4).invert().transpose();
1435
1436 }
1437
1438 transposeIntoArray (r)
1439 {
1440
1441 const m = this.elements;
1442
1443 r[0] = m[0];
1444 r[1] = m[3];
1445 r[2] = m[6];
1446 r[3] = m[1];
1447 r[4] = m[4];
1448 r[5] = m[7];
1449 r[6] = m[2];
1450 r[7] = m[5];
1451 r[8] = m[8];
1452
1453 return this;
1454
1455 }
1456
1457 setUvTransform (tx, ty, sx, sy, rotation, cx, cy)
1458 {
1459
1460 const c = Math.cos(rotation);
1461 const s = Math.sin(rotation);
1462
1463 this.set(
1464 sx * c, sx * s, - sx * (c * cx + s * cy) + cx + tx,
1465 - sy * s, sy * c, - sy * (- s * cx + c * cy) + cy + ty,
1466 0, 0, 1
1467 );
1468
1469 return this;
1470
1471 }
1472
1473 //
1474
1475 scale (sx, sy)
1476 {
1477
1478 this.premultiply(_m3.makeScale(sx, sy));
1479
1480 return this;
1481
1482 }
1483
1484 rotate (theta)
1485 {
1486
1487 this.premultiply(_m3.makeRotation(- theta));
1488
1489 return this;
1490
1491 }
1492
1493 translate (tx, ty)
1494 {
1495
1496 this.premultiply(_m3.makeTranslation(tx, ty));
1497
1498 return this;
1499
1500 }
1501
1502 // for 2D Transforms
1503
1504 makeTranslation (x, y)
1505 {
1506
1507 if (x.isVector2)
1508 {
1509
1510 this.set(
1511
1512 1, 0, x.x,
1513 0, 1, x.y,
1514 0, 0, 1
1515
1516 );
1517
1518 } else
1519 {
1520
1521 this.set(
1522
1523 1, 0, x,
1524 0, 1, y,
1525 0, 0, 1
1526
1527 );
1528
1529 }
1530
1531 return this;
1532
1533 }
1534
1535 makeRotation (theta)
1536 {
1537
1538 // counterclockwise
1539
1540 const c = Math.cos(theta);
1541 const s = Math.sin(theta);
1542
1543 this.set(
1544
1545 c, - s, 0,
1546 s, c, 0,
1547 0, 0, 1
1548
1549 );
1550
1551 return this;
1552
1553 }
1554
1555 makeScale (x, y)
1556 {
1557
1558 this.set(
1559
1560 x, 0, 0,
1561 0, y, 0,
1562 0, 0, 1
1563
1564 );
1565
1566 return this;
1567
1568 }
1569
1570 //
1571
1572 equals (matrix)
1573 {
1574
1575 const te = this.elements;
1576 const me = matrix.elements;
1577
1578 for (let i = 0; i < 9; i++)
1579 {
1580
1581 if (te[i] !== me[i]) return false;
1582
1583 }
1584
1585 return true;
1586
1587 }
1588
1589 fromArray (array, offset = 0)
1590 {
1591
1592 for (let i = 0; i < 9; i++)
1593 {
1594
1595 this.elements[i] = array[i + offset];
1596
1597 }
1598
1599 return this;
1600
1601 }
1602
1603 toArray (array = [], offset = 0)
1604 {
1605
1606 const te = this.elements;
1607
1608 array[offset] = te[0];
1609 array[offset + 1] = te[1];
1610 array[offset + 2] = te[2];
1611
1612 array[offset + 3] = te[3];
1613 array[offset + 4] = te[4];
1614 array[offset + 5] = te[5];
1615
1616 array[offset + 6] = te[6];
1617 array[offset + 7] = te[7];
1618 array[offset + 8] = te[8];
1619
1620 return array;
1621
1622 }
1623
1624 clone ()
1625 {
1626
1627 return new this.constructor().fromArray(this.elements);
1628
1629 }
1630
1631}
1632
1633const _m3 = /*@__PURE__*/ new Matrix3();
1634
1635function arrayNeedsUint32 (array)
1636{
1637
1638 // assumes larger values usually on last
1639
1640 for (let i = array.length - 1; i >= 0; --i)
1641 {
1642
1643 if (array[i] >= 65535) return true; // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565
1644
1645 }
1646
1647 return false;
1648
1649}
1650
1651const TYPED_ARRAYS = {
1652 Int8Array: Int8Array,
1653 Uint8Array: Uint8Array,
1654 Uint8ClampedArray: Uint8ClampedArray,
1655 Int16Array: Int16Array,
1656 Uint16Array: Uint16Array,
1657 Int32Array: Int32Array,
1658 Uint32Array: Uint32Array,
1659 Float32Array: Float32Array,
1660 Float64Array: Float64Array
1661};
1662
1663function getTypedArray (type, buffer)
1664{
1665
1666 return new TYPED_ARRAYS[type](buffer);
1667
1668}
1669
1670function createElementNS (name)
1671{
1672
1673 return document.createElementNS('http://www.w3.org/1999/xhtml', name);
1674
1675}
1676
1677function createCanvasElement ()
1678{
1679
1680 const canvas = createElementNS('canvas');
1681 canvas.style.display = 'block';
1682 return canvas;
1683
1684}
1685
1686const _cache = {};
1687
1688function warnOnce (message)
1689{
1690
1691 if (message in _cache) return;
1692
1693 _cache[message] = true;
1694
1695 console.warn(message);
1696
1697}
1698
1699function probeAsync (gl, sync, interval)
1700{
1701
1702 return new Promise(function (resolve, reject)
1703 {
1704
1705 function probe ()
1706 {
1707
1708 switch (gl.clientWaitSync(sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0))
1709 {
1710
1711 case gl.WAIT_FAILED:
1712 reject();
1713 break;
1714
1715 case gl.TIMEOUT_EXPIRED:
1716 setTimeout(probe, interval);
1717 break;
1718
1719 default:
1720 resolve();
1721
1722 }
1723
1724 }
1725
1726 setTimeout(probe, interval);
1727
1728 });
1729
1730}
1731
1732/**
1733 * Matrices converting P3 <-> Rec. 709 primaries, without gamut mapping
1734 * or clipping. Based on W3C specifications for sRGB and Display P3,
1735 * and ICC specifications for the D50 connection space. Values in/out
1736 * are _linear_ sRGB and _linear_ Display P3.
1737 *
1738 * Note that both sRGB and Display P3 use the sRGB transfer functions.
1739 *
1740 * Reference:
1741 * - http://www.russellcottrell.com/photo/matrixCalculator.htm
1742 */
1743
1744const LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = /*@__PURE__*/ new Matrix3().set(
1745 0.8224621, 0.177538, 0.0,
1746 0.0331941, 0.9668058, 0.0,
1747 0.0170827, 0.0723974, 0.9105199,
1748);
1749
1750const LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = /*@__PURE__*/ new Matrix3().set(
1751 1.2249401, - 0.2249404, 0.0,
1752 - 0.0420569, 1.0420571, 0.0,
1753 - 0.0196376, - 0.0786361, 1.0982735
1754);
1755
1756/**
1757 * Defines supported color spaces by transfer function and primaries,
1758 * and provides conversions to/from the Linear-sRGB reference space.
1759 */
1760const COLOR_SPACES = {
1761 [LinearSRGBColorSpace]: {
1762 transfer: LinearTransfer,
1763 primaries: Rec709Primaries,
1764 toReference: (color) => color,
1765 fromReference: (color) => color,
1766 },
1767 [SRGBColorSpace]: {
1768 transfer: SRGBTransfer,
1769 primaries: Rec709Primaries,
1770 toReference: (color) => color.convertSRGBToLinear(),
1771 fromReference: (color) => color.convertLinearToSRGB(),
1772 },
1773 [LinearDisplayP3ColorSpace]: {
1774 transfer: LinearTransfer,
1775 primaries: P3Primaries,
1776 toReference: (color) => color.applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB),
1777 fromReference: (color) => color.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P3),
1778 },
1779 [DisplayP3ColorSpace]: {
1780 transfer: SRGBTransfer,
1781 primaries: P3Primaries,
1782 toReference: (color) => color.convertSRGBToLinear().applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB),
1783 fromReference: (color) => color.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P3).convertLinearToSRGB(),
1784 },
1785};
1786
1787const SUPPORTED_WORKING_COLOR_SPACES = new Set([LinearSRGBColorSpace, LinearDisplayP3ColorSpace]);
1788
1789const ColorManagement = {
1790
1791 enabled: true,
1792
1793 _workingColorSpace: LinearSRGBColorSpace,
1794
1795 get workingColorSpace ()
1796 {
1797
1798 return this._workingColorSpace;
1799
1800 },
1801
1802 set workingColorSpace (colorSpace)
1803 {
1804
1805 if (!SUPPORTED_WORKING_COLOR_SPACES.has(colorSpace))
1806 {
1807
1808 throw new Error(`Unsupported working color space, "${colorSpace}".`);
1809
1810 }
1811
1812 this._workingColorSpace = colorSpace;
1813
1814 },
1815
1816 convert: function (color, sourceColorSpace, targetColorSpace)
1817 {
1818
1819 if (this.enabled === false || sourceColorSpace === targetColorSpace || !sourceColorSpace || !targetColorSpace)
1820 {
1821
1822 return color;
1823
1824 }
1825
1826 const sourceToReference = COLOR_SPACES[sourceColorSpace].toReference;
1827 const targetFromReference = COLOR_SPACES[targetColorSpace].fromReference;
1828
1829 return targetFromReference(sourceToReference(color));
1830
1831 },
1832
1833 fromWorkingColorSpace: function (color, targetColorSpace)
1834 {
1835
1836 return this.convert(color, this._workingColorSpace, targetColorSpace);
1837
1838 },
1839
1840 toWorkingColorSpace: function (color, sourceColorSpace)
1841 {
1842
1843 return this.convert(color, sourceColorSpace, this._workingColorSpace);
1844
1845 },
1846
1847 getPrimaries: function (colorSpace)
1848 {
1849
1850 return COLOR_SPACES[colorSpace].primaries;
1851
1852 },
1853
1854 getTransfer: function (colorSpace)
1855 {
1856
1857 if (colorSpace === NoColorSpace) return LinearTransfer;
1858
1859 return COLOR_SPACES[colorSpace].transfer;
1860
1861 },
1862
1863};
1864
1865
1866function SRGBToLinear (c)
1867{
1868
1869 return (c < 0.04045) ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
1870
1871}
1872
1873function LinearToSRGB (c)
1874{
1875
1876 return (c < 0.0031308) ? c * 12.92 : 1.055 * (Math.pow(c, 0.41666)) - 0.055;
1877
1878}
1879
1880let _canvas;
1881
1882class ImageUtils
1883{
1884
1885 static getDataURL (image)
1886 {
1887
1888 if (/^data:/i.test(image.src))
1889 {
1890
1891 return image.src;
1892
1893 }
1894
1895 if (typeof HTMLCanvasElement === 'undefined')
1896 {
1897
1898 return image.src;
1899
1900 }
1901
1902 let canvas;
1903
1904 if (image instanceof HTMLCanvasElement)
1905 {
1906
1907 canvas = image;
1908
1909 } else
1910 {
1911
1912 if (_canvas === undefined) _canvas = createElementNS('canvas');
1913
1914 _canvas.width = image.width;
1915 _canvas.height = image.height;
1916
1917 const context = _canvas.getContext('2d');
1918
1919 if (image instanceof ImageData)
1920 {
1921
1922 context.putImageData(image, 0, 0);
1923
1924 } else
1925 {
1926
1927 context.drawImage(image, 0, 0, image.width, image.height);
1928
1929 }
1930
1931 canvas = _canvas;
1932
1933 }
1934
1935 if (canvas.width > 2048 || canvas.height > 2048)
1936 {
1937
1938 console.warn('THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image);
1939
1940 return canvas.toDataURL('image/jpeg', 0.6);
1941
1942 } else
1943 {
1944
1945 return canvas.toDataURL('image/png');
1946
1947 }
1948
1949 }
1950
1951 static sRGBToLinear (image)
1952 {
1953
1954 if ((typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement) ||
1955 (typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement) ||
1956 (typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap))
1957 {
1958
1959 const canvas = createElementNS('canvas');
1960
1961 canvas.width = image.width;
1962 canvas.height = image.height;
1963
1964 const context = canvas.getContext('2d');
1965 context.drawImage(image, 0, 0, image.width, image.height);
1966
1967 const imageData = context.getImageData(0, 0, image.width, image.height);
1968 const data = imageData.data;
1969
1970 for (let i = 0; i < data.length; i++)
1971 {
1972
1973 data[i] = SRGBToLinear(data[i] / 255) * 255;
1974
1975 }
1976
1977 context.putImageData(imageData, 0, 0);
1978
1979 return canvas;
1980
1981 } else if (image.data)
1982 {
1983
1984 const data = image.data.slice(0);
1985
1986 for (let i = 0; i < data.length; i++)
1987 {
1988
1989 if (data instanceof Uint8Array || data instanceof Uint8ClampedArray)
1990 {
1991
1992 data[i] = Math.floor(SRGBToLinear(data[i] / 255) * 255);
1993
1994 } else
1995 {
1996
1997 // assuming float
1998
1999 data[i] = SRGBToLinear(data[i]);
2000
2001 }
2002
2003 }
2004
2005 return {
2006 data: data,
2007 width: image.width,
2008 height: image.height
2009 };
2010
2011 } else
2012 {
2013
2014 console.warn('THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.');
2015 return image;
2016
2017 }
2018
2019 }
2020
2021}
2022
2023let _sourceId = 0;
2024
2025class Source
2026{
2027
2028 constructor(data = null)
2029 {
2030
2031 this.isSource = true;
2032
2033 Object.defineProperty(this, 'id', { value: _sourceId++ });
2034
2035 this.uuid = generateUUID();
2036
2037 this.data = data;
2038 this.dataReady = true;
2039
2040 this.version = 0;
2041
2042 }
2043
2044 set needsUpdate (value)
2045 {
2046
2047 if (value === true) this.version++;
2048
2049 }
2050
2051 toJSON (meta)
2052 {
2053
2054 const isRootObject = (meta === undefined || typeof meta === 'string');
2055
2056 if (!isRootObject && meta.images[this.uuid] !== undefined)
2057 {
2058
2059 return meta.images[this.uuid];
2060
2061 }
2062
2063 const output = {
2064 uuid: this.uuid,
2065 url: ''
2066 };
2067
2068 const data = this.data;
2069
2070 if (data !== null)
2071 {
2072
2073 let url;
2074
2075 if (Array.isArray(data))
2076 {
2077
2078 // cube texture
2079
2080 url = [];
2081
2082 for (let i = 0, l = data.length; i < l; i++)
2083 {
2084
2085 if (data[i].isDataTexture)
2086 {
2087
2088 url.push(serializeImage(data[i].image));
2089
2090 } else
2091 {
2092
2093 url.push(serializeImage(data[i]));
2094
2095 }
2096
2097 }
2098
2099 } else
2100 {
2101
2102 // texture
2103
2104 url = serializeImage(data);
2105
2106 }
2107
2108 output.url = url;
2109
2110 }
2111
2112 if (!isRootObject)
2113 {
2114
2115 meta.images[this.uuid] = output;
2116
2117 }
2118
2119 return output;
2120
2121 }
2122
2123}
2124
2125function serializeImage (image)
2126{
2127
2128 if ((typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement) ||
2129 (typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement) ||
2130 (typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap))
2131 {
2132
2133 // default images
2134
2135 return ImageUtils.getDataURL(image);
2136
2137 } else
2138 {
2139
2140 if (image.data)
2141 {
2142
2143 // images of DataTexture
2144
2145 return {
2146 data: Array.from(image.data),
2147 width: image.width,
2148 height: image.height,
2149 type: image.data.constructor.name
2150 };
2151
2152 } else
2153 {
2154
2155 console.warn('THREE.Texture: Unable to serialize Texture.');
2156 return {};
2157
2158 }
2159
2160 }
2161
2162}
2163
2164let _textureId = 0;
2165
2166class Texture extends EventDispatcher
2167{
2168
2169 constructor(image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace)
2170 {
2171
2172 super();
2173
2174 this.isTexture = true;
2175
2176 Object.defineProperty(this, 'id', { value: _textureId++ });
2177
2178 this.uuid = generateUUID();
2179
2180 this.name = '';
2181
2182 this.source = new Source(image);
2183 this.mipmaps = [];
2184
2185 this.mapping = mapping;
2186 this.channel = 0;
2187
2188 this.wrapS = wrapS;
2189 this.wrapT = wrapT;
2190
2191 this.magFilter = magFilter;
2192 this.minFilter = minFilter;
2193
2194 this.anisotropy = anisotropy;
2195
2196 this.format = format;
2197 this.internalFormat = null;
2198 this.type = type;
2199
2200 this.offset = new Vector2(0, 0);
2201 this.repeat = new Vector2(1, 1);
2202 this.center = new Vector2(0, 0);
2203 this.rotation = 0;
2204
2205 this.matrixAutoUpdate = true;
2206 this.matrix = new Matrix3();
2207
2208 this.generateMipmaps = true;
2209 this.premultiplyAlpha = false;
2210 this.flipY = true;
2211 this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
2212
2213 this.colorSpace = colorSpace;
2214
2215 this.userData = {};
2216
2217 this.version = 0;
2218 this.onUpdate = null;
2219
2220 this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not
2221 this.pmremVersion = 0; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)
2222
2223 }
2224
2225 get image ()
2226 {
2227
2228 return this.source.data;
2229
2230 }
2231
2232 set image (value = null)
2233 {
2234
2235 this.source.data = value;
2236
2237 }
2238
2239 updateMatrix ()
2240 {
2241
2242 this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
2243
2244 }
2245
2246 clone ()
2247 {
2248
2249 return new this.constructor().copy(this);
2250
2251 }
2252
2253 copy (source)
2254 {
2255
2256 this.name = source.name;
2257
2258 this.source = source.source;
2259 this.mipmaps = source.mipmaps.slice(0);
2260
2261 this.mapping = source.mapping;
2262 this.channel = source.channel;
2263
2264 this.wrapS = source.wrapS;
2265 this.wrapT = source.wrapT;
2266
2267 this.magFilter = source.magFilter;
2268 this.minFilter = source.minFilter;
2269
2270 this.anisotropy = source.anisotropy;
2271
2272 this.format = source.format;
2273 this.internalFormat = source.internalFormat;
2274 this.type = source.type;
2275
2276 this.offset.copy(source.offset);
2277 this.repeat.copy(source.repeat);
2278 this.center.copy(source.center);
2279 this.rotation = source.rotation;
2280
2281 this.matrixAutoUpdate = source.matrixAutoUpdate;
2282 this.matrix.copy(source.matrix);
2283
2284 this.generateMipmaps = source.generateMipmaps;
2285 this.premultiplyAlpha = source.premultiplyAlpha;
2286 this.flipY = source.flipY;
2287 this.unpackAlignment = source.unpackAlignment;
2288 this.colorSpace = source.colorSpace;
2289
2290 this.userData = JSON.parse(JSON.stringify(source.userData));
2291
2292 this.needsUpdate = true;
2293
2294 return this;
2295
2296 }
2297
2298 toJSON (meta)
2299 {
2300
2301 const isRootObject = (meta === undefined || typeof meta === 'string');
2302
2303 if (!isRootObject && meta.textures[this.uuid] !== undefined)
2304 {
2305
2306 return meta.textures[this.uuid];
2307
2308 }
2309
2310 const output = {
2311
2312 metadata: {
2313 version: 4.6,
2314 type: 'Texture',
2315 generator: 'Texture.toJSON'
2316 },
2317
2318 uuid: this.uuid,
2319 name: this.name,
2320
2321 image: this.source.toJSON(meta).uuid,
2322
2323 mapping: this.mapping,
2324 channel: this.channel,
2325
2326 repeat: [this.repeat.x, this.repeat.y],
2327 offset: [this.offset.x, this.offset.y],
2328 center: [this.center.x, this.center.y],
2329 rotation: this.rotation,
2330
2331 wrap: [this.wrapS, this.wrapT],
2332
2333 format: this.format,
2334 internalFormat: this.internalFormat,
2335 type: this.type,
2336 colorSpace: this.colorSpace,
2337
2338 minFilter: this.minFilter,
2339 magFilter: this.magFilter,
2340 anisotropy: this.anisotropy,
2341
2342 flipY: this.flipY,
2343
2344 generateMipmaps: this.generateMipmaps,
2345 premultiplyAlpha: this.premultiplyAlpha,
2346 unpackAlignment: this.unpackAlignment
2347
2348 };
2349
2350 if (Object.keys(this.userData).length > 0) output.userData = this.userData;
2351
2352 if (!isRootObject)
2353 {
2354
2355 meta.textures[this.uuid] = output;
2356
2357 }
2358
2359 return output;
2360
2361 }
2362
2363 dispose ()
2364 {
2365
2366 this.dispatchEvent({ type: 'dispose' });
2367
2368 }
2369
2370 transformUv (uv)
2371 {
2372
2373 if (this.mapping !== UVMapping) return uv;
2374
2375 uv.applyMatrix3(this.matrix);
2376
2377 if (uv.x < 0 || uv.x > 1)
2378 {
2379
2380 switch (this.wrapS)
2381 {
2382
2383 case RepeatWrapping:
2384
2385 uv.x = uv.x - Math.floor(uv.x);
2386 break;
2387
2388 case ClampToEdgeWrapping:
2389
2390 uv.x = uv.x < 0 ? 0 : 1;
2391 break;
2392
2393 case MirroredRepeatWrapping:
2394
2395 if (Math.abs(Math.floor(uv.x) % 2) === 1)
2396 {
2397
2398 uv.x = Math.ceil(uv.x) - uv.x;
2399
2400 } else
2401 {
2402
2403 uv.x = uv.x - Math.floor(uv.x);
2404
2405 }
2406
2407 break;
2408
2409 }
2410
2411 }
2412
2413 if (uv.y < 0 || uv.y > 1)
2414 {
2415
2416 switch (this.wrapT)
2417 {
2418
2419 case RepeatWrapping:
2420
2421 uv.y = uv.y - Math.floor(uv.y);
2422 break;
2423
2424 case ClampToEdgeWrapping:
2425
2426 uv.y = uv.y < 0 ? 0 : 1;
2427 break;
2428
2429 case MirroredRepeatWrapping:
2430
2431 if (Math.abs(Math.floor(uv.y) % 2) === 1)
2432 {
2433
2434 uv.y = Math.ceil(uv.y) - uv.y;
2435
2436 } else
2437 {
2438
2439 uv.y = uv.y - Math.floor(uv.y);
2440
2441 }
2442
2443 break;
2444
2445 }
2446
2447 }
2448
2449 if (this.flipY)
2450 {
2451
2452 uv.y = 1 - uv.y;
2453
2454 }
2455
2456 return uv;
2457
2458 }
2459
2460 set needsUpdate (value)
2461 {
2462
2463 if (value === true)
2464 {
2465
2466 this.version++;
2467 this.source.needsUpdate = true;
2468
2469 }
2470
2471 }
2472
2473 set needsPMREMUpdate (value)
2474 {
2475
2476 if (value === true)
2477 {
2478
2479 this.pmremVersion++;
2480
2481 }
2482
2483 }
2484
2485}
2486
2487Texture.DEFAULT_IMAGE = null;
2488Texture.DEFAULT_MAPPING = UVMapping;
2489Texture.DEFAULT_ANISOTROPY = 1;
2490
2491class Vector4
2492{
2493
2494 constructor(x = 0, y = 0, z = 0, w = 1)
2495 {
2496
2497 Vector4.prototype.isVector4 = true;
2498
2499 this.x = x;
2500 this.y = y;
2501 this.z = z;
2502 this.w = w;
2503
2504 }
2505
2506 get width ()
2507 {
2508
2509 return this.z;
2510
2511 }
2512
2513 set width (value)
2514 {
2515
2516 this.z = value;
2517
2518 }
2519
2520 get height ()
2521 {
2522
2523 return this.w;
2524
2525 }
2526
2527 set height (value)
2528 {
2529
2530 this.w = value;
2531
2532 }
2533
2534 set (x, y, z, w)
2535 {
2536
2537 this.x = x;
2538 this.y = y;
2539 this.z = z;
2540 this.w = w;
2541
2542 return this;
2543
2544 }
2545
2546 setScalar (scalar)
2547 {
2548
2549 this.x = scalar;
2550 this.y = scalar;
2551 this.z = scalar;
2552 this.w = scalar;
2553
2554 return this;
2555
2556 }
2557
2558 setX (x)
2559 {
2560
2561 this.x = x;
2562
2563 return this;
2564
2565 }
2566
2567 setY (y)
2568 {
2569
2570 this.y = y;
2571
2572 return this;
2573
2574 }
2575
2576 setZ (z)
2577 {
2578
2579 this.z = z;
2580
2581 return this;
2582
2583 }
2584
2585 setW (w)
2586 {
2587
2588 this.w = w;
2589
2590 return this;
2591
2592 }
2593
2594 setComponent (index, value)
2595 {
2596
2597 switch (index)
2598 {
2599
2600 case 0: this.x = value; break;
2601 case 1: this.y = value; break;
2602 case 2: this.z = value; break;
2603 case 3: this.w = value; break;
2604 default: throw new Error('index is out of range: ' + index);
2605
2606 }
2607
2608 return this;
2609
2610 }
2611
2612 getComponent (index)
2613 {
2614
2615 switch (index)
2616 {
2617
2618 case 0: return this.x;
2619 case 1: return this.y;
2620 case 2: return this.z;
2621 case 3: return this.w;
2622 default: throw new Error('index is out of range: ' + index);
2623
2624 }
2625
2626 }
2627
2628 clone ()
2629 {
2630
2631 return new this.constructor(this.x, this.y, this.z, this.w);
2632
2633 }
2634
2635 copy (v)
2636 {
2637
2638 this.x = v.x;
2639 this.y = v.y;
2640 this.z = v.z;
2641 this.w = (v.w !== undefined) ? v.w : 1;
2642
2643 return this;
2644
2645 }
2646
2647 add (v)
2648 {
2649
2650 this.x += v.x;
2651 this.y += v.y;
2652 this.z += v.z;
2653 this.w += v.w;
2654
2655 return this;
2656
2657 }
2658
2659 addScalar (s)
2660 {
2661
2662 this.x += s;
2663 this.y += s;
2664 this.z += s;
2665 this.w += s;
2666
2667 return this;
2668
2669 }
2670
2671 addVectors (a, b)
2672 {
2673
2674 this.x = a.x + b.x;
2675 this.y = a.y + b.y;
2676 this.z = a.z + b.z;
2677 this.w = a.w + b.w;
2678
2679 return this;
2680
2681 }
2682
2683 addScaledVector (v, s)
2684 {
2685
2686 this.x += v.x * s;
2687 this.y += v.y * s;
2688 this.z += v.z * s;
2689 this.w += v.w * s;
2690
2691 return this;
2692
2693 }
2694
2695 sub (v)
2696 {
2697
2698 this.x -= v.x;
2699 this.y -= v.y;
2700 this.z -= v.z;
2701 this.w -= v.w;
2702
2703 return this;
2704
2705 }
2706
2707 subScalar (s)
2708 {
2709
2710 this.x -= s;
2711 this.y -= s;
2712 this.z -= s;
2713 this.w -= s;
2714
2715 return this;
2716
2717 }
2718
2719 subVectors (a, b)
2720 {
2721
2722 this.x = a.x - b.x;
2723 this.y = a.y - b.y;
2724 this.z = a.z - b.z;
2725 this.w = a.w - b.w;
2726
2727 return this;
2728
2729 }
2730
2731 multiply (v)
2732 {
2733
2734 this.x *= v.x;
2735 this.y *= v.y;
2736 this.z *= v.z;
2737 this.w *= v.w;
2738
2739 return this;
2740
2741 }
2742
2743 multiplyScalar (scalar)
2744 {
2745
2746 this.x *= scalar;
2747 this.y *= scalar;
2748 this.z *= scalar;
2749 this.w *= scalar;
2750
2751 return this;
2752
2753 }
2754
2755 applyMatrix4 (m)
2756 {
2757
2758 const x = this.x, y = this.y, z = this.z, w = this.w;
2759 const e = m.elements;
2760
2761 this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
2762 this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
2763 this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
2764 this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
2765
2766 return this;
2767
2768 }
2769
2770 divideScalar (scalar)
2771 {
2772
2773 return this.multiplyScalar(1 / scalar);
2774
2775 }
2776
2777 setAxisAngleFromQuaternion (q)
2778 {
2779
2780 // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
2781
2782 // q is assumed to be normalized
2783
2784 this.w = 2 * Math.acos(q.w);
2785
2786 const s = Math.sqrt(1 - q.w * q.w);
2787
2788 if (s < 0.0001)
2789 {
2790
2791 this.x = 1;
2792 this.y = 0;
2793 this.z = 0;
2794
2795 } else
2796 {
2797
2798 this.x = q.x / s;
2799 this.y = q.y / s;
2800 this.z = q.z / s;
2801
2802 }
2803
2804 return this;
2805
2806 }
2807
2808 setAxisAngleFromRotationMatrix (m)
2809 {
2810
2811 // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
2812
2813 // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
2814
2815 let angle, x, y, z; // variables for result
2816 const epsilon = 0.01, // margin to allow for rounding errors
2817 epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
2818
2819 te = m.elements,
2820
2821 m11 = te[0], m12 = te[4], m13 = te[8],
2822 m21 = te[1], m22 = te[5], m23 = te[9],
2823 m31 = te[2], m32 = te[6], m33 = te[10];
2824
2825 if ((Math.abs(m12 - m21) < epsilon) &&
2826 (Math.abs(m13 - m31) < epsilon) &&
2827 (Math.abs(m23 - m32) < epsilon))
2828 {
2829
2830 // singularity found
2831 // first check for identity matrix which must have +1 for all terms
2832 // in leading diagonal and zero in other terms
2833
2834 if ((Math.abs(m12 + m21) < epsilon2) &&
2835 (Math.abs(m13 + m31) < epsilon2) &&
2836 (Math.abs(m23 + m32) < epsilon2) &&
2837 (Math.abs(m11 + m22 + m33 - 3) < epsilon2))
2838 {
2839
2840 // this singularity is identity matrix so angle = 0
2841
2842 this.set(1, 0, 0, 0);
2843
2844 return this; // zero angle, arbitrary axis
2845
2846 }
2847
2848 // otherwise this singularity is angle = 180
2849
2850 angle = Math.PI;
2851
2852 const xx = (m11 + 1) / 2;
2853 const yy = (m22 + 1) / 2;
2854 const zz = (m33 + 1) / 2;
2855 const xy = (m12 + m21) / 4;
2856 const xz = (m13 + m31) / 4;
2857 const yz = (m23 + m32) / 4;
2858
2859 if ((xx > yy) && (xx > zz))
2860 {
2861
2862 // m11 is the largest diagonal term
2863
2864 if (xx < epsilon)
2865 {
2866
2867 x = 0;
2868 y = 0.707106781;
2869 z = 0.707106781;
2870
2871 } else
2872 {
2873
2874 x = Math.sqrt(xx);
2875 y = xy / x;
2876 z = xz / x;
2877
2878 }
2879
2880 } else if (yy > zz)
2881 {
2882
2883 // m22 is the largest diagonal term
2884
2885 if (yy < epsilon)
2886 {
2887
2888 x = 0.707106781;
2889 y = 0;
2890 z = 0.707106781;
2891
2892 } else
2893 {
2894
2895 y = Math.sqrt(yy);
2896 x = xy / y;
2897 z = yz / y;
2898
2899 }
2900
2901 } else
2902 {
2903
2904 // m33 is the largest diagonal term so base result on this
2905
2906 if (zz < epsilon)
2907 {
2908
2909 x = 0.707106781;
2910 y = 0.707106781;
2911 z = 0;
2912
2913 } else
2914 {
2915
2916 z = Math.sqrt(zz);
2917 x = xz / z;
2918 y = yz / z;
2919
2920 }
2921
2922 }
2923
2924 this.set(x, y, z, angle);
2925
2926 return this; // return 180 deg rotation
2927
2928 }
2929
2930 // as we have reached here there are no singularities so we can handle normally
2931
2932 let s = Math.sqrt((m32 - m23) * (m32 - m23) +
2933 (m13 - m31) * (m13 - m31) +
2934 (m21 - m12) * (m21 - m12)); // used to normalize
2935
2936 if (Math.abs(s) < 0.001) s = 1;
2937
2938 // prevent divide by zero, should not happen if matrix is orthogonal and should be
2939 // caught by singularity test above, but I've left it in just in case
2940
2941 this.x = (m32 - m23) / s;
2942 this.y = (m13 - m31) / s;
2943 this.z = (m21 - m12) / s;
2944 this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
2945
2946 return this;
2947
2948 }
2949
2950 setFromMatrixPosition (m)
2951 {
2952
2953 const e = m.elements;
2954
2955 this.x = e[12];
2956 this.y = e[13];
2957 this.z = e[14];
2958 this.w = e[15];
2959
2960 return this;
2961
2962 }
2963
2964 min (v)
2965 {
2966
2967 this.x = Math.min(this.x, v.x);
2968 this.y = Math.min(this.y, v.y);
2969 this.z = Math.min(this.z, v.z);
2970 this.w = Math.min(this.w, v.w);
2971
2972 return this;
2973
2974 }
2975
2976 max (v)
2977 {
2978
2979 this.x = Math.max(this.x, v.x);
2980 this.y = Math.max(this.y, v.y);
2981 this.z = Math.max(this.z, v.z);
2982 this.w = Math.max(this.w, v.w);
2983
2984 return this;
2985
2986 }
2987
2988 clamp (min, max)
2989 {
2990
2991 // assumes min < max, componentwise
2992
2993 this.x = Math.max(min.x, Math.min(max.x, this.x));
2994 this.y = Math.max(min.y, Math.min(max.y, this.y));
2995 this.z = Math.max(min.z, Math.min(max.z, this.z));
2996 this.w = Math.max(min.w, Math.min(max.w, this.w));
2997
2998 return this;
2999
3000 }
3001
3002 clampScalar (minVal, maxVal)
3003 {
3004
3005 this.x = Math.max(minVal, Math.min(maxVal, this.x));
3006 this.y = Math.max(minVal, Math.min(maxVal, this.y));
3007 this.z = Math.max(minVal, Math.min(maxVal, this.z));
3008 this.w = Math.max(minVal, Math.min(maxVal, this.w));
3009
3010 return this;
3011
3012 }
3013
3014 clampLength (min, max)
3015 {
3016
3017 const length = this.length();
3018
3019 return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
3020
3021 }
3022
3023 floor ()
3024 {
3025
3026 this.x = Math.floor(this.x);
3027 this.y = Math.floor(this.y);
3028 this.z = Math.floor(this.z);
3029 this.w = Math.floor(this.w);
3030
3031 return this;
3032
3033 }
3034
3035 ceil ()
3036 {
3037
3038 this.x = Math.ceil(this.x);
3039 this.y = Math.ceil(this.y);
3040 this.z = Math.ceil(this.z);
3041 this.w = Math.ceil(this.w);
3042
3043 return this;
3044
3045 }
3046
3047 round ()
3048 {
3049
3050 this.x = Math.round(this.x);
3051 this.y = Math.round(this.y);
3052 this.z = Math.round(this.z);
3053 this.w = Math.round(this.w);
3054
3055 return this;
3056
3057 }
3058
3059 roundToZero ()
3060 {
3061
3062 this.x = Math.trunc(this.x);
3063 this.y = Math.trunc(this.y);
3064 this.z = Math.trunc(this.z);
3065 this.w = Math.trunc(this.w);
3066
3067 return this;
3068
3069 }
3070
3071 negate ()
3072 {
3073
3074 this.x = - this.x;
3075 this.y = - this.y;
3076 this.z = - this.z;
3077 this.w = - this.w;
3078
3079 return this;
3080
3081 }
3082
3083 dot (v)
3084 {
3085
3086 return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
3087
3088 }
3089
3090 lengthSq ()
3091 {
3092
3093 return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
3094
3095 }
3096
3097 length ()
3098 {
3099
3100 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
3101
3102 }
3103
3104 manhattanLength ()
3105 {
3106
3107 return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
3108
3109 }
3110
3111 normalize ()
3112 {
3113
3114 return this.divideScalar(this.length() || 1);
3115
3116 }
3117
3118 setLength (length)
3119 {
3120
3121 return this.normalize().multiplyScalar(length);
3122
3123 }
3124
3125 lerp (v, alpha)
3126 {
3127
3128 this.x += (v.x - this.x) * alpha;
3129 this.y += (v.y - this.y) * alpha;
3130 this.z += (v.z - this.z) * alpha;
3131 this.w += (v.w - this.w) * alpha;
3132
3133 return this;
3134
3135 }
3136
3137 lerpVectors (v1, v2, alpha)
3138 {
3139
3140 this.x = v1.x + (v2.x - v1.x) * alpha;
3141 this.y = v1.y + (v2.y - v1.y) * alpha;
3142 this.z = v1.z + (v2.z - v1.z) * alpha;
3143 this.w = v1.w + (v2.w - v1.w) * alpha;
3144
3145 return this;
3146
3147 }
3148
3149 equals (v)
3150 {
3151
3152 return ((v.x === this.x) && (v.y === this.y) && (v.z === this.z) && (v.w === this.w));
3153
3154 }
3155
3156 fromArray (array, offset = 0)
3157 {
3158
3159 this.x = array[offset];
3160 this.y = array[offset + 1];
3161 this.z = array[offset + 2];
3162 this.w = array[offset + 3];
3163
3164 return this;
3165
3166 }
3167
3168 toArray (array = [], offset = 0)
3169 {
3170
3171 array[offset] = this.x;
3172 array[offset + 1] = this.y;
3173 array[offset + 2] = this.z;
3174 array[offset + 3] = this.w;
3175
3176 return array;
3177
3178 }
3179
3180 fromBufferAttribute (attribute, index)
3181 {
3182
3183 this.x = attribute.getX(index);
3184 this.y = attribute.getY(index);
3185 this.z = attribute.getZ(index);
3186 this.w = attribute.getW(index);
3187
3188 return this;
3189
3190 }
3191
3192 random ()
3193 {
3194
3195 this.x = Math.random();
3196 this.y = Math.random();
3197 this.z = Math.random();
3198 this.w = Math.random();
3199
3200 return this;
3201
3202 }
3203
3204 *[Symbol.iterator] ()
3205 {
3206
3207 yield this.x;
3208 yield this.y;
3209 yield this.z;
3210 yield this.w;
3211
3212 }
3213
3214}
3215
3216/*
3217 In options, we can specify:
3218 * Texture parameters for an auto-generated target texture
3219 * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
3220*/
3221class RenderTarget extends EventDispatcher
3222{
3223
3224 constructor(width = 1, height = 1, options = {})
3225 {
3226
3227 super();
3228
3229 this.isRenderTarget = true;
3230
3231 this.width = width;
3232 this.height = height;
3233 this.depth = 1;
3234
3235 this.scissor = new Vector4(0, 0, width, height);
3236 this.scissorTest = false;
3237
3238 this.viewport = new Vector4(0, 0, width, height);
3239
3240 const image = { width: width, height: height, depth: 1 };
3241
3242 options = Object.assign({
3243 generateMipmaps: false,
3244 internalFormat: null,
3245 minFilter: LinearFilter,
3246 depthBuffer: true,
3247 stencilBuffer: false,
3248 resolveDepthBuffer: true,
3249 resolveStencilBuffer: true,
3250 depthTexture: null,
3251 samples: 0,
3252 count: 1
3253 }, options);
3254
3255 const texture = new Texture(image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace);
3256
3257 texture.flipY = false;
3258 texture.generateMipmaps = options.generateMipmaps;
3259 texture.internalFormat = options.internalFormat;
3260
3261 this.textures = [];
3262
3263 const count = options.count;
3264 for (let i = 0; i < count; i++)
3265 {
3266
3267 this.textures[i] = texture.clone();
3268 this.textures[i].isRenderTargetTexture = true;
3269
3270 }
3271
3272 this.depthBuffer = options.depthBuffer;
3273 this.stencilBuffer = options.stencilBuffer;
3274
3275 this.resolveDepthBuffer = options.resolveDepthBuffer;
3276 this.resolveStencilBuffer = options.resolveStencilBuffer;
3277
3278 this.depthTexture = options.depthTexture;
3279
3280 this.samples = options.samples;
3281
3282 }
3283
3284 get texture ()
3285 {
3286
3287 return this.textures[0];
3288
3289 }
3290
3291 set texture (value)
3292 {
3293
3294 this.textures[0] = value;
3295
3296 }
3297
3298 setSize (width, height, depth = 1)
3299 {
3300
3301 if (this.width !== width || this.height !== height || this.depth !== depth)
3302 {
3303
3304 this.width = width;
3305 this.height = height;
3306 this.depth = depth;
3307
3308 for (let i = 0, il = this.textures.length; i < il; i++)
3309 {
3310
3311 this.textures[i].image.width = width;
3312 this.textures[i].image.height = height;
3313 this.textures[i].image.depth = depth;
3314
3315 }
3316
3317 this.dispose();
3318
3319 }
3320
3321 this.viewport.set(0, 0, width, height);
3322 this.scissor.set(0, 0, width, height);
3323
3324 }
3325
3326 clone ()
3327 {
3328
3329 return new this.constructor().copy(this);
3330
3331 }
3332
3333 copy (source)
3334 {
3335
3336 this.width = source.width;
3337 this.height = source.height;
3338 this.depth = source.depth;
3339
3340 this.scissor.copy(source.scissor);
3341 this.scissorTest = source.scissorTest;
3342
3343 this.viewport.copy(source.viewport);
3344
3345 this.textures.length = 0;
3346
3347 for (let i = 0, il = source.textures.length; i < il; i++)
3348 {
3349
3350 this.textures[i] = source.textures[i].clone();
3351 this.textures[i].isRenderTargetTexture = true;
3352
3353 }
3354
3355 // ensure image object is not shared, see #20328
3356
3357 const image = Object.assign({}, source.texture.image);
3358 this.texture.source = new Source(image);
3359
3360 this.depthBuffer = source.depthBuffer;
3361 this.stencilBuffer = source.stencilBuffer;
3362
3363 this.resolveDepthBuffer = source.resolveDepthBuffer;
3364 this.resolveStencilBuffer = source.resolveStencilBuffer;
3365
3366 if (source.depthTexture !== null) this.depthTexture = source.depthTexture.clone();
3367
3368 this.samples = source.samples;
3369
3370 return this;
3371
3372 }
3373
3374 dispose ()
3375 {
3376
3377 this.dispatchEvent({ type: 'dispose' });
3378
3379 }
3380
3381}
3382
3383class WebGLRenderTarget extends RenderTarget
3384{
3385
3386 constructor(width = 1, height = 1, options = {})
3387 {
3388
3389 super(width, height, options);
3390
3391 this.isWebGLRenderTarget = true;
3392
3393 }
3394
3395}
3396
3397class DataArrayTexture extends Texture
3398{
3399
3400 constructor(data = null, width = 1, height = 1, depth = 1)
3401 {
3402
3403 super(null);
3404
3405 this.isDataArrayTexture = true;
3406
3407 this.image = { data, width, height, depth };
3408
3409 this.magFilter = NearestFilter;
3410 this.minFilter = NearestFilter;
3411
3412 this.wrapR = ClampToEdgeWrapping;
3413
3414 this.generateMipmaps = false;
3415 this.flipY = false;
3416 this.unpackAlignment = 1;
3417
3418 this.layerUpdates = new Set();
3419
3420 }
3421
3422 addLayerUpdate (layerIndex)
3423 {
3424
3425 this.layerUpdates.add(layerIndex);
3426
3427 }
3428
3429 clearLayerUpdates ()
3430 {
3431
3432 this.layerUpdates.clear();
3433
3434 }
3435
3436}
3437
3438class WebGLArrayRenderTarget extends WebGLRenderTarget
3439{
3440
3441 constructor(width = 1, height = 1, depth = 1, options = {})
3442 {
3443
3444 super(width, height, options);
3445
3446 this.isWebGLArrayRenderTarget = true;
3447
3448 this.depth = depth;
3449
3450 this.texture = new DataArrayTexture(null, width, height, depth);
3451
3452 this.texture.isRenderTargetTexture = true;
3453
3454 }
3455
3456}
3457
3458class Data3DTexture extends Texture
3459{
3460
3461 constructor(data = null, width = 1, height = 1, depth = 1)
3462 {
3463
3464 // We're going to add .setXXX() methods for setting properties later.
3465 // Users can still set in DataTexture3D directly.
3466 //
3467 // const texture = new THREE.DataTexture3D( data, width, height, depth );
3468 // texture.anisotropy = 16;
3469 //
3470 // See #14839
3471
3472 super(null);
3473
3474 this.isData3DTexture = true;
3475
3476 this.image = { data, width, height, depth };
3477
3478 this.magFilter = NearestFilter;
3479 this.minFilter = NearestFilter;
3480
3481 this.wrapR = ClampToEdgeWrapping;
3482
3483 this.generateMipmaps = false;
3484 this.flipY = false;
3485 this.unpackAlignment = 1;
3486
3487 }
3488
3489}
3490
3491class WebGL3DRenderTarget extends WebGLRenderTarget
3492{
3493
3494 constructor(width = 1, height = 1, depth = 1, options = {})
3495 {
3496
3497 super(width, height, options);
3498
3499 this.isWebGL3DRenderTarget = true;
3500
3501 this.depth = depth;
3502
3503 this.texture = new Data3DTexture(null, width, height, depth);
3504
3505 this.texture.isRenderTargetTexture = true;
3506
3507 }
3508
3509}
3510
3511class Quaternion
3512{
3513
3514 constructor(x = 0, y = 0, z = 0, w = 1)
3515 {
3516
3517 this.isQuaternion = true;
3518
3519 this._x = x;
3520 this._y = y;
3521 this._z = z;
3522 this._w = w;
3523
3524 }
3525
3526 static slerpFlat (dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t)
3527 {
3528
3529 // fuzz-free, array-based Quaternion SLERP operation
3530
3531 let x0 = src0[srcOffset0 + 0],
3532 y0 = src0[srcOffset0 + 1],
3533 z0 = src0[srcOffset0 + 2],
3534 w0 = src0[srcOffset0 + 3];
3535
3536 const x1 = src1[srcOffset1 + 0],
3537 y1 = src1[srcOffset1 + 1],
3538 z1 = src1[srcOffset1 + 2],
3539 w1 = src1[srcOffset1 + 3];
3540
3541 if (t === 0)
3542 {
3543
3544 dst[dstOffset + 0] = x0;
3545 dst[dstOffset + 1] = y0;
3546 dst[dstOffset + 2] = z0;
3547 dst[dstOffset + 3] = w0;
3548 return;
3549
3550 }
3551
3552 if (t === 1)
3553 {
3554
3555 dst[dstOffset + 0] = x1;
3556 dst[dstOffset + 1] = y1;
3557 dst[dstOffset + 2] = z1;
3558 dst[dstOffset + 3] = w1;
3559 return;
3560
3561 }
3562
3563 if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1)
3564 {
3565
3566 let s = 1 - t;
3567 const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
3568 dir = (cos >= 0 ? 1 : - 1),
3569 sqrSin = 1 - cos * cos;
3570
3571 // Skip the Slerp for tiny steps to avoid numeric problems:
3572 if (sqrSin > Number.EPSILON)
3573 {
3574
3575 const sin = Math.sqrt(sqrSin),
3576 len = Math.atan2(sin, cos * dir);
3577
3578 s = Math.sin(s * len) / sin;
3579 t = Math.sin(t * len) / sin;
3580
3581 }
3582
3583 const tDir = t * dir;
3584
3585 x0 = x0 * s + x1 * tDir;
3586 y0 = y0 * s + y1 * tDir;
3587 z0 = z0 * s + z1 * tDir;
3588 w0 = w0 * s + w1 * tDir;
3589
3590 // Normalize in case we just did a lerp:
3591 if (s === 1 - t)
3592 {
3593
3594 const f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
3595
3596 x0 *= f;
3597 y0 *= f;
3598 z0 *= f;
3599 w0 *= f;
3600
3601 }
3602
3603 }
3604
3605 dst[dstOffset] = x0;
3606 dst[dstOffset + 1] = y0;
3607 dst[dstOffset + 2] = z0;
3608 dst[dstOffset + 3] = w0;
3609
3610 }
3611
3612 static multiplyQuaternionsFlat (dst, dstOffset, src0, srcOffset0, src1, srcOffset1)
3613 {
3614
3615 const x0 = src0[srcOffset0];
3616 const y0 = src0[srcOffset0 + 1];
3617 const z0 = src0[srcOffset0 + 2];
3618 const w0 = src0[srcOffset0 + 3];
3619
3620 const x1 = src1[srcOffset1];
3621 const y1 = src1[srcOffset1 + 1];
3622 const z1 = src1[srcOffset1 + 2];
3623 const w1 = src1[srcOffset1 + 3];
3624
3625 dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
3626 dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
3627 dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
3628 dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
3629
3630 return dst;
3631
3632 }
3633
3634 get x ()
3635 {
3636
3637 return this._x;
3638
3639 }
3640
3641 set x (value)
3642 {
3643
3644 this._x = value;
3645 this._onChangeCallback();
3646
3647 }
3648
3649 get y ()
3650 {
3651
3652 return this._y;
3653
3654 }
3655
3656 set y (value)
3657 {
3658
3659 this._y = value;
3660 this._onChangeCallback();
3661
3662 }
3663
3664 get z ()
3665 {
3666
3667 return this._z;
3668
3669 }
3670
3671 set z (value)
3672 {
3673
3674 this._z = value;
3675 this._onChangeCallback();
3676
3677 }
3678
3679 get w ()
3680 {
3681
3682 return this._w;
3683
3684 }
3685
3686 set w (value)
3687 {
3688
3689 this._w = value;
3690 this._onChangeCallback();
3691
3692 }
3693
3694 set (x, y, z, w)
3695 {
3696
3697 this._x = x;
3698 this._y = y;
3699 this._z = z;
3700 this._w = w;
3701
3702 this._onChangeCallback();
3703
3704 return this;
3705
3706 }
3707
3708 clone ()
3709 {
3710
3711 return new this.constructor(this._x, this._y, this._z, this._w);
3712
3713 }
3714
3715 copy (quaternion)
3716 {
3717
3718 this._x = quaternion.x;
3719 this._y = quaternion.y;
3720 this._z = quaternion.z;
3721 this._w = quaternion.w;
3722
3723 this._onChangeCallback();
3724
3725 return this;
3726
3727 }
3728
3729 setFromEuler (euler, update = true)
3730 {
3731
3732 const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
3733
3734 // http://www.mathworks.com/matlabcentral/fileexchange/
3735 // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
3736 // content/SpinCalc.m
3737
3738 const cos = Math.cos;
3739 const sin = Math.sin;
3740
3741 const c1 = cos(x / 2);
3742 const c2 = cos(y / 2);
3743 const c3 = cos(z / 2);
3744
3745 const s1 = sin(x / 2);
3746 const s2 = sin(y / 2);
3747 const s3 = sin(z / 2);
3748
3749 switch (order)
3750 {
3751
3752 case 'XYZ':
3753 this._x = s1 * c2 * c3 + c1 * s2 * s3;
3754 this._y = c1 * s2 * c3 - s1 * c2 * s3;
3755 this._z = c1 * c2 * s3 + s1 * s2 * c3;
3756 this._w = c1 * c2 * c3 - s1 * s2 * s3;
3757 break;
3758
3759 case 'YXZ':
3760 this._x = s1 * c2 * c3 + c1 * s2 * s3;
3761 this._y = c1 * s2 * c3 - s1 * c2 * s3;
3762 this._z = c1 * c2 * s3 - s1 * s2 * c3;
3763 this._w = c1 * c2 * c3 + s1 * s2 * s3;
3764 break;
3765
3766 case 'ZXY':
3767 this._x = s1 * c2 * c3 - c1 * s2 * s3;
3768 this._y = c1 * s2 * c3 + s1 * c2 * s3;
3769 this._z = c1 * c2 * s3 + s1 * s2 * c3;
3770 this._w = c1 * c2 * c3 - s1 * s2 * s3;
3771 break;
3772
3773 case 'ZYX':
3774 this._x = s1 * c2 * c3 - c1 * s2 * s3;
3775 this._y = c1 * s2 * c3 + s1 * c2 * s3;
3776 this._z = c1 * c2 * s3 - s1 * s2 * c3;
3777 this._w = c1 * c2 * c3 + s1 * s2 * s3;
3778 break;
3779
3780 case 'YZX':
3781 this._x = s1 * c2 * c3 + c1 * s2 * s3;
3782 this._y = c1 * s2 * c3 + s1 * c2 * s3;
3783 this._z = c1 * c2 * s3 - s1 * s2 * c3;
3784 this._w = c1 * c2 * c3 - s1 * s2 * s3;
3785 break;
3786
3787 case 'XZY':
3788 this._x = s1 * c2 * c3 - c1 * s2 * s3;
3789 this._y = c1 * s2 * c3 - s1 * c2 * s3;
3790 this._z = c1 * c2 * s3 + s1 * s2 * c3;
3791 this._w = c1 * c2 * c3 + s1 * s2 * s3;
3792 break;
3793
3794 default:
3795 console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
3796
3797 }
3798
3799 if (update === true) this._onChangeCallback();
3800
3801 return this;
3802
3803 }
3804
3805 setFromAxisAngle (axis, angle)
3806 {
3807
3808 // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
3809
3810 // assumes axis is normalized
3811
3812 const halfAngle = angle / 2, s = Math.sin(halfAngle);
3813
3814 this._x = axis.x * s;
3815 this._y = axis.y * s;
3816 this._z = axis.z * s;
3817 this._w = Math.cos(halfAngle);
3818
3819 this._onChangeCallback();
3820
3821 return this;
3822
3823 }
3824
3825 setFromRotationMatrix (m)
3826 {
3827
3828 // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
3829
3830 // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
3831
3832 const te = m.elements,
3833
3834 m11 = te[0], m12 = te[4], m13 = te[8],
3835 m21 = te[1], m22 = te[5], m23 = te[9],
3836 m31 = te[2], m32 = te[6], m33 = te[10],
3837
3838 trace = m11 + m22 + m33;
3839
3840 if (trace > 0)
3841 {
3842
3843 const s = 0.5 / Math.sqrt(trace + 1.0);
3844
3845 this._w = 0.25 / s;
3846 this._x = (m32 - m23) * s;
3847 this._y = (m13 - m31) * s;
3848 this._z = (m21 - m12) * s;
3849
3850 } else if (m11 > m22 && m11 > m33)
3851 {
3852
3853 const s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
3854
3855 this._w = (m32 - m23) / s;
3856 this._x = 0.25 * s;
3857 this._y = (m12 + m21) / s;
3858 this._z = (m13 + m31) / s;
3859
3860 } else if (m22 > m33)
3861 {
3862
3863 const s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
3864
3865 this._w = (m13 - m31) / s;
3866 this._x = (m12 + m21) / s;
3867 this._y = 0.25 * s;
3868 this._z = (m23 + m32) / s;
3869
3870 } else
3871 {
3872
3873 const s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
3874
3875 this._w = (m21 - m12) / s;
3876 this._x = (m13 + m31) / s;
3877 this._y = (m23 + m32) / s;
3878 this._z = 0.25 * s;
3879
3880 }
3881
3882 this._onChangeCallback();
3883
3884 return this;
3885
3886 }
3887
3888 setFromUnitVectors (vFrom, vTo)
3889 {
3890
3891 // assumes direction vectors vFrom and vTo are normalized
3892
3893 let r = vFrom.dot(vTo) + 1;
3894
3895 if (r < Number.EPSILON)
3896 {
3897
3898 // vFrom and vTo point in opposite directions
3899
3900 r = 0;
3901
3902 if (Math.abs(vFrom.x) > Math.abs(vFrom.z))
3903 {
3904
3905 this._x = - vFrom.y;
3906 this._y = vFrom.x;
3907 this._z = 0;
3908 this._w = r;
3909
3910 } else
3911 {
3912
3913 this._x = 0;
3914 this._y = - vFrom.z;
3915 this._z = vFrom.y;
3916 this._w = r;
3917
3918 }
3919
3920 } else
3921 {
3922
3923 // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
3924
3925 this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
3926 this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
3927 this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
3928 this._w = r;
3929
3930 }
3931
3932 return this.normalize();
3933
3934 }
3935
3936 angleTo (q)
3937 {
3938
3939 return 2 * Math.acos(Math.abs(clamp(this.dot(q), - 1, 1)));
3940
3941 }
3942
3943 rotateTowards (q, step)
3944 {
3945
3946 const angle = this.angleTo(q);
3947
3948 if (angle === 0) return this;
3949
3950 const t = Math.min(1, step / angle);
3951
3952 this.slerp(q, t);
3953
3954 return this;
3955
3956 }
3957
3958 identity ()
3959 {
3960
3961 return this.set(0, 0, 0, 1);
3962
3963 }
3964
3965 invert ()
3966 {
3967
3968 // quaternion is assumed to have unit length
3969
3970 return this.conjugate();
3971
3972 }
3973
3974 conjugate ()
3975 {
3976
3977 this._x *= - 1;
3978 this._y *= - 1;
3979 this._z *= - 1;
3980
3981 this._onChangeCallback();
3982
3983 return this;
3984
3985 }
3986
3987 dot (v)
3988 {
3989
3990 return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
3991
3992 }
3993
3994 lengthSq ()
3995 {
3996
3997 return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
3998
3999 }
4000
4001 length ()
4002 {
4003
4004 return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
4005
4006 }
4007
4008 normalize ()
4009 {
4010
4011 let l = this.length();
4012
4013 if (l === 0)
4014 {
4015
4016 this._x = 0;
4017 this._y = 0;
4018 this._z = 0;
4019 this._w = 1;
4020
4021 } else
4022 {
4023
4024 l = 1 / l;
4025
4026 this._x = this._x * l;
4027 this._y = this._y * l;
4028 this._z = this._z * l;
4029 this._w = this._w * l;
4030
4031 }
4032
4033 this._onChangeCallback();
4034
4035 return this;
4036
4037 }
4038
4039 multiply (q)
4040 {
4041
4042 return this.multiplyQuaternions(this, q);
4043
4044 }
4045
4046 premultiply (q)
4047 {
4048
4049 return this.multiplyQuaternions(q, this);
4050
4051 }
4052
4053 multiplyQuaternions (a, b)
4054 {
4055
4056 // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
4057
4058 const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
4059 const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
4060
4061 this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
4062 this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
4063 this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
4064 this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
4065
4066 this._onChangeCallback();
4067
4068 return this;
4069
4070 }
4071
4072 slerp (qb, t)
4073 {
4074
4075 if (t === 0) return this;
4076 if (t === 1) return this.copy(qb);
4077
4078 const x = this._x, y = this._y, z = this._z, w = this._w;
4079
4080 // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
4081
4082 let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
4083
4084 if (cosHalfTheta < 0)
4085 {
4086
4087 this._w = - qb._w;
4088 this._x = - qb._x;
4089 this._y = - qb._y;
4090 this._z = - qb._z;
4091
4092 cosHalfTheta = - cosHalfTheta;
4093
4094 } else
4095 {
4096
4097 this.copy(qb);
4098
4099 }
4100
4101 if (cosHalfTheta >= 1.0)
4102 {
4103
4104 this._w = w;
4105 this._x = x;
4106 this._y = y;
4107 this._z = z;
4108
4109 return this;
4110
4111 }
4112
4113 const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
4114
4115 if (sqrSinHalfTheta <= Number.EPSILON)
4116 {
4117
4118 const s = 1 - t;
4119 this._w = s * w + t * this._w;
4120 this._x = s * x + t * this._x;
4121 this._y = s * y + t * this._y;
4122 this._z = s * z + t * this._z;
4123
4124 this.normalize(); // normalize calls _onChangeCallback()
4125
4126 return this;
4127
4128 }
4129
4130 const sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
4131 const halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
4132 const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
4133 ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
4134
4135 this._w = (w * ratioA + this._w * ratioB);
4136 this._x = (x * ratioA + this._x * ratioB);
4137 this._y = (y * ratioA + this._y * ratioB);
4138 this._z = (z * ratioA + this._z * ratioB);
4139
4140 this._onChangeCallback();
4141
4142 return this;
4143
4144 }
4145
4146 slerpQuaternions (qa, qb, t)
4147 {
4148
4149 return this.copy(qa).slerp(qb, t);
4150
4151 }
4152
4153 random ()
4154 {
4155
4156 // sets this quaternion to a uniform random unit quaternnion
4157
4158 // Ken Shoemake
4159 // Uniform random rotations
4160 // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
4161
4162 const theta1 = 2 * Math.PI * Math.random();
4163 const theta2 = 2 * Math.PI * Math.random();
4164
4165 const x0 = Math.random();
4166 const r1 = Math.sqrt(1 - x0);
4167 const r2 = Math.sqrt(x0);
4168
4169 return this.set(
4170 r1 * Math.sin(theta1),
4171 r1 * Math.cos(theta1),
4172 r2 * Math.sin(theta2),
4173 r2 * Math.cos(theta2),
4174 );
4175
4176 }
4177
4178 equals (quaternion)
4179 {
4180
4181 return (quaternion._x === this._x) && (quaternion._y === this._y) && (quaternion._z === this._z) && (quaternion._w === this._w);
4182
4183 }
4184
4185 fromArray (array, offset = 0)
4186 {
4187
4188 this._x = array[offset];
4189 this._y = array[offset + 1];
4190 this._z = array[offset + 2];
4191 this._w = array[offset + 3];
4192
4193 this._onChangeCallback();
4194
4195 return this;
4196
4197 }
4198
4199 toArray (array = [], offset = 0)
4200 {
4201
4202 array[offset] = this._x;
4203 array[offset + 1] = this._y;
4204 array[offset + 2] = this._z;
4205 array[offset + 3] = this._w;
4206
4207 return array;
4208
4209 }
4210
4211 fromBufferAttribute (attribute, index)
4212 {
4213
4214 this._x = attribute.getX(index);
4215 this._y = attribute.getY(index);
4216 this._z = attribute.getZ(index);
4217 this._w = attribute.getW(index);
4218
4219 this._onChangeCallback();
4220
4221 return this;
4222
4223 }
4224
4225 toJSON ()
4226 {
4227
4228 return this.toArray();
4229
4230 }
4231
4232 _onChange (callback)
4233 {
4234
4235 this._onChangeCallback = callback;
4236
4237 return this;
4238
4239 }
4240
4241 _onChangeCallback () { }
4242
4243 *[Symbol.iterator] ()
4244 {
4245
4246 yield this._x;
4247 yield this._y;
4248 yield this._z;
4249 yield this._w;
4250
4251 }
4252
4253}
4254
4255class Vector3
4256{
4257
4258 constructor(x = 0, y = 0, z = 0)
4259 {
4260
4261 Vector3.prototype.isVector3 = true;
4262
4263 this.x = x;
4264 this.y = y;
4265 this.z = z;
4266
4267 }
4268
4269 set (x, y, z)
4270 {
4271
4272 if (z === undefined) z = this.z; // sprite.scale.set(x,y)
4273
4274 this.x = x;
4275 this.y = y;
4276 this.z = z;
4277
4278 return this;
4279
4280 }
4281
4282 setScalar (scalar)
4283 {
4284
4285 this.x = scalar;
4286 this.y = scalar;
4287 this.z = scalar;
4288
4289 return this;
4290
4291 }
4292
4293 setX (x)
4294 {
4295
4296 this.x = x;
4297
4298 return this;
4299
4300 }
4301
4302 setY (y)
4303 {
4304
4305 this.y = y;
4306
4307 return this;
4308
4309 }
4310
4311 setZ (z)
4312 {
4313
4314 this.z = z;
4315
4316 return this;
4317
4318 }
4319
4320 setComponent (index, value)
4321 {
4322
4323 switch (index)
4324 {
4325
4326 case 0: this.x = value; break;
4327 case 1: this.y = value; break;
4328 case 2: this.z = value; break;
4329 default: throw new Error('index is out of range: ' + index);
4330
4331 }
4332
4333 return this;
4334
4335 }
4336
4337 getComponent (index)
4338 {
4339
4340 switch (index)
4341 {
4342
4343 case 0: return this.x;
4344 case 1: return this.y;
4345 case 2: return this.z;
4346 default: throw new Error('index is out of range: ' + index);
4347
4348 }
4349
4350 }
4351
4352 clone ()
4353 {
4354
4355 return new this.constructor(this.x, this.y, this.z);
4356
4357 }
4358
4359 copy (v)
4360 {
4361
4362 this.x = v.x;
4363 this.y = v.y;
4364 this.z = v.z;
4365
4366 return this;
4367
4368 }
4369
4370 add (v)
4371 {
4372
4373 this.x += v.x;
4374 this.y += v.y;
4375 this.z += v.z;
4376
4377 return this;
4378
4379 }
4380
4381 addScalar (s)
4382 {
4383
4384 this.x += s;
4385 this.y += s;
4386 this.z += s;
4387
4388 return this;
4389
4390 }
4391
4392 addVectors (a, b)
4393 {
4394
4395 this.x = a.x + b.x;
4396 this.y = a.y + b.y;
4397 this.z = a.z + b.z;
4398
4399 return this;
4400
4401 }
4402
4403 addScaledVector (v, s)
4404 {
4405
4406 this.x += v.x * s;
4407 this.y += v.y * s;
4408 this.z += v.z * s;
4409
4410 return this;
4411
4412 }
4413
4414 sub (v)
4415 {
4416
4417 this.x -= v.x;
4418 this.y -= v.y;
4419 this.z -= v.z;
4420
4421 return this;
4422
4423 }
4424
4425 subScalar (s)
4426 {
4427
4428 this.x -= s;
4429 this.y -= s;
4430 this.z -= s;
4431
4432 return this;
4433
4434 }
4435
4436 subVectors (a, b)
4437 {
4438
4439 this.x = a.x - b.x;
4440 this.y = a.y - b.y;
4441 this.z = a.z - b.z;
4442
4443 return this;
4444
4445 }
4446
4447 multiply (v)
4448 {
4449
4450 this.x *= v.x;
4451 this.y *= v.y;
4452 this.z *= v.z;
4453
4454 return this;
4455
4456 }
4457
4458 multiplyScalar (scalar)
4459 {
4460
4461 this.x *= scalar;
4462 this.y *= scalar;
4463 this.z *= scalar;
4464
4465 return this;
4466
4467 }
4468
4469 multiplyVectors (a, b)
4470 {
4471
4472 this.x = a.x * b.x;
4473 this.y = a.y * b.y;
4474 this.z = a.z * b.z;
4475
4476 return this;
4477
4478 }
4479
4480 applyEuler (euler)
4481 {
4482
4483 return this.applyQuaternion(_quaternion$4.setFromEuler(euler));
4484
4485 }
4486
4487 applyAxisAngle (axis, angle)
4488 {
4489
4490 return this.applyQuaternion(_quaternion$4.setFromAxisAngle(axis, angle));
4491
4492 }
4493
4494 applyMatrix3 (m)
4495 {
4496
4497 const x = this.x, y = this.y, z = this.z;
4498 const e = m.elements;
4499
4500 this.x = e[0] * x + e[3] * y + e[6] * z;
4501 this.y = e[1] * x + e[4] * y + e[7] * z;
4502 this.z = e[2] * x + e[5] * y + e[8] * z;
4503
4504 return this;
4505
4506 }
4507
4508 applyNormalMatrix (m)
4509 {
4510
4511 return this.applyMatrix3(m).normalize();
4512
4513 }
4514
4515 applyMatrix4 (m)
4516 {
4517
4518 const x = this.x, y = this.y, z = this.z;
4519 const e = m.elements;
4520
4521 const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
4522
4523 this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
4524 this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
4525 this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
4526
4527 return this;
4528
4529 }
4530
4531 applyQuaternion (q)
4532 {
4533
4534 // quaternion q is assumed to have unit length
4535
4536 const vx = this.x, vy = this.y, vz = this.z;
4537 const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
4538
4539 // t = 2 * cross( q.xyz, v );
4540 const tx = 2 * (qy * vz - qz * vy);
4541 const ty = 2 * (qz * vx - qx * vz);
4542 const tz = 2 * (qx * vy - qy * vx);
4543
4544 // v + q.w * t + cross( q.xyz, t );
4545 this.x = vx + qw * tx + qy * tz - qz * ty;
4546 this.y = vy + qw * ty + qz * tx - qx * tz;
4547 this.z = vz + qw * tz + qx * ty - qy * tx;
4548
4549 return this;
4550
4551 }
4552
4553 project (camera)
4554 {
4555
4556 return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
4557
4558 }
4559
4560 unproject (camera)
4561 {
4562
4563 return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
4564
4565 }
4566
4567 transformDirection (m)
4568 {
4569
4570 // input: THREE.Matrix4 affine matrix
4571 // vector interpreted as a direction
4572
4573 const x = this.x, y = this.y, z = this.z;
4574 const e = m.elements;
4575
4576 this.x = e[0] * x + e[4] * y + e[8] * z;
4577 this.y = e[1] * x + e[5] * y + e[9] * z;
4578 this.z = e[2] * x + e[6] * y + e[10] * z;
4579
4580 return this.normalize();
4581
4582 }
4583
4584 divide (v)
4585 {
4586
4587 this.x /= v.x;
4588 this.y /= v.y;
4589 this.z /= v.z;
4590
4591 return this;
4592
4593 }
4594
4595 divideScalar (scalar)
4596 {
4597
4598 return this.multiplyScalar(1 / scalar);
4599
4600 }
4601
4602 min (v)
4603 {
4604
4605 this.x = Math.min(this.x, v.x);
4606 this.y = Math.min(this.y, v.y);
4607 this.z = Math.min(this.z, v.z);
4608
4609 return this;
4610
4611 }
4612
4613 max (v)
4614 {
4615
4616 this.x = Math.max(this.x, v.x);
4617 this.y = Math.max(this.y, v.y);
4618 this.z = Math.max(this.z, v.z);
4619
4620 return this;
4621
4622 }
4623
4624 clamp (min, max)
4625 {
4626
4627 // assumes min < max, componentwise
4628
4629 this.x = Math.max(min.x, Math.min(max.x, this.x));
4630 this.y = Math.max(min.y, Math.min(max.y, this.y));
4631 this.z = Math.max(min.z, Math.min(max.z, this.z));
4632
4633 return this;
4634
4635 }
4636
4637 clampScalar (minVal, maxVal)
4638 {
4639
4640 this.x = Math.max(minVal, Math.min(maxVal, this.x));
4641 this.y = Math.max(minVal, Math.min(maxVal, this.y));
4642 this.z = Math.max(minVal, Math.min(maxVal, this.z));
4643
4644 return this;
4645
4646 }
4647
4648 clampLength (min, max)
4649 {
4650
4651 const length = this.length();
4652
4653 return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
4654
4655 }
4656
4657 floor ()
4658 {
4659
4660 this.x = Math.floor(this.x);
4661 this.y = Math.floor(this.y);
4662 this.z = Math.floor(this.z);
4663
4664 return this;
4665
4666 }
4667
4668 ceil ()
4669 {
4670
4671 this.x = Math.ceil(this.x);
4672 this.y = Math.ceil(this.y);
4673 this.z = Math.ceil(this.z);
4674
4675 return this;
4676
4677 }
4678
4679 round ()
4680 {
4681
4682 this.x = Math.round(this.x);
4683 this.y = Math.round(this.y);
4684 this.z = Math.round(this.z);
4685
4686 return this;
4687
4688 }
4689
4690 roundToZero ()
4691 {
4692
4693 this.x = Math.trunc(this.x);
4694 this.y = Math.trunc(this.y);
4695 this.z = Math.trunc(this.z);
4696
4697 return this;
4698
4699 }
4700
4701 negate ()
4702 {
4703
4704 this.x = - this.x;
4705 this.y = - this.y;
4706 this.z = - this.z;
4707
4708 return this;
4709
4710 }
4711
4712 dot (v)
4713 {
4714
4715 return this.x * v.x + this.y * v.y + this.z * v.z;
4716
4717 }
4718
4719 // TODO lengthSquared?
4720
4721 lengthSq ()
4722 {
4723
4724 return this.x * this.x + this.y * this.y + this.z * this.z;
4725
4726 }
4727
4728 length ()
4729 {
4730
4731 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
4732
4733 }
4734
4735 manhattanLength ()
4736 {
4737
4738 return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
4739
4740 }
4741
4742 normalize ()
4743 {
4744
4745 return this.divideScalar(this.length() || 1);
4746
4747 }
4748
4749 setLength (length)
4750 {
4751
4752 return this.normalize().multiplyScalar(length);
4753
4754 }
4755
4756 lerp (v, alpha)
4757 {
4758
4759 this.x += (v.x - this.x) * alpha;
4760 this.y += (v.y - this.y) * alpha;
4761 this.z += (v.z - this.z) * alpha;
4762
4763 return this;
4764
4765 }
4766
4767 lerpVectors (v1, v2, alpha)
4768 {
4769
4770 this.x = v1.x + (v2.x - v1.x) * alpha;
4771 this.y = v1.y + (v2.y - v1.y) * alpha;
4772 this.z = v1.z + (v2.z - v1.z) * alpha;
4773
4774 return this;
4775
4776 }
4777
4778 cross (v)
4779 {
4780
4781 return this.crossVectors(this, v);
4782
4783 }
4784
4785 crossVectors (a, b)
4786 {
4787
4788 const ax = a.x, ay = a.y, az = a.z;
4789 const bx = b.x, by = b.y, bz = b.z;
4790
4791 this.x = ay * bz - az * by;
4792 this.y = az * bx - ax * bz;
4793 this.z = ax * by - ay * bx;
4794
4795 return this;
4796
4797 }
4798
4799 projectOnVector (v)
4800 {
4801
4802 const denominator = v.lengthSq();
4803
4804 if (denominator === 0) return this.set(0, 0, 0);
4805
4806 const scalar = v.dot(this) / denominator;
4807
4808 return this.copy(v).multiplyScalar(scalar);
4809
4810 }
4811
4812 projectOnPlane (planeNormal)
4813 {
4814
4815 _vector$c.copy(this).projectOnVector(planeNormal);
4816
4817 return this.sub(_vector$c);
4818
4819 }
4820
4821 reflect (normal)
4822 {
4823
4824 // reflect incident vector off plane orthogonal to normal
4825 // normal is assumed to have unit length
4826
4827 return this.sub(_vector$c.copy(normal).multiplyScalar(2 * this.dot(normal)));
4828
4829 }
4830
4831 angleTo (v)
4832 {
4833
4834 const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
4835
4836 if (denominator === 0) return Math.PI / 2;
4837
4838 const theta = this.dot(v) / denominator;
4839
4840 // clamp, to handle numerical problems
4841
4842 return Math.acos(clamp(theta, - 1, 1));
4843
4844 }
4845
4846 distanceTo (v)
4847 {
4848
4849 return Math.sqrt(this.distanceToSquared(v));
4850
4851 }
4852
4853 distanceToSquared (v)
4854 {
4855
4856 const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
4857
4858 return dx * dx + dy * dy + dz * dz;
4859
4860 }
4861
4862 manhattanDistanceTo (v)
4863 {
4864
4865 return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
4866
4867 }
4868
4869 setFromSpherical (s)
4870 {
4871
4872 return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
4873
4874 }
4875
4876 setFromSphericalCoords (radius, phi, theta)
4877 {
4878
4879 const sinPhiRadius = Math.sin(phi) * radius;
4880
4881 this.x = sinPhiRadius * Math.sin(theta);
4882 this.y = Math.cos(phi) * radius;
4883 this.z = sinPhiRadius * Math.cos(theta);
4884
4885 return this;
4886
4887 }
4888
4889 setFromCylindrical (c)
4890 {
4891
4892 return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
4893
4894 }
4895
4896 setFromCylindricalCoords (radius, theta, y)
4897 {
4898
4899 this.x = radius * Math.sin(theta);
4900 this.y = y;
4901 this.z = radius * Math.cos(theta);
4902
4903 return this;
4904
4905 }
4906
4907 setFromMatrixPosition (m)
4908 {
4909
4910 const e = m.elements;
4911
4912 this.x = e[12];
4913 this.y = e[13];
4914 this.z = e[14];
4915
4916 return this;
4917
4918 }
4919
4920 setFromMatrixScale (m)
4921 {
4922
4923 const sx = this.setFromMatrixColumn(m, 0).length();
4924 const sy = this.setFromMatrixColumn(m, 1).length();
4925 const sz = this.setFromMatrixColumn(m, 2).length();
4926
4927 this.x = sx;
4928 this.y = sy;
4929 this.z = sz;
4930
4931 return this;
4932
4933 }
4934
4935 setFromMatrixColumn (m, index)
4936 {
4937
4938 return this.fromArray(m.elements, index * 4);
4939
4940 }
4941
4942 setFromMatrix3Column (m, index)
4943 {
4944
4945 return this.fromArray(m.elements, index * 3);
4946
4947 }
4948
4949 setFromEuler (e)
4950 {
4951
4952 this.x = e._x;
4953 this.y = e._y;
4954 this.z = e._z;
4955
4956 return this;
4957
4958 }
4959
4960 setFromColor (c)
4961 {
4962
4963 this.x = c.r;
4964 this.y = c.g;
4965 this.z = c.b;
4966
4967 return this;
4968
4969 }
4970
4971 equals (v)
4972 {
4973
4974 return ((v.x === this.x) && (v.y === this.y) && (v.z === this.z));
4975
4976 }
4977
4978 fromArray (array, offset = 0)
4979 {
4980
4981 this.x = array[offset];
4982 this.y = array[offset + 1];
4983 this.z = array[offset + 2];
4984
4985 return this;
4986
4987 }
4988
4989 toArray (array = [], offset = 0)
4990 {
4991
4992 array[offset] = this.x;
4993 array[offset + 1] = this.y;
4994 array[offset + 2] = this.z;
4995
4996 return array;
4997
4998 }
4999
5000 fromBufferAttribute (attribute, index)
5001 {
5002
5003 this.x = attribute.getX(index);
5004 this.y = attribute.getY(index);
5005 this.z = attribute.getZ(index);
5006
5007 return this;
5008
5009 }
5010
5011 random ()
5012 {
5013
5014 this.x = Math.random();
5015 this.y = Math.random();
5016 this.z = Math.random();
5017
5018 return this;
5019
5020 }
5021
5022 randomDirection ()
5023 {
5024
5025 // https://mathworld.wolfram.com/SpherePointPicking.html
5026
5027 const theta = Math.random() * Math.PI * 2;
5028 const u = Math.random() * 2 - 1;
5029 const c = Math.sqrt(1 - u * u);
5030
5031 this.x = c * Math.cos(theta);
5032 this.y = u;
5033 this.z = c * Math.sin(theta);
5034
5035 return this;
5036
5037 }
5038
5039 *[Symbol.iterator] ()
5040 {
5041
5042 yield this.x;
5043 yield this.y;
5044 yield this.z;
5045
5046 }
5047
5048}
5049
5050const _vector$c = /*@__PURE__*/ new Vector3();
5051const _quaternion$4 = /*@__PURE__*/ new Quaternion();
5052
5053class Box3
5054{
5055
5056 constructor(min = new Vector3(+ Infinity, + Infinity, + Infinity), max = new Vector3(- Infinity, - Infinity, - Infinity))
5057 {
5058
5059 this.isBox3 = true;
5060
5061 this.min = min;
5062 this.max = max;
5063
5064 }
5065
5066 set (min, max)
5067 {
5068
5069 this.min.copy(min);
5070 this.max.copy(max);
5071
5072 return this;
5073
5074 }
5075
5076 setFromArray (array)
5077 {
5078
5079 this.makeEmpty();
5080
5081 for (let i = 0, il = array.length; i < il; i += 3)
5082 {
5083
5084 this.expandByPoint(_vector$b.fromArray(array, i));
5085
5086 }
5087
5088 return this;
5089
5090 }
5091
5092 setFromBufferAttribute (attribute)
5093 {
5094
5095 this.makeEmpty();
5096
5097 for (let i = 0, il = attribute.count; i < il; i++)
5098 {
5099
5100 this.expandByPoint(_vector$b.fromBufferAttribute(attribute, i));
5101
5102 }
5103
5104 return this;
5105
5106 }
5107
5108 setFromPoints (points)
5109 {
5110
5111 this.makeEmpty();
5112
5113 for (let i = 0, il = points.length; i < il; i++)
5114 {
5115
5116 this.expandByPoint(points[i]);
5117
5118 }
5119
5120 return this;
5121
5122 }
5123
5124 setFromCenterAndSize (center, size)
5125 {
5126
5127 const halfSize = _vector$b.copy(size).multiplyScalar(0.5);
5128
5129 this.min.copy(center).sub(halfSize);
5130 this.max.copy(center).add(halfSize);
5131
5132 return this;
5133
5134 }
5135
5136 setFromObject (object, precise = false)
5137 {
5138
5139 this.makeEmpty();
5140
5141 return this.expandByObject(object, precise);
5142
5143 }
5144
5145 clone ()
5146 {
5147
5148 return new this.constructor().copy(this);
5149
5150 }
5151
5152 copy (box)
5153 {
5154
5155 this.min.copy(box.min);
5156 this.max.copy(box.max);
5157
5158 return this;
5159
5160 }
5161
5162 makeEmpty ()
5163 {
5164
5165 this.min.x = this.min.y = this.min.z = + Infinity;
5166 this.max.x = this.max.y = this.max.z = - Infinity;
5167
5168 return this;
5169
5170 }
5171
5172 isEmpty ()
5173 {
5174
5175 // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
5176
5177 return (this.max.x < this.min.x) || (this.max.y < this.min.y) || (this.max.z < this.min.z);
5178
5179 }
5180
5181 getCenter (target)
5182 {
5183
5184 return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
5185
5186 }
5187
5188 getSize (target)
5189 {
5190
5191 return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
5192
5193 }
5194
5195 expandByPoint (point)
5196 {
5197
5198 this.min.min(point);
5199 this.max.max(point);
5200
5201 return this;
5202
5203 }
5204
5205 expandByVector (vector)
5206 {
5207
5208 this.min.sub(vector);
5209 this.max.add(vector);
5210
5211 return this;
5212
5213 }
5214
5215 expandByScalar (scalar)
5216 {
5217
5218 this.min.addScalar(- scalar);
5219 this.max.addScalar(scalar);
5220
5221 return this;
5222
5223 }
5224
5225 expandByObject (object, precise = false)
5226 {
5227
5228 // Computes the world-axis-aligned bounding box of an object (including its children),
5229 // accounting for both the object's, and children's, world transforms
5230
5231 object.updateWorldMatrix(false, false);
5232
5233 const geometry = object.geometry;
5234
5235 if (geometry !== undefined)
5236 {
5237
5238 const positionAttribute = geometry.getAttribute('position');
5239
5240 // precise AABB computation based on vertex data requires at least a position attribute.
5241 // instancing isn't supported so far and uses the normal (conservative) code path.
5242
5243 if (precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true)
5244 {
5245
5246 for (let i = 0, l = positionAttribute.count; i < l; i++)
5247 {
5248
5249 if (object.isMesh === true)
5250 {
5251
5252 object.getVertexPosition(i, _vector$b);
5253
5254 } else
5255 {
5256
5257 _vector$b.fromBufferAttribute(positionAttribute, i);
5258
5259 }
5260
5261 _vector$b.applyMatrix4(object.matrixWorld);
5262 this.expandByPoint(_vector$b);
5263
5264 }
5265
5266 } else
5267 {
5268
5269 if (object.boundingBox !== undefined)
5270 {
5271
5272 // object-level bounding box
5273
5274 if (object.boundingBox === null)
5275 {
5276
5277 object.computeBoundingBox();
5278
5279 }
5280
5281 _box$4.copy(object.boundingBox);
5282
5283
5284 } else
5285 {
5286
5287 // geometry-level bounding box
5288
5289 if (geometry.boundingBox === null)
5290 {
5291
5292 geometry.computeBoundingBox();
5293
5294 }
5295
5296 _box$4.copy(geometry.boundingBox);
5297
5298 }
5299
5300 _box$4.applyMatrix4(object.matrixWorld);
5301
5302 this.union(_box$4);
5303
5304 }
5305
5306 }
5307
5308 const children = object.children;
5309
5310 for (let i = 0, l = children.length; i < l; i++)
5311 {
5312
5313 this.expandByObject(children[i], precise);
5314
5315 }
5316
5317 return this;
5318
5319 }
5320
5321 containsPoint (point)
5322 {
5323
5324 return point.x < this.min.x || point.x > this.max.x ||
5325 point.y < this.min.y || point.y > this.max.y ||
5326 point.z < this.min.z || point.z > this.max.z ? false : true;
5327
5328 }
5329
5330 containsBox (box)
5331 {
5332
5333 return this.min.x <= box.min.x && box.max.x <= this.max.x &&
5334 this.min.y <= box.min.y && box.max.y <= this.max.y &&
5335 this.min.z <= box.min.z && box.max.z <= this.max.z;
5336
5337 }
5338
5339 getParameter (point, target)
5340 {
5341
5342 // This can potentially have a divide by zero if the box
5343 // has a size dimension of 0.
5344
5345 return target.set(
5346 (point.x - this.min.x) / (this.max.x - this.min.x),
5347 (point.y - this.min.y) / (this.max.y - this.min.y),
5348 (point.z - this.min.z) / (this.max.z - this.min.z)
5349 );
5350
5351 }
5352
5353 intersectsBox (box)
5354 {
5355
5356 // using 6 splitting planes to rule out intersections.
5357 return box.max.x < this.min.x || box.min.x > this.max.x ||
5358 box.max.y < this.min.y || box.min.y > this.max.y ||
5359 box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
5360
5361 }
5362
5363 intersectsSphere (sphere)
5364 {
5365
5366 // Find the point on the AABB closest to the sphere center.
5367 this.clampPoint(sphere.center, _vector$b);
5368
5369 // If that point is inside the sphere, the AABB and sphere intersect.
5370 return _vector$b.distanceToSquared(sphere.center) <= (sphere.radius * sphere.radius);
5371
5372 }
5373
5374 intersectsPlane (plane)
5375 {
5376
5377 // We compute the minimum and maximum dot product values. If those values
5378 // are on the same side (back or front) of the plane, then there is no intersection.
5379
5380 let min, max;
5381
5382 if (plane.normal.x > 0)
5383 {
5384
5385 min = plane.normal.x * this.min.x;
5386 max = plane.normal.x * this.max.x;
5387
5388 } else
5389 {
5390
5391 min = plane.normal.x * this.max.x;
5392 max = plane.normal.x * this.min.x;
5393
5394 }
5395
5396 if (plane.normal.y > 0)
5397 {
5398
5399 min += plane.normal.y * this.min.y;
5400 max += plane.normal.y * this.max.y;
5401
5402 } else
5403 {
5404
5405 min += plane.normal.y * this.max.y;
5406 max += plane.normal.y * this.min.y;
5407
5408 }
5409
5410 if (plane.normal.z > 0)
5411 {
5412
5413 min += plane.normal.z * this.min.z;
5414 max += plane.normal.z * this.max.z;
5415
5416 } else
5417 {
5418
5419 min += plane.normal.z * this.max.z;
5420 max += plane.normal.z * this.min.z;
5421
5422 }
5423
5424 return (min <= - plane.constant && max >= - plane.constant);
5425
5426 }
5427
5428 intersectsTriangle (triangle)
5429 {
5430
5431 if (this.isEmpty())
5432 {
5433
5434 return false;
5435
5436 }
5437
5438 // compute box center and extents
5439 this.getCenter(_center);
5440 _extents.subVectors(this.max, _center);
5441
5442 // translate triangle to aabb origin
5443 _v0$2.subVectors(triangle.a, _center);
5444 _v1$7.subVectors(triangle.b, _center);
5445 _v2$4.subVectors(triangle.c, _center);
5446
5447 // compute edge vectors for triangle
5448 _f0.subVectors(_v1$7, _v0$2);
5449 _f1.subVectors(_v2$4, _v1$7);
5450 _f2.subVectors(_v0$2, _v2$4);
5451
5452 // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
5453 // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
5454 // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
5455 let axes = [
5456 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
5457 _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
5458 - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
5459 ];
5460 if (!satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents))
5461 {
5462
5463 return false;
5464
5465 }
5466
5467 // test 3 face normals from the aabb
5468 axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
5469 if (!satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents))
5470 {
5471
5472 return false;
5473
5474 }
5475
5476 // finally testing the face normal of the triangle
5477 // use already existing triangle edge vectors here
5478 _triangleNormal.crossVectors(_f0, _f1);
5479 axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
5480
5481 return satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents);
5482
5483 }
5484
5485 clampPoint (point, target)
5486 {
5487
5488 return target.copy(point).clamp(this.min, this.max);
5489
5490 }
5491
5492 distanceToPoint (point)
5493 {
5494
5495 return this.clampPoint(point, _vector$b).distanceTo(point);
5496
5497 }
5498
5499 getBoundingSphere (target)
5500 {
5501
5502 if (this.isEmpty())
5503 {
5504
5505 target.makeEmpty();
5506
5507 } else
5508 {
5509
5510 this.getCenter(target.center);
5511
5512 target.radius = this.getSize(_vector$b).length() * 0.5;
5513
5514 }
5515
5516 return target;
5517
5518 }
5519
5520 intersect (box)
5521 {
5522
5523 this.min.max(box.min);
5524 this.max.min(box.max);
5525
5526 // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
5527 if (this.isEmpty()) this.makeEmpty();
5528
5529 return this;
5530
5531 }
5532
5533 union (box)
5534 {
5535
5536 this.min.min(box.min);
5537 this.max.max(box.max);
5538
5539 return this;
5540
5541 }
5542
5543 applyMatrix4 (matrix)
5544 {
5545
5546 // transform of empty box is an empty box.
5547 if (this.isEmpty()) return this;
5548
5549 // NOTE: I am using a binary pattern to specify all 2^3 combinations below
5550 _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
5551 _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
5552 _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
5553 _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
5554 _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
5555 _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
5556 _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
5557 _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
5558
5559 this.setFromPoints(_points);
5560
5561 return this;
5562
5563 }
5564
5565 translate (offset)
5566 {
5567
5568 this.min.add(offset);
5569 this.max.add(offset);
5570
5571 return this;
5572
5573 }
5574
5575 equals (box)
5576 {
5577
5578 return box.min.equals(this.min) && box.max.equals(this.max);
5579
5580 }
5581
5582}
5583
5584const _points = [
5585 /*@__PURE__*/ new Vector3(),
5586 /*@__PURE__*/ new Vector3(),
5587 /*@__PURE__*/ new Vector3(),
5588 /*@__PURE__*/ new Vector3(),
5589 /*@__PURE__*/ new Vector3(),
5590 /*@__PURE__*/ new Vector3(),
5591 /*@__PURE__*/ new Vector3(),
5592 /*@__PURE__*/ new Vector3()
5593];
5594
5595const _vector$b = /*@__PURE__*/ new Vector3();
5596
5597const _box$4 = /*@__PURE__*/ new Box3();
5598
5599// triangle centered vertices
5600
5601const _v0$2 = /*@__PURE__*/ new Vector3();
5602const _v1$7 = /*@__PURE__*/ new Vector3();
5603const _v2$4 = /*@__PURE__*/ new Vector3();
5604
5605// triangle edge vectors
5606
5607const _f0 = /*@__PURE__*/ new Vector3();
5608const _f1 = /*@__PURE__*/ new Vector3();
5609const _f2 = /*@__PURE__*/ new Vector3();
5610
5611const _center = /*@__PURE__*/ new Vector3();
5612const _extents = /*@__PURE__*/ new Vector3();
5613const _triangleNormal = /*@__PURE__*/ new Vector3();
5614const _testAxis = /*@__PURE__*/ new Vector3();
5615
5616function satForAxes (axes, v0, v1, v2, extents)
5617{
5618
5619 for (let i = 0, j = axes.length - 3; i <= j; i += 3)
5620 {
5621
5622 _testAxis.fromArray(axes, i);
5623 // project the aabb onto the separating axis
5624 const r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z);
5625 // project all 3 vertices of the triangle onto the separating axis
5626 const p0 = v0.dot(_testAxis);
5627 const p1 = v1.dot(_testAxis);
5628 const p2 = v2.dot(_testAxis);
5629 // actual test, basically see if either of the most extreme of the triangle points intersects r
5630 if (Math.max(- Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r)
5631 {
5632
5633 // points of the projected triangle are outside the projected half-length of the aabb
5634 // the axis is separating and we can exit
5635 return false;
5636
5637 }
5638
5639 }
5640
5641 return true;
5642
5643}
5644
5645const _box$3 = /*@__PURE__*/ new Box3();
5646const _v1$6 = /*@__PURE__*/ new Vector3();
5647const _v2$3 = /*@__PURE__*/ new Vector3();
5648
5649class Sphere
5650{
5651
5652 constructor(center = new Vector3(), radius = - 1)
5653 {
5654
5655 this.isSphere = true;
5656
5657 this.center = center;
5658 this.radius = radius;
5659
5660 }
5661
5662 set (center, radius)
5663 {
5664
5665 this.center.copy(center);
5666 this.radius = radius;
5667
5668 return this;
5669
5670 }
5671
5672 setFromPoints (points, optionalCenter)
5673 {
5674
5675 const center = this.center;
5676
5677 if (optionalCenter !== undefined)
5678 {
5679
5680 center.copy(optionalCenter);
5681
5682 } else
5683 {
5684
5685 _box$3.setFromPoints(points).getCenter(center);
5686
5687 }
5688
5689 let maxRadiusSq = 0;
5690
5691 for (let i = 0, il = points.length; i < il; i++)
5692 {
5693
5694 maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
5695
5696 }
5697
5698 this.radius = Math.sqrt(maxRadiusSq);
5699
5700 return this;
5701
5702 }
5703
5704 copy (sphere)
5705 {
5706
5707 this.center.copy(sphere.center);
5708 this.radius = sphere.radius;
5709
5710 return this;
5711
5712 }
5713
5714 isEmpty ()
5715 {
5716
5717 return (this.radius < 0);
5718
5719 }
5720
5721 makeEmpty ()
5722 {
5723
5724 this.center.set(0, 0, 0);
5725 this.radius = - 1;
5726
5727 return this;
5728
5729 }
5730
5731 containsPoint (point)
5732 {
5733
5734 return (point.distanceToSquared(this.center) <= (this.radius * this.radius));
5735
5736 }
5737
5738 distanceToPoint (point)
5739 {
5740
5741 return (point.distanceTo(this.center) - this.radius);
5742
5743 }
5744
5745 intersectsSphere (sphere)
5746 {
5747
5748 const radiusSum = this.radius + sphere.radius;
5749
5750 return sphere.center.distanceToSquared(this.center) <= (radiusSum * radiusSum);
5751
5752 }
5753
5754 intersectsBox (box)
5755 {
5756
5757 return box.intersectsSphere(this);
5758
5759 }
5760
5761 intersectsPlane (plane)
5762 {
5763
5764 return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
5765
5766 }
5767
5768 clampPoint (point, target)
5769 {
5770
5771 const deltaLengthSq = this.center.distanceToSquared(point);
5772
5773 target.copy(point);
5774
5775 if (deltaLengthSq > (this.radius * this.radius))
5776 {
5777
5778 target.sub(this.center).normalize();
5779 target.multiplyScalar(this.radius).add(this.center);
5780
5781 }
5782
5783 return target;
5784
5785 }
5786
5787 getBoundingBox (target)
5788 {
5789
5790 if (this.isEmpty())
5791 {
5792
5793 // Empty sphere produces empty bounding box
5794 target.makeEmpty();
5795 return target;
5796
5797 }
5798
5799 target.set(this.center, this.center);
5800 target.expandByScalar(this.radius);
5801
5802 return target;
5803
5804 }
5805
5806 applyMatrix4 (matrix)
5807 {
5808
5809 this.center.applyMatrix4(matrix);
5810 this.radius = this.radius * matrix.getMaxScaleOnAxis();
5811
5812 return this;
5813
5814 }
5815
5816 translate (offset)
5817 {
5818
5819 this.center.add(offset);
5820
5821 return this;
5822
5823 }
5824
5825 expandByPoint (point)
5826 {
5827
5828 if (this.isEmpty())
5829 {
5830
5831 this.center.copy(point);
5832
5833 this.radius = 0;
5834
5835 return this;
5836
5837 }
5838
5839 _v1$6.subVectors(point, this.center);
5840
5841 const lengthSq = _v1$6.lengthSq();
5842
5843 if (lengthSq > (this.radius * this.radius))
5844 {
5845
5846 // calculate the minimal sphere
5847
5848 const length = Math.sqrt(lengthSq);
5849
5850 const delta = (length - this.radius) * 0.5;
5851
5852 this.center.addScaledVector(_v1$6, delta / length);
5853
5854 this.radius += delta;
5855
5856 }
5857
5858 return this;
5859
5860 }
5861
5862 union (sphere)
5863 {
5864
5865 if (sphere.isEmpty())
5866 {
5867
5868 return this;
5869
5870 }
5871
5872 if (this.isEmpty())
5873 {
5874
5875 this.copy(sphere);
5876
5877 return this;
5878
5879 }
5880
5881 if (this.center.equals(sphere.center) === true)
5882 {
5883
5884 this.radius = Math.max(this.radius, sphere.radius);
5885
5886 } else
5887 {
5888
5889 _v2$3.subVectors(sphere.center, this.center).setLength(sphere.radius);
5890
5891 this.expandByPoint(_v1$6.copy(sphere.center).add(_v2$3));
5892
5893 this.expandByPoint(_v1$6.copy(sphere.center).sub(_v2$3));
5894
5895 }
5896
5897 return this;
5898
5899 }
5900
5901 equals (sphere)
5902 {
5903
5904 return sphere.center.equals(this.center) && (sphere.radius === this.radius);
5905
5906 }
5907
5908 clone ()
5909 {
5910
5911 return new this.constructor().copy(this);
5912
5913 }
5914
5915}
5916
5917const _vector$a = /*@__PURE__*/ new Vector3();
5918const _segCenter = /*@__PURE__*/ new Vector3();
5919const _segDir = /*@__PURE__*/ new Vector3();
5920const _diff = /*@__PURE__*/ new Vector3();
5921
5922const _edge1 = /*@__PURE__*/ new Vector3();
5923const _edge2 = /*@__PURE__*/ new Vector3();
5924const _normal$1 = /*@__PURE__*/ new Vector3();
5925
5926class Ray
5927{
5928
5929 constructor(origin = new Vector3(), direction = new Vector3(0, 0, - 1))
5930 {
5931
5932 this.origin = origin;
5933 this.direction = direction;
5934
5935 }
5936
5937 set (origin, direction)
5938 {
5939
5940 this.origin.copy(origin);
5941 this.direction.copy(direction);
5942
5943 return this;
5944
5945 }
5946
5947 copy (ray)
5948 {
5949
5950 this.origin.copy(ray.origin);
5951 this.direction.copy(ray.direction);
5952
5953 return this;
5954
5955 }
5956
5957 at (t, target)
5958 {
5959
5960 return target.copy(this.origin).addScaledVector(this.direction, t);
5961
5962 }
5963
5964 lookAt (v)
5965 {
5966
5967 this.direction.copy(v).sub(this.origin).normalize();
5968
5969 return this;
5970
5971 }
5972
5973 recast (t)
5974 {
5975
5976 this.origin.copy(this.at(t, _vector$a));
5977
5978 return this;
5979
5980 }
5981
5982 closestPointToPoint (point, target)
5983 {
5984
5985 target.subVectors(point, this.origin);
5986
5987 const directionDistance = target.dot(this.direction);
5988
5989 if (directionDistance < 0)
5990 {
5991
5992 return target.copy(this.origin);
5993
5994 }
5995
5996 return target.copy(this.origin).addScaledVector(this.direction, directionDistance);
5997
5998 }
5999
6000 distanceToPoint (point)
6001 {
6002
6003 return Math.sqrt(this.distanceSqToPoint(point));
6004
6005 }
6006
6007 distanceSqToPoint (point)
6008 {
6009
6010 const directionDistance = _vector$a.subVectors(point, this.origin).dot(this.direction);
6011
6012 // point behind the ray
6013
6014 if (directionDistance < 0)
6015 {
6016
6017 return this.origin.distanceToSquared(point);
6018
6019 }
6020
6021 _vector$a.copy(this.origin).addScaledVector(this.direction, directionDistance);
6022
6023 return _vector$a.distanceToSquared(point);
6024
6025 }
6026
6027 distanceSqToSegment (v0, v1, optionalPointOnRay, optionalPointOnSegment)
6028 {
6029
6030 // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h
6031 // It returns the min distance between the ray and the segment
6032 // defined by v0 and v1
6033 // It can also set two optional targets :
6034 // - The closest point on the ray
6035 // - The closest point on the segment
6036
6037 _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
6038 _segDir.copy(v1).sub(v0).normalize();
6039 _diff.copy(this.origin).sub(_segCenter);
6040
6041 const segExtent = v0.distanceTo(v1) * 0.5;
6042 const a01 = - this.direction.dot(_segDir);
6043 const b0 = _diff.dot(this.direction);
6044 const b1 = - _diff.dot(_segDir);
6045 const c = _diff.lengthSq();
6046 const det = Math.abs(1 - a01 * a01);
6047 let s0, s1, sqrDist, extDet;
6048
6049 if (det > 0)
6050 {
6051
6052 // The ray and segment are not parallel.
6053
6054 s0 = a01 * b1 - b0;
6055 s1 = a01 * b0 - b1;
6056 extDet = segExtent * det;
6057
6058 if (s0 >= 0)
6059 {
6060
6061 if (s1 >= - extDet)
6062 {
6063
6064 if (s1 <= extDet)
6065 {
6066
6067 // region 0
6068 // Minimum at interior points of ray and segment.
6069
6070 const invDet = 1 / det;
6071 s0 *= invDet;
6072 s1 *= invDet;
6073 sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
6074
6075 } else
6076 {
6077
6078 // region 1
6079
6080 s1 = segExtent;
6081 s0 = Math.max(0, - (a01 * s1 + b0));
6082 sqrDist = - s0 * s0 + s1 * (s1 + 2 * b1) + c;
6083
6084 }
6085
6086 } else
6087 {
6088
6089 // region 5
6090
6091 s1 = - segExtent;
6092 s0 = Math.max(0, - (a01 * s1 + b0));
6093 sqrDist = - s0 * s0 + s1 * (s1 + 2 * b1) + c;
6094
6095 }
6096
6097 } else
6098 {
6099
6100 if (s1 <= - extDet)
6101 {
6102
6103 // region 4
6104
6105 s0 = Math.max(0, - (- a01 * segExtent + b0));
6106 s1 = (s0 > 0) ? - segExtent : Math.min(Math.max(- segExtent, - b1), segExtent);
6107 sqrDist = - s0 * s0 + s1 * (s1 + 2 * b1) + c;
6108
6109 } else if (s1 <= extDet)
6110 {
6111
6112 // region 3
6113
6114 s0 = 0;
6115 s1 = Math.min(Math.max(- segExtent, - b1), segExtent);
6116 sqrDist = s1 * (s1 + 2 * b1) + c;
6117
6118 } else
6119 {
6120
6121 // region 2
6122
6123 s0 = Math.max(0, - (a01 * segExtent + b0));
6124 s1 = (s0 > 0) ? segExtent : Math.min(Math.max(- segExtent, - b1), segExtent);
6125 sqrDist = - s0 * s0 + s1 * (s1 + 2 * b1) + c;
6126
6127 }
6128
6129 }
6130
6131 } else
6132 {
6133
6134 // Ray and segment are parallel.
6135
6136 s1 = (a01 > 0) ? - segExtent : segExtent;
6137 s0 = Math.max(0, - (a01 * s1 + b0));
6138 sqrDist = - s0 * s0 + s1 * (s1 + 2 * b1) + c;
6139
6140 }
6141
6142 if (optionalPointOnRay)
6143 {
6144
6145 optionalPointOnRay.copy(this.origin).addScaledVector(this.direction, s0);
6146
6147 }
6148
6149 if (optionalPointOnSegment)
6150 {
6151
6152 optionalPointOnSegment.copy(_segCenter).addScaledVector(_segDir, s1);
6153
6154 }
6155
6156 return sqrDist;
6157
6158 }
6159
6160 intersectSphere (sphere, target)
6161 {
6162
6163 _vector$a.subVectors(sphere.center, this.origin);
6164 const tca = _vector$a.dot(this.direction);
6165 const d2 = _vector$a.dot(_vector$a) - tca * tca;
6166 const radius2 = sphere.radius * sphere.radius;
6167
6168 if (d2 > radius2) return null;
6169
6170 const thc = Math.sqrt(radius2 - d2);
6171
6172 // t0 = first intersect point - entrance on front of sphere
6173 const t0 = tca - thc;
6174
6175 // t1 = second intersect point - exit point on back of sphere
6176 const t1 = tca + thc;
6177
6178 // test to see if t1 is behind the ray - if so, return null
6179 if (t1 < 0) return null;
6180
6181 // test to see if t0 is behind the ray:
6182 // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
6183 // in order to always return an intersect point that is in front of the ray.
6184 if (t0 < 0) return this.at(t1, target);
6185
6186 // else t0 is in front of the ray, so return the first collision point scaled by t0
6187 return this.at(t0, target);
6188
6189 }
6190
6191 intersectsSphere (sphere)
6192 {
6193
6194 return this.distanceSqToPoint(sphere.center) <= (sphere.radius * sphere.radius);
6195
6196 }
6197
6198 distanceToPlane (plane)
6199 {
6200
6201 const denominator = plane.normal.dot(this.direction);
6202
6203 if (denominator === 0)
6204 {
6205
6206 // line is coplanar, return origin
6207 if (plane.distanceToPoint(this.origin) === 0)
6208 {
6209
6210 return 0;
6211
6212 }
6213
6214 // Null is preferable to undefined since undefined means.... it is undefined
6215
6216 return null;
6217
6218 }
6219
6220 const t = - (this.origin.dot(plane.normal) + plane.constant) / denominator;
6221
6222 // Return if the ray never intersects the plane
6223
6224 return t >= 0 ? t : null;
6225
6226 }
6227
6228 intersectPlane (plane, target)
6229 {
6230
6231 const t = this.distanceToPlane(plane);
6232
6233 if (t === null)
6234 {
6235
6236 return null;
6237
6238 }
6239
6240 return this.at(t, target);
6241
6242 }
6243
6244 intersectsPlane (plane)
6245 {
6246
6247 // check if the ray lies on the plane first
6248
6249 const distToPoint = plane.distanceToPoint(this.origin);
6250
6251 if (distToPoint === 0)
6252 {
6253
6254 return true;
6255
6256 }
6257
6258 const denominator = plane.normal.dot(this.direction);
6259
6260 if (denominator * distToPoint < 0)
6261 {
6262
6263 return true;
6264
6265 }
6266
6267 // ray origin is behind the plane (and is pointing behind it)
6268
6269 return false;
6270
6271 }
6272
6273 intersectBox (box, target)
6274 {
6275
6276 let tmin, tmax, tymin, tymax, tzmin, tzmax;
6277
6278 const invdirx = 1 / this.direction.x,
6279 invdiry = 1 / this.direction.y,
6280 invdirz = 1 / this.direction.z;
6281
6282 const origin = this.origin;
6283
6284 if (invdirx >= 0)
6285 {
6286
6287 tmin = (box.min.x - origin.x) * invdirx;
6288 tmax = (box.max.x - origin.x) * invdirx;
6289
6290 } else
6291 {
6292
6293 tmin = (box.max.x - origin.x) * invdirx;
6294 tmax = (box.min.x - origin.x) * invdirx;
6295
6296 }
6297
6298 if (invdiry >= 0)
6299 {
6300
6301 tymin = (box.min.y - origin.y) * invdiry;
6302 tymax = (box.max.y - origin.y) * invdiry;
6303
6304 } else
6305 {
6306
6307 tymin = (box.max.y - origin.y) * invdiry;
6308 tymax = (box.min.y - origin.y) * invdiry;
6309
6310 }
6311
6312 if ((tmin > tymax) || (tymin > tmax)) return null;
6313
6314 if (tymin > tmin || isNaN(tmin)) tmin = tymin;
6315
6316 if (tymax < tmax || isNaN(tmax)) tmax = tymax;
6317
6318 if (invdirz >= 0)
6319 {
6320
6321 tzmin = (box.min.z - origin.z) * invdirz;
6322 tzmax = (box.max.z - origin.z) * invdirz;
6323
6324 } else
6325 {
6326
6327 tzmin = (box.max.z - origin.z) * invdirz;
6328 tzmax = (box.min.z - origin.z) * invdirz;
6329
6330 }
6331
6332 if ((tmin > tzmax) || (tzmin > tmax)) return null;
6333
6334 if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
6335
6336 if (tzmax < tmax || tmax !== tmax) tmax = tzmax;
6337
6338 //return point closest to the ray (positive side)
6339
6340 if (tmax < 0) return null;
6341
6342 return this.at(tmin >= 0 ? tmin : tmax, target);
6343
6344 }
6345
6346 intersectsBox (box)
6347 {
6348
6349 return this.intersectBox(box, _vector$a) !== null;
6350
6351 }
6352
6353 intersectTriangle (a, b, c, backfaceCulling, target)
6354 {
6355
6356 // Compute the offset origin, edges, and normal.
6357
6358 // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
6359
6360 _edge1.subVectors(b, a);
6361 _edge2.subVectors(c, a);
6362 _normal$1.crossVectors(_edge1, _edge2);
6363
6364 // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
6365 // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
6366 // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
6367 // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
6368 // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
6369 let DdN = this.direction.dot(_normal$1);
6370 let sign;
6371
6372 if (DdN > 0)
6373 {
6374
6375 if (backfaceCulling) return null;
6376 sign = 1;
6377
6378 } else if (DdN < 0)
6379 {
6380
6381 sign = - 1;
6382 DdN = - DdN;
6383
6384 } else
6385 {
6386
6387 return null;
6388
6389 }
6390
6391 _diff.subVectors(this.origin, a);
6392 const DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2));
6393
6394 // b1 < 0, no intersection
6395 if (DdQxE2 < 0)
6396 {
6397
6398 return null;
6399
6400 }
6401
6402 const DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff));
6403
6404 // b2 < 0, no intersection
6405 if (DdE1xQ < 0)
6406 {
6407
6408 return null;
6409
6410 }
6411
6412 // b1+b2 > 1, no intersection
6413 if (DdQxE2 + DdE1xQ > DdN)
6414 {
6415
6416 return null;
6417
6418 }
6419
6420 // Line intersects triangle, check if ray does.
6421 const QdN = - sign * _diff.dot(_normal$1);
6422
6423 // t < 0, no intersection
6424 if (QdN < 0)
6425 {
6426
6427 return null;
6428
6429 }
6430
6431 // Ray intersects triangle.
6432 return this.at(QdN / DdN, target);
6433
6434 }
6435
6436 applyMatrix4 (matrix4)
6437 {
6438
6439 this.origin.applyMatrix4(matrix4);
6440 this.direction.transformDirection(matrix4);
6441
6442 return this;
6443
6444 }
6445
6446 equals (ray)
6447 {
6448
6449 return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
6450
6451 }
6452
6453 clone ()
6454 {
6455
6456 return new this.constructor().copy(this);
6457
6458 }
6459
6460}
6461
6462class Matrix4
6463{
6464
6465 constructor(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44)
6466 {
6467
6468 Matrix4.prototype.isMatrix4 = true;
6469
6470 this.elements = [
6471
6472 1, 0, 0, 0,
6473 0, 1, 0, 0,
6474 0, 0, 1, 0,
6475 0, 0, 0, 1
6476
6477 ];
6478
6479 if (n11 !== undefined)
6480 {
6481
6482 this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44);
6483
6484 }
6485
6486 }
6487
6488 set (n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44)
6489 {
6490
6491 const te = this.elements;
6492
6493 te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14;
6494 te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24;
6495 te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34;
6496 te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44;
6497
6498 return this;
6499
6500 }
6501
6502 identity ()
6503 {
6504
6505 this.set(
6506
6507 1, 0, 0, 0,
6508 0, 1, 0, 0,
6509 0, 0, 1, 0,
6510 0, 0, 0, 1
6511
6512 );
6513
6514 return this;
6515
6516 }
6517
6518 clone ()
6519 {
6520
6521 return new Matrix4().fromArray(this.elements);
6522
6523 }
6524
6525 copy (m)
6526 {
6527
6528 const te = this.elements;
6529 const me = m.elements;
6530
6531 te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; te[3] = me[3];
6532 te[4] = me[4]; te[5] = me[5]; te[6] = me[6]; te[7] = me[7];
6533 te[8] = me[8]; te[9] = me[9]; te[10] = me[10]; te[11] = me[11];
6534 te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; te[15] = me[15];
6535
6536 return this;
6537
6538 }
6539
6540 copyPosition (m)
6541 {
6542
6543 const te = this.elements, me = m.elements;
6544
6545 te[12] = me[12];
6546 te[13] = me[13];
6547 te[14] = me[14];
6548
6549 return this;
6550
6551 }
6552
6553 setFromMatrix3 (m)
6554 {
6555
6556 const me = m.elements;
6557
6558 this.set(
6559
6560 me[0], me[3], me[6], 0,
6561 me[1], me[4], me[7], 0,
6562 me[2], me[5], me[8], 0,
6563 0, 0, 0, 1
6564
6565 );
6566
6567 return this;
6568
6569 }
6570
6571 extractBasis (xAxis, yAxis, zAxis)
6572 {
6573
6574 xAxis.setFromMatrixColumn(this, 0);
6575 yAxis.setFromMatrixColumn(this, 1);
6576 zAxis.setFromMatrixColumn(this, 2);
6577
6578 return this;
6579
6580 }
6581
6582 makeBasis (xAxis, yAxis, zAxis)
6583 {
6584
6585 this.set(
6586 xAxis.x, yAxis.x, zAxis.x, 0,
6587 xAxis.y, yAxis.y, zAxis.y, 0,
6588 xAxis.z, yAxis.z, zAxis.z, 0,
6589 0, 0, 0, 1
6590 );
6591
6592 return this;
6593
6594 }
6595
6596 extractRotation (m)
6597 {
6598
6599 // this method does not support reflection matrices
6600
6601 const te = this.elements;
6602 const me = m.elements;
6603
6604 const scaleX = 1 / _v1$5.setFromMatrixColumn(m, 0).length();
6605 const scaleY = 1 / _v1$5.setFromMatrixColumn(m, 1).length();
6606 const scaleZ = 1 / _v1$5.setFromMatrixColumn(m, 2).length();
6607
6608 te[0] = me[0] * scaleX;
6609 te[1] = me[1] * scaleX;
6610 te[2] = me[2] * scaleX;
6611 te[3] = 0;
6612
6613 te[4] = me[4] * scaleY;
6614 te[5] = me[5] * scaleY;
6615 te[6] = me[6] * scaleY;
6616 te[7] = 0;
6617
6618 te[8] = me[8] * scaleZ;
6619 te[9] = me[9] * scaleZ;
6620 te[10] = me[10] * scaleZ;
6621 te[11] = 0;
6622
6623 te[12] = 0;
6624 te[13] = 0;
6625 te[14] = 0;
6626 te[15] = 1;
6627
6628 return this;
6629
6630 }
6631
6632 makeRotationFromEuler (euler)
6633 {
6634
6635 const te = this.elements;
6636
6637 const x = euler.x, y = euler.y, z = euler.z;
6638 const a = Math.cos(x), b = Math.sin(x);
6639 const c = Math.cos(y), d = Math.sin(y);
6640 const e = Math.cos(z), f = Math.sin(z);
6641
6642 if (euler.order === 'XYZ')
6643 {
6644
6645 const ae = a * e, af = a * f, be = b * e, bf = b * f;
6646
6647 te[0] = c * e;
6648 te[4] = - c * f;
6649 te[8] = d;
6650
6651 te[1] = af + be * d;
6652 te[5] = ae - bf * d;
6653 te[9] = - b * c;
6654
6655 te[2] = bf - ae * d;
6656 te[6] = be + af * d;
6657 te[10] = a * c;
6658
6659 } else if (euler.order === 'YXZ')
6660 {
6661
6662 const ce = c * e, cf = c * f, de = d * e, df = d * f;
6663
6664 te[0] = ce + df * b;
6665 te[4] = de * b - cf;
6666 te[8] = a * d;
6667
6668 te[1] = a * f;
6669 te[5] = a * e;
6670 te[9] = - b;
6671
6672 te[2] = cf * b - de;
6673 te[6] = df + ce * b;
6674 te[10] = a * c;
6675
6676 } else if (euler.order === 'ZXY')
6677 {
6678
6679 const ce = c * e, cf = c * f, de = d * e, df = d * f;
6680
6681 te[0] = ce - df * b;
6682 te[4] = - a * f;
6683 te[8] = de + cf * b;
6684
6685 te[1] = cf + de * b;
6686 te[5] = a * e;
6687 te[9] = df - ce * b;
6688
6689 te[2] = - a * d;
6690 te[6] = b;
6691 te[10] = a * c;
6692
6693 } else if (euler.order === 'ZYX')
6694 {
6695
6696 const ae = a * e, af = a * f, be = b * e, bf = b * f;
6697
6698 te[0] = c * e;
6699 te[4] = be * d - af;
6700 te[8] = ae * d + bf;
6701
6702 te[1] = c * f;
6703 te[5] = bf * d + ae;
6704 te[9] = af * d - be;
6705
6706 te[2] = - d;
6707 te[6] = b * c;
6708 te[10] = a * c;
6709
6710 } else if (euler.order === 'YZX')
6711 {
6712
6713 const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
6714
6715 te[0] = c * e;
6716 te[4] = bd - ac * f;
6717 te[8] = bc * f + ad;
6718
6719 te[1] = f;
6720 te[5] = a * e;
6721 te[9] = - b * e;
6722
6723 te[2] = - d * e;
6724 te[6] = ad * f + bc;
6725 te[10] = ac - bd * f;
6726
6727 } else if (euler.order === 'XZY')
6728 {
6729
6730 const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
6731
6732 te[0] = c * e;
6733 te[4] = - f;
6734 te[8] = d * e;
6735
6736 te[1] = ac * f + bd;
6737 te[5] = a * e;
6738 te[9] = ad * f - bc;
6739
6740 te[2] = bc * f - ad;
6741 te[6] = b * e;
6742 te[10] = bd * f + ac;
6743
6744 }
6745
6746 // bottom row
6747 te[3] = 0;
6748 te[7] = 0;
6749 te[11] = 0;
6750
6751 // last column
6752 te[12] = 0;
6753 te[13] = 0;
6754 te[14] = 0;
6755 te[15] = 1;
6756
6757 return this;
6758
6759 }
6760
6761 makeRotationFromQuaternion (q)
6762 {
6763
6764 return this.compose(_zero, q, _one);
6765
6766 }
6767
6768 lookAt (eye, target, up)
6769 {
6770
6771 const te = this.elements;
6772
6773 _z.subVectors(eye, target);
6774
6775 if (_z.lengthSq() === 0)
6776 {
6777
6778 // eye and target are in the same position
6779
6780 _z.z = 1;
6781
6782 }
6783
6784 _z.normalize();
6785 _x.crossVectors(up, _z);
6786
6787 if (_x.lengthSq() === 0)
6788 {
6789
6790 // up and z are parallel
6791
6792 if (Math.abs(up.z) === 1)
6793 {
6794
6795 _z.x += 0.0001;
6796
6797 } else
6798 {
6799
6800 _z.z += 0.0001;
6801
6802 }
6803
6804 _z.normalize();
6805 _x.crossVectors(up, _z);
6806
6807 }
6808
6809 _x.normalize();
6810 _y.crossVectors(_z, _x);
6811
6812 te[0] = _x.x; te[4] = _y.x; te[8] = _z.x;
6813 te[1] = _x.y; te[5] = _y.y; te[9] = _z.y;
6814 te[2] = _x.z; te[6] = _y.z; te[10] = _z.z;
6815
6816 return this;
6817
6818 }
6819
6820 multiply (m)
6821 {
6822
6823 return this.multiplyMatrices(this, m);
6824
6825 }
6826
6827 premultiply (m)
6828 {
6829
6830 return this.multiplyMatrices(m, this);
6831
6832 }
6833
6834 multiplyMatrices (a, b)
6835 {
6836
6837 const ae = a.elements;
6838 const be = b.elements;
6839 const te = this.elements;
6840
6841 const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
6842 const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
6843 const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
6844 const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
6845
6846 const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
6847 const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
6848 const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
6849 const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
6850
6851 te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
6852 te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
6853 te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
6854 te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
6855
6856 te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
6857 te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
6858 te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
6859 te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
6860
6861 te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
6862 te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
6863 te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
6864 te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
6865
6866 te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
6867 te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
6868 te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
6869 te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
6870
6871 return this;
6872
6873 }
6874
6875 multiplyScalar (s)
6876 {
6877
6878 const te = this.elements;
6879
6880 te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s;
6881 te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s;
6882 te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s;
6883 te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s;
6884
6885 return this;
6886
6887 }
6888
6889 determinant ()
6890 {
6891
6892 const te = this.elements;
6893
6894 const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
6895 const n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
6896 const n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
6897 const n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
6898
6899 //TODO: make this more efficient
6900 //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
6901
6902 return (
6903 n41 * (
6904 + n14 * n23 * n32
6905 - n13 * n24 * n32
6906 - n14 * n22 * n33
6907 + n12 * n24 * n33
6908 + n13 * n22 * n34
6909 - n12 * n23 * n34
6910 ) +
6911 n42 * (
6912 + n11 * n23 * n34
6913 - n11 * n24 * n33
6914 + n14 * n21 * n33
6915 - n13 * n21 * n34
6916 + n13 * n24 * n31
6917 - n14 * n23 * n31
6918 ) +
6919 n43 * (
6920 + n11 * n24 * n32
6921 - n11 * n22 * n34
6922 - n14 * n21 * n32
6923 + n12 * n21 * n34
6924 + n14 * n22 * n31
6925 - n12 * n24 * n31
6926 ) +
6927 n44 * (
6928 - n13 * n22 * n31
6929 - n11 * n23 * n32
6930 + n11 * n22 * n33
6931 + n13 * n21 * n32
6932 - n12 * n21 * n33
6933 + n12 * n23 * n31
6934 )
6935
6936 );
6937
6938 }
6939
6940 transpose ()
6941 {
6942
6943 const te = this.elements;
6944 let tmp;
6945
6946 tmp = te[1]; te[1] = te[4]; te[4] = tmp;
6947 tmp = te[2]; te[2] = te[8]; te[8] = tmp;
6948 tmp = te[6]; te[6] = te[9]; te[9] = tmp;
6949
6950 tmp = te[3]; te[3] = te[12]; te[12] = tmp;
6951 tmp = te[7]; te[7] = te[13]; te[13] = tmp;
6952 tmp = te[11]; te[11] = te[14]; te[14] = tmp;
6953
6954 return this;
6955
6956 }
6957
6958 setPosition (x, y, z)
6959 {
6960
6961 const te = this.elements;
6962
6963 if (x.isVector3)
6964 {
6965
6966 te[12] = x.x;
6967 te[13] = x.y;
6968 te[14] = x.z;
6969
6970 } else
6971 {
6972
6973 te[12] = x;
6974 te[13] = y;
6975 te[14] = z;
6976
6977 }
6978
6979 return this;
6980
6981 }
6982
6983 invert ()
6984 {
6985
6986 // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
6987 const te = this.elements,
6988
6989 n11 = te[0], n21 = te[1], n31 = te[2], n41 = te[3],
6990 n12 = te[4], n22 = te[5], n32 = te[6], n42 = te[7],
6991 n13 = te[8], n23 = te[9], n33 = te[10], n43 = te[11],
6992 n14 = te[12], n24 = te[13], n34 = te[14], n44 = te[15],
6993
6994 t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
6995 t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
6996 t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
6997 t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
6998
6999 const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
7000
7001 if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
7002
7003 const detInv = 1 / det;
7004
7005 te[0] = t11 * detInv;
7006 te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
7007 te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
7008 te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
7009
7010 te[4] = t12 * detInv;
7011 te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
7012 te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
7013 te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
7014
7015 te[8] = t13 * detInv;
7016 te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
7017 te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
7018 te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
7019
7020 te[12] = t14 * detInv;
7021 te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
7022 te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
7023 te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
7024
7025 return this;
7026
7027 }
7028
7029 scale (v)
7030 {
7031
7032 const te = this.elements;
7033 const x = v.x, y = v.y, z = v.z;
7034
7035 te[0] *= x; te[4] *= y; te[8] *= z;
7036 te[1] *= x; te[5] *= y; te[9] *= z;
7037 te[2] *= x; te[6] *= y; te[10] *= z;
7038 te[3] *= x; te[7] *= y; te[11] *= z;
7039
7040 return this;
7041
7042 }
7043
7044 getMaxScaleOnAxis ()
7045 {
7046
7047 const te = this.elements;
7048
7049 const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
7050 const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
7051 const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
7052
7053 return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
7054
7055 }
7056
7057 makeTranslation (x, y, z)
7058 {
7059
7060 if (x.isVector3)
7061 {
7062
7063 this.set(
7064
7065 1, 0, 0, x.x,
7066 0, 1, 0, x.y,
7067 0, 0, 1, x.z,
7068 0, 0, 0, 1
7069
7070 );
7071
7072 } else
7073 {
7074
7075 this.set(
7076
7077 1, 0, 0, x,
7078 0, 1, 0, y,
7079 0, 0, 1, z,
7080 0, 0, 0, 1
7081
7082 );
7083
7084 }
7085
7086 return this;
7087
7088 }
7089
7090 makeRotationX (theta)
7091 {
7092
7093 const c = Math.cos(theta), s = Math.sin(theta);
7094
7095 this.set(
7096
7097 1, 0, 0, 0,
7098 0, c, - s, 0,
7099 0, s, c, 0,
7100 0, 0, 0, 1
7101
7102 );
7103
7104 return this;
7105
7106 }
7107
7108 makeRotationY (theta)
7109 {
7110
7111 const c = Math.cos(theta), s = Math.sin(theta);
7112
7113 this.set(
7114
7115 c, 0, s, 0,
7116 0, 1, 0, 0,
7117 - s, 0, c, 0,
7118 0, 0, 0, 1
7119
7120 );
7121
7122 return this;
7123
7124 }
7125
7126 makeRotationZ (theta)
7127 {
7128
7129 const c = Math.cos(theta), s = Math.sin(theta);
7130
7131 this.set(
7132
7133 c, - s, 0, 0,
7134 s, c, 0, 0,
7135 0, 0, 1, 0,
7136 0, 0, 0, 1
7137
7138 );
7139
7140 return this;
7141
7142 }
7143
7144 makeRotationAxis (axis, angle)
7145 {
7146
7147 // Based on http://www.gamedev.net/reference/articles/article1199.asp
7148
7149 const c = Math.cos(angle);
7150 const s = Math.sin(angle);
7151 const t = 1 - c;
7152 const x = axis.x, y = axis.y, z = axis.z;
7153 const tx = t * x, ty = t * y;
7154
7155 this.set(
7156
7157 tx * x + c, tx * y - s * z, tx * z + s * y, 0,
7158 tx * y + s * z, ty * y + c, ty * z - s * x, 0,
7159 tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
7160 0, 0, 0, 1
7161
7162 );
7163
7164 return this;
7165
7166 }
7167
7168 makeScale (x, y, z)
7169 {
7170
7171 this.set(
7172
7173 x, 0, 0, 0,
7174 0, y, 0, 0,
7175 0, 0, z, 0,
7176 0, 0, 0, 1
7177
7178 );
7179
7180 return this;
7181
7182 }
7183
7184 makeShear (xy, xz, yx, yz, zx, zy)
7185 {
7186
7187 this.set(
7188
7189 1, yx, zx, 0,
7190 xy, 1, zy, 0,
7191 xz, yz, 1, 0,
7192 0, 0, 0, 1
7193
7194 );
7195
7196 return this;
7197
7198 }
7199
7200 compose (position, quaternion, scale)
7201 {
7202
7203 const te = this.elements;
7204
7205 const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
7206 const x2 = x + x, y2 = y + y, z2 = z + z;
7207 const xx = x * x2, xy = x * y2, xz = x * z2;
7208 const yy = y * y2, yz = y * z2, zz = z * z2;
7209 const wx = w * x2, wy = w * y2, wz = w * z2;
7210
7211 const sx = scale.x, sy = scale.y, sz = scale.z;
7212
7213 te[0] = (1 - (yy + zz)) * sx;
7214 te[1] = (xy + wz) * sx;
7215 te[2] = (xz - wy) * sx;
7216 te[3] = 0;
7217
7218 te[4] = (xy - wz) * sy;
7219 te[5] = (1 - (xx + zz)) * sy;
7220 te[6] = (yz + wx) * sy;
7221 te[7] = 0;
7222
7223 te[8] = (xz + wy) * sz;
7224 te[9] = (yz - wx) * sz;
7225 te[10] = (1 - (xx + yy)) * sz;
7226 te[11] = 0;
7227
7228 te[12] = position.x;
7229 te[13] = position.y;
7230 te[14] = position.z;
7231 te[15] = 1;
7232
7233 return this;
7234
7235 }
7236
7237 decompose (position, quaternion, scale)
7238 {
7239
7240 const te = this.elements;
7241
7242 let sx = _v1$5.set(te[0], te[1], te[2]).length();
7243 const sy = _v1$5.set(te[4], te[5], te[6]).length();
7244 const sz = _v1$5.set(te[8], te[9], te[10]).length();
7245
7246 // if determine is negative, we need to invert one scale
7247 const det = this.determinant();
7248 if (det < 0) sx = - sx;
7249
7250 position.x = te[12];
7251 position.y = te[13];
7252 position.z = te[14];
7253
7254 // scale the rotation part
7255 _m1$4.copy(this);
7256
7257 const invSX = 1 / sx;
7258 const invSY = 1 / sy;
7259 const invSZ = 1 / sz;
7260
7261 _m1$4.elements[0] *= invSX;
7262 _m1$4.elements[1] *= invSX;
7263 _m1$4.elements[2] *= invSX;
7264
7265 _m1$4.elements[4] *= invSY;
7266 _m1$4.elements[5] *= invSY;
7267 _m1$4.elements[6] *= invSY;
7268
7269 _m1$4.elements[8] *= invSZ;
7270 _m1$4.elements[9] *= invSZ;
7271 _m1$4.elements[10] *= invSZ;
7272
7273 quaternion.setFromRotationMatrix(_m1$4);
7274
7275 scale.x = sx;
7276 scale.y = sy;
7277 scale.z = sz;
7278
7279 return this;
7280
7281 }
7282
7283 makePerspective (left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem)
7284 {
7285
7286 const te = this.elements;
7287 const x = 2 * near / (right - left);
7288 const y = 2 * near / (top - bottom);
7289
7290 const a = (right + left) / (right - left);
7291 const b = (top + bottom) / (top - bottom);
7292
7293 let c, d;
7294
7295 if (coordinateSystem === WebGLCoordinateSystem)
7296 {
7297
7298 c = - (far + near) / (far - near);
7299 d = (- 2 * far * near) / (far - near);
7300
7301 } else if (coordinateSystem === WebGPUCoordinateSystem)
7302 {
7303
7304 c = - far / (far - near);
7305 d = (- far * near) / (far - near);
7306
7307 } else
7308 {
7309
7310 throw new Error('THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem);
7311
7312 }
7313
7314 te[0] = x; te[4] = 0; te[8] = a; te[12] = 0;
7315 te[1] = 0; te[5] = y; te[9] = b; te[13] = 0;
7316 te[2] = 0; te[6] = 0; te[10] = c; te[14] = d;
7317 te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0;
7318
7319 return this;
7320
7321 }
7322
7323 makeOrthographic (left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem)
7324 {
7325
7326 const te = this.elements;
7327 const w = 1.0 / (right - left);
7328 const h = 1.0 / (top - bottom);
7329 const p = 1.0 / (far - near);
7330
7331 const x = (right + left) * w;
7332 const y = (top + bottom) * h;
7333
7334 let z, zInv;
7335
7336 if (coordinateSystem === WebGLCoordinateSystem)
7337 {
7338
7339 z = (far + near) * p;
7340 zInv = - 2 * p;
7341
7342 } else if (coordinateSystem === WebGPUCoordinateSystem)
7343 {
7344
7345 z = near * p;
7346 zInv = - 1 * p;
7347
7348 } else
7349 {
7350
7351 throw new Error('THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem);
7352
7353 }
7354
7355 te[0] = 2 * w; te[4] = 0; te[8] = 0; te[12] = - x;
7356 te[1] = 0; te[5] = 2 * h; te[9] = 0; te[13] = - y;
7357 te[2] = 0; te[6] = 0; te[10] = zInv; te[14] = - z;
7358 te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1;
7359
7360 return this;
7361
7362 }
7363
7364 equals (matrix)
7365 {
7366
7367 const te = this.elements;
7368 const me = matrix.elements;
7369
7370 for (let i = 0; i < 16; i++)
7371 {
7372
7373 if (te[i] !== me[i]) return false;
7374
7375 }
7376
7377 return true;
7378
7379 }
7380
7381 fromArray (array, offset = 0)
7382 {
7383
7384 for (let i = 0; i < 16; i++)
7385 {
7386
7387 this.elements[i] = array[i + offset];
7388
7389 }
7390
7391 return this;
7392
7393 }
7394
7395 toArray (array = [], offset = 0)
7396 {
7397
7398 const te = this.elements;
7399
7400 array[offset] = te[0];
7401 array[offset + 1] = te[1];
7402 array[offset + 2] = te[2];
7403 array[offset + 3] = te[3];
7404
7405 array[offset + 4] = te[4];
7406 array[offset + 5] = te[5];
7407 array[offset + 6] = te[6];
7408 array[offset + 7] = te[7];
7409
7410 array[offset + 8] = te[8];
7411 array[offset + 9] = te[9];
7412 array[offset + 10] = te[10];
7413 array[offset + 11] = te[11];
7414
7415 array[offset + 12] = te[12];
7416 array[offset + 13] = te[13];
7417 array[offset + 14] = te[14];
7418 array[offset + 15] = te[15];
7419
7420 return array;
7421
7422 }
7423
7424}
7425
7426const _v1$5 = /*@__PURE__*/ new Vector3();
7427const _m1$4 = /*@__PURE__*/ new Matrix4();
7428const _zero = /*@__PURE__*/ new Vector3(0, 0, 0);
7429const _one = /*@__PURE__*/ new Vector3(1, 1, 1);
7430const _x = /*@__PURE__*/ new Vector3();
7431const _y = /*@__PURE__*/ new Vector3();
7432const _z = /*@__PURE__*/ new Vector3();
7433
7434const _matrix$2 = /*@__PURE__*/ new Matrix4();
7435const _quaternion$3 = /*@__PURE__*/ new Quaternion();
7436
7437class Euler
7438{
7439
7440 constructor(x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER)
7441 {
7442
7443 this.isEuler = true;
7444
7445 this._x = x;
7446 this._y = y;
7447 this._z = z;
7448 this._order = order;
7449
7450 }
7451
7452 get x ()
7453 {
7454
7455 return this._x;
7456
7457 }
7458
7459 set x (value)
7460 {
7461
7462 this._x = value;
7463 this._onChangeCallback();
7464
7465 }
7466
7467 get y ()
7468 {
7469
7470 return this._y;
7471
7472 }
7473
7474 set y (value)
7475 {
7476
7477 this._y = value;
7478 this._onChangeCallback();
7479
7480 }
7481
7482 get z ()
7483 {
7484
7485 return this._z;
7486
7487 }
7488
7489 set z (value)
7490 {
7491
7492 this._z = value;
7493 this._onChangeCallback();
7494
7495 }
7496
7497 get order ()
7498 {
7499
7500 return this._order;
7501
7502 }
7503
7504 set order (value)
7505 {
7506
7507 this._order = value;
7508 this._onChangeCallback();
7509
7510 }
7511
7512 set (x, y, z, order = this._order)
7513 {
7514
7515 this._x = x;
7516 this._y = y;
7517 this._z = z;
7518 this._order = order;
7519
7520 this._onChangeCallback();
7521
7522 return this;
7523
7524 }
7525
7526 clone ()
7527 {
7528
7529 return new this.constructor(this._x, this._y, this._z, this._order);
7530
7531 }
7532
7533 copy (euler)
7534 {
7535
7536 this._x = euler._x;
7537 this._y = euler._y;
7538 this._z = euler._z;
7539 this._order = euler._order;
7540
7541 this._onChangeCallback();
7542
7543 return this;
7544
7545 }
7546
7547 setFromRotationMatrix (m, order = this._order, update = true)
7548 {
7549
7550 // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
7551
7552 const te = m.elements;
7553 const m11 = te[0], m12 = te[4], m13 = te[8];
7554 const m21 = te[1], m22 = te[5], m23 = te[9];
7555 const m31 = te[2], m32 = te[6], m33 = te[10];
7556
7557 switch (order)
7558 {
7559
7560 case 'XYZ':
7561
7562 this._y = Math.asin(clamp(m13, - 1, 1));
7563
7564 if (Math.abs(m13) < 0.9999999)
7565 {
7566
7567 this._x = Math.atan2(- m23, m33);
7568 this._z = Math.atan2(- m12, m11);
7569
7570 } else
7571 {
7572
7573 this._x = Math.atan2(m32, m22);
7574 this._z = 0;
7575
7576 }
7577
7578 break;
7579
7580 case 'YXZ':
7581
7582 this._x = Math.asin(- clamp(m23, - 1, 1));
7583
7584 if (Math.abs(m23) < 0.9999999)
7585 {
7586
7587 this._y = Math.atan2(m13, m33);
7588 this._z = Math.atan2(m21, m22);
7589
7590 } else
7591 {
7592
7593 this._y = Math.atan2(- m31, m11);
7594 this._z = 0;
7595
7596 }
7597
7598 break;
7599
7600 case 'ZXY':
7601
7602 this._x = Math.asin(clamp(m32, - 1, 1));
7603
7604 if (Math.abs(m32) < 0.9999999)
7605 {
7606
7607 this._y = Math.atan2(- m31, m33);
7608 this._z = Math.atan2(- m12, m22);
7609
7610 } else
7611 {
7612
7613 this._y = 0;
7614 this._z = Math.atan2(m21, m11);
7615
7616 }
7617
7618 break;
7619
7620 case 'ZYX':
7621
7622 this._y = Math.asin(- clamp(m31, - 1, 1));
7623
7624 if (Math.abs(m31) < 0.9999999)
7625 {
7626
7627 this._x = Math.atan2(m32, m33);
7628 this._z = Math.atan2(m21, m11);
7629
7630 } else
7631 {
7632
7633 this._x = 0;
7634 this._z = Math.atan2(- m12, m22);
7635
7636 }
7637
7638 break;
7639
7640 case 'YZX':
7641
7642 this._z = Math.asin(clamp(m21, - 1, 1));
7643
7644 if (Math.abs(m21) < 0.9999999)
7645 {
7646
7647 this._x = Math.atan2(- m23, m22);
7648 this._y = Math.atan2(- m31, m11);
7649
7650 } else
7651 {
7652
7653 this._x = 0;
7654 this._y = Math.atan2(m13, m33);
7655
7656 }
7657
7658 break;
7659
7660 case 'XZY':
7661
7662 this._z = Math.asin(- clamp(m12, - 1, 1));
7663
7664 if (Math.abs(m12) < 0.9999999)
7665 {
7666
7667 this._x = Math.atan2(m32, m22);
7668 this._y = Math.atan2(m13, m11);
7669
7670 } else
7671 {
7672
7673 this._x = Math.atan2(- m23, m33);
7674 this._y = 0;
7675
7676 }
7677
7678 break;
7679
7680 default:
7681
7682 console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
7683
7684 }
7685
7686 this._order = order;
7687
7688 if (update === true) this._onChangeCallback();
7689
7690 return this;
7691
7692 }
7693
7694 setFromQuaternion (q, order, update)
7695 {
7696
7697 _matrix$2.makeRotationFromQuaternion(q);
7698
7699 return this.setFromRotationMatrix(_matrix$2, order, update);
7700
7701 }
7702
7703 setFromVector3 (v, order = this._order)
7704 {
7705
7706 return this.set(v.x, v.y, v.z, order);
7707
7708 }
7709
7710 reorder (newOrder)
7711 {
7712
7713 // WARNING: this discards revolution information -bhouston
7714
7715 _quaternion$3.setFromEuler(this);
7716
7717 return this.setFromQuaternion(_quaternion$3, newOrder);
7718
7719 }
7720
7721 equals (euler)
7722 {
7723
7724 return (euler._x === this._x) && (euler._y === this._y) && (euler._z === this._z) && (euler._order === this._order);
7725
7726 }
7727
7728 fromArray (array)
7729 {
7730
7731 this._x = array[0];
7732 this._y = array[1];
7733 this._z = array[2];
7734 if (array[3] !== undefined) this._order = array[3];
7735
7736 this._onChangeCallback();
7737
7738 return this;
7739
7740 }
7741
7742 toArray (array = [], offset = 0)
7743 {
7744
7745 array[offset] = this._x;
7746 array[offset + 1] = this._y;
7747 array[offset + 2] = this._z;
7748 array[offset + 3] = this._order;
7749
7750 return array;
7751
7752 }
7753
7754 _onChange (callback)
7755 {
7756
7757 this._onChangeCallback = callback;
7758
7759 return this;
7760
7761 }
7762
7763 _onChangeCallback () { }
7764
7765 *[Symbol.iterator] ()
7766 {
7767
7768 yield this._x;
7769 yield this._y;
7770 yield this._z;
7771 yield this._order;
7772
7773 }
7774
7775}
7776
7777Euler.DEFAULT_ORDER = 'XYZ';
7778
7779class Layers
7780{
7781
7782 constructor()
7783 {
7784
7785 this.mask = 1 | 0;
7786
7787 }
7788
7789 set (channel)
7790 {
7791
7792 this.mask = (1 << channel | 0) >>> 0;
7793
7794 }
7795
7796 enable (channel)
7797 {
7798
7799 this.mask |= 1 << channel | 0;
7800
7801 }
7802
7803 enableAll ()
7804 {
7805
7806 this.mask = 0xffffffff | 0;
7807
7808 }
7809
7810 toggle (channel)
7811 {
7812
7813 this.mask ^= 1 << channel | 0;
7814
7815 }
7816
7817 disable (channel)
7818 {
7819
7820 this.mask &= ~(1 << channel | 0);
7821
7822 }
7823
7824 disableAll ()
7825 {
7826
7827 this.mask = 0;
7828
7829 }
7830
7831 test (layers)
7832 {
7833
7834 return (this.mask & layers.mask) !== 0;
7835
7836 }
7837
7838 isEnabled (channel)
7839 {
7840
7841 return (this.mask & (1 << channel | 0)) !== 0;
7842
7843 }
7844
7845}
7846
7847let _object3DId = 0;
7848
7849const _v1$4 = /*@__PURE__*/ new Vector3();
7850const _q1 = /*@__PURE__*/ new Quaternion();
7851const _m1$3 = /*@__PURE__*/ new Matrix4();
7852const _target = /*@__PURE__*/ new Vector3();
7853
7854const _position$3 = /*@__PURE__*/ new Vector3();
7855const _scale$2 = /*@__PURE__*/ new Vector3();
7856const _quaternion$2 = /*@__PURE__*/ new Quaternion();
7857
7858const _xAxis = /*@__PURE__*/ new Vector3(1, 0, 0);
7859const _yAxis = /*@__PURE__*/ new Vector3(0, 1, 0);
7860const _zAxis = /*@__PURE__*/ new Vector3(0, 0, 1);
7861
7862const _addedEvent = { type: 'added' };
7863const _removedEvent = { type: 'removed' };
7864
7865const _childaddedEvent = { type: 'childadded', child: null };
7866const _childremovedEvent = { type: 'childremoved', child: null };
7867
7868class Object3D extends EventDispatcher
7869{
7870
7871 constructor()
7872 {
7873
7874 super();
7875
7876 this.isObject3D = true;
7877
7878 Object.defineProperty(this, 'id', { value: _object3DId++ });
7879
7880 this.uuid = generateUUID();
7881
7882 this.name = '';
7883 this.type = 'Object3D';
7884
7885 this.parent = null;
7886 this.children = [];
7887
7888 this.up = Object3D.DEFAULT_UP.clone();
7889
7890 const position = new Vector3();
7891 const rotation = new Euler();
7892 const quaternion = new Quaternion();
7893 const scale = new Vector3(1, 1, 1);
7894
7895 function onRotationChange ()
7896 {
7897
7898 quaternion.setFromEuler(rotation, false);
7899
7900 }
7901
7902 function onQuaternionChange ()
7903 {
7904
7905 rotation.setFromQuaternion(quaternion, undefined, false);
7906
7907 }
7908
7909 rotation._onChange(onRotationChange);
7910 quaternion._onChange(onQuaternionChange);
7911
7912 Object.defineProperties(this, {
7913 position: {
7914 configurable: true,
7915 enumerable: true,
7916 value: position
7917 },
7918 rotation: {
7919 configurable: true,
7920 enumerable: true,
7921 value: rotation
7922 },
7923 quaternion: {
7924 configurable: true,
7925 enumerable: true,
7926 value: quaternion
7927 },
7928 scale: {
7929 configurable: true,
7930 enumerable: true,
7931 value: scale
7932 },
7933 modelViewMatrix: {
7934 value: new Matrix4()
7935 },
7936 normalMatrix: {
7937 value: new Matrix3()
7938 }
7939 });
7940
7941 this.matrix = new Matrix4();
7942 this.matrixWorld = new Matrix4();
7943
7944 this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
7945
7946 this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer
7947 this.matrixWorldNeedsUpdate = false;
7948
7949 this.layers = new Layers();
7950 this.visible = true;
7951
7952 this.castShadow = false;
7953 this.receiveShadow = false;
7954
7955 this.frustumCulled = true;
7956 this.renderOrder = 0;
7957
7958 this.animations = [];
7959
7960 this.userData = {};
7961
7962 }
7963
7964 onBeforeShadow ( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */) { }
7965
7966 onAfterShadow ( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */) { }
7967
7968 onBeforeRender ( /* renderer, scene, camera, geometry, material, group */) { }
7969
7970 onAfterRender ( /* renderer, scene, camera, geometry, material, group */) { }
7971
7972 applyMatrix4 (matrix)
7973 {
7974
7975 if (this.matrixAutoUpdate) this.updateMatrix();
7976
7977 this.matrix.premultiply(matrix);
7978
7979 this.matrix.decompose(this.position, this.quaternion, this.scale);
7980
7981 }
7982
7983 applyQuaternion (q)
7984 {
7985
7986 this.quaternion.premultiply(q);
7987
7988 return this;
7989
7990 }
7991
7992 setRotationFromAxisAngle (axis, angle)
7993 {
7994
7995 // assumes axis is normalized
7996
7997 this.quaternion.setFromAxisAngle(axis, angle);
7998
7999 }
8000
8001 setRotationFromEuler (euler)
8002 {
8003
8004 this.quaternion.setFromEuler(euler, true);
8005
8006 }
8007
8008 setRotationFromMatrix (m)
8009 {
8010
8011 // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
8012
8013 this.quaternion.setFromRotationMatrix(m);
8014
8015 }
8016
8017 setRotationFromQuaternion (q)
8018 {
8019
8020 // assumes q is normalized
8021
8022 this.quaternion.copy(q);
8023
8024 }
8025
8026 rotateOnAxis (axis, angle)
8027 {
8028
8029 // rotate object on axis in object space
8030 // axis is assumed to be normalized
8031
8032 _q1.setFromAxisAngle(axis, angle);
8033
8034 this.quaternion.multiply(_q1);
8035
8036 return this;
8037
8038 }
8039
8040 rotateOnWorldAxis (axis, angle)
8041 {
8042
8043 // rotate object on axis in world space
8044 // axis is assumed to be normalized
8045 // method assumes no rotated parent
8046
8047 _q1.setFromAxisAngle(axis, angle);
8048
8049 this.quaternion.premultiply(_q1);
8050
8051 return this;
8052
8053 }
8054
8055 rotateX (angle)
8056 {
8057
8058 return this.rotateOnAxis(_xAxis, angle);
8059
8060 }
8061
8062 rotateY (angle)
8063 {
8064
8065 return this.rotateOnAxis(_yAxis, angle);
8066
8067 }
8068
8069 rotateZ (angle)
8070 {
8071
8072 return this.rotateOnAxis(_zAxis, angle);
8073
8074 }
8075
8076 translateOnAxis (axis, distance)
8077 {
8078
8079 // translate object by distance along axis in object space
8080 // axis is assumed to be normalized
8081
8082 _v1$4.copy(axis).applyQuaternion(this.quaternion);
8083
8084 this.position.add(_v1$4.multiplyScalar(distance));
8085
8086 return this;
8087
8088 }
8089
8090 translateX (distance)
8091 {
8092
8093 return this.translateOnAxis(_xAxis, distance);
8094
8095 }
8096
8097 translateY (distance)
8098 {
8099
8100 return this.translateOnAxis(_yAxis, distance);
8101
8102 }
8103
8104 translateZ (distance)
8105 {
8106
8107 return this.translateOnAxis(_zAxis, distance);
8108
8109 }
8110
8111 localToWorld (vector)
8112 {
8113
8114 this.updateWorldMatrix(true, false);
8115
8116 return vector.applyMatrix4(this.matrixWorld);
8117
8118 }
8119
8120 worldToLocal (vector)
8121 {
8122
8123 this.updateWorldMatrix(true, false);
8124
8125 return vector.applyMatrix4(_m1$3.copy(this.matrixWorld).invert());
8126
8127 }
8128
8129 lookAt (x, y, z)
8130 {
8131
8132 // This method does not support objects having non-uniformly-scaled parent(s)
8133
8134 if (x.isVector3)
8135 {
8136
8137 _target.copy(x);
8138
8139 } else
8140 {
8141
8142 _target.set(x, y, z);
8143
8144 }
8145
8146 const parent = this.parent;
8147
8148 this.updateWorldMatrix(true, false);
8149
8150 _position$3.setFromMatrixPosition(this.matrixWorld);
8151
8152 if (this.isCamera || this.isLight)
8153 {
8154
8155 _m1$3.lookAt(_position$3, _target, this.up);
8156
8157 } else
8158 {
8159
8160 _m1$3.lookAt(_target, _position$3, this.up);
8161
8162 }
8163
8164 this.quaternion.setFromRotationMatrix(_m1$3);
8165
8166 if (parent)
8167 {
8168
8169 _m1$3.extractRotation(parent.matrixWorld);
8170 _q1.setFromRotationMatrix(_m1$3);
8171 this.quaternion.premultiply(_q1.invert());
8172
8173 }
8174
8175 }
8176
8177 add (object)
8178 {
8179
8180 if (arguments.length > 1)
8181 {
8182
8183 for (let i = 0; i < arguments.length; i++)
8184 {
8185
8186 this.add(arguments[i]);
8187
8188 }
8189
8190 return this;
8191
8192 }
8193
8194 if (object === this)
8195 {
8196
8197 console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
8198 return this;
8199
8200 }
8201
8202 if (object && object.isObject3D)
8203 {
8204
8205 object.removeFromParent();
8206 object.parent = this;
8207 this.children.push(object);
8208
8209 object.dispatchEvent(_addedEvent);
8210
8211 _childaddedEvent.child = object;
8212 this.dispatchEvent(_childaddedEvent);
8213 _childaddedEvent.child = null;
8214
8215 } else
8216 {
8217
8218 console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
8219
8220 }
8221
8222 return this;
8223
8224 }
8225
8226 remove (object)
8227 {
8228
8229 if (arguments.length > 1)
8230 {
8231
8232 for (let i = 0; i < arguments.length; i++)
8233 {
8234
8235 this.remove(arguments[i]);
8236
8237 }
8238
8239 return this;
8240
8241 }
8242
8243 const index = this.children.indexOf(object);
8244
8245 if (index !== - 1)
8246 {
8247
8248 object.parent = null;
8249 this.children.splice(index, 1);
8250
8251 object.dispatchEvent(_removedEvent);
8252
8253 _childremovedEvent.child = object;
8254 this.dispatchEvent(_childremovedEvent);
8255 _childremovedEvent.child = null;
8256
8257 }
8258
8259 return this;
8260
8261 }
8262
8263 removeFromParent ()
8264 {
8265
8266 const parent = this.parent;
8267
8268 if (parent !== null)
8269 {
8270
8271 parent.remove(this);
8272
8273 }
8274
8275 return this;
8276
8277 }
8278
8279 clear ()
8280 {
8281
8282 return this.remove(... this.children);
8283
8284 }
8285
8286 attach (object)
8287 {
8288
8289 // adds object as a child of this, while maintaining the object's world transform
8290
8291 // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)
8292
8293 this.updateWorldMatrix(true, false);
8294
8295 _m1$3.copy(this.matrixWorld).invert();
8296
8297 if (object.parent !== null)
8298 {
8299
8300 object.parent.updateWorldMatrix(true, false);
8301
8302 _m1$3.multiply(object.parent.matrixWorld);
8303
8304 }
8305
8306 object.applyMatrix4(_m1$3);
8307
8308 object.removeFromParent();
8309 object.parent = this;
8310 this.children.push(object);
8311
8312 object.updateWorldMatrix(false, true);
8313
8314 object.dispatchEvent(_addedEvent);
8315
8316 _childaddedEvent.child = object;
8317 this.dispatchEvent(_childaddedEvent);
8318 _childaddedEvent.child = null;
8319
8320 return this;
8321
8322 }
8323
8324 getObjectById (id)
8325 {
8326
8327 return this.getObjectByProperty('id', id);
8328
8329 }
8330
8331 getObjectByName (name)
8332 {
8333
8334 return this.getObjectByProperty('name', name);
8335
8336 }
8337
8338 getObjectByProperty (name, value)
8339 {
8340
8341 if (this[name] === value) return this;
8342
8343 for (let i = 0, l = this.children.length; i < l; i++)
8344 {
8345
8346 const child = this.children[i];
8347 const object = child.getObjectByProperty(name, value);
8348
8349 if (object !== undefined)
8350 {
8351
8352 return object;
8353
8354 }
8355
8356 }
8357
8358 return undefined;
8359
8360 }
8361
8362 getObjectsByProperty (name, value, result = [])
8363 {
8364
8365 if (this[name] === value) result.push(this);
8366
8367 const children = this.children;
8368
8369 for (let i = 0, l = children.length; i < l; i++)
8370 {
8371
8372 children[i].getObjectsByProperty(name, value, result);
8373
8374 }
8375
8376 return result;
8377
8378 }
8379
8380 getWorldPosition (target)
8381 {
8382
8383 this.updateWorldMatrix(true, false);
8384
8385 return target.setFromMatrixPosition(this.matrixWorld);
8386
8387 }
8388
8389 getWorldQuaternion (target)
8390 {
8391
8392 this.updateWorldMatrix(true, false);
8393
8394 this.matrixWorld.decompose(_position$3, target, _scale$2);
8395
8396 return target;
8397
8398 }
8399
8400 getWorldScale (target)
8401 {
8402
8403 this.updateWorldMatrix(true, false);
8404
8405 this.matrixWorld.decompose(_position$3, _quaternion$2, target);
8406
8407 return target;
8408
8409 }
8410
8411 getWorldDirection (target)
8412 {
8413
8414 this.updateWorldMatrix(true, false);
8415
8416 const e = this.matrixWorld.elements;
8417
8418 return target.set(e[8], e[9], e[10]).normalize();
8419
8420 }
8421
8422 raycast ( /* raycaster, intersects */) { }
8423
8424 traverse (callback)
8425 {
8426
8427 callback(this);
8428
8429 const children = this.children;
8430
8431 for (let i = 0, l = children.length; i < l; i++)
8432 {
8433
8434 children[i].traverse(callback);
8435
8436 }
8437
8438 }
8439
8440 traverseVisible (callback)
8441 {
8442
8443 if (this.visible === false) return;
8444
8445 callback(this);
8446
8447 const children = this.children;
8448
8449 for (let i = 0, l = children.length; i < l; i++)
8450 {
8451
8452 children[i].traverseVisible(callback);
8453
8454 }
8455
8456 }
8457
8458 traverseAncestors (callback)
8459 {
8460
8461 const parent = this.parent;
8462
8463 if (parent !== null)
8464 {
8465
8466 callback(parent);
8467
8468 parent.traverseAncestors(callback);
8469
8470 }
8471
8472 }
8473
8474 updateMatrix ()
8475 {
8476
8477 this.matrix.compose(this.position, this.quaternion, this.scale);
8478
8479 this.matrixWorldNeedsUpdate = true;
8480
8481 }
8482
8483 updateMatrixWorld (force)
8484 {
8485
8486 if (this.matrixAutoUpdate) this.updateMatrix();
8487
8488 if (this.matrixWorldNeedsUpdate || force)
8489 {
8490
8491 if (this.matrixWorldAutoUpdate === true)
8492 {
8493
8494 if (this.parent === null)
8495 {
8496
8497 this.matrixWorld.copy(this.matrix);
8498
8499 } else
8500 {
8501
8502 this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
8503
8504 }
8505
8506 }
8507
8508 this.matrixWorldNeedsUpdate = false;
8509
8510 force = true;
8511
8512 }
8513
8514 // make sure descendants are updated if required
8515
8516 const children = this.children;
8517
8518 for (let i = 0, l = children.length; i < l; i++)
8519 {
8520
8521 const child = children[i];
8522
8523 child.updateMatrixWorld(force);
8524
8525 }
8526
8527 }
8528
8529 updateWorldMatrix (updateParents, updateChildren)
8530 {
8531
8532 const parent = this.parent;
8533
8534 if (updateParents === true && parent !== null)
8535 {
8536
8537 parent.updateWorldMatrix(true, false);
8538
8539 }
8540
8541 if (this.matrixAutoUpdate) this.updateMatrix();
8542
8543 if (this.matrixWorldAutoUpdate === true)
8544 {
8545
8546 if (this.parent === null)
8547 {
8548
8549 this.matrixWorld.copy(this.matrix);
8550
8551 } else
8552 {
8553
8554 this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
8555
8556 }
8557
8558 }
8559
8560 // make sure descendants are updated
8561
8562 if (updateChildren === true)
8563 {
8564
8565 const children = this.children;
8566
8567 for (let i = 0, l = children.length; i < l; i++)
8568 {
8569
8570 const child = children[i];
8571
8572 child.updateWorldMatrix(false, true);
8573
8574 }
8575
8576 }
8577
8578 }
8579
8580 toJSON (meta)
8581 {
8582
8583 // meta is a string when called from JSON.stringify
8584 const isRootObject = (meta === undefined || typeof meta === 'string');
8585
8586 const output = {};
8587
8588 // meta is a hash used to collect geometries, materials.
8589 // not providing it implies that this is the root object
8590 // being serialized.
8591 if (isRootObject)
8592 {
8593
8594 // initialize meta obj
8595 meta = {
8596 geometries: {},
8597 materials: {},
8598 textures: {},
8599 images: {},
8600 shapes: {},
8601 skeletons: {},
8602 animations: {},
8603 nodes: {}
8604 };
8605
8606 output.metadata = {
8607 version: 4.6,
8608 type: 'Object',
8609 generator: 'Object3D.toJSON'
8610 };
8611
8612 }
8613
8614 // standard Object3D serialization
8615
8616 const object = {};
8617
8618 object.uuid = this.uuid;
8619 object.type = this.type;
8620
8621 if (this.name !== '') object.name = this.name;
8622 if (this.castShadow === true) object.castShadow = true;
8623 if (this.receiveShadow === true) object.receiveShadow = true;
8624 if (this.visible === false) object.visible = false;
8625 if (this.frustumCulled === false) object.frustumCulled = false;
8626 if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
8627 if (Object.keys(this.userData).length > 0) object.userData = this.userData;
8628
8629 object.layers = this.layers.mask;
8630 object.matrix = this.matrix.toArray();
8631 object.up = this.up.toArray();
8632
8633 if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false;
8634
8635 // object specific properties
8636
8637 if (this.isInstancedMesh)
8638 {
8639
8640 object.type = 'InstancedMesh';
8641 object.count = this.count;
8642 object.instanceMatrix = this.instanceMatrix.toJSON();
8643 if (this.instanceColor !== null) object.instanceColor = this.instanceColor.toJSON();
8644
8645 }
8646
8647 if (this.isBatchedMesh)
8648 {
8649
8650 object.type = 'BatchedMesh';
8651 object.perObjectFrustumCulled = this.perObjectFrustumCulled;
8652 object.sortObjects = this.sortObjects;
8653
8654 object.drawRanges = this._drawRanges;
8655 object.reservedRanges = this._reservedRanges;
8656
8657 object.visibility = this._visibility;
8658 object.active = this._active;
8659 object.bounds = this._bounds.map(bound => ({
8660 boxInitialized: bound.boxInitialized,
8661 boxMin: bound.box.min.toArray(),
8662 boxMax: bound.box.max.toArray(),
8663
8664 sphereInitialized: bound.sphereInitialized,
8665 sphereRadius: bound.sphere.radius,
8666 sphereCenter: bound.sphere.center.toArray()
8667 }));
8668
8669 object.maxInstanceCount = this._maxInstanceCount;
8670 object.maxVertexCount = this._maxVertexCount;
8671 object.maxIndexCount = this._maxIndexCount;
8672
8673 object.geometryInitialized = this._geometryInitialized;
8674 object.geometryCount = this._geometryCount;
8675
8676 object.matricesTexture = this._matricesTexture.toJSON(meta);
8677
8678 if (this._colorsTexture !== null) object.colorsTexture = this._colorsTexture.toJSON(meta);
8679
8680 if (this.boundingSphere !== null)
8681 {
8682
8683 object.boundingSphere = {
8684 center: object.boundingSphere.center.toArray(),
8685 radius: object.boundingSphere.radius
8686 };
8687
8688 }
8689
8690 if (this.boundingBox !== null)
8691 {
8692
8693 object.boundingBox = {
8694 min: object.boundingBox.min.toArray(),
8695 max: object.boundingBox.max.toArray()
8696 };
8697
8698 }
8699
8700 }
8701
8702 //
8703
8704 function serialize (library, element)
8705 {
8706
8707 if (library[element.uuid] === undefined)
8708 {
8709
8710 library[element.uuid] = element.toJSON(meta);
8711
8712 }
8713
8714 return element.uuid;
8715
8716 }
8717
8718 if (this.isScene)
8719 {
8720
8721 if (this.background)
8722 {
8723
8724 if (this.background.isColor)
8725 {
8726
8727 object.background = this.background.toJSON();
8728
8729 } else if (this.background.isTexture)
8730 {
8731
8732 object.background = this.background.toJSON(meta).uuid;
8733
8734 }
8735
8736 }
8737
8738 if (this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true)
8739 {
8740
8741 object.environment = this.environment.toJSON(meta).uuid;
8742
8743 }
8744
8745 } else if (this.isMesh || this.isLine || this.isPoints)
8746 {
8747
8748 object.geometry = serialize(meta.geometries, this.geometry);
8749
8750 const parameters = this.geometry.parameters;
8751
8752 if (parameters !== undefined && parameters.shapes !== undefined)
8753 {
8754
8755 const shapes = parameters.shapes;
8756
8757 if (Array.isArray(shapes))
8758 {
8759
8760 for (let i = 0, l = shapes.length; i < l; i++)
8761 {
8762
8763 const shape = shapes[i];
8764
8765 serialize(meta.shapes, shape);
8766
8767 }
8768
8769 } else
8770 {
8771
8772 serialize(meta.shapes, shapes);
8773
8774 }
8775
8776 }
8777
8778 }
8779
8780 if (this.isSkinnedMesh)
8781 {
8782
8783 object.bindMode = this.bindMode;
8784 object.bindMatrix = this.bindMatrix.toArray();
8785
8786 if (this.skeleton !== undefined)
8787 {
8788
8789 serialize(meta.skeletons, this.skeleton);
8790
8791 object.skeleton = this.skeleton.uuid;
8792
8793 }
8794
8795 }
8796
8797 if (this.material !== undefined)
8798 {
8799
8800 if (Array.isArray(this.material))
8801 {
8802
8803 const uuids = [];
8804
8805 for (let i = 0, l = this.material.length; i < l; i++)
8806 {
8807
8808 uuids.push(serialize(meta.materials, this.material[i]));
8809
8810 }
8811
8812 object.material = uuids;
8813
8814 } else
8815 {
8816
8817 object.material = serialize(meta.materials, this.material);
8818
8819 }
8820
8821 }
8822
8823 //
8824
8825 if (this.children.length > 0)
8826 {
8827
8828 object.children = [];
8829
8830 for (let i = 0; i < this.children.length; i++)
8831 {
8832
8833 object.children.push(this.children[i].toJSON(meta).object);
8834
8835 }
8836
8837 }
8838
8839 //
8840
8841 if (this.animations.length > 0)
8842 {
8843
8844 object.animations = [];
8845
8846 for (let i = 0; i < this.animations.length; i++)
8847 {
8848
8849 const animation = this.animations[i];
8850
8851 object.animations.push(serialize(meta.animations, animation));
8852
8853 }
8854
8855 }
8856
8857 if (isRootObject)
8858 {
8859
8860 const geometries = extractFromCache(meta.geometries);
8861 const materials = extractFromCache(meta.materials);
8862 const textures = extractFromCache(meta.textures);
8863 const images = extractFromCache(meta.images);
8864 const shapes = extractFromCache(meta.shapes);
8865 const skeletons = extractFromCache(meta.skeletons);
8866 const animations = extractFromCache(meta.animations);
8867 const nodes = extractFromCache(meta.nodes);
8868
8869 if (geometries.length > 0) output.geometries = geometries;
8870 if (materials.length > 0) output.materials = materials;
8871 if (textures.length > 0) output.textures = textures;
8872 if (images.length > 0) output.images = images;
8873 if (shapes.length > 0) output.shapes = shapes;
8874 if (skeletons.length > 0) output.skeletons = skeletons;
8875 if (animations.length > 0) output.animations = animations;
8876 if (nodes.length > 0) output.nodes = nodes;
8877
8878 }
8879
8880 output.object = object;
8881
8882 return output;
8883
8884 // extract data from the cache hash
8885 // remove metadata on each item
8886 // and return as array
8887 function extractFromCache (cache)
8888 {
8889
8890 const values = [];
8891 for (const key in cache)
8892 {
8893
8894 const data = cache[key];
8895 delete data.metadata;
8896 values.push(data);
8897
8898 }
8899
8900 return values;
8901
8902 }
8903
8904 }
8905
8906 clone (recursive)
8907 {
8908
8909 return new this.constructor().copy(this, recursive);
8910
8911 }
8912
8913 copy (source, recursive = true)
8914 {
8915
8916 this.name = source.name;
8917
8918 this.up.copy(source.up);
8919
8920 this.position.copy(source.position);
8921 this.rotation.order = source.rotation.order;
8922 this.quaternion.copy(source.quaternion);
8923 this.scale.copy(source.scale);
8924
8925 this.matrix.copy(source.matrix);
8926 this.matrixWorld.copy(source.matrixWorld);
8927
8928 this.matrixAutoUpdate = source.matrixAutoUpdate;
8929
8930 this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;
8931 this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
8932
8933 this.layers.mask = source.layers.mask;
8934 this.visible = source.visible;
8935
8936 this.castShadow = source.castShadow;
8937 this.receiveShadow = source.receiveShadow;
8938
8939 this.frustumCulled = source.frustumCulled;
8940 this.renderOrder = source.renderOrder;
8941
8942 this.animations = source.animations.slice();
8943
8944 this.userData = JSON.parse(JSON.stringify(source.userData));
8945
8946 if (recursive === true)
8947 {
8948
8949 for (let i = 0; i < source.children.length; i++)
8950 {
8951
8952 const child = source.children[i];
8953 this.add(child.clone());
8954
8955 }
8956
8957 }
8958
8959 return this;
8960
8961 }
8962
8963}
8964
8965Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3(0, 1, 0);
8966Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
8967Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
8968
8969const _v0$1 = /*@__PURE__*/ new Vector3();
8970const _v1$3 = /*@__PURE__*/ new Vector3();
8971const _v2$2 = /*@__PURE__*/ new Vector3();
8972const _v3$2 = /*@__PURE__*/ new Vector3();
8973
8974const _vab = /*@__PURE__*/ new Vector3();
8975const _vac = /*@__PURE__*/ new Vector3();
8976const _vbc = /*@__PURE__*/ new Vector3();
8977const _vap = /*@__PURE__*/ new Vector3();
8978const _vbp = /*@__PURE__*/ new Vector3();
8979const _vcp = /*@__PURE__*/ new Vector3();
8980
8981class Triangle
8982{
8983
8984 constructor(a = new Vector3(), b = new Vector3(), c = new Vector3())
8985 {
8986
8987 this.a = a;
8988 this.b = b;
8989 this.c = c;
8990
8991 }
8992
8993 static getNormal (a, b, c, target)
8994 {
8995
8996 target.subVectors(c, b);
8997 _v0$1.subVectors(a, b);
8998 target.cross(_v0$1);
8999
9000 const targetLengthSq = target.lengthSq();
9001 if (targetLengthSq > 0)
9002 {
9003
9004 return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
9005
9006 }
9007
9008 return target.set(0, 0, 0);
9009
9010 }
9011
9012 // static/instance method to calculate barycentric coordinates
9013 // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
9014 static getBarycoord (point, a, b, c, target)
9015 {
9016
9017 _v0$1.subVectors(c, a);
9018 _v1$3.subVectors(b, a);
9019 _v2$2.subVectors(point, a);
9020
9021 const dot00 = _v0$1.dot(_v0$1);
9022 const dot01 = _v0$1.dot(_v1$3);
9023 const dot02 = _v0$1.dot(_v2$2);
9024 const dot11 = _v1$3.dot(_v1$3);
9025 const dot12 = _v1$3.dot(_v2$2);
9026
9027 const denom = (dot00 * dot11 - dot01 * dot01);
9028
9029 // collinear or singular triangle
9030 if (denom === 0)
9031 {
9032
9033 target.set(0, 0, 0);
9034 return null;
9035
9036 }
9037
9038 const invDenom = 1 / denom;
9039 const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
9040 const v = (dot00 * dot12 - dot01 * dot02) * invDenom;
9041
9042 // barycentric coordinates must always sum to 1
9043 return target.set(1 - u - v, v, u);
9044
9045 }
9046
9047 static containsPoint (point, a, b, c)
9048 {
9049
9050 // if the triangle is degenerate then we can't contain a point
9051 if (this.getBarycoord(point, a, b, c, _v3$2) === null)
9052 {
9053
9054 return false;
9055
9056 }
9057
9058 return (_v3$2.x >= 0) && (_v3$2.y >= 0) && ((_v3$2.x + _v3$2.y) <= 1);
9059
9060 }
9061
9062 static getInterpolation (point, p1, p2, p3, v1, v2, v3, target)
9063 {
9064
9065 if (this.getBarycoord(point, p1, p2, p3, _v3$2) === null)
9066 {
9067
9068 target.x = 0;
9069 target.y = 0;
9070 if ('z' in target) target.z = 0;
9071 if ('w' in target) target.w = 0;
9072 return null;
9073
9074 }
9075
9076 target.setScalar(0);
9077 target.addScaledVector(v1, _v3$2.x);
9078 target.addScaledVector(v2, _v3$2.y);
9079 target.addScaledVector(v3, _v3$2.z);
9080
9081 return target;
9082
9083 }
9084
9085 static isFrontFacing (a, b, c, direction)
9086 {
9087
9088 _v0$1.subVectors(c, b);
9089 _v1$3.subVectors(a, b);
9090
9091 // strictly front facing
9092 return (_v0$1.cross(_v1$3).dot(direction) < 0) ? true : false;
9093
9094 }
9095
9096 set (a, b, c)
9097 {
9098
9099 this.a.copy(a);
9100 this.b.copy(b);
9101 this.c.copy(c);
9102
9103 return this;
9104
9105 }
9106
9107 setFromPointsAndIndices (points, i0, i1, i2)
9108 {
9109
9110 this.a.copy(points[i0]);
9111 this.b.copy(points[i1]);
9112 this.c.copy(points[i2]);
9113
9114 return this;
9115
9116 }
9117
9118 setFromAttributeAndIndices (attribute, i0, i1, i2)
9119 {
9120
9121 this.a.fromBufferAttribute(attribute, i0);
9122 this.b.fromBufferAttribute(attribute, i1);
9123 this.c.fromBufferAttribute(attribute, i2);
9124
9125 return this;
9126
9127 }
9128
9129 clone ()
9130 {
9131
9132 return new this.constructor().copy(this);
9133
9134 }
9135
9136 copy (triangle)
9137 {
9138
9139 this.a.copy(triangle.a);
9140 this.b.copy(triangle.b);
9141 this.c.copy(triangle.c);
9142
9143 return this;
9144
9145 }
9146
9147 getArea ()
9148 {
9149
9150 _v0$1.subVectors(this.c, this.b);
9151 _v1$3.subVectors(this.a, this.b);
9152
9153 return _v0$1.cross(_v1$3).length() * 0.5;
9154
9155 }
9156
9157 getMidpoint (target)
9158 {
9159
9160 return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
9161
9162 }
9163
9164 getNormal (target)
9165 {
9166
9167 return Triangle.getNormal(this.a, this.b, this.c, target);
9168
9169 }
9170
9171 getPlane (target)
9172 {
9173
9174 return target.setFromCoplanarPoints(this.a, this.b, this.c);
9175
9176 }
9177
9178 getBarycoord (point, target)
9179 {
9180
9181 return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
9182
9183 }
9184
9185 getInterpolation (point, v1, v2, v3, target)
9186 {
9187
9188 return Triangle.getInterpolation(point, this.a, this.b, this.c, v1, v2, v3, target);
9189
9190 }
9191
9192 containsPoint (point)
9193 {
9194
9195 return Triangle.containsPoint(point, this.a, this.b, this.c);
9196
9197 }
9198
9199 isFrontFacing (direction)
9200 {
9201
9202 return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
9203
9204 }
9205
9206 intersectsBox (box)
9207 {
9208
9209 return box.intersectsTriangle(this);
9210
9211 }
9212
9213 closestPointToPoint (p, target)
9214 {
9215
9216 const a = this.a, b = this.b, c = this.c;
9217 let v, w;
9218
9219 // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
9220 // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
9221 // under the accompanying license; see chapter 5.1.5 for detailed explanation.
9222 // basically, we're distinguishing which of the voronoi regions of the triangle
9223 // the point lies in with the minimum amount of redundant computation.
9224
9225 _vab.subVectors(b, a);
9226 _vac.subVectors(c, a);
9227 _vap.subVectors(p, a);
9228 const d1 = _vab.dot(_vap);
9229 const d2 = _vac.dot(_vap);
9230 if (d1 <= 0 && d2 <= 0)
9231 {
9232
9233 // vertex region of A; barycentric coords (1, 0, 0)
9234 return target.copy(a);
9235
9236 }
9237
9238 _vbp.subVectors(p, b);
9239 const d3 = _vab.dot(_vbp);
9240 const d4 = _vac.dot(_vbp);
9241 if (d3 >= 0 && d4 <= d3)
9242 {
9243
9244 // vertex region of B; barycentric coords (0, 1, 0)
9245 return target.copy(b);
9246
9247 }
9248
9249 const vc = d1 * d4 - d3 * d2;
9250 if (vc <= 0 && d1 >= 0 && d3 <= 0)
9251 {
9252
9253 v = d1 / (d1 - d3);
9254 // edge region of AB; barycentric coords (1-v, v, 0)
9255 return target.copy(a).addScaledVector(_vab, v);
9256
9257 }
9258
9259 _vcp.subVectors(p, c);
9260 const d5 = _vab.dot(_vcp);
9261 const d6 = _vac.dot(_vcp);
9262 if (d6 >= 0 && d5 <= d6)
9263 {
9264
9265 // vertex region of C; barycentric coords (0, 0, 1)
9266 return target.copy(c);
9267
9268 }
9269
9270 const vb = d5 * d2 - d1 * d6;
9271 if (vb <= 0 && d2 >= 0 && d6 <= 0)
9272 {
9273
9274 w = d2 / (d2 - d6);
9275 // edge region of AC; barycentric coords (1-w, 0, w)
9276 return target.copy(a).addScaledVector(_vac, w);
9277
9278 }
9279
9280 const va = d3 * d6 - d5 * d4;
9281 if (va <= 0 && (d4 - d3) >= 0 && (d5 - d6) >= 0)
9282 {
9283
9284 _vbc.subVectors(c, b);
9285 w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
9286 // edge region of BC; barycentric coords (0, 1-w, w)
9287 return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
9288
9289 }
9290
9291 // face region
9292 const denom = 1 / (va + vb + vc);
9293 // u = va * denom
9294 v = vb * denom;
9295 w = vc * denom;
9296
9297 return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
9298
9299 }
9300
9301 equals (triangle)
9302 {
9303
9304 return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
9305
9306 }
9307
9308}
9309
9310const _colorKeywords = {
9311 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
9312 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
9313 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
9314 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
9315 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
9316 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
9317 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
9318 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
9319 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
9320 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
9321 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
9322 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
9323 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
9324 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
9325 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
9326 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
9327 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
9328 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
9329 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
9330 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
9331 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
9332 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
9333 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
9334 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32
9335};
9336
9337const _hslA = { h: 0, s: 0, l: 0 };
9338const _hslB = { h: 0, s: 0, l: 0 };
9339
9340function hue2rgb (p, q, t)
9341{
9342
9343 if (t < 0) t += 1;
9344 if (t > 1) t -= 1;
9345 if (t < 1 / 6) return p + (q - p) * 6 * t;
9346 if (t < 1 / 2) return q;
9347 if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
9348 return p;
9349
9350}
9351
9352class Color
9353{
9354
9355 constructor(r, g, b)
9356 {
9357
9358 this.isColor = true;
9359
9360 this.r = 1;
9361 this.g = 1;
9362 this.b = 1;
9363
9364 return this.set(r, g, b);
9365
9366 }
9367
9368 set (r, g, b)
9369 {
9370
9371 if (g === undefined && b === undefined)
9372 {
9373
9374 // r is THREE.Color, hex or string
9375
9376 const value = r;
9377
9378 if (value && value.isColor)
9379 {
9380
9381 this.copy(value);
9382
9383 } else if (typeof value === 'number')
9384 {
9385
9386 this.setHex(value);
9387
9388 } else if (typeof value === 'string')
9389 {
9390
9391 this.setStyle(value);
9392
9393 }
9394
9395 } else
9396 {
9397
9398 this.setRGB(r, g, b);
9399
9400 }
9401
9402 return this;
9403
9404 }
9405
9406 setScalar (scalar)
9407 {
9408
9409 this.r = scalar;
9410 this.g = scalar;
9411 this.b = scalar;
9412
9413 return this;
9414
9415 }
9416
9417 setHex (hex, colorSpace = SRGBColorSpace)
9418 {
9419
9420 hex = Math.floor(hex);
9421
9422 this.r = (hex >> 16 & 255) / 255;
9423 this.g = (hex >> 8 & 255) / 255;
9424 this.b = (hex & 255) / 255;
9425
9426 ColorManagement.toWorkingColorSpace(this, colorSpace);
9427
9428 return this;
9429
9430 }
9431
9432 setRGB (r, g, b, colorSpace = ColorManagement.workingColorSpace)
9433 {
9434
9435 this.r = r;
9436 this.g = g;
9437 this.b = b;
9438
9439 ColorManagement.toWorkingColorSpace(this, colorSpace);
9440
9441 return this;
9442
9443 }
9444
9445 setHSL (h, s, l, colorSpace = ColorManagement.workingColorSpace)
9446 {
9447
9448 // h,s,l ranges are in 0.0 - 1.0
9449 h = euclideanModulo(h, 1);
9450 s = clamp(s, 0, 1);
9451 l = clamp(l, 0, 1);
9452
9453 if (s === 0)
9454 {
9455
9456 this.r = this.g = this.b = l;
9457
9458 } else
9459 {
9460
9461 const p = l <= 0.5 ? l * (1 + s) : l + s - (l * s);
9462 const q = (2 * l) - p;
9463
9464 this.r = hue2rgb(q, p, h + 1 / 3);
9465 this.g = hue2rgb(q, p, h);
9466 this.b = hue2rgb(q, p, h - 1 / 3);
9467
9468 }
9469
9470 ColorManagement.toWorkingColorSpace(this, colorSpace);
9471
9472 return this;
9473
9474 }
9475
9476 setStyle (style, colorSpace = SRGBColorSpace)
9477 {
9478
9479 function handleAlpha (string)
9480 {
9481
9482 if (string === undefined) return;
9483
9484 if (parseFloat(string) < 1)
9485 {
9486
9487 console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
9488
9489 }
9490
9491 }
9492
9493
9494 let m;
9495
9496 if (m = /^(\w+)\(([^\)]*)\)/.exec(style))
9497 {
9498
9499 // rgb / hsl
9500
9501 let color;
9502 const name = m[1];
9503 const components = m[2];
9504
9505 switch (name)
9506 {
9507
9508 case 'rgb':
9509 case 'rgba':
9510
9511 if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))
9512 {
9513
9514 // rgb(255,0,0) rgba(255,0,0,0.5)
9515
9516 handleAlpha(color[4]);
9517
9518 return this.setRGB(
9519 Math.min(255, parseInt(color[1], 10)) / 255,
9520 Math.min(255, parseInt(color[2], 10)) / 255,
9521 Math.min(255, parseInt(color[3], 10)) / 255,
9522 colorSpace
9523 );
9524
9525 }
9526
9527 if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))
9528 {
9529
9530 // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
9531
9532 handleAlpha(color[4]);
9533
9534 return this.setRGB(
9535 Math.min(100, parseInt(color[1], 10)) / 100,
9536 Math.min(100, parseInt(color[2], 10)) / 100,
9537 Math.min(100, parseInt(color[3], 10)) / 100,
9538 colorSpace
9539 );
9540
9541 }
9542
9543 break;
9544
9545 case 'hsl':
9546 case 'hsla':
9547
9548 if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))
9549 {
9550
9551 // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
9552
9553 handleAlpha(color[4]);
9554
9555 return this.setHSL(
9556 parseFloat(color[1]) / 360,
9557 parseFloat(color[2]) / 100,
9558 parseFloat(color[3]) / 100,
9559 colorSpace
9560 );
9561
9562 }
9563
9564 break;
9565
9566 default:
9567
9568 console.warn('THREE.Color: Unknown color model ' + style);
9569
9570 }
9571
9572 } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style))
9573 {
9574
9575 // hex color
9576
9577 const hex = m[1];
9578 const size = hex.length;
9579
9580 if (size === 3)
9581 {
9582
9583 // #ff0
9584 return this.setRGB(
9585 parseInt(hex.charAt(0), 16) / 15,
9586 parseInt(hex.charAt(1), 16) / 15,
9587 parseInt(hex.charAt(2), 16) / 15,
9588 colorSpace
9589 );
9590
9591 } else if (size === 6)
9592 {
9593
9594 // #ff0000
9595 return this.setHex(parseInt(hex, 16), colorSpace);
9596
9597 } else
9598 {
9599
9600 console.warn('THREE.Color: Invalid hex color ' + style);
9601
9602 }
9603
9604 } else if (style && style.length > 0)
9605 {
9606
9607 return this.setColorName(style, colorSpace);
9608
9609 }
9610
9611 return this;
9612
9613 }
9614
9615 setColorName (style, colorSpace = SRGBColorSpace)
9616 {
9617
9618 // color keywords
9619 const hex = _colorKeywords[style.toLowerCase()];
9620
9621 if (hex !== undefined)
9622 {
9623
9624 // red
9625 this.setHex(hex, colorSpace);
9626
9627 } else
9628 {
9629
9630 // unknown color
9631 console.warn('THREE.Color: Unknown color ' + style);
9632
9633 }
9634
9635 return this;
9636
9637 }
9638
9639 clone ()
9640 {
9641
9642 return new this.constructor(this.r, this.g, this.b);
9643
9644 }
9645
9646 copy (color)
9647 {
9648
9649 this.r = color.r;
9650 this.g = color.g;
9651 this.b = color.b;
9652
9653 return this;
9654
9655 }
9656
9657 copySRGBToLinear (color)
9658 {
9659
9660 this.r = SRGBToLinear(color.r);
9661 this.g = SRGBToLinear(color.g);
9662 this.b = SRGBToLinear(color.b);
9663
9664 return this;
9665
9666 }
9667
9668 copyLinearToSRGB (color)
9669 {
9670
9671 this.r = LinearToSRGB(color.r);
9672 this.g = LinearToSRGB(color.g);
9673 this.b = LinearToSRGB(color.b);
9674
9675 return this;
9676
9677 }
9678
9679 convertSRGBToLinear ()
9680 {
9681
9682 this.copySRGBToLinear(this);
9683
9684 return this;
9685
9686 }
9687
9688 convertLinearToSRGB ()
9689 {
9690
9691 this.copyLinearToSRGB(this);
9692
9693 return this;
9694
9695 }
9696
9697 getHex (colorSpace = SRGBColorSpace)
9698 {
9699
9700 ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
9701
9702 return Math.round(clamp(_color.r * 255, 0, 255)) * 65536 + Math.round(clamp(_color.g * 255, 0, 255)) * 256 + Math.round(clamp(_color.b * 255, 0, 255));
9703
9704 }
9705
9706 getHexString (colorSpace = SRGBColorSpace)
9707 {
9708
9709 return ('000000' + this.getHex(colorSpace).toString(16)).slice(- 6);
9710
9711 }
9712
9713 getHSL (target, colorSpace = ColorManagement.workingColorSpace)
9714 {
9715
9716 // h,s,l ranges are in 0.0 - 1.0
9717
9718 ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
9719
9720 const r = _color.r, g = _color.g, b = _color.b;
9721
9722 const max = Math.max(r, g, b);
9723 const min = Math.min(r, g, b);
9724
9725 let hue, saturation;
9726 const lightness = (min + max) / 2.0;
9727
9728 if (min === max)
9729 {
9730
9731 hue = 0;
9732 saturation = 0;
9733
9734 } else
9735 {
9736
9737 const delta = max - min;
9738
9739 saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
9740
9741 switch (max)
9742 {
9743
9744 case r: hue = (g - b) / delta + (g < b ? 6 : 0); break;
9745 case g: hue = (b - r) / delta + 2; break;
9746 case b: hue = (r - g) / delta + 4; break;
9747
9748 }
9749
9750 hue /= 6;
9751
9752 }
9753
9754 target.h = hue;
9755 target.s = saturation;
9756 target.l = lightness;
9757
9758 return target;
9759
9760 }
9761
9762 getRGB (target, colorSpace = ColorManagement.workingColorSpace)
9763 {
9764
9765 ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
9766
9767 target.r = _color.r;
9768 target.g = _color.g;
9769 target.b = _color.b;
9770
9771 return target;
9772
9773 }
9774
9775 getStyle (colorSpace = SRGBColorSpace)
9776 {
9777
9778 ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace);
9779
9780 const r = _color.r, g = _color.g, b = _color.b;
9781
9782 if (colorSpace !== SRGBColorSpace)
9783 {
9784
9785 // Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/).
9786 return `color(${colorSpace} ${r.toFixed(3)} ${g.toFixed(3)} ${b.toFixed(3)})`;
9787
9788 }
9789
9790 return `rgb(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)})`;
9791
9792 }
9793
9794 offsetHSL (h, s, l)
9795 {
9796
9797 this.getHSL(_hslA);
9798
9799 return this.setHSL(_hslA.h + h, _hslA.s + s, _hslA.l + l);
9800
9801 }
9802
9803 add (color)
9804 {
9805
9806 this.r += color.r;
9807 this.g += color.g;
9808 this.b += color.b;
9809
9810 return this;
9811
9812 }
9813
9814 addColors (color1, color2)
9815 {
9816
9817 this.r = color1.r + color2.r;
9818 this.g = color1.g + color2.g;
9819 this.b = color1.b + color2.b;
9820
9821 return this;
9822
9823 }
9824
9825 addScalar (s)
9826 {
9827
9828 this.r += s;
9829 this.g += s;
9830 this.b += s;
9831
9832 return this;
9833
9834 }
9835
9836 sub (color)
9837 {
9838
9839 this.r = Math.max(0, this.r - color.r);
9840 this.g = Math.max(0, this.g - color.g);
9841 this.b = Math.max(0, this.b - color.b);
9842
9843 return this;
9844
9845 }
9846
9847 multiply (color)
9848 {
9849
9850 this.r *= color.r;
9851 this.g *= color.g;
9852 this.b *= color.b;
9853
9854 return this;
9855
9856 }
9857
9858 multiplyScalar (s)
9859 {
9860
9861 this.r *= s;
9862 this.g *= s;
9863 this.b *= s;
9864
9865 return this;
9866
9867 }
9868
9869 lerp (color, alpha)
9870 {
9871
9872 this.r += (color.r - this.r) * alpha;
9873 this.g += (color.g - this.g) * alpha;
9874 this.b += (color.b - this.b) * alpha;
9875
9876 return this;
9877
9878 }
9879
9880 lerpColors (color1, color2, alpha)
9881 {
9882
9883 this.r = color1.r + (color2.r - color1.r) * alpha;
9884 this.g = color1.g + (color2.g - color1.g) * alpha;
9885 this.b = color1.b + (color2.b - color1.b) * alpha;
9886
9887 return this;
9888
9889 }
9890
9891 lerpHSL (color, alpha)
9892 {
9893
9894 this.getHSL(_hslA);
9895 color.getHSL(_hslB);
9896
9897 const h = lerp(_hslA.h, _hslB.h, alpha);
9898 const s = lerp(_hslA.s, _hslB.s, alpha);
9899 const l = lerp(_hslA.l, _hslB.l, alpha);
9900
9901 this.setHSL(h, s, l);
9902
9903 return this;
9904
9905 }
9906
9907 setFromVector3 (v)
9908 {
9909
9910 this.r = v.x;
9911 this.g = v.y;
9912 this.b = v.z;
9913
9914 return this;
9915
9916 }
9917
9918 applyMatrix3 (m)
9919 {
9920
9921 const r = this.r, g = this.g, b = this.b;
9922 const e = m.elements;
9923
9924 this.r = e[0] * r + e[3] * g + e[6] * b;
9925 this.g = e[1] * r + e[4] * g + e[7] * b;
9926 this.b = e[2] * r + e[5] * g + e[8] * b;
9927
9928 return this;
9929
9930 }
9931
9932 equals (c)
9933 {
9934
9935 return (c.r === this.r) && (c.g === this.g) && (c.b === this.b);
9936
9937 }
9938
9939 fromArray (array, offset = 0)
9940 {
9941
9942 this.r = array[offset];
9943 this.g = array[offset + 1];
9944 this.b = array[offset + 2];
9945
9946 return this;
9947
9948 }
9949
9950 toArray (array = [], offset = 0)
9951 {
9952
9953 array[offset] = this.r;
9954 array[offset + 1] = this.g;
9955 array[offset + 2] = this.b;
9956
9957 return array;
9958
9959 }
9960
9961 fromBufferAttribute (attribute, index)
9962 {
9963
9964 this.r = attribute.getX(index);
9965 this.g = attribute.getY(index);
9966 this.b = attribute.getZ(index);
9967
9968 return this;
9969
9970 }
9971
9972 toJSON ()
9973 {
9974
9975 return this.getHex();
9976
9977 }
9978
9979 *[Symbol.iterator] ()
9980 {
9981
9982 yield this.r;
9983 yield this.g;
9984 yield this.b;
9985
9986 }
9987
9988}
9989
9990const _color = /*@__PURE__*/ new Color();
9991
9992Color.NAMES = _colorKeywords;
9993
9994let _materialId = 0;
9995
9996class Material extends EventDispatcher
9997{
9998
9999 constructor()
10000 {
10001
10002 super();
10003
10004 this.isMaterial = true;
10005
10006 Object.defineProperty(this, 'id', { value: _materialId++ });
10007
10008 this.uuid = generateUUID();
10009
10010 this.name = '';
10011 this.type = 'Material';
10012
10013 this.blending = NormalBlending;
10014 this.side = FrontSide;
10015 this.vertexColors = false;
10016
10017 this.opacity = 1;
10018 this.transparent = false;
10019 this.alphaHash = false;
10020
10021 this.blendSrc = SrcAlphaFactor;
10022 this.blendDst = OneMinusSrcAlphaFactor;
10023 this.blendEquation = AddEquation;
10024 this.blendSrcAlpha = null;
10025 this.blendDstAlpha = null;
10026 this.blendEquationAlpha = null;
10027 this.blendColor = new Color(0, 0, 0);
10028 this.blendAlpha = 0;
10029
10030 this.depthFunc = LessEqualDepth;
10031 this.depthTest = true;
10032 this.depthWrite = true;
10033
10034 this.stencilWriteMask = 0xff;
10035 this.stencilFunc = AlwaysStencilFunc;
10036 this.stencilRef = 0;
10037 this.stencilFuncMask = 0xff;
10038 this.stencilFail = KeepStencilOp;
10039 this.stencilZFail = KeepStencilOp;
10040 this.stencilZPass = KeepStencilOp;
10041 this.stencilWrite = false;
10042
10043 this.clippingPlanes = null;
10044 this.clipIntersection = false;
10045 this.clipShadows = false;
10046
10047 this.shadowSide = null;
10048
10049 this.colorWrite = true;
10050
10051 this.precision = null; // override the renderer's default precision for this material
10052
10053 this.polygonOffset = false;
10054 this.polygonOffsetFactor = 0;
10055 this.polygonOffsetUnits = 0;
10056
10057 this.dithering = false;
10058
10059 this.alphaToCoverage = false;
10060 this.premultipliedAlpha = false;
10061 this.forceSinglePass = false;
10062
10063 this.visible = true;
10064
10065 this.toneMapped = true;
10066
10067 this.userData = {};
10068
10069 this.version = 0;
10070
10071 this._alphaTest = 0;
10072
10073 }
10074
10075 get alphaTest ()
10076 {
10077
10078 return this._alphaTest;
10079
10080 }
10081
10082 set alphaTest (value)
10083 {
10084
10085 if (this._alphaTest > 0 !== value > 0)
10086 {
10087
10088 this.version++;
10089
10090 }
10091
10092 this._alphaTest = value;
10093
10094 }
10095
10096 onBeforeCompile ( /* shaderobject, renderer */) { }
10097
10098 customProgramCacheKey ()
10099 {
10100
10101 return this.onBeforeCompile.toString();
10102
10103 }
10104
10105 setValues (values)
10106 {
10107
10108 if (values === undefined) return;
10109
10110 for (const key in values)
10111 {
10112
10113 const newValue = values[key];
10114
10115 if (newValue === undefined)
10116 {
10117
10118 console.warn(`THREE.Material: parameter '${key}' has value of undefined.`);
10119 continue;
10120
10121 }
10122
10123 const currentValue = this[key];
10124
10125 if (currentValue === undefined)
10126 {
10127
10128 console.warn(`THREE.Material: '${key}' is not a property of THREE.${this.type}.`);
10129 continue;
10130
10131 }
10132
10133 if (currentValue && currentValue.isColor)
10134 {
10135
10136 currentValue.set(newValue);
10137
10138 } else if ((currentValue && currentValue.isVector3) && (newValue && newValue.isVector3))
10139 {
10140
10141 currentValue.copy(newValue);
10142
10143 } else
10144 {
10145
10146 this[key] = newValue;
10147
10148 }
10149
10150 }
10151
10152 }
10153
10154 toJSON (meta)
10155 {
10156
10157 const isRootObject = (meta === undefined || typeof meta === 'string');
10158
10159 if (isRootObject)
10160 {
10161
10162 meta = {
10163 textures: {},
10164 images: {}
10165 };
10166
10167 }
10168
10169 const data = {
10170 metadata: {
10171 version: 4.6,
10172 type: 'Material',
10173 generator: 'Material.toJSON'
10174 }
10175 };
10176
10177 // standard Material serialization
10178 data.uuid = this.uuid;
10179 data.type = this.type;
10180
10181 if (this.name !== '') data.name = this.name;
10182
10183 if (this.color && this.color.isColor) data.color = this.color.getHex();
10184
10185 if (this.roughness !== undefined) data.roughness = this.roughness;
10186 if (this.metalness !== undefined) data.metalness = this.metalness;
10187
10188 if (this.sheen !== undefined) data.sheen = this.sheen;
10189 if (this.sheenColor && this.sheenColor.isColor) data.sheenColor = this.sheenColor.getHex();
10190 if (this.sheenRoughness !== undefined) data.sheenRoughness = this.sheenRoughness;
10191 if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
10192 if (this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
10193
10194 if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
10195 if (this.specularIntensity !== undefined) data.specularIntensity = this.specularIntensity;
10196 if (this.specularColor && this.specularColor.isColor) data.specularColor = this.specularColor.getHex();
10197 if (this.shininess !== undefined) data.shininess = this.shininess;
10198 if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
10199 if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
10200
10201 if (this.clearcoatMap && this.clearcoatMap.isTexture)
10202 {
10203
10204 data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
10205
10206 }
10207
10208 if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture)
10209 {
10210
10211 data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
10212
10213 }
10214
10215 if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture)
10216 {
10217
10218 data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
10219 data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
10220
10221 }
10222
10223 if (this.dispersion !== undefined) data.dispersion = this.dispersion;
10224
10225 if (this.iridescence !== undefined) data.iridescence = this.iridescence;
10226 if (this.iridescenceIOR !== undefined) data.iridescenceIOR = this.iridescenceIOR;
10227 if (this.iridescenceThicknessRange !== undefined) data.iridescenceThicknessRange = this.iridescenceThicknessRange;
10228
10229 if (this.iridescenceMap && this.iridescenceMap.isTexture)
10230 {
10231
10232 data.iridescenceMap = this.iridescenceMap.toJSON(meta).uuid;
10233
10234 }
10235
10236 if (this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture)
10237 {
10238
10239 data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON(meta).uuid;
10240
10241 }
10242
10243 if (this.anisotropy !== undefined) data.anisotropy = this.anisotropy;
10244 if (this.anisotropyRotation !== undefined) data.anisotropyRotation = this.anisotropyRotation;
10245
10246 if (this.anisotropyMap && this.anisotropyMap.isTexture)
10247 {
10248
10249 data.anisotropyMap = this.anisotropyMap.toJSON(meta).uuid;
10250
10251 }
10252
10253 if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
10254 if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
10255 if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
10256
10257 if (this.lightMap && this.lightMap.isTexture)
10258 {
10259
10260 data.lightMap = this.lightMap.toJSON(meta).uuid;
10261 data.lightMapIntensity = this.lightMapIntensity;
10262
10263 }
10264
10265 if (this.aoMap && this.aoMap.isTexture)
10266 {
10267
10268 data.aoMap = this.aoMap.toJSON(meta).uuid;
10269 data.aoMapIntensity = this.aoMapIntensity;
10270
10271 }
10272
10273 if (this.bumpMap && this.bumpMap.isTexture)
10274 {
10275
10276 data.bumpMap = this.bumpMap.toJSON(meta).uuid;
10277 data.bumpScale = this.bumpScale;
10278
10279 }
10280
10281 if (this.normalMap && this.normalMap.isTexture)
10282 {
10283
10284 data.normalMap = this.normalMap.toJSON(meta).uuid;
10285 data.normalMapType = this.normalMapType;
10286 data.normalScale = this.normalScale.toArray();
10287
10288 }
10289
10290 if (this.displacementMap && this.displacementMap.isTexture)
10291 {
10292
10293 data.displacementMap = this.displacementMap.toJSON(meta).uuid;
10294 data.displacementScale = this.displacementScale;
10295 data.displacementBias = this.displacementBias;
10296
10297 }
10298
10299 if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
10300 if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
10301
10302 if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
10303 if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
10304 if (this.specularIntensityMap && this.specularIntensityMap.isTexture) data.specularIntensityMap = this.specularIntensityMap.toJSON(meta).uuid;
10305 if (this.specularColorMap && this.specularColorMap.isTexture) data.specularColorMap = this.specularColorMap.toJSON(meta).uuid;
10306
10307 if (this.envMap && this.envMap.isTexture)
10308 {
10309
10310 data.envMap = this.envMap.toJSON(meta).uuid;
10311
10312 if (this.combine !== undefined) data.combine = this.combine;
10313
10314 }
10315
10316 if (this.envMapRotation !== undefined) data.envMapRotation = this.envMapRotation.toArray();
10317 if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
10318 if (this.reflectivity !== undefined) data.reflectivity = this.reflectivity;
10319 if (this.refractionRatio !== undefined) data.refractionRatio = this.refractionRatio;
10320
10321 if (this.gradientMap && this.gradientMap.isTexture)
10322 {
10323
10324 data.gradientMap = this.gradientMap.toJSON(meta).uuid;
10325
10326 }
10327
10328 if (this.transmission !== undefined) data.transmission = this.transmission;
10329 if (this.transmissionMap && this.transmissionMap.isTexture) data.transmissionMap = this.transmissionMap.toJSON(meta).uuid;
10330 if (this.thickness !== undefined) data.thickness = this.thickness;
10331 if (this.thicknessMap && this.thicknessMap.isTexture) data.thicknessMap = this.thicknessMap.toJSON(meta).uuid;
10332 if (this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity) data.attenuationDistance = this.attenuationDistance;
10333 if (this.attenuationColor !== undefined) data.attenuationColor = this.attenuationColor.getHex();
10334
10335 if (this.size !== undefined) data.size = this.size;
10336 if (this.shadowSide !== null) data.shadowSide = this.shadowSide;
10337 if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
10338
10339 if (this.blending !== NormalBlending) data.blending = this.blending;
10340 if (this.side !== FrontSide) data.side = this.side;
10341 if (this.vertexColors === true) data.vertexColors = true;
10342
10343 if (this.opacity < 1) data.opacity = this.opacity;
10344 if (this.transparent === true) data.transparent = true;
10345
10346 if (this.blendSrc !== SrcAlphaFactor) data.blendSrc = this.blendSrc;
10347 if (this.blendDst !== OneMinusSrcAlphaFactor) data.blendDst = this.blendDst;
10348 if (this.blendEquation !== AddEquation) data.blendEquation = this.blendEquation;
10349 if (this.blendSrcAlpha !== null) data.blendSrcAlpha = this.blendSrcAlpha;
10350 if (this.blendDstAlpha !== null) data.blendDstAlpha = this.blendDstAlpha;
10351 if (this.blendEquationAlpha !== null) data.blendEquationAlpha = this.blendEquationAlpha;
10352 if (this.blendColor && this.blendColor.isColor) data.blendColor = this.blendColor.getHex();
10353 if (this.blendAlpha !== 0) data.blendAlpha = this.blendAlpha;
10354
10355 if (this.depthFunc !== LessEqualDepth) data.depthFunc = this.depthFunc;
10356 if (this.depthTest === false) data.depthTest = this.depthTest;
10357 if (this.depthWrite === false) data.depthWrite = this.depthWrite;
10358 if (this.colorWrite === false) data.colorWrite = this.colorWrite;
10359
10360 if (this.stencilWriteMask !== 0xff) data.stencilWriteMask = this.stencilWriteMask;
10361 if (this.stencilFunc !== AlwaysStencilFunc) data.stencilFunc = this.stencilFunc;
10362 if (this.stencilRef !== 0) data.stencilRef = this.stencilRef;
10363 if (this.stencilFuncMask !== 0xff) data.stencilFuncMask = this.stencilFuncMask;
10364 if (this.stencilFail !== KeepStencilOp) data.stencilFail = this.stencilFail;
10365 if (this.stencilZFail !== KeepStencilOp) data.stencilZFail = this.stencilZFail;
10366 if (this.stencilZPass !== KeepStencilOp) data.stencilZPass = this.stencilZPass;
10367 if (this.stencilWrite === true) data.stencilWrite = this.stencilWrite;
10368
10369 // rotation (SpriteMaterial)
10370 if (this.rotation !== undefined && this.rotation !== 0) data.rotation = this.rotation;
10371
10372 if (this.polygonOffset === true) data.polygonOffset = true;
10373 if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
10374 if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
10375
10376 if (this.linewidth !== undefined && this.linewidth !== 1) data.linewidth = this.linewidth;
10377 if (this.dashSize !== undefined) data.dashSize = this.dashSize;
10378 if (this.gapSize !== undefined) data.gapSize = this.gapSize;
10379 if (this.scale !== undefined) data.scale = this.scale;
10380
10381 if (this.dithering === true) data.dithering = true;
10382
10383 if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
10384 if (this.alphaHash === true) data.alphaHash = true;
10385 if (this.alphaToCoverage === true) data.alphaToCoverage = true;
10386 if (this.premultipliedAlpha === true) data.premultipliedAlpha = true;
10387 if (this.forceSinglePass === true) data.forceSinglePass = true;
10388
10389 if (this.wireframe === true) data.wireframe = true;
10390 if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
10391 if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
10392 if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
10393
10394 if (this.flatShading === true) data.flatShading = true;
10395
10396 if (this.visible === false) data.visible = false;
10397
10398 if (this.toneMapped === false) data.toneMapped = false;
10399
10400 if (this.fog === false) data.fog = false;
10401
10402 if (Object.keys(this.userData).length > 0) data.userData = this.userData;
10403
10404 // TODO: Copied from Object3D.toJSON
10405
10406 function extractFromCache (cache)
10407 {
10408
10409 const values = [];
10410
10411 for (const key in cache)
10412 {
10413
10414 const data = cache[key];
10415 delete data.metadata;
10416 values.push(data);
10417
10418 }
10419
10420 return values;
10421
10422 }
10423
10424 if (isRootObject)
10425 {
10426
10427 const textures = extractFromCache(meta.textures);
10428 const images = extractFromCache(meta.images);
10429
10430 if (textures.length > 0) data.textures = textures;
10431 if (images.length > 0) data.images = images;
10432
10433 }
10434
10435 return data;
10436
10437 }
10438
10439 clone ()
10440 {
10441
10442 return new this.constructor().copy(this);
10443
10444 }
10445
10446 copy (source)
10447 {
10448
10449 this.name = source.name;
10450
10451 this.blending = source.blending;
10452 this.side = source.side;
10453 this.vertexColors = source.vertexColors;
10454
10455 this.opacity = source.opacity;
10456 this.transparent = source.transparent;
10457
10458 this.blendSrc = source.blendSrc;
10459 this.blendDst = source.blendDst;
10460 this.blendEquation = source.blendEquation;
10461 this.blendSrcAlpha = source.blendSrcAlpha;
10462 this.blendDstAlpha = source.blendDstAlpha;
10463 this.blendEquationAlpha = source.blendEquationAlpha;
10464 this.blendColor.copy(source.blendColor);
10465 this.blendAlpha = source.blendAlpha;
10466
10467 this.depthFunc = source.depthFunc;
10468 this.depthTest = source.depthTest;
10469 this.depthWrite = source.depthWrite;
10470
10471 this.stencilWriteMask = source.stencilWriteMask;
10472 this.stencilFunc = source.stencilFunc;
10473 this.stencilRef = source.stencilRef;
10474 this.stencilFuncMask = source.stencilFuncMask;
10475 this.stencilFail = source.stencilFail;
10476 this.stencilZFail = source.stencilZFail;
10477 this.stencilZPass = source.stencilZPass;
10478 this.stencilWrite = source.stencilWrite;
10479
10480 const srcPlanes = source.clippingPlanes;
10481 let dstPlanes = null;
10482
10483 if (srcPlanes !== null)
10484 {
10485
10486 const n = srcPlanes.length;
10487 dstPlanes = new Array(n);
10488
10489 for (let i = 0; i !== n; ++i)
10490 {
10491
10492 dstPlanes[i] = srcPlanes[i].clone();
10493
10494 }
10495
10496 }
10497
10498 this.clippingPlanes = dstPlanes;
10499 this.clipIntersection = source.clipIntersection;
10500 this.clipShadows = source.clipShadows;
10501
10502 this.shadowSide = source.shadowSide;
10503
10504 this.colorWrite = source.colorWrite;
10505
10506 this.precision = source.precision;
10507
10508 this.polygonOffset = source.polygonOffset;
10509 this.polygonOffsetFactor = source.polygonOffsetFactor;
10510 this.polygonOffsetUnits = source.polygonOffsetUnits;
10511
10512 this.dithering = source.dithering;
10513
10514 this.alphaTest = source.alphaTest;
10515 this.alphaHash = source.alphaHash;
10516 this.alphaToCoverage = source.alphaToCoverage;
10517 this.premultipliedAlpha = source.premultipliedAlpha;
10518 this.forceSinglePass = source.forceSinglePass;
10519
10520 this.visible = source.visible;
10521
10522 this.toneMapped = source.toneMapped;
10523
10524 this.userData = JSON.parse(JSON.stringify(source.userData));
10525
10526 return this;
10527
10528 }
10529
10530 dispose ()
10531 {
10532
10533 this.dispatchEvent({ type: 'dispose' });
10534
10535 }
10536
10537 set needsUpdate (value)
10538 {
10539
10540 if (value === true) this.version++;
10541
10542 }
10543
10544 onBuild ( /* shaderobject, renderer */)
10545 {
10546
10547 console.warn('Material: onBuild() has been removed.'); // @deprecated, r166
10548
10549 }
10550
10551 onBeforeRender ( /* renderer, scene, camera, geometry, object, group */)
10552 {
10553
10554 console.warn('Material: onBeforeRender() has been removed.'); // @deprecated, r166
10555
10556 }
10557
10558
10559}
10560
10561class MeshBasicMaterial extends Material
10562{
10563
10564 constructor(parameters)
10565 {
10566
10567 super();
10568
10569 this.isMeshBasicMaterial = true;
10570
10571 this.type = 'MeshBasicMaterial';
10572
10573 this.color = new Color(0xffffff); // emissive
10574
10575 this.map = null;
10576
10577 this.lightMap = null;
10578 this.lightMapIntensity = 1.0;
10579
10580 this.aoMap = null;
10581 this.aoMapIntensity = 1.0;
10582
10583 this.specularMap = null;
10584
10585 this.alphaMap = null;
10586
10587 this.envMap = null;
10588 this.envMapRotation = new Euler();
10589 this.combine = MultiplyOperation;
10590 this.reflectivity = 1;
10591 this.refractionRatio = 0.98;
10592
10593 this.wireframe = false;
10594 this.wireframeLinewidth = 1;
10595 this.wireframeLinecap = 'round';
10596 this.wireframeLinejoin = 'round';
10597
10598 this.fog = true;
10599
10600 this.setValues(parameters);
10601
10602 }
10603
10604 copy (source)
10605 {
10606
10607 super.copy(source);
10608
10609 this.color.copy(source.color);
10610
10611 this.map = source.map;
10612
10613 this.lightMap = source.lightMap;
10614 this.lightMapIntensity = source.lightMapIntensity;
10615
10616 this.aoMap = source.aoMap;
10617 this.aoMapIntensity = source.aoMapIntensity;
10618
10619 this.specularMap = source.specularMap;
10620
10621 this.alphaMap = source.alphaMap;
10622
10623 this.envMap = source.envMap;
10624 this.envMapRotation.copy(source.envMapRotation);
10625 this.combine = source.combine;
10626 this.reflectivity = source.reflectivity;
10627 this.refractionRatio = source.refractionRatio;
10628
10629 this.wireframe = source.wireframe;
10630 this.wireframeLinewidth = source.wireframeLinewidth;
10631 this.wireframeLinecap = source.wireframeLinecap;
10632 this.wireframeLinejoin = source.wireframeLinejoin;
10633
10634 this.fog = source.fog;
10635
10636 return this;
10637
10638 }
10639
10640}
10641
10642// Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
10643
10644const _tables = /*@__PURE__*/ _generateTables();
10645
10646function _generateTables ()
10647{
10648
10649 // float32 to float16 helpers
10650
10651 const buffer = new ArrayBuffer(4);
10652 const floatView = new Float32Array(buffer);
10653 const uint32View = new Uint32Array(buffer);
10654
10655 const baseTable = new Uint32Array(512);
10656 const shiftTable = new Uint32Array(512);
10657
10658 for (let i = 0; i < 256; ++i)
10659 {
10660
10661 const e = i - 127;
10662
10663 // very small number (0, -0)
10664
10665 if (e < - 27)
10666 {
10667
10668 baseTable[i] = 0x0000;
10669 baseTable[i | 0x100] = 0x8000;
10670 shiftTable[i] = 24;
10671 shiftTable[i | 0x100] = 24;
10672
10673 // small number (denorm)
10674
10675 } else if (e < - 14)
10676 {
10677
10678 baseTable[i] = 0x0400 >> (- e - 14);
10679 baseTable[i | 0x100] = (0x0400 >> (- e - 14)) | 0x8000;
10680 shiftTable[i] = - e - 1;
10681 shiftTable[i | 0x100] = - e - 1;
10682
10683 // normal number
10684
10685 } else if (e <= 15)
10686 {
10687
10688 baseTable[i] = (e + 15) << 10;
10689 baseTable[i | 0x100] = ((e + 15) << 10) | 0x8000;
10690 shiftTable[i] = 13;
10691 shiftTable[i | 0x100] = 13;
10692
10693 // large number (Infinity, -Infinity)
10694
10695 } else if (e < 128)
10696 {
10697
10698 baseTable[i] = 0x7c00;
10699 baseTable[i | 0x100] = 0xfc00;
10700 shiftTable[i] = 24;
10701 shiftTable[i | 0x100] = 24;
10702
10703 // stay (NaN, Infinity, -Infinity)
10704
10705 } else
10706 {
10707
10708 baseTable[i] = 0x7c00;
10709 baseTable[i | 0x100] = 0xfc00;
10710 shiftTable[i] = 13;
10711 shiftTable[i | 0x100] = 13;
10712
10713 }
10714
10715 }
10716
10717 // float16 to float32 helpers
10718
10719 const mantissaTable = new Uint32Array(2048);
10720 const exponentTable = new Uint32Array(64);
10721 const offsetTable = new Uint32Array(64);
10722
10723 for (let i = 1; i < 1024; ++i)
10724 {
10725
10726 let m = i << 13; // zero pad mantissa bits
10727 let e = 0; // zero exponent
10728
10729 // normalized
10730 while ((m & 0x00800000) === 0)
10731 {
10732
10733 m <<= 1;
10734 e -= 0x00800000; // decrement exponent
10735
10736 }
10737
10738 m &= ~0x00800000; // clear leading 1 bit
10739 e += 0x38800000; // adjust bias
10740
10741 mantissaTable[i] = m | e;
10742
10743 }
10744
10745 for (let i = 1024; i < 2048; ++i)
10746 {
10747
10748 mantissaTable[i] = 0x38000000 + ((i - 1024) << 13);
10749
10750 }
10751
10752 for (let i = 1; i < 31; ++i)
10753 {
10754
10755 exponentTable[i] = i << 23;
10756
10757 }
10758
10759 exponentTable[31] = 0x47800000;
10760 exponentTable[32] = 0x80000000;
10761
10762 for (let i = 33; i < 63; ++i)
10763 {
10764
10765 exponentTable[i] = 0x80000000 + ((i - 32) << 23);
10766
10767 }
10768
10769 exponentTable[63] = 0xc7800000;
10770
10771 for (let i = 1; i < 64; ++i)
10772 {
10773
10774 if (i !== 32)
10775 {
10776
10777 offsetTable[i] = 1024;
10778
10779 }
10780
10781 }
10782
10783 return {
10784 floatView: floatView,
10785 uint32View: uint32View,
10786 baseTable: baseTable,
10787 shiftTable: shiftTable,
10788 mantissaTable: mantissaTable,
10789 exponentTable: exponentTable,
10790 offsetTable: offsetTable
10791 };
10792
10793}
10794
10795// float32 to float16
10796
10797function toHalfFloat (val)
10798{
10799
10800 if (Math.abs(val) > 65504) console.warn('THREE.DataUtils.toHalfFloat(): Value out of range.');
10801
10802 val = clamp(val, - 65504, 65504);
10803
10804 _tables.floatView[0] = val;
10805 const f = _tables.uint32View[0];
10806 const e = (f >> 23) & 0x1ff;
10807 return _tables.baseTable[e] + ((f & 0x007fffff) >> _tables.shiftTable[e]);
10808
10809}
10810
10811// float16 to float32
10812
10813function fromHalfFloat (val)
10814{
10815
10816 const m = val >> 10;
10817 _tables.uint32View[0] = _tables.mantissaTable[_tables.offsetTable[m] + (val & 0x3ff)] + _tables.exponentTable[m];
10818 return _tables.floatView[0];
10819
10820}
10821
10822const DataUtils = {
10823 toHalfFloat: toHalfFloat,
10824 fromHalfFloat: fromHalfFloat,
10825};
10826
10827const _vector$9 = /*@__PURE__*/ new Vector3();
10828const _vector2$1 = /*@__PURE__*/ new Vector2();
10829
10830class BufferAttribute
10831{
10832
10833 constructor(array, itemSize, normalized = false)
10834 {
10835
10836 if (Array.isArray(array))
10837 {
10838
10839 throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
10840
10841 }
10842
10843 this.isBufferAttribute = true;
10844
10845 this.name = '';
10846
10847 this.array = array;
10848 this.itemSize = itemSize;
10849 this.count = array !== undefined ? array.length / itemSize : 0;
10850 this.normalized = normalized;
10851
10852 this.usage = StaticDrawUsage;
10853 this._updateRange = { offset: 0, count: - 1 };
10854 this.updateRanges = [];
10855 this.gpuType = FloatType;
10856
10857 this.version = 0;
10858
10859 }
10860
10861 onUploadCallback () { }
10862
10863 set needsUpdate (value)
10864 {
10865
10866 if (value === true) this.version++;
10867
10868 }
10869
10870 get updateRange ()
10871 {
10872
10873 warnOnce('THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead.'); // @deprecated, r159
10874 return this._updateRange;
10875
10876 }
10877
10878 setUsage (value)
10879 {
10880
10881 this.usage = value;
10882
10883 return this;
10884
10885 }
10886
10887 addUpdateRange (start, count)
10888 {
10889
10890 this.updateRanges.push({ start, count });
10891
10892 }
10893
10894 clearUpdateRanges ()
10895 {
10896
10897 this.updateRanges.length = 0;
10898
10899 }
10900
10901 copy (source)
10902 {
10903
10904 this.name = source.name;
10905 this.array = new source.array.constructor(source.array);
10906 this.itemSize = source.itemSize;
10907 this.count = source.count;
10908 this.normalized = source.normalized;
10909
10910 this.usage = source.usage;
10911 this.gpuType = source.gpuType;
10912
10913 return this;
10914
10915 }
10916
10917 copyAt (index1, attribute, index2)
10918 {
10919
10920 index1 *= this.itemSize;
10921 index2 *= attribute.itemSize;
10922
10923 for (let i = 0, l = this.itemSize; i < l; i++)
10924 {
10925
10926 this.array[index1 + i] = attribute.array[index2 + i];
10927
10928 }
10929
10930 return this;
10931
10932 }
10933
10934 copyArray (array)
10935 {
10936
10937 this.array.set(array);
10938
10939 return this;
10940
10941 }
10942
10943 applyMatrix3 (m)
10944 {
10945
10946 if (this.itemSize === 2)
10947 {
10948
10949 for (let i = 0, l = this.count; i < l; i++)
10950 {
10951
10952 _vector2$1.fromBufferAttribute(this, i);
10953 _vector2$1.applyMatrix3(m);
10954
10955 this.setXY(i, _vector2$1.x, _vector2$1.y);
10956
10957 }
10958
10959 } else if (this.itemSize === 3)
10960 {
10961
10962 for (let i = 0, l = this.count; i < l; i++)
10963 {
10964
10965 _vector$9.fromBufferAttribute(this, i);
10966 _vector$9.applyMatrix3(m);
10967
10968 this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
10969
10970 }
10971
10972 }
10973
10974 return this;
10975
10976 }
10977
10978 applyMatrix4 (m)
10979 {
10980
10981 for (let i = 0, l = this.count; i < l; i++)
10982 {
10983
10984 _vector$9.fromBufferAttribute(this, i);
10985
10986 _vector$9.applyMatrix4(m);
10987
10988 this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
10989
10990 }
10991
10992 return this;
10993
10994 }
10995
10996 applyNormalMatrix (m)
10997 {
10998
10999 for (let i = 0, l = this.count; i < l; i++)
11000 {
11001
11002 _vector$9.fromBufferAttribute(this, i);
11003
11004 _vector$9.applyNormalMatrix(m);
11005
11006 this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
11007
11008 }
11009
11010 return this;
11011
11012 }
11013
11014 transformDirection (m)
11015 {
11016
11017 for (let i = 0, l = this.count; i < l; i++)
11018 {
11019
11020 _vector$9.fromBufferAttribute(this, i);
11021
11022 _vector$9.transformDirection(m);
11023
11024 this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
11025
11026 }
11027
11028 return this;
11029
11030 }
11031
11032 set (value, offset = 0)
11033 {
11034
11035 // Matching BufferAttribute constructor, do not normalize the array.
11036 this.array.set(value, offset);
11037
11038 return this;
11039
11040 }
11041
11042 getComponent (index, component)
11043 {
11044
11045 let value = this.array[index * this.itemSize + component];
11046
11047 if (this.normalized) value = denormalize(value, this.array);
11048
11049 return value;
11050
11051 }
11052
11053 setComponent (index, component, value)
11054 {
11055
11056 if (this.normalized) value = normalize(value, this.array);
11057
11058 this.array[index * this.itemSize + component] = value;
11059
11060 return this;
11061
11062 }
11063
11064 getX (index)
11065 {
11066
11067 let x = this.array[index * this.itemSize];
11068
11069 if (this.normalized) x = denormalize(x, this.array);
11070
11071 return x;
11072
11073 }
11074
11075 setX (index, x)
11076 {
11077
11078 if (this.normalized) x = normalize(x, this.array);
11079
11080 this.array[index * this.itemSize] = x;
11081
11082 return this;
11083
11084 }
11085
11086 getY (index)
11087 {
11088
11089 let y = this.array[index * this.itemSize + 1];
11090
11091 if (this.normalized) y = denormalize(y, this.array);
11092
11093 return y;
11094
11095 }
11096
11097 setY (index, y)
11098 {
11099
11100 if (this.normalized) y = normalize(y, this.array);
11101
11102 this.array[index * this.itemSize + 1] = y;
11103
11104 return this;
11105
11106 }
11107
11108 getZ (index)
11109 {
11110
11111 let z = this.array[index * this.itemSize + 2];
11112
11113 if (this.normalized) z = denormalize(z, this.array);
11114
11115 return z;
11116
11117 }
11118
11119 setZ (index, z)
11120 {
11121
11122 if (this.normalized) z = normalize(z, this.array);
11123
11124 this.array[index * this.itemSize + 2] = z;
11125
11126 return this;
11127
11128 }
11129
11130 getW (index)
11131 {
11132
11133 let w = this.array[index * this.itemSize + 3];
11134
11135 if (this.normalized) w = denormalize(w, this.array);
11136
11137 return w;
11138
11139 }
11140
11141 setW (index, w)
11142 {
11143
11144 if (this.normalized) w = normalize(w, this.array);
11145
11146 this.array[index * this.itemSize + 3] = w;
11147
11148 return this;
11149
11150 }
11151
11152 setXY (index, x, y)
11153 {
11154
11155 index *= this.itemSize;
11156
11157 if (this.normalized)
11158 {
11159
11160 x = normalize(x, this.array);
11161 y = normalize(y, this.array);
11162
11163 }
11164
11165 this.array[index + 0] = x;
11166 this.array[index + 1] = y;
11167
11168 return this;
11169
11170 }
11171
11172 setXYZ (index, x, y, z)
11173 {
11174
11175 index *= this.itemSize;
11176
11177 if (this.normalized)
11178 {
11179
11180 x = normalize(x, this.array);
11181 y = normalize(y, this.array);
11182 z = normalize(z, this.array);
11183
11184 }
11185
11186 this.array[index + 0] = x;
11187 this.array[index + 1] = y;
11188 this.array[index + 2] = z;
11189
11190 return this;
11191
11192 }
11193
11194 setXYZW (index, x, y, z, w)
11195 {
11196
11197 index *= this.itemSize;
11198
11199 if (this.normalized)
11200 {
11201
11202 x = normalize(x, this.array);
11203 y = normalize(y, this.array);
11204 z = normalize(z, this.array);
11205 w = normalize(w, this.array);
11206
11207 }
11208
11209 this.array[index + 0] = x;
11210 this.array[index + 1] = y;
11211 this.array[index + 2] = z;
11212 this.array[index + 3] = w;
11213
11214 return this;
11215
11216 }
11217
11218 onUpload (callback)
11219 {
11220
11221 this.onUploadCallback = callback;
11222
11223 return this;
11224
11225 }
11226
11227 clone ()
11228 {
11229
11230 return new this.constructor(this.array, this.itemSize).copy(this);
11231
11232 }
11233
11234 toJSON ()
11235 {
11236
11237 const data = {
11238 itemSize: this.itemSize,
11239 type: this.array.constructor.name,
11240 array: Array.from(this.array),
11241 normalized: this.normalized
11242 };
11243
11244 if (this.name !== '') data.name = this.name;
11245 if (this.usage !== StaticDrawUsage) data.usage = this.usage;
11246
11247 return data;
11248
11249 }
11250
11251}
11252
11253//
11254
11255class Int8BufferAttribute extends BufferAttribute
11256{
11257
11258 constructor(array, itemSize, normalized)
11259 {
11260
11261 super(new Int8Array(array), itemSize, normalized);
11262
11263 }
11264
11265}
11266
11267class Uint8BufferAttribute extends BufferAttribute
11268{
11269
11270 constructor(array, itemSize, normalized)
11271 {
11272
11273 super(new Uint8Array(array), itemSize, normalized);
11274
11275 }
11276
11277}
11278
11279class Uint8ClampedBufferAttribute extends BufferAttribute
11280{
11281
11282 constructor(array, itemSize, normalized)
11283 {
11284
11285 super(new Uint8ClampedArray(array), itemSize, normalized);
11286
11287 }
11288
11289}
11290
11291class Int16BufferAttribute extends BufferAttribute
11292{
11293
11294 constructor(array, itemSize, normalized)
11295 {
11296
11297 super(new Int16Array(array), itemSize, normalized);
11298
11299 }
11300
11301}
11302
11303class Uint16BufferAttribute extends BufferAttribute
11304{
11305
11306 constructor(array, itemSize, normalized)
11307 {
11308
11309 super(new Uint16Array(array), itemSize, normalized);
11310
11311 }
11312
11313}
11314
11315class Int32BufferAttribute extends BufferAttribute
11316{
11317
11318 constructor(array, itemSize, normalized)
11319 {
11320
11321 super(new Int32Array(array), itemSize, normalized);
11322
11323 }
11324
11325}
11326
11327class Uint32BufferAttribute extends BufferAttribute
11328{
11329
11330 constructor(array, itemSize, normalized)
11331 {
11332
11333 super(new Uint32Array(array), itemSize, normalized);
11334
11335 }
11336
11337}
11338
11339class Float16BufferAttribute extends BufferAttribute
11340{
11341
11342 constructor(array, itemSize, normalized)
11343 {
11344
11345 super(new Uint16Array(array), itemSize, normalized);
11346
11347 this.isFloat16BufferAttribute = true;
11348
11349 }
11350
11351 getX (index)
11352 {
11353
11354 let x = fromHalfFloat(this.array[index * this.itemSize]);
11355
11356 if (this.normalized) x = denormalize(x, this.array);
11357
11358 return x;
11359
11360 }
11361
11362 setX (index, x)
11363 {
11364
11365 if (this.normalized) x = normalize(x, this.array);
11366
11367 this.array[index * this.itemSize] = toHalfFloat(x);
11368
11369 return this;
11370
11371 }
11372
11373 getY (index)
11374 {
11375
11376 let y = fromHalfFloat(this.array[index * this.itemSize + 1]);
11377
11378 if (this.normalized) y = denormalize(y, this.array);
11379
11380 return y;
11381
11382 }
11383
11384 setY (index, y)
11385 {
11386
11387 if (this.normalized) y = normalize(y, this.array);
11388
11389 this.array[index * this.itemSize + 1] = toHalfFloat(y);
11390
11391 return this;
11392
11393 }
11394
11395 getZ (index)
11396 {
11397
11398 let z = fromHalfFloat(this.array[index * this.itemSize + 2]);
11399
11400 if (this.normalized) z = denormalize(z, this.array);
11401
11402 return z;
11403
11404 }
11405
11406 setZ (index, z)
11407 {
11408
11409 if (this.normalized) z = normalize(z, this.array);
11410
11411 this.array[index * this.itemSize + 2] = toHalfFloat(z);
11412
11413 return this;
11414
11415 }
11416
11417 getW (index)
11418 {
11419
11420 let w = fromHalfFloat(this.array[index * this.itemSize + 3]);
11421
11422 if (this.normalized) w = denormalize(w, this.array);
11423
11424 return w;
11425
11426 }
11427
11428 setW (index, w)
11429 {
11430
11431 if (this.normalized) w = normalize(w, this.array);
11432
11433 this.array[index * this.itemSize + 3] = toHalfFloat(w);
11434
11435 return this;
11436
11437 }
11438
11439 setXY (index, x, y)
11440 {
11441
11442 index *= this.itemSize;
11443
11444 if (this.normalized)
11445 {
11446
11447 x = normalize(x, this.array);
11448 y = normalize(y, this.array);
11449
11450 }
11451
11452 this.array[index + 0] = toHalfFloat(x);
11453 this.array[index + 1] = toHalfFloat(y);
11454
11455 return this;
11456
11457 }
11458
11459 setXYZ (index, x, y, z)
11460 {
11461
11462 index *= this.itemSize;
11463
11464 if (this.normalized)
11465 {
11466
11467 x = normalize(x, this.array);
11468 y = normalize(y, this.array);
11469 z = normalize(z, this.array);
11470
11471 }
11472
11473 this.array[index + 0] = toHalfFloat(x);
11474 this.array[index + 1] = toHalfFloat(y);
11475 this.array[index + 2] = toHalfFloat(z);
11476
11477 return this;
11478
11479 }
11480
11481 setXYZW (index, x, y, z, w)
11482 {
11483
11484 index *= this.itemSize;
11485
11486 if (this.normalized)
11487 {
11488
11489 x = normalize(x, this.array);
11490 y = normalize(y, this.array);
11491 z = normalize(z, this.array);
11492 w = normalize(w, this.array);
11493
11494 }
11495
11496 this.array[index + 0] = toHalfFloat(x);
11497 this.array[index + 1] = toHalfFloat(y);
11498 this.array[index + 2] = toHalfFloat(z);
11499 this.array[index + 3] = toHalfFloat(w);
11500
11501 return this;
11502
11503 }
11504
11505}
11506
11507
11508class Float32BufferAttribute extends BufferAttribute
11509{
11510
11511 constructor(array, itemSize, normalized)
11512 {
11513
11514 super(new Float32Array(array), itemSize, normalized);
11515
11516 }
11517
11518}
11519
11520let _id$2 = 0;
11521
11522const _m1$2 = /*@__PURE__*/ new Matrix4();
11523const _obj = /*@__PURE__*/ new Object3D();
11524const _offset = /*@__PURE__*/ new Vector3();
11525const _box$2 = /*@__PURE__*/ new Box3();
11526const _boxMorphTargets = /*@__PURE__*/ new Box3();
11527const _vector$8 = /*@__PURE__*/ new Vector3();
11528
11529class BufferGeometry extends EventDispatcher
11530{
11531
11532 constructor()
11533 {
11534
11535 super();
11536
11537 this.isBufferGeometry = true;
11538
11539 Object.defineProperty(this, 'id', { value: _id$2++ });
11540
11541 this.uuid = generateUUID();
11542
11543 this.name = '';
11544 this.type = 'BufferGeometry';
11545
11546 this.index = null;
11547 this.attributes = {};
11548
11549 this.morphAttributes = {};
11550 this.morphTargetsRelative = false;
11551
11552 this.groups = [];
11553
11554 this.boundingBox = null;
11555 this.boundingSphere = null;
11556
11557 this.drawRange = { start: 0, count: Infinity };
11558
11559 this.userData = {};
11560
11561 }
11562
11563 getIndex ()
11564 {
11565
11566 return this.index;
11567
11568 }
11569
11570 setIndex (index)
11571 {
11572
11573 if (Array.isArray(index))
11574 {
11575
11576 this.index = new (arrayNeedsUint32(index) ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
11577
11578 } else
11579 {
11580
11581 this.index = index;
11582
11583 }
11584
11585 return this;
11586
11587 }
11588
11589 getAttribute (name)
11590 {
11591
11592 return this.attributes[name];
11593
11594 }
11595
11596 setAttribute (name, attribute)
11597 {
11598
11599 this.attributes[name] = attribute;
11600
11601 return this;
11602
11603 }
11604
11605 deleteAttribute (name)
11606 {
11607
11608 delete this.attributes[name];
11609
11610 return this;
11611
11612 }
11613
11614 hasAttribute (name)
11615 {
11616
11617 return this.attributes[name] !== undefined;
11618
11619 }
11620
11621 addGroup (start, count, materialIndex = 0)
11622 {
11623
11624 this.groups.push({
11625
11626 start: start,
11627 count: count,
11628 materialIndex: materialIndex
11629
11630 });
11631
11632 }
11633
11634 clearGroups ()
11635 {
11636
11637 this.groups = [];
11638
11639 }
11640
11641 setDrawRange (start, count)
11642 {
11643
11644 this.drawRange.start = start;
11645 this.drawRange.count = count;
11646
11647 }
11648
11649 applyMatrix4 (matrix)
11650 {
11651
11652 const position = this.attributes.position;
11653
11654 if (position !== undefined)
11655 {
11656
11657 position.applyMatrix4(matrix);
11658
11659 position.needsUpdate = true;
11660
11661 }
11662
11663 const normal = this.attributes.normal;
11664
11665 if (normal !== undefined)
11666 {
11667
11668 const normalMatrix = new Matrix3().getNormalMatrix(matrix);
11669
11670 normal.applyNormalMatrix(normalMatrix);
11671
11672 normal.needsUpdate = true;
11673
11674 }
11675
11676 const tangent = this.attributes.tangent;
11677
11678 if (tangent !== undefined)
11679 {
11680
11681 tangent.transformDirection(matrix);
11682
11683 tangent.needsUpdate = true;
11684
11685 }
11686
11687 if (this.boundingBox !== null)
11688 {
11689
11690 this.computeBoundingBox();
11691
11692 }
11693
11694 if (this.boundingSphere !== null)
11695 {
11696
11697 this.computeBoundingSphere();
11698
11699 }
11700
11701 return this;
11702
11703 }
11704
11705 applyQuaternion (q)
11706 {
11707
11708 _m1$2.makeRotationFromQuaternion(q);
11709
11710 this.applyMatrix4(_m1$2);
11711
11712 return this;
11713
11714 }
11715
11716 rotateX (angle)
11717 {
11718
11719 // rotate geometry around world x-axis
11720
11721 _m1$2.makeRotationX(angle);
11722
11723 this.applyMatrix4(_m1$2);
11724
11725 return this;
11726
11727 }
11728
11729 rotateY (angle)
11730 {
11731
11732 // rotate geometry around world y-axis
11733
11734 _m1$2.makeRotationY(angle);
11735
11736 this.applyMatrix4(_m1$2);
11737
11738 return this;
11739
11740 }
11741
11742 rotateZ (angle)
11743 {
11744
11745 // rotate geometry around world z-axis
11746
11747 _m1$2.makeRotationZ(angle);
11748
11749 this.applyMatrix4(_m1$2);
11750
11751 return this;
11752
11753 }
11754
11755 translate (x, y, z)
11756 {
11757
11758 // translat
11759… afgekapt