BlueGit

timfa filemanager

Files

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

three.module.js

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