]> gitweb.ps.run Git - cloth_sim/blob - Scripts/three.js
Distinguish between right and left mouse click for wind and dragging
[cloth_sim] / Scripts / three.js
1 // threejs.org/license
2 (function (global, factory) {
3         typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4         typeof define === 'function' && define.amd ? define(['exports'], factory) :
5         (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
6 }(this, (function (exports) { 'use strict';
7
8         // Polyfills
9         if (Number.EPSILON === undefined) {
10                 Number.EPSILON = Math.pow(2, -52);
11         }
12
13         if (Number.isInteger === undefined) {
14                 // Missing in IE
15                 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
16                 Number.isInteger = function (value) {
17                         return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
18                 };
19         } //
20
21
22         if (Math.sign === undefined) {
23                 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
24                 Math.sign = function (x) {
25                         return x < 0 ? -1 : x > 0 ? 1 : +x;
26                 };
27         }
28
29         if ('name' in Function.prototype === false) {
30                 // Missing in IE
31                 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
32                 Object.defineProperty(Function.prototype, 'name', {
33                         get: function get() {
34                                 return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
35                         }
36                 });
37         }
38
39         if (Object.assign === undefined) {
40                 // Missing in IE
41                 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
42                 Object.assign = function (target) {
43
44                         if (target === undefined || target === null) {
45                                 throw new TypeError('Cannot convert undefined or null to object');
46                         }
47
48                         var output = Object(target);
49
50                         for (var index = 1; index < arguments.length; index++) {
51                                 var source = arguments[index];
52
53                                 if (source !== undefined && source !== null) {
54                                         for (var nextKey in source) {
55                                                 if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
56                                                         output[nextKey] = source[nextKey];
57                                                 }
58                                         }
59                                 }
60                         }
61
62                         return output;
63                 };
64         }
65
66         var REVISION = '123';
67         var MOUSE = {
68                 LEFT: 0,
69                 MIDDLE: 1,
70                 RIGHT: 2,
71                 ROTATE: 0,
72                 DOLLY: 1,
73                 PAN: 2
74         };
75         var TOUCH = {
76                 ROTATE: 0,
77                 PAN: 1,
78                 DOLLY_PAN: 2,
79                 DOLLY_ROTATE: 3
80         };
81         var CullFaceNone = 0;
82         var CullFaceBack = 1;
83         var CullFaceFront = 2;
84         var CullFaceFrontBack = 3;
85         var BasicShadowMap = 0;
86         var PCFShadowMap = 1;
87         var PCFSoftShadowMap = 2;
88         var VSMShadowMap = 3;
89         var FrontSide = 0;
90         var BackSide = 1;
91         var DoubleSide = 2;
92         var FlatShading = 1;
93         var SmoothShading = 2;
94         var NoBlending = 0;
95         var NormalBlending = 1;
96         var AdditiveBlending = 2;
97         var SubtractiveBlending = 3;
98         var MultiplyBlending = 4;
99         var CustomBlending = 5;
100         var AddEquation = 100;
101         var SubtractEquation = 101;
102         var ReverseSubtractEquation = 102;
103         var MinEquation = 103;
104         var MaxEquation = 104;
105         var ZeroFactor = 200;
106         var OneFactor = 201;
107         var SrcColorFactor = 202;
108         var OneMinusSrcColorFactor = 203;
109         var SrcAlphaFactor = 204;
110         var OneMinusSrcAlphaFactor = 205;
111         var DstAlphaFactor = 206;
112         var OneMinusDstAlphaFactor = 207;
113         var DstColorFactor = 208;
114         var OneMinusDstColorFactor = 209;
115         var SrcAlphaSaturateFactor = 210;
116         var NeverDepth = 0;
117         var AlwaysDepth = 1;
118         var LessDepth = 2;
119         var LessEqualDepth = 3;
120         var EqualDepth = 4;
121         var GreaterEqualDepth = 5;
122         var GreaterDepth = 6;
123         var NotEqualDepth = 7;
124         var MultiplyOperation = 0;
125         var MixOperation = 1;
126         var AddOperation = 2;
127         var NoToneMapping = 0;
128         var LinearToneMapping = 1;
129         var ReinhardToneMapping = 2;
130         var CineonToneMapping = 3;
131         var ACESFilmicToneMapping = 4;
132         var CustomToneMapping = 5;
133         var UVMapping = 300;
134         var CubeReflectionMapping = 301;
135         var CubeRefractionMapping = 302;
136         var EquirectangularReflectionMapping = 303;
137         var EquirectangularRefractionMapping = 304;
138         var CubeUVReflectionMapping = 306;
139         var CubeUVRefractionMapping = 307;
140         var RepeatWrapping = 1000;
141         var ClampToEdgeWrapping = 1001;
142         var MirroredRepeatWrapping = 1002;
143         var NearestFilter = 1003;
144         var NearestMipmapNearestFilter = 1004;
145         var NearestMipMapNearestFilter = 1004;
146         var NearestMipmapLinearFilter = 1005;
147         var NearestMipMapLinearFilter = 1005;
148         var LinearFilter = 1006;
149         var LinearMipmapNearestFilter = 1007;
150         var LinearMipMapNearestFilter = 1007;
151         var LinearMipmapLinearFilter = 1008;
152         var LinearMipMapLinearFilter = 1008;
153         var UnsignedByteType = 1009;
154         var ByteType = 1010;
155         var ShortType = 1011;
156         var UnsignedShortType = 1012;
157         var IntType = 1013;
158         var UnsignedIntType = 1014;
159         var FloatType = 1015;
160         var HalfFloatType = 1016;
161         var UnsignedShort4444Type = 1017;
162         var UnsignedShort5551Type = 1018;
163         var UnsignedShort565Type = 1019;
164         var UnsignedInt248Type = 1020;
165         var AlphaFormat = 1021;
166         var RGBFormat = 1022;
167         var RGBAFormat = 1023;
168         var LuminanceFormat = 1024;
169         var LuminanceAlphaFormat = 1025;
170         var RGBEFormat = RGBAFormat;
171         var DepthFormat = 1026;
172         var DepthStencilFormat = 1027;
173         var RedFormat = 1028;
174         var RedIntegerFormat = 1029;
175         var RGFormat = 1030;
176         var RGIntegerFormat = 1031;
177         var RGBIntegerFormat = 1032;
178         var RGBAIntegerFormat = 1033;
179         var RGB_S3TC_DXT1_Format = 33776;
180         var RGBA_S3TC_DXT1_Format = 33777;
181         var RGBA_S3TC_DXT3_Format = 33778;
182         var RGBA_S3TC_DXT5_Format = 33779;
183         var RGB_PVRTC_4BPPV1_Format = 35840;
184         var RGB_PVRTC_2BPPV1_Format = 35841;
185         var RGBA_PVRTC_4BPPV1_Format = 35842;
186         var RGBA_PVRTC_2BPPV1_Format = 35843;
187         var RGB_ETC1_Format = 36196;
188         var RGB_ETC2_Format = 37492;
189         var RGBA_ETC2_EAC_Format = 37496;
190         var RGBA_ASTC_4x4_Format = 37808;
191         var RGBA_ASTC_5x4_Format = 37809;
192         var RGBA_ASTC_5x5_Format = 37810;
193         var RGBA_ASTC_6x5_Format = 37811;
194         var RGBA_ASTC_6x6_Format = 37812;
195         var RGBA_ASTC_8x5_Format = 37813;
196         var RGBA_ASTC_8x6_Format = 37814;
197         var RGBA_ASTC_8x8_Format = 37815;
198         var RGBA_ASTC_10x5_Format = 37816;
199         var RGBA_ASTC_10x6_Format = 37817;
200         var RGBA_ASTC_10x8_Format = 37818;
201         var RGBA_ASTC_10x10_Format = 37819;
202         var RGBA_ASTC_12x10_Format = 37820;
203         var RGBA_ASTC_12x12_Format = 37821;
204         var RGBA_BPTC_Format = 36492;
205         var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
206         var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
207         var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
208         var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
209         var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
210         var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
211         var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
212         var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
213         var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
214         var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
215         var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
216         var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
217         var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
218         var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
219         var LoopOnce = 2200;
220         var LoopRepeat = 2201;
221         var LoopPingPong = 2202;
222         var InterpolateDiscrete = 2300;
223         var InterpolateLinear = 2301;
224         var InterpolateSmooth = 2302;
225         var ZeroCurvatureEnding = 2400;
226         var ZeroSlopeEnding = 2401;
227         var WrapAroundEnding = 2402;
228         var NormalAnimationBlendMode = 2500;
229         var AdditiveAnimationBlendMode = 2501;
230         var TrianglesDrawMode = 0;
231         var TriangleStripDrawMode = 1;
232         var TriangleFanDrawMode = 2;
233         var LinearEncoding = 3000;
234         var sRGBEncoding = 3001;
235         var GammaEncoding = 3007;
236         var RGBEEncoding = 3002;
237         var LogLuvEncoding = 3003;
238         var RGBM7Encoding = 3004;
239         var RGBM16Encoding = 3005;
240         var RGBDEncoding = 3006;
241         var BasicDepthPacking = 3200;
242         var RGBADepthPacking = 3201;
243         var TangentSpaceNormalMap = 0;
244         var ObjectSpaceNormalMap = 1;
245         var ZeroStencilOp = 0;
246         var KeepStencilOp = 7680;
247         var ReplaceStencilOp = 7681;
248         var IncrementStencilOp = 7682;
249         var DecrementStencilOp = 7683;
250         var IncrementWrapStencilOp = 34055;
251         var DecrementWrapStencilOp = 34056;
252         var InvertStencilOp = 5386;
253         var NeverStencilFunc = 512;
254         var LessStencilFunc = 513;
255         var EqualStencilFunc = 514;
256         var LessEqualStencilFunc = 515;
257         var GreaterStencilFunc = 516;
258         var NotEqualStencilFunc = 517;
259         var GreaterEqualStencilFunc = 518;
260         var AlwaysStencilFunc = 519;
261         var StaticDrawUsage = 35044;
262         var DynamicDrawUsage = 35048;
263         var StreamDrawUsage = 35040;
264         var StaticReadUsage = 35045;
265         var DynamicReadUsage = 35049;
266         var StreamReadUsage = 35041;
267         var StaticCopyUsage = 35046;
268         var DynamicCopyUsage = 35050;
269         var StreamCopyUsage = 35042;
270         var GLSL1 = "100";
271         var GLSL3 = "300 es";
272
273         /**
274          * https://github.com/mrdoob/eventdispatcher.js/
275          */
276         function EventDispatcher() {}
277
278         Object.assign(EventDispatcher.prototype, {
279                 addEventListener: function addEventListener(type, listener) {
280                         if (this._listeners === undefined) this._listeners = {};
281                         var listeners = this._listeners;
282
283                         if (listeners[type] === undefined) {
284                                 listeners[type] = [];
285                         }
286
287                         if (listeners[type].indexOf(listener) === -1) {
288                                 listeners[type].push(listener);
289                         }
290                 },
291                 hasEventListener: function hasEventListener(type, listener) {
292                         if (this._listeners === undefined) return false;
293                         var listeners = this._listeners;
294                         return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
295                 },
296                 removeEventListener: function removeEventListener(type, listener) {
297                         if (this._listeners === undefined) return;
298                         var listeners = this._listeners;
299                         var listenerArray = listeners[type];
300
301                         if (listenerArray !== undefined) {
302                                 var index = listenerArray.indexOf(listener);
303
304                                 if (index !== -1) {
305                                         listenerArray.splice(index, 1);
306                                 }
307                         }
308                 },
309                 dispatchEvent: function dispatchEvent(event) {
310                         if (this._listeners === undefined) return;
311                         var listeners = this._listeners;
312                         var listenerArray = listeners[event.type];
313
314                         if (listenerArray !== undefined) {
315                                 event.target = this; // Make a copy, in case listeners are removed while iterating.
316
317                                 var array = listenerArray.slice(0);
318
319                                 for (var i = 0, l = array.length; i < l; i++) {
320                                         array[i].call(this, event);
321                                 }
322                         }
323                 }
324         });
325
326         var _lut = [];
327
328         for (var i = 0; i < 256; i++) {
329                 _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
330         }
331
332         var _seed = 1234567;
333         var MathUtils = {
334                 DEG2RAD: Math.PI / 180,
335                 RAD2DEG: 180 / Math.PI,
336                 generateUUID: function generateUUID() {
337                         // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
338                         var d0 = Math.random() * 0xffffffff | 0;
339                         var d1 = Math.random() * 0xffffffff | 0;
340                         var d2 = Math.random() * 0xffffffff | 0;
341                         var d3 = Math.random() * 0xffffffff | 0;
342                         var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
343
344                         return uuid.toUpperCase();
345                 },
346                 clamp: function clamp(value, min, max) {
347                         return Math.max(min, Math.min(max, value));
348                 },
349                 // compute euclidian modulo of m % n
350                 // https://en.wikipedia.org/wiki/Modulo_operation
351                 euclideanModulo: function euclideanModulo(n, m) {
352                         return (n % m + m) % m;
353                 },
354                 // Linear mapping from range <a1, a2> to range <b1, b2>
355                 mapLinear: function mapLinear(x, a1, a2, b1, b2) {
356                         return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
357                 },
358                 // https://en.wikipedia.org/wiki/Linear_interpolation
359                 lerp: function lerp(x, y, t) {
360                         return (1 - t) * x + t * y;
361                 },
362                 // http://en.wikipedia.org/wiki/Smoothstep
363                 smoothstep: function smoothstep(x, min, max) {
364                         if (x <= min) return 0;
365                         if (x >= max) return 1;
366                         x = (x - min) / (max - min);
367                         return x * x * (3 - 2 * x);
368                 },
369                 smootherstep: function smootherstep(x, min, max) {
370                         if (x <= min) return 0;
371                         if (x >= max) return 1;
372                         x = (x - min) / (max - min);
373                         return x * x * x * (x * (x * 6 - 15) + 10);
374                 },
375                 // Random integer from <low, high> interval
376                 randInt: function randInt(low, high) {
377                         return low + Math.floor(Math.random() * (high - low + 1));
378                 },
379                 // Random float from <low, high> interval
380                 randFloat: function randFloat(low, high) {
381                         return low + Math.random() * (high - low);
382                 },
383                 // Random float from <-range/2, range/2> interval
384                 randFloatSpread: function randFloatSpread(range) {
385                         return range * (0.5 - Math.random());
386                 },
387                 // Deterministic pseudo-random float in the interval [ 0, 1 ]
388                 seededRandom: function seededRandom(s) {
389                         if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
390
391                         _seed = _seed * 16807 % 2147483647;
392                         return (_seed - 1) / 2147483646;
393                 },
394                 degToRad: function degToRad(degrees) {
395                         return degrees * MathUtils.DEG2RAD;
396                 },
397                 radToDeg: function radToDeg(radians) {
398                         return radians * MathUtils.RAD2DEG;
399                 },
400                 isPowerOfTwo: function isPowerOfTwo(value) {
401                         return (value & value - 1) === 0 && value !== 0;
402                 },
403                 ceilPowerOfTwo: function ceilPowerOfTwo(value) {
404                         return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
405                 },
406                 floorPowerOfTwo: function floorPowerOfTwo(value) {
407                         return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
408                 },
409                 setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
410                         // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
411                         // rotations are applied to the axes in the order specified by 'order'
412                         // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
413                         // angles are in radians
414                         var cos = Math.cos;
415                         var sin = Math.sin;
416                         var c2 = cos(b / 2);
417                         var s2 = sin(b / 2);
418                         var c13 = cos((a + c) / 2);
419                         var s13 = sin((a + c) / 2);
420                         var c1_3 = cos((a - c) / 2);
421                         var s1_3 = sin((a - c) / 2);
422                         var c3_1 = cos((c - a) / 2);
423                         var s3_1 = sin((c - a) / 2);
424
425                         switch (order) {
426                                 case 'XYX':
427                                         q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
428                                         break;
429
430                                 case 'YZY':
431                                         q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
432                                         break;
433
434                                 case 'ZXZ':
435                                         q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
436                                         break;
437
438                                 case 'XZX':
439                                         q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
440                                         break;
441
442                                 case 'YXY':
443                                         q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
444                                         break;
445
446                                 case 'ZYZ':
447                                         q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
448                                         break;
449
450                                 default:
451                                         console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
452                         }
453                 }
454         };
455
456         function _defineProperties(target, props) {
457                 for (var i = 0; i < props.length; i++) {
458                         var descriptor = props[i];
459                         descriptor.enumerable = descriptor.enumerable || false;
460                         descriptor.configurable = true;
461                         if ("value" in descriptor) descriptor.writable = true;
462                         Object.defineProperty(target, descriptor.key, descriptor);
463                 }
464         }
465
466         function _createClass(Constructor, protoProps, staticProps) {
467                 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
468                 if (staticProps) _defineProperties(Constructor, staticProps);
469                 return Constructor;
470         }
471
472         function _inheritsLoose(subClass, superClass) {
473                 subClass.prototype = Object.create(superClass.prototype);
474                 subClass.prototype.constructor = subClass;
475                 subClass.__proto__ = superClass;
476         }
477
478         function _assertThisInitialized(self) {
479                 if (self === void 0) {
480                         throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
481                 }
482
483                 return self;
484         }
485
486         var Vector2 = /*#__PURE__*/function () {
487                 function Vector2(x, y) {
488                         if (x === void 0) {
489                                 x = 0;
490                         }
491
492                         if (y === void 0) {
493                                 y = 0;
494                         }
495
496                         Object.defineProperty(this, 'isVector2', {
497                                 value: true
498                         });
499                         this.x = x;
500                         this.y = y;
501                 }
502
503                 var _proto = Vector2.prototype;
504
505                 _proto.set = function set(x, y) {
506                         this.x = x;
507                         this.y = y;
508                         return this;
509                 };
510
511                 _proto.setScalar = function setScalar(scalar) {
512                         this.x = scalar;
513                         this.y = scalar;
514                         return this;
515                 };
516
517                 _proto.setX = function setX(x) {
518                         this.x = x;
519                         return this;
520                 };
521
522                 _proto.setY = function setY(y) {
523                         this.y = y;
524                         return this;
525                 };
526
527                 _proto.setComponent = function setComponent(index, value) {
528                         switch (index) {
529                                 case 0:
530                                         this.x = value;
531                                         break;
532
533                                 case 1:
534                                         this.y = value;
535                                         break;
536
537                                 default:
538                                         throw new Error('index is out of range: ' + index);
539                         }
540
541                         return this;
542                 };
543
544                 _proto.getComponent = function getComponent(index) {
545                         switch (index) {
546                                 case 0:
547                                         return this.x;
548
549                                 case 1:
550                                         return this.y;
551
552                                 default:
553                                         throw new Error('index is out of range: ' + index);
554                         }
555                 };
556
557                 _proto.clone = function clone() {
558                         return new this.constructor(this.x, this.y);
559                 };
560
561                 _proto.copy = function copy(v) {
562                         this.x = v.x;
563                         this.y = v.y;
564                         return this;
565                 };
566
567                 _proto.add = function add(v, w) {
568                         if (w !== undefined) {
569                                 console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
570                                 return this.addVectors(v, w);
571                         }
572
573                         this.x += v.x;
574                         this.y += v.y;
575                         return this;
576                 };
577
578                 _proto.addScalar = function addScalar(s) {
579                         this.x += s;
580                         this.y += s;
581                         return this;
582                 };
583
584                 _proto.addVectors = function addVectors(a, b) {
585                         this.x = a.x + b.x;
586                         this.y = a.y + b.y;
587                         return this;
588                 };
589
590                 _proto.addScaledVector = function addScaledVector(v, s) {
591                         this.x += v.x * s;
592                         this.y += v.y * s;
593                         return this;
594                 };
595
596                 _proto.sub = function sub(v, w) {
597                         if (w !== undefined) {
598                                 console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
599                                 return this.subVectors(v, w);
600                         }
601
602                         this.x -= v.x;
603                         this.y -= v.y;
604                         return this;
605                 };
606
607                 _proto.subScalar = function subScalar(s) {
608                         this.x -= s;
609                         this.y -= s;
610                         return this;
611                 };
612
613                 _proto.subVectors = function subVectors(a, b) {
614                         this.x = a.x - b.x;
615                         this.y = a.y - b.y;
616                         return this;
617                 };
618
619                 _proto.multiply = function multiply(v) {
620                         this.x *= v.x;
621                         this.y *= v.y;
622                         return this;
623                 };
624
625                 _proto.multiplyScalar = function multiplyScalar(scalar) {
626                         this.x *= scalar;
627                         this.y *= scalar;
628                         return this;
629                 };
630
631                 _proto.divide = function divide(v) {
632                         this.x /= v.x;
633                         this.y /= v.y;
634                         return this;
635                 };
636
637                 _proto.divideScalar = function divideScalar(scalar) {
638                         return this.multiplyScalar(1 / scalar);
639                 };
640
641                 _proto.applyMatrix3 = function applyMatrix3(m) {
642                         var x = this.x,
643                                         y = this.y;
644                         var e = m.elements;
645                         this.x = e[0] * x + e[3] * y + e[6];
646                         this.y = e[1] * x + e[4] * y + e[7];
647                         return this;
648                 };
649
650                 _proto.min = function min(v) {
651                         this.x = Math.min(this.x, v.x);
652                         this.y = Math.min(this.y, v.y);
653                         return this;
654                 };
655
656                 _proto.max = function max(v) {
657                         this.x = Math.max(this.x, v.x);
658                         this.y = Math.max(this.y, v.y);
659                         return this;
660                 };
661
662                 _proto.clamp = function clamp(min, max) {
663                         // assumes min < max, componentwise
664                         this.x = Math.max(min.x, Math.min(max.x, this.x));
665                         this.y = Math.max(min.y, Math.min(max.y, this.y));
666                         return this;
667                 };
668
669                 _proto.clampScalar = function clampScalar(minVal, maxVal) {
670                         this.x = Math.max(minVal, Math.min(maxVal, this.x));
671                         this.y = Math.max(minVal, Math.min(maxVal, this.y));
672                         return this;
673                 };
674
675                 _proto.clampLength = function clampLength(min, max) {
676                         var length = this.length();
677                         return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
678                 };
679
680                 _proto.floor = function floor() {
681                         this.x = Math.floor(this.x);
682                         this.y = Math.floor(this.y);
683                         return this;
684                 };
685
686                 _proto.ceil = function ceil() {
687                         this.x = Math.ceil(this.x);
688                         this.y = Math.ceil(this.y);
689                         return this;
690                 };
691
692                 _proto.round = function round() {
693                         this.x = Math.round(this.x);
694                         this.y = Math.round(this.y);
695                         return this;
696                 };
697
698                 _proto.roundToZero = function roundToZero() {
699                         this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
700                         this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
701                         return this;
702                 };
703
704                 _proto.negate = function negate() {
705                         this.x = -this.x;
706                         this.y = -this.y;
707                         return this;
708                 };
709
710                 _proto.dot = function dot(v) {
711                         return this.x * v.x + this.y * v.y;
712                 };
713
714                 _proto.cross = function cross(v) {
715                         return this.x * v.y - this.y * v.x;
716                 };
717
718                 _proto.lengthSq = function lengthSq() {
719                         return this.x * this.x + this.y * this.y;
720                 };
721
722                 _proto.length = function length() {
723                         return Math.sqrt(this.x * this.x + this.y * this.y);
724                 };
725
726                 _proto.manhattanLength = function manhattanLength() {
727                         return Math.abs(this.x) + Math.abs(this.y);
728                 };
729
730                 _proto.normalize = function normalize() {
731                         return this.divideScalar(this.length() || 1);
732                 };
733
734                 _proto.angle = function angle() {
735                         // computes the angle in radians with respect to the positive x-axis
736                         var angle = Math.atan2(-this.y, -this.x) + Math.PI;
737                         return angle;
738                 };
739
740                 _proto.distanceTo = function distanceTo(v) {
741                         return Math.sqrt(this.distanceToSquared(v));
742                 };
743
744                 _proto.distanceToSquared = function distanceToSquared(v) {
745                         var dx = this.x - v.x,
746                                         dy = this.y - v.y;
747                         return dx * dx + dy * dy;
748                 };
749
750                 _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
751                         return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
752                 };
753
754                 _proto.setLength = function setLength(length) {
755                         return this.normalize().multiplyScalar(length);
756                 };
757
758                 _proto.lerp = function lerp(v, alpha) {
759                         this.x += (v.x - this.x) * alpha;
760                         this.y += (v.y - this.y) * alpha;
761                         return this;
762                 };
763
764                 _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
765                         this.x = v1.x + (v2.x - v1.x) * alpha;
766                         this.y = v1.y + (v2.y - v1.y) * alpha;
767                         return this;
768                 };
769
770                 _proto.equals = function equals(v) {
771                         return v.x === this.x && v.y === this.y;
772                 };
773
774                 _proto.fromArray = function fromArray(array, offset) {
775                         if (offset === void 0) {
776                                 offset = 0;
777                         }
778
779                         this.x = array[offset];
780                         this.y = array[offset + 1];
781                         return this;
782                 };
783
784                 _proto.toArray = function toArray(array, offset) {
785                         if (array === void 0) {
786                                 array = [];
787                         }
788
789                         if (offset === void 0) {
790                                 offset = 0;
791                         }
792
793                         array[offset] = this.x;
794                         array[offset + 1] = this.y;
795                         return array;
796                 };
797
798                 _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
799                         if (offset !== undefined) {
800                                 console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
801                         }
802
803                         this.x = attribute.getX(index);
804                         this.y = attribute.getY(index);
805                         return this;
806                 };
807
808                 _proto.rotateAround = function rotateAround(center, angle) {
809                         var c = Math.cos(angle),
810                                         s = Math.sin(angle);
811                         var x = this.x - center.x;
812                         var y = this.y - center.y;
813                         this.x = x * c - y * s + center.x;
814                         this.y = x * s + y * c + center.y;
815                         return this;
816                 };
817
818                 _proto.random = function random() {
819                         this.x = Math.random();
820                         this.y = Math.random();
821                         return this;
822                 };
823
824                 _createClass(Vector2, [{
825                         key: "width",
826                         get: function get() {
827                                 return this.x;
828                         },
829                         set: function set(value) {
830                                 this.x = value;
831                         }
832                 }, {
833                         key: "height",
834                         get: function get() {
835                                 return this.y;
836                         },
837                         set: function set(value) {
838                                 this.y = value;
839                         }
840                 }]);
841
842                 return Vector2;
843         }();
844
845         var Matrix3 = /*#__PURE__*/function () {
846                 function Matrix3() {
847                         Object.defineProperty(this, 'isMatrix3', {
848                                 value: true
849                         });
850                         this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
851
852                         if (arguments.length > 0) {
853                                 console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
854                         }
855                 }
856
857                 var _proto = Matrix3.prototype;
858
859                 _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
860                         var te = this.elements;
861                         te[0] = n11;
862                         te[1] = n21;
863                         te[2] = n31;
864                         te[3] = n12;
865                         te[4] = n22;
866                         te[5] = n32;
867                         te[6] = n13;
868                         te[7] = n23;
869                         te[8] = n33;
870                         return this;
871                 };
872
873                 _proto.identity = function identity() {
874                         this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
875                         return this;
876                 };
877
878                 _proto.clone = function clone() {
879                         return new this.constructor().fromArray(this.elements);
880                 };
881
882                 _proto.copy = function copy(m) {
883                         var te = this.elements;
884                         var me = m.elements;
885                         te[0] = me[0];
886                         te[1] = me[1];
887                         te[2] = me[2];
888                         te[3] = me[3];
889                         te[4] = me[4];
890                         te[5] = me[5];
891                         te[6] = me[6];
892                         te[7] = me[7];
893                         te[8] = me[8];
894                         return this;
895                 };
896
897                 _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
898                         xAxis.setFromMatrix3Column(this, 0);
899                         yAxis.setFromMatrix3Column(this, 1);
900                         zAxis.setFromMatrix3Column(this, 2);
901                         return this;
902                 };
903
904                 _proto.setFromMatrix4 = function setFromMatrix4(m) {
905                         var me = m.elements;
906                         this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
907                         return this;
908                 };
909
910                 _proto.multiply = function multiply(m) {
911                         return this.multiplyMatrices(this, m);
912                 };
913
914                 _proto.premultiply = function premultiply(m) {
915                         return this.multiplyMatrices(m, this);
916                 };
917
918                 _proto.multiplyMatrices = function multiplyMatrices(a, b) {
919                         var ae = a.elements;
920                         var be = b.elements;
921                         var te = this.elements;
922                         var a11 = ae[0],
923                                         a12 = ae[3],
924                                         a13 = ae[6];
925                         var a21 = ae[1],
926                                         a22 = ae[4],
927                                         a23 = ae[7];
928                         var a31 = ae[2],
929                                         a32 = ae[5],
930                                         a33 = ae[8];
931                         var b11 = be[0],
932                                         b12 = be[3],
933                                         b13 = be[6];
934                         var b21 = be[1],
935                                         b22 = be[4],
936                                         b23 = be[7];
937                         var b31 = be[2],
938                                         b32 = be[5],
939                                         b33 = be[8];
940                         te[0] = a11 * b11 + a12 * b21 + a13 * b31;
941                         te[3] = a11 * b12 + a12 * b22 + a13 * b32;
942                         te[6] = a11 * b13 + a12 * b23 + a13 * b33;
943                         te[1] = a21 * b11 + a22 * b21 + a23 * b31;
944                         te[4] = a21 * b12 + a22 * b22 + a23 * b32;
945                         te[7] = a21 * b13 + a22 * b23 + a23 * b33;
946                         te[2] = a31 * b11 + a32 * b21 + a33 * b31;
947                         te[5] = a31 * b12 + a32 * b22 + a33 * b32;
948                         te[8] = a31 * b13 + a32 * b23 + a33 * b33;
949                         return this;
950                 };
951
952                 _proto.multiplyScalar = function multiplyScalar(s) {
953                         var te = this.elements;
954                         te[0] *= s;
955                         te[3] *= s;
956                         te[6] *= s;
957                         te[1] *= s;
958                         te[4] *= s;
959                         te[7] *= s;
960                         te[2] *= s;
961                         te[5] *= s;
962                         te[8] *= s;
963                         return this;
964                 };
965
966                 _proto.determinant = function determinant() {
967                         var te = this.elements;
968                         var a = te[0],
969                                         b = te[1],
970                                         c = te[2],
971                                         d = te[3],
972                                         e = te[4],
973                                         f = te[5],
974                                         g = te[6],
975                                         h = te[7],
976                                         i = te[8];
977                         return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
978                 };
979
980                 _proto.invert = function invert() {
981                         var te = this.elements,
982                                         n11 = te[0],
983                                         n21 = te[1],
984                                         n31 = te[2],
985                                         n12 = te[3],
986                                         n22 = te[4],
987                                         n32 = te[5],
988                                         n13 = te[6],
989                                         n23 = te[7],
990                                         n33 = te[8],
991                                         t11 = n33 * n22 - n32 * n23,
992                                         t12 = n32 * n13 - n33 * n12,
993                                         t13 = n23 * n12 - n22 * n13,
994                                         det = n11 * t11 + n21 * t12 + n31 * t13;
995                         if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
996                         var detInv = 1 / det;
997                         te[0] = t11 * detInv;
998                         te[1] = (n31 * n23 - n33 * n21) * detInv;
999                         te[2] = (n32 * n21 - n31 * n22) * detInv;
1000                         te[3] = t12 * detInv;
1001                         te[4] = (n33 * n11 - n31 * n13) * detInv;
1002                         te[5] = (n31 * n12 - n32 * n11) * detInv;
1003                         te[6] = t13 * detInv;
1004                         te[7] = (n21 * n13 - n23 * n11) * detInv;
1005                         te[8] = (n22 * n11 - n21 * n12) * detInv;
1006                         return this;
1007                 };
1008
1009                 _proto.transpose = function transpose() {
1010                         var tmp;
1011                         var m = this.elements;
1012                         tmp = m[1];
1013                         m[1] = m[3];
1014                         m[3] = tmp;
1015                         tmp = m[2];
1016                         m[2] = m[6];
1017                         m[6] = tmp;
1018                         tmp = m[5];
1019                         m[5] = m[7];
1020                         m[7] = tmp;
1021                         return this;
1022                 };
1023
1024                 _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
1025                         return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
1026                 };
1027
1028                 _proto.transposeIntoArray = function transposeIntoArray(r) {
1029                         var m = this.elements;
1030                         r[0] = m[0];
1031                         r[1] = m[3];
1032                         r[2] = m[6];
1033                         r[3] = m[1];
1034                         r[4] = m[4];
1035                         r[5] = m[7];
1036                         r[6] = m[2];
1037                         r[7] = m[5];
1038                         r[8] = m[8];
1039                         return this;
1040                 };
1041
1042                 _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
1043                         var c = Math.cos(rotation);
1044                         var s = Math.sin(rotation);
1045                         this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
1046                 };
1047
1048                 _proto.scale = function scale(sx, sy) {
1049                         var te = this.elements;
1050                         te[0] *= sx;
1051                         te[3] *= sx;
1052                         te[6] *= sx;
1053                         te[1] *= sy;
1054                         te[4] *= sy;
1055                         te[7] *= sy;
1056                         return this;
1057                 };
1058
1059                 _proto.rotate = function rotate(theta) {
1060                         var c = Math.cos(theta);
1061                         var s = Math.sin(theta);
1062                         var te = this.elements;
1063                         var a11 = te[0],
1064                                         a12 = te[3],
1065                                         a13 = te[6];
1066                         var a21 = te[1],
1067                                         a22 = te[4],
1068                                         a23 = te[7];
1069                         te[0] = c * a11 + s * a21;
1070                         te[3] = c * a12 + s * a22;
1071                         te[6] = c * a13 + s * a23;
1072                         te[1] = -s * a11 + c * a21;
1073                         te[4] = -s * a12 + c * a22;
1074                         te[7] = -s * a13 + c * a23;
1075                         return this;
1076                 };
1077
1078                 _proto.translate = function translate(tx, ty) {
1079                         var te = this.elements;
1080                         te[0] += tx * te[2];
1081                         te[3] += tx * te[5];
1082                         te[6] += tx * te[8];
1083                         te[1] += ty * te[2];
1084                         te[4] += ty * te[5];
1085                         te[7] += ty * te[8];
1086                         return this;
1087                 };
1088
1089                 _proto.equals = function equals(matrix) {
1090                         var te = this.elements;
1091                         var me = matrix.elements;
1092
1093                         for (var i = 0; i < 9; i++) {
1094                                 if (te[i] !== me[i]) return false;
1095                         }
1096
1097                         return true;
1098                 };
1099
1100                 _proto.fromArray = function fromArray(array, offset) {
1101                         if (offset === void 0) {
1102                                 offset = 0;
1103                         }
1104
1105                         for (var i = 0; i < 9; i++) {
1106                                 this.elements[i] = array[i + offset];
1107                         }
1108
1109                         return this;
1110                 };
1111
1112                 _proto.toArray = function toArray(array, offset) {
1113                         if (array === void 0) {
1114                                 array = [];
1115                         }
1116
1117                         if (offset === void 0) {
1118                                 offset = 0;
1119                         }
1120
1121                         var te = this.elements;
1122                         array[offset] = te[0];
1123                         array[offset + 1] = te[1];
1124                         array[offset + 2] = te[2];
1125                         array[offset + 3] = te[3];
1126                         array[offset + 4] = te[4];
1127                         array[offset + 5] = te[5];
1128                         array[offset + 6] = te[6];
1129                         array[offset + 7] = te[7];
1130                         array[offset + 8] = te[8];
1131                         return array;
1132                 };
1133
1134                 return Matrix3;
1135         }();
1136
1137         var _canvas;
1138
1139         var ImageUtils = {
1140                 getDataURL: function getDataURL(image) {
1141                         if (/^data:/i.test(image.src)) {
1142                                 return image.src;
1143                         }
1144
1145                         if (typeof HTMLCanvasElement == 'undefined') {
1146                                 return image.src;
1147                         }
1148
1149                         var canvas;
1150
1151                         if (image instanceof HTMLCanvasElement) {
1152                                 canvas = image;
1153                         } else {
1154                                 if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
1155                                 _canvas.width = image.width;
1156                                 _canvas.height = image.height;
1157
1158                                 var context = _canvas.getContext('2d');
1159
1160                                 if (image instanceof ImageData) {
1161                                         context.putImageData(image, 0, 0);
1162                                 } else {
1163                                         context.drawImage(image, 0, 0, image.width, image.height);
1164                                 }
1165
1166                                 canvas = _canvas;
1167                         }
1168
1169                         if (canvas.width > 2048 || canvas.height > 2048) {
1170                                 return canvas.toDataURL('image/jpeg', 0.6);
1171                         } else {
1172                                 return canvas.toDataURL('image/png');
1173                         }
1174                 }
1175         };
1176
1177         var textureId = 0;
1178
1179         function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
1180                 if (image === void 0) {
1181                         image = Texture.DEFAULT_IMAGE;
1182                 }
1183
1184                 if (mapping === void 0) {
1185                         mapping = Texture.DEFAULT_MAPPING;
1186                 }
1187
1188                 if (wrapS === void 0) {
1189                         wrapS = ClampToEdgeWrapping;
1190                 }
1191
1192                 if (wrapT === void 0) {
1193                         wrapT = ClampToEdgeWrapping;
1194                 }
1195
1196                 if (magFilter === void 0) {
1197                         magFilter = LinearFilter;
1198                 }
1199
1200                 if (minFilter === void 0) {
1201                         minFilter = LinearMipmapLinearFilter;
1202                 }
1203
1204                 if (format === void 0) {
1205                         format = RGBAFormat;
1206                 }
1207
1208                 if (type === void 0) {
1209                         type = UnsignedByteType;
1210                 }
1211
1212                 if (anisotropy === void 0) {
1213                         anisotropy = 1;
1214                 }
1215
1216                 if (encoding === void 0) {
1217                         encoding = LinearEncoding;
1218                 }
1219
1220                 Object.defineProperty(this, 'id', {
1221                         value: textureId++
1222                 });
1223                 this.uuid = MathUtils.generateUUID();
1224                 this.name = '';
1225                 this.image = image;
1226                 this.mipmaps = [];
1227                 this.mapping = mapping;
1228                 this.wrapS = wrapS;
1229                 this.wrapT = wrapT;
1230                 this.magFilter = magFilter;
1231                 this.minFilter = minFilter;
1232                 this.anisotropy = anisotropy;
1233                 this.format = format;
1234                 this.internalFormat = null;
1235                 this.type = type;
1236                 this.offset = new Vector2(0, 0);
1237                 this.repeat = new Vector2(1, 1);
1238                 this.center = new Vector2(0, 0);
1239                 this.rotation = 0;
1240                 this.matrixAutoUpdate = true;
1241                 this.matrix = new Matrix3();
1242                 this.generateMipmaps = true;
1243                 this.premultiplyAlpha = false;
1244                 this.flipY = true;
1245                 this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
1246                 // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
1247                 //
1248                 // Also changing the encoding after already used by a Material will not automatically make the Material
1249                 // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
1250
1251                 this.encoding = encoding;
1252                 this.version = 0;
1253                 this.onUpdate = null;
1254         }
1255
1256         Texture.DEFAULT_IMAGE = undefined;
1257         Texture.DEFAULT_MAPPING = UVMapping;
1258         Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
1259                 constructor: Texture,
1260                 isTexture: true,
1261                 updateMatrix: function updateMatrix() {
1262                         this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
1263                 },
1264                 clone: function clone() {
1265                         return new this.constructor().copy(this);
1266                 },
1267                 copy: function copy(source) {
1268                         this.name = source.name;
1269                         this.image = source.image;
1270                         this.mipmaps = source.mipmaps.slice(0);
1271                         this.mapping = source.mapping;
1272                         this.wrapS = source.wrapS;
1273                         this.wrapT = source.wrapT;
1274                         this.magFilter = source.magFilter;
1275                         this.minFilter = source.minFilter;
1276                         this.anisotropy = source.anisotropy;
1277                         this.format = source.format;
1278                         this.internalFormat = source.internalFormat;
1279                         this.type = source.type;
1280                         this.offset.copy(source.offset);
1281                         this.repeat.copy(source.repeat);
1282                         this.center.copy(source.center);
1283                         this.rotation = source.rotation;
1284                         this.matrixAutoUpdate = source.matrixAutoUpdate;
1285                         this.matrix.copy(source.matrix);
1286                         this.generateMipmaps = source.generateMipmaps;
1287                         this.premultiplyAlpha = source.premultiplyAlpha;
1288                         this.flipY = source.flipY;
1289                         this.unpackAlignment = source.unpackAlignment;
1290                         this.encoding = source.encoding;
1291                         return this;
1292                 },
1293                 toJSON: function toJSON(meta) {
1294                         var isRootObject = meta === undefined || typeof meta === 'string';
1295
1296                         if (!isRootObject && meta.textures[this.uuid] !== undefined) {
1297                                 return meta.textures[this.uuid];
1298                         }
1299
1300                         var output = {
1301                                 metadata: {
1302                                         version: 4.5,
1303                                         type: 'Texture',
1304                                         generator: 'Texture.toJSON'
1305                                 },
1306                                 uuid: this.uuid,
1307                                 name: this.name,
1308                                 mapping: this.mapping,
1309                                 repeat: [this.repeat.x, this.repeat.y],
1310                                 offset: [this.offset.x, this.offset.y],
1311                                 center: [this.center.x, this.center.y],
1312                                 rotation: this.rotation,
1313                                 wrap: [this.wrapS, this.wrapT],
1314                                 format: this.format,
1315                                 type: this.type,
1316                                 encoding: this.encoding,
1317                                 minFilter: this.minFilter,
1318                                 magFilter: this.magFilter,
1319                                 anisotropy: this.anisotropy,
1320                                 flipY: this.flipY,
1321                                 premultiplyAlpha: this.premultiplyAlpha,
1322                                 unpackAlignment: this.unpackAlignment
1323                         };
1324
1325                         if (this.image !== undefined) {
1326                                 // TODO: Move to THREE.Image
1327                                 var image = this.image;
1328
1329                                 if (image.uuid === undefined) {
1330                                         image.uuid = MathUtils.generateUUID(); // UGH
1331                                 }
1332
1333                                 if (!isRootObject && meta.images[image.uuid] === undefined) {
1334                                         var url;
1335
1336                                         if (Array.isArray(image)) {
1337                                                 // process array of images e.g. CubeTexture
1338                                                 url = [];
1339
1340                                                 for (var i = 0, l = image.length; i < l; i++) {
1341                                                         // check cube texture with data textures
1342                                                         if (image[i].isDataTexture) {
1343                                                                 url.push(serializeImage(image[i].image));
1344                                                         } else {
1345                                                                 url.push(serializeImage(image[i]));
1346                                                         }
1347                                                 }
1348                                         } else {
1349                                                 // process single image
1350                                                 url = serializeImage(image);
1351                                         }
1352
1353                                         meta.images[image.uuid] = {
1354                                                 uuid: image.uuid,
1355                                                 url: url
1356                                         };
1357                                 }
1358
1359                                 output.image = image.uuid;
1360                         }
1361
1362                         if (!isRootObject) {
1363                                 meta.textures[this.uuid] = output;
1364                         }
1365
1366                         return output;
1367                 },
1368                 dispose: function dispose() {
1369                         this.dispatchEvent({
1370                                 type: 'dispose'
1371                         });
1372                 },
1373                 transformUv: function transformUv(uv) {
1374                         if (this.mapping !== UVMapping) return uv;
1375                         uv.applyMatrix3(this.matrix);
1376
1377                         if (uv.x < 0 || uv.x > 1) {
1378                                 switch (this.wrapS) {
1379                                         case RepeatWrapping:
1380                                                 uv.x = uv.x - Math.floor(uv.x);
1381                                                 break;
1382
1383                                         case ClampToEdgeWrapping:
1384                                                 uv.x = uv.x < 0 ? 0 : 1;
1385                                                 break;
1386
1387                                         case MirroredRepeatWrapping:
1388                                                 if (Math.abs(Math.floor(uv.x) % 2) === 1) {
1389                                                         uv.x = Math.ceil(uv.x) - uv.x;
1390                                                 } else {
1391                                                         uv.x = uv.x - Math.floor(uv.x);
1392                                                 }
1393
1394                                                 break;
1395                                 }
1396                         }
1397
1398                         if (uv.y < 0 || uv.y > 1) {
1399                                 switch (this.wrapT) {
1400                                         case RepeatWrapping:
1401                                                 uv.y = uv.y - Math.floor(uv.y);
1402                                                 break;
1403
1404                                         case ClampToEdgeWrapping:
1405                                                 uv.y = uv.y < 0 ? 0 : 1;
1406                                                 break;
1407
1408                                         case MirroredRepeatWrapping:
1409                                                 if (Math.abs(Math.floor(uv.y) % 2) === 1) {
1410                                                         uv.y = Math.ceil(uv.y) - uv.y;
1411                                                 } else {
1412                                                         uv.y = uv.y - Math.floor(uv.y);
1413                                                 }
1414
1415                                                 break;
1416                                 }
1417                         }
1418
1419                         if (this.flipY) {
1420                                 uv.y = 1 - uv.y;
1421                         }
1422
1423                         return uv;
1424                 }
1425         });
1426         Object.defineProperty(Texture.prototype, "needsUpdate", {
1427                 set: function set(value) {
1428                         if (value === true) this.version++;
1429                 }
1430         });
1431
1432         function serializeImage(image) {
1433                 if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
1434                         // default images
1435                         return ImageUtils.getDataURL(image);
1436                 } else {
1437                         if (image.data) {
1438                                 // images of DataTexture
1439                                 return {
1440                                         data: Array.prototype.slice.call(image.data),
1441                                         width: image.width,
1442                                         height: image.height,
1443                                         type: image.data.constructor.name
1444                                 };
1445                         } else {
1446                                 console.warn('THREE.Texture: Unable to serialize Texture.');
1447                                 return {};
1448                         }
1449                 }
1450         }
1451
1452         var Vector4 = /*#__PURE__*/function () {
1453                 function Vector4(x, y, z, w) {
1454                         if (x === void 0) {
1455                                 x = 0;
1456                         }
1457
1458                         if (y === void 0) {
1459                                 y = 0;
1460                         }
1461
1462                         if (z === void 0) {
1463                                 z = 0;
1464                         }
1465
1466                         if (w === void 0) {
1467                                 w = 1;
1468                         }
1469
1470                         Object.defineProperty(this, 'isVector4', {
1471                                 value: true
1472                         });
1473                         this.x = x;
1474                         this.y = y;
1475                         this.z = z;
1476                         this.w = w;
1477                 }
1478
1479                 var _proto = Vector4.prototype;
1480
1481                 _proto.set = function set(x, y, z, w) {
1482                         this.x = x;
1483                         this.y = y;
1484                         this.z = z;
1485                         this.w = w;
1486                         return this;
1487                 };
1488
1489                 _proto.setScalar = function setScalar(scalar) {
1490                         this.x = scalar;
1491                         this.y = scalar;
1492                         this.z = scalar;
1493                         this.w = scalar;
1494                         return this;
1495                 };
1496
1497                 _proto.setX = function setX(x) {
1498                         this.x = x;
1499                         return this;
1500                 };
1501
1502                 _proto.setY = function setY(y) {
1503                         this.y = y;
1504                         return this;
1505                 };
1506
1507                 _proto.setZ = function setZ(z) {
1508                         this.z = z;
1509                         return this;
1510                 };
1511
1512                 _proto.setW = function setW(w) {
1513                         this.w = w;
1514                         return this;
1515                 };
1516
1517                 _proto.setComponent = function setComponent(index, value) {
1518                         switch (index) {
1519                                 case 0:
1520                                         this.x = value;
1521                                         break;
1522
1523                                 case 1:
1524                                         this.y = value;
1525                                         break;
1526
1527                                 case 2:
1528                                         this.z = value;
1529                                         break;
1530
1531                                 case 3:
1532                                         this.w = value;
1533                                         break;
1534
1535                                 default:
1536                                         throw new Error('index is out of range: ' + index);
1537                         }
1538
1539                         return this;
1540                 };
1541
1542                 _proto.getComponent = function getComponent(index) {
1543                         switch (index) {
1544                                 case 0:
1545                                         return this.x;
1546
1547                                 case 1:
1548                                         return this.y;
1549
1550                                 case 2:
1551                                         return this.z;
1552
1553                                 case 3:
1554                                         return this.w;
1555
1556                                 default:
1557                                         throw new Error('index is out of range: ' + index);
1558                         }
1559                 };
1560
1561                 _proto.clone = function clone() {
1562                         return new this.constructor(this.x, this.y, this.z, this.w);
1563                 };
1564
1565                 _proto.copy = function copy(v) {
1566                         this.x = v.x;
1567                         this.y = v.y;
1568                         this.z = v.z;
1569                         this.w = v.w !== undefined ? v.w : 1;
1570                         return this;
1571                 };
1572
1573                 _proto.add = function add(v, w) {
1574                         if (w !== undefined) {
1575                                 console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
1576                                 return this.addVectors(v, w);
1577                         }
1578
1579                         this.x += v.x;
1580                         this.y += v.y;
1581                         this.z += v.z;
1582                         this.w += v.w;
1583                         return this;
1584                 };
1585
1586                 _proto.addScalar = function addScalar(s) {
1587                         this.x += s;
1588                         this.y += s;
1589                         this.z += s;
1590                         this.w += s;
1591                         return this;
1592                 };
1593
1594                 _proto.addVectors = function addVectors(a, b) {
1595                         this.x = a.x + b.x;
1596                         this.y = a.y + b.y;
1597                         this.z = a.z + b.z;
1598                         this.w = a.w + b.w;
1599                         return this;
1600                 };
1601
1602                 _proto.addScaledVector = function addScaledVector(v, s) {
1603                         this.x += v.x * s;
1604                         this.y += v.y * s;
1605                         this.z += v.z * s;
1606                         this.w += v.w * s;
1607                         return this;
1608                 };
1609
1610                 _proto.sub = function sub(v, w) {
1611                         if (w !== undefined) {
1612                                 console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
1613                                 return this.subVectors(v, w);
1614                         }
1615
1616                         this.x -= v.x;
1617                         this.y -= v.y;
1618                         this.z -= v.z;
1619                         this.w -= v.w;
1620                         return this;
1621                 };
1622
1623                 _proto.subScalar = function subScalar(s) {
1624                         this.x -= s;
1625                         this.y -= s;
1626                         this.z -= s;
1627                         this.w -= s;
1628                         return this;
1629                 };
1630
1631                 _proto.subVectors = function subVectors(a, b) {
1632                         this.x = a.x - b.x;
1633                         this.y = a.y - b.y;
1634                         this.z = a.z - b.z;
1635                         this.w = a.w - b.w;
1636                         return this;
1637                 };
1638
1639                 _proto.multiplyScalar = function multiplyScalar(scalar) {
1640                         this.x *= scalar;
1641                         this.y *= scalar;
1642                         this.z *= scalar;
1643                         this.w *= scalar;
1644                         return this;
1645                 };
1646
1647                 _proto.applyMatrix4 = function applyMatrix4(m) {
1648                         var x = this.x,
1649                                         y = this.y,
1650                                         z = this.z,
1651                                         w = this.w;
1652                         var e = m.elements;
1653                         this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
1654                         this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
1655                         this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
1656                         this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
1657                         return this;
1658                 };
1659
1660                 _proto.divideScalar = function divideScalar(scalar) {
1661                         return this.multiplyScalar(1 / scalar);
1662                 };
1663
1664                 _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
1665                         // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
1666                         // q is assumed to be normalized
1667                         this.w = 2 * Math.acos(q.w);
1668                         var s = Math.sqrt(1 - q.w * q.w);
1669
1670                         if (s < 0.0001) {
1671                                 this.x = 1;
1672                                 this.y = 0;
1673                                 this.z = 0;
1674                         } else {
1675                                 this.x = q.x / s;
1676                                 this.y = q.y / s;
1677                                 this.z = q.z / s;
1678                         }
1679
1680                         return this;
1681                 };
1682
1683                 _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
1684                         // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
1685                         // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
1686                         var angle, x, y, z; // variables for result
1687
1688                         var epsilon = 0.01,
1689                                         // margin to allow for rounding errors
1690                         epsilon2 = 0.1,
1691                                         // margin to distinguish between 0 and 180 degrees
1692                         te = m.elements,
1693                                         m11 = te[0],
1694                                         m12 = te[4],
1695                                         m13 = te[8],
1696                                         m21 = te[1],
1697                                         m22 = te[5],
1698                                         m23 = te[9],
1699                                         m31 = te[2],
1700                                         m32 = te[6],
1701                                         m33 = te[10];
1702
1703                         if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
1704                                 // singularity found
1705                                 // first check for identity matrix which must have +1 for all terms
1706                                 // in leading diagonal and zero in other terms
1707                                 if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
1708                                         // this singularity is identity matrix so angle = 0
1709                                         this.set(1, 0, 0, 0);
1710                                         return this; // zero angle, arbitrary axis
1711                                 } // otherwise this singularity is angle = 180
1712
1713
1714                                 angle = Math.PI;
1715                                 var xx = (m11 + 1) / 2;
1716                                 var yy = (m22 + 1) / 2;
1717                                 var zz = (m33 + 1) / 2;
1718                                 var xy = (m12 + m21) / 4;
1719                                 var xz = (m13 + m31) / 4;
1720                                 var yz = (m23 + m32) / 4;
1721
1722                                 if (xx > yy && xx > zz) {
1723                                         // m11 is the largest diagonal term
1724                                         if (xx < epsilon) {
1725                                                 x = 0;
1726                                                 y = 0.707106781;
1727                                                 z = 0.707106781;
1728                                         } else {
1729                                                 x = Math.sqrt(xx);
1730                                                 y = xy / x;
1731                                                 z = xz / x;
1732                                         }
1733                                 } else if (yy > zz) {
1734                                         // m22 is the largest diagonal term
1735                                         if (yy < epsilon) {
1736                                                 x = 0.707106781;
1737                                                 y = 0;
1738                                                 z = 0.707106781;
1739                                         } else {
1740                                                 y = Math.sqrt(yy);
1741                                                 x = xy / y;
1742                                                 z = yz / y;
1743                                         }
1744                                 } else {
1745                                         // m33 is the largest diagonal term so base result on this
1746                                         if (zz < epsilon) {
1747                                                 x = 0.707106781;
1748                                                 y = 0.707106781;
1749                                                 z = 0;
1750                                         } else {
1751                                                 z = Math.sqrt(zz);
1752                                                 x = xz / z;
1753                                                 y = yz / z;
1754                                         }
1755                                 }
1756
1757                                 this.set(x, y, z, angle);
1758                                 return this; // return 180 deg rotation
1759                         } // as we have reached here there are no singularities so we can handle normally
1760
1761
1762                         var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
1763
1764                         if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
1765                         // caught by singularity test above, but I've left it in just in case
1766
1767                         this.x = (m32 - m23) / s;
1768                         this.y = (m13 - m31) / s;
1769                         this.z = (m21 - m12) / s;
1770                         this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
1771                         return this;
1772                 };
1773
1774                 _proto.min = function min(v) {
1775                         this.x = Math.min(this.x, v.x);
1776                         this.y = Math.min(this.y, v.y);
1777                         this.z = Math.min(this.z, v.z);
1778                         this.w = Math.min(this.w, v.w);
1779                         return this;
1780                 };
1781
1782                 _proto.max = function max(v) {
1783                         this.x = Math.max(this.x, v.x);
1784                         this.y = Math.max(this.y, v.y);
1785                         this.z = Math.max(this.z, v.z);
1786                         this.w = Math.max(this.w, v.w);
1787                         return this;
1788                 };
1789
1790                 _proto.clamp = function clamp(min, max) {
1791                         // assumes min < max, componentwise
1792                         this.x = Math.max(min.x, Math.min(max.x, this.x));
1793                         this.y = Math.max(min.y, Math.min(max.y, this.y));
1794                         this.z = Math.max(min.z, Math.min(max.z, this.z));
1795                         this.w = Math.max(min.w, Math.min(max.w, this.w));
1796                         return this;
1797                 };
1798
1799                 _proto.clampScalar = function clampScalar(minVal, maxVal) {
1800                         this.x = Math.max(minVal, Math.min(maxVal, this.x));
1801                         this.y = Math.max(minVal, Math.min(maxVal, this.y));
1802                         this.z = Math.max(minVal, Math.min(maxVal, this.z));
1803                         this.w = Math.max(minVal, Math.min(maxVal, this.w));
1804                         return this;
1805                 };
1806
1807                 _proto.clampLength = function clampLength(min, max) {
1808                         var length = this.length();
1809                         return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1810                 };
1811
1812                 _proto.floor = function floor() {
1813                         this.x = Math.floor(this.x);
1814                         this.y = Math.floor(this.y);
1815                         this.z = Math.floor(this.z);
1816                         this.w = Math.floor(this.w);
1817                         return this;
1818                 };
1819
1820                 _proto.ceil = function ceil() {
1821                         this.x = Math.ceil(this.x);
1822                         this.y = Math.ceil(this.y);
1823                         this.z = Math.ceil(this.z);
1824                         this.w = Math.ceil(this.w);
1825                         return this;
1826                 };
1827
1828                 _proto.round = function round() {
1829                         this.x = Math.round(this.x);
1830                         this.y = Math.round(this.y);
1831                         this.z = Math.round(this.z);
1832                         this.w = Math.round(this.w);
1833                         return this;
1834                 };
1835
1836                 _proto.roundToZero = function roundToZero() {
1837                         this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
1838                         this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
1839                         this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
1840                         this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
1841                         return this;
1842                 };
1843
1844                 _proto.negate = function negate() {
1845                         this.x = -this.x;
1846                         this.y = -this.y;
1847                         this.z = -this.z;
1848                         this.w = -this.w;
1849                         return this;
1850                 };
1851
1852                 _proto.dot = function dot(v) {
1853                         return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
1854                 };
1855
1856                 _proto.lengthSq = function lengthSq() {
1857                         return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
1858                 };
1859
1860                 _proto.length = function length() {
1861                         return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
1862                 };
1863
1864                 _proto.manhattanLength = function manhattanLength() {
1865                         return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
1866                 };
1867
1868                 _proto.normalize = function normalize() {
1869                         return this.divideScalar(this.length() || 1);
1870                 };
1871
1872                 _proto.setLength = function setLength(length) {
1873                         return this.normalize().multiplyScalar(length);
1874                 };
1875
1876                 _proto.lerp = function lerp(v, alpha) {
1877                         this.x += (v.x - this.x) * alpha;
1878                         this.y += (v.y - this.y) * alpha;
1879                         this.z += (v.z - this.z) * alpha;
1880                         this.w += (v.w - this.w) * alpha;
1881                         return this;
1882                 };
1883
1884                 _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
1885                         this.x = v1.x + (v2.x - v1.x) * alpha;
1886                         this.y = v1.y + (v2.y - v1.y) * alpha;
1887                         this.z = v1.z + (v2.z - v1.z) * alpha;
1888                         this.w = v1.w + (v2.w - v1.w) * alpha;
1889                         return this;
1890                 };
1891
1892                 _proto.equals = function equals(v) {
1893                         return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
1894                 };
1895
1896                 _proto.fromArray = function fromArray(array, offset) {
1897                         if (offset === void 0) {
1898                                 offset = 0;
1899                         }
1900
1901                         this.x = array[offset];
1902                         this.y = array[offset + 1];
1903                         this.z = array[offset + 2];
1904                         this.w = array[offset + 3];
1905                         return this;
1906                 };
1907
1908                 _proto.toArray = function toArray(array, offset) {
1909                         if (array === void 0) {
1910                                 array = [];
1911                         }
1912
1913                         if (offset === void 0) {
1914                                 offset = 0;
1915                         }
1916
1917                         array[offset] = this.x;
1918                         array[offset + 1] = this.y;
1919                         array[offset + 2] = this.z;
1920                         array[offset + 3] = this.w;
1921                         return array;
1922                 };
1923
1924                 _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
1925                         if (offset !== undefined) {
1926                                 console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
1927                         }
1928
1929                         this.x = attribute.getX(index);
1930                         this.y = attribute.getY(index);
1931                         this.z = attribute.getZ(index);
1932                         this.w = attribute.getW(index);
1933                         return this;
1934                 };
1935
1936                 _proto.random = function random() {
1937                         this.x = Math.random();
1938                         this.y = Math.random();
1939                         this.z = Math.random();
1940                         this.w = Math.random();
1941                         return this;
1942                 };
1943
1944                 _createClass(Vector4, [{
1945                         key: "width",
1946                         get: function get() {
1947                                 return this.z;
1948                         },
1949                         set: function set(value) {
1950                                 this.z = value;
1951                         }
1952                 }, {
1953                         key: "height",
1954                         get: function get() {
1955                                 return this.w;
1956                         },
1957                         set: function set(value) {
1958                                 this.w = value;
1959                         }
1960                 }]);
1961
1962                 return Vector4;
1963         }();
1964
1965         /*
1966          In options, we can specify:
1967          * Texture parameters for an auto-generated target texture
1968          * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
1969         */
1970
1971         function WebGLRenderTarget(width, height, options) {
1972                 this.width = width;
1973                 this.height = height;
1974                 this.scissor = new Vector4(0, 0, width, height);
1975                 this.scissorTest = false;
1976                 this.viewport = new Vector4(0, 0, width, height);
1977                 options = options || {};
1978                 this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
1979                 this.texture.image = {};
1980                 this.texture.image.width = width;
1981                 this.texture.image.height = height;
1982                 this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
1983                 this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
1984                 this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
1985                 this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
1986                 this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
1987         }
1988
1989         WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
1990                 constructor: WebGLRenderTarget,
1991                 isWebGLRenderTarget: true,
1992                 setSize: function setSize(width, height) {
1993                         if (this.width !== width || this.height !== height) {
1994                                 this.width = width;
1995                                 this.height = height;
1996                                 this.texture.image.width = width;
1997                                 this.texture.image.height = height;
1998                                 this.dispose();
1999                         }
2000
2001                         this.viewport.set(0, 0, width, height);
2002                         this.scissor.set(0, 0, width, height);
2003                 },
2004                 clone: function clone() {
2005                         return new this.constructor().copy(this);
2006                 },
2007                 copy: function copy(source) {
2008                         this.width = source.width;
2009                         this.height = source.height;
2010                         this.viewport.copy(source.viewport);
2011                         this.texture = source.texture.clone();
2012                         this.depthBuffer = source.depthBuffer;
2013                         this.stencilBuffer = source.stencilBuffer;
2014                         this.depthTexture = source.depthTexture;
2015                         return this;
2016                 },
2017                 dispose: function dispose() {
2018                         this.dispatchEvent({
2019                                 type: 'dispose'
2020                         });
2021                 }
2022         });
2023
2024         function WebGLMultisampleRenderTarget(width, height, options) {
2025                 WebGLRenderTarget.call(this, width, height, options);
2026                 this.samples = 4;
2027         }
2028
2029         WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
2030                 constructor: WebGLMultisampleRenderTarget,
2031                 isWebGLMultisampleRenderTarget: true,
2032                 copy: function copy(source) {
2033                         WebGLRenderTarget.prototype.copy.call(this, source);
2034                         this.samples = source.samples;
2035                         return this;
2036                 }
2037         });
2038
2039         var Quaternion = /*#__PURE__*/function () {
2040                 function Quaternion(x, y, z, w) {
2041                         if (x === void 0) {
2042                                 x = 0;
2043                         }
2044
2045                         if (y === void 0) {
2046                                 y = 0;
2047                         }
2048
2049                         if (z === void 0) {
2050                                 z = 0;
2051                         }
2052
2053                         if (w === void 0) {
2054                                 w = 1;
2055                         }
2056
2057                         Object.defineProperty(this, 'isQuaternion', {
2058                                 value: true
2059                         });
2060                         this._x = x;
2061                         this._y = y;
2062                         this._z = z;
2063                         this._w = w;
2064                 }
2065
2066                 Quaternion.slerp = function slerp(qa, qb, qm, t) {
2067                         return qm.copy(qa).slerp(qb, t);
2068                 };
2069
2070                 Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
2071                         // fuzz-free, array-based Quaternion SLERP operation
2072                         var x0 = src0[srcOffset0 + 0],
2073                                         y0 = src0[srcOffset0 + 1],
2074                                         z0 = src0[srcOffset0 + 2],
2075                                         w0 = src0[srcOffset0 + 3];
2076                         var x1 = src1[srcOffset1 + 0],
2077                                         y1 = src1[srcOffset1 + 1],
2078                                         z1 = src1[srcOffset1 + 2],
2079                                         w1 = src1[srcOffset1 + 3];
2080
2081                         if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
2082                                 var s = 1 - t;
2083                                 var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
2084                                                 dir = cos >= 0 ? 1 : -1,
2085                                                 sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
2086
2087                                 if (sqrSin > Number.EPSILON) {
2088                                         var sin = Math.sqrt(sqrSin),
2089                                                         len = Math.atan2(sin, cos * dir);
2090                                         s = Math.sin(s * len) / sin;
2091                                         t = Math.sin(t * len) / sin;
2092                                 }
2093
2094                                 var tDir = t * dir;
2095                                 x0 = x0 * s + x1 * tDir;
2096                                 y0 = y0 * s + y1 * tDir;
2097                                 z0 = z0 * s + z1 * tDir;
2098                                 w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
2099
2100                                 if (s === 1 - t) {
2101                                         var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
2102                                         x0 *= f;
2103                                         y0 *= f;
2104                                         z0 *= f;
2105                                         w0 *= f;
2106                                 }
2107                         }
2108
2109                         dst[dstOffset] = x0;
2110                         dst[dstOffset + 1] = y0;
2111                         dst[dstOffset + 2] = z0;
2112                         dst[dstOffset + 3] = w0;
2113                 };
2114
2115                 Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
2116                         var x0 = src0[srcOffset0];
2117                         var y0 = src0[srcOffset0 + 1];
2118                         var z0 = src0[srcOffset0 + 2];
2119                         var w0 = src0[srcOffset0 + 3];
2120                         var x1 = src1[srcOffset1];
2121                         var y1 = src1[srcOffset1 + 1];
2122                         var z1 = src1[srcOffset1 + 2];
2123                         var w1 = src1[srcOffset1 + 3];
2124                         dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
2125                         dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
2126                         dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
2127                         dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
2128                         return dst;
2129                 };
2130
2131                 var _proto = Quaternion.prototype;
2132
2133                 _proto.set = function set(x, y, z, w) {
2134                         this._x = x;
2135                         this._y = y;
2136                         this._z = z;
2137                         this._w = w;
2138
2139                         this._onChangeCallback();
2140
2141                         return this;
2142                 };
2143
2144                 _proto.clone = function clone() {
2145                         return new this.constructor(this._x, this._y, this._z, this._w);
2146                 };
2147
2148                 _proto.copy = function copy(quaternion) {
2149                         this._x = quaternion.x;
2150                         this._y = quaternion.y;
2151                         this._z = quaternion.z;
2152                         this._w = quaternion.w;
2153
2154                         this._onChangeCallback();
2155
2156                         return this;
2157                 };
2158
2159                 _proto.setFromEuler = function setFromEuler(euler, update) {
2160                         if (!(euler && euler.isEuler)) {
2161                                 throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
2162                         }
2163
2164                         var x = euler._x,
2165                                         y = euler._y,
2166                                         z = euler._z,
2167                                         order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
2168                         //      20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
2169                         //      content/SpinCalc.m
2170
2171                         var cos = Math.cos;
2172                         var sin = Math.sin;
2173                         var c1 = cos(x / 2);
2174                         var c2 = cos(y / 2);
2175                         var c3 = cos(z / 2);
2176                         var s1 = sin(x / 2);
2177                         var s2 = sin(y / 2);
2178                         var s3 = sin(z / 2);
2179
2180                         switch (order) {
2181                                 case 'XYZ':
2182                                         this._x = s1 * c2 * c3 + c1 * s2 * s3;
2183                                         this._y = c1 * s2 * c3 - s1 * c2 * s3;
2184                                         this._z = c1 * c2 * s3 + s1 * s2 * c3;
2185                                         this._w = c1 * c2 * c3 - s1 * s2 * s3;
2186                                         break;
2187
2188                                 case 'YXZ':
2189                                         this._x = s1 * c2 * c3 + c1 * s2 * s3;
2190                                         this._y = c1 * s2 * c3 - s1 * c2 * s3;
2191                                         this._z = c1 * c2 * s3 - s1 * s2 * c3;
2192                                         this._w = c1 * c2 * c3 + s1 * s2 * s3;
2193                                         break;
2194
2195                                 case 'ZXY':
2196                                         this._x = s1 * c2 * c3 - c1 * s2 * s3;
2197                                         this._y = c1 * s2 * c3 + s1 * c2 * s3;
2198                                         this._z = c1 * c2 * s3 + s1 * s2 * c3;
2199                                         this._w = c1 * c2 * c3 - s1 * s2 * s3;
2200                                         break;
2201
2202                                 case 'ZYX':
2203                                         this._x = s1 * c2 * c3 - c1 * s2 * s3;
2204                                         this._y = c1 * s2 * c3 + s1 * c2 * s3;
2205                                         this._z = c1 * c2 * s3 - s1 * s2 * c3;
2206                                         this._w = c1 * c2 * c3 + s1 * s2 * s3;
2207                                         break;
2208
2209                                 case 'YZX':
2210                                         this._x = s1 * c2 * c3 + c1 * s2 * s3;
2211                                         this._y = c1 * s2 * c3 + s1 * c2 * s3;
2212                                         this._z = c1 * c2 * s3 - s1 * s2 * c3;
2213                                         this._w = c1 * c2 * c3 - s1 * s2 * s3;
2214                                         break;
2215
2216                                 case 'XZY':
2217                                         this._x = s1 * c2 * c3 - c1 * s2 * s3;
2218                                         this._y = c1 * s2 * c3 - s1 * c2 * s3;
2219                                         this._z = c1 * c2 * s3 + s1 * s2 * c3;
2220                                         this._w = c1 * c2 * c3 + s1 * s2 * s3;
2221                                         break;
2222
2223                                 default:
2224                                         console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
2225                         }
2226
2227                         if (update !== false) this._onChangeCallback();
2228                         return this;
2229                 };
2230
2231                 _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
2232                         // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
2233                         // assumes axis is normalized
2234                         var halfAngle = angle / 2,
2235                                         s = Math.sin(halfAngle);
2236                         this._x = axis.x * s;
2237                         this._y = axis.y * s;
2238                         this._z = axis.z * s;
2239                         this._w = Math.cos(halfAngle);
2240
2241                         this._onChangeCallback();
2242
2243                         return this;
2244                 };
2245
2246                 _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
2247                         // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
2248                         // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
2249                         var te = m.elements,
2250                                         m11 = te[0],
2251                                         m12 = te[4],
2252                                         m13 = te[8],
2253                                         m21 = te[1],
2254                                         m22 = te[5],
2255                                         m23 = te[9],
2256                                         m31 = te[2],
2257                                         m32 = te[6],
2258                                         m33 = te[10],
2259                                         trace = m11 + m22 + m33;
2260
2261                         if (trace > 0) {
2262                                 var s = 0.5 / Math.sqrt(trace + 1.0);
2263                                 this._w = 0.25 / s;
2264                                 this._x = (m32 - m23) * s;
2265                                 this._y = (m13 - m31) * s;
2266                                 this._z = (m21 - m12) * s;
2267                         } else if (m11 > m22 && m11 > m33) {
2268                                 var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
2269
2270                                 this._w = (m32 - m23) / _s;
2271                                 this._x = 0.25 * _s;
2272                                 this._y = (m12 + m21) / _s;
2273                                 this._z = (m13 + m31) / _s;
2274                         } else if (m22 > m33) {
2275                                 var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
2276
2277                                 this._w = (m13 - m31) / _s2;
2278                                 this._x = (m12 + m21) / _s2;
2279                                 this._y = 0.25 * _s2;
2280                                 this._z = (m23 + m32) / _s2;
2281                         } else {
2282                                 var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
2283
2284                                 this._w = (m21 - m12) / _s3;
2285                                 this._x = (m13 + m31) / _s3;
2286                                 this._y = (m23 + m32) / _s3;
2287                                 this._z = 0.25 * _s3;
2288                         }
2289
2290                         this._onChangeCallback();
2291
2292                         return this;
2293                 };
2294
2295                 _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
2296                         // assumes direction vectors vFrom and vTo are normalized
2297                         var EPS = 0.000001;
2298                         var r = vFrom.dot(vTo) + 1;
2299
2300                         if (r < EPS) {
2301                                 r = 0;
2302
2303                                 if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
2304                                         this._x = -vFrom.y;
2305                                         this._y = vFrom.x;
2306                                         this._z = 0;
2307                                         this._w = r;
2308                                 } else {
2309                                         this._x = 0;
2310                                         this._y = -vFrom.z;
2311                                         this._z = vFrom.y;
2312                                         this._w = r;
2313                                 }
2314                         } else {
2315                                 // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
2316                                 this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
2317                                 this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
2318                                 this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
2319                                 this._w = r;
2320                         }
2321
2322                         return this.normalize();
2323                 };
2324
2325                 _proto.angleTo = function angleTo(q) {
2326                         return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
2327                 };
2328
2329                 _proto.rotateTowards = function rotateTowards(q, step) {
2330                         var angle = this.angleTo(q);
2331                         if (angle === 0) return this;
2332                         var t = Math.min(1, step / angle);
2333                         this.slerp(q, t);
2334                         return this;
2335                 };
2336
2337                 _proto.identity = function identity() {
2338                         return this.set(0, 0, 0, 1);
2339                 };
2340
2341                 _proto.invert = function invert() {
2342                         // quaternion is assumed to have unit length
2343                         return this.conjugate();
2344                 };
2345
2346                 _proto.conjugate = function conjugate() {
2347                         this._x *= -1;
2348                         this._y *= -1;
2349                         this._z *= -1;
2350
2351                         this._onChangeCallback();
2352
2353                         return this;
2354                 };
2355
2356                 _proto.dot = function dot(v) {
2357                         return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
2358                 };
2359
2360                 _proto.lengthSq = function lengthSq() {
2361                         return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
2362                 };
2363
2364                 _proto.length = function length() {
2365                         return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
2366                 };
2367
2368                 _proto.normalize = function normalize() {
2369                         var l = this.length();
2370
2371                         if (l === 0) {
2372                                 this._x = 0;
2373                                 this._y = 0;
2374                                 this._z = 0;
2375                                 this._w = 1;
2376                         } else {
2377                                 l = 1 / l;
2378                                 this._x = this._x * l;
2379                                 this._y = this._y * l;
2380                                 this._z = this._z * l;
2381                                 this._w = this._w * l;
2382                         }
2383
2384                         this._onChangeCallback();
2385
2386                         return this;
2387                 };
2388
2389                 _proto.multiply = function multiply(q, p) {
2390                         if (p !== undefined) {
2391                                 console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
2392                                 return this.multiplyQuaternions(q, p);
2393                         }
2394
2395                         return this.multiplyQuaternions(this, q);
2396                 };
2397
2398                 _proto.premultiply = function premultiply(q) {
2399                         return this.multiplyQuaternions(q, this);
2400                 };
2401
2402                 _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
2403                         // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
2404                         var qax = a._x,
2405                                         qay = a._y,
2406                                         qaz = a._z,
2407                                         qaw = a._w;
2408                         var qbx = b._x,
2409                                         qby = b._y,
2410                                         qbz = b._z,
2411                                         qbw = b._w;
2412                         this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
2413                         this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
2414                         this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
2415                         this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
2416
2417                         this._onChangeCallback();
2418
2419                         return this;
2420                 };
2421
2422                 _proto.slerp = function slerp(qb, t) {
2423                         if (t === 0) return this;
2424                         if (t === 1) return this.copy(qb);
2425                         var x = this._x,
2426                                         y = this._y,
2427                                         z = this._z,
2428                                         w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
2429
2430                         var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
2431
2432                         if (cosHalfTheta < 0) {
2433                                 this._w = -qb._w;
2434                                 this._x = -qb._x;
2435                                 this._y = -qb._y;
2436                                 this._z = -qb._z;
2437                                 cosHalfTheta = -cosHalfTheta;
2438                         } else {
2439                                 this.copy(qb);
2440                         }
2441
2442                         if (cosHalfTheta >= 1.0) {
2443                                 this._w = w;
2444                                 this._x = x;
2445                                 this._y = y;
2446                                 this._z = z;
2447                                 return this;
2448                         }
2449
2450                         var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
2451
2452                         if (sqrSinHalfTheta <= Number.EPSILON) {
2453                                 var s = 1 - t;
2454                                 this._w = s * w + t * this._w;
2455                                 this._x = s * x + t * this._x;
2456                                 this._y = s * y + t * this._y;
2457                                 this._z = s * z + t * this._z;
2458                                 this.normalize();
2459
2460                                 this._onChangeCallback();
2461
2462                                 return this;
2463                         }
2464
2465                         var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
2466                         var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
2467                         var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
2468                                         ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
2469                         this._w = w * ratioA + this._w * ratioB;
2470                         this._x = x * ratioA + this._x * ratioB;
2471                         this._y = y * ratioA + this._y * ratioB;
2472                         this._z = z * ratioA + this._z * ratioB;
2473
2474                         this._onChangeCallback();
2475
2476                         return this;
2477                 };
2478
2479                 _proto.equals = function equals(quaternion) {
2480                         return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
2481                 };
2482
2483                 _proto.fromArray = function fromArray(array, offset) {
2484                         if (offset === void 0) {
2485                                 offset = 0;
2486                         }
2487
2488                         this._x = array[offset];
2489                         this._y = array[offset + 1];
2490                         this._z = array[offset + 2];
2491                         this._w = array[offset + 3];
2492
2493                         this._onChangeCallback();
2494
2495                         return this;
2496                 };
2497
2498                 _proto.toArray = function toArray(array, offset) {
2499                         if (array === void 0) {
2500                                 array = [];
2501                         }
2502
2503                         if (offset === void 0) {
2504                                 offset = 0;
2505                         }
2506
2507                         array[offset] = this._x;
2508                         array[offset + 1] = this._y;
2509                         array[offset + 2] = this._z;
2510                         array[offset + 3] = this._w;
2511                         return array;
2512                 };
2513
2514                 _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
2515                         this._x = attribute.getX(index);
2516                         this._y = attribute.getY(index);
2517                         this._z = attribute.getZ(index);
2518                         this._w = attribute.getW(index);
2519                         return this;
2520                 };
2521
2522                 _proto._onChange = function _onChange(callback) {
2523                         this._onChangeCallback = callback;
2524                         return this;
2525                 };
2526
2527                 _proto._onChangeCallback = function _onChangeCallback() {};
2528
2529                 _createClass(Quaternion, [{
2530                         key: "x",
2531                         get: function get() {
2532                                 return this._x;
2533                         },
2534                         set: function set(value) {
2535                                 this._x = value;
2536
2537                                 this._onChangeCallback();
2538                         }
2539                 }, {
2540                         key: "y",
2541                         get: function get() {
2542                                 return this._y;
2543                         },
2544                         set: function set(value) {
2545                                 this._y = value;
2546
2547                                 this._onChangeCallback();
2548                         }
2549                 }, {
2550                         key: "z",
2551                         get: function get() {
2552                                 return this._z;
2553                         },
2554                         set: function set(value) {
2555                                 this._z = value;
2556
2557                                 this._onChangeCallback();
2558                         }
2559                 }, {
2560                         key: "w",
2561                         get: function get() {
2562                                 return this._w;
2563                         },
2564                         set: function set(value) {
2565                                 this._w = value;
2566
2567                                 this._onChangeCallback();
2568                         }
2569                 }]);
2570
2571                 return Quaternion;
2572         }();
2573
2574         var Vector3 = /*#__PURE__*/function () {
2575                 function Vector3(x, y, z) {
2576                         if (x === void 0) {
2577                                 x = 0;
2578                         }
2579
2580                         if (y === void 0) {
2581                                 y = 0;
2582                         }
2583
2584                         if (z === void 0) {
2585                                 z = 0;
2586                         }
2587
2588                         Object.defineProperty(this, 'isVector3', {
2589                                 value: true
2590                         });
2591                         this.x = x;
2592                         this.y = y;
2593                         this.z = z;
2594                 }
2595
2596                 var _proto = Vector3.prototype;
2597
2598                 _proto.set = function set(x, y, z) {
2599                         if (z === undefined) z = this.z; // sprite.scale.set(x,y)
2600
2601                         this.x = x;
2602                         this.y = y;
2603                         this.z = z;
2604                         return this;
2605                 };
2606
2607                 _proto.setScalar = function setScalar(scalar) {
2608                         this.x = scalar;
2609                         this.y = scalar;
2610                         this.z = scalar;
2611                         return this;
2612                 };
2613
2614                 _proto.setX = function setX(x) {
2615                         this.x = x;
2616                         return this;
2617                 };
2618
2619                 _proto.setY = function setY(y) {
2620                         this.y = y;
2621                         return this;
2622                 };
2623
2624                 _proto.setZ = function setZ(z) {
2625                         this.z = z;
2626                         return this;
2627                 };
2628
2629                 _proto.setComponent = function setComponent(index, value) {
2630                         switch (index) {
2631                                 case 0:
2632                                         this.x = value;
2633                                         break;
2634
2635                                 case 1:
2636                                         this.y = value;
2637                                         break;
2638
2639                                 case 2:
2640                                         this.z = value;
2641                                         break;
2642
2643                                 default:
2644                                         throw new Error('index is out of range: ' + index);
2645                         }
2646
2647                         return this;
2648                 };
2649
2650                 _proto.getComponent = function getComponent(index) {
2651                         switch (index) {
2652                                 case 0:
2653                                         return this.x;
2654
2655                                 case 1:
2656                                         return this.y;
2657
2658                                 case 2:
2659                                         return this.z;
2660
2661                                 default:
2662                                         throw new Error('index is out of range: ' + index);
2663                         }
2664                 };
2665
2666                 _proto.clone = function clone() {
2667                         return new this.constructor(this.x, this.y, this.z);
2668                 };
2669
2670                 _proto.copy = function copy(v) {
2671                         this.x = v.x;
2672                         this.y = v.y;
2673                         this.z = v.z;
2674                         return this;
2675                 };
2676
2677                 _proto.add = function add(v, w) {
2678                         if (w !== undefined) {
2679                                 console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
2680                                 return this.addVectors(v, w);
2681                         }
2682
2683                         this.x += v.x;
2684                         this.y += v.y;
2685                         this.z += v.z;
2686                         return this;
2687                 };
2688
2689                 _proto.addScalar = function addScalar(s) {
2690                         this.x += s;
2691                         this.y += s;
2692                         this.z += s;
2693                         return this;
2694                 };
2695
2696                 _proto.addVectors = function addVectors(a, b) {
2697                         this.x = a.x + b.x;
2698                         this.y = a.y + b.y;
2699                         this.z = a.z + b.z;
2700                         return this;
2701                 };
2702
2703                 _proto.addScaledVector = function addScaledVector(v, s) {
2704                         this.x += v.x * s;
2705                         this.y += v.y * s;
2706                         this.z += v.z * s;
2707                         return this;
2708                 };
2709
2710                 _proto.sub = function sub(v, w) {
2711                         if (w !== undefined) {
2712                                 console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
2713                                 return this.subVectors(v, w);
2714                         }
2715
2716                         this.x -= v.x;
2717                         this.y -= v.y;
2718                         this.z -= v.z;
2719                         return this;
2720                 };
2721
2722                 _proto.subScalar = function subScalar(s) {
2723                         this.x -= s;
2724                         this.y -= s;
2725                         this.z -= s;
2726                         return this;
2727                 };
2728
2729                 _proto.subVectors = function subVectors(a, b) {
2730                         this.x = a.x - b.x;
2731                         this.y = a.y - b.y;
2732                         this.z = a.z - b.z;
2733                         return this;
2734                 };
2735
2736                 _proto.multiply = function multiply(v, w) {
2737                         if (w !== undefined) {
2738                                 console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
2739                                 return this.multiplyVectors(v, w);
2740                         }
2741
2742                         this.x *= v.x;
2743                         this.y *= v.y;
2744                         this.z *= v.z;
2745                         return this;
2746                 };
2747
2748                 _proto.multiplyScalar = function multiplyScalar(scalar) {
2749                         this.x *= scalar;
2750                         this.y *= scalar;
2751                         this.z *= scalar;
2752                         return this;
2753                 };
2754
2755                 _proto.multiplyVectors = function multiplyVectors(a, b) {
2756                         this.x = a.x * b.x;
2757                         this.y = a.y * b.y;
2758                         this.z = a.z * b.z;
2759                         return this;
2760                 };
2761
2762                 _proto.applyEuler = function applyEuler(euler) {
2763                         if (!(euler && euler.isEuler)) {
2764                                 console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
2765                         }
2766
2767                         return this.applyQuaternion(_quaternion.setFromEuler(euler));
2768                 };
2769
2770                 _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
2771                         return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
2772                 };
2773
2774                 _proto.applyMatrix3 = function applyMatrix3(m) {
2775                         var x = this.x,
2776                                         y = this.y,
2777                                         z = this.z;
2778                         var e = m.elements;
2779                         this.x = e[0] * x + e[3] * y + e[6] * z;
2780                         this.y = e[1] * x + e[4] * y + e[7] * z;
2781                         this.z = e[2] * x + e[5] * y + e[8] * z;
2782                         return this;
2783                 };
2784
2785                 _proto.applyNormalMatrix = function applyNormalMatrix(m) {
2786                         return this.applyMatrix3(m).normalize();
2787                 };
2788
2789                 _proto.applyMatrix4 = function applyMatrix4(m) {
2790                         var x = this.x,
2791                                         y = this.y,
2792                                         z = this.z;
2793                         var e = m.elements;
2794                         var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
2795                         this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
2796                         this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
2797                         this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
2798                         return this;
2799                 };
2800
2801                 _proto.applyQuaternion = function applyQuaternion(q) {
2802                         var x = this.x,
2803                                         y = this.y,
2804                                         z = this.z;
2805                         var qx = q.x,
2806                                         qy = q.y,
2807                                         qz = q.z,
2808                                         qw = q.w; // calculate quat * vector
2809
2810                         var ix = qw * x + qy * z - qz * y;
2811                         var iy = qw * y + qz * x - qx * z;
2812                         var iz = qw * z + qx * y - qy * x;
2813                         var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
2814
2815                         this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
2816                         this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
2817                         this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
2818                         return this;
2819                 };
2820
2821                 _proto.project = function project(camera) {
2822                         return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
2823                 };
2824
2825                 _proto.unproject = function unproject(camera) {
2826                         return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
2827                 };
2828
2829                 _proto.transformDirection = function transformDirection(m) {
2830                         // input: THREE.Matrix4 affine matrix
2831                         // vector interpreted as a direction
2832                         var x = this.x,
2833                                         y = this.y,
2834                                         z = this.z;
2835                         var e = m.elements;
2836                         this.x = e[0] * x + e[4] * y + e[8] * z;
2837                         this.y = e[1] * x + e[5] * y + e[9] * z;
2838                         this.z = e[2] * x + e[6] * y + e[10] * z;
2839                         return this.normalize();
2840                 };
2841
2842                 _proto.divide = function divide(v) {
2843                         this.x /= v.x;
2844                         this.y /= v.y;
2845                         this.z /= v.z;
2846                         return this;
2847                 };
2848
2849                 _proto.divideScalar = function divideScalar(scalar) {
2850                         return this.multiplyScalar(1 / scalar);
2851                 };
2852
2853                 _proto.min = function min(v) {
2854                         this.x = Math.min(this.x, v.x);
2855                         this.y = Math.min(this.y, v.y);
2856                         this.z = Math.min(this.z, v.z);
2857                         return this;
2858                 };
2859
2860                 _proto.max = function max(v) {
2861                         this.x = Math.max(this.x, v.x);
2862                         this.y = Math.max(this.y, v.y);
2863                         this.z = Math.max(this.z, v.z);
2864                         return this;
2865                 };
2866
2867                 _proto.clamp = function clamp(min, max) {
2868                         // assumes min < max, componentwise
2869                         this.x = Math.max(min.x, Math.min(max.x, this.x));
2870                         this.y = Math.max(min.y, Math.min(max.y, this.y));
2871                         this.z = Math.max(min.z, Math.min(max.z, this.z));
2872                         return this;
2873                 };
2874
2875                 _proto.clampScalar = function clampScalar(minVal, maxVal) {
2876                         this.x = Math.max(minVal, Math.min(maxVal, this.x));
2877                         this.y = Math.max(minVal, Math.min(maxVal, this.y));
2878                         this.z = Math.max(minVal, Math.min(maxVal, this.z));
2879                         return this;
2880                 };
2881
2882                 _proto.clampLength = function clampLength(min, max) {
2883                         var length = this.length();
2884                         return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
2885                 };
2886
2887                 _proto.floor = function floor() {
2888                         this.x = Math.floor(this.x);
2889                         this.y = Math.floor(this.y);
2890                         this.z = Math.floor(this.z);
2891                         return this;
2892                 };
2893
2894                 _proto.ceil = function ceil() {
2895                         this.x = Math.ceil(this.x);
2896                         this.y = Math.ceil(this.y);
2897                         this.z = Math.ceil(this.z);
2898                         return this;
2899                 };
2900
2901                 _proto.round = function round() {
2902                         this.x = Math.round(this.x);
2903                         this.y = Math.round(this.y);
2904                         this.z = Math.round(this.z);
2905                         return this;
2906                 };
2907
2908                 _proto.roundToZero = function roundToZero() {
2909                         this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
2910                         this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
2911                         this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
2912                         return this;
2913                 };
2914
2915                 _proto.negate = function negate() {
2916                         this.x = -this.x;
2917                         this.y = -this.y;
2918                         this.z = -this.z;
2919                         return this;
2920                 };
2921
2922                 _proto.dot = function dot(v) {
2923                         return this.x * v.x + this.y * v.y + this.z * v.z;
2924                 } // TODO lengthSquared?
2925                 ;
2926
2927                 _proto.lengthSq = function lengthSq() {
2928                         return this.x * this.x + this.y * this.y + this.z * this.z;
2929                 };
2930
2931                 _proto.length = function length() {
2932                         return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2933                 };
2934
2935                 _proto.manhattanLength = function manhattanLength() {
2936                         return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
2937                 };
2938
2939                 _proto.normalize = function normalize() {
2940                         return this.divideScalar(this.length() || 1);
2941                 };
2942
2943                 _proto.setLength = function setLength(length) {
2944                         return this.normalize().multiplyScalar(length);
2945                 };
2946
2947                 _proto.lerp = function lerp(v, alpha) {
2948                         this.x += (v.x - this.x) * alpha;
2949                         this.y += (v.y - this.y) * alpha;
2950                         this.z += (v.z - this.z) * alpha;
2951                         return this;
2952                 };
2953
2954                 _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
2955                         this.x = v1.x + (v2.x - v1.x) * alpha;
2956                         this.y = v1.y + (v2.y - v1.y) * alpha;
2957                         this.z = v1.z + (v2.z - v1.z) * alpha;
2958                         return this;
2959                 };
2960
2961                 _proto.cross = function cross(v, w) {
2962                         if (w !== undefined) {
2963                                 console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
2964                                 return this.crossVectors(v, w);
2965                         }
2966
2967                         return this.crossVectors(this, v);
2968                 };
2969
2970                 _proto.crossVectors = function crossVectors(a, b) {
2971                         var ax = a.x,
2972                                         ay = a.y,
2973                                         az = a.z;
2974                         var bx = b.x,
2975                                         by = b.y,
2976                                         bz = b.z;
2977                         this.x = ay * bz - az * by;
2978                         this.y = az * bx - ax * bz;
2979                         this.z = ax * by - ay * bx;
2980                         return this;
2981                 };
2982
2983                 _proto.projectOnVector = function projectOnVector(v) {
2984                         var denominator = v.lengthSq();
2985                         if (denominator === 0) return this.set(0, 0, 0);
2986                         var scalar = v.dot(this) / denominator;
2987                         return this.copy(v).multiplyScalar(scalar);
2988                 };
2989
2990                 _proto.projectOnPlane = function projectOnPlane(planeNormal) {
2991                         _vector.copy(this).projectOnVector(planeNormal);
2992
2993                         return this.sub(_vector);
2994                 };
2995
2996                 _proto.reflect = function reflect(normal) {
2997                         // reflect incident vector off plane orthogonal to normal
2998                         // normal is assumed to have unit length
2999                         return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
3000                 };
3001
3002                 _proto.angleTo = function angleTo(v) {
3003                         var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
3004                         if (denominator === 0) return Math.PI / 2;
3005                         var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
3006
3007                         return Math.acos(MathUtils.clamp(theta, -1, 1));
3008                 };
3009
3010                 _proto.distanceTo = function distanceTo(v) {
3011                         return Math.sqrt(this.distanceToSquared(v));
3012                 };
3013
3014                 _proto.distanceToSquared = function distanceToSquared(v) {
3015                         var dx = this.x - v.x,
3016                                         dy = this.y - v.y,
3017                                         dz = this.z - v.z;
3018                         return dx * dx + dy * dy + dz * dz;
3019                 };
3020
3021                 _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
3022                         return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
3023                 };
3024
3025                 _proto.setFromSpherical = function setFromSpherical(s) {
3026                         return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
3027                 };
3028
3029                 _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
3030                         var sinPhiRadius = Math.sin(phi) * radius;
3031                         this.x = sinPhiRadius * Math.sin(theta);
3032                         this.y = Math.cos(phi) * radius;
3033                         this.z = sinPhiRadius * Math.cos(theta);
3034                         return this;
3035                 };
3036
3037                 _proto.setFromCylindrical = function setFromCylindrical(c) {
3038                         return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
3039                 };
3040
3041                 _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
3042                         this.x = radius * Math.sin(theta);
3043                         this.y = y;
3044                         this.z = radius * Math.cos(theta);
3045                         return this;
3046                 };
3047
3048                 _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
3049                         var e = m.elements;
3050                         this.x = e[12];
3051                         this.y = e[13];
3052                         this.z = e[14];
3053                         return this;
3054                 };
3055
3056                 _proto.setFromMatrixScale = function setFromMatrixScale(m) {
3057                         var sx = this.setFromMatrixColumn(m, 0).length();
3058                         var sy = this.setFromMatrixColumn(m, 1).length();
3059                         var sz = this.setFromMatrixColumn(m, 2).length();
3060                         this.x = sx;
3061                         this.y = sy;
3062                         this.z = sz;
3063                         return this;
3064                 };
3065
3066                 _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
3067                         return this.fromArray(m.elements, index * 4);
3068                 };
3069
3070                 _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
3071                         return this.fromArray(m.elements, index * 3);
3072                 };
3073
3074                 _proto.equals = function equals(v) {
3075                         return v.x === this.x && v.y === this.y && v.z === this.z;
3076                 };
3077
3078                 _proto.fromArray = function fromArray(array, offset) {
3079                         if (offset === void 0) {
3080                                 offset = 0;
3081                         }
3082
3083                         this.x = array[offset];
3084                         this.y = array[offset + 1];
3085                         this.z = array[offset + 2];
3086                         return this;
3087                 };
3088
3089                 _proto.toArray = function toArray(array, offset) {
3090                         if (array === void 0) {
3091                                 array = [];
3092                         }
3093
3094                         if (offset === void 0) {
3095                                 offset = 0;
3096                         }
3097
3098                         array[offset] = this.x;
3099                         array[offset + 1] = this.y;
3100                         array[offset + 2] = this.z;
3101                         return array;
3102                 };
3103
3104                 _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
3105                         if (offset !== undefined) {
3106                                 console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
3107                         }
3108
3109                         this.x = attribute.getX(index);
3110                         this.y = attribute.getY(index);
3111                         this.z = attribute.getZ(index);
3112                         return this;
3113                 };
3114
3115                 _proto.random = function random() {
3116                         this.x = Math.random();
3117                         this.y = Math.random();
3118                         this.z = Math.random();
3119                         return this;
3120                 };
3121
3122                 return Vector3;
3123         }();
3124
3125         var _vector = /*@__PURE__*/new Vector3();
3126
3127         var _quaternion = /*@__PURE__*/new Quaternion();
3128
3129         var Box3 = /*#__PURE__*/function () {
3130                 function Box3(min, max) {
3131                         Object.defineProperty(this, 'isBox3', {
3132                                 value: true
3133                         });
3134                         this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
3135                         this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
3136                 }
3137
3138                 var _proto = Box3.prototype;
3139
3140                 _proto.set = function set(min, max) {
3141                         this.min.copy(min);
3142                         this.max.copy(max);
3143                         return this;
3144                 };
3145
3146                 _proto.setFromArray = function setFromArray(array) {
3147                         var minX = +Infinity;
3148                         var minY = +Infinity;
3149                         var minZ = +Infinity;
3150                         var maxX = -Infinity;
3151                         var maxY = -Infinity;
3152                         var maxZ = -Infinity;
3153
3154                         for (var i = 0, l = array.length; i < l; i += 3) {
3155                                 var x = array[i];
3156                                 var y = array[i + 1];
3157                                 var z = array[i + 2];
3158                                 if (x < minX) minX = x;
3159                                 if (y < minY) minY = y;
3160                                 if (z < minZ) minZ = z;
3161                                 if (x > maxX) maxX = x;
3162                                 if (y > maxY) maxY = y;
3163                                 if (z > maxZ) maxZ = z;
3164                         }
3165
3166                         this.min.set(minX, minY, minZ);
3167                         this.max.set(maxX, maxY, maxZ);
3168                         return this;
3169                 };
3170
3171                 _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
3172                         var minX = +Infinity;
3173                         var minY = +Infinity;
3174                         var minZ = +Infinity;
3175                         var maxX = -Infinity;
3176                         var maxY = -Infinity;
3177                         var maxZ = -Infinity;
3178
3179                         for (var i = 0, l = attribute.count; i < l; i++) {
3180                                 var x = attribute.getX(i);
3181                                 var y = attribute.getY(i);
3182                                 var z = attribute.getZ(i);
3183                                 if (x < minX) minX = x;
3184                                 if (y < minY) minY = y;
3185                                 if (z < minZ) minZ = z;
3186                                 if (x > maxX) maxX = x;
3187                                 if (y > maxY) maxY = y;
3188                                 if (z > maxZ) maxZ = z;
3189                         }
3190
3191                         this.min.set(minX, minY, minZ);
3192                         this.max.set(maxX, maxY, maxZ);
3193                         return this;
3194                 };
3195
3196                 _proto.setFromPoints = function setFromPoints(points) {
3197                         this.makeEmpty();
3198
3199                         for (var i = 0, il = points.length; i < il; i++) {
3200                                 this.expandByPoint(points[i]);
3201                         }
3202
3203                         return this;
3204                 };
3205
3206                 _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
3207                         var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
3208
3209                         this.min.copy(center).sub(halfSize);
3210                         this.max.copy(center).add(halfSize);
3211                         return this;
3212                 };
3213
3214                 _proto.setFromObject = function setFromObject(object) {
3215                         this.makeEmpty();
3216                         return this.expandByObject(object);
3217                 };
3218
3219                 _proto.clone = function clone() {
3220                         return new this.constructor().copy(this);
3221                 };
3222
3223                 _proto.copy = function copy(box) {
3224                         this.min.copy(box.min);
3225                         this.max.copy(box.max);
3226                         return this;
3227                 };
3228
3229                 _proto.makeEmpty = function makeEmpty() {
3230                         this.min.x = this.min.y = this.min.z = +Infinity;
3231                         this.max.x = this.max.y = this.max.z = -Infinity;
3232                         return this;
3233                 };
3234
3235                 _proto.isEmpty = function isEmpty() {
3236                         // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
3237                         return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
3238                 };
3239
3240                 _proto.getCenter = function getCenter(target) {
3241                         if (target === undefined) {
3242                                 console.warn('THREE.Box3: .getCenter() target is now required');
3243                                 target = new Vector3();
3244                         }
3245
3246                         return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
3247                 };
3248
3249                 _proto.getSize = function getSize(target) {
3250                         if (target === undefined) {
3251                                 console.warn('THREE.Box3: .getSize() target is now required');
3252                                 target = new Vector3();
3253                         }
3254
3255                         return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
3256                 };
3257
3258                 _proto.expandByPoint = function expandByPoint(point) {
3259                         this.min.min(point);
3260                         this.max.max(point);
3261                         return this;
3262                 };
3263
3264                 _proto.expandByVector = function expandByVector(vector) {
3265                         this.min.sub(vector);
3266                         this.max.add(vector);
3267                         return this;
3268                 };
3269
3270                 _proto.expandByScalar = function expandByScalar(scalar) {
3271                         this.min.addScalar(-scalar);
3272                         this.max.addScalar(scalar);
3273                         return this;
3274                 };
3275
3276                 _proto.expandByObject = function expandByObject(object) {
3277                         // Computes the world-axis-aligned bounding box of an object (including its children),
3278                         // accounting for both the object's, and children's, world transforms
3279                         object.updateWorldMatrix(false, false);
3280                         var geometry = object.geometry;
3281
3282                         if (geometry !== undefined) {
3283                                 if (geometry.boundingBox === null) {
3284                                         geometry.computeBoundingBox();
3285                                 }
3286
3287                                 _box.copy(geometry.boundingBox);
3288
3289                                 _box.applyMatrix4(object.matrixWorld);
3290
3291                                 this.union(_box);
3292                         }
3293
3294                         var children = object.children;
3295
3296                         for (var i = 0, l = children.length; i < l; i++) {
3297                                 this.expandByObject(children[i]);
3298                         }
3299
3300                         return this;
3301                 };
3302
3303                 _proto.containsPoint = function containsPoint(point) {
3304                         return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
3305                 };
3306
3307                 _proto.containsBox = function containsBox(box) {
3308                         return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
3309                 };
3310
3311                 _proto.getParameter = function getParameter(point, target) {
3312                         // This can potentially have a divide by zero if the box
3313                         // has a size dimension of 0.
3314                         if (target === undefined) {
3315                                 console.warn('THREE.Box3: .getParameter() target is now required');
3316                                 target = new Vector3();
3317                         }
3318
3319                         return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
3320                 };
3321
3322                 _proto.intersectsBox = function intersectsBox(box) {
3323                         // using 6 splitting planes to rule out intersections.
3324                         return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
3325                 };
3326
3327                 _proto.intersectsSphere = function intersectsSphere(sphere) {
3328                         // Find the point on the AABB closest to the sphere center.
3329                         this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
3330
3331                         return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
3332                 };
3333
3334                 _proto.intersectsPlane = function intersectsPlane(plane) {
3335                         // We compute the minimum and maximum dot product values. If those values
3336                         // are on the same side (back or front) of the plane, then there is no intersection.
3337                         var min, max;
3338
3339                         if (plane.normal.x > 0) {
3340                                 min = plane.normal.x * this.min.x;
3341                                 max = plane.normal.x * this.max.x;
3342                         } else {
3343                                 min = plane.normal.x * this.max.x;
3344                                 max = plane.normal.x * this.min.x;
3345                         }
3346
3347                         if (plane.normal.y > 0) {
3348                                 min += plane.normal.y * this.min.y;
3349                                 max += plane.normal.y * this.max.y;
3350                         } else {
3351                                 min += plane.normal.y * this.max.y;
3352                                 max += plane.normal.y * this.min.y;
3353                         }
3354
3355                         if (plane.normal.z > 0) {
3356                                 min += plane.normal.z * this.min.z;
3357                                 max += plane.normal.z * this.max.z;
3358                         } else {
3359                                 min += plane.normal.z * this.max.z;
3360                                 max += plane.normal.z * this.min.z;
3361                         }
3362
3363                         return min <= -plane.constant && max >= -plane.constant;
3364                 };
3365
3366                 _proto.intersectsTriangle = function intersectsTriangle(triangle) {
3367                         if (this.isEmpty()) {
3368                                 return false;
3369                         } // compute box center and extents
3370
3371
3372                         this.getCenter(_center);
3373
3374                         _extents.subVectors(this.max, _center); // translate triangle to aabb origin
3375
3376
3377                         _v0.subVectors(triangle.a, _center);
3378
3379                         _v1.subVectors(triangle.b, _center);
3380
3381                         _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
3382
3383
3384                         _f0.subVectors(_v1, _v0);
3385
3386                         _f1.subVectors(_v2, _v1);
3387
3388                         _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
3389                         // 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
3390                         // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
3391
3392
3393                         var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
3394
3395                         if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
3396                                 return false;
3397                         } // test 3 face normals from the aabb
3398
3399
3400                         axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
3401
3402                         if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
3403                                 return false;
3404                         } // finally testing the face normal of the triangle
3405                         // use already existing triangle edge vectors here
3406
3407
3408                         _triangleNormal.crossVectors(_f0, _f1);
3409
3410                         axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
3411                         return satForAxes(axes, _v0, _v1, _v2, _extents);
3412                 };
3413
3414                 _proto.clampPoint = function clampPoint(point, target) {
3415                         if (target === undefined) {
3416                                 console.warn('THREE.Box3: .clampPoint() target is now required');
3417                                 target = new Vector3();
3418                         }
3419
3420                         return target.copy(point).clamp(this.min, this.max);
3421                 };
3422
3423                 _proto.distanceToPoint = function distanceToPoint(point) {
3424                         var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
3425
3426                         return clampedPoint.sub(point).length();
3427                 };
3428
3429                 _proto.getBoundingSphere = function getBoundingSphere(target) {
3430                         if (target === undefined) {
3431                                 console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
3432                         }
3433
3434                         this.getCenter(target.center);
3435                         target.radius = this.getSize(_vector$1).length() * 0.5;
3436                         return target;
3437                 };
3438
3439                 _proto.intersect = function intersect(box) {
3440                         this.min.max(box.min);
3441                         this.max.min(box.max); // 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.
3442
3443                         if (this.isEmpty()) this.makeEmpty();
3444                         return this;
3445                 };
3446
3447                 _proto.union = function union(box) {
3448                         this.min.min(box.min);
3449                         this.max.max(box.max);
3450                         return this;
3451                 };
3452
3453                 _proto.applyMatrix4 = function applyMatrix4(matrix) {
3454                         // transform of empty box is an empty box.
3455                         if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
3456
3457                         _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
3458
3459
3460                         _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
3461
3462
3463                         _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
3464
3465
3466                         _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
3467
3468
3469                         _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
3470
3471
3472                         _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
3473
3474
3475                         _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
3476
3477
3478                         _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
3479
3480
3481                         this.setFromPoints(_points);
3482                         return this;
3483                 };
3484
3485                 _proto.translate = function translate(offset) {
3486                         this.min.add(offset);
3487                         this.max.add(offset);
3488                         return this;
3489                 };
3490
3491                 _proto.equals = function equals(box) {
3492                         return box.min.equals(this.min) && box.max.equals(this.max);
3493                 };
3494
3495                 return Box3;
3496         }();
3497
3498         function satForAxes(axes, v0, v1, v2, extents) {
3499                 for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
3500                         _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
3501
3502
3503                         var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
3504
3505                         var p0 = v0.dot(_testAxis);
3506                         var p1 = v1.dot(_testAxis);
3507                         var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
3508
3509                         if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
3510                                 // points of the projected triangle are outside the projected half-length of the aabb
3511                                 // the axis is seperating and we can exit
3512                                 return false;
3513                         }
3514                 }
3515
3516                 return true;
3517         }
3518
3519         var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
3520
3521         var _vector$1 = /*@__PURE__*/new Vector3();
3522
3523         var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
3524
3525
3526         var _v0 = /*@__PURE__*/new Vector3();
3527
3528         var _v1 = /*@__PURE__*/new Vector3();
3529
3530         var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
3531
3532
3533         var _f0 = /*@__PURE__*/new Vector3();
3534
3535         var _f1 = /*@__PURE__*/new Vector3();
3536
3537         var _f2 = /*@__PURE__*/new Vector3();
3538
3539         var _center = /*@__PURE__*/new Vector3();
3540
3541         var _extents = /*@__PURE__*/new Vector3();
3542
3543         var _triangleNormal = /*@__PURE__*/new Vector3();
3544
3545         var _testAxis = /*@__PURE__*/new Vector3();
3546
3547         var _box$1 = /*@__PURE__*/new Box3();
3548
3549         var Sphere = /*#__PURE__*/function () {
3550                 function Sphere(center, radius) {
3551                         this.center = center !== undefined ? center : new Vector3();
3552                         this.radius = radius !== undefined ? radius : -1;
3553                 }
3554
3555                 var _proto = Sphere.prototype;
3556
3557                 _proto.set = function set(center, radius) {
3558                         this.center.copy(center);
3559                         this.radius = radius;
3560                         return this;
3561                 };
3562
3563                 _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
3564                         var center = this.center;
3565
3566                         if (optionalCenter !== undefined) {
3567                                 center.copy(optionalCenter);
3568                         } else {
3569                                 _box$1.setFromPoints(points).getCenter(center);
3570                         }
3571
3572                         var maxRadiusSq = 0;
3573
3574                         for (var i = 0, il = points.length; i < il; i++) {
3575                                 maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
3576                         }
3577
3578                         this.radius = Math.sqrt(maxRadiusSq);
3579                         return this;
3580                 };
3581
3582                 _proto.clone = function clone() {
3583                         return new this.constructor().copy(this);
3584                 };
3585
3586                 _proto.copy = function copy(sphere) {
3587                         this.center.copy(sphere.center);
3588                         this.radius = sphere.radius;
3589                         return this;
3590                 };
3591
3592                 _proto.isEmpty = function isEmpty() {
3593                         return this.radius < 0;
3594                 };
3595
3596                 _proto.makeEmpty = function makeEmpty() {
3597                         this.center.set(0, 0, 0);
3598                         this.radius = -1;
3599                         return this;
3600                 };
3601
3602                 _proto.containsPoint = function containsPoint(point) {
3603                         return point.distanceToSquared(this.center) <= this.radius * this.radius;
3604                 };
3605
3606                 _proto.distanceToPoint = function distanceToPoint(point) {
3607                         return point.distanceTo(this.center) - this.radius;
3608                 };
3609
3610                 _proto.intersectsSphere = function intersectsSphere(sphere) {
3611                         var radiusSum = this.radius + sphere.radius;
3612                         return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
3613                 };
3614
3615                 _proto.intersectsBox = function intersectsBox(box) {
3616                         return box.intersectsSphere(this);
3617                 };
3618
3619                 _proto.intersectsPlane = function intersectsPlane(plane) {
3620                         return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
3621                 };
3622
3623                 _proto.clampPoint = function clampPoint(point, target) {
3624                         var deltaLengthSq = this.center.distanceToSquared(point);
3625
3626                         if (target === undefined) {
3627                                 console.warn('THREE.Sphere: .clampPoint() target is now required');
3628                                 target = new Vector3();
3629                         }
3630
3631                         target.copy(point);
3632
3633                         if (deltaLengthSq > this.radius * this.radius) {
3634                                 target.sub(this.center).normalize();
3635                                 target.multiplyScalar(this.radius).add(this.center);
3636                         }
3637
3638                         return target;
3639                 };
3640
3641                 _proto.getBoundingBox = function getBoundingBox(target) {
3642                         if (target === undefined) {
3643                                 console.warn('THREE.Sphere: .getBoundingBox() target is now required');
3644                                 target = new Box3();
3645                         }
3646
3647                         if (this.isEmpty()) {
3648                                 // Empty sphere produces empty bounding box
3649                                 target.makeEmpty();
3650                                 return target;
3651                         }
3652
3653                         target.set(this.center, this.center);
3654                         target.expandByScalar(this.radius);
3655                         return target;
3656                 };
3657
3658                 _proto.applyMatrix4 = function applyMatrix4(matrix) {
3659                         this.center.applyMatrix4(matrix);
3660                         this.radius = this.radius * matrix.getMaxScaleOnAxis();
3661                         return this;
3662                 };
3663
3664                 _proto.translate = function translate(offset) {
3665                         this.center.add(offset);
3666                         return this;
3667                 };
3668
3669                 _proto.equals = function equals(sphere) {
3670                         return sphere.center.equals(this.center) && sphere.radius === this.radius;
3671                 };
3672
3673                 return Sphere;
3674         }();
3675
3676         var _vector$2 = /*@__PURE__*/new Vector3();
3677
3678         var _segCenter = /*@__PURE__*/new Vector3();
3679
3680         var _segDir = /*@__PURE__*/new Vector3();
3681
3682         var _diff = /*@__PURE__*/new Vector3();
3683
3684         var _edge1 = /*@__PURE__*/new Vector3();
3685
3686         var _edge2 = /*@__PURE__*/new Vector3();
3687
3688         var _normal = /*@__PURE__*/new Vector3();
3689
3690         var Ray = /*#__PURE__*/function () {
3691                 function Ray(origin, direction) {
3692                         this.origin = origin !== undefined ? origin : new Vector3();
3693                         this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
3694                 }
3695
3696                 var _proto = Ray.prototype;
3697
3698                 _proto.set = function set(origin, direction) {
3699                         this.origin.copy(origin);
3700                         this.direction.copy(direction);
3701                         return this;
3702                 };
3703
3704                 _proto.clone = function clone() {
3705                         return new this.constructor().copy(this);
3706                 };
3707
3708                 _proto.copy = function copy(ray) {
3709                         this.origin.copy(ray.origin);
3710                         this.direction.copy(ray.direction);
3711                         return this;
3712                 };
3713
3714                 _proto.at = function at(t, target) {
3715                         if (target === undefined) {
3716                                 console.warn('THREE.Ray: .at() target is now required');
3717                                 target = new Vector3();
3718                         }
3719
3720                         return target.copy(this.direction).multiplyScalar(t).add(this.origin);
3721                 };
3722
3723                 _proto.lookAt = function lookAt(v) {
3724                         this.direction.copy(v).sub(this.origin).normalize();
3725                         return this;
3726                 };
3727
3728                 _proto.recast = function recast(t) {
3729                         this.origin.copy(this.at(t, _vector$2));
3730                         return this;
3731                 };
3732
3733                 _proto.closestPointToPoint = function closestPointToPoint(point, target) {
3734                         if (target === undefined) {
3735                                 console.warn('THREE.Ray: .closestPointToPoint() target is now required');
3736                                 target = new Vector3();
3737                         }
3738
3739                         target.subVectors(point, this.origin);
3740                         var directionDistance = target.dot(this.direction);
3741
3742                         if (directionDistance < 0) {
3743                                 return target.copy(this.origin);
3744                         }
3745
3746                         return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
3747                 };
3748
3749                 _proto.distanceToPoint = function distanceToPoint(point) {
3750                         return Math.sqrt(this.distanceSqToPoint(point));
3751                 };
3752
3753                 _proto.distanceSqToPoint = function distanceSqToPoint(point) {
3754                         var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
3755
3756
3757                         if (directionDistance < 0) {
3758                                 return this.origin.distanceToSquared(point);
3759                         }
3760
3761                         _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
3762
3763                         return _vector$2.distanceToSquared(point);
3764                 };
3765
3766                 _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
3767                         // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
3768                         // It returns the min distance between the ray and the segment
3769                         // defined by v0 and v1
3770                         // It can also set two optional targets :
3771                         // - The closest point on the ray
3772                         // - The closest point on the segment
3773                         _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
3774
3775                         _segDir.copy(v1).sub(v0).normalize();
3776
3777                         _diff.copy(this.origin).sub(_segCenter);
3778
3779                         var segExtent = v0.distanceTo(v1) * 0.5;
3780                         var a01 = -this.direction.dot(_segDir);
3781
3782                         var b0 = _diff.dot(this.direction);
3783
3784                         var b1 = -_diff.dot(_segDir);
3785
3786                         var c = _diff.lengthSq();
3787
3788                         var det = Math.abs(1 - a01 * a01);
3789                         var s0, s1, sqrDist, extDet;
3790
3791                         if (det > 0) {
3792                                 // The ray and segment are not parallel.
3793                                 s0 = a01 * b1 - b0;
3794                                 s1 = a01 * b0 - b1;
3795                                 extDet = segExtent * det;
3796
3797                                 if (s0 >= 0) {
3798                                         if (s1 >= -extDet) {
3799                                                 if (s1 <= extDet) {
3800                                                         // region 0
3801                                                         // Minimum at interior points of ray and segment.
3802                                                         var invDet = 1 / det;
3803                                                         s0 *= invDet;
3804                                                         s1 *= invDet;
3805                                                         sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
3806                                                 } else {
3807                                                         // region 1
3808                                                         s1 = segExtent;
3809                                                         s0 = Math.max(0, -(a01 * s1 + b0));
3810                                                         sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
3811                                                 }
3812                                         } else {
3813                                                 // region 5
3814                                                 s1 = -segExtent;
3815                                                 s0 = Math.max(0, -(a01 * s1 + b0));
3816                                                 sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
3817                                         }
3818                                 } else {
3819                                         if (s1 <= -extDet) {
3820                                                 // region 4
3821                                                 s0 = Math.max(0, -(-a01 * segExtent + b0));
3822                                                 s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
3823                                                 sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
3824                                         } else if (s1 <= extDet) {
3825                                                 // region 3
3826                                                 s0 = 0;
3827                                                 s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
3828                                                 sqrDist = s1 * (s1 + 2 * b1) + c;
3829                                         } else {
3830                                                 // region 2
3831                                                 s0 = Math.max(0, -(a01 * segExtent + b0));
3832                                                 s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
3833                                                 sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
3834                                         }
3835                                 }
3836                         } else {
3837                                 // Ray and segment are parallel.
3838                                 s1 = a01 > 0 ? -segExtent : segExtent;
3839                                 s0 = Math.max(0, -(a01 * s1 + b0));
3840                                 sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
3841                         }
3842
3843                         if (optionalPointOnRay) {
3844                                 optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
3845                         }
3846
3847                         if (optionalPointOnSegment) {
3848                                 optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
3849                         }
3850
3851                         return sqrDist;
3852                 };
3853
3854                 _proto.intersectSphere = function intersectSphere(sphere, target) {
3855                         _vector$2.subVectors(sphere.center, this.origin);
3856
3857                         var tca = _vector$2.dot(this.direction);
3858
3859                         var d2 = _vector$2.dot(_vector$2) - tca * tca;
3860                         var radius2 = sphere.radius * sphere.radius;
3861                         if (d2 > radius2) return null;
3862                         var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
3863
3864                         var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
3865
3866                         var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
3867
3868                         if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
3869                         // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
3870                         // in order to always return an intersect point that is in front of the ray.
3871
3872                         if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
3873
3874                         return this.at(t0, target);
3875                 };
3876
3877                 _proto.intersectsSphere = function intersectsSphere(sphere) {
3878                         return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
3879                 };
3880
3881                 _proto.distanceToPlane = function distanceToPlane(plane) {
3882                         var denominator = plane.normal.dot(this.direction);
3883
3884                         if (denominator === 0) {
3885                                 // line is coplanar, return origin
3886                                 if (plane.distanceToPoint(this.origin) === 0) {
3887                                         return 0;
3888                                 } // Null is preferable to undefined since undefined means.... it is undefined
3889
3890
3891                                 return null;
3892                         }
3893
3894                         var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
3895
3896                         return t >= 0 ? t : null;
3897                 };
3898
3899                 _proto.intersectPlane = function intersectPlane(plane, target) {
3900                         var t = this.distanceToPlane(plane);
3901
3902                         if (t === null) {
3903                                 return null;
3904                         }
3905
3906                         return this.at(t, target);
3907                 };
3908
3909                 _proto.intersectsPlane = function intersectsPlane(plane) {
3910                         // check if the ray lies on the plane first
3911                         var distToPoint = plane.distanceToPoint(this.origin);
3912
3913                         if (distToPoint === 0) {
3914                                 return true;
3915                         }
3916
3917                         var denominator = plane.normal.dot(this.direction);
3918
3919                         if (denominator * distToPoint < 0) {
3920                                 return true;
3921                         } // ray origin is behind the plane (and is pointing behind it)
3922
3923
3924                         return false;
3925                 };
3926
3927                 _proto.intersectBox = function intersectBox(box, target) {
3928                         var tmin, tmax, tymin, tymax, tzmin, tzmax;
3929                         var invdirx = 1 / this.direction.x,
3930                                         invdiry = 1 / this.direction.y,
3931                                         invdirz = 1 / this.direction.z;
3932                         var origin = this.origin;
3933
3934                         if (invdirx >= 0) {
3935                                 tmin = (box.min.x - origin.x) * invdirx;
3936                                 tmax = (box.max.x - origin.x) * invdirx;
3937                         } else {
3938                                 tmin = (box.max.x - origin.x) * invdirx;
3939                                 tmax = (box.min.x - origin.x) * invdirx;
3940                         }
3941
3942                         if (invdiry >= 0) {
3943                                 tymin = (box.min.y - origin.y) * invdiry;
3944                                 tymax = (box.max.y - origin.y) * invdiry;
3945                         } else {
3946                                 tymin = (box.max.y - origin.y) * invdiry;
3947                                 tymax = (box.min.y - origin.y) * invdiry;
3948                         }
3949
3950                         if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
3951                         // (result of 0 * Infinity). x !== x returns true if x is NaN
3952
3953                         if (tymin > tmin || tmin !== tmin) tmin = tymin;
3954                         if (tymax < tmax || tmax !== tmax) tmax = tymax;
3955
3956                         if (invdirz >= 0) {
3957                                 tzmin = (box.min.z - origin.z) * invdirz;
3958                                 tzmax = (box.max.z - origin.z) * invdirz;
3959                         } else {
3960                                 tzmin = (box.max.z - origin.z) * invdirz;
3961                                 tzmax = (box.min.z - origin.z) * invdirz;
3962                         }
3963
3964                         if (tmin > tzmax || tzmin > tmax) return null;
3965                         if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
3966                         if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
3967
3968                         if (tmax < 0) return null;
3969                         return this.at(tmin >= 0 ? tmin : tmax, target);
3970                 };
3971
3972                 _proto.intersectsBox = function intersectsBox(box) {
3973                         return this.intersectBox(box, _vector$2) !== null;
3974                 };
3975
3976                 _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
3977                         // Compute the offset origin, edges, and normal.
3978                         // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
3979                         _edge1.subVectors(b, a);
3980
3981                         _edge2.subVectors(c, a);
3982
3983                         _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
3984                         // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
3985                         //       |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
3986                         //       |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
3987                         //       |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
3988
3989
3990                         var DdN = this.direction.dot(_normal);
3991                         var sign;
3992
3993                         if (DdN > 0) {
3994                                 if (backfaceCulling) return null;
3995                                 sign = 1;
3996                         } else if (DdN < 0) {
3997                                 sign = -1;
3998                                 DdN = -DdN;
3999                         } else {
4000                                 return null;
4001                         }
4002
4003                         _diff.subVectors(this.origin, a);
4004
4005                         var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
4006
4007                         if (DdQxE2 < 0) {
4008                                 return null;
4009                         }
4010
4011                         var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
4012
4013                         if (DdE1xQ < 0) {
4014                                 return null;
4015                         } // b1+b2 > 1, no intersection
4016
4017
4018                         if (DdQxE2 + DdE1xQ > DdN) {
4019                                 return null;
4020                         } // Line intersects triangle, check if ray does.
4021
4022
4023                         var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
4024
4025
4026                         if (QdN < 0) {
4027                                 return null;
4028                         } // Ray intersects triangle.
4029
4030
4031                         return this.at(QdN / DdN, target);
4032                 };
4033
4034                 _proto.applyMatrix4 = function applyMatrix4(matrix4) {
4035                         this.origin.applyMatrix4(matrix4);
4036                         this.direction.transformDirection(matrix4);
4037                         return this;
4038                 };
4039
4040                 _proto.equals = function equals(ray) {
4041                         return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
4042                 };
4043
4044                 return Ray;
4045         }();
4046
4047         var Matrix4 = /*#__PURE__*/function () {
4048                 function Matrix4() {
4049                         Object.defineProperty(this, 'isMatrix4', {
4050                                 value: true
4051                         });
4052                         this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
4053
4054                         if (arguments.length > 0) {
4055                                 console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
4056                         }
4057                 }
4058
4059                 var _proto = Matrix4.prototype;
4060
4061                 _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
4062                         var te = this.elements;
4063                         te[0] = n11;
4064                         te[4] = n12;
4065                         te[8] = n13;
4066                         te[12] = n14;
4067                         te[1] = n21;
4068                         te[5] = n22;
4069                         te[9] = n23;
4070                         te[13] = n24;
4071                         te[2] = n31;
4072                         te[6] = n32;
4073                         te[10] = n33;
4074                         te[14] = n34;
4075                         te[3] = n41;
4076                         te[7] = n42;
4077                         te[11] = n43;
4078                         te[15] = n44;
4079                         return this;
4080                 };
4081
4082                 _proto.identity = function identity() {
4083                         this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
4084                         return this;
4085                 };
4086
4087                 _proto.clone = function clone() {
4088                         return new Matrix4().fromArray(this.elements);
4089                 };
4090
4091                 _proto.copy = function copy(m) {
4092                         var te = this.elements;
4093                         var me = m.elements;
4094                         te[0] = me[0];
4095                         te[1] = me[1];
4096                         te[2] = me[2];
4097                         te[3] = me[3];
4098                         te[4] = me[4];
4099                         te[5] = me[5];
4100                         te[6] = me[6];
4101                         te[7] = me[7];
4102                         te[8] = me[8];
4103                         te[9] = me[9];
4104                         te[10] = me[10];
4105                         te[11] = me[11];
4106                         te[12] = me[12];
4107                         te[13] = me[13];
4108                         te[14] = me[14];
4109                         te[15] = me[15];
4110                         return this;
4111                 };
4112
4113                 _proto.copyPosition = function copyPosition(m) {
4114                         var te = this.elements,
4115                                         me = m.elements;
4116                         te[12] = me[12];
4117                         te[13] = me[13];
4118                         te[14] = me[14];
4119                         return this;
4120                 };
4121
4122                 _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
4123                         xAxis.setFromMatrixColumn(this, 0);
4124                         yAxis.setFromMatrixColumn(this, 1);
4125                         zAxis.setFromMatrixColumn(this, 2);
4126                         return this;
4127                 };
4128
4129                 _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
4130                         this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
4131                         return this;
4132                 };
4133
4134                 _proto.extractRotation = function extractRotation(m) {
4135                         // this method does not support reflection matrices
4136                         var te = this.elements;
4137                         var me = m.elements;
4138
4139                         var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
4140
4141                         var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
4142
4143                         var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
4144
4145                         te[0] = me[0] * scaleX;
4146                         te[1] = me[1] * scaleX;
4147                         te[2] = me[2] * scaleX;
4148                         te[3] = 0;
4149                         te[4] = me[4] * scaleY;
4150                         te[5] = me[5] * scaleY;
4151                         te[6] = me[6] * scaleY;
4152                         te[7] = 0;
4153                         te[8] = me[8] * scaleZ;
4154                         te[9] = me[9] * scaleZ;
4155                         te[10] = me[10] * scaleZ;
4156                         te[11] = 0;
4157                         te[12] = 0;
4158                         te[13] = 0;
4159                         te[14] = 0;
4160                         te[15] = 1;
4161                         return this;
4162                 };
4163
4164                 _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
4165                         if (!(euler && euler.isEuler)) {
4166                                 console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
4167                         }
4168
4169                         var te = this.elements;
4170                         var x = euler.x,
4171                                         y = euler.y,
4172                                         z = euler.z;
4173                         var a = Math.cos(x),
4174                                         b = Math.sin(x);
4175                         var c = Math.cos(y),
4176                                         d = Math.sin(y);
4177                         var e = Math.cos(z),
4178                                         f = Math.sin(z);
4179
4180                         if (euler.order === 'XYZ') {
4181                                 var ae = a * e,
4182                                                 af = a * f,
4183                                                 be = b * e,
4184                                                 bf = b * f;
4185                                 te[0] = c * e;
4186                                 te[4] = -c * f;
4187                                 te[8] = d;
4188                                 te[1] = af + be * d;
4189                                 te[5] = ae - bf * d;
4190                                 te[9] = -b * c;
4191                                 te[2] = bf - ae * d;
4192                                 te[6] = be + af * d;
4193                                 te[10] = a * c;
4194                         } else if (euler.order === 'YXZ') {
4195                                 var ce = c * e,
4196                                                 cf = c * f,
4197                                                 de = d * e,
4198                                                 df = d * f;
4199                                 te[0] = ce + df * b;
4200                                 te[4] = de * b - cf;
4201                                 te[8] = a * d;
4202                                 te[1] = a * f;
4203                                 te[5] = a * e;
4204                                 te[9] = -b;
4205                                 te[2] = cf * b - de;
4206                                 te[6] = df + ce * b;
4207                                 te[10] = a * c;
4208                         } else if (euler.order === 'ZXY') {
4209                                 var _ce = c * e,
4210                                                 _cf = c * f,
4211                                                 _de = d * e,
4212                                                 _df = d * f;
4213
4214                                 te[0] = _ce - _df * b;
4215                                 te[4] = -a * f;
4216                                 te[8] = _de + _cf * b;
4217                                 te[1] = _cf + _de * b;
4218                                 te[5] = a * e;
4219                                 te[9] = _df - _ce * b;
4220                                 te[2] = -a * d;
4221                                 te[6] = b;
4222                                 te[10] = a * c;
4223                         } else if (euler.order === 'ZYX') {
4224                                 var _ae = a * e,
4225                                                 _af = a * f,
4226                                                 _be = b * e,
4227                                                 _bf = b * f;
4228
4229                                 te[0] = c * e;
4230                                 te[4] = _be * d - _af;
4231                                 te[8] = _ae * d + _bf;
4232                                 te[1] = c * f;
4233                                 te[5] = _bf * d + _ae;
4234                                 te[9] = _af * d - _be;
4235                                 te[2] = -d;
4236                                 te[6] = b * c;
4237                                 te[10] = a * c;
4238                         } else if (euler.order === 'YZX') {
4239                                 var ac = a * c,
4240                                                 ad = a * d,
4241                                                 bc = b * c,
4242                                                 bd = b * d;
4243                                 te[0] = c * e;
4244                                 te[4] = bd - ac * f;
4245                                 te[8] = bc * f + ad;
4246                                 te[1] = f;
4247                                 te[5] = a * e;
4248                                 te[9] = -b * e;
4249                                 te[2] = -d * e;
4250                                 te[6] = ad * f + bc;
4251                                 te[10] = ac - bd * f;
4252                         } else if (euler.order === 'XZY') {
4253                                 var _ac = a * c,
4254                                                 _ad = a * d,
4255                                                 _bc = b * c,
4256                                                 _bd = b * d;
4257
4258                                 te[0] = c * e;
4259                                 te[4] = -f;
4260                                 te[8] = d * e;
4261                                 te[1] = _ac * f + _bd;
4262                                 te[5] = a * e;
4263                                 te[9] = _ad * f - _bc;
4264                                 te[2] = _bc * f - _ad;
4265                                 te[6] = b * e;
4266                                 te[10] = _bd * f + _ac;
4267                         } // bottom row
4268
4269
4270                         te[3] = 0;
4271                         te[7] = 0;
4272                         te[11] = 0; // last column
4273
4274                         te[12] = 0;
4275                         te[13] = 0;
4276                         te[14] = 0;
4277                         te[15] = 1;
4278                         return this;
4279                 };
4280
4281                 _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
4282                         return this.compose(_zero, q, _one);
4283                 };
4284
4285                 _proto.lookAt = function lookAt(eye, target, up) {
4286                         var te = this.elements;
4287
4288                         _z.subVectors(eye, target);
4289
4290                         if (_z.lengthSq() === 0) {
4291                                 // eye and target are in the same position
4292                                 _z.z = 1;
4293                         }
4294
4295                         _z.normalize();
4296
4297                         _x.crossVectors(up, _z);
4298
4299                         if (_x.lengthSq() === 0) {
4300                                 // up and z are parallel
4301                                 if (Math.abs(up.z) === 1) {
4302                                         _z.x += 0.0001;
4303                                 } else {
4304                                         _z.z += 0.0001;
4305                                 }
4306
4307                                 _z.normalize();
4308
4309                                 _x.crossVectors(up, _z);
4310                         }
4311
4312                         _x.normalize();
4313
4314                         _y.crossVectors(_z, _x);
4315
4316                         te[0] = _x.x;
4317                         te[4] = _y.x;
4318                         te[8] = _z.x;
4319                         te[1] = _x.y;
4320                         te[5] = _y.y;
4321                         te[9] = _z.y;
4322                         te[2] = _x.z;
4323                         te[6] = _y.z;
4324                         te[10] = _z.z;
4325                         return this;
4326                 };
4327
4328                 _proto.multiply = function multiply(m, n) {
4329                         if (n !== undefined) {
4330                                 console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
4331                                 return this.multiplyMatrices(m, n);
4332                         }
4333
4334                         return this.multiplyMatrices(this, m);
4335                 };
4336
4337                 _proto.premultiply = function premultiply(m) {
4338                         return this.multiplyMatrices(m, this);
4339                 };
4340
4341                 _proto.multiplyMatrices = function multiplyMatrices(a, b) {
4342                         var ae = a.elements;
4343                         var be = b.elements;
4344                         var te = this.elements;
4345                         var a11 = ae[0],
4346                                         a12 = ae[4],
4347                                         a13 = ae[8],
4348                                         a14 = ae[12];
4349                         var a21 = ae[1],
4350                                         a22 = ae[5],
4351                                         a23 = ae[9],
4352                                         a24 = ae[13];
4353                         var a31 = ae[2],
4354                                         a32 = ae[6],
4355                                         a33 = ae[10],
4356                                         a34 = ae[14];
4357                         var a41 = ae[3],
4358                                         a42 = ae[7],
4359                                         a43 = ae[11],
4360                                         a44 = ae[15];
4361                         var b11 = be[0],
4362                                         b12 = be[4],
4363                                         b13 = be[8],
4364                                         b14 = be[12];
4365                         var b21 = be[1],
4366                                         b22 = be[5],
4367                                         b23 = be[9],
4368                                         b24 = be[13];
4369                         var b31 = be[2],
4370                                         b32 = be[6],
4371                                         b33 = be[10],
4372                                         b34 = be[14];
4373                         var b41 = be[3],
4374                                         b42 = be[7],
4375                                         b43 = be[11],
4376                                         b44 = be[15];
4377                         te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
4378                         te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
4379                         te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
4380                         te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
4381                         te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
4382                         te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
4383                         te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
4384                         te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
4385                         te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
4386                         te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
4387                         te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
4388                         te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
4389                         te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
4390                         te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
4391                         te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
4392                         te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
4393                         return this;
4394                 };
4395
4396                 _proto.multiplyScalar = function multiplyScalar(s) {
4397                         var te = this.elements;
4398                         te[0] *= s;
4399                         te[4] *= s;
4400                         te[8] *= s;
4401                         te[12] *= s;
4402                         te[1] *= s;
4403                         te[5] *= s;
4404                         te[9] *= s;
4405                         te[13] *= s;
4406                         te[2] *= s;
4407                         te[6] *= s;
4408                         te[10] *= s;
4409                         te[14] *= s;
4410                         te[3] *= s;
4411                         te[7] *= s;
4412                         te[11] *= s;
4413                         te[15] *= s;
4414                         return this;
4415                 };
4416
4417                 _proto.determinant = function determinant() {
4418                         var te = this.elements;
4419                         var n11 = te[0],
4420                                         n12 = te[4],
4421                                         n13 = te[8],
4422                                         n14 = te[12];
4423                         var n21 = te[1],
4424                                         n22 = te[5],
4425                                         n23 = te[9],
4426                                         n24 = te[13];
4427                         var n31 = te[2],
4428                                         n32 = te[6],
4429                                         n33 = te[10],
4430                                         n34 = te[14];
4431                         var n41 = te[3],
4432                                         n42 = te[7],
4433                                         n43 = te[11],
4434                                         n44 = te[15]; //TODO: make this more efficient
4435                         //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
4436
4437                         return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
4438                 };
4439
4440                 _proto.transpose = function transpose() {
4441                         var te = this.elements;
4442                         var tmp;
4443                         tmp = te[1];
4444                         te[1] = te[4];
4445                         te[4] = tmp;
4446                         tmp = te[2];
4447                         te[2] = te[8];
4448                         te[8] = tmp;
4449                         tmp = te[6];
4450                         te[6] = te[9];
4451                         te[9] = tmp;
4452                         tmp = te[3];
4453                         te[3] = te[12];
4454                         te[12] = tmp;
4455                         tmp = te[7];
4456                         te[7] = te[13];
4457                         te[13] = tmp;
4458                         tmp = te[11];
4459                         te[11] = te[14];
4460                         te[14] = tmp;
4461                         return this;
4462                 };
4463
4464                 _proto.setPosition = function setPosition(x, y, z) {
4465                         var te = this.elements;
4466
4467                         if (x.isVector3) {
4468                                 te[12] = x.x;
4469                                 te[13] = x.y;
4470                                 te[14] = x.z;
4471                         } else {
4472                                 te[12] = x;
4473                                 te[13] = y;
4474                                 te[14] = z;
4475                         }
4476
4477                         return this;
4478                 };
4479
4480                 _proto.invert = function invert() {
4481                         // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
4482                         var te = this.elements,
4483                                         n11 = te[0],
4484                                         n21 = te[1],
4485                                         n31 = te[2],
4486                                         n41 = te[3],
4487                                         n12 = te[4],
4488                                         n22 = te[5],
4489                                         n32 = te[6],
4490                                         n42 = te[7],
4491                                         n13 = te[8],
4492                                         n23 = te[9],
4493                                         n33 = te[10],
4494                                         n43 = te[11],
4495                                         n14 = te[12],
4496                                         n24 = te[13],
4497                                         n34 = te[14],
4498                                         n44 = te[15],
4499                                         t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
4500                                         t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
4501                                         t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
4502                                         t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
4503                         var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
4504                         if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4505                         var detInv = 1 / det;
4506                         te[0] = t11 * detInv;
4507                         te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
4508                         te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
4509                         te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
4510                         te[4] = t12 * detInv;
4511                         te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
4512                         te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
4513                         te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
4514                         te[8] = t13 * detInv;
4515                         te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
4516                         te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
4517                         te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
4518                         te[12] = t14 * detInv;
4519                         te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
4520                         te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
4521                         te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
4522                         return this;
4523                 };
4524
4525                 _proto.scale = function scale(v) {
4526                         var te = this.elements;
4527                         var x = v.x,
4528                                         y = v.y,
4529                                         z = v.z;
4530                         te[0] *= x;
4531                         te[4] *= y;
4532                         te[8] *= z;
4533                         te[1] *= x;
4534                         te[5] *= y;
4535                         te[9] *= z;
4536                         te[2] *= x;
4537                         te[6] *= y;
4538                         te[10] *= z;
4539                         te[3] *= x;
4540                         te[7] *= y;
4541                         te[11] *= z;
4542                         return this;
4543                 };
4544
4545                 _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
4546                         var te = this.elements;
4547                         var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
4548                         var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
4549                         var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
4550                         return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
4551                 };
4552
4553                 _proto.makeTranslation = function makeTranslation(x, y, z) {
4554                         this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
4555                         return this;
4556                 };
4557
4558                 _proto.makeRotationX = function makeRotationX(theta) {
4559                         var c = Math.cos(theta),
4560                                         s = Math.sin(theta);
4561                         this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
4562                         return this;
4563                 };
4564
4565                 _proto.makeRotationY = function makeRotationY(theta) {
4566                         var c = Math.cos(theta),
4567                                         s = Math.sin(theta);
4568                         this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
4569                         return this;
4570                 };
4571
4572                 _proto.makeRotationZ = function makeRotationZ(theta) {
4573                         var c = Math.cos(theta),
4574                                         s = Math.sin(theta);
4575                         this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
4576                         return this;
4577                 };
4578
4579                 _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
4580                         // Based on http://www.gamedev.net/reference/articles/article1199.asp
4581                         var c = Math.cos(angle);
4582                         var s = Math.sin(angle);
4583                         var t = 1 - c;
4584                         var x = axis.x,
4585                                         y = axis.y,
4586                                         z = axis.z;
4587                         var tx = t * x,
4588                                         ty = t * y;
4589                         this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
4590                         return this;
4591                 };
4592
4593                 _proto.makeScale = function makeScale(x, y, z) {
4594                         this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
4595                         return this;
4596                 };
4597
4598                 _proto.makeShear = function makeShear(x, y, z) {
4599                         this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
4600                         return this;
4601                 };
4602
4603                 _proto.compose = function compose(position, quaternion, scale) {
4604                         var te = this.elements;
4605                         var x = quaternion._x,
4606                                         y = quaternion._y,
4607                                         z = quaternion._z,
4608                                         w = quaternion._w;
4609                         var x2 = x + x,
4610                                         y2 = y + y,
4611                                         z2 = z + z;
4612                         var xx = x * x2,
4613                                         xy = x * y2,
4614                                         xz = x * z2;
4615                         var yy = y * y2,
4616                                         yz = y * z2,
4617                                         zz = z * z2;
4618                         var wx = w * x2,
4619                                         wy = w * y2,
4620                                         wz = w * z2;
4621                         var sx = scale.x,
4622                                         sy = scale.y,
4623                                         sz = scale.z;
4624                         te[0] = (1 - (yy + zz)) * sx;
4625                         te[1] = (xy + wz) * sx;
4626                         te[2] = (xz - wy) * sx;
4627                         te[3] = 0;
4628                         te[4] = (xy - wz) * sy;
4629                         te[5] = (1 - (xx + zz)) * sy;
4630                         te[6] = (yz + wx) * sy;
4631                         te[7] = 0;
4632                         te[8] = (xz + wy) * sz;
4633                         te[9] = (yz - wx) * sz;
4634                         te[10] = (1 - (xx + yy)) * sz;
4635                         te[11] = 0;
4636                         te[12] = position.x;
4637                         te[13] = position.y;
4638                         te[14] = position.z;
4639                         te[15] = 1;
4640                         return this;
4641                 };
4642
4643                 _proto.decompose = function decompose(position, quaternion, scale) {
4644                         var te = this.elements;
4645
4646                         var sx = _v1$1.set(te[0], te[1], te[2]).length();
4647
4648                         var sy = _v1$1.set(te[4], te[5], te[6]).length();
4649
4650                         var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
4651
4652
4653                         var det = this.determinant();
4654                         if (det < 0) sx = -sx;
4655                         position.x = te[12];
4656                         position.y = te[13];
4657                         position.z = te[14]; // scale the rotation part
4658
4659                         _m1.copy(this);
4660
4661                         var invSX = 1 / sx;
4662                         var invSY = 1 / sy;
4663                         var invSZ = 1 / sz;
4664                         _m1.elements[0] *= invSX;
4665                         _m1.elements[1] *= invSX;
4666                         _m1.elements[2] *= invSX;
4667                         _m1.elements[4] *= invSY;
4668                         _m1.elements[5] *= invSY;
4669                         _m1.elements[6] *= invSY;
4670                         _m1.elements[8] *= invSZ;
4671                         _m1.elements[9] *= invSZ;
4672                         _m1.elements[10] *= invSZ;
4673                         quaternion.setFromRotationMatrix(_m1);
4674                         scale.x = sx;
4675                         scale.y = sy;
4676                         scale.z = sz;
4677                         return this;
4678                 };
4679
4680                 _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
4681                         if (far === undefined) {
4682                                 console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
4683                         }
4684
4685                         var te = this.elements;
4686                         var x = 2 * near / (right - left);
4687                         var y = 2 * near / (top - bottom);
4688                         var a = (right + left) / (right - left);
4689                         var b = (top + bottom) / (top - bottom);
4690                         var c = -(far + near) / (far - near);
4691                         var d = -2 * far * near / (far - near);
4692                         te[0] = x;
4693                         te[4] = 0;
4694                         te[8] = a;
4695                         te[12] = 0;
4696                         te[1] = 0;
4697                         te[5] = y;
4698                         te[9] = b;
4699                         te[13] = 0;
4700                         te[2] = 0;
4701                         te[6] = 0;
4702                         te[10] = c;
4703                         te[14] = d;
4704                         te[3] = 0;
4705                         te[7] = 0;
4706                         te[11] = -1;
4707                         te[15] = 0;
4708                         return this;
4709                 };
4710
4711                 _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
4712                         var te = this.elements;
4713                         var w = 1.0 / (right - left);
4714                         var h = 1.0 / (top - bottom);
4715                         var p = 1.0 / (far - near);
4716                         var x = (right + left) * w;
4717                         var y = (top + bottom) * h;
4718                         var z = (far + near) * p;
4719                         te[0] = 2 * w;
4720                         te[4] = 0;
4721                         te[8] = 0;
4722                         te[12] = -x;
4723                         te[1] = 0;
4724                         te[5] = 2 * h;
4725                         te[9] = 0;
4726                         te[13] = -y;
4727                         te[2] = 0;
4728                         te[6] = 0;
4729                         te[10] = -2 * p;
4730                         te[14] = -z;
4731                         te[3] = 0;
4732                         te[7] = 0;
4733                         te[11] = 0;
4734                         te[15] = 1;
4735                         return this;
4736                 };
4737
4738                 _proto.equals = function equals(matrix) {
4739                         var te = this.elements;
4740                         var me = matrix.elements;
4741
4742                         for (var i = 0; i < 16; i++) {
4743                                 if (te[i] !== me[i]) return false;
4744                         }
4745
4746                         return true;
4747                 };
4748
4749                 _proto.fromArray = function fromArray(array, offset) {
4750                         if (offset === void 0) {
4751                                 offset = 0;
4752                         }
4753
4754                         for (var i = 0; i < 16; i++) {
4755                                 this.elements[i] = array[i + offset];
4756                         }
4757
4758                         return this;
4759                 };
4760
4761                 _proto.toArray = function toArray(array, offset) {
4762                         if (array === void 0) {
4763                                 array = [];
4764                         }
4765
4766                         if (offset === void 0) {
4767                                 offset = 0;
4768                         }
4769
4770                         var te = this.elements;
4771                         array[offset] = te[0];
4772                         array[offset + 1] = te[1];
4773                         array[offset + 2] = te[2];
4774                         array[offset + 3] = te[3];
4775                         array[offset + 4] = te[4];
4776                         array[offset + 5] = te[5];
4777                         array[offset + 6] = te[6];
4778                         array[offset + 7] = te[7];
4779                         array[offset + 8] = te[8];
4780                         array[offset + 9] = te[9];
4781                         array[offset + 10] = te[10];
4782                         array[offset + 11] = te[11];
4783                         array[offset + 12] = te[12];
4784                         array[offset + 13] = te[13];
4785                         array[offset + 14] = te[14];
4786                         array[offset + 15] = te[15];
4787                         return array;
4788                 };
4789
4790                 return Matrix4;
4791         }();
4792
4793         var _v1$1 = /*@__PURE__*/new Vector3();
4794
4795         var _m1 = /*@__PURE__*/new Matrix4();
4796
4797         var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
4798
4799         var _one = /*@__PURE__*/new Vector3(1, 1, 1);
4800
4801         var _x = /*@__PURE__*/new Vector3();
4802
4803         var _y = /*@__PURE__*/new Vector3();
4804
4805         var _z = /*@__PURE__*/new Vector3();
4806
4807         var Euler = /*#__PURE__*/function () {
4808                 function Euler(x, y, z, order) {
4809                         if (x === void 0) {
4810                                 x = 0;
4811                         }
4812
4813                         if (y === void 0) {
4814                                 y = 0;
4815                         }
4816
4817                         if (z === void 0) {
4818                                 z = 0;
4819                         }
4820
4821                         if (order === void 0) {
4822                                 order = Euler.DefaultOrder;
4823                         }
4824
4825                         Object.defineProperty(this, 'isEuler', {
4826                                 value: true
4827                         });
4828                         this._x = x;
4829                         this._y = y;
4830                         this._z = z;
4831                         this._order = order;
4832                 }
4833
4834                 var _proto = Euler.prototype;
4835
4836                 _proto.set = function set(x, y, z, order) {
4837                         this._x = x;
4838                         this._y = y;
4839                         this._z = z;
4840                         this._order = order || this._order;
4841
4842                         this._onChangeCallback();
4843
4844                         return this;
4845                 };
4846
4847                 _proto.clone = function clone() {
4848                         return new this.constructor(this._x, this._y, this._z, this._order);
4849                 };
4850
4851                 _proto.copy = function copy(euler) {
4852                         this._x = euler._x;
4853                         this._y = euler._y;
4854                         this._z = euler._z;
4855                         this._order = euler._order;
4856
4857                         this._onChangeCallback();
4858
4859                         return this;
4860                 };
4861
4862                 _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
4863                         var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
4864
4865                         var te = m.elements;
4866                         var m11 = te[0],
4867                                         m12 = te[4],
4868                                         m13 = te[8];
4869                         var m21 = te[1],
4870                                         m22 = te[5],
4871                                         m23 = te[9];
4872                         var m31 = te[2],
4873                                         m32 = te[6],
4874                                         m33 = te[10];
4875                         order = order || this._order;
4876
4877                         switch (order) {
4878                                 case 'XYZ':
4879                                         this._y = Math.asin(clamp(m13, -1, 1));
4880
4881                                         if (Math.abs(m13) < 0.9999999) {
4882                                                 this._x = Math.atan2(-m23, m33);
4883                                                 this._z = Math.atan2(-m12, m11);
4884                                         } else {
4885                                                 this._x = Math.atan2(m32, m22);
4886                                                 this._z = 0;
4887                                         }
4888
4889                                         break;
4890
4891                                 case 'YXZ':
4892                                         this._x = Math.asin(-clamp(m23, -1, 1));
4893
4894                                         if (Math.abs(m23) < 0.9999999) {
4895                                                 this._y = Math.atan2(m13, m33);
4896                                                 this._z = Math.atan2(m21, m22);
4897                                         } else {
4898                                                 this._y = Math.atan2(-m31, m11);
4899                                                 this._z = 0;
4900                                         }
4901
4902                                         break;
4903
4904                                 case 'ZXY':
4905                                         this._x = Math.asin(clamp(m32, -1, 1));
4906
4907                                         if (Math.abs(m32) < 0.9999999) {
4908                                                 this._y = Math.atan2(-m31, m33);
4909                                                 this._z = Math.atan2(-m12, m22);
4910                                         } else {
4911                                                 this._y = 0;
4912                                                 this._z = Math.atan2(m21, m11);
4913                                         }
4914
4915                                         break;
4916
4917                                 case 'ZYX':
4918                                         this._y = Math.asin(-clamp(m31, -1, 1));
4919
4920                                         if (Math.abs(m31) < 0.9999999) {
4921                                                 this._x = Math.atan2(m32, m33);
4922                                                 this._z = Math.atan2(m21, m11);
4923                                         } else {
4924                                                 this._x = 0;
4925                                                 this._z = Math.atan2(-m12, m22);
4926                                         }
4927
4928                                         break;
4929
4930                                 case 'YZX':
4931                                         this._z = Math.asin(clamp(m21, -1, 1));
4932
4933                                         if (Math.abs(m21) < 0.9999999) {
4934                                                 this._x = Math.atan2(-m23, m22);
4935                                                 this._y = Math.atan2(-m31, m11);
4936                                         } else {
4937                                                 this._x = 0;
4938                                                 this._y = Math.atan2(m13, m33);
4939                                         }
4940
4941                                         break;
4942
4943                                 case 'XZY':
4944                                         this._z = Math.asin(-clamp(m12, -1, 1));
4945
4946                                         if (Math.abs(m12) < 0.9999999) {
4947                                                 this._x = Math.atan2(m32, m22);
4948                                                 this._y = Math.atan2(m13, m11);
4949                                         } else {
4950                                                 this._x = Math.atan2(-m23, m33);
4951                                                 this._y = 0;
4952                                         }
4953
4954                                         break;
4955
4956                                 default:
4957                                         console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
4958                         }
4959
4960                         this._order = order;
4961                         if (update !== false) this._onChangeCallback();
4962                         return this;
4963                 };
4964
4965                 _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
4966                         _matrix.makeRotationFromQuaternion(q);
4967
4968                         return this.setFromRotationMatrix(_matrix, order, update);
4969                 };
4970
4971                 _proto.setFromVector3 = function setFromVector3(v, order) {
4972                         return this.set(v.x, v.y, v.z, order || this._order);
4973                 };
4974
4975                 _proto.reorder = function reorder(newOrder) {
4976                         // WARNING: this discards revolution information -bhouston
4977                         _quaternion$1.setFromEuler(this);
4978
4979                         return this.setFromQuaternion(_quaternion$1, newOrder);
4980                 };
4981
4982                 _proto.equals = function equals(euler) {
4983                         return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
4984                 };
4985
4986                 _proto.fromArray = function fromArray(array) {
4987                         this._x = array[0];
4988                         this._y = array[1];
4989                         this._z = array[2];
4990                         if (array[3] !== undefined) this._order = array[3];
4991
4992                         this._onChangeCallback();
4993
4994                         return this;
4995                 };
4996
4997                 _proto.toArray = function toArray(array, offset) {
4998                         if (array === void 0) {
4999                                 array = [];
5000                         }
5001
5002                         if (offset === void 0) {
5003                                 offset = 0;
5004                         }
5005
5006                         array[offset] = this._x;
5007                         array[offset + 1] = this._y;
5008                         array[offset + 2] = this._z;
5009                         array[offset + 3] = this._order;
5010                         return array;
5011                 };
5012
5013                 _proto.toVector3 = function toVector3(optionalResult) {
5014                         if (optionalResult) {
5015                                 return optionalResult.set(this._x, this._y, this._z);
5016                         } else {
5017                                 return new Vector3(this._x, this._y, this._z);
5018                         }
5019                 };
5020
5021                 _proto._onChange = function _onChange(callback) {
5022                         this._onChangeCallback = callback;
5023                         return this;
5024                 };
5025
5026                 _proto._onChangeCallback = function _onChangeCallback() {};
5027
5028                 _createClass(Euler, [{
5029                         key: "x",
5030                         get: function get() {
5031                                 return this._x;
5032                         },
5033                         set: function set(value) {
5034                                 this._x = value;
5035
5036                                 this._onChangeCallback();
5037                         }
5038                 }, {
5039                         key: "y",
5040                         get: function get() {
5041                                 return this._y;
5042                         },
5043                         set: function set(value) {
5044                                 this._y = value;
5045
5046                                 this._onChangeCallback();
5047                         }
5048                 }, {
5049                         key: "z",
5050                         get: function get() {
5051                                 return this._z;
5052                         },
5053                         set: function set(value) {
5054                                 this._z = value;
5055
5056                                 this._onChangeCallback();
5057                         }
5058                 }, {
5059                         key: "order",
5060                         get: function get() {
5061                                 return this._order;
5062                         },
5063                         set: function set(value) {
5064                                 this._order = value;
5065
5066                                 this._onChangeCallback();
5067                         }
5068                 }]);
5069
5070                 return Euler;
5071         }();
5072
5073         Euler.DefaultOrder = 'XYZ';
5074         Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
5075
5076         var _matrix = /*@__PURE__*/new Matrix4();
5077
5078         var _quaternion$1 = /*@__PURE__*/new Quaternion();
5079
5080         var Layers = /*#__PURE__*/function () {
5081                 function Layers() {
5082                         this.mask = 1 | 0;
5083                 }
5084
5085                 var _proto = Layers.prototype;
5086
5087                 _proto.set = function set(channel) {
5088                         this.mask = 1 << channel | 0;
5089                 };
5090
5091                 _proto.enable = function enable(channel) {
5092                         this.mask |= 1 << channel | 0;
5093                 };
5094
5095                 _proto.enableAll = function enableAll() {
5096                         this.mask = 0xffffffff | 0;
5097                 };
5098
5099                 _proto.toggle = function toggle(channel) {
5100                         this.mask ^= 1 << channel | 0;
5101                 };
5102
5103                 _proto.disable = function disable(channel) {
5104                         this.mask &= ~(1 << channel | 0);
5105                 };
5106
5107                 _proto.disableAll = function disableAll() {
5108                         this.mask = 0;
5109                 };
5110
5111                 _proto.test = function test(layers) {
5112                         return (this.mask & layers.mask) !== 0;
5113                 };
5114
5115                 return Layers;
5116         }();
5117
5118         var _object3DId = 0;
5119
5120         var _v1$2 = new Vector3();
5121
5122         var _q1 = new Quaternion();
5123
5124         var _m1$1 = new Matrix4();
5125
5126         var _target = new Vector3();
5127
5128         var _position = new Vector3();
5129
5130         var _scale = new Vector3();
5131
5132         var _quaternion$2 = new Quaternion();
5133
5134         var _xAxis = new Vector3(1, 0, 0);
5135
5136         var _yAxis = new Vector3(0, 1, 0);
5137
5138         var _zAxis = new Vector3(0, 0, 1);
5139
5140         var _addedEvent = {
5141                 type: 'added'
5142         };
5143         var _removedEvent = {
5144                 type: 'removed'
5145         };
5146
5147         function Object3D() {
5148                 Object.defineProperty(this, 'id', {
5149                         value: _object3DId++
5150                 });
5151                 this.uuid = MathUtils.generateUUID();
5152                 this.name = '';
5153                 this.type = 'Object3D';
5154                 this.parent = null;
5155                 this.children = [];
5156                 this.up = Object3D.DefaultUp.clone();
5157                 var position = new Vector3();
5158                 var rotation = new Euler();
5159                 var quaternion = new Quaternion();
5160                 var scale = new Vector3(1, 1, 1);
5161
5162                 function onRotationChange() {
5163                         quaternion.setFromEuler(rotation, false);
5164                 }
5165
5166                 function onQuaternionChange() {
5167                         rotation.setFromQuaternion(quaternion, undefined, false);
5168                 }
5169
5170                 rotation._onChange(onRotationChange);
5171
5172                 quaternion._onChange(onQuaternionChange);
5173
5174                 Object.defineProperties(this, {
5175                         position: {
5176                                 configurable: true,
5177                                 enumerable: true,
5178                                 value: position
5179                         },
5180                         rotation: {
5181                                 configurable: true,
5182                                 enumerable: true,
5183                                 value: rotation
5184                         },
5185                         quaternion: {
5186                                 configurable: true,
5187                                 enumerable: true,
5188                                 value: quaternion
5189                         },
5190                         scale: {
5191                                 configurable: true,
5192                                 enumerable: true,
5193                                 value: scale
5194                         },
5195                         modelViewMatrix: {
5196                                 value: new Matrix4()
5197                         },
5198                         normalMatrix: {
5199                                 value: new Matrix3()
5200                         }
5201                 });
5202                 this.matrix = new Matrix4();
5203                 this.matrixWorld = new Matrix4();
5204                 this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
5205                 this.matrixWorldNeedsUpdate = false;
5206                 this.layers = new Layers();
5207                 this.visible = true;
5208                 this.castShadow = false;
5209                 this.receiveShadow = false;
5210                 this.frustumCulled = true;
5211                 this.renderOrder = 0;
5212                 this.animations = [];
5213                 this.userData = {};
5214         }
5215
5216         Object3D.DefaultUp = new Vector3(0, 1, 0);
5217         Object3D.DefaultMatrixAutoUpdate = true;
5218         Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
5219                 constructor: Object3D,
5220                 isObject3D: true,
5221                 onBeforeRender: function onBeforeRender() {},
5222                 onAfterRender: function onAfterRender() {},
5223                 applyMatrix4: function applyMatrix4(matrix) {
5224                         if (this.matrixAutoUpdate) this.updateMatrix();
5225                         this.matrix.premultiply(matrix);
5226                         this.matrix.decompose(this.position, this.quaternion, this.scale);
5227                 },
5228                 applyQuaternion: function applyQuaternion(q) {
5229                         this.quaternion.premultiply(q);
5230                         return this;
5231                 },
5232                 setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
5233                         // assumes axis is normalized
5234                         this.quaternion.setFromAxisAngle(axis, angle);
5235                 },
5236                 setRotationFromEuler: function setRotationFromEuler(euler) {
5237                         this.quaternion.setFromEuler(euler, true);
5238                 },
5239                 setRotationFromMatrix: function setRotationFromMatrix(m) {
5240                         // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
5241                         this.quaternion.setFromRotationMatrix(m);
5242                 },
5243                 setRotationFromQuaternion: function setRotationFromQuaternion(q) {
5244                         // assumes q is normalized
5245                         this.quaternion.copy(q);
5246                 },
5247                 rotateOnAxis: function rotateOnAxis(axis, angle) {
5248                         // rotate object on axis in object space
5249                         // axis is assumed to be normalized
5250                         _q1.setFromAxisAngle(axis, angle);
5251
5252                         this.quaternion.multiply(_q1);
5253                         return this;
5254                 },
5255                 rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
5256                         // rotate object on axis in world space
5257                         // axis is assumed to be normalized
5258                         // method assumes no rotated parent
5259                         _q1.setFromAxisAngle(axis, angle);
5260
5261                         this.quaternion.premultiply(_q1);
5262                         return this;
5263                 },
5264                 rotateX: function rotateX(angle) {
5265                         return this.rotateOnAxis(_xAxis, angle);
5266                 },
5267                 rotateY: function rotateY(angle) {
5268                         return this.rotateOnAxis(_yAxis, angle);
5269                 },
5270                 rotateZ: function rotateZ(angle) {
5271                         return this.rotateOnAxis(_zAxis, angle);
5272                 },
5273                 translateOnAxis: function translateOnAxis(axis, distance) {
5274                         // translate object by distance along axis in object space
5275                         // axis is assumed to be normalized
5276                         _v1$2.copy(axis).applyQuaternion(this.quaternion);
5277
5278                         this.position.add(_v1$2.multiplyScalar(distance));
5279                         return this;
5280                 },
5281                 translateX: function translateX(distance) {
5282                         return this.translateOnAxis(_xAxis, distance);
5283                 },
5284                 translateY: function translateY(distance) {
5285                         return this.translateOnAxis(_yAxis, distance);
5286                 },
5287                 translateZ: function translateZ(distance) {
5288                         return this.translateOnAxis(_zAxis, distance);
5289                 },
5290                 localToWorld: function localToWorld(vector) {
5291                         return vector.applyMatrix4(this.matrixWorld);
5292                 },
5293                 worldToLocal: function worldToLocal(vector) {
5294                         return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
5295                 },
5296                 lookAt: function lookAt(x, y, z) {
5297                         // This method does not support objects having non-uniformly-scaled parent(s)
5298                         if (x.isVector3) {
5299                                 _target.copy(x);
5300                         } else {
5301                                 _target.set(x, y, z);
5302                         }
5303
5304                         var parent = this.parent;
5305                         this.updateWorldMatrix(true, false);
5306
5307                         _position.setFromMatrixPosition(this.matrixWorld);
5308
5309                         if (this.isCamera || this.isLight) {
5310                                 _m1$1.lookAt(_position, _target, this.up);
5311                         } else {
5312                                 _m1$1.lookAt(_target, _position, this.up);
5313                         }
5314
5315                         this.quaternion.setFromRotationMatrix(_m1$1);
5316
5317                         if (parent) {
5318                                 _m1$1.extractRotation(parent.matrixWorld);
5319
5320                                 _q1.setFromRotationMatrix(_m1$1);
5321
5322                                 this.quaternion.premultiply(_q1.invert());
5323                         }
5324                 },
5325                 add: function add(object) {
5326                         if (arguments.length > 1) {
5327                                 for (var i = 0; i < arguments.length; i++) {
5328                                         this.add(arguments[i]);
5329                                 }
5330
5331                                 return this;
5332                         }
5333
5334                         if (object === this) {
5335                                 console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
5336                                 return this;
5337                         }
5338
5339                         if (object && object.isObject3D) {
5340                                 if (object.parent !== null) {
5341                                         object.parent.remove(object);
5342                                 }
5343
5344                                 object.parent = this;
5345                                 this.children.push(object);
5346                                 object.dispatchEvent(_addedEvent);
5347                         } else {
5348                                 console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
5349                         }
5350
5351                         return this;
5352                 },
5353                 remove: function remove(object) {
5354                         if (arguments.length > 1) {
5355                                 for (var i = 0; i < arguments.length; i++) {
5356                                         this.remove(arguments[i]);
5357                                 }
5358
5359                                 return this;
5360                         }
5361
5362                         var index = this.children.indexOf(object);
5363
5364                         if (index !== -1) {
5365                                 object.parent = null;
5366                                 this.children.splice(index, 1);
5367                                 object.dispatchEvent(_removedEvent);
5368                         }
5369
5370                         return this;
5371                 },
5372                 clear: function clear() {
5373                         for (var i = 0; i < this.children.length; i++) {
5374                                 var object = this.children[i];
5375                                 object.parent = null;
5376                                 object.dispatchEvent(_removedEvent);
5377                         }
5378
5379                         this.children.length = 0;
5380                         return this;
5381                 },
5382                 attach: function attach(object) {
5383                         // adds object as a child of this, while maintaining the object's world transform
5384                         this.updateWorldMatrix(true, false);
5385
5386                         _m1$1.copy(this.matrixWorld).invert();
5387
5388                         if (object.parent !== null) {
5389                                 object.parent.updateWorldMatrix(true, false);
5390
5391                                 _m1$1.multiply(object.parent.matrixWorld);
5392                         }
5393
5394                         object.applyMatrix4(_m1$1);
5395                         object.updateWorldMatrix(false, false);
5396                         this.add(object);
5397                         return this;
5398                 },
5399                 getObjectById: function getObjectById(id) {
5400                         return this.getObjectByProperty('id', id);
5401                 },
5402                 getObjectByName: function getObjectByName(name) {
5403                         return this.getObjectByProperty('name', name);
5404                 },
5405                 getObjectByProperty: function getObjectByProperty(name, value) {
5406                         if (this[name] === value) return this;
5407
5408                         for (var i = 0, l = this.children.length; i < l; i++) {
5409                                 var child = this.children[i];
5410                                 var object = child.getObjectByProperty(name, value);
5411
5412                                 if (object !== undefined) {
5413                                         return object;
5414                                 }
5415                         }
5416
5417                         return undefined;
5418                 },
5419                 getWorldPosition: function getWorldPosition(target) {
5420                         if (target === undefined) {
5421                                 console.warn('THREE.Object3D: .getWorldPosition() target is now required');
5422                                 target = new Vector3();
5423                         }
5424
5425                         this.updateWorldMatrix(true, false);
5426                         return target.setFromMatrixPosition(this.matrixWorld);
5427                 },
5428                 getWorldQuaternion: function getWorldQuaternion(target) {
5429                         if (target === undefined) {
5430                                 console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
5431                                 target = new Quaternion();
5432                         }
5433
5434                         this.updateWorldMatrix(true, false);
5435                         this.matrixWorld.decompose(_position, target, _scale);
5436                         return target;
5437                 },
5438                 getWorldScale: function getWorldScale(target) {
5439                         if (target === undefined) {
5440                                 console.warn('THREE.Object3D: .getWorldScale() target is now required');
5441                                 target = new Vector3();
5442                         }
5443
5444                         this.updateWorldMatrix(true, false);
5445                         this.matrixWorld.decompose(_position, _quaternion$2, target);
5446                         return target;
5447                 },
5448                 getWorldDirection: function getWorldDirection(target) {
5449                         if (target === undefined) {
5450                                 console.warn('THREE.Object3D: .getWorldDirection() target is now required');
5451                                 target = new Vector3();
5452                         }
5453
5454                         this.updateWorldMatrix(true, false);
5455                         var e = this.matrixWorld.elements;
5456                         return target.set(e[8], e[9], e[10]).normalize();
5457                 },
5458                 raycast: function raycast() {},
5459                 traverse: function traverse(callback) {
5460                         callback(this);
5461                         var children = this.children;
5462
5463                         for (var i = 0, l = children.length; i < l; i++) {
5464                                 children[i].traverse(callback);
5465                         }
5466                 },
5467                 traverseVisible: function traverseVisible(callback) {
5468                         if (this.visible === false) return;
5469                         callback(this);
5470                         var children = this.children;
5471
5472                         for (var i = 0, l = children.length; i < l; i++) {
5473                                 children[i].traverseVisible(callback);
5474                         }
5475                 },
5476                 traverseAncestors: function traverseAncestors(callback) {
5477                         var parent = this.parent;
5478
5479                         if (parent !== null) {
5480                                 callback(parent);
5481                                 parent.traverseAncestors(callback);
5482                         }
5483                 },
5484                 updateMatrix: function updateMatrix() {
5485                         this.matrix.compose(this.position, this.quaternion, this.scale);
5486                         this.matrixWorldNeedsUpdate = true;
5487                 },
5488                 updateMatrixWorld: function updateMatrixWorld(force) {
5489                         if (this.matrixAutoUpdate) this.updateMatrix();
5490
5491                         if (this.matrixWorldNeedsUpdate || force) {
5492                                 if (this.parent === null) {
5493                                         this.matrixWorld.copy(this.matrix);
5494                                 } else {
5495                                         this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
5496                                 }
5497
5498                                 this.matrixWorldNeedsUpdate = false;
5499                                 force = true;
5500                         } // update children
5501
5502
5503                         var children = this.children;
5504
5505                         for (var i = 0, l = children.length; i < l; i++) {
5506                                 children[i].updateMatrixWorld(force);
5507                         }
5508                 },
5509                 updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
5510                         var parent = this.parent;
5511
5512                         if (updateParents === true && parent !== null) {
5513                                 parent.updateWorldMatrix(true, false);
5514                         }
5515
5516                         if (this.matrixAutoUpdate) this.updateMatrix();
5517
5518                         if (this.parent === null) {
5519                                 this.matrixWorld.copy(this.matrix);
5520                         } else {
5521                                 this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
5522                         } // update children
5523
5524
5525                         if (updateChildren === true) {
5526                                 var children = this.children;
5527
5528                                 for (var i = 0, l = children.length; i < l; i++) {
5529                                         children[i].updateWorldMatrix(false, true);
5530                                 }
5531                         }
5532                 },
5533                 toJSON: function toJSON(meta) {
5534                         // meta is a string when called from JSON.stringify
5535                         var isRootObject = meta === undefined || typeof meta === 'string';
5536                         var output = {}; // meta is a hash used to collect geometries, materials.
5537                         // not providing it implies that this is the root object
5538                         // being serialized.
5539
5540                         if (isRootObject) {
5541                                 // initialize meta obj
5542                                 meta = {
5543                                         geometries: {},
5544                                         materials: {},
5545                                         textures: {},
5546                                         images: {},
5547                                         shapes: {},
5548                                         skeletons: {},
5549                                         animations: {}
5550                                 };
5551                                 output.metadata = {
5552                                         version: 4.5,
5553                                         type: 'Object',
5554                                         generator: 'Object3D.toJSON'
5555                                 };
5556                         } // standard Object3D serialization
5557
5558
5559                         var object = {};
5560                         object.uuid = this.uuid;
5561                         object.type = this.type;
5562                         if (this.name !== '') object.name = this.name;
5563                         if (this.castShadow === true) object.castShadow = true;
5564                         if (this.receiveShadow === true) object.receiveShadow = true;
5565                         if (this.visible === false) object.visible = false;
5566                         if (this.frustumCulled === false) object.frustumCulled = false;
5567                         if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
5568                         if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
5569                         object.layers = this.layers.mask;
5570                         object.matrix = this.matrix.toArray();
5571                         if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
5572
5573                         if (this.isInstancedMesh) {
5574                                 object.type = 'InstancedMesh';
5575                                 object.count = this.count;
5576                                 object.instanceMatrix = this.instanceMatrix.toJSON();
5577                         } //
5578
5579
5580                         function serialize(library, element) {
5581                                 if (library[element.uuid] === undefined) {
5582                                         library[element.uuid] = element.toJSON(meta);
5583                                 }
5584
5585                                 return element.uuid;
5586                         }
5587
5588                         if (this.isMesh || this.isLine || this.isPoints) {
5589                                 object.geometry = serialize(meta.geometries, this.geometry);
5590                                 var parameters = this.geometry.parameters;
5591
5592                                 if (parameters !== undefined && parameters.shapes !== undefined) {
5593                                         var shapes = parameters.shapes;
5594
5595                                         if (Array.isArray(shapes)) {
5596                                                 for (var i = 0, l = shapes.length; i < l; i++) {
5597                                                         var shape = shapes[i];
5598                                                         serialize(meta.shapes, shape);
5599                                                 }
5600                                         } else {
5601                                                 serialize(meta.shapes, shapes);
5602                                         }
5603                                 }
5604                         }
5605
5606                         if (this.isSkinnedMesh) {
5607                                 object.bindMode = this.bindMode;
5608                                 object.bindMatrix = this.bindMatrix.toArray();
5609
5610                                 if (this.skeleton !== undefined) {
5611                                         serialize(meta.skeletons, this.skeleton);
5612                                         object.skeleton = this.skeleton.uuid;
5613                                 }
5614                         }
5615
5616                         if (this.material !== undefined) {
5617                                 if (Array.isArray(this.material)) {
5618                                         var uuids = [];
5619
5620                                         for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
5621                                                 uuids.push(serialize(meta.materials, this.material[_i]));
5622                                         }
5623
5624                                         object.material = uuids;
5625                                 } else {
5626                                         object.material = serialize(meta.materials, this.material);
5627                                 }
5628                         } //
5629
5630
5631                         if (this.children.length > 0) {
5632                                 object.children = [];
5633
5634                                 for (var _i2 = 0; _i2 < this.children.length; _i2++) {
5635                                         object.children.push(this.children[_i2].toJSON(meta).object);
5636                                 }
5637                         } //
5638
5639
5640                         if (this.animations.length > 0) {
5641                                 object.animations = [];
5642
5643                                 for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
5644                                         var animation = this.animations[_i3];
5645                                         object.animations.push(serialize(meta.animations, animation));
5646                                 }
5647                         }
5648
5649                         if (isRootObject) {
5650                                 var geometries = extractFromCache(meta.geometries);
5651                                 var materials = extractFromCache(meta.materials);
5652                                 var textures = extractFromCache(meta.textures);
5653                                 var images = extractFromCache(meta.images);
5654
5655                                 var _shapes = extractFromCache(meta.shapes);
5656
5657                                 var skeletons = extractFromCache(meta.skeletons);
5658                                 var animations = extractFromCache(meta.animations);
5659                                 if (geometries.length > 0) output.geometries = geometries;
5660                                 if (materials.length > 0) output.materials = materials;
5661                                 if (textures.length > 0) output.textures = textures;
5662                                 if (images.length > 0) output.images = images;
5663                                 if (_shapes.length > 0) output.shapes = _shapes;
5664                                 if (skeletons.length > 0) output.skeletons = skeletons;
5665                                 if (animations.length > 0) output.animations = animations;
5666                         }
5667
5668                         output.object = object;
5669                         return output; // extract data from the cache hash
5670                         // remove metadata on each item
5671                         // and return as array
5672
5673                         function extractFromCache(cache) {
5674                                 var values = [];
5675
5676                                 for (var key in cache) {
5677                                         var data = cache[key];
5678                                         delete data.metadata;
5679                                         values.push(data);
5680                                 }
5681
5682                                 return values;
5683                         }
5684                 },
5685                 clone: function clone(recursive) {
5686                         return new this.constructor().copy(this, recursive);
5687                 },
5688                 copy: function copy(source, recursive) {
5689                         if (recursive === void 0) {
5690                                 recursive = true;
5691                         }
5692
5693                         this.name = source.name;
5694                         this.up.copy(source.up);
5695                         this.position.copy(source.position);
5696                         this.rotation.order = source.rotation.order;
5697                         this.quaternion.copy(source.quaternion);
5698                         this.scale.copy(source.scale);
5699                         this.matrix.copy(source.matrix);
5700                         this.matrixWorld.copy(source.matrixWorld);
5701                         this.matrixAutoUpdate = source.matrixAutoUpdate;
5702                         this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
5703                         this.layers.mask = source.layers.mask;
5704                         this.visible = source.visible;
5705                         this.castShadow = source.castShadow;
5706                         this.receiveShadow = source.receiveShadow;
5707                         this.frustumCulled = source.frustumCulled;
5708                         this.renderOrder = source.renderOrder;
5709                         this.userData = JSON.parse(JSON.stringify(source.userData));
5710
5711                         if (recursive === true) {
5712                                 for (var i = 0; i < source.children.length; i++) {
5713                                         var child = source.children[i];
5714                                         this.add(child.clone());
5715                                 }
5716                         }
5717
5718                         return this;
5719                 }
5720         });
5721
5722         var _vector1 = /*@__PURE__*/new Vector3();
5723
5724         var _vector2 = /*@__PURE__*/new Vector3();
5725
5726         var _normalMatrix = /*@__PURE__*/new Matrix3();
5727
5728         var Plane = /*#__PURE__*/function () {
5729                 function Plane(normal, constant) {
5730                         Object.defineProperty(this, 'isPlane', {
5731                                 value: true
5732                         }); // normal is assumed to be normalized
5733
5734                         this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
5735                         this.constant = constant !== undefined ? constant : 0;
5736                 }
5737
5738                 var _proto = Plane.prototype;
5739
5740                 _proto.set = function set(normal, constant) {
5741                         this.normal.copy(normal);
5742                         this.constant = constant;
5743                         return this;
5744                 };
5745
5746                 _proto.setComponents = function setComponents(x, y, z, w) {
5747                         this.normal.set(x, y, z);
5748                         this.constant = w;
5749                         return this;
5750                 };
5751
5752                 _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
5753                         this.normal.copy(normal);
5754                         this.constant = -point.dot(this.normal);
5755                         return this;
5756                 };
5757
5758                 _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
5759                         var normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
5760
5761
5762                         this.setFromNormalAndCoplanarPoint(normal, a);
5763                         return this;
5764                 };
5765
5766                 _proto.clone = function clone() {
5767                         return new this.constructor().copy(this);
5768                 };
5769
5770                 _proto.copy = function copy(plane) {
5771                         this.normal.copy(plane.normal);
5772                         this.constant = plane.constant;
5773                         return this;
5774                 };
5775
5776                 _proto.normalize = function normalize() {
5777                         // Note: will lead to a divide by zero if the plane is invalid.
5778                         var inverseNormalLength = 1.0 / this.normal.length();
5779                         this.normal.multiplyScalar(inverseNormalLength);
5780                         this.constant *= inverseNormalLength;
5781                         return this;
5782                 };
5783
5784                 _proto.negate = function negate() {
5785                         this.constant *= -1;
5786                         this.normal.negate();
5787                         return this;
5788                 };
5789
5790                 _proto.distanceToPoint = function distanceToPoint(point) {
5791                         return this.normal.dot(point) + this.constant;
5792                 };
5793
5794                 _proto.distanceToSphere = function distanceToSphere(sphere) {
5795                         return this.distanceToPoint(sphere.center) - sphere.radius;
5796                 };
5797
5798                 _proto.projectPoint = function projectPoint(point, target) {
5799                         if (target === undefined) {
5800                                 console.warn('THREE.Plane: .projectPoint() target is now required');
5801                                 target = new Vector3();
5802                         }
5803
5804                         return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
5805                 };
5806
5807                 _proto.intersectLine = function intersectLine(line, target) {
5808                         if (target === undefined) {
5809                                 console.warn('THREE.Plane: .intersectLine() target is now required');
5810                                 target = new Vector3();
5811                         }
5812
5813                         var direction = line.delta(_vector1);
5814                         var denominator = this.normal.dot(direction);
5815
5816                         if (denominator === 0) {
5817                                 // line is coplanar, return origin
5818                                 if (this.distanceToPoint(line.start) === 0) {
5819                                         return target.copy(line.start);
5820                                 } // Unsure if this is the correct method to handle this case.
5821
5822
5823                                 return undefined;
5824                         }
5825
5826                         var t = -(line.start.dot(this.normal) + this.constant) / denominator;
5827
5828                         if (t < 0 || t > 1) {
5829                                 return undefined;
5830                         }
5831
5832                         return target.copy(direction).multiplyScalar(t).add(line.start);
5833                 };
5834
5835                 _proto.intersectsLine = function intersectsLine(line) {
5836                         // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
5837                         var startSign = this.distanceToPoint(line.start);
5838                         var endSign = this.distanceToPoint(line.end);
5839                         return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
5840                 };
5841
5842                 _proto.intersectsBox = function intersectsBox(box) {
5843                         return box.intersectsPlane(this);
5844                 };
5845
5846                 _proto.intersectsSphere = function intersectsSphere(sphere) {
5847                         return sphere.intersectsPlane(this);
5848                 };
5849
5850                 _proto.coplanarPoint = function coplanarPoint(target) {
5851                         if (target === undefined) {
5852                                 console.warn('THREE.Plane: .coplanarPoint() target is now required');
5853                                 target = new Vector3();
5854                         }
5855
5856                         return target.copy(this.normal).multiplyScalar(-this.constant);
5857                 };
5858
5859                 _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
5860                         var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
5861
5862                         var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
5863                         var normal = this.normal.applyMatrix3(normalMatrix).normalize();
5864                         this.constant = -referencePoint.dot(normal);
5865                         return this;
5866                 };
5867
5868                 _proto.translate = function translate(offset) {
5869                         this.constant -= offset.dot(this.normal);
5870                         return this;
5871                 };
5872
5873                 _proto.equals = function equals(plane) {
5874                         return plane.normal.equals(this.normal) && plane.constant === this.constant;
5875                 };
5876
5877                 return Plane;
5878         }();
5879
5880         var _v0$1 = /*@__PURE__*/new Vector3();
5881
5882         var _v1$3 = /*@__PURE__*/new Vector3();
5883
5884         var _v2$1 = /*@__PURE__*/new Vector3();
5885
5886         var _v3 = /*@__PURE__*/new Vector3();
5887
5888         var _vab = /*@__PURE__*/new Vector3();
5889
5890         var _vac = /*@__PURE__*/new Vector3();
5891
5892         var _vbc = /*@__PURE__*/new Vector3();
5893
5894         var _vap = /*@__PURE__*/new Vector3();
5895
5896         var _vbp = /*@__PURE__*/new Vector3();
5897
5898         var _vcp = /*@__PURE__*/new Vector3();
5899
5900         var Triangle = /*#__PURE__*/function () {
5901                 function Triangle(a, b, c) {
5902                         this.a = a !== undefined ? a : new Vector3();
5903                         this.b = b !== undefined ? b : new Vector3();
5904                         this.c = c !== undefined ? c : new Vector3();
5905                 }
5906
5907                 Triangle.getNormal = function getNormal(a, b, c, target) {
5908                         if (target === undefined) {
5909                                 console.warn('THREE.Triangle: .getNormal() target is now required');
5910                                 target = new Vector3();
5911                         }
5912
5913                         target.subVectors(c, b);
5914
5915                         _v0$1.subVectors(a, b);
5916
5917                         target.cross(_v0$1);
5918                         var targetLengthSq = target.lengthSq();
5919
5920                         if (targetLengthSq > 0) {
5921                                 return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
5922                         }
5923
5924                         return target.set(0, 0, 0);
5925                 } // static/instance method to calculate barycentric coordinates
5926                 // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
5927                 ;
5928
5929                 Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
5930                         _v0$1.subVectors(c, a);
5931
5932                         _v1$3.subVectors(b, a);
5933
5934                         _v2$1.subVectors(point, a);
5935
5936                         var dot00 = _v0$1.dot(_v0$1);
5937
5938                         var dot01 = _v0$1.dot(_v1$3);
5939
5940                         var dot02 = _v0$1.dot(_v2$1);
5941
5942                         var dot11 = _v1$3.dot(_v1$3);
5943
5944                         var dot12 = _v1$3.dot(_v2$1);
5945
5946                         var denom = dot00 * dot11 - dot01 * dot01;
5947
5948                         if (target === undefined) {
5949                                 console.warn('THREE.Triangle: .getBarycoord() target is now required');
5950                                 target = new Vector3();
5951                         } // collinear or singular triangle
5952
5953
5954                         if (denom === 0) {
5955                                 // arbitrary location outside of triangle?
5956                                 // not sure if this is the best idea, maybe should be returning undefined
5957                                 return target.set(-2, -1, -1);
5958                         }
5959
5960                         var invDenom = 1 / denom;
5961                         var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
5962                         var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
5963
5964                         return target.set(1 - u - v, v, u);
5965                 };
5966
5967                 Triangle.containsPoint = function containsPoint(point, a, b, c) {
5968                         this.getBarycoord(point, a, b, c, _v3);
5969                         return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
5970                 };
5971
5972                 Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
5973                         this.getBarycoord(point, p1, p2, p3, _v3);
5974                         target.set(0, 0);
5975                         target.addScaledVector(uv1, _v3.x);
5976                         target.addScaledVector(uv2, _v3.y);
5977                         target.addScaledVector(uv3, _v3.z);
5978                         return target;
5979                 };
5980
5981                 Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
5982                         _v0$1.subVectors(c, b);
5983
5984                         _v1$3.subVectors(a, b); // strictly front facing
5985
5986
5987                         return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
5988                 };
5989
5990                 var _proto = Triangle.prototype;
5991
5992                 _proto.set = function set(a, b, c) {
5993                         this.a.copy(a);
5994                         this.b.copy(b);
5995                         this.c.copy(c);
5996                         return this;
5997                 };
5998
5999                 _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
6000                         this.a.copy(points[i0]);
6001                         this.b.copy(points[i1]);
6002                         this.c.copy(points[i2]);
6003                         return this;
6004                 };
6005
6006                 _proto.clone = function clone() {
6007                         return new this.constructor().copy(this);
6008                 };
6009
6010                 _proto.copy = function copy(triangle) {
6011                         this.a.copy(triangle.a);
6012                         this.b.copy(triangle.b);
6013                         this.c.copy(triangle.c);
6014                         return this;
6015                 };
6016
6017                 _proto.getArea = function getArea() {
6018                         _v0$1.subVectors(this.c, this.b);
6019
6020                         _v1$3.subVectors(this.a, this.b);
6021
6022                         return _v0$1.cross(_v1$3).length() * 0.5;
6023                 };
6024
6025                 _proto.getMidpoint = function getMidpoint(target) {
6026                         if (target === undefined) {
6027                                 console.warn('THREE.Triangle: .getMidpoint() target is now required');
6028                                 target = new Vector3();
6029                         }
6030
6031                         return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
6032                 };
6033
6034                 _proto.getNormal = function getNormal(target) {
6035                         return Triangle.getNormal(this.a, this.b, this.c, target);
6036                 };
6037
6038                 _proto.getPlane = function getPlane(target) {
6039                         if (target === undefined) {
6040                                 console.warn('THREE.Triangle: .getPlane() target is now required');
6041                                 target = new Plane();
6042                         }
6043
6044                         return target.setFromCoplanarPoints(this.a, this.b, this.c);
6045                 };
6046
6047                 _proto.getBarycoord = function getBarycoord(point, target) {
6048                         return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
6049                 };
6050
6051                 _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
6052                         return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
6053                 };
6054
6055                 _proto.containsPoint = function containsPoint(point) {
6056                         return Triangle.containsPoint(point, this.a, this.b, this.c);
6057                 };
6058
6059                 _proto.isFrontFacing = function isFrontFacing(direction) {
6060                         return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
6061                 };
6062
6063                 _proto.intersectsBox = function intersectsBox(box) {
6064                         return box.intersectsTriangle(this);
6065                 };
6066
6067                 _proto.closestPointToPoint = function closestPointToPoint(p, target) {
6068                         if (target === undefined) {
6069                                 console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
6070                                 target = new Vector3();
6071                         }
6072
6073                         var a = this.a,
6074                                         b = this.b,
6075                                         c = this.c;
6076                         var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
6077                         // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
6078                         // under the accompanying license; see chapter 5.1.5 for detailed explanation.
6079                         // basically, we're distinguishing which of the voronoi regions of the triangle
6080                         // the point lies in with the minimum amount of redundant computation.
6081
6082                         _vab.subVectors(b, a);
6083
6084                         _vac.subVectors(c, a);
6085
6086                         _vap.subVectors(p, a);
6087
6088                         var d1 = _vab.dot(_vap);
6089
6090                         var d2 = _vac.dot(_vap);
6091
6092                         if (d1 <= 0 && d2 <= 0) {
6093                                 // vertex region of A; barycentric coords (1, 0, 0)
6094                                 return target.copy(a);
6095                         }
6096
6097                         _vbp.subVectors(p, b);
6098
6099                         var d3 = _vab.dot(_vbp);
6100
6101                         var d4 = _vac.dot(_vbp);
6102
6103                         if (d3 >= 0 && d4 <= d3) {
6104                                 // vertex region of B; barycentric coords (0, 1, 0)
6105                                 return target.copy(b);
6106                         }
6107
6108                         var vc = d1 * d4 - d3 * d2;
6109
6110                         if (vc <= 0 && d1 >= 0 && d3 <= 0) {
6111                                 v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
6112
6113                                 return target.copy(a).addScaledVector(_vab, v);
6114                         }
6115
6116                         _vcp.subVectors(p, c);
6117
6118                         var d5 = _vab.dot(_vcp);
6119
6120                         var d6 = _vac.dot(_vcp);
6121
6122                         if (d6 >= 0 && d5 <= d6) {
6123                                 // vertex region of C; barycentric coords (0, 0, 1)
6124                                 return target.copy(c);
6125                         }
6126
6127                         var vb = d5 * d2 - d1 * d6;
6128
6129                         if (vb <= 0 && d2 >= 0 && d6 <= 0) {
6130                                 w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
6131
6132                                 return target.copy(a).addScaledVector(_vac, w);
6133                         }
6134
6135                         var va = d3 * d6 - d5 * d4;
6136
6137                         if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
6138                                 _vbc.subVectors(c, b);
6139
6140                                 w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
6141
6142                                 return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
6143                         } // face region
6144
6145
6146                         var denom = 1 / (va + vb + vc); // u = va * denom
6147
6148                         v = vb * denom;
6149                         w = vc * denom;
6150                         return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
6151                 };
6152
6153                 _proto.equals = function equals(triangle) {
6154                         return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
6155                 };
6156
6157                 return Triangle;
6158         }();
6159
6160         var _colorKeywords = {
6161                 'aliceblue': 0xF0F8FF,
6162                 'antiquewhite': 0xFAEBD7,
6163                 'aqua': 0x00FFFF,
6164                 'aquamarine': 0x7FFFD4,
6165                 'azure': 0xF0FFFF,
6166                 'beige': 0xF5F5DC,
6167                 'bisque': 0xFFE4C4,
6168                 'black': 0x000000,
6169                 'blanchedalmond': 0xFFEBCD,
6170                 'blue': 0x0000FF,
6171                 'blueviolet': 0x8A2BE2,
6172                 'brown': 0xA52A2A,
6173                 'burlywood': 0xDEB887,
6174                 'cadetblue': 0x5F9EA0,
6175                 'chartreuse': 0x7FFF00,
6176                 'chocolate': 0xD2691E,
6177                 'coral': 0xFF7F50,
6178                 'cornflowerblue': 0x6495ED,
6179                 'cornsilk': 0xFFF8DC,
6180                 'crimson': 0xDC143C,
6181                 'cyan': 0x00FFFF,
6182                 'darkblue': 0x00008B,
6183                 'darkcyan': 0x008B8B,
6184                 'darkgoldenrod': 0xB8860B,
6185                 'darkgray': 0xA9A9A9,
6186                 'darkgreen': 0x006400,
6187                 'darkgrey': 0xA9A9A9,
6188                 'darkkhaki': 0xBDB76B,
6189                 'darkmagenta': 0x8B008B,
6190                 'darkolivegreen': 0x556B2F,
6191                 'darkorange': 0xFF8C00,
6192                 'darkorchid': 0x9932CC,
6193                 'darkred': 0x8B0000,
6194                 'darksalmon': 0xE9967A,
6195                 'darkseagreen': 0x8FBC8F,
6196                 'darkslateblue': 0x483D8B,
6197                 'darkslategray': 0x2F4F4F,
6198                 'darkslategrey': 0x2F4F4F,
6199                 'darkturquoise': 0x00CED1,
6200                 'darkviolet': 0x9400D3,
6201                 'deeppink': 0xFF1493,
6202                 'deepskyblue': 0x00BFFF,
6203                 'dimgray': 0x696969,
6204                 'dimgrey': 0x696969,
6205                 'dodgerblue': 0x1E90FF,
6206                 'firebrick': 0xB22222,
6207                 'floralwhite': 0xFFFAF0,
6208                 'forestgreen': 0x228B22,
6209                 'fuchsia': 0xFF00FF,
6210                 'gainsboro': 0xDCDCDC,
6211                 'ghostwhite': 0xF8F8FF,
6212                 'gold': 0xFFD700,
6213                 'goldenrod': 0xDAA520,
6214                 'gray': 0x808080,
6215                 'green': 0x008000,
6216                 'greenyellow': 0xADFF2F,
6217                 'grey': 0x808080,
6218                 'honeydew': 0xF0FFF0,
6219                 'hotpink': 0xFF69B4,
6220                 'indianred': 0xCD5C5C,
6221                 'indigo': 0x4B0082,
6222                 'ivory': 0xFFFFF0,
6223                 'khaki': 0xF0E68C,
6224                 'lavender': 0xE6E6FA,
6225                 'lavenderblush': 0xFFF0F5,
6226                 'lawngreen': 0x7CFC00,
6227                 'lemonchiffon': 0xFFFACD,
6228                 'lightblue': 0xADD8E6,
6229                 'lightcoral': 0xF08080,
6230                 'lightcyan': 0xE0FFFF,
6231                 'lightgoldenrodyellow': 0xFAFAD2,
6232                 'lightgray': 0xD3D3D3,
6233                 'lightgreen': 0x90EE90,
6234                 'lightgrey': 0xD3D3D3,
6235                 'lightpink': 0xFFB6C1,
6236                 'lightsalmon': 0xFFA07A,
6237                 'lightseagreen': 0x20B2AA,
6238                 'lightskyblue': 0x87CEFA,
6239                 'lightslategray': 0x778899,
6240                 'lightslategrey': 0x778899,
6241                 'lightsteelblue': 0xB0C4DE,
6242                 'lightyellow': 0xFFFFE0,
6243                 'lime': 0x00FF00,
6244                 'limegreen': 0x32CD32,
6245                 'linen': 0xFAF0E6,
6246                 'magenta': 0xFF00FF,
6247                 'maroon': 0x800000,
6248                 'mediumaquamarine': 0x66CDAA,
6249                 'mediumblue': 0x0000CD,
6250                 'mediumorchid': 0xBA55D3,
6251                 'mediumpurple': 0x9370DB,
6252                 'mediumseagreen': 0x3CB371,
6253                 'mediumslateblue': 0x7B68EE,
6254                 'mediumspringgreen': 0x00FA9A,
6255                 'mediumturquoise': 0x48D1CC,
6256                 'mediumvioletred': 0xC71585,
6257                 'midnightblue': 0x191970,
6258                 'mintcream': 0xF5FFFA,
6259                 'mistyrose': 0xFFE4E1,
6260                 'moccasin': 0xFFE4B5,
6261                 'navajowhite': 0xFFDEAD,
6262                 'navy': 0x000080,
6263                 'oldlace': 0xFDF5E6,
6264                 'olive': 0x808000,
6265                 'olivedrab': 0x6B8E23,
6266                 'orange': 0xFFA500,
6267                 'orangered': 0xFF4500,
6268                 'orchid': 0xDA70D6,
6269                 'palegoldenrod': 0xEEE8AA,
6270                 'palegreen': 0x98FB98,
6271                 'paleturquoise': 0xAFEEEE,
6272                 'palevioletred': 0xDB7093,
6273                 'papayawhip': 0xFFEFD5,
6274                 'peachpuff': 0xFFDAB9,
6275                 'peru': 0xCD853F,
6276                 'pink': 0xFFC0CB,
6277                 'plum': 0xDDA0DD,
6278                 'powderblue': 0xB0E0E6,
6279                 'purple': 0x800080,
6280                 'rebeccapurple': 0x663399,
6281                 'red': 0xFF0000,
6282                 'rosybrown': 0xBC8F8F,
6283                 'royalblue': 0x4169E1,
6284                 'saddlebrown': 0x8B4513,
6285                 'salmon': 0xFA8072,
6286                 'sandybrown': 0xF4A460,
6287                 'seagreen': 0x2E8B57,
6288                 'seashell': 0xFFF5EE,
6289                 'sienna': 0xA0522D,
6290                 'silver': 0xC0C0C0,
6291                 'skyblue': 0x87CEEB,
6292                 'slateblue': 0x6A5ACD,
6293                 'slategray': 0x708090,
6294                 'slategrey': 0x708090,
6295                 'snow': 0xFFFAFA,
6296                 'springgreen': 0x00FF7F,
6297                 'steelblue': 0x4682B4,
6298                 'tan': 0xD2B48C,
6299                 'teal': 0x008080,
6300                 'thistle': 0xD8BFD8,
6301                 'tomato': 0xFF6347,
6302                 'turquoise': 0x40E0D0,
6303                 'violet': 0xEE82EE,
6304                 'wheat': 0xF5DEB3,
6305                 'white': 0xFFFFFF,
6306                 'whitesmoke': 0xF5F5F5,
6307                 'yellow': 0xFFFF00,
6308                 'yellowgreen': 0x9ACD32
6309         };
6310         var _hslA = {
6311                 h: 0,
6312                 s: 0,
6313                 l: 0
6314         };
6315         var _hslB = {
6316                 h: 0,
6317                 s: 0,
6318                 l: 0
6319         };
6320
6321         function hue2rgb(p, q, t) {
6322                 if (t < 0) t += 1;
6323                 if (t > 1) t -= 1;
6324                 if (t < 1 / 6) return p + (q - p) * 6 * t;
6325                 if (t < 1 / 2) return q;
6326                 if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
6327                 return p;
6328         }
6329
6330         function SRGBToLinear(c) {
6331                 return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
6332         }
6333
6334         function LinearToSRGB(c) {
6335                 return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
6336         }
6337
6338         var Color = /*#__PURE__*/function () {
6339                 function Color(r, g, b) {
6340                         Object.defineProperty(this, 'isColor', {
6341                                 value: true
6342                         });
6343
6344                         if (g === undefined && b === undefined) {
6345                                 // r is THREE.Color, hex or string
6346                                 return this.set(r);
6347                         }
6348
6349                         return this.setRGB(r, g, b);
6350                 }
6351
6352                 var _proto = Color.prototype;
6353
6354                 _proto.set = function set(value) {
6355                         if (value && value.isColor) {
6356                                 this.copy(value);
6357                         } else if (typeof value === 'number') {
6358                                 this.setHex(value);
6359                         } else if (typeof value === 'string') {
6360                                 this.setStyle(value);
6361                         }
6362
6363                         return this;
6364                 };
6365
6366                 _proto.setScalar = function setScalar(scalar) {
6367                         this.r = scalar;
6368                         this.g = scalar;
6369                         this.b = scalar;
6370                         return this;
6371                 };
6372
6373                 _proto.setHex = function setHex(hex) {
6374                         hex = Math.floor(hex);
6375                         this.r = (hex >> 16 & 255) / 255;
6376                         this.g = (hex >> 8 & 255) / 255;
6377                         this.b = (hex & 255) / 255;
6378                         return this;
6379                 };
6380
6381                 _proto.setRGB = function setRGB(r, g, b) {
6382                         this.r = r;
6383                         this.g = g;
6384                         this.b = b;
6385                         return this;
6386                 };
6387
6388                 _proto.setHSL = function setHSL(h, s, l) {
6389                         // h,s,l ranges are in 0.0 - 1.0
6390                         h = MathUtils.euclideanModulo(h, 1);
6391                         s = MathUtils.clamp(s, 0, 1);
6392                         l = MathUtils.clamp(l, 0, 1);
6393
6394                         if (s === 0) {
6395                                 this.r = this.g = this.b = l;
6396                         } else {
6397                                 var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
6398                                 var q = 2 * l - p;
6399                                 this.r = hue2rgb(q, p, h + 1 / 3);
6400                                 this.g = hue2rgb(q, p, h);
6401                                 this.b = hue2rgb(q, p, h - 1 / 3);
6402                         }
6403
6404                         return this;
6405                 };
6406
6407                 _proto.setStyle = function setStyle(style) {
6408                         function handleAlpha(string) {
6409                                 if (string === undefined) return;
6410
6411                                 if (parseFloat(string) < 1) {
6412                                         console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
6413                                 }
6414                         }
6415
6416                         var m;
6417
6418                         if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
6419                                 // rgb / hsl
6420                                 var color;
6421                                 var name = m[1];
6422                                 var components = m[2];
6423
6424                                 switch (name) {
6425                                         case 'rgb':
6426                                         case 'rgba':
6427                                                 if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
6428                                                         // rgb(255,0,0) rgba(255,0,0,0.5)
6429                                                         this.r = Math.min(255, parseInt(color[1], 10)) / 255;
6430                                                         this.g = Math.min(255, parseInt(color[2], 10)) / 255;
6431                                                         this.b = Math.min(255, parseInt(color[3], 10)) / 255;
6432                                                         handleAlpha(color[5]);
6433                                                         return this;
6434                                                 }
6435
6436                                                 if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
6437                                                         // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
6438                                                         this.r = Math.min(100, parseInt(color[1], 10)) / 100;
6439                                                         this.g = Math.min(100, parseInt(color[2], 10)) / 100;
6440                                                         this.b = Math.min(100, parseInt(color[3], 10)) / 100;
6441                                                         handleAlpha(color[5]);
6442                                                         return this;
6443                                                 }
6444
6445                                                 break;
6446
6447                                         case 'hsl':
6448                                         case 'hsla':
6449                                                 if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
6450                                                         // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
6451                                                         var h = parseFloat(color[1]) / 360;
6452                                                         var s = parseInt(color[2], 10) / 100;
6453                                                         var l = parseInt(color[3], 10) / 100;
6454                                                         handleAlpha(color[5]);
6455                                                         return this.setHSL(h, s, l);
6456                                                 }
6457
6458                                                 break;
6459                                 }
6460                         } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
6461                                 // hex color
6462                                 var hex = m[1];
6463                                 var size = hex.length;
6464
6465                                 if (size === 3) {
6466                                         // #ff0
6467                                         this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
6468                                         this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
6469                                         this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
6470                                         return this;
6471                                 } else if (size === 6) {
6472                                         // #ff0000
6473                                         this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
6474                                         this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
6475                                         this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
6476                                         return this;
6477                                 }
6478                         }
6479
6480                         if (style && style.length > 0) {
6481                                 return this.setColorName(style);
6482                         }
6483
6484                         return this;
6485                 };
6486
6487                 _proto.setColorName = function setColorName(style) {
6488                         // color keywords
6489                         var hex = _colorKeywords[style];
6490
6491                         if (hex !== undefined) {
6492                                 // red
6493                                 this.setHex(hex);
6494                         } else {
6495                                 // unknown color
6496                                 console.warn('THREE.Color: Unknown color ' + style);
6497                         }
6498
6499                         return this;
6500                 };
6501
6502                 _proto.clone = function clone() {
6503                         return new this.constructor(this.r, this.g, this.b);
6504                 };
6505
6506                 _proto.copy = function copy(color) {
6507                         this.r = color.r;
6508                         this.g = color.g;
6509                         this.b = color.b;
6510                         return this;
6511                 };
6512
6513                 _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
6514                         if (gammaFactor === void 0) {
6515                                 gammaFactor = 2.0;
6516                         }
6517
6518                         this.r = Math.pow(color.r, gammaFactor);
6519                         this.g = Math.pow(color.g, gammaFactor);
6520                         this.b = Math.pow(color.b, gammaFactor);
6521                         return this;
6522                 };
6523
6524                 _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
6525                         if (gammaFactor === void 0) {
6526                                 gammaFactor = 2.0;
6527                         }
6528
6529                         var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
6530                         this.r = Math.pow(color.r, safeInverse);
6531                         this.g = Math.pow(color.g, safeInverse);
6532                         this.b = Math.pow(color.b, safeInverse);
6533                         return this;
6534                 };
6535
6536                 _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
6537                         this.copyGammaToLinear(this, gammaFactor);
6538                         return this;
6539                 };
6540
6541                 _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
6542                         this.copyLinearToGamma(this, gammaFactor);
6543                         return this;
6544                 };
6545
6546                 _proto.copySRGBToLinear = function copySRGBToLinear(color) {
6547                         this.r = SRGBToLinear(color.r);
6548                         this.g = SRGBToLinear(color.g);
6549                         this.b = SRGBToLinear(color.b);
6550                         return this;
6551                 };
6552
6553                 _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
6554                         this.r = LinearToSRGB(color.r);
6555                         this.g = LinearToSRGB(color.g);
6556                         this.b = LinearToSRGB(color.b);
6557                         return this;
6558                 };
6559
6560                 _proto.convertSRGBToLinear = function convertSRGBToLinear() {
6561                         this.copySRGBToLinear(this);
6562                         return this;
6563                 };
6564
6565                 _proto.convertLinearToSRGB = function convertLinearToSRGB() {
6566                         this.copyLinearToSRGB(this);
6567                         return this;
6568                 };
6569
6570                 _proto.getHex = function getHex() {
6571                         return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
6572                 };
6573
6574                 _proto.getHexString = function getHexString() {
6575                         return ('000000' + this.getHex().toString(16)).slice(-6);
6576                 };
6577
6578                 _proto.getHSL = function getHSL(target) {
6579                         // h,s,l ranges are in 0.0 - 1.0
6580                         if (target === undefined) {
6581                                 console.warn('THREE.Color: .getHSL() target is now required');
6582                                 target = {
6583                                         h: 0,
6584                                         s: 0,
6585                                         l: 0
6586                                 };
6587                         }
6588
6589                         var r = this.r,
6590                                         g = this.g,
6591                                         b = this.b;
6592                         var max = Math.max(r, g, b);
6593                         var min = Math.min(r, g, b);
6594                         var hue, saturation;
6595                         var lightness = (min + max) / 2.0;
6596
6597                         if (min === max) {
6598                                 hue = 0;
6599                                 saturation = 0;
6600                         } else {
6601                                 var delta = max - min;
6602                                 saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
6603
6604                                 switch (max) {
6605                                         case r:
6606                                                 hue = (g - b) / delta + (g < b ? 6 : 0);
6607                                                 break;
6608
6609                                         case g:
6610                                                 hue = (b - r) / delta + 2;
6611                                                 break;
6612
6613                                         case b:
6614                                                 hue = (r - g) / delta + 4;
6615                                                 break;
6616                                 }
6617
6618                                 hue /= 6;
6619                         }
6620
6621                         target.h = hue;
6622                         target.s = saturation;
6623                         target.l = lightness;
6624                         return target;
6625                 };
6626
6627                 _proto.getStyle = function getStyle() {
6628                         return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
6629                 };
6630
6631                 _proto.offsetHSL = function offsetHSL(h, s, l) {
6632                         this.getHSL(_hslA);
6633                         _hslA.h += h;
6634                         _hslA.s += s;
6635                         _hslA.l += l;
6636                         this.setHSL(_hslA.h, _hslA.s, _hslA.l);
6637                         return this;
6638                 };
6639
6640                 _proto.add = function add(color) {
6641                         this.r += color.r;
6642                         this.g += color.g;
6643                         this.b += color.b;
6644                         return this;
6645                 };
6646
6647                 _proto.addColors = function addColors(color1, color2) {
6648                         this.r = color1.r + color2.r;
6649                         this.g = color1.g + color2.g;
6650                         this.b = color1.b + color2.b;
6651                         return this;
6652                 };
6653
6654                 _proto.addScalar = function addScalar(s) {
6655                         this.r += s;
6656                         this.g += s;
6657                         this.b += s;
6658                         return this;
6659                 };
6660
6661                 _proto.sub = function sub(color) {
6662                         this.r = Math.max(0, this.r - color.r);
6663                         this.g = Math.max(0, this.g - color.g);
6664                         this.b = Math.max(0, this.b - color.b);
6665                         return this;
6666                 };
6667
6668                 _proto.multiply = function multiply(color) {
6669                         this.r *= color.r;
6670                         this.g *= color.g;
6671                         this.b *= color.b;
6672                         return this;
6673                 };
6674
6675                 _proto.multiplyScalar = function multiplyScalar(s) {
6676                         this.r *= s;
6677                         this.g *= s;
6678                         this.b *= s;
6679                         return this;
6680                 };
6681
6682                 _proto.lerp = function lerp(color, alpha) {
6683                         this.r += (color.r - this.r) * alpha;
6684                         this.g += (color.g - this.g) * alpha;
6685                         this.b += (color.b - this.b) * alpha;
6686                         return this;
6687                 };
6688
6689                 _proto.lerpHSL = function lerpHSL(color, alpha) {
6690                         this.getHSL(_hslA);
6691                         color.getHSL(_hslB);
6692                         var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
6693                         var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
6694                         var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
6695                         this.setHSL(h, s, l);
6696                         return this;
6697                 };
6698
6699                 _proto.equals = function equals(c) {
6700                         return c.r === this.r && c.g === this.g && c.b === this.b;
6701                 };
6702
6703                 _proto.fromArray = function fromArray(array, offset) {
6704                         if (offset === void 0) {
6705                                 offset = 0;
6706                         }
6707
6708                         this.r = array[offset];
6709                         this.g = array[offset + 1];
6710                         this.b = array[offset + 2];
6711                         return this;
6712                 };
6713
6714                 _proto.toArray = function toArray(array, offset) {
6715                         if (array === void 0) {
6716                                 array = [];
6717                         }
6718
6719                         if (offset === void 0) {
6720                                 offset = 0;
6721                         }
6722
6723                         array[offset] = this.r;
6724                         array[offset + 1] = this.g;
6725                         array[offset + 2] = this.b;
6726                         return array;
6727                 };
6728
6729                 _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
6730                         this.r = attribute.getX(index);
6731                         this.g = attribute.getY(index);
6732                         this.b = attribute.getZ(index);
6733
6734                         if (attribute.normalized === true) {
6735                                 // assuming Uint8Array
6736                                 this.r /= 255;
6737                                 this.g /= 255;
6738                                 this.b /= 255;
6739                         }
6740
6741                         return this;
6742                 };
6743
6744                 _proto.toJSON = function toJSON() {
6745                         return this.getHex();
6746                 };
6747
6748                 return Color;
6749         }();
6750
6751         Color.NAMES = _colorKeywords;
6752         Color.prototype.r = 1;
6753         Color.prototype.g = 1;
6754         Color.prototype.b = 1;
6755
6756         var Face3 = /*#__PURE__*/function () {
6757                 function Face3(a, b, c, normal, color, materialIndex) {
6758                         if (materialIndex === void 0) {
6759                                 materialIndex = 0;
6760                         }
6761
6762                         this.a = a;
6763                         this.b = b;
6764                         this.c = c;
6765                         this.normal = normal && normal.isVector3 ? normal : new Vector3();
6766                         this.vertexNormals = Array.isArray(normal) ? normal : [];
6767                         this.color = color && color.isColor ? color : new Color();
6768                         this.vertexColors = Array.isArray(color) ? color : [];
6769                         this.materialIndex = materialIndex;
6770                 }
6771
6772                 var _proto = Face3.prototype;
6773
6774                 _proto.clone = function clone() {
6775                         return new this.constructor().copy(this);
6776                 };
6777
6778                 _proto.copy = function copy(source) {
6779                         this.a = source.a;
6780                         this.b = source.b;
6781                         this.c = source.c;
6782                         this.normal.copy(source.normal);
6783                         this.color.copy(source.color);
6784                         this.materialIndex = source.materialIndex;
6785
6786                         for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
6787                                 this.vertexNormals[i] = source.vertexNormals[i].clone();
6788                         }
6789
6790                         for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
6791                                 this.vertexColors[_i] = source.vertexColors[_i].clone();
6792                         }
6793
6794                         return this;
6795                 };
6796
6797                 return Face3;
6798         }();
6799
6800         var materialId = 0;
6801
6802         function Material() {
6803                 Object.defineProperty(this, 'id', {
6804                         value: materialId++
6805                 });
6806                 this.uuid = MathUtils.generateUUID();
6807                 this.name = '';
6808                 this.type = 'Material';
6809                 this.fog = true;
6810                 this.blending = NormalBlending;
6811                 this.side = FrontSide;
6812                 this.flatShading = false;
6813                 this.vertexColors = false;
6814                 this.opacity = 1;
6815                 this.transparent = false;
6816                 this.blendSrc = SrcAlphaFactor;
6817                 this.blendDst = OneMinusSrcAlphaFactor;
6818                 this.blendEquation = AddEquation;
6819                 this.blendSrcAlpha = null;
6820                 this.blendDstAlpha = null;
6821                 this.blendEquationAlpha = null;
6822                 this.depthFunc = LessEqualDepth;
6823                 this.depthTest = true;
6824                 this.depthWrite = true;
6825                 this.stencilWriteMask = 0xff;
6826                 this.stencilFunc = AlwaysStencilFunc;
6827                 this.stencilRef = 0;
6828                 this.stencilFuncMask = 0xff;
6829                 this.stencilFail = KeepStencilOp;
6830                 this.stencilZFail = KeepStencilOp;
6831                 this.stencilZPass = KeepStencilOp;
6832                 this.stencilWrite = false;
6833                 this.clippingPlanes = null;
6834                 this.clipIntersection = false;
6835                 this.clipShadows = false;
6836                 this.shadowSide = null;
6837                 this.colorWrite = true;
6838                 this.precision = null; // override the renderer's default precision for this material
6839
6840                 this.polygonOffset = false;
6841                 this.polygonOffsetFactor = 0;
6842                 this.polygonOffsetUnits = 0;
6843                 this.dithering = false;
6844                 this.alphaTest = 0;
6845                 this.premultipliedAlpha = false;
6846                 this.visible = true;
6847                 this.toneMapped = true;
6848                 this.userData = {};
6849                 this.version = 0;
6850         }
6851
6852         Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
6853                 constructor: Material,
6854                 isMaterial: true,
6855                 onBeforeCompile: function onBeforeCompile()
6856                 /* shaderobject, renderer */
6857                 {},
6858                 customProgramCacheKey: function customProgramCacheKey() {
6859                         return this.onBeforeCompile.toString();
6860                 },
6861                 setValues: function setValues(values) {
6862                         if (values === undefined) return;
6863
6864                         for (var key in values) {
6865                                 var newValue = values[key];
6866
6867                                 if (newValue === undefined) {
6868                                         console.warn("THREE.Material: '" + key + "' parameter is undefined.");
6869                                         continue;
6870                                 } // for backward compatability if shading is set in the constructor
6871
6872
6873                                 if (key === 'shading') {
6874                                         console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
6875                                         this.flatShading = newValue === FlatShading ? true : false;
6876                                         continue;
6877                                 }
6878
6879                                 var currentValue = this[key];
6880
6881                                 if (currentValue === undefined) {
6882                                         console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
6883                                         continue;
6884                                 }
6885
6886                                 if (currentValue && currentValue.isColor) {
6887                                         currentValue.set(newValue);
6888                                 } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
6889                                         currentValue.copy(newValue);
6890                                 } else {
6891                                         this[key] = newValue;
6892                                 }
6893                         }
6894                 },
6895                 toJSON: function toJSON(meta) {
6896                         var isRoot = meta === undefined || typeof meta === 'string';
6897
6898                         if (isRoot) {
6899                                 meta = {
6900                                         textures: {},
6901                                         images: {}
6902                                 };
6903                         }
6904
6905                         var data = {
6906                                 metadata: {
6907                                         version: 4.5,
6908                                         type: 'Material',
6909                                         generator: 'Material.toJSON'
6910                                 }
6911                         }; // standard Material serialization
6912
6913                         data.uuid = this.uuid;
6914                         data.type = this.type;
6915                         if (this.name !== '') data.name = this.name;
6916                         if (this.color && this.color.isColor) data.color = this.color.getHex();
6917                         if (this.roughness !== undefined) data.roughness = this.roughness;
6918                         if (this.metalness !== undefined) data.metalness = this.metalness;
6919                         if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
6920                         if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
6921                         if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
6922                         if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
6923                         if (this.shininess !== undefined) data.shininess = this.shininess;
6924                         if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
6925                         if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
6926
6927                         if (this.clearcoatMap && this.clearcoatMap.isTexture) {
6928                                 data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
6929                         }
6930
6931                         if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
6932                                 data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
6933                         }
6934
6935                         if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
6936                                 data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
6937                                 data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
6938                         }
6939
6940                         if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
6941                         if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
6942                         if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
6943                         if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
6944
6945                         if (this.aoMap && this.aoMap.isTexture) {
6946                                 data.aoMap = this.aoMap.toJSON(meta).uuid;
6947                                 data.aoMapIntensity = this.aoMapIntensity;
6948                         }
6949
6950                         if (this.bumpMap && this.bumpMap.isTexture) {
6951                                 data.bumpMap = this.bumpMap.toJSON(meta).uuid;
6952                                 data.bumpScale = this.bumpScale;
6953                         }
6954
6955                         if (this.normalMap && this.normalMap.isTexture) {
6956                                 data.normalMap = this.normalMap.toJSON(meta).uuid;
6957                                 data.normalMapType = this.normalMapType;
6958                                 data.normalScale = this.normalScale.toArray();
6959                         }
6960
6961                         if (this.displacementMap && this.displacementMap.isTexture) {
6962                                 data.displacementMap = this.displacementMap.toJSON(meta).uuid;
6963                                 data.displacementScale = this.displacementScale;
6964                                 data.displacementBias = this.displacementBias;
6965                         }
6966
6967                         if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
6968                         if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
6969                         if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
6970                         if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
6971
6972                         if (this.envMap && this.envMap.isTexture) {
6973                                 data.envMap = this.envMap.toJSON(meta).uuid;
6974                                 data.reflectivity = this.reflectivity; // Scale behind envMap
6975
6976                                 data.refractionRatio = this.refractionRatio;
6977                                 if (this.combine !== undefined) data.combine = this.combine;
6978                                 if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
6979                         }
6980
6981                         if (this.gradientMap && this.gradientMap.isTexture) {
6982                                 data.gradientMap = this.gradientMap.toJSON(meta).uuid;
6983                         }
6984
6985                         if (this.size !== undefined) data.size = this.size;
6986                         if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
6987                         if (this.blending !== NormalBlending) data.blending = this.blending;
6988                         if (this.flatShading === true) data.flatShading = this.flatShading;
6989                         if (this.side !== FrontSide) data.side = this.side;
6990                         if (this.vertexColors) data.vertexColors = true;
6991                         if (this.opacity < 1) data.opacity = this.opacity;
6992                         if (this.transparent === true) data.transparent = this.transparent;
6993                         data.depthFunc = this.depthFunc;
6994                         data.depthTest = this.depthTest;
6995                         data.depthWrite = this.depthWrite;
6996                         data.stencilWrite = this.stencilWrite;
6997                         data.stencilWriteMask = this.stencilWriteMask;
6998                         data.stencilFunc = this.stencilFunc;
6999                         data.stencilRef = this.stencilRef;
7000                         data.stencilFuncMask = this.stencilFuncMask;
7001                         data.stencilFail = this.stencilFail;
7002                         data.stencilZFail = this.stencilZFail;
7003                         data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
7004
7005                         if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
7006                         if (this.polygonOffset === true) data.polygonOffset = true;
7007                         if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
7008                         if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
7009                         if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
7010                         if (this.dashSize !== undefined) data.dashSize = this.dashSize;
7011                         if (this.gapSize !== undefined) data.gapSize = this.gapSize;
7012                         if (this.scale !== undefined) data.scale = this.scale;
7013                         if (this.dithering === true) data.dithering = true;
7014                         if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
7015                         if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
7016                         if (this.wireframe === true) data.wireframe = this.wireframe;
7017                         if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
7018                         if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
7019                         if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
7020                         if (this.morphTargets === true) data.morphTargets = true;
7021                         if (this.morphNormals === true) data.morphNormals = true;
7022                         if (this.skinning === true) data.skinning = true;
7023                         if (this.visible === false) data.visible = false;
7024                         if (this.toneMapped === false) data.toneMapped = false;
7025                         if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
7026
7027                         function extractFromCache(cache) {
7028                                 var values = [];
7029
7030                                 for (var key in cache) {
7031                                         var _data = cache[key];
7032                                         delete _data.metadata;
7033                                         values.push(_data);
7034                                 }
7035
7036                                 return values;
7037                         }
7038
7039                         if (isRoot) {
7040                                 var textures = extractFromCache(meta.textures);
7041                                 var images = extractFromCache(meta.images);
7042                                 if (textures.length > 0) data.textures = textures;
7043                                 if (images.length > 0) data.images = images;
7044                         }
7045
7046                         return data;
7047                 },
7048                 clone: function clone() {
7049                         return new this.constructor().copy(this);
7050                 },
7051                 copy: function copy(source) {
7052                         this.name = source.name;
7053                         this.fog = source.fog;
7054                         this.blending = source.blending;
7055                         this.side = source.side;
7056                         this.flatShading = source.flatShading;
7057                         this.vertexColors = source.vertexColors;
7058                         this.opacity = source.opacity;
7059                         this.transparent = source.transparent;
7060                         this.blendSrc = source.blendSrc;
7061                         this.blendDst = source.blendDst;
7062                         this.blendEquation = source.blendEquation;
7063                         this.blendSrcAlpha = source.blendSrcAlpha;
7064                         this.blendDstAlpha = source.blendDstAlpha;
7065                         this.blendEquationAlpha = source.blendEquationAlpha;
7066                         this.depthFunc = source.depthFunc;
7067                         this.depthTest = source.depthTest;
7068                         this.depthWrite = source.depthWrite;
7069                         this.stencilWriteMask = source.stencilWriteMask;
7070                         this.stencilFunc = source.stencilFunc;
7071                         this.stencilRef = source.stencilRef;
7072                         this.stencilFuncMask = source.stencilFuncMask;
7073                         this.stencilFail = source.stencilFail;
7074                         this.stencilZFail = source.stencilZFail;
7075                         this.stencilZPass = source.stencilZPass;
7076                         this.stencilWrite = source.stencilWrite;
7077                         var srcPlanes = source.clippingPlanes;
7078                         var dstPlanes = null;
7079
7080                         if (srcPlanes !== null) {
7081                                 var n = srcPlanes.length;
7082                                 dstPlanes = new Array(n);
7083
7084                                 for (var i = 0; i !== n; ++i) {
7085                                         dstPlanes[i] = srcPlanes[i].clone();
7086                                 }
7087                         }
7088
7089                         this.clippingPlanes = dstPlanes;
7090                         this.clipIntersection = source.clipIntersection;
7091                         this.clipShadows = source.clipShadows;
7092                         this.shadowSide = source.shadowSide;
7093                         this.colorWrite = source.colorWrite;
7094                         this.precision = source.precision;
7095                         this.polygonOffset = source.polygonOffset;
7096                         this.polygonOffsetFactor = source.polygonOffsetFactor;
7097                         this.polygonOffsetUnits = source.polygonOffsetUnits;
7098                         this.dithering = source.dithering;
7099                         this.alphaTest = source.alphaTest;
7100                         this.premultipliedAlpha = source.premultipliedAlpha;
7101                         this.visible = source.visible;
7102                         this.toneMapped = source.toneMapped;
7103                         this.userData = JSON.parse(JSON.stringify(source.userData));
7104                         return this;
7105                 },
7106                 dispose: function dispose() {
7107                         this.dispatchEvent({
7108                                 type: 'dispose'
7109                         });
7110                 }
7111         });
7112         Object.defineProperty(Material.prototype, 'needsUpdate', {
7113                 set: function set(value) {
7114                         if (value === true) this.version++;
7115                 }
7116         });
7117
7118         /**
7119          * parameters = {
7120          *      color: <hex>,
7121          *      opacity: <float>,
7122          *      map: new THREE.Texture( <Image> ),
7123          *
7124          *      lightMap: new THREE.Texture( <Image> ),
7125          *      lightMapIntensity: <float>
7126          *
7127          *      aoMap: new THREE.Texture( <Image> ),
7128          *      aoMapIntensity: <float>
7129          *
7130          *      specularMap: new THREE.Texture( <Image> ),
7131          *
7132          *      alphaMap: new THREE.Texture( <Image> ),
7133          *
7134          *      envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
7135          *      combine: THREE.Multiply,
7136          *      reflectivity: <float>,
7137          *      refractionRatio: <float>,
7138          *
7139          *      depthTest: <bool>,
7140          *      depthWrite: <bool>,
7141          *
7142          *      wireframe: <boolean>,
7143          *      wireframeLinewidth: <float>,
7144          *
7145          *      skinning: <bool>,
7146          *      morphTargets: <bool>
7147          * }
7148          */
7149
7150         function MeshBasicMaterial(parameters) {
7151                 Material.call(this);
7152                 this.type = 'MeshBasicMaterial';
7153                 this.color = new Color(0xffffff); // emissive
7154
7155                 this.map = null;
7156                 this.lightMap = null;
7157                 this.lightMapIntensity = 1.0;
7158                 this.aoMap = null;
7159                 this.aoMapIntensity = 1.0;
7160                 this.specularMap = null;
7161                 this.alphaMap = null;
7162                 this.envMap = null;
7163                 this.combine = MultiplyOperation;
7164                 this.reflectivity = 1;
7165                 this.refractionRatio = 0.98;
7166                 this.wireframe = false;
7167                 this.wireframeLinewidth = 1;
7168                 this.wireframeLinecap = 'round';
7169                 this.wireframeLinejoin = 'round';
7170                 this.skinning = false;
7171                 this.morphTargets = false;
7172                 this.setValues(parameters);
7173         }
7174
7175         MeshBasicMaterial.prototype = Object.create(Material.prototype);
7176         MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
7177         MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
7178
7179         MeshBasicMaterial.prototype.copy = function (source) {
7180                 Material.prototype.copy.call(this, source);
7181                 this.color.copy(source.color);
7182                 this.map = source.map;
7183                 this.lightMap = source.lightMap;
7184                 this.lightMapIntensity = source.lightMapIntensity;
7185                 this.aoMap = source.aoMap;
7186                 this.aoMapIntensity = source.aoMapIntensity;
7187                 this.specularMap = source.specularMap;
7188                 this.alphaMap = source.alphaMap;
7189                 this.envMap = source.envMap;
7190                 this.combine = source.combine;
7191                 this.reflectivity = source.reflectivity;
7192                 this.refractionRatio = source.refractionRatio;
7193                 this.wireframe = source.wireframe;
7194                 this.wireframeLinewidth = source.wireframeLinewidth;
7195                 this.wireframeLinecap = source.wireframeLinecap;
7196                 this.wireframeLinejoin = source.wireframeLinejoin;
7197                 this.skinning = source.skinning;
7198                 this.morphTargets = source.morphTargets;
7199                 return this;
7200         };
7201
7202         var _vector$3 = new Vector3();
7203
7204         var _vector2$1 = new Vector2();
7205
7206         function BufferAttribute(array, itemSize, normalized) {
7207                 if (Array.isArray(array)) {
7208                         throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
7209                 }
7210
7211                 this.name = '';
7212                 this.array = array;
7213                 this.itemSize = itemSize;
7214                 this.count = array !== undefined ? array.length / itemSize : 0;
7215                 this.normalized = normalized === true;
7216                 this.usage = StaticDrawUsage;
7217                 this.updateRange = {
7218                         offset: 0,
7219                         count: -1
7220                 };
7221                 this.version = 0;
7222         }
7223
7224         Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
7225                 set: function set(value) {
7226                         if (value === true) this.version++;
7227                 }
7228         });
7229         Object.assign(BufferAttribute.prototype, {
7230                 isBufferAttribute: true,
7231                 onUploadCallback: function onUploadCallback() {},
7232                 setUsage: function setUsage(value) {
7233                         this.usage = value;
7234                         return this;
7235                 },
7236                 copy: function copy(source) {
7237                         this.name = source.name;
7238                         this.array = new source.array.constructor(source.array);
7239                         this.itemSize = source.itemSize;
7240                         this.count = source.count;
7241                         this.normalized = source.normalized;
7242                         this.usage = source.usage;
7243                         return this;
7244                 },
7245                 copyAt: function copyAt(index1, attribute, index2) {
7246                         index1 *= this.itemSize;
7247                         index2 *= attribute.itemSize;
7248
7249                         for (var i = 0, l = this.itemSize; i < l; i++) {
7250                                 this.array[index1 + i] = attribute.array[index2 + i];
7251                         }
7252
7253                         return this;
7254                 },
7255                 copyArray: function copyArray(array) {
7256                         this.array.set(array);
7257                         return this;
7258                 },
7259                 copyColorsArray: function copyColorsArray(colors) {
7260                         var array = this.array;
7261                         var offset = 0;
7262
7263                         for (var i = 0, l = colors.length; i < l; i++) {
7264                                 var color = colors[i];
7265
7266                                 if (color === undefined) {
7267                                         console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
7268                                         color = new Color();
7269                                 }
7270
7271                                 array[offset++] = color.r;
7272                                 array[offset++] = color.g;
7273                                 array[offset++] = color.b;
7274                         }
7275
7276                         return this;
7277                 },
7278                 copyVector2sArray: function copyVector2sArray(vectors) {
7279                         var array = this.array;
7280                         var offset = 0;
7281
7282                         for (var i = 0, l = vectors.length; i < l; i++) {
7283                                 var vector = vectors[i];
7284
7285                                 if (vector === undefined) {
7286                                         console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
7287                                         vector = new Vector2();
7288                                 }
7289
7290                                 array[offset++] = vector.x;
7291                                 array[offset++] = vector.y;
7292                         }
7293
7294                         return this;
7295                 },
7296                 copyVector3sArray: function copyVector3sArray(vectors) {
7297                         var array = this.array;
7298                         var offset = 0;
7299
7300                         for (var i = 0, l = vectors.length; i < l; i++) {
7301                                 var vector = vectors[i];
7302
7303                                 if (vector === undefined) {
7304                                         console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
7305                                         vector = new Vector3();
7306                                 }
7307
7308                                 array[offset++] = vector.x;
7309                                 array[offset++] = vector.y;
7310                                 array[offset++] = vector.z;
7311                         }
7312
7313                         return this;
7314                 },
7315                 copyVector4sArray: function copyVector4sArray(vectors) {
7316                         var array = this.array;
7317                         var offset = 0;
7318
7319                         for (var i = 0, l = vectors.length; i < l; i++) {
7320                                 var vector = vectors[i];
7321
7322                                 if (vector === undefined) {
7323                                         console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
7324                                         vector = new Vector4();
7325                                 }
7326
7327                                 array[offset++] = vector.x;
7328                                 array[offset++] = vector.y;
7329                                 array[offset++] = vector.z;
7330                                 array[offset++] = vector.w;
7331                         }
7332
7333                         return this;
7334                 },
7335                 applyMatrix3: function applyMatrix3(m) {
7336                         if (this.itemSize === 2) {
7337                                 for (var i = 0, l = this.count; i < l; i++) {
7338                                         _vector2$1.fromBufferAttribute(this, i);
7339
7340                                         _vector2$1.applyMatrix3(m);
7341
7342                                         this.setXY(i, _vector2$1.x, _vector2$1.y);
7343                                 }
7344                         } else if (this.itemSize === 3) {
7345                                 for (var _i = 0, _l = this.count; _i < _l; _i++) {
7346                                         _vector$3.fromBufferAttribute(this, _i);
7347
7348                                         _vector$3.applyMatrix3(m);
7349
7350                                         this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
7351                                 }
7352                         }
7353
7354                         return this;
7355                 },
7356                 applyMatrix4: function applyMatrix4(m) {
7357                         for (var i = 0, l = this.count; i < l; i++) {
7358                                 _vector$3.x = this.getX(i);
7359                                 _vector$3.y = this.getY(i);
7360                                 _vector$3.z = this.getZ(i);
7361
7362                                 _vector$3.applyMatrix4(m);
7363
7364                                 this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
7365                         }
7366
7367                         return this;
7368                 },
7369                 applyNormalMatrix: function applyNormalMatrix(m) {
7370                         for (var i = 0, l = this.count; i < l; i++) {
7371                                 _vector$3.x = this.getX(i);
7372                                 _vector$3.y = this.getY(i);
7373                                 _vector$3.z = this.getZ(i);
7374
7375                                 _vector$3.applyNormalMatrix(m);
7376
7377                                 this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
7378                         }
7379
7380                         return this;
7381                 },
7382                 transformDirection: function transformDirection(m) {
7383                         for (var i = 0, l = this.count; i < l; i++) {
7384                                 _vector$3.x = this.getX(i);
7385                                 _vector$3.y = this.getY(i);
7386                                 _vector$3.z = this.getZ(i);
7387
7388                                 _vector$3.transformDirection(m);
7389
7390                                 this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
7391                         }
7392
7393                         return this;
7394                 },
7395                 set: function set(value, offset) {
7396                         if (offset === void 0) {
7397                                 offset = 0;
7398                         }
7399
7400                         this.array.set(value, offset);
7401                         return this;
7402                 },
7403                 getX: function getX(index) {
7404                         return this.array[index * this.itemSize];
7405                 },
7406                 setX: function setX(index, x) {
7407                         this.array[index * this.itemSize] = x;
7408                         return this;
7409                 },
7410                 getY: function getY(index) {
7411                         return this.array[index * this.itemSize + 1];
7412                 },
7413                 setY: function setY(index, y) {
7414                         this.array[index * this.itemSize + 1] = y;
7415                         return this;
7416                 },
7417                 getZ: function getZ(index) {
7418                         return this.array[index * this.itemSize + 2];
7419                 },
7420                 setZ: function setZ(index, z) {
7421                         this.array[index * this.itemSize + 2] = z;
7422                         return this;
7423                 },
7424                 getW: function getW(index) {
7425                         return this.array[index * this.itemSize + 3];
7426                 },
7427                 setW: function setW(index, w) {
7428                         this.array[index * this.itemSize + 3] = w;
7429                         return this;
7430                 },
7431                 setXY: function setXY(index, x, y) {
7432                         index *= this.itemSize;
7433                         this.array[index + 0] = x;
7434                         this.array[index + 1] = y;
7435                         return this;
7436                 },
7437                 setXYZ: function setXYZ(index, x, y, z) {
7438                         index *= this.itemSize;
7439                         this.array[index + 0] = x;
7440                         this.array[index + 1] = y;
7441                         this.array[index + 2] = z;
7442                         return this;
7443                 },
7444                 setXYZW: function setXYZW(index, x, y, z, w) {
7445                         index *= this.itemSize;
7446                         this.array[index + 0] = x;
7447                         this.array[index + 1] = y;
7448                         this.array[index + 2] = z;
7449                         this.array[index + 3] = w;
7450                         return this;
7451                 },
7452                 onUpload: function onUpload(callback) {
7453                         this.onUploadCallback = callback;
7454                         return this;
7455                 },
7456                 clone: function clone() {
7457                         return new this.constructor(this.array, this.itemSize).copy(this);
7458                 },
7459                 toJSON: function toJSON() {
7460                         return {
7461                                 itemSize: this.itemSize,
7462                                 type: this.array.constructor.name,
7463                                 array: Array.prototype.slice.call(this.array),
7464                                 normalized: this.normalized
7465                         };
7466                 }
7467         }); //
7468
7469         function Int8BufferAttribute(array, itemSize, normalized) {
7470                 BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
7471         }
7472
7473         Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7474         Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
7475
7476         function Uint8BufferAttribute(array, itemSize, normalized) {
7477                 BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
7478         }
7479
7480         Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7481         Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
7482
7483         function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
7484                 BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
7485         }
7486
7487         Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7488         Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
7489
7490         function Int16BufferAttribute(array, itemSize, normalized) {
7491                 BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
7492         }
7493
7494         Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7495         Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
7496
7497         function Uint16BufferAttribute(array, itemSize, normalized) {
7498                 BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
7499         }
7500
7501         Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7502         Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
7503
7504         function Int32BufferAttribute(array, itemSize, normalized) {
7505                 BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
7506         }
7507
7508         Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7509         Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
7510
7511         function Uint32BufferAttribute(array, itemSize, normalized) {
7512                 BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
7513         }
7514
7515         Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7516         Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
7517
7518         function Float16BufferAttribute(array, itemSize, normalized) {
7519                 BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
7520         }
7521
7522         Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7523         Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
7524         Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
7525
7526         function Float32BufferAttribute(array, itemSize, normalized) {
7527                 BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
7528         }
7529
7530         Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7531         Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
7532
7533         function Float64BufferAttribute(array, itemSize, normalized) {
7534                 BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
7535         }
7536
7537         Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
7538         Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
7539
7540         var DirectGeometry = /*#__PURE__*/function () {
7541                 function DirectGeometry() {
7542                         this.vertices = [];
7543                         this.normals = [];
7544                         this.colors = [];
7545                         this.uvs = [];
7546                         this.uvs2 = [];
7547                         this.groups = [];
7548                         this.morphTargets = {};
7549                         this.skinWeights = [];
7550                         this.skinIndices = []; // this.lineDistances = [];
7551
7552                         this.boundingBox = null;
7553                         this.boundingSphere = null; // update flags
7554
7555                         this.verticesNeedUpdate = false;
7556                         this.normalsNeedUpdate = false;
7557                         this.colorsNeedUpdate = false;
7558                         this.uvsNeedUpdate = false;
7559                         this.groupsNeedUpdate = false;
7560                 }
7561
7562                 var _proto = DirectGeometry.prototype;
7563
7564                 _proto.computeGroups = function computeGroups(geometry) {
7565                         var groups = [];
7566                         var group, i;
7567                         var materialIndex = undefined;
7568                         var faces = geometry.faces;
7569
7570                         for (i = 0; i < faces.length; i++) {
7571                                 var face = faces[i]; // materials
7572
7573                                 if (face.materialIndex !== materialIndex) {
7574                                         materialIndex = face.materialIndex;
7575
7576                                         if (group !== undefined) {
7577                                                 group.count = i * 3 - group.start;
7578                                                 groups.push(group);
7579                                         }
7580
7581                                         group = {
7582                                                 start: i * 3,
7583                                                 materialIndex: materialIndex
7584                                         };
7585                                 }
7586                         }
7587
7588                         if (group !== undefined) {
7589                                 group.count = i * 3 - group.start;
7590                                 groups.push(group);
7591                         }
7592
7593                         this.groups = groups;
7594                 };
7595
7596                 _proto.fromGeometry = function fromGeometry(geometry) {
7597                         var faces = geometry.faces;
7598                         var vertices = geometry.vertices;
7599                         var faceVertexUvs = geometry.faceVertexUvs;
7600                         var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
7601                         var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
7602
7603                         var morphTargets = geometry.morphTargets;
7604                         var morphTargetsLength = morphTargets.length;
7605                         var morphTargetsPosition;
7606
7607                         if (morphTargetsLength > 0) {
7608                                 morphTargetsPosition = [];
7609
7610                                 for (var i = 0; i < morphTargetsLength; i++) {
7611                                         morphTargetsPosition[i] = {
7612                                                 name: morphTargets[i].name,
7613                                                 data: []
7614                                         };
7615                                 }
7616
7617                                 this.morphTargets.position = morphTargetsPosition;
7618                         }
7619
7620                         var morphNormals = geometry.morphNormals;
7621                         var morphNormalsLength = morphNormals.length;
7622                         var morphTargetsNormal;
7623
7624                         if (morphNormalsLength > 0) {
7625                                 morphTargetsNormal = [];
7626
7627                                 for (var _i = 0; _i < morphNormalsLength; _i++) {
7628                                         morphTargetsNormal[_i] = {
7629                                                 name: morphNormals[_i].name,
7630                                                 data: []
7631                                         };
7632                                 }
7633
7634                                 this.morphTargets.normal = morphTargetsNormal;
7635                         } // skins
7636
7637
7638                         var skinIndices = geometry.skinIndices;
7639                         var skinWeights = geometry.skinWeights;
7640                         var hasSkinIndices = skinIndices.length === vertices.length;
7641                         var hasSkinWeights = skinWeights.length === vertices.length; //
7642
7643                         if (vertices.length > 0 && faces.length === 0) {
7644                                 console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
7645                         }
7646
7647                         for (var _i2 = 0; _i2 < faces.length; _i2++) {
7648                                 var face = faces[_i2];
7649                                 this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
7650                                 var vertexNormals = face.vertexNormals;
7651
7652                                 if (vertexNormals.length === 3) {
7653                                         this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
7654                                 } else {
7655                                         var normal = face.normal;
7656                                         this.normals.push(normal, normal, normal);
7657                                 }
7658
7659                                 var vertexColors = face.vertexColors;
7660
7661                                 if (vertexColors.length === 3) {
7662                                         this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
7663                                 } else {
7664                                         var color = face.color;
7665                                         this.colors.push(color, color, color);
7666                                 }
7667
7668                                 if (hasFaceVertexUv === true) {
7669                                         var vertexUvs = faceVertexUvs[0][_i2];
7670
7671                                         if (vertexUvs !== undefined) {
7672                                                 this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
7673                                         } else {
7674                                                 console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
7675                                                 this.uvs.push(new Vector2(), new Vector2(), new Vector2());
7676                                         }
7677                                 }
7678
7679                                 if (hasFaceVertexUv2 === true) {
7680                                         var _vertexUvs = faceVertexUvs[1][_i2];
7681
7682                                         if (_vertexUvs !== undefined) {
7683                                                 this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
7684                                         } else {
7685                                                 console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
7686                                                 this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
7687                                         }
7688                                 } // morphs
7689
7690
7691                                 for (var j = 0; j < morphTargetsLength; j++) {
7692                                         var morphTarget = morphTargets[j].vertices;
7693                                         morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
7694                                 }
7695
7696                                 for (var _j = 0; _j < morphNormalsLength; _j++) {
7697                                         var morphNormal = morphNormals[_j].vertexNormals[_i2];
7698
7699                                         morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
7700                                 } // skins
7701
7702
7703                                 if (hasSkinIndices) {
7704                                         this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
7705                                 }
7706
7707                                 if (hasSkinWeights) {
7708                                         this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
7709                                 }
7710                         }
7711
7712                         this.computeGroups(geometry);
7713                         this.verticesNeedUpdate = geometry.verticesNeedUpdate;
7714                         this.normalsNeedUpdate = geometry.normalsNeedUpdate;
7715                         this.colorsNeedUpdate = geometry.colorsNeedUpdate;
7716                         this.uvsNeedUpdate = geometry.uvsNeedUpdate;
7717                         this.groupsNeedUpdate = geometry.groupsNeedUpdate;
7718
7719                         if (geometry.boundingSphere !== null) {
7720                                 this.boundingSphere = geometry.boundingSphere.clone();
7721                         }
7722
7723                         if (geometry.boundingBox !== null) {
7724                                 this.boundingBox = geometry.boundingBox.clone();
7725                         }
7726
7727                         return this;
7728                 };
7729
7730                 return DirectGeometry;
7731         }();
7732
7733         function arrayMax(array) {
7734                 if (array.length === 0) return -Infinity;
7735                 var max = array[0];
7736
7737                 for (var i = 1, l = array.length; i < l; ++i) {
7738                         if (array[i] > max) max = array[i];
7739                 }
7740
7741                 return max;
7742         }
7743
7744         var TYPED_ARRAYS = {
7745                 Int8Array: Int8Array,
7746                 Uint8Array: Uint8Array,
7747                 // Workaround for IE11 pre KB2929437. See #11440
7748                 Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
7749                 Int16Array: Int16Array,
7750                 Uint16Array: Uint16Array,
7751                 Int32Array: Int32Array,
7752                 Uint32Array: Uint32Array,
7753                 Float32Array: Float32Array,
7754                 Float64Array: Float64Array
7755         };
7756
7757         function getTypedArray(type, buffer) {
7758                 return new TYPED_ARRAYS[type](buffer);
7759         }
7760
7761         var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
7762
7763         var _m1$2 = new Matrix4();
7764
7765         var _obj = new Object3D();
7766
7767         var _offset = new Vector3();
7768
7769         var _box$2 = new Box3();
7770
7771         var _boxMorphTargets = new Box3();
7772
7773         var _vector$4 = new Vector3();
7774
7775         function BufferGeometry() {
7776                 Object.defineProperty(this, 'id', {
7777                         value: _bufferGeometryId += 2
7778                 });
7779                 this.uuid = MathUtils.generateUUID();
7780                 this.name = '';
7781                 this.type = 'BufferGeometry';
7782                 this.index = null;
7783                 this.attributes = {};
7784                 this.morphAttributes = {};
7785                 this.morphTargetsRelative = false;
7786                 this.groups = [];
7787                 this.boundingBox = null;
7788                 this.boundingSphere = null;
7789                 this.drawRange = {
7790                         start: 0,
7791                         count: Infinity
7792                 };
7793                 this.userData = {};
7794         }
7795
7796         BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
7797                 constructor: BufferGeometry,
7798                 isBufferGeometry: true,
7799                 getIndex: function getIndex() {
7800                         return this.index;
7801                 },
7802                 setIndex: function setIndex(index) {
7803                         if (Array.isArray(index)) {
7804                                 this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
7805                         } else {
7806                                 this.index = index;
7807                         }
7808
7809                         return this;
7810                 },
7811                 getAttribute: function getAttribute(name) {
7812                         return this.attributes[name];
7813                 },
7814                 setAttribute: function setAttribute(name, attribute) {
7815                         this.attributes[name] = attribute;
7816                         return this;
7817                 },
7818                 deleteAttribute: function deleteAttribute(name) {
7819                         delete this.attributes[name];
7820                         return this;
7821                 },
7822                 hasAttribute: function hasAttribute(name) {
7823                         return this.attributes[name] !== undefined;
7824                 },
7825                 addGroup: function addGroup(start, count, materialIndex) {
7826                         if (materialIndex === void 0) {
7827                                 materialIndex = 0;
7828                         }
7829
7830                         this.groups.push({
7831                                 start: start,
7832                                 count: count,
7833                                 materialIndex: materialIndex
7834                         });
7835                 },
7836                 clearGroups: function clearGroups() {
7837                         this.groups = [];
7838                 },
7839                 setDrawRange: function setDrawRange(start, count) {
7840                         this.drawRange.start = start;
7841                         this.drawRange.count = count;
7842                 },
7843                 applyMatrix4: function applyMatrix4(matrix) {
7844                         var position = this.attributes.position;
7845
7846                         if (position !== undefined) {
7847                                 position.applyMatrix4(matrix);
7848                                 position.needsUpdate = true;
7849                         }
7850
7851                         var normal = this.attributes.normal;
7852
7853                         if (normal !== undefined) {
7854                                 var normalMatrix = new Matrix3().getNormalMatrix(matrix);
7855                                 normal.applyNormalMatrix(normalMatrix);
7856                                 normal.needsUpdate = true;
7857                         }
7858
7859                         var tangent = this.attributes.tangent;
7860
7861                         if (tangent !== undefined) {
7862                                 tangent.transformDirection(matrix);
7863                                 tangent.needsUpdate = true;
7864                         }
7865
7866                         if (this.boundingBox !== null) {
7867                                 this.computeBoundingBox();
7868                         }
7869
7870                         if (this.boundingSphere !== null) {
7871                                 this.computeBoundingSphere();
7872                         }
7873
7874                         return this;
7875                 },
7876                 rotateX: function rotateX(angle) {
7877                         // rotate geometry around world x-axis
7878                         _m1$2.makeRotationX(angle);
7879
7880                         this.applyMatrix4(_m1$2);
7881                         return this;
7882                 },
7883                 rotateY: function rotateY(angle) {
7884                         // rotate geometry around world y-axis
7885                         _m1$2.makeRotationY(angle);
7886
7887                         this.applyMatrix4(_m1$2);
7888                         return this;
7889                 },
7890                 rotateZ: function rotateZ(angle) {
7891                         // rotate geometry around world z-axis
7892                         _m1$2.makeRotationZ(angle);
7893
7894                         this.applyMatrix4(_m1$2);
7895                         return this;
7896                 },
7897                 translate: function translate(x, y, z) {
7898                         // translate geometry
7899                         _m1$2.makeTranslation(x, y, z);
7900
7901                         this.applyMatrix4(_m1$2);
7902                         return this;
7903                 },
7904                 scale: function scale(x, y, z) {
7905                         // scale geometry
7906                         _m1$2.makeScale(x, y, z);
7907
7908                         this.applyMatrix4(_m1$2);
7909                         return this;
7910                 },
7911                 lookAt: function lookAt(vector) {
7912                         _obj.lookAt(vector);
7913
7914                         _obj.updateMatrix();
7915
7916                         this.applyMatrix4(_obj.matrix);
7917                         return this;
7918                 },
7919                 center: function center() {
7920                         this.computeBoundingBox();
7921                         this.boundingBox.getCenter(_offset).negate();
7922                         this.translate(_offset.x, _offset.y, _offset.z);
7923                         return this;
7924                 },
7925                 setFromObject: function setFromObject(object) {
7926                         // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
7927                         var geometry = object.geometry;
7928
7929                         if (object.isPoints || object.isLine) {
7930                                 var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
7931                                 var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
7932                                 this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
7933                                 this.setAttribute('color', colors.copyColorsArray(geometry.colors));
7934
7935                                 if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
7936                                         var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
7937                                         this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
7938                                 }
7939
7940                                 if (geometry.boundingSphere !== null) {
7941                                         this.boundingSphere = geometry.boundingSphere.clone();
7942                                 }
7943
7944                                 if (geometry.boundingBox !== null) {
7945                                         this.boundingBox = geometry.boundingBox.clone();
7946                                 }
7947                         } else if (object.isMesh) {
7948                                 if (geometry && geometry.isGeometry) {
7949                                         this.fromGeometry(geometry);
7950                                 }
7951                         }
7952
7953                         return this;
7954                 },
7955                 setFromPoints: function setFromPoints(points) {
7956                         var position = [];
7957
7958                         for (var i = 0, l = points.length; i < l; i++) {
7959                                 var point = points[i];
7960                                 position.push(point.x, point.y, point.z || 0);
7961                         }
7962
7963                         this.setAttribute('position', new Float32BufferAttribute(position, 3));
7964                         return this;
7965                 },
7966                 updateFromObject: function updateFromObject(object) {
7967                         var geometry = object.geometry;
7968
7969                         if (object.isMesh) {
7970                                 var direct = geometry.__directGeometry;
7971
7972                                 if (geometry.elementsNeedUpdate === true) {
7973                                         direct = undefined;
7974                                         geometry.elementsNeedUpdate = false;
7975                                 }
7976
7977                                 if (direct === undefined) {
7978                                         return this.fromGeometry(geometry);
7979                                 }
7980
7981                                 direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
7982                                 direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
7983                                 direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
7984                                 direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
7985                                 direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
7986                                 geometry.verticesNeedUpdate = false;
7987                                 geometry.normalsNeedUpdate = false;
7988                                 geometry.colorsNeedUpdate = false;
7989                                 geometry.uvsNeedUpdate = false;
7990                                 geometry.groupsNeedUpdate = false;
7991                                 geometry = direct;
7992                         }
7993
7994                         if (geometry.verticesNeedUpdate === true) {
7995                                 var attribute = this.attributes.position;
7996
7997                                 if (attribute !== undefined) {
7998                                         attribute.copyVector3sArray(geometry.vertices);
7999                                         attribute.needsUpdate = true;
8000                                 }
8001
8002                                 geometry.verticesNeedUpdate = false;
8003                         }
8004
8005                         if (geometry.normalsNeedUpdate === true) {
8006                                 var _attribute = this.attributes.normal;
8007
8008                                 if (_attribute !== undefined) {
8009                                         _attribute.copyVector3sArray(geometry.normals);
8010
8011                                         _attribute.needsUpdate = true;
8012                                 }
8013
8014                                 geometry.normalsNeedUpdate = false;
8015                         }
8016
8017                         if (geometry.colorsNeedUpdate === true) {
8018                                 var _attribute2 = this.attributes.color;
8019
8020                                 if (_attribute2 !== undefined) {
8021                                         _attribute2.copyColorsArray(geometry.colors);
8022
8023                                         _attribute2.needsUpdate = true;
8024                                 }
8025
8026                                 geometry.colorsNeedUpdate = false;
8027                         }
8028
8029                         if (geometry.uvsNeedUpdate) {
8030                                 var _attribute3 = this.attributes.uv;
8031
8032                                 if (_attribute3 !== undefined) {
8033                                         _attribute3.copyVector2sArray(geometry.uvs);
8034
8035                                         _attribute3.needsUpdate = true;
8036                                 }
8037
8038                                 geometry.uvsNeedUpdate = false;
8039                         }
8040
8041                         if (geometry.lineDistancesNeedUpdate) {
8042                                 var _attribute4 = this.attributes.lineDistance;
8043
8044                                 if (_attribute4 !== undefined) {
8045                                         _attribute4.copyArray(geometry.lineDistances);
8046
8047                                         _attribute4.needsUpdate = true;
8048                                 }
8049
8050                                 geometry.lineDistancesNeedUpdate = false;
8051                         }
8052
8053                         if (geometry.groupsNeedUpdate) {
8054                                 geometry.computeGroups(object.geometry);
8055                                 this.groups = geometry.groups;
8056                                 geometry.groupsNeedUpdate = false;
8057                         }
8058
8059                         return this;
8060                 },
8061                 fromGeometry: function fromGeometry(geometry) {
8062                         geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
8063                         return this.fromDirectGeometry(geometry.__directGeometry);
8064                 },
8065                 fromDirectGeometry: function fromDirectGeometry(geometry) {
8066                         var positions = new Float32Array(geometry.vertices.length * 3);
8067                         this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
8068
8069                         if (geometry.normals.length > 0) {
8070                                 var normals = new Float32Array(geometry.normals.length * 3);
8071                                 this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
8072                         }
8073
8074                         if (geometry.colors.length > 0) {
8075                                 var colors = new Float32Array(geometry.colors.length * 3);
8076                                 this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
8077                         }
8078
8079                         if (geometry.uvs.length > 0) {
8080                                 var uvs = new Float32Array(geometry.uvs.length * 2);
8081                                 this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
8082                         }
8083
8084                         if (geometry.uvs2.length > 0) {
8085                                 var uvs2 = new Float32Array(geometry.uvs2.length * 2);
8086                                 this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
8087                         } // groups
8088
8089
8090                         this.groups = geometry.groups; // morphs
8091
8092                         for (var name in geometry.morphTargets) {
8093                                 var array = [];
8094                                 var morphTargets = geometry.morphTargets[name];
8095
8096                                 for (var i = 0, l = morphTargets.length; i < l; i++) {
8097                                         var morphTarget = morphTargets[i];
8098                                         var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
8099                                         attribute.name = morphTarget.name;
8100                                         array.push(attribute.copyVector3sArray(morphTarget.data));
8101                                 }
8102
8103                                 this.morphAttributes[name] = array;
8104                         } // skinning
8105
8106
8107                         if (geometry.skinIndices.length > 0) {
8108                                 var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
8109                                 this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
8110                         }
8111
8112                         if (geometry.skinWeights.length > 0) {
8113                                 var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
8114                                 this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
8115                         } //
8116
8117
8118                         if (geometry.boundingSphere !== null) {
8119                                 this.boundingSphere = geometry.boundingSphere.clone();
8120                         }
8121
8122                         if (geometry.boundingBox !== null) {
8123                                 this.boundingBox = geometry.boundingBox.clone();
8124                         }
8125
8126                         return this;
8127                 },
8128                 computeBoundingBox: function computeBoundingBox() {
8129                         if (this.boundingBox === null) {
8130                                 this.boundingBox = new Box3();
8131                         }
8132
8133                         var position = this.attributes.position;
8134                         var morphAttributesPosition = this.morphAttributes.position;
8135
8136                         if (position && position.isGLBufferAttribute) {
8137                                 console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
8138                                 this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
8139                                 return;
8140                         }
8141
8142                         if (position !== undefined) {
8143                                 this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
8144
8145                                 if (morphAttributesPosition) {
8146                                         for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
8147                                                 var morphAttribute = morphAttributesPosition[i];
8148
8149                                                 _box$2.setFromBufferAttribute(morphAttribute);
8150
8151                                                 if (this.morphTargetsRelative) {
8152                                                         _vector$4.addVectors(this.boundingBox.min, _box$2.min);
8153
8154                                                         this.boundingBox.expandByPoint(_vector$4);
8155
8156                                                         _vector$4.addVectors(this.boundingBox.max, _box$2.max);
8157
8158                                                         this.boundingBox.expandByPoint(_vector$4);
8159                                                 } else {
8160                                                         this.boundingBox.expandByPoint(_box$2.min);
8161                                                         this.boundingBox.expandByPoint(_box$2.max);
8162                                                 }
8163                                         }
8164                                 }
8165                         } else {
8166                                 this.boundingBox.makeEmpty();
8167                         }
8168
8169                         if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
8170                                 console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
8171                         }
8172                 },
8173                 computeBoundingSphere: function computeBoundingSphere() {
8174                         if (this.boundingSphere === null) {
8175                                 this.boundingSphere = new Sphere();
8176                         }
8177
8178                         var position = this.attributes.position;
8179                         var morphAttributesPosition = this.morphAttributes.position;
8180
8181                         if (position && position.isGLBufferAttribute) {
8182                                 console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
8183                                 this.boundingSphere.set(new Vector3(), Infinity);
8184                                 return;
8185                         }
8186
8187                         if (position) {
8188                                 // first, find the center of the bounding sphere
8189                                 var center = this.boundingSphere.center;
8190
8191                                 _box$2.setFromBufferAttribute(position); // process morph attributes if present
8192
8193
8194                                 if (morphAttributesPosition) {
8195                                         for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
8196                                                 var morphAttribute = morphAttributesPosition[i];
8197
8198                                                 _boxMorphTargets.setFromBufferAttribute(morphAttribute);
8199
8200                                                 if (this.morphTargetsRelative) {
8201                                                         _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
8202
8203                                                         _box$2.expandByPoint(_vector$4);
8204
8205                                                         _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
8206
8207                                                         _box$2.expandByPoint(_vector$4);
8208                                                 } else {
8209                                                         _box$2.expandByPoint(_boxMorphTargets.min);
8210
8211                                                         _box$2.expandByPoint(_boxMorphTargets.max);
8212                                                 }
8213                                         }
8214                                 }
8215
8216                                 _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
8217                                 // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
8218
8219
8220                                 var maxRadiusSq = 0;
8221
8222                                 for (var _i = 0, _il = position.count; _i < _il; _i++) {
8223                                         _vector$4.fromBufferAttribute(position, _i);
8224
8225                                         maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
8226                                 } // process morph attributes if present
8227
8228
8229                                 if (morphAttributesPosition) {
8230                                         for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
8231                                                 var _morphAttribute = morphAttributesPosition[_i2];
8232                                                 var morphTargetsRelative = this.morphTargetsRelative;
8233
8234                                                 for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
8235                                                         _vector$4.fromBufferAttribute(_morphAttribute, j);
8236
8237                                                         if (morphTargetsRelative) {
8238                                                                 _offset.fromBufferAttribute(position, j);
8239
8240                                                                 _vector$4.add(_offset);
8241                                                         }
8242
8243                                                         maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
8244                                                 }
8245                                         }
8246                                 }
8247
8248                                 this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
8249
8250                                 if (isNaN(this.boundingSphere.radius)) {
8251                                         console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
8252                                 }
8253                         }
8254                 },
8255                 computeFaceNormals: function computeFaceNormals() {// backwards compatibility
8256                 },
8257                 computeVertexNormals: function computeVertexNormals() {
8258                         var index = this.index;
8259                         var positionAttribute = this.getAttribute('position');
8260
8261                         if (positionAttribute !== undefined) {
8262                                 var normalAttribute = this.getAttribute('normal');
8263
8264                                 if (normalAttribute === undefined) {
8265                                         normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
8266                                         this.setAttribute('normal', normalAttribute);
8267                                 } else {
8268                                         // reset existing normals to zero
8269                                         for (var i = 0, il = normalAttribute.count; i < il; i++) {
8270                                                 normalAttribute.setXYZ(i, 0, 0, 0);
8271                                         }
8272                                 }
8273
8274                                 var pA = new Vector3(),
8275                                                 pB = new Vector3(),
8276                                                 pC = new Vector3();
8277                                 var nA = new Vector3(),
8278                                                 nB = new Vector3(),
8279                                                 nC = new Vector3();
8280                                 var cb = new Vector3(),
8281                                                 ab = new Vector3(); // indexed elements
8282
8283                                 if (index) {
8284                                         for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
8285                                                 var vA = index.getX(_i3 + 0);
8286                                                 var vB = index.getX(_i3 + 1);
8287                                                 var vC = index.getX(_i3 + 2);
8288                                                 pA.fromBufferAttribute(positionAttribute, vA);
8289                                                 pB.fromBufferAttribute(positionAttribute, vB);
8290                                                 pC.fromBufferAttribute(positionAttribute, vC);
8291                                                 cb.subVectors(pC, pB);
8292                                                 ab.subVectors(pA, pB);
8293                                                 cb.cross(ab);
8294                                                 nA.fromBufferAttribute(normalAttribute, vA);
8295                                                 nB.fromBufferAttribute(normalAttribute, vB);
8296                                                 nC.fromBufferAttribute(normalAttribute, vC);
8297                                                 nA.add(cb);
8298                                                 nB.add(cb);
8299                                                 nC.add(cb);
8300                                                 normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
8301                                                 normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
8302                                                 normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
8303                                         }
8304                                 } else {
8305                                         // non-indexed elements (unconnected triangle soup)
8306                                         for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
8307                                                 pA.fromBufferAttribute(positionAttribute, _i4 + 0);
8308                                                 pB.fromBufferAttribute(positionAttribute, _i4 + 1);
8309                                                 pC.fromBufferAttribute(positionAttribute, _i4 + 2);
8310                                                 cb.subVectors(pC, pB);
8311                                                 ab.subVectors(pA, pB);
8312                                                 cb.cross(ab);
8313                                                 normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
8314                                                 normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
8315                                                 normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
8316                                         }
8317                                 }
8318
8319                                 this.normalizeNormals();
8320                                 normalAttribute.needsUpdate = true;
8321                         }
8322                 },
8323                 merge: function merge(geometry, offset) {
8324                         if (!(geometry && geometry.isBufferGeometry)) {
8325                                 console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
8326                                 return;
8327                         }
8328
8329                         if (offset === undefined) {
8330                                 offset = 0;
8331                                 console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
8332                         }
8333
8334                         var attributes = this.attributes;
8335
8336                         for (var key in attributes) {
8337                                 if (geometry.attributes[key] === undefined) continue;
8338                                 var attribute1 = attributes[key];
8339                                 var attributeArray1 = attribute1.array;
8340                                 var attribute2 = geometry.attributes[key];
8341                                 var attributeArray2 = attribute2.array;
8342                                 var attributeOffset = attribute2.itemSize * offset;
8343                                 var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
8344
8345                                 for (var i = 0, j = attributeOffset; i < length; i++, j++) {
8346                                         attributeArray1[j] = attributeArray2[i];
8347                                 }
8348                         }
8349
8350                         return this;
8351                 },
8352                 normalizeNormals: function normalizeNormals() {
8353                         var normals = this.attributes.normal;
8354
8355                         for (var i = 0, il = normals.count; i < il; i++) {
8356                                 _vector$4.fromBufferAttribute(normals, i);
8357
8358                                 _vector$4.normalize();
8359
8360                                 normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
8361                         }
8362                 },
8363                 toNonIndexed: function toNonIndexed() {
8364                         function convertBufferAttribute(attribute, indices) {
8365                                 var array = attribute.array;
8366                                 var itemSize = attribute.itemSize;
8367                                 var normalized = attribute.normalized;
8368                                 var array2 = new array.constructor(indices.length * itemSize);
8369                                 var index = 0,
8370                                                 index2 = 0;
8371
8372                                 for (var i = 0, l = indices.length; i < l; i++) {
8373                                         index = indices[i] * itemSize;
8374
8375                                         for (var j = 0; j < itemSize; j++) {
8376                                                 array2[index2++] = array[index++];
8377                                         }
8378                                 }
8379
8380                                 return new BufferAttribute(array2, itemSize, normalized);
8381                         } //
8382
8383
8384                         if (this.index === null) {
8385                                 console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
8386                                 return this;
8387                         }
8388
8389                         var geometry2 = new BufferGeometry();
8390                         var indices = this.index.array;
8391                         var attributes = this.attributes; // attributes
8392
8393                         for (var name in attributes) {
8394                                 var attribute = attributes[name];
8395                                 var newAttribute = convertBufferAttribute(attribute, indices);
8396                                 geometry2.setAttribute(name, newAttribute);
8397                         } // morph attributes
8398
8399
8400                         var morphAttributes = this.morphAttributes;
8401
8402                         for (var _name in morphAttributes) {
8403                                 var morphArray = [];
8404                                 var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
8405
8406                                 for (var i = 0, il = morphAttribute.length; i < il; i++) {
8407                                         var _attribute5 = morphAttribute[i];
8408
8409                                         var _newAttribute = convertBufferAttribute(_attribute5, indices);
8410
8411                                         morphArray.push(_newAttribute);
8412                                 }
8413
8414                                 geometry2.morphAttributes[_name] = morphArray;
8415                         }
8416
8417                         geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
8418
8419                         var groups = this.groups;
8420
8421                         for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
8422                                 var group = groups[_i5];
8423                                 geometry2.addGroup(group.start, group.count, group.materialIndex);
8424                         }
8425
8426                         return geometry2;
8427                 },
8428                 toJSON: function toJSON() {
8429                         var data = {
8430                                 metadata: {
8431                                         version: 4.5,
8432                                         type: 'BufferGeometry',
8433                                         generator: 'BufferGeometry.toJSON'
8434                                 }
8435                         }; // standard BufferGeometry serialization
8436
8437                         data.uuid = this.uuid;
8438                         data.type = this.type;
8439                         if (this.name !== '') data.name = this.name;
8440                         if (Object.keys(this.userData).length > 0) data.userData = this.userData;
8441
8442                         if (this.parameters !== undefined) {
8443                                 var parameters = this.parameters;
8444
8445                                 for (var key in parameters) {
8446                                         if (parameters[key] !== undefined) data[key] = parameters[key];
8447                                 }
8448
8449                                 return data;
8450                         }
8451
8452                         data.data = {
8453                                 attributes: {}
8454                         };
8455                         var index = this.index;
8456
8457                         if (index !== null) {
8458                                 data.data.index = {
8459                                         type: index.array.constructor.name,
8460                                         array: Array.prototype.slice.call(index.array)
8461                                 };
8462                         }
8463
8464                         var attributes = this.attributes;
8465
8466                         for (var _key in attributes) {
8467                                 var attribute = attributes[_key];
8468                                 var attributeData = attribute.toJSON(data.data);
8469                                 if (attribute.name !== '') attributeData.name = attribute.name;
8470                                 data.data.attributes[_key] = attributeData;
8471                         }
8472
8473                         var morphAttributes = {};
8474                         var hasMorphAttributes = false;
8475
8476                         for (var _key2 in this.morphAttributes) {
8477                                 var attributeArray = this.morphAttributes[_key2];
8478                                 var array = [];
8479
8480                                 for (var i = 0, il = attributeArray.length; i < il; i++) {
8481                                         var _attribute6 = attributeArray[i];
8482
8483                                         var _attributeData = _attribute6.toJSON(data.data);
8484
8485                                         if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
8486                                         array.push(_attributeData);
8487                                 }
8488
8489                                 if (array.length > 0) {
8490                                         morphAttributes[_key2] = array;
8491                                         hasMorphAttributes = true;
8492                                 }
8493                         }
8494
8495                         if (hasMorphAttributes) {
8496                                 data.data.morphAttributes = morphAttributes;
8497                                 data.data.morphTargetsRelative = this.morphTargetsRelative;
8498                         }
8499
8500                         var groups = this.groups;
8501
8502                         if (groups.length > 0) {
8503                                 data.data.groups = JSON.parse(JSON.stringify(groups));
8504                         }
8505
8506                         var boundingSphere = this.boundingSphere;
8507
8508                         if (boundingSphere !== null) {
8509                                 data.data.boundingSphere = {
8510                                         center: boundingSphere.center.toArray(),
8511                                         radius: boundingSphere.radius
8512                                 };
8513                         }
8514
8515                         return data;
8516                 },
8517                 clone: function clone() {
8518                         /*
8519                          // Handle primitives
8520                                  const parameters = this.parameters;
8521                                  if ( parameters !== undefined ) {
8522                                  const values = [];
8523                                  for ( const key in parameters ) {
8524                                  values.push( parameters[ key ] );
8525                                  }
8526                                  const geometry = Object.create( this.constructor.prototype );
8527                          this.constructor.apply( geometry, values );
8528                          return geometry;
8529                                  }
8530                                  return new this.constructor().copy( this );
8531                          */
8532                         return new BufferGeometry().copy(this);
8533                 },
8534                 copy: function copy(source) {
8535                         // reset
8536                         this.index = null;
8537                         this.attributes = {};
8538                         this.morphAttributes = {};
8539                         this.groups = [];
8540                         this.boundingBox = null;
8541                         this.boundingSphere = null; // used for storing cloned, shared data
8542
8543                         var data = {}; // name
8544
8545                         this.name = source.name; // index
8546
8547                         var index = source.index;
8548
8549                         if (index !== null) {
8550                                 this.setIndex(index.clone(data));
8551                         } // attributes
8552
8553
8554                         var attributes = source.attributes;
8555
8556                         for (var name in attributes) {
8557                                 var attribute = attributes[name];
8558                                 this.setAttribute(name, attribute.clone(data));
8559                         } // morph attributes
8560
8561
8562                         var morphAttributes = source.morphAttributes;
8563
8564                         for (var _name2 in morphAttributes) {
8565                                 var array = [];
8566                                 var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
8567
8568                                 for (var i = 0, l = morphAttribute.length; i < l; i++) {
8569                                         array.push(morphAttribute[i].clone(data));
8570                                 }
8571
8572                                 this.morphAttributes[_name2] = array;
8573                         }
8574
8575                         this.morphTargetsRelative = source.morphTargetsRelative; // groups
8576
8577                         var groups = source.groups;
8578
8579                         for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
8580                                 var group = groups[_i6];
8581                                 this.addGroup(group.start, group.count, group.materialIndex);
8582                         } // bounding box
8583
8584
8585                         var boundingBox = source.boundingBox;
8586
8587                         if (boundingBox !== null) {
8588                                 this.boundingBox = boundingBox.clone();
8589                         } // bounding sphere
8590
8591
8592                         var boundingSphere = source.boundingSphere;
8593
8594                         if (boundingSphere !== null) {
8595                                 this.boundingSphere = boundingSphere.clone();
8596                         } // draw range
8597
8598
8599                         this.drawRange.start = source.drawRange.start;
8600                         this.drawRange.count = source.drawRange.count; // user data
8601
8602                         this.userData = source.userData;
8603                         return this;
8604                 },
8605                 dispose: function dispose() {
8606                         this.dispatchEvent({
8607                                 type: 'dispose'
8608                         });
8609                 }
8610         });
8611
8612         var _inverseMatrix = new Matrix4();
8613
8614         var _ray = new Ray();
8615
8616         var _sphere = new Sphere();
8617
8618         var _vA = new Vector3();
8619
8620         var _vB = new Vector3();
8621
8622         var _vC = new Vector3();
8623
8624         var _tempA = new Vector3();
8625
8626         var _tempB = new Vector3();
8627
8628         var _tempC = new Vector3();
8629
8630         var _morphA = new Vector3();
8631
8632         var _morphB = new Vector3();
8633
8634         var _morphC = new Vector3();
8635
8636         var _uvA = new Vector2();
8637
8638         var _uvB = new Vector2();
8639
8640         var _uvC = new Vector2();
8641
8642         var _intersectionPoint = new Vector3();
8643
8644         var _intersectionPointWorld = new Vector3();
8645
8646         function Mesh(geometry, material) {
8647                 Object3D.call(this);
8648                 this.type = 'Mesh';
8649                 this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
8650                 this.material = material !== undefined ? material : new MeshBasicMaterial();
8651                 this.updateMorphTargets();
8652         }
8653
8654         Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
8655                 constructor: Mesh,
8656                 isMesh: true,
8657                 copy: function copy(source) {
8658                         Object3D.prototype.copy.call(this, source);
8659
8660                         if (source.morphTargetInfluences !== undefined) {
8661                                 this.morphTargetInfluences = source.morphTargetInfluences.slice();
8662                         }
8663
8664                         if (source.morphTargetDictionary !== undefined) {
8665                                 this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
8666                         }
8667
8668                         this.material = source.material;
8669                         this.geometry = source.geometry;
8670                         return this;
8671                 },
8672                 updateMorphTargets: function updateMorphTargets() {
8673                         var geometry = this.geometry;
8674
8675                         if (geometry.isBufferGeometry) {
8676                                 var morphAttributes = geometry.morphAttributes;
8677                                 var keys = Object.keys(morphAttributes);
8678
8679                                 if (keys.length > 0) {
8680                                         var morphAttribute = morphAttributes[keys[0]];
8681
8682                                         if (morphAttribute !== undefined) {
8683                                                 this.morphTargetInfluences = [];
8684                                                 this.morphTargetDictionary = {};
8685
8686                                                 for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
8687                                                         var name = morphAttribute[m].name || String(m);
8688                                                         this.morphTargetInfluences.push(0);
8689                                                         this.morphTargetDictionary[name] = m;
8690                                                 }
8691                                         }
8692                                 }
8693                         } else {
8694                                 var morphTargets = geometry.morphTargets;
8695
8696                                 if (morphTargets !== undefined && morphTargets.length > 0) {
8697                                         console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
8698                                 }
8699                         }
8700                 },
8701                 raycast: function raycast(raycaster, intersects) {
8702                         var geometry = this.geometry;
8703                         var material = this.material;
8704                         var matrixWorld = this.matrixWorld;
8705                         if (material === undefined) return; // Checking boundingSphere distance to ray
8706
8707                         if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
8708
8709                         _sphere.copy(geometry.boundingSphere);
8710
8711                         _sphere.applyMatrix4(matrixWorld);
8712
8713                         if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
8714
8715                         _inverseMatrix.copy(matrixWorld).invert();
8716
8717                         _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
8718
8719
8720                         if (geometry.boundingBox !== null) {
8721                                 if (_ray.intersectsBox(geometry.boundingBox) === false) return;
8722                         }
8723
8724                         var intersection;
8725
8726                         if (geometry.isBufferGeometry) {
8727                                 var index = geometry.index;
8728                                 var position = geometry.attributes.position;
8729                                 var morphPosition = geometry.morphAttributes.position;
8730                                 var morphTargetsRelative = geometry.morphTargetsRelative;
8731                                 var uv = geometry.attributes.uv;
8732                                 var uv2 = geometry.attributes.uv2;
8733                                 var groups = geometry.groups;
8734                                 var drawRange = geometry.drawRange;
8735
8736                                 if (index !== null) {
8737                                         // indexed buffer geometry
8738                                         if (Array.isArray(material)) {
8739                                                 for (var i = 0, il = groups.length; i < il; i++) {
8740                                                         var group = groups[i];
8741                                                         var groupMaterial = material[group.materialIndex];
8742                                                         var start = Math.max(group.start, drawRange.start);
8743                                                         var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
8744
8745                                                         for (var j = start, jl = end; j < jl; j += 3) {
8746                                                                 var a = index.getX(j);
8747                                                                 var b = index.getX(j + 1);
8748                                                                 var c = index.getX(j + 2);
8749                                                                 intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
8750
8751                                                                 if (intersection) {
8752                                                                         intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
8753
8754                                                                         intersection.face.materialIndex = group.materialIndex;
8755                                                                         intersects.push(intersection);
8756                                                                 }
8757                                                         }
8758                                                 }
8759                                         } else {
8760                                                 var _start = Math.max(0, drawRange.start);
8761
8762                                                 var _end = Math.min(index.count, drawRange.start + drawRange.count);
8763
8764                                                 for (var _i = _start, _il = _end; _i < _il; _i += 3) {
8765                                                         var _a = index.getX(_i);
8766
8767                                                         var _b = index.getX(_i + 1);
8768
8769                                                         var _c = index.getX(_i + 2);
8770
8771                                                         intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
8772
8773                                                         if (intersection) {
8774                                                                 intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
8775
8776                                                                 intersects.push(intersection);
8777                                                         }
8778                                                 }
8779                                         }
8780                                 } else if (position !== undefined) {
8781                                         // non-indexed buffer geometry
8782                                         if (Array.isArray(material)) {
8783                                                 for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
8784                                                         var _group = groups[_i2];
8785                                                         var _groupMaterial = material[_group.materialIndex];
8786
8787                                                         var _start2 = Math.max(_group.start, drawRange.start);
8788
8789                                                         var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
8790
8791                                                         for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
8792                                                                 var _a2 = _j;
8793
8794                                                                 var _b2 = _j + 1;
8795
8796                                                                 var _c2 = _j + 2;
8797
8798                                                                 intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
8799
8800                                                                 if (intersection) {
8801                                                                         intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
8802
8803                                                                         intersection.face.materialIndex = _group.materialIndex;
8804                                                                         intersects.push(intersection);
8805                                                                 }
8806                                                         }
8807                                                 }
8808                                         } else {
8809                                                 var _start3 = Math.max(0, drawRange.start);
8810
8811                                                 var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
8812
8813                                                 for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
8814                                                         var _a3 = _i3;
8815
8816                                                         var _b3 = _i3 + 1;
8817
8818                                                         var _c3 = _i3 + 2;
8819
8820                                                         intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
8821
8822                                                         if (intersection) {
8823                                                                 intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
8824
8825                                                                 intersects.push(intersection);
8826                                                         }
8827                                                 }
8828                                         }
8829                                 }
8830                         } else if (geometry.isGeometry) {
8831                                 var isMultiMaterial = Array.isArray(material);
8832                                 var vertices = geometry.vertices;
8833                                 var faces = geometry.faces;
8834                                 var uvs;
8835                                 var faceVertexUvs = geometry.faceVertexUvs[0];
8836                                 if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
8837
8838                                 for (var f = 0, fl = faces.length; f < fl; f++) {
8839                                         var face = faces[f];
8840                                         var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
8841                                         if (faceMaterial === undefined) continue;
8842                                         var fvA = vertices[face.a];
8843                                         var fvB = vertices[face.b];
8844                                         var fvC = vertices[face.c];
8845                                         intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
8846
8847                                         if (intersection) {
8848                                                 if (uvs && uvs[f]) {
8849                                                         var uvs_f = uvs[f];
8850
8851                                                         _uvA.copy(uvs_f[0]);
8852
8853                                                         _uvB.copy(uvs_f[1]);
8854
8855                                                         _uvC.copy(uvs_f[2]);
8856
8857                                                         intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
8858                                                 }
8859
8860                                                 intersection.face = face;
8861                                                 intersection.faceIndex = f;
8862                                                 intersects.push(intersection);
8863                                         }
8864                                 }
8865                         }
8866                 }
8867         });
8868
8869         function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
8870                 var intersect;
8871
8872                 if (material.side === BackSide) {
8873                         intersect = ray.intersectTriangle(pC, pB, pA, true, point);
8874                 } else {
8875                         intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
8876                 }
8877
8878                 if (intersect === null) return null;
8879
8880                 _intersectionPointWorld.copy(point);
8881
8882                 _intersectionPointWorld.applyMatrix4(object.matrixWorld);
8883
8884                 var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
8885                 if (distance < raycaster.near || distance > raycaster.far) return null;
8886                 return {
8887                         distance: distance,
8888                         point: _intersectionPointWorld.clone(),
8889                         object: object
8890                 };
8891         }
8892
8893         function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
8894                 _vA.fromBufferAttribute(position, a);
8895
8896                 _vB.fromBufferAttribute(position, b);
8897
8898                 _vC.fromBufferAttribute(position, c);
8899
8900                 var morphInfluences = object.morphTargetInfluences;
8901
8902                 if (material.morphTargets && morphPosition && morphInfluences) {
8903                         _morphA.set(0, 0, 0);
8904
8905                         _morphB.set(0, 0, 0);
8906
8907                         _morphC.set(0, 0, 0);
8908
8909                         for (var i = 0, il = morphPosition.length; i < il; i++) {
8910                                 var influence = morphInfluences[i];
8911                                 var morphAttribute = morphPosition[i];
8912                                 if (influence === 0) continue;
8913
8914                                 _tempA.fromBufferAttribute(morphAttribute, a);
8915
8916                                 _tempB.fromBufferAttribute(morphAttribute, b);
8917
8918                                 _tempC.fromBufferAttribute(morphAttribute, c);
8919
8920                                 if (morphTargetsRelative) {
8921                                         _morphA.addScaledVector(_tempA, influence);
8922
8923                                         _morphB.addScaledVector(_tempB, influence);
8924
8925                                         _morphC.addScaledVector(_tempC, influence);
8926                                 } else {
8927                                         _morphA.addScaledVector(_tempA.sub(_vA), influence);
8928
8929                                         _morphB.addScaledVector(_tempB.sub(_vB), influence);
8930
8931                                         _morphC.addScaledVector(_tempC.sub(_vC), influence);
8932                                 }
8933                         }
8934
8935                         _vA.add(_morphA);
8936
8937                         _vB.add(_morphB);
8938
8939                         _vC.add(_morphC);
8940                 }
8941
8942                 if (object.isSkinnedMesh) {
8943                         object.boneTransform(a, _vA);
8944                         object.boneTransform(b, _vB);
8945                         object.boneTransform(c, _vC);
8946                 }
8947
8948                 var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
8949
8950                 if (intersection) {
8951                         if (uv) {
8952                                 _uvA.fromBufferAttribute(uv, a);
8953
8954                                 _uvB.fromBufferAttribute(uv, b);
8955
8956                                 _uvC.fromBufferAttribute(uv, c);
8957
8958                                 intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
8959                         }
8960
8961                         if (uv2) {
8962                                 _uvA.fromBufferAttribute(uv2, a);
8963
8964                                 _uvB.fromBufferAttribute(uv2, b);
8965
8966                                 _uvC.fromBufferAttribute(uv2, c);
8967
8968                                 intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
8969                         }
8970
8971                         var face = new Face3(a, b, c);
8972                         Triangle.getNormal(_vA, _vB, _vC, face.normal);
8973                         intersection.face = face;
8974                 }
8975
8976                 return intersection;
8977         }
8978
8979         var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
8980                 _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
8981
8982                 function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
8983                         var _this;
8984
8985                         if (width === void 0) {
8986                                 width = 1;
8987                         }
8988
8989                         if (height === void 0) {
8990                                 height = 1;
8991                         }
8992
8993                         if (depth === void 0) {
8994                                 depth = 1;
8995                         }
8996
8997                         if (widthSegments === void 0) {
8998                                 widthSegments = 1;
8999                         }
9000
9001                         if (heightSegments === void 0) {
9002                                 heightSegments = 1;
9003                         }
9004
9005                         if (depthSegments === void 0) {
9006                                 depthSegments = 1;
9007                         }
9008
9009                         _this = _BufferGeometry.call(this) || this;
9010                         _this.type = 'BoxBufferGeometry';
9011                         _this.parameters = {
9012                                 width: width,
9013                                 height: height,
9014                                 depth: depth,
9015                                 widthSegments: widthSegments,
9016                                 heightSegments: heightSegments,
9017                                 depthSegments: depthSegments
9018                         };
9019
9020                         var scope = _assertThisInitialized(_this); // segments
9021
9022
9023                         widthSegments = Math.floor(widthSegments);
9024                         heightSegments = Math.floor(heightSegments);
9025                         depthSegments = Math.floor(depthSegments); // buffers
9026
9027                         var indices = [];
9028                         var vertices = [];
9029                         var normals = [];
9030                         var uvs = []; // helper variables
9031
9032                         var numberOfVertices = 0;
9033                         var groupStart = 0; // build each side of the box geometry
9034
9035                         buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
9036
9037                         buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
9038
9039                         buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
9040
9041                         buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
9042
9043                         buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
9044
9045                         buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
9046                         // build geometry
9047
9048                         _this.setIndex(indices);
9049
9050                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
9051
9052                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
9053
9054                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
9055
9056                         function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
9057                                 var segmentWidth = width / gridX;
9058                                 var segmentHeight = height / gridY;
9059                                 var widthHalf = width / 2;
9060                                 var heightHalf = height / 2;
9061                                 var depthHalf = depth / 2;
9062                                 var gridX1 = gridX + 1;
9063                                 var gridY1 = gridY + 1;
9064                                 var vertexCounter = 0;
9065                                 var groupCount = 0;
9066                                 var vector = new Vector3(); // generate vertices, normals and uvs
9067
9068                                 for (var iy = 0; iy < gridY1; iy++) {
9069                                         var y = iy * segmentHeight - heightHalf;
9070
9071                                         for (var ix = 0; ix < gridX1; ix++) {
9072                                                 var x = ix * segmentWidth - widthHalf; // set values to correct vector component
9073
9074                                                 vector[u] = x * udir;
9075                                                 vector[v] = y * vdir;
9076                                                 vector[w] = depthHalf; // now apply vector to vertex buffer
9077
9078                                                 vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
9079
9080                                                 vector[u] = 0;
9081                                                 vector[v] = 0;
9082                                                 vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
9083
9084                                                 normals.push(vector.x, vector.y, vector.z); // uvs
9085
9086                                                 uvs.push(ix / gridX);
9087                                                 uvs.push(1 - iy / gridY); // counters
9088
9089                                                 vertexCounter += 1;
9090                                         }
9091                                 } // indices
9092                                 // 1. you need three indices to draw a single face
9093                                 // 2. a single segment consists of two faces
9094                                 // 3. so we need to generate six (2*3) indices per segment
9095
9096
9097                                 for (var _iy = 0; _iy < gridY; _iy++) {
9098                                         for (var _ix = 0; _ix < gridX; _ix++) {
9099                                                 var a = numberOfVertices + _ix + gridX1 * _iy;
9100                                                 var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
9101                                                 var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
9102                                                 var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
9103
9104                                                 indices.push(a, b, d);
9105                                                 indices.push(b, c, d); // increase counter
9106
9107                                                 groupCount += 6;
9108                                         }
9109                                 } // add a group to the geometry. this will ensure multi material support
9110
9111
9112                                 scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
9113
9114                                 groupStart += groupCount; // update total number of vertices
9115
9116                                 numberOfVertices += vertexCounter;
9117                         }
9118
9119                         return _this;
9120                 }
9121
9122                 return BoxBufferGeometry;
9123         }(BufferGeometry);
9124
9125         /**
9126          * Uniform Utilities
9127          */
9128         function cloneUniforms(src) {
9129                 var dst = {};
9130
9131                 for (var u in src) {
9132                         dst[u] = {};
9133
9134                         for (var p in src[u]) {
9135                                 var property = src[u][p];
9136
9137                                 if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
9138                                         dst[u][p] = property.clone();
9139                                 } else if (Array.isArray(property)) {
9140                                         dst[u][p] = property.slice();
9141                                 } else {
9142                                         dst[u][p] = property;
9143                                 }
9144                         }
9145                 }
9146
9147                 return dst;
9148         }
9149         function mergeUniforms(uniforms) {
9150                 var merged = {};
9151
9152                 for (var u = 0; u < uniforms.length; u++) {
9153                         var tmp = cloneUniforms(uniforms[u]);
9154
9155                         for (var p in tmp) {
9156                                 merged[p] = tmp[p];
9157                         }
9158                 }
9159
9160                 return merged;
9161         } // Legacy
9162
9163         var UniformsUtils = {
9164                 clone: cloneUniforms,
9165                 merge: mergeUniforms
9166         };
9167
9168         var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
9169
9170         var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
9171
9172         /**
9173          * parameters = {
9174          *      defines: { "label" : "value" },
9175          *      uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
9176          *
9177          *      fragmentShader: <string>,
9178          *      vertexShader: <string>,
9179          *
9180          *      wireframe: <boolean>,
9181          *      wireframeLinewidth: <float>,
9182          *
9183          *      lights: <bool>,
9184          *
9185          *      skinning: <bool>,
9186          *      morphTargets: <bool>,
9187          *      morphNormals: <bool>
9188          * }
9189          */
9190
9191         function ShaderMaterial(parameters) {
9192                 Material.call(this);
9193                 this.type = 'ShaderMaterial';
9194                 this.defines = {};
9195                 this.uniforms = {};
9196                 this.vertexShader = default_vertex;
9197                 this.fragmentShader = default_fragment;
9198                 this.linewidth = 1;
9199                 this.wireframe = false;
9200                 this.wireframeLinewidth = 1;
9201                 this.fog = false; // set to use scene fog
9202
9203                 this.lights = false; // set to use scene lights
9204
9205                 this.clipping = false; // set to use user-defined clipping planes
9206
9207                 this.skinning = false; // set to use skinning attribute streams
9208
9209                 this.morphTargets = false; // set to use morph targets
9210
9211                 this.morphNormals = false; // set to use morph normals
9212
9213                 this.extensions = {
9214                         derivatives: false,
9215                         // set to use derivatives
9216                         fragDepth: false,
9217                         // set to use fragment depth values
9218                         drawBuffers: false,
9219                         // set to use draw buffers
9220                         shaderTextureLOD: false // set to use shader texture LOD
9221
9222                 }; // When rendered geometry doesn't include these attributes but the material does,
9223                 // use these default values in WebGL. This avoids errors when buffer data is missing.
9224
9225                 this.defaultAttributeValues = {
9226                         'color': [1, 1, 1],
9227                         'uv': [0, 0],
9228                         'uv2': [0, 0]
9229                 };
9230                 this.index0AttributeName = undefined;
9231                 this.uniformsNeedUpdate = false;
9232                 this.glslVersion = null;
9233
9234                 if (parameters !== undefined) {
9235                         if (parameters.attributes !== undefined) {
9236                                 console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
9237                         }
9238
9239                         this.setValues(parameters);
9240                 }
9241         }
9242
9243         ShaderMaterial.prototype = Object.create(Material.prototype);
9244         ShaderMaterial.prototype.constructor = ShaderMaterial;
9245         ShaderMaterial.prototype.isShaderMaterial = true;
9246
9247         ShaderMaterial.prototype.copy = function (source) {
9248                 Material.prototype.copy.call(this, source);
9249                 this.fragmentShader = source.fragmentShader;
9250                 this.vertexShader = source.vertexShader;
9251                 this.uniforms = cloneUniforms(source.uniforms);
9252                 this.defines = Object.assign({}, source.defines);
9253                 this.wireframe = source.wireframe;
9254                 this.wireframeLinewidth = source.wireframeLinewidth;
9255                 this.lights = source.lights;
9256                 this.clipping = source.clipping;
9257                 this.skinning = source.skinning;
9258                 this.morphTargets = source.morphTargets;
9259                 this.morphNormals = source.morphNormals;
9260                 this.extensions = Object.assign({}, source.extensions);
9261                 this.glslVersion = source.glslVersion;
9262                 return this;
9263         };
9264
9265         ShaderMaterial.prototype.toJSON = function (meta) {
9266                 var data = Material.prototype.toJSON.call(this, meta);
9267                 data.glslVersion = this.glslVersion;
9268                 data.uniforms = {};
9269
9270                 for (var name in this.uniforms) {
9271                         var uniform = this.uniforms[name];
9272                         var value = uniform.value;
9273
9274                         if (value && value.isTexture) {
9275                                 data.uniforms[name] = {
9276                                         type: 't',
9277                                         value: value.toJSON(meta).uuid
9278                                 };
9279                         } else if (value && value.isColor) {
9280                                 data.uniforms[name] = {
9281                                         type: 'c',
9282                                         value: value.getHex()
9283                                 };
9284                         } else if (value && value.isVector2) {
9285                                 data.uniforms[name] = {
9286                                         type: 'v2',
9287                                         value: value.toArray()
9288                                 };
9289                         } else if (value && value.isVector3) {
9290                                 data.uniforms[name] = {
9291                                         type: 'v3',
9292                                         value: value.toArray()
9293                                 };
9294                         } else if (value && value.isVector4) {
9295                                 data.uniforms[name] = {
9296                                         type: 'v4',
9297                                         value: value.toArray()
9298                                 };
9299                         } else if (value && value.isMatrix3) {
9300                                 data.uniforms[name] = {
9301                                         type: 'm3',
9302                                         value: value.toArray()
9303                                 };
9304                         } else if (value && value.isMatrix4) {
9305                                 data.uniforms[name] = {
9306                                         type: 'm4',
9307                                         value: value.toArray()
9308                                 };
9309                         } else {
9310                                 data.uniforms[name] = {
9311                                         value: value
9312                                 }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
9313                         }
9314                 }
9315
9316                 if (Object.keys(this.defines).length > 0) data.defines = this.defines;
9317                 data.vertexShader = this.vertexShader;
9318                 data.fragmentShader = this.fragmentShader;
9319                 var extensions = {};
9320
9321                 for (var key in this.extensions) {
9322                         if (this.extensions[key] === true) extensions[key] = true;
9323                 }
9324
9325                 if (Object.keys(extensions).length > 0) data.extensions = extensions;
9326                 return data;
9327         };
9328
9329         function Camera() {
9330                 Object3D.call(this);
9331                 this.type = 'Camera';
9332                 this.matrixWorldInverse = new Matrix4();
9333                 this.projectionMatrix = new Matrix4();
9334                 this.projectionMatrixInverse = new Matrix4();
9335         }
9336
9337         Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
9338                 constructor: Camera,
9339                 isCamera: true,
9340                 copy: function copy(source, recursive) {
9341                         Object3D.prototype.copy.call(this, source, recursive);
9342                         this.matrixWorldInverse.copy(source.matrixWorldInverse);
9343                         this.projectionMatrix.copy(source.projectionMatrix);
9344                         this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
9345                         return this;
9346                 },
9347                 getWorldDirection: function getWorldDirection(target) {
9348                         if (target === undefined) {
9349                                 console.warn('THREE.Camera: .getWorldDirection() target is now required');
9350                                 target = new Vector3();
9351                         }
9352
9353                         this.updateWorldMatrix(true, false);
9354                         var e = this.matrixWorld.elements;
9355                         return target.set(-e[8], -e[9], -e[10]).normalize();
9356                 },
9357                 updateMatrixWorld: function updateMatrixWorld(force) {
9358                         Object3D.prototype.updateMatrixWorld.call(this, force);
9359                         this.matrixWorldInverse.copy(this.matrixWorld).invert();
9360                 },
9361                 updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
9362                         Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
9363                         this.matrixWorldInverse.copy(this.matrixWorld).invert();
9364                 },
9365                 clone: function clone() {
9366                         return new this.constructor().copy(this);
9367                 }
9368         });
9369
9370         function PerspectiveCamera(fov, aspect, near, far) {
9371                 if (fov === void 0) {
9372                         fov = 50;
9373                 }
9374
9375                 if (aspect === void 0) {
9376                         aspect = 1;
9377                 }
9378
9379                 if (near === void 0) {
9380                         near = 0.1;
9381                 }
9382
9383                 if (far === void 0) {
9384                         far = 2000;
9385                 }
9386
9387                 Camera.call(this);
9388                 this.type = 'PerspectiveCamera';
9389                 this.fov = fov;
9390                 this.zoom = 1;
9391                 this.near = near;
9392                 this.far = far;
9393                 this.focus = 10;
9394                 this.aspect = aspect;
9395                 this.view = null;
9396                 this.filmGauge = 35; // width of the film (default in millimeters)
9397
9398                 this.filmOffset = 0; // horizontal film offset (same unit as gauge)
9399
9400                 this.updateProjectionMatrix();
9401         }
9402
9403         PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
9404                 constructor: PerspectiveCamera,
9405                 isPerspectiveCamera: true,
9406                 copy: function copy(source, recursive) {
9407                         Camera.prototype.copy.call(this, source, recursive);
9408                         this.fov = source.fov;
9409                         this.zoom = source.zoom;
9410                         this.near = source.near;
9411                         this.far = source.far;
9412                         this.focus = source.focus;
9413                         this.aspect = source.aspect;
9414                         this.view = source.view === null ? null : Object.assign({}, source.view);
9415                         this.filmGauge = source.filmGauge;
9416                         this.filmOffset = source.filmOffset;
9417                         return this;
9418                 },
9419
9420                 /**
9421                  * Sets the FOV by focal length in respect to the current .filmGauge.
9422                  *
9423                  * The default film gauge is 35, so that the focal length can be specified for
9424                  * a 35mm (full frame) camera.
9425                  *
9426                  * Values for focal length and film gauge must have the same unit.
9427                  */
9428                 setFocalLength: function setFocalLength(focalLength) {
9429                         // see http://www.bobatkins.com/photography/technical/field_of_view.html
9430                         var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
9431                         this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
9432                         this.updateProjectionMatrix();
9433                 },
9434
9435                 /**
9436                  * Calculates the focal length from the current .fov and .filmGauge.
9437                  */
9438                 getFocalLength: function getFocalLength() {
9439                         var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
9440                         return 0.5 * this.getFilmHeight() / vExtentSlope;
9441                 },
9442                 getEffectiveFOV: function getEffectiveFOV() {
9443                         return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
9444                 },
9445                 getFilmWidth: function getFilmWidth() {
9446                         // film not completely covered in portrait format (aspect < 1)
9447                         return this.filmGauge * Math.min(this.aspect, 1);
9448                 },
9449                 getFilmHeight: function getFilmHeight() {
9450                         // film not completely covered in landscape format (aspect > 1)
9451                         return this.filmGauge / Math.max(this.aspect, 1);
9452                 },
9453
9454                 /**
9455                  * Sets an offset in a larger frustum. This is useful for multi-window or
9456                  * multi-monitor/multi-machine setups.
9457                  *
9458                  * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
9459                  * the monitors are in grid like this
9460                  *
9461                  *       +---+---+---+
9462                  *       | A | B | C |
9463                  *       +---+---+---+
9464                  *       | D | E | F |
9465                  *       +---+---+---+
9466                  *
9467                  * then for each monitor you would call it like this
9468                  *
9469                  *       const w = 1920;
9470                  *       const h = 1080;
9471                  *       const fullWidth = w * 3;
9472                  *       const fullHeight = h * 2;
9473                  *
9474                  *       --A--
9475                  *       camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
9476                  *       --B--
9477                  *       camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
9478                  *       --C--
9479                  *       camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
9480                  *       --D--
9481                  *       camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
9482                  *       --E--
9483                  *       camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
9484                  *       --F--
9485                  *       camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
9486                  *
9487                  *       Note there is no reason monitors have to be the same size or in a grid.
9488                  */
9489                 setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
9490                         this.aspect = fullWidth / fullHeight;
9491
9492                         if (this.view === null) {
9493                                 this.view = {
9494                                         enabled: true,
9495                                         fullWidth: 1,
9496                                         fullHeight: 1,
9497                                         offsetX: 0,
9498                                         offsetY: 0,
9499                                         width: 1,
9500                                         height: 1
9501                                 };
9502                         }
9503
9504                         this.view.enabled = true;
9505                         this.view.fullWidth = fullWidth;
9506                         this.view.fullHeight = fullHeight;
9507                         this.view.offsetX = x;
9508                         this.view.offsetY = y;
9509                         this.view.width = width;
9510                         this.view.height = height;
9511                         this.updateProjectionMatrix();
9512                 },
9513                 clearViewOffset: function clearViewOffset() {
9514                         if (this.view !== null) {
9515                                 this.view.enabled = false;
9516                         }
9517
9518                         this.updateProjectionMatrix();
9519                 },
9520                 updateProjectionMatrix: function updateProjectionMatrix() {
9521                         var near = this.near;
9522                         var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
9523                         var height = 2 * top;
9524                         var width = this.aspect * height;
9525                         var left = -0.5 * width;
9526                         var view = this.view;
9527
9528                         if (this.view !== null && this.view.enabled) {
9529                                 var fullWidth = view.fullWidth,
9530                                                 fullHeight = view.fullHeight;
9531                                 left += view.offsetX * width / fullWidth;
9532                                 top -= view.offsetY * height / fullHeight;
9533                                 width *= view.width / fullWidth;
9534                                 height *= view.height / fullHeight;
9535                         }
9536
9537                         var skew = this.filmOffset;
9538                         if (skew !== 0) left += near * skew / this.getFilmWidth();
9539                         this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
9540                         this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
9541                 },
9542                 toJSON: function toJSON(meta) {
9543                         var data = Object3D.prototype.toJSON.call(this, meta);
9544                         data.object.fov = this.fov;
9545                         data.object.zoom = this.zoom;
9546                         data.object.near = this.near;
9547                         data.object.far = this.far;
9548                         data.object.focus = this.focus;
9549                         data.object.aspect = this.aspect;
9550                         if (this.view !== null) data.object.view = Object.assign({}, this.view);
9551                         data.object.filmGauge = this.filmGauge;
9552                         data.object.filmOffset = this.filmOffset;
9553                         return data;
9554                 }
9555         });
9556
9557         var fov = 90,
9558                         aspect = 1;
9559
9560         function CubeCamera(near, far, renderTarget) {
9561                 Object3D.call(this);
9562                 this.type = 'CubeCamera';
9563
9564                 if (renderTarget.isWebGLCubeRenderTarget !== true) {
9565                         console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
9566                         return;
9567                 }
9568
9569                 this.renderTarget = renderTarget;
9570                 var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
9571                 cameraPX.layers = this.layers;
9572                 cameraPX.up.set(0, -1, 0);
9573                 cameraPX.lookAt(new Vector3(1, 0, 0));
9574                 this.add(cameraPX);
9575                 var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
9576                 cameraNX.layers = this.layers;
9577                 cameraNX.up.set(0, -1, 0);
9578                 cameraNX.lookAt(new Vector3(-1, 0, 0));
9579                 this.add(cameraNX);
9580                 var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
9581                 cameraPY.layers = this.layers;
9582                 cameraPY.up.set(0, 0, 1);
9583                 cameraPY.lookAt(new Vector3(0, 1, 0));
9584                 this.add(cameraPY);
9585                 var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
9586                 cameraNY.layers = this.layers;
9587                 cameraNY.up.set(0, 0, -1);
9588                 cameraNY.lookAt(new Vector3(0, -1, 0));
9589                 this.add(cameraNY);
9590                 var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
9591                 cameraPZ.layers = this.layers;
9592                 cameraPZ.up.set(0, -1, 0);
9593                 cameraPZ.lookAt(new Vector3(0, 0, 1));
9594                 this.add(cameraPZ);
9595                 var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
9596                 cameraNZ.layers = this.layers;
9597                 cameraNZ.up.set(0, -1, 0);
9598                 cameraNZ.lookAt(new Vector3(0, 0, -1));
9599                 this.add(cameraNZ);
9600
9601                 this.update = function (renderer, scene) {
9602                         if (this.parent === null) this.updateMatrixWorld();
9603                         var currentXrEnabled = renderer.xr.enabled;
9604                         var currentRenderTarget = renderer.getRenderTarget();
9605                         renderer.xr.enabled = false;
9606                         var generateMipmaps = renderTarget.texture.generateMipmaps;
9607                         renderTarget.texture.generateMipmaps = false;
9608                         renderer.setRenderTarget(renderTarget, 0);
9609                         renderer.render(scene, cameraPX);
9610                         renderer.setRenderTarget(renderTarget, 1);
9611                         renderer.render(scene, cameraNX);
9612                         renderer.setRenderTarget(renderTarget, 2);
9613                         renderer.render(scene, cameraPY);
9614                         renderer.setRenderTarget(renderTarget, 3);
9615                         renderer.render(scene, cameraNY);
9616                         renderer.setRenderTarget(renderTarget, 4);
9617                         renderer.render(scene, cameraPZ);
9618                         renderTarget.texture.generateMipmaps = generateMipmaps;
9619                         renderer.setRenderTarget(renderTarget, 5);
9620                         renderer.render(scene, cameraNZ);
9621                         renderer.setRenderTarget(currentRenderTarget);
9622                         renderer.xr.enabled = currentXrEnabled;
9623                 };
9624         }
9625
9626         CubeCamera.prototype = Object.create(Object3D.prototype);
9627         CubeCamera.prototype.constructor = CubeCamera;
9628
9629         function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
9630                 images = images !== undefined ? images : [];
9631                 mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
9632                 format = format !== undefined ? format : RGBFormat;
9633                 Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
9634                 this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
9635                 //
9636                 // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
9637                 // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
9638                 // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
9639                 // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
9640                 // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
9641                 // when using WebGLCubeRenderTarget.texture as a cube texture.
9642
9643                 this._needsFlipEnvMap = true;
9644         }
9645
9646         CubeTexture.prototype = Object.create(Texture.prototype);
9647         CubeTexture.prototype.constructor = CubeTexture;
9648         CubeTexture.prototype.isCubeTexture = true;
9649         Object.defineProperty(CubeTexture.prototype, 'images', {
9650                 get: function get() {
9651                         return this.image;
9652                 },
9653                 set: function set(value) {
9654                         this.image = value;
9655                 }
9656         });
9657
9658         function WebGLCubeRenderTarget(size, options, dummy) {
9659                 if (Number.isInteger(options)) {
9660                         console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
9661                         options = dummy;
9662                 }
9663
9664                 WebGLRenderTarget.call(this, size, size, options);
9665                 options = options || {};
9666                 this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
9667                 this.texture._needsFlipEnvMap = false;
9668         }
9669
9670         WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
9671         WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
9672         WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
9673
9674         WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
9675                 this.texture.type = texture.type;
9676                 this.texture.format = RGBAFormat; // see #18859
9677
9678                 this.texture.encoding = texture.encoding;
9679                 this.texture.generateMipmaps = texture.generateMipmaps;
9680                 this.texture.minFilter = texture.minFilter;
9681                 this.texture.magFilter = texture.magFilter;
9682                 var shader = {
9683                         uniforms: {
9684                                 tEquirect: {
9685                                         value: null
9686                                 }
9687                         },
9688                         vertexShader:
9689                         /* glsl */
9690                         "\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t#include <begin_vertex>\n\t\t\t\t#include <project_vertex>\n\n\t\t\t}\n\t\t",
9691                         fragmentShader:
9692                         /* glsl */
9693                         "\n\n\t\t\tuniform sampler2D tEquirect;\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t}\n\t\t"
9694                 };
9695                 var geometry = new BoxBufferGeometry(5, 5, 5);
9696                 var material = new ShaderMaterial({
9697                         name: 'CubemapFromEquirect',
9698                         uniforms: cloneUniforms(shader.uniforms),
9699                         vertexShader: shader.vertexShader,
9700                         fragmentShader: shader.fragmentShader,
9701                         side: BackSide,
9702                         blending: NoBlending
9703                 });
9704                 material.uniforms.tEquirect.value = texture;
9705                 var mesh = new Mesh(geometry, material);
9706                 var currentMinFilter = texture.minFilter; // Avoid blurred poles
9707
9708                 if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
9709                 var camera = new CubeCamera(1, 10, this);
9710                 camera.update(renderer, mesh);
9711                 texture.minFilter = currentMinFilter;
9712                 mesh.geometry.dispose();
9713                 mesh.material.dispose();
9714                 return this;
9715         };
9716
9717         WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
9718                 var currentRenderTarget = renderer.getRenderTarget();
9719
9720                 for (var i = 0; i < 6; i++) {
9721                         renderer.setRenderTarget(this, i);
9722                         renderer.clear(color, depth, stencil);
9723                 }
9724
9725                 renderer.setRenderTarget(currentRenderTarget);
9726         };
9727
9728         function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
9729                 Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
9730                 this.image = {
9731                         data: data || null,
9732                         width: width || 1,
9733                         height: height || 1
9734                 };
9735                 this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
9736                 this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
9737                 this.generateMipmaps = false;
9738                 this.flipY = false;
9739                 this.unpackAlignment = 1;
9740                 this.needsUpdate = true;
9741         }
9742
9743         DataTexture.prototype = Object.create(Texture.prototype);
9744         DataTexture.prototype.constructor = DataTexture;
9745         DataTexture.prototype.isDataTexture = true;
9746
9747         var _sphere$1 = /*@__PURE__*/new Sphere();
9748
9749         var _vector$5 = /*@__PURE__*/new Vector3();
9750
9751         var Frustum = /*#__PURE__*/function () {
9752                 function Frustum(p0, p1, p2, p3, p4, p5) {
9753                         this.planes = [p0 !== undefined ? p0 : new Plane(), p1 !== undefined ? p1 : new Plane(), p2 !== undefined ? p2 : new Plane(), p3 !== undefined ? p3 : new Plane(), p4 !== undefined ? p4 : new Plane(), p5 !== undefined ? p5 : new Plane()];
9754                 }
9755
9756                 var _proto = Frustum.prototype;
9757
9758                 _proto.set = function set(p0, p1, p2, p3, p4, p5) {
9759                         var planes = this.planes;
9760                         planes[0].copy(p0);
9761                         planes[1].copy(p1);
9762                         planes[2].copy(p2);
9763                         planes[3].copy(p3);
9764                         planes[4].copy(p4);
9765                         planes[5].copy(p5);
9766                         return this;
9767                 };
9768
9769                 _proto.clone = function clone() {
9770                         return new this.constructor().copy(this);
9771                 };
9772
9773                 _proto.copy = function copy(frustum) {
9774                         var planes = this.planes;
9775
9776                         for (var i = 0; i < 6; i++) {
9777                                 planes[i].copy(frustum.planes[i]);
9778                         }
9779
9780                         return this;
9781                 };
9782
9783                 _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
9784                         var planes = this.planes;
9785                         var me = m.elements;
9786                         var me0 = me[0],
9787                                         me1 = me[1],
9788                                         me2 = me[2],
9789                                         me3 = me[3];
9790                         var me4 = me[4],
9791                                         me5 = me[5],
9792                                         me6 = me[6],
9793                                         me7 = me[7];
9794                         var me8 = me[8],
9795                                         me9 = me[9],
9796                                         me10 = me[10],
9797                                         me11 = me[11];
9798                         var me12 = me[12],
9799                                         me13 = me[13],
9800                                         me14 = me[14],
9801                                         me15 = me[15];
9802                         planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
9803                         planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
9804                         planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
9805                         planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
9806                         planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
9807                         planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
9808                         return this;
9809                 };
9810
9811                 _proto.intersectsObject = function intersectsObject(object) {
9812                         var geometry = object.geometry;
9813                         if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
9814
9815                         _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
9816
9817                         return this.intersectsSphere(_sphere$1);
9818                 };
9819
9820                 _proto.intersectsSprite = function intersectsSprite(sprite) {
9821                         _sphere$1.center.set(0, 0, 0);
9822
9823                         _sphere$1.radius = 0.7071067811865476;
9824
9825                         _sphere$1.applyMatrix4(sprite.matrixWorld);
9826
9827                         return this.intersectsSphere(_sphere$1);
9828                 };
9829
9830                 _proto.intersectsSphere = function intersectsSphere(sphere) {
9831                         var planes = this.planes;
9832                         var center = sphere.center;
9833                         var negRadius = -sphere.radius;
9834
9835                         for (var i = 0; i < 6; i++) {
9836                                 var distance = planes[i].distanceToPoint(center);
9837
9838                                 if (distance < negRadius) {
9839                                         return false;
9840                                 }
9841                         }
9842
9843                         return true;
9844                 };
9845
9846                 _proto.intersectsBox = function intersectsBox(box) {
9847                         var planes = this.planes;
9848
9849                         for (var i = 0; i < 6; i++) {
9850                                 var plane = planes[i]; // corner at max distance
9851
9852                                 _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
9853                                 _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
9854                                 _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
9855
9856                                 if (plane.distanceToPoint(_vector$5) < 0) {
9857                                         return false;
9858                                 }
9859                         }
9860
9861                         return true;
9862                 };
9863
9864                 _proto.containsPoint = function containsPoint(point) {
9865                         var planes = this.planes;
9866
9867                         for (var i = 0; i < 6; i++) {
9868                                 if (planes[i].distanceToPoint(point) < 0) {
9869                                         return false;
9870                                 }
9871                         }
9872
9873                         return true;
9874                 };
9875
9876                 return Frustum;
9877         }();
9878
9879         function WebGLAnimation() {
9880                 var context = null;
9881                 var isAnimating = false;
9882                 var animationLoop = null;
9883                 var requestId = null;
9884
9885                 function onAnimationFrame(time, frame) {
9886                         animationLoop(time, frame);
9887                         requestId = context.requestAnimationFrame(onAnimationFrame);
9888                 }
9889
9890                 return {
9891                         start: function start() {
9892                                 if (isAnimating === true) return;
9893                                 if (animationLoop === null) return;
9894                                 requestId = context.requestAnimationFrame(onAnimationFrame);
9895                                 isAnimating = true;
9896                         },
9897                         stop: function stop() {
9898                                 context.cancelAnimationFrame(requestId);
9899                                 isAnimating = false;
9900                         },
9901                         setAnimationLoop: function setAnimationLoop(callback) {
9902                                 animationLoop = callback;
9903                         },
9904                         setContext: function setContext(value) {
9905                                 context = value;
9906                         }
9907                 };
9908         }
9909
9910         function WebGLAttributes(gl, capabilities) {
9911                 var isWebGL2 = capabilities.isWebGL2;
9912                 var buffers = new WeakMap();
9913
9914                 function createBuffer(attribute, bufferType) {
9915                         var array = attribute.array;
9916                         var usage = attribute.usage;
9917                         var buffer = gl.createBuffer();
9918                         gl.bindBuffer(bufferType, buffer);
9919                         gl.bufferData(bufferType, array, usage);
9920                         attribute.onUploadCallback();
9921                         var type = 5126;
9922
9923                         if (array instanceof Float32Array) {
9924                                 type = 5126;
9925                         } else if (array instanceof Float64Array) {
9926                                 console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
9927                         } else if (array instanceof Uint16Array) {
9928                                 if (attribute.isFloat16BufferAttribute) {
9929                                         if (isWebGL2) {
9930                                                 type = 5131;
9931                                         } else {
9932                                                 console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
9933                                         }
9934                                 } else {
9935                                         type = 5123;
9936                                 }
9937                         } else if (array instanceof Int16Array) {
9938                                 type = 5122;
9939                         } else if (array instanceof Uint32Array) {
9940                                 type = 5125;
9941                         } else if (array instanceof Int32Array) {
9942                                 type = 5124;
9943                         } else if (array instanceof Int8Array) {
9944                                 type = 5120;
9945                         } else if (array instanceof Uint8Array) {
9946                                 type = 5121;
9947                         }
9948
9949                         return {
9950                                 buffer: buffer,
9951                                 type: type,
9952                                 bytesPerElement: array.BYTES_PER_ELEMENT,
9953                                 version: attribute.version
9954                         };
9955                 }
9956
9957                 function updateBuffer(buffer, attribute, bufferType) {
9958                         var array = attribute.array;
9959                         var updateRange = attribute.updateRange;
9960                         gl.bindBuffer(bufferType, buffer);
9961
9962                         if (updateRange.count === -1) {
9963                                 // Not using update ranges
9964                                 gl.bufferSubData(bufferType, 0, array);
9965                         } else {
9966                                 if (isWebGL2) {
9967                                         gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
9968                                 } else {
9969                                         gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
9970                                 }
9971
9972                                 updateRange.count = -1; // reset range
9973                         }
9974                 } //
9975
9976
9977                 function get(attribute) {
9978                         if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
9979                         return buffers.get(attribute);
9980                 }
9981
9982                 function remove(attribute) {
9983                         if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
9984                         var data = buffers.get(attribute);
9985
9986                         if (data) {
9987                                 gl.deleteBuffer(data.buffer);
9988                                 buffers.delete(attribute);
9989                         }
9990                 }
9991
9992                 function update(attribute, bufferType) {
9993                         if (attribute.isGLBufferAttribute) {
9994                                 var cached = buffers.get(attribute);
9995
9996                                 if (!cached || cached.version < attribute.version) {
9997                                         buffers.set(attribute, {
9998                                                 buffer: attribute.buffer,
9999                                                 type: attribute.type,
10000                                                 bytesPerElement: attribute.elementSize,
10001                                                 version: attribute.version
10002                                         });
10003                                 }
10004
10005                                 return;
10006                         }
10007
10008                         if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
10009                         var data = buffers.get(attribute);
10010
10011                         if (data === undefined) {
10012                                 buffers.set(attribute, createBuffer(attribute, bufferType));
10013                         } else if (data.version < attribute.version) {
10014                                 updateBuffer(data.buffer, attribute, bufferType);
10015                                 data.version = attribute.version;
10016                         }
10017                 }
10018
10019                 return {
10020                         get: get,
10021                         remove: remove,
10022                         update: update
10023                 };
10024         }
10025
10026         var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
10027                 _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
10028
10029                 function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
10030                         var _this;
10031
10032                         if (width === void 0) {
10033                                 width = 1;
10034                         }
10035
10036                         if (height === void 0) {
10037                                 height = 1;
10038                         }
10039
10040                         if (widthSegments === void 0) {
10041                                 widthSegments = 1;
10042                         }
10043
10044                         if (heightSegments === void 0) {
10045                                 heightSegments = 1;
10046                         }
10047
10048                         _this = _BufferGeometry.call(this) || this;
10049                         _this.type = 'PlaneBufferGeometry';
10050                         _this.parameters = {
10051                                 width: width,
10052                                 height: height,
10053                                 widthSegments: widthSegments,
10054                                 heightSegments: heightSegments
10055                         };
10056                         var width_half = width / 2;
10057                         var height_half = height / 2;
10058                         var gridX = Math.floor(widthSegments);
10059                         var gridY = Math.floor(heightSegments);
10060                         var gridX1 = gridX + 1;
10061                         var gridY1 = gridY + 1;
10062                         var segment_width = width / gridX;
10063                         var segment_height = height / gridY; //
10064
10065                         var indices = [];
10066                         var vertices = [];
10067                         var normals = [];
10068                         var uvs = [];
10069
10070                         for (var iy = 0; iy < gridY1; iy++) {
10071                                 var y = iy * segment_height - height_half;
10072
10073                                 for (var ix = 0; ix < gridX1; ix++) {
10074                                         var x = ix * segment_width - width_half;
10075                                         vertices.push(x, -y, 0);
10076                                         normals.push(0, 0, 1);
10077                                         uvs.push(ix / gridX);
10078                                         uvs.push(1 - iy / gridY);
10079                                 }
10080                         }
10081
10082                         for (var _iy = 0; _iy < gridY; _iy++) {
10083                                 for (var _ix = 0; _ix < gridX; _ix++) {
10084                                         var a = _ix + gridX1 * _iy;
10085                                         var b = _ix + gridX1 * (_iy + 1);
10086                                         var c = _ix + 1 + gridX1 * (_iy + 1);
10087                                         var d = _ix + 1 + gridX1 * _iy;
10088                                         indices.push(a, b, d);
10089                                         indices.push(b, c, d);
10090                                 }
10091                         }
10092
10093                         _this.setIndex(indices);
10094
10095                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
10096
10097                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
10098
10099                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
10100
10101                         return _this;
10102                 }
10103
10104                 return PlaneBufferGeometry;
10105         }(BufferGeometry);
10106
10107         var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
10108
10109         var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
10110
10111         var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
10112
10113         var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";
10114
10115         var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
10116
10117         var begin_vertex = "vec3 transformed = vec3( position );";
10118
10119         var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
10120
10121         var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie(float roughness, float NoH) {\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125);\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\nfloat V_Neubelt(float NoV, float NoL) {\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif";
10122
10123         var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
10124
10125         var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
10126
10127         var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
10128
10129         var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
10130
10131         var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
10132
10133         var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
10134
10135         var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
10136
10137         var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
10138
10139         var color_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor.xyz *= color.xyz;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";
10140
10141         var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}";
10142
10143         var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );\n\t\tvec2 f = fract( uv );\n\t\tuv += 0.5 - f;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\tvec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x += texelSize;\n\t\tvec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.y += texelSize;\n\t\tvec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x -= texelSize;\n\t\tvec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tvec3 tm = mix( tl, tr, f.x );\n\t\tvec3 bm = mix( bl, br, f.x );\n\t\treturn mix( tm, bm, f.y );\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif";
10144
10145         var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
10146
10147         var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
10148
10149         var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
10150
10151         var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
10152
10153         var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
10154
10155         var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
10156
10157         var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
10158
10159         var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
10160
10161         var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";
10162
10163         var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
10164
10165         var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
10166
10167         var envmap_vertex = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";
10168
10169         var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
10170
10171         var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
10172
10173         var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";
10174
10175         var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";
10176
10177         var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";
10178
10179         var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
10180
10181         var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
10182
10183         var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";
10184
10185         var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
10186
10187         var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat sigma = PI * roughness * roughness / ( 1.0 + roughness );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + log2( sigma );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
10188
10189         var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
10190
10191         var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)";
10192
10193         var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
10194
10195         var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";
10196
10197         var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;\nmaterial.specularRoughness = min( material.specularRoughness, 1.0 );\n#ifdef REFLECTIVITY\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#endif\n#ifdef CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheen;\n#endif";
10198
10199         var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat specularRoughness;\n\tvec3 specularColor;\n#ifdef CLEARCOAT\n\tfloat clearcoat;\n\tfloat clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3(           0, 1,           0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(\n\t\t\tmaterial.specularRoughness,\n\t\t\tdirectLight.direction,\n\t\t\tgeometry,\n\t\t\tmaterial.sheenColor\n\t\t);\n\t#else\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);\n\t#endif\n\treflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\tfloat clearcoatInv = 1.0 - clearcoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
10200
10201         var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
10202
10203         var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );\n\t#ifdef CLEARCOAT\n\t\tclearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );\n\t#endif\n#endif";
10204
10205         var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";
10206
10207         var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
10208
10209         var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";
10210
10211         var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
10212
10213         var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";
10214
10215         var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
10216
10217         var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
10218
10219         var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
10220
10221         var map_particle_pars_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
10222
10223         var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
10224
10225         var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
10226
10227         var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n#endif";
10228
10229         var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\t\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\t\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
10230
10231         var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
10232
10233         var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
10234
10235         var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
10236
10237         var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
10238
10239         var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
10240
10241         var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );\n\t#endif\n#endif";
10242
10243         var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";
10244
10245         var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";
10246
10247         var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
10248
10249         var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";
10250
10251         var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
10252
10253         var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";
10254
10255         var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
10256
10257         var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
10258
10259         var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t  texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t        texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t    f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
10260
10261         var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
10262
10263         var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";
10264
10265         var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
10266
10267         var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
10268
10269         var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
10270
10271         var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
10272
10273         var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";
10274
10275         var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
10276
10277         var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
10278
10279         var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
10280
10281         var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3(     1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108,       1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605,     1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";
10282
10283         var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
10284
10285         var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
10286
10287         var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
10288
10289         var uv_pars_vertex = "#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif";
10290
10291         var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
10292
10293         var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
10294
10295         var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif";
10296
10297         var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
10298
10299         var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";
10300
10301         var background_frag = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
10302
10303         var background_vert = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
10304
10305         var cube_frag = "#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
10306
10307         var cube_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
10308
10309         var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}";
10310
10311         var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";
10312
10313         var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
10314
10315         var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";
10316
10317         var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
10318
10319         var equirect_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
10320
10321         var linedashed_frag = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
10322
10323         var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
10324
10325         var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
10326
10327         var meshbasic_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
10328
10329         var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
10330
10331         var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
10332
10333         var meshmatcap_frag = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
10334
10335         var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
10336
10337         var meshtoon_frag = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
10338
10339         var meshtoon_vert = "#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
10340
10341         var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
10342
10343         var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
10344
10345         var meshphysical_frag = "#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSMISSION\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSMISSION\n\tuniform float transmission;\n#endif\n#ifdef REFLECTIVITY\n\tuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <transmissionmap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#ifdef TRANSMISSION\n\t\tfloat totalTransmission = transmission;\n\t#endif\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <transmissionmap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= mix( saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) ), 1.0, metalness );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
10346
10347         var meshphysical_vert = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
10348
10349         var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
10350
10351         var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
10352
10353         var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
10354
10355         var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
10356
10357         var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
10358
10359         var shadow_vert = "#include <common>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
10360
10361         var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
10362
10363         var sprite_vert = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
10364
10365         var ShaderChunk = {
10366                 alphamap_fragment: alphamap_fragment,
10367                 alphamap_pars_fragment: alphamap_pars_fragment,
10368                 alphatest_fragment: alphatest_fragment,
10369                 aomap_fragment: aomap_fragment,
10370                 aomap_pars_fragment: aomap_pars_fragment,
10371                 begin_vertex: begin_vertex,
10372                 beginnormal_vertex: beginnormal_vertex,
10373                 bsdfs: bsdfs,
10374                 bumpmap_pars_fragment: bumpmap_pars_fragment,
10375                 clipping_planes_fragment: clipping_planes_fragment,
10376                 clipping_planes_pars_fragment: clipping_planes_pars_fragment,
10377                 clipping_planes_pars_vertex: clipping_planes_pars_vertex,
10378                 clipping_planes_vertex: clipping_planes_vertex,
10379                 color_fragment: color_fragment,
10380                 color_pars_fragment: color_pars_fragment,
10381                 color_pars_vertex: color_pars_vertex,
10382                 color_vertex: color_vertex,
10383                 common: common,
10384                 cube_uv_reflection_fragment: cube_uv_reflection_fragment,
10385                 defaultnormal_vertex: defaultnormal_vertex,
10386                 displacementmap_pars_vertex: displacementmap_pars_vertex,
10387                 displacementmap_vertex: displacementmap_vertex,
10388                 emissivemap_fragment: emissivemap_fragment,
10389                 emissivemap_pars_fragment: emissivemap_pars_fragment,
10390                 encodings_fragment: encodings_fragment,
10391                 encodings_pars_fragment: encodings_pars_fragment,
10392                 envmap_fragment: envmap_fragment,
10393                 envmap_common_pars_fragment: envmap_common_pars_fragment,
10394                 envmap_pars_fragment: envmap_pars_fragment,
10395                 envmap_pars_vertex: envmap_pars_vertex,
10396                 envmap_physical_pars_fragment: envmap_physical_pars_fragment,
10397                 envmap_vertex: envmap_vertex,
10398                 fog_vertex: fog_vertex,
10399                 fog_pars_vertex: fog_pars_vertex,
10400                 fog_fragment: fog_fragment,
10401                 fog_pars_fragment: fog_pars_fragment,
10402                 gradientmap_pars_fragment: gradientmap_pars_fragment,
10403                 lightmap_fragment: lightmap_fragment,
10404                 lightmap_pars_fragment: lightmap_pars_fragment,
10405                 lights_lambert_vertex: lights_lambert_vertex,
10406                 lights_pars_begin: lights_pars_begin,
10407                 lights_toon_fragment: lights_toon_fragment,
10408                 lights_toon_pars_fragment: lights_toon_pars_fragment,
10409                 lights_phong_fragment: lights_phong_fragment,
10410                 lights_phong_pars_fragment: lights_phong_pars_fragment,
10411                 lights_physical_fragment: lights_physical_fragment,
10412                 lights_physical_pars_fragment: lights_physical_pars_fragment,
10413                 lights_fragment_begin: lights_fragment_begin,
10414                 lights_fragment_maps: lights_fragment_maps,
10415                 lights_fragment_end: lights_fragment_end,
10416                 logdepthbuf_fragment: logdepthbuf_fragment,
10417                 logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
10418                 logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
10419                 logdepthbuf_vertex: logdepthbuf_vertex,
10420                 map_fragment: map_fragment,
10421                 map_pars_fragment: map_pars_fragment,
10422                 map_particle_fragment: map_particle_fragment,
10423                 map_particle_pars_fragment: map_particle_pars_fragment,
10424                 metalnessmap_fragment: metalnessmap_fragment,
10425                 metalnessmap_pars_fragment: metalnessmap_pars_fragment,
10426                 morphnormal_vertex: morphnormal_vertex,
10427                 morphtarget_pars_vertex: morphtarget_pars_vertex,
10428                 morphtarget_vertex: morphtarget_vertex,
10429                 normal_fragment_begin: normal_fragment_begin,
10430                 normal_fragment_maps: normal_fragment_maps,
10431                 normalmap_pars_fragment: normalmap_pars_fragment,
10432                 clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
10433                 clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
10434                 clearcoat_pars_fragment: clearcoat_pars_fragment,
10435                 packing: packing,
10436                 premultiplied_alpha_fragment: premultiplied_alpha_fragment,
10437                 project_vertex: project_vertex,
10438                 dithering_fragment: dithering_fragment,
10439                 dithering_pars_fragment: dithering_pars_fragment,
10440                 roughnessmap_fragment: roughnessmap_fragment,
10441                 roughnessmap_pars_fragment: roughnessmap_pars_fragment,
10442                 shadowmap_pars_fragment: shadowmap_pars_fragment,
10443                 shadowmap_pars_vertex: shadowmap_pars_vertex,
10444                 shadowmap_vertex: shadowmap_vertex,
10445                 shadowmask_pars_fragment: shadowmask_pars_fragment,
10446                 skinbase_vertex: skinbase_vertex,
10447                 skinning_pars_vertex: skinning_pars_vertex,
10448                 skinning_vertex: skinning_vertex,
10449                 skinnormal_vertex: skinnormal_vertex,
10450                 specularmap_fragment: specularmap_fragment,
10451                 specularmap_pars_fragment: specularmap_pars_fragment,
10452                 tonemapping_fragment: tonemapping_fragment,
10453                 tonemapping_pars_fragment: tonemapping_pars_fragment,
10454                 transmissionmap_fragment: transmissionmap_fragment,
10455                 transmissionmap_pars_fragment: transmissionmap_pars_fragment,
10456                 uv_pars_fragment: uv_pars_fragment,
10457                 uv_pars_vertex: uv_pars_vertex,
10458                 uv_vertex: uv_vertex,
10459                 uv2_pars_fragment: uv2_pars_fragment,
10460                 uv2_pars_vertex: uv2_pars_vertex,
10461                 uv2_vertex: uv2_vertex,
10462                 worldpos_vertex: worldpos_vertex,
10463                 background_frag: background_frag,
10464                 background_vert: background_vert,
10465                 cube_frag: cube_frag,
10466                 cube_vert: cube_vert,
10467                 depth_frag: depth_frag,
10468                 depth_vert: depth_vert,
10469                 distanceRGBA_frag: distanceRGBA_frag,
10470                 distanceRGBA_vert: distanceRGBA_vert,
10471                 equirect_frag: equirect_frag,
10472                 equirect_vert: equirect_vert,
10473                 linedashed_frag: linedashed_frag,
10474                 linedashed_vert: linedashed_vert,
10475                 meshbasic_frag: meshbasic_frag,
10476                 meshbasic_vert: meshbasic_vert,
10477                 meshlambert_frag: meshlambert_frag,
10478                 meshlambert_vert: meshlambert_vert,
10479                 meshmatcap_frag: meshmatcap_frag,
10480                 meshmatcap_vert: meshmatcap_vert,
10481                 meshtoon_frag: meshtoon_frag,
10482                 meshtoon_vert: meshtoon_vert,
10483                 meshphong_frag: meshphong_frag,
10484                 meshphong_vert: meshphong_vert,
10485                 meshphysical_frag: meshphysical_frag,
10486                 meshphysical_vert: meshphysical_vert,
10487                 normal_frag: normal_frag,
10488                 normal_vert: normal_vert,
10489                 points_frag: points_frag,
10490                 points_vert: points_vert,
10491                 shadow_frag: shadow_frag,
10492                 shadow_vert: shadow_vert,
10493                 sprite_frag: sprite_frag,
10494                 sprite_vert: sprite_vert
10495         };
10496
10497         /**
10498          * Uniforms library for shared webgl shaders
10499          */
10500
10501         var UniformsLib = {
10502                 common: {
10503                         diffuse: {
10504                                 value: new Color(0xeeeeee)
10505                         },
10506                         opacity: {
10507                                 value: 1.0
10508                         },
10509                         map: {
10510                                 value: null
10511                         },
10512                         uvTransform: {
10513                                 value: new Matrix3()
10514                         },
10515                         uv2Transform: {
10516                                 value: new Matrix3()
10517                         },
10518                         alphaMap: {
10519                                 value: null
10520                         }
10521                 },
10522                 specularmap: {
10523                         specularMap: {
10524                                 value: null
10525                         }
10526                 },
10527                 envmap: {
10528                         envMap: {
10529                                 value: null
10530                         },
10531                         flipEnvMap: {
10532                                 value: -1
10533                         },
10534                         reflectivity: {
10535                                 value: 1.0
10536                         },
10537                         refractionRatio: {
10538                                 value: 0.98
10539                         },
10540                         maxMipLevel: {
10541                                 value: 0
10542                         }
10543                 },
10544                 aomap: {
10545                         aoMap: {
10546                                 value: null
10547                         },
10548                         aoMapIntensity: {
10549                                 value: 1
10550                         }
10551                 },
10552                 lightmap: {
10553                         lightMap: {
10554                                 value: null
10555                         },
10556                         lightMapIntensity: {
10557                                 value: 1
10558                         }
10559                 },
10560                 emissivemap: {
10561                         emissiveMap: {
10562                                 value: null
10563                         }
10564                 },
10565                 bumpmap: {
10566                         bumpMap: {
10567                                 value: null
10568                         },
10569                         bumpScale: {
10570                                 value: 1
10571                         }
10572                 },
10573                 normalmap: {
10574                         normalMap: {
10575                                 value: null
10576                         },
10577                         normalScale: {
10578                                 value: new Vector2(1, 1)
10579                         }
10580                 },
10581                 displacementmap: {
10582                         displacementMap: {
10583                                 value: null
10584                         },
10585                         displacementScale: {
10586                                 value: 1
10587                         },
10588                         displacementBias: {
10589                                 value: 0
10590                         }
10591                 },
10592                 roughnessmap: {
10593                         roughnessMap: {
10594                                 value: null
10595                         }
10596                 },
10597                 metalnessmap: {
10598                         metalnessMap: {
10599                                 value: null
10600                         }
10601                 },
10602                 gradientmap: {
10603                         gradientMap: {
10604                                 value: null
10605                         }
10606                 },
10607                 fog: {
10608                         fogDensity: {
10609                                 value: 0.00025
10610                         },
10611                         fogNear: {
10612                                 value: 1
10613                         },
10614                         fogFar: {
10615                                 value: 2000
10616                         },
10617                         fogColor: {
10618                                 value: new Color(0xffffff)
10619                         }
10620                 },
10621                 lights: {
10622                         ambientLightColor: {
10623                                 value: []
10624                         },
10625                         lightProbe: {
10626                                 value: []
10627                         },
10628                         directionalLights: {
10629                                 value: [],
10630                                 properties: {
10631                                         direction: {},
10632                                         color: {}
10633                                 }
10634                         },
10635                         directionalLightShadows: {
10636                                 value: [],
10637                                 properties: {
10638                                         shadowBias: {},
10639                                         shadowNormalBias: {},
10640                                         shadowRadius: {},
10641                                         shadowMapSize: {}
10642                                 }
10643                         },
10644                         directionalShadowMap: {
10645                                 value: []
10646                         },
10647                         directionalShadowMatrix: {
10648                                 value: []
10649                         },
10650                         spotLights: {
10651                                 value: [],
10652                                 properties: {
10653                                         color: {},
10654                                         position: {},
10655                                         direction: {},
10656                                         distance: {},
10657                                         coneCos: {},
10658                                         penumbraCos: {},
10659                                         decay: {}
10660                                 }
10661                         },
10662                         spotLightShadows: {
10663                                 value: [],
10664                                 properties: {
10665                                         shadowBias: {},
10666                                         shadowNormalBias: {},
10667                                         shadowRadius: {},
10668                                         shadowMapSize: {}
10669                                 }
10670                         },
10671                         spotShadowMap: {
10672                                 value: []
10673                         },
10674                         spotShadowMatrix: {
10675                                 value: []
10676                         },
10677                         pointLights: {
10678                                 value: [],
10679                                 properties: {
10680                                         color: {},
10681                                         position: {},
10682                                         decay: {},
10683                                         distance: {}
10684                                 }
10685                         },
10686                         pointLightShadows: {
10687                                 value: [],
10688                                 properties: {
10689                                         shadowBias: {},
10690                                         shadowNormalBias: {},
10691                                         shadowRadius: {},
10692                                         shadowMapSize: {},
10693                                         shadowCameraNear: {},
10694                                         shadowCameraFar: {}
10695                                 }
10696                         },
10697                         pointShadowMap: {
10698                                 value: []
10699                         },
10700                         pointShadowMatrix: {
10701                                 value: []
10702                         },
10703                         hemisphereLights: {
10704                                 value: [],
10705                                 properties: {
10706                                         direction: {},
10707                                         skyColor: {},
10708                                         groundColor: {}
10709                                 }
10710                         },
10711                         // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
10712                         rectAreaLights: {
10713                                 value: [],
10714                                 properties: {
10715                                         color: {},
10716                                         position: {},
10717                                         width: {},
10718                                         height: {}
10719                                 }
10720                         },
10721                         ltc_1: {
10722                                 value: null
10723                         },
10724                         ltc_2: {
10725                                 value: null
10726                         }
10727                 },
10728                 points: {
10729                         diffuse: {
10730                                 value: new Color(0xeeeeee)
10731                         },
10732                         opacity: {
10733                                 value: 1.0
10734                         },
10735                         size: {
10736                                 value: 1.0
10737                         },
10738                         scale: {
10739                                 value: 1.0
10740                         },
10741                         map: {
10742                                 value: null
10743                         },
10744                         alphaMap: {
10745                                 value: null
10746                         },
10747                         uvTransform: {
10748                                 value: new Matrix3()
10749                         }
10750                 },
10751                 sprite: {
10752                         diffuse: {
10753                                 value: new Color(0xeeeeee)
10754                         },
10755                         opacity: {
10756                                 value: 1.0
10757                         },
10758                         center: {
10759                                 value: new Vector2(0.5, 0.5)
10760                         },
10761                         rotation: {
10762                                 value: 0.0
10763                         },
10764                         map: {
10765                                 value: null
10766                         },
10767                         alphaMap: {
10768                                 value: null
10769                         },
10770                         uvTransform: {
10771                                 value: new Matrix3()
10772                         }
10773                 }
10774         };
10775
10776         var ShaderLib = {
10777                 basic: {
10778                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
10779                         vertexShader: ShaderChunk.meshbasic_vert,
10780                         fragmentShader: ShaderChunk.meshbasic_frag
10781                 },
10782                 lambert: {
10783                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
10784                                 emissive: {
10785                                         value: new Color(0x000000)
10786                                 }
10787                         }]),
10788                         vertexShader: ShaderChunk.meshlambert_vert,
10789                         fragmentShader: ShaderChunk.meshlambert_frag
10790                 },
10791                 phong: {
10792                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
10793                                 emissive: {
10794                                         value: new Color(0x000000)
10795                                 },
10796                                 specular: {
10797                                         value: new Color(0x111111)
10798                                 },
10799                                 shininess: {
10800                                         value: 30
10801                                 }
10802                         }]),
10803                         vertexShader: ShaderChunk.meshphong_vert,
10804                         fragmentShader: ShaderChunk.meshphong_frag
10805                 },
10806                 standard: {
10807                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.roughnessmap, UniformsLib.metalnessmap, UniformsLib.fog, UniformsLib.lights, {
10808                                 emissive: {
10809                                         value: new Color(0x000000)
10810                                 },
10811                                 roughness: {
10812                                         value: 1.0
10813                                 },
10814                                 metalness: {
10815                                         value: 0.0
10816                                 },
10817                                 envMapIntensity: {
10818                                         value: 1
10819                                 } // temporary
10820
10821                         }]),
10822                         vertexShader: ShaderChunk.meshphysical_vert,
10823                         fragmentShader: ShaderChunk.meshphysical_frag
10824                 },
10825                 toon: {
10826                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
10827                                 emissive: {
10828                                         value: new Color(0x000000)
10829                                 }
10830                         }]),
10831                         vertexShader: ShaderChunk.meshtoon_vert,
10832                         fragmentShader: ShaderChunk.meshtoon_frag
10833                 },
10834                 matcap: {
10835                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
10836                                 matcap: {
10837                                         value: null
10838                                 }
10839                         }]),
10840                         vertexShader: ShaderChunk.meshmatcap_vert,
10841                         fragmentShader: ShaderChunk.meshmatcap_frag
10842                 },
10843                 points: {
10844                         uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
10845                         vertexShader: ShaderChunk.points_vert,
10846                         fragmentShader: ShaderChunk.points_frag
10847                 },
10848                 dashed: {
10849                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
10850                                 scale: {
10851                                         value: 1
10852                                 },
10853                                 dashSize: {
10854                                         value: 1
10855                                 },
10856                                 totalSize: {
10857                                         value: 2
10858                                 }
10859                         }]),
10860                         vertexShader: ShaderChunk.linedashed_vert,
10861                         fragmentShader: ShaderChunk.linedashed_frag
10862                 },
10863                 depth: {
10864                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
10865                         vertexShader: ShaderChunk.depth_vert,
10866                         fragmentShader: ShaderChunk.depth_frag
10867                 },
10868                 normal: {
10869                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
10870                                 opacity: {
10871                                         value: 1.0
10872                                 }
10873                         }]),
10874                         vertexShader: ShaderChunk.normal_vert,
10875                         fragmentShader: ShaderChunk.normal_frag
10876                 },
10877                 sprite: {
10878                         uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
10879                         vertexShader: ShaderChunk.sprite_vert,
10880                         fragmentShader: ShaderChunk.sprite_frag
10881                 },
10882                 background: {
10883                         uniforms: {
10884                                 uvTransform: {
10885                                         value: new Matrix3()
10886                                 },
10887                                 t2D: {
10888                                         value: null
10889                                 }
10890                         },
10891                         vertexShader: ShaderChunk.background_vert,
10892                         fragmentShader: ShaderChunk.background_frag
10893                 },
10894
10895                 /* -------------------------------------------------------------------------
10896                 //      Cube map shader
10897                  ------------------------------------------------------------------------- */
10898                 cube: {
10899                         uniforms: mergeUniforms([UniformsLib.envmap, {
10900                                 opacity: {
10901                                         value: 1.0
10902                                 }
10903                         }]),
10904                         vertexShader: ShaderChunk.cube_vert,
10905                         fragmentShader: ShaderChunk.cube_frag
10906                 },
10907                 equirect: {
10908                         uniforms: {
10909                                 tEquirect: {
10910                                         value: null
10911                                 }
10912                         },
10913                         vertexShader: ShaderChunk.equirect_vert,
10914                         fragmentShader: ShaderChunk.equirect_frag
10915                 },
10916                 distanceRGBA: {
10917                         uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
10918                                 referencePosition: {
10919                                         value: new Vector3()
10920                                 },
10921                                 nearDistance: {
10922                                         value: 1
10923                                 },
10924                                 farDistance: {
10925                                         value: 1000
10926                                 }
10927                         }]),
10928                         vertexShader: ShaderChunk.distanceRGBA_vert,
10929                         fragmentShader: ShaderChunk.distanceRGBA_frag
10930                 },
10931                 shadow: {
10932                         uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
10933                                 color: {
10934                                         value: new Color(0x00000)
10935                                 },
10936                                 opacity: {
10937                                         value: 1.0
10938                                 }
10939                         }]),
10940                         vertexShader: ShaderChunk.shadow_vert,
10941                         fragmentShader: ShaderChunk.shadow_frag
10942                 }
10943         };
10944         ShaderLib.physical = {
10945                 uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
10946                         clearcoat: {
10947                                 value: 0
10948                         },
10949                         clearcoatMap: {
10950                                 value: null
10951                         },
10952                         clearcoatRoughness: {
10953                                 value: 0
10954                         },
10955                         clearcoatRoughnessMap: {
10956                                 value: null
10957                         },
10958                         clearcoatNormalScale: {
10959                                 value: new Vector2(1, 1)
10960                         },
10961                         clearcoatNormalMap: {
10962                                 value: null
10963                         },
10964                         sheen: {
10965                                 value: new Color(0x000000)
10966                         },
10967                         transmission: {
10968                                 value: 0
10969                         },
10970                         transmissionMap: {
10971                                 value: null
10972                         }
10973                 }]),
10974                 vertexShader: ShaderChunk.meshphysical_vert,
10975                 fragmentShader: ShaderChunk.meshphysical_frag
10976         };
10977
10978         function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
10979                 var clearColor = new Color(0x000000);
10980                 var clearAlpha = 0;
10981                 var planeMesh;
10982                 var boxMesh;
10983                 var currentBackground = null;
10984                 var currentBackgroundVersion = 0;
10985                 var currentTonemapping = null;
10986
10987                 function render(renderList, scene, camera, forceClear) {
10988                         var background = scene.isScene === true ? scene.background : null;
10989
10990                         if (background && background.isTexture) {
10991                                 background = cubemaps.get(background);
10992                         } // Ignore background in AR
10993                         // TODO: Reconsider this.
10994
10995
10996                         var xr = renderer.xr;
10997                         var session = xr.getSession && xr.getSession();
10998
10999                         if (session && session.environmentBlendMode === 'additive') {
11000                                 background = null;
11001                         }
11002
11003                         if (background === null) {
11004                                 setClear(clearColor, clearAlpha);
11005                         } else if (background && background.isColor) {
11006                                 setClear(background, 1);
11007                                 forceClear = true;
11008                         }
11009
11010                         if (renderer.autoClear || forceClear) {
11011                                 renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
11012                         }
11013
11014                         if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
11015                                 if (boxMesh === undefined) {
11016                                         boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
11017                                                 name: 'BackgroundCubeMaterial',
11018                                                 uniforms: cloneUniforms(ShaderLib.cube.uniforms),
11019                                                 vertexShader: ShaderLib.cube.vertexShader,
11020                                                 fragmentShader: ShaderLib.cube.fragmentShader,
11021                                                 side: BackSide,
11022                                                 depthTest: false,
11023                                                 depthWrite: false,
11024                                                 fog: false
11025                                         }));
11026                                         boxMesh.geometry.deleteAttribute('normal');
11027                                         boxMesh.geometry.deleteAttribute('uv');
11028
11029                                         boxMesh.onBeforeRender = function (renderer, scene, camera) {
11030                                                 this.matrixWorld.copyPosition(camera.matrixWorld);
11031                                         }; // enable code injection for non-built-in material
11032
11033
11034                                         Object.defineProperty(boxMesh.material, 'envMap', {
11035                                                 get: function get() {
11036                                                         return this.uniforms.envMap.value;
11037                                                 }
11038                                         });
11039                                         objects.update(boxMesh);
11040                                 }
11041
11042                                 if (background.isWebGLCubeRenderTarget) {
11043                                         // TODO Deprecate
11044                                         background = background.texture;
11045                                 }
11046
11047                                 boxMesh.material.uniforms.envMap.value = background;
11048                                 boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
11049
11050                                 if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
11051                                         boxMesh.material.needsUpdate = true;
11052                                         currentBackground = background;
11053                                         currentBackgroundVersion = background.version;
11054                                         currentTonemapping = renderer.toneMapping;
11055                                 } // push to the pre-sorted opaque render list
11056
11057
11058                                 renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
11059                         } else if (background && background.isTexture) {
11060                                 if (planeMesh === undefined) {
11061                                         planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
11062                                                 name: 'BackgroundMaterial',
11063                                                 uniforms: cloneUniforms(ShaderLib.background.uniforms),
11064                                                 vertexShader: ShaderLib.background.vertexShader,
11065                                                 fragmentShader: ShaderLib.background.fragmentShader,
11066                                                 side: FrontSide,
11067                                                 depthTest: false,
11068                                                 depthWrite: false,
11069                                                 fog: false
11070                                         }));
11071                                         planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
11072
11073                                         Object.defineProperty(planeMesh.material, 'map', {
11074                                                 get: function get() {
11075                                                         return this.uniforms.t2D.value;
11076                                                 }
11077                                         });
11078                                         objects.update(planeMesh);
11079                                 }
11080
11081                                 planeMesh.material.uniforms.t2D.value = background;
11082
11083                                 if (background.matrixAutoUpdate === true) {
11084                                         background.updateMatrix();
11085                                 }
11086
11087                                 planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
11088
11089                                 if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
11090                                         planeMesh.material.needsUpdate = true;
11091                                         currentBackground = background;
11092                                         currentBackgroundVersion = background.version;
11093                                         currentTonemapping = renderer.toneMapping;
11094                                 } // push to the pre-sorted opaque render list
11095
11096
11097                                 renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
11098                         }
11099                 }
11100
11101                 function setClear(color, alpha) {
11102                         state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
11103                 }
11104
11105                 return {
11106                         getClearColor: function getClearColor() {
11107                                 return clearColor;
11108                         },
11109                         setClearColor: function setClearColor(color, alpha) {
11110                                 if (alpha === void 0) {
11111                                         alpha = 1;
11112                                 }
11113
11114                                 clearColor.set(color);
11115                                 clearAlpha = alpha;
11116                                 setClear(clearColor, clearAlpha);
11117                         },
11118                         getClearAlpha: function getClearAlpha() {
11119                                 return clearAlpha;
11120                         },
11121                         setClearAlpha: function setClearAlpha(alpha) {
11122                                 clearAlpha = alpha;
11123                                 setClear(clearColor, clearAlpha);
11124                         },
11125                         render: render
11126                 };
11127         }
11128
11129         function WebGLBindingStates(gl, extensions, attributes, capabilities) {
11130                 var maxVertexAttributes = gl.getParameter(34921);
11131                 var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
11132                 var vaoAvailable = capabilities.isWebGL2 || extension !== null;
11133                 var bindingStates = {};
11134                 var defaultState = createBindingState(null);
11135                 var currentState = defaultState;
11136
11137                 function setup(object, material, program, geometry, index) {
11138                         var updateBuffers = false;
11139
11140                         if (vaoAvailable) {
11141                                 var state = getBindingState(geometry, program, material);
11142
11143                                 if (currentState !== state) {
11144                                         currentState = state;
11145                                         bindVertexArrayObject(currentState.object);
11146                                 }
11147
11148                                 updateBuffers = needsUpdate(geometry, index);
11149                                 if (updateBuffers) saveCache(geometry, index);
11150                         } else {
11151                                 var wireframe = material.wireframe === true;
11152
11153                                 if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
11154                                         currentState.geometry = geometry.id;
11155                                         currentState.program = program.id;
11156                                         currentState.wireframe = wireframe;
11157                                         updateBuffers = true;
11158                                 }
11159                         }
11160
11161                         if (object.isInstancedMesh === true) {
11162                                 updateBuffers = true;
11163                         }
11164
11165                         if (index !== null) {
11166                                 attributes.update(index, 34963);
11167                         }
11168
11169                         if (updateBuffers) {
11170                                 setupVertexAttributes(object, material, program, geometry);
11171
11172                                 if (index !== null) {
11173                                         gl.bindBuffer(34963, attributes.get(index).buffer);
11174                                 }
11175                         }
11176                 }
11177
11178                 function createVertexArrayObject() {
11179                         if (capabilities.isWebGL2) return gl.createVertexArray();
11180                         return extension.createVertexArrayOES();
11181                 }
11182
11183                 function bindVertexArrayObject(vao) {
11184                         if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
11185                         return extension.bindVertexArrayOES(vao);
11186                 }
11187
11188                 function deleteVertexArrayObject(vao) {
11189                         if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
11190                         return extension.deleteVertexArrayOES(vao);
11191                 }
11192
11193                 function getBindingState(geometry, program, material) {
11194                         var wireframe = material.wireframe === true;
11195                         var programMap = bindingStates[geometry.id];
11196
11197                         if (programMap === undefined) {
11198                                 programMap = {};
11199                                 bindingStates[geometry.id] = programMap;
11200                         }
11201
11202                         var stateMap = programMap[program.id];
11203
11204                         if (stateMap === undefined) {
11205                                 stateMap = {};
11206                                 programMap[program.id] = stateMap;
11207                         }
11208
11209                         var state = stateMap[wireframe];
11210
11211                         if (state === undefined) {
11212                                 state = createBindingState(createVertexArrayObject());
11213                                 stateMap[wireframe] = state;
11214                         }
11215
11216                         return state;
11217                 }
11218
11219                 function createBindingState(vao) {
11220                         var newAttributes = [];
11221                         var enabledAttributes = [];
11222                         var attributeDivisors = [];
11223
11224                         for (var i = 0; i < maxVertexAttributes; i++) {
11225                                 newAttributes[i] = 0;
11226                                 enabledAttributes[i] = 0;
11227                                 attributeDivisors[i] = 0;
11228                         }
11229
11230                         return {
11231                                 // for backward compatibility on non-VAO support browser
11232                                 geometry: null,
11233                                 program: null,
11234                                 wireframe: false,
11235                                 newAttributes: newAttributes,
11236                                 enabledAttributes: enabledAttributes,
11237                                 attributeDivisors: attributeDivisors,
11238                                 object: vao,
11239                                 attributes: {},
11240                                 index: null
11241                         };
11242                 }
11243
11244                 function needsUpdate(geometry, index) {
11245                         var cachedAttributes = currentState.attributes;
11246                         var geometryAttributes = geometry.attributes;
11247                         var attributesNum = 0;
11248
11249                         for (var key in geometryAttributes) {
11250                                 var cachedAttribute = cachedAttributes[key];
11251                                 var geometryAttribute = geometryAttributes[key];
11252                                 if (cachedAttribute === undefined) return true;
11253                                 if (cachedAttribute.attribute !== geometryAttribute) return true;
11254                                 if (cachedAttribute.data !== geometryAttribute.data) return true;
11255                                 attributesNum++;
11256                         }
11257
11258                         if (currentState.attributesNum !== attributesNum) return true;
11259                         if (currentState.index !== index) return true;
11260                         return false;
11261                 }
11262
11263                 function saveCache(geometry, index) {
11264                         var cache = {};
11265                         var attributes = geometry.attributes;
11266                         var attributesNum = 0;
11267
11268                         for (var key in attributes) {
11269                                 var attribute = attributes[key];
11270                                 var data = {};
11271                                 data.attribute = attribute;
11272
11273                                 if (attribute.data) {
11274                                         data.data = attribute.data;
11275                                 }
11276
11277                                 cache[key] = data;
11278                                 attributesNum++;
11279                         }
11280
11281                         currentState.attributes = cache;
11282                         currentState.attributesNum = attributesNum;
11283                         currentState.index = index;
11284                 }
11285
11286                 function initAttributes() {
11287                         var newAttributes = currentState.newAttributes;
11288
11289                         for (var i = 0, il = newAttributes.length; i < il; i++) {
11290                                 newAttributes[i] = 0;
11291                         }
11292                 }
11293
11294                 function enableAttribute(attribute) {
11295                         enableAttributeAndDivisor(attribute, 0);
11296                 }
11297
11298                 function enableAttributeAndDivisor(attribute, meshPerAttribute) {
11299                         var newAttributes = currentState.newAttributes;
11300                         var enabledAttributes = currentState.enabledAttributes;
11301                         var attributeDivisors = currentState.attributeDivisors;
11302                         newAttributes[attribute] = 1;
11303
11304                         if (enabledAttributes[attribute] === 0) {
11305                                 gl.enableVertexAttribArray(attribute);
11306                                 enabledAttributes[attribute] = 1;
11307                         }
11308
11309                         if (attributeDivisors[attribute] !== meshPerAttribute) {
11310                                 var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
11311
11312                                 _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
11313
11314                                 attributeDivisors[attribute] = meshPerAttribute;
11315                         }
11316                 }
11317
11318                 function disableUnusedAttributes() {
11319                         var newAttributes = currentState.newAttributes;
11320                         var enabledAttributes = currentState.enabledAttributes;
11321
11322                         for (var i = 0, il = enabledAttributes.length; i < il; i++) {
11323                                 if (enabledAttributes[i] !== newAttributes[i]) {
11324                                         gl.disableVertexAttribArray(i);
11325                                         enabledAttributes[i] = 0;
11326                                 }
11327                         }
11328                 }
11329
11330                 function vertexAttribPointer(index, size, type, normalized, stride, offset) {
11331                         if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
11332                                 gl.vertexAttribIPointer(index, size, type, stride, offset);
11333                         } else {
11334                                 gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
11335                         }
11336                 }
11337
11338                 function setupVertexAttributes(object, material, program, geometry) {
11339                         if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
11340                                 if (extensions.get('ANGLE_instanced_arrays') === null) return;
11341                         }
11342
11343                         initAttributes();
11344                         var geometryAttributes = geometry.attributes;
11345                         var programAttributes = program.getAttributes();
11346                         var materialDefaultAttributeValues = material.defaultAttributeValues;
11347
11348                         for (var name in programAttributes) {
11349                                 var programAttribute = programAttributes[name];
11350
11351                                 if (programAttribute >= 0) {
11352                                         var geometryAttribute = geometryAttributes[name];
11353
11354                                         if (geometryAttribute !== undefined) {
11355                                                 var normalized = geometryAttribute.normalized;
11356                                                 var size = geometryAttribute.itemSize;
11357                                                 var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
11358
11359                                                 if (attribute === undefined) continue;
11360                                                 var buffer = attribute.buffer;
11361                                                 var type = attribute.type;
11362                                                 var bytesPerElement = attribute.bytesPerElement;
11363
11364                                                 if (geometryAttribute.isInterleavedBufferAttribute) {
11365                                                         var data = geometryAttribute.data;
11366                                                         var stride = data.stride;
11367                                                         var offset = geometryAttribute.offset;
11368
11369                                                         if (data && data.isInstancedInterleavedBuffer) {
11370                                                                 enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
11371
11372                                                                 if (geometry._maxInstanceCount === undefined) {
11373                                                                         geometry._maxInstanceCount = data.meshPerAttribute * data.count;
11374                                                                 }
11375                                                         } else {
11376                                                                 enableAttribute(programAttribute);
11377                                                         }
11378
11379                                                         gl.bindBuffer(34962, buffer);
11380                                                         vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
11381                                                 } else {
11382                                                         if (geometryAttribute.isInstancedBufferAttribute) {
11383                                                                 enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
11384
11385                                                                 if (geometry._maxInstanceCount === undefined) {
11386                                                                         geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
11387                                                                 }
11388                                                         } else {
11389                                                                 enableAttribute(programAttribute);
11390                                                         }
11391
11392                                                         gl.bindBuffer(34962, buffer);
11393                                                         vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
11394                                                 }
11395                                         } else if (name === 'instanceMatrix') {
11396                                                 var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
11397
11398
11399                                                 if (_attribute === undefined) continue;
11400                                                 var _buffer = _attribute.buffer;
11401                                                 var _type = _attribute.type;
11402                                                 enableAttributeAndDivisor(programAttribute + 0, 1);
11403                                                 enableAttributeAndDivisor(programAttribute + 1, 1);
11404                                                 enableAttributeAndDivisor(programAttribute + 2, 1);
11405                                                 enableAttributeAndDivisor(programAttribute + 3, 1);
11406                                                 gl.bindBuffer(34962, _buffer);
11407                                                 gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
11408                                                 gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
11409                                                 gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
11410                                                 gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
11411                                         } else if (name === 'instanceColor') {
11412                                                 var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
11413
11414
11415                                                 if (_attribute2 === undefined) continue;
11416                                                 var _buffer2 = _attribute2.buffer;
11417                                                 var _type2 = _attribute2.type;
11418                                                 enableAttributeAndDivisor(programAttribute, 1);
11419                                                 gl.bindBuffer(34962, _buffer2);
11420                                                 gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
11421                                         } else if (materialDefaultAttributeValues !== undefined) {
11422                                                 var value = materialDefaultAttributeValues[name];
11423
11424                                                 if (value !== undefined) {
11425                                                         switch (value.length) {
11426                                                                 case 2:
11427                                                                         gl.vertexAttrib2fv(programAttribute, value);
11428                                                                         break;
11429
11430                                                                 case 3:
11431                                                                         gl.vertexAttrib3fv(programAttribute, value);
11432                                                                         break;
11433
11434                                                                 case 4:
11435                                                                         gl.vertexAttrib4fv(programAttribute, value);
11436                                                                         break;
11437
11438                                                                 default:
11439                                                                         gl.vertexAttrib1fv(programAttribute, value);
11440                                                         }
11441                                                 }
11442                                         }
11443                                 }
11444                         }
11445
11446                         disableUnusedAttributes();
11447                 }
11448
11449                 function dispose() {
11450                         reset();
11451
11452                         for (var geometryId in bindingStates) {
11453                                 var programMap = bindingStates[geometryId];
11454
11455                                 for (var programId in programMap) {
11456                                         var stateMap = programMap[programId];
11457
11458                                         for (var wireframe in stateMap) {
11459                                                 deleteVertexArrayObject(stateMap[wireframe].object);
11460                                                 delete stateMap[wireframe];
11461                                         }
11462
11463                                         delete programMap[programId];
11464                                 }
11465
11466                                 delete bindingStates[geometryId];
11467                         }
11468                 }
11469
11470                 function releaseStatesOfGeometry(geometry) {
11471                         if (bindingStates[geometry.id] === undefined) return;
11472                         var programMap = bindingStates[geometry.id];
11473
11474                         for (var programId in programMap) {
11475                                 var stateMap = programMap[programId];
11476
11477                                 for (var wireframe in stateMap) {
11478                                         deleteVertexArrayObject(stateMap[wireframe].object);
11479                                         delete stateMap[wireframe];
11480                                 }
11481
11482                                 delete programMap[programId];
11483                         }
11484
11485                         delete bindingStates[geometry.id];
11486                 }
11487
11488                 function releaseStatesOfProgram(program) {
11489                         for (var geometryId in bindingStates) {
11490                                 var programMap = bindingStates[geometryId];
11491                                 if (programMap[program.id] === undefined) continue;
11492                                 var stateMap = programMap[program.id];
11493
11494                                 for (var wireframe in stateMap) {
11495                                         deleteVertexArrayObject(stateMap[wireframe].object);
11496                                         delete stateMap[wireframe];
11497                                 }
11498
11499                                 delete programMap[program.id];
11500                         }
11501                 }
11502
11503                 function reset() {
11504                         resetDefaultState();
11505                         if (currentState === defaultState) return;
11506                         currentState = defaultState;
11507                         bindVertexArrayObject(currentState.object);
11508                 } // for backward-compatilibity
11509
11510
11511                 function resetDefaultState() {
11512                         defaultState.geometry = null;
11513                         defaultState.program = null;
11514                         defaultState.wireframe = false;
11515                 }
11516
11517                 return {
11518                         setup: setup,
11519                         reset: reset,
11520                         resetDefaultState: resetDefaultState,
11521                         dispose: dispose,
11522                         releaseStatesOfGeometry: releaseStatesOfGeometry,
11523                         releaseStatesOfProgram: releaseStatesOfProgram,
11524                         initAttributes: initAttributes,
11525                         enableAttribute: enableAttribute,
11526                         disableUnusedAttributes: disableUnusedAttributes
11527                 };
11528         }
11529
11530         function WebGLBufferRenderer(gl, extensions, info, capabilities) {
11531                 var isWebGL2 = capabilities.isWebGL2;
11532                 var mode;
11533
11534                 function setMode(value) {
11535                         mode = value;
11536                 }
11537
11538                 function render(start, count) {
11539                         gl.drawArrays(mode, start, count);
11540                         info.update(count, mode, 1);
11541                 }
11542
11543                 function renderInstances(start, count, primcount) {
11544                         if (primcount === 0) return;
11545                         var extension, methodName;
11546
11547                         if (isWebGL2) {
11548                                 extension = gl;
11549                                 methodName = 'drawArraysInstanced';
11550                         } else {
11551                                 extension = extensions.get('ANGLE_instanced_arrays');
11552                                 methodName = 'drawArraysInstancedANGLE';
11553
11554                                 if (extension === null) {
11555                                         console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
11556                                         return;
11557                                 }
11558                         }
11559
11560                         extension[methodName](mode, start, count, primcount);
11561                         info.update(count, mode, primcount);
11562                 } //
11563
11564
11565                 this.setMode = setMode;
11566                 this.render = render;
11567                 this.renderInstances = renderInstances;
11568         }
11569
11570         function WebGLCapabilities(gl, extensions, parameters) {
11571                 var maxAnisotropy;
11572
11573                 function getMaxAnisotropy() {
11574                         if (maxAnisotropy !== undefined) return maxAnisotropy;
11575                         var extension = extensions.get('EXT_texture_filter_anisotropic');
11576
11577                         if (extension !== null) {
11578                                 maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
11579                         } else {
11580                                 maxAnisotropy = 0;
11581                         }
11582
11583                         return maxAnisotropy;
11584                 }
11585
11586                 function getMaxPrecision(precision) {
11587                         if (precision === 'highp') {
11588                                 if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
11589                                         return 'highp';
11590                                 }
11591
11592                                 precision = 'mediump';
11593                         }
11594
11595                         if (precision === 'mediump') {
11596                                 if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
11597                                         return 'mediump';
11598                                 }
11599                         }
11600
11601                         return 'lowp';
11602                 }
11603                 /* eslint-disable no-undef */
11604
11605
11606                 var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
11607                 /* eslint-enable no-undef */
11608
11609                 var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
11610                 var maxPrecision = getMaxPrecision(precision);
11611
11612                 if (maxPrecision !== precision) {
11613                         console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
11614                         precision = maxPrecision;
11615                 }
11616
11617                 var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
11618                 var maxTextures = gl.getParameter(34930);
11619                 var maxVertexTextures = gl.getParameter(35660);
11620                 var maxTextureSize = gl.getParameter(3379);
11621                 var maxCubemapSize = gl.getParameter(34076);
11622                 var maxAttributes = gl.getParameter(34921);
11623                 var maxVertexUniforms = gl.getParameter(36347);
11624                 var maxVaryings = gl.getParameter(36348);
11625                 var maxFragmentUniforms = gl.getParameter(36349);
11626                 var vertexTextures = maxVertexTextures > 0;
11627                 var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
11628                 var floatVertexTextures = vertexTextures && floatFragmentTextures;
11629                 var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
11630                 return {
11631                         isWebGL2: isWebGL2,
11632                         getMaxAnisotropy: getMaxAnisotropy,
11633                         getMaxPrecision: getMaxPrecision,
11634                         precision: precision,
11635                         logarithmicDepthBuffer: logarithmicDepthBuffer,
11636                         maxTextures: maxTextures,
11637                         maxVertexTextures: maxVertexTextures,
11638                         maxTextureSize: maxTextureSize,
11639                         maxCubemapSize: maxCubemapSize,
11640                         maxAttributes: maxAttributes,
11641                         maxVertexUniforms: maxVertexUniforms,
11642                         maxVaryings: maxVaryings,
11643                         maxFragmentUniforms: maxFragmentUniforms,
11644                         vertexTextures: vertexTextures,
11645                         floatFragmentTextures: floatFragmentTextures,
11646                         floatVertexTextures: floatVertexTextures,
11647                         maxSamples: maxSamples
11648                 };
11649         }
11650
11651         function WebGLClipping(properties) {
11652                 var scope = this;
11653                 var globalState = null,
11654                                 numGlobalPlanes = 0,
11655                                 localClippingEnabled = false,
11656                                 renderingShadows = false;
11657                 var plane = new Plane(),
11658                                 viewNormalMatrix = new Matrix3(),
11659                                 uniform = {
11660                         value: null,
11661                         needsUpdate: false
11662                 };
11663                 this.uniform = uniform;
11664                 this.numPlanes = 0;
11665                 this.numIntersection = 0;
11666
11667                 this.init = function (planes, enableLocalClipping, camera) {
11668                         var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
11669                         // run another frame in order to reset the state:
11670                         numGlobalPlanes !== 0 || localClippingEnabled;
11671                         localClippingEnabled = enableLocalClipping;
11672                         globalState = projectPlanes(planes, camera, 0);
11673                         numGlobalPlanes = planes.length;
11674                         return enabled;
11675                 };
11676
11677                 this.beginShadows = function () {
11678                         renderingShadows = true;
11679                         projectPlanes(null);
11680                 };
11681
11682                 this.endShadows = function () {
11683                         renderingShadows = false;
11684                         resetGlobalState();
11685                 };
11686
11687                 this.setState = function (material, camera, useCache) {
11688                         var planes = material.clippingPlanes,
11689                                         clipIntersection = material.clipIntersection,
11690                                         clipShadows = material.clipShadows;
11691                         var materialProperties = properties.get(material);
11692
11693                         if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
11694                                 // there's no local clipping
11695                                 if (renderingShadows) {
11696                                         // there's no global clipping
11697                                         projectPlanes(null);
11698                                 } else {
11699                                         resetGlobalState();
11700                                 }
11701                         } else {
11702                                 var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
11703                                                 lGlobal = nGlobal * 4;
11704                                 var dstArray = materialProperties.clippingState || null;
11705                                 uniform.value = dstArray; // ensure unique state
11706
11707                                 dstArray = projectPlanes(planes, camera, lGlobal, useCache);
11708
11709                                 for (var i = 0; i !== lGlobal; ++i) {
11710                                         dstArray[i] = globalState[i];
11711                                 }
11712
11713                                 materialProperties.clippingState = dstArray;
11714                                 this.numIntersection = clipIntersection ? this.numPlanes : 0;
11715                                 this.numPlanes += nGlobal;
11716                         }
11717                 };
11718
11719                 function resetGlobalState() {
11720                         if (uniform.value !== globalState) {
11721                                 uniform.value = globalState;
11722                                 uniform.needsUpdate = numGlobalPlanes > 0;
11723                         }
11724
11725                         scope.numPlanes = numGlobalPlanes;
11726                         scope.numIntersection = 0;
11727                 }
11728
11729                 function projectPlanes(planes, camera, dstOffset, skipTransform) {
11730                         var nPlanes = planes !== null ? planes.length : 0;
11731                         var dstArray = null;
11732
11733                         if (nPlanes !== 0) {
11734                                 dstArray = uniform.value;
11735
11736                                 if (skipTransform !== true || dstArray === null) {
11737                                         var flatSize = dstOffset + nPlanes * 4,
11738                                                         viewMatrix = camera.matrixWorldInverse;
11739                                         viewNormalMatrix.getNormalMatrix(viewMatrix);
11740
11741                                         if (dstArray === null || dstArray.length < flatSize) {
11742                                                 dstArray = new Float32Array(flatSize);
11743                                         }
11744
11745                                         for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
11746                                                 plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
11747                                                 plane.normal.toArray(dstArray, i4);
11748                                                 dstArray[i4 + 3] = plane.constant;
11749                                         }
11750                                 }
11751
11752                                 uniform.value = dstArray;
11753                                 uniform.needsUpdate = true;
11754                         }
11755
11756                         scope.numPlanes = nPlanes;
11757                         scope.numIntersection = 0;
11758                         return dstArray;
11759                 }
11760         }
11761
11762         function WebGLCubeMaps(renderer) {
11763                 var cubemaps = new WeakMap();
11764
11765                 function mapTextureMapping(texture, mapping) {
11766                         if (mapping === EquirectangularReflectionMapping) {
11767                                 texture.mapping = CubeReflectionMapping;
11768                         } else if (mapping === EquirectangularRefractionMapping) {
11769                                 texture.mapping = CubeRefractionMapping;
11770                         }
11771
11772                         return texture;
11773                 }
11774
11775                 function get(texture) {
11776                         if (texture && texture.isTexture) {
11777                                 var mapping = texture.mapping;
11778
11779                                 if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
11780                                         if (cubemaps.has(texture)) {
11781                                                 var cubemap = cubemaps.get(texture).texture;
11782                                                 return mapTextureMapping(cubemap, texture.mapping);
11783                                         } else {
11784                                                 var image = texture.image;
11785
11786                                                 if (image && image.height > 0) {
11787                                                         var currentRenderList = renderer.getRenderList();
11788                                                         var currentRenderTarget = renderer.getRenderTarget();
11789                                                         var currentRenderState = renderer.getRenderState();
11790                                                         var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
11791                                                         renderTarget.fromEquirectangularTexture(renderer, texture);
11792                                                         cubemaps.set(texture, renderTarget);
11793                                                         renderer.setRenderTarget(currentRenderTarget);
11794                                                         renderer.setRenderList(currentRenderList);
11795                                                         renderer.setRenderState(currentRenderState);
11796                                                         texture.addEventListener('dispose', onTextureDispose);
11797                                                         return mapTextureMapping(renderTarget.texture, texture.mapping);
11798                                                 } else {
11799                                                         // image not yet ready. try the conversion next frame
11800                                                         return null;
11801                                                 }
11802                                         }
11803                                 }
11804                         }
11805
11806                         return texture;
11807                 }
11808
11809                 function onTextureDispose(event) {
11810                         var texture = event.target;
11811                         texture.removeEventListener('dispose', onTextureDispose);
11812                         var cubemap = cubemaps.get(texture);
11813
11814                         if (cubemap !== undefined) {
11815                                 cubemaps.delete(texture);
11816                                 cubemap.dispose();
11817                         }
11818                 }
11819
11820                 function dispose() {
11821                         cubemaps = new WeakMap();
11822                 }
11823
11824                 return {
11825                         get: get,
11826                         dispose: dispose
11827                 };
11828         }
11829
11830         function WebGLExtensions(gl) {
11831                 var extensions = {};
11832                 return {
11833                         has: function has(name) {
11834                                 if (extensions[name] !== undefined) {
11835                                         return extensions[name] !== null;
11836                                 }
11837
11838                                 var extension;
11839
11840                                 switch (name) {
11841                                         case 'WEBGL_depth_texture':
11842                                                 extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
11843                                                 break;
11844
11845                                         case 'EXT_texture_filter_anisotropic':
11846                                                 extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
11847                                                 break;
11848
11849                                         case 'WEBGL_compressed_texture_s3tc':
11850                                                 extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
11851                                                 break;
11852
11853                                         case 'WEBGL_compressed_texture_pvrtc':
11854                                                 extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
11855                                                 break;
11856
11857                                         default:
11858                                                 extension = gl.getExtension(name);
11859                                 }
11860
11861                                 extensions[name] = extension;
11862                                 return extension !== null;
11863                         },
11864                         get: function get(name) {
11865                                 if (!this.has(name)) {
11866                                         console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
11867                                 }
11868
11869                                 return extensions[name];
11870                         }
11871                 };
11872         }
11873
11874         function WebGLGeometries(gl, attributes, info, bindingStates) {
11875                 var geometries = new WeakMap();
11876                 var wireframeAttributes = new WeakMap();
11877
11878                 function onGeometryDispose(event) {
11879                         var geometry = event.target;
11880                         var buffergeometry = geometries.get(geometry);
11881
11882                         if (buffergeometry.index !== null) {
11883                                 attributes.remove(buffergeometry.index);
11884                         }
11885
11886                         for (var name in buffergeometry.attributes) {
11887                                 attributes.remove(buffergeometry.attributes[name]);
11888                         }
11889
11890                         geometry.removeEventListener('dispose', onGeometryDispose);
11891                         geometries.delete(geometry);
11892                         var attribute = wireframeAttributes.get(buffergeometry);
11893
11894                         if (attribute) {
11895                                 attributes.remove(attribute);
11896                                 wireframeAttributes.delete(buffergeometry);
11897                         }
11898
11899                         bindingStates.releaseStatesOfGeometry(buffergeometry);
11900
11901                         if (geometry.isInstancedBufferGeometry === true) {
11902                                 delete geometry._maxInstanceCount;
11903                         } //
11904
11905
11906                         info.memory.geometries--;
11907                 }
11908
11909                 function get(object, geometry) {
11910                         var buffergeometry = geometries.get(geometry);
11911                         if (buffergeometry) return buffergeometry;
11912                         geometry.addEventListener('dispose', onGeometryDispose);
11913
11914                         if (geometry.isBufferGeometry) {
11915                                 buffergeometry = geometry;
11916                         } else if (geometry.isGeometry) {
11917                                 if (geometry._bufferGeometry === undefined) {
11918                                         geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
11919                                 }
11920
11921                                 buffergeometry = geometry._bufferGeometry;
11922                         }
11923
11924                         geometries.set(geometry, buffergeometry);
11925                         info.memory.geometries++;
11926                         return buffergeometry;
11927                 }
11928
11929                 function update(geometry) {
11930                         var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
11931
11932                         for (var name in geometryAttributes) {
11933                                 attributes.update(geometryAttributes[name], 34962);
11934                         } // morph targets
11935
11936
11937                         var morphAttributes = geometry.morphAttributes;
11938
11939                         for (var _name in morphAttributes) {
11940                                 var array = morphAttributes[_name];
11941
11942                                 for (var i = 0, l = array.length; i < l; i++) {
11943                                         attributes.update(array[i], 34962);
11944                                 }
11945                         }
11946                 }
11947
11948                 function updateWireframeAttribute(geometry) {
11949                         var indices = [];
11950                         var geometryIndex = geometry.index;
11951                         var geometryPosition = geometry.attributes.position;
11952                         var version = 0;
11953
11954                         if (geometryIndex !== null) {
11955                                 var array = geometryIndex.array;
11956                                 version = geometryIndex.version;
11957
11958                                 for (var i = 0, l = array.length; i < l; i += 3) {
11959                                         var a = array[i + 0];
11960                                         var b = array[i + 1];
11961                                         var c = array[i + 2];
11962                                         indices.push(a, b, b, c, c, a);
11963                                 }
11964                         } else {
11965                                 var _array = geometryPosition.array;
11966                                 version = geometryPosition.version;
11967
11968                                 for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
11969                                         var _a = _i + 0;
11970
11971                                         var _b = _i + 1;
11972
11973                                         var _c = _i + 2;
11974
11975                                         indices.push(_a, _b, _b, _c, _c, _a);
11976                                 }
11977                         }
11978
11979                         var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
11980                         attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
11981                         //
11982
11983                         var previousAttribute = wireframeAttributes.get(geometry);
11984                         if (previousAttribute) attributes.remove(previousAttribute); //
11985
11986                         wireframeAttributes.set(geometry, attribute);
11987                 }
11988
11989                 function getWireframeAttribute(geometry) {
11990                         var currentAttribute = wireframeAttributes.get(geometry);
11991
11992                         if (currentAttribute) {
11993                                 var geometryIndex = geometry.index;
11994
11995                                 if (geometryIndex !== null) {
11996                                         // if the attribute is obsolete, create a new one
11997                                         if (currentAttribute.version < geometryIndex.version) {
11998                                                 updateWireframeAttribute(geometry);
11999                                         }
12000                                 }
12001                         } else {
12002                                 updateWireframeAttribute(geometry);
12003                         }
12004
12005                         return wireframeAttributes.get(geometry);
12006                 }
12007
12008                 return {
12009                         get: get,
12010                         update: update,
12011                         getWireframeAttribute: getWireframeAttribute
12012                 };
12013         }
12014
12015         function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
12016                 var isWebGL2 = capabilities.isWebGL2;
12017                 var mode;
12018
12019                 function setMode(value) {
12020                         mode = value;
12021                 }
12022
12023                 var type, bytesPerElement;
12024
12025                 function setIndex(value) {
12026                         type = value.type;
12027                         bytesPerElement = value.bytesPerElement;
12028                 }
12029
12030                 function render(start, count) {
12031                         gl.drawElements(mode, count, type, start * bytesPerElement);
12032                         info.update(count, mode, 1);
12033                 }
12034
12035                 function renderInstances(start, count, primcount) {
12036                         if (primcount === 0) return;
12037                         var extension, methodName;
12038
12039                         if (isWebGL2) {
12040                                 extension = gl;
12041                                 methodName = 'drawElementsInstanced';
12042                         } else {
12043                                 extension = extensions.get('ANGLE_instanced_arrays');
12044                                 methodName = 'drawElementsInstancedANGLE';
12045
12046                                 if (extension === null) {
12047                                         console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
12048                                         return;
12049                                 }
12050                         }
12051
12052                         extension[methodName](mode, count, type, start * bytesPerElement, primcount);
12053                         info.update(count, mode, primcount);
12054                 } //
12055
12056
12057                 this.setMode = setMode;
12058                 this.setIndex = setIndex;
12059                 this.render = render;
12060                 this.renderInstances = renderInstances;
12061         }
12062
12063         function WebGLInfo(gl) {
12064                 var memory = {
12065                         geometries: 0,
12066                         textures: 0
12067                 };
12068                 var render = {
12069                         frame: 0,
12070                         calls: 0,
12071                         triangles: 0,
12072                         points: 0,
12073                         lines: 0
12074                 };
12075
12076                 function update(count, mode, instanceCount) {
12077                         render.calls++;
12078
12079                         switch (mode) {
12080                                 case 4:
12081                                         render.triangles += instanceCount * (count / 3);
12082                                         break;
12083
12084                                 case 1:
12085                                         render.lines += instanceCount * (count / 2);
12086                                         break;
12087
12088                                 case 3:
12089                                         render.lines += instanceCount * (count - 1);
12090                                         break;
12091
12092                                 case 2:
12093                                         render.lines += instanceCount * count;
12094                                         break;
12095
12096                                 case 0:
12097                                         render.points += instanceCount * count;
12098                                         break;
12099
12100                                 default:
12101                                         console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
12102                                         break;
12103                         }
12104                 }
12105
12106                 function reset() {
12107                         render.frame++;
12108                         render.calls = 0;
12109                         render.triangles = 0;
12110                         render.points = 0;
12111                         render.lines = 0;
12112                 }
12113
12114                 return {
12115                         memory: memory,
12116                         render: render,
12117                         programs: null,
12118                         autoReset: true,
12119                         reset: reset,
12120                         update: update
12121                 };
12122         }
12123
12124         function numericalSort(a, b) {
12125                 return a[0] - b[0];
12126         }
12127
12128         function absNumericalSort(a, b) {
12129                 return Math.abs(b[1]) - Math.abs(a[1]);
12130         }
12131
12132         function WebGLMorphtargets(gl) {
12133                 var influencesList = {};
12134                 var morphInfluences = new Float32Array(8);
12135                 var workInfluences = [];
12136
12137                 for (var i = 0; i < 8; i++) {
12138                         workInfluences[i] = [i, 0];
12139                 }
12140
12141                 function update(object, geometry, material, program) {
12142                         var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
12143                         // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
12144
12145                         var length = objectInfluences === undefined ? 0 : objectInfluences.length;
12146                         var influences = influencesList[geometry.id];
12147
12148                         if (influences === undefined) {
12149                                 // initialise list
12150                                 influences = [];
12151
12152                                 for (var _i = 0; _i < length; _i++) {
12153                                         influences[_i] = [_i, 0];
12154                                 }
12155
12156                                 influencesList[geometry.id] = influences;
12157                         } // Collect influences
12158
12159
12160                         for (var _i2 = 0; _i2 < length; _i2++) {
12161                                 var influence = influences[_i2];
12162                                 influence[0] = _i2;
12163                                 influence[1] = objectInfluences[_i2];
12164                         }
12165
12166                         influences.sort(absNumericalSort);
12167
12168                         for (var _i3 = 0; _i3 < 8; _i3++) {
12169                                 if (_i3 < length && influences[_i3][1]) {
12170                                         workInfluences[_i3][0] = influences[_i3][0];
12171                                         workInfluences[_i3][1] = influences[_i3][1];
12172                                 } else {
12173                                         workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
12174                                         workInfluences[_i3][1] = 0;
12175                                 }
12176                         }
12177
12178                         workInfluences.sort(numericalSort);
12179                         var morphTargets = material.morphTargets && geometry.morphAttributes.position;
12180                         var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
12181                         var morphInfluencesSum = 0;
12182
12183                         for (var _i4 = 0; _i4 < 8; _i4++) {
12184                                 var _influence = workInfluences[_i4];
12185                                 var index = _influence[0];
12186                                 var value = _influence[1];
12187
12188                                 if (index !== Number.MAX_SAFE_INTEGER && value) {
12189                                         if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
12190                                                 geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
12191                                         }
12192
12193                                         if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
12194                                                 geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
12195                                         }
12196
12197                                         morphInfluences[_i4] = value;
12198                                         morphInfluencesSum += value;
12199                                 } else {
12200                                         if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
12201                                                 geometry.deleteAttribute('morphTarget' + _i4);
12202                                         }
12203
12204                                         if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
12205                                                 geometry.deleteAttribute('morphNormal' + _i4);
12206                                         }
12207
12208                                         morphInfluences[_i4] = 0;
12209                                 }
12210                         } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
12211                         // This allows us to switch between absolute morphs and relative morphs without changing shader code
12212                         // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
12213
12214
12215                         var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
12216                         program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
12217                         program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
12218                 }
12219
12220                 return {
12221                         update: update
12222                 };
12223         }
12224
12225         function WebGLObjects(gl, geometries, attributes, info) {
12226                 var updateMap = new WeakMap();
12227
12228                 function update(object) {
12229                         var frame = info.render.frame;
12230                         var geometry = object.geometry;
12231                         var buffergeometry = geometries.get(object, geometry); // Update once per frame
12232
12233                         if (updateMap.get(buffergeometry) !== frame) {
12234                                 if (geometry.isGeometry) {
12235                                         buffergeometry.updateFromObject(object);
12236                                 }
12237
12238                                 geometries.update(buffergeometry);
12239                                 updateMap.set(buffergeometry, frame);
12240                         }
12241
12242                         if (object.isInstancedMesh) {
12243                                 attributes.update(object.instanceMatrix, 34962);
12244
12245                                 if (object.instanceColor !== null) {
12246                                         attributes.update(object.instanceColor, 34962);
12247                                 }
12248                         }
12249
12250                         return buffergeometry;
12251                 }
12252
12253                 function dispose() {
12254                         updateMap = new WeakMap();
12255                 }
12256
12257                 return {
12258                         update: update,
12259                         dispose: dispose
12260                 };
12261         }
12262
12263         function DataTexture2DArray(data, width, height, depth) {
12264                 if (data === void 0) {
12265                         data = null;
12266                 }
12267
12268                 if (width === void 0) {
12269                         width = 1;
12270                 }
12271
12272                 if (height === void 0) {
12273                         height = 1;
12274                 }
12275
12276                 if (depth === void 0) {
12277                         depth = 1;
12278                 }
12279
12280                 Texture.call(this, null);
12281                 this.image = {
12282                         data: data,
12283                         width: width,
12284                         height: height,
12285                         depth: depth
12286                 };
12287                 this.magFilter = NearestFilter;
12288                 this.minFilter = NearestFilter;
12289                 this.wrapR = ClampToEdgeWrapping;
12290                 this.generateMipmaps = false;
12291                 this.flipY = false;
12292                 this.needsUpdate = true;
12293         }
12294
12295         DataTexture2DArray.prototype = Object.create(Texture.prototype);
12296         DataTexture2DArray.prototype.constructor = DataTexture2DArray;
12297         DataTexture2DArray.prototype.isDataTexture2DArray = true;
12298
12299         function DataTexture3D(data, width, height, depth) {
12300                 if (data === void 0) {
12301                         data = null;
12302                 }
12303
12304                 if (width === void 0) {
12305                         width = 1;
12306                 }
12307
12308                 if (height === void 0) {
12309                         height = 1;
12310                 }
12311
12312                 if (depth === void 0) {
12313                         depth = 1;
12314                 }
12315
12316                 // We're going to add .setXXX() methods for setting properties later.
12317                 // Users can still set in DataTexture3D directly.
12318                 //
12319                 //      const texture = new THREE.DataTexture3D( data, width, height, depth );
12320                 //      texture.anisotropy = 16;
12321                 //
12322                 // See #14839
12323                 Texture.call(this, null);
12324                 this.image = {
12325                         data: data,
12326                         width: width,
12327                         height: height,
12328                         depth: depth
12329                 };
12330                 this.magFilter = NearestFilter;
12331                 this.minFilter = NearestFilter;
12332                 this.wrapR = ClampToEdgeWrapping;
12333                 this.generateMipmaps = false;
12334                 this.flipY = false;
12335                 this.needsUpdate = true;
12336         }
12337
12338         DataTexture3D.prototype = Object.create(Texture.prototype);
12339         DataTexture3D.prototype.constructor = DataTexture3D;
12340         DataTexture3D.prototype.isDataTexture3D = true;
12341
12342         /**
12343          * Uniforms of a program.
12344          * Those form a tree structure with a special top-level container for the root,
12345          * which you get by calling 'new WebGLUniforms( gl, program )'.
12346          *
12347          *
12348          * Properties of inner nodes including the top-level container:
12349          *
12350          * .seq - array of nested uniforms
12351          * .map - nested uniforms by name
12352          *
12353          *
12354          * Methods of all nodes except the top-level container:
12355          *
12356          * .setValue( gl, value, [textures] )
12357          *
12358          *              uploads a uniform value(s)
12359          *              the 'textures' parameter is needed for sampler uniforms
12360          *
12361          *
12362          * Static methods of the top-level container (textures factorizations):
12363          *
12364          * .upload( gl, seq, values, textures )
12365          *
12366          *              sets uniforms in 'seq' to 'values[id].value'
12367          *
12368          * .seqWithValue( seq, values ) : filteredSeq
12369          *
12370          *              filters 'seq' entries with corresponding entry in values
12371          *
12372          *
12373          * Methods of the top-level container (textures factorizations):
12374          *
12375          * .setValue( gl, name, value, textures )
12376          *
12377          *              sets uniform with       name 'name' to 'value'
12378          *
12379          * .setOptional( gl, obj, prop )
12380          *
12381          *              like .set for an optional property of the object
12382          *
12383          */
12384         var emptyTexture = new Texture();
12385         var emptyTexture2dArray = new DataTexture2DArray();
12386         var emptyTexture3d = new DataTexture3D();
12387         var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
12388         // Array Caches (provide typed arrays for temporary by size)
12389
12390         var arrayCacheF32 = [];
12391         var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
12392
12393         var mat4array = new Float32Array(16);
12394         var mat3array = new Float32Array(9);
12395         var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
12396
12397         function flatten(array, nBlocks, blockSize) {
12398                 var firstElem = array[0];
12399                 if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
12400                 // see http://jacksondunstan.com/articles/983
12401
12402                 var n = nBlocks * blockSize;
12403                 var r = arrayCacheF32[n];
12404
12405                 if (r === undefined) {
12406                         r = new Float32Array(n);
12407                         arrayCacheF32[n] = r;
12408                 }
12409
12410                 if (nBlocks !== 0) {
12411                         firstElem.toArray(r, 0);
12412
12413                         for (var i = 1, offset = 0; i !== nBlocks; ++i) {
12414                                 offset += blockSize;
12415                                 array[i].toArray(r, offset);
12416                         }
12417                 }
12418
12419                 return r;
12420         }
12421
12422         function arraysEqual(a, b) {
12423                 if (a.length !== b.length) return false;
12424
12425                 for (var i = 0, l = a.length; i < l; i++) {
12426                         if (a[i] !== b[i]) return false;
12427                 }
12428
12429                 return true;
12430         }
12431
12432         function copyArray(a, b) {
12433                 for (var i = 0, l = b.length; i < l; i++) {
12434                         a[i] = b[i];
12435                 }
12436         } // Texture unit allocation
12437
12438
12439         function allocTexUnits(textures, n) {
12440                 var r = arrayCacheI32[n];
12441
12442                 if (r === undefined) {
12443                         r = new Int32Array(n);
12444                         arrayCacheI32[n] = r;
12445                 }
12446
12447                 for (var i = 0; i !== n; ++i) {
12448                         r[i] = textures.allocateTextureUnit();
12449                 }
12450
12451                 return r;
12452         } // --- Setters ---
12453         // Note: Defining these methods externally, because they come in a bunch
12454         // and this way their names minify.
12455         // Single scalar
12456
12457
12458         function setValueV1f(gl, v) {
12459                 var cache = this.cache;
12460                 if (cache[0] === v) return;
12461                 gl.uniform1f(this.addr, v);
12462                 cache[0] = v;
12463         } // Single float vector (from flat array or THREE.VectorN)
12464
12465
12466         function setValueV2f(gl, v) {
12467                 var cache = this.cache;
12468
12469                 if (v.x !== undefined) {
12470                         if (cache[0] !== v.x || cache[1] !== v.y) {
12471                                 gl.uniform2f(this.addr, v.x, v.y);
12472                                 cache[0] = v.x;
12473                                 cache[1] = v.y;
12474                         }
12475                 } else {
12476                         if (arraysEqual(cache, v)) return;
12477                         gl.uniform2fv(this.addr, v);
12478                         copyArray(cache, v);
12479                 }
12480         }
12481
12482         function setValueV3f(gl, v) {
12483                 var cache = this.cache;
12484
12485                 if (v.x !== undefined) {
12486                         if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
12487                                 gl.uniform3f(this.addr, v.x, v.y, v.z);
12488                                 cache[0] = v.x;
12489                                 cache[1] = v.y;
12490                                 cache[2] = v.z;
12491                         }
12492                 } else if (v.r !== undefined) {
12493                         if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
12494                                 gl.uniform3f(this.addr, v.r, v.g, v.b);
12495                                 cache[0] = v.r;
12496                                 cache[1] = v.g;
12497                                 cache[2] = v.b;
12498                         }
12499                 } else {
12500                         if (arraysEqual(cache, v)) return;
12501                         gl.uniform3fv(this.addr, v);
12502                         copyArray(cache, v);
12503                 }
12504         }
12505
12506         function setValueV4f(gl, v) {
12507                 var cache = this.cache;
12508
12509                 if (v.x !== undefined) {
12510                         if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
12511                                 gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
12512                                 cache[0] = v.x;
12513                                 cache[1] = v.y;
12514                                 cache[2] = v.z;
12515                                 cache[3] = v.w;
12516                         }
12517                 } else {
12518                         if (arraysEqual(cache, v)) return;
12519                         gl.uniform4fv(this.addr, v);
12520                         copyArray(cache, v);
12521                 }
12522         } // Single matrix (from flat array or MatrixN)
12523
12524
12525         function setValueM2(gl, v) {
12526                 var cache = this.cache;
12527                 var elements = v.elements;
12528
12529                 if (elements === undefined) {
12530                         if (arraysEqual(cache, v)) return;
12531                         gl.uniformMatrix2fv(this.addr, false, v);
12532                         copyArray(cache, v);
12533                 } else {
12534                         if (arraysEqual(cache, elements)) return;
12535                         mat2array.set(elements);
12536                         gl.uniformMatrix2fv(this.addr, false, mat2array);
12537                         copyArray(cache, elements);
12538                 }
12539         }
12540
12541         function setValueM3(gl, v) {
12542                 var cache = this.cache;
12543                 var elements = v.elements;
12544
12545                 if (elements === undefined) {
12546                         if (arraysEqual(cache, v)) return;
12547                         gl.uniformMatrix3fv(this.addr, false, v);
12548                         copyArray(cache, v);
12549                 } else {
12550                         if (arraysEqual(cache, elements)) return;
12551                         mat3array.set(elements);
12552                         gl.uniformMatrix3fv(this.addr, false, mat3array);
12553                         copyArray(cache, elements);
12554                 }
12555         }
12556
12557         function setValueM4(gl, v) {
12558                 var cache = this.cache;
12559                 var elements = v.elements;
12560
12561                 if (elements === undefined) {
12562                         if (arraysEqual(cache, v)) return;
12563                         gl.uniformMatrix4fv(this.addr, false, v);
12564                         copyArray(cache, v);
12565                 } else {
12566                         if (arraysEqual(cache, elements)) return;
12567                         mat4array.set(elements);
12568                         gl.uniformMatrix4fv(this.addr, false, mat4array);
12569                         copyArray(cache, elements);
12570                 }
12571         } // Single texture (2D / Cube)
12572
12573
12574         function setValueT1(gl, v, textures) {
12575                 var cache = this.cache;
12576                 var unit = textures.allocateTextureUnit();
12577
12578                 if (cache[0] !== unit) {
12579                         gl.uniform1i(this.addr, unit);
12580                         cache[0] = unit;
12581                 }
12582
12583                 textures.safeSetTexture2D(v || emptyTexture, unit);
12584         }
12585
12586         function setValueT2DArray1(gl, v, textures) {
12587                 var cache = this.cache;
12588                 var unit = textures.allocateTextureUnit();
12589
12590                 if (cache[0] !== unit) {
12591                         gl.uniform1i(this.addr, unit);
12592                         cache[0] = unit;
12593                 }
12594
12595                 textures.setTexture2DArray(v || emptyTexture2dArray, unit);
12596         }
12597
12598         function setValueT3D1(gl, v, textures) {
12599                 var cache = this.cache;
12600                 var unit = textures.allocateTextureUnit();
12601
12602                 if (cache[0] !== unit) {
12603                         gl.uniform1i(this.addr, unit);
12604                         cache[0] = unit;
12605                 }
12606
12607                 textures.setTexture3D(v || emptyTexture3d, unit);
12608         }
12609
12610         function setValueT6(gl, v, textures) {
12611                 var cache = this.cache;
12612                 var unit = textures.allocateTextureUnit();
12613
12614                 if (cache[0] !== unit) {
12615                         gl.uniform1i(this.addr, unit);
12616                         cache[0] = unit;
12617                 }
12618
12619                 textures.safeSetTextureCube(v || emptyCubeTexture, unit);
12620         } // Integer / Boolean vectors or arrays thereof (always flat arrays)
12621
12622
12623         function setValueV1i(gl, v) {
12624                 var cache = this.cache;
12625                 if (cache[0] === v) return;
12626                 gl.uniform1i(this.addr, v);
12627                 cache[0] = v;
12628         }
12629
12630         function setValueV2i(gl, v) {
12631                 var cache = this.cache;
12632                 if (arraysEqual(cache, v)) return;
12633                 gl.uniform2iv(this.addr, v);
12634                 copyArray(cache, v);
12635         }
12636
12637         function setValueV3i(gl, v) {
12638                 var cache = this.cache;
12639                 if (arraysEqual(cache, v)) return;
12640                 gl.uniform3iv(this.addr, v);
12641                 copyArray(cache, v);
12642         }
12643
12644         function setValueV4i(gl, v) {
12645                 var cache = this.cache;
12646                 if (arraysEqual(cache, v)) return;
12647                 gl.uniform4iv(this.addr, v);
12648                 copyArray(cache, v);
12649         } // uint
12650
12651
12652         function setValueV1ui(gl, v) {
12653                 var cache = this.cache;
12654                 if (cache[0] === v) return;
12655                 gl.uniform1ui(this.addr, v);
12656                 cache[0] = v;
12657         } // Helper to pick the right setter for the singular case
12658
12659
12660         function getSingularSetter(type) {
12661                 switch (type) {
12662                         case 0x1406:
12663                                 return setValueV1f;
12664                         // FLOAT
12665
12666                         case 0x8b50:
12667                                 return setValueV2f;
12668                         // _VEC2
12669
12670                         case 0x8b51:
12671                                 return setValueV3f;
12672                         // _VEC3
12673
12674                         case 0x8b52:
12675                                 return setValueV4f;
12676                         // _VEC4
12677
12678                         case 0x8b5a:
12679                                 return setValueM2;
12680                         // _MAT2
12681
12682                         case 0x8b5b:
12683                                 return setValueM3;
12684                         // _MAT3
12685
12686                         case 0x8b5c:
12687                                 return setValueM4;
12688                         // _MAT4
12689
12690                         case 0x1404:
12691                         case 0x8b56:
12692                                 return setValueV1i;
12693                         // INT, BOOL
12694
12695                         case 0x8b53:
12696                         case 0x8b57:
12697                                 return setValueV2i;
12698                         // _VEC2
12699
12700                         case 0x8b54:
12701                         case 0x8b58:
12702                                 return setValueV3i;
12703                         // _VEC3
12704
12705                         case 0x8b55:
12706                         case 0x8b59:
12707                                 return setValueV4i;
12708                         // _VEC4
12709
12710                         case 0x1405:
12711                                 return setValueV1ui;
12712                         // UINT
12713
12714                         case 0x8b5e: // SAMPLER_2D
12715
12716                         case 0x8d66: // SAMPLER_EXTERNAL_OES
12717
12718                         case 0x8dca: // INT_SAMPLER_2D
12719
12720                         case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
12721
12722                         case 0x8b62:
12723                                 // SAMPLER_2D_SHADOW
12724                                 return setValueT1;
12725
12726                         case 0x8b5f: // SAMPLER_3D
12727
12728                         case 0x8dcb: // INT_SAMPLER_3D
12729
12730                         case 0x8dd3:
12731                                 // UNSIGNED_INT_SAMPLER_3D
12732                                 return setValueT3D1;
12733
12734                         case 0x8b60: // SAMPLER_CUBE
12735
12736                         case 0x8dcc: // INT_SAMPLER_CUBE
12737
12738                         case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
12739
12740                         case 0x8dc5:
12741                                 // SAMPLER_CUBE_SHADOW
12742                                 return setValueT6;
12743
12744                         case 0x8dc1: // SAMPLER_2D_ARRAY
12745
12746                         case 0x8dcf: // INT_SAMPLER_2D_ARRAY
12747
12748                         case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
12749
12750                         case 0x8dc4:
12751                                 // SAMPLER_2D_ARRAY_SHADOW
12752                                 return setValueT2DArray1;
12753                 }
12754         } // Array of scalars
12755
12756
12757         function setValueV1fArray(gl, v) {
12758                 gl.uniform1fv(this.addr, v);
12759         } // Integer / Boolean vectors or arrays thereof (always flat arrays)
12760
12761
12762         function setValueV1iArray(gl, v) {
12763                 gl.uniform1iv(this.addr, v);
12764         }
12765
12766         function setValueV2iArray(gl, v) {
12767                 gl.uniform2iv(this.addr, v);
12768         }
12769
12770         function setValueV3iArray(gl, v) {
12771                 gl.uniform3iv(this.addr, v);
12772         }
12773
12774         function setValueV4iArray(gl, v) {
12775                 gl.uniform4iv(this.addr, v);
12776         } // Array of vectors (flat or from THREE classes)
12777
12778
12779         function setValueV2fArray(gl, v) {
12780                 var data = flatten(v, this.size, 2);
12781                 gl.uniform2fv(this.addr, data);
12782         }
12783
12784         function setValueV3fArray(gl, v) {
12785                 var data = flatten(v, this.size, 3);
12786                 gl.uniform3fv(this.addr, data);
12787         }
12788
12789         function setValueV4fArray(gl, v) {
12790                 var data = flatten(v, this.size, 4);
12791                 gl.uniform4fv(this.addr, data);
12792         } // Array of matrices (flat or from THREE clases)
12793
12794
12795         function setValueM2Array(gl, v) {
12796                 var data = flatten(v, this.size, 4);
12797                 gl.uniformMatrix2fv(this.addr, false, data);
12798         }
12799
12800         function setValueM3Array(gl, v) {
12801                 var data = flatten(v, this.size, 9);
12802                 gl.uniformMatrix3fv(this.addr, false, data);
12803         }
12804
12805         function setValueM4Array(gl, v) {
12806                 var data = flatten(v, this.size, 16);
12807                 gl.uniformMatrix4fv(this.addr, false, data);
12808         } // Array of textures (2D / Cube)
12809
12810
12811         function setValueT1Array(gl, v, textures) {
12812                 var n = v.length;
12813                 var units = allocTexUnits(textures, n);
12814                 gl.uniform1iv(this.addr, units);
12815
12816                 for (var i = 0; i !== n; ++i) {
12817                         textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
12818                 }
12819         }
12820
12821         function setValueT6Array(gl, v, textures) {
12822                 var n = v.length;
12823                 var units = allocTexUnits(textures, n);
12824                 gl.uniform1iv(this.addr, units);
12825
12826                 for (var i = 0; i !== n; ++i) {
12827                         textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
12828                 }
12829         } // Helper to pick the right setter for a pure (bottom-level) array
12830
12831
12832         function getPureArraySetter(type) {
12833                 switch (type) {
12834                         case 0x1406:
12835                                 return setValueV1fArray;
12836                         // FLOAT
12837
12838                         case 0x8b50:
12839                                 return setValueV2fArray;
12840                         // _VEC2
12841
12842                         case 0x8b51:
12843                                 return setValueV3fArray;
12844                         // _VEC3
12845
12846                         case 0x8b52:
12847                                 return setValueV4fArray;
12848                         // _VEC4
12849
12850                         case 0x8b5a:
12851                                 return setValueM2Array;
12852                         // _MAT2
12853
12854                         case 0x8b5b:
12855                                 return setValueM3Array;
12856                         // _MAT3
12857
12858                         case 0x8b5c:
12859                                 return setValueM4Array;
12860                         // _MAT4
12861
12862                         case 0x1404:
12863                         case 0x8b56:
12864                                 return setValueV1iArray;
12865                         // INT, BOOL
12866
12867                         case 0x8b53:
12868                         case 0x8b57:
12869                                 return setValueV2iArray;
12870                         // _VEC2
12871
12872                         case 0x8b54:
12873                         case 0x8b58:
12874                                 return setValueV3iArray;
12875                         // _VEC3
12876
12877                         case 0x8b55:
12878                         case 0x8b59:
12879                                 return setValueV4iArray;
12880                         // _VEC4
12881
12882                         case 0x8b5e: // SAMPLER_2D
12883
12884                         case 0x8d66: // SAMPLER_EXTERNAL_OES
12885
12886                         case 0x8dca: // INT_SAMPLER_2D
12887
12888                         case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
12889
12890                         case 0x8b62:
12891                                 // SAMPLER_2D_SHADOW
12892                                 return setValueT1Array;
12893
12894                         case 0x8b60: // SAMPLER_CUBE
12895
12896                         case 0x8dcc: // INT_SAMPLER_CUBE
12897
12898                         case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
12899
12900                         case 0x8dc5:
12901                                 // SAMPLER_CUBE_SHADOW
12902                                 return setValueT6Array;
12903                 }
12904         } // --- Uniform Classes ---
12905
12906
12907         function SingleUniform(id, activeInfo, addr) {
12908                 this.id = id;
12909                 this.addr = addr;
12910                 this.cache = [];
12911                 this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
12912         }
12913
12914         function PureArrayUniform(id, activeInfo, addr) {
12915                 this.id = id;
12916                 this.addr = addr;
12917                 this.cache = [];
12918                 this.size = activeInfo.size;
12919                 this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
12920         }
12921
12922         PureArrayUniform.prototype.updateCache = function (data) {
12923                 var cache = this.cache;
12924
12925                 if (data instanceof Float32Array && cache.length !== data.length) {
12926                         this.cache = new Float32Array(data.length);
12927                 }
12928
12929                 copyArray(cache, data);
12930         };
12931
12932         function StructuredUniform(id) {
12933                 this.id = id;
12934                 this.seq = [];
12935                 this.map = {};
12936         }
12937
12938         StructuredUniform.prototype.setValue = function (gl, value, textures) {
12939                 var seq = this.seq;
12940
12941                 for (var i = 0, n = seq.length; i !== n; ++i) {
12942                         var u = seq[i];
12943                         u.setValue(gl, value[u.id], textures);
12944                 }
12945         }; // --- Top-level ---
12946         // Parser - builds up the property tree from the path strings
12947
12948
12949         var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
12950         //      - the identifier (member name or array index)
12951         //      - followed by an optional right bracket (found when array index)
12952         //      - followed by an optional left bracket or dot (type of subscript)
12953         //
12954         // Note: These portions can be read in a non-overlapping fashion and
12955         // allow straightforward parsing of the hierarchy that WebGL encodes
12956         // in the uniform names.
12957
12958         function addUniform(container, uniformObject) {
12959                 container.seq.push(uniformObject);
12960                 container.map[uniformObject.id] = uniformObject;
12961         }
12962
12963         function parseUniform(activeInfo, addr, container) {
12964                 var path = activeInfo.name,
12965                                 pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
12966
12967                 RePathPart.lastIndex = 0;
12968
12969                 while (true) {
12970                         var match = RePathPart.exec(path),
12971                                         matchEnd = RePathPart.lastIndex;
12972                         var id = match[1];
12973                         var idIsIndex = match[2] === ']',
12974                                         subscript = match[3];
12975                         if (idIsIndex) id = id | 0; // convert to integer
12976
12977                         if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
12978                                 // bare name or "pure" bottom-level array "[0]" suffix
12979                                 addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
12980                                 break;
12981                         } else {
12982                                 // step into inner node / create it in case it doesn't exist
12983                                 var map = container.map;
12984                                 var next = map[id];
12985
12986                                 if (next === undefined) {
12987                                         next = new StructuredUniform(id);
12988                                         addUniform(container, next);
12989                                 }
12990
12991                                 container = next;
12992                         }
12993                 }
12994         } // Root Container
12995
12996
12997         function WebGLUniforms(gl, program) {
12998                 this.seq = [];
12999                 this.map = {};
13000                 var n = gl.getProgramParameter(program, 35718);
13001
13002                 for (var i = 0; i < n; ++i) {
13003                         var info = gl.getActiveUniform(program, i),
13004                                         addr = gl.getUniformLocation(program, info.name);
13005                         parseUniform(info, addr, this);
13006                 }
13007         }
13008
13009         WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
13010                 var u = this.map[name];
13011                 if (u !== undefined) u.setValue(gl, value, textures);
13012         };
13013
13014         WebGLUniforms.prototype.setOptional = function (gl, object, name) {
13015                 var v = object[name];
13016                 if (v !== undefined) this.setValue(gl, name, v);
13017         }; // Static interface
13018
13019
13020         WebGLUniforms.upload = function (gl, seq, values, textures) {
13021                 for (var i = 0, n = seq.length; i !== n; ++i) {
13022                         var u = seq[i],
13023                                         v = values[u.id];
13024
13025                         if (v.needsUpdate !== false) {
13026                                 // note: always updating when .needsUpdate is undefined
13027                                 u.setValue(gl, v.value, textures);
13028                         }
13029                 }
13030         };
13031
13032         WebGLUniforms.seqWithValue = function (seq, values) {
13033                 var r = [];
13034
13035                 for (var i = 0, n = seq.length; i !== n; ++i) {
13036                         var u = seq[i];
13037                         if (u.id in values) r.push(u);
13038                 }
13039
13040                 return r;
13041         };
13042
13043         function WebGLShader(gl, type, string) {
13044                 var shader = gl.createShader(type);
13045                 gl.shaderSource(shader, string);
13046                 gl.compileShader(shader);
13047                 return shader;
13048         }
13049
13050         var programIdCount = 0;
13051
13052         function addLineNumbers(string) {
13053                 var lines = string.split('\n');
13054
13055                 for (var i = 0; i < lines.length; i++) {
13056                         lines[i] = i + 1 + ': ' + lines[i];
13057                 }
13058
13059                 return lines.join('\n');
13060         }
13061
13062         function getEncodingComponents(encoding) {
13063                 switch (encoding) {
13064                         case LinearEncoding:
13065                                 return ['Linear', '( value )'];
13066
13067                         case sRGBEncoding:
13068                                 return ['sRGB', '( value )'];
13069
13070                         case RGBEEncoding:
13071                                 return ['RGBE', '( value )'];
13072
13073                         case RGBM7Encoding:
13074                                 return ['RGBM', '( value, 7.0 )'];
13075
13076                         case RGBM16Encoding:
13077                                 return ['RGBM', '( value, 16.0 )'];
13078
13079                         case RGBDEncoding:
13080                                 return ['RGBD', '( value, 256.0 )'];
13081
13082                         case GammaEncoding:
13083                                 return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
13084
13085                         case LogLuvEncoding:
13086                                 return ['LogLuv', '( value )'];
13087
13088                         default:
13089                                 console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
13090                                 return ['Linear', '( value )'];
13091                 }
13092         }
13093
13094         function getShaderErrors(gl, shader, type) {
13095                 var status = gl.getShaderParameter(shader, 35713);
13096                 var log = gl.getShaderInfoLog(shader).trim();
13097                 if (status && log === '') return ''; // --enable-privileged-webgl-extension
13098                 // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
13099
13100                 var source = gl.getShaderSource(shader);
13101                 return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
13102         }
13103
13104         function getTexelDecodingFunction(functionName, encoding) {
13105                 var components = getEncodingComponents(encoding);
13106                 return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
13107         }
13108
13109         function getTexelEncodingFunction(functionName, encoding) {
13110                 var components = getEncodingComponents(encoding);
13111                 return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
13112         }
13113
13114         function getToneMappingFunction(functionName, toneMapping) {
13115                 var toneMappingName;
13116
13117                 switch (toneMapping) {
13118                         case LinearToneMapping:
13119                                 toneMappingName = 'Linear';
13120                                 break;
13121
13122                         case ReinhardToneMapping:
13123                                 toneMappingName = 'Reinhard';
13124                                 break;
13125
13126                         case CineonToneMapping:
13127                                 toneMappingName = 'OptimizedCineon';
13128                                 break;
13129
13130                         case ACESFilmicToneMapping:
13131                                 toneMappingName = 'ACESFilmic';
13132                                 break;
13133
13134                         case CustomToneMapping:
13135                                 toneMappingName = 'Custom';
13136                                 break;
13137
13138                         default:
13139                                 console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
13140                                 toneMappingName = 'Linear';
13141                 }
13142
13143                 return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
13144         }
13145
13146         function generateExtensions(parameters) {
13147                 var chunks = [parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ? '#extension GL_OES_standard_derivatives : enable' : '', (parameters.extensionFragDepth || parameters.logarithmicDepthBuffer) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '', parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ? '#extension GL_EXT_draw_buffers : require' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''];
13148                 return chunks.filter(filterEmptyLine).join('\n');
13149         }
13150
13151         function generateDefines(defines) {
13152                 var chunks = [];
13153
13154                 for (var name in defines) {
13155                         var value = defines[name];
13156                         if (value === false) continue;
13157                         chunks.push('#define ' + name + ' ' + value);
13158                 }
13159
13160                 return chunks.join('\n');
13161         }
13162
13163         function fetchAttributeLocations(gl, program) {
13164                 var attributes = {};
13165                 var n = gl.getProgramParameter(program, 35721);
13166
13167                 for (var i = 0; i < n; i++) {
13168                         var info = gl.getActiveAttrib(program, i);
13169                         var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
13170
13171                         attributes[name] = gl.getAttribLocation(program, name);
13172                 }
13173
13174                 return attributes;
13175         }
13176
13177         function filterEmptyLine(string) {
13178                 return string !== '';
13179         }
13180
13181         function replaceLightNums(string, parameters) {
13182                 return string.replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g, parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows);
13183         }
13184
13185         function replaceClippingPlaneNums(string, parameters) {
13186                 return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
13187         } // Resolve Includes
13188
13189
13190         var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
13191
13192         function resolveIncludes(string) {
13193                 return string.replace(includePattern, includeReplacer);
13194         }
13195
13196         function includeReplacer(match, include) {
13197                 var string = ShaderChunk[include];
13198
13199                 if (string === undefined) {
13200                         throw new Error('Can not resolve #include <' + include + '>');
13201                 }
13202
13203                 return resolveIncludes(string);
13204         } // Unroll Loops
13205
13206
13207         var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
13208         var unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;
13209
13210         function unrollLoops(string) {
13211                 return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
13212         }
13213
13214         function deprecatedLoopReplacer(match, start, end, snippet) {
13215                 console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
13216                 return loopReplacer(match, start, end, snippet);
13217         }
13218
13219         function loopReplacer(match, start, end, snippet) {
13220                 var string = '';
13221
13222                 for (var i = parseInt(start); i < parseInt(end); i++) {
13223                         string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
13224                 }
13225
13226                 return string;
13227         } //
13228
13229
13230         function generatePrecision(parameters) {
13231                 var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
13232
13233                 if (parameters.precision === "highp") {
13234                         precisionstring += "\n#define HIGH_PRECISION";
13235                 } else if (parameters.precision === "mediump") {
13236                         precisionstring += "\n#define MEDIUM_PRECISION";
13237                 } else if (parameters.precision === "lowp") {
13238                         precisionstring += "\n#define LOW_PRECISION";
13239                 }
13240
13241                 return precisionstring;
13242         }
13243
13244         function generateShadowMapTypeDefine(parameters) {
13245                 var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
13246
13247                 if (parameters.shadowMapType === PCFShadowMap) {
13248                         shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
13249                 } else if (parameters.shadowMapType === PCFSoftShadowMap) {
13250                         shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
13251                 } else if (parameters.shadowMapType === VSMShadowMap) {
13252                         shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
13253                 }
13254
13255                 return shadowMapTypeDefine;
13256         }
13257
13258         function generateEnvMapTypeDefine(parameters) {
13259                 var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
13260
13261                 if (parameters.envMap) {
13262                         switch (parameters.envMapMode) {
13263                                 case CubeReflectionMapping:
13264                                 case CubeRefractionMapping:
13265                                         envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
13266                                         break;
13267
13268                                 case CubeUVReflectionMapping:
13269                                 case CubeUVRefractionMapping:
13270                                         envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
13271                                         break;
13272                         }
13273                 }
13274
13275                 return envMapTypeDefine;
13276         }
13277
13278         function generateEnvMapModeDefine(parameters) {
13279                 var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
13280
13281                 if (parameters.envMap) {
13282                         switch (parameters.envMapMode) {
13283                                 case CubeRefractionMapping:
13284                                 case CubeUVRefractionMapping:
13285                                         envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
13286                                         break;
13287                         }
13288                 }
13289
13290                 return envMapModeDefine;
13291         }
13292
13293         function generateEnvMapBlendingDefine(parameters) {
13294                 var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
13295
13296                 if (parameters.envMap) {
13297                         switch (parameters.combine) {
13298                                 case MultiplyOperation:
13299                                         envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
13300                                         break;
13301
13302                                 case MixOperation:
13303                                         envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
13304                                         break;
13305
13306                                 case AddOperation:
13307                                         envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
13308                                         break;
13309                         }
13310                 }
13311
13312                 return envMapBlendingDefine;
13313         }
13314
13315         function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
13316                 var gl = renderer.getContext();
13317                 var defines = parameters.defines;
13318                 var vertexShader = parameters.vertexShader;
13319                 var fragmentShader = parameters.fragmentShader;
13320                 var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
13321                 var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
13322                 var envMapModeDefine = generateEnvMapModeDefine(parameters);
13323                 var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
13324                 var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
13325                 var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
13326                 var customDefines = generateDefines(defines);
13327                 var program = gl.createProgram();
13328                 var prefixVertex, prefixFragment;
13329                 var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
13330
13331                 if (parameters.isRawShaderMaterial) {
13332                         prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
13333
13334                         if (prefixVertex.length > 0) {
13335                                 prefixVertex += '\n';
13336                         }
13337
13338                         prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
13339
13340                         if (prefixFragment.length > 0) {
13341                                 prefixFragment += '\n';
13342                         }
13343                 } else {
13344                         prefixVertex = [generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.instancing ? '#define USE_INSTANCING' : '', parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '', parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '', '#define GAMMA_FACTOR ' + gammaFactorDefine, '#define MAX_BONES ' + parameters.maxBones, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors ? '#define USE_COLOR' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.skinning ? '#define USE_SKINNING' : '', parameters.useVertexTexture ? '#define BONE_TEXTURE' : '', parameters.morphTargets ? '#define USE_MORPHTARGETS' : '', parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', 'uniform mat4 modelMatrix;', 'uniform mat4 modelViewMatrix;', 'uniform mat4 projectionMatrix;', 'uniform mat4 viewMatrix;', 'uniform mat3 normalMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', '#ifdef USE_INSTANCING', '   attribute mat4 instanceMatrix;', '#endif', '#ifdef USE_INSTANCING_COLOR', '     attribute vec3 instanceColor;', '#endif', 'attribute vec3 position;', 'attribute vec3 normal;', 'attribute vec2 uv;', '#ifdef USE_TANGENT', '   attribute vec4 tangent;', '#endif', '#ifdef USE_COLOR', '       attribute vec3 color;', '#endif', '#ifdef USE_MORPHTARGETS', '  attribute vec3 morphTarget0;', '        attribute vec3 morphTarget1;', '        attribute vec3 morphTarget2;', '        attribute vec3 morphTarget3;', '        #ifdef USE_MORPHNORMALS', '             attribute vec3 morphNormal0;', '                attribute vec3 morphNormal1;', '                attribute vec3 morphNormal2;', '                attribute vec3 morphNormal3;', '        #else', '               attribute vec3 morphTarget4;', '                attribute vec3 morphTarget5;', '                attribute vec3 morphTarget6;', '                attribute vec3 morphTarget7;', '        #endif', '#endif', '#ifdef USE_SKINNING', '     attribute vec4 skinIndex;', '   attribute vec4 skinWeight;', '#endif', '\n'].filter(filterEmptyLine).join('\n');
13345                         prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
13346                         '#define GAMMA_FACTOR ' + gammaFactorDefine, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.matcap ? '#define USE_MATCAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapTypeDefine : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.envMap ? '#define ' + envMapBlendingDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.sheen ? '#define USE_SHEEN' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.gradientMap ? '#define USE_GRADIENTMAP' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '', parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#define TEXTURE_LOD_EXT' : '', 'uniform mat4 viewMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', parameters.toneMapping !== NoToneMapping ? '#define TONE_MAPPING' : '', parameters.toneMapping !== NoToneMapping ? ShaderChunk['tonemapping_pars_fragment'] : '', // this code is required here because it is used by the toneMapping() function defined below
13347                         parameters.toneMapping !== NoToneMapping ? getToneMappingFunction('toneMapping', parameters.toneMapping) : '', parameters.dithering ? '#define DITHERING' : '', ShaderChunk['encodings_pars_fragment'], // this code is required here because it is used by the various encoding/decoding function defined below
13348                         parameters.map ? getTexelDecodingFunction('mapTexelToLinear', parameters.mapEncoding) : '', parameters.matcap ? getTexelDecodingFunction('matcapTexelToLinear', parameters.matcapEncoding) : '', parameters.envMap ? getTexelDecodingFunction('envMapTexelToLinear', parameters.envMapEncoding) : '', parameters.emissiveMap ? getTexelDecodingFunction('emissiveMapTexelToLinear', parameters.emissiveMapEncoding) : '', parameters.lightMap ? getTexelDecodingFunction('lightMapTexelToLinear', parameters.lightMapEncoding) : '', getTexelEncodingFunction('linearToOutputTexel', parameters.outputEncoding), parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '', '\n'].filter(filterEmptyLine).join('\n');
13349                 }
13350
13351                 vertexShader = resolveIncludes(vertexShader);
13352                 vertexShader = replaceLightNums(vertexShader, parameters);
13353                 vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
13354                 fragmentShader = resolveIncludes(fragmentShader);
13355                 fragmentShader = replaceLightNums(fragmentShader, parameters);
13356                 fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
13357                 vertexShader = unrollLoops(vertexShader);
13358                 fragmentShader = unrollLoops(fragmentShader);
13359
13360                 if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
13361                         // GLSL 3.0 conversion for built-in materials and ShaderMaterial
13362                         versionString = '#version 300 es\n';
13363                         prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
13364                         prefixFragment = ['#define varying in', parameters.glslVersion === GLSL3 ? '' : 'out highp vec4 pc_fragColor;', parameters.glslVersion === GLSL3 ? '' : '#define gl_FragColor pc_fragColor', '#define gl_FragDepthEXT gl_FragDepth', '#define texture2D texture', '#define textureCube texture', '#define texture2DProj textureProj', '#define texture2DLodEXT textureLod', '#define texture2DProjLodEXT textureProjLod', '#define textureCubeLodEXT textureLod', '#define texture2DGradEXT textureGrad', '#define texture2DProjGradEXT textureProjGrad', '#define textureCubeGradEXT textureGrad'].join('\n') + '\n' + prefixFragment;
13365                 }
13366
13367                 var vertexGlsl = versionString + prefixVertex + vertexShader;
13368                 var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
13369                 // console.log( '*FRAGMENT*', fragmentGlsl );
13370
13371                 var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
13372                 var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
13373                 gl.attachShader(program, glVertexShader);
13374                 gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
13375
13376                 if (parameters.index0AttributeName !== undefined) {
13377                         gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
13378                 } else if (parameters.morphTargets === true) {
13379                         // programs with morphTargets displace position out of attribute 0
13380                         gl.bindAttribLocation(program, 0, 'position');
13381                 }
13382
13383                 gl.linkProgram(program); // check for link errors
13384
13385                 if (renderer.debug.checkShaderErrors) {
13386                         var programLog = gl.getProgramInfoLog(program).trim();
13387                         var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
13388                         var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
13389                         var runnable = true;
13390                         var haveDiagnostics = true;
13391
13392                         if (gl.getProgramParameter(program, 35714) === false) {
13393                                 runnable = false;
13394                                 var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
13395                                 var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
13396                                 console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
13397                         } else if (programLog !== '') {
13398                                 console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
13399                         } else if (vertexLog === '' || fragmentLog === '') {
13400                                 haveDiagnostics = false;
13401                         }
13402
13403                         if (haveDiagnostics) {
13404                                 this.diagnostics = {
13405                                         runnable: runnable,
13406                                         programLog: programLog,
13407                                         vertexShader: {
13408                                                 log: vertexLog,
13409                                                 prefix: prefixVertex
13410                                         },
13411                                         fragmentShader: {
13412                                                 log: fragmentLog,
13413                                                 prefix: prefixFragment
13414                                         }
13415                                 };
13416                         }
13417                 } // Clean up
13418                 // Crashes in iOS9 and iOS10. #18402
13419                 // gl.detachShader( program, glVertexShader );
13420                 // gl.detachShader( program, glFragmentShader );
13421
13422
13423                 gl.deleteShader(glVertexShader);
13424                 gl.deleteShader(glFragmentShader); // set up caching for uniform locations
13425
13426                 var cachedUniforms;
13427
13428                 this.getUniforms = function () {
13429                         if (cachedUniforms === undefined) {
13430                                 cachedUniforms = new WebGLUniforms(gl, program);
13431                         }
13432
13433                         return cachedUniforms;
13434                 }; // set up caching for attribute locations
13435
13436
13437                 var cachedAttributes;
13438
13439                 this.getAttributes = function () {
13440                         if (cachedAttributes === undefined) {
13441                                 cachedAttributes = fetchAttributeLocations(gl, program);
13442                         }
13443
13444                         return cachedAttributes;
13445                 }; // free resource
13446
13447
13448                 this.destroy = function () {
13449                         bindingStates.releaseStatesOfProgram(this);
13450                         gl.deleteProgram(program);
13451                         this.program = undefined;
13452                 }; //
13453
13454
13455                 this.name = parameters.shaderName;
13456                 this.id = programIdCount++;
13457                 this.cacheKey = cacheKey;
13458                 this.usedTimes = 1;
13459                 this.program = program;
13460                 this.vertexShader = glVertexShader;
13461                 this.fragmentShader = glFragmentShader;
13462                 return this;
13463         }
13464
13465         function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
13466                 var programs = [];
13467                 var isWebGL2 = capabilities.isWebGL2;
13468                 var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
13469                 var floatVertexTextures = capabilities.floatVertexTextures;
13470                 var maxVertexUniforms = capabilities.maxVertexUniforms;
13471                 var vertexTextures = capabilities.vertexTextures;
13472                 var precision = capabilities.precision;
13473                 var shaderIDs = {
13474                         MeshDepthMaterial: 'depth',
13475                         MeshDistanceMaterial: 'distanceRGBA',
13476                         MeshNormalMaterial: 'normal',
13477                         MeshBasicMaterial: 'basic',
13478                         MeshLambertMaterial: 'lambert',
13479                         MeshPhongMaterial: 'phong',
13480                         MeshToonMaterial: 'toon',
13481                         MeshStandardMaterial: 'physical',
13482                         MeshPhysicalMaterial: 'physical',
13483                         MeshMatcapMaterial: 'matcap',
13484                         LineBasicMaterial: 'basic',
13485                         LineDashedMaterial: 'dashed',
13486                         PointsMaterial: 'points',
13487                         ShadowMaterial: 'shadow',
13488                         SpriteMaterial: 'sprite'
13489                 };
13490                 var parameterNames = ["precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing", "instancingColor", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding", "envMapCubeUV", "lightMap", "lightMapEncoding", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "tangentSpaceNormalMap", "clearcoatMap", "clearcoatRoughnessMap", "clearcoatNormalMap", "displacementMap", "specularMap", "roughnessMap", "metalnessMap", "gradientMap", "alphaMap", "combine", "vertexColors", "vertexTangents", "vertexUvs", "uvsVertexOnly", "fog", "useFog", "fogExp2", "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning", "maxBones", "useVertexTexture", "morphTargets", "morphNormals", "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha", "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights", "numDirLightShadows", "numPointLightShadows", "numSpotLightShadows", "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights', "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering", "sheen", "transmissionMap"];
13491
13492                 function getMaxBones(object) {
13493                         var skeleton = object.skeleton;
13494                         var bones = skeleton.bones;
13495
13496                         if (floatVertexTextures) {
13497                                 return 1024;
13498                         } else {
13499                                 // default for when object is not specified
13500                                 // ( for example when prebuilding shader to be used with multiple objects )
13501                                 //
13502                                 //      - leave some extra space for other uniforms
13503                                 //      - limit here is ANGLE's 254 max uniform vectors
13504                                 //              (up to 54 should be safe)
13505                                 var nVertexUniforms = maxVertexUniforms;
13506                                 var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
13507                                 var maxBones = Math.min(nVertexMatrices, bones.length);
13508
13509                                 if (maxBones < bones.length) {
13510                                         console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
13511                                         return 0;
13512                                 }
13513
13514                                 return maxBones;
13515                         }
13516                 }
13517
13518                 function getTextureEncodingFromMap(map) {
13519                         var encoding;
13520
13521                         if (!map) {
13522                                 encoding = LinearEncoding;
13523                         } else if (map.isTexture) {
13524                                 encoding = map.encoding;
13525                         } else if (map.isWebGLRenderTarget) {
13526                                 console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
13527                                 encoding = map.texture.encoding;
13528                         }
13529
13530                         return encoding;
13531                 }
13532
13533                 function getParameters(material, lights, shadows, scene, object) {
13534                         var fog = scene.fog;
13535                         var environment = material.isMeshStandardMaterial ? scene.environment : null;
13536                         var envMap = cubemaps.get(material.envMap || environment);
13537                         var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
13538                         // (not to blow over maxLights budget)
13539
13540                         var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
13541
13542                         if (material.precision !== null) {
13543                                 precision = capabilities.getMaxPrecision(material.precision);
13544
13545                                 if (precision !== material.precision) {
13546                                         console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
13547                                 }
13548                         }
13549
13550                         var vertexShader, fragmentShader;
13551
13552                         if (shaderID) {
13553                                 var shader = ShaderLib[shaderID];
13554                                 vertexShader = shader.vertexShader;
13555                                 fragmentShader = shader.fragmentShader;
13556                         } else {
13557                                 vertexShader = material.vertexShader;
13558                                 fragmentShader = material.fragmentShader;
13559                         }
13560
13561                         var currentRenderTarget = renderer.getRenderTarget();
13562                         var parameters = {
13563                                 isWebGL2: isWebGL2,
13564                                 shaderID: shaderID,
13565                                 shaderName: material.type,
13566                                 vertexShader: vertexShader,
13567                                 fragmentShader: fragmentShader,
13568                                 defines: material.defines,
13569                                 isRawShaderMaterial: material.isRawShaderMaterial === true,
13570                                 glslVersion: material.glslVersion,
13571                                 precision: precision,
13572                                 instancing: object.isInstancedMesh === true,
13573                                 instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
13574                                 supportsVertexTextures: vertexTextures,
13575                                 outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
13576                                 map: !!material.map,
13577                                 mapEncoding: getTextureEncodingFromMap(material.map),
13578                                 matcap: !!material.matcap,
13579                                 matcapEncoding: getTextureEncodingFromMap(material.matcap),
13580                                 envMap: !!envMap,
13581                                 envMapMode: envMap && envMap.mapping,
13582                                 envMapEncoding: getTextureEncodingFromMap(envMap),
13583                                 envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
13584                                 lightMap: !!material.lightMap,
13585                                 lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
13586                                 aoMap: !!material.aoMap,
13587                                 emissiveMap: !!material.emissiveMap,
13588                                 emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
13589                                 bumpMap: !!material.bumpMap,
13590                                 normalMap: !!material.normalMap,
13591                                 objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
13592                                 tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
13593                                 clearcoatMap: !!material.clearcoatMap,
13594                                 clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
13595                                 clearcoatNormalMap: !!material.clearcoatNormalMap,
13596                                 displacementMap: !!material.displacementMap,
13597                                 roughnessMap: !!material.roughnessMap,
13598                                 metalnessMap: !!material.metalnessMap,
13599                                 specularMap: !!material.specularMap,
13600                                 alphaMap: !!material.alphaMap,
13601                                 gradientMap: !!material.gradientMap,
13602                                 sheen: !!material.sheen,
13603                                 transmissionMap: !!material.transmissionMap,
13604                                 combine: material.combine,
13605                                 vertexTangents: material.normalMap && material.vertexTangents,
13606                                 vertexColors: material.vertexColors,
13607                                 vertexUvs: !!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatMap || !!material.clearcoatRoughnessMap || !!material.clearcoatNormalMap || !!material.displacementMap || !!material.transmissionMap,
13608                                 uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
13609                                 fog: !!fog,
13610                                 useFog: material.fog,
13611                                 fogExp2: fog && fog.isFogExp2,
13612                                 flatShading: material.flatShading,
13613                                 sizeAttenuation: material.sizeAttenuation,
13614                                 logarithmicDepthBuffer: logarithmicDepthBuffer,
13615                                 skinning: material.skinning && maxBones > 0,
13616                                 maxBones: maxBones,
13617                                 useVertexTexture: floatVertexTextures,
13618                                 morphTargets: material.morphTargets,
13619                                 morphNormals: material.morphNormals,
13620                                 maxMorphTargets: renderer.maxMorphTargets,
13621                                 maxMorphNormals: renderer.maxMorphNormals,
13622                                 numDirLights: lights.directional.length,
13623                                 numPointLights: lights.point.length,
13624                                 numSpotLights: lights.spot.length,
13625                                 numRectAreaLights: lights.rectArea.length,
13626                                 numHemiLights: lights.hemi.length,
13627                                 numDirLightShadows: lights.directionalShadowMap.length,
13628                                 numPointLightShadows: lights.pointShadowMap.length,
13629                                 numSpotLightShadows: lights.spotShadowMap.length,
13630                                 numClippingPlanes: clipping.numPlanes,
13631                                 numClipIntersection: clipping.numIntersection,
13632                                 dithering: material.dithering,
13633                                 shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
13634                                 shadowMapType: renderer.shadowMap.type,
13635                                 toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
13636                                 physicallyCorrectLights: renderer.physicallyCorrectLights,
13637                                 premultipliedAlpha: material.premultipliedAlpha,
13638                                 alphaTest: material.alphaTest,
13639                                 doubleSided: material.side === DoubleSide,
13640                                 flipSided: material.side === BackSide,
13641                                 depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
13642                                 index0AttributeName: material.index0AttributeName,
13643                                 extensionDerivatives: material.extensions && material.extensions.derivatives,
13644                                 extensionFragDepth: material.extensions && material.extensions.fragDepth,
13645                                 extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
13646                                 extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
13647                                 rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
13648                                 rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
13649                                 rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
13650                                 customProgramCacheKey: material.customProgramCacheKey()
13651                         };
13652                         return parameters;
13653                 }
13654
13655                 function getProgramCacheKey(parameters) {
13656                         var array = [];
13657
13658                         if (parameters.shaderID) {
13659                                 array.push(parameters.shaderID);
13660                         } else {
13661                                 array.push(parameters.fragmentShader);
13662                                 array.push(parameters.vertexShader);
13663                         }
13664
13665                         if (parameters.defines !== undefined) {
13666                                 for (var name in parameters.defines) {
13667                                         array.push(name);
13668                                         array.push(parameters.defines[name]);
13669                                 }
13670                         }
13671
13672                         if (parameters.isRawShaderMaterial === false) {
13673                                 for (var i = 0; i < parameterNames.length; i++) {
13674                                         array.push(parameters[parameterNames[i]]);
13675                                 }
13676
13677                                 array.push(renderer.outputEncoding);
13678                                 array.push(renderer.gammaFactor);
13679                         }
13680
13681                         array.push(parameters.customProgramCacheKey);
13682                         return array.join();
13683                 }
13684
13685                 function getUniforms(material) {
13686                         var shaderID = shaderIDs[material.type];
13687                         var uniforms;
13688
13689                         if (shaderID) {
13690                                 var shader = ShaderLib[shaderID];
13691                                 uniforms = UniformsUtils.clone(shader.uniforms);
13692                         } else {
13693                                 uniforms = material.uniforms;
13694                         }
13695
13696                         return uniforms;
13697                 }
13698
13699                 function acquireProgram(parameters, cacheKey) {
13700                         var program; // Check if code has been already compiled
13701
13702                         for (var p = 0, pl = programs.length; p < pl; p++) {
13703                                 var preexistingProgram = programs[p];
13704
13705                                 if (preexistingProgram.cacheKey === cacheKey) {
13706                                         program = preexistingProgram;
13707                                         ++program.usedTimes;
13708                                         break;
13709                                 }
13710                         }
13711
13712                         if (program === undefined) {
13713                                 program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
13714                                 programs.push(program);
13715                         }
13716
13717                         return program;
13718                 }
13719
13720                 function releaseProgram(program) {
13721                         if (--program.usedTimes === 0) {
13722                                 // Remove from unordered set
13723                                 var i = programs.indexOf(program);
13724                                 programs[i] = programs[programs.length - 1];
13725                                 programs.pop(); // Free WebGL resources
13726
13727                                 program.destroy();
13728                         }
13729                 }
13730
13731                 return {
13732                         getParameters: getParameters,
13733                         getProgramCacheKey: getProgramCacheKey,
13734                         getUniforms: getUniforms,
13735                         acquireProgram: acquireProgram,
13736                         releaseProgram: releaseProgram,
13737                         // Exposed for resource monitoring & error feedback via renderer.info:
13738                         programs: programs
13739                 };
13740         }
13741
13742         function WebGLProperties() {
13743                 var properties = new WeakMap();
13744
13745                 function get(object) {
13746                         var map = properties.get(object);
13747
13748                         if (map === undefined) {
13749                                 map = {};
13750                                 properties.set(object, map);
13751                         }
13752
13753                         return map;
13754                 }
13755
13756                 function remove(object) {
13757                         properties.delete(object);
13758                 }
13759
13760                 function update(object, key, value) {
13761                         properties.get(object)[key] = value;
13762                 }
13763
13764                 function dispose() {
13765                         properties = new WeakMap();
13766                 }
13767
13768                 return {
13769                         get: get,
13770                         remove: remove,
13771                         update: update,
13772                         dispose: dispose
13773                 };
13774         }
13775
13776         function painterSortStable(a, b) {
13777                 if (a.groupOrder !== b.groupOrder) {
13778                         return a.groupOrder - b.groupOrder;
13779                 } else if (a.renderOrder !== b.renderOrder) {
13780                         return a.renderOrder - b.renderOrder;
13781                 } else if (a.program !== b.program) {
13782                         return a.program.id - b.program.id;
13783                 } else if (a.material.id !== b.material.id) {
13784                         return a.material.id - b.material.id;
13785                 } else if (a.z !== b.z) {
13786                         return a.z - b.z;
13787                 } else {
13788                         return a.id - b.id;
13789                 }
13790         }
13791
13792         function reversePainterSortStable(a, b) {
13793                 if (a.groupOrder !== b.groupOrder) {
13794                         return a.groupOrder - b.groupOrder;
13795                 } else if (a.renderOrder !== b.renderOrder) {
13796                         return a.renderOrder - b.renderOrder;
13797                 } else if (a.z !== b.z) {
13798                         return b.z - a.z;
13799                 } else {
13800                         return a.id - b.id;
13801                 }
13802         }
13803
13804         function WebGLRenderList(properties) {
13805                 var renderItems = [];
13806                 var renderItemsIndex = 0;
13807                 var opaque = [];
13808                 var transparent = [];
13809                 var defaultProgram = {
13810                         id: -1
13811                 };
13812
13813                 function init() {
13814                         renderItemsIndex = 0;
13815                         opaque.length = 0;
13816                         transparent.length = 0;
13817                 }
13818
13819                 function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
13820                         var renderItem = renderItems[renderItemsIndex];
13821                         var materialProperties = properties.get(material);
13822
13823                         if (renderItem === undefined) {
13824                                 renderItem = {
13825                                         id: object.id,
13826                                         object: object,
13827                                         geometry: geometry,
13828                                         material: material,
13829                                         program: materialProperties.program || defaultProgram,
13830                                         groupOrder: groupOrder,
13831                                         renderOrder: object.renderOrder,
13832                                         z: z,
13833                                         group: group
13834                                 };
13835                                 renderItems[renderItemsIndex] = renderItem;
13836                         } else {
13837                                 renderItem.id = object.id;
13838                                 renderItem.object = object;
13839                                 renderItem.geometry = geometry;
13840                                 renderItem.material = material;
13841                                 renderItem.program = materialProperties.program || defaultProgram;
13842                                 renderItem.groupOrder = groupOrder;
13843                                 renderItem.renderOrder = object.renderOrder;
13844                                 renderItem.z = z;
13845                                 renderItem.group = group;
13846                         }
13847
13848                         renderItemsIndex++;
13849                         return renderItem;
13850                 }
13851
13852                 function push(object, geometry, material, groupOrder, z, group) {
13853                         var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
13854                         (material.transparent === true ? transparent : opaque).push(renderItem);
13855                 }
13856
13857                 function unshift(object, geometry, material, groupOrder, z, group) {
13858                         var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
13859                         (material.transparent === true ? transparent : opaque).unshift(renderItem);
13860                 }
13861
13862                 function sort(customOpaqueSort, customTransparentSort) {
13863                         if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
13864                         if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
13865                 }
13866
13867                 function finish() {
13868                         // Clear references from inactive renderItems in the list
13869                         for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
13870                                 var renderItem = renderItems[i];
13871                                 if (renderItem.id === null) break;
13872                                 renderItem.id = null;
13873                                 renderItem.object = null;
13874                                 renderItem.geometry = null;
13875                                 renderItem.material = null;
13876                                 renderItem.program = null;
13877                                 renderItem.group = null;
13878                         }
13879                 }
13880
13881                 return {
13882                         opaque: opaque,
13883                         transparent: transparent,
13884                         init: init,
13885                         push: push,
13886                         unshift: unshift,
13887                         finish: finish,
13888                         sort: sort
13889                 };
13890         }
13891
13892         function WebGLRenderLists(properties) {
13893                 var lists = new WeakMap();
13894
13895                 function get(scene, camera) {
13896                         var cameras = lists.get(scene);
13897                         var list;
13898
13899                         if (cameras === undefined) {
13900                                 list = new WebGLRenderList(properties);
13901                                 lists.set(scene, new WeakMap());
13902                                 lists.get(scene).set(camera, list);
13903                         } else {
13904                                 list = cameras.get(camera);
13905
13906                                 if (list === undefined) {
13907                                         list = new WebGLRenderList(properties);
13908                                         cameras.set(camera, list);
13909                                 }
13910                         }
13911
13912                         return list;
13913                 }
13914
13915                 function dispose() {
13916                         lists = new WeakMap();
13917                 }
13918
13919                 return {
13920                         get: get,
13921                         dispose: dispose
13922                 };
13923         }
13924
13925         function UniformsCache() {
13926                 var lights = {};
13927                 return {
13928                         get: function get(light) {
13929                                 if (lights[light.id] !== undefined) {
13930                                         return lights[light.id];
13931                                 }
13932
13933                                 var uniforms;
13934
13935                                 switch (light.type) {
13936                                         case 'DirectionalLight':
13937                                                 uniforms = {
13938                                                         direction: new Vector3(),
13939                                                         color: new Color()
13940                                                 };
13941                                                 break;
13942
13943                                         case 'SpotLight':
13944                                                 uniforms = {
13945                                                         position: new Vector3(),
13946                                                         direction: new Vector3(),
13947                                                         color: new Color(),
13948                                                         distance: 0,
13949                                                         coneCos: 0,
13950                                                         penumbraCos: 0,
13951                                                         decay: 0
13952                                                 };
13953                                                 break;
13954
13955                                         case 'PointLight':
13956                                                 uniforms = {
13957                                                         position: new Vector3(),
13958                                                         color: new Color(),
13959                                                         distance: 0,
13960                                                         decay: 0
13961                                                 };
13962                                                 break;
13963
13964                                         case 'HemisphereLight':
13965                                                 uniforms = {
13966                                                         direction: new Vector3(),
13967                                                         skyColor: new Color(),
13968                                                         groundColor: new Color()
13969                                                 };
13970                                                 break;
13971
13972                                         case 'RectAreaLight':
13973                                                 uniforms = {
13974                                                         color: new Color(),
13975                                                         position: new Vector3(),
13976                                                         halfWidth: new Vector3(),
13977                                                         halfHeight: new Vector3()
13978                                                 };
13979                                                 break;
13980                                 }
13981
13982                                 lights[light.id] = uniforms;
13983                                 return uniforms;
13984                         }
13985                 };
13986         }
13987
13988         function ShadowUniformsCache() {
13989                 var lights = {};
13990                 return {
13991                         get: function get(light) {
13992                                 if (lights[light.id] !== undefined) {
13993                                         return lights[light.id];
13994                                 }
13995
13996                                 var uniforms;
13997
13998                                 switch (light.type) {
13999                                         case 'DirectionalLight':
14000                                                 uniforms = {
14001                                                         shadowBias: 0,
14002                                                         shadowNormalBias: 0,
14003                                                         shadowRadius: 1,
14004                                                         shadowMapSize: new Vector2()
14005                                                 };
14006                                                 break;
14007
14008                                         case 'SpotLight':
14009                                                 uniforms = {
14010                                                         shadowBias: 0,
14011                                                         shadowNormalBias: 0,
14012                                                         shadowRadius: 1,
14013                                                         shadowMapSize: new Vector2()
14014                                                 };
14015                                                 break;
14016
14017                                         case 'PointLight':
14018                                                 uniforms = {
14019                                                         shadowBias: 0,
14020                                                         shadowNormalBias: 0,
14021                                                         shadowRadius: 1,
14022                                                         shadowMapSize: new Vector2(),
14023                                                         shadowCameraNear: 1,
14024                                                         shadowCameraFar: 1000
14025                                                 };
14026                                                 break;
14027                                         // TODO (abelnation): set RectAreaLight shadow uniforms
14028                                 }
14029
14030                                 lights[light.id] = uniforms;
14031                                 return uniforms;
14032                         }
14033                 };
14034         }
14035
14036         var nextVersion = 0;
14037
14038         function shadowCastingLightsFirst(lightA, lightB) {
14039                 return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
14040         }
14041
14042         function WebGLLights(extensions, capabilities) {
14043                 var cache = new UniformsCache();
14044                 var shadowCache = ShadowUniformsCache();
14045                 var state = {
14046                         version: 0,
14047                         hash: {
14048                                 directionalLength: -1,
14049                                 pointLength: -1,
14050                                 spotLength: -1,
14051                                 rectAreaLength: -1,
14052                                 hemiLength: -1,
14053                                 numDirectionalShadows: -1,
14054                                 numPointShadows: -1,
14055                                 numSpotShadows: -1
14056                         },
14057                         ambient: [0, 0, 0],
14058                         probe: [],
14059                         directional: [],
14060                         directionalShadow: [],
14061                         directionalShadowMap: [],
14062                         directionalShadowMatrix: [],
14063                         spot: [],
14064                         spotShadow: [],
14065                         spotShadowMap: [],
14066                         spotShadowMatrix: [],
14067                         rectArea: [],
14068                         rectAreaLTC1: null,
14069                         rectAreaLTC2: null,
14070                         point: [],
14071                         pointShadow: [],
14072                         pointShadowMap: [],
14073                         pointShadowMatrix: [],
14074                         hemi: []
14075                 };
14076
14077                 for (var i = 0; i < 9; i++) {
14078                         state.probe.push(new Vector3());
14079                 }
14080
14081                 var vector3 = new Vector3();
14082                 var matrix4 = new Matrix4();
14083                 var matrix42 = new Matrix4();
14084
14085                 function setup(lights, shadows, camera) {
14086                         var r = 0,
14087                                         g = 0,
14088                                         b = 0;
14089
14090                         for (var _i = 0; _i < 9; _i++) {
14091                                 state.probe[_i].set(0, 0, 0);
14092                         }
14093
14094                         var directionalLength = 0;
14095                         var pointLength = 0;
14096                         var spotLength = 0;
14097                         var rectAreaLength = 0;
14098                         var hemiLength = 0;
14099                         var numDirectionalShadows = 0;
14100                         var numPointShadows = 0;
14101                         var numSpotShadows = 0;
14102                         var viewMatrix = camera.matrixWorldInverse;
14103                         lights.sort(shadowCastingLightsFirst);
14104
14105                         for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
14106                                 var light = lights[_i2];
14107                                 var color = light.color;
14108                                 var intensity = light.intensity;
14109                                 var distance = light.distance;
14110                                 var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
14111
14112                                 if (light.isAmbientLight) {
14113                                         r += color.r * intensity;
14114                                         g += color.g * intensity;
14115                                         b += color.b * intensity;
14116                                 } else if (light.isLightProbe) {
14117                                         for (var j = 0; j < 9; j++) {
14118                                                 state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
14119                                         }
14120                                 } else if (light.isDirectionalLight) {
14121                                         var uniforms = cache.get(light);
14122                                         uniforms.color.copy(light.color).multiplyScalar(light.intensity);
14123                                         uniforms.direction.setFromMatrixPosition(light.matrixWorld);
14124                                         vector3.setFromMatrixPosition(light.target.matrixWorld);
14125                                         uniforms.direction.sub(vector3);
14126                                         uniforms.direction.transformDirection(viewMatrix);
14127
14128                                         if (light.castShadow) {
14129                                                 var shadow = light.shadow;
14130                                                 var shadowUniforms = shadowCache.get(light);
14131                                                 shadowUniforms.shadowBias = shadow.bias;
14132                                                 shadowUniforms.shadowNormalBias = shadow.normalBias;
14133                                                 shadowUniforms.shadowRadius = shadow.radius;
14134                                                 shadowUniforms.shadowMapSize = shadow.mapSize;
14135                                                 state.directionalShadow[directionalLength] = shadowUniforms;
14136                                                 state.directionalShadowMap[directionalLength] = shadowMap;
14137                                                 state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
14138                                                 numDirectionalShadows++;
14139                                         }
14140
14141                                         state.directional[directionalLength] = uniforms;
14142                                         directionalLength++;
14143                                 } else if (light.isSpotLight) {
14144                                         var _uniforms = cache.get(light);
14145
14146                                         _uniforms.position.setFromMatrixPosition(light.matrixWorld);
14147
14148                                         _uniforms.position.applyMatrix4(viewMatrix);
14149
14150                                         _uniforms.color.copy(color).multiplyScalar(intensity);
14151
14152                                         _uniforms.distance = distance;
14153
14154                                         _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
14155
14156                                         vector3.setFromMatrixPosition(light.target.matrixWorld);
14157
14158                                         _uniforms.direction.sub(vector3);
14159
14160                                         _uniforms.direction.transformDirection(viewMatrix);
14161
14162                                         _uniforms.coneCos = Math.cos(light.angle);
14163                                         _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
14164                                         _uniforms.decay = light.decay;
14165
14166                                         if (light.castShadow) {
14167                                                 var _shadow = light.shadow;
14168
14169                                                 var _shadowUniforms = shadowCache.get(light);
14170
14171                                                 _shadowUniforms.shadowBias = _shadow.bias;
14172                                                 _shadowUniforms.shadowNormalBias = _shadow.normalBias;
14173                                                 _shadowUniforms.shadowRadius = _shadow.radius;
14174                                                 _shadowUniforms.shadowMapSize = _shadow.mapSize;
14175                                                 state.spotShadow[spotLength] = _shadowUniforms;
14176                                                 state.spotShadowMap[spotLength] = shadowMap;
14177                                                 state.spotShadowMatrix[spotLength] = light.shadow.matrix;
14178                                                 numSpotShadows++;
14179                                         }
14180
14181                                         state.spot[spotLength] = _uniforms;
14182                                         spotLength++;
14183                                 } else if (light.isRectAreaLight) {
14184                                         var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
14185                                         //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
14186                                         // (b) intensity is the brightness of the light
14187
14188
14189                                         _uniforms2.color.copy(color).multiplyScalar(intensity);
14190
14191                                         _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
14192
14193                                         _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
14194
14195
14196                                         matrix42.identity();
14197                                         matrix4.copy(light.matrixWorld);
14198                                         matrix4.premultiply(viewMatrix);
14199                                         matrix42.extractRotation(matrix4);
14200
14201                                         _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
14202
14203                                         _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
14204
14205                                         _uniforms2.halfWidth.applyMatrix4(matrix42);
14206
14207                                         _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
14208                                         // uniforms.distance = distance;
14209
14210
14211                                         state.rectArea[rectAreaLength] = _uniforms2;
14212                                         rectAreaLength++;
14213                                 } else if (light.isPointLight) {
14214                                         var _uniforms3 = cache.get(light);
14215
14216                                         _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
14217
14218                                         _uniforms3.position.applyMatrix4(viewMatrix);
14219
14220                                         _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
14221
14222                                         _uniforms3.distance = light.distance;
14223                                         _uniforms3.decay = light.decay;
14224
14225                                         if (light.castShadow) {
14226                                                 var _shadow2 = light.shadow;
14227
14228                                                 var _shadowUniforms2 = shadowCache.get(light);
14229
14230                                                 _shadowUniforms2.shadowBias = _shadow2.bias;
14231                                                 _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
14232                                                 _shadowUniforms2.shadowRadius = _shadow2.radius;
14233                                                 _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
14234                                                 _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
14235                                                 _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
14236                                                 state.pointShadow[pointLength] = _shadowUniforms2;
14237                                                 state.pointShadowMap[pointLength] = shadowMap;
14238                                                 state.pointShadowMatrix[pointLength] = light.shadow.matrix;
14239                                                 numPointShadows++;
14240                                         }
14241
14242                                         state.point[pointLength] = _uniforms3;
14243                                         pointLength++;
14244                                 } else if (light.isHemisphereLight) {
14245                                         var _uniforms4 = cache.get(light);
14246
14247                                         _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
14248
14249                                         _uniforms4.direction.transformDirection(viewMatrix);
14250
14251                                         _uniforms4.direction.normalize();
14252
14253                                         _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
14254
14255                                         _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
14256
14257                                         state.hemi[hemiLength] = _uniforms4;
14258                                         hemiLength++;
14259                                 }
14260                         }
14261
14262                         if (rectAreaLength > 0) {
14263                                 if (capabilities.isWebGL2) {
14264                                         // WebGL 2
14265                                         state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
14266                                         state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
14267                                 } else {
14268                                         // WebGL 1
14269                                         if (extensions.has('OES_texture_float_linear') === true) {
14270                                                 state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
14271                                                 state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
14272                                         } else if (extensions.has('OES_texture_half_float_linear') === true) {
14273                                                 state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
14274                                                 state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
14275                                         } else {
14276                                                 console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
14277                                         }
14278                                 }
14279                         }
14280
14281                         state.ambient[0] = r;
14282                         state.ambient[1] = g;
14283                         state.ambient[2] = b;
14284                         var hash = state.hash;
14285
14286                         if (hash.directionalLength !== directionalLength || hash.pointLength !== pointLength || hash.spotLength !== spotLength || hash.rectAreaLength !== rectAreaLength || hash.hemiLength !== hemiLength || hash.numDirectionalShadows !== numDirectionalShadows || hash.numPointShadows !== numPointShadows || hash.numSpotShadows !== numSpotShadows) {
14287                                 state.directional.length = directionalLength;
14288                                 state.spot.length = spotLength;
14289                                 state.rectArea.length = rectAreaLength;
14290                                 state.point.length = pointLength;
14291                                 state.hemi.length = hemiLength;
14292                                 state.directionalShadow.length = numDirectionalShadows;
14293                                 state.directionalShadowMap.length = numDirectionalShadows;
14294                                 state.pointShadow.length = numPointShadows;
14295                                 state.pointShadowMap.length = numPointShadows;
14296                                 state.spotShadow.length = numSpotShadows;
14297                                 state.spotShadowMap.length = numSpotShadows;
14298                                 state.directionalShadowMatrix.length = numDirectionalShadows;
14299                                 state.pointShadowMatrix.length = numPointShadows;
14300                                 state.spotShadowMatrix.length = numSpotShadows;
14301                                 hash.directionalLength = directionalLength;
14302                                 hash.pointLength = pointLength;
14303                                 hash.spotLength = spotLength;
14304                                 hash.rectAreaLength = rectAreaLength;
14305                                 hash.hemiLength = hemiLength;
14306                                 hash.numDirectionalShadows = numDirectionalShadows;
14307                                 hash.numPointShadows = numPointShadows;
14308                                 hash.numSpotShadows = numSpotShadows;
14309                                 state.version = nextVersion++;
14310                         }
14311                 }
14312
14313                 return {
14314                         setup: setup,
14315                         state: state
14316                 };
14317         }
14318
14319         function WebGLRenderState(extensions, capabilities) {
14320                 var lights = new WebGLLights(extensions, capabilities);
14321                 var lightsArray = [];
14322                 var shadowsArray = [];
14323
14324                 function init() {
14325                         lightsArray.length = 0;
14326                         shadowsArray.length = 0;
14327                 }
14328
14329                 function pushLight(light) {
14330                         lightsArray.push(light);
14331                 }
14332
14333                 function pushShadow(shadowLight) {
14334                         shadowsArray.push(shadowLight);
14335                 }
14336
14337                 function setupLights(camera) {
14338                         lights.setup(lightsArray, shadowsArray, camera);
14339                 }
14340
14341                 var state = {
14342                         lightsArray: lightsArray,
14343                         shadowsArray: shadowsArray,
14344                         lights: lights
14345                 };
14346                 return {
14347                         init: init,
14348                         state: state,
14349                         setupLights: setupLights,
14350                         pushLight: pushLight,
14351                         pushShadow: pushShadow
14352                 };
14353         }
14354
14355         function WebGLRenderStates(extensions, capabilities) {
14356                 var renderStates = new WeakMap();
14357
14358                 function get(scene, camera) {
14359                         var renderState;
14360
14361                         if (renderStates.has(scene) === false) {
14362                                 renderState = new WebGLRenderState(extensions, capabilities);
14363                                 renderStates.set(scene, new WeakMap());
14364                                 renderStates.get(scene).set(camera, renderState);
14365                         } else {
14366                                 if (renderStates.get(scene).has(camera) === false) {
14367                                         renderState = new WebGLRenderState(extensions, capabilities);
14368                                         renderStates.get(scene).set(camera, renderState);
14369                                 } else {
14370                                         renderState = renderStates.get(scene).get(camera);
14371                                 }
14372                         }
14373
14374                         return renderState;
14375                 }
14376
14377                 function dispose() {
14378                         renderStates = new WeakMap();
14379                 }
14380
14381                 return {
14382                         get: get,
14383                         dispose: dispose
14384                 };
14385         }
14386
14387         /**
14388          * parameters = {
14389          *
14390          *      opacity: <float>,
14391          *
14392          *      map: new THREE.Texture( <Image> ),
14393          *
14394          *      alphaMap: new THREE.Texture( <Image> ),
14395          *
14396          *      displacementMap: new THREE.Texture( <Image> ),
14397          *      displacementScale: <float>,
14398          *      displacementBias: <float>,
14399          *
14400          *      wireframe: <boolean>,
14401          *      wireframeLinewidth: <float>
14402          * }
14403          */
14404
14405         function MeshDepthMaterial(parameters) {
14406                 Material.call(this);
14407                 this.type = 'MeshDepthMaterial';
14408                 this.depthPacking = BasicDepthPacking;
14409                 this.skinning = false;
14410                 this.morphTargets = false;
14411                 this.map = null;
14412                 this.alphaMap = null;
14413                 this.displacementMap = null;
14414                 this.displacementScale = 1;
14415                 this.displacementBias = 0;
14416                 this.wireframe = false;
14417                 this.wireframeLinewidth = 1;
14418                 this.fog = false;
14419                 this.setValues(parameters);
14420         }
14421
14422         MeshDepthMaterial.prototype = Object.create(Material.prototype);
14423         MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
14424         MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
14425
14426         MeshDepthMaterial.prototype.copy = function (source) {
14427                 Material.prototype.copy.call(this, source);
14428                 this.depthPacking = source.depthPacking;
14429                 this.skinning = source.skinning;
14430                 this.morphTargets = source.morphTargets;
14431                 this.map = source.map;
14432                 this.alphaMap = source.alphaMap;
14433                 this.displacementMap = source.displacementMap;
14434                 this.displacementScale = source.displacementScale;
14435                 this.displacementBias = source.displacementBias;
14436                 this.wireframe = source.wireframe;
14437                 this.wireframeLinewidth = source.wireframeLinewidth;
14438                 return this;
14439         };
14440
14441         /**
14442          * parameters = {
14443          *
14444          *      referencePosition: <float>,
14445          *      nearDistance: <float>,
14446          *      farDistance: <float>,
14447          *
14448          *      skinning: <bool>,
14449          *      morphTargets: <bool>,
14450          *
14451          *      map: new THREE.Texture( <Image> ),
14452          *
14453          *      alphaMap: new THREE.Texture( <Image> ),
14454          *
14455          *      displacementMap: new THREE.Texture( <Image> ),
14456          *      displacementScale: <float>,
14457          *      displacementBias: <float>
14458          *
14459          * }
14460          */
14461
14462         function MeshDistanceMaterial(parameters) {
14463                 Material.call(this);
14464                 this.type = 'MeshDistanceMaterial';
14465                 this.referencePosition = new Vector3();
14466                 this.nearDistance = 1;
14467                 this.farDistance = 1000;
14468                 this.skinning = false;
14469                 this.morphTargets = false;
14470                 this.map = null;
14471                 this.alphaMap = null;
14472                 this.displacementMap = null;
14473                 this.displacementScale = 1;
14474                 this.displacementBias = 0;
14475                 this.fog = false;
14476                 this.setValues(parameters);
14477         }
14478
14479         MeshDistanceMaterial.prototype = Object.create(Material.prototype);
14480         MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
14481         MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
14482
14483         MeshDistanceMaterial.prototype.copy = function (source) {
14484                 Material.prototype.copy.call(this, source);
14485                 this.referencePosition.copy(source.referencePosition);
14486                 this.nearDistance = source.nearDistance;
14487                 this.farDistance = source.farDistance;
14488                 this.skinning = source.skinning;
14489                 this.morphTargets = source.morphTargets;
14490                 this.map = source.map;
14491                 this.alphaMap = source.alphaMap;
14492                 this.displacementMap = source.displacementMap;
14493                 this.displacementScale = source.displacementScale;
14494                 this.displacementBias = source.displacementBias;
14495                 return this;
14496         };
14497
14498         var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
14499
14500         var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
14501
14502         function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
14503                 var _frustum = new Frustum();
14504
14505                 var _shadowMapSize = new Vector2(),
14506                                 _viewportSize = new Vector2(),
14507                                 _viewport = new Vector4(),
14508                                 _depthMaterials = [],
14509                                 _distanceMaterials = [],
14510                                 _materialCache = {};
14511
14512                 var shadowSide = {
14513                         0: BackSide,
14514                         1: FrontSide,
14515                         2: DoubleSide
14516                 };
14517                 var shadowMaterialVertical = new ShaderMaterial({
14518                         defines: {
14519                                 SAMPLE_RATE: 2.0 / 8.0,
14520                                 HALF_SAMPLE_RATE: 1.0 / 8.0
14521                         },
14522                         uniforms: {
14523                                 shadow_pass: {
14524                                         value: null
14525                                 },
14526                                 resolution: {
14527                                         value: new Vector2()
14528                                 },
14529                                 radius: {
14530                                         value: 4.0
14531                                 }
14532                         },
14533                         vertexShader: vsm_vert,
14534                         fragmentShader: vsm_frag
14535                 });
14536                 var shadowMaterialHorizonal = shadowMaterialVertical.clone();
14537                 shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
14538                 var fullScreenTri = new BufferGeometry();
14539                 fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
14540                 var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
14541                 var scope = this;
14542                 this.enabled = false;
14543                 this.autoUpdate = true;
14544                 this.needsUpdate = false;
14545                 this.type = PCFShadowMap;
14546
14547                 this.render = function (lights, scene, camera) {
14548                         if (scope.enabled === false) return;
14549                         if (scope.autoUpdate === false && scope.needsUpdate === false) return;
14550                         if (lights.length === 0) return;
14551
14552                         var currentRenderTarget = _renderer.getRenderTarget();
14553
14554                         var activeCubeFace = _renderer.getActiveCubeFace();
14555
14556                         var activeMipmapLevel = _renderer.getActiveMipmapLevel();
14557
14558                         var _state = _renderer.state; // Set GL state for depth map.
14559
14560                         _state.setBlending(NoBlending);
14561
14562                         _state.buffers.color.setClear(1, 1, 1, 1);
14563
14564                         _state.buffers.depth.setTest(true);
14565
14566                         _state.setScissorTest(false); // render depth map
14567
14568
14569                         for (var i = 0, il = lights.length; i < il; i++) {
14570                                 var light = lights[i];
14571                                 var shadow = light.shadow;
14572
14573                                 if (shadow === undefined) {
14574                                         console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
14575                                         continue;
14576                                 }
14577
14578                                 if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
14579
14580                                 _shadowMapSize.copy(shadow.mapSize);
14581
14582                                 var shadowFrameExtents = shadow.getFrameExtents();
14583
14584                                 _shadowMapSize.multiply(shadowFrameExtents);
14585
14586                                 _viewportSize.copy(shadow.mapSize);
14587
14588                                 if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
14589                                         if (_shadowMapSize.x > maxTextureSize) {
14590                                                 _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
14591                                                 _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
14592                                                 shadow.mapSize.x = _viewportSize.x;
14593                                         }
14594
14595                                         if (_shadowMapSize.y > maxTextureSize) {
14596                                                 _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
14597                                                 _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
14598                                                 shadow.mapSize.y = _viewportSize.y;
14599                                         }
14600                                 }
14601
14602                                 if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
14603                                         var pars = {
14604                                                 minFilter: LinearFilter,
14605                                                 magFilter: LinearFilter,
14606                                                 format: RGBAFormat
14607                                         };
14608                                         shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
14609                                         shadow.map.texture.name = light.name + ".shadowMap";
14610                                         shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
14611                                         shadow.camera.updateProjectionMatrix();
14612                                 }
14613
14614                                 if (shadow.map === null) {
14615                                         var _pars = {
14616                                                 minFilter: NearestFilter,
14617                                                 magFilter: NearestFilter,
14618                                                 format: RGBAFormat
14619                                         };
14620                                         shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
14621                                         shadow.map.texture.name = light.name + ".shadowMap";
14622                                         shadow.camera.updateProjectionMatrix();
14623                                 }
14624
14625                                 _renderer.setRenderTarget(shadow.map);
14626
14627                                 _renderer.clear();
14628
14629                                 var viewportCount = shadow.getViewportCount();
14630
14631                                 for (var vp = 0; vp < viewportCount; vp++) {
14632                                         var viewport = shadow.getViewport(vp);
14633
14634                                         _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
14635
14636                                         _state.viewport(_viewport);
14637
14638                                         shadow.updateMatrices(light, vp);
14639                                         _frustum = shadow.getFrustum();
14640                                         renderObject(scene, camera, shadow.camera, light, this.type);
14641                                 } // do blur pass for VSM
14642
14643
14644                                 if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
14645                                         VSMPass(shadow, camera);
14646                                 }
14647
14648                                 shadow.needsUpdate = false;
14649                         }
14650
14651                         scope.needsUpdate = false;
14652
14653                         _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
14654                 };
14655
14656                 function VSMPass(shadow, camera) {
14657                         var geometry = _objects.update(fullScreenMesh); // vertical pass
14658
14659
14660                         shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
14661                         shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
14662                         shadowMaterialVertical.uniforms.radius.value = shadow.radius;
14663
14664                         _renderer.setRenderTarget(shadow.mapPass);
14665
14666                         _renderer.clear();
14667
14668                         _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
14669
14670
14671                         shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
14672                         shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
14673                         shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
14674
14675                         _renderer.setRenderTarget(shadow.map);
14676
14677                         _renderer.clear();
14678
14679                         _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
14680                 }
14681
14682                 function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
14683                         var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
14684                         var material = _depthMaterials[index];
14685
14686                         if (material === undefined) {
14687                                 material = new MeshDepthMaterial({
14688                                         depthPacking: RGBADepthPacking,
14689                                         morphTargets: useMorphing,
14690                                         skinning: useSkinning
14691                                 });
14692                                 _depthMaterials[index] = material;
14693                         }
14694
14695                         return material;
14696                 }
14697
14698                 function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
14699                         var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
14700                         var material = _distanceMaterials[index];
14701
14702                         if (material === undefined) {
14703                                 material = new MeshDistanceMaterial({
14704                                         morphTargets: useMorphing,
14705                                         skinning: useSkinning
14706                                 });
14707                                 _distanceMaterials[index] = material;
14708                         }
14709
14710                         return material;
14711                 }
14712
14713                 function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
14714                         var result = null;
14715                         var getMaterialVariant = getDepthMaterialVariant;
14716                         var customMaterial = object.customDepthMaterial;
14717
14718                         if (light.isPointLight === true) {
14719                                 getMaterialVariant = getDistanceMaterialVariant;
14720                                 customMaterial = object.customDistanceMaterial;
14721                         }
14722
14723                         if (customMaterial === undefined) {
14724                                 var useMorphing = false;
14725
14726                                 if (material.morphTargets === true) {
14727                                         useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
14728                                 }
14729
14730                                 var useSkinning = false;
14731
14732                                 if (object.isSkinnedMesh === true) {
14733                                         if (material.skinning === true) {
14734                                                 useSkinning = true;
14735                                         } else {
14736                                                 console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
14737                                         }
14738                                 }
14739
14740                                 var useInstancing = object.isInstancedMesh === true;
14741                                 result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
14742                         } else {
14743                                 result = customMaterial;
14744                         }
14745
14746                         if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
14747                                 // in this case we need a unique material instance reflecting the
14748                                 // appropriate state
14749                                 var keyA = result.uuid,
14750                                                 keyB = material.uuid;
14751                                 var materialsForVariant = _materialCache[keyA];
14752
14753                                 if (materialsForVariant === undefined) {
14754                                         materialsForVariant = {};
14755                                         _materialCache[keyA] = materialsForVariant;
14756                                 }
14757
14758                                 var cachedMaterial = materialsForVariant[keyB];
14759
14760                                 if (cachedMaterial === undefined) {
14761                                         cachedMaterial = result.clone();
14762                                         materialsForVariant[keyB] = cachedMaterial;
14763                                 }
14764
14765                                 result = cachedMaterial;
14766                         }
14767
14768                         result.visible = material.visible;
14769                         result.wireframe = material.wireframe;
14770
14771                         if (type === VSMShadowMap) {
14772                                 result.side = material.shadowSide !== null ? material.shadowSide : material.side;
14773                         } else {
14774                                 result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
14775                         }
14776
14777                         result.clipShadows = material.clipShadows;
14778                         result.clippingPlanes = material.clippingPlanes;
14779                         result.clipIntersection = material.clipIntersection;
14780                         result.wireframeLinewidth = material.wireframeLinewidth;
14781                         result.linewidth = material.linewidth;
14782
14783                         if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
14784                                 result.referencePosition.setFromMatrixPosition(light.matrixWorld);
14785                                 result.nearDistance = shadowCameraNear;
14786                                 result.farDistance = shadowCameraFar;
14787                         }
14788
14789                         return result;
14790                 }
14791
14792                 function renderObject(object, camera, shadowCamera, light, type) {
14793                         if (object.visible === false) return;
14794                         var visible = object.layers.test(camera.layers);
14795
14796                         if (visible && (object.isMesh || object.isLine || object.isPoints)) {
14797                                 if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
14798                                         object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
14799
14800                                         var geometry = _objects.update(object);
14801
14802                                         var material = object.material;
14803
14804                                         if (Array.isArray(material)) {
14805                                                 var groups = geometry.groups;
14806
14807                                                 for (var k = 0, kl = groups.length; k < kl; k++) {
14808                                                         var group = groups[k];
14809                                                         var groupMaterial = material[group.materialIndex];
14810
14811                                                         if (groupMaterial && groupMaterial.visible) {
14812                                                                 var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
14813
14814                                                                 _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
14815                                                         }
14816                                                 }
14817                                         } else if (material.visible) {
14818                                                 var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
14819
14820                                                 _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
14821                                         }
14822                                 }
14823                         }
14824
14825                         var children = object.children;
14826
14827                         for (var i = 0, l = children.length; i < l; i++) {
14828                                 renderObject(children[i], camera, shadowCamera, light, type);
14829                         }
14830                 }
14831         }
14832
14833         function WebGLState(gl, extensions, capabilities) {
14834                 var _equationToGL, _factorToGL;
14835
14836                 var isWebGL2 = capabilities.isWebGL2;
14837
14838                 function ColorBuffer() {
14839                         var locked = false;
14840                         var color = new Vector4();
14841                         var currentColorMask = null;
14842                         var currentColorClear = new Vector4(0, 0, 0, 0);
14843                         return {
14844                                 setMask: function setMask(colorMask) {
14845                                         if (currentColorMask !== colorMask && !locked) {
14846                                                 gl.colorMask(colorMask, colorMask, colorMask, colorMask);
14847                                                 currentColorMask = colorMask;
14848                                         }
14849                                 },
14850                                 setLocked: function setLocked(lock) {
14851                                         locked = lock;
14852                                 },
14853                                 setClear: function setClear(r, g, b, a, premultipliedAlpha) {
14854                                         if (premultipliedAlpha === true) {
14855                                                 r *= a;
14856                                                 g *= a;
14857                                                 b *= a;
14858                                         }
14859
14860                                         color.set(r, g, b, a);
14861
14862                                         if (currentColorClear.equals(color) === false) {
14863                                                 gl.clearColor(r, g, b, a);
14864                                                 currentColorClear.copy(color);
14865                                         }
14866                                 },
14867                                 reset: function reset() {
14868                                         locked = false;
14869                                         currentColorMask = null;
14870                                         currentColorClear.set(-1, 0, 0, 0); // set to invalid state
14871                                 }
14872                         };
14873                 }
14874
14875                 function DepthBuffer() {
14876                         var locked = false;
14877                         var currentDepthMask = null;
14878                         var currentDepthFunc = null;
14879                         var currentDepthClear = null;
14880                         return {
14881                                 setTest: function setTest(depthTest) {
14882                                         if (depthTest) {
14883                                                 enable(2929);
14884                                         } else {
14885                                                 disable(2929);
14886                                         }
14887                                 },
14888                                 setMask: function setMask(depthMask) {
14889                                         if (currentDepthMask !== depthMask && !locked) {
14890                                                 gl.depthMask(depthMask);
14891                                                 currentDepthMask = depthMask;
14892                                         }
14893                                 },
14894                                 setFunc: function setFunc(depthFunc) {
14895                                         if (currentDepthFunc !== depthFunc) {
14896                                                 if (depthFunc) {
14897                                                         switch (depthFunc) {
14898                                                                 case NeverDepth:
14899                                                                         gl.depthFunc(512);
14900                                                                         break;
14901
14902                                                                 case AlwaysDepth:
14903                                                                         gl.depthFunc(519);
14904                                                                         break;
14905
14906                                                                 case LessDepth:
14907                                                                         gl.depthFunc(513);
14908                                                                         break;
14909
14910                                                                 case LessEqualDepth:
14911                                                                         gl.depthFunc(515);
14912                                                                         break;
14913
14914                                                                 case EqualDepth:
14915                                                                         gl.depthFunc(514);
14916                                                                         break;
14917
14918                                                                 case GreaterEqualDepth:
14919                                                                         gl.depthFunc(518);
14920                                                                         break;
14921
14922                                                                 case GreaterDepth:
14923                                                                         gl.depthFunc(516);
14924                                                                         break;
14925
14926                                                                 case NotEqualDepth:
14927                                                                         gl.depthFunc(517);
14928                                                                         break;
14929
14930                                                                 default:
14931                                                                         gl.depthFunc(515);
14932                                                         }
14933                                                 } else {
14934                                                         gl.depthFunc(515);
14935                                                 }
14936
14937                                                 currentDepthFunc = depthFunc;
14938                                         }
14939                                 },
14940                                 setLocked: function setLocked(lock) {
14941                                         locked = lock;
14942                                 },
14943                                 setClear: function setClear(depth) {
14944                                         if (currentDepthClear !== depth) {
14945                                                 gl.clearDepth(depth);
14946                                                 currentDepthClear = depth;
14947                                         }
14948                                 },
14949                                 reset: function reset() {
14950                                         locked = false;
14951                                         currentDepthMask = null;
14952                                         currentDepthFunc = null;
14953                                         currentDepthClear = null;
14954                                 }
14955                         };
14956                 }
14957
14958                 function StencilBuffer() {
14959                         var locked = false;
14960                         var currentStencilMask = null;
14961                         var currentStencilFunc = null;
14962                         var currentStencilRef = null;
14963                         var currentStencilFuncMask = null;
14964                         var currentStencilFail = null;
14965                         var currentStencilZFail = null;
14966                         var currentStencilZPass = null;
14967                         var currentStencilClear = null;
14968                         return {
14969                                 setTest: function setTest(stencilTest) {
14970                                         if (!locked) {
14971                                                 if (stencilTest) {
14972                                                         enable(2960);
14973                                                 } else {
14974                                                         disable(2960);
14975                                                 }
14976                                         }
14977                                 },
14978                                 setMask: function setMask(stencilMask) {
14979                                         if (currentStencilMask !== stencilMask && !locked) {
14980                                                 gl.stencilMask(stencilMask);
14981                                                 currentStencilMask = stencilMask;
14982                                         }
14983                                 },
14984                                 setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
14985                                         if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
14986                                                 gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
14987                                                 currentStencilFunc = stencilFunc;
14988                                                 currentStencilRef = stencilRef;
14989                                                 currentStencilFuncMask = stencilMask;
14990                                         }
14991                                 },
14992                                 setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
14993                                         if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
14994                                                 gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
14995                                                 currentStencilFail = stencilFail;
14996                                                 currentStencilZFail = stencilZFail;
14997                                                 currentStencilZPass = stencilZPass;
14998                                         }
14999                                 },
15000                                 setLocked: function setLocked(lock) {
15001                                         locked = lock;
15002                                 },
15003                                 setClear: function setClear(stencil) {
15004                                         if (currentStencilClear !== stencil) {
15005                                                 gl.clearStencil(stencil);
15006                                                 currentStencilClear = stencil;
15007                                         }
15008                                 },
15009                                 reset: function reset() {
15010                                         locked = false;
15011                                         currentStencilMask = null;
15012                                         currentStencilFunc = null;
15013                                         currentStencilRef = null;
15014                                         currentStencilFuncMask = null;
15015                                         currentStencilFail = null;
15016                                         currentStencilZFail = null;
15017                                         currentStencilZPass = null;
15018                                         currentStencilClear = null;
15019                                 }
15020                         };
15021                 } //
15022
15023
15024                 var colorBuffer = new ColorBuffer();
15025                 var depthBuffer = new DepthBuffer();
15026                 var stencilBuffer = new StencilBuffer();
15027                 var enabledCapabilities = {};
15028                 var currentProgram = null;
15029                 var currentBlendingEnabled = null;
15030                 var currentBlending = null;
15031                 var currentBlendEquation = null;
15032                 var currentBlendSrc = null;
15033                 var currentBlendDst = null;
15034                 var currentBlendEquationAlpha = null;
15035                 var currentBlendSrcAlpha = null;
15036                 var currentBlendDstAlpha = null;
15037                 var currentPremultipledAlpha = false;
15038                 var currentFlipSided = null;
15039                 var currentCullFace = null;
15040                 var currentLineWidth = null;
15041                 var currentPolygonOffsetFactor = null;
15042                 var currentPolygonOffsetUnits = null;
15043                 var maxTextures = gl.getParameter(35661);
15044                 var lineWidthAvailable = false;
15045                 var version = 0;
15046                 var glVersion = gl.getParameter(7938);
15047
15048                 if (glVersion.indexOf('WebGL') !== -1) {
15049                         version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
15050                         lineWidthAvailable = version >= 1.0;
15051                 } else if (glVersion.indexOf('OpenGL ES') !== -1) {
15052                         version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
15053                         lineWidthAvailable = version >= 2.0;
15054                 }
15055
15056                 var currentTextureSlot = null;
15057                 var currentBoundTextures = {};
15058                 var currentScissor = new Vector4();
15059                 var currentViewport = new Vector4();
15060
15061                 function createTexture(type, target, count) {
15062                         var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
15063
15064                         var texture = gl.createTexture();
15065                         gl.bindTexture(type, texture);
15066                         gl.texParameteri(type, 10241, 9728);
15067                         gl.texParameteri(type, 10240, 9728);
15068
15069                         for (var i = 0; i < count; i++) {
15070                                 gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
15071                         }
15072
15073                         return texture;
15074                 }
15075
15076                 var emptyTextures = {};
15077                 emptyTextures[3553] = createTexture(3553, 3553, 1);
15078                 emptyTextures[34067] = createTexture(34067, 34069, 6); // init
15079
15080                 colorBuffer.setClear(0, 0, 0, 1);
15081                 depthBuffer.setClear(1);
15082                 stencilBuffer.setClear(0);
15083                 enable(2929);
15084                 depthBuffer.setFunc(LessEqualDepth);
15085                 setFlipSided(false);
15086                 setCullFace(CullFaceBack);
15087                 enable(2884);
15088                 setBlending(NoBlending); //
15089
15090                 function enable(id) {
15091                         if (enabledCapabilities[id] !== true) {
15092                                 gl.enable(id);
15093                                 enabledCapabilities[id] = true;
15094                         }
15095                 }
15096
15097                 function disable(id) {
15098                         if (enabledCapabilities[id] !== false) {
15099                                 gl.disable(id);
15100                                 enabledCapabilities[id] = false;
15101                         }
15102                 }
15103
15104                 function useProgram(program) {
15105                         if (currentProgram !== program) {
15106                                 gl.useProgram(program);
15107                                 currentProgram = program;
15108                                 return true;
15109                         }
15110
15111                         return false;
15112                 }
15113
15114                 var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
15115
15116                 if (isWebGL2) {
15117                         equationToGL[MinEquation] = 32775;
15118                         equationToGL[MaxEquation] = 32776;
15119                 } else {
15120                         var extension = extensions.get('EXT_blend_minmax');
15121
15122                         if (extension !== null) {
15123                                 equationToGL[MinEquation] = extension.MIN_EXT;
15124                                 equationToGL[MaxEquation] = extension.MAX_EXT;
15125                         }
15126                 }
15127
15128                 var factorToGL = (_factorToGL = {}, _factorToGL[ZeroFactor] = 0, _factorToGL[OneFactor] = 1, _factorToGL[SrcColorFactor] = 768, _factorToGL[SrcAlphaFactor] = 770, _factorToGL[SrcAlphaSaturateFactor] = 776, _factorToGL[DstColorFactor] = 774, _factorToGL[DstAlphaFactor] = 772, _factorToGL[OneMinusSrcColorFactor] = 769, _factorToGL[OneMinusSrcAlphaFactor] = 771, _factorToGL[OneMinusDstColorFactor] = 775, _factorToGL[OneMinusDstAlphaFactor] = 773, _factorToGL);
15129
15130                 function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
15131                         if (blending === NoBlending) {
15132                                 if (currentBlendingEnabled) {
15133                                         disable(3042);
15134                                         currentBlendingEnabled = false;
15135                                 }
15136
15137                                 return;
15138                         }
15139
15140                         if (!currentBlendingEnabled) {
15141                                 enable(3042);
15142                                 currentBlendingEnabled = true;
15143                         }
15144
15145                         if (blending !== CustomBlending) {
15146                                 if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
15147                                         if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
15148                                                 gl.blendEquation(32774);
15149                                                 currentBlendEquation = AddEquation;
15150                                                 currentBlendEquationAlpha = AddEquation;
15151                                         }
15152
15153                                         if (premultipliedAlpha) {
15154                                                 switch (blending) {
15155                                                         case NormalBlending:
15156                                                                 gl.blendFuncSeparate(1, 771, 1, 771);
15157                                                                 break;
15158
15159                                                         case AdditiveBlending:
15160                                                                 gl.blendFunc(1, 1);
15161                                                                 break;
15162
15163                                                         case SubtractiveBlending:
15164                                                                 gl.blendFuncSeparate(0, 0, 769, 771);
15165                                                                 break;
15166
15167                                                         case MultiplyBlending:
15168                                                                 gl.blendFuncSeparate(0, 768, 0, 770);
15169                                                                 break;
15170
15171                                                         default:
15172                                                                 console.error('THREE.WebGLState: Invalid blending: ', blending);
15173                                                                 break;
15174                                                 }
15175                                         } else {
15176                                                 switch (blending) {
15177                                                         case NormalBlending:
15178                                                                 gl.blendFuncSeparate(770, 771, 1, 771);
15179                                                                 break;
15180
15181                                                         case AdditiveBlending:
15182                                                                 gl.blendFunc(770, 1);
15183                                                                 break;
15184
15185                                                         case SubtractiveBlending:
15186                                                                 gl.blendFunc(0, 769);
15187                                                                 break;
15188
15189                                                         case MultiplyBlending:
15190                                                                 gl.blendFunc(0, 768);
15191                                                                 break;
15192
15193                                                         default:
15194                                                                 console.error('THREE.WebGLState: Invalid blending: ', blending);
15195                                                                 break;
15196                                                 }
15197                                         }
15198
15199                                         currentBlendSrc = null;
15200                                         currentBlendDst = null;
15201                                         currentBlendSrcAlpha = null;
15202                                         currentBlendDstAlpha = null;
15203                                         currentBlending = blending;
15204                                         currentPremultipledAlpha = premultipliedAlpha;
15205                                 }
15206
15207                                 return;
15208                         } // custom blending
15209
15210
15211                         blendEquationAlpha = blendEquationAlpha || blendEquation;
15212                         blendSrcAlpha = blendSrcAlpha || blendSrc;
15213                         blendDstAlpha = blendDstAlpha || blendDst;
15214
15215                         if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
15216                                 gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
15217                                 currentBlendEquation = blendEquation;
15218                                 currentBlendEquationAlpha = blendEquationAlpha;
15219                         }
15220
15221                         if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
15222                                 gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
15223                                 currentBlendSrc = blendSrc;
15224                                 currentBlendDst = blendDst;
15225                                 currentBlendSrcAlpha = blendSrcAlpha;
15226                                 currentBlendDstAlpha = blendDstAlpha;
15227                         }
15228
15229                         currentBlending = blending;
15230                         currentPremultipledAlpha = null;
15231                 }
15232
15233                 function setMaterial(material, frontFaceCW) {
15234                         material.side === DoubleSide ? disable(2884) : enable(2884);
15235                         var flipSided = material.side === BackSide;
15236                         if (frontFaceCW) flipSided = !flipSided;
15237                         setFlipSided(flipSided);
15238                         material.blending === NormalBlending && material.transparent === false ? setBlending(NoBlending) : setBlending(material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha);
15239                         depthBuffer.setFunc(material.depthFunc);
15240                         depthBuffer.setTest(material.depthTest);
15241                         depthBuffer.setMask(material.depthWrite);
15242                         colorBuffer.setMask(material.colorWrite);
15243                         var stencilWrite = material.stencilWrite;
15244                         stencilBuffer.setTest(stencilWrite);
15245
15246                         if (stencilWrite) {
15247                                 stencilBuffer.setMask(material.stencilWriteMask);
15248                                 stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
15249                                 stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
15250                         }
15251
15252                         setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
15253                 } //
15254
15255
15256                 function setFlipSided(flipSided) {
15257                         if (currentFlipSided !== flipSided) {
15258                                 if (flipSided) {
15259                                         gl.frontFace(2304);
15260                                 } else {
15261                                         gl.frontFace(2305);
15262                                 }
15263
15264                                 currentFlipSided = flipSided;
15265                         }
15266                 }
15267
15268                 function setCullFace(cullFace) {
15269                         if (cullFace !== CullFaceNone) {
15270                                 enable(2884);
15271
15272                                 if (cullFace !== currentCullFace) {
15273                                         if (cullFace === CullFaceBack) {
15274                                                 gl.cullFace(1029);
15275                                         } else if (cullFace === CullFaceFront) {
15276                                                 gl.cullFace(1028);
15277                                         } else {
15278                                                 gl.cullFace(1032);
15279                                         }
15280                                 }
15281                         } else {
15282                                 disable(2884);
15283                         }
15284
15285                         currentCullFace = cullFace;
15286                 }
15287
15288                 function setLineWidth(width) {
15289                         if (width !== currentLineWidth) {
15290                                 if (lineWidthAvailable) gl.lineWidth(width);
15291                                 currentLineWidth = width;
15292                         }
15293                 }
15294
15295                 function setPolygonOffset(polygonOffset, factor, units) {
15296                         if (polygonOffset) {
15297                                 enable(32823);
15298
15299                                 if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
15300                                         gl.polygonOffset(factor, units);
15301                                         currentPolygonOffsetFactor = factor;
15302                                         currentPolygonOffsetUnits = units;
15303                                 }
15304                         } else {
15305                                 disable(32823);
15306                         }
15307                 }
15308
15309                 function setScissorTest(scissorTest) {
15310                         if (scissorTest) {
15311                                 enable(3089);
15312                         } else {
15313                                 disable(3089);
15314                         }
15315                 } // texture
15316
15317
15318                 function activeTexture(webglSlot) {
15319                         if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
15320
15321                         if (currentTextureSlot !== webglSlot) {
15322                                 gl.activeTexture(webglSlot);
15323                                 currentTextureSlot = webglSlot;
15324                         }
15325                 }
15326
15327                 function bindTexture(webglType, webglTexture) {
15328                         if (currentTextureSlot === null) {
15329                                 activeTexture();
15330                         }
15331
15332                         var boundTexture = currentBoundTextures[currentTextureSlot];
15333
15334                         if (boundTexture === undefined) {
15335                                 boundTexture = {
15336                                         type: undefined,
15337                                         texture: undefined
15338                                 };
15339                                 currentBoundTextures[currentTextureSlot] = boundTexture;
15340                         }
15341
15342                         if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
15343                                 gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
15344                                 boundTexture.type = webglType;
15345                                 boundTexture.texture = webglTexture;
15346                         }
15347                 }
15348
15349                 function unbindTexture() {
15350                         var boundTexture = currentBoundTextures[currentTextureSlot];
15351
15352                         if (boundTexture !== undefined && boundTexture.type !== undefined) {
15353                                 gl.bindTexture(boundTexture.type, null);
15354                                 boundTexture.type = undefined;
15355                                 boundTexture.texture = undefined;
15356                         }
15357                 }
15358
15359                 function compressedTexImage2D() {
15360                         try {
15361                                 gl.compressedTexImage2D.apply(gl, arguments);
15362                         } catch (error) {
15363                                 console.error('THREE.WebGLState:', error);
15364                         }
15365                 }
15366
15367                 function texImage2D() {
15368                         try {
15369                                 gl.texImage2D.apply(gl, arguments);
15370                         } catch (error) {
15371                                 console.error('THREE.WebGLState:', error);
15372                         }
15373                 }
15374
15375                 function texImage3D() {
15376                         try {
15377                                 gl.texImage3D.apply(gl, arguments);
15378                         } catch (error) {
15379                                 console.error('THREE.WebGLState:', error);
15380                         }
15381                 } //
15382
15383
15384                 function scissor(scissor) {
15385                         if (currentScissor.equals(scissor) === false) {
15386                                 gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
15387                                 currentScissor.copy(scissor);
15388                         }
15389                 }
15390
15391                 function viewport(viewport) {
15392                         if (currentViewport.equals(viewport) === false) {
15393                                 gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
15394                                 currentViewport.copy(viewport);
15395                         }
15396                 } //
15397
15398
15399                 function reset() {
15400                         enabledCapabilities = {};
15401                         currentTextureSlot = null;
15402                         currentBoundTextures = {};
15403                         currentProgram = null;
15404                         currentBlendingEnabled = null;
15405                         currentBlending = null;
15406                         currentBlendEquation = null;
15407                         currentBlendSrc = null;
15408                         currentBlendDst = null;
15409                         currentBlendEquationAlpha = null;
15410                         currentBlendSrcAlpha = null;
15411                         currentBlendDstAlpha = null;
15412                         currentPremultipledAlpha = false;
15413                         currentFlipSided = null;
15414                         currentCullFace = null;
15415                         currentLineWidth = null;
15416                         currentPolygonOffsetFactor = null;
15417                         currentPolygonOffsetUnits = null;
15418                         colorBuffer.reset();
15419                         depthBuffer.reset();
15420                         stencilBuffer.reset();
15421                 }
15422
15423                 return {
15424                         buffers: {
15425                                 color: colorBuffer,
15426                                 depth: depthBuffer,
15427                                 stencil: stencilBuffer
15428                         },
15429                         enable: enable,
15430                         disable: disable,
15431                         useProgram: useProgram,
15432                         setBlending: setBlending,
15433                         setMaterial: setMaterial,
15434                         setFlipSided: setFlipSided,
15435                         setCullFace: setCullFace,
15436                         setLineWidth: setLineWidth,
15437                         setPolygonOffset: setPolygonOffset,
15438                         setScissorTest: setScissorTest,
15439                         activeTexture: activeTexture,
15440                         bindTexture: bindTexture,
15441                         unbindTexture: unbindTexture,
15442                         compressedTexImage2D: compressedTexImage2D,
15443                         texImage2D: texImage2D,
15444                         texImage3D: texImage3D,
15445                         scissor: scissor,
15446                         viewport: viewport,
15447                         reset: reset
15448                 };
15449         }
15450
15451         function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
15452                 var _wrappingToGL, _filterToGL;
15453
15454                 var isWebGL2 = capabilities.isWebGL2;
15455                 var maxTextures = capabilities.maxTextures;
15456                 var maxCubemapSize = capabilities.maxCubemapSize;
15457                 var maxTextureSize = capabilities.maxTextureSize;
15458                 var maxSamples = capabilities.maxSamples;
15459
15460                 var _videoTextures = new WeakMap();
15461
15462                 var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
15463                 // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
15464                 // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
15465
15466
15467                 var useOffscreenCanvas = false;
15468
15469                 try {
15470                         useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
15471                 } catch (err) {// Ignore any errors
15472                 }
15473
15474                 function createCanvas(width, height) {
15475                         // Use OffscreenCanvas when available. Specially needed in web workers
15476                         return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
15477                 }
15478
15479                 function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
15480                         var scale = 1; // handle case if texture exceeds max size
15481
15482                         if (image.width > maxSize || image.height > maxSize) {
15483                                 scale = maxSize / Math.max(image.width, image.height);
15484                         } // only perform resize if necessary
15485
15486
15487                         if (scale < 1 || needsPowerOfTwo === true) {
15488                                 // only perform resize for certain image types
15489                                 if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
15490                                         var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
15491                                         var width = floor(scale * image.width);
15492                                         var height = floor(scale * image.height);
15493                                         if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
15494
15495                                         var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
15496                                         canvas.width = width;
15497                                         canvas.height = height;
15498                                         var context = canvas.getContext('2d');
15499                                         context.drawImage(image, 0, 0, width, height);
15500                                         console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
15501                                         return canvas;
15502                                 } else {
15503                                         if ('data' in image) {
15504                                                 console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
15505                                         }
15506
15507                                         return image;
15508                                 }
15509                         }
15510
15511                         return image;
15512                 }
15513
15514                 function isPowerOfTwo(image) {
15515                         return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
15516                 }
15517
15518                 function textureNeedsPowerOfTwo(texture) {
15519                         if (isWebGL2) return false;
15520                         return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
15521                 }
15522
15523                 function textureNeedsGenerateMipmaps(texture, supportsMips) {
15524                         return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
15525                 }
15526
15527                 function generateMipmap(target, texture, width, height) {
15528                         _gl.generateMipmap(target);
15529
15530                         var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
15531
15532                         textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
15533                 }
15534
15535                 function getInternalFormat(internalFormatName, glFormat, glType) {
15536                         if (isWebGL2 === false) return glFormat;
15537
15538                         if (internalFormatName !== null) {
15539                                 if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
15540                                 console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
15541                         }
15542
15543                         var internalFormat = glFormat;
15544
15545                         if (glFormat === 6403) {
15546                                 if (glType === 5126) internalFormat = 33326;
15547                                 if (glType === 5131) internalFormat = 33325;
15548                                 if (glType === 5121) internalFormat = 33321;
15549                         }
15550
15551                         if (glFormat === 6407) {
15552                                 if (glType === 5126) internalFormat = 34837;
15553                                 if (glType === 5131) internalFormat = 34843;
15554                                 if (glType === 5121) internalFormat = 32849;
15555                         }
15556
15557                         if (glFormat === 6408) {
15558                                 if (glType === 5126) internalFormat = 34836;
15559                                 if (glType === 5131) internalFormat = 34842;
15560                                 if (glType === 5121) internalFormat = 32856;
15561                         }
15562
15563                         if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
15564                                 extensions.get('EXT_color_buffer_float');
15565                         }
15566
15567                         return internalFormat;
15568                 } // Fallback filters for non-power-of-2 textures
15569
15570
15571                 function filterFallback(f) {
15572                         if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
15573                                 return 9728;
15574                         }
15575
15576                         return 9729;
15577                 } //
15578
15579
15580                 function onTextureDispose(event) {
15581                         var texture = event.target;
15582                         texture.removeEventListener('dispose', onTextureDispose);
15583                         deallocateTexture(texture);
15584
15585                         if (texture.isVideoTexture) {
15586                                 _videoTextures.delete(texture);
15587                         }
15588
15589                         info.memory.textures--;
15590                 }
15591
15592                 function onRenderTargetDispose(event) {
15593                         var renderTarget = event.target;
15594                         renderTarget.removeEventListener('dispose', onRenderTargetDispose);
15595                         deallocateRenderTarget(renderTarget);
15596                         info.memory.textures--;
15597                 } //
15598
15599
15600                 function deallocateTexture(texture) {
15601                         var textureProperties = properties.get(texture);
15602                         if (textureProperties.__webglInit === undefined) return;
15603
15604                         _gl.deleteTexture(textureProperties.__webglTexture);
15605
15606                         properties.remove(texture);
15607                 }
15608
15609                 function deallocateRenderTarget(renderTarget) {
15610                         var renderTargetProperties = properties.get(renderTarget);
15611                         var textureProperties = properties.get(renderTarget.texture);
15612                         if (!renderTarget) return;
15613
15614                         if (textureProperties.__webglTexture !== undefined) {
15615                                 _gl.deleteTexture(textureProperties.__webglTexture);
15616                         }
15617
15618                         if (renderTarget.depthTexture) {
15619                                 renderTarget.depthTexture.dispose();
15620                         }
15621
15622                         if (renderTarget.isWebGLCubeRenderTarget) {
15623                                 for (var i = 0; i < 6; i++) {
15624                                         _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
15625
15626                                         if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
15627                                 }
15628                         } else {
15629                                 _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
15630
15631                                 if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
15632                                 if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
15633                                 if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
15634                                 if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
15635                         }
15636
15637                         properties.remove(renderTarget.texture);
15638                         properties.remove(renderTarget);
15639                 } //
15640
15641
15642                 var textureUnits = 0;
15643
15644                 function resetTextureUnits() {
15645                         textureUnits = 0;
15646                 }
15647
15648                 function allocateTextureUnit() {
15649                         var textureUnit = textureUnits;
15650
15651                         if (textureUnit >= maxTextures) {
15652                                 console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
15653                         }
15654
15655                         textureUnits += 1;
15656                         return textureUnit;
15657                 } //
15658
15659
15660                 function setTexture2D(texture, slot) {
15661                         var textureProperties = properties.get(texture);
15662                         if (texture.isVideoTexture) updateVideoTexture(texture);
15663
15664                         if (texture.version > 0 && textureProperties.__version !== texture.version) {
15665                                 var image = texture.image;
15666
15667                                 if (image === undefined) {
15668                                         console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
15669                                 } else if (image.complete === false) {
15670                                         console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
15671                                 } else {
15672                                         uploadTexture(textureProperties, texture, slot);
15673                                         return;
15674                                 }
15675                         }
15676
15677                         state.activeTexture(33984 + slot);
15678                         state.bindTexture(3553, textureProperties.__webglTexture);
15679                 }
15680
15681                 function setTexture2DArray(texture, slot) {
15682                         var textureProperties = properties.get(texture);
15683
15684                         if (texture.version > 0 && textureProperties.__version !== texture.version) {
15685                                 uploadTexture(textureProperties, texture, slot);
15686                                 return;
15687                         }
15688
15689                         state.activeTexture(33984 + slot);
15690                         state.bindTexture(35866, textureProperties.__webglTexture);
15691                 }
15692
15693                 function setTexture3D(texture, slot) {
15694                         var textureProperties = properties.get(texture);
15695
15696                         if (texture.version > 0 && textureProperties.__version !== texture.version) {
15697                                 uploadTexture(textureProperties, texture, slot);
15698                                 return;
15699                         }
15700
15701                         state.activeTexture(33984 + slot);
15702                         state.bindTexture(32879, textureProperties.__webglTexture);
15703                 }
15704
15705                 function setTextureCube(texture, slot) {
15706                         var textureProperties = properties.get(texture);
15707
15708                         if (texture.version > 0 && textureProperties.__version !== texture.version) {
15709                                 uploadCubeTexture(textureProperties, texture, slot);
15710                                 return;
15711                         }
15712
15713                         state.activeTexture(33984 + slot);
15714                         state.bindTexture(34067, textureProperties.__webglTexture);
15715                 }
15716
15717                 var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
15718                 var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
15719
15720                 function setTextureParameters(textureType, texture, supportsMips) {
15721                         if (supportsMips) {
15722                                 _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
15723
15724                                 _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
15725
15726                                 if (textureType === 32879 || textureType === 35866) {
15727                                         _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
15728                                 }
15729
15730                                 _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
15731
15732                                 _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
15733                         } else {
15734                                 _gl.texParameteri(textureType, 10242, 33071);
15735
15736                                 _gl.texParameteri(textureType, 10243, 33071);
15737
15738                                 if (textureType === 32879 || textureType === 35866) {
15739                                         _gl.texParameteri(textureType, 32882, 33071);
15740                                 }
15741
15742                                 if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
15743                                         console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
15744                                 }
15745
15746                                 _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
15747
15748                                 _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
15749
15750                                 if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
15751                                         console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
15752                                 }
15753                         }
15754
15755                         var extension = extensions.get('EXT_texture_filter_anisotropic');
15756
15757                         if (extension) {
15758                                 if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
15759                                 if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
15760
15761                                 if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
15762                                         _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
15763
15764                                         properties.get(texture).__currentAnisotropy = texture.anisotropy;
15765                                 }
15766                         }
15767                 }
15768
15769                 function initTexture(textureProperties, texture) {
15770                         if (textureProperties.__webglInit === undefined) {
15771                                 textureProperties.__webglInit = true;
15772                                 texture.addEventListener('dispose', onTextureDispose);
15773                                 textureProperties.__webglTexture = _gl.createTexture();
15774                                 info.memory.textures++;
15775                         }
15776                 }
15777
15778                 function uploadTexture(textureProperties, texture, slot) {
15779                         var textureType = 3553;
15780                         if (texture.isDataTexture2DArray) textureType = 35866;
15781                         if (texture.isDataTexture3D) textureType = 32879;
15782                         initTexture(textureProperties, texture);
15783                         state.activeTexture(33984 + slot);
15784                         state.bindTexture(textureType, textureProperties.__webglTexture);
15785
15786                         _gl.pixelStorei(37440, texture.flipY);
15787
15788                         _gl.pixelStorei(37441, texture.premultiplyAlpha);
15789
15790                         _gl.pixelStorei(3317, texture.unpackAlignment);
15791
15792                         var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
15793                         var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
15794                         var supportsMips = isPowerOfTwo(image) || isWebGL2,
15795                                         glFormat = utils.convert(texture.format);
15796                         var glType = utils.convert(texture.type),
15797                                         glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
15798                         setTextureParameters(textureType, texture, supportsMips);
15799                         var mipmap;
15800                         var mipmaps = texture.mipmaps;
15801
15802                         if (texture.isDepthTexture) {
15803                                 // populate depth texture with dummy data
15804                                 glInternalFormat = 6402;
15805
15806                                 if (isWebGL2) {
15807                                         if (texture.type === FloatType) {
15808                                                 glInternalFormat = 36012;
15809                                         } else if (texture.type === UnsignedIntType) {
15810                                                 glInternalFormat = 33190;
15811                                         } else if (texture.type === UnsignedInt248Type) {
15812                                                 glInternalFormat = 35056;
15813                                         } else {
15814                                                 glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
15815                                         }
15816                                 } else {
15817                                         if (texture.type === FloatType) {
15818                                                 console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
15819                                         }
15820                                 } // validation checks for WebGL 1
15821
15822
15823                                 if (texture.format === DepthFormat && glInternalFormat === 6402) {
15824                                         // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
15825                                         // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
15826                                         // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
15827                                         if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
15828                                                 console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
15829                                                 texture.type = UnsignedShortType;
15830                                                 glType = utils.convert(texture.type);
15831                                         }
15832                                 }
15833
15834                                 if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
15835                                         // Depth stencil textures need the DEPTH_STENCIL internal format
15836                                         // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
15837                                         glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
15838                                         // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
15839                                         // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
15840
15841                                         if (texture.type !== UnsignedInt248Type) {
15842                                                 console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
15843                                                 texture.type = UnsignedInt248Type;
15844                                                 glType = utils.convert(texture.type);
15845                                         }
15846                                 } //
15847
15848
15849                                 state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
15850                         } else if (texture.isDataTexture) {
15851                                 // use manually created mipmaps if available
15852                                 // if there are no manual mipmaps
15853                                 // set 0 level mipmap and then use GL to generate other mipmap levels
15854                                 if (mipmaps.length > 0 && supportsMips) {
15855                                         for (var i = 0, il = mipmaps.length; i < il; i++) {
15856                                                 mipmap = mipmaps[i];
15857                                                 state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
15858                                         }
15859
15860                                         texture.generateMipmaps = false;
15861                                         textureProperties.__maxMipLevel = mipmaps.length - 1;
15862                                 } else {
15863                                         state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
15864                                         textureProperties.__maxMipLevel = 0;
15865                                 }
15866                         } else if (texture.isCompressedTexture) {
15867                                 for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
15868                                         mipmap = mipmaps[_i];
15869
15870                                         if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
15871                                                 if (glFormat !== null) {
15872                                                         state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
15873                                                 } else {
15874                                                         console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
15875                                                 }
15876                                         } else {
15877                                                 state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
15878                                         }
15879                                 }
15880
15881                                 textureProperties.__maxMipLevel = mipmaps.length - 1;
15882                         } else if (texture.isDataTexture2DArray) {
15883                                 state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
15884                                 textureProperties.__maxMipLevel = 0;
15885                         } else if (texture.isDataTexture3D) {
15886                                 state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
15887                                 textureProperties.__maxMipLevel = 0;
15888                         } else {
15889                                 // regular Texture (image, video, canvas)
15890                                 // use manually created mipmaps if available
15891                                 // if there are no manual mipmaps
15892                                 // set 0 level mipmap and then use GL to generate other mipmap levels
15893                                 if (mipmaps.length > 0 && supportsMips) {
15894                                         for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
15895                                                 mipmap = mipmaps[_i2];
15896                                                 state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
15897                                         }
15898
15899                                         texture.generateMipmaps = false;
15900                                         textureProperties.__maxMipLevel = mipmaps.length - 1;
15901                                 } else {
15902                                         state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
15903                                         textureProperties.__maxMipLevel = 0;
15904                                 }
15905                         }
15906
15907                         if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
15908                                 generateMipmap(textureType, texture, image.width, image.height);
15909                         }
15910
15911                         textureProperties.__version = texture.version;
15912                         if (texture.onUpdate) texture.onUpdate(texture);
15913                 }
15914
15915                 function uploadCubeTexture(textureProperties, texture, slot) {
15916                         if (texture.image.length !== 6) return;
15917                         initTexture(textureProperties, texture);
15918                         state.activeTexture(33984 + slot);
15919                         state.bindTexture(34067, textureProperties.__webglTexture);
15920
15921                         _gl.pixelStorei(37440, texture.flipY);
15922
15923                         var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
15924                         var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
15925                         var cubeImage = [];
15926
15927                         for (var i = 0; i < 6; i++) {
15928                                 if (!isCompressed && !isDataTexture) {
15929                                         cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
15930                                 } else {
15931                                         cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
15932                                 }
15933                         }
15934
15935                         var image = cubeImage[0],
15936                                         supportsMips = isPowerOfTwo(image) || isWebGL2,
15937                                         glFormat = utils.convert(texture.format),
15938                                         glType = utils.convert(texture.type),
15939                                         glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
15940                         setTextureParameters(34067, texture, supportsMips);
15941                         var mipmaps;
15942
15943                         if (isCompressed) {
15944                                 for (var _i3 = 0; _i3 < 6; _i3++) {
15945                                         mipmaps = cubeImage[_i3].mipmaps;
15946
15947                                         for (var j = 0; j < mipmaps.length; j++) {
15948                                                 var mipmap = mipmaps[j];
15949
15950                                                 if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
15951                                                         if (glFormat !== null) {
15952                                                                 state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
15953                                                         } else {
15954                                                                 console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
15955                                                         }
15956                                                 } else {
15957                                                         state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
15958                                                 }
15959                                         }
15960                                 }
15961
15962                                 textureProperties.__maxMipLevel = mipmaps.length - 1;
15963                         } else {
15964                                 mipmaps = texture.mipmaps;
15965
15966                                 for (var _i4 = 0; _i4 < 6; _i4++) {
15967                                         if (isDataTexture) {
15968                                                 state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
15969
15970                                                 for (var _j = 0; _j < mipmaps.length; _j++) {
15971                                                         var _mipmap = mipmaps[_j];
15972                                                         var mipmapImage = _mipmap.image[_i4].image;
15973                                                         state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
15974                                                 }
15975                                         } else {
15976                                                 state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
15977
15978                                                 for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
15979                                                         var _mipmap2 = mipmaps[_j2];
15980                                                         state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
15981                                                 }
15982                                         }
15983                                 }
15984
15985                                 textureProperties.__maxMipLevel = mipmaps.length;
15986                         }
15987
15988                         if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
15989                                 // We assume images for cube map have the same size.
15990                                 generateMipmap(34067, texture, image.width, image.height);
15991                         }
15992
15993                         textureProperties.__version = texture.version;
15994                         if (texture.onUpdate) texture.onUpdate(texture);
15995                 } // Render targets
15996                 // Setup storage for target texture and bind it to correct framebuffer
15997
15998
15999                 function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
16000                         var glFormat = utils.convert(renderTarget.texture.format);
16001                         var glType = utils.convert(renderTarget.texture.type);
16002                         var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
16003                         state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
16004
16005                         _gl.bindFramebuffer(36160, framebuffer);
16006
16007                         _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
16008
16009                         _gl.bindFramebuffer(36160, null);
16010                 } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
16011
16012
16013                 function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
16014                         _gl.bindRenderbuffer(36161, renderbuffer);
16015
16016                         if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
16017                                 var glInternalFormat = 33189;
16018
16019                                 if (isMultisample) {
16020                                         var depthTexture = renderTarget.depthTexture;
16021
16022                                         if (depthTexture && depthTexture.isDepthTexture) {
16023                                                 if (depthTexture.type === FloatType) {
16024                                                         glInternalFormat = 36012;
16025                                                 } else if (depthTexture.type === UnsignedIntType) {
16026                                                         glInternalFormat = 33190;
16027                                                 }
16028                                         }
16029
16030                                         var samples = getRenderTargetSamples(renderTarget);
16031
16032                                         _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
16033                                 } else {
16034                                         _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
16035                                 }
16036
16037                                 _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
16038                         } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
16039                                 if (isMultisample) {
16040                                         var _samples = getRenderTargetSamples(renderTarget);
16041
16042                                         _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
16043                                 } else {
16044                                         _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
16045                                 }
16046
16047                                 _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
16048                         } else {
16049                                 var glFormat = utils.convert(renderTarget.texture.format);
16050                                 var glType = utils.convert(renderTarget.texture.type);
16051
16052                                 var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
16053
16054                                 if (isMultisample) {
16055                                         var _samples2 = getRenderTargetSamples(renderTarget);
16056
16057                                         _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
16058                                 } else {
16059                                         _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
16060                                 }
16061                         }
16062
16063                         _gl.bindRenderbuffer(36161, null);
16064                 } // Setup resources for a Depth Texture for a FBO (needs an extension)
16065
16066
16067                 function setupDepthTexture(framebuffer, renderTarget) {
16068                         var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
16069                         if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
16070
16071                         _gl.bindFramebuffer(36160, framebuffer);
16072
16073                         if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
16074                                 throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
16075                         } // upload an empty depth texture with framebuffer size
16076
16077
16078                         if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
16079                                 renderTarget.depthTexture.image.width = renderTarget.width;
16080                                 renderTarget.depthTexture.image.height = renderTarget.height;
16081                                 renderTarget.depthTexture.needsUpdate = true;
16082                         }
16083
16084                         setTexture2D(renderTarget.depthTexture, 0);
16085
16086                         var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
16087
16088                         if (renderTarget.depthTexture.format === DepthFormat) {
16089                                 _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
16090                         } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
16091                                 _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
16092                         } else {
16093                                 throw new Error('Unknown depthTexture format');
16094                         }
16095                 } // Setup GL resources for a non-texture depth buffer
16096
16097
16098                 function setupDepthRenderbuffer(renderTarget) {
16099                         var renderTargetProperties = properties.get(renderTarget);
16100                         var isCube = renderTarget.isWebGLCubeRenderTarget === true;
16101
16102                         if (renderTarget.depthTexture) {
16103                                 if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
16104                                 setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
16105                         } else {
16106                                 if (isCube) {
16107                                         renderTargetProperties.__webglDepthbuffer = [];
16108
16109                                         for (var i = 0; i < 6; i++) {
16110                                                 _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
16111
16112                                                 renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
16113                                                 setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
16114                                         }
16115                                 } else {
16116                                         _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
16117
16118                                         renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
16119                                         setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
16120                                 }
16121                         }
16122
16123                         _gl.bindFramebuffer(36160, null);
16124                 } // Set up GL resources for the render target
16125
16126
16127                 function setupRenderTarget(renderTarget) {
16128                         var renderTargetProperties = properties.get(renderTarget);
16129                         var textureProperties = properties.get(renderTarget.texture);
16130                         renderTarget.addEventListener('dispose', onRenderTargetDispose);
16131                         textureProperties.__webglTexture = _gl.createTexture();
16132                         info.memory.textures++;
16133                         var isCube = renderTarget.isWebGLCubeRenderTarget === true;
16134                         var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
16135                         var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
16136
16137                         if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
16138                                 renderTarget.texture.format = RGBAFormat;
16139                                 console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
16140                         } // Setup framebuffer
16141
16142
16143                         if (isCube) {
16144                                 renderTargetProperties.__webglFramebuffer = [];
16145
16146                                 for (var i = 0; i < 6; i++) {
16147                                         renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
16148                                 }
16149                         } else {
16150                                 renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
16151
16152                                 if (isMultisample) {
16153                                         if (isWebGL2) {
16154                                                 renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
16155                                                 renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
16156
16157                                                 _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
16158
16159                                                 var glFormat = utils.convert(renderTarget.texture.format);
16160                                                 var glType = utils.convert(renderTarget.texture.type);
16161                                                 var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
16162                                                 var samples = getRenderTargetSamples(renderTarget);
16163
16164                                                 _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
16165
16166                                                 _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
16167
16168                                                 _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
16169
16170                                                 _gl.bindRenderbuffer(36161, null);
16171
16172                                                 if (renderTarget.depthBuffer) {
16173                                                         renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
16174                                                         setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
16175                                                 }
16176
16177                                                 _gl.bindFramebuffer(36160, null);
16178                                         } else {
16179                                                 console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
16180                                         }
16181                                 }
16182                         } // Setup color buffer
16183
16184
16185                         if (isCube) {
16186                                 state.bindTexture(34067, textureProperties.__webglTexture);
16187                                 setTextureParameters(34067, renderTarget.texture, supportsMips);
16188
16189                                 for (var _i5 = 0; _i5 < 6; _i5++) {
16190                                         setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
16191                                 }
16192
16193                                 if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
16194                                         generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
16195                                 }
16196
16197                                 state.bindTexture(34067, null);
16198                         } else {
16199                                 state.bindTexture(3553, textureProperties.__webglTexture);
16200                                 setTextureParameters(3553, renderTarget.texture, supportsMips);
16201                                 setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
16202
16203                                 if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
16204                                         generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
16205                                 }
16206
16207                                 state.bindTexture(3553, null);
16208                         } // Setup depth and stencil buffers
16209
16210
16211                         if (renderTarget.depthBuffer) {
16212                                 setupDepthRenderbuffer(renderTarget);
16213                         }
16214                 }
16215
16216                 function updateRenderTargetMipmap(renderTarget) {
16217                         var texture = renderTarget.texture;
16218                         var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
16219
16220                         if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
16221                                 var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
16222
16223                                 var webglTexture = properties.get(texture).__webglTexture;
16224
16225                                 state.bindTexture(target, webglTexture);
16226                                 generateMipmap(target, texture, renderTarget.width, renderTarget.height);
16227                                 state.bindTexture(target, null);
16228                         }
16229                 }
16230
16231                 function updateMultisampleRenderTarget(renderTarget) {
16232                         if (renderTarget.isWebGLMultisampleRenderTarget) {
16233                                 if (isWebGL2) {
16234                                         var renderTargetProperties = properties.get(renderTarget);
16235
16236                                         _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
16237
16238                                         _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
16239
16240                                         var width = renderTarget.width;
16241                                         var height = renderTarget.height;
16242                                         var mask = 16384;
16243                                         if (renderTarget.depthBuffer) mask |= 256;
16244                                         if (renderTarget.stencilBuffer) mask |= 1024;
16245
16246                                         _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
16247
16248                                         _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
16249
16250                                 } else {
16251                                         console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
16252                                 }
16253                         }
16254                 }
16255
16256                 function getRenderTargetSamples(renderTarget) {
16257                         return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
16258                 }
16259
16260                 function updateVideoTexture(texture) {
16261                         var frame = info.render.frame; // Check the last frame we updated the VideoTexture
16262
16263                         if (_videoTextures.get(texture) !== frame) {
16264                                 _videoTextures.set(texture, frame);
16265
16266                                 texture.update();
16267                         }
16268                 } // backwards compatibility
16269
16270
16271                 var warnedTexture2D = false;
16272                 var warnedTextureCube = false;
16273
16274                 function safeSetTexture2D(texture, slot) {
16275                         if (texture && texture.isWebGLRenderTarget) {
16276                                 if (warnedTexture2D === false) {
16277                                         console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
16278                                         warnedTexture2D = true;
16279                                 }
16280
16281                                 texture = texture.texture;
16282                         }
16283
16284                         setTexture2D(texture, slot);
16285                 }
16286
16287                 function safeSetTextureCube(texture, slot) {
16288                         if (texture && texture.isWebGLCubeRenderTarget) {
16289                                 if (warnedTextureCube === false) {
16290                                         console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
16291                                         warnedTextureCube = true;
16292                                 }
16293
16294                                 texture = texture.texture;
16295                         }
16296
16297                         setTextureCube(texture, slot);
16298                 } //
16299
16300
16301                 this.allocateTextureUnit = allocateTextureUnit;
16302                 this.resetTextureUnits = resetTextureUnits;
16303                 this.setTexture2D = setTexture2D;
16304                 this.setTexture2DArray = setTexture2DArray;
16305                 this.setTexture3D = setTexture3D;
16306                 this.setTextureCube = setTextureCube;
16307                 this.setupRenderTarget = setupRenderTarget;
16308                 this.updateRenderTargetMipmap = updateRenderTargetMipmap;
16309                 this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
16310                 this.safeSetTexture2D = safeSetTexture2D;
16311                 this.safeSetTextureCube = safeSetTextureCube;
16312         }
16313
16314         function WebGLUtils(gl, extensions, capabilities) {
16315                 var isWebGL2 = capabilities.isWebGL2;
16316
16317                 function convert(p) {
16318                         var extension;
16319                         if (p === UnsignedByteType) return 5121;
16320                         if (p === UnsignedShort4444Type) return 32819;
16321                         if (p === UnsignedShort5551Type) return 32820;
16322                         if (p === UnsignedShort565Type) return 33635;
16323                         if (p === ByteType) return 5120;
16324                         if (p === ShortType) return 5122;
16325                         if (p === UnsignedShortType) return 5123;
16326                         if (p === IntType) return 5124;
16327                         if (p === UnsignedIntType) return 5125;
16328                         if (p === FloatType) return 5126;
16329
16330                         if (p === HalfFloatType) {
16331                                 if (isWebGL2) return 5131;
16332                                 extension = extensions.get('OES_texture_half_float');
16333
16334                                 if (extension !== null) {
16335                                         return extension.HALF_FLOAT_OES;
16336                                 } else {
16337                                         return null;
16338                                 }
16339                         }
16340
16341                         if (p === AlphaFormat) return 6406;
16342                         if (p === RGBFormat) return 6407;
16343                         if (p === RGBAFormat) return 6408;
16344                         if (p === LuminanceFormat) return 6409;
16345                         if (p === LuminanceAlphaFormat) return 6410;
16346                         if (p === DepthFormat) return 6402;
16347                         if (p === DepthStencilFormat) return 34041;
16348                         if (p === RedFormat) return 6403; // WebGL2 formats.
16349
16350                         if (p === RedIntegerFormat) return 36244;
16351                         if (p === RGFormat) return 33319;
16352                         if (p === RGIntegerFormat) return 33320;
16353                         if (p === RGBIntegerFormat) return 36248;
16354                         if (p === RGBAIntegerFormat) return 36249;
16355
16356                         if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
16357                                 extension = extensions.get('WEBGL_compressed_texture_s3tc');
16358
16359                                 if (extension !== null) {
16360                                         if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
16361                                         if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
16362                                         if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
16363                                         if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
16364                                 } else {
16365                                         return null;
16366                                 }
16367                         }
16368
16369                         if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
16370                                 extension = extensions.get('WEBGL_compressed_texture_pvrtc');
16371
16372                                 if (extension !== null) {
16373                                         if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
16374                                         if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
16375                                         if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
16376                                         if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
16377                                 } else {
16378                                         return null;
16379                                 }
16380                         }
16381
16382                         if (p === RGB_ETC1_Format) {
16383                                 extension = extensions.get('WEBGL_compressed_texture_etc1');
16384
16385                                 if (extension !== null) {
16386                                         return extension.COMPRESSED_RGB_ETC1_WEBGL;
16387                                 } else {
16388                                         return null;
16389                                 }
16390                         }
16391
16392                         if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
16393                                 extension = extensions.get('WEBGL_compressed_texture_etc');
16394
16395                                 if (extension !== null) {
16396                                         if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
16397                                         if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
16398                                 }
16399                         }
16400
16401                         if (p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format || p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format || p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format || p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format || p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format || p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format) {
16402                                 extension = extensions.get('WEBGL_compressed_texture_astc');
16403
16404                                 if (extension !== null) {
16405                                         // TODO Complete?
16406                                         return p;
16407                                 } else {
16408                                         return null;
16409                                 }
16410                         }
16411
16412                         if (p === RGBA_BPTC_Format) {
16413                                 extension = extensions.get('EXT_texture_compression_bptc');
16414
16415                                 if (extension !== null) {
16416                                         // TODO Complete?
16417                                         return p;
16418                                 } else {
16419                                         return null;
16420                                 }
16421                         }
16422
16423                         if (p === UnsignedInt248Type) {
16424                                 if (isWebGL2) return 34042;
16425                                 extension = extensions.get('WEBGL_depth_texture');
16426
16427                                 if (extension !== null) {
16428                                         return extension.UNSIGNED_INT_24_8_WEBGL;
16429                                 } else {
16430                                         return null;
16431                                 }
16432                         }
16433                 }
16434
16435                 return {
16436                         convert: convert
16437                 };
16438         }
16439
16440         function ArrayCamera(array) {
16441                 if (array === void 0) {
16442                         array = [];
16443                 }
16444
16445                 PerspectiveCamera.call(this);
16446                 this.cameras = array;
16447         }
16448
16449         ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
16450                 constructor: ArrayCamera,
16451                 isArrayCamera: true
16452         });
16453
16454         function Group() {
16455                 Object3D.call(this);
16456                 this.type = 'Group';
16457         }
16458
16459         Group.prototype = Object.assign(Object.create(Object3D.prototype), {
16460                 constructor: Group,
16461                 isGroup: true
16462         });
16463
16464         function WebXRController() {
16465                 this._targetRay = null;
16466                 this._grip = null;
16467                 this._hand = null;
16468         }
16469
16470         Object.assign(WebXRController.prototype, {
16471                 constructor: WebXRController,
16472                 getHandSpace: function getHandSpace() {
16473                         if (this._hand === null) {
16474                                 this._hand = new Group();
16475                                 this._hand.matrixAutoUpdate = false;
16476                                 this._hand.visible = false;
16477                                 this._hand.joints = [];
16478                                 this._hand.inputState = {
16479                                         pinching: false
16480                                 };
16481
16482                                 if (window.XRHand) {
16483                                         for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
16484                                                 // The transform of this joint will be updated with the joint pose on each frame
16485                                                 var joint = new Group();
16486                                                 joint.matrixAutoUpdate = false;
16487                                                 joint.visible = false;
16488
16489                                                 this._hand.joints.push(joint); // ??
16490
16491
16492                                                 this._hand.add(joint);
16493                                         }
16494                                 }
16495                         }
16496
16497                         return this._hand;
16498                 },
16499                 getTargetRaySpace: function getTargetRaySpace() {
16500                         if (this._targetRay === null) {
16501                                 this._targetRay = new Group();
16502                                 this._targetRay.matrixAutoUpdate = false;
16503                                 this._targetRay.visible = false;
16504                         }
16505
16506                         return this._targetRay;
16507                 },
16508                 getGripSpace: function getGripSpace() {
16509                         if (this._grip === null) {
16510                                 this._grip = new Group();
16511                                 this._grip.matrixAutoUpdate = false;
16512                                 this._grip.visible = false;
16513                         }
16514
16515                         return this._grip;
16516                 },
16517                 dispatchEvent: function dispatchEvent(event) {
16518                         if (this._targetRay !== null) {
16519                                 this._targetRay.dispatchEvent(event);
16520                         }
16521
16522                         if (this._grip !== null) {
16523                                 this._grip.dispatchEvent(event);
16524                         }
16525
16526                         if (this._hand !== null) {
16527                                 this._hand.dispatchEvent(event);
16528                         }
16529
16530                         return this;
16531                 },
16532                 disconnect: function disconnect(inputSource) {
16533                         this.dispatchEvent({
16534                                 type: 'disconnected',
16535                                 data: inputSource
16536                         });
16537
16538                         if (this._targetRay !== null) {
16539                                 this._targetRay.visible = false;
16540                         }
16541
16542                         if (this._grip !== null) {
16543                                 this._grip.visible = false;
16544                         }
16545
16546                         if (this._hand !== null) {
16547                                 this._hand.visible = false;
16548                         }
16549
16550                         return this;
16551                 },
16552                 update: function update(inputSource, frame, referenceSpace) {
16553                         var inputPose = null;
16554                         var gripPose = null;
16555                         var handPose = null;
16556                         var targetRay = this._targetRay;
16557                         var grip = this._grip;
16558                         var hand = this._hand;
16559
16560                         if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
16561                                 if (hand && inputSource.hand) {
16562                                         handPose = true;
16563
16564                                         for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
16565                                                 if (inputSource.hand[i]) {
16566                                                         // Update the joints groups with the XRJoint poses
16567                                                         var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
16568                                                         var joint = hand.joints[i];
16569
16570                                                         if (jointPose !== null) {
16571                                                                 joint.matrix.fromArray(jointPose.transform.matrix);
16572                                                                 joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
16573                                                                 joint.jointRadius = jointPose.radius;
16574                                                         }
16575
16576                                                         joint.visible = jointPose !== null; // Custom events
16577                                                         // Check pinch
16578
16579                                                         var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
16580                                                         var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
16581                                                         var distance = indexTip.position.distanceTo(thumbTip.position);
16582                                                         var distanceToPinch = 0.02;
16583                                                         var threshold = 0.005;
16584
16585                                                         if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
16586                                                                 hand.inputState.pinching = false;
16587                                                                 this.dispatchEvent({
16588                                                                         type: "pinchend",
16589                                                                         handedness: inputSource.handedness,
16590                                                                         target: this
16591                                                                 });
16592                                                         } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
16593                                                                 hand.inputState.pinching = true;
16594                                                                 this.dispatchEvent({
16595                                                                         type: "pinchstart",
16596                                                                         handedness: inputSource.handedness,
16597                                                                         target: this
16598                                                                 });
16599                                                         }
16600                                                 }
16601                                         }
16602                                 } else {
16603                                         if (targetRay !== null) {
16604                                                 inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
16605
16606                                                 if (inputPose !== null) {
16607                                                         targetRay.matrix.fromArray(inputPose.transform.matrix);
16608                                                         targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
16609                                                 }
16610                                         }
16611
16612                                         if (grip !== null && inputSource.gripSpace) {
16613                                                 gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
16614
16615                                                 if (gripPose !== null) {
16616                                                         grip.matrix.fromArray(gripPose.transform.matrix);
16617                                                         grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
16618                                                 }
16619                                         }
16620                                 }
16621                         }
16622
16623                         if (targetRay !== null) {
16624                                 targetRay.visible = inputPose !== null;
16625                         }
16626
16627                         if (grip !== null) {
16628                                 grip.visible = gripPose !== null;
16629                         }
16630
16631                         if (hand !== null) {
16632                                 hand.visible = handPose !== null;
16633                         }
16634
16635                         return this;
16636                 }
16637         });
16638
16639         function WebXRManager(renderer, gl) {
16640                 var scope = this;
16641                 var session = null;
16642                 var framebufferScaleFactor = 1.0;
16643                 var referenceSpace = null;
16644                 var referenceSpaceType = 'local-floor';
16645                 var pose = null;
16646                 var controllers = [];
16647                 var inputSourcesMap = new Map(); //
16648
16649                 var cameraL = new PerspectiveCamera();
16650                 cameraL.layers.enable(1);
16651                 cameraL.viewport = new Vector4();
16652                 var cameraR = new PerspectiveCamera();
16653                 cameraR.layers.enable(2);
16654                 cameraR.viewport = new Vector4();
16655                 var cameras = [cameraL, cameraR];
16656                 var cameraVR = new ArrayCamera();
16657                 cameraVR.layers.enable(1);
16658                 cameraVR.layers.enable(2);
16659                 var _currentDepthNear = null;
16660                 var _currentDepthFar = null; //
16661
16662                 this.enabled = false;
16663                 this.isPresenting = false;
16664
16665                 this.getController = function (index) {
16666                         var controller = controllers[index];
16667
16668                         if (controller === undefined) {
16669                                 controller = new WebXRController();
16670                                 controllers[index] = controller;
16671                         }
16672
16673                         return controller.getTargetRaySpace();
16674                 };
16675
16676                 this.getControllerGrip = function (index) {
16677                         var controller = controllers[index];
16678
16679                         if (controller === undefined) {
16680                                 controller = new WebXRController();
16681                                 controllers[index] = controller;
16682                         }
16683
16684                         return controller.getGripSpace();
16685                 };
16686
16687                 this.getHand = function (index) {
16688                         var controller = controllers[index];
16689
16690                         if (controller === undefined) {
16691                                 controller = new WebXRController();
16692                                 controllers[index] = controller;
16693                         }
16694
16695                         return controller.getHandSpace();
16696                 }; //
16697
16698
16699                 function onSessionEvent(event) {
16700                         var controller = inputSourcesMap.get(event.inputSource);
16701
16702                         if (controller) {
16703                                 controller.dispatchEvent({
16704                                         type: event.type,
16705                                         data: event.inputSource
16706                                 });
16707                         }
16708                 }
16709
16710                 function onSessionEnd() {
16711                         inputSourcesMap.forEach(function (controller, inputSource) {
16712                                 controller.disconnect(inputSource);
16713                         });
16714                         inputSourcesMap.clear(); //
16715
16716                         renderer.setFramebuffer(null);
16717                         renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
16718
16719                         animation.stop();
16720                         scope.isPresenting = false;
16721                         scope.dispatchEvent({
16722                                 type: 'sessionend'
16723                         });
16724                 }
16725
16726                 function onRequestReferenceSpace(value) {
16727                         referenceSpace = value;
16728                         animation.setContext(session);
16729                         animation.start();
16730                         scope.isPresenting = true;
16731                         scope.dispatchEvent({
16732                                 type: 'sessionstart'
16733                         });
16734                 }
16735
16736                 this.setFramebufferScaleFactor = function (value) {
16737                         framebufferScaleFactor = value;
16738
16739                         if (scope.isPresenting === true) {
16740                                 console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
16741                         }
16742                 };
16743
16744                 this.setReferenceSpaceType = function (value) {
16745                         referenceSpaceType = value;
16746
16747                         if (scope.isPresenting === true) {
16748                                 console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
16749                         }
16750                 };
16751
16752                 this.getReferenceSpace = function () {
16753                         return referenceSpace;
16754                 };
16755
16756                 this.getSession = function () {
16757                         return session;
16758                 };
16759
16760                 this.setSession = function (value) {
16761                         session = value;
16762
16763                         if (session !== null) {
16764                                 session.addEventListener('select', onSessionEvent);
16765                                 session.addEventListener('selectstart', onSessionEvent);
16766                                 session.addEventListener('selectend', onSessionEvent);
16767                                 session.addEventListener('squeeze', onSessionEvent);
16768                                 session.addEventListener('squeezestart', onSessionEvent);
16769                                 session.addEventListener('squeezeend', onSessionEvent);
16770                                 session.addEventListener('end', onSessionEnd);
16771                                 var attributes = gl.getContextAttributes();
16772
16773                                 if (attributes.xrCompatible !== true) {
16774                                         gl.makeXRCompatible();
16775                                 }
16776
16777                                 var layerInit = {
16778                                         antialias: attributes.antialias,
16779                                         alpha: attributes.alpha,
16780                                         depth: attributes.depth,
16781                                         stencil: attributes.stencil,
16782                                         framebufferScaleFactor: framebufferScaleFactor
16783                                 }; // eslint-disable-next-line no-undef
16784
16785                                 var baseLayer = new XRWebGLLayer(session, gl, layerInit);
16786                                 session.updateRenderState({
16787                                         baseLayer: baseLayer
16788                                 });
16789                                 session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
16790
16791                                 session.addEventListener('inputsourceschange', updateInputSources);
16792                         }
16793                 };
16794
16795                 function updateInputSources(event) {
16796                         var inputSources = session.inputSources; // Assign inputSources to available controllers
16797
16798                         for (var i = 0; i < controllers.length; i++) {
16799                                 inputSourcesMap.set(inputSources[i], controllers[i]);
16800                         } // Notify disconnected
16801
16802
16803                         for (var _i = 0; _i < event.removed.length; _i++) {
16804                                 var inputSource = event.removed[_i];
16805                                 var controller = inputSourcesMap.get(inputSource);
16806
16807                                 if (controller) {
16808                                         controller.dispatchEvent({
16809                                                 type: 'disconnected',
16810                                                 data: inputSource
16811                                         });
16812                                         inputSourcesMap.delete(inputSource);
16813                                 }
16814                         } // Notify connected
16815
16816
16817                         for (var _i2 = 0; _i2 < event.added.length; _i2++) {
16818                                 var _inputSource = event.added[_i2];
16819
16820                                 var _controller = inputSourcesMap.get(_inputSource);
16821
16822                                 if (_controller) {
16823                                         _controller.dispatchEvent({
16824                                                 type: 'connected',
16825                                                 data: _inputSource
16826                                         });
16827                                 }
16828                         }
16829                 } //
16830
16831
16832                 var cameraLPos = new Vector3();
16833                 var cameraRPos = new Vector3();
16834                 /**
16835                  * Assumes 2 cameras that are parallel and share an X-axis, and that
16836                  * the cameras' projection and world matrices have already been set.
16837                  * And that near and far planes are identical for both cameras.
16838                  * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
16839                  */
16840
16841                 function setProjectionFromUnion(camera, cameraL, cameraR) {
16842                         cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
16843                         cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
16844                         var ipd = cameraLPos.distanceTo(cameraRPos);
16845                         var projL = cameraL.projectionMatrix.elements;
16846                         var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
16847                         // most likely identical top and bottom frustum extents.
16848                         // Use the left camera for these values.
16849
16850                         var near = projL[14] / (projL[10] - 1);
16851                         var far = projL[14] / (projL[10] + 1);
16852                         var topFov = (projL[9] + 1) / projL[5];
16853                         var bottomFov = (projL[9] - 1) / projL[5];
16854                         var leftFov = (projL[8] - 1) / projL[0];
16855                         var rightFov = (projR[8] + 1) / projR[0];
16856                         var left = near * leftFov;
16857                         var right = near * rightFov; // Calculate the new camera's position offset from the
16858                         // left camera. xOffset should be roughly half `ipd`.
16859
16860                         var zOffset = ipd / (-leftFov + rightFov);
16861                         var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
16862
16863                         cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
16864                         camera.translateX(xOffset);
16865                         camera.translateZ(zOffset);
16866                         camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
16867                         camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
16868                         // the values so that the near plane's position does not change in world space,
16869                         // although must now be relative to the new union camera.
16870
16871                         var near2 = near + zOffset;
16872                         var far2 = far + zOffset;
16873                         var left2 = left - xOffset;
16874                         var right2 = right + (ipd - xOffset);
16875                         var top2 = topFov * far / far2 * near2;
16876                         var bottom2 = bottomFov * far / far2 * near2;
16877                         camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
16878                 }
16879
16880                 function updateCamera(camera, parent) {
16881                         if (parent === null) {
16882                                 camera.matrixWorld.copy(camera.matrix);
16883                         } else {
16884                                 camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
16885                         }
16886
16887                         camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
16888                 }
16889
16890                 this.getCamera = function (camera) {
16891                         cameraVR.near = cameraR.near = cameraL.near = camera.near;
16892                         cameraVR.far = cameraR.far = cameraL.far = camera.far;
16893
16894                         if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
16895                                 // Note that the new renderState won't apply until the next frame. See #18320
16896                                 session.updateRenderState({
16897                                         depthNear: cameraVR.near,
16898                                         depthFar: cameraVR.far
16899                                 });
16900                                 _currentDepthNear = cameraVR.near;
16901                                 _currentDepthFar = cameraVR.far;
16902                         }
16903
16904                         var parent = camera.parent;
16905                         var cameras = cameraVR.cameras;
16906                         updateCamera(cameraVR, parent);
16907
16908                         for (var i = 0; i < cameras.length; i++) {
16909                                 updateCamera(cameras[i], parent);
16910                         } // update camera and its children
16911
16912
16913                         camera.matrixWorld.copy(cameraVR.matrixWorld);
16914                         var children = camera.children;
16915
16916                         for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
16917                                 children[_i3].updateMatrixWorld(true);
16918                         } // update projection matrix for proper view frustum culling
16919
16920
16921                         if (cameras.length === 2) {
16922                                 setProjectionFromUnion(cameraVR, cameraL, cameraR);
16923                         } else {
16924                                 // assume single camera setup (AR)
16925                                 cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
16926                         }
16927
16928                         return cameraVR;
16929                 }; // Animation Loop
16930
16931
16932                 var onAnimationFrameCallback = null;
16933
16934                 function onAnimationFrame(time, frame) {
16935                         pose = frame.getViewerPose(referenceSpace);
16936
16937                         if (pose !== null) {
16938                                 var views = pose.views;
16939                                 var baseLayer = session.renderState.baseLayer;
16940                                 renderer.setFramebuffer(baseLayer.framebuffer);
16941                                 var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
16942
16943                                 if (views.length !== cameraVR.cameras.length) {
16944                                         cameraVR.cameras.length = 0;
16945                                         cameraVRNeedsUpdate = true;
16946                                 }
16947
16948                                 for (var i = 0; i < views.length; i++) {
16949                                         var view = views[i];
16950                                         var viewport = baseLayer.getViewport(view);
16951                                         var camera = cameras[i];
16952                                         camera.matrix.fromArray(view.transform.matrix);
16953                                         camera.projectionMatrix.fromArray(view.projectionMatrix);
16954                                         camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
16955
16956                                         if (i === 0) {
16957                                                 cameraVR.matrix.copy(camera.matrix);
16958                                         }
16959
16960                                         if (cameraVRNeedsUpdate === true) {
16961                                                 cameraVR.cameras.push(camera);
16962                                         }
16963                                 }
16964                         } //
16965
16966
16967                         var inputSources = session.inputSources;
16968
16969                         for (var _i4 = 0; _i4 < controllers.length; _i4++) {
16970                                 var controller = controllers[_i4];
16971                                 var inputSource = inputSources[_i4];
16972                                 controller.update(inputSource, frame, referenceSpace);
16973                         }
16974
16975                         if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
16976                 }
16977
16978                 var animation = new WebGLAnimation();
16979                 animation.setAnimationLoop(onAnimationFrame);
16980
16981                 this.setAnimationLoop = function (callback) {
16982                         onAnimationFrameCallback = callback;
16983                 };
16984
16985                 this.dispose = function () {};
16986         }
16987
16988         Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
16989
16990         function WebGLMaterials(properties) {
16991                 function refreshFogUniforms(uniforms, fog) {
16992                         uniforms.fogColor.value.copy(fog.color);
16993
16994                         if (fog.isFog) {
16995                                 uniforms.fogNear.value = fog.near;
16996                                 uniforms.fogFar.value = fog.far;
16997                         } else if (fog.isFogExp2) {
16998                                 uniforms.fogDensity.value = fog.density;
16999                         }
17000                 }
17001
17002                 function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
17003                         if (material.isMeshBasicMaterial) {
17004                                 refreshUniformsCommon(uniforms, material);
17005                         } else if (material.isMeshLambertMaterial) {
17006                                 refreshUniformsCommon(uniforms, material);
17007                                 refreshUniformsLambert(uniforms, material);
17008                         } else if (material.isMeshToonMaterial) {
17009                                 refreshUniformsCommon(uniforms, material);
17010                                 refreshUniformsToon(uniforms, material);
17011                         } else if (material.isMeshPhongMaterial) {
17012                                 refreshUniformsCommon(uniforms, material);
17013                                 refreshUniformsPhong(uniforms, material);
17014                         } else if (material.isMeshStandardMaterial) {
17015                                 refreshUniformsCommon(uniforms, material);
17016
17017                                 if (material.isMeshPhysicalMaterial) {
17018                                         refreshUniformsPhysical(uniforms, material);
17019                                 } else {
17020                                         refreshUniformsStandard(uniforms, material);
17021                                 }
17022                         } else if (material.isMeshMatcapMaterial) {
17023                                 refreshUniformsCommon(uniforms, material);
17024                                 refreshUniformsMatcap(uniforms, material);
17025                         } else if (material.isMeshDepthMaterial) {
17026                                 refreshUniformsCommon(uniforms, material);
17027                                 refreshUniformsDepth(uniforms, material);
17028                         } else if (material.isMeshDistanceMaterial) {
17029                                 refreshUniformsCommon(uniforms, material);
17030                                 refreshUniformsDistance(uniforms, material);
17031                         } else if (material.isMeshNormalMaterial) {
17032                                 refreshUniformsCommon(uniforms, material);
17033                                 refreshUniformsNormal(uniforms, material);
17034                         } else if (material.isLineBasicMaterial) {
17035                                 refreshUniformsLine(uniforms, material);
17036
17037                                 if (material.isLineDashedMaterial) {
17038                                         refreshUniformsDash(uniforms, material);
17039                                 }
17040                         } else if (material.isPointsMaterial) {
17041                                 refreshUniformsPoints(uniforms, material, pixelRatio, height);
17042                         } else if (material.isSpriteMaterial) {
17043                                 refreshUniformsSprites(uniforms, material);
17044                         } else if (material.isShadowMaterial) {
17045                                 uniforms.color.value.copy(material.color);
17046                                 uniforms.opacity.value = material.opacity;
17047                         } else if (material.isShaderMaterial) {
17048                                 material.uniformsNeedUpdate = false; // #15581
17049                         }
17050                 }
17051
17052                 function refreshUniformsCommon(uniforms, material) {
17053                         uniforms.opacity.value = material.opacity;
17054
17055                         if (material.color) {
17056                                 uniforms.diffuse.value.copy(material.color);
17057                         }
17058
17059                         if (material.emissive) {
17060                                 uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
17061                         }
17062
17063                         if (material.map) {
17064                                 uniforms.map.value = material.map;
17065                         }
17066
17067                         if (material.alphaMap) {
17068                                 uniforms.alphaMap.value = material.alphaMap;
17069                         }
17070
17071                         if (material.specularMap) {
17072                                 uniforms.specularMap.value = material.specularMap;
17073                         }
17074
17075                         var envMap = properties.get(material).envMap;
17076
17077                         if (envMap) {
17078                                 uniforms.envMap.value = envMap;
17079                                 uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
17080                                 uniforms.reflectivity.value = material.reflectivity;
17081                                 uniforms.refractionRatio.value = material.refractionRatio;
17082
17083                                 var maxMipLevel = properties.get(envMap).__maxMipLevel;
17084
17085                                 if (maxMipLevel !== undefined) {
17086                                         uniforms.maxMipLevel.value = maxMipLevel;
17087                                 }
17088                         }
17089
17090                         if (material.lightMap) {
17091                                 uniforms.lightMap.value = material.lightMap;
17092                                 uniforms.lightMapIntensity.value = material.lightMapIntensity;
17093                         }
17094
17095                         if (material.aoMap) {
17096                                 uniforms.aoMap.value = material.aoMap;
17097                                 uniforms.aoMapIntensity.value = material.aoMapIntensity;
17098                         } // uv repeat and offset setting priorities
17099                         // 1. color map
17100                         // 2. specular map
17101                         // 3. displacementMap map
17102                         // 4. normal map
17103                         // 5. bump map
17104                         // 6. roughnessMap map
17105                         // 7. metalnessMap map
17106                         // 8. alphaMap map
17107                         // 9. emissiveMap map
17108                         // 10. clearcoat map
17109                         // 11. clearcoat normal map
17110                         // 12. clearcoat roughnessMap map
17111
17112
17113                         var uvScaleMap;
17114
17115                         if (material.map) {
17116                                 uvScaleMap = material.map;
17117                         } else if (material.specularMap) {
17118                                 uvScaleMap = material.specularMap;
17119                         } else if (material.displacementMap) {
17120                                 uvScaleMap = material.displacementMap;
17121                         } else if (material.normalMap) {
17122                                 uvScaleMap = material.normalMap;
17123                         } else if (material.bumpMap) {
17124                                 uvScaleMap = material.bumpMap;
17125                         } else if (material.roughnessMap) {
17126                                 uvScaleMap = material.roughnessMap;
17127                         } else if (material.metalnessMap) {
17128                                 uvScaleMap = material.metalnessMap;
17129                         } else if (material.alphaMap) {
17130                                 uvScaleMap = material.alphaMap;
17131                         } else if (material.emissiveMap) {
17132                                 uvScaleMap = material.emissiveMap;
17133                         } else if (material.clearcoatMap) {
17134                                 uvScaleMap = material.clearcoatMap;
17135                         } else if (material.clearcoatNormalMap) {
17136                                 uvScaleMap = material.clearcoatNormalMap;
17137                         } else if (material.clearcoatRoughnessMap) {
17138                                 uvScaleMap = material.clearcoatRoughnessMap;
17139                         }
17140
17141                         if (uvScaleMap !== undefined) {
17142                                 // backwards compatibility
17143                                 if (uvScaleMap.isWebGLRenderTarget) {
17144                                         uvScaleMap = uvScaleMap.texture;
17145                                 }
17146
17147                                 if (uvScaleMap.matrixAutoUpdate === true) {
17148                                         uvScaleMap.updateMatrix();
17149                                 }
17150
17151                                 uniforms.uvTransform.value.copy(uvScaleMap.matrix);
17152                         } // uv repeat and offset setting priorities for uv2
17153                         // 1. ao map
17154                         // 2. light map
17155
17156
17157                         var uv2ScaleMap;
17158
17159                         if (material.aoMap) {
17160                                 uv2ScaleMap = material.aoMap;
17161                         } else if (material.lightMap) {
17162                                 uv2ScaleMap = material.lightMap;
17163                         }
17164
17165                         if (uv2ScaleMap !== undefined) {
17166                                 // backwards compatibility
17167                                 if (uv2ScaleMap.isWebGLRenderTarget) {
17168                                         uv2ScaleMap = uv2ScaleMap.texture;
17169                                 }
17170
17171                                 if (uv2ScaleMap.matrixAutoUpdate === true) {
17172                                         uv2ScaleMap.updateMatrix();
17173                                 }
17174
17175                                 uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
17176                         }
17177                 }
17178
17179                 function refreshUniformsLine(uniforms, material) {
17180                         uniforms.diffuse.value.copy(material.color);
17181                         uniforms.opacity.value = material.opacity;
17182                 }
17183
17184                 function refreshUniformsDash(uniforms, material) {
17185                         uniforms.dashSize.value = material.dashSize;
17186                         uniforms.totalSize.value = material.dashSize + material.gapSize;
17187                         uniforms.scale.value = material.scale;
17188                 }
17189
17190                 function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
17191                         uniforms.diffuse.value.copy(material.color);
17192                         uniforms.opacity.value = material.opacity;
17193                         uniforms.size.value = material.size * pixelRatio;
17194                         uniforms.scale.value = height * 0.5;
17195
17196                         if (material.map) {
17197                                 uniforms.map.value = material.map;
17198                         }
17199
17200                         if (material.alphaMap) {
17201                                 uniforms.alphaMap.value = material.alphaMap;
17202                         } // uv repeat and offset setting priorities
17203                         // 1. color map
17204                         // 2. alpha map
17205
17206
17207                         var uvScaleMap;
17208
17209                         if (material.map) {
17210                                 uvScaleMap = material.map;
17211                         } else if (material.alphaMap) {
17212                                 uvScaleMap = material.alphaMap;
17213                         }
17214
17215                         if (uvScaleMap !== undefined) {
17216                                 if (uvScaleMap.matrixAutoUpdate === true) {
17217                                         uvScaleMap.updateMatrix();
17218                                 }
17219
17220                                 uniforms.uvTransform.value.copy(uvScaleMap.matrix);
17221                         }
17222                 }
17223
17224                 function refreshUniformsSprites(uniforms, material) {
17225                         uniforms.diffuse.value.copy(material.color);
17226                         uniforms.opacity.value = material.opacity;
17227                         uniforms.rotation.value = material.rotation;
17228
17229                         if (material.map) {
17230                                 uniforms.map.value = material.map;
17231                         }
17232
17233                         if (material.alphaMap) {
17234                                 uniforms.alphaMap.value = material.alphaMap;
17235                         } // uv repeat and offset setting priorities
17236                         // 1. color map
17237                         // 2. alpha map
17238
17239
17240                         var uvScaleMap;
17241
17242                         if (material.map) {
17243                                 uvScaleMap = material.map;
17244                         } else if (material.alphaMap) {
17245                                 uvScaleMap = material.alphaMap;
17246                         }
17247
17248                         if (uvScaleMap !== undefined) {
17249                                 if (uvScaleMap.matrixAutoUpdate === true) {
17250                                         uvScaleMap.updateMatrix();
17251                                 }
17252
17253                                 uniforms.uvTransform.value.copy(uvScaleMap.matrix);
17254                         }
17255                 }
17256
17257                 function refreshUniformsLambert(uniforms, material) {
17258                         if (material.emissiveMap) {
17259                                 uniforms.emissiveMap.value = material.emissiveMap;
17260                         }
17261                 }
17262
17263                 function refreshUniformsPhong(uniforms, material) {
17264                         uniforms.specular.value.copy(material.specular);
17265                         uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
17266
17267                         if (material.emissiveMap) {
17268                                 uniforms.emissiveMap.value = material.emissiveMap;
17269                         }
17270
17271                         if (material.bumpMap) {
17272                                 uniforms.bumpMap.value = material.bumpMap;
17273                                 uniforms.bumpScale.value = material.bumpScale;
17274                                 if (material.side === BackSide) uniforms.bumpScale.value *= -1;
17275                         }
17276
17277                         if (material.normalMap) {
17278                                 uniforms.normalMap.value = material.normalMap;
17279                                 uniforms.normalScale.value.copy(material.normalScale);
17280                                 if (material.side === BackSide) uniforms.normalScale.value.negate();
17281                         }
17282
17283                         if (material.displacementMap) {
17284                                 uniforms.displacementMap.value = material.displacementMap;
17285                                 uniforms.displacementScale.value = material.displacementScale;
17286                                 uniforms.displacementBias.value = material.displacementBias;
17287                         }
17288                 }
17289
17290                 function refreshUniformsToon(uniforms, material) {
17291                         if (material.gradientMap) {
17292                                 uniforms.gradientMap.value = material.gradientMap;
17293                         }
17294
17295                         if (material.emissiveMap) {
17296                                 uniforms.emissiveMap.value = material.emissiveMap;
17297                         }
17298
17299                         if (material.bumpMap) {
17300                                 uniforms.bumpMap.value = material.bumpMap;
17301                                 uniforms.bumpScale.value = material.bumpScale;
17302                                 if (material.side === BackSide) uniforms.bumpScale.value *= -1;
17303                         }
17304
17305                         if (material.normalMap) {
17306                                 uniforms.normalMap.value = material.normalMap;
17307                                 uniforms.normalScale.value.copy(material.normalScale);
17308                                 if (material.side === BackSide) uniforms.normalScale.value.negate();
17309                         }
17310
17311                         if (material.displacementMap) {
17312                                 uniforms.displacementMap.value = material.displacementMap;
17313                                 uniforms.displacementScale.value = material.displacementScale;
17314                                 uniforms.displacementBias.value = material.displacementBias;
17315                         }
17316                 }
17317
17318                 function refreshUniformsStandard(uniforms, material) {
17319                         uniforms.roughness.value = material.roughness;
17320                         uniforms.metalness.value = material.metalness;
17321
17322                         if (material.roughnessMap) {
17323                                 uniforms.roughnessMap.value = material.roughnessMap;
17324                         }
17325
17326                         if (material.metalnessMap) {
17327                                 uniforms.metalnessMap.value = material.metalnessMap;
17328                         }
17329
17330                         if (material.emissiveMap) {
17331                                 uniforms.emissiveMap.value = material.emissiveMap;
17332                         }
17333
17334                         if (material.bumpMap) {
17335                                 uniforms.bumpMap.value = material.bumpMap;
17336                                 uniforms.bumpScale.value = material.bumpScale;
17337                                 if (material.side === BackSide) uniforms.bumpScale.value *= -1;
17338                         }
17339
17340                         if (material.normalMap) {
17341                                 uniforms.normalMap.value = material.normalMap;
17342                                 uniforms.normalScale.value.copy(material.normalScale);
17343                                 if (material.side === BackSide) uniforms.normalScale.value.negate();
17344                         }
17345
17346                         if (material.displacementMap) {
17347                                 uniforms.displacementMap.value = material.displacementMap;
17348                                 uniforms.displacementScale.value = material.displacementScale;
17349                                 uniforms.displacementBias.value = material.displacementBias;
17350                         }
17351
17352                         var envMap = properties.get(material).envMap;
17353
17354                         if (envMap) {
17355                                 //uniforms.envMap.value = material.envMap; // part of uniforms common
17356                                 uniforms.envMapIntensity.value = material.envMapIntensity;
17357                         }
17358                 }
17359
17360                 function refreshUniformsPhysical(uniforms, material) {
17361                         refreshUniformsStandard(uniforms, material);
17362                         uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
17363
17364                         uniforms.clearcoat.value = material.clearcoat;
17365                         uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
17366                         if (material.sheen) uniforms.sheen.value.copy(material.sheen);
17367
17368                         if (material.clearcoatMap) {
17369                                 uniforms.clearcoatMap.value = material.clearcoatMap;
17370                         }
17371
17372                         if (material.clearcoatRoughnessMap) {
17373                                 uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
17374                         }
17375
17376                         if (material.clearcoatNormalMap) {
17377                                 uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
17378                                 uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
17379
17380                                 if (material.side === BackSide) {
17381                                         uniforms.clearcoatNormalScale.value.negate();
17382                                 }
17383                         }
17384
17385                         uniforms.transmission.value = material.transmission;
17386
17387                         if (material.transmissionMap) {
17388                                 uniforms.transmissionMap.value = material.transmissionMap;
17389                         }
17390                 }
17391
17392                 function refreshUniformsMatcap(uniforms, material) {
17393                         if (material.matcap) {
17394                                 uniforms.matcap.value = material.matcap;
17395                         }
17396
17397                         if (material.bumpMap) {
17398                                 uniforms.bumpMap.value = material.bumpMap;
17399                                 uniforms.bumpScale.value = material.bumpScale;
17400                                 if (material.side === BackSide) uniforms.bumpScale.value *= -1;
17401                         }
17402
17403                         if (material.normalMap) {
17404                                 uniforms.normalMap.value = material.normalMap;
17405                                 uniforms.normalScale.value.copy(material.normalScale);
17406                                 if (material.side === BackSide) uniforms.normalScale.value.negate();
17407                         }
17408
17409                         if (material.displacementMap) {
17410                                 uniforms.displacementMap.value = material.displacementMap;
17411                                 uniforms.displacementScale.value = material.displacementScale;
17412                                 uniforms.displacementBias.value = material.displacementBias;
17413                         }
17414                 }
17415
17416                 function refreshUniformsDepth(uniforms, material) {
17417                         if (material.displacementMap) {
17418                                 uniforms.displacementMap.value = material.displacementMap;
17419                                 uniforms.displacementScale.value = material.displacementScale;
17420                                 uniforms.displacementBias.value = material.displacementBias;
17421                         }
17422                 }
17423
17424                 function refreshUniformsDistance(uniforms, material) {
17425                         if (material.displacementMap) {
17426                                 uniforms.displacementMap.value = material.displacementMap;
17427                                 uniforms.displacementScale.value = material.displacementScale;
17428                                 uniforms.displacementBias.value = material.displacementBias;
17429                         }
17430
17431                         uniforms.referencePosition.value.copy(material.referencePosition);
17432                         uniforms.nearDistance.value = material.nearDistance;
17433                         uniforms.farDistance.value = material.farDistance;
17434                 }
17435
17436                 function refreshUniformsNormal(uniforms, material) {
17437                         if (material.bumpMap) {
17438                                 uniforms.bumpMap.value = material.bumpMap;
17439                                 uniforms.bumpScale.value = material.bumpScale;
17440                                 if (material.side === BackSide) uniforms.bumpScale.value *= -1;
17441                         }
17442
17443                         if (material.normalMap) {
17444                                 uniforms.normalMap.value = material.normalMap;
17445                                 uniforms.normalScale.value.copy(material.normalScale);
17446                                 if (material.side === BackSide) uniforms.normalScale.value.negate();
17447                         }
17448
17449                         if (material.displacementMap) {
17450                                 uniforms.displacementMap.value = material.displacementMap;
17451                                 uniforms.displacementScale.value = material.displacementScale;
17452                                 uniforms.displacementBias.value = material.displacementBias;
17453                         }
17454                 }
17455
17456                 return {
17457                         refreshFogUniforms: refreshFogUniforms,
17458                         refreshMaterialUniforms: refreshMaterialUniforms
17459                 };
17460         }
17461
17462         function createCanvasElement() {
17463                 var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
17464                 canvas.style.display = 'block';
17465                 return canvas;
17466         }
17467
17468         function WebGLRenderer(parameters) {
17469                 parameters = parameters || {};
17470
17471                 var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
17472                                 _context = parameters.context !== undefined ? parameters.context : null,
17473                                 _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
17474                                 _depth = parameters.depth !== undefined ? parameters.depth : true,
17475                                 _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
17476                                 _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
17477                                 _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
17478                                 _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
17479                                 _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
17480                                 _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
17481
17482                 var currentRenderList = null;
17483                 var currentRenderState = null; // public properties
17484
17485                 this.domElement = _canvas; // Debug configuration container
17486
17487                 this.debug = {
17488                         /**
17489                          * Enables error checking and reporting when shader programs are being compiled
17490                          * @type {boolean}
17491                          */
17492                         checkShaderErrors: true
17493                 }; // clearing
17494
17495                 this.autoClear = true;
17496                 this.autoClearColor = true;
17497                 this.autoClearDepth = true;
17498                 this.autoClearStencil = true; // scene graph
17499
17500                 this.sortObjects = true; // user-defined clipping
17501
17502                 this.clippingPlanes = [];
17503                 this.localClippingEnabled = false; // physically based shading
17504
17505                 this.gammaFactor = 2.0; // for backwards compatibility
17506
17507                 this.outputEncoding = LinearEncoding; // physical lights
17508
17509                 this.physicallyCorrectLights = false; // tone mapping
17510
17511                 this.toneMapping = NoToneMapping;
17512                 this.toneMappingExposure = 1.0; // morphs
17513
17514                 this.maxMorphTargets = 8;
17515                 this.maxMorphNormals = 4; // internal properties
17516
17517                 var _this = this;
17518
17519                 var _isContextLost = false; // internal state cache
17520
17521                 var _framebuffer = null;
17522                 var _currentActiveCubeFace = 0;
17523                 var _currentActiveMipmapLevel = 0;
17524                 var _currentRenderTarget = null;
17525                 var _currentFramebuffer = null;
17526
17527                 var _currentMaterialId = -1;
17528
17529                 var _currentCamera = null;
17530                 var _currentArrayCamera = null;
17531
17532                 var _currentViewport = new Vector4();
17533
17534                 var _currentScissor = new Vector4();
17535
17536                 var _currentScissorTest = null; //
17537
17538                 var _width = _canvas.width;
17539                 var _height = _canvas.height;
17540                 var _pixelRatio = 1;
17541                 var _opaqueSort = null;
17542                 var _transparentSort = null;
17543
17544                 var _viewport = new Vector4(0, 0, _width, _height);
17545
17546                 var _scissor = new Vector4(0, 0, _width, _height);
17547
17548                 var _scissorTest = false; // frustum
17549
17550                 var _frustum = new Frustum(); // clipping
17551
17552
17553                 var _clippingEnabled = false;
17554                 var _localClippingEnabled = false; // camera matrices cache
17555
17556                 var _projScreenMatrix = new Matrix4();
17557
17558                 var _vector3 = new Vector3();
17559
17560                 var _emptyScene = {
17561                         background: null,
17562                         fog: null,
17563                         environment: null,
17564                         overrideMaterial: null,
17565                         isScene: true
17566                 };
17567
17568                 function getTargetPixelRatio() {
17569                         return _currentRenderTarget === null ? _pixelRatio : 1;
17570                 } // initialize
17571
17572
17573                 var _gl = _context;
17574
17575                 function getContext(contextNames, contextAttributes) {
17576                         for (var i = 0; i < contextNames.length; i++) {
17577                                 var contextName = contextNames[i];
17578
17579                                 var context = _canvas.getContext(contextName, contextAttributes);
17580
17581                                 if (context !== null) return context;
17582                         }
17583
17584                         return null;
17585                 }
17586
17587                 try {
17588                         var contextAttributes = {
17589                                 alpha: _alpha,
17590                                 depth: _depth,
17591                                 stencil: _stencil,
17592                                 antialias: _antialias,
17593                                 premultipliedAlpha: _premultipliedAlpha,
17594                                 preserveDrawingBuffer: _preserveDrawingBuffer,
17595                                 powerPreference: _powerPreference,
17596                                 failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
17597                         }; // event listeners must be registered before WebGL context is created, see #12753
17598
17599                         _canvas.addEventListener('webglcontextlost', onContextLost, false);
17600
17601                         _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
17602
17603                         if (_gl === null) {
17604                                 var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
17605
17606                                 if (_this.isWebGL1Renderer === true) {
17607                                         contextNames.shift();
17608                                 }
17609
17610                                 _gl = getContext(contextNames, contextAttributes);
17611
17612                                 if (_gl === null) {
17613                                         if (getContext(contextNames)) {
17614                                                 throw new Error('Error creating WebGL context with your selected attributes.');
17615                                         } else {
17616                                                 throw new Error('Error creating WebGL context.');
17617                                         }
17618                                 }
17619                         } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
17620
17621
17622                         if (_gl.getShaderPrecisionFormat === undefined) {
17623                                 _gl.getShaderPrecisionFormat = function () {
17624                                         return {
17625                                                 'rangeMin': 1,
17626                                                 'rangeMax': 1,
17627                                                 'precision': 1
17628                                         };
17629                                 };
17630                         }
17631                 } catch (error) {
17632                         console.error('THREE.WebGLRenderer: ' + error.message);
17633                         throw error;
17634                 }
17635
17636                 var extensions, capabilities, state, info;
17637                 var properties, textures, cubemaps, attributes, geometries, objects;
17638                 var programCache, materials, renderLists, renderStates, clipping;
17639                 var background, morphtargets, bufferRenderer, indexedBufferRenderer;
17640                 var utils, bindingStates;
17641
17642                 function initGLContext() {
17643                         extensions = new WebGLExtensions(_gl);
17644                         capabilities = new WebGLCapabilities(_gl, extensions, parameters);
17645
17646                         if (capabilities.isWebGL2 === false) {
17647                                 extensions.get('WEBGL_depth_texture');
17648                                 extensions.get('OES_texture_float');
17649                                 extensions.get('OES_texture_half_float');
17650                                 extensions.get('OES_texture_half_float_linear');
17651                                 extensions.get('OES_standard_derivatives');
17652                                 extensions.get('OES_element_index_uint');
17653                                 extensions.get('OES_vertex_array_object');
17654                                 extensions.get('ANGLE_instanced_arrays');
17655                         }
17656
17657                         extensions.get('OES_texture_float_linear');
17658                         utils = new WebGLUtils(_gl, extensions, capabilities);
17659                         state = new WebGLState(_gl, extensions, capabilities);
17660                         state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
17661                         state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
17662                         info = new WebGLInfo(_gl);
17663                         properties = new WebGLProperties();
17664                         textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
17665                         cubemaps = new WebGLCubeMaps(_this);
17666                         attributes = new WebGLAttributes(_gl, capabilities);
17667                         bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
17668                         geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
17669                         objects = new WebGLObjects(_gl, geometries, attributes, info);
17670                         morphtargets = new WebGLMorphtargets(_gl);
17671                         clipping = new WebGLClipping(properties);
17672                         programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
17673                         materials = new WebGLMaterials(properties);
17674                         renderLists = new WebGLRenderLists(properties);
17675                         renderStates = new WebGLRenderStates(extensions, capabilities);
17676                         background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
17677                         bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
17678                         indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
17679                         info.programs = programCache.programs;
17680                         _this.capabilities = capabilities;
17681                         _this.extensions = extensions;
17682                         _this.properties = properties;
17683                         _this.renderLists = renderLists;
17684                         _this.state = state;
17685                         _this.info = info;
17686                 }
17687
17688                 initGLContext(); // xr
17689
17690                 var xr = new WebXRManager(_this, _gl);
17691                 this.xr = xr; // shadow map
17692
17693                 var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
17694                 this.shadowMap = shadowMap; // API
17695
17696                 this.getContext = function () {
17697                         return _gl;
17698                 };
17699
17700                 this.getContextAttributes = function () {
17701                         return _gl.getContextAttributes();
17702                 };
17703
17704                 this.forceContextLoss = function () {
17705                         var extension = extensions.get('WEBGL_lose_context');
17706                         if (extension) extension.loseContext();
17707                 };
17708
17709                 this.forceContextRestore = function () {
17710                         var extension = extensions.get('WEBGL_lose_context');
17711                         if (extension) extension.restoreContext();
17712                 };
17713
17714                 this.getPixelRatio = function () {
17715                         return _pixelRatio;
17716                 };
17717
17718                 this.setPixelRatio = function (value) {
17719                         if (value === undefined) return;
17720                         _pixelRatio = value;
17721                         this.setSize(_width, _height, false);
17722                 };
17723
17724                 this.getSize = function (target) {
17725                         if (target === undefined) {
17726                                 console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
17727                                 target = new Vector2();
17728                         }
17729
17730                         return target.set(_width, _height);
17731                 };
17732
17733                 this.setSize = function (width, height, updateStyle) {
17734                         if (xr.isPresenting) {
17735                                 console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
17736                                 return;
17737                         }
17738
17739                         _width = width;
17740                         _height = height;
17741                         _canvas.width = Math.floor(width * _pixelRatio);
17742                         _canvas.height = Math.floor(height * _pixelRatio);
17743
17744                         if (updateStyle !== false) {
17745                                 _canvas.style.width = width + 'px';
17746                                 _canvas.style.height = height + 'px';
17747                         }
17748
17749                         this.setViewport(0, 0, width, height);
17750                 };
17751
17752                 this.getDrawingBufferSize = function (target) {
17753                         if (target === undefined) {
17754                                 console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
17755                                 target = new Vector2();
17756                         }
17757
17758                         return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
17759                 };
17760
17761                 this.setDrawingBufferSize = function (width, height, pixelRatio) {
17762                         _width = width;
17763                         _height = height;
17764                         _pixelRatio = pixelRatio;
17765                         _canvas.width = Math.floor(width * pixelRatio);
17766                         _canvas.height = Math.floor(height * pixelRatio);
17767                         this.setViewport(0, 0, width, height);
17768                 };
17769
17770                 this.getCurrentViewport = function (target) {
17771                         if (target === undefined) {
17772                                 console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
17773                                 target = new Vector4();
17774                         }
17775
17776                         return target.copy(_currentViewport);
17777                 };
17778
17779                 this.getViewport = function (target) {
17780                         return target.copy(_viewport);
17781                 };
17782
17783                 this.setViewport = function (x, y, width, height) {
17784                         if (x.isVector4) {
17785                                 _viewport.set(x.x, x.y, x.z, x.w);
17786                         } else {
17787                                 _viewport.set(x, y, width, height);
17788                         }
17789
17790                         state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
17791                 };
17792
17793                 this.getScissor = function (target) {
17794                         return target.copy(_scissor);
17795                 };
17796
17797                 this.setScissor = function (x, y, width, height) {
17798                         if (x.isVector4) {
17799                                 _scissor.set(x.x, x.y, x.z, x.w);
17800                         } else {
17801                                 _scissor.set(x, y, width, height);
17802                         }
17803
17804                         state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
17805                 };
17806
17807                 this.getScissorTest = function () {
17808                         return _scissorTest;
17809                 };
17810
17811                 this.setScissorTest = function (boolean) {
17812                         state.setScissorTest(_scissorTest = boolean);
17813                 };
17814
17815                 this.setOpaqueSort = function (method) {
17816                         _opaqueSort = method;
17817                 };
17818
17819                 this.setTransparentSort = function (method) {
17820                         _transparentSort = method;
17821                 }; // Clearing
17822
17823
17824                 this.getClearColor = function () {
17825                         return background.getClearColor();
17826                 };
17827
17828                 this.setClearColor = function () {
17829                         background.setClearColor.apply(background, arguments);
17830                 };
17831
17832                 this.getClearAlpha = function () {
17833                         return background.getClearAlpha();
17834                 };
17835
17836                 this.setClearAlpha = function () {
17837                         background.setClearAlpha.apply(background, arguments);
17838                 };
17839
17840                 this.clear = function (color, depth, stencil) {
17841                         var bits = 0;
17842                         if (color === undefined || color) bits |= 16384;
17843                         if (depth === undefined || depth) bits |= 256;
17844                         if (stencil === undefined || stencil) bits |= 1024;
17845
17846                         _gl.clear(bits);
17847                 };
17848
17849                 this.clearColor = function () {
17850                         this.clear(true, false, false);
17851                 };
17852
17853                 this.clearDepth = function () {
17854                         this.clear(false, true, false);
17855                 };
17856
17857                 this.clearStencil = function () {
17858                         this.clear(false, false, true);
17859                 }; //
17860
17861
17862                 this.dispose = function () {
17863                         _canvas.removeEventListener('webglcontextlost', onContextLost, false);
17864
17865                         _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
17866
17867                         renderLists.dispose();
17868                         renderStates.dispose();
17869                         properties.dispose();
17870                         cubemaps.dispose();
17871                         objects.dispose();
17872                         bindingStates.dispose();
17873                         xr.dispose();
17874                         animation.stop();
17875                 }; // Events
17876
17877
17878                 function onContextLost(event) {
17879                         event.preventDefault();
17880                         console.log('THREE.WebGLRenderer: Context Lost.');
17881                         _isContextLost = true;
17882                 }
17883
17884                 function onContextRestore()
17885                 /* event */
17886                 {
17887                         console.log('THREE.WebGLRenderer: Context Restored.');
17888                         _isContextLost = false;
17889                         initGLContext();
17890                 }
17891
17892                 function onMaterialDispose(event) {
17893                         var material = event.target;
17894                         material.removeEventListener('dispose', onMaterialDispose);
17895                         deallocateMaterial(material);
17896                 } // Buffer deallocation
17897
17898
17899                 function deallocateMaterial(material) {
17900                         releaseMaterialProgramReference(material);
17901                         properties.remove(material);
17902                 }
17903
17904                 function releaseMaterialProgramReference(material) {
17905                         var programInfo = properties.get(material).program;
17906
17907                         if (programInfo !== undefined) {
17908                                 programCache.releaseProgram(programInfo);
17909                         }
17910                 } // Buffer rendering
17911
17912
17913                 function renderObjectImmediate(object, program) {
17914                         object.render(function (object) {
17915                                 _this.renderBufferImmediate(object, program);
17916                         });
17917                 }
17918
17919                 this.renderBufferImmediate = function (object, program) {
17920                         bindingStates.initAttributes();
17921                         var buffers = properties.get(object);
17922                         if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
17923                         if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
17924                         if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
17925                         if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
17926                         var programAttributes = program.getAttributes();
17927
17928                         if (object.hasPositions) {
17929                                 _gl.bindBuffer(34962, buffers.position);
17930
17931                                 _gl.bufferData(34962, object.positionArray, 35048);
17932
17933                                 bindingStates.enableAttribute(programAttributes.position);
17934
17935                                 _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
17936                         }
17937
17938                         if (object.hasNormals) {
17939                                 _gl.bindBuffer(34962, buffers.normal);
17940
17941                                 _gl.bufferData(34962, object.normalArray, 35048);
17942
17943                                 bindingStates.enableAttribute(programAttributes.normal);
17944
17945                                 _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
17946                         }
17947
17948                         if (object.hasUvs) {
17949                                 _gl.bindBuffer(34962, buffers.uv);
17950
17951                                 _gl.bufferData(34962, object.uvArray, 35048);
17952
17953                                 bindingStates.enableAttribute(programAttributes.uv);
17954
17955                                 _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
17956                         }
17957
17958                         if (object.hasColors) {
17959                                 _gl.bindBuffer(34962, buffers.color);
17960
17961                                 _gl.bufferData(34962, object.colorArray, 35048);
17962
17963                                 bindingStates.enableAttribute(programAttributes.color);
17964
17965                                 _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
17966                         }
17967
17968                         bindingStates.disableUnusedAttributes();
17969
17970                         _gl.drawArrays(4, 0, object.count);
17971
17972                         object.count = 0;
17973                 };
17974
17975                 this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
17976                         if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
17977
17978                         var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
17979                         var program = setProgram(camera, scene, material, object);
17980                         state.setMaterial(material, frontFaceCW); //
17981
17982                         var index = geometry.index;
17983                         var position = geometry.attributes.position; //
17984
17985                         if (index === null) {
17986                                 if (position === undefined || position.count === 0) return;
17987                         } else if (index.count === 0) {
17988                                 return;
17989                         } //
17990
17991
17992                         var rangeFactor = 1;
17993
17994                         if (material.wireframe === true) {
17995                                 index = geometries.getWireframeAttribute(geometry);
17996                                 rangeFactor = 2;
17997                         }
17998
17999                         if (material.morphTargets || material.morphNormals) {
18000                                 morphtargets.update(object, geometry, material, program);
18001                         }
18002
18003                         bindingStates.setup(object, material, program, geometry, index);
18004                         var attribute;
18005                         var renderer = bufferRenderer;
18006
18007                         if (index !== null) {
18008                                 attribute = attributes.get(index);
18009                                 renderer = indexedBufferRenderer;
18010                                 renderer.setIndex(attribute);
18011                         } //
18012
18013
18014                         var dataCount = index !== null ? index.count : position.count;
18015                         var rangeStart = geometry.drawRange.start * rangeFactor;
18016                         var rangeCount = geometry.drawRange.count * rangeFactor;
18017                         var groupStart = group !== null ? group.start * rangeFactor : 0;
18018                         var groupCount = group !== null ? group.count * rangeFactor : Infinity;
18019                         var drawStart = Math.max(rangeStart, groupStart);
18020                         var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
18021                         var drawCount = Math.max(0, drawEnd - drawStart + 1);
18022                         if (drawCount === 0) return; //
18023
18024                         if (object.isMesh) {
18025                                 if (material.wireframe === true) {
18026                                         state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
18027                                         renderer.setMode(1);
18028                                 } else {
18029                                         renderer.setMode(4);
18030                                 }
18031                         } else if (object.isLine) {
18032                                 var lineWidth = material.linewidth;
18033                                 if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
18034
18035                                 state.setLineWidth(lineWidth * getTargetPixelRatio());
18036
18037                                 if (object.isLineSegments) {
18038                                         renderer.setMode(1);
18039                                 } else if (object.isLineLoop) {
18040                                         renderer.setMode(2);
18041                                 } else {
18042                                         renderer.setMode(3);
18043                                 }
18044                         } else if (object.isPoints) {
18045                                 renderer.setMode(0);
18046                         } else if (object.isSprite) {
18047                                 renderer.setMode(4);
18048                         }
18049
18050                         if (object.isInstancedMesh) {
18051                                 renderer.renderInstances(drawStart, drawCount, object.count);
18052                         } else if (geometry.isInstancedBufferGeometry) {
18053                                 var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
18054                                 renderer.renderInstances(drawStart, drawCount, instanceCount);
18055                         } else {
18056                                 renderer.render(drawStart, drawCount);
18057                         }
18058                 }; // Compile
18059
18060
18061                 this.compile = function (scene, camera) {
18062                         currentRenderState = renderStates.get(scene, camera);
18063                         currentRenderState.init();
18064                         scene.traverseVisible(function (object) {
18065                                 if (object.isLight && object.layers.test(camera.layers)) {
18066                                         currentRenderState.pushLight(object);
18067
18068                                         if (object.castShadow) {
18069                                                 currentRenderState.pushShadow(object);
18070                                         }
18071                                 }
18072                         });
18073                         currentRenderState.setupLights(camera);
18074                         var compiled = new WeakMap();
18075                         scene.traverse(function (object) {
18076                                 var material = object.material;
18077
18078                                 if (material) {
18079                                         if (Array.isArray(material)) {
18080                                                 for (var i = 0; i < material.length; i++) {
18081                                                         var material2 = material[i];
18082
18083                                                         if (compiled.has(material2) === false) {
18084                                                                 initMaterial(material2, scene, object);
18085                                                                 compiled.set(material2);
18086                                                         }
18087                                                 }
18088                                         } else if (compiled.has(material) === false) {
18089                                                 initMaterial(material, scene, object);
18090                                                 compiled.set(material);
18091                                         }
18092                                 }
18093                         });
18094                 }; // Animation Loop
18095
18096
18097                 var onAnimationFrameCallback = null;
18098
18099                 function onAnimationFrame(time) {
18100                         if (xr.isPresenting) return;
18101                         if (onAnimationFrameCallback) onAnimationFrameCallback(time);
18102                 }
18103
18104                 var animation = new WebGLAnimation();
18105                 animation.setAnimationLoop(onAnimationFrame);
18106                 if (typeof window !== 'undefined') animation.setContext(window);
18107
18108                 this.setAnimationLoop = function (callback) {
18109                         onAnimationFrameCallback = callback;
18110                         xr.setAnimationLoop(callback);
18111                         callback === null ? animation.stop() : animation.start();
18112                 }; // Rendering
18113
18114
18115                 this.render = function (scene, camera) {
18116                         var renderTarget, forceClear;
18117
18118                         if (arguments[2] !== undefined) {
18119                                 console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
18120                                 renderTarget = arguments[2];
18121                         }
18122
18123                         if (arguments[3] !== undefined) {
18124                                 console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
18125                                 forceClear = arguments[3];
18126                         }
18127
18128                         if (camera !== undefined && camera.isCamera !== true) {
18129                                 console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
18130                                 return;
18131                         }
18132
18133                         if (_isContextLost === true) return; // reset caching for this frame
18134
18135                         bindingStates.resetDefaultState();
18136                         _currentMaterialId = -1;
18137                         _currentCamera = null; // update scene graph
18138
18139                         if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
18140
18141                         if (camera.parent === null) camera.updateMatrixWorld();
18142
18143                         if (xr.enabled === true && xr.isPresenting === true) {
18144                                 camera = xr.getCamera(camera);
18145                         } //
18146
18147
18148                         if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
18149                         currentRenderState = renderStates.get(scene, camera);
18150                         currentRenderState.init();
18151
18152                         _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
18153
18154                         _frustum.setFromProjectionMatrix(_projScreenMatrix);
18155
18156                         _localClippingEnabled = this.localClippingEnabled;
18157                         _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
18158                         currentRenderList = renderLists.get(scene, camera);
18159                         currentRenderList.init();
18160                         projectObject(scene, camera, 0, _this.sortObjects);
18161                         currentRenderList.finish();
18162
18163                         if (_this.sortObjects === true) {
18164                                 currentRenderList.sort(_opaqueSort, _transparentSort);
18165                         } //
18166
18167
18168                         if (_clippingEnabled === true) clipping.beginShadows();
18169                         var shadowsArray = currentRenderState.state.shadowsArray;
18170                         shadowMap.render(shadowsArray, scene, camera);
18171                         currentRenderState.setupLights(camera);
18172                         if (_clippingEnabled === true) clipping.endShadows(); //
18173
18174                         if (this.info.autoReset === true) this.info.reset();
18175
18176                         if (renderTarget !== undefined) {
18177                                 this.setRenderTarget(renderTarget);
18178                         } //
18179
18180
18181                         background.render(currentRenderList, scene, camera, forceClear); // render scene
18182
18183                         var opaqueObjects = currentRenderList.opaque;
18184                         var transparentObjects = currentRenderList.transparent;
18185                         if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
18186                         if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
18187
18188                         if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
18189
18190                         if (_currentRenderTarget !== null) {
18191                                 // Generate mipmap if we're using any kind of mipmap filtering
18192                                 textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
18193
18194                                 textures.updateMultisampleRenderTarget(_currentRenderTarget);
18195                         } // Ensure depth buffer writing is enabled so it can be cleared on next render
18196
18197
18198                         state.buffers.depth.setTest(true);
18199                         state.buffers.depth.setMask(true);
18200                         state.buffers.color.setMask(true);
18201                         state.setPolygonOffset(false); // _gl.finish();
18202
18203                         currentRenderList = null;
18204                         currentRenderState = null;
18205                 };
18206
18207                 function projectObject(object, camera, groupOrder, sortObjects) {
18208                         if (object.visible === false) return;
18209                         var visible = object.layers.test(camera.layers);
18210
18211                         if (visible) {
18212                                 if (object.isGroup) {
18213                                         groupOrder = object.renderOrder;
18214                                 } else if (object.isLOD) {
18215                                         if (object.autoUpdate === true) object.update(camera);
18216                                 } else if (object.isLight) {
18217                                         currentRenderState.pushLight(object);
18218
18219                                         if (object.castShadow) {
18220                                                 currentRenderState.pushShadow(object);
18221                                         }
18222                                 } else if (object.isSprite) {
18223                                         if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
18224                                                 if (sortObjects) {
18225                                                         _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
18226                                                 }
18227
18228                                                 var geometry = objects.update(object);
18229                                                 var material = object.material;
18230
18231                                                 if (material.visible) {
18232                                                         currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
18233                                                 }
18234                                         }
18235                                 } else if (object.isImmediateRenderObject) {
18236                                         if (sortObjects) {
18237                                                 _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
18238                                         }
18239
18240                                         currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
18241                                 } else if (object.isMesh || object.isLine || object.isPoints) {
18242                                         if (object.isSkinnedMesh) {
18243                                                 // update skeleton only once in a frame
18244                                                 if (object.skeleton.frame !== info.render.frame) {
18245                                                         object.skeleton.update();
18246                                                         object.skeleton.frame = info.render.frame;
18247                                                 }
18248                                         }
18249
18250                                         if (!object.frustumCulled || _frustum.intersectsObject(object)) {
18251                                                 if (sortObjects) {
18252                                                         _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
18253                                                 }
18254
18255                                                 var _geometry = objects.update(object);
18256
18257                                                 var _material = object.material;
18258
18259                                                 if (Array.isArray(_material)) {
18260                                                         var groups = _geometry.groups;
18261
18262                                                         for (var i = 0, l = groups.length; i < l; i++) {
18263                                                                 var group = groups[i];
18264                                                                 var groupMaterial = _material[group.materialIndex];
18265
18266                                                                 if (groupMaterial && groupMaterial.visible) {
18267                                                                         currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
18268                                                                 }
18269                                                         }
18270                                                 } else if (_material.visible) {
18271                                                         currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
18272                                                 }
18273                                         }
18274                                 }
18275                         }
18276
18277                         var children = object.children;
18278
18279                         for (var _i = 0, _l = children.length; _i < _l; _i++) {
18280                                 projectObject(children[_i], camera, groupOrder, sortObjects);
18281                         }
18282                 }
18283
18284                 function renderObjects(renderList, scene, camera) {
18285                         var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
18286
18287                         for (var i = 0, l = renderList.length; i < l; i++) {
18288                                 var renderItem = renderList[i];
18289                                 var object = renderItem.object;
18290                                 var geometry = renderItem.geometry;
18291                                 var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
18292                                 var group = renderItem.group;
18293
18294                                 if (camera.isArrayCamera) {
18295                                         _currentArrayCamera = camera;
18296                                         var cameras = camera.cameras;
18297
18298                                         for (var j = 0, jl = cameras.length; j < jl; j++) {
18299                                                 var camera2 = cameras[j];
18300
18301                                                 if (object.layers.test(camera2.layers)) {
18302                                                         state.viewport(_currentViewport.copy(camera2.viewport));
18303                                                         currentRenderState.setupLights(camera2);
18304                                                         renderObject(object, scene, camera2, geometry, material, group);
18305                                                 }
18306                                         }
18307                                 } else {
18308                                         _currentArrayCamera = null;
18309                                         renderObject(object, scene, camera, geometry, material, group);
18310                                 }
18311                         }
18312                 }
18313
18314                 function renderObject(object, scene, camera, geometry, material, group) {
18315                         object.onBeforeRender(_this, scene, camera, geometry, material, group);
18316                         currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
18317                         object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
18318                         object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
18319
18320                         if (object.isImmediateRenderObject) {
18321                                 var program = setProgram(camera, scene, material, object);
18322                                 state.setMaterial(material);
18323                                 bindingStates.reset();
18324                                 renderObjectImmediate(object, program);
18325                         } else {
18326                                 _this.renderBufferDirect(camera, scene, geometry, material, object, group);
18327                         }
18328
18329                         object.onAfterRender(_this, scene, camera, geometry, material, group);
18330                         currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
18331                 }
18332
18333                 function initMaterial(material, scene, object) {
18334                         if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
18335
18336                         var materialProperties = properties.get(material);
18337                         var lights = currentRenderState.state.lights;
18338                         var shadowsArray = currentRenderState.state.shadowsArray;
18339                         var lightsStateVersion = lights.state.version;
18340                         var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
18341                         var programCacheKey = programCache.getProgramCacheKey(parameters);
18342                         var program = materialProperties.program;
18343                         var programChange = true;
18344
18345                         if (program === undefined) {
18346                                 // new material
18347                                 material.addEventListener('dispose', onMaterialDispose);
18348                         } else if (program.cacheKey !== programCacheKey) {
18349                                 // changed glsl or parameters
18350                                 releaseMaterialProgramReference(material);
18351                         } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
18352                                 programChange = false;
18353                         } else if (parameters.shaderID !== undefined) {
18354                                 // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
18355                                 var environment = material.isMeshStandardMaterial ? scene.environment : null;
18356                                 materialProperties.envMap = cubemaps.get(material.envMap || environment);
18357                                 return;
18358                         } else {
18359                                 // only rebuild uniform list
18360                                 programChange = false;
18361                         }
18362
18363                         if (programChange) {
18364                                 parameters.uniforms = programCache.getUniforms(material);
18365                                 material.onBeforeCompile(parameters, _this);
18366                                 program = programCache.acquireProgram(parameters, programCacheKey);
18367                                 materialProperties.program = program;
18368                                 materialProperties.uniforms = parameters.uniforms;
18369                                 materialProperties.outputEncoding = parameters.outputEncoding;
18370                         }
18371
18372                         var uniforms = materialProperties.uniforms;
18373
18374                         if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
18375                                 materialProperties.numClippingPlanes = clipping.numPlanes;
18376                                 materialProperties.numIntersection = clipping.numIntersection;
18377                                 uniforms.clippingPlanes = clipping.uniform;
18378                         }
18379
18380                         materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
18381                         materialProperties.fog = scene.fog;
18382                         materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
18383
18384                         materialProperties.needsLights = materialNeedsLights(material);
18385                         materialProperties.lightsStateVersion = lightsStateVersion;
18386
18387                         if (materialProperties.needsLights) {
18388                                 // wire up the material to this renderer's lighting state
18389                                 uniforms.ambientLightColor.value = lights.state.ambient;
18390                                 uniforms.lightProbe.value = lights.state.probe;
18391                                 uniforms.directionalLights.value = lights.state.directional;
18392                                 uniforms.directionalLightShadows.value = lights.state.directionalShadow;
18393                                 uniforms.spotLights.value = lights.state.spot;
18394                                 uniforms.spotLightShadows.value = lights.state.spotShadow;
18395                                 uniforms.rectAreaLights.value = lights.state.rectArea;
18396                                 uniforms.ltc_1.value = lights.state.rectAreaLTC1;
18397                                 uniforms.ltc_2.value = lights.state.rectAreaLTC2;
18398                                 uniforms.pointLights.value = lights.state.point;
18399                                 uniforms.pointLightShadows.value = lights.state.pointShadow;
18400                                 uniforms.hemisphereLights.value = lights.state.hemi;
18401                                 uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
18402                                 uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
18403                                 uniforms.spotShadowMap.value = lights.state.spotShadowMap;
18404                                 uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
18405                                 uniforms.pointShadowMap.value = lights.state.pointShadowMap;
18406                                 uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
18407                         }
18408
18409                         var progUniforms = materialProperties.program.getUniforms();
18410                         var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
18411                         materialProperties.uniformsList = uniformsList;
18412                 }
18413
18414                 function setProgram(camera, scene, material, object) {
18415                         if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
18416
18417                         textures.resetTextureUnits();
18418                         var fog = scene.fog;
18419                         var environment = material.isMeshStandardMaterial ? scene.environment : null;
18420                         var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
18421                         var envMap = cubemaps.get(material.envMap || environment);
18422                         var materialProperties = properties.get(material);
18423                         var lights = currentRenderState.state.lights;
18424
18425                         if (_clippingEnabled === true) {
18426                                 if (_localClippingEnabled === true || camera !== _currentCamera) {
18427                                         var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
18428                                         // object instead of the material, once it becomes feasible
18429                                         // (#8465, #8379)
18430
18431                                         clipping.setState(material, camera, useCache);
18432                                 }
18433                         }
18434
18435                         if (material.version === materialProperties.__version) {
18436                                 if (material.fog && materialProperties.fog !== fog) {
18437                                         initMaterial(material, scene, object);
18438                                 } else if (materialProperties.environment !== environment) {
18439                                         initMaterial(material, scene, object);
18440                                 } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
18441                                         initMaterial(material, scene, object);
18442                                 } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
18443                                         initMaterial(material, scene, object);
18444                                 } else if (materialProperties.outputEncoding !== encoding) {
18445                                         initMaterial(material, scene, object);
18446                                 } else if (materialProperties.envMap !== envMap) {
18447                                         initMaterial(material, scene, object);
18448                                 }
18449                         } else {
18450                                 initMaterial(material, scene, object);
18451                                 materialProperties.__version = material.version;
18452                         }
18453
18454                         var refreshProgram = false;
18455                         var refreshMaterial = false;
18456                         var refreshLights = false;
18457                         var program = materialProperties.program,
18458                                         p_uniforms = program.getUniforms(),
18459                                         m_uniforms = materialProperties.uniforms;
18460
18461                         if (state.useProgram(program.program)) {
18462                                 refreshProgram = true;
18463                                 refreshMaterial = true;
18464                                 refreshLights = true;
18465                         }
18466
18467                         if (material.id !== _currentMaterialId) {
18468                                 _currentMaterialId = material.id;
18469                                 refreshMaterial = true;
18470                         }
18471
18472                         if (refreshProgram || _currentCamera !== camera) {
18473                                 p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
18474
18475                                 if (capabilities.logarithmicDepthBuffer) {
18476                                         p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
18477                                 }
18478
18479                                 if (_currentCamera !== camera) {
18480                                         _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
18481                                         // now, in case this material supports lights - or later, when
18482                                         // the next material that does gets activated:
18483
18484                                         refreshMaterial = true; // set to true on material change
18485
18486                                         refreshLights = true; // remains set until update done
18487                                 } // load material specific uniforms
18488                                 // (shader material also gets them for the sake of genericity)
18489
18490
18491                                 if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
18492                                         var uCamPos = p_uniforms.map.cameraPosition;
18493
18494                                         if (uCamPos !== undefined) {
18495                                                 uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
18496                                         }
18497                                 }
18498
18499                                 if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
18500                                         p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
18501                                 }
18502
18503                                 if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
18504                                         p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
18505                                 }
18506                         } // skinning uniforms must be set even if material didn't change
18507                         // auto-setting of texture unit for bone texture must go before other textures
18508                         // otherwise textures used for skinning can take over texture units reserved for other material textures
18509
18510
18511                         if (material.skinning) {
18512                                 p_uniforms.setOptional(_gl, object, 'bindMatrix');
18513                                 p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
18514                                 var skeleton = object.skeleton;
18515
18516                                 if (skeleton) {
18517                                         var bones = skeleton.bones;
18518
18519                                         if (capabilities.floatVertexTextures) {
18520                                                 if (skeleton.boneTexture === null) {
18521                                                         // layout (1 matrix = 4 pixels)
18522                                                         //                      RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
18523                                                         //      with    8x8     pixel texture max        16 bones * 4 pixels =  (8 * 8)
18524                                                         //                       16x16 pixel texture max         64 bones * 4 pixels = (16 * 16)
18525                                                         //                       32x32 pixel texture max        256 bones * 4 pixels = (32 * 32)
18526                                                         //                       64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
18527                                                         var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
18528
18529                                                         size = MathUtils.ceilPowerOfTwo(size);
18530                                                         size = Math.max(size, 4);
18531                                                         var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
18532
18533                                                         boneMatrices.set(skeleton.boneMatrices); // copy current values
18534
18535                                                         var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
18536                                                         skeleton.boneMatrices = boneMatrices;
18537                                                         skeleton.boneTexture = boneTexture;
18538                                                         skeleton.boneTextureSize = size;
18539                                                 }
18540
18541                                                 p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
18542                                                 p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
18543                                         } else {
18544                                                 p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
18545                                         }
18546                                 }
18547                         }
18548
18549                         if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
18550                                 materialProperties.receiveShadow = object.receiveShadow;
18551                                 p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
18552                         }
18553
18554                         if (refreshMaterial) {
18555                                 p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
18556
18557                                 if (materialProperties.needsLights) {
18558                                         // the current material requires lighting info
18559                                         // note: all lighting uniforms are always set correctly
18560                                         // they simply reference the renderer's state for their
18561                                         // values
18562                                         //
18563                                         // use the current material's .needsUpdate flags to set
18564                                         // the GL state when required
18565                                         markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
18566                                 } // refresh uniforms common to several materials
18567
18568
18569                                 if (fog && material.fog) {
18570                                         materials.refreshFogUniforms(m_uniforms, fog);
18571                                 }
18572
18573                                 materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
18574                                 WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
18575                         }
18576
18577                         if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
18578                                 WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
18579                                 material.uniformsNeedUpdate = false;
18580                         }
18581
18582                         if (material.isSpriteMaterial) {
18583                                 p_uniforms.setValue(_gl, 'center', object.center);
18584                         } // common matrices
18585
18586
18587                         p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
18588                         p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
18589                         p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
18590                         return program;
18591                 } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
18592
18593
18594                 function markUniformsLightsNeedsUpdate(uniforms, value) {
18595                         uniforms.ambientLightColor.needsUpdate = value;
18596                         uniforms.lightProbe.needsUpdate = value;
18597                         uniforms.directionalLights.needsUpdate = value;
18598                         uniforms.directionalLightShadows.needsUpdate = value;
18599                         uniforms.pointLights.needsUpdate = value;
18600                         uniforms.pointLightShadows.needsUpdate = value;
18601                         uniforms.spotLights.needsUpdate = value;
18602                         uniforms.spotLightShadows.needsUpdate = value;
18603                         uniforms.rectAreaLights.needsUpdate = value;
18604                         uniforms.hemisphereLights.needsUpdate = value;
18605                 }
18606
18607                 function materialNeedsLights(material) {
18608                         return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
18609                 } //
18610
18611
18612                 this.setFramebuffer = function (value) {
18613                         if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
18614                         _framebuffer = value;
18615                 };
18616
18617                 this.getActiveCubeFace = function () {
18618                         return _currentActiveCubeFace;
18619                 };
18620
18621                 this.getActiveMipmapLevel = function () {
18622                         return _currentActiveMipmapLevel;
18623                 };
18624
18625                 this.getRenderList = function () {
18626                         return currentRenderList;
18627                 };
18628
18629                 this.setRenderList = function (renderList) {
18630                         currentRenderList = renderList;
18631                 };
18632
18633                 this.getRenderState = function () {
18634                         return currentRenderState;
18635                 };
18636
18637                 this.setRenderState = function (renderState) {
18638                         currentRenderState = renderState;
18639                 };
18640
18641                 this.getRenderTarget = function () {
18642                         return _currentRenderTarget;
18643                 };
18644
18645                 this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
18646                         if (activeCubeFace === void 0) {
18647                                 activeCubeFace = 0;
18648                         }
18649
18650                         if (activeMipmapLevel === void 0) {
18651                                 activeMipmapLevel = 0;
18652                         }
18653
18654                         _currentRenderTarget = renderTarget;
18655                         _currentActiveCubeFace = activeCubeFace;
18656                         _currentActiveMipmapLevel = activeMipmapLevel;
18657
18658                         if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
18659                                 textures.setupRenderTarget(renderTarget);
18660                         }
18661
18662                         var framebuffer = _framebuffer;
18663                         var isCube = false;
18664
18665                         if (renderTarget) {
18666                                 var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
18667
18668                                 if (renderTarget.isWebGLCubeRenderTarget) {
18669                                         framebuffer = __webglFramebuffer[activeCubeFace];
18670                                         isCube = true;
18671                                 } else if (renderTarget.isWebGLMultisampleRenderTarget) {
18672                                         framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
18673                                 } else {
18674                                         framebuffer = __webglFramebuffer;
18675                                 }
18676
18677                                 _currentViewport.copy(renderTarget.viewport);
18678
18679                                 _currentScissor.copy(renderTarget.scissor);
18680
18681                                 _currentScissorTest = renderTarget.scissorTest;
18682                         } else {
18683                                 _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
18684
18685                                 _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
18686
18687                                 _currentScissorTest = _scissorTest;
18688                         }
18689
18690                         if (_currentFramebuffer !== framebuffer) {
18691                                 _gl.bindFramebuffer(36160, framebuffer);
18692
18693                                 _currentFramebuffer = framebuffer;
18694                         }
18695
18696                         state.viewport(_currentViewport);
18697                         state.scissor(_currentScissor);
18698                         state.setScissorTest(_currentScissorTest);
18699
18700                         if (isCube) {
18701                                 var textureProperties = properties.get(renderTarget.texture);
18702
18703                                 _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
18704                         }
18705                 };
18706
18707                 this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
18708                         if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
18709                                 console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
18710                                 return;
18711                         }
18712
18713                         var framebuffer = properties.get(renderTarget).__webglFramebuffer;
18714
18715                         if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
18716                                 framebuffer = framebuffer[activeCubeFaceIndex];
18717                         }
18718
18719                         if (framebuffer) {
18720                                 var restore = false;
18721
18722                                 if (framebuffer !== _currentFramebuffer) {
18723                                         _gl.bindFramebuffer(36160, framebuffer);
18724
18725                                         restore = true;
18726                                 }
18727
18728                                 try {
18729                                         var texture = renderTarget.texture;
18730                                         var textureFormat = texture.format;
18731                                         var textureType = texture.type;
18732
18733                                         if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
18734                                                 console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
18735                                                 return;
18736                                         }
18737
18738                                         if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
18739                                         !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
18740                                         !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
18741                                                 console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
18742                                                 return;
18743                                         }
18744
18745                                         if (_gl.checkFramebufferStatus(36160) === 36053) {
18746                                                 // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
18747                                                 if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
18748                                                         _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
18749                                                 }
18750                                         } else {
18751                                                 console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
18752                                         }
18753                                 } finally {
18754                                         if (restore) {
18755                                                 _gl.bindFramebuffer(36160, _currentFramebuffer);
18756                                         }
18757                                 }
18758                         }
18759                 };
18760
18761                 this.copyFramebufferToTexture = function (position, texture, level) {
18762                         if (level === void 0) {
18763                                 level = 0;
18764                         }
18765
18766                         var levelScale = Math.pow(2, -level);
18767                         var width = Math.floor(texture.image.width * levelScale);
18768                         var height = Math.floor(texture.image.height * levelScale);
18769                         var glFormat = utils.convert(texture.format);
18770                         textures.setTexture2D(texture, 0);
18771
18772                         _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
18773
18774                         state.unbindTexture();
18775                 };
18776
18777                 this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
18778                         if (level === void 0) {
18779                                 level = 0;
18780                         }
18781
18782                         var width = srcTexture.image.width;
18783                         var height = srcTexture.image.height;
18784                         var glFormat = utils.convert(dstTexture.format);
18785                         var glType = utils.convert(dstTexture.type);
18786                         textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
18787                         // parameters, make sure they are correct for the dstTexture
18788
18789                         _gl.pixelStorei(37440, dstTexture.flipY);
18790
18791                         _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
18792
18793                         _gl.pixelStorei(3317, dstTexture.unpackAlignment);
18794
18795                         if (srcTexture.isDataTexture) {
18796                                 _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
18797                         } else {
18798                                 if (srcTexture.isCompressedTexture) {
18799                                         _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
18800                                 } else {
18801                                         _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
18802                                 }
18803                         } // Generate mipmaps only when copying level 0
18804
18805
18806                         if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
18807                         state.unbindTexture();
18808                 };
18809
18810                 this.initTexture = function (texture) {
18811                         textures.setTexture2D(texture, 0);
18812                         state.unbindTexture();
18813                 };
18814
18815                 if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
18816                         __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
18817                                 detail: this
18818                         })); // eslint-disable-line no-undef
18819
18820                 }
18821         }
18822
18823         function WebGL1Renderer(parameters) {
18824                 WebGLRenderer.call(this, parameters);
18825         }
18826
18827         WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
18828                 constructor: WebGL1Renderer,
18829                 isWebGL1Renderer: true
18830         });
18831
18832         var FogExp2 = /*#__PURE__*/function () {
18833                 function FogExp2(color, density) {
18834                         Object.defineProperty(this, 'isFogExp2', {
18835                                 value: true
18836                         });
18837                         this.name = '';
18838                         this.color = new Color(color);
18839                         this.density = density !== undefined ? density : 0.00025;
18840                 }
18841
18842                 var _proto = FogExp2.prototype;
18843
18844                 _proto.clone = function clone() {
18845                         return new FogExp2(this.color, this.density);
18846                 };
18847
18848                 _proto.toJSON = function toJSON()
18849                 /* meta */
18850                 {
18851                         return {
18852                                 type: 'FogExp2',
18853                                 color: this.color.getHex(),
18854                                 density: this.density
18855                         };
18856                 };
18857
18858                 return FogExp2;
18859         }();
18860
18861         var Fog = /*#__PURE__*/function () {
18862                 function Fog(color, near, far) {
18863                         Object.defineProperty(this, 'isFog', {
18864                                 value: true
18865                         });
18866                         this.name = '';
18867                         this.color = new Color(color);
18868                         this.near = near !== undefined ? near : 1;
18869                         this.far = far !== undefined ? far : 1000;
18870                 }
18871
18872                 var _proto = Fog.prototype;
18873
18874                 _proto.clone = function clone() {
18875                         return new Fog(this.color, this.near, this.far);
18876                 };
18877
18878                 _proto.toJSON = function toJSON()
18879                 /* meta */
18880                 {
18881                         return {
18882                                 type: 'Fog',
18883                                 color: this.color.getHex(),
18884                                 near: this.near,
18885                                 far: this.far
18886                         };
18887                 };
18888
18889                 return Fog;
18890         }();
18891
18892         var Scene = /*#__PURE__*/function (_Object3D) {
18893                 _inheritsLoose(Scene, _Object3D);
18894
18895                 function Scene() {
18896                         var _this;
18897
18898                         _this = _Object3D.call(this) || this;
18899                         Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
18900                                 value: true
18901                         });
18902                         _this.type = 'Scene';
18903                         _this.background = null;
18904                         _this.environment = null;
18905                         _this.fog = null;
18906                         _this.overrideMaterial = null;
18907                         _this.autoUpdate = true; // checked by the renderer
18908
18909                         if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
18910                                 __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
18911                                         detail: _assertThisInitialized(_this)
18912                                 })); // eslint-disable-line no-undef
18913
18914                         }
18915
18916                         return _this;
18917                 }
18918
18919                 var _proto = Scene.prototype;
18920
18921                 _proto.copy = function copy(source, recursive) {
18922                         _Object3D.prototype.copy.call(this, source, recursive);
18923
18924                         if (source.background !== null) this.background = source.background.clone();
18925                         if (source.environment !== null) this.environment = source.environment.clone();
18926                         if (source.fog !== null) this.fog = source.fog.clone();
18927                         if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
18928                         this.autoUpdate = source.autoUpdate;
18929                         this.matrixAutoUpdate = source.matrixAutoUpdate;
18930                         return this;
18931                 };
18932
18933                 _proto.toJSON = function toJSON(meta) {
18934                         var data = _Object3D.prototype.toJSON.call(this, meta);
18935
18936                         if (this.background !== null) data.object.background = this.background.toJSON(meta);
18937                         if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
18938                         if (this.fog !== null) data.object.fog = this.fog.toJSON();
18939                         return data;
18940                 };
18941
18942                 return Scene;
18943         }(Object3D);
18944
18945         function InterleavedBuffer(array, stride) {
18946                 this.array = array;
18947                 this.stride = stride;
18948                 this.count = array !== undefined ? array.length / stride : 0;
18949                 this.usage = StaticDrawUsage;
18950                 this.updateRange = {
18951                         offset: 0,
18952                         count: -1
18953                 };
18954                 this.version = 0;
18955                 this.uuid = MathUtils.generateUUID();
18956         }
18957
18958         Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
18959                 set: function set(value) {
18960                         if (value === true) this.version++;
18961                 }
18962         });
18963         Object.assign(InterleavedBuffer.prototype, {
18964                 isInterleavedBuffer: true,
18965                 onUploadCallback: function onUploadCallback() {},
18966                 setUsage: function setUsage(value) {
18967                         this.usage = value;
18968                         return this;
18969                 },
18970                 copy: function copy(source) {
18971                         this.array = new source.array.constructor(source.array);
18972                         this.count = source.count;
18973                         this.stride = source.stride;
18974                         this.usage = source.usage;
18975                         return this;
18976                 },
18977                 copyAt: function copyAt(index1, attribute, index2) {
18978                         index1 *= this.stride;
18979                         index2 *= attribute.stride;
18980
18981                         for (var i = 0, l = this.stride; i < l; i++) {
18982                                 this.array[index1 + i] = attribute.array[index2 + i];
18983                         }
18984
18985                         return this;
18986                 },
18987                 set: function set(value, offset) {
18988                         if (offset === void 0) {
18989                                 offset = 0;
18990                         }
18991
18992                         this.array.set(value, offset);
18993                         return this;
18994                 },
18995                 clone: function clone(data) {
18996                         if (data.arrayBuffers === undefined) {
18997                                 data.arrayBuffers = {};
18998                         }
18999
19000                         if (this.array.buffer._uuid === undefined) {
19001                                 this.array.buffer._uuid = MathUtils.generateUUID();
19002                         }
19003
19004                         if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
19005                                 data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
19006                         }
19007
19008                         var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
19009                         var ib = new InterleavedBuffer(array, this.stride);
19010                         ib.setUsage(this.usage);
19011                         return ib;
19012                 },
19013                 onUpload: function onUpload(callback) {
19014                         this.onUploadCallback = callback;
19015                         return this;
19016                 },
19017                 toJSON: function toJSON(data) {
19018                         if (data.arrayBuffers === undefined) {
19019                                 data.arrayBuffers = {};
19020                         } // generate UUID for array buffer if necessary
19021
19022
19023                         if (this.array.buffer._uuid === undefined) {
19024                                 this.array.buffer._uuid = MathUtils.generateUUID();
19025                         }
19026
19027                         if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
19028                                 data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
19029                         } //
19030
19031
19032                         return {
19033                                 uuid: this.uuid,
19034                                 buffer: this.array.buffer._uuid,
19035                                 type: this.array.constructor.name,
19036                                 stride: this.stride
19037                         };
19038                 }
19039         });
19040
19041         var _vector$6 = new Vector3();
19042
19043         function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
19044                 this.name = '';
19045                 this.data = interleavedBuffer;
19046                 this.itemSize = itemSize;
19047                 this.offset = offset;
19048                 this.normalized = normalized === true;
19049         }
19050
19051         Object.defineProperties(InterleavedBufferAttribute.prototype, {
19052                 count: {
19053                         get: function get() {
19054                                 return this.data.count;
19055                         }
19056                 },
19057                 array: {
19058                         get: function get() {
19059                                 return this.data.array;
19060                         }
19061                 },
19062                 needsUpdate: {
19063                         set: function set(value) {
19064                                 this.data.needsUpdate = value;
19065                         }
19066                 }
19067         });
19068         Object.assign(InterleavedBufferAttribute.prototype, {
19069                 isInterleavedBufferAttribute: true,
19070                 applyMatrix4: function applyMatrix4(m) {
19071                         for (var i = 0, l = this.data.count; i < l; i++) {
19072                                 _vector$6.x = this.getX(i);
19073                                 _vector$6.y = this.getY(i);
19074                                 _vector$6.z = this.getZ(i);
19075
19076                                 _vector$6.applyMatrix4(m);
19077
19078                                 this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
19079                         }
19080
19081                         return this;
19082                 },
19083                 setX: function setX(index, x) {
19084                         this.data.array[index * this.data.stride + this.offset] = x;
19085                         return this;
19086                 },
19087                 setY: function setY(index, y) {
19088                         this.data.array[index * this.data.stride + this.offset + 1] = y;
19089                         return this;
19090                 },
19091                 setZ: function setZ(index, z) {
19092                         this.data.array[index * this.data.stride + this.offset + 2] = z;
19093                         return this;
19094                 },
19095                 setW: function setW(index, w) {
19096                         this.data.array[index * this.data.stride + this.offset + 3] = w;
19097                         return this;
19098                 },
19099                 getX: function getX(index) {
19100                         return this.data.array[index * this.data.stride + this.offset];
19101                 },
19102                 getY: function getY(index) {
19103                         return this.data.array[index * this.data.stride + this.offset + 1];
19104                 },
19105                 getZ: function getZ(index) {
19106                         return this.data.array[index * this.data.stride + this.offset + 2];
19107                 },
19108                 getW: function getW(index) {
19109                         return this.data.array[index * this.data.stride + this.offset + 3];
19110                 },
19111                 setXY: function setXY(index, x, y) {
19112                         index = index * this.data.stride + this.offset;
19113                         this.data.array[index + 0] = x;
19114                         this.data.array[index + 1] = y;
19115                         return this;
19116                 },
19117                 setXYZ: function setXYZ(index, x, y, z) {
19118                         index = index * this.data.stride + this.offset;
19119                         this.data.array[index + 0] = x;
19120                         this.data.array[index + 1] = y;
19121                         this.data.array[index + 2] = z;
19122                         return this;
19123                 },
19124                 setXYZW: function setXYZW(index, x, y, z, w) {
19125                         index = index * this.data.stride + this.offset;
19126                         this.data.array[index + 0] = x;
19127                         this.data.array[index + 1] = y;
19128                         this.data.array[index + 2] = z;
19129                         this.data.array[index + 3] = w;
19130                         return this;
19131                 },
19132                 clone: function clone(data) {
19133                         if (data === undefined) {
19134                                 console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
19135                                 var array = [];
19136
19137                                 for (var i = 0; i < this.count; i++) {
19138                                         var index = i * this.data.stride + this.offset;
19139
19140                                         for (var j = 0; j < this.itemSize; j++) {
19141                                                 array.push(this.data.array[index + j]);
19142                                         }
19143                                 }
19144
19145                                 return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
19146                         } else {
19147                                 if (data.interleavedBuffers === undefined) {
19148                                         data.interleavedBuffers = {};
19149                                 }
19150
19151                                 if (data.interleavedBuffers[this.data.uuid] === undefined) {
19152                                         data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
19153                                 }
19154
19155                                 return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
19156                         }
19157                 },
19158                 toJSON: function toJSON(data) {
19159                         if (data === undefined) {
19160                                 console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
19161                                 var array = [];
19162
19163                                 for (var i = 0; i < this.count; i++) {
19164                                         var index = i * this.data.stride + this.offset;
19165
19166                                         for (var j = 0; j < this.itemSize; j++) {
19167                                                 array.push(this.data.array[index + j]);
19168                                         }
19169                                 } // deinterleave data and save it as an ordinary buffer attribute for now
19170
19171
19172                                 return {
19173                                         itemSize: this.itemSize,
19174                                         type: this.array.constructor.name,
19175                                         array: array,
19176                                         normalized: this.normalized
19177                                 };
19178                         } else {
19179                                 // save as true interlaved attribtue
19180                                 if (data.interleavedBuffers === undefined) {
19181                                         data.interleavedBuffers = {};
19182                                 }
19183
19184                                 if (data.interleavedBuffers[this.data.uuid] === undefined) {
19185                                         data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
19186                                 }
19187
19188                                 return {
19189                                         isInterleavedBufferAttribute: true,
19190                                         itemSize: this.itemSize,
19191                                         data: this.data.uuid,
19192                                         offset: this.offset,
19193                                         normalized: this.normalized
19194                                 };
19195                         }
19196                 }
19197         });
19198
19199         /**
19200          * parameters = {
19201          *      color: <hex>,
19202          *      map: new THREE.Texture( <Image> ),
19203          *      alphaMap: new THREE.Texture( <Image> ),
19204          *      rotation: <float>,
19205          *      sizeAttenuation: <bool>
19206          * }
19207          */
19208
19209         function SpriteMaterial(parameters) {
19210                 Material.call(this);
19211                 this.type = 'SpriteMaterial';
19212                 this.color = new Color(0xffffff);
19213                 this.map = null;
19214                 this.alphaMap = null;
19215                 this.rotation = 0;
19216                 this.sizeAttenuation = true;
19217                 this.transparent = true;
19218                 this.setValues(parameters);
19219         }
19220
19221         SpriteMaterial.prototype = Object.create(Material.prototype);
19222         SpriteMaterial.prototype.constructor = SpriteMaterial;
19223         SpriteMaterial.prototype.isSpriteMaterial = true;
19224
19225         SpriteMaterial.prototype.copy = function (source) {
19226                 Material.prototype.copy.call(this, source);
19227                 this.color.copy(source.color);
19228                 this.map = source.map;
19229                 this.alphaMap = source.alphaMap;
19230                 this.rotation = source.rotation;
19231                 this.sizeAttenuation = source.sizeAttenuation;
19232                 return this;
19233         };
19234
19235         var _geometry;
19236
19237         var _intersectPoint = new Vector3();
19238
19239         var _worldScale = new Vector3();
19240
19241         var _mvPosition = new Vector3();
19242
19243         var _alignedPosition = new Vector2();
19244
19245         var _rotatedPosition = new Vector2();
19246
19247         var _viewWorldMatrix = new Matrix4();
19248
19249         var _vA$1 = new Vector3();
19250
19251         var _vB$1 = new Vector3();
19252
19253         var _vC$1 = new Vector3();
19254
19255         var _uvA$1 = new Vector2();
19256
19257         var _uvB$1 = new Vector2();
19258
19259         var _uvC$1 = new Vector2();
19260
19261         function Sprite(material) {
19262                 Object3D.call(this);
19263                 this.type = 'Sprite';
19264
19265                 if (_geometry === undefined) {
19266                         _geometry = new BufferGeometry();
19267                         var float32Array = new Float32Array([-0.5, -0.5, 0, 0, 0, 0.5, -0.5, 0, 1, 0, 0.5, 0.5, 0, 1, 1, -0.5, 0.5, 0, 0, 1]);
19268                         var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
19269
19270                         _geometry.setIndex([0, 1, 2, 0, 2, 3]);
19271
19272                         _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
19273
19274                         _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
19275                 }
19276
19277                 this.geometry = _geometry;
19278                 this.material = material !== undefined ? material : new SpriteMaterial();
19279                 this.center = new Vector2(0.5, 0.5);
19280         }
19281
19282         Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
19283                 constructor: Sprite,
19284                 isSprite: true,
19285                 raycast: function raycast(raycaster, intersects) {
19286                         if (raycaster.camera === null) {
19287                                 console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
19288                         }
19289
19290                         _worldScale.setFromMatrixScale(this.matrixWorld);
19291
19292                         _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
19293
19294                         this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
19295
19296                         _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
19297
19298                         if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
19299                                 _worldScale.multiplyScalar(-_mvPosition.z);
19300                         }
19301
19302                         var rotation = this.material.rotation;
19303                         var sin, cos;
19304
19305                         if (rotation !== 0) {
19306                                 cos = Math.cos(rotation);
19307                                 sin = Math.sin(rotation);
19308                         }
19309
19310                         var center = this.center;
19311                         transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
19312                         transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
19313                         transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
19314
19315                         _uvA$1.set(0, 0);
19316
19317                         _uvB$1.set(1, 0);
19318
19319                         _uvC$1.set(1, 1); // check first triangle
19320
19321
19322                         var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
19323
19324                         if (intersect === null) {
19325                                 // check second triangle
19326                                 transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
19327
19328                                 _uvB$1.set(0, 1);
19329
19330                                 intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
19331
19332                                 if (intersect === null) {
19333                                         return;
19334                                 }
19335                         }
19336
19337                         var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
19338                         if (distance < raycaster.near || distance > raycaster.far) return;
19339                         intersects.push({
19340                                 distance: distance,
19341                                 point: _intersectPoint.clone(),
19342                                 uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
19343                                 face: null,
19344                                 object: this
19345                         });
19346                 },
19347                 copy: function copy(source) {
19348                         Object3D.prototype.copy.call(this, source);
19349                         if (source.center !== undefined) this.center.copy(source.center);
19350                         this.material = source.material;
19351                         return this;
19352                 }
19353         });
19354
19355         function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
19356                 // compute position in camera space
19357                 _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
19358
19359
19360                 if (sin !== undefined) {
19361                         _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
19362                         _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
19363                 } else {
19364                         _rotatedPosition.copy(_alignedPosition);
19365                 }
19366
19367                 vertexPosition.copy(mvPosition);
19368                 vertexPosition.x += _rotatedPosition.x;
19369                 vertexPosition.y += _rotatedPosition.y; // transform to world space
19370
19371                 vertexPosition.applyMatrix4(_viewWorldMatrix);
19372         }
19373
19374         var _v1$4 = new Vector3();
19375
19376         var _v2$2 = new Vector3();
19377
19378         function LOD() {
19379                 Object3D.call(this);
19380                 this._currentLevel = 0;
19381                 this.type = 'LOD';
19382                 Object.defineProperties(this, {
19383                         levels: {
19384                                 enumerable: true,
19385                                 value: []
19386                         }
19387                 });
19388                 this.autoUpdate = true;
19389         }
19390
19391         LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
19392                 constructor: LOD,
19393                 isLOD: true,
19394                 copy: function copy(source) {
19395                         Object3D.prototype.copy.call(this, source, false);
19396                         var levels = source.levels;
19397
19398                         for (var i = 0, l = levels.length; i < l; i++) {
19399                                 var level = levels[i];
19400                                 this.addLevel(level.object.clone(), level.distance);
19401                         }
19402
19403                         this.autoUpdate = source.autoUpdate;
19404                         return this;
19405                 },
19406                 addLevel: function addLevel(object, distance) {
19407                         if (distance === void 0) {
19408                                 distance = 0;
19409                         }
19410
19411                         distance = Math.abs(distance);
19412                         var levels = this.levels;
19413                         var l;
19414
19415                         for (l = 0; l < levels.length; l++) {
19416                                 if (distance < levels[l].distance) {
19417                                         break;
19418                                 }
19419                         }
19420
19421                         levels.splice(l, 0, {
19422                                 distance: distance,
19423                                 object: object
19424                         });
19425                         this.add(object);
19426                         return this;
19427                 },
19428                 getCurrentLevel: function getCurrentLevel() {
19429                         return this._currentLevel;
19430                 },
19431                 getObjectForDistance: function getObjectForDistance(distance) {
19432                         var levels = this.levels;
19433
19434                         if (levels.length > 0) {
19435                                 var i, l;
19436
19437                                 for (i = 1, l = levels.length; i < l; i++) {
19438                                         if (distance < levels[i].distance) {
19439                                                 break;
19440                                         }
19441                                 }
19442
19443                                 return levels[i - 1].object;
19444                         }
19445
19446                         return null;
19447                 },
19448                 raycast: function raycast(raycaster, intersects) {
19449                         var levels = this.levels;
19450
19451                         if (levels.length > 0) {
19452                                 _v1$4.setFromMatrixPosition(this.matrixWorld);
19453
19454                                 var distance = raycaster.ray.origin.distanceTo(_v1$4);
19455                                 this.getObjectForDistance(distance).raycast(raycaster, intersects);
19456                         }
19457                 },
19458                 update: function update(camera) {
19459                         var levels = this.levels;
19460
19461                         if (levels.length > 1) {
19462                                 _v1$4.setFromMatrixPosition(camera.matrixWorld);
19463
19464                                 _v2$2.setFromMatrixPosition(this.matrixWorld);
19465
19466                                 var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
19467                                 levels[0].object.visible = true;
19468                                 var i, l;
19469
19470                                 for (i = 1, l = levels.length; i < l; i++) {
19471                                         if (distance >= levels[i].distance) {
19472                                                 levels[i - 1].object.visible = false;
19473                                                 levels[i].object.visible = true;
19474                                         } else {
19475                                                 break;
19476                                         }
19477                                 }
19478
19479                                 this._currentLevel = i - 1;
19480
19481                                 for (; i < l; i++) {
19482                                         levels[i].object.visible = false;
19483                                 }
19484                         }
19485                 },
19486                 toJSON: function toJSON(meta) {
19487                         var data = Object3D.prototype.toJSON.call(this, meta);
19488                         if (this.autoUpdate === false) data.object.autoUpdate = false;
19489                         data.object.levels = [];
19490                         var levels = this.levels;
19491
19492                         for (var i = 0, l = levels.length; i < l; i++) {
19493                                 var level = levels[i];
19494                                 data.object.levels.push({
19495                                         object: level.object.uuid,
19496                                         distance: level.distance
19497                                 });
19498                         }
19499
19500                         return data;
19501                 }
19502         });
19503
19504         function SkinnedMesh(geometry, material) {
19505                 if (geometry && geometry.isGeometry) {
19506                         console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
19507                 }
19508
19509                 Mesh.call(this, geometry, material);
19510                 this.type = 'SkinnedMesh';
19511                 this.bindMode = 'attached';
19512                 this.bindMatrix = new Matrix4();
19513                 this.bindMatrixInverse = new Matrix4();
19514         }
19515
19516         SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
19517                 constructor: SkinnedMesh,
19518                 isSkinnedMesh: true,
19519                 copy: function copy(source) {
19520                         Mesh.prototype.copy.call(this, source);
19521                         this.bindMode = source.bindMode;
19522                         this.bindMatrix.copy(source.bindMatrix);
19523                         this.bindMatrixInverse.copy(source.bindMatrixInverse);
19524                         this.skeleton = source.skeleton;
19525                         return this;
19526                 },
19527                 bind: function bind(skeleton, bindMatrix) {
19528                         this.skeleton = skeleton;
19529
19530                         if (bindMatrix === undefined) {
19531                                 this.updateMatrixWorld(true);
19532                                 this.skeleton.calculateInverses();
19533                                 bindMatrix = this.matrixWorld;
19534                         }
19535
19536                         this.bindMatrix.copy(bindMatrix);
19537                         this.bindMatrixInverse.copy(bindMatrix).invert();
19538                 },
19539                 pose: function pose() {
19540                         this.skeleton.pose();
19541                 },
19542                 normalizeSkinWeights: function normalizeSkinWeights() {
19543                         var vector = new Vector4();
19544                         var skinWeight = this.geometry.attributes.skinWeight;
19545
19546                         for (var i = 0, l = skinWeight.count; i < l; i++) {
19547                                 vector.x = skinWeight.getX(i);
19548                                 vector.y = skinWeight.getY(i);
19549                                 vector.z = skinWeight.getZ(i);
19550                                 vector.w = skinWeight.getW(i);
19551                                 var scale = 1.0 / vector.manhattanLength();
19552
19553                                 if (scale !== Infinity) {
19554                                         vector.multiplyScalar(scale);
19555                                 } else {
19556                                         vector.set(1, 0, 0, 0); // do something reasonable
19557                                 }
19558
19559                                 skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
19560                         }
19561                 },
19562                 updateMatrixWorld: function updateMatrixWorld(force) {
19563                         Mesh.prototype.updateMatrixWorld.call(this, force);
19564
19565                         if (this.bindMode === 'attached') {
19566                                 this.bindMatrixInverse.copy(this.matrixWorld).invert();
19567                         } else if (this.bindMode === 'detached') {
19568                                 this.bindMatrixInverse.copy(this.bindMatrix).invert();
19569                         } else {
19570                                 console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
19571                         }
19572                 },
19573                 boneTransform: function () {
19574                         var basePosition = new Vector3();
19575                         var skinIndex = new Vector4();
19576                         var skinWeight = new Vector4();
19577                         var vector = new Vector3();
19578                         var matrix = new Matrix4();
19579                         return function (index, target) {
19580                                 var skeleton = this.skeleton;
19581                                 var geometry = this.geometry;
19582                                 skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
19583                                 skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
19584                                 basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
19585                                 target.set(0, 0, 0);
19586
19587                                 for (var i = 0; i < 4; i++) {
19588                                         var weight = skinWeight.getComponent(i);
19589
19590                                         if (weight !== 0) {
19591                                                 var boneIndex = skinIndex.getComponent(i);
19592                                                 matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
19593                                                 target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
19594                                         }
19595                                 }
19596
19597                                 return target.applyMatrix4(this.bindMatrixInverse);
19598                         };
19599                 }()
19600         });
19601
19602         function Bone() {
19603                 Object3D.call(this);
19604                 this.type = 'Bone';
19605         }
19606
19607         Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
19608                 constructor: Bone,
19609                 isBone: true
19610         });
19611
19612         var _offsetMatrix = new Matrix4();
19613
19614         var _identityMatrix = new Matrix4();
19615
19616         function Skeleton(bones, boneInverses) {
19617                 if (bones === void 0) {
19618                         bones = [];
19619                 }
19620
19621                 if (boneInverses === void 0) {
19622                         boneInverses = [];
19623                 }
19624
19625                 this.uuid = MathUtils.generateUUID();
19626                 this.bones = bones.slice(0);
19627                 this.boneInverses = boneInverses;
19628                 this.boneMatrices = null;
19629                 this.boneTexture = null;
19630                 this.boneTextureSize = 0;
19631                 this.frame = -1;
19632                 this.init();
19633         }
19634
19635         Object.assign(Skeleton.prototype, {
19636                 init: function init() {
19637                         var bones = this.bones;
19638                         var boneInverses = this.boneInverses;
19639                         this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
19640
19641                         if (boneInverses.length === 0) {
19642                                 this.calculateInverses();
19643                         } else {
19644                                 // handle special case
19645                                 if (bones.length !== boneInverses.length) {
19646                                         console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
19647                                         this.boneInverses = [];
19648
19649                                         for (var i = 0, il = this.bones.length; i < il; i++) {
19650                                                 this.boneInverses.push(new Matrix4());
19651                                         }
19652                                 }
19653                         }
19654                 },
19655                 calculateInverses: function calculateInverses() {
19656                         this.boneInverses.length = 0;
19657
19658                         for (var i = 0, il = this.bones.length; i < il; i++) {
19659                                 var inverse = new Matrix4();
19660
19661                                 if (this.bones[i]) {
19662                                         inverse.copy(this.bones[i].matrixWorld).invert();
19663                                 }
19664
19665                                 this.boneInverses.push(inverse);
19666                         }
19667                 },
19668                 pose: function pose() {
19669                         // recover the bind-time world matrices
19670                         for (var i = 0, il = this.bones.length; i < il; i++) {
19671                                 var bone = this.bones[i];
19672
19673                                 if (bone) {
19674                                         bone.matrixWorld.copy(this.boneInverses[i]).invert();
19675                                 }
19676                         } // compute the local matrices, positions, rotations and scales
19677
19678
19679                         for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
19680                                 var _bone = this.bones[_i];
19681
19682                                 if (_bone) {
19683                                         if (_bone.parent && _bone.parent.isBone) {
19684                                                 _bone.matrix.copy(_bone.parent.matrixWorld).invert();
19685
19686                                                 _bone.matrix.multiply(_bone.matrixWorld);
19687                                         } else {
19688                                                 _bone.matrix.copy(_bone.matrixWorld);
19689                                         }
19690
19691                                         _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
19692                                 }
19693                         }
19694                 },
19695                 update: function update() {
19696                         var bones = this.bones;
19697                         var boneInverses = this.boneInverses;
19698                         var boneMatrices = this.boneMatrices;
19699                         var boneTexture = this.boneTexture; // flatten bone matrices to array
19700
19701                         for (var i = 0, il = bones.length; i < il; i++) {
19702                                 // compute the offset between the current and the original transform
19703                                 var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
19704
19705                                 _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
19706
19707                                 _offsetMatrix.toArray(boneMatrices, i * 16);
19708                         }
19709
19710                         if (boneTexture !== null) {
19711                                 boneTexture.needsUpdate = true;
19712                         }
19713                 },
19714                 clone: function clone() {
19715                         return new Skeleton(this.bones, this.boneInverses);
19716                 },
19717                 getBoneByName: function getBoneByName(name) {
19718                         for (var i = 0, il = this.bones.length; i < il; i++) {
19719                                 var bone = this.bones[i];
19720
19721                                 if (bone.name === name) {
19722                                         return bone;
19723                                 }
19724                         }
19725
19726                         return undefined;
19727                 },
19728                 dispose: function dispose() {
19729                         if (this.boneTexture !== null) {
19730                                 this.boneTexture.dispose();
19731                                 this.boneTexture = null;
19732                         }
19733                 },
19734                 fromJSON: function fromJSON(json, bones) {
19735                         this.uuid = json.uuid;
19736
19737                         for (var i = 0, l = json.bones.length; i < l; i++) {
19738                                 var uuid = json.bones[i];
19739                                 var bone = bones[uuid];
19740
19741                                 if (bone === undefined) {
19742                                         console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
19743                                         bone = new Bone();
19744                                 }
19745
19746                                 this.bones.push(bone);
19747                                 this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
19748                         }
19749
19750                         this.init();
19751                         return this;
19752                 },
19753                 toJSON: function toJSON() {
19754                         var data = {
19755                                 metadata: {
19756                                         version: 4.5,
19757                                         type: 'Skeleton',
19758                                         generator: 'Skeleton.toJSON'
19759                                 },
19760                                 bones: [],
19761                                 boneInverses: []
19762                         };
19763                         data.uuid = this.uuid;
19764                         var bones = this.bones;
19765                         var boneInverses = this.boneInverses;
19766
19767                         for (var i = 0, l = bones.length; i < l; i++) {
19768                                 var bone = bones[i];
19769                                 data.bones.push(bone.uuid);
19770                                 var boneInverse = boneInverses[i];
19771                                 data.boneInverses.push(boneInverse.toArray());
19772                         }
19773
19774                         return data;
19775                 }
19776         });
19777
19778         var _instanceLocalMatrix = new Matrix4();
19779
19780         var _instanceWorldMatrix = new Matrix4();
19781
19782         var _instanceIntersects = [];
19783
19784         var _mesh = new Mesh();
19785
19786         function InstancedMesh(geometry, material, count) {
19787                 Mesh.call(this, geometry, material);
19788                 this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
19789                 this.instanceColor = null;
19790                 this.count = count;
19791                 this.frustumCulled = false;
19792         }
19793
19794         InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
19795                 constructor: InstancedMesh,
19796                 isInstancedMesh: true,
19797                 copy: function copy(source) {
19798                         Mesh.prototype.copy.call(this, source);
19799                         this.instanceMatrix.copy(source.instanceMatrix);
19800                         this.count = source.count;
19801                         return this;
19802                 },
19803                 getColorAt: function getColorAt(index, color) {
19804                         color.fromArray(this.instanceColor.array, index * 3);
19805                 },
19806                 getMatrixAt: function getMatrixAt(index, matrix) {
19807                         matrix.fromArray(this.instanceMatrix.array, index * 16);
19808                 },
19809                 raycast: function raycast(raycaster, intersects) {
19810                         var matrixWorld = this.matrixWorld;
19811                         var raycastTimes = this.count;
19812                         _mesh.geometry = this.geometry;
19813                         _mesh.material = this.material;
19814                         if (_mesh.material === undefined) return;
19815
19816                         for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
19817                                 // calculate the world matrix for each instance
19818                                 this.getMatrixAt(instanceId, _instanceLocalMatrix);
19819
19820                                 _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
19821
19822
19823                                 _mesh.matrixWorld = _instanceWorldMatrix;
19824
19825                                 _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
19826
19827
19828                                 for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
19829                                         var intersect = _instanceIntersects[i];
19830                                         intersect.instanceId = instanceId;
19831                                         intersect.object = this;
19832                                         intersects.push(intersect);
19833                                 }
19834
19835                                 _instanceIntersects.length = 0;
19836                         }
19837                 },
19838                 setColorAt: function setColorAt(index, color) {
19839                         if (this.instanceColor === null) {
19840                                 this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
19841                         }
19842
19843                         color.toArray(this.instanceColor.array, index * 3);
19844                 },
19845                 setMatrixAt: function setMatrixAt(index, matrix) {
19846                         matrix.toArray(this.instanceMatrix.array, index * 16);
19847                 },
19848                 updateMorphTargets: function updateMorphTargets() {}
19849         });
19850
19851         /**
19852          * parameters = {
19853          *      color: <hex>,
19854          *      opacity: <float>,
19855          *
19856          *      linewidth: <float>,
19857          *      linecap: "round",
19858          *      linejoin: "round"
19859          * }
19860          */
19861
19862         function LineBasicMaterial(parameters) {
19863                 Material.call(this);
19864                 this.type = 'LineBasicMaterial';
19865                 this.color = new Color(0xffffff);
19866                 this.linewidth = 1;
19867                 this.linecap = 'round';
19868                 this.linejoin = 'round';
19869                 this.morphTargets = false;
19870                 this.setValues(parameters);
19871         }
19872
19873         LineBasicMaterial.prototype = Object.create(Material.prototype);
19874         LineBasicMaterial.prototype.constructor = LineBasicMaterial;
19875         LineBasicMaterial.prototype.isLineBasicMaterial = true;
19876
19877         LineBasicMaterial.prototype.copy = function (source) {
19878                 Material.prototype.copy.call(this, source);
19879                 this.color.copy(source.color);
19880                 this.linewidth = source.linewidth;
19881                 this.linecap = source.linecap;
19882                 this.linejoin = source.linejoin;
19883                 this.morphTargets = source.morphTargets;
19884                 return this;
19885         };
19886
19887         var _start = new Vector3();
19888
19889         var _end = new Vector3();
19890
19891         var _inverseMatrix$1 = new Matrix4();
19892
19893         var _ray$1 = new Ray();
19894
19895         var _sphere$2 = new Sphere();
19896
19897         function Line(geometry, material, mode) {
19898                 if (mode === 1) {
19899                         console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
19900                 }
19901
19902                 Object3D.call(this);
19903                 this.type = 'Line';
19904                 this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
19905                 this.material = material !== undefined ? material : new LineBasicMaterial();
19906                 this.updateMorphTargets();
19907         }
19908
19909         Line.prototype = Object.assign(Object.create(Object3D.prototype), {
19910                 constructor: Line,
19911                 isLine: true,
19912                 copy: function copy(source) {
19913                         Object3D.prototype.copy.call(this, source);
19914                         this.material = source.material;
19915                         this.geometry = source.geometry;
19916                         return this;
19917                 },
19918                 computeLineDistances: function computeLineDistances() {
19919                         var geometry = this.geometry;
19920
19921                         if (geometry.isBufferGeometry) {
19922                                 // we assume non-indexed geometry
19923                                 if (geometry.index === null) {
19924                                         var positionAttribute = geometry.attributes.position;
19925                                         var lineDistances = [0];
19926
19927                                         for (var i = 1, l = positionAttribute.count; i < l; i++) {
19928                                                 _start.fromBufferAttribute(positionAttribute, i - 1);
19929
19930                                                 _end.fromBufferAttribute(positionAttribute, i);
19931
19932                                                 lineDistances[i] = lineDistances[i - 1];
19933                                                 lineDistances[i] += _start.distanceTo(_end);
19934                                         }
19935
19936                                         geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
19937                                 } else {
19938                                         console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
19939                                 }
19940                         } else if (geometry.isGeometry) {
19941                                 var vertices = geometry.vertices;
19942                                 var _lineDistances = geometry.lineDistances;
19943                                 _lineDistances[0] = 0;
19944
19945                                 for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
19946                                         _lineDistances[_i] = _lineDistances[_i - 1];
19947                                         _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
19948                                 }
19949                         }
19950
19951                         return this;
19952                 },
19953                 raycast: function raycast(raycaster, intersects) {
19954                         var geometry = this.geometry;
19955                         var matrixWorld = this.matrixWorld;
19956                         var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
19957
19958                         if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
19959
19960                         _sphere$2.copy(geometry.boundingSphere);
19961
19962                         _sphere$2.applyMatrix4(matrixWorld);
19963
19964                         _sphere$2.radius += threshold;
19965                         if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
19966
19967                         _inverseMatrix$1.copy(matrixWorld).invert();
19968
19969                         _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
19970
19971                         var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
19972                         var localThresholdSq = localThreshold * localThreshold;
19973                         var vStart = new Vector3();
19974                         var vEnd = new Vector3();
19975                         var interSegment = new Vector3();
19976                         var interRay = new Vector3();
19977                         var step = this.isLineSegments ? 2 : 1;
19978
19979                         if (geometry.isBufferGeometry) {
19980                                 var index = geometry.index;
19981                                 var attributes = geometry.attributes;
19982                                 var positionAttribute = attributes.position;
19983
19984                                 if (index !== null) {
19985                                         var indices = index.array;
19986
19987                                         for (var i = 0, l = indices.length - 1; i < l; i += step) {
19988                                                 var a = indices[i];
19989                                                 var b = indices[i + 1];
19990                                                 vStart.fromBufferAttribute(positionAttribute, a);
19991                                                 vEnd.fromBufferAttribute(positionAttribute, b);
19992
19993                                                 var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
19994
19995                                                 if (distSq > localThresholdSq) continue;
19996                                                 interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
19997
19998                                                 var distance = raycaster.ray.origin.distanceTo(interRay);
19999                                                 if (distance < raycaster.near || distance > raycaster.far) continue;
20000                                                 intersects.push({
20001                                                         distance: distance,
20002                                                         // What do we want? intersection point on the ray or on the segment??
20003                                                         // point: raycaster.ray.at( distance ),
20004                                                         point: interSegment.clone().applyMatrix4(this.matrixWorld),
20005                                                         index: i,
20006                                                         face: null,
20007                                                         faceIndex: null,
20008                                                         object: this
20009                                                 });
20010                                         }
20011                                 } else {
20012                                         for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
20013                                                 vStart.fromBufferAttribute(positionAttribute, _i2);
20014                                                 vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
20015
20016                                                 var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
20017
20018                                                 if (_distSq > localThresholdSq) continue;
20019                                                 interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
20020
20021                                                 var _distance = raycaster.ray.origin.distanceTo(interRay);
20022
20023                                                 if (_distance < raycaster.near || _distance > raycaster.far) continue;
20024                                                 intersects.push({
20025                                                         distance: _distance,
20026                                                         // What do we want? intersection point on the ray or on the segment??
20027                                                         // point: raycaster.ray.at( distance ),
20028                                                         point: interSegment.clone().applyMatrix4(this.matrixWorld),
20029                                                         index: _i2,
20030                                                         face: null,
20031                                                         faceIndex: null,
20032                                                         object: this
20033                                                 });
20034                                         }
20035                                 }
20036                         } else if (geometry.isGeometry) {
20037                                 var vertices = geometry.vertices;
20038                                 var nbVertices = vertices.length;
20039
20040                                 for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
20041                                         var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
20042
20043                                         if (_distSq2 > localThresholdSq) continue;
20044                                         interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
20045
20046                                         var _distance2 = raycaster.ray.origin.distanceTo(interRay);
20047
20048                                         if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
20049                                         intersects.push({
20050                                                 distance: _distance2,
20051                                                 // What do we want? intersection point on the ray or on the segment??
20052                                                 // point: raycaster.ray.at( distance ),
20053                                                 point: interSegment.clone().applyMatrix4(this.matrixWorld),
20054                                                 index: _i3,
20055                                                 face: null,
20056                                                 faceIndex: null,
20057                                                 object: this
20058                                         });
20059                                 }
20060                         }
20061                 },
20062                 updateMorphTargets: function updateMorphTargets() {
20063                         var geometry = this.geometry;
20064
20065                         if (geometry.isBufferGeometry) {
20066                                 var morphAttributes = geometry.morphAttributes;
20067                                 var keys = Object.keys(morphAttributes);
20068
20069                                 if (keys.length > 0) {
20070                                         var morphAttribute = morphAttributes[keys[0]];
20071
20072                                         if (morphAttribute !== undefined) {
20073                                                 this.morphTargetInfluences = [];
20074                                                 this.morphTargetDictionary = {};
20075
20076                                                 for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
20077                                                         var name = morphAttribute[m].name || String(m);
20078                                                         this.morphTargetInfluences.push(0);
20079                                                         this.morphTargetDictionary[name] = m;
20080                                                 }
20081                                         }
20082                                 }
20083                         } else {
20084                                 var morphTargets = geometry.morphTargets;
20085
20086                                 if (morphTargets !== undefined && morphTargets.length > 0) {
20087                                         console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
20088                                 }
20089                         }
20090                 }
20091         });
20092
20093         var _start$1 = new Vector3();
20094
20095         var _end$1 = new Vector3();
20096
20097         function LineSegments(geometry, material) {
20098                 Line.call(this, geometry, material);
20099                 this.type = 'LineSegments';
20100         }
20101
20102         LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
20103                 constructor: LineSegments,
20104                 isLineSegments: true,
20105                 computeLineDistances: function computeLineDistances() {
20106                         var geometry = this.geometry;
20107
20108                         if (geometry.isBufferGeometry) {
20109                                 // we assume non-indexed geometry
20110                                 if (geometry.index === null) {
20111                                         var positionAttribute = geometry.attributes.position;
20112                                         var lineDistances = [];
20113
20114                                         for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
20115                                                 _start$1.fromBufferAttribute(positionAttribute, i);
20116
20117                                                 _end$1.fromBufferAttribute(positionAttribute, i + 1);
20118
20119                                                 lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
20120                                                 lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
20121                                         }
20122
20123                                         geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
20124                                 } else {
20125                                         console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
20126                                 }
20127                         } else if (geometry.isGeometry) {
20128                                 var vertices = geometry.vertices;
20129                                 var _lineDistances = geometry.lineDistances;
20130
20131                                 for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
20132                                         _start$1.copy(vertices[_i]);
20133
20134                                         _end$1.copy(vertices[_i + 1]);
20135
20136                                         _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
20137                                         _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
20138                                 }
20139                         }
20140
20141                         return this;
20142                 }
20143         });
20144
20145         function LineLoop(geometry, material) {
20146                 Line.call(this, geometry, material);
20147                 this.type = 'LineLoop';
20148         }
20149
20150         LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
20151                 constructor: LineLoop,
20152                 isLineLoop: true
20153         });
20154
20155         /**
20156          * parameters = {
20157          *      color: <hex>,
20158          *      opacity: <float>,
20159          *      map: new THREE.Texture( <Image> ),
20160          *      alphaMap: new THREE.Texture( <Image> ),
20161          *
20162          *      size: <float>,
20163          *      sizeAttenuation: <bool>
20164          *
20165          *      morphTargets: <bool>
20166          * }
20167          */
20168
20169         function PointsMaterial(parameters) {
20170                 Material.call(this);
20171                 this.type = 'PointsMaterial';
20172                 this.color = new Color(0xffffff);
20173                 this.map = null;
20174                 this.alphaMap = null;
20175                 this.size = 1;
20176                 this.sizeAttenuation = true;
20177                 this.morphTargets = false;
20178                 this.setValues(parameters);
20179         }
20180
20181         PointsMaterial.prototype = Object.create(Material.prototype);
20182         PointsMaterial.prototype.constructor = PointsMaterial;
20183         PointsMaterial.prototype.isPointsMaterial = true;
20184
20185         PointsMaterial.prototype.copy = function (source) {
20186                 Material.prototype.copy.call(this, source);
20187                 this.color.copy(source.color);
20188                 this.map = source.map;
20189                 this.alphaMap = source.alphaMap;
20190                 this.size = source.size;
20191                 this.sizeAttenuation = source.sizeAttenuation;
20192                 this.morphTargets = source.morphTargets;
20193                 return this;
20194         };
20195
20196         var _inverseMatrix$2 = new Matrix4();
20197
20198         var _ray$2 = new Ray();
20199
20200         var _sphere$3 = new Sphere();
20201
20202         var _position$1 = new Vector3();
20203
20204         function Points(geometry, material) {
20205                 Object3D.call(this);
20206                 this.type = 'Points';
20207                 this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
20208                 this.material = material !== undefined ? material : new PointsMaterial();
20209                 this.updateMorphTargets();
20210         }
20211
20212         Points.prototype = Object.assign(Object.create(Object3D.prototype), {
20213                 constructor: Points,
20214                 isPoints: true,
20215                 copy: function copy(source) {
20216                         Object3D.prototype.copy.call(this, source);
20217                         this.material = source.material;
20218                         this.geometry = source.geometry;
20219                         return this;
20220                 },
20221                 raycast: function raycast(raycaster, intersects) {
20222                         var geometry = this.geometry;
20223                         var matrixWorld = this.matrixWorld;
20224                         var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
20225
20226                         if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
20227
20228                         _sphere$3.copy(geometry.boundingSphere);
20229
20230                         _sphere$3.applyMatrix4(matrixWorld);
20231
20232                         _sphere$3.radius += threshold;
20233                         if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
20234
20235                         _inverseMatrix$2.copy(matrixWorld).invert();
20236
20237                         _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
20238
20239                         var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
20240                         var localThresholdSq = localThreshold * localThreshold;
20241
20242                         if (geometry.isBufferGeometry) {
20243                                 var index = geometry.index;
20244                                 var attributes = geometry.attributes;
20245                                 var positionAttribute = attributes.position;
20246
20247                                 if (index !== null) {
20248                                         var indices = index.array;
20249
20250                                         for (var i = 0, il = indices.length; i < il; i++) {
20251                                                 var a = indices[i];
20252
20253                                                 _position$1.fromBufferAttribute(positionAttribute, a);
20254
20255                                                 testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
20256                                         }
20257                                 } else {
20258                                         for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
20259                                                 _position$1.fromBufferAttribute(positionAttribute, _i);
20260
20261                                                 testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
20262                                         }
20263                                 }
20264                         } else {
20265                                 var vertices = geometry.vertices;
20266
20267                                 for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
20268                                         testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
20269                                 }
20270                         }
20271                 },
20272                 updateMorphTargets: function updateMorphTargets() {
20273                         var geometry = this.geometry;
20274
20275                         if (geometry.isBufferGeometry) {
20276                                 var morphAttributes = geometry.morphAttributes;
20277                                 var keys = Object.keys(morphAttributes);
20278
20279                                 if (keys.length > 0) {
20280                                         var morphAttribute = morphAttributes[keys[0]];
20281
20282                                         if (morphAttribute !== undefined) {
20283                                                 this.morphTargetInfluences = [];
20284                                                 this.morphTargetDictionary = {};
20285
20286                                                 for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
20287                                                         var name = morphAttribute[m].name || String(m);
20288                                                         this.morphTargetInfluences.push(0);
20289                                                         this.morphTargetDictionary[name] = m;
20290                                                 }
20291                                         }
20292                                 }
20293                         } else {
20294                                 var morphTargets = geometry.morphTargets;
20295
20296                                 if (morphTargets !== undefined && morphTargets.length > 0) {
20297                                         console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
20298                                 }
20299                         }
20300                 }
20301         });
20302
20303         function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
20304                 var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
20305
20306                 if (rayPointDistanceSq < localThresholdSq) {
20307                         var intersectPoint = new Vector3();
20308
20309                         _ray$2.closestPointToPoint(point, intersectPoint);
20310
20311                         intersectPoint.applyMatrix4(matrixWorld);
20312                         var distance = raycaster.ray.origin.distanceTo(intersectPoint);
20313                         if (distance < raycaster.near || distance > raycaster.far) return;
20314                         intersects.push({
20315                                 distance: distance,
20316                                 distanceToRay: Math.sqrt(rayPointDistanceSq),
20317                                 point: intersectPoint,
20318                                 index: index,
20319                                 face: null,
20320                                 object: object
20321                         });
20322                 }
20323         }
20324
20325         function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
20326                 Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
20327                 this.format = format !== undefined ? format : RGBFormat;
20328                 this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
20329                 this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
20330                 this.generateMipmaps = false;
20331                 var scope = this;
20332
20333                 function updateVideo() {
20334                         scope.needsUpdate = true;
20335                         video.requestVideoFrameCallback(updateVideo);
20336                 }
20337
20338                 if ('requestVideoFrameCallback' in video) {
20339                         video.requestVideoFrameCallback(updateVideo);
20340                 }
20341         }
20342
20343         VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
20344                 constructor: VideoTexture,
20345                 clone: function clone() {
20346                         return new this.constructor(this.image).copy(this);
20347                 },
20348                 isVideoTexture: true,
20349                 update: function update() {
20350                         var video = this.image;
20351                         var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
20352
20353                         if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
20354                                 this.needsUpdate = true;
20355                         }
20356                 }
20357         });
20358
20359         function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
20360                 Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
20361                 this.image = {
20362                         width: width,
20363                         height: height
20364                 };
20365                 this.mipmaps = mipmaps; // no flipping for cube textures
20366                 // (also flipping doesn't work for compressed textures )
20367
20368                 this.flipY = false; // can't generate mipmaps for compressed textures
20369                 // mips must be embedded in DDS files
20370
20371                 this.generateMipmaps = false;
20372         }
20373
20374         CompressedTexture.prototype = Object.create(Texture.prototype);
20375         CompressedTexture.prototype.constructor = CompressedTexture;
20376         CompressedTexture.prototype.isCompressedTexture = true;
20377
20378         function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
20379                 Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
20380                 this.needsUpdate = true;
20381         }
20382
20383         CanvasTexture.prototype = Object.create(Texture.prototype);
20384         CanvasTexture.prototype.constructor = CanvasTexture;
20385         CanvasTexture.prototype.isCanvasTexture = true;
20386
20387         function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
20388                 format = format !== undefined ? format : DepthFormat;
20389
20390                 if (format !== DepthFormat && format !== DepthStencilFormat) {
20391                         throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
20392                 }
20393
20394                 if (type === undefined && format === DepthFormat) type = UnsignedShortType;
20395                 if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
20396                 Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
20397                 this.image = {
20398                         width: width,
20399                         height: height
20400                 };
20401                 this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
20402                 this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
20403                 this.flipY = false;
20404                 this.generateMipmaps = false;
20405         }
20406
20407         DepthTexture.prototype = Object.create(Texture.prototype);
20408         DepthTexture.prototype.constructor = DepthTexture;
20409         DepthTexture.prototype.isDepthTexture = true;
20410
20411         var _geometryId = 0; // Geometry uses even numbers as Id
20412
20413         var _m1$3 = new Matrix4();
20414
20415         var _obj$1 = new Object3D();
20416
20417         var _offset$1 = new Vector3();
20418
20419         function Geometry() {
20420                 Object.defineProperty(this, 'id', {
20421                         value: _geometryId += 2
20422                 });
20423                 this.uuid = MathUtils.generateUUID();
20424                 this.name = '';
20425                 this.type = 'Geometry';
20426                 this.vertices = [];
20427                 this.colors = [];
20428                 this.faces = [];
20429                 this.faceVertexUvs = [[]];
20430                 this.morphTargets = [];
20431                 this.morphNormals = [];
20432                 this.skinWeights = [];
20433                 this.skinIndices = [];
20434                 this.lineDistances = [];
20435                 this.boundingBox = null;
20436                 this.boundingSphere = null; // update flags
20437
20438                 this.elementsNeedUpdate = false;
20439                 this.verticesNeedUpdate = false;
20440                 this.uvsNeedUpdate = false;
20441                 this.normalsNeedUpdate = false;
20442                 this.colorsNeedUpdate = false;
20443                 this.lineDistancesNeedUpdate = false;
20444                 this.groupsNeedUpdate = false;
20445         }
20446
20447         Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
20448                 constructor: Geometry,
20449                 isGeometry: true,
20450                 applyMatrix4: function applyMatrix4(matrix) {
20451                         var normalMatrix = new Matrix3().getNormalMatrix(matrix);
20452
20453                         for (var i = 0, il = this.vertices.length; i < il; i++) {
20454                                 var vertex = this.vertices[i];
20455                                 vertex.applyMatrix4(matrix);
20456                         }
20457
20458                         for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
20459                                 var face = this.faces[_i];
20460                                 face.normal.applyMatrix3(normalMatrix).normalize();
20461
20462                                 for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
20463                                         face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
20464                                 }
20465                         }
20466
20467                         if (this.boundingBox !== null) {
20468                                 this.computeBoundingBox();
20469                         }
20470
20471                         if (this.boundingSphere !== null) {
20472                                 this.computeBoundingSphere();
20473                         }
20474
20475                         this.verticesNeedUpdate = true;
20476                         this.normalsNeedUpdate = true;
20477                         return this;
20478                 },
20479                 rotateX: function rotateX(angle) {
20480                         // rotate geometry around world x-axis
20481                         _m1$3.makeRotationX(angle);
20482
20483                         this.applyMatrix4(_m1$3);
20484                         return this;
20485                 },
20486                 rotateY: function rotateY(angle) {
20487                         // rotate geometry around world y-axis
20488                         _m1$3.makeRotationY(angle);
20489
20490                         this.applyMatrix4(_m1$3);
20491                         return this;
20492                 },
20493                 rotateZ: function rotateZ(angle) {
20494                         // rotate geometry around world z-axis
20495                         _m1$3.makeRotationZ(angle);
20496
20497                         this.applyMatrix4(_m1$3);
20498                         return this;
20499                 },
20500                 translate: function translate(x, y, z) {
20501                         // translate geometry
20502                         _m1$3.makeTranslation(x, y, z);
20503
20504                         this.applyMatrix4(_m1$3);
20505                         return this;
20506                 },
20507                 scale: function scale(x, y, z) {
20508                         // scale geometry
20509                         _m1$3.makeScale(x, y, z);
20510
20511                         this.applyMatrix4(_m1$3);
20512                         return this;
20513                 },
20514                 lookAt: function lookAt(vector) {
20515                         _obj$1.lookAt(vector);
20516
20517                         _obj$1.updateMatrix();
20518
20519                         this.applyMatrix4(_obj$1.matrix);
20520                         return this;
20521                 },
20522                 fromBufferGeometry: function fromBufferGeometry(geometry) {
20523                         var scope = this;
20524                         var index = geometry.index !== null ? geometry.index : undefined;
20525                         var attributes = geometry.attributes;
20526
20527                         if (attributes.position === undefined) {
20528                                 console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
20529                                 return this;
20530                         }
20531
20532                         var position = attributes.position;
20533                         var normal = attributes.normal;
20534                         var color = attributes.color;
20535                         var uv = attributes.uv;
20536                         var uv2 = attributes.uv2;
20537                         if (uv2 !== undefined) this.faceVertexUvs[1] = [];
20538
20539                         for (var i = 0; i < position.count; i++) {
20540                                 scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
20541
20542                                 if (color !== undefined) {
20543                                         scope.colors.push(new Color().fromBufferAttribute(color, i));
20544                                 }
20545                         }
20546
20547                         function addFace(a, b, c, materialIndex) {
20548                                 var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
20549                                 var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
20550                                 var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
20551                                 scope.faces.push(face);
20552
20553                                 if (uv !== undefined) {
20554                                         scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
20555                                 }
20556
20557                                 if (uv2 !== undefined) {
20558                                         scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
20559                                 }
20560                         }
20561
20562                         var groups = geometry.groups;
20563
20564                         if (groups.length > 0) {
20565                                 for (var _i2 = 0; _i2 < groups.length; _i2++) {
20566                                         var group = groups[_i2];
20567                                         var start = group.start;
20568                                         var count = group.count;
20569
20570                                         for (var j = start, jl = start + count; j < jl; j += 3) {
20571                                                 if (index !== undefined) {
20572                                                         addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
20573                                                 } else {
20574                                                         addFace(j, j + 1, j + 2, group.materialIndex);
20575                                                 }
20576                                         }
20577                                 }
20578                         } else {
20579                                 if (index !== undefined) {
20580                                         for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
20581                                                 addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
20582                                         }
20583                                 } else {
20584                                         for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
20585                                                 addFace(_i4, _i4 + 1, _i4 + 2);
20586                                         }
20587                                 }
20588                         }
20589
20590                         this.computeFaceNormals();
20591
20592                         if (geometry.boundingBox !== null) {
20593                                 this.boundingBox = geometry.boundingBox.clone();
20594                         }
20595
20596                         if (geometry.boundingSphere !== null) {
20597                                 this.boundingSphere = geometry.boundingSphere.clone();
20598                         }
20599
20600                         return this;
20601                 },
20602                 center: function center() {
20603                         this.computeBoundingBox();
20604                         this.boundingBox.getCenter(_offset$1).negate();
20605                         this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
20606                         return this;
20607                 },
20608                 normalize: function normalize() {
20609                         this.computeBoundingSphere();
20610                         var center = this.boundingSphere.center;
20611                         var radius = this.boundingSphere.radius;
20612                         var s = radius === 0 ? 1 : 1.0 / radius;
20613                         var matrix = new Matrix4();
20614                         matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
20615                         this.applyMatrix4(matrix);
20616                         return this;
20617                 },
20618                 computeFaceNormals: function computeFaceNormals() {
20619                         var cb = new Vector3(),
20620                                         ab = new Vector3();
20621
20622                         for (var f = 0, fl = this.faces.length; f < fl; f++) {
20623                                 var face = this.faces[f];
20624                                 var vA = this.vertices[face.a];
20625                                 var vB = this.vertices[face.b];
20626                                 var vC = this.vertices[face.c];
20627                                 cb.subVectors(vC, vB);
20628                                 ab.subVectors(vA, vB);
20629                                 cb.cross(ab);
20630                                 cb.normalize();
20631                                 face.normal.copy(cb);
20632                         }
20633                 },
20634                 computeVertexNormals: function computeVertexNormals(areaWeighted) {
20635                         if (areaWeighted === void 0) {
20636                                 areaWeighted = true;
20637                         }
20638
20639                         var vertices = new Array(this.vertices.length);
20640
20641                         for (var v = 0, vl = this.vertices.length; v < vl; v++) {
20642                                 vertices[v] = new Vector3();
20643                         }
20644
20645                         if (areaWeighted) {
20646                                 // vertex normals weighted by triangle areas
20647                                 // http://www.iquilezles.org/www/articles/normals/normals.htm
20648                                 var cb = new Vector3(),
20649                                                 ab = new Vector3();
20650
20651                                 for (var f = 0, fl = this.faces.length; f < fl; f++) {
20652                                         var face = this.faces[f];
20653                                         var vA = this.vertices[face.a];
20654                                         var vB = this.vertices[face.b];
20655                                         var vC = this.vertices[face.c];
20656                                         cb.subVectors(vC, vB);
20657                                         ab.subVectors(vA, vB);
20658                                         cb.cross(ab);
20659                                         vertices[face.a].add(cb);
20660                                         vertices[face.b].add(cb);
20661                                         vertices[face.c].add(cb);
20662                                 }
20663                         } else {
20664                                 this.computeFaceNormals();
20665
20666                                 for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
20667                                         var _face = this.faces[_f];
20668
20669                                         vertices[_face.a].add(_face.normal);
20670
20671                                         vertices[_face.b].add(_face.normal);
20672
20673                                         vertices[_face.c].add(_face.normal);
20674                                 }
20675                         }
20676
20677                         for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
20678                                 vertices[_v].normalize();
20679                         }
20680
20681                         for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
20682                                 var _face2 = this.faces[_f2];
20683                                 var vertexNormals = _face2.vertexNormals;
20684
20685                                 if (vertexNormals.length === 3) {
20686                                         vertexNormals[0].copy(vertices[_face2.a]);
20687                                         vertexNormals[1].copy(vertices[_face2.b]);
20688                                         vertexNormals[2].copy(vertices[_face2.c]);
20689                                 } else {
20690                                         vertexNormals[0] = vertices[_face2.a].clone();
20691                                         vertexNormals[1] = vertices[_face2.b].clone();
20692                                         vertexNormals[2] = vertices[_face2.c].clone();
20693                                 }
20694                         }
20695
20696                         if (this.faces.length > 0) {
20697                                 this.normalsNeedUpdate = true;
20698                         }
20699                 },
20700                 computeFlatVertexNormals: function computeFlatVertexNormals() {
20701                         this.computeFaceNormals();
20702
20703                         for (var f = 0, fl = this.faces.length; f < fl; f++) {
20704                                 var face = this.faces[f];
20705                                 var vertexNormals = face.vertexNormals;
20706
20707                                 if (vertexNormals.length === 3) {
20708                                         vertexNormals[0].copy(face.normal);
20709                                         vertexNormals[1].copy(face.normal);
20710                                         vertexNormals[2].copy(face.normal);
20711                                 } else {
20712                                         vertexNormals[0] = face.normal.clone();
20713                                         vertexNormals[1] = face.normal.clone();
20714                                         vertexNormals[2] = face.normal.clone();
20715                                 }
20716                         }
20717
20718                         if (this.faces.length > 0) {
20719                                 this.normalsNeedUpdate = true;
20720                         }
20721                 },
20722                 computeMorphNormals: function computeMorphNormals() {
20723                         // save original normals
20724                         // - create temp variables on first access
20725                         //       otherwise just copy (for faster repeated calls)
20726                         for (var f = 0, fl = this.faces.length; f < fl; f++) {
20727                                 var face = this.faces[f];
20728
20729                                 if (!face.__originalFaceNormal) {
20730                                         face.__originalFaceNormal = face.normal.clone();
20731                                 } else {
20732                                         face.__originalFaceNormal.copy(face.normal);
20733                                 }
20734
20735                                 if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
20736
20737                                 for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
20738                                         if (!face.__originalVertexNormals[i]) {
20739                                                 face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
20740                                         } else {
20741                                                 face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
20742                                         }
20743                                 }
20744                         } // use temp geometry to compute face and vertex normals for each morph
20745
20746
20747                         var tmpGeo = new Geometry();
20748                         tmpGeo.faces = this.faces;
20749
20750                         for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
20751                                 // create on first access
20752                                 if (!this.morphNormals[_i5]) {
20753                                         this.morphNormals[_i5] = {};
20754                                         this.morphNormals[_i5].faceNormals = [];
20755                                         this.morphNormals[_i5].vertexNormals = [];
20756                                         var dstNormalsFace = this.morphNormals[_i5].faceNormals;
20757                                         var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
20758
20759                                         for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
20760                                                 var faceNormal = new Vector3();
20761                                                 var vertexNormals = {
20762                                                         a: new Vector3(),
20763                                                         b: new Vector3(),
20764                                                         c: new Vector3()
20765                                                 };
20766                                                 dstNormalsFace.push(faceNormal);
20767                                                 dstNormalsVertex.push(vertexNormals);
20768                                         }
20769                                 }
20770
20771                                 var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
20772
20773                                 tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
20774
20775                                 tmpGeo.computeFaceNormals();
20776                                 tmpGeo.computeVertexNormals(); // store morph normals
20777
20778                                 for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
20779                                         var _face3 = this.faces[_f4];
20780                                         var _faceNormal = morphNormals.faceNormals[_f4];
20781                                         var _vertexNormals = morphNormals.vertexNormals[_f4];
20782
20783                                         _faceNormal.copy(_face3.normal);
20784
20785                                         _vertexNormals.a.copy(_face3.vertexNormals[0]);
20786
20787                                         _vertexNormals.b.copy(_face3.vertexNormals[1]);
20788
20789                                         _vertexNormals.c.copy(_face3.vertexNormals[2]);
20790                                 }
20791                         } // restore original normals
20792
20793
20794                         for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
20795                                 var _face4 = this.faces[_f5];
20796                                 _face4.normal = _face4.__originalFaceNormal;
20797                                 _face4.vertexNormals = _face4.__originalVertexNormals;
20798                         }
20799                 },
20800                 computeBoundingBox: function computeBoundingBox() {
20801                         if (this.boundingBox === null) {
20802                                 this.boundingBox = new Box3();
20803                         }
20804
20805                         this.boundingBox.setFromPoints(this.vertices);
20806                 },
20807                 computeBoundingSphere: function computeBoundingSphere() {
20808                         if (this.boundingSphere === null) {
20809                                 this.boundingSphere = new Sphere();
20810                         }
20811
20812                         this.boundingSphere.setFromPoints(this.vertices);
20813                 },
20814                 merge: function merge(geometry, matrix, materialIndexOffset) {
20815                         if (materialIndexOffset === void 0) {
20816                                 materialIndexOffset = 0;
20817                         }
20818
20819                         if (!(geometry && geometry.isGeometry)) {
20820                                 console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
20821                                 return;
20822                         }
20823
20824                         var normalMatrix;
20825                         var vertexOffset = this.vertices.length,
20826                                         vertices1 = this.vertices,
20827                                         vertices2 = geometry.vertices,
20828                                         faces1 = this.faces,
20829                                         faces2 = geometry.faces,
20830                                         colors1 = this.colors,
20831                                         colors2 = geometry.colors;
20832
20833                         if (matrix !== undefined) {
20834                                 normalMatrix = new Matrix3().getNormalMatrix(matrix);
20835                         } // vertices
20836
20837
20838                         for (var i = 0, il = vertices2.length; i < il; i++) {
20839                                 var vertex = vertices2[i];
20840                                 var vertexCopy = vertex.clone();
20841                                 if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
20842                                 vertices1.push(vertexCopy);
20843                         } // colors
20844
20845
20846                         for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
20847                                 colors1.push(colors2[_i6].clone());
20848                         } // faces
20849
20850
20851                         for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
20852                                 var face = faces2[_i7];
20853                                 var normal = void 0,
20854                                                 color = void 0;
20855                                 var faceVertexNormals = face.vertexNormals,
20856                                                 faceVertexColors = face.vertexColors;
20857                                 var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
20858                                 faceCopy.normal.copy(face.normal);
20859
20860                                 if (normalMatrix !== undefined) {
20861                                         faceCopy.normal.applyMatrix3(normalMatrix).normalize();
20862                                 }
20863
20864                                 for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
20865                                         normal = faceVertexNormals[j].clone();
20866
20867                                         if (normalMatrix !== undefined) {
20868                                                 normal.applyMatrix3(normalMatrix).normalize();
20869                                         }
20870
20871                                         faceCopy.vertexNormals.push(normal);
20872                                 }
20873
20874                                 faceCopy.color.copy(face.color);
20875
20876                                 for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
20877                                         color = faceVertexColors[_j];
20878                                         faceCopy.vertexColors.push(color.clone());
20879                                 }
20880
20881                                 faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
20882                                 faces1.push(faceCopy);
20883                         } // uvs
20884
20885
20886                         for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
20887                                 var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
20888                                 if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
20889
20890                                 for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
20891                                         var uvs2 = faceVertexUvs2[_j2],
20892                                                         uvsCopy = [];
20893
20894                                         for (var k = 0, kl = uvs2.length; k < kl; k++) {
20895                                                 uvsCopy.push(uvs2[k].clone());
20896                                         }
20897
20898                                         this.faceVertexUvs[_i8].push(uvsCopy);
20899                                 }
20900                         }
20901                 },
20902                 mergeMesh: function mergeMesh(mesh) {
20903                         if (!(mesh && mesh.isMesh)) {
20904                                 console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
20905                                 return;
20906                         }
20907
20908                         if (mesh.matrixAutoUpdate) mesh.updateMatrix();
20909                         this.merge(mesh.geometry, mesh.matrix);
20910                 },
20911
20912                 /*
20913                  * Checks for duplicate vertices with hashmap.
20914                  * Duplicated vertices are removed
20915                  * and faces' vertices are updated.
20916                  */
20917                 mergeVertices: function mergeVertices(precisionPoints) {
20918                         if (precisionPoints === void 0) {
20919                                 precisionPoints = 4;
20920                         }
20921
20922                         var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
20923
20924                         var unique = [],
20925                                         changes = [];
20926                         var precision = Math.pow(10, precisionPoints);
20927
20928                         for (var i = 0, il = this.vertices.length; i < il; i++) {
20929                                 var v = this.vertices[i];
20930                                 var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
20931
20932                                 if (verticesMap[key] === undefined) {
20933                                         verticesMap[key] = i;
20934                                         unique.push(this.vertices[i]);
20935                                         changes[i] = unique.length - 1;
20936                                 } else {
20937                                         //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
20938                                         changes[i] = changes[verticesMap[key]];
20939                                 }
20940                         } // if faces are completely degenerate after merging vertices, we
20941                         // have to remove them from the geometry.
20942
20943
20944                         var faceIndicesToRemove = [];
20945
20946                         for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
20947                                 var face = this.faces[_i9];
20948                                 face.a = changes[face.a];
20949                                 face.b = changes[face.b];
20950                                 face.c = changes[face.c];
20951                                 var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
20952                                 // we have to remove the face as nothing can be saved
20953
20954                                 for (var n = 0; n < 3; n++) {
20955                                         if (indices[n] === indices[(n + 1) % 3]) {
20956                                                 faceIndicesToRemove.push(_i9);
20957                                                 break;
20958                                         }
20959                                 }
20960                         }
20961
20962                         for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
20963                                 var idx = faceIndicesToRemove[_i10];
20964                                 this.faces.splice(idx, 1);
20965
20966                                 for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
20967                                         this.faceVertexUvs[j].splice(idx, 1);
20968                                 }
20969                         } // Use unique set of vertices
20970
20971
20972                         var diff = this.vertices.length - unique.length;
20973                         this.vertices = unique;
20974                         return diff;
20975                 },
20976                 setFromPoints: function setFromPoints(points) {
20977                         this.vertices = [];
20978
20979                         for (var i = 0, l = points.length; i < l; i++) {
20980                                 var point = points[i];
20981                                 this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
20982                         }
20983
20984                         return this;
20985                 },
20986                 sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
20987                         var faces = this.faces;
20988                         var length = faces.length; // tag faces
20989
20990                         for (var i = 0; i < length; i++) {
20991                                 faces[i]._id = i;
20992                         } // sort faces
20993
20994
20995                         function materialIndexSort(a, b) {
20996                                 return a.materialIndex - b.materialIndex;
20997                         }
20998
20999                         faces.sort(materialIndexSort); // sort uvs
21000
21001                         var uvs1 = this.faceVertexUvs[0];
21002                         var uvs2 = this.faceVertexUvs[1];
21003                         var newUvs1, newUvs2;
21004                         if (uvs1 && uvs1.length === length) newUvs1 = [];
21005                         if (uvs2 && uvs2.length === length) newUvs2 = [];
21006
21007                         for (var _i11 = 0; _i11 < length; _i11++) {
21008                                 var id = faces[_i11]._id;
21009                                 if (newUvs1) newUvs1.push(uvs1[id]);
21010                                 if (newUvs2) newUvs2.push(uvs2[id]);
21011                         }
21012
21013                         if (newUvs1) this.faceVertexUvs[0] = newUvs1;
21014                         if (newUvs2) this.faceVertexUvs[1] = newUvs2;
21015                 },
21016                 toJSON: function toJSON() {
21017                         var data = {
21018                                 metadata: {
21019                                         version: 4.5,
21020                                         type: 'Geometry',
21021                                         generator: 'Geometry.toJSON'
21022                                 }
21023                         }; // standard Geometry serialization
21024
21025                         data.uuid = this.uuid;
21026                         data.type = this.type;
21027                         if (this.name !== '') data.name = this.name;
21028
21029                         if (this.parameters !== undefined) {
21030                                 var parameters = this.parameters;
21031
21032                                 for (var key in parameters) {
21033                                         if (parameters[key] !== undefined) data[key] = parameters[key];
21034                                 }
21035
21036                                 return data;
21037                         }
21038
21039                         var vertices = [];
21040
21041                         for (var i = 0; i < this.vertices.length; i++) {
21042                                 var vertex = this.vertices[i];
21043                                 vertices.push(vertex.x, vertex.y, vertex.z);
21044                         }
21045
21046                         var faces = [];
21047                         var normals = [];
21048                         var normalsHash = {};
21049                         var colors = [];
21050                         var colorsHash = {};
21051                         var uvs = [];
21052                         var uvsHash = {};
21053
21054                         for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
21055                                 var face = this.faces[_i12];
21056                                 var hasMaterial = true;
21057                                 var hasFaceUv = false; // deprecated
21058
21059                                 var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
21060                                 var hasFaceNormal = face.normal.length() > 0;
21061                                 var hasFaceVertexNormal = face.vertexNormals.length > 0;
21062                                 var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
21063                                 var hasFaceVertexColor = face.vertexColors.length > 0;
21064                                 var faceType = 0;
21065                                 faceType = setBit(faceType, 0, 0); // isQuad
21066
21067                                 faceType = setBit(faceType, 1, hasMaterial);
21068                                 faceType = setBit(faceType, 2, hasFaceUv);
21069                                 faceType = setBit(faceType, 3, hasFaceVertexUv);
21070                                 faceType = setBit(faceType, 4, hasFaceNormal);
21071                                 faceType = setBit(faceType, 5, hasFaceVertexNormal);
21072                                 faceType = setBit(faceType, 6, hasFaceColor);
21073                                 faceType = setBit(faceType, 7, hasFaceVertexColor);
21074                                 faces.push(faceType);
21075                                 faces.push(face.a, face.b, face.c);
21076                                 faces.push(face.materialIndex);
21077
21078                                 if (hasFaceVertexUv) {
21079                                         var faceVertexUvs = this.faceVertexUvs[0][_i12];
21080                                         faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
21081                                 }
21082
21083                                 if (hasFaceNormal) {
21084                                         faces.push(getNormalIndex(face.normal));
21085                                 }
21086
21087                                 if (hasFaceVertexNormal) {
21088                                         var vertexNormals = face.vertexNormals;
21089                                         faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
21090                                 }
21091
21092                                 if (hasFaceColor) {
21093                                         faces.push(getColorIndex(face.color));
21094                                 }
21095
21096                                 if (hasFaceVertexColor) {
21097                                         var vertexColors = face.vertexColors;
21098                                         faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
21099                                 }
21100                         }
21101
21102                         function setBit(value, position, enabled) {
21103                                 return enabled ? value | 1 << position : value & ~(1 << position);
21104                         }
21105
21106                         function getNormalIndex(normal) {
21107                                 var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
21108
21109                                 if (normalsHash[hash] !== undefined) {
21110                                         return normalsHash[hash];
21111                                 }
21112
21113                                 normalsHash[hash] = normals.length / 3;
21114                                 normals.push(normal.x, normal.y, normal.z);
21115                                 return normalsHash[hash];
21116                         }
21117
21118                         function getColorIndex(color) {
21119                                 var hash = color.r.toString() + color.g.toString() + color.b.toString();
21120
21121                                 if (colorsHash[hash] !== undefined) {
21122                                         return colorsHash[hash];
21123                                 }
21124
21125                                 colorsHash[hash] = colors.length;
21126                                 colors.push(color.getHex());
21127                                 return colorsHash[hash];
21128                         }
21129
21130                         function getUvIndex(uv) {
21131                                 var hash = uv.x.toString() + uv.y.toString();
21132
21133                                 if (uvsHash[hash] !== undefined) {
21134                                         return uvsHash[hash];
21135                                 }
21136
21137                                 uvsHash[hash] = uvs.length / 2;
21138                                 uvs.push(uv.x, uv.y);
21139                                 return uvsHash[hash];
21140                         }
21141
21142                         data.data = {};
21143                         data.data.vertices = vertices;
21144                         data.data.normals = normals;
21145                         if (colors.length > 0) data.data.colors = colors;
21146                         if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
21147
21148                         data.data.faces = faces;
21149                         return data;
21150                 },
21151                 clone: function clone() {
21152                         /*
21153                          // Handle primitives
21154                                  const parameters = this.parameters;
21155                                  if ( parameters !== undefined ) {
21156                                  const values = [];
21157                                  for ( const key in parameters ) {
21158                                  values.push( parameters[ key ] );
21159                                  }
21160                                  const geometry = Object.create( this.constructor.prototype );
21161                          this.constructor.apply( geometry, values );
21162                          return geometry;
21163                                  }
21164                                  return new this.constructor().copy( this );
21165                          */
21166                         return new Geometry().copy(this);
21167                 },
21168                 copy: function copy(source) {
21169                         // reset
21170                         this.vertices = [];
21171                         this.colors = [];
21172                         this.faces = [];
21173                         this.faceVertexUvs = [[]];
21174                         this.morphTargets = [];
21175                         this.morphNormals = [];
21176                         this.skinWeights = [];
21177                         this.skinIndices = [];
21178                         this.lineDistances = [];
21179                         this.boundingBox = null;
21180                         this.boundingSphere = null; // name
21181
21182                         this.name = source.name; // vertices
21183
21184                         var vertices = source.vertices;
21185
21186                         for (var i = 0, il = vertices.length; i < il; i++) {
21187                                 this.vertices.push(vertices[i].clone());
21188                         } // colors
21189
21190
21191                         var colors = source.colors;
21192
21193                         for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
21194                                 this.colors.push(colors[_i13].clone());
21195                         } // faces
21196
21197
21198                         var faces = source.faces;
21199
21200                         for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
21201                                 this.faces.push(faces[_i14].clone());
21202                         } // face vertex uvs
21203
21204
21205                         for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
21206                                 var faceVertexUvs = source.faceVertexUvs[_i15];
21207
21208                                 if (this.faceVertexUvs[_i15] === undefined) {
21209                                         this.faceVertexUvs[_i15] = [];
21210                                 }
21211
21212                                 for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
21213                                         var uvs = faceVertexUvs[j],
21214                                                         uvsCopy = [];
21215
21216                                         for (var k = 0, kl = uvs.length; k < kl; k++) {
21217                                                 var uv = uvs[k];
21218                                                 uvsCopy.push(uv.clone());
21219                                         }
21220
21221                                         this.faceVertexUvs[_i15].push(uvsCopy);
21222                                 }
21223                         } // morph targets
21224
21225
21226                         var morphTargets = source.morphTargets;
21227
21228                         for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
21229                                 var morphTarget = {};
21230                                 morphTarget.name = morphTargets[_i16].name; // vertices
21231
21232                                 if (morphTargets[_i16].vertices !== undefined) {
21233                                         morphTarget.vertices = [];
21234
21235                                         for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
21236                                                 morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
21237                                         }
21238                                 } // normals
21239
21240
21241                                 if (morphTargets[_i16].normals !== undefined) {
21242                                         morphTarget.normals = [];
21243
21244                                         for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
21245                                                 morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
21246                                         }
21247                                 }
21248
21249                                 this.morphTargets.push(morphTarget);
21250                         } // morph normals
21251
21252
21253                         var morphNormals = source.morphNormals;
21254
21255                         for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
21256                                 var morphNormal = {}; // vertex normals
21257
21258                                 if (morphNormals[_i17].vertexNormals !== undefined) {
21259                                         morphNormal.vertexNormals = [];
21260
21261                                         for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
21262                                                 var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
21263                                                 var destVertexNormal = {};
21264                                                 destVertexNormal.a = srcVertexNormal.a.clone();
21265                                                 destVertexNormal.b = srcVertexNormal.b.clone();
21266                                                 destVertexNormal.c = srcVertexNormal.c.clone();
21267                                                 morphNormal.vertexNormals.push(destVertexNormal);
21268                                         }
21269                                 } // face normals
21270
21271
21272                                 if (morphNormals[_i17].faceNormals !== undefined) {
21273                                         morphNormal.faceNormals = [];
21274
21275                                         for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
21276                                                 morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
21277                                         }
21278                                 }
21279
21280                                 this.morphNormals.push(morphNormal);
21281                         } // skin weights
21282
21283
21284                         var skinWeights = source.skinWeights;
21285
21286                         for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
21287                                 this.skinWeights.push(skinWeights[_i18].clone());
21288                         } // skin indices
21289
21290
21291                         var skinIndices = source.skinIndices;
21292
21293                         for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
21294                                 this.skinIndices.push(skinIndices[_i19].clone());
21295                         } // line distances
21296
21297
21298                         var lineDistances = source.lineDistances;
21299
21300                         for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
21301                                 this.lineDistances.push(lineDistances[_i20]);
21302                         } // bounding box
21303
21304
21305                         var boundingBox = source.boundingBox;
21306
21307                         if (boundingBox !== null) {
21308                                 this.boundingBox = boundingBox.clone();
21309                         } // bounding sphere
21310
21311
21312                         var boundingSphere = source.boundingSphere;
21313
21314                         if (boundingSphere !== null) {
21315                                 this.boundingSphere = boundingSphere.clone();
21316                         } // update flags
21317
21318
21319                         this.elementsNeedUpdate = source.elementsNeedUpdate;
21320                         this.verticesNeedUpdate = source.verticesNeedUpdate;
21321                         this.uvsNeedUpdate = source.uvsNeedUpdate;
21322                         this.normalsNeedUpdate = source.normalsNeedUpdate;
21323                         this.colorsNeedUpdate = source.colorsNeedUpdate;
21324                         this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
21325                         this.groupsNeedUpdate = source.groupsNeedUpdate;
21326                         return this;
21327                 },
21328                 dispose: function dispose() {
21329                         this.dispatchEvent({
21330                                 type: 'dispose'
21331                         });
21332                 }
21333         });
21334
21335         var BoxGeometry = /*#__PURE__*/function (_Geometry) {
21336                 _inheritsLoose(BoxGeometry, _Geometry);
21337
21338                 function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
21339                         var _this;
21340
21341                         _this = _Geometry.call(this) || this;
21342                         _this.type = 'BoxGeometry';
21343                         _this.parameters = {
21344                                 width: width,
21345                                 height: height,
21346                                 depth: depth,
21347                                 widthSegments: widthSegments,
21348                                 heightSegments: heightSegments,
21349                                 depthSegments: depthSegments
21350                         };
21351
21352                         _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
21353
21354                         _this.mergeVertices();
21355
21356                         return _this;
21357                 }
21358
21359                 return BoxGeometry;
21360         }(Geometry);
21361
21362         var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
21363                 _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
21364
21365                 function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
21366                         var _this;
21367
21368                         if (radius === void 0) {
21369                                 radius = 1;
21370                         }
21371
21372                         if (segments === void 0) {
21373                                 segments = 8;
21374                         }
21375
21376                         if (thetaStart === void 0) {
21377                                 thetaStart = 0;
21378                         }
21379
21380                         if (thetaLength === void 0) {
21381                                 thetaLength = Math.PI * 2;
21382                         }
21383
21384                         _this = _BufferGeometry.call(this) || this;
21385                         _this.type = 'CircleBufferGeometry';
21386                         _this.parameters = {
21387                                 radius: radius,
21388                                 segments: segments,
21389                                 thetaStart: thetaStart,
21390                                 thetaLength: thetaLength
21391                         };
21392                         segments = Math.max(3, segments); // buffers
21393
21394                         var indices = [];
21395                         var vertices = [];
21396                         var normals = [];
21397                         var uvs = []; // helper variables
21398
21399                         var vertex = new Vector3();
21400                         var uv = new Vector2(); // center point
21401
21402                         vertices.push(0, 0, 0);
21403                         normals.push(0, 0, 1);
21404                         uvs.push(0.5, 0.5);
21405
21406                         for (var s = 0, i = 3; s <= segments; s++, i += 3) {
21407                                 var segment = thetaStart + s / segments * thetaLength; // vertex
21408
21409                                 vertex.x = radius * Math.cos(segment);
21410                                 vertex.y = radius * Math.sin(segment);
21411                                 vertices.push(vertex.x, vertex.y, vertex.z); // normal
21412
21413                                 normals.push(0, 0, 1); // uvs
21414
21415                                 uv.x = (vertices[i] / radius + 1) / 2;
21416                                 uv.y = (vertices[i + 1] / radius + 1) / 2;
21417                                 uvs.push(uv.x, uv.y);
21418                         } // indices
21419
21420
21421                         for (var _i = 1; _i <= segments; _i++) {
21422                                 indices.push(_i, _i + 1, 0);
21423                         } // build geometry
21424
21425
21426                         _this.setIndex(indices);
21427
21428                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
21429
21430                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
21431
21432                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
21433
21434                         return _this;
21435                 }
21436
21437                 return CircleBufferGeometry;
21438         }(BufferGeometry);
21439
21440         var CircleGeometry = /*#__PURE__*/function (_Geometry) {
21441                 _inheritsLoose(CircleGeometry, _Geometry);
21442
21443                 function CircleGeometry(radius, segments, thetaStart, thetaLength) {
21444                         var _this;
21445
21446                         _this = _Geometry.call(this) || this;
21447                         _this.type = 'CircleGeometry';
21448                         _this.parameters = {
21449                                 radius: radius,
21450                                 segments: segments,
21451                                 thetaStart: thetaStart,
21452                                 thetaLength: thetaLength
21453                         };
21454
21455                         _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
21456
21457                         _this.mergeVertices();
21458
21459                         return _this;
21460                 }
21461
21462                 return CircleGeometry;
21463         }(Geometry);
21464
21465         var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
21466                 _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
21467
21468                 function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
21469                         var _this;
21470
21471                         if (radiusTop === void 0) {
21472                                 radiusTop = 1;
21473                         }
21474
21475                         if (radiusBottom === void 0) {
21476                                 radiusBottom = 1;
21477                         }
21478
21479                         if (height === void 0) {
21480                                 height = 1;
21481                         }
21482
21483                         if (radialSegments === void 0) {
21484                                 radialSegments = 8;
21485                         }
21486
21487                         if (heightSegments === void 0) {
21488                                 heightSegments = 1;
21489                         }
21490
21491                         if (openEnded === void 0) {
21492                                 openEnded = false;
21493                         }
21494
21495                         if (thetaStart === void 0) {
21496                                 thetaStart = 0;
21497                         }
21498
21499                         if (thetaLength === void 0) {
21500                                 thetaLength = Math.PI * 2;
21501                         }
21502
21503                         _this = _BufferGeometry.call(this) || this;
21504                         _this.type = 'CylinderBufferGeometry';
21505                         _this.parameters = {
21506                                 radiusTop: radiusTop,
21507                                 radiusBottom: radiusBottom,
21508                                 height: height,
21509                                 radialSegments: radialSegments,
21510                                 heightSegments: heightSegments,
21511                                 openEnded: openEnded,
21512                                 thetaStart: thetaStart,
21513                                 thetaLength: thetaLength
21514                         };
21515
21516                         var scope = _assertThisInitialized(_this);
21517
21518                         radialSegments = Math.floor(radialSegments);
21519                         heightSegments = Math.floor(heightSegments); // buffers
21520
21521                         var indices = [];
21522                         var vertices = [];
21523                         var normals = [];
21524                         var uvs = []; // helper variables
21525
21526                         var index = 0;
21527                         var indexArray = [];
21528                         var halfHeight = height / 2;
21529                         var groupStart = 0; // generate geometry
21530
21531                         generateTorso();
21532
21533                         if (openEnded === false) {
21534                                 if (radiusTop > 0) generateCap(true);
21535                                 if (radiusBottom > 0) generateCap(false);
21536                         } // build geometry
21537
21538
21539                         _this.setIndex(indices);
21540
21541                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
21542
21543                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
21544
21545                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
21546
21547                         function generateTorso() {
21548                                 var normal = new Vector3();
21549                                 var vertex = new Vector3();
21550                                 var groupCount = 0; // this will be used to calculate the normal
21551
21552                                 var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
21553
21554                                 for (var y = 0; y <= heightSegments; y++) {
21555                                         var indexRow = [];
21556                                         var v = y / heightSegments; // calculate the radius of the current row
21557
21558                                         var radius = v * (radiusBottom - radiusTop) + radiusTop;
21559
21560                                         for (var x = 0; x <= radialSegments; x++) {
21561                                                 var u = x / radialSegments;
21562                                                 var theta = u * thetaLength + thetaStart;
21563                                                 var sinTheta = Math.sin(theta);
21564                                                 var cosTheta = Math.cos(theta); // vertex
21565
21566                                                 vertex.x = radius * sinTheta;
21567                                                 vertex.y = -v * height + halfHeight;
21568                                                 vertex.z = radius * cosTheta;
21569                                                 vertices.push(vertex.x, vertex.y, vertex.z); // normal
21570
21571                                                 normal.set(sinTheta, slope, cosTheta).normalize();
21572                                                 normals.push(normal.x, normal.y, normal.z); // uv
21573
21574                                                 uvs.push(u, 1 - v); // save index of vertex in respective row
21575
21576                                                 indexRow.push(index++);
21577                                         } // now save vertices of the row in our index array
21578
21579
21580                                         indexArray.push(indexRow);
21581                                 } // generate indices
21582
21583
21584                                 for (var _x = 0; _x < radialSegments; _x++) {
21585                                         for (var _y = 0; _y < heightSegments; _y++) {
21586                                                 // we use the index array to access the correct indices
21587                                                 var a = indexArray[_y][_x];
21588                                                 var b = indexArray[_y + 1][_x];
21589                                                 var c = indexArray[_y + 1][_x + 1];
21590                                                 var d = indexArray[_y][_x + 1]; // faces
21591
21592                                                 indices.push(a, b, d);
21593                                                 indices.push(b, c, d); // update group counter
21594
21595                                                 groupCount += 6;
21596                                         }
21597                                 } // add a group to the geometry. this will ensure multi material support
21598
21599
21600                                 scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
21601
21602                                 groupStart += groupCount;
21603                         }
21604
21605                         function generateCap(top) {
21606                                 // save the index of the first center vertex
21607                                 var centerIndexStart = index;
21608                                 var uv = new Vector2();
21609                                 var vertex = new Vector3();
21610                                 var groupCount = 0;
21611                                 var radius = top === true ? radiusTop : radiusBottom;
21612                                 var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
21613                                 // because the geometry needs one set of uvs per face,
21614                                 // we must generate a center vertex per face/segment
21615
21616                                 for (var x = 1; x <= radialSegments; x++) {
21617                                         // vertex
21618                                         vertices.push(0, halfHeight * sign, 0); // normal
21619
21620                                         normals.push(0, sign, 0); // uv
21621
21622                                         uvs.push(0.5, 0.5); // increase index
21623
21624                                         index++;
21625                                 } // save the index of the last center vertex
21626
21627
21628                                 var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
21629
21630                                 for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
21631                                         var u = _x2 / radialSegments;
21632                                         var theta = u * thetaLength + thetaStart;
21633                                         var cosTheta = Math.cos(theta);
21634                                         var sinTheta = Math.sin(theta); // vertex
21635
21636                                         vertex.x = radius * sinTheta;
21637                                         vertex.y = halfHeight * sign;
21638                                         vertex.z = radius * cosTheta;
21639                                         vertices.push(vertex.x, vertex.y, vertex.z); // normal
21640
21641                                         normals.push(0, sign, 0); // uv
21642
21643                                         uv.x = cosTheta * 0.5 + 0.5;
21644                                         uv.y = sinTheta * 0.5 * sign + 0.5;
21645                                         uvs.push(uv.x, uv.y); // increase index
21646
21647                                         index++;
21648                                 } // generate indices
21649
21650
21651                                 for (var _x3 = 0; _x3 < radialSegments; _x3++) {
21652                                         var c = centerIndexStart + _x3;
21653                                         var i = centerIndexEnd + _x3;
21654
21655                                         if (top === true) {
21656                                                 // face top
21657                                                 indices.push(i, i + 1, c);
21658                                         } else {
21659                                                 // face bottom
21660                                                 indices.push(i + 1, i, c);
21661                                         }
21662
21663                                         groupCount += 3;
21664                                 } // add a group to the geometry. this will ensure multi material support
21665
21666
21667                                 scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
21668
21669                                 groupStart += groupCount;
21670                         }
21671
21672                         return _this;
21673                 }
21674
21675                 return CylinderBufferGeometry;
21676         }(BufferGeometry);
21677
21678         var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
21679                 _inheritsLoose(CylinderGeometry, _Geometry);
21680
21681                 function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
21682                         var _this;
21683
21684                         _this = _Geometry.call(this) || this;
21685                         _this.type = 'CylinderGeometry';
21686                         _this.parameters = {
21687                                 radiusTop: radiusTop,
21688                                 radiusBottom: radiusBottom,
21689                                 height: height,
21690                                 radialSegments: radialSegments,
21691                                 heightSegments: heightSegments,
21692                                 openEnded: openEnded,
21693                                 thetaStart: thetaStart,
21694                                 thetaLength: thetaLength
21695                         };
21696
21697                         _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
21698
21699                         _this.mergeVertices();
21700
21701                         return _this;
21702                 }
21703
21704                 return CylinderGeometry;
21705         }(Geometry);
21706
21707         var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
21708                 _inheritsLoose(ConeGeometry, _CylinderGeometry);
21709
21710                 function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
21711                         var _this;
21712
21713                         _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
21714                         _this.type = 'ConeGeometry';
21715                         _this.parameters = {
21716                                 radius: radius,
21717                                 height: height,
21718                                 radialSegments: radialSegments,
21719                                 heightSegments: heightSegments,
21720                                 openEnded: openEnded,
21721                                 thetaStart: thetaStart,
21722                                 thetaLength: thetaLength
21723                         };
21724                         return _this;
21725                 }
21726
21727                 return ConeGeometry;
21728         }(CylinderGeometry);
21729
21730         var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
21731                 _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
21732
21733                 function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
21734                         var _this;
21735
21736                         if (radius === void 0) {
21737                                 radius = 1;
21738                         }
21739
21740                         if (height === void 0) {
21741                                 height = 1;
21742                         }
21743
21744                         if (radialSegments === void 0) {
21745                                 radialSegments = 8;
21746                         }
21747
21748                         if (heightSegments === void 0) {
21749                                 heightSegments = 1;
21750                         }
21751
21752                         if (openEnded === void 0) {
21753                                 openEnded = false;
21754                         }
21755
21756                         if (thetaStart === void 0) {
21757                                 thetaStart = 0;
21758                         }
21759
21760                         if (thetaLength === void 0) {
21761                                 thetaLength = Math.PI * 2;
21762                         }
21763
21764                         _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
21765                         _this.type = 'ConeBufferGeometry';
21766                         _this.parameters = {
21767                                 radius: radius,
21768                                 height: height,
21769                                 radialSegments: radialSegments,
21770                                 heightSegments: heightSegments,
21771                                 openEnded: openEnded,
21772                                 thetaStart: thetaStart,
21773                                 thetaLength: thetaLength
21774                         };
21775                         return _this;
21776                 }
21777
21778                 return ConeBufferGeometry;
21779         }(CylinderBufferGeometry);
21780
21781         var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
21782                 _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
21783
21784                 function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
21785                         var _this;
21786
21787                         if (radius === void 0) {
21788                                 radius = 1;
21789                         }
21790
21791                         if (detail === void 0) {
21792                                 detail = 0;
21793                         }
21794
21795                         _this = _BufferGeometry.call(this) || this;
21796                         _this.type = 'PolyhedronBufferGeometry';
21797                         _this.parameters = {
21798                                 vertices: vertices,
21799                                 indices: indices,
21800                                 radius: radius,
21801                                 detail: detail
21802                         }; // default buffer data
21803
21804                         var vertexBuffer = [];
21805                         var uvBuffer = []; // the subdivision creates the vertex buffer data
21806
21807                         subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
21808
21809                         applyRadius(radius); // finally, create the uv data
21810
21811                         generateUVs(); // build non-indexed geometry
21812
21813                         _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
21814
21815                         _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
21816
21817                         _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
21818
21819                         if (detail === 0) {
21820                                 _this.computeVertexNormals(); // flat normals
21821
21822                         } else {
21823                                 _this.normalizeNormals(); // smooth normals
21824
21825                         } // helper functions
21826
21827
21828                         function subdivide(detail) {
21829                                 var a = new Vector3();
21830                                 var b = new Vector3();
21831                                 var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
21832
21833                                 for (var i = 0; i < indices.length; i += 3) {
21834                                         // get the vertices of the face
21835                                         getVertexByIndex(indices[i + 0], a);
21836                                         getVertexByIndex(indices[i + 1], b);
21837                                         getVertexByIndex(indices[i + 2], c); // perform subdivision
21838
21839                                         subdivideFace(a, b, c, detail);
21840                                 }
21841                         }
21842
21843                         function subdivideFace(a, b, c, detail) {
21844                                 var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
21845
21846                                 var v = []; // construct all of the vertices for this subdivision
21847
21848                                 for (var i = 0; i <= cols; i++) {
21849                                         v[i] = [];
21850                                         var aj = a.clone().lerp(c, i / cols);
21851                                         var bj = b.clone().lerp(c, i / cols);
21852                                         var rows = cols - i;
21853
21854                                         for (var j = 0; j <= rows; j++) {
21855                                                 if (j === 0 && i === cols) {
21856                                                         v[i][j] = aj;
21857                                                 } else {
21858                                                         v[i][j] = aj.clone().lerp(bj, j / rows);
21859                                                 }
21860                                         }
21861                                 } // construct all of the faces
21862
21863
21864                                 for (var _i = 0; _i < cols; _i++) {
21865                                         for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
21866                                                 var k = Math.floor(_j / 2);
21867
21868                                                 if (_j % 2 === 0) {
21869                                                         pushVertex(v[_i][k + 1]);
21870                                                         pushVertex(v[_i + 1][k]);
21871                                                         pushVertex(v[_i][k]);
21872                                                 } else {
21873                                                         pushVertex(v[_i][k + 1]);
21874                                                         pushVertex(v[_i + 1][k + 1]);
21875                                                         pushVertex(v[_i + 1][k]);
21876                                                 }
21877                                         }
21878                                 }
21879                         }
21880
21881                         function applyRadius(radius) {
21882                                 var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
21883
21884                                 for (var i = 0; i < vertexBuffer.length; i += 3) {
21885                                         vertex.x = vertexBuffer[i + 0];
21886                                         vertex.y = vertexBuffer[i + 1];
21887                                         vertex.z = vertexBuffer[i + 2];
21888                                         vertex.normalize().multiplyScalar(radius);
21889                                         vertexBuffer[i + 0] = vertex.x;
21890                                         vertexBuffer[i + 1] = vertex.y;
21891                                         vertexBuffer[i + 2] = vertex.z;
21892                                 }
21893                         }
21894
21895                         function generateUVs() {
21896                                 var vertex = new Vector3();
21897
21898                                 for (var i = 0; i < vertexBuffer.length; i += 3) {
21899                                         vertex.x = vertexBuffer[i + 0];
21900                                         vertex.y = vertexBuffer[i + 1];
21901                                         vertex.z = vertexBuffer[i + 2];
21902                                         var u = azimuth(vertex) / 2 / Math.PI + 0.5;
21903                                         var v = inclination(vertex) / Math.PI + 0.5;
21904                                         uvBuffer.push(u, 1 - v);
21905                                 }
21906
21907                                 correctUVs();
21908                                 correctSeam();
21909                         }
21910
21911                         function correctSeam() {
21912                                 // handle case when face straddles the seam, see #3269
21913                                 for (var i = 0; i < uvBuffer.length; i += 6) {
21914                                         // uv data of a single face
21915                                         var x0 = uvBuffer[i + 0];
21916                                         var x1 = uvBuffer[i + 2];
21917                                         var x2 = uvBuffer[i + 4];
21918                                         var max = Math.max(x0, x1, x2);
21919                                         var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
21920
21921                                         if (max > 0.9 && min < 0.1) {
21922                                                 if (x0 < 0.2) uvBuffer[i + 0] += 1;
21923                                                 if (x1 < 0.2) uvBuffer[i + 2] += 1;
21924                                                 if (x2 < 0.2) uvBuffer[i + 4] += 1;
21925                                         }
21926                                 }
21927                         }
21928
21929                         function pushVertex(vertex) {
21930                                 vertexBuffer.push(vertex.x, vertex.y, vertex.z);
21931                         }
21932
21933                         function getVertexByIndex(index, vertex) {
21934                                 var stride = index * 3;
21935                                 vertex.x = vertices[stride + 0];
21936                                 vertex.y = vertices[stride + 1];
21937                                 vertex.z = vertices[stride + 2];
21938                         }
21939
21940                         function correctUVs() {
21941                                 var a = new Vector3();
21942                                 var b = new Vector3();
21943                                 var c = new Vector3();
21944                                 var centroid = new Vector3();
21945                                 var uvA = new Vector2();
21946                                 var uvB = new Vector2();
21947                                 var uvC = new Vector2();
21948
21949                                 for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
21950                                         a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
21951                                         b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
21952                                         c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
21953                                         uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
21954                                         uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
21955                                         uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
21956                                         centroid.copy(a).add(b).add(c).divideScalar(3);
21957                                         var azi = azimuth(centroid);
21958                                         correctUV(uvA, j + 0, a, azi);
21959                                         correctUV(uvB, j + 2, b, azi);
21960                                         correctUV(uvC, j + 4, c, azi);
21961                                 }
21962                         }
21963
21964                         function correctUV(uv, stride, vector, azimuth) {
21965                                 if (azimuth < 0 && uv.x === 1) {
21966                                         uvBuffer[stride] = uv.x - 1;
21967                                 }
21968
21969                                 if (vector.x === 0 && vector.z === 0) {
21970                                         uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
21971                                 }
21972                         } // Angle around the Y axis, counter-clockwise when looking from above.
21973
21974
21975                         function azimuth(vector) {
21976                                 return Math.atan2(vector.z, -vector.x);
21977                         } // Angle above the XZ plane.
21978
21979
21980                         function inclination(vector) {
21981                                 return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
21982                         }
21983
21984                         return _this;
21985                 }
21986
21987                 return PolyhedronBufferGeometry;
21988         }(BufferGeometry);
21989
21990         var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
21991                 _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
21992
21993                 function DodecahedronBufferGeometry(radius, detail) {
21994                         var _this;
21995
21996                         if (radius === void 0) {
21997                                 radius = 1;
21998                         }
21999
22000                         if (detail === void 0) {
22001                                 detail = 0;
22002                         }
22003
22004                         var t = (1 + Math.sqrt(5)) / 2;
22005                         var r = 1 / t;
22006                         var vertices = [// (±1, Â±1, Â±1)
22007                         -1, -1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, // (0, Â±1/φ, Â±Ï†)
22008                         0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, Â±Ï†, 0)
22009                         -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, Â±1/φ)
22010                         -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
22011                         var indices = [3, 11, 7, 3, 7, 15, 3, 15, 13, 7, 19, 17, 7, 17, 6, 7, 6, 15, 17, 4, 8, 17, 8, 10, 17, 10, 6, 8, 0, 16, 8, 16, 2, 8, 2, 10, 0, 12, 1, 0, 1, 18, 0, 18, 16, 6, 10, 2, 6, 2, 13, 6, 13, 15, 2, 16, 18, 2, 18, 3, 2, 3, 13, 18, 1, 9, 18, 9, 11, 18, 11, 3, 4, 14, 12, 4, 12, 0, 4, 0, 8, 11, 9, 5, 11, 5, 19, 11, 19, 7, 19, 5, 14, 19, 14, 4, 19, 4, 17, 1, 12, 14, 1, 14, 5, 1, 5, 9];
22012                         _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
22013                         _this.type = 'DodecahedronBufferGeometry';
22014                         _this.parameters = {
22015                                 radius: radius,
22016                                 detail: detail
22017                         };
22018                         return _this;
22019                 }
22020
22021                 return DodecahedronBufferGeometry;
22022         }(PolyhedronBufferGeometry);
22023
22024         var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
22025                 _inheritsLoose(DodecahedronGeometry, _Geometry);
22026
22027                 function DodecahedronGeometry(radius, detail) {
22028                         var _this;
22029
22030                         _this = _Geometry.call(this) || this;
22031                         _this.type = 'DodecahedronGeometry';
22032                         _this.parameters = {
22033                                 radius: radius,
22034                                 detail: detail
22035                         };
22036
22037                         _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
22038
22039                         _this.mergeVertices();
22040
22041                         return _this;
22042                 }
22043
22044                 return DodecahedronGeometry;
22045         }(Geometry);
22046
22047         var _v0$2 = new Vector3();
22048
22049         var _v1$5 = new Vector3();
22050
22051         var _normal$1 = new Vector3();
22052
22053         var _triangle = new Triangle();
22054
22055         var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
22056                 _inheritsLoose(EdgesGeometry, _BufferGeometry);
22057
22058                 function EdgesGeometry(geometry, thresholdAngle) {
22059                         var _this;
22060
22061                         _this = _BufferGeometry.call(this) || this;
22062                         _this.type = 'EdgesGeometry';
22063                         _this.parameters = {
22064                                 thresholdAngle: thresholdAngle
22065                         };
22066                         thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
22067
22068                         if (geometry.isGeometry) {
22069                                 geometry = new BufferGeometry().fromGeometry(geometry);
22070                         }
22071
22072                         var precisionPoints = 4;
22073                         var precision = Math.pow(10, precisionPoints);
22074                         var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
22075                         var indexAttr = geometry.getIndex();
22076                         var positionAttr = geometry.getAttribute('position');
22077                         var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
22078                         var indexArr = [0, 0, 0];
22079                         var vertKeys = ['a', 'b', 'c'];
22080                         var hashes = new Array(3);
22081                         var edgeData = {};
22082                         var vertices = [];
22083
22084                         for (var i = 0; i < indexCount; i += 3) {
22085                                 if (indexAttr) {
22086                                         indexArr[0] = indexAttr.getX(i);
22087                                         indexArr[1] = indexAttr.getX(i + 1);
22088                                         indexArr[2] = indexAttr.getX(i + 2);
22089                                 } else {
22090                                         indexArr[0] = i;
22091                                         indexArr[1] = i + 1;
22092                                         indexArr[2] = i + 2;
22093                                 }
22094
22095                                 var a = _triangle.a,
22096                                                 b = _triangle.b,
22097                                                 c = _triangle.c;
22098                                 a.fromBufferAttribute(positionAttr, indexArr[0]);
22099                                 b.fromBufferAttribute(positionAttr, indexArr[1]);
22100                                 c.fromBufferAttribute(positionAttr, indexArr[2]);
22101
22102                                 _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
22103
22104
22105                                 hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
22106                                 hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
22107                                 hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
22108
22109                                 if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
22110                                         continue;
22111                                 } // iterate over every edge
22112
22113
22114                                 for (var j = 0; j < 3; j++) {
22115                                         // get the first and next vertex making up the edge
22116                                         var jNext = (j + 1) % 3;
22117                                         var vecHash0 = hashes[j];
22118                                         var vecHash1 = hashes[jNext];
22119                                         var v0 = _triangle[vertKeys[j]];
22120                                         var v1 = _triangle[vertKeys[jNext]];
22121                                         var hash = vecHash0 + "_" + vecHash1;
22122                                         var reverseHash = vecHash1 + "_" + vecHash0;
22123
22124                                         if (reverseHash in edgeData && edgeData[reverseHash]) {
22125                                                 // if we found a sibling edge add it into the vertex array if
22126                                                 // it meets the angle threshold and delete the edge from the map.
22127                                                 if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
22128                                                         vertices.push(v0.x, v0.y, v0.z);
22129                                                         vertices.push(v1.x, v1.y, v1.z);
22130                                                 }
22131
22132                                                 edgeData[reverseHash] = null;
22133                                         } else if (!(hash in edgeData)) {
22134                                                 // if we've already got an edge here then skip adding a new one
22135                                                 edgeData[hash] = {
22136                                                         index0: indexArr[j],
22137                                                         index1: indexArr[jNext],
22138                                                         normal: _normal$1.clone()
22139                                                 };
22140                                         }
22141                                 }
22142                         } // iterate over all remaining, unmatched edges and add them to the vertex array
22143
22144
22145                         for (var key in edgeData) {
22146                                 if (edgeData[key]) {
22147                                         var _edgeData$key = edgeData[key],
22148                                                         index0 = _edgeData$key.index0,
22149                                                         index1 = _edgeData$key.index1;
22150
22151                                         _v0$2.fromBufferAttribute(positionAttr, index0);
22152
22153                                         _v1$5.fromBufferAttribute(positionAttr, index1);
22154
22155                                         vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
22156                                         vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
22157                                 }
22158                         }
22159
22160                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
22161
22162                         return _this;
22163                 }
22164
22165                 return EdgesGeometry;
22166         }(BufferGeometry);
22167
22168         /**
22169          * Port from https://github.com/mapbox/earcut (v2.2.2)
22170          */
22171         var Earcut = {
22172                 triangulate: function triangulate(data, holeIndices, dim) {
22173                         dim = dim || 2;
22174                         var hasHoles = holeIndices && holeIndices.length;
22175                         var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
22176                         var outerNode = linkedList(data, 0, outerLen, dim, true);
22177                         var triangles = [];
22178                         if (!outerNode || outerNode.next === outerNode.prev) return triangles;
22179                         var minX, minY, maxX, maxY, x, y, invSize;
22180                         if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
22181
22182                         if (data.length > 80 * dim) {
22183                                 minX = maxX = data[0];
22184                                 minY = maxY = data[1];
22185
22186                                 for (var i = dim; i < outerLen; i += dim) {
22187                                         x = data[i];
22188                                         y = data[i + 1];
22189                                         if (x < minX) minX = x;
22190                                         if (y < minY) minY = y;
22191                                         if (x > maxX) maxX = x;
22192                                         if (y > maxY) maxY = y;
22193                                 } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
22194
22195
22196                                 invSize = Math.max(maxX - minX, maxY - minY);
22197                                 invSize = invSize !== 0 ? 1 / invSize : 0;
22198                         }
22199
22200                         earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
22201                         return triangles;
22202                 }
22203         }; // create a circular doubly linked list from polygon points in the specified winding order
22204
22205         function linkedList(data, start, end, dim, clockwise) {
22206                 var i, last;
22207
22208                 if (clockwise === signedArea(data, start, end, dim) > 0) {
22209                         for (i = start; i < end; i += dim) {
22210                                 last = insertNode(i, data[i], data[i + 1], last);
22211                         }
22212                 } else {
22213                         for (i = end - dim; i >= start; i -= dim) {
22214                                 last = insertNode(i, data[i], data[i + 1], last);
22215                         }
22216                 }
22217
22218                 if (last && equals(last, last.next)) {
22219                         removeNode(last);
22220                         last = last.next;
22221                 }
22222
22223                 return last;
22224         } // eliminate colinear or duplicate points
22225
22226
22227         function filterPoints(start, end) {
22228                 if (!start) return start;
22229                 if (!end) end = start;
22230                 var p = start,
22231                                 again;
22232
22233                 do {
22234                         again = false;
22235
22236                         if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
22237                                 removeNode(p);
22238                                 p = end = p.prev;
22239                                 if (p === p.next) break;
22240                                 again = true;
22241                         } else {
22242                                 p = p.next;
22243                         }
22244                 } while (again || p !== end);
22245
22246                 return end;
22247         } // main ear slicing loop which triangulates a polygon (given as a linked list)
22248
22249
22250         function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
22251                 if (!ear) return; // interlink polygon nodes in z-order
22252
22253                 if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
22254                 var stop = ear,
22255                                 prev,
22256                                 next; // iterate through ears, slicing them one by one
22257
22258                 while (ear.prev !== ear.next) {
22259                         prev = ear.prev;
22260                         next = ear.next;
22261
22262                         if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
22263                                 // cut off the triangle
22264                                 triangles.push(prev.i / dim);
22265                                 triangles.push(ear.i / dim);
22266                                 triangles.push(next.i / dim);
22267                                 removeNode(ear); // skipping the next vertex leads to less sliver triangles
22268
22269                                 ear = next.next;
22270                                 stop = next.next;
22271                                 continue;
22272                         }
22273
22274                         ear = next; // if we looped through the whole remaining polygon and can't find any more ears
22275
22276                         if (ear === stop) {
22277                                 // try filtering points and slicing again
22278                                 if (!pass) {
22279                                         earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
22280                                 } else if (pass === 1) {
22281                                         ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
22282                                         earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
22283                                 } else if (pass === 2) {
22284                                         splitEarcut(ear, triangles, dim, minX, minY, invSize);
22285                                 }
22286
22287                                 break;
22288                         }
22289                 }
22290         } // check whether a polygon node forms a valid ear with adjacent nodes
22291
22292
22293         function isEar(ear) {
22294                 var a = ear.prev,
22295                                 b = ear,
22296                                 c = ear.next;
22297                 if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
22298                 // now make sure we don't have other points inside the potential ear
22299
22300                 var p = ear.next.next;
22301
22302                 while (p !== ear.prev) {
22303                         if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
22304                         p = p.next;
22305                 }
22306
22307                 return true;
22308         }
22309
22310         function isEarHashed(ear, minX, minY, invSize) {
22311                 var a = ear.prev,
22312                                 b = ear,
22313                                 c = ear.next;
22314                 if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
22315                 // triangle bbox; min & max are calculated like this for speed
22316
22317                 var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
22318                                 minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
22319                                 maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
22320                                 maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y; // z-order range for the current triangle bbox;
22321
22322                 var minZ = zOrder(minTX, minTY, minX, minY, invSize),
22323                                 maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
22324                 var p = ear.prevZ,
22325                                 n = ear.nextZ; // look for points inside the triangle in both directions
22326
22327                 while (p && p.z >= minZ && n && n.z <= maxZ) {
22328                         if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
22329                         p = p.prevZ;
22330                         if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
22331                         n = n.nextZ;
22332                 } // look for remaining points in decreasing z-order
22333
22334
22335                 while (p && p.z >= minZ) {
22336                         if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
22337                         p = p.prevZ;
22338                 } // look for remaining points in increasing z-order
22339
22340
22341                 while (n && n.z <= maxZ) {
22342                         if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
22343                         n = n.nextZ;
22344                 }
22345
22346                 return true;
22347         } // go through all polygon nodes and cure small local self-intersections
22348
22349
22350         function cureLocalIntersections(start, triangles, dim) {
22351                 var p = start;
22352
22353                 do {
22354                         var a = p.prev,
22355                                         b = p.next.next;
22356
22357                         if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
22358                                 triangles.push(a.i / dim);
22359                                 triangles.push(p.i / dim);
22360                                 triangles.push(b.i / dim); // remove two nodes involved
22361
22362                                 removeNode(p);
22363                                 removeNode(p.next);
22364                                 p = start = b;
22365                         }
22366
22367                         p = p.next;
22368                 } while (p !== start);
22369
22370                 return filterPoints(p);
22371         } // try splitting polygon into two and triangulate them independently
22372
22373
22374         function splitEarcut(start, triangles, dim, minX, minY, invSize) {
22375                 // look for a valid diagonal that divides the polygon into two
22376                 var a = start;
22377
22378                 do {
22379                         var b = a.next.next;
22380
22381                         while (b !== a.prev) {
22382                                 if (a.i !== b.i && isValidDiagonal(a, b)) {
22383                                         // split the polygon in two by the diagonal
22384                                         var c = splitPolygon(a, b); // filter colinear points around the cuts
22385
22386                                         a = filterPoints(a, a.next);
22387                                         c = filterPoints(c, c.next); // run earcut on each half
22388
22389                                         earcutLinked(a, triangles, dim, minX, minY, invSize);
22390                                         earcutLinked(c, triangles, dim, minX, minY, invSize);
22391                                         return;
22392                                 }
22393
22394                                 b = b.next;
22395                         }
22396
22397                         a = a.next;
22398                 } while (a !== start);
22399         } // link every hole into the outer loop, producing a single-ring polygon without holes
22400
22401
22402         function eliminateHoles(data, holeIndices, outerNode, dim) {
22403                 var queue = [];
22404                 var i, len, start, end, list;
22405
22406                 for (i = 0, len = holeIndices.length; i < len; i++) {
22407                         start = holeIndices[i] * dim;
22408                         end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
22409                         list = linkedList(data, start, end, dim, false);
22410                         if (list === list.next) list.steiner = true;
22411                         queue.push(getLeftmost(list));
22412                 }
22413
22414                 queue.sort(compareX); // process holes from left to right
22415
22416                 for (i = 0; i < queue.length; i++) {
22417                         eliminateHole(queue[i], outerNode);
22418                         outerNode = filterPoints(outerNode, outerNode.next);
22419                 }
22420
22421                 return outerNode;
22422         }
22423
22424         function compareX(a, b) {
22425                 return a.x - b.x;
22426         } // find a bridge between vertices that connects hole with an outer ring and and link it
22427
22428
22429         function eliminateHole(hole, outerNode) {
22430                 outerNode = findHoleBridge(hole, outerNode);
22431
22432                 if (outerNode) {
22433                         var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
22434
22435                         filterPoints(outerNode, outerNode.next);
22436                         filterPoints(b, b.next);
22437                 }
22438         } // David Eberly's algorithm for finding a bridge between hole and outer polygon
22439
22440
22441         function findHoleBridge(hole, outerNode) {
22442                 var p = outerNode;
22443                 var hx = hole.x;
22444                 var hy = hole.y;
22445                 var qx = -Infinity,
22446                                 m; // find a segment intersected by a ray from the hole's leftmost point to the left;
22447                 // segment's endpoint with lesser x will be potential connection point
22448
22449                 do {
22450                         if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
22451                                 var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
22452
22453                                 if (x <= hx && x > qx) {
22454                                         qx = x;
22455
22456                                         if (x === hx) {
22457                                                 if (hy === p.y) return p;
22458                                                 if (hy === p.next.y) return p.next;
22459                                         }
22460
22461                                         m = p.x < p.next.x ? p : p.next;
22462                                 }
22463                         }
22464
22465                         p = p.next;
22466                 } while (p !== outerNode);
22467
22468                 if (!m) return null;
22469                 if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
22470                 // look for points inside the triangle of hole point, segment intersection and endpoint;
22471                 // if there are no points found, we have a valid connection;
22472                 // otherwise choose the point of the minimum angle with the ray as connection point
22473
22474                 var stop = m,
22475                                 mx = m.x,
22476                                 my = m.y;
22477                 var tanMin = Infinity,
22478                                 tan;
22479                 p = m;
22480
22481                 do {
22482                         if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
22483                                 tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
22484
22485                                 if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
22486                                         m = p;
22487                                         tanMin = tan;
22488                                 }
22489                         }
22490
22491                         p = p.next;
22492                 } while (p !== stop);
22493
22494                 return m;
22495         } // whether sector in vertex m contains sector in vertex p in the same coordinates
22496
22497
22498         function sectorContainsSector(m, p) {
22499                 return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
22500         } // interlink polygon nodes in z-order
22501
22502
22503         function indexCurve(start, minX, minY, invSize) {
22504                 var p = start;
22505
22506                 do {
22507                         if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
22508                         p.prevZ = p.prev;
22509                         p.nextZ = p.next;
22510                         p = p.next;
22511                 } while (p !== start);
22512
22513                 p.prevZ.nextZ = null;
22514                 p.prevZ = null;
22515                 sortLinked(p);
22516         } // Simon Tatham's linked list merge sort algorithm
22517         // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
22518
22519
22520         function sortLinked(list) {
22521                 var i,
22522                                 p,
22523                                 q,
22524                                 e,
22525                                 tail,
22526                                 numMerges,
22527                                 pSize,
22528                                 qSize,
22529                                 inSize = 1;
22530
22531                 do {
22532                         p = list;
22533                         list = null;
22534                         tail = null;
22535                         numMerges = 0;
22536
22537                         while (p) {
22538                                 numMerges++;
22539                                 q = p;
22540                                 pSize = 0;
22541
22542                                 for (i = 0; i < inSize; i++) {
22543                                         pSize++;
22544                                         q = q.nextZ;
22545                                         if (!q) break;
22546                                 }
22547
22548                                 qSize = inSize;
22549
22550                                 while (pSize > 0 || qSize > 0 && q) {
22551                                         if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
22552                                                 e = p;
22553                                                 p = p.nextZ;
22554                                                 pSize--;
22555                                         } else {
22556                                                 e = q;
22557                                                 q = q.nextZ;
22558                                                 qSize--;
22559                                         }
22560
22561                                         if (tail) tail.nextZ = e;else list = e;
22562                                         e.prevZ = tail;
22563                                         tail = e;
22564                                 }
22565
22566                                 p = q;
22567                         }
22568
22569                         tail.nextZ = null;
22570                         inSize *= 2;
22571                 } while (numMerges > 1);
22572
22573                 return list;
22574         } // z-order of a point given coords and inverse of the longer side of data bbox
22575
22576
22577         function zOrder(x, y, minX, minY, invSize) {
22578                 // coords are transformed into non-negative 15-bit integer range
22579                 x = 32767 * (x - minX) * invSize;
22580                 y = 32767 * (y - minY) * invSize;
22581                 x = (x | x << 8) & 0x00FF00FF;
22582                 x = (x | x << 4) & 0x0F0F0F0F;
22583                 x = (x | x << 2) & 0x33333333;
22584                 x = (x | x << 1) & 0x55555555;
22585                 y = (y | y << 8) & 0x00FF00FF;
22586                 y = (y | y << 4) & 0x0F0F0F0F;
22587                 y = (y | y << 2) & 0x33333333;
22588                 y = (y | y << 1) & 0x55555555;
22589                 return x | y << 1;
22590         } // find the leftmost node of a polygon ring
22591
22592
22593         function getLeftmost(start) {
22594                 var p = start,
22595                                 leftmost = start;
22596
22597                 do {
22598                         if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
22599                         p = p.next;
22600                 } while (p !== start);
22601
22602                 return leftmost;
22603         } // check if a point lies within a convex triangle
22604
22605
22606         function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
22607                 return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
22608         } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
22609
22610
22611         function isValidDiagonal(a, b) {
22612                 return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
22613                 locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
22614                 area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
22615                 equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
22616         } // signed area of a triangle
22617
22618
22619         function area(p, q, r) {
22620                 return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
22621         } // check if two points are equal
22622
22623
22624         function equals(p1, p2) {
22625                 return p1.x === p2.x && p1.y === p2.y;
22626         } // check if two segments intersect
22627
22628
22629         function intersects(p1, q1, p2, q2) {
22630                 var o1 = sign(area(p1, q1, p2));
22631                 var o2 = sign(area(p1, q1, q2));
22632                 var o3 = sign(area(p2, q2, p1));
22633                 var o4 = sign(area(p2, q2, q1));
22634                 if (o1 !== o2 && o3 !== o4) return true; // general case
22635
22636                 if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
22637
22638                 if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
22639
22640                 if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
22641
22642                 if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
22643
22644                 return false;
22645         } // for collinear points p, q, r, check if point q lies on segment pr
22646
22647
22648         function onSegment(p, q, r) {
22649                 return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
22650         }
22651
22652         function sign(num) {
22653                 return num > 0 ? 1 : num < 0 ? -1 : 0;
22654         } // check if a polygon diagonal intersects any polygon segments
22655
22656
22657         function intersectsPolygon(a, b) {
22658                 var p = a;
22659
22660                 do {
22661                         if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b)) return true;
22662                         p = p.next;
22663                 } while (p !== a);
22664
22665                 return false;
22666         } // check if a polygon diagonal is locally inside the polygon
22667
22668
22669         function locallyInside(a, b) {
22670                 return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
22671         } // check if the middle point of a polygon diagonal is inside the polygon
22672
22673
22674         function middleInside(a, b) {
22675                 var p = a,
22676                                 inside = false;
22677                 var px = (a.x + b.x) / 2,
22678                                 py = (a.y + b.y) / 2;
22679
22680                 do {
22681                         if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x) inside = !inside;
22682                         p = p.next;
22683                 } while (p !== a);
22684
22685                 return inside;
22686         } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
22687         // if one belongs to the outer ring and another to a hole, it merges it into a single ring
22688
22689
22690         function splitPolygon(a, b) {
22691                 var a2 = new Node(a.i, a.x, a.y),
22692                                 b2 = new Node(b.i, b.x, b.y),
22693                                 an = a.next,
22694                                 bp = b.prev;
22695                 a.next = b;
22696                 b.prev = a;
22697                 a2.next = an;
22698                 an.prev = a2;
22699                 b2.next = a2;
22700                 a2.prev = b2;
22701                 bp.next = b2;
22702                 b2.prev = bp;
22703                 return b2;
22704         } // create a node and optionally link it with previous one (in a circular doubly linked list)
22705
22706
22707         function insertNode(i, x, y, last) {
22708                 var p = new Node(i, x, y);
22709
22710                 if (!last) {
22711                         p.prev = p;
22712                         p.next = p;
22713                 } else {
22714                         p.next = last.next;
22715                         p.prev = last;
22716                         last.next.prev = p;
22717                         last.next = p;
22718                 }
22719
22720                 return p;
22721         }
22722
22723         function removeNode(p) {
22724                 p.next.prev = p.prev;
22725                 p.prev.next = p.next;
22726                 if (p.prevZ) p.prevZ.nextZ = p.nextZ;
22727                 if (p.nextZ) p.nextZ.prevZ = p.prevZ;
22728         }
22729
22730         function Node(i, x, y) {
22731                 // vertex index in coordinates array
22732                 this.i = i; // vertex coordinates
22733
22734                 this.x = x;
22735                 this.y = y; // previous and next vertex nodes in a polygon ring
22736
22737                 this.prev = null;
22738                 this.next = null; // z-order curve value
22739
22740                 this.z = null; // previous and next nodes in z-order
22741
22742                 this.prevZ = null;
22743                 this.nextZ = null; // indicates whether this is a steiner point
22744
22745                 this.steiner = false;
22746         }
22747
22748         function signedArea(data, start, end, dim) {
22749                 var sum = 0;
22750
22751                 for (var i = start, j = end - dim; i < end; i += dim) {
22752                         sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
22753                         j = i;
22754                 }
22755
22756                 return sum;
22757         }
22758
22759         var ShapeUtils = {
22760                 // calculate area of the contour polygon
22761                 area: function area(contour) {
22762                         var n = contour.length;
22763                         var a = 0.0;
22764
22765                         for (var p = n - 1, q = 0; q < n; p = q++) {
22766                                 a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
22767                         }
22768
22769                         return a * 0.5;
22770                 },
22771                 isClockWise: function isClockWise(pts) {
22772                         return ShapeUtils.area(pts) < 0;
22773                 },
22774                 triangulateShape: function triangulateShape(contour, holes) {
22775                         var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
22776
22777                         var holeIndices = []; // array of hole indices
22778
22779                         var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
22780
22781                         removeDupEndPts(contour);
22782                         addContour(vertices, contour); //
22783
22784                         var holeIndex = contour.length;
22785                         holes.forEach(removeDupEndPts);
22786
22787                         for (var i = 0; i < holes.length; i++) {
22788                                 holeIndices.push(holeIndex);
22789                                 holeIndex += holes[i].length;
22790                                 addContour(vertices, holes[i]);
22791                         } //
22792
22793
22794                         var triangles = Earcut.triangulate(vertices, holeIndices); //
22795
22796                         for (var _i = 0; _i < triangles.length; _i += 3) {
22797                                 faces.push(triangles.slice(_i, _i + 3));
22798                         }
22799
22800                         return faces;
22801                 }
22802         };
22803
22804         function removeDupEndPts(points) {
22805                 var l = points.length;
22806
22807                 if (l > 2 && points[l - 1].equals(points[0])) {
22808                         points.pop();
22809                 }
22810         }
22811
22812         function addContour(vertices, contour) {
22813                 for (var i = 0; i < contour.length; i++) {
22814                         vertices.push(contour[i].x);
22815                         vertices.push(contour[i].y);
22816                 }
22817         }
22818
22819         var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
22820                 _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
22821
22822                 function ExtrudeBufferGeometry(shapes, options) {
22823                         var _this;
22824
22825                         _this = _BufferGeometry.call(this) || this;
22826                         _this.type = 'ExtrudeBufferGeometry';
22827                         _this.parameters = {
22828                                 shapes: shapes,
22829                                 options: options
22830                         };
22831                         shapes = Array.isArray(shapes) ? shapes : [shapes];
22832
22833                         var scope = _assertThisInitialized(_this);
22834
22835                         var verticesArray = [];
22836                         var uvArray = [];
22837
22838                         for (var i = 0, l = shapes.length; i < l; i++) {
22839                                 var shape = shapes[i];
22840                                 addShape(shape);
22841                         } // build geometry
22842
22843
22844                         _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
22845
22846                         _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
22847
22848                         _this.computeVertexNormals(); // functions
22849
22850
22851                         function addShape(shape) {
22852                                 var placeholder = []; // options
22853
22854                                 var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
22855                                 var steps = options.steps !== undefined ? options.steps : 1;
22856                                 var depth = options.depth !== undefined ? options.depth : 100;
22857                                 var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
22858                                 var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
22859                                 var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
22860                                 var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
22861                                 var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
22862                                 var extrudePath = options.extrudePath;
22863                                 var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
22864
22865                                 if (options.amount !== undefined) {
22866                                         console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
22867                                         depth = options.amount;
22868                                 } //
22869
22870
22871                                 var extrudePts,
22872                                                 extrudeByPath = false;
22873                                 var splineTube, binormal, normal, position2;
22874
22875                                 if (extrudePath) {
22876                                         extrudePts = extrudePath.getSpacedPoints(steps);
22877                                         extrudeByPath = true;
22878                                         bevelEnabled = false; // bevels not supported for path extrusion
22879                                         // SETUP TNB variables
22880                                         // TODO1 - have a .isClosed in spline?
22881
22882                                         splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
22883
22884                                         binormal = new Vector3();
22885                                         normal = new Vector3();
22886                                         position2 = new Vector3();
22887                                 } // Safeguards if bevels are not enabled
22888
22889
22890                                 if (!bevelEnabled) {
22891                                         bevelSegments = 0;
22892                                         bevelThickness = 0;
22893                                         bevelSize = 0;
22894                                         bevelOffset = 0;
22895                                 } // Variables initialization
22896
22897
22898                                 var shapePoints = shape.extractPoints(curveSegments);
22899                                 var vertices = shapePoints.shape;
22900                                 var holes = shapePoints.holes;
22901                                 var reverse = !ShapeUtils.isClockWise(vertices);
22902
22903                                 if (reverse) {
22904                                         vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
22905
22906                                         for (var h = 0, hl = holes.length; h < hl; h++) {
22907                                                 var ahole = holes[h];
22908
22909                                                 if (ShapeUtils.isClockWise(ahole)) {
22910                                                         holes[h] = ahole.reverse();
22911                                                 }
22912                                         }
22913                                 }
22914
22915                                 var faces = ShapeUtils.triangulateShape(vertices, holes);
22916                                 /* Vertices */
22917
22918                                 var contour = vertices; // vertices has all points but contour has only points of circumference
22919
22920                                 for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
22921                                         var _ahole = holes[_h];
22922                                         vertices = vertices.concat(_ahole);
22923                                 }
22924
22925                                 function scalePt2(pt, vec, size) {
22926                                         if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
22927                                         return vec.clone().multiplyScalar(size).add(pt);
22928                                 }
22929
22930                                 var vlen = vertices.length,
22931                                                 flen = faces.length; // Find directions for point movement
22932
22933                                 function getBevelVec(inPt, inPrev, inNext) {
22934                                         // computes for inPt the corresponding point inPt' on a new contour
22935                                         //       shifted by 1 unit (length of normalized vector) to the left
22936                                         // if we walk along contour clockwise, this new contour is outside the old one
22937                                         //
22938                                         // inPt' is the intersection of the two lines parallel to the two
22939                                         //      adjacent edges of inPt at a distance of 1 unit on the left side.
22940                                         var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
22941                                         // good reading for geometry algorithms (here: line-line intersection)
22942                                         // http://geomalgorithms.com/a05-_intersect-1.html
22943
22944                                         var v_prev_x = inPt.x - inPrev.x,
22945                                                         v_prev_y = inPt.y - inPrev.y;
22946                                         var v_next_x = inNext.x - inPt.x,
22947                                                         v_next_y = inNext.y - inPt.y;
22948                                         var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
22949
22950                                         var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
22951
22952                                         if (Math.abs(collinear0) > Number.EPSILON) {
22953                                                 // not collinear
22954                                                 // length of vectors for normalizing
22955                                                 var v_prev_len = Math.sqrt(v_prev_lensq);
22956                                                 var v_next_len = Math.sqrt(v_next_x * v_next_x + v_next_y * v_next_y); // shift adjacent points by unit vectors to the left
22957
22958                                                 var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
22959                                                 var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
22960                                                 var ptNextShift_x = inNext.x - v_next_y / v_next_len;
22961                                                 var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
22962
22963                                                 var sf = ((ptNextShift_x - ptPrevShift_x) * v_next_y - (ptNextShift_y - ptPrevShift_y) * v_next_x) / (v_prev_x * v_next_y - v_prev_y * v_next_x); // vector from inPt to intersection point
22964
22965                                                 v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
22966                                                 v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
22967                                                 //      but prevent crazy spikes
22968
22969                                                 var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
22970
22971                                                 if (v_trans_lensq <= 2) {
22972                                                         return new Vector2(v_trans_x, v_trans_y);
22973                                                 } else {
22974                                                         shrink_by = Math.sqrt(v_trans_lensq / 2);
22975                                                 }
22976                                         } else {
22977                                                 // handle special case of collinear edges
22978                                                 var direction_eq = false; // assumes: opposite
22979
22980                                                 if (v_prev_x > Number.EPSILON) {
22981                                                         if (v_next_x > Number.EPSILON) {
22982                                                                 direction_eq = true;
22983                                                         }
22984                                                 } else {
22985                                                         if (v_prev_x < -Number.EPSILON) {
22986                                                                 if (v_next_x < -Number.EPSILON) {
22987                                                                         direction_eq = true;
22988                                                                 }
22989                                                         } else {
22990                                                                 if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
22991                                                                         direction_eq = true;
22992                                                                 }
22993                                                         }
22994                                                 }
22995
22996                                                 if (direction_eq) {
22997                                                         // console.log("Warning: lines are a straight sequence");
22998                                                         v_trans_x = -v_prev_y;
22999                                                         v_trans_y = v_prev_x;
23000                                                         shrink_by = Math.sqrt(v_prev_lensq);
23001                                                 } else {
23002                                                         // console.log("Warning: lines are a straight spike");
23003                                                         v_trans_x = v_prev_x;
23004                                                         v_trans_y = v_prev_y;
23005                                                         shrink_by = Math.sqrt(v_prev_lensq / 2);
23006                                                 }
23007                                         }
23008
23009                                         return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
23010                                 }
23011
23012                                 var contourMovements = [];
23013
23014                                 for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
23015                                         if (j === il) j = 0;
23016                                         if (k === il) k = 0; // (j)---(i)---(k)
23017                                         // console.log('i,j,k', i, j , k)
23018
23019                                         contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
23020                                 }
23021
23022                                 var holesMovements = [];
23023                                 var oneHoleMovements,
23024                                                 verticesMovements = contourMovements.concat();
23025
23026                                 for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
23027                                         var _ahole2 = holes[_h2];
23028                                         oneHoleMovements = [];
23029
23030                                         for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
23031                                                 if (_j === _il) _j = 0;
23032                                                 if (_k === _il) _k = 0; //      (j)---(i)---(k)
23033
23034                                                 oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
23035                                         }
23036
23037                                         holesMovements.push(oneHoleMovements);
23038                                         verticesMovements = verticesMovements.concat(oneHoleMovements);
23039                                 } // Loop bevelSegments, 1 for the front, 1 for the back
23040
23041
23042                                 for (var b = 0; b < bevelSegments; b++) {
23043                                         //for ( b = bevelSegments; b > 0; b -- ) {
23044                                         var t = b / bevelSegments;
23045                                         var z = bevelThickness * Math.cos(t * Math.PI / 2);
23046
23047                                         var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
23048
23049
23050                                         for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
23051                                                 var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
23052                                                 v(vert.x, vert.y, -z);
23053                                         } // expand holes
23054
23055
23056                                         for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
23057                                                 var _ahole3 = holes[_h3];
23058                                                 oneHoleMovements = holesMovements[_h3];
23059
23060                                                 for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
23061                                                         var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
23062
23063                                                         v(_vert.x, _vert.y, -z);
23064                                                 }
23065                                         }
23066                                 }
23067
23068                                 var bs = bevelSize + bevelOffset; // Back facing vertices
23069
23070                                 for (var _i5 = 0; _i5 < vlen; _i5++) {
23071                                         var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
23072
23073                                         if (!extrudeByPath) {
23074                                                 v(_vert2.x, _vert2.y, 0);
23075                                         } else {
23076                                                 // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
23077                                                 normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
23078                                                 binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
23079                                                 position2.copy(extrudePts[0]).add(normal).add(binormal);
23080                                                 v(position2.x, position2.y, position2.z);
23081                                         }
23082                                 } // Add stepped vertices...
23083                                 // Including front facing vertices
23084
23085
23086                                 for (var s = 1; s <= steps; s++) {
23087                                         for (var _i6 = 0; _i6 < vlen; _i6++) {
23088                                                 var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
23089
23090                                                 if (!extrudeByPath) {
23091                                                         v(_vert3.x, _vert3.y, depth / steps * s);
23092                                                 } else {
23093                                                         // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
23094                                                         normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
23095                                                         binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
23096                                                         position2.copy(extrudePts[s]).add(normal).add(binormal);
23097                                                         v(position2.x, position2.y, position2.z);
23098                                                 }
23099                                         }
23100                                 } // Add bevel segments planes
23101                                 //for ( b = 1; b <= bevelSegments; b ++ ) {
23102
23103
23104                                 for (var _b = bevelSegments - 1; _b >= 0; _b--) {
23105                                         var _t = _b / bevelSegments;
23106
23107                                         var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
23108
23109                                         var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
23110
23111
23112                                         for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
23113                                                 var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
23114
23115                                                 v(_vert4.x, _vert4.y, depth + _z);
23116                                         } // expand holes
23117
23118
23119                                         for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
23120                                                 var _ahole4 = holes[_h4];
23121                                                 oneHoleMovements = holesMovements[_h4];
23122
23123                                                 for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
23124                                                         var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
23125
23126                                                         if (!extrudeByPath) {
23127                                                                 v(_vert5.x, _vert5.y, depth + _z);
23128                                                         } else {
23129                                                                 v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
23130                                                         }
23131                                                 }
23132                                         }
23133                                 }
23134                                 /* Faces */
23135                                 // Top and bottom faces
23136
23137
23138                                 buildLidFaces(); // Sides faces
23139
23140                                 buildSideFaces(); ///// Internal functions
23141
23142                                 function buildLidFaces() {
23143                                         var start = verticesArray.length / 3;
23144
23145                                         if (bevelEnabled) {
23146                                                 var layer = 0; // steps + 1
23147
23148                                                 var offset = vlen * layer; // Bottom faces
23149
23150                                                 for (var _i9 = 0; _i9 < flen; _i9++) {
23151                                                         var face = faces[_i9];
23152                                                         f3(face[2] + offset, face[1] + offset, face[0] + offset);
23153                                                 }
23154
23155                                                 layer = steps + bevelSegments * 2;
23156                                                 offset = vlen * layer; // Top faces
23157
23158                                                 for (var _i10 = 0; _i10 < flen; _i10++) {
23159                                                         var _face = faces[_i10];
23160                                                         f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
23161                                                 }
23162                                         } else {
23163                                                 // Bottom faces
23164                                                 for (var _i11 = 0; _i11 < flen; _i11++) {
23165                                                         var _face2 = faces[_i11];
23166                                                         f3(_face2[2], _face2[1], _face2[0]);
23167                                                 } // Top faces
23168
23169
23170                                                 for (var _i12 = 0; _i12 < flen; _i12++) {
23171                                                         var _face3 = faces[_i12];
23172                                                         f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
23173                                                 }
23174                                         }
23175
23176                                         scope.addGroup(start, verticesArray.length / 3 - start, 0);
23177                                 } // Create faces for the z-sides of the shape
23178
23179
23180                                 function buildSideFaces() {
23181                                         var start = verticesArray.length / 3;
23182                                         var layeroffset = 0;
23183                                         sidewalls(contour, layeroffset);
23184                                         layeroffset += contour.length;
23185
23186                                         for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
23187                                                 var _ahole5 = holes[_h5];
23188                                                 sidewalls(_ahole5, layeroffset); //, true
23189
23190                                                 layeroffset += _ahole5.length;
23191                                         }
23192
23193                                         scope.addGroup(start, verticesArray.length / 3 - start, 1);
23194                                 }
23195
23196                                 function sidewalls(contour, layeroffset) {
23197                                         var i = contour.length;
23198
23199                                         while (--i >= 0) {
23200                                                 var _j2 = i;
23201
23202                                                 var _k2 = i - 1;
23203
23204                                                 if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
23205
23206                                                 for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
23207                                                         var slen1 = vlen * _s;
23208                                                         var slen2 = vlen * (_s + 1);
23209
23210                                                         var a = layeroffset + _j2 + slen1,
23211                                                                         _b2 = layeroffset + _k2 + slen1,
23212                                                                         c = layeroffset + _k2 + slen2,
23213                                                                         d = layeroffset + _j2 + slen2;
23214
23215                                                         f4(a, _b2, c, d);
23216                                                 }
23217                                         }
23218                                 }
23219
23220                                 function v(x, y, z) {
23221                                         placeholder.push(x);
23222                                         placeholder.push(y);
23223                                         placeholder.push(z);
23224                                 }
23225
23226                                 function f3(a, b, c) {
23227                                         addVertex(a);
23228                                         addVertex(b);
23229                                         addVertex(c);
23230                                         var nextIndex = verticesArray.length / 3;
23231                                         var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
23232                                         addUV(uvs[0]);
23233                                         addUV(uvs[1]);
23234                                         addUV(uvs[2]);
23235                                 }
23236
23237                                 function f4(a, b, c, d) {
23238                                         addVertex(a);
23239                                         addVertex(b);
23240                                         addVertex(d);
23241                                         addVertex(b);
23242                                         addVertex(c);
23243                                         addVertex(d);
23244                                         var nextIndex = verticesArray.length / 3;
23245                                         var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
23246                                         addUV(uvs[0]);
23247                                         addUV(uvs[1]);
23248                                         addUV(uvs[3]);
23249                                         addUV(uvs[1]);
23250                                         addUV(uvs[2]);
23251                                         addUV(uvs[3]);
23252                                 }
23253
23254                                 function addVertex(index) {
23255                                         verticesArray.push(placeholder[index * 3 + 0]);
23256                                         verticesArray.push(placeholder[index * 3 + 1]);
23257                                         verticesArray.push(placeholder[index * 3 + 2]);
23258                                 }
23259
23260                                 function addUV(vector2) {
23261                                         uvArray.push(vector2.x);
23262                                         uvArray.push(vector2.y);
23263                                 }
23264                         }
23265
23266                         return _this;
23267                 }
23268
23269                 var _proto = ExtrudeBufferGeometry.prototype;
23270
23271                 _proto.toJSON = function toJSON() {
23272                         var data = BufferGeometry.prototype.toJSON.call(this);
23273                         var shapes = this.parameters.shapes;
23274                         var options = this.parameters.options;
23275                         return _toJSON(shapes, options, data);
23276                 };
23277
23278                 return ExtrudeBufferGeometry;
23279         }(BufferGeometry);
23280
23281         var WorldUVGenerator = {
23282                 generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
23283                         var a_x = vertices[indexA * 3];
23284                         var a_y = vertices[indexA * 3 + 1];
23285                         var b_x = vertices[indexB * 3];
23286                         var b_y = vertices[indexB * 3 + 1];
23287                         var c_x = vertices[indexC * 3];
23288                         var c_y = vertices[indexC * 3 + 1];
23289                         return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
23290                 },
23291                 generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
23292                         var a_x = vertices[indexA * 3];
23293                         var a_y = vertices[indexA * 3 + 1];
23294                         var a_z = vertices[indexA * 3 + 2];
23295                         var b_x = vertices[indexB * 3];
23296                         var b_y = vertices[indexB * 3 + 1];
23297                         var b_z = vertices[indexB * 3 + 2];
23298                         var c_x = vertices[indexC * 3];
23299                         var c_y = vertices[indexC * 3 + 1];
23300                         var c_z = vertices[indexC * 3 + 2];
23301                         var d_x = vertices[indexD * 3];
23302                         var d_y = vertices[indexD * 3 + 1];
23303                         var d_z = vertices[indexD * 3 + 2];
23304
23305                         if (Math.abs(a_y - b_y) < 0.01) {
23306                                 return [new Vector2(a_x, 1 - a_z), new Vector2(b_x, 1 - b_z), new Vector2(c_x, 1 - c_z), new Vector2(d_x, 1 - d_z)];
23307                         } else {
23308                                 return [new Vector2(a_y, 1 - a_z), new Vector2(b_y, 1 - b_z), new Vector2(c_y, 1 - c_z), new Vector2(d_y, 1 - d_z)];
23309                         }
23310                 }
23311         };
23312
23313         function _toJSON(shapes, options, data) {
23314                 data.shapes = [];
23315
23316                 if (Array.isArray(shapes)) {
23317                         for (var i = 0, l = shapes.length; i < l; i++) {
23318                                 var shape = shapes[i];
23319                                 data.shapes.push(shape.uuid);
23320                         }
23321                 } else {
23322                         data.shapes.push(shapes.uuid);
23323                 }
23324
23325                 if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
23326                 return data;
23327         }
23328
23329         var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
23330                 _inheritsLoose(ExtrudeGeometry, _Geometry);
23331
23332                 function ExtrudeGeometry(shapes, options) {
23333                         var _this;
23334
23335                         _this = _Geometry.call(this) || this;
23336                         _this.type = 'ExtrudeGeometry';
23337                         _this.parameters = {
23338                                 shapes: shapes,
23339                                 options: options
23340                         };
23341
23342                         _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
23343
23344                         _this.mergeVertices();
23345
23346                         return _this;
23347                 }
23348
23349                 var _proto = ExtrudeGeometry.prototype;
23350
23351                 _proto.toJSON = function toJSON() {
23352                         var data = _Geometry.prototype.toJSON.call(this);
23353
23354                         var shapes = this.parameters.shapes;
23355                         var options = this.parameters.options;
23356                         return _toJSON$1(shapes, options, data);
23357                 };
23358
23359                 return ExtrudeGeometry;
23360         }(Geometry);
23361
23362         function _toJSON$1(shapes, options, data) {
23363                 data.shapes = [];
23364
23365                 if (Array.isArray(shapes)) {
23366                         for (var i = 0, l = shapes.length; i < l; i++) {
23367                                 var shape = shapes[i];
23368                                 data.shapes.push(shape.uuid);
23369                         }
23370                 } else {
23371                         data.shapes.push(shapes.uuid);
23372                 }
23373
23374                 if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
23375                 return data;
23376         }
23377
23378         var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
23379                 _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
23380
23381                 function IcosahedronBufferGeometry(radius, detail) {
23382                         var _this;
23383
23384                         if (radius === void 0) {
23385                                 radius = 1;
23386                         }
23387
23388                         if (detail === void 0) {
23389                                 detail = 0;
23390                         }
23391
23392                         var t = (1 + Math.sqrt(5)) / 2;
23393                         var vertices = [-1, t, 0, 1, t, 0, -1, -t, 0, 1, -t, 0, 0, -1, t, 0, 1, t, 0, -1, -t, 0, 1, -t, t, 0, -1, t, 0, 1, -t, 0, -1, -t, 0, 1];
23394                         var indices = [0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1];
23395                         _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
23396                         _this.type = 'IcosahedronBufferGeometry';
23397                         _this.parameters = {
23398                                 radius: radius,
23399                                 detail: detail
23400                         };
23401                         return _this;
23402                 }
23403
23404                 return IcosahedronBufferGeometry;
23405         }(PolyhedronBufferGeometry);
23406
23407         var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
23408                 _inheritsLoose(IcosahedronGeometry, _Geometry);
23409
23410                 function IcosahedronGeometry(radius, detail) {
23411                         var _this;
23412
23413                         _this = _Geometry.call(this) || this;
23414                         _this.type = 'IcosahedronGeometry';
23415                         _this.parameters = {
23416                                 radius: radius,
23417                                 detail: detail
23418                         };
23419
23420                         _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
23421
23422                         _this.mergeVertices();
23423
23424                         return _this;
23425                 }
23426
23427                 return IcosahedronGeometry;
23428         }(Geometry);
23429
23430         var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
23431                 _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
23432
23433                 function LatheBufferGeometry(points, segments, phiStart, phiLength) {
23434                         var _this;
23435
23436                         if (segments === void 0) {
23437                                 segments = 12;
23438                         }
23439
23440                         if (phiStart === void 0) {
23441                                 phiStart = 0;
23442                         }
23443
23444                         if (phiLength === void 0) {
23445                                 phiLength = Math.PI * 2;
23446                         }
23447
23448                         _this = _BufferGeometry.call(this) || this;
23449                         _this.type = 'LatheBufferGeometry';
23450                         _this.parameters = {
23451                                 points: points,
23452                                 segments: segments,
23453                                 phiStart: phiStart,
23454                                 phiLength: phiLength
23455                         };
23456                         segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
23457
23458                         phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
23459
23460                         var indices = [];
23461                         var vertices = [];
23462                         var uvs = []; // helper variables
23463
23464                         var inverseSegments = 1.0 / segments;
23465                         var vertex = new Vector3();
23466                         var uv = new Vector2(); // generate vertices and uvs
23467
23468                         for (var i = 0; i <= segments; i++) {
23469                                 var phi = phiStart + i * inverseSegments * phiLength;
23470                                 var sin = Math.sin(phi);
23471                                 var cos = Math.cos(phi);
23472
23473                                 for (var j = 0; j <= points.length - 1; j++) {
23474                                         // vertex
23475                                         vertex.x = points[j].x * sin;
23476                                         vertex.y = points[j].y;
23477                                         vertex.z = points[j].x * cos;
23478                                         vertices.push(vertex.x, vertex.y, vertex.z); // uv
23479
23480                                         uv.x = i / segments;
23481                                         uv.y = j / (points.length - 1);
23482                                         uvs.push(uv.x, uv.y);
23483                                 }
23484                         } // indices
23485
23486
23487                         for (var _i = 0; _i < segments; _i++) {
23488                                 for (var _j = 0; _j < points.length - 1; _j++) {
23489                                         var base = _j + _i * points.length;
23490                                         var a = base;
23491                                         var b = base + points.length;
23492                                         var c = base + points.length + 1;
23493                                         var d = base + 1; // faces
23494
23495                                         indices.push(a, b, d);
23496                                         indices.push(b, c, d);
23497                                 }
23498                         } // build geometry
23499
23500
23501                         _this.setIndex(indices);
23502
23503                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
23504
23505                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
23506
23507
23508                         _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
23509                         // because the corresponding vertices are identical (but still have different UVs).
23510
23511
23512                         if (phiLength === Math.PI * 2) {
23513                                 var normals = _this.attributes.normal.array;
23514                                 var n1 = new Vector3();
23515                                 var n2 = new Vector3();
23516                                 var n = new Vector3(); // this is the buffer offset for the last line of vertices
23517
23518                                 var _base = segments * points.length * 3;
23519
23520                                 for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
23521                                         // select the normal of the vertex in the first line
23522                                         n1.x = normals[_j2 + 0];
23523                                         n1.y = normals[_j2 + 1];
23524                                         n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
23525
23526                                         n2.x = normals[_base + _j2 + 0];
23527                                         n2.y = normals[_base + _j2 + 1];
23528                                         n2.z = normals[_base + _j2 + 2]; // average normals
23529
23530                                         n.addVectors(n1, n2).normalize(); // assign the new values to both normals
23531
23532                                         normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
23533                                         normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
23534                                         normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
23535                                 }
23536                         }
23537
23538                         return _this;
23539                 }
23540
23541                 return LatheBufferGeometry;
23542         }(BufferGeometry);
23543
23544         var LatheGeometry = /*#__PURE__*/function (_Geometry) {
23545                 _inheritsLoose(LatheGeometry, _Geometry);
23546
23547                 function LatheGeometry(points, segments, phiStart, phiLength) {
23548                         var _this;
23549
23550                         _this = _Geometry.call(this) || this;
23551                         _this.type = 'LatheGeometry';
23552                         _this.parameters = {
23553                                 points: points,
23554                                 segments: segments,
23555                                 phiStart: phiStart,
23556                                 phiLength: phiLength
23557                         };
23558
23559                         _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
23560
23561                         _this.mergeVertices();
23562
23563                         return _this;
23564                 }
23565
23566                 return LatheGeometry;
23567         }(Geometry);
23568
23569         var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
23570                 _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
23571
23572                 function OctahedronBufferGeometry(radius, detail) {
23573                         var _this;
23574
23575                         if (radius === void 0) {
23576                                 radius = 1;
23577                         }
23578
23579                         if (detail === void 0) {
23580                                 detail = 0;
23581                         }
23582
23583                         var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
23584                         var indices = [0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2];
23585                         _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
23586                         _this.type = 'OctahedronBufferGeometry';
23587                         _this.parameters = {
23588                                 radius: radius,
23589                                 detail: detail
23590                         };
23591                         return _this;
23592                 }
23593
23594                 return OctahedronBufferGeometry;
23595         }(PolyhedronBufferGeometry);
23596
23597         var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
23598                 _inheritsLoose(OctahedronGeometry, _Geometry);
23599
23600                 function OctahedronGeometry(radius, detail) {
23601                         var _this;
23602
23603                         _this = _Geometry.call(this) || this;
23604                         _this.type = 'OctahedronGeometry';
23605                         _this.parameters = {
23606                                 radius: radius,
23607                                 detail: detail
23608                         };
23609
23610                         _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
23611
23612                         _this.mergeVertices();
23613
23614                         return _this;
23615                 }
23616
23617                 return OctahedronGeometry;
23618         }(Geometry);
23619
23620         /**
23621          * Parametric Surfaces Geometry
23622          * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
23623          */
23624
23625         function ParametricBufferGeometry(func, slices, stacks) {
23626                 BufferGeometry.call(this);
23627                 this.type = 'ParametricBufferGeometry';
23628                 this.parameters = {
23629                         func: func,
23630                         slices: slices,
23631                         stacks: stacks
23632                 }; // buffers
23633
23634                 var indices = [];
23635                 var vertices = [];
23636                 var normals = [];
23637                 var uvs = [];
23638                 var EPS = 0.00001;
23639                 var normal = new Vector3();
23640                 var p0 = new Vector3(),
23641                                 p1 = new Vector3();
23642                 var pu = new Vector3(),
23643                                 pv = new Vector3();
23644
23645                 if (func.length < 3) {
23646                         console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
23647                 } // generate vertices, normals and uvs
23648
23649
23650                 var sliceCount = slices + 1;
23651
23652                 for (var i = 0; i <= stacks; i++) {
23653                         var v = i / stacks;
23654
23655                         for (var j = 0; j <= slices; j++) {
23656                                 var u = j / slices; // vertex
23657
23658                                 func(u, v, p0);
23659                                 vertices.push(p0.x, p0.y, p0.z); // normal
23660                                 // approximate tangent vectors via finite differences
23661
23662                                 if (u - EPS >= 0) {
23663                                         func(u - EPS, v, p1);
23664                                         pu.subVectors(p0, p1);
23665                                 } else {
23666                                         func(u + EPS, v, p1);
23667                                         pu.subVectors(p1, p0);
23668                                 }
23669
23670                                 if (v - EPS >= 0) {
23671                                         func(u, v - EPS, p1);
23672                                         pv.subVectors(p0, p1);
23673                                 } else {
23674                                         func(u, v + EPS, p1);
23675                                         pv.subVectors(p1, p0);
23676                                 } // cross product of tangent vectors returns surface normal
23677
23678
23679                                 normal.crossVectors(pu, pv).normalize();
23680                                 normals.push(normal.x, normal.y, normal.z); // uv
23681
23682                                 uvs.push(u, v);
23683                         }
23684                 } // generate indices
23685
23686
23687                 for (var _i = 0; _i < stacks; _i++) {
23688                         for (var _j = 0; _j < slices; _j++) {
23689                                 var a = _i * sliceCount + _j;
23690                                 var b = _i * sliceCount + _j + 1;
23691                                 var c = (_i + 1) * sliceCount + _j + 1;
23692                                 var d = (_i + 1) * sliceCount + _j; // faces one and two
23693
23694                                 indices.push(a, b, d);
23695                                 indices.push(b, c, d);
23696                         }
23697                 } // build geometry
23698
23699
23700                 this.setIndex(indices);
23701                 this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
23702                 this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
23703                 this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
23704         }
23705
23706         ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
23707         ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
23708
23709         /**
23710          * Parametric Surfaces Geometry
23711          * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
23712          */
23713
23714         function ParametricGeometry(func, slices, stacks) {
23715                 Geometry.call(this);
23716                 this.type = 'ParametricGeometry';
23717                 this.parameters = {
23718                         func: func,
23719                         slices: slices,
23720                         stacks: stacks
23721                 };
23722                 this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
23723                 this.mergeVertices();
23724         }
23725
23726         ParametricGeometry.prototype = Object.create(Geometry.prototype);
23727         ParametricGeometry.prototype.constructor = ParametricGeometry;
23728
23729         var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
23730                 _inheritsLoose(PlaneGeometry, _Geometry);
23731
23732                 function PlaneGeometry(width, height, widthSegments, heightSegments) {
23733                         var _this;
23734
23735                         _this = _Geometry.call(this) || this;
23736                         _this.type = 'PlaneGeometry';
23737                         _this.parameters = {
23738                                 width: width,
23739                                 height: height,
23740                                 widthSegments: widthSegments,
23741                                 heightSegments: heightSegments
23742                         };
23743
23744                         _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
23745
23746                         _this.mergeVertices();
23747
23748                         return _this;
23749                 }
23750
23751                 return PlaneGeometry;
23752         }(Geometry);
23753
23754         var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
23755                 _inheritsLoose(PolyhedronGeometry, _Geometry);
23756
23757                 function PolyhedronGeometry(vertices, indices, radius, detail) {
23758                         var _this;
23759
23760                         _this = _Geometry.call(this) || this;
23761                         _this.type = 'PolyhedronGeometry';
23762                         _this.parameters = {
23763                                 vertices: vertices,
23764                                 indices: indices,
23765                                 radius: radius,
23766                                 detail: detail
23767                         };
23768
23769                         _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
23770
23771                         _this.mergeVertices();
23772
23773                         return _this;
23774                 }
23775
23776                 return PolyhedronGeometry;
23777         }(Geometry);
23778
23779         var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
23780                 _inheritsLoose(RingBufferGeometry, _BufferGeometry);
23781
23782                 function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
23783                         var _this;
23784
23785                         if (innerRadius === void 0) {
23786                                 innerRadius = 0.5;
23787                         }
23788
23789                         if (outerRadius === void 0) {
23790                                 outerRadius = 1;
23791                         }
23792
23793                         if (thetaSegments === void 0) {
23794                                 thetaSegments = 8;
23795                         }
23796
23797                         if (phiSegments === void 0) {
23798                                 phiSegments = 1;
23799                         }
23800
23801                         if (thetaStart === void 0) {
23802                                 thetaStart = 0;
23803                         }
23804
23805                         if (thetaLength === void 0) {
23806                                 thetaLength = Math.PI * 2;
23807                         }
23808
23809                         _this = _BufferGeometry.call(this) || this;
23810                         _this.type = 'RingBufferGeometry';
23811                         _this.parameters = {
23812                                 innerRadius: innerRadius,
23813                                 outerRadius: outerRadius,
23814                                 thetaSegments: thetaSegments,
23815                                 phiSegments: phiSegments,
23816                                 thetaStart: thetaStart,
23817                                 thetaLength: thetaLength
23818                         };
23819                         thetaSegments = Math.max(3, thetaSegments);
23820                         phiSegments = Math.max(1, phiSegments); // buffers
23821
23822                         var indices = [];
23823                         var vertices = [];
23824                         var normals = [];
23825                         var uvs = []; // some helper variables
23826
23827                         var radius = innerRadius;
23828                         var radiusStep = (outerRadius - innerRadius) / phiSegments;
23829                         var vertex = new Vector3();
23830                         var uv = new Vector2(); // generate vertices, normals and uvs
23831
23832                         for (var j = 0; j <= phiSegments; j++) {
23833                                 for (var i = 0; i <= thetaSegments; i++) {
23834                                         // values are generate from the inside of the ring to the outside
23835                                         var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
23836
23837                                         vertex.x = radius * Math.cos(segment);
23838                                         vertex.y = radius * Math.sin(segment);
23839                                         vertices.push(vertex.x, vertex.y, vertex.z); // normal
23840
23841                                         normals.push(0, 0, 1); // uv
23842
23843                                         uv.x = (vertex.x / outerRadius + 1) / 2;
23844                                         uv.y = (vertex.y / outerRadius + 1) / 2;
23845                                         uvs.push(uv.x, uv.y);
23846                                 } // increase the radius for next row of vertices
23847
23848
23849                                 radius += radiusStep;
23850                         } // indices
23851
23852
23853                         for (var _j = 0; _j < phiSegments; _j++) {
23854                                 var thetaSegmentLevel = _j * (thetaSegments + 1);
23855
23856                                 for (var _i = 0; _i < thetaSegments; _i++) {
23857                                         var _segment = _i + thetaSegmentLevel;
23858
23859                                         var a = _segment;
23860                                         var b = _segment + thetaSegments + 1;
23861                                         var c = _segment + thetaSegments + 2;
23862                                         var d = _segment + 1; // faces
23863
23864                                         indices.push(a, b, d);
23865                                         indices.push(b, c, d);
23866                                 }
23867                         } // build geometry
23868
23869
23870                         _this.setIndex(indices);
23871
23872                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
23873
23874                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
23875
23876                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
23877
23878                         return _this;
23879                 }
23880
23881                 return RingBufferGeometry;
23882         }(BufferGeometry);
23883
23884         var RingGeometry = /*#__PURE__*/function (_Geometry) {
23885                 _inheritsLoose(RingGeometry, _Geometry);
23886
23887                 function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
23888                         var _this;
23889
23890                         _this = _Geometry.call(this) || this;
23891                         _this.type = 'RingGeometry';
23892                         _this.parameters = {
23893                                 innerRadius: innerRadius,
23894                                 outerRadius: outerRadius,
23895                                 thetaSegments: thetaSegments,
23896                                 phiSegments: phiSegments,
23897                                 thetaStart: thetaStart,
23898                                 thetaLength: thetaLength
23899                         };
23900
23901                         _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
23902
23903                         _this.mergeVertices();
23904
23905                         return _this;
23906                 }
23907
23908                 return RingGeometry;
23909         }(Geometry);
23910
23911         var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
23912                 _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
23913
23914                 function ShapeBufferGeometry(shapes, curveSegments) {
23915                         var _this;
23916
23917                         if (curveSegments === void 0) {
23918                                 curveSegments = 12;
23919                         }
23920
23921                         _this = _BufferGeometry.call(this) || this;
23922                         _this.type = 'ShapeBufferGeometry';
23923                         _this.parameters = {
23924                                 shapes: shapes,
23925                                 curveSegments: curveSegments
23926                         }; // buffers
23927
23928                         var indices = [];
23929                         var vertices = [];
23930                         var normals = [];
23931                         var uvs = []; // helper variables
23932
23933                         var groupStart = 0;
23934                         var groupCount = 0; // allow single and array values for "shapes" parameter
23935
23936                         if (Array.isArray(shapes) === false) {
23937                                 addShape(shapes);
23938                         } else {
23939                                 for (var i = 0; i < shapes.length; i++) {
23940                                         addShape(shapes[i]);
23941
23942                                         _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
23943
23944
23945                                         groupStart += groupCount;
23946                                         groupCount = 0;
23947                                 }
23948                         } // build geometry
23949
23950
23951                         _this.setIndex(indices);
23952
23953                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
23954
23955                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
23956
23957                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
23958
23959
23960                         function addShape(shape) {
23961                                 var indexOffset = vertices.length / 3;
23962                                 var points = shape.extractPoints(curveSegments);
23963                                 var shapeVertices = points.shape;
23964                                 var shapeHoles = points.holes; // check direction of vertices
23965
23966                                 if (ShapeUtils.isClockWise(shapeVertices) === false) {
23967                                         shapeVertices = shapeVertices.reverse();
23968                                 }
23969
23970                                 for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
23971                                         var shapeHole = shapeHoles[_i];
23972
23973                                         if (ShapeUtils.isClockWise(shapeHole) === true) {
23974                                                 shapeHoles[_i] = shapeHole.reverse();
23975                                         }
23976                                 }
23977
23978                                 var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
23979
23980                                 for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
23981                                         var _shapeHole = shapeHoles[_i2];
23982                                         shapeVertices = shapeVertices.concat(_shapeHole);
23983                                 } // vertices, normals, uvs
23984
23985
23986                                 for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
23987                                         var vertex = shapeVertices[_i3];
23988                                         vertices.push(vertex.x, vertex.y, 0);
23989                                         normals.push(0, 0, 1);
23990                                         uvs.push(vertex.x, vertex.y); // world uvs
23991                                 } // incides
23992
23993
23994                                 for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
23995                                         var face = faces[_i4];
23996                                         var a = face[0] + indexOffset;
23997                                         var b = face[1] + indexOffset;
23998                                         var c = face[2] + indexOffset;
23999                                         indices.push(a, b, c);
24000                                         groupCount += 3;
24001                                 }
24002                         }
24003
24004                         return _this;
24005                 }
24006
24007                 var _proto = ShapeBufferGeometry.prototype;
24008
24009                 _proto.toJSON = function toJSON() {
24010                         var data = BufferGeometry.prototype.toJSON.call(this);
24011                         var shapes = this.parameters.shapes;
24012                         return _toJSON$2(shapes, data);
24013                 };
24014
24015                 return ShapeBufferGeometry;
24016         }(BufferGeometry);
24017
24018         function _toJSON$2(shapes, data) {
24019                 data.shapes = [];
24020
24021                 if (Array.isArray(shapes)) {
24022                         for (var i = 0, l = shapes.length; i < l; i++) {
24023                                 var shape = shapes[i];
24024                                 data.shapes.push(shape.uuid);
24025                         }
24026                 } else {
24027                         data.shapes.push(shapes.uuid);
24028                 }
24029
24030                 return data;
24031         }
24032
24033         var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
24034                 _inheritsLoose(ShapeGeometry, _Geometry);
24035
24036                 function ShapeGeometry(shapes, curveSegments) {
24037                         var _this;
24038
24039                         _this = _Geometry.call(this) || this;
24040                         _this.type = 'ShapeGeometry';
24041
24042                         if (typeof curveSegments === 'object') {
24043                                 console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
24044                                 curveSegments = curveSegments.curveSegments;
24045                         }
24046
24047                         _this.parameters = {
24048                                 shapes: shapes,
24049                                 curveSegments: curveSegments
24050                         };
24051
24052                         _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
24053
24054                         _this.mergeVertices();
24055
24056                         return _this;
24057                 }
24058
24059                 var _proto = ShapeGeometry.prototype;
24060
24061                 _proto.toJSON = function toJSON() {
24062                         var data = Geometry.prototype.toJSON.call(this);
24063                         var shapes = this.parameters.shapes;
24064                         return _toJSON$3(shapes, data);
24065                 };
24066
24067                 return ShapeGeometry;
24068         }(Geometry);
24069
24070         function _toJSON$3(shapes, data) {
24071                 data.shapes = [];
24072
24073                 if (Array.isArray(shapes)) {
24074                         for (var i = 0, l = shapes.length; i < l; i++) {
24075                                 var shape = shapes[i];
24076                                 data.shapes.push(shape.uuid);
24077                         }
24078                 } else {
24079                         data.shapes.push(shapes.uuid);
24080                 }
24081
24082                 return data;
24083         }
24084
24085         var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
24086                 _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
24087
24088                 function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
24089                         var _this;
24090
24091                         if (radius === void 0) {
24092                                 radius = 1;
24093                         }
24094
24095                         if (widthSegments === void 0) {
24096                                 widthSegments = 8;
24097                         }
24098
24099                         if (heightSegments === void 0) {
24100                                 heightSegments = 6;
24101                         }
24102
24103                         if (phiStart === void 0) {
24104                                 phiStart = 0;
24105                         }
24106
24107                         if (phiLength === void 0) {
24108                                 phiLength = Math.PI * 2;
24109                         }
24110
24111                         if (thetaStart === void 0) {
24112                                 thetaStart = 0;
24113                         }
24114
24115                         if (thetaLength === void 0) {
24116                                 thetaLength = Math.PI;
24117                         }
24118
24119                         _this = _BufferGeometry.call(this) || this;
24120                         _this.type = 'SphereBufferGeometry';
24121                         _this.parameters = {
24122                                 radius: radius,
24123                                 widthSegments: widthSegments,
24124                                 heightSegments: heightSegments,
24125                                 phiStart: phiStart,
24126                                 phiLength: phiLength,
24127                                 thetaStart: thetaStart,
24128                                 thetaLength: thetaLength
24129                         };
24130                         widthSegments = Math.max(3, Math.floor(widthSegments));
24131                         heightSegments = Math.max(2, Math.floor(heightSegments));
24132                         var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
24133                         var index = 0;
24134                         var grid = [];
24135                         var vertex = new Vector3();
24136                         var normal = new Vector3(); // buffers
24137
24138                         var indices = [];
24139                         var vertices = [];
24140                         var normals = [];
24141                         var uvs = []; // generate vertices, normals and uvs
24142
24143                         for (var iy = 0; iy <= heightSegments; iy++) {
24144                                 var verticesRow = [];
24145                                 var v = iy / heightSegments; // special case for the poles
24146
24147                                 var uOffset = 0;
24148
24149                                 if (iy == 0 && thetaStart == 0) {
24150                                         uOffset = 0.5 / widthSegments;
24151                                 } else if (iy == heightSegments && thetaEnd == Math.PI) {
24152                                         uOffset = -0.5 / widthSegments;
24153                                 }
24154
24155                                 for (var ix = 0; ix <= widthSegments; ix++) {
24156                                         var u = ix / widthSegments; // vertex
24157
24158                                         vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
24159                                         vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
24160                                         vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
24161                                         vertices.push(vertex.x, vertex.y, vertex.z); // normal
24162
24163                                         normal.copy(vertex).normalize();
24164                                         normals.push(normal.x, normal.y, normal.z); // uv
24165
24166                                         uvs.push(u + uOffset, 1 - v);
24167                                         verticesRow.push(index++);
24168                                 }
24169
24170                                 grid.push(verticesRow);
24171                         } // indices
24172
24173
24174                         for (var _iy = 0; _iy < heightSegments; _iy++) {
24175                                 for (var _ix = 0; _ix < widthSegments; _ix++) {
24176                                         var a = grid[_iy][_ix + 1];
24177                                         var b = grid[_iy][_ix];
24178                                         var c = grid[_iy + 1][_ix];
24179                                         var d = grid[_iy + 1][_ix + 1];
24180                                         if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
24181                                         if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
24182                                 }
24183                         } // build geometry
24184
24185
24186                         _this.setIndex(indices);
24187
24188                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
24189
24190                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
24191
24192                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
24193
24194                         return _this;
24195                 }
24196
24197                 return SphereBufferGeometry;
24198         }(BufferGeometry);
24199
24200         var SphereGeometry = /*#__PURE__*/function (_Geometry) {
24201                 _inheritsLoose(SphereGeometry, _Geometry);
24202
24203                 function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
24204                         var _this;
24205
24206                         _this = _Geometry.call(this) || this;
24207                         _this.type = 'SphereGeometry';
24208                         _this.parameters = {
24209                                 radius: radius,
24210                                 widthSegments: widthSegments,
24211                                 heightSegments: heightSegments,
24212                                 phiStart: phiStart,
24213                                 phiLength: phiLength,
24214                                 thetaStart: thetaStart,
24215                                 thetaLength: thetaLength
24216                         };
24217
24218                         _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
24219
24220                         _this.mergeVertices();
24221
24222                         return _this;
24223                 }
24224
24225                 return SphereGeometry;
24226         }(Geometry);
24227
24228         var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
24229                 _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
24230
24231                 function TetrahedronBufferGeometry(radius, detail) {
24232                         var _this;
24233
24234                         if (radius === void 0) {
24235                                 radius = 1;
24236                         }
24237
24238                         if (detail === void 0) {
24239                                 detail = 0;
24240                         }
24241
24242                         var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
24243                         var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
24244                         _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
24245                         _this.type = 'TetrahedronBufferGeometry';
24246                         _this.parameters = {
24247                                 radius: radius,
24248                                 detail: detail
24249                         };
24250                         return _this;
24251                 }
24252
24253                 return TetrahedronBufferGeometry;
24254         }(PolyhedronBufferGeometry);
24255
24256         var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
24257                 _inheritsLoose(TetrahedronGeometry, _Geometry);
24258
24259                 function TetrahedronGeometry(radius, detail) {
24260                         var _this;
24261
24262                         _this = _Geometry.call(this) || this;
24263                         _this.type = 'TetrahedronGeometry';
24264                         _this.parameters = {
24265                                 radius: radius,
24266                                 detail: detail
24267                         };
24268
24269                         _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
24270
24271                         _this.mergeVertices();
24272
24273                         return _this;
24274                 }
24275
24276                 return TetrahedronGeometry;
24277         }(Geometry);
24278
24279         var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
24280                 _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
24281
24282                 function TextBufferGeometry(text, parameters) {
24283                         var _this;
24284
24285                         if (parameters === void 0) {
24286                                 parameters = {};
24287                         }
24288
24289                         var font = parameters.font;
24290
24291                         if (!(font && font.isFont)) {
24292                                 console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
24293                                 return new BufferGeometry() || _assertThisInitialized(_this);
24294                         }
24295
24296                         var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
24297
24298                         parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
24299
24300                         if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
24301                         if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
24302                         if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
24303                         _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
24304                         _this.type = 'TextBufferGeometry';
24305                         return _this;
24306                 }
24307
24308                 return TextBufferGeometry;
24309         }(ExtrudeBufferGeometry);
24310
24311         var TextGeometry = /*#__PURE__*/function (_Geometry) {
24312                 _inheritsLoose(TextGeometry, _Geometry);
24313
24314                 function TextGeometry(text, parameters) {
24315                         var _this;
24316
24317                         _this = _Geometry.call(this) || this;
24318                         _this.type = 'TextGeometry';
24319                         _this.parameters = {
24320                                 text: text,
24321                                 parameters: parameters
24322                         };
24323
24324                         _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
24325
24326                         _this.mergeVertices();
24327
24328                         return _this;
24329                 }
24330
24331                 return TextGeometry;
24332         }(Geometry);
24333
24334         var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
24335                 _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
24336
24337                 function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
24338                         var _this;
24339
24340                         if (radius === void 0) {
24341                                 radius = 1;
24342                         }
24343
24344                         if (tube === void 0) {
24345                                 tube = 0.4;
24346                         }
24347
24348                         if (radialSegments === void 0) {
24349                                 radialSegments = 8;
24350                         }
24351
24352                         if (tubularSegments === void 0) {
24353                                 tubularSegments = 6;
24354                         }
24355
24356                         if (arc === void 0) {
24357                                 arc = Math.PI * 2;
24358                         }
24359
24360                         _this = _BufferGeometry.call(this) || this;
24361                         _this.type = 'TorusBufferGeometry';
24362                         _this.parameters = {
24363                                 radius: radius,
24364                                 tube: tube,
24365                                 radialSegments: radialSegments,
24366                                 tubularSegments: tubularSegments,
24367                                 arc: arc
24368                         };
24369                         radialSegments = Math.floor(radialSegments);
24370                         tubularSegments = Math.floor(tubularSegments); // buffers
24371
24372                         var indices = [];
24373                         var vertices = [];
24374                         var normals = [];
24375                         var uvs = []; // helper variables
24376
24377                         var center = new Vector3();
24378                         var vertex = new Vector3();
24379                         var normal = new Vector3(); // generate vertices, normals and uvs
24380
24381                         for (var j = 0; j <= radialSegments; j++) {
24382                                 for (var i = 0; i <= tubularSegments; i++) {
24383                                         var u = i / tubularSegments * arc;
24384                                         var v = j / radialSegments * Math.PI * 2; // vertex
24385
24386                                         vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
24387                                         vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
24388                                         vertex.z = tube * Math.sin(v);
24389                                         vertices.push(vertex.x, vertex.y, vertex.z); // normal
24390
24391                                         center.x = radius * Math.cos(u);
24392                                         center.y = radius * Math.sin(u);
24393                                         normal.subVectors(vertex, center).normalize();
24394                                         normals.push(normal.x, normal.y, normal.z); // uv
24395
24396                                         uvs.push(i / tubularSegments);
24397                                         uvs.push(j / radialSegments);
24398                                 }
24399                         } // generate indices
24400
24401
24402                         for (var _j = 1; _j <= radialSegments; _j++) {
24403                                 for (var _i = 1; _i <= tubularSegments; _i++) {
24404                                         // indices
24405                                         var a = (tubularSegments + 1) * _j + _i - 1;
24406                                         var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
24407                                         var c = (tubularSegments + 1) * (_j - 1) + _i;
24408                                         var d = (tubularSegments + 1) * _j + _i; // faces
24409
24410                                         indices.push(a, b, d);
24411                                         indices.push(b, c, d);
24412                                 }
24413                         } // build geometry
24414
24415
24416                         _this.setIndex(indices);
24417
24418                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
24419
24420                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
24421
24422                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
24423
24424                         return _this;
24425                 }
24426
24427                 return TorusBufferGeometry;
24428         }(BufferGeometry);
24429
24430         var TorusGeometry = /*#__PURE__*/function (_Geometry) {
24431                 _inheritsLoose(TorusGeometry, _Geometry);
24432
24433                 function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
24434                         var _this;
24435
24436                         _this = _Geometry.call(this) || this;
24437                         _this.type = 'TorusGeometry';
24438                         _this.parameters = {
24439                                 radius: radius,
24440                                 tube: tube,
24441                                 radialSegments: radialSegments,
24442                                 tubularSegments: tubularSegments,
24443                                 arc: arc
24444                         };
24445
24446                         _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
24447
24448                         _this.mergeVertices();
24449
24450                         return _this;
24451                 }
24452
24453                 return TorusGeometry;
24454         }(Geometry);
24455
24456         var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
24457                 _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
24458
24459                 function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
24460                         var _this;
24461
24462                         if (radius === void 0) {
24463                                 radius = 1;
24464                         }
24465
24466                         if (tube === void 0) {
24467                                 tube = 0.4;
24468                         }
24469
24470                         if (tubularSegments === void 0) {
24471                                 tubularSegments = 64;
24472                         }
24473
24474                         if (radialSegments === void 0) {
24475                                 radialSegments = 8;
24476                         }
24477
24478                         if (p === void 0) {
24479                                 p = 2;
24480                         }
24481
24482                         if (q === void 0) {
24483                                 q = 3;
24484                         }
24485
24486                         _this = _BufferGeometry.call(this) || this;
24487                         _this.type = 'TorusKnotBufferGeometry';
24488                         _this.parameters = {
24489                                 radius: radius,
24490                                 tube: tube,
24491                                 tubularSegments: tubularSegments,
24492                                 radialSegments: radialSegments,
24493                                 p: p,
24494                                 q: q
24495                         };
24496                         tubularSegments = Math.floor(tubularSegments);
24497                         radialSegments = Math.floor(radialSegments); // buffers
24498
24499                         var indices = [];
24500                         var vertices = [];
24501                         var normals = [];
24502                         var uvs = []; // helper variables
24503
24504                         var vertex = new Vector3();
24505                         var normal = new Vector3();
24506                         var P1 = new Vector3();
24507                         var P2 = new Vector3();
24508                         var B = new Vector3();
24509                         var T = new Vector3();
24510                         var N = new Vector3(); // generate vertices, normals and uvs
24511
24512                         for (var i = 0; i <= tubularSegments; ++i) {
24513                                 // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
24514                                 var u = i / tubularSegments * p * Math.PI * 2; // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
24515                                 // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
24516
24517                                 calculatePositionOnCurve(u, p, q, radius, P1);
24518                                 calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
24519
24520                                 T.subVectors(P2, P1);
24521                                 N.addVectors(P2, P1);
24522                                 B.crossVectors(T, N);
24523                                 N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
24524
24525                                 B.normalize();
24526                                 N.normalize();
24527
24528                                 for (var j = 0; j <= radialSegments; ++j) {
24529                                         // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
24530                                         // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
24531                                         var v = j / radialSegments * Math.PI * 2;
24532                                         var cx = -tube * Math.cos(v);
24533                                         var cy = tube * Math.sin(v); // now calculate the final vertex position.
24534                                         // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
24535
24536                                         vertex.x = P1.x + (cx * N.x + cy * B.x);
24537                                         vertex.y = P1.y + (cx * N.y + cy * B.y);
24538                                         vertex.z = P1.z + (cx * N.z + cy * B.z);
24539                                         vertices.push(vertex.x, vertex.y, vertex.z); // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
24540
24541                                         normal.subVectors(vertex, P1).normalize();
24542                                         normals.push(normal.x, normal.y, normal.z); // uv
24543
24544                                         uvs.push(i / tubularSegments);
24545                                         uvs.push(j / radialSegments);
24546                                 }
24547                         } // generate indices
24548
24549
24550                         for (var _j = 1; _j <= tubularSegments; _j++) {
24551                                 for (var _i = 1; _i <= radialSegments; _i++) {
24552                                         // indices
24553                                         var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
24554                                         var b = (radialSegments + 1) * _j + (_i - 1);
24555                                         var c = (radialSegments + 1) * _j + _i;
24556                                         var d = (radialSegments + 1) * (_j - 1) + _i; // faces
24557
24558                                         indices.push(a, b, d);
24559                                         indices.push(b, c, d);
24560                                 }
24561                         } // build geometry
24562
24563
24564                         _this.setIndex(indices);
24565
24566                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
24567
24568                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
24569
24570                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
24571
24572
24573                         function calculatePositionOnCurve(u, p, q, radius, position) {
24574                                 var cu = Math.cos(u);
24575                                 var su = Math.sin(u);
24576                                 var quOverP = q / p * u;
24577                                 var cs = Math.cos(quOverP);
24578                                 position.x = radius * (2 + cs) * 0.5 * cu;
24579                                 position.y = radius * (2 + cs) * su * 0.5;
24580                                 position.z = radius * Math.sin(quOverP) * 0.5;
24581                         }
24582
24583                         return _this;
24584                 }
24585
24586                 return TorusKnotBufferGeometry;
24587         }(BufferGeometry);
24588
24589         var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
24590                 _inheritsLoose(TorusKnotGeometry, _Geometry);
24591
24592                 function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
24593                         var _this;
24594
24595                         _this = _Geometry.call(this) || this;
24596                         _this.type = 'TorusKnotGeometry';
24597                         _this.parameters = {
24598                                 radius: radius,
24599                                 tube: tube,
24600                                 tubularSegments: tubularSegments,
24601                                 radialSegments: radialSegments,
24602                                 p: p,
24603                                 q: q
24604                         };
24605                         if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
24606
24607                         _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
24608
24609                         _this.mergeVertices();
24610
24611                         return _this;
24612                 }
24613
24614                 return TorusKnotGeometry;
24615         }(Geometry);
24616
24617         var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
24618                 _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
24619
24620                 function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
24621                         var _this;
24622
24623                         if (tubularSegments === void 0) {
24624                                 tubularSegments = 64;
24625                         }
24626
24627                         if (radius === void 0) {
24628                                 radius = 1;
24629                         }
24630
24631                         if (radialSegments === void 0) {
24632                                 radialSegments = 8;
24633                         }
24634
24635                         if (closed === void 0) {
24636                                 closed = false;
24637                         }
24638
24639                         _this = _BufferGeometry.call(this) || this;
24640                         _this.type = 'TubeBufferGeometry';
24641                         _this.parameters = {
24642                                 path: path,
24643                                 tubularSegments: tubularSegments,
24644                                 radius: radius,
24645                                 radialSegments: radialSegments,
24646                                 closed: closed
24647                         };
24648                         var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
24649
24650                         _this.tangents = frames.tangents;
24651                         _this.normals = frames.normals;
24652                         _this.binormals = frames.binormals; // helper variables
24653
24654                         var vertex = new Vector3();
24655                         var normal = new Vector3();
24656                         var uv = new Vector2();
24657                         var P = new Vector3(); // buffer
24658
24659                         var vertices = [];
24660                         var normals = [];
24661                         var uvs = [];
24662                         var indices = []; // create buffer data
24663
24664                         generateBufferData(); // build geometry
24665
24666                         _this.setIndex(indices);
24667
24668                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
24669
24670                         _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
24671
24672                         _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
24673
24674
24675                         function generateBufferData() {
24676                                 for (var i = 0; i < tubularSegments; i++) {
24677                                         generateSegment(i);
24678                                 } // if the geometry is not closed, generate the last row of vertices and normals
24679                                 // at the regular position on the given path
24680                                 //
24681                                 // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
24682
24683
24684                                 generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
24685                                 // this makes it easy compute correct values for closed geometries
24686
24687                                 generateUVs(); // finally create faces
24688
24689                                 generateIndices();
24690                         }
24691
24692                         function generateSegment(i) {
24693                                 // we use getPointAt to sample evenly distributed points from the given path
24694                                 P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
24695
24696                                 var N = frames.normals[i];
24697                                 var B = frames.binormals[i]; // generate normals and vertices for the current segment
24698
24699                                 for (var j = 0; j <= radialSegments; j++) {
24700                                         var v = j / radialSegments * Math.PI * 2;
24701                                         var sin = Math.sin(v);
24702                                         var cos = -Math.cos(v); // normal
24703
24704                                         normal.x = cos * N.x + sin * B.x;
24705                                         normal.y = cos * N.y + sin * B.y;
24706                                         normal.z = cos * N.z + sin * B.z;
24707                                         normal.normalize();
24708                                         normals.push(normal.x, normal.y, normal.z); // vertex
24709
24710                                         vertex.x = P.x + radius * normal.x;
24711                                         vertex.y = P.y + radius * normal.y;
24712                                         vertex.z = P.z + radius * normal.z;
24713                                         vertices.push(vertex.x, vertex.y, vertex.z);
24714                                 }
24715                         }
24716
24717                         function generateIndices() {
24718                                 for (var j = 1; j <= tubularSegments; j++) {
24719                                         for (var i = 1; i <= radialSegments; i++) {
24720                                                 var a = (radialSegments + 1) * (j - 1) + (i - 1);
24721                                                 var b = (radialSegments + 1) * j + (i - 1);
24722                                                 var c = (radialSegments + 1) * j + i;
24723                                                 var d = (radialSegments + 1) * (j - 1) + i; // faces
24724
24725                                                 indices.push(a, b, d);
24726                                                 indices.push(b, c, d);
24727                                         }
24728                                 }
24729                         }
24730
24731                         function generateUVs() {
24732                                 for (var i = 0; i <= tubularSegments; i++) {
24733                                         for (var j = 0; j <= radialSegments; j++) {
24734                                                 uv.x = i / tubularSegments;
24735                                                 uv.y = j / radialSegments;
24736                                                 uvs.push(uv.x, uv.y);
24737                                         }
24738                                 }
24739                         }
24740
24741                         return _this;
24742                 }
24743
24744                 var _proto = TubeBufferGeometry.prototype;
24745
24746                 _proto.toJSON = function toJSON() {
24747                         var data = BufferGeometry.prototype.toJSON.call(this);
24748                         data.path = this.parameters.path.toJSON();
24749                         return data;
24750                 };
24751
24752                 return TubeBufferGeometry;
24753         }(BufferGeometry);
24754
24755         var TubeGeometry = /*#__PURE__*/function (_Geometry) {
24756                 _inheritsLoose(TubeGeometry, _Geometry);
24757
24758                 function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
24759                         var _this;
24760
24761                         _this = _Geometry.call(this) || this;
24762                         _this.type = 'TubeGeometry';
24763                         _this.parameters = {
24764                                 path: path,
24765                                 tubularSegments: tubularSegments,
24766                                 radius: radius,
24767                                 radialSegments: radialSegments,
24768                                 closed: closed
24769                         };
24770                         if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
24771                         var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
24772
24773                         _this.tangents = bufferGeometry.tangents;
24774                         _this.normals = bufferGeometry.normals;
24775                         _this.binormals = bufferGeometry.binormals; // create geometry
24776
24777                         _this.fromBufferGeometry(bufferGeometry);
24778
24779                         _this.mergeVertices();
24780
24781                         return _this;
24782                 }
24783
24784                 return TubeGeometry;
24785         }(Geometry);
24786
24787         var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
24788                 _inheritsLoose(WireframeGeometry, _BufferGeometry);
24789
24790                 function WireframeGeometry(geometry) {
24791                         var _this;
24792
24793                         _this = _BufferGeometry.call(this) || this;
24794                         _this.type = 'WireframeGeometry'; // buffer
24795
24796                         var vertices = []; // helper variables
24797
24798                         var edge = [0, 0],
24799                                         edges = {};
24800                         var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
24801
24802                         if (geometry && geometry.isGeometry) {
24803                                 // create a data structure that contains all edges without duplicates
24804                                 var faces = geometry.faces;
24805
24806                                 for (var i = 0, l = faces.length; i < l; i++) {
24807                                         var face = faces[i];
24808
24809                                         for (var j = 0; j < 3; j++) {
24810                                                 var edge1 = face[keys[j]];
24811                                                 var edge2 = face[keys[(j + 1) % 3]];
24812                                                 edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
24813
24814                                                 edge[1] = Math.max(edge1, edge2);
24815                                                 var key = edge[0] + ',' + edge[1];
24816
24817                                                 if (edges[key] === undefined) {
24818                                                         edges[key] = {
24819                                                                 index1: edge[0],
24820                                                                 index2: edge[1]
24821                                                         };
24822                                                 }
24823                                         }
24824                                 } // generate vertices
24825
24826
24827                                 for (var _key in edges) {
24828                                         var e = edges[_key];
24829                                         var vertex = geometry.vertices[e.index1];
24830                                         vertices.push(vertex.x, vertex.y, vertex.z);
24831                                         vertex = geometry.vertices[e.index2];
24832                                         vertices.push(vertex.x, vertex.y, vertex.z);
24833                                 }
24834                         } else if (geometry && geometry.isBufferGeometry) {
24835                                 var _vertex = new Vector3();
24836
24837                                 if (geometry.index !== null) {
24838                                         // indexed BufferGeometry
24839                                         var position = geometry.attributes.position;
24840                                         var indices = geometry.index;
24841                                         var groups = geometry.groups;
24842
24843                                         if (groups.length === 0) {
24844                                                 groups = [{
24845                                                         start: 0,
24846                                                         count: indices.count,
24847                                                         materialIndex: 0
24848                                                 }];
24849                                         } // create a data structure that contains all eges without duplicates
24850
24851
24852                                         for (var o = 0, ol = groups.length; o < ol; ++o) {
24853                                                 var group = groups[o];
24854                                                 var start = group.start;
24855                                                 var count = group.count;
24856
24857                                                 for (var _i = start, _l = start + count; _i < _l; _i += 3) {
24858                                                         for (var _j = 0; _j < 3; _j++) {
24859                                                                 var _edge = indices.getX(_i + _j);
24860
24861                                                                 var _edge2 = indices.getX(_i + (_j + 1) % 3);
24862
24863                                                                 edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
24864
24865                                                                 edge[1] = Math.max(_edge, _edge2);
24866
24867                                                                 var _key2 = edge[0] + ',' + edge[1];
24868
24869                                                                 if (edges[_key2] === undefined) {
24870                                                                         edges[_key2] = {
24871                                                                                 index1: edge[0],
24872                                                                                 index2: edge[1]
24873                                                                         };
24874                                                                 }
24875                                                         }
24876                                                 }
24877                                         } // generate vertices
24878
24879
24880                                         for (var _key3 in edges) {
24881                                                 var _e = edges[_key3];
24882
24883                                                 _vertex.fromBufferAttribute(position, _e.index1);
24884
24885                                                 vertices.push(_vertex.x, _vertex.y, _vertex.z);
24886
24887                                                 _vertex.fromBufferAttribute(position, _e.index2);
24888
24889                                                 vertices.push(_vertex.x, _vertex.y, _vertex.z);
24890                                         }
24891                                 } else {
24892                                         // non-indexed BufferGeometry
24893                                         var _position = geometry.attributes.position;
24894
24895                                         for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
24896                                                 for (var _j2 = 0; _j2 < 3; _j2++) {
24897                                                         // three edges per triangle, an edge is represented as (index1, index2)
24898                                                         // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
24899                                                         var index1 = 3 * _i2 + _j2;
24900
24901                                                         _vertex.fromBufferAttribute(_position, index1);
24902
24903                                                         vertices.push(_vertex.x, _vertex.y, _vertex.z);
24904                                                         var index2 = 3 * _i2 + (_j2 + 1) % 3;
24905
24906                                                         _vertex.fromBufferAttribute(_position, index2);
24907
24908                                                         vertices.push(_vertex.x, _vertex.y, _vertex.z);
24909                                                 }
24910                                         }
24911                                 }
24912                         } // build geometry
24913
24914
24915                         _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
24916
24917                         return _this;
24918                 }
24919
24920                 return WireframeGeometry;
24921         }(BufferGeometry);
24922
24923         var Geometries = /*#__PURE__*/Object.freeze({
24924                 __proto__: null,
24925                 BoxGeometry: BoxGeometry,
24926                 BoxBufferGeometry: BoxBufferGeometry,
24927                 CircleGeometry: CircleGeometry,
24928                 CircleBufferGeometry: CircleBufferGeometry,
24929                 ConeGeometry: ConeGeometry,
24930                 ConeBufferGeometry: ConeBufferGeometry,
24931                 CylinderGeometry: CylinderGeometry,
24932                 CylinderBufferGeometry: CylinderBufferGeometry,
24933                 DodecahedronGeometry: DodecahedronGeometry,
24934                 DodecahedronBufferGeometry: DodecahedronBufferGeometry,
24935                 EdgesGeometry: EdgesGeometry,
24936                 ExtrudeGeometry: ExtrudeGeometry,
24937                 ExtrudeBufferGeometry: ExtrudeBufferGeometry,
24938                 IcosahedronGeometry: IcosahedronGeometry,
24939                 IcosahedronBufferGeometry: IcosahedronBufferGeometry,
24940                 LatheGeometry: LatheGeometry,
24941                 LatheBufferGeometry: LatheBufferGeometry,
24942                 OctahedronGeometry: OctahedronGeometry,
24943                 OctahedronBufferGeometry: OctahedronBufferGeometry,
24944                 ParametricGeometry: ParametricGeometry,
24945                 ParametricBufferGeometry: ParametricBufferGeometry,
24946                 PlaneGeometry: PlaneGeometry,
24947                 PlaneBufferGeometry: PlaneBufferGeometry,
24948                 PolyhedronGeometry: PolyhedronGeometry,
24949                 PolyhedronBufferGeometry: PolyhedronBufferGeometry,
24950                 RingGeometry: RingGeometry,
24951                 RingBufferGeometry: RingBufferGeometry,
24952                 ShapeGeometry: ShapeGeometry,
24953                 ShapeBufferGeometry: ShapeBufferGeometry,
24954                 SphereGeometry: SphereGeometry,
24955                 SphereBufferGeometry: SphereBufferGeometry,
24956                 TetrahedronGeometry: TetrahedronGeometry,
24957                 TetrahedronBufferGeometry: TetrahedronBufferGeometry,
24958                 TextGeometry: TextGeometry,
24959                 TextBufferGeometry: TextBufferGeometry,
24960                 TorusGeometry: TorusGeometry,
24961                 TorusBufferGeometry: TorusBufferGeometry,
24962                 TorusKnotGeometry: TorusKnotGeometry,
24963                 TorusKnotBufferGeometry: TorusKnotBufferGeometry,
24964                 TubeGeometry: TubeGeometry,
24965                 TubeBufferGeometry: TubeBufferGeometry,
24966                 WireframeGeometry: WireframeGeometry
24967         });
24968
24969         /**
24970          * parameters = {
24971          *      color: <THREE.Color>
24972          * }
24973          */
24974
24975         function ShadowMaterial(parameters) {
24976                 Material.call(this);
24977                 this.type = 'ShadowMaterial';
24978                 this.color = new Color(0x000000);
24979                 this.transparent = true;
24980                 this.setValues(parameters);
24981         }
24982
24983         ShadowMaterial.prototype = Object.create(Material.prototype);
24984         ShadowMaterial.prototype.constructor = ShadowMaterial;
24985         ShadowMaterial.prototype.isShadowMaterial = true;
24986
24987         ShadowMaterial.prototype.copy = function (source) {
24988                 Material.prototype.copy.call(this, source);
24989                 this.color.copy(source.color);
24990                 return this;
24991         };
24992
24993         function RawShaderMaterial(parameters) {
24994                 ShaderMaterial.call(this, parameters);
24995                 this.type = 'RawShaderMaterial';
24996         }
24997
24998         RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
24999         RawShaderMaterial.prototype.constructor = RawShaderMaterial;
25000         RawShaderMaterial.prototype.isRawShaderMaterial = true;
25001
25002         /**
25003          * parameters = {
25004          *      color: <hex>,
25005          *      roughness: <float>,
25006          *      metalness: <float>,
25007          *      opacity: <float>,
25008          *
25009          *      map: new THREE.Texture( <Image> ),
25010          *
25011          *      lightMap: new THREE.Texture( <Image> ),
25012          *      lightMapIntensity: <float>
25013          *
25014          *      aoMap: new THREE.Texture( <Image> ),
25015          *      aoMapIntensity: <float>
25016          *
25017          *      emissive: <hex>,
25018          *      emissiveIntensity: <float>
25019          *      emissiveMap: new THREE.Texture( <Image> ),
25020          *
25021          *      bumpMap: new THREE.Texture( <Image> ),
25022          *      bumpScale: <float>,
25023          *
25024          *      normalMap: new THREE.Texture( <Image> ),
25025          *      normalMapType: THREE.TangentSpaceNormalMap,
25026          *      normalScale: <Vector2>,
25027          *
25028          *      displacementMap: new THREE.Texture( <Image> ),
25029          *      displacementScale: <float>,
25030          *      displacementBias: <float>,
25031          *
25032          *      roughnessMap: new THREE.Texture( <Image> ),
25033          *
25034          *      metalnessMap: new THREE.Texture( <Image> ),
25035          *
25036          *      alphaMap: new THREE.Texture( <Image> ),
25037          *
25038          *      envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
25039          *      envMapIntensity: <float>
25040          *
25041          *      refractionRatio: <float>,
25042          *
25043          *      wireframe: <boolean>,
25044          *      wireframeLinewidth: <float>,
25045          *
25046          *      skinning: <bool>,
25047          *      morphTargets: <bool>,
25048          *      morphNormals: <bool>
25049          * }
25050          */
25051
25052         function MeshStandardMaterial(parameters) {
25053                 Material.call(this);
25054                 this.defines = {
25055                         'STANDARD': ''
25056                 };
25057                 this.type = 'MeshStandardMaterial';
25058                 this.color = new Color(0xffffff); // diffuse
25059
25060                 this.roughness = 1.0;
25061                 this.metalness = 0.0;
25062                 this.map = null;
25063                 this.lightMap = null;
25064                 this.lightMapIntensity = 1.0;
25065                 this.aoMap = null;
25066                 this.aoMapIntensity = 1.0;
25067                 this.emissive = new Color(0x000000);
25068                 this.emissiveIntensity = 1.0;
25069                 this.emissiveMap = null;
25070                 this.bumpMap = null;
25071                 this.bumpScale = 1;
25072                 this.normalMap = null;
25073                 this.normalMapType = TangentSpaceNormalMap;
25074                 this.normalScale = new Vector2(1, 1);
25075                 this.displacementMap = null;
25076                 this.displacementScale = 1;
25077                 this.displacementBias = 0;
25078                 this.roughnessMap = null;
25079                 this.metalnessMap = null;
25080                 this.alphaMap = null;
25081                 this.envMap = null;
25082                 this.envMapIntensity = 1.0;
25083                 this.refractionRatio = 0.98;
25084                 this.wireframe = false;
25085                 this.wireframeLinewidth = 1;
25086                 this.wireframeLinecap = 'round';
25087                 this.wireframeLinejoin = 'round';
25088                 this.skinning = false;
25089                 this.morphTargets = false;
25090                 this.morphNormals = false;
25091                 this.vertexTangents = false;
25092                 this.setValues(parameters);
25093         }
25094
25095         MeshStandardMaterial.prototype = Object.create(Material.prototype);
25096         MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
25097         MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
25098
25099         MeshStandardMaterial.prototype.copy = function (source) {
25100                 Material.prototype.copy.call(this, source);
25101                 this.defines = {
25102                         'STANDARD': ''
25103                 };
25104                 this.color.copy(source.color);
25105                 this.roughness = source.roughness;
25106                 this.metalness = source.metalness;
25107                 this.map = source.map;
25108                 this.lightMap = source.lightMap;
25109                 this.lightMapIntensity = source.lightMapIntensity;
25110                 this.aoMap = source.aoMap;
25111                 this.aoMapIntensity = source.aoMapIntensity;
25112                 this.emissive.copy(source.emissive);
25113                 this.emissiveMap = source.emissiveMap;
25114                 this.emissiveIntensity = source.emissiveIntensity;
25115                 this.bumpMap = source.bumpMap;
25116                 this.bumpScale = source.bumpScale;
25117                 this.normalMap = source.normalMap;
25118                 this.normalMapType = source.normalMapType;
25119                 this.normalScale.copy(source.normalScale);
25120                 this.displacementMap = source.displacementMap;
25121                 this.displacementScale = source.displacementScale;
25122                 this.displacementBias = source.displacementBias;
25123                 this.roughnessMap = source.roughnessMap;
25124                 this.metalnessMap = source.metalnessMap;
25125                 this.alphaMap = source.alphaMap;
25126                 this.envMap = source.envMap;
25127                 this.envMapIntensity = source.envMapIntensity;
25128                 this.refractionRatio = source.refractionRatio;
25129                 this.wireframe = source.wireframe;
25130                 this.wireframeLinewidth = source.wireframeLinewidth;
25131                 this.wireframeLinecap = source.wireframeLinecap;
25132                 this.wireframeLinejoin = source.wireframeLinejoin;
25133                 this.skinning = source.skinning;
25134                 this.morphTargets = source.morphTargets;
25135                 this.morphNormals = source.morphNormals;
25136                 this.vertexTangents = source.vertexTangents;
25137                 return this;
25138         };
25139
25140         /**
25141          * parameters = {
25142          *      clearcoat: <float>,
25143          *      clearcoatMap: new THREE.Texture( <Image> ),
25144          *      clearcoatRoughness: <float>,
25145          *      clearcoatRoughnessMap: new THREE.Texture( <Image> ),
25146          *      clearcoatNormalScale: <Vector2>,
25147          *      clearcoatNormalMap: new THREE.Texture( <Image> ),
25148          *
25149          *      reflectivity: <float>,
25150          *      ior: <float>,
25151          *
25152          *      sheen: <Color>,
25153          *
25154          *      transmission: <float>,
25155          *      transmissionMap: new THREE.Texture( <Image> )
25156          * }
25157          */
25158
25159         function MeshPhysicalMaterial(parameters) {
25160                 MeshStandardMaterial.call(this);
25161                 this.defines = {
25162                         'STANDARD': '',
25163                         'PHYSICAL': ''
25164                 };
25165                 this.type = 'MeshPhysicalMaterial';
25166                 this.clearcoat = 0.0;
25167                 this.clearcoatMap = null;
25168                 this.clearcoatRoughness = 0.0;
25169                 this.clearcoatRoughnessMap = null;
25170                 this.clearcoatNormalScale = new Vector2(1, 1);
25171                 this.clearcoatNormalMap = null;
25172                 this.reflectivity = 0.5; // maps to F0 = 0.04
25173
25174                 Object.defineProperty(this, 'ior', {
25175                         get: function get() {
25176                                 return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
25177                         },
25178                         set: function set(ior) {
25179                                 this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
25180                         }
25181                 });
25182                 this.sheen = null; // null will disable sheen bsdf
25183
25184                 this.transmission = 0.0;
25185                 this.transmissionMap = null;
25186                 this.setValues(parameters);
25187         }
25188
25189         MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
25190         MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
25191         MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
25192
25193         MeshPhysicalMaterial.prototype.copy = function (source) {
25194                 MeshStandardMaterial.prototype.copy.call(this, source);
25195                 this.defines = {
25196                         'STANDARD': '',
25197                         'PHYSICAL': ''
25198                 };
25199                 this.clearcoat = source.clearcoat;
25200                 this.clearcoatMap = source.clearcoatMap;
25201                 this.clearcoatRoughness = source.clearcoatRoughness;
25202                 this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
25203                 this.clearcoatNormalMap = source.clearcoatNormalMap;
25204                 this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
25205                 this.reflectivity = source.reflectivity;
25206
25207                 if (source.sheen) {
25208                         this.sheen = (this.sheen || new Color()).copy(source.sheen);
25209                 } else {
25210                         this.sheen = null;
25211                 }
25212
25213                 this.transmission = source.transmission;
25214                 this.transmissionMap = source.transmissionMap;
25215                 return this;
25216         };
25217
25218         /**
25219          * parameters = {
25220          *      color: <hex>,
25221          *      specular: <hex>,
25222          *      shininess: <float>,
25223          *      opacity: <float>,
25224          *
25225          *      map: new THREE.Texture( <Image> ),
25226          *
25227          *      lightMap: new THREE.Texture( <Image> ),
25228          *      lightMapIntensity: <float>
25229          *
25230          *      aoMap: new THREE.Texture( <Image> ),
25231          *      aoMapIntensity: <float>
25232          *
25233          *      emissive: <hex>,
25234          *      emissiveIntensity: <float>
25235          *      emissiveMap: new THREE.Texture( <Image> ),
25236          *
25237          *      bumpMap: new THREE.Texture( <Image> ),
25238          *      bumpScale: <float>,
25239          *
25240          *      normalMap: new THREE.Texture( <Image> ),
25241          *      normalMapType: THREE.TangentSpaceNormalMap,
25242          *      normalScale: <Vector2>,
25243          *
25244          *      displacementMap: new THREE.Texture( <Image> ),
25245          *      displacementScale: <float>,
25246          *      displacementBias: <float>,
25247          *
25248          *      specularMap: new THREE.Texture( <Image> ),
25249          *
25250          *      alphaMap: new THREE.Texture( <Image> ),
25251          *
25252          *      envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
25253          *      combine: THREE.MultiplyOperation,
25254          *      reflectivity: <float>,
25255          *      refractionRatio: <float>,
25256          *
25257          *      wireframe: <boolean>,
25258          *      wireframeLinewidth: <float>,
25259          *
25260          *      skinning: <bool>,
25261          *      morphTargets: <bool>,
25262          *      morphNormals: <bool>
25263          * }
25264          */
25265
25266         function MeshPhongMaterial(parameters) {
25267                 Material.call(this);
25268                 this.type = 'MeshPhongMaterial';
25269                 this.color = new Color(0xffffff); // diffuse
25270
25271                 this.specular = new Color(0x111111);
25272                 this.shininess = 30;
25273                 this.map = null;
25274                 this.lightMap = null;
25275                 this.lightMapIntensity = 1.0;
25276                 this.aoMap = null;
25277                 this.aoMapIntensity = 1.0;
25278                 this.emissive = new Color(0x000000);
25279                 this.emissiveIntensity = 1.0;
25280                 this.emissiveMap = null;
25281                 this.bumpMap = null;
25282                 this.bumpScale = 1;
25283                 this.normalMap = null;
25284                 this.normalMapType = TangentSpaceNormalMap;
25285                 this.normalScale = new Vector2(1, 1);
25286                 this.displacementMap = null;
25287                 this.displacementScale = 1;
25288                 this.displacementBias = 0;
25289                 this.specularMap = null;
25290                 this.alphaMap = null;
25291                 this.envMap = null;
25292                 this.combine = MultiplyOperation;
25293                 this.reflectivity = 1;
25294                 this.refractionRatio = 0.98;
25295                 this.wireframe = false;
25296                 this.wireframeLinewidth = 1;
25297                 this.wireframeLinecap = 'round';
25298                 this.wireframeLinejoin = 'round';
25299                 this.skinning = false;
25300                 this.morphTargets = false;
25301                 this.morphNormals = false;
25302                 this.setValues(parameters);
25303         }
25304
25305         MeshPhongMaterial.prototype = Object.create(Material.prototype);
25306         MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
25307         MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
25308
25309         MeshPhongMaterial.prototype.copy = function (source) {
25310                 Material.prototype.copy.call(this, source);
25311                 this.color.copy(source.color);
25312                 this.specular.copy(source.specular);
25313                 this.shininess = source.shininess;
25314                 this.map = source.map;
25315                 this.lightMap = source.lightMap;
25316                 this.lightMapIntensity = source.lightMapIntensity;
25317                 this.aoMap = source.aoMap;
25318                 this.aoMapIntensity = source.aoMapIntensity;
25319                 this.emissive.copy(source.emissive);
25320                 this.emissiveMap = source.emissiveMap;
25321                 this.emissiveIntensity = source.emissiveIntensity;
25322                 this.bumpMap = source.bumpMap;
25323                 this.bumpScale = source.bumpScale;
25324                 this.normalMap = source.normalMap;
25325                 this.normalMapType = source.normalMapType;
25326                 this.normalScale.copy(source.normalScale);
25327                 this.displacementMap = source.displacementMap;
25328                 this.displacementScale = source.displacementScale;
25329                 this.displacementBias = source.displacementBias;
25330                 this.specularMap = source.specularMap;
25331                 this.alphaMap = source.alphaMap;
25332                 this.envMap = source.envMap;
25333                 this.combine = source.combine;
25334                 this.reflectivity = source.reflectivity;
25335                 this.refractionRatio = source.refractionRatio;
25336                 this.wireframe = source.wireframe;
25337                 this.wireframeLinewidth = source.wireframeLinewidth;
25338                 this.wireframeLinecap = source.wireframeLinecap;
25339                 this.wireframeLinejoin = source.wireframeLinejoin;
25340                 this.skinning = source.skinning;
25341                 this.morphTargets = source.morphTargets;
25342                 this.morphNormals = source.morphNormals;
25343                 return this;
25344         };
25345
25346         /**
25347          * parameters = {
25348          *      color: <hex>,
25349          *
25350          *      map: new THREE.Texture( <Image> ),
25351          *      gradientMap: new THREE.Texture( <Image> ),
25352          *
25353          *      lightMap: new THREE.Texture( <Image> ),
25354          *      lightMapIntensity: <float>
25355          *
25356          *      aoMap: new THREE.Texture( <Image> ),
25357          *      aoMapIntensity: <float>
25358          *
25359          *      emissive: <hex>,
25360          *      emissiveIntensity: <float>
25361          *      emissiveMap: new THREE.Texture( <Image> ),
25362          *
25363          *      bumpMap: new THREE.Texture( <Image> ),
25364          *      bumpScale: <float>,
25365          *
25366          *      normalMap: new THREE.Texture( <Image> ),
25367          *      normalMapType: THREE.TangentSpaceNormalMap,
25368          *      normalScale: <Vector2>,
25369          *
25370          *      displacementMap: new THREE.Texture( <Image> ),
25371          *      displacementScale: <float>,
25372          *      displacementBias: <float>,
25373          *
25374          *      alphaMap: new THREE.Texture( <Image> ),
25375          *
25376          *      wireframe: <boolean>,
25377          *      wireframeLinewidth: <float>,
25378          *
25379          *      skinning: <bool>,
25380          *      morphTargets: <bool>,
25381          *      morphNormals: <bool>
25382          * }
25383          */
25384
25385         function MeshToonMaterial(parameters) {
25386                 Material.call(this);
25387                 this.defines = {
25388                         'TOON': ''
25389                 };
25390                 this.type = 'MeshToonMaterial';
25391                 this.color = new Color(0xffffff);
25392                 this.map = null;
25393                 this.gradientMap = null;
25394                 this.lightMap = null;
25395                 this.lightMapIntensity = 1.0;
25396                 this.aoMap = null;
25397                 this.aoMapIntensity = 1.0;
25398                 this.emissive = new Color(0x000000);
25399                 this.emissiveIntensity = 1.0;
25400                 this.emissiveMap = null;
25401                 this.bumpMap = null;
25402                 this.bumpScale = 1;
25403                 this.normalMap = null;
25404                 this.normalMapType = TangentSpaceNormalMap;
25405                 this.normalScale = new Vector2(1, 1);
25406                 this.displacementMap = null;
25407                 this.displacementScale = 1;
25408                 this.displacementBias = 0;
25409                 this.alphaMap = null;
25410                 this.wireframe = false;
25411                 this.wireframeLinewidth = 1;
25412                 this.wireframeLinecap = 'round';
25413                 this.wireframeLinejoin = 'round';
25414                 this.skinning = false;
25415                 this.morphTargets = false;
25416                 this.morphNormals = false;
25417                 this.setValues(parameters);
25418         }
25419
25420         MeshToonMaterial.prototype = Object.create(Material.prototype);
25421         MeshToonMaterial.prototype.constructor = MeshToonMaterial;
25422         MeshToonMaterial.prototype.isMeshToonMaterial = true;
25423
25424         MeshToonMaterial.prototype.copy = function (source) {
25425                 Material.prototype.copy.call(this, source);
25426                 this.color.copy(source.color);
25427                 this.map = source.map;
25428                 this.gradientMap = source.gradientMap;
25429                 this.lightMap = source.lightMap;
25430                 this.lightMapIntensity = source.lightMapIntensity;
25431                 this.aoMap = source.aoMap;
25432                 this.aoMapIntensity = source.aoMapIntensity;
25433                 this.emissive.copy(source.emissive);
25434                 this.emissiveMap = source.emissiveMap;
25435                 this.emissiveIntensity = source.emissiveIntensity;
25436                 this.bumpMap = source.bumpMap;
25437                 this.bumpScale = source.bumpScale;
25438                 this.normalMap = source.normalMap;
25439                 this.normalMapType = source.normalMapType;
25440                 this.normalScale.copy(source.normalScale);
25441                 this.displacementMap = source.displacementMap;
25442                 this.displacementScale = source.displacementScale;
25443                 this.displacementBias = source.displacementBias;
25444                 this.alphaMap = source.alphaMap;
25445                 this.wireframe = source.wireframe;
25446                 this.wireframeLinewidth = source.wireframeLinewidth;
25447                 this.wireframeLinecap = source.wireframeLinecap;
25448                 this.wireframeLinejoin = source.wireframeLinejoin;
25449                 this.skinning = source.skinning;
25450                 this.morphTargets = source.morphTargets;
25451                 this.morphNormals = source.morphNormals;
25452                 return this;
25453         };
25454
25455         /**
25456          * parameters = {
25457          *      opacity: <float>,
25458          *
25459          *      bumpMap: new THREE.Texture( <Image> ),
25460          *      bumpScale: <float>,
25461          *
25462          *      normalMap: new THREE.Texture( <Image> ),
25463          *      normalMapType: THREE.TangentSpaceNormalMap,
25464          *      normalScale: <Vector2>,
25465          *
25466          *      displacementMap: new THREE.Texture( <Image> ),
25467          *      displacementScale: <float>,
25468          *      displacementBias: <float>,
25469          *
25470          *      wireframe: <boolean>,
25471          *      wireframeLinewidth: <float>
25472          *
25473          *      skinning: <bool>,
25474          *      morphTargets: <bool>,
25475          *      morphNormals: <bool>
25476          * }
25477          */
25478
25479         function MeshNormalMaterial(parameters) {
25480                 Material.call(this);
25481                 this.type = 'MeshNormalMaterial';
25482                 this.bumpMap = null;
25483                 this.bumpScale = 1;
25484                 this.normalMap = null;
25485                 this.normalMapType = TangentSpaceNormalMap;
25486                 this.normalScale = new Vector2(1, 1);
25487                 this.displacementMap = null;
25488                 this.displacementScale = 1;
25489                 this.displacementBias = 0;
25490                 this.wireframe = false;
25491                 this.wireframeLinewidth = 1;
25492                 this.fog = false;
25493                 this.skinning = false;
25494                 this.morphTargets = false;
25495                 this.morphNormals = false;
25496                 this.setValues(parameters);
25497         }
25498
25499         MeshNormalMaterial.prototype = Object.create(Material.prototype);
25500         MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
25501         MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
25502
25503         MeshNormalMaterial.prototype.copy = function (source) {
25504                 Material.prototype.copy.call(this, source);
25505                 this.bumpMap = source.bumpMap;
25506                 this.bumpScale = source.bumpScale;
25507                 this.normalMap = source.normalMap;
25508                 this.normalMapType = source.normalMapType;
25509                 this.normalScale.copy(source.normalScale);
25510                 this.displacementMap = source.displacementMap;
25511                 this.displacementScale = source.displacementScale;
25512                 this.displacementBias = source.displacementBias;
25513                 this.wireframe = source.wireframe;
25514                 this.wireframeLinewidth = source.wireframeLinewidth;
25515                 this.skinning = source.skinning;
25516                 this.morphTargets = source.morphTargets;
25517                 this.morphNormals = source.morphNormals;
25518                 return this;
25519         };
25520
25521         /**
25522          * parameters = {
25523          *      color: <hex>,
25524          *      opacity: <float>,
25525          *
25526          *      map: new THREE.Texture( <Image> ),
25527          *
25528          *      lightMap: new THREE.Texture( <Image> ),
25529          *      lightMapIntensity: <float>
25530          *
25531          *      aoMap: new THREE.Texture( <Image> ),
25532          *      aoMapIntensity: <float>
25533          *
25534          *      emissive: <hex>,
25535          *      emissiveIntensity: <float>
25536          *      emissiveMap: new THREE.Texture( <Image> ),
25537          *
25538          *      specularMap: new THREE.Texture( <Image> ),
25539          *
25540          *      alphaMap: new THREE.Texture( <Image> ),
25541          *
25542          *      envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
25543          *      combine: THREE.Multiply,
25544          *      reflectivity: <float>,
25545          *      refractionRatio: <float>,
25546          *
25547          *      wireframe: <boolean>,
25548          *      wireframeLinewidth: <float>,
25549          *
25550          *      skinning: <bool>,
25551          *      morphTargets: <bool>,
25552          *      morphNormals: <bool>
25553          * }
25554          */
25555
25556         function MeshLambertMaterial(parameters) {
25557                 Material.call(this);
25558                 this.type = 'MeshLambertMaterial';
25559                 this.color = new Color(0xffffff); // diffuse
25560
25561                 this.map = null;
25562                 this.lightMap = null;
25563                 this.lightMapIntensity = 1.0;
25564                 this.aoMap = null;
25565                 this.aoMapIntensity = 1.0;
25566                 this.emissive = new Color(0x000000);
25567                 this.emissiveIntensity = 1.0;
25568                 this.emissiveMap = null;
25569                 this.specularMap = null;
25570                 this.alphaMap = null;
25571                 this.envMap = null;
25572                 this.combine = MultiplyOperation;
25573                 this.reflectivity = 1;
25574                 this.refractionRatio = 0.98;
25575                 this.wireframe = false;
25576                 this.wireframeLinewidth = 1;
25577                 this.wireframeLinecap = 'round';
25578                 this.wireframeLinejoin = 'round';
25579                 this.skinning = false;
25580                 this.morphTargets = false;
25581                 this.morphNormals = false;
25582                 this.setValues(parameters);
25583         }
25584
25585         MeshLambertMaterial.prototype = Object.create(Material.prototype);
25586         MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
25587         MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
25588
25589         MeshLambertMaterial.prototype.copy = function (source) {
25590                 Material.prototype.copy.call(this, source);
25591                 this.color.copy(source.color);
25592                 this.map = source.map;
25593                 this.lightMap = source.lightMap;
25594                 this.lightMapIntensity = source.lightMapIntensity;
25595                 this.aoMap = source.aoMap;
25596                 this.aoMapIntensity = source.aoMapIntensity;
25597                 this.emissive.copy(source.emissive);
25598                 this.emissiveMap = source.emissiveMap;
25599                 this.emissiveIntensity = source.emissiveIntensity;
25600                 this.specularMap = source.specularMap;
25601                 this.alphaMap = source.alphaMap;
25602                 this.envMap = source.envMap;
25603                 this.combine = source.combine;
25604                 this.reflectivity = source.reflectivity;
25605                 this.refractionRatio = source.refractionRatio;
25606                 this.wireframe = source.wireframe;
25607                 this.wireframeLinewidth = source.wireframeLinewidth;
25608                 this.wireframeLinecap = source.wireframeLinecap;
25609                 this.wireframeLinejoin = source.wireframeLinejoin;
25610                 this.skinning = source.skinning;
25611                 this.morphTargets = source.morphTargets;
25612                 this.morphNormals = source.morphNormals;
25613                 return this;
25614         };
25615
25616         /**
25617          * parameters = {
25618          *      color: <hex>,
25619          *      opacity: <float>,
25620          *
25621          *      matcap: new THREE.Texture( <Image> ),
25622          *
25623          *      map: new THREE.Texture( <Image> ),
25624          *
25625          *      bumpMap: new THREE.Texture( <Image> ),
25626          *      bumpScale: <float>,
25627          *
25628          *      normalMap: new THREE.Texture( <Image> ),
25629          *      normalMapType: THREE.TangentSpaceNormalMap,
25630          *      normalScale: <Vector2>,
25631          *
25632          *      displacementMap: new THREE.Texture( <Image> ),
25633          *      displacementScale: <float>,
25634          *      displacementBias: <float>,
25635          *
25636          *      alphaMap: new THREE.Texture( <Image> ),
25637          *
25638          *      skinning: <bool>,
25639          *      morphTargets: <bool>,
25640          *      morphNormals: <bool>
25641          * }
25642          */
25643
25644         function MeshMatcapMaterial(parameters) {
25645                 Material.call(this);
25646                 this.defines = {
25647                         'MATCAP': ''
25648                 };
25649                 this.type = 'MeshMatcapMaterial';
25650                 this.color = new Color(0xffffff); // diffuse
25651
25652                 this.matcap = null;
25653                 this.map = null;
25654                 this.bumpMap = null;
25655                 this.bumpScale = 1;
25656                 this.normalMap = null;
25657                 this.normalMapType = TangentSpaceNormalMap;
25658                 this.normalScale = new Vector2(1, 1);
25659                 this.displacementMap = null;
25660                 this.displacementScale = 1;
25661                 this.displacementBias = 0;
25662                 this.alphaMap = null;
25663                 this.skinning = false;
25664                 this.morphTargets = false;
25665                 this.morphNormals = false;
25666                 this.setValues(parameters);
25667         }
25668
25669         MeshMatcapMaterial.prototype = Object.create(Material.prototype);
25670         MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
25671         MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
25672
25673         MeshMatcapMaterial.prototype.copy = function (source) {
25674                 Material.prototype.copy.call(this, source);
25675                 this.defines = {
25676                         'MATCAP': ''
25677                 };
25678                 this.color.copy(source.color);
25679                 this.matcap = source.matcap;
25680                 this.map = source.map;
25681                 this.bumpMap = source.bumpMap;
25682                 this.bumpScale = source.bumpScale;
25683                 this.normalMap = source.normalMap;
25684                 this.normalMapType = source.normalMapType;
25685                 this.normalScale.copy(source.normalScale);
25686                 this.displacementMap = source.displacementMap;
25687                 this.displacementScale = source.displacementScale;
25688                 this.displacementBias = source.displacementBias;
25689                 this.alphaMap = source.alphaMap;
25690                 this.skinning = source.skinning;
25691                 this.morphTargets = source.morphTargets;
25692                 this.morphNormals = source.morphNormals;
25693                 return this;
25694         };
25695
25696         /**
25697          * parameters = {
25698          *      color: <hex>,
25699          *      opacity: <float>,
25700          *
25701          *      linewidth: <float>,
25702          *
25703          *      scale: <float>,
25704          *      dashSize: <float>,
25705          *      gapSize: <float>
25706          * }
25707          */
25708
25709         function LineDashedMaterial(parameters) {
25710                 LineBasicMaterial.call(this);
25711                 this.type = 'LineDashedMaterial';
25712                 this.scale = 1;
25713                 this.dashSize = 3;
25714                 this.gapSize = 1;
25715                 this.setValues(parameters);
25716         }
25717
25718         LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
25719         LineDashedMaterial.prototype.constructor = LineDashedMaterial;
25720         LineDashedMaterial.prototype.isLineDashedMaterial = true;
25721
25722         LineDashedMaterial.prototype.copy = function (source) {
25723                 LineBasicMaterial.prototype.copy.call(this, source);
25724                 this.scale = source.scale;
25725                 this.dashSize = source.dashSize;
25726                 this.gapSize = source.gapSize;
25727                 return this;
25728         };
25729
25730         var Materials = /*#__PURE__*/Object.freeze({
25731                 __proto__: null,
25732                 ShadowMaterial: ShadowMaterial,
25733                 SpriteMaterial: SpriteMaterial,
25734                 RawShaderMaterial: RawShaderMaterial,
25735                 ShaderMaterial: ShaderMaterial,
25736                 PointsMaterial: PointsMaterial,
25737                 MeshPhysicalMaterial: MeshPhysicalMaterial,
25738                 MeshStandardMaterial: MeshStandardMaterial,
25739                 MeshPhongMaterial: MeshPhongMaterial,
25740                 MeshToonMaterial: MeshToonMaterial,
25741                 MeshNormalMaterial: MeshNormalMaterial,
25742                 MeshLambertMaterial: MeshLambertMaterial,
25743                 MeshDepthMaterial: MeshDepthMaterial,
25744                 MeshDistanceMaterial: MeshDistanceMaterial,
25745                 MeshBasicMaterial: MeshBasicMaterial,
25746                 MeshMatcapMaterial: MeshMatcapMaterial,
25747                 LineDashedMaterial: LineDashedMaterial,
25748                 LineBasicMaterial: LineBasicMaterial,
25749                 Material: Material
25750         });
25751
25752         var AnimationUtils = {
25753                 // same as Array.prototype.slice, but also works on typed arrays
25754                 arraySlice: function arraySlice(array, from, to) {
25755                         if (AnimationUtils.isTypedArray(array)) {
25756                                 // in ios9 array.subarray(from, undefined) will return empty array
25757                                 // but array.subarray(from) or array.subarray(from, len) is correct
25758                                 return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
25759                         }
25760
25761                         return array.slice(from, to);
25762                 },
25763                 // converts an array to a specific type
25764                 convertArray: function convertArray(array, type, forceClone) {
25765                         if (!array || // let 'undefined' and 'null' pass
25766                         !forceClone && array.constructor === type) return array;
25767
25768                         if (typeof type.BYTES_PER_ELEMENT === 'number') {
25769                                 return new type(array); // create typed array
25770                         }
25771
25772                         return Array.prototype.slice.call(array); // create Array
25773                 },
25774                 isTypedArray: function isTypedArray(object) {
25775                         return ArrayBuffer.isView(object) && !(object instanceof DataView);
25776                 },
25777                 // returns an array by which times and values can be sorted
25778                 getKeyframeOrder: function getKeyframeOrder(times) {
25779                         function compareTime(i, j) {
25780                                 return times[i] - times[j];
25781                         }
25782
25783                         var n = times.length;
25784                         var result = new Array(n);
25785
25786                         for (var i = 0; i !== n; ++i) {
25787                                 result[i] = i;
25788                         }
25789
25790                         result.sort(compareTime);
25791                         return result;
25792                 },
25793                 // uses the array previously returned by 'getKeyframeOrder' to sort data
25794                 sortedArray: function sortedArray(values, stride, order) {
25795                         var nValues = values.length;
25796                         var result = new values.constructor(nValues);
25797
25798                         for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
25799                                 var srcOffset = order[i] * stride;
25800
25801                                 for (var j = 0; j !== stride; ++j) {
25802                                         result[dstOffset++] = values[srcOffset + j];
25803                                 }
25804                         }
25805
25806                         return result;
25807                 },
25808                 // function for parsing AOS keyframe formats
25809                 flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
25810                         var i = 1,
25811                                         key = jsonKeys[0];
25812
25813                         while (key !== undefined && key[valuePropertyName] === undefined) {
25814                                 key = jsonKeys[i++];
25815                         }
25816
25817                         if (key === undefined) return; // no data
25818
25819                         var value = key[valuePropertyName];
25820                         if (value === undefined) return; // no data
25821
25822                         if (Array.isArray(value)) {
25823                                 do {
25824                                         value = key[valuePropertyName];
25825
25826                                         if (value !== undefined) {
25827                                                 times.push(key.time);
25828                                                 values.push.apply(values, value); // push all elements
25829                                         }
25830
25831                                         key = jsonKeys[i++];
25832                                 } while (key !== undefined);
25833                         } else if (value.toArray !== undefined) {
25834                                 // ...assume THREE.Math-ish
25835                                 do {
25836                                         value = key[valuePropertyName];
25837
25838                                         if (value !== undefined) {
25839                                                 times.push(key.time);
25840                                                 value.toArray(values, values.length);
25841                                         }
25842
25843                                         key = jsonKeys[i++];
25844                                 } while (key !== undefined);
25845                         } else {
25846                                 // otherwise push as-is
25847                                 do {
25848                                         value = key[valuePropertyName];
25849
25850                                         if (value !== undefined) {
25851                                                 times.push(key.time);
25852                                                 values.push(value);
25853                                         }
25854
25855                                         key = jsonKeys[i++];
25856                                 } while (key !== undefined);
25857                         }
25858                 },
25859                 subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
25860                         if (fps === void 0) {
25861                                 fps = 30;
25862                         }
25863
25864                         var clip = sourceClip.clone();
25865                         clip.name = name;
25866                         var tracks = [];
25867
25868                         for (var i = 0; i < clip.tracks.length; ++i) {
25869                                 var track = clip.tracks[i];
25870                                 var valueSize = track.getValueSize();
25871                                 var times = [];
25872                                 var values = [];
25873
25874                                 for (var j = 0; j < track.times.length; ++j) {
25875                                         var frame = track.times[j] * fps;
25876                                         if (frame < startFrame || frame >= endFrame) continue;
25877                                         times.push(track.times[j]);
25878
25879                                         for (var k = 0; k < valueSize; ++k) {
25880                                                 values.push(track.values[j * valueSize + k]);
25881                                         }
25882                                 }
25883
25884                                 if (times.length === 0) continue;
25885                                 track.times = AnimationUtils.convertArray(times, track.times.constructor);
25886                                 track.values = AnimationUtils.convertArray(values, track.values.constructor);
25887                                 tracks.push(track);
25888                         }
25889
25890                         clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
25891
25892                         var minStartTime = Infinity;
25893
25894                         for (var _i = 0; _i < clip.tracks.length; ++_i) {
25895                                 if (minStartTime > clip.tracks[_i].times[0]) {
25896                                         minStartTime = clip.tracks[_i].times[0];
25897                                 }
25898                         } // shift all tracks such that clip begins at t=0
25899
25900
25901                         for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
25902                                 clip.tracks[_i2].shift(-1 * minStartTime);
25903                         }
25904
25905                         clip.resetDuration();
25906                         return clip;
25907                 },
25908                 makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
25909                         if (referenceFrame === void 0) {
25910                                 referenceFrame = 0;
25911                         }
25912
25913                         if (referenceClip === void 0) {
25914                                 referenceClip = targetClip;
25915                         }
25916
25917                         if (fps === void 0) {
25918                                 fps = 30;
25919                         }
25920
25921                         if (fps <= 0) fps = 30;
25922                         var numTracks = referenceClip.tracks.length;
25923                         var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
25924
25925                         var _loop = function _loop(i) {
25926                                 var referenceTrack = referenceClip.tracks[i];
25927                                 var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
25928
25929                                 if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
25930
25931                                 var targetTrack = targetClip.tracks.find(function (track) {
25932                                         return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
25933                                 });
25934                                 if (targetTrack === undefined) return "continue";
25935                                 var referenceOffset = 0;
25936                                 var referenceValueSize = referenceTrack.getValueSize();
25937
25938                                 if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
25939                                         referenceOffset = referenceValueSize / 3;
25940                                 }
25941
25942                                 var targetOffset = 0;
25943                                 var targetValueSize = targetTrack.getValueSize();
25944
25945                                 if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
25946                                         targetOffset = targetValueSize / 3;
25947                                 }
25948
25949                                 var lastIndex = referenceTrack.times.length - 1;
25950                                 var referenceValue = void 0; // Find the value to subtract out of the track
25951
25952                                 if (referenceTime <= referenceTrack.times[0]) {
25953                                         // Reference frame is earlier than the first keyframe, so just use the first keyframe
25954                                         var startIndex = referenceOffset;
25955                                         var endIndex = referenceValueSize - referenceOffset;
25956                                         referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
25957                                 } else if (referenceTime >= referenceTrack.times[lastIndex]) {
25958                                         // Reference frame is after the last keyframe, so just use the last keyframe
25959                                         var _startIndex = lastIndex * referenceValueSize + referenceOffset;
25960
25961                                         var _endIndex = _startIndex + referenceValueSize - referenceOffset;
25962
25963                                         referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
25964                                 } else {
25965                                         // Interpolate to the reference value
25966                                         var interpolant = referenceTrack.createInterpolant();
25967                                         var _startIndex2 = referenceOffset;
25968
25969                                         var _endIndex2 = referenceValueSize - referenceOffset;
25970
25971                                         interpolant.evaluate(referenceTime);
25972                                         referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
25973                                 } // Conjugate the quaternion
25974
25975
25976                                 if (referenceTrackType === 'quaternion') {
25977                                         var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
25978                                         referenceQuat.toArray(referenceValue);
25979                                 } // Subtract the reference value from all of the track values
25980
25981
25982                                 var numTimes = targetTrack.times.length;
25983
25984                                 for (var j = 0; j < numTimes; ++j) {
25985                                         var valueStart = j * targetValueSize + targetOffset;
25986
25987                                         if (referenceTrackType === 'quaternion') {
25988                                                 // Multiply the conjugate for quaternion track types
25989                                                 Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
25990                                         } else {
25991                                                 var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
25992
25993                                                 for (var k = 0; k < valueEnd; ++k) {
25994                                                         targetTrack.values[valueStart + k] -= referenceValue[k];
25995                                                 }
25996                                         }
25997                                 }
25998                         };
25999
26000                         for (var i = 0; i < numTracks; ++i) {
26001                                 var _ret = _loop(i);
26002
26003                                 if (_ret === "continue") continue;
26004                         }
26005
26006                         targetClip.blendMode = AdditiveAnimationBlendMode;
26007                         return targetClip;
26008                 }
26009         };
26010
26011         /**
26012          * Abstract base class of interpolants over parametric samples.
26013          *
26014          * The parameter domain is one dimensional, typically the time or a path
26015          * along a curve defined by the data.
26016          *
26017          * The sample values can have any dimensionality and derived classes may
26018          * apply special interpretations to the data.
26019          *
26020          * This class provides the interval seek in a Template Method, deferring
26021          * the actual interpolation to derived classes.
26022          *
26023          * Time complexity is O(1) for linear access crossing at most two points
26024          * and O(log N) for random access, where N is the number of positions.
26025          *
26026          * References:
26027          *
26028          *              http://www.oodesign.com/template-method-pattern.html
26029          *
26030          */
26031         function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
26032                 this.parameterPositions = parameterPositions;
26033                 this._cachedIndex = 0;
26034                 this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
26035                 this.sampleValues = sampleValues;
26036                 this.valueSize = sampleSize;
26037         }
26038
26039         Object.assign(Interpolant.prototype, {
26040                 evaluate: function evaluate(t) {
26041                         var pp = this.parameterPositions;
26042                         var i1 = this._cachedIndex,
26043                                         t1 = pp[i1],
26044                                         t0 = pp[i1 - 1];
26045
26046                         validate_interval: {
26047                                 seek: {
26048                                         var right;
26049
26050                                         linear_scan: {
26051                                                 //- See http://jsperf.com/comparison-to-undefined/3
26052                                                 //- slower code:
26053                                                 //-
26054                                                 //-                             if ( t >= t1 || t1 === undefined ) {
26055                                                 forward_scan: if (!(t < t1)) {
26056                                                         for (var giveUpAt = i1 + 2;;) {
26057                                                                 if (t1 === undefined) {
26058                                                                         if (t < t0) break forward_scan; // after end
26059
26060                                                                         i1 = pp.length;
26061                                                                         this._cachedIndex = i1;
26062                                                                         return this.afterEnd_(i1 - 1, t, t0);
26063                                                                 }
26064
26065                                                                 if (i1 === giveUpAt) break; // this loop
26066
26067                                                                 t0 = t1;
26068                                                                 t1 = pp[++i1];
26069
26070                                                                 if (t < t1) {
26071                                                                         // we have arrived at the sought interval
26072                                                                         break seek;
26073                                                                 }
26074                                                         } // prepare binary search on the right side of the index
26075
26076
26077                                                         right = pp.length;
26078                                                         break linear_scan;
26079                                                 } //- slower code:
26080                                                 //-                                     if ( t < t0 || t0 === undefined ) {
26081
26082
26083                                                 if (!(t >= t0)) {
26084                                                         // looping?
26085                                                         var t1global = pp[1];
26086
26087                                                         if (t < t1global) {
26088                                                                 i1 = 2; // + 1, using the scan for the details
26089
26090                                                                 t0 = t1global;
26091                                                         } // linear reverse scan
26092
26093
26094                                                         for (var _giveUpAt = i1 - 2;;) {
26095                                                                 if (t0 === undefined) {
26096                                                                         // before start
26097                                                                         this._cachedIndex = 0;
26098                                                                         return this.beforeStart_(0, t, t1);
26099                                                                 }
26100
26101                                                                 if (i1 === _giveUpAt) break; // this loop
26102
26103                                                                 t1 = t0;
26104                                                                 t0 = pp[--i1 - 1];
26105
26106                                                                 if (t >= t0) {
26107                                                                         // we have arrived at the sought interval
26108                                                                         break seek;
26109                                                                 }
26110                                                         } // prepare binary search on the left side of the index
26111
26112
26113                                                         right = i1;
26114                                                         i1 = 0;
26115                                                         break linear_scan;
26116                                                 } // the interval is valid
26117
26118
26119                                                 break validate_interval;
26120                                         } // linear scan
26121                                         // binary search
26122
26123
26124                                         while (i1 < right) {
26125                                                 var mid = i1 + right >>> 1;
26126
26127                                                 if (t < pp[mid]) {
26128                                                         right = mid;
26129                                                 } else {
26130                                                         i1 = mid + 1;
26131                                                 }
26132                                         }
26133
26134                                         t1 = pp[i1];
26135                                         t0 = pp[i1 - 1]; // check boundary cases, again
26136
26137                                         if (t0 === undefined) {
26138                                                 this._cachedIndex = 0;
26139                                                 return this.beforeStart_(0, t, t1);
26140                                         }
26141
26142                                         if (t1 === undefined) {
26143                                                 i1 = pp.length;
26144                                                 this._cachedIndex = i1;
26145                                                 return this.afterEnd_(i1 - 1, t0, t);
26146                                         }
26147                                 } // seek
26148
26149
26150                                 this._cachedIndex = i1;
26151                                 this.intervalChanged_(i1, t0, t1);
26152                         } // validate_interval
26153
26154
26155                         return this.interpolate_(i1, t0, t, t1);
26156                 },
26157                 settings: null,
26158                 // optional, subclass-specific settings structure
26159                 // Note: The indirection allows central control of many interpolants.
26160                 // --- Protected interface
26161                 DefaultSettings_: {},
26162                 getSettings_: function getSettings_() {
26163                         return this.settings || this.DefaultSettings_;
26164                 },
26165                 copySampleValue_: function copySampleValue_(index) {
26166                         // copies a sample value to the result buffer
26167                         var result = this.resultBuffer,
26168                                         values = this.sampleValues,
26169                                         stride = this.valueSize,
26170                                         offset = index * stride;
26171
26172                         for (var i = 0; i !== stride; ++i) {
26173                                 result[i] = values[offset + i];
26174                         }
26175
26176                         return result;
26177                 },
26178                 // Template methods for derived classes:
26179                 interpolate_: function interpolate_()
26180                 /* i1, t0, t, t1 */
26181                 {
26182                         throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
26183                 },
26184                 intervalChanged_: function intervalChanged_()
26185                 /* i1, t0, t1 */
26186                 {// empty
26187                 }
26188         }); // DECLARE ALIAS AFTER assign prototype
26189
26190         Object.assign(Interpolant.prototype, {
26191                 //( 0, t, t0 ), returns this.resultBuffer
26192                 beforeStart_: Interpolant.prototype.copySampleValue_,
26193                 //( N-1, tN-1, t ), returns this.resultBuffer
26194                 afterEnd_: Interpolant.prototype.copySampleValue_
26195         });
26196
26197         /**
26198          * Fast and simple cubic spline interpolant.
26199          *
26200          * It was derived from a Hermitian construction setting the first derivative
26201          * at each sample position to the linear slope between neighboring positions
26202          * over their parameter interval.
26203          */
26204
26205         function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
26206                 Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
26207                 this._weightPrev = -0;
26208                 this._offsetPrev = -0;
26209                 this._weightNext = -0;
26210                 this._offsetNext = -0;
26211         }
26212
26213         CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
26214                 constructor: CubicInterpolant,
26215                 DefaultSettings_: {
26216                         endingStart: ZeroCurvatureEnding,
26217                         endingEnd: ZeroCurvatureEnding
26218                 },
26219                 intervalChanged_: function intervalChanged_(i1, t0, t1) {
26220                         var pp = this.parameterPositions;
26221                         var iPrev = i1 - 2,
26222                                         iNext = i1 + 1,
26223                                         tPrev = pp[iPrev],
26224                                         tNext = pp[iNext];
26225
26226                         if (tPrev === undefined) {
26227                                 switch (this.getSettings_().endingStart) {
26228                                         case ZeroSlopeEnding:
26229                                                 // f'(t0) = 0
26230                                                 iPrev = i1;
26231                                                 tPrev = 2 * t0 - t1;
26232                                                 break;
26233
26234                                         case WrapAroundEnding:
26235                                                 // use the other end of the curve
26236                                                 iPrev = pp.length - 2;
26237                                                 tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
26238                                                 break;
26239
26240                                         default:
26241                                                 // ZeroCurvatureEnding
26242                                                 // f''(t0) = 0 a.k.a. Natural Spline
26243                                                 iPrev = i1;
26244                                                 tPrev = t1;
26245                                 }
26246                         }
26247
26248                         if (tNext === undefined) {
26249                                 switch (this.getSettings_().endingEnd) {
26250                                         case ZeroSlopeEnding:
26251                                                 // f'(tN) = 0
26252                                                 iNext = i1;
26253                                                 tNext = 2 * t1 - t0;
26254                                                 break;
26255
26256                                         case WrapAroundEnding:
26257                                                 // use the other end of the curve
26258                                                 iNext = 1;
26259                                                 tNext = t1 + pp[1] - pp[0];
26260                                                 break;
26261
26262                                         default:
26263                                                 // ZeroCurvatureEnding
26264                                                 // f''(tN) = 0, a.k.a. Natural Spline
26265                                                 iNext = i1 - 1;
26266                                                 tNext = t0;
26267                                 }
26268                         }
26269
26270                         var halfDt = (t1 - t0) * 0.5,
26271                                         stride = this.valueSize;
26272                         this._weightPrev = halfDt / (t0 - tPrev);
26273                         this._weightNext = halfDt / (tNext - t1);
26274                         this._offsetPrev = iPrev * stride;
26275                         this._offsetNext = iNext * stride;
26276                 },
26277                 interpolate_: function interpolate_(i1, t0, t, t1) {
26278                         var result = this.resultBuffer,
26279                                         values = this.sampleValues,
26280                                         stride = this.valueSize,
26281                                         o1 = i1 * stride,
26282                                         o0 = o1 - stride,
26283                                         oP = this._offsetPrev,
26284                                         oN = this._offsetNext,
26285                                         wP = this._weightPrev,
26286                                         wN = this._weightNext,
26287                                         p = (t - t0) / (t1 - t0),
26288                                         pp = p * p,
26289                                         ppp = pp * p; // evaluate polynomials
26290
26291                         var sP = -wP * ppp + 2 * wP * pp - wP * p;
26292                         var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
26293                         var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
26294                         var sN = wN * ppp - wN * pp; // combine data linearly
26295
26296                         for (var i = 0; i !== stride; ++i) {
26297                                 result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
26298                         }
26299
26300                         return result;
26301                 }
26302         });
26303
26304         function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
26305                 Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
26306         }
26307
26308         LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
26309                 constructor: LinearInterpolant,
26310                 interpolate_: function interpolate_(i1, t0, t, t1) {
26311                         var result = this.resultBuffer,
26312                                         values = this.sampleValues,
26313                                         stride = this.valueSize,
26314                                         offset1 = i1 * stride,
26315                                         offset0 = offset1 - stride,
26316                                         weight1 = (t - t0) / (t1 - t0),
26317                                         weight0 = 1 - weight1;
26318
26319                         for (var i = 0; i !== stride; ++i) {
26320                                 result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
26321                         }
26322
26323                         return result;
26324                 }
26325         });
26326
26327         /**
26328          *
26329          * Interpolant that evaluates to the sample value at the position preceeding
26330          * the parameter.
26331          */
26332
26333         function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
26334                 Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
26335         }
26336
26337         DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
26338                 constructor: DiscreteInterpolant,
26339                 interpolate_: function interpolate_(i1
26340                 /*, t0, t, t1 */
26341                 ) {
26342                         return this.copySampleValue_(i1 - 1);
26343                 }
26344         });
26345
26346         function KeyframeTrack(name, times, values, interpolation) {
26347                 if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
26348                 if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
26349                 this.name = name;
26350                 this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
26351                 this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
26352                 this.setInterpolation(interpolation || this.DefaultInterpolation);
26353         } // Static methods
26354
26355
26356         Object.assign(KeyframeTrack, {
26357                 // Serialization (in static context, because of constructor invocation
26358                 // and automatic invocation of .toJSON):
26359                 toJSON: function toJSON(track) {
26360                         var trackType = track.constructor;
26361                         var json; // derived classes can define a static toJSON method
26362
26363                         if (trackType.toJSON !== undefined) {
26364                                 json = trackType.toJSON(track);
26365                         } else {
26366                                 // by default, we assume the data can be serialized as-is
26367                                 json = {
26368                                         'name': track.name,
26369                                         'times': AnimationUtils.convertArray(track.times, Array),
26370                                         'values': AnimationUtils.convertArray(track.values, Array)
26371                                 };
26372                                 var interpolation = track.getInterpolation();
26373
26374                                 if (interpolation !== track.DefaultInterpolation) {
26375                                         json.interpolation = interpolation;
26376                                 }
26377                         }
26378
26379                         json.type = track.ValueTypeName; // mandatory
26380
26381                         return json;
26382                 }
26383         });
26384         Object.assign(KeyframeTrack.prototype, {
26385                 constructor: KeyframeTrack,
26386                 TimeBufferType: Float32Array,
26387                 ValueBufferType: Float32Array,
26388                 DefaultInterpolation: InterpolateLinear,
26389                 InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
26390                         return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
26391                 },
26392                 InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
26393                         return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
26394                 },
26395                 InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
26396                         return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
26397                 },
26398                 setInterpolation: function setInterpolation(interpolation) {
26399                         var factoryMethod;
26400
26401                         switch (interpolation) {
26402                                 case InterpolateDiscrete:
26403                                         factoryMethod = this.InterpolantFactoryMethodDiscrete;
26404                                         break;
26405
26406                                 case InterpolateLinear:
26407                                         factoryMethod = this.InterpolantFactoryMethodLinear;
26408                                         break;
26409
26410                                 case InterpolateSmooth:
26411                                         factoryMethod = this.InterpolantFactoryMethodSmooth;
26412                                         break;
26413                         }
26414
26415                         if (factoryMethod === undefined) {
26416                                 var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
26417
26418                                 if (this.createInterpolant === undefined) {
26419                                         // fall back to default, unless the default itself is messed up
26420                                         if (interpolation !== this.DefaultInterpolation) {
26421                                                 this.setInterpolation(this.DefaultInterpolation);
26422                                         } else {
26423                                                 throw new Error(message); // fatal, in this case
26424                                         }
26425                                 }
26426
26427                                 console.warn('THREE.KeyframeTrack:', message);
26428                                 return this;
26429                         }
26430
26431                         this.createInterpolant = factoryMethod;
26432                         return this;
26433                 },
26434                 getInterpolation: function getInterpolation() {
26435                         switch (this.createInterpolant) {
26436                                 case this.InterpolantFactoryMethodDiscrete:
26437                                         return InterpolateDiscrete;
26438
26439                                 case this.InterpolantFactoryMethodLinear:
26440                                         return InterpolateLinear;
26441
26442                                 case this.InterpolantFactoryMethodSmooth:
26443                                         return InterpolateSmooth;
26444                         }
26445                 },
26446                 getValueSize: function getValueSize() {
26447                         return this.values.length / this.times.length;
26448                 },
26449                 // move all keyframes either forwards or backwards in time
26450                 shift: function shift(timeOffset) {
26451                         if (timeOffset !== 0.0) {
26452                                 var times = this.times;
26453
26454                                 for (var i = 0, n = times.length; i !== n; ++i) {
26455                                         times[i] += timeOffset;
26456                                 }
26457                         }
26458
26459                         return this;
26460                 },
26461                 // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
26462                 scale: function scale(timeScale) {
26463                         if (timeScale !== 1.0) {
26464                                 var times = this.times;
26465
26466                                 for (var i = 0, n = times.length; i !== n; ++i) {
26467                                         times[i] *= timeScale;
26468                                 }
26469                         }
26470
26471                         return this;
26472                 },
26473                 // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
26474                 // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
26475                 trim: function trim(startTime, endTime) {
26476                         var times = this.times,
26477                                         nKeys = times.length;
26478                         var from = 0,
26479                                         to = nKeys - 1;
26480
26481                         while (from !== nKeys && times[from] < startTime) {
26482                                 ++from;
26483                         }
26484
26485                         while (to !== -1 && times[to] > endTime) {
26486                                 --to;
26487                         }
26488
26489                         ++to; // inclusive -> exclusive bound
26490
26491                         if (from !== 0 || to !== nKeys) {
26492                                 // empty tracks are forbidden, so keep at least one keyframe
26493                                 if (from >= to) {
26494                                         to = Math.max(to, 1);
26495                                         from = to - 1;
26496                                 }
26497
26498                                 var stride = this.getValueSize();
26499                                 this.times = AnimationUtils.arraySlice(times, from, to);
26500                                 this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
26501                         }
26502
26503                         return this;
26504                 },
26505                 // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
26506                 validate: function validate() {
26507                         var valid = true;
26508                         var valueSize = this.getValueSize();
26509
26510                         if (valueSize - Math.floor(valueSize) !== 0) {
26511                                 console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
26512                                 valid = false;
26513                         }
26514
26515                         var times = this.times,
26516                                         values = this.values,
26517                                         nKeys = times.length;
26518
26519                         if (nKeys === 0) {
26520                                 console.error('THREE.KeyframeTrack: Track is empty.', this);
26521                                 valid = false;
26522                         }
26523
26524                         var prevTime = null;
26525
26526                         for (var i = 0; i !== nKeys; i++) {
26527                                 var currTime = times[i];
26528
26529                                 if (typeof currTime === 'number' && isNaN(currTime)) {
26530                                         console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
26531                                         valid = false;
26532                                         break;
26533                                 }
26534
26535                                 if (prevTime !== null && prevTime > currTime) {
26536                                         console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
26537                                         valid = false;
26538                                         break;
26539                                 }
26540
26541                                 prevTime = currTime;
26542                         }
26543
26544                         if (values !== undefined) {
26545                                 if (AnimationUtils.isTypedArray(values)) {
26546                                         for (var _i = 0, n = values.length; _i !== n; ++_i) {
26547                                                 var value = values[_i];
26548
26549                                                 if (isNaN(value)) {
26550                                                         console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
26551                                                         valid = false;
26552                                                         break;
26553                                                 }
26554                                         }
26555                                 }
26556                         }
26557
26558                         return valid;
26559                 },
26560                 // removes equivalent sequential keys as common in morph target sequences
26561                 // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
26562                 optimize: function optimize() {
26563                         // times or values may be shared with other tracks, so overwriting is unsafe
26564                         var times = AnimationUtils.arraySlice(this.times),
26565                                         values = AnimationUtils.arraySlice(this.values),
26566                                         stride = this.getValueSize(),
26567                                         smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
26568                                         lastIndex = times.length - 1;
26569                         var writeIndex = 1;
26570
26571                         for (var i = 1; i < lastIndex; ++i) {
26572                                 var keep = false;
26573                                 var time = times[i];
26574                                 var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
26575
26576                                 if (time !== timeNext && (i !== 1 || time !== time[0])) {
26577                                         if (!smoothInterpolation) {
26578                                                 // remove unnecessary keyframes same as their neighbors
26579                                                 var offset = i * stride,
26580                                                                 offsetP = offset - stride,
26581                                                                 offsetN = offset + stride;
26582
26583                                                 for (var j = 0; j !== stride; ++j) {
26584                                                         var value = values[offset + j];
26585
26586                                                         if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
26587                                                                 keep = true;
26588                                                                 break;
26589                                                         }
26590                                                 }
26591                                         } else {
26592                                                 keep = true;
26593                                         }
26594                                 } // in-place compaction
26595
26596
26597                                 if (keep) {
26598                                         if (i !== writeIndex) {
26599                                                 times[writeIndex] = times[i];
26600                                                 var readOffset = i * stride,
26601                                                                 writeOffset = writeIndex * stride;
26602
26603                                                 for (var _j = 0; _j !== stride; ++_j) {
26604                                                         values[writeOffset + _j] = values[readOffset + _j];
26605                                                 }
26606                                         }
26607
26608                                         ++writeIndex;
26609                                 }
26610                         } // flush last keyframe (compaction looks ahead)
26611
26612
26613                         if (lastIndex > 0) {
26614                                 times[writeIndex] = times[lastIndex];
26615
26616                                 for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
26617                                         values[_writeOffset + _j2] = values[_readOffset + _j2];
26618                                 }
26619
26620                                 ++writeIndex;
26621                         }
26622
26623                         if (writeIndex !== times.length) {
26624                                 this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
26625                                 this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
26626                         } else {
26627                                 this.times = times;
26628                                 this.values = values;
26629                         }
26630
26631                         return this;
26632                 },
26633                 clone: function clone() {
26634                         var times = AnimationUtils.arraySlice(this.times, 0);
26635                         var values = AnimationUtils.arraySlice(this.values, 0);
26636                         var TypedKeyframeTrack = this.constructor;
26637                         var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
26638
26639                         track.createInterpolant = this.createInterpolant;
26640                         return track;
26641                 }
26642         });
26643
26644         /**
26645          * A Track of Boolean keyframe values.
26646          */
26647
26648         function BooleanKeyframeTrack(name, times, values) {
26649                 KeyframeTrack.call(this, name, times, values);
26650         }
26651
26652         BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
26653                 constructor: BooleanKeyframeTrack,
26654                 ValueTypeName: 'bool',
26655                 ValueBufferType: Array,
26656                 DefaultInterpolation: InterpolateDiscrete,
26657                 InterpolantFactoryMethodLinear: undefined,
26658                 InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
26659                 // representation of a single value and a custom interpolant that
26660                 // computes "firstValue ^ isOdd( index )".
26661
26662         });
26663
26664         /**
26665          * A Track of keyframe values that represent color.
26666          */
26667
26668         function ColorKeyframeTrack(name, times, values, interpolation) {
26669                 KeyframeTrack.call(this, name, times, values, interpolation);
26670         }
26671
26672         ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
26673                 constructor: ColorKeyframeTrack,
26674                 ValueTypeName: 'color' // ValueBufferType is inherited
26675                 // DefaultInterpolation is inherited
26676                 // Note: Very basic implementation and nothing special yet.
26677                 // However, this is the place for color space parameterization.
26678
26679         });
26680
26681         /**
26682          * A Track of numeric keyframe values.
26683          */
26684
26685         function NumberKeyframeTrack(name, times, values, interpolation) {
26686                 KeyframeTrack.call(this, name, times, values, interpolation);
26687         }
26688
26689         NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
26690                 constructor: NumberKeyframeTrack,
26691                 ValueTypeName: 'number' // ValueBufferType is inherited
26692                 // DefaultInterpolation is inherited
26693
26694         });
26695
26696         /**
26697          * Spherical linear unit quaternion interpolant.
26698          */
26699
26700         function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
26701                 Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
26702         }
26703
26704         QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
26705                 constructor: QuaternionLinearInterpolant,
26706                 interpolate_: function interpolate_(i1, t0, t, t1) {
26707                         var result = this.resultBuffer,
26708                                         values = this.sampleValues,
26709                                         stride = this.valueSize,
26710                                         alpha = (t - t0) / (t1 - t0);
26711                         var offset = i1 * stride;
26712
26713                         for (var end = offset + stride; offset !== end; offset += 4) {
26714                                 Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
26715                         }
26716
26717                         return result;
26718                 }
26719         });
26720
26721         /**
26722          * A Track of quaternion keyframe values.
26723          */
26724
26725         function QuaternionKeyframeTrack(name, times, values, interpolation) {
26726                 KeyframeTrack.call(this, name, times, values, interpolation);
26727         }
26728
26729         QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
26730                 constructor: QuaternionKeyframeTrack,
26731                 ValueTypeName: 'quaternion',
26732                 // ValueBufferType is inherited
26733                 DefaultInterpolation: InterpolateLinear,
26734                 InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
26735                         return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
26736                 },
26737                 InterpolantFactoryMethodSmooth: undefined // not yet implemented
26738
26739         });
26740
26741         /**
26742          * A Track that interpolates Strings
26743          */
26744
26745         function StringKeyframeTrack(name, times, values, interpolation) {
26746                 KeyframeTrack.call(this, name, times, values, interpolation);
26747         }
26748
26749         StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
26750                 constructor: StringKeyframeTrack,
26751                 ValueTypeName: 'string',
26752                 ValueBufferType: Array,
26753                 DefaultInterpolation: InterpolateDiscrete,
26754                 InterpolantFactoryMethodLinear: undefined,
26755                 InterpolantFactoryMethodSmooth: undefined
26756         });
26757
26758         /**
26759          * A Track of vectored keyframe values.
26760          */
26761
26762         function VectorKeyframeTrack(name, times, values, interpolation) {
26763                 KeyframeTrack.call(this, name, times, values, interpolation);
26764         }
26765
26766         VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
26767                 constructor: VectorKeyframeTrack,
26768                 ValueTypeName: 'vector' // ValueBufferType is inherited
26769                 // DefaultInterpolation is inherited
26770
26771         });
26772
26773         function AnimationClip(name, duration, tracks, blendMode) {
26774                 this.name = name;
26775                 this.tracks = tracks;
26776                 this.duration = duration !== undefined ? duration : -1;
26777                 this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
26778                 this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
26779
26780                 if (this.duration < 0) {
26781                         this.resetDuration();
26782                 }
26783         }
26784
26785         function getTrackTypeForValueTypeName(typeName) {
26786                 switch (typeName.toLowerCase()) {
26787                         case 'scalar':
26788                         case 'double':
26789                         case 'float':
26790                         case 'number':
26791                         case 'integer':
26792                                 return NumberKeyframeTrack;
26793
26794                         case 'vector':
26795                         case 'vector2':
26796                         case 'vector3':
26797                         case 'vector4':
26798                                 return VectorKeyframeTrack;
26799
26800                         case 'color':
26801                                 return ColorKeyframeTrack;
26802
26803                         case 'quaternion':
26804                                 return QuaternionKeyframeTrack;
26805
26806                         case 'bool':
26807                         case 'boolean':
26808                                 return BooleanKeyframeTrack;
26809
26810                         case 'string':
26811                                 return StringKeyframeTrack;
26812                 }
26813
26814                 throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
26815         }
26816
26817         function parseKeyframeTrack(json) {
26818                 if (json.type === undefined) {
26819                         throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
26820                 }
26821
26822                 var trackType = getTrackTypeForValueTypeName(json.type);
26823
26824                 if (json.times === undefined) {
26825                         var times = [],
26826                                         values = [];
26827                         AnimationUtils.flattenJSON(json.keys, times, values, 'value');
26828                         json.times = times;
26829                         json.values = values;
26830                 } // derived classes can define a static parse method
26831
26832
26833                 if (trackType.parse !== undefined) {
26834                         return trackType.parse(json);
26835                 } else {
26836                         // by default, we assume a constructor compatible with the base
26837                         return new trackType(json.name, json.times, json.values, json.interpolation);
26838                 }
26839         }
26840
26841         Object.assign(AnimationClip, {
26842                 parse: function parse(json) {
26843                         var tracks = [],
26844                                         jsonTracks = json.tracks,
26845                                         frameTime = 1.0 / (json.fps || 1.0);
26846
26847                         for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
26848                                 tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
26849                         }
26850
26851                         var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
26852                         clip.uuid = json.uuid;
26853                         return clip;
26854                 },
26855                 toJSON: function toJSON(clip) {
26856                         var tracks = [],
26857                                         clipTracks = clip.tracks;
26858                         var json = {
26859                                 'name': clip.name,
26860                                 'duration': clip.duration,
26861                                 'tracks': tracks,
26862                                 'uuid': clip.uuid,
26863                                 'blendMode': clip.blendMode
26864                         };
26865
26866                         for (var i = 0, n = clipTracks.length; i !== n; ++i) {
26867                                 tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
26868                         }
26869
26870                         return json;
26871                 },
26872                 CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
26873                         var numMorphTargets = morphTargetSequence.length;
26874                         var tracks = [];
26875
26876                         for (var i = 0; i < numMorphTargets; i++) {
26877                                 var times = [];
26878                                 var values = [];
26879                                 times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
26880                                 values.push(0, 1, 0);
26881                                 var order = AnimationUtils.getKeyframeOrder(times);
26882                                 times = AnimationUtils.sortedArray(times, 1, order);
26883                                 values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
26884                                 // last frame as well for perfect loop.
26885
26886                                 if (!noLoop && times[0] === 0) {
26887                                         times.push(numMorphTargets);
26888                                         values.push(values[0]);
26889                                 }
26890
26891                                 tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
26892                         }
26893
26894                         return new AnimationClip(name, -1, tracks);
26895                 },
26896                 findByName: function findByName(objectOrClipArray, name) {
26897                         var clipArray = objectOrClipArray;
26898
26899                         if (!Array.isArray(objectOrClipArray)) {
26900                                 var o = objectOrClipArray;
26901                                 clipArray = o.geometry && o.geometry.animations || o.animations;
26902                         }
26903
26904                         for (var i = 0; i < clipArray.length; i++) {
26905                                 if (clipArray[i].name === name) {
26906                                         return clipArray[i];
26907                                 }
26908                         }
26909
26910                         return null;
26911                 },
26912                 CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
26913                         var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
26914                         // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
26915
26916                         var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
26917                         // patterns like Walk_001, Walk_002, Run_001, Run_002
26918
26919                         for (var i = 0, il = morphTargets.length; i < il; i++) {
26920                                 var morphTarget = morphTargets[i];
26921                                 var parts = morphTarget.name.match(pattern);
26922
26923                                 if (parts && parts.length > 1) {
26924                                         var name = parts[1];
26925                                         var animationMorphTargets = animationToMorphTargets[name];
26926
26927                                         if (!animationMorphTargets) {
26928                                                 animationToMorphTargets[name] = animationMorphTargets = [];
26929                                         }
26930
26931                                         animationMorphTargets.push(morphTarget);
26932                                 }
26933                         }
26934
26935                         var clips = [];
26936
26937                         for (var _name in animationToMorphTargets) {
26938                                 clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
26939                         }
26940
26941                         return clips;
26942                 },
26943                 // parse the animation.hierarchy format
26944                 parseAnimation: function parseAnimation(animation, bones) {
26945                         if (!animation) {
26946                                 console.error('THREE.AnimationClip: No animation in JSONLoader data.');
26947                                 return null;
26948                         }
26949
26950                         var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
26951                                 // only return track if there are actually keys.
26952                                 if (animationKeys.length !== 0) {
26953                                         var times = [];
26954                                         var values = [];
26955                                         AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
26956
26957                                         if (times.length !== 0) {
26958                                                 destTracks.push(new trackType(trackName, times, values));
26959                                         }
26960                                 }
26961                         };
26962
26963                         var tracks = [];
26964                         var clipName = animation.name || 'default';
26965                         var fps = animation.fps || 30;
26966                         var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
26967
26968                         var duration = animation.length || -1;
26969                         var hierarchyTracks = animation.hierarchy || [];
26970
26971                         for (var h = 0; h < hierarchyTracks.length; h++) {
26972                                 var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
26973
26974                                 if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
26975
26976                                 if (animationKeys[0].morphTargets) {
26977                                         // figure out all morph targets used in this track
26978                                         var morphTargetNames = {};
26979                                         var k = void 0;
26980
26981                                         for (k = 0; k < animationKeys.length; k++) {
26982                                                 if (animationKeys[k].morphTargets) {
26983                                                         for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
26984                                                                 morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
26985                                                         }
26986                                                 }
26987                                         } // create a track for each morph target with all zero
26988                                         // morphTargetInfluences except for the keys in which
26989                                         // the morphTarget is named.
26990
26991
26992                                         for (var morphTargetName in morphTargetNames) {
26993                                                 var times = [];
26994                                                 var values = [];
26995
26996                                                 for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
26997                                                         var animationKey = animationKeys[k];
26998                                                         times.push(animationKey.time);
26999                                                         values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
27000                                                 }
27001
27002                                                 tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
27003                                         }
27004
27005                                         duration = morphTargetNames.length * (fps || 1.0);
27006                                 } else {
27007                                         // ...assume skeletal animation
27008                                         var boneName = '.bones[' + bones[h].name + ']';
27009                                         addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
27010                                         addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
27011                                         addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
27012                                 }
27013                         }
27014
27015                         if (tracks.length === 0) {
27016                                 return null;
27017                         }
27018
27019                         var clip = new AnimationClip(clipName, duration, tracks, blendMode);
27020                         return clip;
27021                 }
27022         });
27023         Object.assign(AnimationClip.prototype, {
27024                 resetDuration: function resetDuration() {
27025                         var tracks = this.tracks;
27026                         var duration = 0;
27027
27028                         for (var i = 0, n = tracks.length; i !== n; ++i) {
27029                                 var track = this.tracks[i];
27030                                 duration = Math.max(duration, track.times[track.times.length - 1]);
27031                         }
27032
27033                         this.duration = duration;
27034                         return this;
27035                 },
27036                 trim: function trim() {
27037                         for (var i = 0; i < this.tracks.length; i++) {
27038                                 this.tracks[i].trim(0, this.duration);
27039                         }
27040
27041                         return this;
27042                 },
27043                 validate: function validate() {
27044                         var valid = true;
27045
27046                         for (var i = 0; i < this.tracks.length; i++) {
27047                                 valid = valid && this.tracks[i].validate();
27048                         }
27049
27050                         return valid;
27051                 },
27052                 optimize: function optimize() {
27053                         for (var i = 0; i < this.tracks.length; i++) {
27054                                 this.tracks[i].optimize();
27055                         }
27056
27057                         return this;
27058                 },
27059                 clone: function clone() {
27060                         var tracks = [];
27061
27062                         for (var i = 0; i < this.tracks.length; i++) {
27063                                 tracks.push(this.tracks[i].clone());
27064                         }
27065
27066                         return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
27067                 },
27068                 toJSON: function toJSON() {
27069                         return AnimationClip.toJSON(this);
27070                 }
27071         });
27072
27073         var Cache = {
27074                 enabled: false,
27075                 files: {},
27076                 add: function add(key, file) {
27077                         if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
27078
27079                         this.files[key] = file;
27080                 },
27081                 get: function get(key) {
27082                         if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
27083
27084                         return this.files[key];
27085                 },
27086                 remove: function remove(key) {
27087                         delete this.files[key];
27088                 },
27089                 clear: function clear() {
27090                         this.files = {};
27091                 }
27092         };
27093
27094         function LoadingManager(onLoad, onProgress, onError) {
27095                 var scope = this;
27096                 var isLoading = false;
27097                 var itemsLoaded = 0;
27098                 var itemsTotal = 0;
27099                 var urlModifier = undefined;
27100                 var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
27101                 // in the constructor
27102
27103                 this.onStart = undefined;
27104                 this.onLoad = onLoad;
27105                 this.onProgress = onProgress;
27106                 this.onError = onError;
27107
27108                 this.itemStart = function (url) {
27109                         itemsTotal++;
27110
27111                         if (isLoading === false) {
27112                                 if (scope.onStart !== undefined) {
27113                                         scope.onStart(url, itemsLoaded, itemsTotal);
27114                                 }
27115                         }
27116
27117                         isLoading = true;
27118                 };
27119
27120                 this.itemEnd = function (url) {
27121                         itemsLoaded++;
27122
27123                         if (scope.onProgress !== undefined) {
27124                                 scope.onProgress(url, itemsLoaded, itemsTotal);
27125                         }
27126
27127                         if (itemsLoaded === itemsTotal) {
27128                                 isLoading = false;
27129
27130                                 if (scope.onLoad !== undefined) {
27131                                         scope.onLoad();
27132                                 }
27133                         }
27134                 };
27135
27136                 this.itemError = function (url) {
27137                         if (scope.onError !== undefined) {
27138                                 scope.onError(url);
27139                         }
27140                 };
27141
27142                 this.resolveURL = function (url) {
27143                         if (urlModifier) {
27144                                 return urlModifier(url);
27145                         }
27146
27147                         return url;
27148                 };
27149
27150                 this.setURLModifier = function (transform) {
27151                         urlModifier = transform;
27152                         return this;
27153                 };
27154
27155                 this.addHandler = function (regex, loader) {
27156                         handlers.push(regex, loader);
27157                         return this;
27158                 };
27159
27160                 this.removeHandler = function (regex) {
27161                         var index = handlers.indexOf(regex);
27162
27163                         if (index !== -1) {
27164                                 handlers.splice(index, 2);
27165                         }
27166
27167                         return this;
27168                 };
27169
27170                 this.getHandler = function (file) {
27171                         for (var i = 0, l = handlers.length; i < l; i += 2) {
27172                                 var regex = handlers[i];
27173                                 var loader = handlers[i + 1];
27174                                 if (regex.global) regex.lastIndex = 0; // see #17920
27175
27176                                 if (regex.test(file)) {
27177                                         return loader;
27178                                 }
27179                         }
27180
27181                         return null;
27182                 };
27183         }
27184
27185         var DefaultLoadingManager = new LoadingManager();
27186
27187         function Loader(manager) {
27188                 this.manager = manager !== undefined ? manager : DefaultLoadingManager;
27189                 this.crossOrigin = 'anonymous';
27190                 this.withCredentials = false;
27191                 this.path = '';
27192                 this.resourcePath = '';
27193                 this.requestHeader = {};
27194         }
27195
27196         Object.assign(Loader.prototype, {
27197                 load: function load()
27198                 /* url, onLoad, onProgress, onError */
27199                 {},
27200                 loadAsync: function loadAsync(url, onProgress) {
27201                         var scope = this;
27202                         return new Promise(function (resolve, reject) {
27203                                 scope.load(url, resolve, onProgress, reject);
27204                         });
27205                 },
27206                 parse: function parse()
27207                 /* data */
27208                 {},
27209                 setCrossOrigin: function setCrossOrigin(crossOrigin) {
27210                         this.crossOrigin = crossOrigin;
27211                         return this;
27212                 },
27213                 setWithCredentials: function setWithCredentials(value) {
27214                         this.withCredentials = value;
27215                         return this;
27216                 },
27217                 setPath: function setPath(path) {
27218                         this.path = path;
27219                         return this;
27220                 },
27221                 setResourcePath: function setResourcePath(resourcePath) {
27222                         this.resourcePath = resourcePath;
27223                         return this;
27224                 },
27225                 setRequestHeader: function setRequestHeader(requestHeader) {
27226                         this.requestHeader = requestHeader;
27227                         return this;
27228                 }
27229         });
27230
27231         var loading = {};
27232
27233         function FileLoader(manager) {
27234                 Loader.call(this, manager);
27235         }
27236
27237         FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
27238                 constructor: FileLoader,
27239                 load: function load(url, onLoad, onProgress, onError) {
27240                         if (url === undefined) url = '';
27241                         if (this.path !== undefined) url = this.path + url;
27242                         url = this.manager.resolveURL(url);
27243                         var scope = this;
27244                         var cached = Cache.get(url);
27245
27246                         if (cached !== undefined) {
27247                                 scope.manager.itemStart(url);
27248                                 setTimeout(function () {
27249                                         if (onLoad) onLoad(cached);
27250                                         scope.manager.itemEnd(url);
27251                                 }, 0);
27252                                 return cached;
27253                         } // Check if request is duplicate
27254
27255
27256                         if (loading[url] !== undefined) {
27257                                 loading[url].push({
27258                                         onLoad: onLoad,
27259                                         onProgress: onProgress,
27260                                         onError: onError
27261                                 });
27262                                 return;
27263                         } // Check for data: URI
27264
27265
27266                         var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
27267                         var dataUriRegexResult = url.match(dataUriRegex);
27268                         var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
27269
27270                         if (dataUriRegexResult) {
27271                                 var mimeType = dataUriRegexResult[1];
27272                                 var isBase64 = !!dataUriRegexResult[2];
27273                                 var data = dataUriRegexResult[3];
27274                                 data = decodeURIComponent(data);
27275                                 if (isBase64) data = atob(data);
27276
27277                                 try {
27278                                         var response;
27279                                         var responseType = (this.responseType || '').toLowerCase();
27280
27281                                         switch (responseType) {
27282                                                 case 'arraybuffer':
27283                                                 case 'blob':
27284                                                         var view = new Uint8Array(data.length);
27285
27286                                                         for (var i = 0; i < data.length; i++) {
27287                                                                 view[i] = data.charCodeAt(i);
27288                                                         }
27289
27290                                                         if (responseType === 'blob') {
27291                                                                 response = new Blob([view.buffer], {
27292                                                                         type: mimeType
27293                                                                 });
27294                                                         } else {
27295                                                                 response = view.buffer;
27296                                                         }
27297
27298                                                         break;
27299
27300                                                 case 'document':
27301                                                         var parser = new DOMParser();
27302                                                         response = parser.parseFromString(data, mimeType);
27303                                                         break;
27304
27305                                                 case 'json':
27306                                                         response = JSON.parse(data);
27307                                                         break;
27308
27309                                                 default:
27310                                                         // 'text' or other
27311                                                         response = data;
27312                                                         break;
27313                                         } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
27314
27315
27316                                         setTimeout(function () {
27317                                                 if (onLoad) onLoad(response);
27318                                                 scope.manager.itemEnd(url);
27319                                         }, 0);
27320                                 } catch (error) {
27321                                         // Wait for next browser tick like standard XMLHttpRequest event dispatching does
27322                                         setTimeout(function () {
27323                                                 if (onError) onError(error);
27324                                                 scope.manager.itemError(url);
27325                                                 scope.manager.itemEnd(url);
27326                                         }, 0);
27327                                 }
27328                         } else {
27329                                 // Initialise array for duplicate requests
27330                                 loading[url] = [];
27331                                 loading[url].push({
27332                                         onLoad: onLoad,
27333                                         onProgress: onProgress,
27334                                         onError: onError
27335                                 });
27336                                 request = new XMLHttpRequest();
27337                                 request.open('GET', url, true);
27338                                 request.addEventListener('load', function (event) {
27339                                         var response = this.response;
27340                                         var callbacks = loading[url];
27341                                         delete loading[url];
27342
27343                                         if (this.status === 200 || this.status === 0) {
27344                                                 // Some browsers return HTTP Status 0 when using non-http protocol
27345                                                 // e.g. 'file://' or 'data://'. Handle as success.
27346                                                 if (this.status === 0) console.warn('THREE.FileLoader: HTTP Status 0 received.'); // Add to cache only on HTTP success, so that we do not cache
27347                                                 // error response bodies as proper responses to requests.
27348
27349                                                 Cache.add(url, response);
27350
27351                                                 for (var _i = 0, il = callbacks.length; _i < il; _i++) {
27352                                                         var callback = callbacks[_i];
27353                                                         if (callback.onLoad) callback.onLoad(response);
27354                                                 }
27355
27356                                                 scope.manager.itemEnd(url);
27357                                         } else {
27358                                                 for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
27359                                                         var _callback = callbacks[_i2];
27360                                                         if (_callback.onError) _callback.onError(event);
27361                                                 }
27362
27363                                                 scope.manager.itemError(url);
27364                                                 scope.manager.itemEnd(url);
27365                                         }
27366                                 }, false);
27367                                 request.addEventListener('progress', function (event) {
27368                                         var callbacks = loading[url];
27369
27370                                         for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
27371                                                 var callback = callbacks[_i3];
27372                                                 if (callback.onProgress) callback.onProgress(event);
27373                                         }
27374                                 }, false);
27375                                 request.addEventListener('error', function (event) {
27376                                         var callbacks = loading[url];
27377                                         delete loading[url];
27378
27379                                         for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
27380                                                 var callback = callbacks[_i4];
27381                                                 if (callback.onError) callback.onError(event);
27382                                         }
27383
27384                                         scope.manager.itemError(url);
27385                                         scope.manager.itemEnd(url);
27386                                 }, false);
27387                                 request.addEventListener('abort', function (event) {
27388                                         var callbacks = loading[url];
27389                                         delete loading[url];
27390
27391                                         for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
27392                                                 var callback = callbacks[_i5];
27393                                                 if (callback.onError) callback.onError(event);
27394                                         }
27395
27396                                         scope.manager.itemError(url);
27397                                         scope.manager.itemEnd(url);
27398                                 }, false);
27399                                 if (this.responseType !== undefined) request.responseType = this.responseType;
27400                                 if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
27401                                 if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
27402
27403                                 for (var header in this.requestHeader) {
27404                                         request.setRequestHeader(header, this.requestHeader[header]);
27405                                 }
27406
27407                                 request.send(null);
27408                         }
27409
27410                         scope.manager.itemStart(url);
27411                         return request;
27412                 },
27413                 setResponseType: function setResponseType(value) {
27414                         this.responseType = value;
27415                         return this;
27416                 },
27417                 setMimeType: function setMimeType(value) {
27418                         this.mimeType = value;
27419                         return this;
27420                 }
27421         });
27422
27423         function AnimationLoader(manager) {
27424                 Loader.call(this, manager);
27425         }
27426
27427         AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
27428                 constructor: AnimationLoader,
27429                 load: function load(url, onLoad, onProgress, onError) {
27430                         var scope = this;
27431                         var loader = new FileLoader(scope.manager);
27432                         loader.setPath(scope.path);
27433                         loader.setRequestHeader(scope.requestHeader);
27434                         loader.setWithCredentials(scope.withCredentials);
27435                         loader.load(url, function (text) {
27436                                 try {
27437                                         onLoad(scope.parse(JSON.parse(text)));
27438                                 } catch (e) {
27439                                         if (onError) {
27440                                                 onError(e);
27441                                         } else {
27442                                                 console.error(e);
27443                                         }
27444
27445                                         scope.manager.itemError(url);
27446                                 }
27447                         }, onProgress, onError);
27448                 },
27449                 parse: function parse(json) {
27450                         var animations = [];
27451
27452                         for (var i = 0; i < json.length; i++) {
27453                                 var clip = AnimationClip.parse(json[i]);
27454                                 animations.push(clip);
27455                         }
27456
27457                         return animations;
27458                 }
27459         });
27460
27461         /**
27462          * Abstract Base class to block based textures loader (dds, pvr, ...)
27463          *
27464          * Sub classes have to implement the parse() method which will be used in load().
27465          */
27466
27467         function CompressedTextureLoader(manager) {
27468                 Loader.call(this, manager);
27469         }
27470
27471         CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
27472                 constructor: CompressedTextureLoader,
27473                 load: function load(url, onLoad, onProgress, onError) {
27474                         var scope = this;
27475                         var images = [];
27476                         var texture = new CompressedTexture();
27477                         texture.image = images;
27478                         var loader = new FileLoader(this.manager);
27479                         loader.setPath(this.path);
27480                         loader.setResponseType('arraybuffer');
27481                         loader.setRequestHeader(this.requestHeader);
27482                         loader.setWithCredentials(scope.withCredentials);
27483                         var loaded = 0;
27484
27485                         function loadTexture(i) {
27486                                 loader.load(url[i], function (buffer) {
27487                                         var texDatas = scope.parse(buffer, true);
27488                                         images[i] = {
27489                                                 width: texDatas.width,
27490                                                 height: texDatas.height,
27491                                                 format: texDatas.format,
27492                                                 mipmaps: texDatas.mipmaps
27493                                         };
27494                                         loaded += 1;
27495
27496                                         if (loaded === 6) {
27497                                                 if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
27498                                                 texture.format = texDatas.format;
27499                                                 texture.needsUpdate = true;
27500                                                 if (onLoad) onLoad(texture);
27501                                         }
27502                                 }, onProgress, onError);
27503                         }
27504
27505                         if (Array.isArray(url)) {
27506                                 for (var i = 0, il = url.length; i < il; ++i) {
27507                                         loadTexture(i);
27508                                 }
27509                         } else {
27510                                 // compressed cubemap texture stored in a single DDS file
27511                                 loader.load(url, function (buffer) {
27512                                         var texDatas = scope.parse(buffer, true);
27513
27514                                         if (texDatas.isCubemap) {
27515                                                 var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
27516
27517                                                 for (var f = 0; f < faces; f++) {
27518                                                         images[f] = {
27519                                                                 mipmaps: []
27520                                                         };
27521
27522                                                         for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
27523                                                                 images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
27524                                                                 images[f].format = texDatas.format;
27525                                                                 images[f].width = texDatas.width;
27526                                                                 images[f].height = texDatas.height;
27527                                                         }
27528                                                 }
27529                                         } else {
27530                                                 texture.image.width = texDatas.width;
27531                                                 texture.image.height = texDatas.height;
27532                                                 texture.mipmaps = texDatas.mipmaps;
27533                                         }
27534
27535                                         if (texDatas.mipmapCount === 1) {
27536                                                 texture.minFilter = LinearFilter;
27537                                         }
27538
27539                                         texture.format = texDatas.format;
27540                                         texture.needsUpdate = true;
27541                                         if (onLoad) onLoad(texture);
27542                                 }, onProgress, onError);
27543                         }
27544
27545                         return texture;
27546                 }
27547         });
27548
27549         function ImageLoader(manager) {
27550                 Loader.call(this, manager);
27551         }
27552
27553         ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
27554                 constructor: ImageLoader,
27555                 load: function load(url, onLoad, onProgress, onError) {
27556                         if (this.path !== undefined) url = this.path + url;
27557                         url = this.manager.resolveURL(url);
27558                         var scope = this;
27559                         var cached = Cache.get(url);
27560
27561                         if (cached !== undefined) {
27562                                 scope.manager.itemStart(url);
27563                                 setTimeout(function () {
27564                                         if (onLoad) onLoad(cached);
27565                                         scope.manager.itemEnd(url);
27566                                 }, 0);
27567                                 return cached;
27568                         }
27569
27570                         var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
27571
27572                         function onImageLoad() {
27573                                 image.removeEventListener('load', onImageLoad, false);
27574                                 image.removeEventListener('error', onImageError, false);
27575                                 Cache.add(url, this);
27576                                 if (onLoad) onLoad(this);
27577                                 scope.manager.itemEnd(url);
27578                         }
27579
27580                         function onImageError(event) {
27581                                 image.removeEventListener('load', onImageLoad, false);
27582                                 image.removeEventListener('error', onImageError, false);
27583                                 if (onError) onError(event);
27584                                 scope.manager.itemError(url);
27585                                 scope.manager.itemEnd(url);
27586                         }
27587
27588                         image.addEventListener('load', onImageLoad, false);
27589                         image.addEventListener('error', onImageError, false);
27590
27591                         if (url.substr(0, 5) !== 'data:') {
27592                                 if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
27593                         }
27594
27595                         scope.manager.itemStart(url);
27596                         image.src = url;
27597                         return image;
27598                 }
27599         });
27600
27601         function CubeTextureLoader(manager) {
27602                 Loader.call(this, manager);
27603         }
27604
27605         CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
27606                 constructor: CubeTextureLoader,
27607                 load: function load(urls, onLoad, onProgress, onError) {
27608                         var texture = new CubeTexture();
27609                         var loader = new ImageLoader(this.manager);
27610                         loader.setCrossOrigin(this.crossOrigin);
27611                         loader.setPath(this.path);
27612                         var loaded = 0;
27613
27614                         function loadTexture(i) {
27615                                 loader.load(urls[i], function (image) {
27616                                         texture.images[i] = image;
27617                                         loaded++;
27618
27619                                         if (loaded === 6) {
27620                                                 texture.needsUpdate = true;
27621                                                 if (onLoad) onLoad(texture);
27622                                         }
27623                                 }, undefined, onError);
27624                         }
27625
27626                         for (var i = 0; i < urls.length; ++i) {
27627                                 loadTexture(i);
27628                         }
27629
27630                         return texture;
27631                 }
27632         });
27633
27634         /**
27635          * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
27636          *
27637          * Sub classes have to implement the parse() method which will be used in load().
27638          */
27639
27640         function DataTextureLoader(manager) {
27641                 Loader.call(this, manager);
27642         }
27643
27644         DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
27645                 constructor: DataTextureLoader,
27646                 load: function load(url, onLoad, onProgress, onError) {
27647                         var scope = this;
27648                         var texture = new DataTexture();
27649                         var loader = new FileLoader(this.manager);
27650                         loader.setResponseType('arraybuffer');
27651                         loader.setRequestHeader(this.requestHeader);
27652                         loader.setPath(this.path);
27653                         loader.setWithCredentials(scope.withCredentials);
27654                         loader.load(url, function (buffer) {
27655                                 var texData = scope.parse(buffer);
27656                                 if (!texData) return;
27657
27658                                 if (texData.image !== undefined) {
27659                                         texture.image = texData.image;
27660                                 } else if (texData.data !== undefined) {
27661                                         texture.image.width = texData.width;
27662                                         texture.image.height = texData.height;
27663                                         texture.image.data = texData.data;
27664                                 }
27665
27666                                 texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
27667                                 texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
27668                                 texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
27669                                 texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
27670                                 texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
27671
27672                                 if (texData.format !== undefined) {
27673                                         texture.format = texData.format;
27674                                 }
27675
27676                                 if (texData.type !== undefined) {
27677                                         texture.type = texData.type;
27678                                 }
27679
27680                                 if (texData.mipmaps !== undefined) {
27681                                         texture.mipmaps = texData.mipmaps;
27682                                         texture.minFilter = LinearMipmapLinearFilter; // presumably...
27683                                 }
27684
27685                                 if (texData.mipmapCount === 1) {
27686                                         texture.minFilter = LinearFilter;
27687                                 }
27688
27689                                 texture.needsUpdate = true;
27690                                 if (onLoad) onLoad(texture, texData);
27691                         }, onProgress, onError);
27692                         return texture;
27693                 }
27694         });
27695
27696         function TextureLoader(manager) {
27697                 Loader.call(this, manager);
27698         }
27699
27700         TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
27701                 constructor: TextureLoader,
27702                 load: function load(url, onLoad, onProgress, onError) {
27703                         var texture = new Texture();
27704                         var loader = new ImageLoader(this.manager);
27705                         loader.setCrossOrigin(this.crossOrigin);
27706                         loader.setPath(this.path);
27707                         loader.load(url, function (image) {
27708                                 texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
27709
27710                                 var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
27711                                 texture.format = isJPEG ? RGBFormat : RGBAFormat;
27712                                 texture.needsUpdate = true;
27713
27714                                 if (onLoad !== undefined) {
27715                                         onLoad(texture);
27716                                 }
27717                         }, onProgress, onError);
27718                         return texture;
27719                 }
27720         });
27721
27722         /**
27723          * Extensible curve object.
27724          *
27725          * Some common of curve methods:
27726          * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
27727          * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
27728          * .getPoints(), .getSpacedPoints()
27729          * .getLength()
27730          * .updateArcLengths()
27731          *
27732          * This following curves inherit from THREE.Curve:
27733          *
27734          * -- 2D curves --
27735          * THREE.ArcCurve
27736          * THREE.CubicBezierCurve
27737          * THREE.EllipseCurve
27738          * THREE.LineCurve
27739          * THREE.QuadraticBezierCurve
27740          * THREE.SplineCurve
27741          *
27742          * -- 3D curves --
27743          * THREE.CatmullRomCurve3
27744          * THREE.CubicBezierCurve3
27745          * THREE.LineCurve3
27746          * THREE.QuadraticBezierCurve3
27747          *
27748          * A series of curves can be represented as a THREE.CurvePath.
27749          *
27750          **/
27751
27752         function Curve() {
27753                 this.type = 'Curve';
27754                 this.arcLengthDivisions = 200;
27755         }
27756
27757         Object.assign(Curve.prototype, {
27758                 // Virtual base class method to overwrite and implement in subclasses
27759                 //      - t [0 .. 1]
27760                 getPoint: function getPoint()
27761                 /* t, optionalTarget */
27762                 {
27763                         console.warn('THREE.Curve: .getPoint() not implemented.');
27764                         return null;
27765                 },
27766                 // Get point at relative position in curve according to arc length
27767                 // - u [0 .. 1]
27768                 getPointAt: function getPointAt(u, optionalTarget) {
27769                         var t = this.getUtoTmapping(u);
27770                         return this.getPoint(t, optionalTarget);
27771                 },
27772                 // Get sequence of points using getPoint( t )
27773                 getPoints: function getPoints(divisions) {
27774                         if (divisions === void 0) {
27775                                 divisions = 5;
27776                         }
27777
27778                         var points = [];
27779
27780                         for (var d = 0; d <= divisions; d++) {
27781                                 points.push(this.getPoint(d / divisions));
27782                         }
27783
27784                         return points;
27785                 },
27786                 // Get sequence of points using getPointAt( u )
27787                 getSpacedPoints: function getSpacedPoints(divisions) {
27788                         if (divisions === void 0) {
27789                                 divisions = 5;
27790                         }
27791
27792                         var points = [];
27793
27794                         for (var d = 0; d <= divisions; d++) {
27795                                 points.push(this.getPointAt(d / divisions));
27796                         }
27797
27798                         return points;
27799                 },
27800                 // Get total curve arc length
27801                 getLength: function getLength() {
27802                         var lengths = this.getLengths();
27803                         return lengths[lengths.length - 1];
27804                 },
27805                 // Get list of cumulative segment lengths
27806                 getLengths: function getLengths(divisions) {
27807                         if (divisions === undefined) divisions = this.arcLengthDivisions;
27808
27809                         if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
27810                                 return this.cacheArcLengths;
27811                         }
27812
27813                         this.needsUpdate = false;
27814                         var cache = [];
27815                         var current,
27816                                         last = this.getPoint(0);
27817                         var sum = 0;
27818                         cache.push(0);
27819
27820                         for (var p = 1; p <= divisions; p++) {
27821                                 current = this.getPoint(p / divisions);
27822                                 sum += current.distanceTo(last);
27823                                 cache.push(sum);
27824                                 last = current;
27825                         }
27826
27827                         this.cacheArcLengths = cache;
27828                         return cache; // { sums: cache, sum: sum }; Sum is in the last element.
27829                 },
27830                 updateArcLengths: function updateArcLengths() {
27831                         this.needsUpdate = true;
27832                         this.getLengths();
27833                 },
27834                 // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
27835                 getUtoTmapping: function getUtoTmapping(u, distance) {
27836                         var arcLengths = this.getLengths();
27837                         var i = 0;
27838                         var il = arcLengths.length;
27839                         var targetArcLength; // The targeted u distance value to get
27840
27841                         if (distance) {
27842                                 targetArcLength = distance;
27843                         } else {
27844                                 targetArcLength = u * arcLengths[il - 1];
27845                         } // binary search for the index with largest value smaller than target u distance
27846
27847
27848                         var low = 0,
27849                                         high = il - 1,
27850                                         comparison;
27851
27852                         while (low <= high) {
27853                                 i = Math.floor(low + (high - low) / 2); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
27854
27855                                 comparison = arcLengths[i] - targetArcLength;
27856
27857                                 if (comparison < 0) {
27858                                         low = i + 1;
27859                                 } else if (comparison > 0) {
27860                                         high = i - 1;
27861                                 } else {
27862                                         high = i;
27863                                         break; // DONE
27864                                 }
27865                         }
27866
27867                         i = high;
27868
27869                         if (arcLengths[i] === targetArcLength) {
27870                                 return i / (il - 1);
27871                         } // we could get finer grain at lengths, or use simple interpolation between two points
27872
27873
27874                         var lengthBefore = arcLengths[i];
27875                         var lengthAfter = arcLengths[i + 1];
27876                         var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
27877
27878                         var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
27879
27880                         var t = (i + segmentFraction) / (il - 1);
27881                         return t;
27882                 },
27883                 // Returns a unit vector tangent at t
27884                 // In case any sub curve does not implement its tangent derivation,
27885                 // 2 points a small delta apart will be used to find its gradient
27886                 // which seems to give a reasonable approximation
27887                 getTangent: function getTangent(t, optionalTarget) {
27888                         var delta = 0.0001;
27889                         var t1 = t - delta;
27890                         var t2 = t + delta; // Capping in case of danger
27891
27892                         if (t1 < 0) t1 = 0;
27893                         if (t2 > 1) t2 = 1;
27894                         var pt1 = this.getPoint(t1);
27895                         var pt2 = this.getPoint(t2);
27896                         var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
27897                         tangent.copy(pt2).sub(pt1).normalize();
27898                         return tangent;
27899                 },
27900                 getTangentAt: function getTangentAt(u, optionalTarget) {
27901                         var t = this.getUtoTmapping(u);
27902                         return this.getTangent(t, optionalTarget);
27903                 },
27904                 computeFrenetFrames: function computeFrenetFrames(segments, closed) {
27905                         // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
27906                         var normal = new Vector3();
27907                         var tangents = [];
27908                         var normals = [];
27909                         var binormals = [];
27910                         var vec = new Vector3();
27911                         var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
27912
27913                         for (var i = 0; i <= segments; i++) {
27914                                 var u = i / segments;
27915                                 tangents[i] = this.getTangentAt(u, new Vector3());
27916                                 tangents[i].normalize();
27917                         } // select an initial normal vector perpendicular to the first tangent vector,
27918                         // and in the direction of the minimum tangent xyz component
27919
27920
27921                         normals[0] = new Vector3();
27922                         binormals[0] = new Vector3();
27923                         var min = Number.MAX_VALUE;
27924                         var tx = Math.abs(tangents[0].x);
27925                         var ty = Math.abs(tangents[0].y);
27926                         var tz = Math.abs(tangents[0].z);
27927
27928                         if (tx <= min) {
27929                                 min = tx;
27930                                 normal.set(1, 0, 0);
27931                         }
27932
27933                         if (ty <= min) {
27934                                 min = ty;
27935                                 normal.set(0, 1, 0);
27936                         }
27937
27938                         if (tz <= min) {
27939                                 normal.set(0, 0, 1);
27940                         }
27941
27942                         vec.crossVectors(tangents[0], normal).normalize();
27943                         normals[0].crossVectors(tangents[0], vec);
27944                         binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
27945
27946                         for (var _i = 1; _i <= segments; _i++) {
27947                                 normals[_i] = normals[_i - 1].clone();
27948                                 binormals[_i] = binormals[_i - 1].clone();
27949                                 vec.crossVectors(tangents[_i - 1], tangents[_i]);
27950
27951                                 if (vec.length() > Number.EPSILON) {
27952                                         vec.normalize();
27953                                         var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
27954
27955                                         normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
27956                                 }
27957
27958                                 binormals[_i].crossVectors(tangents[_i], normals[_i]);
27959                         } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
27960
27961
27962                         if (closed === true) {
27963                                 var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
27964
27965                                 _theta /= segments;
27966
27967                                 if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
27968                                         _theta = -_theta;
27969                                 }
27970
27971                                 for (var _i2 = 1; _i2 <= segments; _i2++) {
27972                                         // twist a little...
27973                                         normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
27974
27975                                         binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
27976                                 }
27977                         }
27978
27979                         return {
27980                                 tangents: tangents,
27981                                 normals: normals,
27982                                 binormals: binormals
27983                         };
27984                 },
27985                 clone: function clone() {
27986                         return new this.constructor().copy(this);
27987                 },
27988                 copy: function copy(source) {
27989                         this.arcLengthDivisions = source.arcLengthDivisions;
27990                         return this;
27991                 },
27992                 toJSON: function toJSON() {
27993                         var data = {
27994                                 metadata: {
27995                                         version: 4.5,
27996                                         type: 'Curve',
27997                                         generator: 'Curve.toJSON'
27998                                 }
27999                         };
28000                         data.arcLengthDivisions = this.arcLengthDivisions;
28001                         data.type = this.type;
28002                         return data;
28003                 },
28004                 fromJSON: function fromJSON(json) {
28005                         this.arcLengthDivisions = json.arcLengthDivisions;
28006                         return this;
28007                 }
28008         });
28009
28010         function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
28011                 Curve.call(this);
28012                 this.type = 'EllipseCurve';
28013                 this.aX = aX || 0;
28014                 this.aY = aY || 0;
28015                 this.xRadius = xRadius || 1;
28016                 this.yRadius = yRadius || 1;
28017                 this.aStartAngle = aStartAngle || 0;
28018                 this.aEndAngle = aEndAngle || 2 * Math.PI;
28019                 this.aClockwise = aClockwise || false;
28020                 this.aRotation = aRotation || 0;
28021         }
28022
28023         EllipseCurve.prototype = Object.create(Curve.prototype);
28024         EllipseCurve.prototype.constructor = EllipseCurve;
28025         EllipseCurve.prototype.isEllipseCurve = true;
28026
28027         EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
28028                 var point = optionalTarget || new Vector2();
28029                 var twoPi = Math.PI * 2;
28030                 var deltaAngle = this.aEndAngle - this.aStartAngle;
28031                 var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
28032
28033                 while (deltaAngle < 0) {
28034                         deltaAngle += twoPi;
28035                 }
28036
28037                 while (deltaAngle > twoPi) {
28038                         deltaAngle -= twoPi;
28039                 }
28040
28041                 if (deltaAngle < Number.EPSILON) {
28042                         if (samePoints) {
28043                                 deltaAngle = 0;
28044                         } else {
28045                                 deltaAngle = twoPi;
28046                         }
28047                 }
28048
28049                 if (this.aClockwise === true && !samePoints) {
28050                         if (deltaAngle === twoPi) {
28051                                 deltaAngle = -twoPi;
28052                         } else {
28053                                 deltaAngle = deltaAngle - twoPi;
28054                         }
28055                 }
28056
28057                 var angle = this.aStartAngle + t * deltaAngle;
28058                 var x = this.aX + this.xRadius * Math.cos(angle);
28059                 var y = this.aY + this.yRadius * Math.sin(angle);
28060
28061                 if (this.aRotation !== 0) {
28062                         var cos = Math.cos(this.aRotation);
28063                         var sin = Math.sin(this.aRotation);
28064                         var tx = x - this.aX;
28065                         var ty = y - this.aY; // Rotate the point about the center of the ellipse.
28066
28067                         x = tx * cos - ty * sin + this.aX;
28068                         y = tx * sin + ty * cos + this.aY;
28069                 }
28070
28071                 return point.set(x, y);
28072         };
28073
28074         EllipseCurve.prototype.copy = function (source) {
28075                 Curve.prototype.copy.call(this, source);
28076                 this.aX = source.aX;
28077                 this.aY = source.aY;
28078                 this.xRadius = source.xRadius;
28079                 this.yRadius = source.yRadius;
28080                 this.aStartAngle = source.aStartAngle;
28081                 this.aEndAngle = source.aEndAngle;
28082                 this.aClockwise = source.aClockwise;
28083                 this.aRotation = source.aRotation;
28084                 return this;
28085         };
28086
28087         EllipseCurve.prototype.toJSON = function () {
28088                 var data = Curve.prototype.toJSON.call(this);
28089                 data.aX = this.aX;
28090                 data.aY = this.aY;
28091                 data.xRadius = this.xRadius;
28092                 data.yRadius = this.yRadius;
28093                 data.aStartAngle = this.aStartAngle;
28094                 data.aEndAngle = this.aEndAngle;
28095                 data.aClockwise = this.aClockwise;
28096                 data.aRotation = this.aRotation;
28097                 return data;
28098         };
28099
28100         EllipseCurve.prototype.fromJSON = function (json) {
28101                 Curve.prototype.fromJSON.call(this, json);
28102                 this.aX = json.aX;
28103                 this.aY = json.aY;
28104                 this.xRadius = json.xRadius;
28105                 this.yRadius = json.yRadius;
28106                 this.aStartAngle = json.aStartAngle;
28107                 this.aEndAngle = json.aEndAngle;
28108                 this.aClockwise = json.aClockwise;
28109                 this.aRotation = json.aRotation;
28110                 return this;
28111         };
28112
28113         function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
28114                 EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
28115                 this.type = 'ArcCurve';
28116         }
28117
28118         ArcCurve.prototype = Object.create(EllipseCurve.prototype);
28119         ArcCurve.prototype.constructor = ArcCurve;
28120         ArcCurve.prototype.isArcCurve = true;
28121
28122         /**
28123          * Centripetal CatmullRom Curve - which is useful for avoiding
28124          * cusps and self-intersections in non-uniform catmull rom curves.
28125          * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
28126          *
28127          * curve.type accepts centripetal(default), chordal and catmullrom
28128          * curve.tension is used for catmullrom which defaults to 0.5
28129          */
28130
28131         /*
28132         Based on an optimized c++ solution in
28133          - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
28134          - http://ideone.com/NoEbVM
28135
28136         This CubicPoly class could be used for reusing some variables and calculations,
28137         but for three.js curve use, it could be possible inlined and flatten into a single function call
28138         which can be placed in CurveUtils.
28139         */
28140
28141         function CubicPoly() {
28142                 var c0 = 0,
28143                                 c1 = 0,
28144                                 c2 = 0,
28145                                 c3 = 0;
28146                 /*
28147                  * Compute coefficients for a cubic polynomial
28148                  *       p(s) = c0 + c1*s + c2*s^2 + c3*s^3
28149                  * such that
28150                  *       p(0) = x0, p(1) = x1
28151                  *      and
28152                  *       p'(0) = t0, p'(1) = t1.
28153                  */
28154
28155                 function init(x0, x1, t0, t1) {
28156                         c0 = x0;
28157                         c1 = t0;
28158                         c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
28159                         c3 = 2 * x0 - 2 * x1 + t0 + t1;
28160                 }
28161
28162                 return {
28163                         initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
28164                                 init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
28165                         },
28166                         initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
28167                                 // compute tangents when parameterized in [t1,t2]
28168                                 var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
28169                                 var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
28170
28171                                 t1 *= dt1;
28172                                 t2 *= dt1;
28173                                 init(x1, x2, t1, t2);
28174                         },
28175                         calc: function calc(t) {
28176                                 var t2 = t * t;
28177                                 var t3 = t2 * t;
28178                                 return c0 + c1 * t + c2 * t2 + c3 * t3;
28179                         }
28180                 };
28181         } //
28182
28183
28184         var tmp = new Vector3();
28185         var px = new CubicPoly(),
28186                         py = new CubicPoly(),
28187                         pz = new CubicPoly();
28188
28189         function CatmullRomCurve3(points, closed, curveType, tension) {
28190                 if (points === void 0) {
28191                         points = [];
28192                 }
28193
28194                 if (closed === void 0) {
28195                         closed = false;
28196                 }
28197
28198                 if (curveType === void 0) {
28199                         curveType = 'centripetal';
28200                 }
28201
28202                 if (tension === void 0) {
28203                         tension = 0.5;
28204                 }
28205
28206                 Curve.call(this);
28207                 this.type = 'CatmullRomCurve3';
28208                 this.points = points;
28209                 this.closed = closed;
28210                 this.curveType = curveType;
28211                 this.tension = tension;
28212         }
28213
28214         CatmullRomCurve3.prototype = Object.create(Curve.prototype);
28215         CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
28216         CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
28217
28218         CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
28219                 if (optionalTarget === void 0) {
28220                         optionalTarget = new Vector3();
28221                 }
28222
28223                 var point = optionalTarget;
28224                 var points = this.points;
28225                 var l = points.length;
28226                 var p = (l - (this.closed ? 0 : 1)) * t;
28227                 var intPoint = Math.floor(p);
28228                 var weight = p - intPoint;
28229
28230                 if (this.closed) {
28231                         intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
28232                 } else if (weight === 0 && intPoint === l - 1) {
28233                         intPoint = l - 2;
28234                         weight = 1;
28235                 }
28236
28237                 var p0, p3; // 4 points (p1 & p2 defined below)
28238
28239                 if (this.closed || intPoint > 0) {
28240                         p0 = points[(intPoint - 1) % l];
28241                 } else {
28242                         // extrapolate first point
28243                         tmp.subVectors(points[0], points[1]).add(points[0]);
28244                         p0 = tmp;
28245                 }
28246
28247                 var p1 = points[intPoint % l];
28248                 var p2 = points[(intPoint + 1) % l];
28249
28250                 if (this.closed || intPoint + 2 < l) {
28251                         p3 = points[(intPoint + 2) % l];
28252                 } else {
28253                         // extrapolate last point
28254                         tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
28255                         p3 = tmp;
28256                 }
28257
28258                 if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
28259                         // init Centripetal / Chordal Catmull-Rom
28260                         var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
28261                         var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
28262                         var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
28263                         var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
28264
28265                         if (dt1 < 1e-4) dt1 = 1.0;
28266                         if (dt0 < 1e-4) dt0 = dt1;
28267                         if (dt2 < 1e-4) dt2 = dt1;
28268                         px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
28269                         py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
28270                         pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
28271                 } else if (this.curveType === 'catmullrom') {
28272                         px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
28273                         py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
28274                         pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
28275                 }
28276
28277                 point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
28278                 return point;
28279         };
28280
28281         CatmullRomCurve3.prototype.copy = function (source) {
28282                 Curve.prototype.copy.call(this, source);
28283                 this.points = [];
28284
28285                 for (var i = 0, l = source.points.length; i < l; i++) {
28286                         var point = source.points[i];
28287                         this.points.push(point.clone());
28288                 }
28289
28290                 this.closed = source.closed;
28291                 this.curveType = source.curveType;
28292                 this.tension = source.tension;
28293                 return this;
28294         };
28295
28296         CatmullRomCurve3.prototype.toJSON = function () {
28297                 var data = Curve.prototype.toJSON.call(this);
28298                 data.points = [];
28299
28300                 for (var i = 0, l = this.points.length; i < l; i++) {
28301                         var point = this.points[i];
28302                         data.points.push(point.toArray());
28303                 }
28304
28305                 data.closed = this.closed;
28306                 data.curveType = this.curveType;
28307                 data.tension = this.tension;
28308                 return data;
28309         };
28310
28311         CatmullRomCurve3.prototype.fromJSON = function (json) {
28312                 Curve.prototype.fromJSON.call(this, json);
28313                 this.points = [];
28314
28315                 for (var i = 0, l = json.points.length; i < l; i++) {
28316                         var point = json.points[i];
28317                         this.points.push(new Vector3().fromArray(point));
28318                 }
28319
28320                 this.closed = json.closed;
28321                 this.curveType = json.curveType;
28322                 this.tension = json.tension;
28323                 return this;
28324         };
28325
28326         /**
28327          * Bezier Curves formulas obtained from
28328          * http://en.wikipedia.org/wiki/Bézier_curve
28329          */
28330         function CatmullRom(t, p0, p1, p2, p3) {
28331                 var v0 = (p2 - p0) * 0.5;
28332                 var v1 = (p3 - p1) * 0.5;
28333                 var t2 = t * t;
28334                 var t3 = t * t2;
28335                 return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
28336         } //
28337
28338
28339         function QuadraticBezierP0(t, p) {
28340                 var k = 1 - t;
28341                 return k * k * p;
28342         }
28343
28344         function QuadraticBezierP1(t, p) {
28345                 return 2 * (1 - t) * t * p;
28346         }
28347
28348         function QuadraticBezierP2(t, p) {
28349                 return t * t * p;
28350         }
28351
28352         function QuadraticBezier(t, p0, p1, p2) {
28353                 return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
28354         } //
28355
28356
28357         function CubicBezierP0(t, p) {
28358                 var k = 1 - t;
28359                 return k * k * k * p;
28360         }
28361
28362         function CubicBezierP1(t, p) {
28363                 var k = 1 - t;
28364                 return 3 * k * k * t * p;
28365         }
28366
28367         function CubicBezierP2(t, p) {
28368                 return 3 * (1 - t) * t * t * p;
28369         }
28370
28371         function CubicBezierP3(t, p) {
28372                 return t * t * t * p;
28373         }
28374
28375         function CubicBezier(t, p0, p1, p2, p3) {
28376                 return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
28377         }
28378
28379         function CubicBezierCurve(v0, v1, v2, v3) {
28380                 if (v0 === void 0) {
28381                         v0 = new Vector2();
28382                 }
28383
28384                 if (v1 === void 0) {
28385                         v1 = new Vector2();
28386                 }
28387
28388                 if (v2 === void 0) {
28389                         v2 = new Vector2();
28390                 }
28391
28392                 if (v3 === void 0) {
28393                         v3 = new Vector2();
28394                 }
28395
28396                 Curve.call(this);
28397                 this.type = 'CubicBezierCurve';
28398                 this.v0 = v0;
28399                 this.v1 = v1;
28400                 this.v2 = v2;
28401                 this.v3 = v3;
28402         }
28403
28404         CubicBezierCurve.prototype = Object.create(Curve.prototype);
28405         CubicBezierCurve.prototype.constructor = CubicBezierCurve;
28406         CubicBezierCurve.prototype.isCubicBezierCurve = true;
28407
28408         CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
28409                 if (optionalTarget === void 0) {
28410                         optionalTarget = new Vector2();
28411                 }
28412
28413                 var point = optionalTarget;
28414                 var v0 = this.v0,
28415                                 v1 = this.v1,
28416                                 v2 = this.v2,
28417                                 v3 = this.v3;
28418                 point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
28419                 return point;
28420         };
28421
28422         CubicBezierCurve.prototype.copy = function (source) {
28423                 Curve.prototype.copy.call(this, source);
28424                 this.v0.copy(source.v0);
28425                 this.v1.copy(source.v1);
28426                 this.v2.copy(source.v2);
28427                 this.v3.copy(source.v3);
28428                 return this;
28429         };
28430
28431         CubicBezierCurve.prototype.toJSON = function () {
28432                 var data = Curve.prototype.toJSON.call(this);
28433                 data.v0 = this.v0.toArray();
28434                 data.v1 = this.v1.toArray();
28435                 data.v2 = this.v2.toArray();
28436                 data.v3 = this.v3.toArray();
28437                 return data;
28438         };
28439
28440         CubicBezierCurve.prototype.fromJSON = function (json) {
28441                 Curve.prototype.fromJSON.call(this, json);
28442                 this.v0.fromArray(json.v0);
28443                 this.v1.fromArray(json.v1);
28444                 this.v2.fromArray(json.v2);
28445                 this.v3.fromArray(json.v3);
28446                 return this;
28447         };
28448
28449         function CubicBezierCurve3(v0, v1, v2, v3) {
28450                 if (v0 === void 0) {
28451                         v0 = new Vector3();
28452                 }
28453
28454                 if (v1 === void 0) {
28455                         v1 = new Vector3();
28456                 }
28457
28458                 if (v2 === void 0) {
28459                         v2 = new Vector3();
28460                 }
28461
28462                 if (v3 === void 0) {
28463                         v3 = new Vector3();
28464                 }
28465
28466                 Curve.call(this);
28467                 this.type = 'CubicBezierCurve3';
28468                 this.v0 = v0;
28469                 this.v1 = v1;
28470                 this.v2 = v2;
28471                 this.v3 = v3;
28472         }
28473
28474         CubicBezierCurve3.prototype = Object.create(Curve.prototype);
28475         CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
28476         CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
28477
28478         CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
28479                 if (optionalTarget === void 0) {
28480                         optionalTarget = new Vector3();
28481                 }
28482
28483                 var point = optionalTarget;
28484                 var v0 = this.v0,
28485                                 v1 = this.v1,
28486                                 v2 = this.v2,
28487                                 v3 = this.v3;
28488                 point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y), CubicBezier(t, v0.z, v1.z, v2.z, v3.z));
28489                 return point;
28490         };
28491
28492         CubicBezierCurve3.prototype.copy = function (source) {
28493                 Curve.prototype.copy.call(this, source);
28494                 this.v0.copy(source.v0);
28495                 this.v1.copy(source.v1);
28496                 this.v2.copy(source.v2);
28497                 this.v3.copy(source.v3);
28498                 return this;
28499         };
28500
28501         CubicBezierCurve3.prototype.toJSON = function () {
28502                 var data = Curve.prototype.toJSON.call(this);
28503                 data.v0 = this.v0.toArray();
28504                 data.v1 = this.v1.toArray();
28505                 data.v2 = this.v2.toArray();
28506                 data.v3 = this.v3.toArray();
28507                 return data;
28508         };
28509
28510         CubicBezierCurve3.prototype.fromJSON = function (json) {
28511                 Curve.prototype.fromJSON.call(this, json);
28512                 this.v0.fromArray(json.v0);
28513                 this.v1.fromArray(json.v1);
28514                 this.v2.fromArray(json.v2);
28515                 this.v3.fromArray(json.v3);
28516                 return this;
28517         };
28518
28519         function LineCurve(v1, v2) {
28520                 if (v1 === void 0) {
28521                         v1 = new Vector2();
28522                 }
28523
28524                 if (v2 === void 0) {
28525                         v2 = new Vector2();
28526                 }
28527
28528                 Curve.call(this);
28529                 this.type = 'LineCurve';
28530                 this.v1 = v1;
28531                 this.v2 = v2;
28532         }
28533
28534         LineCurve.prototype = Object.create(Curve.prototype);
28535         LineCurve.prototype.constructor = LineCurve;
28536         LineCurve.prototype.isLineCurve = true;
28537
28538         LineCurve.prototype.getPoint = function (t, optionalTarget) {
28539                 if (optionalTarget === void 0) {
28540                         optionalTarget = new Vector2();
28541                 }
28542
28543                 var point = optionalTarget;
28544
28545                 if (t === 1) {
28546                         point.copy(this.v2);
28547                 } else {
28548                         point.copy(this.v2).sub(this.v1);
28549                         point.multiplyScalar(t).add(this.v1);
28550                 }
28551
28552                 return point;
28553         }; // Line curve is linear, so we can overwrite default getPointAt
28554
28555
28556         LineCurve.prototype.getPointAt = function (u, optionalTarget) {
28557                 return this.getPoint(u, optionalTarget);
28558         };
28559
28560         LineCurve.prototype.getTangent = function (t, optionalTarget) {
28561                 var tangent = optionalTarget || new Vector2();
28562                 tangent.copy(this.v2).sub(this.v1).normalize();
28563                 return tangent;
28564         };
28565
28566         LineCurve.prototype.copy = function (source) {
28567                 Curve.prototype.copy.call(this, source);
28568                 this.v1.copy(source.v1);
28569                 this.v2.copy(source.v2);
28570                 return this;
28571         };
28572
28573         LineCurve.prototype.toJSON = function () {
28574                 var data = Curve.prototype.toJSON.call(this);
28575                 data.v1 = this.v1.toArray();
28576                 data.v2 = this.v2.toArray();
28577                 return data;
28578         };
28579
28580         LineCurve.prototype.fromJSON = function (json) {
28581                 Curve.prototype.fromJSON.call(this, json);
28582                 this.v1.fromArray(json.v1);
28583                 this.v2.fromArray(json.v2);
28584                 return this;
28585         };
28586
28587         function LineCurve3(v1, v2) {
28588                 if (v1 === void 0) {
28589                         v1 = new Vector3();
28590                 }
28591
28592                 if (v2 === void 0) {
28593                         v2 = new Vector3();
28594                 }
28595
28596                 Curve.call(this);
28597                 this.type = 'LineCurve3';
28598                 this.v1 = v1;
28599                 this.v2 = v2;
28600         }
28601
28602         LineCurve3.prototype = Object.create(Curve.prototype);
28603         LineCurve3.prototype.constructor = LineCurve3;
28604         LineCurve3.prototype.isLineCurve3 = true;
28605
28606         LineCurve3.prototype.getPoint = function (t, optionalTarget) {
28607                 if (optionalTarget === void 0) {
28608                         optionalTarget = new Vector3();
28609                 }
28610
28611                 var point = optionalTarget;
28612
28613                 if (t === 1) {
28614                         point.copy(this.v2);
28615                 } else {
28616                         point.copy(this.v2).sub(this.v1);
28617                         point.multiplyScalar(t).add(this.v1);
28618                 }
28619
28620                 return point;
28621         }; // Line curve is linear, so we can overwrite default getPointAt
28622
28623
28624         LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
28625                 return this.getPoint(u, optionalTarget);
28626         };
28627
28628         LineCurve3.prototype.copy = function (source) {
28629                 Curve.prototype.copy.call(this, source);
28630                 this.v1.copy(source.v1);
28631                 this.v2.copy(source.v2);
28632                 return this;
28633         };
28634
28635         LineCurve3.prototype.toJSON = function () {
28636                 var data = Curve.prototype.toJSON.call(this);
28637                 data.v1 = this.v1.toArray();
28638                 data.v2 = this.v2.toArray();
28639                 return data;
28640         };
28641
28642         LineCurve3.prototype.fromJSON = function (json) {
28643                 Curve.prototype.fromJSON.call(this, json);
28644                 this.v1.fromArray(json.v1);
28645                 this.v2.fromArray(json.v2);
28646                 return this;
28647         };
28648
28649         function QuadraticBezierCurve(v0, v1, v2) {
28650                 if (v0 === void 0) {
28651                         v0 = new Vector2();
28652                 }
28653
28654                 if (v1 === void 0) {
28655                         v1 = new Vector2();
28656                 }
28657
28658                 if (v2 === void 0) {
28659                         v2 = new Vector2();
28660                 }
28661
28662                 Curve.call(this);
28663                 this.type = 'QuadraticBezierCurve';
28664                 this.v0 = v0;
28665                 this.v1 = v1;
28666                 this.v2 = v2;
28667         }
28668
28669         QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
28670         QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
28671         QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
28672
28673         QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
28674                 if (optionalTarget === void 0) {
28675                         optionalTarget = new Vector2();
28676                 }
28677
28678                 var point = optionalTarget;
28679                 var v0 = this.v0,
28680                                 v1 = this.v1,
28681                                 v2 = this.v2;
28682                 point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
28683                 return point;
28684         };
28685
28686         QuadraticBezierCurve.prototype.copy = function (source) {
28687                 Curve.prototype.copy.call(this, source);
28688                 this.v0.copy(source.v0);
28689                 this.v1.copy(source.v1);
28690                 this.v2.copy(source.v2);
28691                 return this;
28692         };
28693
28694         QuadraticBezierCurve.prototype.toJSON = function () {
28695                 var data = Curve.prototype.toJSON.call(this);
28696                 data.v0 = this.v0.toArray();
28697                 data.v1 = this.v1.toArray();
28698                 data.v2 = this.v2.toArray();
28699                 return data;
28700         };
28701
28702         QuadraticBezierCurve.prototype.fromJSON = function (json) {
28703                 Curve.prototype.fromJSON.call(this, json);
28704                 this.v0.fromArray(json.v0);
28705                 this.v1.fromArray(json.v1);
28706                 this.v2.fromArray(json.v2);
28707                 return this;
28708         };
28709
28710         function QuadraticBezierCurve3(v0, v1, v2) {
28711                 if (v0 === void 0) {
28712                         v0 = new Vector3();
28713                 }
28714
28715                 if (v1 === void 0) {
28716                         v1 = new Vector3();
28717                 }
28718
28719                 if (v2 === void 0) {
28720                         v2 = new Vector3();
28721                 }
28722
28723                 Curve.call(this);
28724                 this.type = 'QuadraticBezierCurve3';
28725                 this.v0 = v0;
28726                 this.v1 = v1;
28727                 this.v2 = v2;
28728         }
28729
28730         QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
28731         QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
28732         QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
28733
28734         QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
28735                 if (optionalTarget === void 0) {
28736                         optionalTarget = new Vector3();
28737                 }
28738
28739                 var point = optionalTarget;
28740                 var v0 = this.v0,
28741                                 v1 = this.v1,
28742                                 v2 = this.v2;
28743                 point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y), QuadraticBezier(t, v0.z, v1.z, v2.z));
28744                 return point;
28745         };
28746
28747         QuadraticBezierCurve3.prototype.copy = function (source) {
28748                 Curve.prototype.copy.call(this, source);
28749                 this.v0.copy(source.v0);
28750                 this.v1.copy(source.v1);
28751                 this.v2.copy(source.v2);
28752                 return this;
28753         };
28754
28755         QuadraticBezierCurve3.prototype.toJSON = function () {
28756                 var data = Curve.prototype.toJSON.call(this);
28757                 data.v0 = this.v0.toArray();
28758                 data.v1 = this.v1.toArray();
28759                 data.v2 = this.v2.toArray();
28760                 return data;
28761         };
28762
28763         QuadraticBezierCurve3.prototype.fromJSON = function (json) {
28764                 Curve.prototype.fromJSON.call(this, json);
28765                 this.v0.fromArray(json.v0);
28766                 this.v1.fromArray(json.v1);
28767                 this.v2.fromArray(json.v2);
28768                 return this;
28769         };
28770
28771         function SplineCurve(points) {
28772                 if (points === void 0) {
28773                         points = [];
28774                 }
28775
28776                 Curve.call(this);
28777                 this.type = 'SplineCurve';
28778                 this.points = points;
28779         }
28780
28781         SplineCurve.prototype = Object.create(Curve.prototype);
28782         SplineCurve.prototype.constructor = SplineCurve;
28783         SplineCurve.prototype.isSplineCurve = true;
28784
28785         SplineCurve.prototype.getPoint = function (t, optionalTarget) {
28786                 if (optionalTarget === void 0) {
28787                         optionalTarget = new Vector2();
28788                 }
28789
28790                 var point = optionalTarget;
28791                 var points = this.points;
28792                 var p = (points.length - 1) * t;
28793                 var intPoint = Math.floor(p);
28794                 var weight = p - intPoint;
28795                 var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
28796                 var p1 = points[intPoint];
28797                 var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
28798                 var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
28799                 point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
28800                 return point;
28801         };
28802
28803         SplineCurve.prototype.copy = function (source) {
28804                 Curve.prototype.copy.call(this, source);
28805                 this.points = [];
28806
28807                 for (var i = 0, l = source.points.length; i < l; i++) {
28808                         var point = source.points[i];
28809                         this.points.push(point.clone());
28810                 }
28811
28812                 return this;
28813         };
28814
28815         SplineCurve.prototype.toJSON = function () {
28816                 var data = Curve.prototype.toJSON.call(this);
28817                 data.points = [];
28818
28819                 for (var i = 0, l = this.points.length; i < l; i++) {
28820                         var point = this.points[i];
28821                         data.points.push(point.toArray());
28822                 }
28823
28824                 return data;
28825         };
28826
28827         SplineCurve.prototype.fromJSON = function (json) {
28828                 Curve.prototype.fromJSON.call(this, json);
28829                 this.points = [];
28830
28831                 for (var i = 0, l = json.points.length; i < l; i++) {
28832                         var point = json.points[i];
28833                         this.points.push(new Vector2().fromArray(point));
28834                 }
28835
28836                 return this;
28837         };
28838
28839         var Curves = /*#__PURE__*/Object.freeze({
28840                 __proto__: null,
28841                 ArcCurve: ArcCurve,
28842                 CatmullRomCurve3: CatmullRomCurve3,
28843                 CubicBezierCurve: CubicBezierCurve,
28844                 CubicBezierCurve3: CubicBezierCurve3,
28845                 EllipseCurve: EllipseCurve,
28846                 LineCurve: LineCurve,
28847                 LineCurve3: LineCurve3,
28848                 QuadraticBezierCurve: QuadraticBezierCurve,
28849                 QuadraticBezierCurve3: QuadraticBezierCurve3,
28850                 SplineCurve: SplineCurve
28851         });
28852
28853         /**************************************************************
28854          *      Curved Path - a curve path is simply a array of connected
28855          *      curves, but retains the api of a curve
28856          **************************************************************/
28857
28858         function CurvePath() {
28859                 Curve.call(this);
28860                 this.type = 'CurvePath';
28861                 this.curves = [];
28862                 this.autoClose = false; // Automatically closes the path
28863         }
28864
28865         CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
28866                 constructor: CurvePath,
28867                 add: function add(curve) {
28868                         this.curves.push(curve);
28869                 },
28870                 closePath: function closePath() {
28871                         // Add a line curve if start and end of lines are not connected
28872                         var startPoint = this.curves[0].getPoint(0);
28873                         var endPoint = this.curves[this.curves.length - 1].getPoint(1);
28874
28875                         if (!startPoint.equals(endPoint)) {
28876                                 this.curves.push(new LineCurve(endPoint, startPoint));
28877                         }
28878                 },
28879                 // To get accurate point with reference to
28880                 // entire path distance at time t,
28881                 // following has to be done:
28882                 // 1. Length of each sub path have to be known
28883                 // 2. Locate and identify type of curve
28884                 // 3. Get t for the curve
28885                 // 4. Return curve.getPointAt(t')
28886                 getPoint: function getPoint(t) {
28887                         var d = t * this.getLength();
28888                         var curveLengths = this.getCurveLengths();
28889                         var i = 0; // To think about boundaries points.
28890
28891                         while (i < curveLengths.length) {
28892                                 if (curveLengths[i] >= d) {
28893                                         var diff = curveLengths[i] - d;
28894                                         var curve = this.curves[i];
28895                                         var segmentLength = curve.getLength();
28896                                         var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
28897                                         return curve.getPointAt(u);
28898                                 }
28899
28900                                 i++;
28901                         }
28902
28903                         return null; // loop where sum != 0, sum > d , sum+1 <d
28904                 },
28905                 // We cannot use the default THREE.Curve getPoint() with getLength() because in
28906                 // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
28907                 // getPoint() depends on getLength
28908                 getLength: function getLength() {
28909                         var lens = this.getCurveLengths();
28910                         return lens[lens.length - 1];
28911                 },
28912                 // cacheLengths must be recalculated.
28913                 updateArcLengths: function updateArcLengths() {
28914                         this.needsUpdate = true;
28915                         this.cacheLengths = null;
28916                         this.getCurveLengths();
28917                 },
28918                 // Compute lengths and cache them
28919                 // We cannot overwrite getLengths() because UtoT mapping uses it.
28920                 getCurveLengths: function getCurveLengths() {
28921                         // We use cache values if curves and cache array are same length
28922                         if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
28923                                 return this.cacheLengths;
28924                         } // Get length of sub-curve
28925                         // Push sums into cached array
28926
28927
28928                         var lengths = [];
28929                         var sums = 0;
28930
28931                         for (var i = 0, l = this.curves.length; i < l; i++) {
28932                                 sums += this.curves[i].getLength();
28933                                 lengths.push(sums);
28934                         }
28935
28936                         this.cacheLengths = lengths;
28937                         return lengths;
28938                 },
28939                 getSpacedPoints: function getSpacedPoints(divisions) {
28940                         if (divisions === void 0) {
28941                                 divisions = 40;
28942                         }
28943
28944                         var points = [];
28945
28946                         for (var i = 0; i <= divisions; i++) {
28947                                 points.push(this.getPoint(i / divisions));
28948                         }
28949
28950                         if (this.autoClose) {
28951                                 points.push(points[0]);
28952                         }
28953
28954                         return points;
28955                 },
28956                 getPoints: function getPoints(divisions) {
28957                         if (divisions === void 0) {
28958                                 divisions = 12;
28959                         }
28960
28961                         var points = [];
28962                         var last;
28963
28964                         for (var i = 0, curves = this.curves; i < curves.length; i++) {
28965                                 var curve = curves[i];
28966                                 var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
28967                                 var pts = curve.getPoints(resolution);
28968
28969                                 for (var j = 0; j < pts.length; j++) {
28970                                         var point = pts[j];
28971                                         if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
28972
28973                                         points.push(point);
28974                                         last = point;
28975                                 }
28976                         }
28977
28978                         if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
28979                                 points.push(points[0]);
28980                         }
28981
28982                         return points;
28983                 },
28984                 copy: function copy(source) {
28985                         Curve.prototype.copy.call(this, source);
28986                         this.curves = [];
28987
28988                         for (var i = 0, l = source.curves.length; i < l; i++) {
28989                                 var curve = source.curves[i];
28990                                 this.curves.push(curve.clone());
28991                         }
28992
28993                         this.autoClose = source.autoClose;
28994                         return this;
28995                 },
28996                 toJSON: function toJSON() {
28997                         var data = Curve.prototype.toJSON.call(this);
28998                         data.autoClose = this.autoClose;
28999                         data.curves = [];
29000
29001                         for (var i = 0, l = this.curves.length; i < l; i++) {
29002                                 var curve = this.curves[i];
29003                                 data.curves.push(curve.toJSON());
29004                         }
29005
29006                         return data;
29007                 },
29008                 fromJSON: function fromJSON(json) {
29009                         Curve.prototype.fromJSON.call(this, json);
29010                         this.autoClose = json.autoClose;
29011                         this.curves = [];
29012
29013                         for (var i = 0, l = json.curves.length; i < l; i++) {
29014                                 var curve = json.curves[i];
29015                                 this.curves.push(new Curves[curve.type]().fromJSON(curve));
29016                         }
29017
29018                         return this;
29019                 }
29020         });
29021
29022         function Path(points) {
29023                 CurvePath.call(this);
29024                 this.type = 'Path';
29025                 this.currentPoint = new Vector2();
29026
29027                 if (points) {
29028                         this.setFromPoints(points);
29029                 }
29030         }
29031
29032         Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
29033                 constructor: Path,
29034                 setFromPoints: function setFromPoints(points) {
29035                         this.moveTo(points[0].x, points[0].y);
29036
29037                         for (var i = 1, l = points.length; i < l; i++) {
29038                                 this.lineTo(points[i].x, points[i].y);
29039                         }
29040
29041                         return this;
29042                 },
29043                 moveTo: function moveTo(x, y) {
29044                         this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
29045
29046                         return this;
29047                 },
29048                 lineTo: function lineTo(x, y) {
29049                         var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
29050                         this.curves.push(curve);
29051                         this.currentPoint.set(x, y);
29052                         return this;
29053                 },
29054                 quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
29055                         var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
29056                         this.curves.push(curve);
29057                         this.currentPoint.set(aX, aY);
29058                         return this;
29059                 },
29060                 bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
29061                         var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
29062                         this.curves.push(curve);
29063                         this.currentPoint.set(aX, aY);
29064                         return this;
29065                 },
29066                 splineThru: function splineThru(pts
29067                 /*Array of Vector*/
29068                 ) {
29069                         var npts = [this.currentPoint.clone()].concat(pts);
29070                         var curve = new SplineCurve(npts);
29071                         this.curves.push(curve);
29072                         this.currentPoint.copy(pts[pts.length - 1]);
29073                         return this;
29074                 },
29075                 arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
29076                         var x0 = this.currentPoint.x;
29077                         var y0 = this.currentPoint.y;
29078                         this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
29079                         return this;
29080                 },
29081                 absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
29082                         this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
29083                         return this;
29084                 },
29085                 ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
29086                         var x0 = this.currentPoint.x;
29087                         var y0 = this.currentPoint.y;
29088                         this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
29089                         return this;
29090                 },
29091                 absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
29092                         var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
29093
29094                         if (this.curves.length > 0) {
29095                                 // if a previous curve is present, attempt to join
29096                                 var firstPoint = curve.getPoint(0);
29097
29098                                 if (!firstPoint.equals(this.currentPoint)) {
29099                                         this.lineTo(firstPoint.x, firstPoint.y);
29100                                 }
29101                         }
29102
29103                         this.curves.push(curve);
29104                         var lastPoint = curve.getPoint(1);
29105                         this.currentPoint.copy(lastPoint);
29106                         return this;
29107                 },
29108                 copy: function copy(source) {
29109                         CurvePath.prototype.copy.call(this, source);
29110                         this.currentPoint.copy(source.currentPoint);
29111                         return this;
29112                 },
29113                 toJSON: function toJSON() {
29114                         var data = CurvePath.prototype.toJSON.call(this);
29115                         data.currentPoint = this.currentPoint.toArray();
29116                         return data;
29117                 },
29118                 fromJSON: function fromJSON(json) {
29119                         CurvePath.prototype.fromJSON.call(this, json);
29120                         this.currentPoint.fromArray(json.currentPoint);
29121                         return this;
29122                 }
29123         });
29124
29125         function Shape(points) {
29126                 Path.call(this, points);
29127                 this.uuid = MathUtils.generateUUID();
29128                 this.type = 'Shape';
29129                 this.holes = [];
29130         }
29131
29132         Shape.prototype = Object.assign(Object.create(Path.prototype), {
29133                 constructor: Shape,
29134                 getPointsHoles: function getPointsHoles(divisions) {
29135                         var holesPts = [];
29136
29137                         for (var i = 0, l = this.holes.length; i < l; i++) {
29138                                 holesPts[i] = this.holes[i].getPoints(divisions);
29139                         }
29140
29141                         return holesPts;
29142                 },
29143                 // get points of shape and holes (keypoints based on segments parameter)
29144                 extractPoints: function extractPoints(divisions) {
29145                         return {
29146                                 shape: this.getPoints(divisions),
29147                                 holes: this.getPointsHoles(divisions)
29148                         };
29149                 },
29150                 copy: function copy(source) {
29151                         Path.prototype.copy.call(this, source);
29152                         this.holes = [];
29153
29154                         for (var i = 0, l = source.holes.length; i < l; i++) {
29155                                 var hole = source.holes[i];
29156                                 this.holes.push(hole.clone());
29157                         }
29158
29159                         return this;
29160                 },
29161                 toJSON: function toJSON() {
29162                         var data = Path.prototype.toJSON.call(this);
29163                         data.uuid = this.uuid;
29164                         data.holes = [];
29165
29166                         for (var i = 0, l = this.holes.length; i < l; i++) {
29167                                 var hole = this.holes[i];
29168                                 data.holes.push(hole.toJSON());
29169                         }
29170
29171                         return data;
29172                 },
29173                 fromJSON: function fromJSON(json) {
29174                         Path.prototype.fromJSON.call(this, json);
29175                         this.uuid = json.uuid;
29176                         this.holes = [];
29177
29178                         for (var i = 0, l = json.holes.length; i < l; i++) {
29179                                 var hole = json.holes[i];
29180                                 this.holes.push(new Path().fromJSON(hole));
29181                         }
29182
29183                         return this;
29184                 }
29185         });
29186
29187         function Light(color, intensity) {
29188                 if (intensity === void 0) {
29189                         intensity = 1;
29190                 }
29191
29192                 Object3D.call(this);
29193                 this.type = 'Light';
29194                 this.color = new Color(color);
29195                 this.intensity = intensity;
29196         }
29197
29198         Light.prototype = Object.assign(Object.create(Object3D.prototype), {
29199                 constructor: Light,
29200                 isLight: true,
29201                 copy: function copy(source) {
29202                         Object3D.prototype.copy.call(this, source);
29203                         this.color.copy(source.color);
29204                         this.intensity = source.intensity;
29205                         return this;
29206                 },
29207                 toJSON: function toJSON(meta) {
29208                         var data = Object3D.prototype.toJSON.call(this, meta);
29209                         data.object.color = this.color.getHex();
29210                         data.object.intensity = this.intensity;
29211                         if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
29212                         if (this.distance !== undefined) data.object.distance = this.distance;
29213                         if (this.angle !== undefined) data.object.angle = this.angle;
29214                         if (this.decay !== undefined) data.object.decay = this.decay;
29215                         if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
29216                         if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
29217                         return data;
29218                 }
29219         });
29220
29221         function HemisphereLight(skyColor, groundColor, intensity) {
29222                 Light.call(this, skyColor, intensity);
29223                 this.type = 'HemisphereLight';
29224                 this.position.copy(Object3D.DefaultUp);
29225                 this.updateMatrix();
29226                 this.groundColor = new Color(groundColor);
29227         }
29228
29229         HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
29230                 constructor: HemisphereLight,
29231                 isHemisphereLight: true,
29232                 copy: function copy(source) {
29233                         Light.prototype.copy.call(this, source);
29234                         this.groundColor.copy(source.groundColor);
29235                         return this;
29236                 }
29237         });
29238
29239         function LightShadow(camera) {
29240                 this.camera = camera;
29241                 this.bias = 0;
29242                 this.normalBias = 0;
29243                 this.radius = 1;
29244                 this.mapSize = new Vector2(512, 512);
29245                 this.map = null;
29246                 this.mapPass = null;
29247                 this.matrix = new Matrix4();
29248                 this.autoUpdate = true;
29249                 this.needsUpdate = false;
29250                 this._frustum = new Frustum();
29251                 this._frameExtents = new Vector2(1, 1);
29252                 this._viewportCount = 1;
29253                 this._viewports = [new Vector4(0, 0, 1, 1)];
29254         }
29255
29256         Object.assign(LightShadow.prototype, {
29257                 _projScreenMatrix: new Matrix4(),
29258                 _lightPositionWorld: new Vector3(),
29259                 _lookTarget: new Vector3(),
29260                 getViewportCount: function getViewportCount() {
29261                         return this._viewportCount;
29262                 },
29263                 getFrustum: function getFrustum() {
29264                         return this._frustum;
29265                 },
29266                 updateMatrices: function updateMatrices(light) {
29267                         var shadowCamera = this.camera,
29268                                         shadowMatrix = this.matrix,
29269                                         projScreenMatrix = this._projScreenMatrix,
29270                                         lookTarget = this._lookTarget,
29271                                         lightPositionWorld = this._lightPositionWorld;
29272                         lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
29273                         shadowCamera.position.copy(lightPositionWorld);
29274                         lookTarget.setFromMatrixPosition(light.target.matrixWorld);
29275                         shadowCamera.lookAt(lookTarget);
29276                         shadowCamera.updateMatrixWorld();
29277                         projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
29278
29279                         this._frustum.setFromProjectionMatrix(projScreenMatrix);
29280
29281                         shadowMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
29282                         shadowMatrix.multiply(shadowCamera.projectionMatrix);
29283                         shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
29284                 },
29285                 getViewport: function getViewport(viewportIndex) {
29286                         return this._viewports[viewportIndex];
29287                 },
29288                 getFrameExtents: function getFrameExtents() {
29289                         return this._frameExtents;
29290                 },
29291                 copy: function copy(source) {
29292                         this.camera = source.camera.clone();
29293                         this.bias = source.bias;
29294                         this.radius = source.radius;
29295                         this.mapSize.copy(source.mapSize);
29296                         return this;
29297                 },
29298                 clone: function clone() {
29299                         return new this.constructor().copy(this);
29300                 },
29301                 toJSON: function toJSON() {
29302                         var object = {};
29303                         if (this.bias !== 0) object.bias = this.bias;
29304                         if (this.normalBias !== 0) object.normalBias = this.normalBias;
29305                         if (this.radius !== 1) object.radius = this.radius;
29306                         if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
29307                         object.camera = this.camera.toJSON(false).object;
29308                         delete object.camera.matrix;
29309                         return object;
29310                 }
29311         });
29312
29313         function SpotLightShadow() {
29314                 LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
29315                 this.focus = 1;
29316         }
29317
29318         SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
29319                 constructor: SpotLightShadow,
29320                 isSpotLightShadow: true,
29321                 updateMatrices: function updateMatrices(light) {
29322                         var camera = this.camera;
29323                         var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
29324                         var aspect = this.mapSize.width / this.mapSize.height;
29325                         var far = light.distance || camera.far;
29326
29327                         if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
29328                                 camera.fov = fov;
29329                                 camera.aspect = aspect;
29330                                 camera.far = far;
29331                                 camera.updateProjectionMatrix();
29332                         }
29333
29334                         LightShadow.prototype.updateMatrices.call(this, light);
29335                 }
29336         });
29337
29338         function SpotLight(color, intensity, distance, angle, penumbra, decay) {
29339                 Light.call(this, color, intensity);
29340                 this.type = 'SpotLight';
29341                 this.position.copy(Object3D.DefaultUp);
29342                 this.updateMatrix();
29343                 this.target = new Object3D();
29344                 Object.defineProperty(this, 'power', {
29345                         get: function get() {
29346                                 // intensity = power per solid angle.
29347                                 // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
29348                                 return this.intensity * Math.PI;
29349                         },
29350                         set: function set(power) {
29351                                 // intensity = power per solid angle.
29352                                 // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
29353                                 this.intensity = power / Math.PI;
29354                         }
29355                 });
29356                 this.distance = distance !== undefined ? distance : 0;
29357                 this.angle = angle !== undefined ? angle : Math.PI / 3;
29358                 this.penumbra = penumbra !== undefined ? penumbra : 0;
29359                 this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
29360
29361                 this.shadow = new SpotLightShadow();
29362         }
29363
29364         SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
29365                 constructor: SpotLight,
29366                 isSpotLight: true,
29367                 copy: function copy(source) {
29368                         Light.prototype.copy.call(this, source);
29369                         this.distance = source.distance;
29370                         this.angle = source.angle;
29371                         this.penumbra = source.penumbra;
29372                         this.decay = source.decay;
29373                         this.target = source.target.clone();
29374                         this.shadow = source.shadow.clone();
29375                         return this;
29376                 }
29377         });
29378
29379         function PointLightShadow() {
29380                 LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
29381                 this._frameExtents = new Vector2(4, 2);
29382                 this._viewportCount = 6;
29383                 this._viewports = [// These viewports map a cube-map onto a 2D texture with the
29384                 // following orientation:
29385                 //
29386                 //      xzXZ
29387                 //       y Y
29388                 //
29389                 // X - Positive x direction
29390                 // x - Negative x direction
29391                 // Y - Positive y direction
29392                 // y - Negative y direction
29393                 // Z - Positive z direction
29394                 // z - Negative z direction
29395                 // positive X
29396                 new Vector4(2, 1, 1, 1), // negative X
29397                 new Vector4(0, 1, 1, 1), // positive Z
29398                 new Vector4(3, 1, 1, 1), // negative Z
29399                 new Vector4(1, 1, 1, 1), // positive Y
29400                 new Vector4(3, 0, 1, 1), // negative Y
29401                 new Vector4(1, 0, 1, 1)];
29402                 this._cubeDirections = [new Vector3(1, 0, 0), new Vector3(-1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 0, -1), new Vector3(0, 1, 0), new Vector3(0, -1, 0)];
29403                 this._cubeUps = [new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1), new Vector3(0, 0, -1)];
29404         }
29405
29406         PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
29407                 constructor: PointLightShadow,
29408                 isPointLightShadow: true,
29409                 updateMatrices: function updateMatrices(light, viewportIndex) {
29410                         if (viewportIndex === void 0) {
29411                                 viewportIndex = 0;
29412                         }
29413
29414                         var camera = this.camera,
29415                                         shadowMatrix = this.matrix,
29416                                         lightPositionWorld = this._lightPositionWorld,
29417                                         lookTarget = this._lookTarget,
29418                                         projScreenMatrix = this._projScreenMatrix;
29419                         lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
29420                         camera.position.copy(lightPositionWorld);
29421                         lookTarget.copy(camera.position);
29422                         lookTarget.add(this._cubeDirections[viewportIndex]);
29423                         camera.up.copy(this._cubeUps[viewportIndex]);
29424                         camera.lookAt(lookTarget);
29425                         camera.updateMatrixWorld();
29426                         shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
29427                         projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
29428
29429                         this._frustum.setFromProjectionMatrix(projScreenMatrix);
29430                 }
29431         });
29432
29433         function PointLight(color, intensity, distance, decay) {
29434                 Light.call(this, color, intensity);
29435                 this.type = 'PointLight';
29436                 Object.defineProperty(this, 'power', {
29437                         get: function get() {
29438                                 // intensity = power per solid angle.
29439                                 // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
29440                                 return this.intensity * 4 * Math.PI;
29441                         },
29442                         set: function set(power) {
29443                                 // intensity = power per solid angle.
29444                                 // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
29445                                 this.intensity = power / (4 * Math.PI);
29446                         }
29447                 });
29448                 this.distance = distance !== undefined ? distance : 0;
29449                 this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
29450
29451                 this.shadow = new PointLightShadow();
29452         }
29453
29454         PointLight.prototype = Object.assign(Object.create(Light.prototype), {
29455                 constructor: PointLight,
29456                 isPointLight: true,
29457                 copy: function copy(source) {
29458                         Light.prototype.copy.call(this, source);
29459                         this.distance = source.distance;
29460                         this.decay = source.decay;
29461                         this.shadow = source.shadow.clone();
29462                         return this;
29463                 }
29464         });
29465
29466         function OrthographicCamera(left, right, top, bottom, near, far) {
29467                 Camera.call(this);
29468                 this.type = 'OrthographicCamera';
29469                 this.zoom = 1;
29470                 this.view = null;
29471                 this.left = left !== undefined ? left : -1;
29472                 this.right = right !== undefined ? right : 1;
29473                 this.top = top !== undefined ? top : 1;
29474                 this.bottom = bottom !== undefined ? bottom : -1;
29475                 this.near = near !== undefined ? near : 0.1;
29476                 this.far = far !== undefined ? far : 2000;
29477                 this.updateProjectionMatrix();
29478         }
29479
29480         OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
29481                 constructor: OrthographicCamera,
29482                 isOrthographicCamera: true,
29483                 copy: function copy(source, recursive) {
29484                         Camera.prototype.copy.call(this, source, recursive);
29485                         this.left = source.left;
29486                         this.right = source.right;
29487                         this.top = source.top;
29488                         this.bottom = source.bottom;
29489                         this.near = source.near;
29490                         this.far = source.far;
29491                         this.zoom = source.zoom;
29492                         this.view = source.view === null ? null : Object.assign({}, source.view);
29493                         return this;
29494                 },
29495                 setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
29496                         if (this.view === null) {
29497                                 this.view = {
29498                                         enabled: true,
29499                                         fullWidth: 1,
29500                                         fullHeight: 1,
29501                                         offsetX: 0,
29502                                         offsetY: 0,
29503                                         width: 1,
29504                                         height: 1
29505                                 };
29506                         }
29507
29508                         this.view.enabled = true;
29509                         this.view.fullWidth = fullWidth;
29510                         this.view.fullHeight = fullHeight;
29511                         this.view.offsetX = x;
29512                         this.view.offsetY = y;
29513                         this.view.width = width;
29514                         this.view.height = height;
29515                         this.updateProjectionMatrix();
29516                 },
29517                 clearViewOffset: function clearViewOffset() {
29518                         if (this.view !== null) {
29519                                 this.view.enabled = false;
29520                         }
29521
29522                         this.updateProjectionMatrix();
29523                 },
29524                 updateProjectionMatrix: function updateProjectionMatrix() {
29525                         var dx = (this.right - this.left) / (2 * this.zoom);
29526                         var dy = (this.top - this.bottom) / (2 * this.zoom);
29527                         var cx = (this.right + this.left) / 2;
29528                         var cy = (this.top + this.bottom) / 2;
29529                         var left = cx - dx;
29530                         var right = cx + dx;
29531                         var top = cy + dy;
29532                         var bottom = cy - dy;
29533
29534                         if (this.view !== null && this.view.enabled) {
29535                                 var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
29536                                 var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
29537                                 left += scaleW * this.view.offsetX;
29538                                 right = left + scaleW * this.view.width;
29539                                 top -= scaleH * this.view.offsetY;
29540                                 bottom = top - scaleH * this.view.height;
29541                         }
29542
29543                         this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
29544                         this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
29545                 },
29546                 toJSON: function toJSON(meta) {
29547                         var data = Object3D.prototype.toJSON.call(this, meta);
29548                         data.object.zoom = this.zoom;
29549                         data.object.left = this.left;
29550                         data.object.right = this.right;
29551                         data.object.top = this.top;
29552                         data.object.bottom = this.bottom;
29553                         data.object.near = this.near;
29554                         data.object.far = this.far;
29555                         if (this.view !== null) data.object.view = Object.assign({}, this.view);
29556                         return data;
29557                 }
29558         });
29559
29560         function DirectionalLightShadow() {
29561                 LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
29562         }
29563
29564         DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
29565                 constructor: DirectionalLightShadow,
29566                 isDirectionalLightShadow: true,
29567                 updateMatrices: function updateMatrices(light) {
29568                         LightShadow.prototype.updateMatrices.call(this, light);
29569                 }
29570         });
29571
29572         function DirectionalLight(color, intensity) {
29573                 Light.call(this, color, intensity);
29574                 this.type = 'DirectionalLight';
29575                 this.position.copy(Object3D.DefaultUp);
29576                 this.updateMatrix();
29577                 this.target = new Object3D();
29578                 this.shadow = new DirectionalLightShadow();
29579         }
29580
29581         DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
29582                 constructor: DirectionalLight,
29583                 isDirectionalLight: true,
29584                 copy: function copy(source) {
29585                         Light.prototype.copy.call(this, source);
29586                         this.target = source.target.clone();
29587                         this.shadow = source.shadow.clone();
29588                         return this;
29589                 }
29590         });
29591
29592         function AmbientLight(color, intensity) {
29593                 Light.call(this, color, intensity);
29594                 this.type = 'AmbientLight';
29595         }
29596
29597         AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
29598                 constructor: AmbientLight,
29599                 isAmbientLight: true
29600         });
29601
29602         function RectAreaLight(color, intensity, width, height) {
29603                 Light.call(this, color, intensity);
29604                 this.type = 'RectAreaLight';
29605                 this.width = width !== undefined ? width : 10;
29606                 this.height = height !== undefined ? height : 10;
29607         }
29608
29609         RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
29610                 constructor: RectAreaLight,
29611                 isRectAreaLight: true,
29612                 copy: function copy(source) {
29613                         Light.prototype.copy.call(this, source);
29614                         this.width = source.width;
29615                         this.height = source.height;
29616                         return this;
29617                 },
29618                 toJSON: function toJSON(meta) {
29619                         var data = Light.prototype.toJSON.call(this, meta);
29620                         data.object.width = this.width;
29621                         data.object.height = this.height;
29622                         return data;
29623                 }
29624         });
29625
29626         /**
29627          * Primary reference:
29628          *       https://graphics.stanford.edu/papers/envmap/envmap.pdf
29629          *
29630          * Secondary reference:
29631          *       https://www.ppsloan.org/publications/StupidSH36.pdf
29632          */
29633         // 3-band SH defined by 9 coefficients
29634
29635         var SphericalHarmonics3 = /*#__PURE__*/function () {
29636                 function SphericalHarmonics3() {
29637                         Object.defineProperty(this, 'isSphericalHarmonics3', {
29638                                 value: true
29639                         });
29640                         this.coefficients = [];
29641
29642                         for (var i = 0; i < 9; i++) {
29643                                 this.coefficients.push(new Vector3());
29644                         }
29645                 }
29646
29647                 var _proto = SphericalHarmonics3.prototype;
29648
29649                 _proto.set = function set(coefficients) {
29650                         for (var i = 0; i < 9; i++) {
29651                                 this.coefficients[i].copy(coefficients[i]);
29652                         }
29653
29654                         return this;
29655                 };
29656
29657                 _proto.zero = function zero() {
29658                         for (var i = 0; i < 9; i++) {
29659                                 this.coefficients[i].set(0, 0, 0);
29660                         }
29661
29662                         return this;
29663                 } // get the radiance in the direction of the normal
29664                 // target is a Vector3
29665                 ;
29666
29667                 _proto.getAt = function getAt(normal, target) {
29668                         // normal is assumed to be unit length
29669                         var x = normal.x,
29670                                         y = normal.y,
29671                                         z = normal.z;
29672                         var coeff = this.coefficients; // band 0
29673
29674                         target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
29675
29676                         target.addScaledVector(coeff[1], 0.488603 * y);
29677                         target.addScaledVector(coeff[2], 0.488603 * z);
29678                         target.addScaledVector(coeff[3], 0.488603 * x); // band 2
29679
29680                         target.addScaledVector(coeff[4], 1.092548 * (x * y));
29681                         target.addScaledVector(coeff[5], 1.092548 * (y * z));
29682                         target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
29683                         target.addScaledVector(coeff[7], 1.092548 * (x * z));
29684                         target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
29685                         return target;
29686                 } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
29687                 // target is a Vector3
29688                 // https://graphics.stanford.edu/papers/envmap/envmap.pdf
29689                 ;
29690
29691                 _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
29692                         // normal is assumed to be unit length
29693                         var x = normal.x,
29694                                         y = normal.y,
29695                                         z = normal.z;
29696                         var coeff = this.coefficients; // band 0
29697
29698                         target.copy(coeff[0]).multiplyScalar(0.886227); // Ï€ * 0.282095
29699                         // band 1
29700
29701                         target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * Ï€ / 3 ) * 0.488603
29702
29703                         target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
29704                         target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
29705
29706                         target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( Ï€ / 4 ) * 1.092548
29707
29708                         target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
29709                         target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( Ï€ / 4 ) * 0.315392 * 3
29710
29711                         target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
29712                         target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( Ï€ / 4 ) * 0.546274
29713
29714                         return target;
29715                 };
29716
29717                 _proto.add = function add(sh) {
29718                         for (var i = 0; i < 9; i++) {
29719                                 this.coefficients[i].add(sh.coefficients[i]);
29720                         }
29721
29722                         return this;
29723                 };
29724
29725                 _proto.addScaledSH = function addScaledSH(sh, s) {
29726                         for (var i = 0; i < 9; i++) {
29727                                 this.coefficients[i].addScaledVector(sh.coefficients[i], s);
29728                         }
29729
29730                         return this;
29731                 };
29732
29733                 _proto.scale = function scale(s) {
29734                         for (var i = 0; i < 9; i++) {
29735                                 this.coefficients[i].multiplyScalar(s);
29736                         }
29737
29738                         return this;
29739                 };
29740
29741                 _proto.lerp = function lerp(sh, alpha) {
29742                         for (var i = 0; i < 9; i++) {
29743                                 this.coefficients[i].lerp(sh.coefficients[i], alpha);
29744                         }
29745
29746                         return this;
29747                 };
29748
29749                 _proto.equals = function equals(sh) {
29750                         for (var i = 0; i < 9; i++) {
29751                                 if (!this.coefficients[i].equals(sh.coefficients[i])) {
29752                                         return false;
29753                                 }
29754                         }
29755
29756                         return true;
29757                 };
29758
29759                 _proto.copy = function copy(sh) {
29760                         return this.set(sh.coefficients);
29761                 };
29762
29763                 _proto.clone = function clone() {
29764                         return new this.constructor().copy(this);
29765                 };
29766
29767                 _proto.fromArray = function fromArray(array, offset) {
29768                         if (offset === void 0) {
29769                                 offset = 0;
29770                         }
29771
29772                         var coefficients = this.coefficients;
29773
29774                         for (var i = 0; i < 9; i++) {
29775                                 coefficients[i].fromArray(array, offset + i * 3);
29776                         }
29777
29778                         return this;
29779                 };
29780
29781                 _proto.toArray = function toArray(array, offset) {
29782                         if (array === void 0) {
29783                                 array = [];
29784                         }
29785
29786                         if (offset === void 0) {
29787                                 offset = 0;
29788                         }
29789
29790                         var coefficients = this.coefficients;
29791
29792                         for (var i = 0; i < 9; i++) {
29793                                 coefficients[i].toArray(array, offset + i * 3);
29794                         }
29795
29796                         return array;
29797                 } // evaluate the basis functions
29798                 // shBasis is an Array[ 9 ]
29799                 ;
29800
29801                 SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
29802                         // normal is assumed to be unit length
29803                         var x = normal.x,
29804                                         y = normal.y,
29805                                         z = normal.z; // band 0
29806
29807                         shBasis[0] = 0.282095; // band 1
29808
29809                         shBasis[1] = 0.488603 * y;
29810                         shBasis[2] = 0.488603 * z;
29811                         shBasis[3] = 0.488603 * x; // band 2
29812
29813                         shBasis[4] = 1.092548 * x * y;
29814                         shBasis[5] = 1.092548 * y * z;
29815                         shBasis[6] = 0.315392 * (3 * z * z - 1);
29816                         shBasis[7] = 1.092548 * x * z;
29817                         shBasis[8] = 0.546274 * (x * x - y * y);
29818                 };
29819
29820                 return SphericalHarmonics3;
29821         }();
29822
29823         function LightProbe(sh, intensity) {
29824                 Light.call(this, undefined, intensity);
29825                 this.type = 'LightProbe';
29826                 this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
29827         }
29828
29829         LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
29830                 constructor: LightProbe,
29831                 isLightProbe: true,
29832                 copy: function copy(source) {
29833                         Light.prototype.copy.call(this, source);
29834                         this.sh.copy(source.sh);
29835                         return this;
29836                 },
29837                 fromJSON: function fromJSON(json) {
29838                         this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
29839
29840                         this.sh.fromArray(json.sh);
29841                         return this;
29842                 },
29843                 toJSON: function toJSON(meta) {
29844                         var data = Light.prototype.toJSON.call(this, meta);
29845                         data.object.sh = this.sh.toArray();
29846                         return data;
29847                 }
29848         });
29849
29850         function MaterialLoader(manager) {
29851                 Loader.call(this, manager);
29852                 this.textures = {};
29853         }
29854
29855         MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
29856                 constructor: MaterialLoader,
29857                 load: function load(url, onLoad, onProgress, onError) {
29858                         var scope = this;
29859                         var loader = new FileLoader(scope.manager);
29860                         loader.setPath(scope.path);
29861                         loader.setRequestHeader(scope.requestHeader);
29862                         loader.setWithCredentials(scope.withCredentials);
29863                         loader.load(url, function (text) {
29864                                 try {
29865                                         onLoad(scope.parse(JSON.parse(text)));
29866                                 } catch (e) {
29867                                         if (onError) {
29868                                                 onError(e);
29869                                         } else {
29870                                                 console.error(e);
29871                                         }
29872
29873                                         scope.manager.itemError(url);
29874                                 }
29875                         }, onProgress, onError);
29876                 },
29877                 parse: function parse(json) {
29878                         var textures = this.textures;
29879
29880                         function getTexture(name) {
29881                                 if (textures[name] === undefined) {
29882                                         console.warn('THREE.MaterialLoader: Undefined texture', name);
29883                                 }
29884
29885                                 return textures[name];
29886                         }
29887
29888                         var material = new Materials[json.type]();
29889                         if (json.uuid !== undefined) material.uuid = json.uuid;
29890                         if (json.name !== undefined) material.name = json.name;
29891                         if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
29892                         if (json.roughness !== undefined) material.roughness = json.roughness;
29893                         if (json.metalness !== undefined) material.metalness = json.metalness;
29894                         if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
29895                         if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
29896                         if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
29897                         if (json.shininess !== undefined) material.shininess = json.shininess;
29898                         if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
29899                         if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
29900                         if (json.fog !== undefined) material.fog = json.fog;
29901                         if (json.flatShading !== undefined) material.flatShading = json.flatShading;
29902                         if (json.blending !== undefined) material.blending = json.blending;
29903                         if (json.combine !== undefined) material.combine = json.combine;
29904                         if (json.side !== undefined) material.side = json.side;
29905                         if (json.opacity !== undefined) material.opacity = json.opacity;
29906                         if (json.transparent !== undefined) material.transparent = json.transparent;
29907                         if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
29908                         if (json.depthTest !== undefined) material.depthTest = json.depthTest;
29909                         if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
29910                         if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
29911                         if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
29912                         if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
29913                         if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
29914                         if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
29915                         if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
29916                         if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
29917                         if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
29918                         if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
29919                         if (json.wireframe !== undefined) material.wireframe = json.wireframe;
29920                         if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
29921                         if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
29922                         if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
29923                         if (json.rotation !== undefined) material.rotation = json.rotation;
29924                         if (json.linewidth !== 1) material.linewidth = json.linewidth;
29925                         if (json.dashSize !== undefined) material.dashSize = json.dashSize;
29926                         if (json.gapSize !== undefined) material.gapSize = json.gapSize;
29927                         if (json.scale !== undefined) material.scale = json.scale;
29928                         if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
29929                         if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
29930                         if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
29931                         if (json.skinning !== undefined) material.skinning = json.skinning;
29932                         if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
29933                         if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
29934                         if (json.dithering !== undefined) material.dithering = json.dithering;
29935                         if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
29936                         if (json.visible !== undefined) material.visible = json.visible;
29937                         if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
29938                         if (json.userData !== undefined) material.userData = json.userData;
29939
29940                         if (json.vertexColors !== undefined) {
29941                                 if (typeof json.vertexColors === 'number') {
29942                                         material.vertexColors = json.vertexColors > 0 ? true : false;
29943                                 } else {
29944                                         material.vertexColors = json.vertexColors;
29945                                 }
29946                         } // Shader Material
29947
29948
29949                         if (json.uniforms !== undefined) {
29950                                 for (var name in json.uniforms) {
29951                                         var uniform = json.uniforms[name];
29952                                         material.uniforms[name] = {};
29953
29954                                         switch (uniform.type) {
29955                                                 case 't':
29956                                                         material.uniforms[name].value = getTexture(uniform.value);
29957                                                         break;
29958
29959                                                 case 'c':
29960                                                         material.uniforms[name].value = new Color().setHex(uniform.value);
29961                                                         break;
29962
29963                                                 case 'v2':
29964                                                         material.uniforms[name].value = new Vector2().fromArray(uniform.value);
29965                                                         break;
29966
29967                                                 case 'v3':
29968                                                         material.uniforms[name].value = new Vector3().fromArray(uniform.value);
29969                                                         break;
29970
29971                                                 case 'v4':
29972                                                         material.uniforms[name].value = new Vector4().fromArray(uniform.value);
29973                                                         break;
29974
29975                                                 case 'm3':
29976                                                         material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
29977                                                         break;
29978
29979                                                 case 'm4':
29980                                                         material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
29981                                                         break;
29982
29983                                                 default:
29984                                                         material.uniforms[name].value = uniform.value;
29985                                         }
29986                                 }
29987                         }
29988
29989                         if (json.defines !== undefined) material.defines = json.defines;
29990                         if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
29991                         if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
29992
29993                         if (json.extensions !== undefined) {
29994                                 for (var key in json.extensions) {
29995                                         material.extensions[key] = json.extensions[key];
29996                                 }
29997                         } // Deprecated
29998
29999
30000                         if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
30001                         // for PointsMaterial
30002
30003                         if (json.size !== undefined) material.size = json.size;
30004                         if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
30005
30006                         if (json.map !== undefined) material.map = getTexture(json.map);
30007                         if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
30008                         if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
30009                         if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
30010                         if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
30011                         if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
30012                         if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
30013
30014                         if (json.normalScale !== undefined) {
30015                                 var normalScale = json.normalScale;
30016
30017                                 if (Array.isArray(normalScale) === false) {
30018                                         // Blender exporter used to export a scalar. See #7459
30019                                         normalScale = [normalScale, normalScale];
30020                                 }
30021
30022                                 material.normalScale = new Vector2().fromArray(normalScale);
30023                         }
30024
30025                         if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
30026                         if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
30027                         if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
30028                         if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
30029                         if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
30030                         if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
30031                         if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
30032                         if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
30033                         if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
30034                         if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
30035                         if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
30036                         if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
30037                         if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
30038                         if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
30039                         if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
30040                         if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
30041                         if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
30042                         if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
30043                         if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
30044                         if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
30045                         if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
30046                         if (json.transmission !== undefined) material.transmission = json.transmission;
30047                         if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
30048                         return material;
30049                 },
30050                 setTextures: function setTextures(value) {
30051                         this.textures = value;
30052                         return this;
30053                 }
30054         });
30055
30056         var LoaderUtils = {
30057                 decodeText: function decodeText(array) {
30058                         if (typeof TextDecoder !== 'undefined') {
30059                                 return new TextDecoder().decode(array);
30060                         } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
30061                         // throws a "maximum call stack size exceeded" error for large arrays.
30062
30063
30064                         var s = '';
30065
30066                         for (var i = 0, il = array.length; i < il; i++) {
30067                                 // Implicitly assumes little-endian.
30068                                 s += String.fromCharCode(array[i]);
30069                         }
30070
30071                         try {
30072                                 // merges multi-byte utf-8 characters.
30073                                 return decodeURIComponent(escape(s));
30074                         } catch (e) {
30075                                 // see #16358
30076                                 return s;
30077                         }
30078                 },
30079                 extractUrlBase: function extractUrlBase(url) {
30080                         var index = url.lastIndexOf('/');
30081                         if (index === -1) return './';
30082                         return url.substr(0, index + 1);
30083                 }
30084         };
30085
30086         function InstancedBufferGeometry() {
30087                 BufferGeometry.call(this);
30088                 this.type = 'InstancedBufferGeometry';
30089                 this.instanceCount = Infinity;
30090         }
30091
30092         InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
30093                 constructor: InstancedBufferGeometry,
30094                 isInstancedBufferGeometry: true,
30095                 copy: function copy(source) {
30096                         BufferGeometry.prototype.copy.call(this, source);
30097                         this.instanceCount = source.instanceCount;
30098                         return this;
30099                 },
30100                 clone: function clone() {
30101                         return new this.constructor().copy(this);
30102                 },
30103                 toJSON: function toJSON() {
30104                         var data = BufferGeometry.prototype.toJSON.call(this);
30105                         data.instanceCount = this.instanceCount;
30106                         data.isInstancedBufferGeometry = true;
30107                         return data;
30108                 }
30109         });
30110
30111         function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
30112                 if (typeof normalized === 'number') {
30113                         meshPerAttribute = normalized;
30114                         normalized = false;
30115                         console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
30116                 }
30117
30118                 BufferAttribute.call(this, array, itemSize, normalized);
30119                 this.meshPerAttribute = meshPerAttribute || 1;
30120         }
30121
30122         InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
30123                 constructor: InstancedBufferAttribute,
30124                 isInstancedBufferAttribute: true,
30125                 copy: function copy(source) {
30126                         BufferAttribute.prototype.copy.call(this, source);
30127                         this.meshPerAttribute = source.meshPerAttribute;
30128                         return this;
30129                 },
30130                 toJSON: function toJSON() {
30131                         var data = BufferAttribute.prototype.toJSON.call(this);
30132                         data.meshPerAttribute = this.meshPerAttribute;
30133                         data.isInstancedBufferAttribute = true;
30134                         return data;
30135                 }
30136         });
30137
30138         function BufferGeometryLoader(manager) {
30139                 Loader.call(this, manager);
30140         }
30141
30142         BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
30143                 constructor: BufferGeometryLoader,
30144                 load: function load(url, onLoad, onProgress, onError) {
30145                         var scope = this;
30146                         var loader = new FileLoader(scope.manager);
30147                         loader.setPath(scope.path);
30148                         loader.setRequestHeader(scope.requestHeader);
30149                         loader.setWithCredentials(scope.withCredentials);
30150                         loader.load(url, function (text) {
30151                                 try {
30152                                         onLoad(scope.parse(JSON.parse(text)));
30153                                 } catch (e) {
30154                                         if (onError) {
30155                                                 onError(e);
30156                                         } else {
30157                                                 console.error(e);
30158                                         }
30159
30160                                         scope.manager.itemError(url);
30161                                 }
30162                         }, onProgress, onError);
30163                 },
30164                 parse: function parse(json) {
30165                         var interleavedBufferMap = {};
30166                         var arrayBufferMap = {};
30167
30168                         function getInterleavedBuffer(json, uuid) {
30169                                 if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
30170                                 var interleavedBuffers = json.interleavedBuffers;
30171                                 var interleavedBuffer = interleavedBuffers[uuid];
30172                                 var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
30173                                 var array = getTypedArray(interleavedBuffer.type, buffer);
30174                                 var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
30175                                 ib.uuid = interleavedBuffer.uuid;
30176                                 interleavedBufferMap[uuid] = ib;
30177                                 return ib;
30178                         }
30179
30180                         function getArrayBuffer(json, uuid) {
30181                                 if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
30182                                 var arrayBuffers = json.arrayBuffers;
30183                                 var arrayBuffer = arrayBuffers[uuid];
30184                                 var ab = new Uint32Array(arrayBuffer).buffer;
30185                                 arrayBufferMap[uuid] = ab;
30186                                 return ab;
30187                         }
30188
30189                         var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
30190                         var index = json.data.index;
30191
30192                         if (index !== undefined) {
30193                                 var typedArray = getTypedArray(index.type, index.array);
30194                                 geometry.setIndex(new BufferAttribute(typedArray, 1));
30195                         }
30196
30197                         var attributes = json.data.attributes;
30198
30199                         for (var key in attributes) {
30200                                 var attribute = attributes[key];
30201                                 var bufferAttribute = void 0;
30202
30203                                 if (attribute.isInterleavedBufferAttribute) {
30204                                         var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
30205                                         bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
30206                                 } else {
30207                                         var _typedArray = getTypedArray(attribute.type, attribute.array);
30208
30209                                         var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
30210                                         bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
30211                                 }
30212
30213                                 if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
30214                                 geometry.setAttribute(key, bufferAttribute);
30215                         }
30216
30217                         var morphAttributes = json.data.morphAttributes;
30218
30219                         if (morphAttributes) {
30220                                 for (var _key in morphAttributes) {
30221                                         var attributeArray = morphAttributes[_key];
30222                                         var array = [];
30223
30224                                         for (var i = 0, il = attributeArray.length; i < il; i++) {
30225                                                 var _attribute = attributeArray[i];
30226
30227                                                 var _bufferAttribute = void 0;
30228
30229                                                 if (_attribute.isInterleavedBufferAttribute) {
30230                                                         var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
30231
30232                                                         _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
30233                                                 } else {
30234                                                         var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
30235
30236                                                         _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
30237                                                 }
30238
30239                                                 if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
30240                                                 array.push(_bufferAttribute);
30241                                         }
30242
30243                                         geometry.morphAttributes[_key] = array;
30244                                 }
30245                         }
30246
30247                         var morphTargetsRelative = json.data.morphTargetsRelative;
30248
30249                         if (morphTargetsRelative) {
30250                                 geometry.morphTargetsRelative = true;
30251                         }
30252
30253                         var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
30254
30255                         if (groups !== undefined) {
30256                                 for (var _i = 0, n = groups.length; _i !== n; ++_i) {
30257                                         var group = groups[_i];
30258                                         geometry.addGroup(group.start, group.count, group.materialIndex);
30259                                 }
30260                         }
30261
30262                         var boundingSphere = json.data.boundingSphere;
30263
30264                         if (boundingSphere !== undefined) {
30265                                 var center = new Vector3();
30266
30267                                 if (boundingSphere.center !== undefined) {
30268                                         center.fromArray(boundingSphere.center);
30269                                 }
30270
30271                                 geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
30272                         }
30273
30274                         if (json.name) geometry.name = json.name;
30275                         if (json.userData) geometry.userData = json.userData;
30276                         return geometry;
30277                 }
30278         });
30279
30280         var ObjectLoader = /*#__PURE__*/function (_Loader) {
30281                 _inheritsLoose(ObjectLoader, _Loader);
30282
30283                 function ObjectLoader(manager) {
30284                         return _Loader.call(this, manager) || this;
30285                 }
30286
30287                 var _proto = ObjectLoader.prototype;
30288
30289                 _proto.load = function load(url, onLoad, onProgress, onError) {
30290                         var scope = this;
30291                         var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
30292                         this.resourcePath = this.resourcePath || path;
30293                         var loader = new FileLoader(this.manager);
30294                         loader.setPath(this.path);
30295                         loader.setRequestHeader(this.requestHeader);
30296                         loader.setWithCredentials(this.withCredentials);
30297                         loader.load(url, function (text) {
30298                                 var json = null;
30299
30300                                 try {
30301                                         json = JSON.parse(text);
30302                                 } catch (error) {
30303                                         if (onError !== undefined) onError(error);
30304                                         console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
30305                                         return;
30306                                 }
30307
30308                                 var metadata = json.metadata;
30309
30310                                 if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
30311                                         console.error('THREE.ObjectLoader: Can\'t load ' + url);
30312                                         return;
30313                                 }
30314
30315                                 scope.parse(json, onLoad);
30316                         }, onProgress, onError);
30317                 };
30318
30319                 _proto.parse = function parse(json, onLoad) {
30320                         var animations = this.parseAnimations(json.animations);
30321                         var shapes = this.parseShapes(json.shapes);
30322                         var geometries = this.parseGeometries(json.geometries, shapes);
30323                         var images = this.parseImages(json.images, function () {
30324                                 if (onLoad !== undefined) onLoad(object);
30325                         });
30326                         var textures = this.parseTextures(json.textures, images);
30327                         var materials = this.parseMaterials(json.materials, textures);
30328                         var object = this.parseObject(json.object, geometries, materials, animations);
30329                         var skeletons = this.parseSkeletons(json.skeletons, object);
30330                         this.bindSkeletons(object, skeletons); //
30331
30332                         if (onLoad !== undefined) {
30333                                 var hasImages = false;
30334
30335                                 for (var uuid in images) {
30336                                         if (images[uuid] instanceof HTMLImageElement) {
30337                                                 hasImages = true;
30338                                                 break;
30339                                         }
30340                                 }
30341
30342                                 if (hasImages === false) onLoad(object);
30343                         }
30344
30345                         return object;
30346                 };
30347
30348                 _proto.parseShapes = function parseShapes(json) {
30349                         var shapes = {};
30350
30351                         if (json !== undefined) {
30352                                 for (var i = 0, l = json.length; i < l; i++) {
30353                                         var shape = new Shape().fromJSON(json[i]);
30354                                         shapes[shape.uuid] = shape;
30355                                 }
30356                         }
30357
30358                         return shapes;
30359                 };
30360
30361                 _proto.parseSkeletons = function parseSkeletons(json, object) {
30362                         var skeletons = {};
30363                         var bones = {}; // generate bone lookup table
30364
30365                         object.traverse(function (child) {
30366                                 if (child.isBone) bones[child.uuid] = child;
30367                         }); // create skeletons
30368
30369                         if (json !== undefined) {
30370                                 for (var i = 0, l = json.length; i < l; i++) {
30371                                         var skeleton = new Skeleton().fromJSON(json[i], bones);
30372                                         skeletons[skeleton.uuid] = skeleton;
30373                                 }
30374                         }
30375
30376                         return skeletons;
30377                 };
30378
30379                 _proto.parseGeometries = function parseGeometries(json, shapes) {
30380                         var geometries = {};
30381                         var geometryShapes;
30382
30383                         if (json !== undefined) {
30384                                 var bufferGeometryLoader = new BufferGeometryLoader();
30385
30386                                 for (var i = 0, l = json.length; i < l; i++) {
30387                                         var geometry = void 0;
30388                                         var data = json[i];
30389
30390                                         switch (data.type) {
30391                                                 case 'PlaneGeometry':
30392                                                 case 'PlaneBufferGeometry':
30393                                                         geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
30394                                                         break;
30395
30396                                                 case 'BoxGeometry':
30397                                                 case 'BoxBufferGeometry':
30398                                                 case 'CubeGeometry':
30399                                                         // backwards compatible
30400                                                         geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
30401                                                         break;
30402
30403                                                 case 'CircleGeometry':
30404                                                 case 'CircleBufferGeometry':
30405                                                         geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
30406                                                         break;
30407
30408                                                 case 'CylinderGeometry':
30409                                                 case 'CylinderBufferGeometry':
30410                                                         geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
30411                                                         break;
30412
30413                                                 case 'ConeGeometry':
30414                                                 case 'ConeBufferGeometry':
30415                                                         geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
30416                                                         break;
30417
30418                                                 case 'SphereGeometry':
30419                                                 case 'SphereBufferGeometry':
30420                                                         geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
30421                                                         break;
30422
30423                                                 case 'DodecahedronGeometry':
30424                                                 case 'DodecahedronBufferGeometry':
30425                                                 case 'IcosahedronGeometry':
30426                                                 case 'IcosahedronBufferGeometry':
30427                                                 case 'OctahedronGeometry':
30428                                                 case 'OctahedronBufferGeometry':
30429                                                 case 'TetrahedronGeometry':
30430                                                 case 'TetrahedronBufferGeometry':
30431                                                         geometry = new Geometries[data.type](data.radius, data.detail);
30432                                                         break;
30433
30434                                                 case 'RingGeometry':
30435                                                 case 'RingBufferGeometry':
30436                                                         geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
30437                                                         break;
30438
30439                                                 case 'TorusGeometry':
30440                                                 case 'TorusBufferGeometry':
30441                                                         geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
30442                                                         break;
30443
30444                                                 case 'TorusKnotGeometry':
30445                                                 case 'TorusKnotBufferGeometry':
30446                                                         geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
30447                                                         break;
30448
30449                                                 case 'TubeGeometry':
30450                                                 case 'TubeBufferGeometry':
30451                                                         // This only works for built-in curves (e.g. CatmullRomCurve3).
30452                                                         // User defined curves or instances of CurvePath will not be deserialized.
30453                                                         geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
30454                                                         break;
30455
30456                                                 case 'LatheGeometry':
30457                                                 case 'LatheBufferGeometry':
30458                                                         geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
30459                                                         break;
30460
30461                                                 case 'PolyhedronGeometry':
30462                                                 case 'PolyhedronBufferGeometry':
30463                                                         geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
30464                                                         break;
30465
30466                                                 case 'ShapeGeometry':
30467                                                 case 'ShapeBufferGeometry':
30468                                                         geometryShapes = [];
30469
30470                                                         for (var j = 0, jl = data.shapes.length; j < jl; j++) {
30471                                                                 var shape = shapes[data.shapes[j]];
30472                                                                 geometryShapes.push(shape);
30473                                                         }
30474
30475                                                         geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
30476                                                         break;
30477
30478                                                 case 'ExtrudeGeometry':
30479                                                 case 'ExtrudeBufferGeometry':
30480                                                         geometryShapes = [];
30481
30482                                                         for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
30483                                                                 var _shape = shapes[data.shapes[_j]];
30484                                                                 geometryShapes.push(_shape);
30485                                                         }
30486
30487                                                         var extrudePath = data.options.extrudePath;
30488
30489                                                         if (extrudePath !== undefined) {
30490                                                                 data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
30491                                                         }
30492
30493                                                         geometry = new Geometries[data.type](geometryShapes, data.options);
30494                                                         break;
30495
30496                                                 case 'BufferGeometry':
30497                                                 case 'InstancedBufferGeometry':
30498                                                         geometry = bufferGeometryLoader.parse(data);
30499                                                         break;
30500
30501                                                 case 'Geometry':
30502                                                         console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
30503                                                         break;
30504
30505                                                 default:
30506                                                         console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
30507                                                         continue;
30508                                         }
30509
30510                                         geometry.uuid = data.uuid;
30511                                         if (data.name !== undefined) geometry.name = data.name;
30512                                         if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
30513                                         geometries[data.uuid] = geometry;
30514                                 }
30515                         }
30516
30517                         return geometries;
30518                 };
30519
30520                 _proto.parseMaterials = function parseMaterials(json, textures) {
30521                         var cache = {}; // MultiMaterial
30522
30523                         var materials = {};
30524
30525                         if (json !== undefined) {
30526                                 var loader = new MaterialLoader();
30527                                 loader.setTextures(textures);
30528
30529                                 for (var i = 0, l = json.length; i < l; i++) {
30530                                         var data = json[i];
30531
30532                                         if (data.type === 'MultiMaterial') {
30533                                                 // Deprecated
30534                                                 var array = [];
30535
30536                                                 for (var j = 0; j < data.materials.length; j++) {
30537                                                         var material = data.materials[j];
30538
30539                                                         if (cache[material.uuid] === undefined) {
30540                                                                 cache[material.uuid] = loader.parse(material);
30541                                                         }
30542
30543                                                         array.push(cache[material.uuid]);
30544                                                 }
30545
30546                                                 materials[data.uuid] = array;
30547                                         } else {
30548                                                 if (cache[data.uuid] === undefined) {
30549                                                         cache[data.uuid] = loader.parse(data);
30550                                                 }
30551
30552                                                 materials[data.uuid] = cache[data.uuid];
30553                                         }
30554                                 }
30555                         }
30556
30557                         return materials;
30558                 };
30559
30560                 _proto.parseAnimations = function parseAnimations(json) {
30561                         var animations = {};
30562
30563                         if (json !== undefined) {
30564                                 for (var i = 0; i < json.length; i++) {
30565                                         var data = json[i];
30566                                         var clip = AnimationClip.parse(data);
30567                                         animations[clip.uuid] = clip;
30568                                 }
30569                         }
30570
30571                         return animations;
30572                 };
30573
30574                 _proto.parseImages = function parseImages(json, onLoad) {
30575                         var scope = this;
30576                         var images = {};
30577                         var loader;
30578
30579                         function loadImage(url) {
30580                                 scope.manager.itemStart(url);
30581                                 return loader.load(url, function () {
30582                                         scope.manager.itemEnd(url);
30583                                 }, undefined, function () {
30584                                         scope.manager.itemError(url);
30585                                         scope.manager.itemEnd(url);
30586                                 });
30587                         }
30588
30589                         function deserializeImage(image) {
30590                                 if (typeof image === 'string') {
30591                                         var url = image;
30592                                         var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
30593                                         return loadImage(path);
30594                                 } else {
30595                                         if (image.data) {
30596                                                 return {
30597                                                         data: getTypedArray(image.type, image.data),
30598                                                         width: image.width,
30599                                                         height: image.height
30600                                                 };
30601                                         } else {
30602                                                 return null;
30603                                         }
30604                                 }
30605                         }
30606
30607                         if (json !== undefined && json.length > 0) {
30608                                 var manager = new LoadingManager(onLoad);
30609                                 loader = new ImageLoader(manager);
30610                                 loader.setCrossOrigin(this.crossOrigin);
30611
30612                                 for (var i = 0, il = json.length; i < il; i++) {
30613                                         var image = json[i];
30614                                         var url = image.url;
30615
30616                                         if (Array.isArray(url)) {
30617                                                 // load array of images e.g CubeTexture
30618                                                 images[image.uuid] = [];
30619
30620                                                 for (var j = 0, jl = url.length; j < jl; j++) {
30621                                                         var currentUrl = url[j];
30622                                                         var deserializedImage = deserializeImage(currentUrl);
30623
30624                                                         if (deserializedImage !== null) {
30625                                                                 if (deserializedImage instanceof HTMLImageElement) {
30626                                                                         images[image.uuid].push(deserializedImage);
30627                                                                 } else {
30628                                                                         // special case: handle array of data textures for cube textures
30629                                                                         images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
30630                                                                 }
30631                                                         }
30632                                                 }
30633                                         } else {
30634                                                 // load single image
30635                                                 var _deserializedImage = deserializeImage(image.url);
30636
30637                                                 if (_deserializedImage !== null) {
30638                                                         images[image.uuid] = _deserializedImage;
30639                                                 }
30640                                         }
30641                                 }
30642                         }
30643
30644                         return images;
30645                 };
30646
30647                 _proto.parseTextures = function parseTextures(json, images) {
30648                         function parseConstant(value, type) {
30649                                 if (typeof value === 'number') return value;
30650                                 console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
30651                                 return type[value];
30652                         }
30653
30654                         var textures = {};
30655
30656                         if (json !== undefined) {
30657                                 for (var i = 0, l = json.length; i < l; i++) {
30658                                         var data = json[i];
30659
30660                                         if (data.image === undefined) {
30661                                                 console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
30662                                         }
30663
30664                                         if (images[data.image] === undefined) {
30665                                                 console.warn('THREE.ObjectLoader: Undefined image', data.image);
30666                                         }
30667
30668                                         var texture = void 0;
30669                                         var image = images[data.image];
30670
30671                                         if (Array.isArray(image)) {
30672                                                 texture = new CubeTexture(image);
30673                                                 if (image.length === 6) texture.needsUpdate = true;
30674                                         } else {
30675                                                 if (image && image.data) {
30676                                                         texture = new DataTexture(image.data, image.width, image.height);
30677                                                 } else {
30678                                                         texture = new Texture(image);
30679                                                 }
30680
30681                                                 if (image) texture.needsUpdate = true; // textures can have undefined image data
30682                                         }
30683
30684                                         texture.uuid = data.uuid;
30685                                         if (data.name !== undefined) texture.name = data.name;
30686                                         if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
30687                                         if (data.offset !== undefined) texture.offset.fromArray(data.offset);
30688                                         if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
30689                                         if (data.center !== undefined) texture.center.fromArray(data.center);
30690                                         if (data.rotation !== undefined) texture.rotation = data.rotation;
30691
30692                                         if (data.wrap !== undefined) {
30693                                                 texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
30694                                                 texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
30695                                         }
30696
30697                                         if (data.format !== undefined) texture.format = data.format;
30698                                         if (data.type !== undefined) texture.type = data.type;
30699                                         if (data.encoding !== undefined) texture.encoding = data.encoding;
30700                                         if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
30701                                         if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
30702                                         if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
30703                                         if (data.flipY !== undefined) texture.flipY = data.flipY;
30704                                         if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
30705                                         if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
30706                                         textures[data.uuid] = texture;
30707                                 }
30708                         }
30709
30710                         return textures;
30711                 };
30712
30713                 _proto.parseObject = function parseObject(data, geometries, materials, animations) {
30714                         var object;
30715
30716                         function getGeometry(name) {
30717                                 if (geometries[name] === undefined) {
30718                                         console.warn('THREE.ObjectLoader: Undefined geometry', name);
30719                                 }
30720
30721                                 return geometries[name];
30722                         }
30723
30724                         function getMaterial(name) {
30725                                 if (name === undefined) return undefined;
30726
30727                                 if (Array.isArray(name)) {
30728                                         var array = [];
30729
30730                                         for (var i = 0, l = name.length; i < l; i++) {
30731                                                 var uuid = name[i];
30732
30733                                                 if (materials[uuid] === undefined) {
30734                                                         console.warn('THREE.ObjectLoader: Undefined material', uuid);
30735                                                 }
30736
30737                                                 array.push(materials[uuid]);
30738                                         }
30739
30740                                         return array;
30741                                 }
30742
30743                                 if (materials[name] === undefined) {
30744                                         console.warn('THREE.ObjectLoader: Undefined material', name);
30745                                 }
30746
30747                                 return materials[name];
30748                         }
30749
30750                         var geometry, material;
30751
30752                         switch (data.type) {
30753                                 case 'Scene':
30754                                         object = new Scene();
30755
30756                                         if (data.background !== undefined) {
30757                                                 if (Number.isInteger(data.background)) {
30758                                                         object.background = new Color(data.background);
30759                                                 }
30760                                         }
30761
30762                                         if (data.fog !== undefined) {
30763                                                 if (data.fog.type === 'Fog') {
30764                                                         object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
30765                                                 } else if (data.fog.type === 'FogExp2') {
30766                                                         object.fog = new FogExp2(data.fog.color, data.fog.density);
30767                                                 }
30768                                         }
30769
30770                                         break;
30771
30772                                 case 'PerspectiveCamera':
30773                                         object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
30774                                         if (data.focus !== undefined) object.focus = data.focus;
30775                                         if (data.zoom !== undefined) object.zoom = data.zoom;
30776                                         if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
30777                                         if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
30778                                         if (data.view !== undefined) object.view = Object.assign({}, data.view);
30779                                         break;
30780
30781                                 case 'OrthographicCamera':
30782                                         object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
30783                                         if (data.zoom !== undefined) object.zoom = data.zoom;
30784                                         if (data.view !== undefined) object.view = Object.assign({}, data.view);
30785                                         break;
30786
30787                                 case 'AmbientLight':
30788                                         object = new AmbientLight(data.color, data.intensity);
30789                                         break;
30790
30791                                 case 'DirectionalLight':
30792                                         object = new DirectionalLight(data.color, data.intensity);
30793                                         break;
30794
30795                                 case 'PointLight':
30796                                         object = new PointLight(data.color, data.intensity, data.distance, data.decay);
30797                                         break;
30798
30799                                 case 'RectAreaLight':
30800                                         object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
30801                                         break;
30802
30803                                 case 'SpotLight':
30804                                         object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
30805                                         break;
30806
30807                                 case 'HemisphereLight':
30808                                         object = new HemisphereLight(data.color, data.groundColor, data.intensity);
30809                                         break;
30810
30811                                 case 'LightProbe':
30812                                         object = new LightProbe().fromJSON(data);
30813                                         break;
30814
30815                                 case 'SkinnedMesh':
30816                                         geometry = getGeometry(data.geometry);
30817                                         material = getMaterial(data.material);
30818                                         object = new SkinnedMesh(geometry, material);
30819                                         if (data.bindMode !== undefined) object.bindMode = data.bindMode;
30820                                         if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
30821                                         if (data.skeleton !== undefined) object.skeleton = data.skeleton;
30822                                         break;
30823
30824                                 case 'Mesh':
30825                                         geometry = getGeometry(data.geometry);
30826                                         material = getMaterial(data.material);
30827                                         object = new Mesh(geometry, material);
30828                                         break;
30829
30830                                 case 'InstancedMesh':
30831                                         geometry = getGeometry(data.geometry);
30832                                         material = getMaterial(data.material);
30833                                         var count = data.count;
30834                                         var instanceMatrix = data.instanceMatrix;
30835                                         object = new InstancedMesh(geometry, material, count);
30836                                         object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
30837                                         break;
30838
30839                                 case 'LOD':
30840                                         object = new LOD();
30841                                         break;
30842
30843                                 case 'Line':
30844                                         object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
30845                                         break;
30846
30847                                 case 'LineLoop':
30848                                         object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
30849                                         break;
30850
30851                                 case 'LineSegments':
30852                                         object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
30853                                         break;
30854
30855                                 case 'PointCloud':
30856                                 case 'Points':
30857                                         object = new Points(getGeometry(data.geometry), getMaterial(data.material));
30858                                         break;
30859
30860                                 case 'Sprite':
30861                                         object = new Sprite(getMaterial(data.material));
30862                                         break;
30863
30864                                 case 'Group':
30865                                         object = new Group();
30866                                         break;
30867
30868                                 case 'Bone':
30869                                         object = new Bone();
30870                                         break;
30871
30872                                 default:
30873                                         object = new Object3D();
30874                         }
30875
30876                         object.uuid = data.uuid;
30877                         if (data.name !== undefined) object.name = data.name;
30878
30879                         if (data.matrix !== undefined) {
30880                                 object.matrix.fromArray(data.matrix);
30881                                 if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
30882                                 if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
30883                         } else {
30884                                 if (data.position !== undefined) object.position.fromArray(data.position);
30885                                 if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
30886                                 if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
30887                                 if (data.scale !== undefined) object.scale.fromArray(data.scale);
30888                         }
30889
30890                         if (data.castShadow !== undefined) object.castShadow = data.castShadow;
30891                         if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
30892
30893                         if (data.shadow) {
30894                                 if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
30895                                 if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
30896                                 if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
30897                                 if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
30898                                 if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
30899                         }
30900
30901                         if (data.visible !== undefined) object.visible = data.visible;
30902                         if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
30903                         if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
30904                         if (data.userData !== undefined) object.userData = data.userData;
30905                         if (data.layers !== undefined) object.layers.mask = data.layers;
30906
30907                         if (data.children !== undefined) {
30908                                 var children = data.children;
30909
30910                                 for (var i = 0; i < children.length; i++) {
30911                                         object.add(this.parseObject(children[i], geometries, materials, animations));
30912                                 }
30913                         }
30914
30915                         if (data.animations !== undefined) {
30916                                 var objectAnimations = data.animations;
30917
30918                                 for (var _i = 0; _i < objectAnimations.length; _i++) {
30919                                         var uuid = objectAnimations[_i];
30920                                         object.animations.push(animations[uuid]);
30921                                 }
30922                         }
30923
30924                         if (data.type === 'LOD') {
30925                                 if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
30926                                 var levels = data.levels;
30927
30928                                 for (var l = 0; l < levels.length; l++) {
30929                                         var level = levels[l];
30930                                         var child = object.getObjectByProperty('uuid', level.object);
30931
30932                                         if (child !== undefined) {
30933                                                 object.addLevel(child, level.distance);
30934                                         }
30935                                 }
30936                         }
30937
30938                         return object;
30939                 };
30940
30941                 _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
30942                         if (Object.keys(skeletons).length === 0) return;
30943                         object.traverse(function (child) {
30944                                 if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
30945                                         var skeleton = skeletons[child.skeleton];
30946
30947                                         if (skeleton === undefined) {
30948                                                 console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
30949                                         } else {
30950                                                 child.bind(skeleton, child.bindMatrix);
30951                                         }
30952                                 }
30953                         });
30954                 }
30955                 /* DEPRECATED */
30956                 ;
30957
30958                 _proto.setTexturePath = function setTexturePath(value) {
30959                         console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
30960                         return this.setResourcePath(value);
30961                 };
30962
30963                 return ObjectLoader;
30964         }(Loader);
30965
30966         var TEXTURE_MAPPING = {
30967                 UVMapping: UVMapping,
30968                 CubeReflectionMapping: CubeReflectionMapping,
30969                 CubeRefractionMapping: CubeRefractionMapping,
30970                 EquirectangularReflectionMapping: EquirectangularReflectionMapping,
30971                 EquirectangularRefractionMapping: EquirectangularRefractionMapping,
30972                 CubeUVReflectionMapping: CubeUVReflectionMapping,
30973                 CubeUVRefractionMapping: CubeUVRefractionMapping
30974         };
30975         var TEXTURE_WRAPPING = {
30976                 RepeatWrapping: RepeatWrapping,
30977                 ClampToEdgeWrapping: ClampToEdgeWrapping,
30978                 MirroredRepeatWrapping: MirroredRepeatWrapping
30979         };
30980         var TEXTURE_FILTER = {
30981                 NearestFilter: NearestFilter,
30982                 NearestMipmapNearestFilter: NearestMipmapNearestFilter,
30983                 NearestMipmapLinearFilter: NearestMipmapLinearFilter,
30984                 LinearFilter: LinearFilter,
30985                 LinearMipmapNearestFilter: LinearMipmapNearestFilter,
30986                 LinearMipmapLinearFilter: LinearMipmapLinearFilter
30987         };
30988
30989         function ImageBitmapLoader(manager) {
30990                 if (typeof createImageBitmap === 'undefined') {
30991                         console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
30992                 }
30993
30994                 if (typeof fetch === 'undefined') {
30995                         console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
30996                 }
30997
30998                 Loader.call(this, manager);
30999                 this.options = {
31000                         premultiplyAlpha: 'none'
31001                 };
31002         }
31003
31004         ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
31005                 constructor: ImageBitmapLoader,
31006                 isImageBitmapLoader: true,
31007                 setOptions: function setOptions(options) {
31008                         this.options = options;
31009                         return this;
31010                 },
31011                 load: function load(url, onLoad, onProgress, onError) {
31012                         if (url === undefined) url = '';
31013                         if (this.path !== undefined) url = this.path + url;
31014                         url = this.manager.resolveURL(url);
31015                         var scope = this;
31016                         var cached = Cache.get(url);
31017
31018                         if (cached !== undefined) {
31019                                 scope.manager.itemStart(url);
31020                                 setTimeout(function () {
31021                                         if (onLoad) onLoad(cached);
31022                                         scope.manager.itemEnd(url);
31023                                 }, 0);
31024                                 return cached;
31025                         }
31026
31027                         var fetchOptions = {};
31028                         fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
31029                         fetch(url, fetchOptions).then(function (res) {
31030                                 return res.blob();
31031                         }).then(function (blob) {
31032                                 return createImageBitmap(blob, scope.options);
31033                         }).then(function (imageBitmap) {
31034                                 Cache.add(url, imageBitmap);
31035                                 if (onLoad) onLoad(imageBitmap);
31036                                 scope.manager.itemEnd(url);
31037                         }).catch(function (e) {
31038                                 if (onError) onError(e);
31039                                 scope.manager.itemError(url);
31040                                 scope.manager.itemEnd(url);
31041                         });
31042                         scope.manager.itemStart(url);
31043                 }
31044         });
31045
31046         function ShapePath() {
31047                 this.type = 'ShapePath';
31048                 this.color = new Color();
31049                 this.subPaths = [];
31050                 this.currentPath = null;
31051         }
31052
31053         Object.assign(ShapePath.prototype, {
31054                 moveTo: function moveTo(x, y) {
31055                         this.currentPath = new Path();
31056                         this.subPaths.push(this.currentPath);
31057                         this.currentPath.moveTo(x, y);
31058                         return this;
31059                 },
31060                 lineTo: function lineTo(x, y) {
31061                         this.currentPath.lineTo(x, y);
31062                         return this;
31063                 },
31064                 quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
31065                         this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
31066                         return this;
31067                 },
31068                 bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
31069                         this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
31070                         return this;
31071                 },
31072                 splineThru: function splineThru(pts) {
31073                         this.currentPath.splineThru(pts);
31074                         return this;
31075                 },
31076                 toShapes: function toShapes(isCCW, noHoles) {
31077                         function toShapesNoHoles(inSubpaths) {
31078                                 var shapes = [];
31079
31080                                 for (var i = 0, l = inSubpaths.length; i < l; i++) {
31081                                         var _tmpPath = inSubpaths[i];
31082
31083                                         var _tmpShape = new Shape();
31084
31085                                         _tmpShape.curves = _tmpPath.curves;
31086                                         shapes.push(_tmpShape);
31087                                 }
31088
31089                                 return shapes;
31090                         }
31091
31092                         function isPointInsidePolygon(inPt, inPolygon) {
31093                                 var polyLen = inPolygon.length; // inPt on polygon contour => immediate success         or
31094                                 // toggling of inside/outside at every single! intersection point of an edge
31095                                 //      with the horizontal line through inPt, left of inPt
31096                                 //      not counting lowerY endpoints of edges and whole edges on that line
31097
31098                                 var inside = false;
31099
31100                                 for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
31101                                         var edgeLowPt = inPolygon[p];
31102                                         var edgeHighPt = inPolygon[q];
31103                                         var edgeDx = edgeHighPt.x - edgeLowPt.x;
31104                                         var edgeDy = edgeHighPt.y - edgeLowPt.y;
31105
31106                                         if (Math.abs(edgeDy) > Number.EPSILON) {
31107                                                 // not parallel
31108                                                 if (edgeDy < 0) {
31109                                                         edgeLowPt = inPolygon[q];
31110                                                         edgeDx = -edgeDx;
31111                                                         edgeHighPt = inPolygon[p];
31112                                                         edgeDy = -edgeDy;
31113                                                 }
31114
31115                                                 if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
31116
31117                                                 if (inPt.y === edgeLowPt.y) {
31118                                                         if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
31119                                                         // continue;                            // no intersection or edgeLowPt => doesn't count !!!
31120                                                 } else {
31121                                                         var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
31122                                                         if (perpEdge === 0) return true; // inPt is on contour ?
31123
31124                                                         if (perpEdge < 0) continue;
31125                                                         inside = !inside; // true intersection left of inPt
31126                                                 }
31127                                         } else {
31128                                                 // parallel or collinear
31129                                                 if (inPt.y !== edgeLowPt.y) continue; // parallel
31130                                                 // edge lies on the same horizontal line as inPt
31131
31132                                                 if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
31133                                                 // continue;
31134                                         }
31135                                 }
31136
31137                                 return inside;
31138                         }
31139
31140                         var isClockWise = ShapeUtils.isClockWise;
31141                         var subPaths = this.subPaths;
31142                         if (subPaths.length === 0) return [];
31143                         if (noHoles === true) return toShapesNoHoles(subPaths);
31144                         var solid, tmpPath, tmpShape;
31145                         var shapes = [];
31146
31147                         if (subPaths.length === 1) {
31148                                 tmpPath = subPaths[0];
31149                                 tmpShape = new Shape();
31150                                 tmpShape.curves = tmpPath.curves;
31151                                 shapes.push(tmpShape);
31152                                 return shapes;
31153                         }
31154
31155                         var holesFirst = !isClockWise(subPaths[0].getPoints());
31156                         holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
31157
31158                         var betterShapeHoles = [];
31159                         var newShapes = [];
31160                         var newShapeHoles = [];
31161                         var mainIdx = 0;
31162                         var tmpPoints;
31163                         newShapes[mainIdx] = undefined;
31164                         newShapeHoles[mainIdx] = [];
31165
31166                         for (var i = 0, l = subPaths.length; i < l; i++) {
31167                                 tmpPath = subPaths[i];
31168                                 tmpPoints = tmpPath.getPoints();
31169                                 solid = isClockWise(tmpPoints);
31170                                 solid = isCCW ? !solid : solid;
31171
31172                                 if (solid) {
31173                                         if (!holesFirst && newShapes[mainIdx]) mainIdx++;
31174                                         newShapes[mainIdx] = {
31175                                                 s: new Shape(),
31176                                                 p: tmpPoints
31177                                         };
31178                                         newShapes[mainIdx].s.curves = tmpPath.curves;
31179                                         if (holesFirst) mainIdx++;
31180                                         newShapeHoles[mainIdx] = []; //console.log('cw', i);
31181                                 } else {
31182                                         newShapeHoles[mainIdx].push({
31183                                                 h: tmpPath,
31184                                                 p: tmpPoints[0]
31185                                         }); //console.log('ccw', i);
31186                                 }
31187                         } // only Holes? -> probably all Shapes with wrong orientation
31188
31189
31190                         if (!newShapes[0]) return toShapesNoHoles(subPaths);
31191
31192                         if (newShapes.length > 1) {
31193                                 var ambiguous = false;
31194                                 var toChange = [];
31195
31196                                 for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
31197                                         betterShapeHoles[sIdx] = [];
31198                                 }
31199
31200                                 for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
31201                                         var sho = newShapeHoles[_sIdx];
31202
31203                                         for (var hIdx = 0; hIdx < sho.length; hIdx++) {
31204                                                 var ho = sho[hIdx];
31205                                                 var hole_unassigned = true;
31206
31207                                                 for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
31208                                                         if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
31209                                                                 if (_sIdx !== s2Idx) toChange.push({
31210                                                                         froms: _sIdx,
31211                                                                         tos: s2Idx,
31212                                                                         hole: hIdx
31213                                                                 });
31214
31215                                                                 if (hole_unassigned) {
31216                                                                         hole_unassigned = false;
31217                                                                         betterShapeHoles[s2Idx].push(ho);
31218                                                                 } else {
31219                                                                         ambiguous = true;
31220                                                                 }
31221                                                         }
31222                                                 }
31223
31224                                                 if (hole_unassigned) {
31225                                                         betterShapeHoles[_sIdx].push(ho);
31226                                                 }
31227                                         }
31228                                 } // console.log("ambiguous: ", ambiguous);
31229
31230
31231                                 if (toChange.length > 0) {
31232                                         // console.log("to change: ", toChange);
31233                                         if (!ambiguous) newShapeHoles = betterShapeHoles;
31234                                 }
31235                         }
31236
31237                         var tmpHoles;
31238
31239                         for (var _i = 0, il = newShapes.length; _i < il; _i++) {
31240                                 tmpShape = newShapes[_i].s;
31241                                 shapes.push(tmpShape);
31242                                 tmpHoles = newShapeHoles[_i];
31243
31244                                 for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
31245                                         tmpShape.holes.push(tmpHoles[j].h);
31246                                 }
31247                         } //console.log("shape", shapes);
31248
31249
31250                         return shapes;
31251                 }
31252         });
31253
31254         function Font(data) {
31255                 this.type = 'Font';
31256                 this.data = data;
31257         }
31258
31259         Object.assign(Font.prototype, {
31260                 isFont: true,
31261                 generateShapes: function generateShapes(text, size) {
31262                         if (size === void 0) {
31263                                 size = 100;
31264                         }
31265
31266                         var shapes = [];
31267                         var paths = createPaths(text, size, this.data);
31268
31269                         for (var p = 0, pl = paths.length; p < pl; p++) {
31270                                 Array.prototype.push.apply(shapes, paths[p].toShapes());
31271                         }
31272
31273                         return shapes;
31274                 }
31275         });
31276
31277         function createPaths(text, size, data) {
31278                 var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
31279
31280                 var scale = size / data.resolution;
31281                 var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
31282                 var paths = [];
31283                 var offsetX = 0,
31284                                 offsetY = 0;
31285
31286                 for (var i = 0; i < chars.length; i++) {
31287                         var char = chars[i];
31288
31289                         if (char === '\n') {
31290                                 offsetX = 0;
31291                                 offsetY -= line_height;
31292                         } else {
31293                                 var ret = createPath(char, scale, offsetX, offsetY, data);
31294                                 offsetX += ret.offsetX;
31295                                 paths.push(ret.path);
31296                         }
31297                 }
31298
31299                 return paths;
31300         }
31301
31302         function createPath(char, scale, offsetX, offsetY, data) {
31303                 var glyph = data.glyphs[char] || data.glyphs['?'];
31304
31305                 if (!glyph) {
31306                         console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
31307                         return;
31308                 }
31309
31310                 var path = new ShapePath();
31311                 var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
31312
31313                 if (glyph.o) {
31314                         var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
31315
31316                         for (var i = 0, l = outline.length; i < l;) {
31317                                 var action = outline[i++];
31318
31319                                 switch (action) {
31320                                         case 'm':
31321                                                 // moveTo
31322                                                 x = outline[i++] * scale + offsetX;
31323                                                 y = outline[i++] * scale + offsetY;
31324                                                 path.moveTo(x, y);
31325                                                 break;
31326
31327                                         case 'l':
31328                                                 // lineTo
31329                                                 x = outline[i++] * scale + offsetX;
31330                                                 y = outline[i++] * scale + offsetY;
31331                                                 path.lineTo(x, y);
31332                                                 break;
31333
31334                                         case 'q':
31335                                                 // quadraticCurveTo
31336                                                 cpx = outline[i++] * scale + offsetX;
31337                                                 cpy = outline[i++] * scale + offsetY;
31338                                                 cpx1 = outline[i++] * scale + offsetX;
31339                                                 cpy1 = outline[i++] * scale + offsetY;
31340                                                 path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
31341                                                 break;
31342
31343                                         case 'b':
31344                                                 // bezierCurveTo
31345                                                 cpx = outline[i++] * scale + offsetX;
31346                                                 cpy = outline[i++] * scale + offsetY;
31347                                                 cpx1 = outline[i++] * scale + offsetX;
31348                                                 cpy1 = outline[i++] * scale + offsetY;
31349                                                 cpx2 = outline[i++] * scale + offsetX;
31350                                                 cpy2 = outline[i++] * scale + offsetY;
31351                                                 path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
31352                                                 break;
31353                                 }
31354                         }
31355                 }
31356
31357                 return {
31358                         offsetX: glyph.ha * scale,
31359                         path: path
31360                 };
31361         }
31362
31363         function FontLoader(manager) {
31364                 Loader.call(this, manager);
31365         }
31366
31367         FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
31368                 constructor: FontLoader,
31369                 load: function load(url, onLoad, onProgress, onError) {
31370                         var scope = this;
31371                         var loader = new FileLoader(this.manager);
31372                         loader.setPath(this.path);
31373                         loader.setRequestHeader(this.requestHeader);
31374                         loader.setWithCredentials(scope.withCredentials);
31375                         loader.load(url, function (text) {
31376                                 var json;
31377
31378                                 try {
31379                                         json = JSON.parse(text);
31380                                 } catch (e) {
31381                                         console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
31382                                         json = JSON.parse(text.substring(65, text.length - 2));
31383                                 }
31384
31385                                 var font = scope.parse(json);
31386                                 if (onLoad) onLoad(font);
31387                         }, onProgress, onError);
31388                 },
31389                 parse: function parse(json) {
31390                         return new Font(json);
31391                 }
31392         });
31393
31394         var _context;
31395
31396         var AudioContext = {
31397                 getContext: function getContext() {
31398                         if (_context === undefined) {
31399                                 _context = new (window.AudioContext || window.webkitAudioContext)();
31400                         }
31401
31402                         return _context;
31403                 },
31404                 setContext: function setContext(value) {
31405                         _context = value;
31406                 }
31407         };
31408
31409         function AudioLoader(manager) {
31410                 Loader.call(this, manager);
31411         }
31412
31413         AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
31414                 constructor: AudioLoader,
31415                 load: function load(url, onLoad, onProgress, onError) {
31416                         var scope = this;
31417                         var loader = new FileLoader(scope.manager);
31418                         loader.setResponseType('arraybuffer');
31419                         loader.setPath(scope.path);
31420                         loader.setRequestHeader(scope.requestHeader);
31421                         loader.setWithCredentials(scope.withCredentials);
31422                         loader.load(url, function (buffer) {
31423                                 try {
31424                                         // Create a copy of the buffer. The `decodeAudioData` method
31425                                         // detaches the buffer when complete, preventing reuse.
31426                                         var bufferCopy = buffer.slice(0);
31427                                         var context = AudioContext.getContext();
31428                                         context.decodeAudioData(bufferCopy, function (audioBuffer) {
31429                                                 onLoad(audioBuffer);
31430                                         });
31431                                 } catch (e) {
31432                                         if (onError) {
31433                                                 onError(e);
31434                                         } else {
31435                                                 console.error(e);
31436                                         }
31437
31438                                         scope.manager.itemError(url);
31439                                 }
31440                         }, onProgress, onError);
31441                 }
31442         });
31443
31444         function HemisphereLightProbe(skyColor, groundColor, intensity) {
31445                 LightProbe.call(this, undefined, intensity);
31446                 var color1 = new Color().set(skyColor);
31447                 var color2 = new Color().set(groundColor);
31448                 var sky = new Vector3(color1.r, color1.g, color1.b);
31449                 var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
31450
31451                 var c0 = Math.sqrt(Math.PI);
31452                 var c1 = c0 * Math.sqrt(0.75);
31453                 this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
31454                 this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
31455         }
31456
31457         HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
31458                 constructor: HemisphereLightProbe,
31459                 isHemisphereLightProbe: true,
31460                 copy: function copy(source) {
31461                         // modifying colors not currently supported
31462                         LightProbe.prototype.copy.call(this, source);
31463                         return this;
31464                 },
31465                 toJSON: function toJSON(meta) {
31466                         var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
31467
31468                         return data;
31469                 }
31470         });
31471
31472         function AmbientLightProbe(color, intensity) {
31473                 LightProbe.call(this, undefined, intensity);
31474                 var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
31475
31476                 this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
31477         }
31478
31479         AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
31480                 constructor: AmbientLightProbe,
31481                 isAmbientLightProbe: true,
31482                 copy: function copy(source) {
31483                         // modifying color not currently supported
31484                         LightProbe.prototype.copy.call(this, source);
31485                         return this;
31486                 },
31487                 toJSON: function toJSON(meta) {
31488                         var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
31489
31490                         return data;
31491                 }
31492         });
31493
31494         var _eyeRight = new Matrix4();
31495
31496         var _eyeLeft = new Matrix4();
31497
31498         function StereoCamera() {
31499                 this.type = 'StereoCamera';
31500                 this.aspect = 1;
31501                 this.eyeSep = 0.064;
31502                 this.cameraL = new PerspectiveCamera();
31503                 this.cameraL.layers.enable(1);
31504                 this.cameraL.matrixAutoUpdate = false;
31505                 this.cameraR = new PerspectiveCamera();
31506                 this.cameraR.layers.enable(2);
31507                 this.cameraR.matrixAutoUpdate = false;
31508                 this._cache = {
31509                         focus: null,
31510                         fov: null,
31511                         aspect: null,
31512                         near: null,
31513                         far: null,
31514                         zoom: null,
31515                         eyeSep: null
31516                 };
31517         }
31518
31519         Object.assign(StereoCamera.prototype, {
31520                 update: function update(camera) {
31521                         var cache = this._cache;
31522                         var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov || cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near || cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
31523
31524                         if (needsUpdate) {
31525                                 cache.focus = camera.focus;
31526                                 cache.fov = camera.fov;
31527                                 cache.aspect = camera.aspect * this.aspect;
31528                                 cache.near = camera.near;
31529                                 cache.far = camera.far;
31530                                 cache.zoom = camera.zoom;
31531                                 cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
31532                                 // http://paulbourke.net/stereographics/stereorender/
31533
31534                                 var projectionMatrix = camera.projectionMatrix.clone();
31535                                 var eyeSepHalf = cache.eyeSep / 2;
31536                                 var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
31537                                 var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
31538                                 var xmin, xmax; // translate xOffset
31539
31540                                 _eyeLeft.elements[12] = -eyeSepHalf;
31541                                 _eyeRight.elements[12] = eyeSepHalf; // for left eye
31542
31543                                 xmin = -ymax * cache.aspect + eyeSepOnProjection;
31544                                 xmax = ymax * cache.aspect + eyeSepOnProjection;
31545                                 projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
31546                                 projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
31547                                 this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
31548
31549                                 xmin = -ymax * cache.aspect - eyeSepOnProjection;
31550                                 xmax = ymax * cache.aspect - eyeSepOnProjection;
31551                                 projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
31552                                 projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
31553                                 this.cameraR.projectionMatrix.copy(projectionMatrix);
31554                         }
31555
31556                         this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
31557                         this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
31558                 }
31559         });
31560
31561         var Clock = /*#__PURE__*/function () {
31562                 function Clock(autoStart) {
31563                         this.autoStart = autoStart !== undefined ? autoStart : true;
31564                         this.startTime = 0;
31565                         this.oldTime = 0;
31566                         this.elapsedTime = 0;
31567                         this.running = false;
31568                 }
31569
31570                 var _proto = Clock.prototype;
31571
31572                 _proto.start = function start() {
31573                         this.startTime = now();
31574                         this.oldTime = this.startTime;
31575                         this.elapsedTime = 0;
31576                         this.running = true;
31577                 };
31578
31579                 _proto.stop = function stop() {
31580                         this.getElapsedTime();
31581                         this.running = false;
31582                         this.autoStart = false;
31583                 };
31584
31585                 _proto.getElapsedTime = function getElapsedTime() {
31586                         this.getDelta();
31587                         return this.elapsedTime;
31588                 };
31589
31590                 _proto.getDelta = function getDelta() {
31591                         var diff = 0;
31592
31593                         if (this.autoStart && !this.running) {
31594                                 this.start();
31595                                 return 0;
31596                         }
31597
31598                         if (this.running) {
31599                                 var newTime = now();
31600                                 diff = (newTime - this.oldTime) / 1000;
31601                                 this.oldTime = newTime;
31602                                 this.elapsedTime += diff;
31603                         }
31604
31605                         return diff;
31606                 };
31607
31608                 return Clock;
31609         }();
31610
31611         function now() {
31612                 return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
31613         }
31614
31615         var _position$2 = /*@__PURE__*/new Vector3();
31616
31617         var _quaternion$3 = /*@__PURE__*/new Quaternion();
31618
31619         var _scale$1 = /*@__PURE__*/new Vector3();
31620
31621         var _orientation = /*@__PURE__*/new Vector3();
31622
31623         var AudioListener = /*#__PURE__*/function (_Object3D) {
31624                 _inheritsLoose(AudioListener, _Object3D);
31625
31626                 function AudioListener() {
31627                         var _this;
31628
31629                         _this = _Object3D.call(this) || this;
31630                         _this.type = 'AudioListener';
31631                         _this.context = AudioContext.getContext();
31632                         _this.gain = _this.context.createGain();
31633
31634                         _this.gain.connect(_this.context.destination);
31635
31636                         _this.filter = null;
31637                         _this.timeDelta = 0; // private
31638
31639                         _this._clock = new Clock();
31640                         return _this;
31641                 }
31642
31643                 var _proto = AudioListener.prototype;
31644
31645                 _proto.getInput = function getInput() {
31646                         return this.gain;
31647                 };
31648
31649                 _proto.removeFilter = function removeFilter() {
31650                         if (this.filter !== null) {
31651                                 this.gain.disconnect(this.filter);
31652                                 this.filter.disconnect(this.context.destination);
31653                                 this.gain.connect(this.context.destination);
31654                                 this.filter = null;
31655                         }
31656
31657                         return this;
31658                 };
31659
31660                 _proto.getFilter = function getFilter() {
31661                         return this.filter;
31662                 };
31663
31664                 _proto.setFilter = function setFilter(value) {
31665                         if (this.filter !== null) {
31666                                 this.gain.disconnect(this.filter);
31667                                 this.filter.disconnect(this.context.destination);
31668                         } else {
31669                                 this.gain.disconnect(this.context.destination);
31670                         }
31671
31672                         this.filter = value;
31673                         this.gain.connect(this.filter);
31674                         this.filter.connect(this.context.destination);
31675                         return this;
31676                 };
31677
31678                 _proto.getMasterVolume = function getMasterVolume() {
31679                         return this.gain.gain.value;
31680                 };
31681
31682                 _proto.setMasterVolume = function setMasterVolume(value) {
31683                         this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
31684                         return this;
31685                 };
31686
31687                 _proto.updateMatrixWorld = function updateMatrixWorld(force) {
31688                         _Object3D.prototype.updateMatrixWorld.call(this, force);
31689
31690                         var listener = this.context.listener;
31691                         var up = this.up;
31692                         this.timeDelta = this._clock.getDelta();
31693                         this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
31694
31695                         _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
31696
31697                         if (listener.positionX) {
31698                                 // code path for Chrome (see #14393)
31699                                 var endTime = this.context.currentTime + this.timeDelta;
31700                                 listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
31701                                 listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
31702                                 listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
31703                                 listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
31704                                 listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
31705                                 listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
31706                                 listener.upX.linearRampToValueAtTime(up.x, endTime);
31707                                 listener.upY.linearRampToValueAtTime(up.y, endTime);
31708                                 listener.upZ.linearRampToValueAtTime(up.z, endTime);
31709                         } else {
31710                                 listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
31711                                 listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
31712                         }
31713                 };
31714
31715                 return AudioListener;
31716         }(Object3D);
31717
31718         var Audio = /*#__PURE__*/function (_Object3D) {
31719                 _inheritsLoose(Audio, _Object3D);
31720
31721                 function Audio(listener) {
31722                         var _this;
31723
31724                         _this = _Object3D.call(this) || this;
31725                         _this.type = 'Audio';
31726                         _this.listener = listener;
31727                         _this.context = listener.context;
31728                         _this.gain = _this.context.createGain();
31729
31730                         _this.gain.connect(listener.getInput());
31731
31732                         _this.autoplay = false;
31733                         _this.buffer = null;
31734                         _this.detune = 0;
31735                         _this.loop = false;
31736                         _this.loopStart = 0;
31737                         _this.loopEnd = 0;
31738                         _this.offset = 0;
31739                         _this.duration = undefined;
31740                         _this.playbackRate = 1;
31741                         _this.isPlaying = false;
31742                         _this.hasPlaybackControl = true;
31743                         _this.source = null;
31744                         _this.sourceType = 'empty';
31745                         _this._startedAt = 0;
31746                         _this._progress = 0;
31747                         _this._connected = false;
31748                         _this.filters = [];
31749                         return _this;
31750                 }
31751
31752                 var _proto = Audio.prototype;
31753
31754                 _proto.getOutput = function getOutput() {
31755                         return this.gain;
31756                 };
31757
31758                 _proto.setNodeSource = function setNodeSource(audioNode) {
31759                         this.hasPlaybackControl = false;
31760                         this.sourceType = 'audioNode';
31761                         this.source = audioNode;
31762                         this.connect();
31763                         return this;
31764                 };
31765
31766                 _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
31767                         this.hasPlaybackControl = false;
31768                         this.sourceType = 'mediaNode';
31769                         this.source = this.context.createMediaElementSource(mediaElement);
31770                         this.connect();
31771                         return this;
31772                 };
31773
31774                 _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
31775                         this.hasPlaybackControl = false;
31776                         this.sourceType = 'mediaStreamNode';
31777                         this.source = this.context.createMediaStreamSource(mediaStream);
31778                         this.connect();
31779                         return this;
31780                 };
31781
31782                 _proto.setBuffer = function setBuffer(audioBuffer) {
31783                         this.buffer = audioBuffer;
31784                         this.sourceType = 'buffer';
31785                         if (this.autoplay) this.play();
31786                         return this;
31787                 };
31788
31789                 _proto.play = function play(delay) {
31790                         if (delay === void 0) {
31791                                 delay = 0;
31792                         }
31793
31794                         if (this.isPlaying === true) {
31795                                 console.warn('THREE.Audio: Audio is already playing.');
31796                                 return;
31797                         }
31798
31799                         if (this.hasPlaybackControl === false) {
31800                                 console.warn('THREE.Audio: this Audio has no playback control.');
31801                                 return;
31802                         }
31803
31804                         this._startedAt = this.context.currentTime + delay;
31805                         var source = this.context.createBufferSource();
31806                         source.buffer = this.buffer;
31807                         source.loop = this.loop;
31808                         source.loopStart = this.loopStart;
31809                         source.loopEnd = this.loopEnd;
31810                         source.onended = this.onEnded.bind(this);
31811                         source.start(this._startedAt, this._progress + this.offset, this.duration);
31812                         this.isPlaying = true;
31813                         this.source = source;
31814                         this.setDetune(this.detune);
31815                         this.setPlaybackRate(this.playbackRate);
31816                         return this.connect();
31817                 };
31818
31819                 _proto.pause = function pause() {
31820                         if (this.hasPlaybackControl === false) {
31821                                 console.warn('THREE.Audio: this Audio has no playback control.');
31822                                 return;
31823                         }
31824
31825                         if (this.isPlaying === true) {
31826                                 // update current progress
31827                                 this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
31828
31829                                 if (this.loop === true) {
31830                                         // ensure _progress does not exceed duration with looped audios
31831                                         this._progress = this._progress % (this.duration || this.buffer.duration);
31832                                 }
31833
31834                                 this.source.stop();
31835                                 this.source.onended = null;
31836                                 this.isPlaying = false;
31837                         }
31838
31839                         return this;
31840                 };
31841
31842                 _proto.stop = function stop() {
31843                         if (this.hasPlaybackControl === false) {
31844                                 console.warn('THREE.Audio: this Audio has no playback control.');
31845                                 return;
31846                         }
31847
31848                         this._progress = 0;
31849                         this.source.stop();
31850                         this.source.onended = null;
31851                         this.isPlaying = false;
31852                         return this;
31853                 };
31854
31855                 _proto.connect = function connect() {
31856                         if (this.filters.length > 0) {
31857                                 this.source.connect(this.filters[0]);
31858
31859                                 for (var i = 1, l = this.filters.length; i < l; i++) {
31860                                         this.filters[i - 1].connect(this.filters[i]);
31861                                 }
31862
31863                                 this.filters[this.filters.length - 1].connect(this.getOutput());
31864                         } else {
31865                                 this.source.connect(this.getOutput());
31866                         }
31867
31868                         this._connected = true;
31869                         return this;
31870                 };
31871
31872                 _proto.disconnect = function disconnect() {
31873                         if (this.filters.length > 0) {
31874                                 this.source.disconnect(this.filters[0]);
31875
31876                                 for (var i = 1, l = this.filters.length; i < l; i++) {
31877                                         this.filters[i - 1].disconnect(this.filters[i]);
31878                                 }
31879
31880                                 this.filters[this.filters.length - 1].disconnect(this.getOutput());
31881                         } else {
31882                                 this.source.disconnect(this.getOutput());
31883                         }
31884
31885                         this._connected = false;
31886                         return this;
31887                 };
31888
31889                 _proto.getFilters = function getFilters() {
31890                         return this.filters;
31891                 };
31892
31893                 _proto.setFilters = function setFilters(value) {
31894                         if (!value) value = [];
31895
31896                         if (this._connected === true) {
31897                                 this.disconnect();
31898                                 this.filters = value.slice();
31899                                 this.connect();
31900                         } else {
31901                                 this.filters = value.slice();
31902                         }
31903
31904                         return this;
31905                 };
31906
31907                 _proto.setDetune = function setDetune(value) {
31908                         this.detune = value;
31909                         if (this.source.detune === undefined) return; // only set detune when available
31910
31911                         if (this.isPlaying === true) {
31912                                 this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
31913                         }
31914
31915                         return this;
31916                 };
31917
31918                 _proto.getDetune = function getDetune() {
31919                         return this.detune;
31920                 };
31921
31922                 _proto.getFilter = function getFilter() {
31923                         return this.getFilters()[0];
31924                 };
31925
31926                 _proto.setFilter = function setFilter(filter) {
31927                         return this.setFilters(filter ? [filter] : []);
31928                 };
31929
31930                 _proto.setPlaybackRate = function setPlaybackRate(value) {
31931                         if (this.hasPlaybackControl === false) {
31932                                 console.warn('THREE.Audio: this Audio has no playback control.');
31933                                 return;
31934                         }
31935
31936                         this.playbackRate = value;
31937
31938                         if (this.isPlaying === true) {
31939                                 this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
31940                         }
31941
31942                         return this;
31943                 };
31944
31945                 _proto.getPlaybackRate = function getPlaybackRate() {
31946                         return this.playbackRate;
31947                 };
31948
31949                 _proto.onEnded = function onEnded() {
31950                         this.isPlaying = false;
31951                 };
31952
31953                 _proto.getLoop = function getLoop() {
31954                         if (this.hasPlaybackControl === false) {
31955                                 console.warn('THREE.Audio: this Audio has no playback control.');
31956                                 return false;
31957                         }
31958
31959                         return this.loop;
31960                 };
31961
31962                 _proto.setLoop = function setLoop(value) {
31963                         if (this.hasPlaybackControl === false) {
31964                                 console.warn('THREE.Audio: this Audio has no playback control.');
31965                                 return;
31966                         }
31967
31968                         this.loop = value;
31969
31970                         if (this.isPlaying === true) {
31971                                 this.source.loop = this.loop;
31972                         }
31973
31974                         return this;
31975                 };
31976
31977                 _proto.setLoopStart = function setLoopStart(value) {
31978                         this.loopStart = value;
31979                         return this;
31980                 };
31981
31982                 _proto.setLoopEnd = function setLoopEnd(value) {
31983                         this.loopEnd = value;
31984                         return this;
31985                 };
31986
31987                 _proto.getVolume = function getVolume() {
31988                         return this.gain.gain.value;
31989                 };
31990
31991                 _proto.setVolume = function setVolume(value) {
31992                         this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
31993                         return this;
31994                 };
31995
31996                 return Audio;
31997         }(Object3D);
31998
31999         var _position$3 = /*@__PURE__*/new Vector3();
32000
32001         var _quaternion$4 = /*@__PURE__*/new Quaternion();
32002
32003         var _scale$2 = /*@__PURE__*/new Vector3();
32004
32005         var _orientation$1 = /*@__PURE__*/new Vector3();
32006
32007         var PositionalAudio = /*#__PURE__*/function (_Audio) {
32008                 _inheritsLoose(PositionalAudio, _Audio);
32009
32010                 function PositionalAudio(listener) {
32011                         var _this;
32012
32013                         _this = _Audio.call(this, listener) || this;
32014                         _this.panner = _this.context.createPanner();
32015                         _this.panner.panningModel = 'HRTF';
32016
32017                         _this.panner.connect(_this.gain);
32018
32019                         return _this;
32020                 }
32021
32022                 var _proto = PositionalAudio.prototype;
32023
32024                 _proto.getOutput = function getOutput() {
32025                         return this.panner;
32026                 };
32027
32028                 _proto.getRefDistance = function getRefDistance() {
32029                         return this.panner.refDistance;
32030                 };
32031
32032                 _proto.setRefDistance = function setRefDistance(value) {
32033                         this.panner.refDistance = value;
32034                         return this;
32035                 };
32036
32037                 _proto.getRolloffFactor = function getRolloffFactor() {
32038                         return this.panner.rolloffFactor;
32039                 };
32040
32041                 _proto.setRolloffFactor = function setRolloffFactor(value) {
32042                         this.panner.rolloffFactor = value;
32043                         return this;
32044                 };
32045
32046                 _proto.getDistanceModel = function getDistanceModel() {
32047                         return this.panner.distanceModel;
32048                 };
32049
32050                 _proto.setDistanceModel = function setDistanceModel(value) {
32051                         this.panner.distanceModel = value;
32052                         return this;
32053                 };
32054
32055                 _proto.getMaxDistance = function getMaxDistance() {
32056                         return this.panner.maxDistance;
32057                 };
32058
32059                 _proto.setMaxDistance = function setMaxDistance(value) {
32060                         this.panner.maxDistance = value;
32061                         return this;
32062                 };
32063
32064                 _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
32065                         this.panner.coneInnerAngle = coneInnerAngle;
32066                         this.panner.coneOuterAngle = coneOuterAngle;
32067                         this.panner.coneOuterGain = coneOuterGain;
32068                         return this;
32069                 };
32070
32071                 _proto.updateMatrixWorld = function updateMatrixWorld(force) {
32072                         _Audio.prototype.updateMatrixWorld.call(this, force);
32073
32074                         if (this.hasPlaybackControl === true && this.isPlaying === false) return;
32075                         this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
32076
32077                         _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
32078
32079                         var panner = this.panner;
32080
32081                         if (panner.positionX) {
32082                                 // code path for Chrome and Firefox (see #14393)
32083                                 var endTime = this.context.currentTime + this.listener.timeDelta;
32084                                 panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
32085                                 panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
32086                                 panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
32087                                 panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
32088                                 panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
32089                                 panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
32090                         } else {
32091                                 panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
32092                                 panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
32093                         }
32094                 };
32095
32096                 return PositionalAudio;
32097         }(Audio);
32098
32099         var AudioAnalyser = /*#__PURE__*/function () {
32100                 function AudioAnalyser(audio, fftSize) {
32101                         if (fftSize === void 0) {
32102                                 fftSize = 2048;
32103                         }
32104
32105                         this.analyser = audio.context.createAnalyser();
32106                         this.analyser.fftSize = fftSize;
32107                         this.data = new Uint8Array(this.analyser.frequencyBinCount);
32108                         audio.getOutput().connect(this.analyser);
32109                 }
32110
32111                 var _proto = AudioAnalyser.prototype;
32112
32113                 _proto.getFrequencyData = function getFrequencyData() {
32114                         this.analyser.getByteFrequencyData(this.data);
32115                         return this.data;
32116                 };
32117
32118                 _proto.getAverageFrequency = function getAverageFrequency() {
32119                         var value = 0;
32120                         var data = this.getFrequencyData();
32121
32122                         for (var i = 0; i < data.length; i++) {
32123                                 value += data[i];
32124                         }
32125
32126                         return value / data.length;
32127                 };
32128
32129                 return AudioAnalyser;
32130         }();
32131
32132         function PropertyMixer(binding, typeName, valueSize) {
32133                 this.binding = binding;
32134                 this.valueSize = valueSize;
32135                 var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
32136                 //
32137                 // interpolators can use .buffer as their .result
32138                 // the data then goes to 'incoming'
32139                 //
32140                 // 'accu0' and 'accu1' are used frame-interleaved for
32141                 // the cumulative result and are compared to detect
32142                 // changes
32143                 //
32144                 // 'orig' stores the original state of the property
32145                 //
32146                 // 'add' is used for additive cumulative results
32147                 //
32148                 // 'work' is optional and is only present for quaternion types. It is used
32149                 // to store intermediate quaternion multiplication results
32150
32151                 switch (typeName) {
32152                         case 'quaternion':
32153                                 mixFunction = this._slerp;
32154                                 mixFunctionAdditive = this._slerpAdditive;
32155                                 setIdentity = this._setAdditiveIdentityQuaternion;
32156                                 this.buffer = new Float64Array(valueSize * 6);
32157                                 this._workIndex = 5;
32158                                 break;
32159
32160                         case 'string':
32161                         case 'bool':
32162                                 mixFunction = this._select; // Use the regular mix function and for additive on these types,
32163                                 // additive is not relevant for non-numeric types
32164
32165                                 mixFunctionAdditive = this._select;
32166                                 setIdentity = this._setAdditiveIdentityOther;
32167                                 this.buffer = new Array(valueSize * 5);
32168                                 break;
32169
32170                         default:
32171                                 mixFunction = this._lerp;
32172                                 mixFunctionAdditive = this._lerpAdditive;
32173                                 setIdentity = this._setAdditiveIdentityNumeric;
32174                                 this.buffer = new Float64Array(valueSize * 5);
32175                 }
32176
32177                 this._mixBufferRegion = mixFunction;
32178                 this._mixBufferRegionAdditive = mixFunctionAdditive;
32179                 this._setIdentity = setIdentity;
32180                 this._origIndex = 3;
32181                 this._addIndex = 4;
32182                 this.cumulativeWeight = 0;
32183                 this.cumulativeWeightAdditive = 0;
32184                 this.useCount = 0;
32185                 this.referenceCount = 0;
32186         }
32187
32188         Object.assign(PropertyMixer.prototype, {
32189                 // accumulate data in the 'incoming' region into 'accu<i>'
32190                 accumulate: function accumulate(accuIndex, weight) {
32191                         // note: happily accumulating nothing when weight = 0, the caller knows
32192                         // the weight and shouldn't have made the call in the first place
32193                         var buffer = this.buffer,
32194                                         stride = this.valueSize,
32195                                         offset = accuIndex * stride + stride;
32196                         var currentWeight = this.cumulativeWeight;
32197
32198                         if (currentWeight === 0) {
32199                                 // accuN := incoming * weight
32200                                 for (var i = 0; i !== stride; ++i) {
32201                                         buffer[offset + i] = buffer[i];
32202                                 }
32203
32204                                 currentWeight = weight;
32205                         } else {
32206                                 // accuN := accuN + incoming * weight
32207                                 currentWeight += weight;
32208                                 var mix = weight / currentWeight;
32209
32210                                 this._mixBufferRegion(buffer, offset, 0, mix, stride);
32211                         }
32212
32213                         this.cumulativeWeight = currentWeight;
32214                 },
32215                 // accumulate data in the 'incoming' region into 'add'
32216                 accumulateAdditive: function accumulateAdditive(weight) {
32217                         var buffer = this.buffer,
32218                                         stride = this.valueSize,
32219                                         offset = stride * this._addIndex;
32220
32221                         if (this.cumulativeWeightAdditive === 0) {
32222                                 // add = identity
32223                                 this._setIdentity();
32224                         } // add := add + incoming * weight
32225
32226
32227                         this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
32228
32229                         this.cumulativeWeightAdditive += weight;
32230                 },
32231                 // apply the state of 'accu<i>' to the binding when accus differ
32232                 apply: function apply(accuIndex) {
32233                         var stride = this.valueSize,
32234                                         buffer = this.buffer,
32235                                         offset = accuIndex * stride + stride,
32236                                         weight = this.cumulativeWeight,
32237                                         weightAdditive = this.cumulativeWeightAdditive,
32238                                         binding = this.binding;
32239                         this.cumulativeWeight = 0;
32240                         this.cumulativeWeightAdditive = 0;
32241
32242                         if (weight < 1) {
32243                                 // accuN := accuN + original * ( 1 - cumulativeWeight )
32244                                 var originalValueOffset = stride * this._origIndex;
32245
32246                                 this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
32247                         }
32248
32249                         if (weightAdditive > 0) {
32250                                 // accuN := accuN + additive accuN
32251                                 this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
32252                         }
32253
32254                         for (var i = stride, e = stride + stride; i !== e; ++i) {
32255                                 if (buffer[i] !== buffer[i + stride]) {
32256                                         // value has changed -> update scene graph
32257                                         binding.setValue(buffer, offset);
32258                                         break;
32259                                 }
32260                         }
32261                 },
32262                 // remember the state of the bound property and copy it to both accus
32263                 saveOriginalState: function saveOriginalState() {
32264                         var binding = this.binding;
32265                         var buffer = this.buffer,
32266                                         stride = this.valueSize,
32267                                         originalValueOffset = stride * this._origIndex;
32268                         binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
32269
32270                         for (var i = stride, e = originalValueOffset; i !== e; ++i) {
32271                                 buffer[i] = buffer[originalValueOffset + i % stride];
32272                         } // Add to identity for additive
32273
32274
32275                         this._setIdentity();
32276
32277                         this.cumulativeWeight = 0;
32278                         this.cumulativeWeightAdditive = 0;
32279                 },
32280                 // apply the state previously taken via 'saveOriginalState' to the binding
32281                 restoreOriginalState: function restoreOriginalState() {
32282                         var originalValueOffset = this.valueSize * 3;
32283                         this.binding.setValue(this.buffer, originalValueOffset);
32284                 },
32285                 _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
32286                         var startIndex = this._addIndex * this.valueSize;
32287                         var endIndex = startIndex + this.valueSize;
32288
32289                         for (var i = startIndex; i < endIndex; i++) {
32290                                 this.buffer[i] = 0;
32291                         }
32292                 },
32293                 _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
32294                         this._setAdditiveIdentityNumeric();
32295
32296                         this.buffer[this._addIndex * this.valueSize + 3] = 1;
32297                 },
32298                 _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
32299                         var startIndex = this._origIndex * this.valueSize;
32300                         var targetIndex = this._addIndex * this.valueSize;
32301
32302                         for (var i = 0; i < this.valueSize; i++) {
32303                                 this.buffer[targetIndex + i] = this.buffer[startIndex + i];
32304                         }
32305                 },
32306                 // mix functions
32307                 _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
32308                         if (t >= 0.5) {
32309                                 for (var i = 0; i !== stride; ++i) {
32310                                         buffer[dstOffset + i] = buffer[srcOffset + i];
32311                                 }
32312                         }
32313                 },
32314                 _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
32315                         Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
32316                 },
32317                 _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
32318                         var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
32319
32320                         Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
32321
32322                         Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
32323                 },
32324                 _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
32325                         var s = 1 - t;
32326
32327                         for (var i = 0; i !== stride; ++i) {
32328                                 var j = dstOffset + i;
32329                                 buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
32330                         }
32331                 },
32332                 _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
32333                         for (var i = 0; i !== stride; ++i) {
32334                                 var j = dstOffset + i;
32335                                 buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
32336                         }
32337                 }
32338         });
32339
32340         // Characters [].:/ are reserved for track binding syntax.
32341         var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
32342
32343         var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
32344         // only latin characters, and the unicode \p{L} is not yet supported. So
32345         // instead, we exclude reserved characters and match everything else.
32346
32347
32348         var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
32349
32350         var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
32351         // be matched to parse the rest of the track name.
32352
32353
32354         var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
32355
32356
32357         var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
32358         // characters. Accessor may contain any character except closing bracket.
32359
32360
32361         var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
32362         // contain any non-bracket characters.
32363
32364
32365         var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
32366
32367         var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
32368
32369         var _supportedObjectNames = ['material', 'materials', 'bones'];
32370
32371         function Composite(targetGroup, path, optionalParsedPath) {
32372                 var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
32373                 this._targetGroup = targetGroup;
32374                 this._bindings = targetGroup.subscribe_(path, parsedPath);
32375         }
32376
32377         Object.assign(Composite.prototype, {
32378                 getValue: function getValue(array, offset) {
32379                         this.bind(); // bind all binding
32380
32381                         var firstValidIndex = this._targetGroup.nCachedObjects_,
32382                                         binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
32383
32384                         if (binding !== undefined) binding.getValue(array, offset);
32385                 },
32386                 setValue: function setValue(array, offset) {
32387                         var bindings = this._bindings;
32388
32389                         for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
32390                                 bindings[i].setValue(array, offset);
32391                         }
32392                 },
32393                 bind: function bind() {
32394                         var bindings = this._bindings;
32395
32396                         for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
32397                                 bindings[i].bind();
32398                         }
32399                 },
32400                 unbind: function unbind() {
32401                         var bindings = this._bindings;
32402
32403                         for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
32404                                 bindings[i].unbind();
32405                         }
32406                 }
32407         });
32408
32409         function PropertyBinding(rootNode, path, parsedPath) {
32410                 this.path = path;
32411                 this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
32412                 this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
32413                 this.rootNode = rootNode;
32414         }
32415
32416         Object.assign(PropertyBinding, {
32417                 Composite: Composite,
32418                 create: function create(root, path, parsedPath) {
32419                         if (!(root && root.isAnimationObjectGroup)) {
32420                                 return new PropertyBinding(root, path, parsedPath);
32421                         } else {
32422                                 return new PropertyBinding.Composite(root, path, parsedPath);
32423                         }
32424                 },
32425
32426                 /**
32427                  * Replaces spaces with underscores and removes unsupported characters from
32428                  * node names, to ensure compatibility with parseTrackName().
32429                  *
32430                  * @param {string} name Node name to be sanitized.
32431                  * @return {string}
32432                  */
32433                 sanitizeNodeName: function sanitizeNodeName(name) {
32434                         return name.replace(/\s/g, '_').replace(_reservedRe, '');
32435                 },
32436                 parseTrackName: function parseTrackName(trackName) {
32437                         var matches = _trackRe.exec(trackName);
32438
32439                         if (!matches) {
32440                                 throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
32441                         }
32442
32443                         var results = {
32444                                 // directoryName: matches[ 1 ], // (tschw) currently unused
32445                                 nodeName: matches[2],
32446                                 objectName: matches[3],
32447                                 objectIndex: matches[4],
32448                                 propertyName: matches[5],
32449                                 // required
32450                                 propertyIndex: matches[6]
32451                         };
32452                         var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
32453
32454                         if (lastDot !== undefined && lastDot !== -1) {
32455                                 var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
32456                                 // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
32457                                 // 'bar' could be the objectName, or part of a nodeName (which can
32458                                 // include '.' characters).
32459
32460                                 if (_supportedObjectNames.indexOf(objectName) !== -1) {
32461                                         results.nodeName = results.nodeName.substring(0, lastDot);
32462                                         results.objectName = objectName;
32463                                 }
32464                         }
32465
32466                         if (results.propertyName === null || results.propertyName.length === 0) {
32467                                 throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
32468                         }
32469
32470                         return results;
32471                 },
32472                 findNode: function findNode(root, nodeName) {
32473                         if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
32474                                 return root;
32475                         } // search into skeleton bones.
32476
32477
32478                         if (root.skeleton) {
32479                                 var bone = root.skeleton.getBoneByName(nodeName);
32480
32481                                 if (bone !== undefined) {
32482                                         return bone;
32483                                 }
32484                         } // search into node subtree.
32485
32486
32487                         if (root.children) {
32488                                 var searchNodeSubtree = function searchNodeSubtree(children) {
32489                                         for (var i = 0; i < children.length; i++) {
32490                                                 var childNode = children[i];
32491
32492                                                 if (childNode.name === nodeName || childNode.uuid === nodeName) {
32493                                                         return childNode;
32494                                                 }
32495
32496                                                 var result = searchNodeSubtree(childNode.children);
32497                                                 if (result) return result;
32498                                         }
32499
32500                                         return null;
32501                                 };
32502
32503                                 var subTreeNode = searchNodeSubtree(root.children);
32504
32505                                 if (subTreeNode) {
32506                                         return subTreeNode;
32507                                 }
32508                         }
32509
32510                         return null;
32511                 }
32512         });
32513         Object.assign(PropertyBinding.prototype, {
32514                 // prototype, continued
32515                 // these are used to "bind" a nonexistent property
32516                 _getValue_unavailable: function _getValue_unavailable() {},
32517                 _setValue_unavailable: function _setValue_unavailable() {},
32518                 BindingType: {
32519                         Direct: 0,
32520                         EntireArray: 1,
32521                         ArrayElement: 2,
32522                         HasFromToArray: 3
32523                 },
32524                 Versioning: {
32525                         None: 0,
32526                         NeedsUpdate: 1,
32527                         MatrixWorldNeedsUpdate: 2
32528                 },
32529                 GetterByBindingType: [function getValue_direct(buffer, offset) {
32530                         buffer[offset] = this.node[this.propertyName];
32531                 }, function getValue_array(buffer, offset) {
32532                         var source = this.resolvedProperty;
32533
32534                         for (var i = 0, n = source.length; i !== n; ++i) {
32535                                 buffer[offset++] = source[i];
32536                         }
32537                 }, function getValue_arrayElement(buffer, offset) {
32538                         buffer[offset] = this.resolvedProperty[this.propertyIndex];
32539                 }, function getValue_toArray(buffer, offset) {
32540                         this.resolvedProperty.toArray(buffer, offset);
32541                 }],
32542                 SetterByBindingTypeAndVersioning: [[// Direct
32543                 function setValue_direct(buffer, offset) {
32544                         this.targetObject[this.propertyName] = buffer[offset];
32545                 }, function setValue_direct_setNeedsUpdate(buffer, offset) {
32546                         this.targetObject[this.propertyName] = buffer[offset];
32547                         this.targetObject.needsUpdate = true;
32548                 }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
32549                         this.targetObject[this.propertyName] = buffer[offset];
32550                         this.targetObject.matrixWorldNeedsUpdate = true;
32551                 }], [// EntireArray
32552                 function setValue_array(buffer, offset) {
32553                         var dest = this.resolvedProperty;
32554
32555                         for (var i = 0, n = dest.length; i !== n; ++i) {
32556                                 dest[i] = buffer[offset++];
32557                         }
32558                 }, function setValue_array_setNeedsUpdate(buffer, offset) {
32559                         var dest = this.resolvedProperty;
32560
32561                         for (var i = 0, n = dest.length; i !== n; ++i) {
32562                                 dest[i] = buffer[offset++];
32563                         }
32564
32565                         this.targetObject.needsUpdate = true;
32566                 }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
32567                         var dest = this.resolvedProperty;
32568
32569                         for (var i = 0, n = dest.length; i !== n; ++i) {
32570                                 dest[i] = buffer[offset++];
32571                         }
32572
32573                         this.targetObject.matrixWorldNeedsUpdate = true;
32574                 }], [// ArrayElement
32575                 function setValue_arrayElement(buffer, offset) {
32576                         this.resolvedProperty[this.propertyIndex] = buffer[offset];
32577                 }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
32578                         this.resolvedProperty[this.propertyIndex] = buffer[offset];
32579                         this.targetObject.needsUpdate = true;
32580                 }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
32581                         this.resolvedProperty[this.propertyIndex] = buffer[offset];
32582                         this.targetObject.matrixWorldNeedsUpdate = true;
32583                 }], [// HasToFromArray
32584                 function setValue_fromArray(buffer, offset) {
32585                         this.resolvedProperty.fromArray(buffer, offset);
32586                 }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
32587                         this.resolvedProperty.fromArray(buffer, offset);
32588                         this.targetObject.needsUpdate = true;
32589                 }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
32590                         this.resolvedProperty.fromArray(buffer, offset);
32591                         this.targetObject.matrixWorldNeedsUpdate = true;
32592                 }]],
32593                 getValue: function getValue_unbound(targetArray, offset) {
32594                         this.bind();
32595                         this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
32596                         // 'bind' sets 'this.getValue' / 'setValue' and shadows the
32597                         // prototype version of these methods with one that represents
32598                         // the bound state. When the property is not found, the methods
32599                         // become no-ops.
32600                 },
32601                 setValue: function getValue_unbound(sourceArray, offset) {
32602                         this.bind();
32603                         this.setValue(sourceArray, offset);
32604                 },
32605                 // create getter / setter pair for a property in the scene graph
32606                 bind: function bind() {
32607                         var targetObject = this.node;
32608                         var parsedPath = this.parsedPath;
32609                         var objectName = parsedPath.objectName;
32610                         var propertyName = parsedPath.propertyName;
32611                         var propertyIndex = parsedPath.propertyIndex;
32612
32613                         if (!targetObject) {
32614                                 targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
32615                                 this.node = targetObject;
32616                         } // set fail state so we can just 'return' on error
32617
32618
32619                         this.getValue = this._getValue_unavailable;
32620                         this.setValue = this._setValue_unavailable; // ensure there is a value node
32621
32622                         if (!targetObject) {
32623                                 console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
32624                                 return;
32625                         }
32626
32627                         if (objectName) {
32628                                 var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
32629
32630                                 switch (objectName) {
32631                                         case 'materials':
32632                                                 if (!targetObject.material) {
32633                                                         console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
32634                                                         return;
32635                                                 }
32636
32637                                                 if (!targetObject.material.materials) {
32638                                                         console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
32639                                                         return;
32640                                                 }
32641
32642                                                 targetObject = targetObject.material.materials;
32643                                                 break;
32644
32645                                         case 'bones':
32646                                                 if (!targetObject.skeleton) {
32647                                                         console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
32648                                                         return;
32649                                                 } // potential future optimization: skip this if propertyIndex is already an integer
32650                                                 // and convert the integer string to a true integer.
32651
32652
32653                                                 targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
32654
32655                                                 for (var i = 0; i < targetObject.length; i++) {
32656                                                         if (targetObject[i].name === objectIndex) {
32657                                                                 objectIndex = i;
32658                                                                 break;
32659                                                         }
32660                                                 }
32661
32662                                                 break;
32663
32664                                         default:
32665                                                 if (targetObject[objectName] === undefined) {
32666                                                         console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
32667                                                         return;
32668                                                 }
32669
32670                                                 targetObject = targetObject[objectName];
32671                                 }
32672
32673                                 if (objectIndex !== undefined) {
32674                                         if (targetObject[objectIndex] === undefined) {
32675                                                 console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
32676                                                 return;
32677                                         }
32678
32679                                         targetObject = targetObject[objectIndex];
32680                                 }
32681                         } // resolve property
32682
32683
32684                         var nodeProperty = targetObject[propertyName];
32685
32686                         if (nodeProperty === undefined) {
32687                                 var nodeName = parsedPath.nodeName;
32688                                 console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
32689                                 return;
32690                         } // determine versioning scheme
32691
32692
32693                         var versioning = this.Versioning.None;
32694                         this.targetObject = targetObject;
32695
32696                         if (targetObject.needsUpdate !== undefined) {
32697                                 // material
32698                                 versioning = this.Versioning.NeedsUpdate;
32699                         } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
32700                                 // node transform
32701                                 versioning = this.Versioning.MatrixWorldNeedsUpdate;
32702                         } // determine how the property gets bound
32703
32704
32705                         var bindingType = this.BindingType.Direct;
32706
32707                         if (propertyIndex !== undefined) {
32708                                 // access a sub element of the property array (only primitives are supported right now)
32709                                 if (propertyName === "morphTargetInfluences") {
32710                                         // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
32711                                         // support resolving morphTarget names into indices.
32712                                         if (!targetObject.geometry) {
32713                                                 console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
32714                                                 return;
32715                                         }
32716
32717                                         if (targetObject.geometry.isBufferGeometry) {
32718                                                 if (!targetObject.geometry.morphAttributes) {
32719                                                         console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
32720                                                         return;
32721                                                 }
32722
32723                                                 if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
32724                                                         propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
32725                                                 }
32726                                         } else {
32727                                                 console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
32728                                                 return;
32729                                         }
32730                                 }
32731
32732                                 bindingType = this.BindingType.ArrayElement;
32733                                 this.resolvedProperty = nodeProperty;
32734                                 this.propertyIndex = propertyIndex;
32735                         } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
32736                                 // must use copy for Object3D.Euler/Quaternion
32737                                 bindingType = this.BindingType.HasFromToArray;
32738                                 this.resolvedProperty = nodeProperty;
32739                         } else if (Array.isArray(nodeProperty)) {
32740                                 bindingType = this.BindingType.EntireArray;
32741                                 this.resolvedProperty = nodeProperty;
32742                         } else {
32743                                 this.propertyName = propertyName;
32744                         } // select getter / setter
32745
32746
32747                         this.getValue = this.GetterByBindingType[bindingType];
32748                         this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
32749                 },
32750                 unbind: function unbind() {
32751                         this.node = null; // back to the prototype version of getValue / setValue
32752                         // note: avoiding to mutate the shape of 'this' via 'delete'
32753
32754                         this.getValue = this._getValue_unbound;
32755                         this.setValue = this._setValue_unbound;
32756                 }
32757         }); // DECLARE ALIAS AFTER assign prototype
32758
32759         Object.assign(PropertyBinding.prototype, {
32760                 // initial state of these methods that calls 'bind'
32761                 _getValue_unbound: PropertyBinding.prototype.getValue,
32762                 _setValue_unbound: PropertyBinding.prototype.setValue
32763         });
32764
32765         /**
32766          *
32767          * A group of objects that receives a shared animation state.
32768          *
32769          * Usage:
32770          *
32771          *      - Add objects you would otherwise pass as 'root' to the
32772          *              constructor or the .clipAction method of AnimationMixer.
32773          *
32774          *      - Instead pass this object as 'root'.
32775          *
32776          *      - You can also add and remove objects later when the mixer
32777          *              is running.
32778          *
32779          * Note:
32780          *
32781          *              Objects of this class appear as one object to the mixer,
32782          *              so cache control of the individual objects must be done
32783          *              on the group.
32784          *
32785          * Limitation:
32786          *
32787          *      - The animated properties must be compatible among the
32788          *              all objects in the group.
32789          *
32790          *      - A single property can either be controlled through a
32791          *              target group or directly, but not both.
32792          */
32793
32794         function AnimationObjectGroup() {
32795                 this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
32796
32797                 this._objects = Array.prototype.slice.call(arguments);
32798                 this.nCachedObjects_ = 0; // threshold
32799                 // note: read by PropertyBinding.Composite
32800
32801                 var indices = {};
32802                 this._indicesByUUID = indices; // for bookkeeping
32803
32804                 for (var i = 0, n = arguments.length; i !== n; ++i) {
32805                         indices[arguments[i].uuid] = i;
32806                 }
32807
32808                 this._paths = []; // inside: string
32809
32810                 this._parsedPaths = []; // inside: { we don't care, here }
32811
32812                 this._bindings = []; // inside: Array< PropertyBinding >
32813
32814                 this._bindingsIndicesByPath = {}; // inside: indices in these arrays
32815
32816                 var scope = this;
32817                 this.stats = {
32818                         objects: {
32819                                 get total() {
32820                                         return scope._objects.length;
32821                                 },
32822
32823                                 get inUse() {
32824                                         return this.total - scope.nCachedObjects_;
32825                                 }
32826
32827                         },
32828
32829                         get bindingsPerObject() {
32830                                 return scope._bindings.length;
32831                         }
32832
32833                 };
32834         }
32835
32836         Object.assign(AnimationObjectGroup.prototype, {
32837                 isAnimationObjectGroup: true,
32838                 add: function add() {
32839                         var objects = this._objects,
32840                                         indicesByUUID = this._indicesByUUID,
32841                                         paths = this._paths,
32842                                         parsedPaths = this._parsedPaths,
32843                                         bindings = this._bindings,
32844                                         nBindings = bindings.length;
32845                         var knownObject = undefined,
32846                                         nObjects = objects.length,
32847                                         nCachedObjects = this.nCachedObjects_;
32848
32849                         for (var i = 0, n = arguments.length; i !== n; ++i) {
32850                                 var object = arguments[i],
32851                                                 uuid = object.uuid;
32852                                 var index = indicesByUUID[uuid];
32853
32854                                 if (index === undefined) {
32855                                         // unknown object -> add it to the ACTIVE region
32856                                         index = nObjects++;
32857                                         indicesByUUID[uuid] = index;
32858                                         objects.push(object); // accounting is done, now do the same for all bindings
32859
32860                                         for (var j = 0, m = nBindings; j !== m; ++j) {
32861                                                 bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
32862                                         }
32863                                 } else if (index < nCachedObjects) {
32864                                         knownObject = objects[index]; // move existing object to the ACTIVE region
32865
32866                                         var firstActiveIndex = --nCachedObjects,
32867                                                         lastCachedObject = objects[firstActiveIndex];
32868                                         indicesByUUID[lastCachedObject.uuid] = index;
32869                                         objects[index] = lastCachedObject;
32870                                         indicesByUUID[uuid] = firstActiveIndex;
32871                                         objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
32872
32873                                         for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
32874                                                 var bindingsForPath = bindings[_j],
32875                                                                 lastCached = bindingsForPath[firstActiveIndex];
32876                                                 var binding = bindingsForPath[index];
32877                                                 bindingsForPath[index] = lastCached;
32878
32879                                                 if (binding === undefined) {
32880                                                         // since we do not bother to create new bindings
32881                                                         // for objects that are cached, the binding may
32882                                                         // or may not exist
32883                                                         binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
32884                                                 }
32885
32886                                                 bindingsForPath[firstActiveIndex] = binding;
32887                                         }
32888                                 } else if (objects[index] !== knownObject) {
32889                                         console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
32890                                 } // else the object is already where we want it to be
32891
32892                         } // for arguments
32893
32894
32895                         this.nCachedObjects_ = nCachedObjects;
32896                 },
32897                 remove: function remove() {
32898                         var objects = this._objects,
32899                                         indicesByUUID = this._indicesByUUID,
32900                                         bindings = this._bindings,
32901                                         nBindings = bindings.length;
32902                         var nCachedObjects = this.nCachedObjects_;
32903
32904                         for (var i = 0, n = arguments.length; i !== n; ++i) {
32905                                 var object = arguments[i],
32906                                                 uuid = object.uuid,
32907                                                 index = indicesByUUID[uuid];
32908
32909                                 if (index !== undefined && index >= nCachedObjects) {
32910                                         // move existing object into the CACHED region
32911                                         var lastCachedIndex = nCachedObjects++,
32912                                                         firstActiveObject = objects[lastCachedIndex];
32913                                         indicesByUUID[firstActiveObject.uuid] = index;
32914                                         objects[index] = firstActiveObject;
32915                                         indicesByUUID[uuid] = lastCachedIndex;
32916                                         objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
32917
32918                                         for (var j = 0, m = nBindings; j !== m; ++j) {
32919                                                 var bindingsForPath = bindings[j],
32920                                                                 firstActive = bindingsForPath[lastCachedIndex],
32921                                                                 binding = bindingsForPath[index];
32922                                                 bindingsForPath[index] = firstActive;
32923                                                 bindingsForPath[lastCachedIndex] = binding;
32924                                         }
32925                                 }
32926                         } // for arguments
32927
32928
32929                         this.nCachedObjects_ = nCachedObjects;
32930                 },
32931                 // remove & forget
32932                 uncache: function uncache() {
32933                         var objects = this._objects,
32934                                         indicesByUUID = this._indicesByUUID,
32935                                         bindings = this._bindings,
32936                                         nBindings = bindings.length;
32937                         var nCachedObjects = this.nCachedObjects_,
32938                                         nObjects = objects.length;
32939
32940                         for (var i = 0, n = arguments.length; i !== n; ++i) {
32941                                 var object = arguments[i],
32942                                                 uuid = object.uuid,
32943                                                 index = indicesByUUID[uuid];
32944
32945                                 if (index !== undefined) {
32946                                         delete indicesByUUID[uuid];
32947
32948                                         if (index < nCachedObjects) {
32949                                                 // object is cached, shrink the CACHED region
32950                                                 var firstActiveIndex = --nCachedObjects,
32951                                                                 lastCachedObject = objects[firstActiveIndex],
32952                                                                 lastIndex = --nObjects,
32953                                                                 lastObject = objects[lastIndex]; // last cached object takes this object's place
32954
32955                                                 indicesByUUID[lastCachedObject.uuid] = index;
32956                                                 objects[index] = lastCachedObject; // last object goes to the activated slot and pop
32957
32958                                                 indicesByUUID[lastObject.uuid] = firstActiveIndex;
32959                                                 objects[firstActiveIndex] = lastObject;
32960                                                 objects.pop(); // accounting is done, now do the same for all bindings
32961
32962                                                 for (var j = 0, m = nBindings; j !== m; ++j) {
32963                                                         var bindingsForPath = bindings[j],
32964                                                                         lastCached = bindingsForPath[firstActiveIndex],
32965                                                                         last = bindingsForPath[lastIndex];
32966                                                         bindingsForPath[index] = lastCached;
32967                                                         bindingsForPath[firstActiveIndex] = last;
32968                                                         bindingsForPath.pop();
32969                                                 }
32970                                         } else {
32971                                                 // object is active, just swap with the last and pop
32972                                                 var _lastIndex = --nObjects,
32973                                                                 _lastObject = objects[_lastIndex];
32974
32975                                                 if (_lastIndex > 0) {
32976                                                         indicesByUUID[_lastObject.uuid] = index;
32977                                                 }
32978
32979                                                 objects[index] = _lastObject;
32980                                                 objects.pop(); // accounting is done, now do the same for all bindings
32981
32982                                                 for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
32983                                                         var _bindingsForPath = bindings[_j2];
32984                                                         _bindingsForPath[index] = _bindingsForPath[_lastIndex];
32985
32986                                                         _bindingsForPath.pop();
32987                                                 }
32988                                         } // cached or active
32989
32990                                 } // if object is known
32991
32992                         } // for arguments
32993
32994
32995                         this.nCachedObjects_ = nCachedObjects;
32996                 },
32997                 // Internal interface used by befriended PropertyBinding.Composite:
32998                 subscribe_: function subscribe_(path, parsedPath) {
32999                         // returns an array of bindings for the given path that is changed
33000                         // according to the contained objects in the group
33001                         var indicesByPath = this._bindingsIndicesByPath;
33002                         var index = indicesByPath[path];
33003                         var bindings = this._bindings;
33004                         if (index !== undefined) return bindings[index];
33005                         var paths = this._paths,
33006                                         parsedPaths = this._parsedPaths,
33007                                         objects = this._objects,
33008                                         nObjects = objects.length,
33009                                         nCachedObjects = this.nCachedObjects_,
33010                                         bindingsForPath = new Array(nObjects);
33011                         index = bindings.length;
33012                         indicesByPath[path] = index;
33013                         paths.push(path);
33014                         parsedPaths.push(parsedPath);
33015                         bindings.push(bindingsForPath);
33016
33017                         for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
33018                                 var object = objects[i];
33019                                 bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
33020                         }
33021
33022                         return bindingsForPath;
33023                 },
33024                 unsubscribe_: function unsubscribe_(path) {
33025                         // tells the group to forget about a property path and no longer
33026                         // update the array previously obtained with 'subscribe_'
33027                         var indicesByPath = this._bindingsIndicesByPath,
33028                                         index = indicesByPath[path];
33029
33030                         if (index !== undefined) {
33031                                 var paths = this._paths,
33032                                                 parsedPaths = this._parsedPaths,
33033                                                 bindings = this._bindings,
33034                                                 lastBindingsIndex = bindings.length - 1,
33035                                                 lastBindings = bindings[lastBindingsIndex],
33036                                                 lastBindingsPath = path[lastBindingsIndex];
33037                                 indicesByPath[lastBindingsPath] = index;
33038                                 bindings[index] = lastBindings;
33039                                 bindings.pop();
33040                                 parsedPaths[index] = parsedPaths[lastBindingsIndex];
33041                                 parsedPaths.pop();
33042                                 paths[index] = paths[lastBindingsIndex];
33043                                 paths.pop();
33044                         }
33045                 }
33046         });
33047
33048         var AnimationAction = /*#__PURE__*/function () {
33049                 function AnimationAction(mixer, clip, localRoot, blendMode) {
33050                         if (localRoot === void 0) {
33051                                 localRoot = null;
33052                         }
33053
33054                         if (blendMode === void 0) {
33055                                 blendMode = clip.blendMode;
33056                         }
33057
33058                         this._mixer = mixer;
33059                         this._clip = clip;
33060                         this._localRoot = localRoot;
33061                         this.blendMode = blendMode;
33062                         var tracks = clip.tracks,
33063                                         nTracks = tracks.length,
33064                                         interpolants = new Array(nTracks);
33065                         var interpolantSettings = {
33066                                 endingStart: ZeroCurvatureEnding,
33067                                 endingEnd: ZeroCurvatureEnding
33068                         };
33069
33070                         for (var i = 0; i !== nTracks; ++i) {
33071                                 var interpolant = tracks[i].createInterpolant(null);
33072                                 interpolants[i] = interpolant;
33073                                 interpolant.settings = interpolantSettings;
33074                         }
33075
33076                         this._interpolantSettings = interpolantSettings;
33077                         this._interpolants = interpolants; // bound by the mixer
33078                         // inside: PropertyMixer (managed by the mixer)
33079
33080                         this._propertyBindings = new Array(nTracks);
33081                         this._cacheIndex = null; // for the memory manager
33082
33083                         this._byClipCacheIndex = null; // for the memory manager
33084
33085                         this._timeScaleInterpolant = null;
33086                         this._weightInterpolant = null;
33087                         this.loop = LoopRepeat;
33088                         this._loopCount = -1; // global mixer time when the action is to be started
33089                         // it's set back to 'null' upon start of the action
33090
33091                         this._startTime = null; // scaled local time of the action
33092                         // gets clamped or wrapped to 0..clip.duration according to loop
33093
33094                         this.time = 0;
33095                         this.timeScale = 1;
33096                         this._effectiveTimeScale = 1;
33097                         this.weight = 1;
33098                         this._effectiveWeight = 1;
33099                         this.repetitions = Infinity; // no. of repetitions when looping
33100
33101                         this.paused = false; // true -> zero effective time scale
33102
33103                         this.enabled = true; // false -> zero effective weight
33104
33105                         this.clampWhenFinished = false; // keep feeding the last frame?
33106
33107                         this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
33108
33109                         this.zeroSlopeAtEnd = true; // clips for start, loop and end
33110                 } // State & Scheduling
33111
33112
33113                 var _proto = AnimationAction.prototype;
33114
33115                 _proto.play = function play() {
33116                         this._mixer._activateAction(this);
33117
33118                         return this;
33119                 };
33120
33121                 _proto.stop = function stop() {
33122                         this._mixer._deactivateAction(this);
33123
33124                         return this.reset();
33125                 };
33126
33127                 _proto.reset = function reset() {
33128                         this.paused = false;
33129                         this.enabled = true;
33130                         this.time = 0; // restart clip
33131
33132                         this._loopCount = -1; // forget previous loops
33133
33134                         this._startTime = null; // forget scheduling
33135
33136                         return this.stopFading().stopWarping();
33137                 };
33138
33139                 _proto.isRunning = function isRunning() {
33140                         return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
33141                 } // return true when play has been called
33142                 ;
33143
33144                 _proto.isScheduled = function isScheduled() {
33145                         return this._mixer._isActiveAction(this);
33146                 };
33147
33148                 _proto.startAt = function startAt(time) {
33149                         this._startTime = time;
33150                         return this;
33151                 };
33152
33153                 _proto.setLoop = function setLoop(mode, repetitions) {
33154                         this.loop = mode;
33155                         this.repetitions = repetitions;
33156                         return this;
33157                 } // Weight
33158                 // set the weight stopping any scheduled fading
33159                 // although .enabled = false yields an effective weight of zero, this
33160                 // method does *not* change .enabled, because it would be confusing
33161                 ;
33162
33163                 _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
33164                         this.weight = weight; // note: same logic as when updated at runtime
33165
33166                         this._effectiveWeight = this.enabled ? weight : 0;
33167                         return this.stopFading();
33168                 } // return the weight considering fading and .enabled
33169                 ;
33170
33171                 _proto.getEffectiveWeight = function getEffectiveWeight() {
33172                         return this._effectiveWeight;
33173                 };
33174
33175                 _proto.fadeIn = function fadeIn(duration) {
33176                         return this._scheduleFading(duration, 0, 1);
33177                 };
33178
33179                 _proto.fadeOut = function fadeOut(duration) {
33180                         return this._scheduleFading(duration, 1, 0);
33181                 };
33182
33183                 _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
33184                         fadeOutAction.fadeOut(duration);
33185                         this.fadeIn(duration);
33186
33187                         if (warp) {
33188                                 var fadeInDuration = this._clip.duration,
33189                                                 fadeOutDuration = fadeOutAction._clip.duration,
33190                                                 startEndRatio = fadeOutDuration / fadeInDuration,
33191                                                 endStartRatio = fadeInDuration / fadeOutDuration;
33192                                 fadeOutAction.warp(1.0, startEndRatio, duration);
33193                                 this.warp(endStartRatio, 1.0, duration);
33194                         }
33195
33196                         return this;
33197                 };
33198
33199                 _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
33200                         return fadeInAction.crossFadeFrom(this, duration, warp);
33201                 };
33202
33203                 _proto.stopFading = function stopFading() {
33204                         var weightInterpolant = this._weightInterpolant;
33205
33206                         if (weightInterpolant !== null) {
33207                                 this._weightInterpolant = null;
33208
33209                                 this._mixer._takeBackControlInterpolant(weightInterpolant);
33210                         }
33211
33212                         return this;
33213                 } // Time Scale Control
33214                 // set the time scale stopping any scheduled warping
33215                 // although .paused = true yields an effective time scale of zero, this
33216                 // method does *not* change .paused, because it would be confusing
33217                 ;
33218
33219                 _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
33220                         this.timeScale = timeScale;
33221                         this._effectiveTimeScale = this.paused ? 0 : timeScale;
33222                         return this.stopWarping();
33223                 } // return the time scale considering warping and .paused
33224                 ;
33225
33226                 _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
33227                         return this._effectiveTimeScale;
33228                 };
33229
33230                 _proto.setDuration = function setDuration(duration) {
33231                         this.timeScale = this._clip.duration / duration;
33232                         return this.stopWarping();
33233                 };
33234
33235                 _proto.syncWith = function syncWith(action) {
33236                         this.time = action.time;
33237                         this.timeScale = action.timeScale;
33238                         return this.stopWarping();
33239                 };
33240
33241                 _proto.halt = function halt(duration) {
33242                         return this.warp(this._effectiveTimeScale, 0, duration);
33243                 };
33244
33245                 _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
33246                         var mixer = this._mixer,
33247                                         now = mixer.time,
33248                                         timeScale = this.timeScale;
33249                         var interpolant = this._timeScaleInterpolant;
33250
33251                         if (interpolant === null) {
33252                                 interpolant = mixer._lendControlInterpolant();
33253                                 this._timeScaleInterpolant = interpolant;
33254                         }
33255
33256                         var times = interpolant.parameterPositions,
33257                                         values = interpolant.sampleValues;
33258                         times[0] = now;
33259                         times[1] = now + duration;
33260                         values[0] = startTimeScale / timeScale;
33261                         values[1] = endTimeScale / timeScale;
33262                         return this;
33263                 };
33264
33265                 _proto.stopWarping = function stopWarping() {
33266                         var timeScaleInterpolant = this._timeScaleInterpolant;
33267
33268                         if (timeScaleInterpolant !== null) {
33269                                 this._timeScaleInterpolant = null;
33270
33271                                 this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
33272                         }
33273
33274                         return this;
33275                 } // Object Accessors
33276                 ;
33277
33278                 _proto.getMixer = function getMixer() {
33279                         return this._mixer;
33280                 };
33281
33282                 _proto.getClip = function getClip() {
33283                         return this._clip;
33284                 };
33285
33286                 _proto.getRoot = function getRoot() {
33287                         return this._localRoot || this._mixer._root;
33288                 } // Interna
33289                 ;
33290
33291                 _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
33292                         // called by the mixer
33293                         if (!this.enabled) {
33294                                 // call ._updateWeight() to update ._effectiveWeight
33295                                 this._updateWeight(time);
33296
33297                                 return;
33298                         }
33299
33300                         var startTime = this._startTime;
33301
33302                         if (startTime !== null) {
33303                                 // check for scheduled start of action
33304                                 var timeRunning = (time - startTime) * timeDirection;
33305
33306                                 if (timeRunning < 0 || timeDirection === 0) {
33307                                         return; // yet to come / don't decide when delta = 0
33308                                 } // start
33309
33310
33311                                 this._startTime = null; // unschedule
33312
33313                                 deltaTime = timeDirection * timeRunning;
33314                         } // apply time scale and advance time
33315
33316
33317                         deltaTime *= this._updateTimeScale(time);
33318
33319                         var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
33320                         // an effective weight of 0
33321
33322
33323                         var weight = this._updateWeight(time);
33324
33325                         if (weight > 0) {
33326                                 var _interpolants = this._interpolants;
33327                                 var propertyMixers = this._propertyBindings;
33328
33329                                 switch (this.blendMode) {
33330                                         case AdditiveAnimationBlendMode:
33331                                                 for (var j = 0, m = _interpolants.length; j !== m; ++j) {
33332                                                         _interpolants[j].evaluate(clipTime);
33333
33334                                                         propertyMixers[j].accumulateAdditive(weight);
33335                                                 }
33336
33337                                                 break;
33338
33339                                         case NormalAnimationBlendMode:
33340                                         default:
33341                                                 for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
33342                                                         _interpolants[_j].evaluate(clipTime);
33343
33344                                                         propertyMixers[_j].accumulate(accuIndex, weight);
33345                                                 }
33346
33347                                 }
33348                         }
33349                 };
33350
33351                 _proto._updateWeight = function _updateWeight(time) {
33352                         var weight = 0;
33353
33354                         if (this.enabled) {
33355                                 weight = this.weight;
33356                                 var interpolant = this._weightInterpolant;
33357
33358                                 if (interpolant !== null) {
33359                                         var interpolantValue = interpolant.evaluate(time)[0];
33360                                         weight *= interpolantValue;
33361
33362                                         if (time > interpolant.parameterPositions[1]) {
33363                                                 this.stopFading();
33364
33365                                                 if (interpolantValue === 0) {
33366                                                         // faded out, disable
33367                                                         this.enabled = false;
33368                                                 }
33369                                         }
33370                                 }
33371                         }
33372
33373                         this._effectiveWeight = weight;
33374                         return weight;
33375                 };
33376
33377                 _proto._updateTimeScale = function _updateTimeScale(time) {
33378                         var timeScale = 0;
33379
33380                         if (!this.paused) {
33381                                 timeScale = this.timeScale;
33382                                 var interpolant = this._timeScaleInterpolant;
33383
33384                                 if (interpolant !== null) {
33385                                         var interpolantValue = interpolant.evaluate(time)[0];
33386                                         timeScale *= interpolantValue;
33387
33388                                         if (time > interpolant.parameterPositions[1]) {
33389                                                 this.stopWarping();
33390
33391                                                 if (timeScale === 0) {
33392                                                         // motion has halted, pause
33393                                                         this.paused = true;
33394                                                 } else {
33395                                                         // warp done - apply final time scale
33396                                                         this.timeScale = timeScale;
33397                                                 }
33398                                         }
33399                                 }
33400                         }
33401
33402                         this._effectiveTimeScale = timeScale;
33403                         return timeScale;
33404                 };
33405
33406                 _proto._updateTime = function _updateTime(deltaTime) {
33407                         var duration = this._clip.duration;
33408                         var loop = this.loop;
33409                         var time = this.time + deltaTime;
33410                         var loopCount = this._loopCount;
33411                         var pingPong = loop === LoopPingPong;
33412
33413                         if (deltaTime === 0) {
33414                                 if (loopCount === -1) return time;
33415                                 return pingPong && (loopCount & 1) === 1 ? duration - time : time;
33416                         }
33417
33418                         if (loop === LoopOnce) {
33419                                 if (loopCount === -1) {
33420                                         // just started
33421                                         this._loopCount = 0;
33422
33423                                         this._setEndings(true, true, false);
33424                                 }
33425
33426                                 handle_stop: {
33427                                         if (time >= duration) {
33428                                                 time = duration;
33429                                         } else if (time < 0) {
33430                                                 time = 0;
33431                                         } else {
33432                                                 this.time = time;
33433                                                 break handle_stop;
33434                                         }
33435
33436                                         if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
33437                                         this.time = time;
33438
33439                                         this._mixer.dispatchEvent({
33440                                                 type: 'finished',
33441                                                 action: this,
33442                                                 direction: deltaTime < 0 ? -1 : 1
33443                                         });
33444                                 }
33445                         } else {
33446                                 // repetitive Repeat or PingPong
33447                                 if (loopCount === -1) {
33448                                         // just started
33449                                         if (deltaTime >= 0) {
33450                                                 loopCount = 0;
33451
33452                                                 this._setEndings(true, this.repetitions === 0, pingPong);
33453                                         } else {
33454                                                 // when looping in reverse direction, the initial
33455                                                 // transition through zero counts as a repetition,
33456                                                 // so leave loopCount at -1
33457                                                 this._setEndings(this.repetitions === 0, true, pingPong);
33458                                         }
33459                                 }
33460
33461                                 if (time >= duration || time < 0) {
33462                                         // wrap around
33463                                         var loopDelta = Math.floor(time / duration); // signed
33464
33465                                         time -= duration * loopDelta;
33466                                         loopCount += Math.abs(loopDelta);
33467                                         var pending = this.repetitions - loopCount;
33468
33469                                         if (pending <= 0) {
33470                                                 // have to stop (switch state, clamp time, fire event)
33471                                                 if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
33472                                                 time = deltaTime > 0 ? duration : 0;
33473                                                 this.time = time;
33474
33475                                                 this._mixer.dispatchEvent({
33476                                                         type: 'finished',
33477                                                         action: this,
33478                                                         direction: deltaTime > 0 ? 1 : -1
33479                                                 });
33480                                         } else {
33481                                                 // keep running
33482                                                 if (pending === 1) {
33483                                                         // entering the last round
33484                                                         var atStart = deltaTime < 0;
33485
33486                                                         this._setEndings(atStart, !atStart, pingPong);
33487                                                 } else {
33488                                                         this._setEndings(false, false, pingPong);
33489                                                 }
33490
33491                                                 this._loopCount = loopCount;
33492                                                 this.time = time;
33493
33494                                                 this._mixer.dispatchEvent({
33495                                                         type: 'loop',
33496                                                         action: this,
33497                                                         loopDelta: loopDelta
33498                                                 });
33499                                         }
33500                                 } else {
33501                                         this.time = time;
33502                                 }
33503
33504                                 if (pingPong && (loopCount & 1) === 1) {
33505                                         // invert time for the "pong round"
33506                                         return duration - time;
33507                                 }
33508                         }
33509
33510                         return time;
33511                 };
33512
33513                 _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
33514                         var settings = this._interpolantSettings;
33515
33516                         if (pingPong) {
33517                                 settings.endingStart = ZeroSlopeEnding;
33518                                 settings.endingEnd = ZeroSlopeEnding;
33519                         } else {
33520                                 // assuming for LoopOnce atStart == atEnd == true
33521                                 if (atStart) {
33522                                         settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
33523                                 } else {
33524                                         settings.endingStart = WrapAroundEnding;
33525                                 }
33526
33527                                 if (atEnd) {
33528                                         settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
33529                                 } else {
33530                                         settings.endingEnd = WrapAroundEnding;
33531                                 }
33532                         }
33533                 };
33534
33535                 _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
33536                         var mixer = this._mixer,
33537                                         now = mixer.time;
33538                         var interpolant = this._weightInterpolant;
33539
33540                         if (interpolant === null) {
33541                                 interpolant = mixer._lendControlInterpolant();
33542                                 this._weightInterpolant = interpolant;
33543                         }
33544
33545                         var times = interpolant.parameterPositions,
33546                                         values = interpolant.sampleValues;
33547                         times[0] = now;
33548                         values[0] = weightNow;
33549                         times[1] = now + duration;
33550                         values[1] = weightThen;
33551                         return this;
33552                 };
33553
33554                 return AnimationAction;
33555         }();
33556
33557         function AnimationMixer(root) {
33558                 this._root = root;
33559
33560                 this._initMemoryManager();
33561
33562                 this._accuIndex = 0;
33563                 this.time = 0;
33564                 this.timeScale = 1.0;
33565         }
33566
33567         AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
33568                 constructor: AnimationMixer,
33569                 _bindAction: function _bindAction(action, prototypeAction) {
33570                         var root = action._localRoot || this._root,
33571                                         tracks = action._clip.tracks,
33572                                         nTracks = tracks.length,
33573                                         bindings = action._propertyBindings,
33574                                         interpolants = action._interpolants,
33575                                         rootUuid = root.uuid,
33576                                         bindingsByRoot = this._bindingsByRootAndName;
33577                         var bindingsByName = bindingsByRoot[rootUuid];
33578
33579                         if (bindingsByName === undefined) {
33580                                 bindingsByName = {};
33581                                 bindingsByRoot[rootUuid] = bindingsByName;
33582                         }
33583
33584                         for (var i = 0; i !== nTracks; ++i) {
33585                                 var track = tracks[i],
33586                                                 trackName = track.name;
33587                                 var binding = bindingsByName[trackName];
33588
33589                                 if (binding !== undefined) {
33590                                         bindings[i] = binding;
33591                                 } else {
33592                                         binding = bindings[i];
33593
33594                                         if (binding !== undefined) {
33595                                                 // existing binding, make sure the cache knows
33596                                                 if (binding._cacheIndex === null) {
33597                                                         ++binding.referenceCount;
33598
33599                                                         this._addInactiveBinding(binding, rootUuid, trackName);
33600                                                 }
33601
33602                                                 continue;
33603                                         }
33604
33605                                         var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
33606                                         binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
33607                                         ++binding.referenceCount;
33608
33609                                         this._addInactiveBinding(binding, rootUuid, trackName);
33610
33611                                         bindings[i] = binding;
33612                                 }
33613
33614                                 interpolants[i].resultBuffer = binding.buffer;
33615                         }
33616                 },
33617                 _activateAction: function _activateAction(action) {
33618                         if (!this._isActiveAction(action)) {
33619                                 if (action._cacheIndex === null) {
33620                                         // this action has been forgotten by the cache, but the user
33621                                         // appears to be still using it -> rebind
33622                                         var rootUuid = (action._localRoot || this._root).uuid,
33623                                                         clipUuid = action._clip.uuid,
33624                                                         actionsForClip = this._actionsByClip[clipUuid];
33625
33626                                         this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
33627
33628                                         this._addInactiveAction(action, clipUuid, rootUuid);
33629                                 }
33630
33631                                 var bindings = action._propertyBindings; // increment reference counts / sort out state
33632
33633                                 for (var i = 0, n = bindings.length; i !== n; ++i) {
33634                                         var binding = bindings[i];
33635
33636                                         if (binding.useCount++ === 0) {
33637                                                 this._lendBinding(binding);
33638
33639                                                 binding.saveOriginalState();
33640                                         }
33641                                 }
33642
33643                                 this._lendAction(action);
33644                         }
33645                 },
33646                 _deactivateAction: function _deactivateAction(action) {
33647                         if (this._isActiveAction(action)) {
33648                                 var bindings = action._propertyBindings; // decrement reference counts / sort out state
33649
33650                                 for (var i = 0, n = bindings.length; i !== n; ++i) {
33651                                         var binding = bindings[i];
33652
33653                                         if (--binding.useCount === 0) {
33654                                                 binding.restoreOriginalState();
33655
33656                                                 this._takeBackBinding(binding);
33657                                         }
33658                                 }
33659
33660                                 this._takeBackAction(action);
33661                         }
33662                 },
33663                 // Memory manager
33664                 _initMemoryManager: function _initMemoryManager() {
33665                         this._actions = []; // 'nActiveActions' followed by inactive ones
33666
33667                         this._nActiveActions = 0;
33668                         this._actionsByClip = {}; // inside:
33669                         // {
33670                         //      knownActions: Array< AnimationAction > - used as prototypes
33671                         //      actionByRoot: AnimationAction - lookup
33672                         // }
33673
33674                         this._bindings = []; // 'nActiveBindings' followed by inactive ones
33675
33676                         this._nActiveBindings = 0;
33677                         this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
33678
33679                         this._controlInterpolants = []; // same game as above
33680
33681                         this._nActiveControlInterpolants = 0;
33682                         var scope = this;
33683                         this.stats = {
33684                                 actions: {
33685                                         get total() {
33686                                                 return scope._actions.length;
33687                                         },
33688
33689                                         get inUse() {
33690                                                 return scope._nActiveActions;
33691                                         }
33692
33693                                 },
33694                                 bindings: {
33695                                         get total() {
33696                                                 return scope._bindings.length;
33697                                         },
33698
33699                                         get inUse() {
33700                                                 return scope._nActiveBindings;
33701                                         }
33702
33703                                 },
33704                                 controlInterpolants: {
33705                                         get total() {
33706                                                 return scope._controlInterpolants.length;
33707                                         },
33708
33709                                         get inUse() {
33710                                                 return scope._nActiveControlInterpolants;
33711                                         }
33712
33713                                 }
33714                         };
33715                 },
33716                 // Memory management for AnimationAction objects
33717                 _isActiveAction: function _isActiveAction(action) {
33718                         var index = action._cacheIndex;
33719                         return index !== null && index < this._nActiveActions;
33720                 },
33721                 _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
33722                         var actions = this._actions,
33723                                         actionsByClip = this._actionsByClip;
33724                         var actionsForClip = actionsByClip[clipUuid];
33725
33726                         if (actionsForClip === undefined) {
33727                                 actionsForClip = {
33728                                         knownActions: [action],
33729                                         actionByRoot: {}
33730                                 };
33731                                 action._byClipCacheIndex = 0;
33732                                 actionsByClip[clipUuid] = actionsForClip;
33733                         } else {
33734                                 var knownActions = actionsForClip.knownActions;
33735                                 action._byClipCacheIndex = knownActions.length;
33736                                 knownActions.push(action);
33737                         }
33738
33739                         action._cacheIndex = actions.length;
33740                         actions.push(action);
33741                         actionsForClip.actionByRoot[rootUuid] = action;
33742                 },
33743                 _removeInactiveAction: function _removeInactiveAction(action) {
33744                         var actions = this._actions,
33745                                         lastInactiveAction = actions[actions.length - 1],
33746                                         cacheIndex = action._cacheIndex;
33747                         lastInactiveAction._cacheIndex = cacheIndex;
33748                         actions[cacheIndex] = lastInactiveAction;
33749                         actions.pop();
33750                         action._cacheIndex = null;
33751                         var clipUuid = action._clip.uuid,
33752                                         actionsByClip = this._actionsByClip,
33753                                         actionsForClip = actionsByClip[clipUuid],
33754                                         knownActionsForClip = actionsForClip.knownActions,
33755                                         lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
33756                                         byClipCacheIndex = action._byClipCacheIndex;
33757                         lastKnownAction._byClipCacheIndex = byClipCacheIndex;
33758                         knownActionsForClip[byClipCacheIndex] = lastKnownAction;
33759                         knownActionsForClip.pop();
33760                         action._byClipCacheIndex = null;
33761                         var actionByRoot = actionsForClip.actionByRoot,
33762                                         rootUuid = (action._localRoot || this._root).uuid;
33763                         delete actionByRoot[rootUuid];
33764
33765                         if (knownActionsForClip.length === 0) {
33766                                 delete actionsByClip[clipUuid];
33767                         }
33768
33769                         this._removeInactiveBindingsForAction(action);
33770                 },
33771                 _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
33772                         var bindings = action._propertyBindings;
33773
33774                         for (var i = 0, n = bindings.length; i !== n; ++i) {
33775                                 var binding = bindings[i];
33776
33777                                 if (--binding.referenceCount === 0) {
33778                                         this._removeInactiveBinding(binding);
33779                                 }
33780                         }
33781                 },
33782                 _lendAction: function _lendAction(action) {
33783                         // [ active actions |   inactive actions        ]
33784                         // [    active actions >| inactive actions ]
33785                         //                                                               s                              a
33786                         //                                                                      <-swap->
33787                         //                                                               a                              s
33788                         var actions = this._actions,
33789                                         prevIndex = action._cacheIndex,
33790                                         lastActiveIndex = this._nActiveActions++,
33791                                         firstInactiveAction = actions[lastActiveIndex];
33792                         action._cacheIndex = lastActiveIndex;
33793                         actions[lastActiveIndex] = action;
33794                         firstInactiveAction._cacheIndex = prevIndex;
33795                         actions[prevIndex] = firstInactiveAction;
33796                 },
33797                 _takeBackAction: function _takeBackAction(action) {
33798                         // [    active actions  | inactive actions ]
33799                         // [ active actions |< inactive actions ]
33800                         //                              a                               s
33801                         //                               <-swap->
33802                         //                              s                               a
33803                         var actions = this._actions,
33804                                         prevIndex = action._cacheIndex,
33805                                         firstInactiveIndex = --this._nActiveActions,
33806                                         lastActiveAction = actions[firstInactiveIndex];
33807                         action._cacheIndex = firstInactiveIndex;
33808                         actions[firstInactiveIndex] = action;
33809                         lastActiveAction._cacheIndex = prevIndex;
33810                         actions[prevIndex] = lastActiveAction;
33811                 },
33812                 // Memory management for PropertyMixer objects
33813                 _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
33814                         var bindingsByRoot = this._bindingsByRootAndName,
33815                                         bindings = this._bindings;
33816                         var bindingByName = bindingsByRoot[rootUuid];
33817
33818                         if (bindingByName === undefined) {
33819                                 bindingByName = {};
33820                                 bindingsByRoot[rootUuid] = bindingByName;
33821                         }
33822
33823                         bindingByName[trackName] = binding;
33824                         binding._cacheIndex = bindings.length;
33825                         bindings.push(binding);
33826                 },
33827                 _removeInactiveBinding: function _removeInactiveBinding(binding) {
33828                         var bindings = this._bindings,
33829                                         propBinding = binding.binding,
33830                                         rootUuid = propBinding.rootNode.uuid,
33831                                         trackName = propBinding.path,
33832                                         bindingsByRoot = this._bindingsByRootAndName,
33833                                         bindingByName = bindingsByRoot[rootUuid],
33834                                         lastInactiveBinding = bindings[bindings.length - 1],
33835                                         cacheIndex = binding._cacheIndex;
33836                         lastInactiveBinding._cacheIndex = cacheIndex;
33837                         bindings[cacheIndex] = lastInactiveBinding;
33838                         bindings.pop();
33839                         delete bindingByName[trackName];
33840
33841                         if (Object.keys(bindingByName).length === 0) {
33842                                 delete bindingsByRoot[rootUuid];
33843                         }
33844                 },
33845                 _lendBinding: function _lendBinding(binding) {
33846                         var bindings = this._bindings,
33847                                         prevIndex = binding._cacheIndex,
33848                                         lastActiveIndex = this._nActiveBindings++,
33849                                         firstInactiveBinding = bindings[lastActiveIndex];
33850                         binding._cacheIndex = lastActiveIndex;
33851                         bindings[lastActiveIndex] = binding;
33852                         firstInactiveBinding._cacheIndex = prevIndex;
33853                         bindings[prevIndex] = firstInactiveBinding;
33854                 },
33855                 _takeBackBinding: function _takeBackBinding(binding) {
33856                         var bindings = this._bindings,
33857                                         prevIndex = binding._cacheIndex,
33858                                         firstInactiveIndex = --this._nActiveBindings,
33859                                         lastActiveBinding = bindings[firstInactiveIndex];
33860                         binding._cacheIndex = firstInactiveIndex;
33861                         bindings[firstInactiveIndex] = binding;
33862                         lastActiveBinding._cacheIndex = prevIndex;
33863                         bindings[prevIndex] = lastActiveBinding;
33864                 },
33865                 // Memory management of Interpolants for weight and time scale
33866                 _lendControlInterpolant: function _lendControlInterpolant() {
33867                         var interpolants = this._controlInterpolants,
33868                                         lastActiveIndex = this._nActiveControlInterpolants++;
33869                         var interpolant = interpolants[lastActiveIndex];
33870
33871                         if (interpolant === undefined) {
33872                                 interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
33873                                 interpolant.__cacheIndex = lastActiveIndex;
33874                                 interpolants[lastActiveIndex] = interpolant;
33875                         }
33876
33877                         return interpolant;
33878                 },
33879                 _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
33880                         var interpolants = this._controlInterpolants,
33881                                         prevIndex = interpolant.__cacheIndex,
33882                                         firstInactiveIndex = --this._nActiveControlInterpolants,
33883                                         lastActiveInterpolant = interpolants[firstInactiveIndex];
33884                         interpolant.__cacheIndex = firstInactiveIndex;
33885                         interpolants[firstInactiveIndex] = interpolant;
33886                         lastActiveInterpolant.__cacheIndex = prevIndex;
33887                         interpolants[prevIndex] = lastActiveInterpolant;
33888                 },
33889                 _controlInterpolantsResultBuffer: new Float32Array(1),
33890                 // return an action for a clip optionally using a custom root target
33891                 // object (this method allocates a lot of dynamic memory in case a
33892                 // previously unknown clip/root combination is specified)
33893                 clipAction: function clipAction(clip, optionalRoot, blendMode) {
33894                         var root = optionalRoot || this._root,
33895                                         rootUuid = root.uuid;
33896                         var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
33897                         var clipUuid = clipObject !== null ? clipObject.uuid : clip;
33898                         var actionsForClip = this._actionsByClip[clipUuid];
33899                         var prototypeAction = null;
33900
33901                         if (blendMode === undefined) {
33902                                 if (clipObject !== null) {
33903                                         blendMode = clipObject.blendMode;
33904                                 } else {
33905                                         blendMode = NormalAnimationBlendMode;
33906                                 }
33907                         }
33908
33909                         if (actionsForClip !== undefined) {
33910                                 var existingAction = actionsForClip.actionByRoot[rootUuid];
33911
33912                                 if (existingAction !== undefined && existingAction.blendMode === blendMode) {
33913                                         return existingAction;
33914                                 } // we know the clip, so we don't have to parse all
33915                                 // the bindings again but can just copy
33916
33917
33918                                 prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
33919
33920                                 if (clipObject === null) clipObject = prototypeAction._clip;
33921                         } // clip must be known when specified via string
33922
33923
33924                         if (clipObject === null) return null; // allocate all resources required to run it
33925
33926                         var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
33927
33928                         this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
33929
33930
33931                         this._addInactiveAction(newAction, clipUuid, rootUuid);
33932
33933                         return newAction;
33934                 },
33935                 // get an existing action
33936                 existingAction: function existingAction(clip, optionalRoot) {
33937                         var root = optionalRoot || this._root,
33938                                         rootUuid = root.uuid,
33939                                         clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
33940                                         clipUuid = clipObject ? clipObject.uuid : clip,
33941                                         actionsForClip = this._actionsByClip[clipUuid];
33942
33943                         if (actionsForClip !== undefined) {
33944                                 return actionsForClip.actionByRoot[rootUuid] || null;
33945                         }
33946
33947                         return null;
33948                 },
33949                 // deactivates all previously scheduled actions
33950                 stopAllAction: function stopAllAction() {
33951                         var actions = this._actions,
33952                                         nActions = this._nActiveActions;
33953
33954                         for (var i = nActions - 1; i >= 0; --i) {
33955                                 actions[i].stop();
33956                         }
33957
33958                         return this;
33959                 },
33960                 // advance the time and update apply the animation
33961                 update: function update(deltaTime) {
33962                         deltaTime *= this.timeScale;
33963                         var actions = this._actions,
33964                                         nActions = this._nActiveActions,
33965                                         time = this.time += deltaTime,
33966                                         timeDirection = Math.sign(deltaTime),
33967                                         accuIndex = this._accuIndex ^= 1; // run active actions
33968
33969                         for (var i = 0; i !== nActions; ++i) {
33970                                 var action = actions[i];
33971
33972                                 action._update(time, deltaTime, timeDirection, accuIndex);
33973                         } // update scene graph
33974
33975
33976                         var bindings = this._bindings,
33977                                         nBindings = this._nActiveBindings;
33978
33979                         for (var _i = 0; _i !== nBindings; ++_i) {
33980                                 bindings[_i].apply(accuIndex);
33981                         }
33982
33983                         return this;
33984                 },
33985                 // Allows you to seek to a specific time in an animation.
33986                 setTime: function setTime(timeInSeconds) {
33987                         this.time = 0; // Zero out time attribute for AnimationMixer object;
33988
33989                         for (var i = 0; i < this._actions.length; i++) {
33990                                 this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
33991                         }
33992
33993                         return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
33994                 },
33995                 // return this mixer's root target object
33996                 getRoot: function getRoot() {
33997                         return this._root;
33998                 },
33999                 // free all resources specific to a particular clip
34000                 uncacheClip: function uncacheClip(clip) {
34001                         var actions = this._actions,
34002                                         clipUuid = clip.uuid,
34003                                         actionsByClip = this._actionsByClip,
34004                                         actionsForClip = actionsByClip[clipUuid];
34005
34006                         if (actionsForClip !== undefined) {
34007                                 // note: just calling _removeInactiveAction would mess up the
34008                                 // iteration state and also require updating the state we can
34009                                 // just throw away
34010                                 var actionsToRemove = actionsForClip.knownActions;
34011
34012                                 for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
34013                                         var action = actionsToRemove[i];
34014
34015                                         this._deactivateAction(action);
34016
34017                                         var cacheIndex = action._cacheIndex,
34018                                                         lastInactiveAction = actions[actions.length - 1];
34019                                         action._cacheIndex = null;
34020                                         action._byClipCacheIndex = null;
34021                                         lastInactiveAction._cacheIndex = cacheIndex;
34022                                         actions[cacheIndex] = lastInactiveAction;
34023                                         actions.pop();
34024
34025                                         this._removeInactiveBindingsForAction(action);
34026                                 }
34027
34028                                 delete actionsByClip[clipUuid];
34029                         }
34030                 },
34031                 // free all resources specific to a particular root target object
34032                 uncacheRoot: function uncacheRoot(root) {
34033                         var rootUuid = root.uuid,
34034                                         actionsByClip = this._actionsByClip;
34035
34036                         for (var clipUuid in actionsByClip) {
34037                                 var actionByRoot = actionsByClip[clipUuid].actionByRoot,
34038                                                 action = actionByRoot[rootUuid];
34039
34040                                 if (action !== undefined) {
34041                                         this._deactivateAction(action);
34042
34043                                         this._removeInactiveAction(action);
34044                                 }
34045                         }
34046
34047                         var bindingsByRoot = this._bindingsByRootAndName,
34048                                         bindingByName = bindingsByRoot[rootUuid];
34049
34050                         if (bindingByName !== undefined) {
34051                                 for (var trackName in bindingByName) {
34052                                         var binding = bindingByName[trackName];
34053                                         binding.restoreOriginalState();
34054
34055                                         this._removeInactiveBinding(binding);
34056                                 }
34057                         }
34058                 },
34059                 // remove a targeted clip from the cache
34060                 uncacheAction: function uncacheAction(clip, optionalRoot) {
34061                         var action = this.existingAction(clip, optionalRoot);
34062
34063                         if (action !== null) {
34064                                 this._deactivateAction(action);
34065
34066                                 this._removeInactiveAction(action);
34067                         }
34068                 }
34069         });
34070
34071         var Uniform = /*#__PURE__*/function () {
34072                 function Uniform(value) {
34073                         if (typeof value === 'string') {
34074                                 console.warn('THREE.Uniform: Type parameter is no longer needed.');
34075                                 value = arguments[1];
34076                         }
34077
34078                         this.value = value;
34079                 }
34080
34081                 var _proto = Uniform.prototype;
34082
34083                 _proto.clone = function clone() {
34084                         return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
34085                 };
34086
34087                 return Uniform;
34088         }();
34089
34090         function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
34091                 InterleavedBuffer.call(this, array, stride);
34092                 this.meshPerAttribute = meshPerAttribute || 1;
34093         }
34094
34095         InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
34096                 constructor: InstancedInterleavedBuffer,
34097                 isInstancedInterleavedBuffer: true,
34098                 copy: function copy(source) {
34099                         InterleavedBuffer.prototype.copy.call(this, source);
34100                         this.meshPerAttribute = source.meshPerAttribute;
34101                         return this;
34102                 },
34103                 clone: function clone(data) {
34104                         var ib = InterleavedBuffer.prototype.clone.call(this, data);
34105                         ib.meshPerAttribute = this.meshPerAttribute;
34106                         return ib;
34107                 },
34108                 toJSON: function toJSON(data) {
34109                         var json = InterleavedBuffer.prototype.toJSON.call(this, data);
34110                         json.isInstancedInterleavedBuffer = true;
34111                         json.meshPerAttribute = this.meshPerAttribute;
34112                         return json;
34113                 }
34114         });
34115
34116         function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
34117                 this.buffer = buffer;
34118                 this.type = type;
34119                 this.itemSize = itemSize;
34120                 this.elementSize = elementSize;
34121                 this.count = count;
34122                 this.version = 0;
34123         }
34124
34125         Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
34126                 set: function set(value) {
34127                         if (value === true) this.version++;
34128                 }
34129         });
34130         Object.assign(GLBufferAttribute.prototype, {
34131                 isGLBufferAttribute: true,
34132                 setBuffer: function setBuffer(buffer) {
34133                         this.buffer = buffer;
34134                         return this;
34135                 },
34136                 setType: function setType(type, elementSize) {
34137                         this.type = type;
34138                         this.elementSize = elementSize;
34139                         return this;
34140                 },
34141                 setItemSize: function setItemSize(itemSize) {
34142                         this.itemSize = itemSize;
34143                         return this;
34144                 },
34145                 setCount: function setCount(count) {
34146                         this.count = count;
34147                         return this;
34148                 }
34149         });
34150
34151         function Raycaster(origin, direction, near, far) {
34152                 this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
34153
34154                 this.near = near || 0;
34155                 this.far = far || Infinity;
34156                 this.camera = null;
34157                 this.layers = new Layers();
34158                 this.params = {
34159                         Mesh: {},
34160                         Line: {
34161                                 threshold: 1
34162                         },
34163                         LOD: {},
34164                         Points: {
34165                                 threshold: 1
34166                         },
34167                         Sprite: {}
34168                 };
34169                 Object.defineProperties(this.params, {
34170                         PointCloud: {
34171                                 get: function get() {
34172                                         console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
34173                                         return this.Points;
34174                                 }
34175                         }
34176                 });
34177         }
34178
34179         function ascSort(a, b) {
34180                 return a.distance - b.distance;
34181         }
34182
34183         function _intersectObject(object, raycaster, intersects, recursive) {
34184                 if (object.layers.test(raycaster.layers)) {
34185                         object.raycast(raycaster, intersects);
34186                 }
34187
34188                 if (recursive === true) {
34189                         var children = object.children;
34190
34191                         for (var i = 0, l = children.length; i < l; i++) {
34192                                 _intersectObject(children[i], raycaster, intersects, true);
34193                         }
34194                 }
34195         }
34196
34197         Object.assign(Raycaster.prototype, {
34198                 set: function set(origin, direction) {
34199                         // direction is assumed to be normalized (for accurate distance calculations)
34200                         this.ray.set(origin, direction);
34201                 },
34202                 setFromCamera: function setFromCamera(coords, camera) {
34203                         if (camera && camera.isPerspectiveCamera) {
34204                                 this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
34205                                 this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
34206                                 this.camera = camera;
34207                         } else if (camera && camera.isOrthographicCamera) {
34208                                 this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
34209
34210                                 this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
34211                                 this.camera = camera;
34212                         } else {
34213                                 console.error('THREE.Raycaster: Unsupported camera type.');
34214                         }
34215                 },
34216                 intersectObject: function intersectObject(object, recursive, optionalTarget) {
34217                         var intersects = optionalTarget || [];
34218
34219                         _intersectObject(object, this, intersects, recursive);
34220
34221                         intersects.sort(ascSort);
34222                         return intersects;
34223                 },
34224                 intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
34225                         var intersects = optionalTarget || [];
34226
34227                         if (Array.isArray(objects) === false) {
34228                                 console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
34229                                 return intersects;
34230                         }
34231
34232                         for (var i = 0, l = objects.length; i < l; i++) {
34233                                 _intersectObject(objects[i], this, intersects, recursive);
34234                         }
34235
34236                         intersects.sort(ascSort);
34237                         return intersects;
34238                 }
34239         });
34240
34241         /**
34242          * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
34243          *
34244          * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
34245          * The azimuthal angle (theta) is measured from the positive z-axis.
34246          */
34247
34248         var Spherical = /*#__PURE__*/function () {
34249                 function Spherical(radius, phi, theta) {
34250                         if (radius === void 0) {
34251                                 radius = 1;
34252                         }
34253
34254                         if (phi === void 0) {
34255                                 phi = 0;
34256                         }
34257
34258                         if (theta === void 0) {
34259                                 theta = 0;
34260                         }
34261
34262                         this.radius = radius;
34263                         this.phi = phi; // polar angle
34264
34265                         this.theta = theta; // azimuthal angle
34266
34267                         return this;
34268                 }
34269
34270                 var _proto = Spherical.prototype;
34271
34272                 _proto.set = function set(radius, phi, theta) {
34273                         this.radius = radius;
34274                         this.phi = phi;
34275                         this.theta = theta;
34276                         return this;
34277                 };
34278
34279                 _proto.clone = function clone() {
34280                         return new this.constructor().copy(this);
34281                 };
34282
34283                 _proto.copy = function copy(other) {
34284                         this.radius = other.radius;
34285                         this.phi = other.phi;
34286                         this.theta = other.theta;
34287                         return this;
34288                 } // restrict phi to be betwee EPS and PI-EPS
34289                 ;
34290
34291                 _proto.makeSafe = function makeSafe() {
34292                         var EPS = 0.000001;
34293                         this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
34294                         return this;
34295                 };
34296
34297                 _proto.setFromVector3 = function setFromVector3(v) {
34298                         return this.setFromCartesianCoords(v.x, v.y, v.z);
34299                 };
34300
34301                 _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
34302                         this.radius = Math.sqrt(x * x + y * y + z * z);
34303
34304                         if (this.radius === 0) {
34305                                 this.theta = 0;
34306                                 this.phi = 0;
34307                         } else {
34308                                 this.theta = Math.atan2(x, z);
34309                                 this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
34310                         }
34311
34312                         return this;
34313                 };
34314
34315                 return Spherical;
34316         }();
34317
34318         /**
34319          * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
34320          */
34321         var Cylindrical = /*#__PURE__*/function () {
34322                 function Cylindrical(radius, theta, y) {
34323                         this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
34324
34325                         this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
34326
34327                         this.y = y !== undefined ? y : 0; // height above the x-z plane
34328
34329                         return this;
34330                 }
34331
34332                 var _proto = Cylindrical.prototype;
34333
34334                 _proto.set = function set(radius, theta, y) {
34335                         this.radius = radius;
34336                         this.theta = theta;
34337                         this.y = y;
34338                         return this;
34339                 };
34340
34341                 _proto.clone = function clone() {
34342                         return new this.constructor().copy(this);
34343                 };
34344
34345                 _proto.copy = function copy(other) {
34346                         this.radius = other.radius;
34347                         this.theta = other.theta;
34348                         this.y = other.y;
34349                         return this;
34350                 };
34351
34352                 _proto.setFromVector3 = function setFromVector3(v) {
34353                         return this.setFromCartesianCoords(v.x, v.y, v.z);
34354                 };
34355
34356                 _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
34357                         this.radius = Math.sqrt(x * x + z * z);
34358                         this.theta = Math.atan2(x, z);
34359                         this.y = y;
34360                         return this;
34361                 };
34362
34363                 return Cylindrical;
34364         }();
34365
34366         var _vector$7 = /*@__PURE__*/new Vector2();
34367
34368         var Box2 = /*#__PURE__*/function () {
34369                 function Box2(min, max) {
34370                         Object.defineProperty(this, 'isBox2', {
34371                                 value: true
34372                         });
34373                         this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
34374                         this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
34375                 }
34376
34377                 var _proto = Box2.prototype;
34378
34379                 _proto.set = function set(min, max) {
34380                         this.min.copy(min);
34381                         this.max.copy(max);
34382                         return this;
34383                 };
34384
34385                 _proto.setFromPoints = function setFromPoints(points) {
34386                         this.makeEmpty();
34387
34388                         for (var i = 0, il = points.length; i < il; i++) {
34389                                 this.expandByPoint(points[i]);
34390                         }
34391
34392                         return this;
34393                 };
34394
34395                 _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
34396                         var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
34397
34398                         this.min.copy(center).sub(halfSize);
34399                         this.max.copy(center).add(halfSize);
34400                         return this;
34401                 };
34402
34403                 _proto.clone = function clone() {
34404                         return new this.constructor().copy(this);
34405                 };
34406
34407                 _proto.copy = function copy(box) {
34408                         this.min.copy(box.min);
34409                         this.max.copy(box.max);
34410                         return this;
34411                 };
34412
34413                 _proto.makeEmpty = function makeEmpty() {
34414                         this.min.x = this.min.y = +Infinity;
34415                         this.max.x = this.max.y = -Infinity;
34416                         return this;
34417                 };
34418
34419                 _proto.isEmpty = function isEmpty() {
34420                         // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
34421                         return this.max.x < this.min.x || this.max.y < this.min.y;
34422                 };
34423
34424                 _proto.getCenter = function getCenter(target) {
34425                         if (target === undefined) {
34426                                 console.warn('THREE.Box2: .getCenter() target is now required');
34427                                 target = new Vector2();
34428                         }
34429
34430                         return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
34431                 };
34432
34433                 _proto.getSize = function getSize(target) {
34434                         if (target === undefined) {
34435                                 console.warn('THREE.Box2: .getSize() target is now required');
34436                                 target = new Vector2();
34437                         }
34438
34439                         return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
34440                 };
34441
34442                 _proto.expandByPoint = function expandByPoint(point) {
34443                         this.min.min(point);
34444                         this.max.max(point);
34445                         return this;
34446                 };
34447
34448                 _proto.expandByVector = function expandByVector(vector) {
34449                         this.min.sub(vector);
34450                         this.max.add(vector);
34451                         return this;
34452                 };
34453
34454                 _proto.expandByScalar = function expandByScalar(scalar) {
34455                         this.min.addScalar(-scalar);
34456                         this.max.addScalar(scalar);
34457                         return this;
34458                 };
34459
34460                 _proto.containsPoint = function containsPoint(point) {
34461                         return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
34462                 };
34463
34464                 _proto.containsBox = function containsBox(box) {
34465                         return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y;
34466                 };
34467
34468                 _proto.getParameter = function getParameter(point, target) {
34469                         // This can potentially have a divide by zero if the box
34470                         // has a size dimension of 0.
34471                         if (target === undefined) {
34472                                 console.warn('THREE.Box2: .getParameter() target is now required');
34473                                 target = new Vector2();
34474                         }
34475
34476                         return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y));
34477                 };
34478
34479                 _proto.intersectsBox = function intersectsBox(box) {
34480                         // using 4 splitting planes to rule out intersections
34481                         return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
34482                 };
34483
34484                 _proto.clampPoint = function clampPoint(point, target) {
34485                         if (target === undefined) {
34486                                 console.warn('THREE.Box2: .clampPoint() target is now required');
34487                                 target = new Vector2();
34488                         }
34489
34490                         return target.copy(point).clamp(this.min, this.max);
34491                 };
34492
34493                 _proto.distanceToPoint = function distanceToPoint(point) {
34494                         var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
34495
34496                         return clampedPoint.sub(point).length();
34497                 };
34498
34499                 _proto.intersect = function intersect(box) {
34500                         this.min.max(box.min);
34501                         this.max.min(box.max);
34502                         return this;
34503                 };
34504
34505                 _proto.union = function union(box) {
34506                         this.min.min(box.min);
34507                         this.max.max(box.max);
34508                         return this;
34509                 };
34510
34511                 _proto.translate = function translate(offset) {
34512                         this.min.add(offset);
34513                         this.max.add(offset);
34514                         return this;
34515                 };
34516
34517                 _proto.equals = function equals(box) {
34518                         return box.min.equals(this.min) && box.max.equals(this.max);
34519                 };
34520
34521                 return Box2;
34522         }();
34523
34524         var _startP = /*@__PURE__*/new Vector3();
34525
34526         var _startEnd = /*@__PURE__*/new Vector3();
34527
34528         var Line3 = /*#__PURE__*/function () {
34529                 function Line3(start, end) {
34530                         this.start = start !== undefined ? start : new Vector3();
34531                         this.end = end !== undefined ? end : new Vector3();
34532                 }
34533
34534                 var _proto = Line3.prototype;
34535
34536                 _proto.set = function set(start, end) {
34537                         this.start.copy(start);
34538                         this.end.copy(end);
34539                         return this;
34540                 };
34541
34542                 _proto.clone = function clone() {
34543                         return new this.constructor().copy(this);
34544                 };
34545
34546                 _proto.copy = function copy(line) {
34547                         this.start.copy(line.start);
34548                         this.end.copy(line.end);
34549                         return this;
34550                 };
34551
34552                 _proto.getCenter = function getCenter(target) {
34553                         if (target === undefined) {
34554                                 console.warn('THREE.Line3: .getCenter() target is now required');
34555                                 target = new Vector3();
34556                         }
34557
34558                         return target.addVectors(this.start, this.end).multiplyScalar(0.5);
34559                 };
34560
34561                 _proto.delta = function delta(target) {
34562                         if (target === undefined) {
34563                                 console.warn('THREE.Line3: .delta() target is now required');
34564                                 target = new Vector3();
34565                         }
34566
34567                         return target.subVectors(this.end, this.start);
34568                 };
34569
34570                 _proto.distanceSq = function distanceSq() {
34571                         return this.start.distanceToSquared(this.end);
34572                 };
34573
34574                 _proto.distance = function distance() {
34575                         return this.start.distanceTo(this.end);
34576                 };
34577
34578                 _proto.at = function at(t, target) {
34579                         if (target === undefined) {
34580                                 console.warn('THREE.Line3: .at() target is now required');
34581                                 target = new Vector3();
34582                         }
34583
34584                         return this.delta(target).multiplyScalar(t).add(this.start);
34585                 };
34586
34587                 _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
34588                         _startP.subVectors(point, this.start);
34589
34590                         _startEnd.subVectors(this.end, this.start);
34591
34592                         var startEnd2 = _startEnd.dot(_startEnd);
34593
34594                         var startEnd_startP = _startEnd.dot(_startP);
34595
34596                         var t = startEnd_startP / startEnd2;
34597
34598                         if (clampToLine) {
34599                                 t = MathUtils.clamp(t, 0, 1);
34600                         }
34601
34602                         return t;
34603                 };
34604
34605                 _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
34606                         var t = this.closestPointToPointParameter(point, clampToLine);
34607
34608                         if (target === undefined) {
34609                                 console.warn('THREE.Line3: .closestPointToPoint() target is now required');
34610                                 target = new Vector3();
34611                         }
34612
34613                         return this.delta(target).multiplyScalar(t).add(this.start);
34614                 };
34615
34616                 _proto.applyMatrix4 = function applyMatrix4(matrix) {
34617                         this.start.applyMatrix4(matrix);
34618                         this.end.applyMatrix4(matrix);
34619                         return this;
34620                 };
34621
34622                 _proto.equals = function equals(line) {
34623                         return line.start.equals(this.start) && line.end.equals(this.end);
34624                 };
34625
34626                 return Line3;
34627         }();
34628
34629         function ImmediateRenderObject(material) {
34630                 Object3D.call(this);
34631                 this.material = material;
34632
34633                 this.render = function ()
34634                 /* renderCallback */
34635                 {};
34636
34637                 this.hasPositions = false;
34638                 this.hasNormals = false;
34639                 this.hasColors = false;
34640                 this.hasUvs = false;
34641                 this.positionArray = null;
34642                 this.normalArray = null;
34643                 this.colorArray = null;
34644                 this.uvArray = null;
34645                 this.count = 0;
34646         }
34647
34648         ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
34649         ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
34650         ImmediateRenderObject.prototype.isImmediateRenderObject = true;
34651
34652         var _vector$8 = /*@__PURE__*/new Vector3();
34653
34654         var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
34655                 _inheritsLoose(SpotLightHelper, _Object3D);
34656
34657                 function SpotLightHelper(light, color) {
34658                         var _this;
34659
34660                         _this = _Object3D.call(this) || this;
34661                         _this.light = light;
34662
34663                         _this.light.updateMatrixWorld();
34664
34665                         _this.matrix = light.matrixWorld;
34666                         _this.matrixAutoUpdate = false;
34667                         _this.color = color;
34668                         var geometry = new BufferGeometry();
34669                         var positions = [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, -1, 1];
34670
34671                         for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
34672                                 var p1 = i / l * Math.PI * 2;
34673                                 var p2 = j / l * Math.PI * 2;
34674                                 positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
34675                         }
34676
34677                         geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
34678                         var material = new LineBasicMaterial({
34679                                 fog: false,
34680                                 toneMapped: false
34681                         });
34682                         _this.cone = new LineSegments(geometry, material);
34683
34684                         _this.add(_this.cone);
34685
34686                         _this.update();
34687
34688                         return _this;
34689                 }
34690
34691                 var _proto = SpotLightHelper.prototype;
34692
34693                 _proto.dispose = function dispose() {
34694                         this.cone.geometry.dispose();
34695                         this.cone.material.dispose();
34696                 };
34697
34698                 _proto.update = function update() {
34699                         this.light.updateMatrixWorld();
34700                         var coneLength = this.light.distance ? this.light.distance : 1000;
34701                         var coneWidth = coneLength * Math.tan(this.light.angle);
34702                         this.cone.scale.set(coneWidth, coneWidth, coneLength);
34703
34704                         _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
34705
34706                         this.cone.lookAt(_vector$8);
34707
34708                         if (this.color !== undefined) {
34709                                 this.cone.material.color.set(this.color);
34710                         } else {
34711                                 this.cone.material.color.copy(this.light.color);
34712                         }
34713                 };
34714
34715                 return SpotLightHelper;
34716         }(Object3D);
34717
34718         var _vector$9 = /*@__PURE__*/new Vector3();
34719
34720         var _boneMatrix = /*@__PURE__*/new Matrix4();
34721
34722         var _matrixWorldInv = /*@__PURE__*/new Matrix4();
34723
34724         var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
34725                 _inheritsLoose(SkeletonHelper, _LineSegments);
34726
34727                 function SkeletonHelper(object) {
34728                         var _this;
34729
34730                         var bones = getBoneList(object);
34731                         var geometry = new BufferGeometry();
34732                         var vertices = [];
34733                         var colors = [];
34734                         var color1 = new Color(0, 0, 1);
34735                         var color2 = new Color(0, 1, 0);
34736
34737                         for (var i = 0; i < bones.length; i++) {
34738                                 var bone = bones[i];
34739
34740                                 if (bone.parent && bone.parent.isBone) {
34741                                         vertices.push(0, 0, 0);
34742                                         vertices.push(0, 0, 0);
34743                                         colors.push(color1.r, color1.g, color1.b);
34744                                         colors.push(color2.r, color2.g, color2.b);
34745                                 }
34746                         }
34747
34748                         geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
34749                         geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
34750                         var material = new LineBasicMaterial({
34751                                 vertexColors: true,
34752                                 depthTest: false,
34753                                 depthWrite: false,
34754                                 toneMapped: false,
34755                                 transparent: true
34756                         });
34757                         _this = _LineSegments.call(this, geometry, material) || this;
34758                         _this.type = 'SkeletonHelper';
34759                         _this.isSkeletonHelper = true;
34760                         _this.root = object;
34761                         _this.bones = bones;
34762                         _this.matrix = object.matrixWorld;
34763                         _this.matrixAutoUpdate = false;
34764                         return _this;
34765                 }
34766
34767                 var _proto = SkeletonHelper.prototype;
34768
34769                 _proto.updateMatrixWorld = function updateMatrixWorld(force) {
34770                         var bones = this.bones;
34771                         var geometry = this.geometry;
34772                         var position = geometry.getAttribute('position');
34773
34774                         _matrixWorldInv.copy(this.root.matrixWorld).invert();
34775
34776                         for (var i = 0, j = 0; i < bones.length; i++) {
34777                                 var bone = bones[i];
34778
34779                                 if (bone.parent && bone.parent.isBone) {
34780                                         _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
34781
34782                                         _vector$9.setFromMatrixPosition(_boneMatrix);
34783
34784                                         position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
34785
34786                                         _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
34787
34788                                         _vector$9.setFromMatrixPosition(_boneMatrix);
34789
34790                                         position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
34791                                         j += 2;
34792                                 }
34793                         }
34794
34795                         geometry.getAttribute('position').needsUpdate = true;
34796
34797                         _LineSegments.prototype.updateMatrixWorld.call(this, force);
34798                 };
34799
34800                 return SkeletonHelper;
34801         }(LineSegments);
34802
34803         function getBoneList(object) {
34804                 var boneList = [];
34805
34806                 if (object && object.isBone) {
34807                         boneList.push(object);
34808                 }
34809
34810                 for (var i = 0; i < object.children.length; i++) {
34811                         boneList.push.apply(boneList, getBoneList(object.children[i]));
34812                 }
34813
34814                 return boneList;
34815         }
34816
34817         var PointLightHelper = /*#__PURE__*/function (_Mesh) {
34818                 _inheritsLoose(PointLightHelper, _Mesh);
34819
34820                 function PointLightHelper(light, sphereSize, color) {
34821                         var _this;
34822
34823                         var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
34824                         var material = new MeshBasicMaterial({
34825                                 wireframe: true,
34826                                 fog: false,
34827                                 toneMapped: false
34828                         });
34829                         _this = _Mesh.call(this, geometry, material) || this;
34830                         _this.light = light;
34831
34832                         _this.light.updateMatrixWorld();
34833
34834                         _this.color = color;
34835                         _this.type = 'PointLightHelper';
34836                         _this.matrix = _this.light.matrixWorld;
34837                         _this.matrixAutoUpdate = false;
34838
34839                         _this.update();
34840                         /*
34841                         // TODO: delete this comment?
34842                         const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
34843                         const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
34844                         this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
34845                         this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
34846                         const d = light.distance;
34847                         if ( d === 0.0 ) {
34848                                 this.lightDistance.visible = false;
34849                         } else {
34850                                 this.lightDistance.scale.set( d, d, d );
34851                         }
34852                         this.add( this.lightDistance );
34853                         */
34854
34855
34856                         return _this;
34857                 }
34858
34859                 var _proto = PointLightHelper.prototype;
34860
34861                 _proto.dispose = function dispose() {
34862                         this.geometry.dispose();
34863                         this.material.dispose();
34864                 };
34865
34866                 _proto.update = function update() {
34867                         if (this.color !== undefined) {
34868                                 this.material.color.set(this.color);
34869                         } else {
34870                                 this.material.color.copy(this.light.color);
34871                         }
34872                         /*
34873                         const d = this.light.distance;
34874                                 if ( d === 0.0 ) {
34875                                         this.lightDistance.visible = false;
34876                                 } else {
34877                                         this.lightDistance.visible = true;
34878                                 this.lightDistance.scale.set( d, d, d );
34879                                 }
34880                         */
34881
34882                 };
34883
34884                 return PointLightHelper;
34885         }(Mesh);
34886
34887         var _vector$a = /*@__PURE__*/new Vector3();
34888
34889         var _color1 = /*@__PURE__*/new Color();
34890
34891         var _color2 = /*@__PURE__*/new Color();
34892
34893         var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
34894                 _inheritsLoose(HemisphereLightHelper, _Object3D);
34895
34896                 function HemisphereLightHelper(light, size, color) {
34897                         var _this;
34898
34899                         _this = _Object3D.call(this) || this;
34900                         _this.light = light;
34901
34902                         _this.light.updateMatrixWorld();
34903
34904                         _this.matrix = light.matrixWorld;
34905                         _this.matrixAutoUpdate = false;
34906                         _this.color = color;
34907                         var geometry = new OctahedronBufferGeometry(size);
34908                         geometry.rotateY(Math.PI * 0.5);
34909                         _this.material = new MeshBasicMaterial({
34910                                 wireframe: true,
34911                                 fog: false,
34912                                 toneMapped: false
34913                         });
34914                         if (_this.color === undefined) _this.material.vertexColors = true;
34915                         var position = geometry.getAttribute('position');
34916                         var colors = new Float32Array(position.count * 3);
34917                         geometry.setAttribute('color', new BufferAttribute(colors, 3));
34918
34919                         _this.add(new Mesh(geometry, _this.material));
34920
34921                         _this.update();
34922
34923                         return _this;
34924                 }
34925
34926                 var _proto = HemisphereLightHelper.prototype;
34927
34928                 _proto.dispose = function dispose() {
34929                         this.children[0].geometry.dispose();
34930                         this.children[0].material.dispose();
34931                 };
34932
34933                 _proto.update = function update() {
34934                         var mesh = this.children[0];
34935
34936                         if (this.color !== undefined) {
34937                                 this.material.color.set(this.color);
34938                         } else {
34939                                 var colors = mesh.geometry.getAttribute('color');
34940
34941                                 _color1.copy(this.light.color);
34942
34943                                 _color2.copy(this.light.groundColor);
34944
34945                                 for (var i = 0, l = colors.count; i < l; i++) {
34946                                         var color = i < l / 2 ? _color1 : _color2;
34947                                         colors.setXYZ(i, color.r, color.g, color.b);
34948                                 }
34949
34950                                 colors.needsUpdate = true;
34951                         }
34952
34953                         mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
34954                 };
34955
34956                 return HemisphereLightHelper;
34957         }(Object3D);
34958
34959         var GridHelper = /*#__PURE__*/function (_LineSegments) {
34960                 _inheritsLoose(GridHelper, _LineSegments);
34961
34962                 function GridHelper(size, divisions, color1, color2) {
34963                         var _this;
34964
34965                         if (size === void 0) {
34966                                 size = 10;
34967                         }
34968
34969                         if (divisions === void 0) {
34970                                 divisions = 10;
34971                         }
34972
34973                         if (color1 === void 0) {
34974                                 color1 = 0x444444;
34975                         }
34976
34977                         if (color2 === void 0) {
34978                                 color2 = 0x888888;
34979                         }
34980
34981                         color1 = new Color(color1);
34982                         color2 = new Color(color2);
34983                         var center = divisions / 2;
34984                         var step = size / divisions;
34985                         var halfSize = size / 2;
34986                         var vertices = [],
34987                                         colors = [];
34988
34989                         for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
34990                                 vertices.push(-halfSize, 0, k, halfSize, 0, k);
34991                                 vertices.push(k, 0, -halfSize, k, 0, halfSize);
34992                                 var color = i === center ? color1 : color2;
34993                                 color.toArray(colors, j);
34994                                 j += 3;
34995                                 color.toArray(colors, j);
34996                                 j += 3;
34997                                 color.toArray(colors, j);
34998                                 j += 3;
34999                                 color.toArray(colors, j);
35000                                 j += 3;
35001                         }
35002
35003                         var geometry = new BufferGeometry();
35004                         geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
35005                         geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
35006                         var material = new LineBasicMaterial({
35007                                 vertexColors: true,
35008                                 toneMapped: false
35009                         });
35010                         _this = _LineSegments.call(this, geometry, material) || this;
35011                         _this.type = 'GridHelper';
35012                         return _this;
35013                 }
35014
35015                 return GridHelper;
35016         }(LineSegments);
35017
35018         var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
35019                 _inheritsLoose(PolarGridHelper, _LineSegments);
35020
35021                 function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
35022                         var _this;
35023
35024                         if (radius === void 0) {
35025                                 radius = 10;
35026                         }
35027
35028                         if (radials === void 0) {
35029                                 radials = 16;
35030                         }
35031
35032                         if (circles === void 0) {
35033                                 circles = 8;
35034                         }
35035
35036                         if (divisions === void 0) {
35037                                 divisions = 64;
35038                         }
35039
35040                         if (color1 === void 0) {
35041                                 color1 = 0x444444;
35042                         }
35043
35044                         if (color2 === void 0) {
35045                                 color2 = 0x888888;
35046                         }
35047
35048                         color1 = new Color(color1);
35049                         color2 = new Color(color2);
35050                         var vertices = [];
35051                         var colors = []; // create the radials
35052
35053                         for (var i = 0; i <= radials; i++) {
35054                                 var v = i / radials * (Math.PI * 2);
35055                                 var x = Math.sin(v) * radius;
35056                                 var z = Math.cos(v) * radius;
35057                                 vertices.push(0, 0, 0);
35058                                 vertices.push(x, 0, z);
35059                                 var color = i & 1 ? color1 : color2;
35060                                 colors.push(color.r, color.g, color.b);
35061                                 colors.push(color.r, color.g, color.b);
35062                         } // create the circles
35063
35064
35065                         for (var _i = 0; _i <= circles; _i++) {
35066                                 var _color = _i & 1 ? color1 : color2;
35067
35068                                 var r = radius - radius / circles * _i;
35069
35070                                 for (var j = 0; j < divisions; j++) {
35071                                         // first vertex
35072                                         var _v = j / divisions * (Math.PI * 2);
35073
35074                                         var _x = Math.sin(_v) * r;
35075
35076                                         var _z = Math.cos(_v) * r;
35077
35078                                         vertices.push(_x, 0, _z);
35079                                         colors.push(_color.r, _color.g, _color.b); // second vertex
35080
35081                                         _v = (j + 1) / divisions * (Math.PI * 2);
35082                                         _x = Math.sin(_v) * r;
35083                                         _z = Math.cos(_v) * r;
35084                                         vertices.push(_x, 0, _z);
35085                                         colors.push(_color.r, _color.g, _color.b);
35086                                 }
35087                         }
35088
35089                         var geometry = new BufferGeometry();
35090                         geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
35091                         geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
35092                         var material = new LineBasicMaterial({
35093                                 vertexColors: true,
35094                                 toneMapped: false
35095                         });
35096                         _this = _LineSegments.call(this, geometry, material) || this;
35097                         _this.type = 'PolarGridHelper';
35098                         return _this;
35099                 }
35100
35101                 return PolarGridHelper;
35102         }(LineSegments);
35103
35104         var _v1$6 = /*@__PURE__*/new Vector3();
35105
35106         var _v2$3 = /*@__PURE__*/new Vector3();
35107
35108         var _v3$1 = /*@__PURE__*/new Vector3();
35109
35110         var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
35111                 _inheritsLoose(DirectionalLightHelper, _Object3D);
35112
35113                 function DirectionalLightHelper(light, size, color) {
35114                         var _this;
35115
35116                         _this = _Object3D.call(this) || this;
35117                         _this.light = light;
35118
35119                         _this.light.updateMatrixWorld();
35120
35121                         _this.matrix = light.matrixWorld;
35122                         _this.matrixAutoUpdate = false;
35123                         _this.color = color;
35124                         if (size === undefined) size = 1;
35125                         var geometry = new BufferGeometry();
35126                         geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
35127                         var material = new LineBasicMaterial({
35128                                 fog: false,
35129                                 toneMapped: false
35130                         });
35131                         _this.lightPlane = new Line(geometry, material);
35132
35133                         _this.add(_this.lightPlane);
35134
35135                         geometry = new BufferGeometry();
35136                         geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
35137                         _this.targetLine = new Line(geometry, material);
35138
35139                         _this.add(_this.targetLine);
35140
35141                         _this.update();
35142
35143                         return _this;
35144                 }
35145
35146                 var _proto = DirectionalLightHelper.prototype;
35147
35148                 _proto.dispose = function dispose() {
35149                         this.lightPlane.geometry.dispose();
35150                         this.lightPlane.material.dispose();
35151                         this.targetLine.geometry.dispose();
35152                         this.targetLine.material.dispose();
35153                 };
35154
35155                 _proto.update = function update() {
35156                         _v1$6.setFromMatrixPosition(this.light.matrixWorld);
35157
35158                         _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
35159
35160                         _v3$1.subVectors(_v2$3, _v1$6);
35161
35162                         this.lightPlane.lookAt(_v2$3);
35163
35164                         if (this.color !== undefined) {
35165                                 this.lightPlane.material.color.set(this.color);
35166                                 this.targetLine.material.color.set(this.color);
35167                         } else {
35168                                 this.lightPlane.material.color.copy(this.light.color);
35169                                 this.targetLine.material.color.copy(this.light.color);
35170                         }
35171
35172                         this.targetLine.lookAt(_v2$3);
35173                         this.targetLine.scale.z = _v3$1.length();
35174                 };
35175
35176                 return DirectionalLightHelper;
35177         }(Object3D);
35178
35179         var _vector$b = /*@__PURE__*/new Vector3();
35180
35181         var _camera = /*@__PURE__*/new Camera();
35182         /**
35183          *      - shows frustum, line of sight and up of the camera
35184          *      - suitable for fast updates
35185          *      - based on frustum visualization in lightgl.js shadowmap example
35186          *              http://evanw.github.com/lightgl.js/tests/shadowmap.html
35187          */
35188
35189
35190         var CameraHelper = /*#__PURE__*/function (_LineSegments) {
35191                 _inheritsLoose(CameraHelper, _LineSegments);
35192
35193                 function CameraHelper(camera) {
35194                         var _this;
35195
35196                         var geometry = new BufferGeometry();
35197                         var material = new LineBasicMaterial({
35198                                 color: 0xffffff,
35199                                 vertexColors: true,
35200                                 toneMapped: false
35201                         });
35202                         var vertices = [];
35203                         var colors = [];
35204                         var pointMap = {}; // colors
35205
35206                         var colorFrustum = new Color(0xffaa00);
35207                         var colorCone = new Color(0xff0000);
35208                         var colorUp = new Color(0x00aaff);
35209                         var colorTarget = new Color(0xffffff);
35210                         var colorCross = new Color(0x333333); // near
35211
35212                         addLine('n1', 'n2', colorFrustum);
35213                         addLine('n2', 'n4', colorFrustum);
35214                         addLine('n4', 'n3', colorFrustum);
35215                         addLine('n3', 'n1', colorFrustum); // far
35216
35217                         addLine('f1', 'f2', colorFrustum);
35218                         addLine('f2', 'f4', colorFrustum);
35219                         addLine('f4', 'f3', colorFrustum);
35220                         addLine('f3', 'f1', colorFrustum); // sides
35221
35222                         addLine('n1', 'f1', colorFrustum);
35223                         addLine('n2', 'f2', colorFrustum);
35224                         addLine('n3', 'f3', colorFrustum);
35225                         addLine('n4', 'f4', colorFrustum); // cone
35226
35227                         addLine('p', 'n1', colorCone);
35228                         addLine('p', 'n2', colorCone);
35229                         addLine('p', 'n3', colorCone);
35230                         addLine('p', 'n4', colorCone); // up
35231
35232                         addLine('u1', 'u2', colorUp);
35233                         addLine('u2', 'u3', colorUp);
35234                         addLine('u3', 'u1', colorUp); // target
35235
35236                         addLine('c', 't', colorTarget);
35237                         addLine('p', 'c', colorCross); // cross
35238
35239                         addLine('cn1', 'cn2', colorCross);
35240                         addLine('cn3', 'cn4', colorCross);
35241                         addLine('cf1', 'cf2', colorCross);
35242                         addLine('cf3', 'cf4', colorCross);
35243
35244                         function addLine(a, b, color) {
35245                                 addPoint(a, color);
35246                                 addPoint(b, color);
35247                         }
35248
35249                         function addPoint(id, color) {
35250                                 vertices.push(0, 0, 0);
35251                                 colors.push(color.r, color.g, color.b);
35252
35253                                 if (pointMap[id] === undefined) {
35254                                         pointMap[id] = [];
35255                                 }
35256
35257                                 pointMap[id].push(vertices.length / 3 - 1);
35258                         }
35259
35260                         geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
35261                         geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
35262                         _this = _LineSegments.call(this, geometry, material) || this;
35263                         _this.type = 'CameraHelper';
35264                         _this.camera = camera;
35265                         if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
35266                         _this.matrix = camera.matrixWorld;
35267                         _this.matrixAutoUpdate = false;
35268                         _this.pointMap = pointMap;
35269
35270                         _this.update();
35271
35272                         return _this;
35273                 }
35274
35275                 var _proto = CameraHelper.prototype;
35276
35277                 _proto.update = function update() {
35278                         var geometry = this.geometry;
35279                         var pointMap = this.pointMap;
35280                         var w = 1,
35281                                         h = 1; // we need just camera projection matrix inverse
35282                         // world matrix must be identity
35283
35284                         _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
35285
35286
35287                         setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
35288                         setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
35289
35290                         setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
35291                         setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
35292                         setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
35293                         setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
35294
35295                         setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
35296                         setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
35297                         setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
35298                         setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
35299
35300                         setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
35301                         setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
35302                         setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
35303
35304                         setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
35305                         setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
35306                         setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
35307                         setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
35308                         setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
35309                         setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
35310                         setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
35311                         setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
35312                         geometry.getAttribute('position').needsUpdate = true;
35313                 };
35314
35315                 return CameraHelper;
35316         }(LineSegments);
35317
35318         function setPoint(point, pointMap, geometry, camera, x, y, z) {
35319                 _vector$b.set(x, y, z).unproject(camera);
35320
35321                 var points = pointMap[point];
35322
35323                 if (points !== undefined) {
35324                         var position = geometry.getAttribute('position');
35325
35326                         for (var i = 0, l = points.length; i < l; i++) {
35327                                 position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
35328                         }
35329                 }
35330         }
35331
35332         var _box$3 = /*@__PURE__*/new Box3();
35333
35334         var BoxHelper = /*#__PURE__*/function (_LineSegments) {
35335                 _inheritsLoose(BoxHelper, _LineSegments);
35336
35337                 function BoxHelper(object, color) {
35338                         var _this;
35339
35340                         if (color === void 0) {
35341                                 color = 0xffff00;
35342                         }
35343
35344                         var indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
35345                         var positions = new Float32Array(8 * 3);
35346                         var geometry = new BufferGeometry();
35347                         geometry.setIndex(new BufferAttribute(indices, 1));
35348                         geometry.setAttribute('position', new BufferAttribute(positions, 3));
35349                         _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
35350                                 color: color,
35351                                 toneMapped: false
35352                         })) || this;
35353                         _this.object = object;
35354                         _this.type = 'BoxHelper';
35355                         _this.matrixAutoUpdate = false;
35356
35357                         _this.update();
35358
35359                         return _this;
35360                 }
35361
35362                 var _proto = BoxHelper.prototype;
35363
35364                 _proto.update = function update(object) {
35365                         if (object !== undefined) {
35366                                 console.warn('THREE.BoxHelper: .update() has no longer arguments.');
35367                         }
35368
35369                         if (this.object !== undefined) {
35370                                 _box$3.setFromObject(this.object);
35371                         }
35372
35373                         if (_box$3.isEmpty()) return;
35374                         var min = _box$3.min;
35375                         var max = _box$3.max;
35376                         /*
35377                                 5____4
35378                         1/___0/|
35379                         | 6__|_7
35380                         2/___3/
35381                                 0: max.x, max.y, max.z
35382                         1: min.x, max.y, max.z
35383                         2: min.x, min.y, max.z
35384                         3: max.x, min.y, max.z
35385                         4: max.x, max.y, min.z
35386                         5: min.x, max.y, min.z
35387                         6: min.x, min.y, min.z
35388                         7: max.x, min.y, min.z
35389                         */
35390
35391                         var position = this.geometry.attributes.position;
35392                         var array = position.array;
35393                         array[0] = max.x;
35394                         array[1] = max.y;
35395                         array[2] = max.z;
35396                         array[3] = min.x;
35397                         array[4] = max.y;
35398                         array[5] = max.z;
35399                         array[6] = min.x;
35400                         array[7] = min.y;
35401                         array[8] = max.z;
35402                         array[9] = max.x;
35403                         array[10] = min.y;
35404                         array[11] = max.z;
35405                         array[12] = max.x;
35406                         array[13] = max.y;
35407                         array[14] = min.z;
35408                         array[15] = min.x;
35409                         array[16] = max.y;
35410                         array[17] = min.z;
35411                         array[18] = min.x;
35412                         array[19] = min.y;
35413                         array[20] = min.z;
35414                         array[21] = max.x;
35415                         array[22] = min.y;
35416                         array[23] = min.z;
35417                         position.needsUpdate = true;
35418                         this.geometry.computeBoundingSphere();
35419                 };
35420
35421                 _proto.setFromObject = function setFromObject(object) {
35422                         this.object = object;
35423                         this.update();
35424                         return this;
35425                 };
35426
35427                 _proto.copy = function copy(source) {
35428                         LineSegments.prototype.copy.call(this, source);
35429                         this.object = source.object;
35430                         return this;
35431                 };
35432
35433                 return BoxHelper;
35434         }(LineSegments);
35435
35436         var Box3Helper = /*#__PURE__*/function (_LineSegments) {
35437                 _inheritsLoose(Box3Helper, _LineSegments);
35438
35439                 function Box3Helper(box, color) {
35440                         var _this;
35441
35442                         if (color === void 0) {
35443                                 color = 0xffff00;
35444                         }
35445
35446                         var indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
35447                         var positions = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1];
35448                         var geometry = new BufferGeometry();
35449                         geometry.setIndex(new BufferAttribute(indices, 1));
35450                         geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
35451                         _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
35452                                 color: color,
35453                                 toneMapped: false
35454                         })) || this;
35455                         _this.box = box;
35456                         _this.type = 'Box3Helper';
35457
35458                         _this.geometry.computeBoundingSphere();
35459
35460                         return _this;
35461                 }
35462
35463                 var _proto = Box3Helper.prototype;
35464
35465                 _proto.updateMatrixWorld = function updateMatrixWorld(force) {
35466                         var box = this.box;
35467                         if (box.isEmpty()) return;
35468                         box.getCenter(this.position);
35469                         box.getSize(this.scale);
35470                         this.scale.multiplyScalar(0.5);
35471
35472                         _LineSegments.prototype.updateMatrixWorld.call(this, force);
35473                 };
35474
35475                 return Box3Helper;
35476         }(LineSegments);
35477
35478         var PlaneHelper = /*#__PURE__*/function (_Line) {
35479                 _inheritsLoose(PlaneHelper, _Line);
35480
35481                 function PlaneHelper(plane, size, hex) {
35482                         var _this;
35483
35484                         if (size === void 0) {
35485                                 size = 1;
35486                         }
35487
35488                         if (hex === void 0) {
35489                                 hex = 0xffff00;
35490                         }
35491
35492                         var color = hex;
35493                         var positions = [1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0];
35494                         var geometry = new BufferGeometry();
35495                         geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
35496                         geometry.computeBoundingSphere();
35497                         _this = _Line.call(this, geometry, new LineBasicMaterial({
35498                                 color: color,
35499                                 toneMapped: false
35500                         })) || this;
35501                         _this.type = 'PlaneHelper';
35502                         _this.plane = plane;
35503                         _this.size = size;
35504                         var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
35505                         var geometry2 = new BufferGeometry();
35506                         geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
35507                         geometry2.computeBoundingSphere();
35508
35509                         _this.add(new Mesh(geometry2, new MeshBasicMaterial({
35510                                 color: color,
35511                                 opacity: 0.2,
35512                                 transparent: true,
35513                                 depthWrite: false,
35514                                 toneMapped: false
35515                         })));
35516
35517                         return _this;
35518                 }
35519
35520                 var _proto = PlaneHelper.prototype;
35521
35522                 _proto.updateMatrixWorld = function updateMatrixWorld(force) {
35523                         var scale = -this.plane.constant;
35524                         if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
35525
35526                         this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
35527                         this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
35528
35529                         this.lookAt(this.plane.normal);
35530
35531                         _Line.prototype.updateMatrixWorld.call(this, force);
35532                 };
35533
35534                 return PlaneHelper;
35535         }(Line);
35536
35537         var _axis = /*@__PURE__*/new Vector3();
35538
35539         var _lineGeometry, _coneGeometry;
35540
35541         var ArrowHelper = /*#__PURE__*/function (_Object3D) {
35542                 _inheritsLoose(ArrowHelper, _Object3D);
35543
35544                 function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
35545                         var _this;
35546
35547                         _this = _Object3D.call(this) || this; // dir is assumed to be normalized
35548
35549                         _this.type = 'ArrowHelper';
35550                         if (dir === undefined) dir = new Vector3(0, 0, 1);
35551                         if (origin === undefined) origin = new Vector3(0, 0, 0);
35552                         if (length === undefined) length = 1;
35553                         if (color === undefined) color = 0xffff00;
35554                         if (headLength === undefined) headLength = 0.2 * length;
35555                         if (headWidth === undefined) headWidth = 0.2 * headLength;
35556
35557                         if (_lineGeometry === undefined) {
35558                                 _lineGeometry = new BufferGeometry();
35559
35560                                 _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
35561
35562                                 _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
35563
35564                                 _coneGeometry.translate(0, -0.5, 0);
35565                         }
35566
35567                         _this.position.copy(origin);
35568
35569                         _this.line = new Line(_lineGeometry, new LineBasicMaterial({
35570                                 color: color,
35571                                 toneMapped: false
35572                         }));
35573                         _this.line.matrixAutoUpdate = false;
35574
35575                         _this.add(_this.line);
35576
35577                         _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
35578                                 color: color,
35579                                 toneMapped: false
35580                         }));
35581                         _this.cone.matrixAutoUpdate = false;
35582
35583                         _this.add(_this.cone);
35584
35585                         _this.setDirection(dir);
35586
35587                         _this.setLength(length, headLength, headWidth);
35588
35589                         return _this;
35590                 }
35591
35592                 var _proto = ArrowHelper.prototype;
35593
35594                 _proto.setDirection = function setDirection(dir) {
35595                         // dir is assumed to be normalized
35596                         if (dir.y > 0.99999) {
35597                                 this.quaternion.set(0, 0, 0, 1);
35598                         } else if (dir.y < -0.99999) {
35599                                 this.quaternion.set(1, 0, 0, 0);
35600                         } else {
35601                                 _axis.set(dir.z, 0, -dir.x).normalize();
35602
35603                                 var radians = Math.acos(dir.y);
35604                                 this.quaternion.setFromAxisAngle(_axis, radians);
35605                         }
35606                 };
35607
35608                 _proto.setLength = function setLength(length, headLength, headWidth) {
35609                         if (headLength === undefined) headLength = 0.2 * length;
35610                         if (headWidth === undefined) headWidth = 0.2 * headLength;
35611                         this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
35612
35613                         this.line.updateMatrix();
35614                         this.cone.scale.set(headWidth, headLength, headWidth);
35615                         this.cone.position.y = length;
35616                         this.cone.updateMatrix();
35617                 };
35618
35619                 _proto.setColor = function setColor(color) {
35620                         this.line.material.color.set(color);
35621                         this.cone.material.color.set(color);
35622                 };
35623
35624                 _proto.copy = function copy(source) {
35625                         _Object3D.prototype.copy.call(this, source, false);
35626
35627                         this.line.copy(source.line);
35628                         this.cone.copy(source.cone);
35629                         return this;
35630                 };
35631
35632                 return ArrowHelper;
35633         }(Object3D);
35634
35635         var AxesHelper = /*#__PURE__*/function (_LineSegments) {
35636                 _inheritsLoose(AxesHelper, _LineSegments);
35637
35638                 function AxesHelper(size) {
35639                         var _this;
35640
35641                         if (size === void 0) {
35642                                 size = 1;
35643                         }
35644
35645                         var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
35646                         var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
35647                         var geometry = new BufferGeometry();
35648                         geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
35649                         geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
35650                         var material = new LineBasicMaterial({
35651                                 vertexColors: true,
35652                                 toneMapped: false
35653                         });
35654                         _this = _LineSegments.call(this, geometry, material) || this;
35655                         _this.type = 'AxesHelper';
35656                         return _this;
35657                 }
35658
35659                 return AxesHelper;
35660         }(LineSegments);
35661
35662         var _floatView = new Float32Array(1);
35663
35664         var _int32View = new Int32Array(_floatView.buffer);
35665
35666         var DataUtils = {
35667                 // Converts float32 to float16 (stored as uint16 value).
35668                 toHalfFloat: function toHalfFloat(val) {
35669                         // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
35670
35671                         /* This method is faster than the OpenEXR implementation (very often
35672                         * used, eg. in Ogre), with the additional benefit of rounding, inspired
35673                         * by James Tursa?s half-precision code. */
35674                         _floatView[0] = val;
35675                         var x = _int32View[0];
35676                         var bits = x >> 16 & 0x8000;
35677                         /* Get the sign */
35678
35679                         var m = x >> 12 & 0x07ff;
35680                         /* Keep one extra bit for rounding */
35681
35682                         var e = x >> 23 & 0xff;
35683                         /* Using int is faster here */
35684
35685                         /* If zero, or denormal, or exponent underflows too much for a denormal
35686                                 * half, return signed zero. */
35687
35688                         if (e < 103) return bits;
35689                         /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
35690
35691                         if (e > 142) {
35692                                 bits |= 0x7c00;
35693                                 /* If exponent was 0xff and one mantissa bit was set, it means NaN,
35694                                                         * not Inf, so make sure we set one mantissa bit too. */
35695
35696                                 bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
35697                                 return bits;
35698                         }
35699                         /* If exponent underflows but not too much, return a denormal */
35700
35701
35702                         if (e < 113) {
35703                                 m |= 0x0800;
35704                                 /* Extra rounding may overflow and set mantissa to 0 and exponent
35705                                         * to 1, which is OK. */
35706
35707                                 bits |= (m >> 114 - e) + (m >> 113 - e & 1);
35708                                 return bits;
35709                         }
35710
35711                         bits |= e - 112 << 10 | m >> 1;
35712                         /* Extra rounding. An overflow will set mantissa to 0 and increment
35713                                 * the exponent, which is OK. */
35714
35715                         bits += m & 1;
35716                         return bits;
35717                 }
35718         };
35719
35720         var _ENCODINGS;
35721         var LOD_MIN = 4;
35722         var LOD_MAX = 8;
35723         var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
35724         // chosen to approximate a Trowbridge-Reitz distribution function times the
35725         // geometric shadowing function. These sigma values squared must match the
35726         // variance #defines in cube_uv_reflection_fragment.glsl.js.
35727
35728         var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
35729         var TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length; // The maximum length of the blur for loop. Smaller sigmas will use fewer
35730         // samples and exit early, but not recompile the shader.
35731
35732         var MAX_SAMPLES = 20;
35733         var ENCODINGS = (_ENCODINGS = {}, _ENCODINGS[LinearEncoding] = 0, _ENCODINGS[sRGBEncoding] = 1, _ENCODINGS[RGBEEncoding] = 2, _ENCODINGS[RGBM7Encoding] = 3, _ENCODINGS[RGBM16Encoding] = 4, _ENCODINGS[RGBDEncoding] = 5, _ENCODINGS[GammaEncoding] = 6, _ENCODINGS);
35734
35735         var _flatCamera = /*@__PURE__*/new OrthographicCamera();
35736
35737         var _createPlanes2 = /*@__PURE__*/_createPlanes(),
35738                         _lodPlanes = _createPlanes2._lodPlanes,
35739                         _sizeLods = _createPlanes2._sizeLods,
35740                         _sigmas = _createPlanes2._sigmas;
35741
35742         var _oldTarget = null; // Golden Ratio
35743
35744         var PHI = (1 + Math.sqrt(5)) / 2;
35745         var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
35746         // same axis), used as axis directions evenly spread on a sphere.
35747
35748         var _axisDirections = [/*@__PURE__*/new Vector3(1, 1, 1), /*@__PURE__*/new Vector3(-1, 1, 1), /*@__PURE__*/new Vector3(1, 1, -1), /*@__PURE__*/new Vector3(-1, 1, -1), /*@__PURE__*/new Vector3(0, PHI, INV_PHI), /*@__PURE__*/new Vector3(0, PHI, -INV_PHI), /*@__PURE__*/new Vector3(INV_PHI, 0, PHI), /*@__PURE__*/new Vector3(-INV_PHI, 0, PHI), /*@__PURE__*/new Vector3(PHI, INV_PHI, 0), /*@__PURE__*/new Vector3(-PHI, INV_PHI, 0)];
35749         /**
35750          * This class generates a Prefiltered, Mipmapped Radiance Environment Map
35751          * (PMREM) from a cubeMap environment texture. This allows different levels of
35752          * blur to be quickly accessed based on material roughness. It is packed into a
35753          * special CubeUV format that allows us to perform custom interpolation so that
35754          * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
35755          * chain, it only goes down to the LOD_MIN level (above), and then creates extra
35756          * even more filtered 'mips' at the same LOD_MIN resolution, associated with
35757          * higher roughness levels. In this way we maintain resolution to smoothly
35758          * interpolate diffuse lighting while limiting sampling computation.
35759          */
35760
35761         var PMREMGenerator = /*#__PURE__*/function () {
35762                 function PMREMGenerator(renderer) {
35763                         this._renderer = renderer;
35764                         this._pingPongRenderTarget = null;
35765                         this._blurMaterial = _getBlurShader(MAX_SAMPLES);
35766                         this._equirectShader = null;
35767                         this._cubemapShader = null;
35768
35769                         this._compileMaterial(this._blurMaterial);
35770                 }
35771                 /**
35772                  * Generates a PMREM from a supplied Scene, which can be faster than using an
35773                  * image if networking bandwidth is low. Optional sigma specifies a blur radius
35774                  * in radians to be applied to the scene before PMREM generation. Optional near
35775                  * and far planes ensure the scene is rendered in its entirety (the cubeCamera
35776                  * is placed at the origin).
35777                  */
35778
35779
35780                 var _proto = PMREMGenerator.prototype;
35781
35782                 _proto.fromScene = function fromScene(scene, sigma, near, far) {
35783                         if (sigma === void 0) {
35784                                 sigma = 0;
35785                         }
35786
35787                         if (near === void 0) {
35788                                 near = 0.1;
35789                         }
35790
35791                         if (far === void 0) {
35792                                 far = 100;
35793                         }
35794
35795                         _oldTarget = this._renderer.getRenderTarget();
35796
35797                         var cubeUVRenderTarget = this._allocateTargets();
35798
35799                         this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
35800
35801                         if (sigma > 0) {
35802                                 this._blur(cubeUVRenderTarget, 0, 0, sigma);
35803                         }
35804
35805                         this._applyPMREM(cubeUVRenderTarget);
35806
35807                         this._cleanup(cubeUVRenderTarget);
35808
35809                         return cubeUVRenderTarget;
35810                 }
35811                 /**
35812                  * Generates a PMREM from an equirectangular texture, which can be either LDR
35813                  * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
35814                  * as this matches best with the 256 x 256 cubemap output.
35815                  */
35816                 ;
35817
35818                 _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
35819                         return this._fromTexture(equirectangular);
35820                 }
35821                 /**
35822                  * Generates a PMREM from an cubemap texture, which can be either LDR
35823                  * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
35824                  * as this matches best with the 256 x 256 cubemap output.
35825                  */
35826                 ;
35827
35828                 _proto.fromCubemap = function fromCubemap(cubemap) {
35829                         return this._fromTexture(cubemap);
35830                 }
35831                 /**
35832                  * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
35833                  * your texture's network fetch for increased concurrency.
35834                  */
35835                 ;
35836
35837                 _proto.compileCubemapShader = function compileCubemapShader() {
35838                         if (this._cubemapShader === null) {
35839                                 this._cubemapShader = _getCubemapShader();
35840
35841                                 this._compileMaterial(this._cubemapShader);
35842                         }
35843                 }
35844                 /**
35845                  * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
35846                  * your texture's network fetch for increased concurrency.
35847                  */
35848                 ;
35849
35850                 _proto.compileEquirectangularShader = function compileEquirectangularShader() {
35851                         if (this._equirectShader === null) {
35852                                 this._equirectShader = _getEquirectShader();
35853
35854                                 this._compileMaterial(this._equirectShader);
35855                         }
35856                 }
35857                 /**
35858                  * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
35859                  * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
35860                  * one of them will cause any others to also become unusable.
35861                  */
35862                 ;
35863
35864                 _proto.dispose = function dispose() {
35865                         this._blurMaterial.dispose();
35866
35867                         if (this._cubemapShader !== null) this._cubemapShader.dispose();
35868                         if (this._equirectShader !== null) this._equirectShader.dispose();
35869
35870                         for (var i = 0; i < _lodPlanes.length; i++) {
35871                                 _lodPlanes[i].dispose();
35872                         }
35873                 } // private interface
35874                 ;
35875
35876                 _proto._cleanup = function _cleanup(outputTarget) {
35877                         this._pingPongRenderTarget.dispose();
35878
35879                         this._renderer.setRenderTarget(_oldTarget);
35880
35881                         outputTarget.scissorTest = false;
35882
35883                         _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
35884                 };
35885
35886                 _proto._fromTexture = function _fromTexture(texture) {
35887                         _oldTarget = this._renderer.getRenderTarget();
35888
35889                         var cubeUVRenderTarget = this._allocateTargets(texture);
35890
35891                         this._textureToCubeUV(texture, cubeUVRenderTarget);
35892
35893                         this._applyPMREM(cubeUVRenderTarget);
35894
35895                         this._cleanup(cubeUVRenderTarget);
35896
35897                         return cubeUVRenderTarget;
35898                 };
35899
35900                 _proto._allocateTargets = function _allocateTargets(texture) {
35901                         // warning: null texture is valid
35902                         var params = {
35903                                 magFilter: NearestFilter,
35904                                 minFilter: NearestFilter,
35905                                 generateMipmaps: false,
35906                                 type: UnsignedByteType,
35907                                 format: RGBEFormat,
35908                                 encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
35909                                 depthBuffer: false
35910                         };
35911
35912                         var cubeUVRenderTarget = _createRenderTarget(params);
35913
35914                         cubeUVRenderTarget.depthBuffer = texture ? false : true;
35915                         this._pingPongRenderTarget = _createRenderTarget(params);
35916                         return cubeUVRenderTarget;
35917                 };
35918
35919                 _proto._compileMaterial = function _compileMaterial(material) {
35920                         var tmpMesh = new Mesh(_lodPlanes[0], material);
35921
35922                         this._renderer.compile(tmpMesh, _flatCamera);
35923                 };
35924
35925                 _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
35926                         var fov = 90;
35927                         var aspect = 1;
35928                         var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
35929                         var upSign = [1, -1, 1, 1, 1, 1];
35930                         var forwardSign = [1, 1, 1, -1, -1, -1];
35931                         var renderer = this._renderer;
35932                         var outputEncoding = renderer.outputEncoding;
35933                         var toneMapping = renderer.toneMapping;
35934                         var clearColor = renderer.getClearColor();
35935                         var clearAlpha = renderer.getClearAlpha();
35936                         renderer.toneMapping = NoToneMapping;
35937                         renderer.outputEncoding = LinearEncoding;
35938                         var background = scene.background;
35939
35940                         if (background && background.isColor) {
35941                                 background.convertSRGBToLinear(); // Convert linear to RGBE
35942
35943                                 var maxComponent = Math.max(background.r, background.g, background.b);
35944                                 var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
35945                                 background = background.multiplyScalar(Math.pow(2.0, -fExp));
35946                                 var alpha = (fExp + 128.0) / 255.0;
35947                                 renderer.setClearColor(background, alpha);
35948                                 scene.background = null;
35949                         }
35950
35951                         for (var i = 0; i < 6; i++) {
35952                                 var col = i % 3;
35953
35954                                 if (col == 0) {
35955                                         cubeCamera.up.set(0, upSign[i], 0);
35956                                         cubeCamera.lookAt(forwardSign[i], 0, 0);
35957                                 } else if (col == 1) {
35958                                         cubeCamera.up.set(0, 0, upSign[i]);
35959                                         cubeCamera.lookAt(0, forwardSign[i], 0);
35960                                 } else {
35961                                         cubeCamera.up.set(0, upSign[i], 0);
35962                                         cubeCamera.lookAt(0, 0, forwardSign[i]);
35963                                 }
35964
35965                                 _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
35966
35967                                 renderer.setRenderTarget(cubeUVRenderTarget);
35968                                 renderer.render(scene, cubeCamera);
35969                         }
35970
35971                         renderer.toneMapping = toneMapping;
35972                         renderer.outputEncoding = outputEncoding;
35973                         renderer.setClearColor(clearColor, clearAlpha);
35974                 };
35975
35976                 _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
35977                         var renderer = this._renderer;
35978
35979                         if (texture.isCubeTexture) {
35980                                 if (this._cubemapShader == null) {
35981                                         this._cubemapShader = _getCubemapShader();
35982                                 }
35983                         } else {
35984                                 if (this._equirectShader == null) {
35985                                         this._equirectShader = _getEquirectShader();
35986                                 }
35987                         }
35988
35989                         var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
35990                         var mesh = new Mesh(_lodPlanes[0], material);
35991                         var uniforms = material.uniforms;
35992                         uniforms['envMap'].value = texture;
35993
35994                         if (!texture.isCubeTexture) {
35995                                 uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
35996                         }
35997
35998                         uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
35999                         uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
36000
36001                         _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
36002
36003                         renderer.setRenderTarget(cubeUVRenderTarget);
36004                         renderer.render(mesh, _flatCamera);
36005                 };
36006
36007                 _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
36008                         var renderer = this._renderer;
36009                         var autoClear = renderer.autoClear;
36010                         renderer.autoClear = false;
36011
36012                         for (var i = 1; i < TOTAL_LODS; i++) {
36013                                 var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
36014                                 var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
36015
36016                                 this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
36017                         }
36018
36019                         renderer.autoClear = autoClear;
36020                 }
36021                 /**
36022                  * This is a two-pass Gaussian blur for a cubemap. Normally this is done
36023                  * vertically and horizontally, but this breaks down on a cube. Here we apply
36024                  * the blur latitudinally (around the poles), and then longitudinally (towards
36025                  * the poles) to approximate the orthogonally-separable blur. It is least
36026                  * accurate at the poles, but still does a decent job.
36027                  */
36028                 ;
36029
36030                 _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
36031                         var pingPongRenderTarget = this._pingPongRenderTarget;
36032
36033                         this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
36034
36035                         this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
36036                 };
36037
36038                 _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
36039                         var renderer = this._renderer;
36040                         var blurMaterial = this._blurMaterial;
36041
36042                         if (direction !== 'latitudinal' && direction !== 'longitudinal') {
36043                                 console.error('blur direction must be either latitudinal or longitudinal!');
36044                         } // Number of standard deviations at which to cut off the discrete approximation.
36045
36046
36047                         var STANDARD_DEVIATIONS = 3;
36048                         var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
36049                         var blurUniforms = blurMaterial.uniforms;
36050                         var pixels = _sizeLods[lodIn] - 1;
36051                         var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
36052                         var sigmaPixels = sigmaRadians / radiansPerPixel;
36053                         var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
36054
36055                         if (samples > MAX_SAMPLES) {
36056                                 console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
36057                         }
36058
36059                         var weights = [];
36060                         var sum = 0;
36061
36062                         for (var i = 0; i < MAX_SAMPLES; ++i) {
36063                                 var _x = i / sigmaPixels;
36064
36065                                 var weight = Math.exp(-_x * _x / 2);
36066                                 weights.push(weight);
36067
36068                                 if (i == 0) {
36069                                         sum += weight;
36070                                 } else if (i < samples) {
36071                                         sum += 2 * weight;
36072                                 }
36073                         }
36074
36075                         for (var _i = 0; _i < weights.length; _i++) {
36076                                 weights[_i] = weights[_i] / sum;
36077                         }
36078
36079                         blurUniforms['envMap'].value = targetIn.texture;
36080                         blurUniforms['samples'].value = samples;
36081                         blurUniforms['weights'].value = weights;
36082                         blurUniforms['latitudinal'].value = direction === 'latitudinal';
36083
36084                         if (poleAxis) {
36085                                 blurUniforms['poleAxis'].value = poleAxis;
36086                         }
36087
36088                         blurUniforms['dTheta'].value = radiansPerPixel;
36089                         blurUniforms['mipInt'].value = LOD_MAX - lodIn;
36090                         blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
36091                         blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
36092                         var outputSize = _sizeLods[lodOut];
36093                         var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
36094                         var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
36095
36096                         _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
36097
36098                         renderer.setRenderTarget(targetOut);
36099                         renderer.render(blurMesh, _flatCamera);
36100                 };
36101
36102                 return PMREMGenerator;
36103         }();
36104
36105         function _isLDR(texture) {
36106                 if (texture === undefined || texture.type !== UnsignedByteType) return false;
36107                 return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
36108         }
36109
36110         function _createPlanes() {
36111                 var _lodPlanes = [];
36112                 var _sizeLods = [];
36113                 var _sigmas = [];
36114                 var lod = LOD_MAX;
36115
36116                 for (var i = 0; i < TOTAL_LODS; i++) {
36117                         var sizeLod = Math.pow(2, lod);
36118
36119                         _sizeLods.push(sizeLod);
36120
36121                         var sigma = 1.0 / sizeLod;
36122
36123                         if (i > LOD_MAX - LOD_MIN) {
36124                                 sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
36125                         } else if (i == 0) {
36126                                 sigma = 0;
36127                         }
36128
36129                         _sigmas.push(sigma);
36130
36131                         var texelSize = 1.0 / (sizeLod - 1);
36132                         var min = -texelSize / 2;
36133                         var max = 1 + texelSize / 2;
36134                         var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
36135                         var cubeFaces = 6;
36136                         var vertices = 6;
36137                         var positionSize = 3;
36138                         var uvSize = 2;
36139                         var faceIndexSize = 1;
36140                         var position = new Float32Array(positionSize * vertices * cubeFaces);
36141                         var uv = new Float32Array(uvSize * vertices * cubeFaces);
36142                         var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
36143
36144                         for (var face = 0; face < cubeFaces; face++) {
36145                                 var x = face % 3 * 2 / 3 - 1;
36146                                 var y = face > 2 ? 0 : -1;
36147                                 var coordinates = [x, y, 0, x + 2 / 3, y, 0, x + 2 / 3, y + 1, 0, x, y, 0, x + 2 / 3, y + 1, 0, x, y + 1, 0];
36148                                 position.set(coordinates, positionSize * vertices * face);
36149                                 uv.set(uv1, uvSize * vertices * face);
36150                                 var fill = [face, face, face, face, face, face];
36151                                 faceIndex.set(fill, faceIndexSize * vertices * face);
36152                         }
36153
36154                         var planes = new BufferGeometry();
36155                         planes.setAttribute('position', new BufferAttribute(position, positionSize));
36156                         planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
36157                         planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
36158
36159                         _lodPlanes.push(planes);
36160
36161                         if (lod > LOD_MIN) {
36162                                 lod--;
36163                         }
36164                 }
36165
36166                 return {
36167                         _lodPlanes: _lodPlanes,
36168                         _sizeLods: _sizeLods,
36169                         _sigmas: _sigmas
36170                 };
36171         }
36172
36173         function _createRenderTarget(params) {
36174                 var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
36175                 cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
36176                 cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
36177                 cubeUVRenderTarget.scissorTest = true;
36178                 return cubeUVRenderTarget;
36179         }
36180
36181         function _setViewport(target, x, y, width, height) {
36182                 target.viewport.set(x, y, width, height);
36183                 target.scissor.set(x, y, width, height);
36184         }
36185
36186         function _getBlurShader(maxSamples) {
36187                 var weights = new Float32Array(maxSamples);
36188                 var poleAxis = new Vector3(0, 1, 0);
36189                 var shaderMaterial = new RawShaderMaterial({
36190                         name: 'SphericalGaussianBlur',
36191                         defines: {
36192                                 'n': maxSamples
36193                         },
36194                         uniforms: {
36195                                 'envMap': {
36196                                         value: null
36197                                 },
36198                                 'samples': {
36199                                         value: 1
36200                                 },
36201                                 'weights': {
36202                                         value: weights
36203                                 },
36204                                 'latitudinal': {
36205                                         value: false
36206                                 },
36207                                 'dTheta': {
36208                                         value: 0
36209                                 },
36210                                 'mipInt': {
36211                                         value: 0
36212                                 },
36213                                 'poleAxis': {
36214                                         value: poleAxis
36215                                 },
36216                                 'inputEncoding': {
36217                                         value: ENCODINGS[LinearEncoding]
36218                                 },
36219                                 'outputEncoding': {
36220                                         value: ENCODINGS[LinearEncoding]
36221                                 }
36222                         },
36223                         vertexShader: _getCommonVertexShader(),
36224                         fragmentShader:
36225                         /* glsl */
36226                         "\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t" + _getEncodings() + "\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",
36227                         blending: NoBlending,
36228                         depthTest: false,
36229                         depthWrite: false
36230                 });
36231                 return shaderMaterial;
36232         }
36233
36234         function _getEquirectShader() {
36235                 var texelSize = new Vector2(1, 1);
36236                 var shaderMaterial = new RawShaderMaterial({
36237                         name: 'EquirectangularToCubeUV',
36238                         uniforms: {
36239                                 'envMap': {
36240                                         value: null
36241                                 },
36242                                 'texelSize': {
36243                                         value: texelSize
36244                                 },
36245                                 'inputEncoding': {
36246                                         value: ENCODINGS[LinearEncoding]
36247                                 },
36248                                 'outputEncoding': {
36249                                         value: ENCODINGS[LinearEncoding]
36250                                 }
36251                         },
36252                         vertexShader: _getCommonVertexShader(),
36253                         fragmentShader:
36254                         /* glsl */
36255                         "\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform vec2 texelSize;\n\n\t\t\t" + _getEncodings() + "\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tvec2 f = fract( uv / texelSize - 0.5 );\n\t\t\t\tuv -= f * texelSize;\n\t\t\t\tvec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x += texelSize.x;\n\t\t\t\tvec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.y += texelSize.y;\n\t\t\t\tvec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x -= texelSize.x;\n\t\t\t\tvec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\n\t\t\t\tvec3 tm = mix( tl, tr, f.x );\n\t\t\t\tvec3 bm = mix( bl, br, f.x );\n\t\t\t\tgl_FragColor.rgb = mix( tm, bm, f.y );\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",
36256                         blending: NoBlending,
36257                         depthTest: false,
36258                         depthWrite: false
36259                 });
36260                 return shaderMaterial;
36261         }
36262
36263         function _getCubemapShader() {
36264                 var shaderMaterial = new RawShaderMaterial({
36265                         name: 'CubemapToCubeUV',
36266                         uniforms: {
36267                                 'envMap': {
36268                                         value: null
36269                                 },
36270                                 'inputEncoding': {
36271                                         value: ENCODINGS[LinearEncoding]
36272                                 },
36273                                 'outputEncoding': {
36274                                         value: ENCODINGS[LinearEncoding]
36275                                 }
36276                         },
36277                         vertexShader: _getCommonVertexShader(),
36278                         fragmentShader:
36279                         /* glsl */
36280                         "\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\t" + _getEncodings() + "\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",
36281                         blending: NoBlending,
36282                         depthTest: false,
36283                         depthWrite: false
36284                 });
36285                 return shaderMaterial;
36286         }
36287
36288         function _getCommonVertexShader() {
36289                 return (
36290                         /* glsl */
36291                         "\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t"
36292                 );
36293         }
36294
36295         function _getEncodings() {
36296                 return (
36297                         /* glsl */
36298                         "\n\n\t\tuniform int inputEncoding;\n\t\tuniform int outputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( inputEncoding == 1 ) {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 2 ) {\n\n\t\t\t\treturn RGBEToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 3 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 7.0 );\n\n\t\t\t} else if ( inputEncoding == 4 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 16.0 );\n\n\t\t\t} else if ( inputEncoding == 5 ) {\n\n\t\t\t\treturn RGBDToLinear( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn GammaToLinear( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 linearToOutputTexel( vec4 value ) {\n\n\t\t\tif ( outputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( outputEncoding == 1 ) {\n\n\t\t\t\treturn LinearTosRGB( value );\n\n\t\t\t} else if ( outputEncoding == 2 ) {\n\n\t\t\t\treturn LinearToRGBE( value );\n\n\t\t\t} else if ( outputEncoding == 3 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 7.0 );\n\n\t\t\t} else if ( outputEncoding == 4 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 16.0 );\n\n\t\t\t} else if ( outputEncoding == 5 ) {\n\n\t\t\t\treturn LinearToRGBD( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn LinearToGamma( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t"
36299                 );
36300         }
36301
36302         function Face4(a, b, c, d, normal, color, materialIndex) {
36303                 console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
36304                 return new Face3(a, b, c, normal, color, materialIndex);
36305         }
36306         var LineStrip = 0;
36307         var LinePieces = 1;
36308         var NoColors = 0;
36309         var FaceColors = 1;
36310         var VertexColors = 2;
36311         function MeshFaceMaterial(materials) {
36312                 console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
36313                 return materials;
36314         }
36315         function MultiMaterial(materials) {
36316                 if (materials === void 0) {
36317                         materials = [];
36318                 }
36319
36320                 console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
36321                 materials.isMultiMaterial = true;
36322                 materials.materials = materials;
36323
36324                 materials.clone = function () {
36325                         return materials.slice();
36326                 };
36327
36328                 return materials;
36329         }
36330         function PointCloud(geometry, material) {
36331                 console.warn('THREE.PointCloud has been renamed to THREE.Points.');
36332                 return new Points(geometry, material);
36333         }
36334         function Particle(material) {
36335                 console.warn('THREE.Particle has been renamed to THREE.Sprite.');
36336                 return new Sprite(material);
36337         }
36338         function ParticleSystem(geometry, material) {
36339                 console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
36340                 return new Points(geometry, material);
36341         }
36342         function PointCloudMaterial(parameters) {
36343                 console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
36344                 return new PointsMaterial(parameters);
36345         }
36346         function ParticleBasicMaterial(parameters) {
36347                 console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
36348                 return new PointsMaterial(parameters);
36349         }
36350         function ParticleSystemMaterial(parameters) {
36351                 console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
36352                 return new PointsMaterial(parameters);
36353         }
36354         function Vertex(x, y, z) {
36355                 console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
36356                 return new Vector3(x, y, z);
36357         } //
36358
36359         function DynamicBufferAttribute(array, itemSize) {
36360                 console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
36361                 return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
36362         }
36363         function Int8Attribute(array, itemSize) {
36364                 console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
36365                 return new Int8BufferAttribute(array, itemSize);
36366         }
36367         function Uint8Attribute(array, itemSize) {
36368                 console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
36369                 return new Uint8BufferAttribute(array, itemSize);
36370         }
36371         function Uint8ClampedAttribute(array, itemSize) {
36372                 console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
36373                 return new Uint8ClampedBufferAttribute(array, itemSize);
36374         }
36375         function Int16Attribute(array, itemSize) {
36376                 console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
36377                 return new Int16BufferAttribute(array, itemSize);
36378         }
36379         function Uint16Attribute(array, itemSize) {
36380                 console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
36381                 return new Uint16BufferAttribute(array, itemSize);
36382         }
36383         function Int32Attribute(array, itemSize) {
36384                 console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
36385                 return new Int32BufferAttribute(array, itemSize);
36386         }
36387         function Uint32Attribute(array, itemSize) {
36388                 console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
36389                 return new Uint32BufferAttribute(array, itemSize);
36390         }
36391         function Float32Attribute(array, itemSize) {
36392                 console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
36393                 return new Float32BufferAttribute(array, itemSize);
36394         }
36395         function Float64Attribute(array, itemSize) {
36396                 console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
36397                 return new Float64BufferAttribute(array, itemSize);
36398         } //
36399
36400         Curve.create = function (construct, getPoint) {
36401                 console.log('THREE.Curve.create() has been deprecated');
36402                 construct.prototype = Object.create(Curve.prototype);
36403                 construct.prototype.constructor = construct;
36404                 construct.prototype.getPoint = getPoint;
36405                 return construct;
36406         }; //
36407
36408
36409         Object.assign(CurvePath.prototype, {
36410                 createPointsGeometry: function createPointsGeometry(divisions) {
36411                         console.warn('THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from path points (for Line or Points objects)
36412
36413                         var pts = this.getPoints(divisions);
36414                         return this.createGeometry(pts);
36415                 },
36416                 createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
36417                         console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
36418
36419                         var pts = this.getSpacedPoints(divisions);
36420                         return this.createGeometry(pts);
36421                 },
36422                 createGeometry: function createGeometry(points) {
36423                         console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
36424                         var geometry = new Geometry();
36425
36426                         for (var i = 0, l = points.length; i < l; i++) {
36427                                 var point = points[i];
36428                                 geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
36429                         }
36430
36431                         return geometry;
36432                 }
36433         }); //
36434
36435         Object.assign(Path.prototype, {
36436                 fromPoints: function fromPoints(points) {
36437                         console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
36438                         return this.setFromPoints(points);
36439                 }
36440         }); //
36441
36442         function ClosedSplineCurve3(points) {
36443                 console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
36444                 CatmullRomCurve3.call(this, points);
36445                 this.type = 'catmullrom';
36446                 this.closed = true;
36447         }
36448         ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
36449
36450         function SplineCurve3(points) {
36451                 console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
36452                 CatmullRomCurve3.call(this, points);
36453                 this.type = 'catmullrom';
36454         }
36455         SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
36456
36457         function Spline(points) {
36458                 console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
36459                 CatmullRomCurve3.call(this, points);
36460                 this.type = 'catmullrom';
36461         }
36462         Spline.prototype = Object.create(CatmullRomCurve3.prototype);
36463         Object.assign(Spline.prototype, {
36464                 initFromArray: function initFromArray()
36465                 /* a */
36466                 {
36467                         console.error('THREE.Spline: .initFromArray() has been removed.');
36468                 },
36469                 getControlPointsArray: function getControlPointsArray()
36470                 /* optionalTarget */
36471                 {
36472                         console.error('THREE.Spline: .getControlPointsArray() has been removed.');
36473                 },
36474                 reparametrizeByArcLength: function reparametrizeByArcLength()
36475                 /* samplingCoef */
36476                 {
36477                         console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
36478                 }
36479         }); //
36480
36481         function AxisHelper(size) {
36482                 console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
36483                 return new AxesHelper(size);
36484         }
36485         function BoundingBoxHelper(object, color) {
36486                 console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
36487                 return new BoxHelper(object, color);
36488         }
36489         function EdgesHelper(object, hex) {
36490                 console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
36491                 return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
36492                         color: hex !== undefined ? hex : 0xffffff
36493                 }));
36494         }
36495
36496         GridHelper.prototype.setColors = function () {
36497                 console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
36498         };
36499
36500         SkeletonHelper.prototype.update = function () {
36501                 console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
36502         };
36503
36504         function WireframeHelper(object, hex) {
36505                 console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
36506                 return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
36507                         color: hex !== undefined ? hex : 0xffffff
36508                 }));
36509         } //
36510
36511         Object.assign(Loader.prototype, {
36512                 extractUrlBase: function extractUrlBase(url) {
36513                         console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
36514                         return LoaderUtils.extractUrlBase(url);
36515                 }
36516         });
36517         Loader.Handlers = {
36518                 add: function add()
36519                 /* regex, loader */
36520                 {
36521                         console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
36522                 },
36523                 get: function get()
36524                 /* file */
36525                 {
36526                         console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
36527                 }
36528         };
36529         function XHRLoader(manager) {
36530                 console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
36531                 return new FileLoader(manager);
36532         }
36533         function BinaryTextureLoader(manager) {
36534                 console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
36535                 return new DataTextureLoader(manager);
36536         } //
36537
36538         Object.assign(Box2.prototype, {
36539                 center: function center(optionalTarget) {
36540                         console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
36541                         return this.getCenter(optionalTarget);
36542                 },
36543                 empty: function empty() {
36544                         console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
36545                         return this.isEmpty();
36546                 },
36547                 isIntersectionBox: function isIntersectionBox(box) {
36548                         console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
36549                         return this.intersectsBox(box);
36550                 },
36551                 size: function size(optionalTarget) {
36552                         console.warn('THREE.Box2: .size() has been renamed to .getSize().');
36553                         return this.getSize(optionalTarget);
36554                 }
36555         });
36556         Object.assign(Box3.prototype, {
36557                 center: function center(optionalTarget) {
36558                         console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
36559                         return this.getCenter(optionalTarget);
36560                 },
36561                 empty: function empty() {
36562                         console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
36563                         return this.isEmpty();
36564                 },
36565                 isIntersectionBox: function isIntersectionBox(box) {
36566                         console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
36567                         return this.intersectsBox(box);
36568                 },
36569                 isIntersectionSphere: function isIntersectionSphere(sphere) {
36570                         console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
36571                         return this.intersectsSphere(sphere);
36572                 },
36573                 size: function size(optionalTarget) {
36574                         console.warn('THREE.Box3: .size() has been renamed to .getSize().');
36575                         return this.getSize(optionalTarget);
36576                 }
36577         });
36578         Object.assign(Sphere.prototype, {
36579                 empty: function empty() {
36580                         console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
36581                         return this.isEmpty();
36582                 }
36583         });
36584
36585         Frustum.prototype.setFromMatrix = function (m) {
36586                 console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
36587                 return this.setFromProjectionMatrix(m);
36588         };
36589
36590         Line3.prototype.center = function (optionalTarget) {
36591                 console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
36592                 return this.getCenter(optionalTarget);
36593         };
36594
36595         Object.assign(MathUtils, {
36596                 random16: function random16() {
36597                         console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
36598                         return Math.random();
36599                 },
36600                 nearestPowerOfTwo: function nearestPowerOfTwo(value) {
36601                         console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
36602                         return MathUtils.floorPowerOfTwo(value);
36603                 },
36604                 nextPowerOfTwo: function nextPowerOfTwo(value) {
36605                         console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
36606                         return MathUtils.ceilPowerOfTwo(value);
36607                 }
36608         });
36609         Object.assign(Matrix3.prototype, {
36610                 flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
36611                         console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
36612                         return this.toArray(array, offset);
36613                 },
36614                 multiplyVector3: function multiplyVector3(vector) {
36615                         console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
36616                         return vector.applyMatrix3(this);
36617                 },
36618                 multiplyVector3Array: function multiplyVector3Array()
36619                 /* a */
36620                 {
36621                         console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
36622                 },
36623                 applyToBufferAttribute: function applyToBufferAttribute(attribute) {
36624                         console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
36625                         return attribute.applyMatrix3(this);
36626                 },
36627                 applyToVector3Array: function applyToVector3Array()
36628                 /* array, offset, length */
36629                 {
36630                         console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
36631                 },
36632                 getInverse: function getInverse(matrix) {
36633                         console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
36634                         return this.copy(matrix).invert();
36635                 }
36636         });
36637         Object.assign(Matrix4.prototype, {
36638                 extractPosition: function extractPosition(m) {
36639                         console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
36640                         return this.copyPosition(m);
36641                 },
36642                 flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
36643                         console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
36644                         return this.toArray(array, offset);
36645                 },
36646                 getPosition: function getPosition() {
36647                         console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
36648                         return new Vector3().setFromMatrixColumn(this, 3);
36649                 },
36650                 setRotationFromQuaternion: function setRotationFromQuaternion(q) {
36651                         console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
36652                         return this.makeRotationFromQuaternion(q);
36653                 },
36654                 multiplyToArray: function multiplyToArray() {
36655                         console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
36656                 },
36657                 multiplyVector3: function multiplyVector3(vector) {
36658                         console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
36659                         return vector.applyMatrix4(this);
36660                 },
36661                 multiplyVector4: function multiplyVector4(vector) {
36662                         console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
36663                         return vector.applyMatrix4(this);
36664                 },
36665                 multiplyVector3Array: function multiplyVector3Array()
36666                 /* a */
36667                 {
36668                         console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
36669                 },
36670                 rotateAxis: function rotateAxis(v) {
36671                         console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
36672                         v.transformDirection(this);
36673                 },
36674                 crossVector: function crossVector(vector) {
36675                         console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
36676                         return vector.applyMatrix4(this);
36677                 },
36678                 translate: function translate() {
36679                         console.error('THREE.Matrix4: .translate() has been removed.');
36680                 },
36681                 rotateX: function rotateX() {
36682                         console.error('THREE.Matrix4: .rotateX() has been removed.');
36683                 },
36684                 rotateY: function rotateY() {
36685                         console.error('THREE.Matrix4: .rotateY() has been removed.');
36686                 },
36687                 rotateZ: function rotateZ() {
36688                         console.error('THREE.Matrix4: .rotateZ() has been removed.');
36689                 },
36690                 rotateByAxis: function rotateByAxis() {
36691                         console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
36692                 },
36693                 applyToBufferAttribute: function applyToBufferAttribute(attribute) {
36694                         console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
36695                         return attribute.applyMatrix4(this);
36696                 },
36697                 applyToVector3Array: function applyToVector3Array()
36698                 /* array, offset, length */
36699                 {
36700                         console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
36701                 },
36702                 makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
36703                         console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
36704                         return this.makePerspective(left, right, top, bottom, near, far);
36705                 },
36706                 getInverse: function getInverse(matrix) {
36707                         console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
36708                         return this.copy(matrix).invert();
36709                 }
36710         });
36711
36712         Plane.prototype.isIntersectionLine = function (line) {
36713                 console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
36714                 return this.intersectsLine(line);
36715         };
36716
36717         Object.assign(Quaternion.prototype, {
36718                 multiplyVector3: function multiplyVector3(vector) {
36719                         console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
36720                         return vector.applyQuaternion(this);
36721                 },
36722                 inverse: function inverse() {
36723                         console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
36724                         return this.invert();
36725                 }
36726         });
36727         Object.assign(Ray.prototype, {
36728                 isIntersectionBox: function isIntersectionBox(box) {
36729                         console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
36730                         return this.intersectsBox(box);
36731                 },
36732                 isIntersectionPlane: function isIntersectionPlane(plane) {
36733                         console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
36734                         return this.intersectsPlane(plane);
36735                 },
36736                 isIntersectionSphere: function isIntersectionSphere(sphere) {
36737                         console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
36738                         return this.intersectsSphere(sphere);
36739                 }
36740         });
36741         Object.assign(Triangle.prototype, {
36742                 area: function area() {
36743                         console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
36744                         return this.getArea();
36745                 },
36746                 barycoordFromPoint: function barycoordFromPoint(point, target) {
36747                         console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
36748                         return this.getBarycoord(point, target);
36749                 },
36750                 midpoint: function midpoint(target) {
36751                         console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
36752                         return this.getMidpoint(target);
36753                 },
36754                 normal: function normal(target) {
36755                         console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
36756                         return this.getNormal(target);
36757                 },
36758                 plane: function plane(target) {
36759                         console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
36760                         return this.getPlane(target);
36761                 }
36762         });
36763         Object.assign(Triangle, {
36764                 barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
36765                         console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
36766                         return Triangle.getBarycoord(point, a, b, c, target);
36767                 },
36768                 normal: function normal(a, b, c, target) {
36769                         console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
36770                         return Triangle.getNormal(a, b, c, target);
36771                 }
36772         });
36773         Object.assign(Shape.prototype, {
36774                 extractAllPoints: function extractAllPoints(divisions) {
36775                         console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
36776                         return this.extractPoints(divisions);
36777                 },
36778                 extrude: function extrude(options) {
36779                         console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
36780                         return new ExtrudeGeometry(this, options);
36781                 },
36782                 makeGeometry: function makeGeometry(options) {
36783                         console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
36784                         return new ShapeGeometry(this, options);
36785                 }
36786         });
36787         Object.assign(Vector2.prototype, {
36788                 fromAttribute: function fromAttribute(attribute, index, offset) {
36789                         console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
36790                         return this.fromBufferAttribute(attribute, index, offset);
36791                 },
36792                 distanceToManhattan: function distanceToManhattan(v) {
36793                         console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
36794                         return this.manhattanDistanceTo(v);
36795                 },
36796                 lengthManhattan: function lengthManhattan() {
36797                         console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
36798                         return this.manhattanLength();
36799                 }
36800         });
36801         Object.assign(Vector3.prototype, {
36802                 setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
36803                         console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
36804                 },
36805                 setEulerFromQuaternion: function setEulerFromQuaternion() {
36806                         console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
36807                 },
36808                 getPositionFromMatrix: function getPositionFromMatrix(m) {
36809                         console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
36810                         return this.setFromMatrixPosition(m);
36811                 },
36812                 getScaleFromMatrix: function getScaleFromMatrix(m) {
36813                         console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
36814                         return this.setFromMatrixScale(m);
36815                 },
36816                 getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
36817                         console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
36818                         return this.setFromMatrixColumn(matrix, index);
36819                 },
36820                 applyProjection: function applyProjection(m) {
36821                         console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
36822                         return this.applyMatrix4(m);
36823                 },
36824                 fromAttribute: function fromAttribute(attribute, index, offset) {
36825                         console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
36826                         return this.fromBufferAttribute(attribute, index, offset);
36827                 },
36828                 distanceToManhattan: function distanceToManhattan(v) {
36829                         console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
36830                         return this.manhattanDistanceTo(v);
36831                 },
36832                 lengthManhattan: function lengthManhattan() {
36833                         console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
36834                         return this.manhattanLength();
36835                 }
36836         });
36837         Object.assign(Vector4.prototype, {
36838                 fromAttribute: function fromAttribute(attribute, index, offset) {
36839                         console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
36840                         return this.fromBufferAttribute(attribute, index, offset);
36841                 },
36842                 lengthManhattan: function lengthManhattan() {
36843                         console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
36844                         return this.manhattanLength();
36845                 }
36846         }); //
36847
36848         Object.assign(Geometry.prototype, {
36849                 computeTangents: function computeTangents() {
36850                         console.error('THREE.Geometry: .computeTangents() has been removed.');
36851                 },
36852                 computeLineDistances: function computeLineDistances() {
36853                         console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
36854                 },
36855                 applyMatrix: function applyMatrix(matrix) {
36856                         console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
36857                         return this.applyMatrix4(matrix);
36858                 }
36859         });
36860         Object.assign(Object3D.prototype, {
36861                 getChildByName: function getChildByName(name) {
36862                         console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
36863                         return this.getObjectByName(name);
36864                 },
36865                 renderDepth: function renderDepth() {
36866                         console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
36867                 },
36868                 translate: function translate(distance, axis) {
36869                         console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
36870                         return this.translateOnAxis(axis, distance);
36871                 },
36872                 getWorldRotation: function getWorldRotation() {
36873                         console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
36874                 },
36875                 applyMatrix: function applyMatrix(matrix) {
36876                         console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
36877                         return this.applyMatrix4(matrix);
36878                 }
36879         });
36880         Object.defineProperties(Object3D.prototype, {
36881                 eulerOrder: {
36882                         get: function get() {
36883                                 console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
36884                                 return this.rotation.order;
36885                         },
36886                         set: function set(value) {
36887                                 console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
36888                                 this.rotation.order = value;
36889                         }
36890                 },
36891                 useQuaternion: {
36892                         get: function get() {
36893                                 console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
36894                         },
36895                         set: function set() {
36896                                 console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
36897                         }
36898                 }
36899         });
36900         Object.assign(Mesh.prototype, {
36901                 setDrawMode: function setDrawMode() {
36902                         console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
36903                 }
36904         });
36905         Object.defineProperties(Mesh.prototype, {
36906                 drawMode: {
36907                         get: function get() {
36908                                 console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
36909                                 return TrianglesDrawMode;
36910                         },
36911                         set: function set() {
36912                                 console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
36913                         }
36914                 }
36915         });
36916         Object.defineProperties(LOD.prototype, {
36917                 objects: {
36918                         get: function get() {
36919                                 console.warn('THREE.LOD: .objects has been renamed to .levels.');
36920                                 return this.levels;
36921                         }
36922                 }
36923         });
36924         Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
36925                 get: function get() {
36926                         console.warn('THREE.Skeleton: useVertexTexture has been removed.');
36927                 },
36928                 set: function set() {
36929                         console.warn('THREE.Skeleton: useVertexTexture has been removed.');
36930                 }
36931         });
36932
36933         SkinnedMesh.prototype.initBones = function () {
36934                 console.error('THREE.SkinnedMesh: initBones() has been removed.');
36935         };
36936
36937         Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
36938                 get: function get() {
36939                         console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
36940                         return this.arcLengthDivisions;
36941                 },
36942                 set: function set(value) {
36943                         console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
36944                         this.arcLengthDivisions = value;
36945                 }
36946         }); //
36947
36948         PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
36949                 console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
36950                 if (filmGauge !== undefined) this.filmGauge = filmGauge;
36951                 this.setFocalLength(focalLength);
36952         }; //
36953
36954
36955         Object.defineProperties(Light.prototype, {
36956                 onlyShadow: {
36957                         set: function set() {
36958                                 console.warn('THREE.Light: .onlyShadow has been removed.');
36959                         }
36960                 },
36961                 shadowCameraFov: {
36962                         set: function set(value) {
36963                                 console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
36964                                 this.shadow.camera.fov = value;
36965                         }
36966                 },
36967                 shadowCameraLeft: {
36968                         set: function set(value) {
36969                                 console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
36970                                 this.shadow.camera.left = value;
36971                         }
36972                 },
36973                 shadowCameraRight: {
36974                         set: function set(value) {
36975                                 console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
36976                                 this.shadow.camera.right = value;
36977                         }
36978                 },
36979                 shadowCameraTop: {
36980                         set: function set(value) {
36981                                 console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
36982                                 this.shadow.camera.top = value;
36983                         }
36984                 },
36985                 shadowCameraBottom: {
36986                         set: function set(value) {
36987                                 console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
36988                                 this.shadow.camera.bottom = value;
36989                         }
36990                 },
36991                 shadowCameraNear: {
36992                         set: function set(value) {
36993                                 console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
36994                                 this.shadow.camera.near = value;
36995                         }
36996                 },
36997                 shadowCameraFar: {
36998                         set: function set(value) {
36999                                 console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
37000                                 this.shadow.camera.far = value;
37001                         }
37002                 },
37003                 shadowCameraVisible: {
37004                         set: function set() {
37005                                 console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
37006                         }
37007                 },
37008                 shadowBias: {
37009                         set: function set(value) {
37010                                 console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
37011                                 this.shadow.bias = value;
37012                         }
37013                 },
37014                 shadowDarkness: {
37015                         set: function set() {
37016                                 console.warn('THREE.Light: .shadowDarkness has been removed.');
37017                         }
37018                 },
37019                 shadowMapWidth: {
37020                         set: function set(value) {
37021                                 console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
37022                                 this.shadow.mapSize.width = value;
37023                         }
37024                 },
37025                 shadowMapHeight: {
37026                         set: function set(value) {
37027                                 console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
37028                                 this.shadow.mapSize.height = value;
37029                         }
37030                 }
37031         }); //
37032
37033         Object.defineProperties(BufferAttribute.prototype, {
37034                 length: {
37035                         get: function get() {
37036                                 console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
37037                                 return this.array.length;
37038                         }
37039                 },
37040                 dynamic: {
37041                         get: function get() {
37042                                 console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
37043                                 return this.usage === DynamicDrawUsage;
37044                         },
37045                         set: function set()
37046                         /* value */
37047                         {
37048                                 console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
37049                                 this.setUsage(DynamicDrawUsage);
37050                         }
37051                 }
37052         });
37053         Object.assign(BufferAttribute.prototype, {
37054                 setDynamic: function setDynamic(value) {
37055                         console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
37056                         this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
37057                         return this;
37058                 },
37059                 copyIndicesArray: function copyIndicesArray()
37060                 /* indices */
37061                 {
37062                         console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
37063                 },
37064                 setArray: function setArray()
37065                 /* array */
37066                 {
37067                         console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
37068                 }
37069         });
37070         Object.assign(BufferGeometry.prototype, {
37071                 addIndex: function addIndex(index) {
37072                         console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
37073                         this.setIndex(index);
37074                 },
37075                 addAttribute: function addAttribute(name, attribute) {
37076                         console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
37077
37078                         if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
37079                                 console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
37080                                 return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
37081                         }
37082
37083                         if (name === 'index') {
37084                                 console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
37085                                 this.setIndex(attribute);
37086                                 return this;
37087                         }
37088
37089                         return this.setAttribute(name, attribute);
37090                 },
37091                 addDrawCall: function addDrawCall(start, count, indexOffset) {
37092                         if (indexOffset !== undefined) {
37093                                 console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
37094                         }
37095
37096                         console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
37097                         this.addGroup(start, count);
37098                 },
37099                 clearDrawCalls: function clearDrawCalls() {
37100                         console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
37101                         this.clearGroups();
37102                 },
37103                 computeTangents: function computeTangents() {
37104                         console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
37105                 },
37106                 computeOffsets: function computeOffsets() {
37107                         console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
37108                 },
37109                 removeAttribute: function removeAttribute(name) {
37110                         console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
37111                         return this.deleteAttribute(name);
37112                 },
37113                 applyMatrix: function applyMatrix(matrix) {
37114                         console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
37115                         return this.applyMatrix4(matrix);
37116                 }
37117         });
37118         Object.defineProperties(BufferGeometry.prototype, {
37119                 drawcalls: {
37120                         get: function get() {
37121                                 console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
37122                                 return this.groups;
37123                         }
37124                 },
37125                 offsets: {
37126                         get: function get() {
37127                                 console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
37128                                 return this.groups;
37129                         }
37130                 }
37131         });
37132         Object.defineProperties(InstancedBufferGeometry.prototype, {
37133                 maxInstancedCount: {
37134                         get: function get() {
37135                                 console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
37136                                 return this.instanceCount;
37137                         },
37138                         set: function set(value) {
37139                                 console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
37140                                 this.instanceCount = value;
37141                         }
37142                 }
37143         });
37144         Object.defineProperties(Raycaster.prototype, {
37145                 linePrecision: {
37146                         get: function get() {
37147                                 console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
37148                                 return this.params.Line.threshold;
37149                         },
37150                         set: function set(value) {
37151                                 console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
37152                                 this.params.Line.threshold = value;
37153                         }
37154                 }
37155         });
37156         Object.defineProperties(InterleavedBuffer.prototype, {
37157                 dynamic: {
37158                         get: function get() {
37159                                 console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
37160                                 return this.usage === DynamicDrawUsage;
37161                         },
37162                         set: function set(value) {
37163                                 console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
37164                                 this.setUsage(value);
37165                         }
37166                 }
37167         });
37168         Object.assign(InterleavedBuffer.prototype, {
37169                 setDynamic: function setDynamic(value) {
37170                         console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
37171                         this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
37172                         return this;
37173                 },
37174                 setArray: function setArray()
37175                 /* array */
37176                 {
37177                         console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
37178                 }
37179         }); //
37180
37181         Object.assign(ExtrudeBufferGeometry.prototype, {
37182                 getArrays: function getArrays() {
37183                         console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
37184                 },
37185                 addShapeList: function addShapeList() {
37186                         console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
37187                 },
37188                 addShape: function addShape() {
37189                         console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
37190                 }
37191         }); //
37192
37193         Object.assign(Scene.prototype, {
37194                 dispose: function dispose() {
37195                         console.error('THREE.Scene: .dispose() has been removed.');
37196                 }
37197         }); //
37198
37199         Object.defineProperties(Uniform.prototype, {
37200                 dynamic: {
37201                         set: function set() {
37202                                 console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
37203                         }
37204                 },
37205                 onUpdate: {
37206                         value: function value() {
37207                                 console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
37208                                 return this;
37209                         }
37210                 }
37211         }); //
37212
37213         Object.defineProperties(Material.prototype, {
37214                 wrapAround: {
37215                         get: function get() {
37216                                 console.warn('THREE.Material: .wrapAround has been removed.');
37217                         },
37218                         set: function set() {
37219                                 console.warn('THREE.Material: .wrapAround has been removed.');
37220                         }
37221                 },
37222                 overdraw: {
37223                         get: function get() {
37224                                 console.warn('THREE.Material: .overdraw has been removed.');
37225                         },
37226                         set: function set() {
37227                                 console.warn('THREE.Material: .overdraw has been removed.');
37228                         }
37229                 },
37230                 wrapRGB: {
37231                         get: function get() {
37232                                 console.warn('THREE.Material: .wrapRGB has been removed.');
37233                                 return new Color();
37234                         }
37235                 },
37236                 shading: {
37237                         get: function get() {
37238                                 console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
37239                         },
37240                         set: function set(value) {
37241                                 console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
37242                                 this.flatShading = value === FlatShading;
37243                         }
37244                 },
37245                 stencilMask: {
37246                         get: function get() {
37247                                 console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
37248                                 return this.stencilFuncMask;
37249                         },
37250                         set: function set(value) {
37251                                 console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
37252                                 this.stencilFuncMask = value;
37253                         }
37254                 }
37255         });
37256         Object.defineProperties(MeshPhongMaterial.prototype, {
37257                 metal: {
37258                         get: function get() {
37259                                 console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
37260                                 return false;
37261                         },
37262                         set: function set() {
37263                                 console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
37264                         }
37265                 }
37266         });
37267         Object.defineProperties(MeshPhysicalMaterial.prototype, {
37268                 transparency: {
37269                         get: function get() {
37270                                 console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
37271                                 return this.transmission;
37272                         },
37273                         set: function set(value) {
37274                                 console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
37275                                 this.transmission = value;
37276                         }
37277                 }
37278         });
37279         Object.defineProperties(ShaderMaterial.prototype, {
37280                 derivatives: {
37281                         get: function get() {
37282                                 console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
37283                                 return this.extensions.derivatives;
37284                         },
37285                         set: function set(value) {
37286                                 console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
37287                                 this.extensions.derivatives = value;
37288                         }
37289                 }
37290         }); //
37291
37292         Object.assign(WebGLRenderer.prototype, {
37293                 clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
37294                         console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
37295                         this.setRenderTarget(renderTarget);
37296                         this.clear(color, depth, stencil);
37297                 },
37298                 animate: function animate(callback) {
37299                         console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
37300                         this.setAnimationLoop(callback);
37301                 },
37302                 getCurrentRenderTarget: function getCurrentRenderTarget() {
37303                         console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
37304                         return this.getRenderTarget();
37305                 },
37306                 getMaxAnisotropy: function getMaxAnisotropy() {
37307                         console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
37308                         return this.capabilities.getMaxAnisotropy();
37309                 },
37310                 getPrecision: function getPrecision() {
37311                         console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
37312                         return this.capabilities.precision;
37313                 },
37314                 resetGLState: function resetGLState() {
37315                         console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
37316                         return this.state.reset();
37317                 },
37318                 supportsFloatTextures: function supportsFloatTextures() {
37319                         console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
37320                         return this.extensions.get('OES_texture_float');
37321                 },
37322                 supportsHalfFloatTextures: function supportsHalfFloatTextures() {
37323                         console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
37324                         return this.extensions.get('OES_texture_half_float');
37325                 },
37326                 supportsStandardDerivatives: function supportsStandardDerivatives() {
37327                         console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
37328                         return this.extensions.get('OES_standard_derivatives');
37329                 },
37330                 supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
37331                         console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
37332                         return this.extensions.get('WEBGL_compressed_texture_s3tc');
37333                 },
37334                 supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
37335                         console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
37336                         return this.extensions.get('WEBGL_compressed_texture_pvrtc');
37337                 },
37338                 supportsBlendMinMax: function supportsBlendMinMax() {
37339                         console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
37340                         return this.extensions.get('EXT_blend_minmax');
37341                 },
37342                 supportsVertexTextures: function supportsVertexTextures() {
37343                         console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
37344                         return this.capabilities.vertexTextures;
37345                 },
37346                 supportsInstancedArrays: function supportsInstancedArrays() {
37347                         console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
37348                         return this.extensions.get('ANGLE_instanced_arrays');
37349                 },
37350                 enableScissorTest: function enableScissorTest(boolean) {
37351                         console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
37352                         this.setScissorTest(boolean);
37353                 },
37354                 initMaterial: function initMaterial() {
37355                         console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
37356                 },
37357                 addPrePlugin: function addPrePlugin() {
37358                         console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
37359                 },
37360                 addPostPlugin: function addPostPlugin() {
37361                         console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
37362                 },
37363                 updateShadowMap: function updateShadowMap() {
37364                         console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
37365                 },
37366                 setFaceCulling: function setFaceCulling() {
37367                         console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
37368                 },
37369                 allocTextureUnit: function allocTextureUnit() {
37370                         console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
37371                 },
37372                 setTexture: function setTexture() {
37373                         console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
37374                 },
37375                 setTexture2D: function setTexture2D() {
37376                         console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
37377                 },
37378                 setTextureCube: function setTextureCube() {
37379                         console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
37380                 },
37381                 getActiveMipMapLevel: function getActiveMipMapLevel() {
37382                         console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
37383                         return this.getActiveMipmapLevel();
37384                 }
37385         });
37386         Object.defineProperties(WebGLRenderer.prototype, {
37387                 shadowMapEnabled: {
37388                         get: function get() {
37389                                 return this.shadowMap.enabled;
37390                         },
37391                         set: function set(value) {
37392                                 console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
37393                                 this.shadowMap.enabled = value;
37394                         }
37395                 },
37396                 shadowMapType: {
37397                         get: function get() {
37398                                 return this.shadowMap.type;
37399                         },
37400                         set: function set(value) {
37401                                 console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
37402                                 this.shadowMap.type = value;
37403                         }
37404                 },
37405                 shadowMapCullFace: {
37406                         get: function get() {
37407                                 console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
37408                                 return undefined;
37409                         },
37410                         set: function set()
37411                         /* value */
37412                         {
37413                                 console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
37414                         }
37415                 },
37416                 context: {
37417                         get: function get() {
37418                                 console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
37419                                 return this.getContext();
37420                         }
37421                 },
37422                 vr: {
37423                         get: function get() {
37424                                 console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
37425                                 return this.xr;
37426                         }
37427                 },
37428                 gammaInput: {
37429                         get: function get() {
37430                                 console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
37431                                 return false;
37432                         },
37433                         set: function set() {
37434                                 console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
37435                         }
37436                 },
37437                 gammaOutput: {
37438                         get: function get() {
37439                                 console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
37440                                 return false;
37441                         },
37442                         set: function set(value) {
37443                                 console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
37444                                 this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
37445                         }
37446                 },
37447                 toneMappingWhitePoint: {
37448                         get: function get() {
37449                                 console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
37450                                 return 1.0;
37451                         },
37452                         set: function set() {
37453                                 console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
37454                         }
37455                 }
37456         });
37457         Object.defineProperties(WebGLShadowMap.prototype, {
37458                 cullFace: {
37459                         get: function get() {
37460                                 console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
37461                                 return undefined;
37462                         },
37463                         set: function set()
37464                         /* cullFace */
37465                         {
37466                                 console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
37467                         }
37468                 },
37469                 renderReverseSided: {
37470                         get: function get() {
37471                                 console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
37472                                 return undefined;
37473                         },
37474                         set: function set() {
37475                                 console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
37476                         }
37477                 },
37478                 renderSingleSided: {
37479                         get: function get() {
37480                                 console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
37481                                 return undefined;
37482                         },
37483                         set: function set() {
37484                                 console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
37485                         }
37486                 }
37487         });
37488         function WebGLRenderTargetCube(width, height, options) {
37489                 console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
37490                 return new WebGLCubeRenderTarget(width, options);
37491         } //
37492
37493         Object.defineProperties(WebGLRenderTarget.prototype, {
37494                 wrapS: {
37495                         get: function get() {
37496                                 console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
37497                                 return this.texture.wrapS;
37498                         },
37499                         set: function set(value) {
37500                                 console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
37501                                 this.texture.wrapS = value;
37502                         }
37503                 },
37504                 wrapT: {
37505                         get: function get() {
37506                                 console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
37507                                 return this.texture.wrapT;
37508                         },
37509                         set: function set(value) {
37510                                 console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
37511                                 this.texture.wrapT = value;
37512                         }
37513                 },
37514                 magFilter: {
37515                         get: function get() {
37516                                 console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
37517                                 return this.texture.magFilter;
37518                         },
37519                         set: function set(value) {
37520                                 console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
37521                                 this.texture.magFilter = value;
37522                         }
37523                 },
37524                 minFilter: {
37525                         get: function get() {
37526                                 console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
37527                                 return this.texture.minFilter;
37528                         },
37529                         set: function set(value) {
37530                                 console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
37531                                 this.texture.minFilter = value;
37532                         }
37533                 },
37534                 anisotropy: {
37535                         get: function get() {
37536                                 console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
37537                                 return this.texture.anisotropy;
37538                         },
37539                         set: function set(value) {
37540                                 console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
37541                                 this.texture.anisotropy = value;
37542                         }
37543                 },
37544                 offset: {
37545                         get: function get() {
37546                                 console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
37547                                 return this.texture.offset;
37548                         },
37549                         set: function set(value) {
37550                                 console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
37551                                 this.texture.offset = value;
37552                         }
37553                 },
37554                 repeat: {
37555                         get: function get() {
37556                                 console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
37557                                 return this.texture.repeat;
37558                         },
37559                         set: function set(value) {
37560                                 console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
37561                                 this.texture.repeat = value;
37562                         }
37563                 },
37564                 format: {
37565                         get: function get() {
37566                                 console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
37567                                 return this.texture.format;
37568                         },
37569                         set: function set(value) {
37570                                 console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
37571                                 this.texture.format = value;
37572                         }
37573                 },
37574                 type: {
37575                         get: function get() {
37576                                 console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
37577                                 return this.texture.type;
37578                         },
37579                         set: function set(value) {
37580                                 console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
37581                                 this.texture.type = value;
37582                         }
37583                 },
37584                 generateMipmaps: {
37585                         get: function get() {
37586                                 console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
37587                                 return this.texture.generateMipmaps;
37588                         },
37589                         set: function set(value) {
37590                                 console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
37591                                 this.texture.generateMipmaps = value;
37592                         }
37593                 }
37594         }); //
37595
37596         Object.defineProperties(Audio.prototype, {
37597                 load: {
37598                         value: function value(file) {
37599                                 console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
37600                                 var scope = this;
37601                                 var audioLoader = new AudioLoader();
37602                                 audioLoader.load(file, function (buffer) {
37603                                         scope.setBuffer(buffer);
37604                                 });
37605                                 return this;
37606                         }
37607                 },
37608                 startTime: {
37609                         set: function set() {
37610                                 console.warn('THREE.Audio: .startTime is now .play( delay ).');
37611                         }
37612                 }
37613         });
37614
37615         AudioAnalyser.prototype.getData = function () {
37616                 console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
37617                 return this.getFrequencyData();
37618         }; //
37619
37620
37621         CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
37622                 console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
37623                 return this.update(renderer, scene);
37624         };
37625
37626         CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
37627                 console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
37628                 return this.renderTarget.clear(renderer, color, depth, stencil);
37629         }; //
37630
37631
37632         var GeometryUtils = {
37633                 merge: function merge(geometry1, geometry2, materialIndexOffset) {
37634                         console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
37635                         var matrix;
37636
37637                         if (geometry2.isMesh) {
37638                                 geometry2.matrixAutoUpdate && geometry2.updateMatrix();
37639                                 matrix = geometry2.matrix;
37640                                 geometry2 = geometry2.geometry;
37641                         }
37642
37643                         geometry1.merge(geometry2, matrix, materialIndexOffset);
37644                 },
37645                 center: function center(geometry) {
37646                         console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
37647                         return geometry.center();
37648                 }
37649         };
37650         ImageUtils.crossOrigin = undefined;
37651
37652         ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
37653                 console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
37654                 var loader = new TextureLoader();
37655                 loader.setCrossOrigin(this.crossOrigin);
37656                 var texture = loader.load(url, onLoad, undefined, onError);
37657                 if (mapping) texture.mapping = mapping;
37658                 return texture;
37659         };
37660
37661         ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
37662                 console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
37663                 var loader = new CubeTextureLoader();
37664                 loader.setCrossOrigin(this.crossOrigin);
37665                 var texture = loader.load(urls, onLoad, undefined, onError);
37666                 if (mapping) texture.mapping = mapping;
37667                 return texture;
37668         };
37669
37670         ImageUtils.loadCompressedTexture = function () {
37671                 console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
37672         };
37673
37674         ImageUtils.loadCompressedTextureCube = function () {
37675                 console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
37676         }; //
37677
37678
37679         function CanvasRenderer() {
37680                 console.error('THREE.CanvasRenderer has been removed');
37681         } //
37682
37683         function JSONLoader() {
37684                 console.error('THREE.JSONLoader has been removed.');
37685         } //
37686
37687         var SceneUtils = {
37688                 createMultiMaterialObject: function createMultiMaterialObject()
37689                 /* geometry, materials */
37690                 {
37691                         console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
37692                 },
37693                 detach: function detach()
37694                 /* child, parent, scene */
37695                 {
37696                         console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
37697                 },
37698                 attach: function attach()
37699                 /* child, scene, parent */
37700                 {
37701                         console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
37702                 }
37703         }; //
37704
37705         function LensFlare() {
37706                 console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
37707         }
37708
37709         if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
37710                 /* eslint-disable no-undef */
37711                 __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
37712                         detail: {
37713                                 revision: REVISION
37714                         }
37715                 }));
37716                 /* eslint-enable no-undef */
37717
37718         }
37719
37720         exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
37721         exports.AddEquation = AddEquation;
37722         exports.AddOperation = AddOperation;
37723         exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
37724         exports.AdditiveBlending = AdditiveBlending;
37725         exports.AlphaFormat = AlphaFormat;
37726         exports.AlwaysDepth = AlwaysDepth;
37727         exports.AlwaysStencilFunc = AlwaysStencilFunc;
37728         exports.AmbientLight = AmbientLight;
37729         exports.AmbientLightProbe = AmbientLightProbe;
37730         exports.AnimationClip = AnimationClip;
37731         exports.AnimationLoader = AnimationLoader;
37732         exports.AnimationMixer = AnimationMixer;
37733         exports.AnimationObjectGroup = AnimationObjectGroup;
37734         exports.AnimationUtils = AnimationUtils;
37735         exports.ArcCurve = ArcCurve;
37736         exports.ArrayCamera = ArrayCamera;
37737         exports.ArrowHelper = ArrowHelper;
37738         exports.Audio = Audio;
37739         exports.AudioAnalyser = AudioAnalyser;
37740         exports.AudioContext = AudioContext;
37741         exports.AudioListener = AudioListener;
37742         exports.AudioLoader = AudioLoader;
37743         exports.AxesHelper = AxesHelper;
37744         exports.AxisHelper = AxisHelper;
37745         exports.BackSide = BackSide;
37746         exports.BasicDepthPacking = BasicDepthPacking;
37747         exports.BasicShadowMap = BasicShadowMap;
37748         exports.BinaryTextureLoader = BinaryTextureLoader;
37749         exports.Bone = Bone;
37750         exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
37751         exports.BoundingBoxHelper = BoundingBoxHelper;
37752         exports.Box2 = Box2;
37753         exports.Box3 = Box3;
37754         exports.Box3Helper = Box3Helper;
37755         exports.BoxBufferGeometry = BoxBufferGeometry;
37756         exports.BoxGeometry = BoxGeometry;
37757         exports.BoxHelper = BoxHelper;
37758         exports.BufferAttribute = BufferAttribute;
37759         exports.BufferGeometry = BufferGeometry;
37760         exports.BufferGeometryLoader = BufferGeometryLoader;
37761         exports.ByteType = ByteType;
37762         exports.Cache = Cache;
37763         exports.Camera = Camera;
37764         exports.CameraHelper = CameraHelper;
37765         exports.CanvasRenderer = CanvasRenderer;
37766         exports.CanvasTexture = CanvasTexture;
37767         exports.CatmullRomCurve3 = CatmullRomCurve3;
37768         exports.CineonToneMapping = CineonToneMapping;
37769         exports.CircleBufferGeometry = CircleBufferGeometry;
37770         exports.CircleGeometry = CircleGeometry;
37771         exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
37772         exports.Clock = Clock;
37773         exports.ClosedSplineCurve3 = ClosedSplineCurve3;
37774         exports.Color = Color;
37775         exports.ColorKeyframeTrack = ColorKeyframeTrack;
37776         exports.CompressedTexture = CompressedTexture;
37777         exports.CompressedTextureLoader = CompressedTextureLoader;
37778         exports.ConeBufferGeometry = ConeBufferGeometry;
37779         exports.ConeGeometry = ConeGeometry;
37780         exports.CubeCamera = CubeCamera;
37781         exports.CubeGeometry = BoxGeometry;
37782         exports.CubeReflectionMapping = CubeReflectionMapping;
37783         exports.CubeRefractionMapping = CubeRefractionMapping;
37784         exports.CubeTexture = CubeTexture;
37785         exports.CubeTextureLoader = CubeTextureLoader;
37786         exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
37787         exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
37788         exports.CubicBezierCurve = CubicBezierCurve;
37789         exports.CubicBezierCurve3 = CubicBezierCurve3;
37790         exports.CubicInterpolant = CubicInterpolant;
37791         exports.CullFaceBack = CullFaceBack;
37792         exports.CullFaceFront = CullFaceFront;
37793         exports.CullFaceFrontBack = CullFaceFrontBack;
37794         exports.CullFaceNone = CullFaceNone;
37795         exports.Curve = Curve;
37796         exports.CurvePath = CurvePath;
37797         exports.CustomBlending = CustomBlending;
37798         exports.CustomToneMapping = CustomToneMapping;
37799         exports.CylinderBufferGeometry = CylinderBufferGeometry;
37800         exports.CylinderGeometry = CylinderGeometry;
37801         exports.Cylindrical = Cylindrical;
37802         exports.DataTexture = DataTexture;
37803         exports.DataTexture2DArray = DataTexture2DArray;
37804         exports.DataTexture3D = DataTexture3D;
37805         exports.DataTextureLoader = DataTextureLoader;
37806         exports.DataUtils = DataUtils;
37807         exports.DecrementStencilOp = DecrementStencilOp;
37808         exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
37809         exports.DefaultLoadingManager = DefaultLoadingManager;
37810         exports.DepthFormat = DepthFormat;
37811         exports.DepthStencilFormat = DepthStencilFormat;
37812         exports.DepthTexture = DepthTexture;
37813         exports.DirectionalLight = DirectionalLight;
37814         exports.DirectionalLightHelper = DirectionalLightHelper;
37815         exports.DiscreteInterpolant = DiscreteInterpolant;
37816         exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
37817         exports.DodecahedronGeometry = DodecahedronGeometry;
37818         exports.DoubleSide = DoubleSide;
37819         exports.DstAlphaFactor = DstAlphaFactor;
37820         exports.DstColorFactor = DstColorFactor;
37821         exports.DynamicBufferAttribute = DynamicBufferAttribute;
37822         exports.DynamicCopyUsage = DynamicCopyUsage;
37823         exports.DynamicDrawUsage = DynamicDrawUsage;
37824         exports.DynamicReadUsage = DynamicReadUsage;
37825         exports.EdgesGeometry = EdgesGeometry;
37826         exports.EdgesHelper = EdgesHelper;
37827         exports.EllipseCurve = EllipseCurve;
37828         exports.EqualDepth = EqualDepth;
37829         exports.EqualStencilFunc = EqualStencilFunc;
37830         exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
37831         exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
37832         exports.Euler = Euler;
37833         exports.EventDispatcher = EventDispatcher;
37834         exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
37835         exports.ExtrudeGeometry = ExtrudeGeometry;
37836         exports.Face3 = Face3;
37837         exports.Face4 = Face4;
37838         exports.FaceColors = FaceColors;
37839         exports.FileLoader = FileLoader;
37840         exports.FlatShading = FlatShading;
37841         exports.Float16BufferAttribute = Float16BufferAttribute;
37842         exports.Float32Attribute = Float32Attribute;
37843         exports.Float32BufferAttribute = Float32BufferAttribute;
37844         exports.Float64Attribute = Float64Attribute;
37845         exports.Float64BufferAttribute = Float64BufferAttribute;
37846         exports.FloatType = FloatType;
37847         exports.Fog = Fog;
37848         exports.FogExp2 = FogExp2;
37849         exports.Font = Font;
37850         exports.FontLoader = FontLoader;
37851         exports.FrontSide = FrontSide;
37852         exports.Frustum = Frustum;
37853         exports.GLBufferAttribute = GLBufferAttribute;
37854         exports.GLSL1 = GLSL1;
37855         exports.GLSL3 = GLSL3;
37856         exports.GammaEncoding = GammaEncoding;
37857         exports.Geometry = Geometry;
37858         exports.GeometryUtils = GeometryUtils;
37859         exports.GreaterDepth = GreaterDepth;
37860         exports.GreaterEqualDepth = GreaterEqualDepth;
37861         exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
37862         exports.GreaterStencilFunc = GreaterStencilFunc;
37863         exports.GridHelper = GridHelper;
37864         exports.Group = Group;
37865         exports.HalfFloatType = HalfFloatType;
37866         exports.HemisphereLight = HemisphereLight;
37867         exports.HemisphereLightHelper = HemisphereLightHelper;
37868         exports.HemisphereLightProbe = HemisphereLightProbe;
37869         exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
37870         exports.IcosahedronGeometry = IcosahedronGeometry;
37871         exports.ImageBitmapLoader = ImageBitmapLoader;
37872         exports.ImageLoader = ImageLoader;
37873         exports.ImageUtils = ImageUtils;
37874         exports.ImmediateRenderObject = ImmediateRenderObject;
37875         exports.IncrementStencilOp = IncrementStencilOp;
37876         exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
37877         exports.InstancedBufferAttribute = InstancedBufferAttribute;
37878         exports.InstancedBufferGeometry = InstancedBufferGeometry;
37879         exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
37880         exports.InstancedMesh = InstancedMesh;
37881         exports.Int16Attribute = Int16Attribute;
37882         exports.Int16BufferAttribute = Int16BufferAttribute;
37883         exports.Int32Attribute = Int32Attribute;
37884         exports.Int32BufferAttribute = Int32BufferAttribute;
37885         exports.Int8Attribute = Int8Attribute;
37886         exports.Int8BufferAttribute = Int8BufferAttribute;
37887         exports.IntType = IntType;
37888         exports.InterleavedBuffer = InterleavedBuffer;
37889         exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
37890         exports.Interpolant = Interpolant;
37891         exports.InterpolateDiscrete = InterpolateDiscrete;
37892         exports.InterpolateLinear = InterpolateLinear;
37893         exports.InterpolateSmooth = InterpolateSmooth;
37894         exports.InvertStencilOp = InvertStencilOp;
37895         exports.JSONLoader = JSONLoader;
37896         exports.KeepStencilOp = KeepStencilOp;
37897         exports.KeyframeTrack = KeyframeTrack;
37898         exports.LOD = LOD;
37899         exports.LatheBufferGeometry = LatheBufferGeometry;
37900         exports.LatheGeometry = LatheGeometry;
37901         exports.Layers = Layers;
37902         exports.LensFlare = LensFlare;
37903         exports.LessDepth = LessDepth;
37904         exports.LessEqualDepth = LessEqualDepth;
37905         exports.LessEqualStencilFunc = LessEqualStencilFunc;
37906         exports.LessStencilFunc = LessStencilFunc;
37907         exports.Light = Light;
37908         exports.LightProbe = LightProbe;
37909         exports.Line = Line;
37910         exports.Line3 = Line3;
37911         exports.LineBasicMaterial = LineBasicMaterial;
37912         exports.LineCurve = LineCurve;
37913         exports.LineCurve3 = LineCurve3;
37914         exports.LineDashedMaterial = LineDashedMaterial;
37915         exports.LineLoop = LineLoop;
37916         exports.LinePieces = LinePieces;
37917         exports.LineSegments = LineSegments;
37918         exports.LineStrip = LineStrip;
37919         exports.LinearEncoding = LinearEncoding;
37920         exports.LinearFilter = LinearFilter;
37921         exports.LinearInterpolant = LinearInterpolant;
37922         exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
37923         exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
37924         exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
37925         exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
37926         exports.LinearToneMapping = LinearToneMapping;
37927         exports.Loader = Loader;
37928         exports.LoaderUtils = LoaderUtils;
37929         exports.LoadingManager = LoadingManager;
37930         exports.LogLuvEncoding = LogLuvEncoding;
37931         exports.LoopOnce = LoopOnce;
37932         exports.LoopPingPong = LoopPingPong;
37933         exports.LoopRepeat = LoopRepeat;
37934         exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
37935         exports.LuminanceFormat = LuminanceFormat;
37936         exports.MOUSE = MOUSE;
37937         exports.Material = Material;
37938         exports.MaterialLoader = MaterialLoader;
37939         exports.Math = MathUtils;
37940         exports.MathUtils = MathUtils;
37941         exports.Matrix3 = Matrix3;
37942         exports.Matrix4 = Matrix4;
37943         exports.MaxEquation = MaxEquation;
37944         exports.Mesh = Mesh;
37945         exports.MeshBasicMaterial = MeshBasicMaterial;
37946         exports.MeshDepthMaterial = MeshDepthMaterial;
37947         exports.MeshDistanceMaterial = MeshDistanceMaterial;
37948         exports.MeshFaceMaterial = MeshFaceMaterial;
37949         exports.MeshLambertMaterial = MeshLambertMaterial;
37950         exports.MeshMatcapMaterial = MeshMatcapMaterial;
37951         exports.MeshNormalMaterial = MeshNormalMaterial;
37952         exports.MeshPhongMaterial = MeshPhongMaterial;
37953         exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
37954         exports.MeshStandardMaterial = MeshStandardMaterial;
37955         exports.MeshToonMaterial = MeshToonMaterial;
37956         exports.MinEquation = MinEquation;
37957         exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
37958         exports.MixOperation = MixOperation;
37959         exports.MultiMaterial = MultiMaterial;
37960         exports.MultiplyBlending = MultiplyBlending;
37961         exports.MultiplyOperation = MultiplyOperation;
37962         exports.NearestFilter = NearestFilter;
37963         exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
37964         exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
37965         exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
37966         exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
37967         exports.NeverDepth = NeverDepth;
37968         exports.NeverStencilFunc = NeverStencilFunc;
37969         exports.NoBlending = NoBlending;
37970         exports.NoColors = NoColors;
37971         exports.NoToneMapping = NoToneMapping;
37972         exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
37973         exports.NormalBlending = NormalBlending;
37974         exports.NotEqualDepth = NotEqualDepth;
37975         exports.NotEqualStencilFunc = NotEqualStencilFunc;
37976         exports.NumberKeyframeTrack = NumberKeyframeTrack;
37977         exports.Object3D = Object3D;
37978         exports.ObjectLoader = ObjectLoader;
37979         exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
37980         exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
37981         exports.OctahedronGeometry = OctahedronGeometry;
37982         exports.OneFactor = OneFactor;
37983         exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
37984         exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
37985         exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
37986         exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
37987         exports.OrthographicCamera = OrthographicCamera;
37988         exports.PCFShadowMap = PCFShadowMap;
37989         exports.PCFSoftShadowMap = PCFSoftShadowMap;
37990         exports.PMREMGenerator = PMREMGenerator;
37991         exports.ParametricBufferGeometry = ParametricBufferGeometry;
37992         exports.ParametricGeometry = ParametricGeometry;
37993         exports.Particle = Particle;
37994         exports.ParticleBasicMaterial = ParticleBasicMaterial;
37995         exports.ParticleSystem = ParticleSystem;
37996         exports.ParticleSystemMaterial = ParticleSystemMaterial;
37997         exports.Path = Path;
37998         exports.PerspectiveCamera = PerspectiveCamera;
37999         exports.Plane = Plane;
38000         exports.PlaneBufferGeometry = PlaneBufferGeometry;
38001         exports.PlaneGeometry = PlaneGeometry;
38002         exports.PlaneHelper = PlaneHelper;
38003         exports.PointCloud = PointCloud;
38004         exports.PointCloudMaterial = PointCloudMaterial;
38005         exports.PointLight = PointLight;
38006         exports.PointLightHelper = PointLightHelper;
38007         exports.Points = Points;
38008         exports.PointsMaterial = PointsMaterial;
38009         exports.PolarGridHelper = PolarGridHelper;
38010         exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
38011         exports.PolyhedronGeometry = PolyhedronGeometry;
38012         exports.PositionalAudio = PositionalAudio;
38013         exports.PropertyBinding = PropertyBinding;
38014         exports.PropertyMixer = PropertyMixer;
38015         exports.QuadraticBezierCurve = QuadraticBezierCurve;
38016         exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
38017         exports.Quaternion = Quaternion;
38018         exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
38019         exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
38020         exports.REVISION = REVISION;
38021         exports.RGBADepthPacking = RGBADepthPacking;
38022         exports.RGBAFormat = RGBAFormat;
38023         exports.RGBAIntegerFormat = RGBAIntegerFormat;
38024         exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
38025         exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
38026         exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
38027         exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
38028         exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
38029         exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
38030         exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
38031         exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
38032         exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
38033         exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
38034         exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
38035         exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
38036         exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
38037         exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
38038         exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
38039         exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
38040         exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
38041         exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
38042         exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
38043         exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
38044         exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
38045         exports.RGBDEncoding = RGBDEncoding;
38046         exports.RGBEEncoding = RGBEEncoding;
38047         exports.RGBEFormat = RGBEFormat;
38048         exports.RGBFormat = RGBFormat;
38049         exports.RGBIntegerFormat = RGBIntegerFormat;
38050         exports.RGBM16Encoding = RGBM16Encoding;
38051         exports.RGBM7Encoding = RGBM7Encoding;
38052         exports.RGB_ETC1_Format = RGB_ETC1_Format;
38053         exports.RGB_ETC2_Format = RGB_ETC2_Format;
38054         exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
38055         exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
38056         exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
38057         exports.RGFormat = RGFormat;
38058         exports.RGIntegerFormat = RGIntegerFormat;
38059         exports.RawShaderMaterial = RawShaderMaterial;
38060         exports.Ray = Ray;
38061         exports.Raycaster = Raycaster;
38062         exports.RectAreaLight = RectAreaLight;
38063         exports.RedFormat = RedFormat;
38064         exports.RedIntegerFormat = RedIntegerFormat;
38065         exports.ReinhardToneMapping = ReinhardToneMapping;
38066         exports.RepeatWrapping = RepeatWrapping;
38067         exports.ReplaceStencilOp = ReplaceStencilOp;
38068         exports.ReverseSubtractEquation = ReverseSubtractEquation;
38069         exports.RingBufferGeometry = RingBufferGeometry;
38070         exports.RingGeometry = RingGeometry;
38071         exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
38072         exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
38073         exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
38074         exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
38075         exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
38076         exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
38077         exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
38078         exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
38079         exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
38080         exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
38081         exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
38082         exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
38083         exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
38084         exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
38085         exports.Scene = Scene;
38086         exports.SceneUtils = SceneUtils;
38087         exports.ShaderChunk = ShaderChunk;
38088         exports.ShaderLib = ShaderLib;
38089         exports.ShaderMaterial = ShaderMaterial;
38090         exports.ShadowMaterial = ShadowMaterial;
38091         exports.Shape = Shape;
38092         exports.ShapeBufferGeometry = ShapeBufferGeometry;
38093         exports.ShapeGeometry = ShapeGeometry;
38094         exports.ShapePath = ShapePath;
38095         exports.ShapeUtils = ShapeUtils;
38096         exports.ShortType = ShortType;
38097         exports.Skeleton = Skeleton;
38098         exports.SkeletonHelper = SkeletonHelper;
38099         exports.SkinnedMesh = SkinnedMesh;
38100         exports.SmoothShading = SmoothShading;
38101         exports.Sphere = Sphere;
38102         exports.SphereBufferGeometry = SphereBufferGeometry;
38103         exports.SphereGeometry = SphereGeometry;
38104         exports.Spherical = Spherical;
38105         exports.SphericalHarmonics3 = SphericalHarmonics3;
38106         exports.Spline = Spline;
38107         exports.SplineCurve = SplineCurve;
38108         exports.SplineCurve3 = SplineCurve3;
38109         exports.SpotLight = SpotLight;
38110         exports.SpotLightHelper = SpotLightHelper;
38111         exports.Sprite = Sprite;
38112         exports.SpriteMaterial = SpriteMaterial;
38113         exports.SrcAlphaFactor = SrcAlphaFactor;
38114         exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
38115         exports.SrcColorFactor = SrcColorFactor;
38116         exports.StaticCopyUsage = StaticCopyUsage;
38117         exports.StaticDrawUsage = StaticDrawUsage;
38118         exports.StaticReadUsage = StaticReadUsage;
38119         exports.StereoCamera = StereoCamera;
38120         exports.StreamCopyUsage = StreamCopyUsage;
38121         exports.StreamDrawUsage = StreamDrawUsage;
38122         exports.StreamReadUsage = StreamReadUsage;
38123         exports.StringKeyframeTrack = StringKeyframeTrack;
38124         exports.SubtractEquation = SubtractEquation;
38125         exports.SubtractiveBlending = SubtractiveBlending;
38126         exports.TOUCH = TOUCH;
38127         exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
38128         exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
38129         exports.TetrahedronGeometry = TetrahedronGeometry;
38130         exports.TextBufferGeometry = TextBufferGeometry;
38131         exports.TextGeometry = TextGeometry;
38132         exports.Texture = Texture;
38133         exports.TextureLoader = TextureLoader;
38134         exports.TorusBufferGeometry = TorusBufferGeometry;
38135         exports.TorusGeometry = TorusGeometry;
38136         exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
38137         exports.TorusKnotGeometry = TorusKnotGeometry;
38138         exports.Triangle = Triangle;
38139         exports.TriangleFanDrawMode = TriangleFanDrawMode;
38140         exports.TriangleStripDrawMode = TriangleStripDrawMode;
38141         exports.TrianglesDrawMode = TrianglesDrawMode;
38142         exports.TubeBufferGeometry = TubeBufferGeometry;
38143         exports.TubeGeometry = TubeGeometry;
38144         exports.UVMapping = UVMapping;
38145         exports.Uint16Attribute = Uint16Attribute;
38146         exports.Uint16BufferAttribute = Uint16BufferAttribute;
38147         exports.Uint32Attribute = Uint32Attribute;
38148         exports.Uint32BufferAttribute = Uint32BufferAttribute;
38149         exports.Uint8Attribute = Uint8Attribute;
38150         exports.Uint8BufferAttribute = Uint8BufferAttribute;
38151         exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
38152         exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
38153         exports.Uniform = Uniform;
38154         exports.UniformsLib = UniformsLib;
38155         exports.UniformsUtils = UniformsUtils;
38156         exports.UnsignedByteType = UnsignedByteType;
38157         exports.UnsignedInt248Type = UnsignedInt248Type;
38158         exports.UnsignedIntType = UnsignedIntType;
38159         exports.UnsignedShort4444Type = UnsignedShort4444Type;
38160         exports.UnsignedShort5551Type = UnsignedShort5551Type;
38161         exports.UnsignedShort565Type = UnsignedShort565Type;
38162         exports.UnsignedShortType = UnsignedShortType;
38163         exports.VSMShadowMap = VSMShadowMap;
38164         exports.Vector2 = Vector2;
38165         exports.Vector3 = Vector3;
38166         exports.Vector4 = Vector4;
38167         exports.VectorKeyframeTrack = VectorKeyframeTrack;
38168         exports.Vertex = Vertex;
38169         exports.VertexColors = VertexColors;
38170         exports.VideoTexture = VideoTexture;
38171         exports.WebGL1Renderer = WebGL1Renderer;
38172         exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
38173         exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
38174         exports.WebGLRenderTarget = WebGLRenderTarget;
38175         exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
38176         exports.WebGLRenderer = WebGLRenderer;
38177         exports.WebGLUtils = WebGLUtils;
38178         exports.WireframeGeometry = WireframeGeometry;
38179         exports.WireframeHelper = WireframeHelper;
38180         exports.WrapAroundEnding = WrapAroundEnding;
38181         exports.XHRLoader = XHRLoader;
38182         exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
38183         exports.ZeroFactor = ZeroFactor;
38184         exports.ZeroSlopeEnding = ZeroSlopeEnding;
38185         exports.ZeroStencilOp = ZeroStencilOp;
38186         exports.sRGBEncoding = sRGBEncoding;
38187
38188         Object.defineProperty(exports, '__esModule', { value: true });
38189
38190 })));